Skip to content

Commit

Permalink
Merge pull request #5038 from bcgov/test-AH-2878
Browse files Browse the repository at this point in the history
Ticket 2878. Invoice/Receipt naming adjusting and template adjustment.
  • Loading branch information
Aman-Hundal authored Feb 5, 2024
2 parents bb057f3 + c225a4e commit 171771b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Binary file not shown.
5 changes: 3 additions & 2 deletions request-management-api/request_api/resources/fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def put(request_id: int, payment_id: int):
@API.route('/foirequests/<int:request_id>/ministryrequest/<int:ministry_request_id>/payments/<int:payment_id>')
@API.route('/cfrfee/<int:request_id>/ministryrequest/<int:ministry_request_id>/payments/<int:payment_id>')
class Payment(Resource):

@staticmethod
@cross_origin(origins=allowedorigins())
def put(request_id: int, ministry_request_id: int, payment_id: int):
Expand All @@ -96,11 +95,13 @@ def put(request_id: int, ministry_request_id: int, payment_id: int):
fee: FeeService = FeeService(request_id=ministry_request_id, payment_id=payment_id)
response, parsed_args = fee.complete_payment(request_json)
if (response['status'] == 'PAID'):
latest_cfr = cfrfeeservice().getcfrfeehistory(ministry_request_id)[0]
previously_paid_amount = latest_cfr['feedata']['amountpaid'] if latest_cfr['feedata']['amountpaid'] is not None else "0.00"
amountpaid = float(parsed_args.get('trnAmount'))
cfrfeeservice().paycfrfee(ministry_request_id, amountpaid)
paymentservice().createpaymentversion(request_id, ministry_request_id, amountpaid)
data = requestservice().getrequestdetails(request_id, ministry_request_id)
paymentservice().createpaymentreceipt(request_id, ministry_request_id, data, parsed_args)
paymentservice().createpaymentreceipt(request_id, ministry_request_id, data, parsed_args, previously_paid_amount)
nextstatename, paymenteventtype = paymentservice().postpayment(ministry_request_id, data)
cfrfeeservice().updatepaymentmethod(ministry_request_id, paymenteventtype)
# automated state transition and due date calculation
Expand Down
9 changes: 6 additions & 3 deletions request-management-api/request_api/services/paymentservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ def getpaymentexpirydate(self, requestid, ministryrequestid):
return parse(str(paymentexpirydate)).strftime("%Y-%m-%d")
return ""

def createpaymentreceipt(self, request_id, ministry_request_id, data, parsed_args):
def createpaymentreceipt(self, request_id, ministry_request_id, data, parsed_args, previously_paid_amount):
try:
data['previous_amt_paid'] = previously_paid_amount
templatename = self.__getlatesttemplatename(ministry_request_id)
balancedue = float(data['cfrfee']['feedata']["balanceDue"])
prevstate = data["stateTransition"][1]["status"] if "stateTransition" in data and len(data["stateTransition"]) > 2 else None
basepath = 'request_api/receipt_templates/'
receiptname = 'cfr_fee_payment_receipt'
attachmentcategory = "FEE-ESTIMATE-PAYMENT-RECEIPT"
filename = "Fee Estimate Payment Receipt.pdf"
filename = f"Fee Estimate Payment Receipt {data['cfrfee']['created_at']}.pdf"
print(data)
if balancedue > 0:
receipt_template_path= basepath + self.getreceiptename('HALFPAYMENT') +".docx"
receiptname = self.getreceiptename('HALFPAYMENT')
Expand All @@ -101,7 +103,7 @@ def createpaymentreceipt(self, request_id, ministry_request_id, data, parsed_arg
if prevstate.lower() == "response" or (templatename and templatename == 'PAYOUTSTANDING'):
receiptname = self.getreceiptename('PAYOUTSTANDING')
attachmentcategory = "OUTSTANDING-PAYMENT-RECEIPT"
filename = "Fee Balance Outstanding Payment Receipt.pdf"
filename = f"Fee Balance Outstanding Payment Receipt {data['cfrfee']['created_at']}.pdf"
receipt_template_path= basepath + receiptname + ".docx"
data['waivedAmount'] = data['cfrfee']['feedata']['estimatedlocatinghrs'] * 30 if data['cfrfee']['feedata']['estimatedlocatinghrs'] < 3 else 90
data.update({'paymentInfo': {
Expand All @@ -110,6 +112,7 @@ def createpaymentreceipt(self, request_id, ministry_request_id, data, parsed_arg
'transactionId': parsed_args.get('pbcTxnNumber'),
'cardType': parsed_args.get('cardType')
}})
print(data)
document_service : DocumentGenerationService = DocumentGenerationService(receiptname)
receipt = document_service.generate_receipt(data,receipt_template_path)
document_service.upload_receipt(filename, receipt.content, ministry_request_id, data['bcgovcode'], data['idNumber'], attachmentcategory)
Expand Down

0 comments on commit 171771b

Please sign in to comment.