Skip to content

Commit

Permalink
Merge pull request #1109 from xzzy/master2
Browse files Browse the repository at this point in the history
Change Itemized report to a date range
  • Loading branch information
xzzy authored Dec 31, 2024
2 parents 170075e + 9997cb8 commit 9e0765f
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 13 deletions.
20 changes: 20 additions & 0 deletions ledger/payments/migrations/0036_auto_20241107_1450.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2024-11-07 06:50
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('payments', '0035_auto_20240702_2229'),
]

operations = [
migrations.AlterField(
model_name='oracleinterfacepermission',
name='access_type',
field=models.CharField(blank=True, choices=[('all_access', 'Full access to all Financial Tools'), ('view_ledger_tools', 'View Ledger Payment Tools'), ('manage_ledger_tool', 'Manage Ledger Payment Tools'), ('view_payment_totals', 'View Payment Totals'), ('reports_access', 'Reports Access')], default=None, max_length=100, null=True),
),
]
23 changes: 18 additions & 5 deletions ledgergw/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1751,21 +1751,34 @@ def get(self, request, format=None):

report = None
data = {
"date": request.GET.get('date'),
"date_to": request.GET.get('settlement_date_to'),
"date_from": request.GET.get('settlement_date_from'),
}


serializer = SettlementReportSerializer(data=data)
serializer.is_valid(raise_exception=True)
filename = 'Itemised-Transaction-Report-{}'.format(str(serializer.validated_data['date']))

diff_between_dates = (serializer.validated_data['date_to'] - serializer.validated_data['date_from'])
diff_between_dates_in_days = diff_between_dates.days
if diff_between_dates_in_days > 31:
raise serializers.ValidationError('This report has a max limit of 31 days. Please try a smaller date range.')

if diff_between_dates_in_days < 0:
raise serializers.ValidationError('There is an error with the dates you entered. Please check your dates and try again.')

filename = 'Itemised-Transaction-Report-from-{}-to-{}'.format(serializer.validated_data['date_from'].strftime("%Y-%m-%d"),serializer.validated_data['date_to'].strftime("%Y-%m-%d"))
# Generate Report
report = reports.itemised_transaction_report(serializer.validated_data['date'],system)
report = reports.itemised_transaction_report(serializer.validated_data['date_from'],serializer.validated_data['date_to'],system)
if report:
response = HttpResponse(FileWrapper(report), content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="{}.csv"'.format(filename)
return response
else:
raise serializers.ValidationError('No report was generated.')
raise serializers.ValidationError('No report was generated.')
else:
raise serializers.ValidationError('Forbidden Access.')
raise serializers.ValidationError('Forbidden Access.')

except serializers.ValidationError:
raise
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions ledgergw/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@ def booking_bpoint_settlement_report(_date,system):
raise


def itemised_transaction_report(_date,system):
def itemised_transaction_report(_date_from,_date_to,system):
try:
invoices = Invoice.objects.filter(settlement_date=_date,reference__startswith=system)
invoices = Invoice.objects.filter(settlement_date__gte=_date_from,settlement_date__lte=_date_to,reference__startswith=system).order_by('settlement_date')

strIO = StringIO()
fieldnames = ['Invoice Number','Invoice Date','Order Number','Oracle code','Description','Settlement Date','Quantity','Tax Incl','Tax Excl','GST']
Expand Down
3 changes: 2 additions & 1 deletion ledgergw/serialisers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class ReportSerializer(serializers.Serializer):
end = serializers.DateTimeField(input_formats=['%d/%m/%Y'])

class SettlementReportSerializer(serializers.Serializer):
date = serializers.DateTimeField(input_formats=['%d/%m/%Y'])
date_from = serializers.DateTimeField(input_formats=['%d/%m/%Y'])
date_to= serializers.DateTimeField(input_formats=['%d/%m/%Y'])

class OracleSerializer(serializers.Serializer):
date = serializers.DateField(input_formats=['%d/%m/%Y','%Y-%m-%d'])
Expand Down
67 changes: 62 additions & 5 deletions ledgergw/templates/ledgergw/web/reports.html
Original file line number Diff line number Diff line change
Expand Up @@ -313,21 +313,40 @@ <h3 style="margin-bottom:20px;">Itemised Transactions Report</h3>
</div>
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="">Settlement Date</label>
<label for="">Settlement From Date:</label>
<div class="input-group date" ref="itemisedtransreportDatePicker" id='itemisedtransreportDatePicker'>
<input type="text" class="form-control" name="itemised_trans_report" id='itemisedtransreportDatePicker' placeholder="DD/MM/YYYY" required autocomplete='off'>
<input type="text" class="form-control" name="itemised_trans_report_from" id='itemisedtransreportDatePicker' placeholder="DD/MM/YYYY" required autocomplete='off'>
<span class="input-group-addon input-group-text">
<span class="bi bi-calendar2-range-fill"></span>
</span>
</div>
</div>

</div>
<div class="col-sm-6">
<div class="form-group">
<label for="">Settlement To Date:</label>
<div class="input-group date" ref="itemisedtransreportToDatePicker" id='itemisedtransreportToDatePicker'>
<input type="text" class="form-control" name="itemised_trans_report_to" id='itemisedtransreportToDatePicker' placeholder="DD/MM/YYYY" required autocomplete='off'>
<span class="input-group-addon input-group-text">
<span class="bi bi-calendar2-range-fill"></span>
</span>
</div>
</div>

</div>

<div class="col-sm-12">
<br>
<div class="form-group">
<button onclick="reports.ItemisedTransactionReport()" class="btn btn-primary pull-left" >Generate Report</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -415,6 +434,7 @@ <h3 style="margin-bottom:20px;">Itemised Transactions Report</h3>
reports.var.paymentauditDatePicker = $('#paymentauditDatePicker').datepicker(reports.var.datepickerOptions);
reports.var.timepaymentauditreportDatePicker = $('#timepaymentauditreportDatePicker').datepicker(reports.var.datepickerOptions);
reports.var.itemisedtransreportDatePicker = $('#itemisedtransreportDatePicker').datepicker(reports.var.datepickerOptions);
reports.var.itemisedtransreportToDatePicker = $('#itemisedtransreportToDatePicker').datepicker(reports.var.datepickerOptions);
reports.var.flatDateStartPicker.on('dp.hide',function (e) {
reports.var.flatDateEndPicker.data("DateTimePicker").date(null);
reports.var.flatDateEndPicker.data("DateTimePicker").minDate(e.date);
Expand Down Expand Up @@ -549,15 +569,52 @@ <h3 style="margin-bottom:20px;">Itemised Transactions Report</h3>
},
ItemisedTransactionReport: function() {

var settlement_date = moment(reports.var.itemisedtransreportDatePicker.datepicker("getDate")).format('DD/MM/YYYY');
var report_url = reports.var.itemised_transactions_url+"?system="+reports.var.system_id+"&date="+settlement_date;
window.location.assign(report_url);
var settlement_date_from = moment(reports.var.itemisedtransreportDatePicker.datepicker("getDate")).format('DD/MM/YYYY');
var settlement_date_to = moment(reports.var.itemisedtransreportToDatePicker.datepicker("getDate")).format('DD/MM/YYYY');
var report_url = reports.var.itemised_transactions_url+"?system="+reports.var.system_id+"&settlement_date_from="+settlement_date_from+"&settlement_date_to="+settlement_date_to;


fetch(report_url)
.then(resp => {

if (resp.status != 200) {

return resp.text() ;

}
return resp.blob();
}

)
.then(blob => {

if (typeof blob == 'string') {
return Promise.reject(blob);
}
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
// the filename you want
a.download = 'itemised_transaction_report_'+moment(reports.var.itemisedtransreportDatePicker.datepicker("getDate")).format('DD-MM-YYYY')+'-'+moment(reports.var.itemisedtransreportToDatePicker.datepicker("getDate")).format('DD-MM-YYYY')+'.csv';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
alert('File downloaded successfully!');

})
.catch(err => {
alert('ERROR: '+err)

});
// window.location.assign(report_url);

}





}
reports.init();

Expand Down

0 comments on commit 9e0765f

Please sign in to comment.