Skip to content

Commit

Permalink
Merge pull request #1114 from xzzy/master2
Browse files Browse the repository at this point in the history
Invoice support for different ABN and logo and settlement search date range
  • Loading branch information
xzzy authored Feb 5, 2025
2 parents bdea246 + aa882ca commit 8790f0c
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2025-02-04 14:08
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('payments', '0036_auto_20241107_1450'),
]

operations = [
migrations.AddField(
model_name='oracleinterfacesystem',
name='invoice_template',
field=models.CharField(blank=True, choices=[('dbca_default', 'DBCA Default'), ('ria', 'RIA')], default='dbca_default', max_length=20, null=True),
),
]
20 changes: 20 additions & 0 deletions ledger/payments/migrations/0038_oracleinterfacesystem_abn.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 2025-02-05 12:49
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('payments', '0037_oracleinterfacesystem_invoice_template'),
]

operations = [
migrations.AddField(
model_name='oracleinterfacesystem',
name='abn',
field=models.CharField(blank=True, default='', max_length=50, null=True),
),
]
10 changes: 9 additions & 1 deletion ledger/payments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ class OracleInterfaceSystem(models.Model):
("version_1", "Version 1"),
("version_2", "Version 2")
)


INVOICE_TEMPLATE = (
("dbca_default", "DBCA Default"),
("ria", "RIA")
)

system_id = models.CharField(max_length=10)
system_name = models.CharField(max_length=128)
enabled = models.BooleanField(default=False)
Expand All @@ -68,6 +73,9 @@ class OracleInterfaceSystem(models.Model):
method = models.CharField(max_length=30)
integration_type = models.CharField(max_length=20, choices=INTEGRATION_TYPE, default='no_api', null=True,blank=True)
oracle_calculation = models.CharField(max_length=20, choices=ORACLE_CALCULATION, default='version_1', null=True,blank=True)
invoice_template = models.CharField(max_length=20, choices=INVOICE_TEMPLATE, default='dbca_default', null=True,blank=True)
abn = models.CharField(max_length=50, default='', null=True,blank=True)

# specific for bpoint
bpoint_currency = models.CharField(max_length=5, default="AUD", null=True,blank=True)
bpoint_biller_code = models.CharField(max_length=256, default="", null=True,blank=True)
Expand Down
35 changes: 28 additions & 7 deletions ledger/payments/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

from ledger.accounts.models import Document
from ledger.checkout.utils import calculate_excl_gst
from ledger.payments import models as payments_models

#DPAW_HEADER_LOGO = os.path.join(settings.PROJECT_DIR, 'payments','static', 'payments', 'img','dbca_logo.jpg')
#DPAW_HEADER_LOGO_SM = os.path.join(settings.PROJECT_DIR, 'payments','static', 'payments', 'img','dbca_logo_small.png')
#BPAY_LOGO = os.path.join(settings.PROJECT_DIR, 'payments','static', 'payments', 'img', 'BPAY_2012_PORT_BLUE.png')

DPAW_HEADER_LOGO = os.path.join(settings.STATIC_ROOT, 'payments','img', 'dbca_logo.jpg')
DPAW_HEADER_LOGO_SM = os.path.join(settings.STATIC_ROOT, 'payments','img','dbca_logo_small.png')
ROTTNEST_ISLAND_LOGO = os.path.join(settings.STATIC_ROOT, 'payments','img', 'rottnest_island_70h.png')
BPAY_LOGO = os.path.join(settings.STATIC_ROOT, 'payments','img', 'BPAY_2012_PORT_BLUE.png')


Expand Down Expand Up @@ -208,26 +210,45 @@ def draw(self):


def _create_header(canvas, doc, draw_page_number=True):
invoice = doc.invoice
ois = payments_models.OracleInterfaceSystem.objects.filter(system_id=invoice.system)
invoice_template = 'dbca_template'
abn = "38 052 249 024"
if ois.count() > 0:
invoice_template = ois[0].invoice_template
if ois[0].abn:
if len(ois[0].abn) > 2:
abn = ois[0].abn


canvas.saveState()
canvas.setTitle('Invoice')
canvas.setFont(BOLD_FONTNAME, LARGE_FONTSIZE)

current_y = PAGE_HEIGHT - HEADER_MARGIN

dpaw_header_logo = ImageReader(DPAW_HEADER_LOGO)
dpaw_header_logo_size = dpaw_header_logo.getSize()
canvas.drawImage(dpaw_header_logo, PAGE_WIDTH / 3, current_y - (dpaw_header_logo_size[1]/2),width=dpaw_header_logo_size[0]/2, height=dpaw_header_logo_size[1]/2, mask='auto')
if invoice_template == 'ria':
current_y -= 10
dpaw_header_logo = ImageReader(ROTTNEST_ISLAND_LOGO)
dpaw_header_logo_size = dpaw_header_logo.getSize()
canvas.drawImage(dpaw_header_logo, PAGE_WIDTH / 4, current_y - (dpaw_header_logo_size[1]/2),width=dpaw_header_logo_size[0]/1.7, height=dpaw_header_logo_size[1]/1.7, mask='auto')
else:
dpaw_header_logo_size = dpaw_header_logo.getSize()
canvas.drawImage(dpaw_header_logo, PAGE_WIDTH / 3, current_y - (dpaw_header_logo_size[1]/2),width=dpaw_header_logo_size[0]/2, height=dpaw_header_logo_size[1]/2, mask='auto')



current_y -= 70
canvas.drawCentredString(PAGE_WIDTH / 2, current_y - LARGE_FONTSIZE, 'TAX INVOICE / RECEIPT')

current_y -= 20
canvas.drawCentredString(PAGE_WIDTH / 2, current_y - LARGE_FONTSIZE, 'ABN: 38 052 249 024')
current_y -= 20
canvas.drawCentredString(PAGE_WIDTH / 2, current_y - LARGE_FONTSIZE, 'ABN: {}'.format(abn))

# Invoice address details
invoice_details_offset = 37
current_y -= 20
invoice = doc.invoice

total_gst_tax = invoice.order.total_incl_tax - invoice.order.total_excl_tax

canvas.setFont(BOLD_FONTNAME, SMALL_FONTSIZE)
Expand Down Expand Up @@ -279,7 +300,7 @@ def _create_header(canvas, doc, draw_page_number=True):

def _create_invoice(invoice_buffer, invoice):
every_page_frame = Frame(PAGE_MARGIN, PAGE_MARGIN + 250, PAGE_WIDTH - 2 * PAGE_MARGIN,
PAGE_HEIGHT -450 , id='EveryPagesFrame',showBoundary=0)
PAGE_HEIGHT -460 , id='EveryPagesFrame',showBoundary=0)
remit_frame = Frame(PAGE_MARGIN, PAGE_MARGIN, PAGE_WIDTH - 2 * PAGE_MARGIN,
PAGE_HEIGHT - 600, id='RemitFrame',showBoundary=0)
every_page_template = PageTemplate(id='EveryPages', frames=[every_page_frame,remit_frame], onPage=_create_header)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 17 additions & 5 deletions ledgergw/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from rest_framework import viewsets, serializers, status, generics, views
from rest_framework.renderers import JSONRenderer
from decimal import Decimal
from ledgergw.serialisers import ReportSerializer, SettlementReportSerializer, OracleSerializer
from ledgergw.serialisers import ReportSerializer, SettlementReportSerializer, OracleSerializer,ItemisedSettlementReportSerializer
from ledgergw import utils as ledgergw_utils
from django.http import HttpResponse
from wsgiref.util import FileWrapper
Expand Down Expand Up @@ -1716,13 +1716,25 @@ def get(self, request, format=None):
if isp["reports_access"] is True or isp["all_access"] is True:
report = None
data = {
"date": request.GET.get('date'),
"date_from": request.GET.get('from_date'),
"date_to": request.GET.get('to_date'),
}
serializer = SettlementReportSerializer(data=data)
serializer.is_valid(raise_exception=True)
filename = 'Settlement 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 = 'Settlement Report-{}-{}'.format(str(serializer.validated_data['date_from']),serializer.validated_data['date_to'])

# Generate Report
report = reports.booking_bpoint_settlement_report(serializer.validated_data['date'],system)
report = reports.booking_bpoint_settlement_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)
Expand Down Expand Up @@ -1756,7 +1768,7 @@ def get(self, request, format=None):
}


serializer = SettlementReportSerializer(data=data)
serializer = ItemisedSettlementReportSerializer(data=data)
serializer.is_valid(raise_exception=True)

diff_between_dates = (serializer.validated_data['date_to'] - serializer.validated_data['date_from'])
Expand Down
17 changes: 8 additions & 9 deletions ledgergw/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,13 @@ def booking_refunds_old(start,end, system):
except:
raise

def booking_bpoint_settlement_report(_date,system):
def booking_bpoint_settlement_report(date_from,date_to,system):
try:
bpoint, cash = [], []
bpoint.extend([x for x in BpointTransaction.objects.filter(settlement_date=_date,response_code=0,crn1__startswith=system).exclude(crn1__endswith='_test')])
cash = CashTransaction.objects.filter(created__date=_date,invoice__reference__startswith=system).exclude(type__in=['move_out','move_in'])

bpoint.extend([x for x in BpointTransaction.objects.filter(settlement_date__gte=date_from,settlement_date__lte=date_to,response_code=0,crn1__startswith=system).exclude(crn1__endswith='_test')])
cash = CashTransaction.objects.filter(created__date=date_from,invoice__reference__startswith=system).exclude(type__in=['move_out','move_in'])
strIO = StringIO()
fieldnames = ['Payment Date','Settlement Date','Confirmation Number','Name','Type','Amount','Invoice']
fieldnames = ['Payment Date','Settlement Date','Type','Amount','Invoice']
writer = csv.writer(strIO)
writer.writerow(fieldnames)
for b in bpoint:
Expand All @@ -409,9 +408,9 @@ def booking_bpoint_settlement_report(_date,system):
# pass

#if booking:
b_name = u'{} {}'.format('First NAME' ,'Last NAME')

created = timezone.localtime(b.created, pytz.timezone('Australia/Perth'))
writer.writerow([created.strftime('%d/%m/%Y %H:%M:%S'),b.settlement_date.strftime('%d/%m/%Y'),'BOOKIGN CONFIURMATION NUMBER',b_name.encode('utf-8'),str(b.action),b.amount,invoice.reference])
writer.writerow([created.strftime('%d/%m/%Y %H:%M:%S'),b.settlement_date.strftime('%d/%m/%Y'),str(b.action),b.amount,invoice.reference])
#else:
# writer.writerow([b.created.strftime('%d/%m/%Y %H:%M:%S'),b.settlement_date.strftime('%d/%m/%Y'),'','',str(b.action),b.amount,invoice.reference])
except Invoice.DoesNotExist:
Expand All @@ -421,9 +420,9 @@ def booking_bpoint_settlement_report(_date,system):
try:
invoice = b.invoice

b_name = u'{} {}'.format('First NAME 1','Last NAME 2')

created = timezone.localtime(b.created, pytz.timezone('Australia/Perth'))
writer.writerow([created.strftime('%d/%m/%Y %H:%M:%S'),b.created.strftime('%d/%m/%Y'),'BOOKIGN CONFIURMATION NUMBER',b_name.encode('utf-8'),str(b.type),b.amount,invoice.reference])
writer.writerow([created.strftime('%d/%m/%Y %H:%M:%S'),b.created.strftime('%d/%m/%Y'),str(b.type),b.amount,invoice.reference])
except Invoice.DoesNotExist:
pass

Expand Down
4 changes: 4 additions & 0 deletions ledgergw/serialisers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class SettlementReportSerializer(serializers.Serializer):
date_from = serializers.DateTimeField(input_formats=['%d/%m/%Y'])
date_to= serializers.DateTimeField(input_formats=['%d/%m/%Y'])

class ItemisedSettlementReportSerializer(serializers.Serializer):
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'])
override = serializers.BooleanField(default=False)
Expand Down
Loading

0 comments on commit 8790f0c

Please sign in to comment.