From 0202996756644f39fe82a87260ed6810258064f9 Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Thu, 29 Feb 2024 16:40:52 +0100 Subject: [PATCH] MT#59537 create_invoice() add existing balance check * if no balance is found for the provided period a 422 error is returned: showdetails => $c->loc('period start=[_1] end=[_2].', $stime, $etime), error => 'Could not find active balance.', httpcode => HTTP_UNPROCESSABLE_ENTITY, instead of a 500 server because of access to undefined $balance value Change-Id: Icccb9f253d117327641b6803ac0d2cdb09cf030f --- lib/NGCP/Panel/Utils/Invoice.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/NGCP/Panel/Utils/Invoice.pm b/lib/NGCP/Panel/Utils/Invoice.pm index ef6d047864..c1754d1b4b 100644 --- a/lib/NGCP/Panel/Utils/Invoice.pm +++ b/lib/NGCP/Panel/Utils/Invoice.pm @@ -73,6 +73,15 @@ sub create_invoice { contract => $contract, stime => $stime, etime => $etime,); + + unless ($balance) { + die { + showdetails => $c->loc('period start=[_1] end=[_2].', $stime, $etime), + error => 'Could not find active balance.', + httpcode => HTTP_UNPROCESSABLE_ENTITY, + }; + } + $stime = NGCP::Panel::Utils::DateTime::convert_tz($balance->start,undef,'UTC',$c); $etime = NGCP::Panel::Utils::DateTime::convert_tz($balance->end,undef,'UTC',$c); my $bm_actual = NGCP::Panel::Utils::BillingMappings::get_actual_billing_mapping( @@ -364,4 +373,4 @@ sub check_invoice_data{ } -1; \ No newline at end of file +1;