|
|
|
@ -263,21 +263,68 @@ sub invoice_generate :Chained('base') :PathPart('generate') :Args(0) {
|
|
|
|
item => $out->{invoice_data},
|
|
|
|
item => $out->{invoice_data},
|
|
|
|
#item => $out->{invoice_data},
|
|
|
|
#item => $out->{invoice_data},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
use irka;
|
|
|
|
|
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
irka::loglong(Dumper($in));
|
|
|
|
|
|
|
|
my $in_validated = $validator->fif;
|
|
|
|
my $in_validated = $validator->fif;
|
|
|
|
if($posted){
|
|
|
|
if($posted){
|
|
|
|
$c->log->debug("validated=".$validator->validated.";");
|
|
|
|
$c->log->debug("validated=".$validator->validated.";");
|
|
|
|
if(1 || $validator->validated) {
|
|
|
|
if($validator->validated) {
|
|
|
|
#copy/pasted from NGCP\Panel\Role\API\Customers.pm
|
|
|
|
#copy/pasted from NGCP\Panel\Role\API\Customers.pm
|
|
|
|
use irka;
|
|
|
|
|
|
|
|
use Data::Dumper;
|
|
|
|
#use irka;
|
|
|
|
irka::loglong(Dumper($in));
|
|
|
|
#use Data::Dumper;
|
|
|
|
|
|
|
|
#irka::loglong(Dumper($in));
|
|
|
|
|
|
|
|
|
|
|
|
#$c->log->debug('getInvoice:contract_id='.Dumper($in).';');
|
|
|
|
#$c->log->debug('getInvoice:contract_id='.Dumper($in).';');
|
|
|
|
|
|
|
|
$c->forward('generate_invoice',[$in, $out]);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
#$backend->storeInvoiceTemplateInfo(%$in_validated);
|
|
|
|
|
|
|
|
$c->flash(messages => [{type => 'success', text => $c->loc(
|
|
|
|
|
|
|
|
$in->{invoice_id}
|
|
|
|
|
|
|
|
?'Invoice template updated'
|
|
|
|
|
|
|
|
:'Invoice template created'
|
|
|
|
|
|
|
|
) }]);
|
|
|
|
|
|
|
|
} catch($e) {
|
|
|
|
|
|
|
|
NGCP::Panel::Utils::Message->error(
|
|
|
|
|
|
|
|
c => $c,
|
|
|
|
|
|
|
|
error => $e,
|
|
|
|
|
|
|
|
desc => $c->loc(
|
|
|
|
|
|
|
|
'Failed to generate invoice.'
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$c->stash( messages => $c->flash->{messages} );
|
|
|
|
|
|
|
|
$c->stash( template => 'helpers/ajax_messages.tt' );
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
#$c->stash( m => {create_flag => !$in->{invoice_id}} );
|
|
|
|
|
|
|
|
#$c->stash( form => $validator );
|
|
|
|
|
|
|
|
##$c->stash( template => 'helpers/ajax_form_modal.tt' );
|
|
|
|
|
|
|
|
#$c->stash( template => 'invoice/template_info_form.tt' );
|
|
|
|
|
|
|
|
$c->response->headers->header( 'X-Form-Status' => 'error' );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$validator->validated){
|
|
|
|
|
|
|
|
#$c->stash( in => $in );
|
|
|
|
|
|
|
|
#$c->stash( out => $out );
|
|
|
|
|
|
|
|
$c->stash( m => {create_flag => !$in->{invoice_id}} );
|
|
|
|
|
|
|
|
$c->stash( form => $validator );
|
|
|
|
|
|
|
|
#$c->stash( template => 'helpers/ajax_form_modal.tt' );
|
|
|
|
|
|
|
|
$c->stash( template => 'invoice/invoice_generate_form.tt' );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$c->detach( $c->view("SVG") );#to the sake of nowrapper
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#absolutely Model method
|
|
|
|
|
|
|
|
sub generate_invoice :Private{
|
|
|
|
|
|
|
|
my ($self, $c, $in, $out) = @_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $backend = NGCP::Panel::Model::DB::InvoiceTemplate->new( schema => $c->model('DB') );
|
|
|
|
|
|
|
|
$c->log->debug('generate_invoice;');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $provider = $c->stash->{provider};
|
|
|
|
|
|
|
|
#$Data::Dumper::Maxdepth = 1;
|
|
|
|
|
|
|
|
|
|
|
|
my $client_contract = $backend->getContractInfo('contract_id' => $in->{client_contract_id});
|
|
|
|
my $client_contract = $backend->getContractInfo('contract_id' => $in->{client_contract_id});
|
|
|
|
my $client_contact = $backend->getContactInfo('contact_id' => $client_contract->get_column('contact_id') );
|
|
|
|
my $client_contact = $backend->getContactInfo('contact_id' => $client_contract->get_column('contact_id') );
|
|
|
|
my $provider_contract = $backend->getContractInfo('contract_id' => $c->stash->{provider}->contract_id);
|
|
|
|
my $provider_contract = $backend->getContractInfo('contract_id' => $provider->get_column('contract_id') );
|
|
|
|
my $provider_contact = $backend->getContactInfo('contact_id' => $provider_contract->get_column('id'));
|
|
|
|
my $provider_contact = $backend->getContactInfo('contact_id' => $provider_contract->get_column('id'));
|
|
|
|
my $contract_balance = $backend->getContractBalance($in);
|
|
|
|
my $contract_balance = $backend->getContractBalance($in);
|
|
|
|
#$c->log->debug("customer->id="..";");
|
|
|
|
#$c->log->debug("customer->id="..";");
|
|
|
|
@ -296,7 +343,6 @@ sub invoice_generate :Chained('base') :PathPart('generate') :Args(0) {
|
|
|
|
if($contract_balance->get_column('invoice_id')){
|
|
|
|
if($contract_balance->get_column('invoice_id')){
|
|
|
|
$invoice = $backend->getInvoice('invoice_id' => $contract_balance->get_column('invoice_id') );
|
|
|
|
$invoice = $backend->getInvoice('invoice_id' => $contract_balance->get_column('invoice_id') );
|
|
|
|
#$c->log->debug('getInvoice:invoice.id='.$invoice->get_column('id').';');
|
|
|
|
#$c->log->debug('getInvoice:invoice.id='.$invoice->get_column('id').';');
|
|
|
|
$c->log->debug('getInvoice:invoice.id='.$contract_balance->get_column('invoice_id').';');
|
|
|
|
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
$invoice = $backend->createInvoice(
|
|
|
|
$invoice = $backend->createInvoice(
|
|
|
|
'contract_balance' => $contract_balance,
|
|
|
|
'contract_balance' => $contract_balance,
|
|
|
|
@ -313,11 +359,11 @@ sub invoice_generate :Chained('base') :PathPart('generate') :Args(0) {
|
|
|
|
no_fake_data => 1,
|
|
|
|
no_fake_data => 1,
|
|
|
|
tt_type => 'svg',
|
|
|
|
tt_type => 'svg',
|
|
|
|
tt_sourcestate => 'saved',
|
|
|
|
tt_sourcestate => 'saved',
|
|
|
|
tt_id => $c->stash->{provider}->id,
|
|
|
|
tt_id => $in->{provider_id},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
$out = {
|
|
|
|
$out = {
|
|
|
|
%$out,
|
|
|
|
%$out,
|
|
|
|
tt_id => $c->stash->{provider}->id,
|
|
|
|
tt_id => $in->{provider_id},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
my $stash = {
|
|
|
|
my $stash = {
|
|
|
|
provider => $provider_contact,
|
|
|
|
provider => $provider_contact,
|
|
|
|
@ -327,7 +373,7 @@ sub invoice_generate :Chained('base') :PathPart('generate') :Args(0) {
|
|
|
|
invoice_details_calls => $c->stash->{invoice_details_calls},
|
|
|
|
invoice_details_calls => $c->stash->{invoice_details_calls},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
my $svg = '';
|
|
|
|
my $svg = '';
|
|
|
|
$backend->getInvoiceTemplate( %$in, result => \$svg );#provider_id in i is enough
|
|
|
|
$backend->getInvoiceTemplate( %$in, result => \$svg );#provider_id in $in is enough
|
|
|
|
if(!$svg){
|
|
|
|
if(!$svg){
|
|
|
|
NGCP::Panel::Utils::InvoiceTemplate::getDefaultInvoiceTemplate( c => $c, type => 'svg', result => \$svg );
|
|
|
|
NGCP::Panel::Utils::InvoiceTemplate::getDefaultInvoiceTemplate( c => $c, type => 'svg', result => \$svg );
|
|
|
|
NGCP::Panel::Utils::InvoiceTemplate::preprocessInvoiceTemplateSvg( {no_fake_data => 1}, \$svg);
|
|
|
|
NGCP::Panel::Utils::InvoiceTemplate::preprocessInvoiceTemplateSvg( {no_fake_data => 1}, \$svg);
|
|
|
|
@ -335,47 +381,8 @@ sub invoice_generate :Chained('base') :PathPart('generate') :Args(0) {
|
|
|
|
$svg = $c->view('SVG')->getTemplateProcessed($c,\$svg, $stash );
|
|
|
|
$svg = $c->view('SVG')->getTemplateProcessed($c,\$svg, $stash );
|
|
|
|
NGCP::Panel::Utils::InvoiceTemplate::convertSvg2Pdf($c,\$svg,$in,$out);
|
|
|
|
NGCP::Panel::Utils::InvoiceTemplate::convertSvg2Pdf($c,\$svg,$in,$out);
|
|
|
|
$backend->storeInvoiceData('invoice'=>$invoice,'data'=>\$out->{tt_string_pdf});
|
|
|
|
$backend->storeInvoiceData('invoice'=>$invoice,'data'=>\$out->{tt_string_pdf});
|
|
|
|
try {
|
|
|
|
|
|
|
|
#$backend->storeInvoiceTemplateInfo(%$in_validated);
|
|
|
|
|
|
|
|
$c->flash(messages => [{type => 'success', text => $c->loc(
|
|
|
|
|
|
|
|
$in->{invoice_id}
|
|
|
|
|
|
|
|
?'Invoice template updated'
|
|
|
|
|
|
|
|
:'Invoice template created'
|
|
|
|
|
|
|
|
) }]);
|
|
|
|
|
|
|
|
} catch($e) {
|
|
|
|
|
|
|
|
NGCP::Panel::Utils::Message->error(
|
|
|
|
|
|
|
|
c => $c,
|
|
|
|
|
|
|
|
error => $e,
|
|
|
|
|
|
|
|
desc => $c->loc(
|
|
|
|
|
|
|
|
$in->{invoice_id}
|
|
|
|
|
|
|
|
?'Failed to update invoice template.'
|
|
|
|
|
|
|
|
:'Failed to create invoice template.'
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$c->stash( messages => $c->flash->{messages} );
|
|
|
|
|
|
|
|
$c->stash( template => 'helpers/ajax_messages.tt' );
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
#$c->stash( m => {create_flag => !$in->{invoice_id}} );
|
|
|
|
|
|
|
|
#$c->stash( form => $validator );
|
|
|
|
|
|
|
|
##$c->stash( template => 'helpers/ajax_form_modal.tt' );
|
|
|
|
|
|
|
|
#$c->stash( template => 'invoice/template_info_form.tt' );
|
|
|
|
|
|
|
|
$c->response->headers->header( 'X-Form-Status' => 'error' );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$validator->validated){
|
|
|
|
|
|
|
|
#$c->stash( in => $in );
|
|
|
|
|
|
|
|
#$c->stash( out => $out );
|
|
|
|
|
|
|
|
$c->stash( m => {create_flag => !$in->{invoice_id}} );
|
|
|
|
|
|
|
|
$c->stash( form => $validator );
|
|
|
|
|
|
|
|
#$c->stash( template => 'helpers/ajax_form_modal.tt' );
|
|
|
|
|
|
|
|
$c->stash( template => 'invoice/invoice_generate_form.tt' );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$c->detach( $c->view("SVG") );#to the sake of nowrapper
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub template_base :Chained('base') :PathPart('template') :CaptureArgs(0) {
|
|
|
|
sub template_base :Chained('base') :PathPart('template') :CaptureArgs(0) {
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
my($validator,$backend,$in,$out);
|
|
|
|
my($validator,$backend,$in,$out);
|
|
|
|
|