diff --git a/lib/NGCP/Panel/Controller/Invoice.pm b/lib/NGCP/Panel/Controller/Invoice.pm index b9f0b5c9de..500721231e 100644 --- a/lib/NGCP/Panel/Controller/Invoice.pm +++ b/lib/NGCP/Panel/Controller/Invoice.pm @@ -156,6 +156,7 @@ sub invoice_list :Chained('invoice_details_calls') :PathPart('list') :Args(0) { my ($self, $c) = @_; my $backend = NGCP::Panel::Model::DB::InvoiceTemplate->new( schema => $c->model('DB') ); $c->forward( 'template_list_data' ); + my $provider_id = $c->stash->{provider}->id; $c->stash( client_contacts_list => $backend->getInvoiceProviderClients( provider_id => $provider_id ), template => 'invoice/list.tt', @@ -167,7 +168,6 @@ sub template_base :Chained('base') :PathPart('template') :CaptureArgs(0) { my($validator,$backend,$in,$out); $backend = NGCP::Panel::Model::DB::InvoiceTemplate->new( schema => $c->model('DB') ); $c->log->debug('template_base'); - $c->forward( 'template_list_data' ); #my $client_id = $c->stash->{client} ? $c->stash->{client}->id : undef ; #my $client; #if($client_id){ @@ -383,12 +383,14 @@ sub template_list_data :Chained('base') :PathPart('') :CaptureArgs(0) { sub template_list :Chained('template_base') :PathPart('list') :Args(0) { my ($self, $c) = @_; $c->log->debug('template_list'); + $c->forward( 'template_list_data' ); $c->stash( template => 'invoice/template_list.tt' ); $c->detach($c->view('SVG'));#just no wrapper - maybe there is some other way? } sub template :Chained('template_base') :PathPart('') :Args(0) { my ($self, $c) = @_; + $c->forward('invoice_list'); $c->stash(template => 'invoice/template.tt'); } @@ -399,6 +401,12 @@ sub template_view :Chained('template_base') :PathPart('view') :Args { my($validator,$backend,$in,$out); +#fake data + $c->forward('invoice_details_calls'); + $c->forward('invoice_details_zones'); + #invoice number and data + #client info + #input (undef,undef,@$in{qw/tt_type tt_viewmode tt_sourcestate tt_output_type tt_id/}) = @_ ; $in->{provider_id} = $c->stash->{provider}->id; diff --git a/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm b/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm index 79e74625c6..165fc96cf6 100644 --- a/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm +++ b/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm @@ -274,14 +274,13 @@ sub getInvoiceProviderClients{ #very optimistic programming style - #return NGCP::Panel::Utils::Contract::get_contract_rs( - # schema => $self->schema, - # )->search_rs({ - # 'contact.reseller_id' => $provider_id, - # },{ - # join => 'contact', - #}); - return $self->schema->resultset('contacts')->search_rs({},{}); + return NGCP::Panel::Utils::Contract::get_contract_rs( + schema => $self->schema, + )->search_rs({ + 'contact.reseller_id' => $provider_id, + },{ + join => 'contact', + }); } sub get_contract_calls_rs{ @@ -291,26 +290,51 @@ sub get_contract_calls_rs{ my $source_account_id_condition; if(!$client_id){ $source_account_id_condition = { 'in' => $self->getInvoiceProviderClients(%params)->search_rs({},{ - 'select' => 'me.id', - })->as_query() }; + 'select' => 'me.id', + })->as_query() + #$self->schema('contracts')->search_rs({},{ + # 'select' => 'me.id', + # 'join' => 'contact', + #})->as_query() + }; }else{ $source_account_id_condition = $client_id; } - my $zonecalls_rs = $self->schema->resultset('cdr')->search( { + $sql = ' + select cdr.* from accounting.cdr + inner join contracts on cdr.source_account_id=contracts.id + and contracts.status != "terminated" + inner join contacts on contracts.contact_id=contacts.id + and contacts.reseller_id=1 and contacts.reseller_id!=contacts.id + where + cdr.source_user_id != 0 + and cdr.call_status="ok" + and exists (select * + from billing_mappings + inner join products on billing_mappings.product_id=products.id and products.class in("sipaccount","pbxaccount") + where contracts.id=billing_mappings.contract_id + and (billing_mappings.start_date >= now() OR start_date IS NULL) + and (billing_mappings.end_date <= now() OR end_date IS NULL) + ) + order by cdr.start_time + '; + my $calls_rs = $self->schema->resultset('cdr')->search( { # source_user_id => { 'in' => [ map {$_->uuid} @{$contract->{subscriber}} ] }, - call_status => 'ok', - source_user_id => { '!=' => '0' }, - - #source_account_id => $source_account_id_condition, - #-or => [ - # source_user_id => voip_subscribers.uuid, - # destination_user_id => voip_subscribers.uuid, - #], - #start_time => - # [ -and => - # { '>=' => $stime->epoch}, - # { '<=' => $etime->epoch}, - # ], + 'call_status' => 'ok', + 'source_user_id' => { '!=' => '0' }, + 'contact.id' => { '!=' => $provider_id }, + '-and' => [ + #'contact.reseller_id' => $provider_id, + 'contact.reseller_id' => { '!=' => undef }, + ], + 'source_account.status' => { '!=' => 'terminated'}, + '-exists' => $self->schema->resultset('billing_mappings')->search({ + 'contract_id' => \'= source_account.id', + 'product.class' => [ "sipaccount", "pbxaccount" ], + },{ + alias => 'billing_mappings_top', + join => 'product', + })->as_query, },{ '+select' => [ 'source_customer_billing_zones_history.zone', @@ -318,11 +342,15 @@ sub get_contract_calls_rs{ 'destination_user_in', ], '+as' => [qw/zone zone_detail destination/], - 'join' => ['source_customer_billing_zones_history','contracts'], - 'rows' => 37, + 'join' => [ + { + 'source_account' => 'contact', + }, + 'source_customer_billing_zones_history', + ] } ); - return $zonecalls_rs; + return $calls_rs; } sub get_contract_zonesfees_rs { my $self = shift; @@ -351,7 +379,8 @@ sub get_contract_zonesfees_rs { # source_user_id => { 'in' => [ map {$_->uuid} @{$contract->{subscriber}} ] }, call_status => 'ok', source_user_id => { '!=' => '0' }, - source_account_id => $source_account_id_condition, + #source_account_id => $source_account_id_condition, + # start_time => # [ -and => # { '>=' => $stime->epoch}, diff --git a/share/templates/invoice/invoice_template_aux.tt b/share/templates/invoice/invoice_template_aux.tt index dd9f489a7c..5383292472 100644 --- a/share/templates/invoice/invoice_template_aux.tt +++ b/share/templates/invoice/invoice_template_aux.tt @@ -195,8 +195,8 @@ [%END-%] [%END-%] - [% total.pagetype.zone.global.import(total.global)%] - [% total.pagetype.zone.perpage.import(total.perpage)%] + [%# total.pagetype.zone.global.import(total.global)%] + [%# total.pagetype.zone.perpage.import(total.perpage)%] [% total.global = {}%] [% total.perpage = [] %] @@ -221,6 +221,6 @@ [% document_footer()%] [%END-%] [%END-%] - [% total.pagetype.call.global.import(total.global)%] - [% total.pagetype.call.perpage.import(total.perpage)%] + [% total.pagetype.call.global = total.pagetype.call.global.import(total.global)%] + [% total.pagetype.call.perpage = total.pagetype.call.perpage.import(total.perpage)%] [%END-%]