MT#5879 Error in not inflated date values.

But other seems as working.
mr3.3.1
Irina Peshinskaya 11 years ago
parent 17d98b9faa
commit c60c9af216

@ -277,27 +277,7 @@ sub get_content_ajax :Chained('base') :PathPart('editcontent/get/ajax') :Args(0)
my ($self, $c) = @_; my ($self, $c) = @_;
my $tmpl = $c->stash->{tmpl}; my $tmpl = $c->stash->{tmpl};
my $content; my $content = NGCP::Panel::Utils::InvoiceTemplate::svg_content($tmpl->data);
if($tmpl->data) {
$content = $tmpl->data;
} else {
my $default = 'invoice/default/invoice_template_svg.tt';
my $t = NGCP::Panel::Utils::InvoiceTemplate::get_tt();
try {
$content = $t->context->insert($default);
} catch($e) {
# TODO: handle error!
$c->log->error("failed to load default invoice template: $e");
return;
}
}
# some part of the chain doesn't like content being encoded as utf8 at that poing
# already; decode here, and umlauts etc will be fine througout the chain.
# TODO: doesn't work when loaded from db?
use utf8;
utf8::decode($content);
$c->response->content_type('text/html'); $c->response->content_type('text/html');
$c->response->body($content); $c->response->body($content);

@ -53,7 +53,9 @@ sub svg_pdf {
# when using 90dpi. # when using 90dpi.
# (it doesn't happen with inkscape, no idea what rsvg does) # (it doesn't happen with inkscape, no idea what rsvg does)
my @cmd_args = (qw/-a -f pdf -z 0.8/, @pagefiles); my @cmd_args = (qw/-a -f pdf -z 0.8/, @pagefiles);
$$pdf_ref = capturex([0], "/usr/bin/rsvg-convert", @cmd_args); my $cmd = '/usr/bin/rsvg-convert';
my $cmd_full = $cmd.' '.join(' ', @cmd_args);
$c and $c->log->debug( $cmd_full );
return 1; return 1;
} }
@ -92,7 +94,7 @@ sub sanitize_svg {
$node->getParentNode->removeChild($node); $node->getParentNode->removeChild($node);
} }
} }
#we do here nothing against TemplateToolkit code invasion - is it correct?
$$svg_ref = ($xp->findnodes('/'))[0]->toString(); $$svg_ref = ($xp->findnodes('/'))[0]->toString();
return 1; return 1;
} }
@ -114,6 +116,30 @@ sub get_tt {
return $tt; return $tt;
} }
sub svg_content{
my ($c, $content) = @_;
if(!$content) {
#default is the same for all - I would like to move it as something constant to itils
my $default = 'invoice/default/invoice_template_svg.tt';
my $t = NGCP::Panel::Utils::InvoiceTemplate::get_tt();
try {
$content = $t->context->insert($default);
} catch($e) {
# TODO: handle error!
$c and $c->log->error("failed to load default invoice template: $e");
return;
}
}
# some part of the chain doesn't like content being encoded as utf8 at that poing
# already; decode here, and umlauts etc will be fine througout the chain.
# TODO: doesn't work when loaded from db?
use utf8;
utf8::decode($content);
return $content;
}
sub process_child_nodes { sub process_child_nodes {
my ($node, $firsty, $y) = @_; my ($node, $firsty, $y) = @_;
for my $attr (qw/y y1 y2/) { for my $attr (qw/y y1 y2/) {

@ -103,10 +103,12 @@
MACRO timestamp2time BLOCK; MACRO timestamp2time BLOCK;
t = Math.int(timestamp); t = Math.int(timestamp);
h = Math.int(t / 3600); h = Math.int(t / 3600);
m = Math.int((t % 3600) / 60); m = Math.int((t % 3600) / 60);
s = Math.int((t % 3600) % 60); s = Math.int((t % 3600) % 60);
hs = String.new(h); hs = hs.format("%02d"); hs = String.new(h); hs = hs.format("%02d");
ms = String.new(m); ms = ms.format("%02d"); ms = String.new(m); ms = ms.format("%02d");
ss = String.new(s); ss = ss.format("%02d"); ss = String.new(s); ss = ss.format("%02d");
@ -116,6 +118,7 @@
MACRO money_format BLOCK; MACRO money_format BLOCK;
comma = comma || '.'; comma = comma || '.';
amount = amount ? amount : 0 ;
full = Math.int(amount / 100); full = Math.int(amount / 100);
cent = Math.int(amount % 100); cent = Math.int(amount % 100);
cents = String.new(cent); cents = cents.format("%02d"); cents = String.new(cent); cents = cents.format("%02d");

@ -28,7 +28,7 @@ use NGCP::Panel::Utils::DateTime;
use NGCP::Panel::Utils::Contract; use NGCP::Panel::Utils::Contract;
use NGCP::Panel::Utils::InvoiceTemplate; use NGCP::Panel::Utils::InvoiceTemplate;
use NGCP::Panel::Utils::Email; use NGCP::Panel::Utils::Email;
use NGCP::Panel::View::SVG; #use NGCP::Panel::View::SVG;
my $debug = 0; my $debug = 0;
@ -93,8 +93,9 @@ sub process_invoices{
print "reseller_id=".$provider_contract->{reseller_core_id}.";conatct_id=".$client_contact->{id}.";contract_id=".$client_contract->{id}.";\n"; print "reseller_id=".$provider_contract->{reseller_core_id}.";conatct_id=".$client_contact->{id}.";contract_id=".$client_contract->{id}.";\n";
if( my $billing_profile = get_billing_profile($client_contract, $stime, $etime) ){ if( my $billing_profile = get_billing_profile($client_contract, $stime, $etime) ){
my $invoice = generate_invoice_data($provider_contract,$provider_contact,$client_contract,$client_contact,$billing_profile, $stime, $etime); if(my $invoice = generate_invoice_data($provider_contract,$provider_contact,$client_contract,$client_contact,$billing_profile, $stime, $etime)){
push @{$invoices->{$client_contact->{id}}}, $invoice; push @{$invoices->{$client_contact->{id}}}, $invoice;
}
}else{#if billing profile }else{#if billing profile
print "No billing profile;\n" print "No billing profile;\n"
} }
@ -160,7 +161,7 @@ sub get_billing_profile{
sub get_invoice_data_raw{ sub get_invoice_data_raw{
my($client_contract, $stime, $etime) = @_; my($client_contract, $stime, $etime) = @_;
my $invoice_details_calls = $dbh->selectall_arrayref('select cdr.*,bzh.zone, bzh.detail as zone_detail my $invoice_details_calls = $dbh->selectall_arrayref('select cdr.*,from_unixtime(cdr.start_time) as start_time,bzh.zone, bzh.detail as zone_detail
from accounting.cdr from accounting.cdr
LEFT JOIN billing.billing_zones_history bzh ON bzh.id = cdr.source_customer_billing_zone_id LEFT JOIN billing.billing_zones_history bzh ON bzh.id = cdr.source_customer_billing_zone_id
where where
@ -202,55 +203,74 @@ sub get_invoice_data_raw{
sub generate_invoice_data{ sub generate_invoice_data{
my($provider_contract,$provider_contact,$client_contract,$client_contact,$billing_profile, $stime, $etime) = @_; my($provider_contract,$provider_contact,$client_contract,$client_contact,$billing_profile, $stime, $etime) = @_;
state ($c_mock,$view,$svg_default); state ($t,$svg_default);
if(!$c_mock){ if(!$t){
$c_mock = Test::MockObject->new(); $t = NGCP::Panel::Utils::InvoiceTemplate::get_tt();
$c_mock->set_false(qw/debug/); $svg_default = $t->context->insert('invoice/default/invoice_template_svg.tt');
$view = NGCP::Panel::View::SVG->new($c_mock,{}); NGCP::Panel::Utils::InvoiceTemplate::preprocess_svg(\$svg_default);
$svg_default = $view->getTemplateContent(undef,'invoice/invoice_template_svg.tt'); }
NGCP::Panel::Utils::InvoiceTemplate::preprocessInvoiceTemplateSvg( { no_fake_data => 1 }, \$svg_default); my $svg = $dbh->selectrow_array('select data from invoice_templates where type = "svg" and reseller_id=?',undef,$provider_contract->{reseller_core_id});#is_active = 1 and
if($svg){
NGCP::Panel::Utils::InvoiceTemplate::preprocess_svg(\$svg);
}else{
#$svg = $svg_default;
print "No saved active tempalate - no invoice;\n";
return;
} }
#my $zonecalls = NGCP::Panel::Utils::Contract::get_contract_zonesfees(
# c => $c,
# contract_id => $contract_id,
# stime => $stime,
# etime => $etime,
# in => 0,
# out => 1,
# group_by_detail => 1,
#);
my ($contract_balance,$invoice)=({},{}); my ($contract_balance,$invoice)=({},{});
($contract_balance,$invoice) = get_contract_balance($client_contract,$billing_profile,$contract_balance,$invoice,$stime,$etime); ($contract_balance,$invoice) = get_contract_balance($client_contract,$billing_profile,$contract_balance,$invoice,$stime,$etime);
$client_contact->{country_name} = country($client_contact->{country} || ''); $client_contact->{country_name} = country($client_contact->{country} || '');
my($stash) = get_invoice_data_raw($client_contract, $stime, $etime);
$stash = { # TODO: if not a full month, calculate fraction?
%$stash, #TODO: to utils::contract and share with catalyst version
provider => $provider_contact, $invoice = {
client => $client_contact, %$invoice,
invoice => $invoice, amount_net => $contract_balance->{cash_balance_interval} + $billing_profile->{interval_charge},
bp => $billing_profile, amount_vat => $client_contract->{add_vat}
}; ?
my ($in, $out); $invoice->{amount_net} * ($client_contract->{vat_rate}/100)
#tt_id used only as part in temporary directory : 0,
$in = { amount_total => $invoice->{amount_net} + $invoice->{amount_vat},
no_fake_data => 1, period_start => $stime,
provider_id => $provider_contract->{reseller_core_id}, period_end => $etime,
tt_type => 'svg',
tt_sourcestate => 'saved',
tt_id => $provider_contract->{reseller_core_id},
}; };
$out = { my($invoice_data) = get_invoice_data_raw($client_contract, $stime, $etime);
tt_id => $provider_contract->{reseller_core_id}, my $out = '';
my $pdf = '';
my $vars = {
rescontact => $provider_contact,
customer => $client_contract,
custcontact => $client_contact,
billprof => $billing_profile,
calls => $invoice_data->{invoice_details_calls},
zones => {
totalcost => $contract_balance->{cash_balance_interval},
data => $invoice_data->{invoice_details_zones},
},
}; };
my $svg = $dbh->selectrow_array('select base64_saved from invoice_templates where is_active = 1 and type = "svg" and reseller_id=?',undef,$provider_contract->{reseller_core_id}); print "QQ.1;\n";
if($svg){ #print "svg=$svg;\n";
NGCP::Panel::Utils::InvoiceTemplate::preprocessInvoiceTemplateSvg($in,\$svg); $out = $t->context->process(\$svg, $vars);
}else{ print "QQ.2;\n";
$svg = $svg_default; print "out=$out;\n";
} NGCP::Panel::Utils::InvoiceTemplate::svg_pdf(undef, \$out, \$pdf);
$svg = $view->getTemplateProcessed($c_mock,\$svg, $stash ); print "QQ.3;\n";
#print $svg;
#die(); $invoice->{data} = $pdf;
NGCP::Panel::Utils::InvoiceTemplate::convertSvg2Pdf(undef,\$svg,$in,$out);
#binmode(STDOUT);
#print $out->{tt_string_pdf};
#die;
$invoice->{data} = $out->{tt_string_pdf};
#set sent_date to null after each data regeneration #set sent_date to null after each data regeneration
$dbh->do('update invoices set data=?,sent_date=? where id=?',undef,$out->{tt_string_pdf},undef,$invoice->{id}); $dbh->do('update invoices set sent_date=?,data=?,amount_net,amount_vat,amount_total where id=?',undef,undef,@$invoice->{qw/data amount_net amount_vat amount_total id/});
return $invoice; return $invoice;
} }
sub get_contract_balance{ sub get_contract_balance{
@ -276,7 +296,7 @@ sub create_invoice{
#my $invoice_serial = $dbh->selectrow_array('select max(invoices.serial) from invoices inner join contract_balances on invoices.id=contract_balances.invoice_id where contract_balances.contract_id=?',undef,$contract_id ); #my $invoice_serial = $dbh->selectrow_array('select max(invoices.serial) from invoices inner join contract_balances on invoices.id=contract_balances.invoice_id where contract_balances.contract_id=?',undef,$contract_id );
my $invoice_serial = $dbh->selectrow_array('select max(invoices.serial) from invoices'); my $invoice_serial = $dbh->selectrow_array('select max(invoices.serial) from invoices');
$invoice_serial += 1; $invoice_serial += 1;
$dbh->do('insert into invoices(year,month,serial)values(?,?,?)', undef, $stime->year, $stime->month,$invoice_serial ); $dbh->do('insert into invoices(contract_id,period_start,period_end,serial)values(?,?,?,?)', undef, $contract_id,$stime->ymd, $stime->ymd,$invoice_serial );
my $invoice_id = $dbh->last_insert_id(undef,'billing','invoices','id'); my $invoice_id = $dbh->last_insert_id(undef,'billing','invoices','id');
$dbh->do('update contract_balances set invoice_id = ? where contract_id=? and start=? and end=?', undef, $invoice_id,$contract_id, $stime->datetime, $etime->datetime ); $dbh->do('update contract_balances set invoice_id = ? where contract_id=? and start=? and end=?', undef, $invoice_id,$contract_id, $stime->datetime, $etime->datetime );
return $dbh->selectrow_hashref('select * from invoices where id=?',undef, $invoice_id); return $dbh->selectrow_hashref('select * from invoices where id=?',undef, $invoice_id);
@ -310,24 +330,24 @@ sub email{
if(@$client_invoices < 1 ){ if(@$client_invoices < 1 ){
return; return;
} }
state $transport_default; #state $transport_default;
$transport_default ||= Email::Sender::Transport::SMTP->new({ #$transport_default ||= Email::Sender::Transport::SMTP->new({
sasl_username => 'ipeshinskaya', # sasl_username => 'ipeshinskaya',
#
#host => 'mail.sipwise.com', # #host => 'mail.sipwise.com',
#port => 587, # #port => 587,
#sasl_password => '', # #sasl_password => '',
#ssl => 0, # #ssl => 0,
#
host => 'smtp.googlemail.com', # host => 'smtp.googlemail.com',
port => 465, # port => 465,
ssl => 1, # ssl => 1,
sasl_password => 'ntjljhbyf0307', # sasl_password => '',
}); #});
#
my $transport; #my $transport;
$transport_in and $transport = $transport_in; #$transport_in and $transport = $transport_in;
$transport ||= $transport_default; #$transport ||= $transport_default;
#print Dumper $transport; #print Dumper $transport;

Loading…
Cancel
Save