diff --git a/lib/NGCP/Panel/Controller/Invoice.pm b/lib/NGCP/Panel/Controller/Invoice.pm index 7c274dd53e..fd0adf28cb 100644 --- a/lib/NGCP/Panel/Controller/Invoice.pm +++ b/lib/NGCP/Panel/Controller/Invoice.pm @@ -219,7 +219,7 @@ sub create :Chained('inv_list') :PathPart('create') :Args() :Does(ACL) :ACLDetac delete $form->values->{period} )->truncate(to => 'month'); my $etime = $stime->clone->add(months => 1)->subtract(seconds => 1); - + #this has to be refactored - select a contract balance instead of a "period" my $balance = NGCP::Panel::Utils::ProfilePackages::get_contract_balance(c => $c, contract => $customer, @@ -228,7 +228,7 @@ sub create :Chained('inv_list') :PathPart('create') :Args() :Does(ACL) :ACLDetac $stime = $balance->start; $etime = $balance->end; my $bm_actual = NGCP::Panel::Utils::ProfilePackages::get_actual_billing_mapping(c => $c, contract => $customer, now => $balance->start); - my $billing_profile = $bm_actual->billing_mappings->first->billing_profile; + my $billing_profile = $bm_actual->billing_mappings->first->billing_profile; my $zonecalls = NGCP::Panel::Utils::Contract::get_contract_zonesfees( c => $c, @@ -245,7 +245,7 @@ sub create :Chained('inv_list') :PathPart('create') :Args() :Does(ACL) :ACLDetac stime => $stime, etime => $etime, ); - my $calllist = [ map { + my $calllist = [ map { my $call = {$_->get_inflated_columns}; $call->{start_time} = $call->{start_time}->epoch; $call->{source_customer_cost} += 0.0; # make sure it's a number @@ -281,7 +281,7 @@ sub create :Chained('inv_list') :PathPart('create') :Args() :Does(ACL) :ACLDetac # generate tmp serial here, derive one from after insert $form->values->{serial} = "tmp".time.int(rand(99999)); $form->values->{data} = undef; - + #maybe inflation should be applied? Generation failed here, although the latest schema applied. $form->values->{period_start} = $stime->ymd.' '. $stime->hms; $form->values->{period_end} = $etime->ymd.' '. $etime->hms; @@ -317,11 +317,12 @@ sub create :Chained('inv_list') :PathPart('create') :Args() :Does(ACL) :ACLDetac $vars->{rescontact} = { $customer->contact->reseller->contract->contact->get_inflated_columns }; $vars->{customer} = { $customer->get_inflated_columns }; $vars->{custcontact} = { $customer->contact->get_inflated_columns }; - + $vars->{billprof} = { $billing_profile->get_inflated_columns }; + + NGCP::Panel::Utils::Invoice::prepare_contact_data($vars->{billprof}); NGCP::Panel::Utils::Invoice::prepare_contact_data($vars->{custcontact}); NGCP::Panel::Utils::Invoice::prepare_contact_data($vars->{rescontact}); - - $vars->{billprof} = { $billing_profile->get_inflated_columns }; + $vars->{invoice} = { period_start => $stime, period_end => $etime, diff --git a/share/tools/generate_invoices.pl b/share/tools/generate_invoices.pl index 7e4c7151ea..d52c4b6677 100755 --- a/share/tools/generate_invoices.pl +++ b/share/tools/generate_invoices.pl @@ -417,6 +417,7 @@ sub generate_invoice_data{ my($contract_balance_data) = get_invoice_data_raw($client_contract, $stime, $etime,{count_contract_balance => 1}); ($contract_balance,$invoice) = get_contract_balance($client_contract,$billing_profile,$contract_balance,$contract_balance_data,$invoice,$stime,$etime); #$logger->debug( Dumper $contract_balance ); + NGCP::Panel::Utils::Invoice::prepare_contact_data($billing_profile); NGCP::Panel::Utils::Invoice::prepare_contact_data($client_contact); NGCP::Panel::Utils::Invoice::prepare_contact_data($provider_contact); #TODO: if not a full month, calculate fraction?