MT#5879 Put PDF to DB.

ipeshinskaya/InvoiceTemplate5
Irina Peshinskaya 11 years ago committed by Victor Seva
parent d5c2b33a0c
commit bde7cc02e6

@ -18,13 +18,13 @@ sub epoch_local {
);
}
sub from_string {
my $s = shift;
# just for convenience, if date is passed like xxxx-xx-xx xx:xx:xx,
# convert it to xxxx-xx-xxTxx:xx:xx
$s =~ s/^(\d{4}\-\d{2}\-\d{2})\s+(\d.+)$/$1T$2/;
my $ts = DateTime::Format::ISO8601->parse_datetime($s);
return $ts;
sub new_local {
my %params;
@params{qw/year month day hour minute second nanosecond/} = @_;
return DateTime->new(
time_zone => DateTime::TimeZone->new(name => 'local'),
%params,
);
}
1;

@ -7,6 +7,17 @@
[%date.format(dateval,'%B')%] [%ordinate(date.format(dateval,'%e'))%] [%IF !noyear; date.format(dateval,'%Y'); END%]
[%END%]
[%
dateval.value = date.now();
dateval.month_end = date_format('00:00:00 00-' _ (Math.int(date.format(dateval.value,'%m')) + 1) _ date.format(dateval.value,'-%Y'), noyear = 1 );
dateval.month_start = date_format('00:00:00 01-' _ date.format(dateval.value,'%m-%Y'), noyear = 1 );
dateval.year=date.format(dateval.value,'%Y');
invoice.serial=Math.int(invoice.serial)|format('%06d');
invoice.month=date.format(invoice.start,'%B');
%]
[%MACRO ordinate(num) BLOCK -%]
[% IF num.search('(?<!1)1$') -%]
[% sfx = 'st' -%]
@ -27,6 +38,13 @@
[%END%]
[%END%]
[%MACRO ife(value,suffix) BLOCK -%]
[%value_clear = value.replace('[ ,]','')%]
[% IF value_clear -%]
[% value _ suffix -%]
[%END%]
[%END%]
[%MACRO get_page(pagetype) BLOCK -%]
[%#use this macro until no symbolic references in tt %]
[%#data can be empty, if we just need y - it doesn't depend on data %]
@ -79,11 +97,11 @@
[% total.global.number = total.global.number + calldata.get_column('number') -%]
[% total.global.duration = total.global.duration + calldata.get_column('duration') -%]
[% total.global.free_time = total.global.free_time + calldata.get_column('free_time') -%]
[% total.global.cost = total.global.cost + calldata.get_column('cost') -%]
[% total.global.cost = total.global.cost + ( Math.int(calldata.get_column('cost')) / 100 ) -%]
[% total.perpage.${pagelocal}.number = total.perpage.${pagelocal}.number + calldata.get_column('number') -%]
[% total.perpage.${pagelocal}.duration = total.perpage.${pagelocal}.duration + calldata.get_column('duration') -%]
[% total.perpage.${pagelocal}.free_time = total.perpage.${pagelocal}.free_time + calldata.get_column('free_time') -%]
[% total.perpage.${pagelocal}.cost = total.perpage.${pagelocal}.cost + calldata.get_column('cost') -%]
[% total.perpage.${pagelocal}.cost = total.perpage.${pagelocal}.cost + ( Math.int(calldata.get_column('cost')) / 100) -%]
[% adjustrow(call, page, pagelocal, pageslocalnum, rowtype, tt_type, rows_interval, loop.count) -%]
[%END -%]
[%END -%]
@ -92,9 +110,9 @@
[% FOR call IN callsdata -%][%#invoice_details%]
[%IF call.1; calldata = call.1; END%]
[% total.global.duration = total.global.duration + calldata.get_column('duration') -%]
[% total.global.cost = total.global.cost + calldata.get_column('source_customer_cost') -%]
[% total.global.cost = total.global.cost + ( Math.int(calldata.get_column('source_customer_cost')) / 100 ) -%]
[% total.perpage.${pagelocal}.duration = total.perpage.${pagelocal}.duration + calldata.get_column('duration') -%]
[% total.perpage.${pagelocal}.cost = total.perpage.${pagelocal}.cost + calldata.get_column('source_customer_cost') -%]
[% total.perpage.${pagelocal}.cost = total.perpage.${pagelocal}.cost + ( Math.int(calldata.get_column('source_customer_cost')) / 100 ) -%]
[% adjustrow(call, page, pagelocal, pageslocalnum, rowtype, tt_type, rows_interval, loop.count) -%]
[%END -%]
[%END -%]
@ -180,9 +198,13 @@
[% output = output _ document_footer()%]
[%END-%]
[%END-%]
[%#Dumper.dump(total)%]
[% total.pagetype.call.global = total.pagetype.call.global.import(total.global)%]
[% total.pagetype.call.perpage = total.pagetype.call.perpage.import(total.perpage)%]
[% total.pagetype.call.global.import(total.global)%]
[%# total.pagetype.call.perpage.import(total.perpage)%]
[%#Dumper.dump(total)%]
[% total.global = {}%]
[% total.perpage = [] %]
@ -208,9 +230,16 @@
[%END-%]
[%END-%]
[% total.pagetype.call.global = total.pagetype.call.global.import(total.global)%]
[% total.pagetype.call.perpage = total.pagetype.call.perpage.import(total.perpage)%]
[%# Dumper.dump(total)%]
[% total.pagetype.zone.global.import(total.global)%]
[%# total.pagetype.zone.perpage = total.pagetype.zone.perpage.import(total.perpage)%]
[%DEFAULT invoice.amount_netto = total.pagetype.call.global.cost + total.pagetype.zone.global.cost %]
[%DEFAULT invoice.amount_vat = invoice.amount_netto * 0.2 %]
[%DEFAULT invoice.amount = invoice.amount_netto + invoice.amount_vat %]
[%DEFAULT invoice.amount_payment = invoice.amount - invoice.debit %]
[%IF ( pagetype == 'title' || pagetype=='all') %]
[% pagenum = 1%]
[% output_title = output_title _ document_header()%]

@ -2,17 +2,13 @@
USE Date;
USE Math;
DEFAULT date.month_end = date_format('00:00:00 00-' _ (Math.int(date.format(date.now(),'%m')) + 1) _ date.format(date.now(),'-%Y'), noyear = 1 );
DEFAULT date.month_start = date_format('00:00:00 01-' _ date.format(date.now(),'%m-%Y'), noyear = 1 );
DEFAULT date.year=date.format(date.now(),'%Y');
IF !invoice.number;
IF !invoice.serial;
DEFAULT invoice.amount='1200';
DEFAULT invoice.amount_netto='1000';
DEFAULT invoice.amount_payment='650';
DEFAULT invoice.amount_vat='200';
DEFAULT invoice.cloud_pbx_amount='921';
DEFAULT invoice.date.month=date.format(date.now(),'%B');
DEFAULT invoice.month=date.format(date.now(),'%B');
DEFAULT invoice.debit='500';
DEFAULT invoice.discount_service='10';
DEFAULT invoice.discount_wire_transfer='40';
@ -22,23 +18,30 @@ DEFAULT invoice.voice_termination_fees='10';
END;
IF !provider;
DEFAULT provider.bic='ABCDEFG1234';
DEFAULT provider.city='Provider City';
DEFAULT provider.company='Provider Gmbh.';
DEFAULT provider.country='Provider-Country';
DEFAULT provider.email='office@provider.com';
DEFAULT provider.fax='+1 650 1234566';
DEFAULT provider.fn='305595';
DEFAULT provider.iban='1234567890ABC';
DEFAULT provider.mobile='+1 650 1234568';
DEFAULT provider.phone='+1 650 1234567';
DEFAULT provider.postcode='65104';
DEFAULT provider.street='Provider Street';
DEFAULT provider.url='http://www.provider.com/';
DEFAULT provider.vat='UATAA1234AA1234';
DEFAULT provider.bic='ABCDEFG1234';
DEFAULT provider.city='Provider City';
DEFAULT provider.company='Provider Gmbh.';
DEFAULT provider.country='Provider-Country';
DEFAULT provider.email='office@provider.com';
DEFAULT provider.fax='+1 650 1234566';
DEFAULT provider.fn='305595';
DEFAULT provider.iban='1234567890ABC';
DEFAULT provider.mobile='+1 650 1234568';
DEFAULT provider.phone='+1 650 1234567';
DEFAULT provider.postcode='65104';
DEFAULT provider.street='Provider Street';
DEFAULT provider.url='http://www.provider.com/';
DEFAULT provider.vat='UATAA1234AA1234';
ELSE;
FOREACH i in ['bic','city','company','country','email','fax','fn','iban','mobile','phone','postcode','street','url','vat'];
provider.${i} = provider.get_column($i);
TRY;
provider.${i} = provider.get_column(i);
CATCH;
provider.${i} = 'Provider' _ ucfirst(i);
END;
#IF !provider.${i};
provider.${i} = 'Provider' _ ucfirst(i);
#END;
END;
END;

@ -2,7 +2,6 @@
<!--{[%PROCESS 'invoice/invoice_template_lorem.tt' -%]}-->
<!--{[%money_format = format('%.2f') %]}-->
<!--{[%row_vertical_interval = 10 -%]}-->
<!--{[%MACRO document_header BLOCK-%]}-->
<svg width="215mm" height="297mm" viewBox="0 0 215 297" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:space="preserve" stroke-width="0" stroke="#000000" fill="#000000" font-size="4pt" text-anchor="start">
@ -54,7 +53,7 @@ g, text, tspan {
<text x="190" y="55" id="titlepage_clientinfo__accountid" class="h3" text-anchor="end">Account ID: [%client.id%]</text>
<text x="190" y="65" id="titlepage_clientinfo__vatid" class="h3" text-anchor="end">VAT ID: [%client.vatid%]</text>
<text x="190" y="75" id="titlepage_invoiceinfo__date" class="h3" text-anchor="end">[%provider.city%], [%date_format(date.now)%]</text>
<text x="190" y="75" id="titlepage_invoiceinfo__date" class="h3" text-anchor="end">[%ife(provider.city,', ')%] [%date_format(date.now)%]</text>
<text x="20" y="95" font-weight="bold" class="h1">Invoice [%invoice.serial%]</text>
@ -67,11 +66,11 @@ g, text, tspan {
<text x="195" y="130" text-anchor="end">[%money_format(invoice.discount_wire_transfer)%]</text>
<text x="15" y="140">Service Allowance</text>
<text x="195" y="140" text-anchor="end">[%money_format(invoice.serviceallowance)%]</text>
<text x="15" y="150">Cloud PBX Account [%date.month_start%] - [%date.month_end%] [%date.year%]</text>
<text x="15" y="150">Cloud PBX Account [%dateval.month_start%] - [%dateval.month_end%] [%dateval.year%]</text>
<text x="195" y="150" text-anchor="end">[%money_format(invoice.cloud_pbx_amount)%]</text>
<text x="15" y="160">Discount (12M reduced Service Fee)</text>
<text x="195" y="160" text-anchor="end">[%money_format(invoice.discount_service)%]</text>
<text x="15" y="170">Voice Termination Fees [%date.month_start%] - [%date.month_end%] [%date.year%]</text>
<text x="15" y="170">Voice Termination Fees [%dateval.month_start%] - [%dateval.month_end%] [%dateval.year%]</text>
<text x="195" y="170" text-anchor="end">[%money_format(invoice.voice_termination_fees)%]</text>
<text x="45" y="190">Sum EUR (net):</text>
@ -85,7 +84,7 @@ g, text, tspan {
<text x="15" y="230">The amount will be booked via SEPA from your account</text>
<text x="15" y="235">[%client.sepa%] (BIC: [%client.bic%])</text>
<text x="15" y="240">on [%invoice.date.month%] 25th earliest.</text>
<text x="15" y="240">on [%invoice.month%] 25th earliest.</text>
<text x="15" y="250" style="font-size:1.8pt;">Please note: You can file a complaint regarding this issue within 3 months of receiption of this invoice in written form.</text>
<text x="15" y="255">More details can be found online at www.sipwise.net in My Account.</text>
<text x="15" y="260">With best regards,</text>
@ -128,7 +127,7 @@ g, text, tspan {
<tspan x="95" id="zonepage_calls_total_number"><!--{[% data.number %]}--><!--{[%#}-->0<!--{%]}--></tspan>
<tspan x="130" id="zonepage_calls_total_duration"><!--{[% data.duration|format('%.3f') %]}--><!--{[%#}-->0.000<!--{%]}--></tspan>
<tspan x="160" id="zonepage_calls_total_freetime"><!--{[% data.free_time|format('%d') %]}--><!--{[%#}-->0.0<!--{%]}--></tspan>
<tspan x="190" id="zonepage_calls_total_cost"><!--{[% ( data.cost / 100 )|format('%.2f') %]}--><!--{[%#}-->0.00<!--{%]}--></tspan>
<tspan x="190" id="zonepage_calls_total_cost"><!--{[% ( data.cost )|format('%.2f') %]}--><!--{[%#}-->0.00<!--{%]}--></tspan>
</text>
<rect x="0" y="15" width="195" height="0.1" stroke="#444444" stroke-width="0.08" fill="none"/>
<!--{[%END-%]}-->
@ -147,7 +146,7 @@ g, text, tspan {
<!--page-->
<g id="callpage" display="none">
<title>CallPage</title>
<g y="50" x="10" width="195" height="150" id="callpage_invoicedetails" transform="translate(10, 50)" rows="20" rows-interval="20">
<g y="50" x="10" width="195" height="150" id="callpage_invoicedetails" transform="translate(10, 50)" rows="20" rows-interval="10">
<!--{[%MACRO titlerow BLOCK-%]}-->
@ -178,7 +177,7 @@ g, text, tspan {
<text y="20" text-anchor="end" id="callpage_calls_total" class="datarow">
<tspan x="0" id="callpage_calls_total_title" text-anchor="start">Total:</tspan>
<tspan x="60" id="callpage_calls_total_duration"><!--{[% data.duration|format('%.3f') %]}--><!--{[%#}-->0.000<!--{%]}--></tspan>
<tspan x="185" id="callpage_calls_total_cost"><!--{[% ( data.cost / 100 )|format('%.2f') %]}--><!--{[%#}-->0.00<!--{%]}--></tspan>
<tspan x="185" id="callpage_calls_total_cost"><!--{[% ( data.cost )|format('%.2f') %]}--><!--{[%#}-->0.00<!--{%]}--></tspan>
</text>
<rect x="0" y="15" width="195" height="0.1" stroke="#444444" stroke-width="0.08" fill="none"/>
<!--{[%END-%]}-->

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

@ -1,19 +1,25 @@
#!/usr/bin/perl -w
use lib '/media/sf_/usr/share/VMHost/ngcp-panel/lib';
#use lib '/media/sf_/usr/share/VMHost/ngcp-panel/lib';
use strict;
use Getopt::Long;
use DBI;
use Data::Dumper;
use NGCP::Panel::Utils::DateTime;
use DateTime::TimeZone;
#use Net::Domain qw(hostfqdn);
#use LWP::UserAgent;
use Test::MockObject;
use Sipwise::Base;
use NGCP::Panel;
use NGCP::Panel::Utils::DateTime;
use NGCP::Panel::Utils::Contract;
use NGCP::Panel::Utils::InvoiceTemplate;
use NGCP::Panel;
use NGCP::Panel::View::SVG;
use Test::MockObject;
use Sipwise::Base;
my $opt = {};
Getopt::Long::GetOptions($opt, 'reseller_id:i@', 'client_contact_id:i@', 'stime:s', 'etime:s', 'help|?')
or die 'could not process command-line options';
my $debug = 0;
my ($dbuser, $dbpass);
@ -31,37 +37,27 @@ if(-f $mfile) {
print "using user '$dbuser' with pass '$dbpass'\n"
if($debug);
#my ($ua, $req, $res);
#use LWP::UserAgent;
#use HTTP::Request;
#$ua = LWP::UserAgent->new;
#$req = HTTP::Request->new('OPTIONS', 'https://192.168.56.7:1444/invoice/3/template');
##$res = $ua->request($req);
#my $controller = NGCP::Panel->controller('Invoice');
#my $c = NGCP::Panel->prepare($ua);
##$c->request->param->{tt_id} = 126;
##$c->request->method( 'POST' );
##$c->request->uri( 'https://192.168.56.7:1444/invoice/3/template');
#die();
my $dbh = DBI->connect('dbi:mysql:billing;host=localhost', $dbuser, $dbpass)
or die "failed to connect to billing DB\n";
my $stime = NGCP::Panel::Utils::DateTime::current_local()->truncate( to => 'month' );
my $etime_plus = $stime->clone->add( months => 1 );
my $etime = $etime_plus->clone->subtract( seconds => 1 );
my $c_mock = Test::MockObject->new();
$c_mock->set_false(qw/debug/);
my $view = NGCP::Panel::View::SVG->new($c_mock,{});
my $stime = $opt->{stime}
? NGCP::Panel::Utils::DateTime::new_local(split(/\D+/,$opt->{stime}))
: NGCP::Panel::Utils::DateTime::current_local()->truncate( to => 'month' );
my $etime = $opt->{etime}
? NGCP::Panel::Utils::DateTime::new_local(split(/\D+/,$opt->{etime}))
: $stime->clone->add( months => 1 )->subtract( seconds => 1 );
my $svg_default = $view->getTemplateContent(undef,'invoice/invoice_template_svg.tt');
NGCP::Panel::Utils::InvoiceTemplate::preprocessInvoiceTemplateSvg( {no_fake_data => 1}, \$svg_default);
#print $etime->ymd;
foreach my $provider_contract( @{$dbh->selectall_arrayref('select contracts.*,resellers.id as reseller_core_id from resellers inner join contracts on resellers.contract_id=contracts.id where resellers.status != "terminated"', { Slice => {} } ) } ){
foreach my $provider_contract( @{$dbh->selectall_arrayref('select contracts.*,resellers.id as reseller_core_id from resellers inner join contracts on resellers.contract_id=contracts.id where resellers.status != "terminated"'.ify('and resellers.id', @{$opt->{reseller_id}}), { Slice => {} }, @{$opt->{reseller_id}} ) } ){
my $provider_contact = $dbh->selectrow_hashref('select * from contacts where id=?', undef, $provider_contract->{contact_id} );
foreach my $client_contact (@{ $dbh->selectall_arrayref('select contacts.* from contacts where reseller_id = ?', { Slice => {} }, $provider_contract->{reseller_core_id} ) } ){
foreach my $client_contact (@{ $dbh->selectall_arrayref('select contacts.* from contacts where reseller_id = ?'.ify(' and contacts.id', @{$opt->{client_contact_id}}), { Slice => {} }, $provider_contract->{reseller_core_id}, @{$opt->{client_contact_id}} ) } ){
my $client_contract = $dbh->selectrow_hashref('select contracts.* from contracts where contracts.contact_id=? ', undef, $client_contact->{id} );
if( my $billing_profile = $dbh->selectrow_hashref('select billing_profiles.*
@ -76,23 +72,9 @@ foreach my $provider_contract( @{$dbh->selectall_arrayref('select contracts.*,re
and (billing_mappings.end_date >= ? OR billing_mappings.end_date IS NULL)'
, undef, $client_contract->{id}, $etime->epoch, $stime->epoch
) ){
my $invoice;
if(!(my $contract_balance = $dbh->selectrow_hashref('select * from contract_balances where contract_id=? and date(start)=? and date(end)=?',undef,$client_contract->{id},$stime->ymd,$etime->ymd))){
@$contract_balance{qw/cash_balance cash_balance_interval free_time_balance free_time_balance_interval/} = NGCP::Panel::Utils::Contract::get_contract_balance_values(
%$billing_profile,
stime => $stime,
etime => $etime->datetime,
);
$dbh->do('insert into contract_balances(contract_id,cash_balance,cash_balance_interval,free_time_balance,free_time_balance_interval,start,end,invoice_id)values(?,?,?,?,?,?,?,?)',undef,$client_contract->{id},@$contract_balance{qw/cash_balance cash_balance_interval free_time_balance free_time_balance_interval/},$stime->datetime, $etime->datetime,undef );
$invoice = create_invoice($client_contract->{id},$stime, $etime);
$contract_balance = $dbh->selectrow_hashref('select * from contract_balances where id=?',undef,$dbh->last_insert_id(undef,'billing','contract_balances','id'));
}else{
if(!$contract_balance->{invoice_id} || !( $invoice = $dbh->selectrow_hashref('select * from invoices where id=?',undef,$contract_balance->{invoice_id} ))){
$invoice = create_invoice($client_contract->{id},$stime, $etime);
}
}
my ($contract_balance,$invoice)=({},{});
($contract_balance,$invoice) = get_contract_balance($client_contract,$billing_profile,$contract_balance,$invoice,$stime,$etime);
my $invoice_details_calls = $dbh->selectall_arrayref('select cdr.*,bzh.zone, bzh.detail as zone_detail
from accounting.cdr
LEFT JOIN billing.billing_zones_history bzh ON bzh.id = cdr.source_customer_billing_zone_id
@ -106,7 +88,7 @@ foreach my $provider_contract( @{$dbh->selectall_arrayref('select contracts.*,re
limit 25'
, { Slice => {} }
#, $client_contract->{id},$stime->epoch,$etime->epoch
);
);
my $invoice_details_zones = $dbh->selectall_arrayref('select SUM(cdr.source_customer_cost) AS cost, COUNT(*) AS number, SUM(cdr.duration) AS duration,sum(cdr.source_customer_free_time) as free_time, bzh.zone
from accounting.cdr
LEFT JOIN billing.billing_zones_history bzh ON bzh.id = cdr.source_customer_billing_zone_id
@ -120,7 +102,6 @@ foreach my $provider_contract( @{$dbh->selectall_arrayref('select contracts.*,re
order by bzh.zone'
, {Slice => {} }
#, $client_contract->{id},$stime->epoch,$etime->epoch
);
my $i = 1;
$invoice_details_calls = [map{[$i++,$_]} (@$invoice_details_calls) x 1];
@ -133,10 +114,10 @@ foreach my $provider_contract( @{$dbh->selectall_arrayref('select contracts.*,re
provider_id => $provider_contract->{reseller_core_id},
tt_type => 'svg',
tt_sourcestate => 'saved',
tt_id => 1,
tt_id => $provider_contract->{reseller_core_id},
};
$out = {
tt_id => 1,
tt_id => $provider_contract->{reseller_core_id},
};
my $stash = {
provider => $provider_contact,
@ -146,24 +127,40 @@ foreach my $provider_contract( @{$dbh->selectall_arrayref('select contracts.*,re
invoice_details_calls => $invoice_details_calls,
};
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});
if(!$svg){
$svg = $svg_default;
#print "svg=$svg;";
}else{
if($svg){
NGCP::Panel::Utils::InvoiceTemplate::preprocessInvoiceTemplateSvg($in,\$svg);
}else{
$svg = $svg_default;
}
$svg = $view->getTemplateProcessed($c_mock,\$svg, $stash );
#print $svg;
#die();
NGCP::Panel::Utils::InvoiceTemplate::convertSvg2Pdf(undef,\$svg,$in,$out);
binmode(STDOUT);
print $out->{tt_string_pdf};
die;
#my $result = $c->forward($controller, 'invoice_templaet', [] );
#$req = HTTP::Request->new('OPTIONS', $uri.'/invoice/'..'/');
#$res = $ua->request($req);
#binmode(STDOUT);
#print $out->{tt_string_pdf};
#die;
$dbh->do('update invoices set data=? where id=?',undef,$out->{tt_string_pdf},$invoice->{id});
}
}
}
sub get_contract_balance{
my($client_contract,$billing_profile,$contract_balance,$invoice,$stime,$etime) = @_;
if(!($contract_balance = $dbh->selectrow_hashref('select * from contract_balances where contract_id=? and date(start)=? and date(end)=?',undef,$client_contract->{id},$stime->ymd,$etime->ymd))){
@$contract_balance{qw/cash_balance cash_balance_interval free_time_balance free_time_balance_interval/} = NGCP::Panel::Utils::Contract::get_contract_balance_values(
%$billing_profile,
stime => $stime,
etime => $etime,
);
$dbh->do('insert into contract_balances(contract_id,cash_balance,cash_balance_interval,free_time_balance,free_time_balance_interval,start,end,invoice_id)values(?,?,?,?,?,?,?,?)',undef,$client_contract->{id},@$contract_balance{qw/cash_balance cash_balance_interval free_time_balance free_time_balance_interval/},$stime->datetime, $etime->datetime,undef );
$invoice = create_invoice($client_contract->{id},$stime, $etime);
$contract_balance = $dbh->selectrow_hashref('select * from contract_balances where id=?',undef,$dbh->last_insert_id(undef,'billing','contract_balances','id'));
}else{
if(!$contract_balance->{invoice_id} || !( $invoice = $dbh->selectrow_hashref('select * from invoices where id=?',undef,$contract_balance->{invoice_id} ))){
$invoice = create_invoice($client_contract->{id},$stime, $etime);
}
}
return ($contract_balance,$invoice);
}
sub create_invoice{
my($contract_id, $stime, $etime) = @_;
@ -176,7 +173,10 @@ sub create_invoice{
return $dbh->selectrow_hashref('select * from invoices where id=?',undef, $invoice_id);
}
sub ify{
my $key = shift;
return ( $#_ == 0 ) ? ' '.$key.' = ? ': ( ( $#_ > 0 ) ? ( ' '.$key. 'in('.('?'x($#_+1)).') ') : '' );
}

Loading…
Cancel
Save