MT#5879 Rework dummy variable handling for invoice

mr3.3.1
Andreas Granig 12 years ago
parent fa07184a46
commit 807e77855d

@ -257,6 +257,7 @@ sub delete :Chained('base') :PathPart('delete') {
sub edit_content :Chained('base') :PathPart('editcontent') :Args(0) {
my ($self, $c) = @_;
$c->stash(NGCP::Panel::Utils::InvoiceTemplate::get_dummy_data());
$c->stash(template => 'invoice/template.tt');
}
@ -345,10 +346,10 @@ sub preview_content :Chained('base') :PathPart('editcontent/preview') :Args(0) {
my $vars = {};
try {
my $no_fake = 0;
NGCP::Panel::Utils::InvoiceTemplate::preprocess_svg($no_fake, \$svg);
$t->process(\$svg, $vars, \$out) || do {
my $dummy = NGCP::Panel::Utils::Invoice::get_dummy_data();
NGCP::Panel::Utils::InvoiceTemplate::preprocess_svg(\$svg);
$t->process(\$svg, $dummy, \$out) || do {
my $error = $t->error();
my $msg = "error processing template, type=".$error->type.", info='".$error->info."'";
$c->log->error($msg);

@ -40,7 +40,7 @@ sub svg_pdf {
}
sub preprocess_svg {
my($no_fake_data, $svg_ref) = @_;
my($svg_ref) = @_;
my $xp = XML::XPath->new($$svg_ref);
@ -51,13 +51,6 @@ sub preprocess_svg {
}
}
if($no_fake_data) {
my $comment = $xp->find('/comment()[contains(.,"invoice_template_lorem.tt")]');
foreach my $node($comment->get_nodelist) {
$node->getParentNode->removeChild($node);
}
}
my $comment = $xp->find('//comment()[normalize-space(.) = "{}" or normalize-space(.) = "{ }"]');
foreach my $node($comment->get_nodelist) {
$node->getParentNode->removeChild($node);
@ -103,5 +96,85 @@ sub get_tt {
return $tt;
}
sub get_dummy_data {
return {
rescontact => {
gender => 'male',
firstname => 'Resellerfirst',
lastname => 'Resellerlast',
comregnum => 'COMREG1234567890',
company => 'Resellercompany Inc.',
street => 'Resellerstreet 12/3',
postcode => '12345',
city => 'Resellercity',
country => 'Resellercountry',
phonenumber => '+1234567890',
mobilenumber => '+2234567890',
faxnumber => '+3234567890',
iban => 'RESIBAN1234567890',
bic => 'RESBIC1234567890',
},
customer => {
id => rand(10000)+10000,
external_id => 'Resext1234567890',
},
custcontact => {
gender => 'male',
firstname => 'Customerfirst',
lastname => 'Customerlast',
comregnum => 'COMREG1234567890',
company => 'Customercompany Inc.',
street => 'Customerstreet 12/3',
postcode => '12345',
city => 'Customercity',
country => 'Customercountry',
phonenumber => '+4234567890',
mobilenumber => '+5234567890',
faxnumber => '+6234567890',
iban => 'CUSTIBAN1234567890',
bic => 'CUSTBIC1234567890',
},
billprof => {
handle => 'BILPROF12345',
name => 'Test Billing Profile',
prepaid => 0,
interval_charge => 29.90,
interval_free_time => 2000,
interval_free_cash => 0,
interval_unit => 'month',
interval_count => 1,
currency => 'EUR',
vat_rate => 20,
vat_included => 0,
},
invoice => {
year => '2014',
month => '01',
serial => '1234567',
},
calls => [
map {{
start_time => time,
source_customer_cost => rand(1000),
duration => rand(7200) + 10,
destination_user_in => "1".$_."1234567890",
call_type => (qw/cfu cfb cft cfna/)[rand 4],
zone => "Zone $_",
zone_detail => "Detail $_",
}}(1 .. 100)
],
zones => [
map {{
number => rand(200),
cost => rand(10000),
duration => rand(10000),
free_time => 0,
zone => "Zone $_",
zone_detail => "Detail $_",
}}(1 .. 15)
],
};
}
1;
# vim: set tabstop=4 expandtab:

@ -1,162 +0,0 @@
[%
USE Dumper;
USE Date;
USE Math;
template_variables.description = {};
template_variables.description.import({
invoice => {
'invoice_self' => 'Information about invoice.',
'amount' => 'Invoice amount with already considered discount.',
}
});
IF !invoice.serial;
#info from db
DEFAULT invoice.month=date.format(date.now(),'%m');
DEFAULT invoice.serial=Math.int(Math.rand(999999))|format('%06d');
DEFAULT invoice.year=date.format(date.now(),'%y');
#/info from db
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.debit='500';
DEFAULT invoice.discount_service='10';
DEFAULT invoice.discount_wire_transfer='40';
DEFAULT invoice.serviceallowance='69';
DEFAULT invoice.voice_termination_fees='10';
END;
template_variables.description.import({
provider => {
'provider_self' => 'Information about invoice issuer, reseller.',
'bic' => 'BIC information of provider.',
'city' => 'Provider city.',
}
});
IF 1 || !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';
ELSE;
FOREACH i in ['bic','city','company','country','email','fax','fn','iban','mobile','phone','postcode','street','url','vat'];
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;
template_variables.description.import({
client => {
'client_self' => 'Information about invoice receiver, customer.',
'bic' => "Client's BIC.",
}
});
IF !client.id;
DEFAULT client.bic='ABCDEFG1234';
DEFAULT client.city='Client City';
DEFAULT client.country='Client-Country';
DEFAULT client.title='Herr Dipl. Ing (FH)';
DEFAULT client.firstname='Client Firstname';
DEFAULT client.id=Math.int(Math.rand(999999))|format('%06d');
DEFAULT client.lastname='Client-Lastname Sr.';
DEFAULT client.postcode='65104';
DEFAULT client.sepa='AT1234567890';
DEFAULT client.street='Client Street';
DEFAULT client.vatid='AA1234';
END;
template_variables.description.import({
bp => {
'name' => 'Billing Profile name',
'interval_charge' => 'Constant fee for invoice period.',
}
});
IF !bp.id;
DEFAULT bp.name='Default Billing Profile';
DEFAULT bp.interval_charge='125';
DEFAULT bp.handle ='default';
DEFAULT bp.prepaid = '';
DEFAULT bp.interval_charge = '';
DEFAULT bp.interval_free_time = '';
DEFAULT bp.interval_free_cash = '';
DEFAULT bp.interval_unit = '';
DEFAULT bp.interval_count = '';
DEFAULT bp.fraud_interval_limit = '';
DEFAULT bp.fraud_interval_lock = '';
DEFAULT bp.fraud_interval_notify = '';
DEFAULT bp.fraud_daily_limit = '';
DEFAULT bp.fraud_daily_lock = '';
DEFAULT bp.fraud_daily_notify = '';
DEFAULT bp.currency = '';
DEFAULT bp.vat_rate = '';
DEFAULT bp.vat_included = '';
END;
invoice_details_zones = [];
invoice_details_calls = [];
template_variables.description.import({
callsdata => {
'callsdata_self' => 'Information about calls.',
'start_time' => 'Call start time, Call will be included in invoice period, in which call started.',
}
});
IF !invoice_details_calls.size();
i=1;
WHILE i <= 44;
invoice_details_calls.push([i,{
start_time => date.format(date.now(),'%s'),
source_customer_cost => i / 10,
duration => i * 10,
destination_user_in => '+1234567890',
call_type => 'call',
zone => 'Example Zone',
zone_detail => 'Default',
}]);
i = i + 1;
END;
END;
template_variables.description.import({
zonesdata => {
'zonesdata_self' => 'Information about zone fees.',
'number' => 'Number of calls to the zone.',
}
});
IF !invoice_details_zones.size();
i=1;
WHILE i <= 45;
invoice_details_zones.push([i,{
number => i * 2 ,
cost => i / 10,
duration => i * 10,
free_time => i * 5,
zone => 'Example Zone',
zone_detail => 'Default',
}]);
i = i + 1;
END;
END;
%]

@ -1,4 +1,3 @@
<!--{[%PROCESS 'invoice/default/invoice_template_lorem.tt' -%]}-->
<!--{[%PROCESS 'invoice/default/invoice_template_aux.tt' -%]}-->
<!--{[%money_format = format('%.2f') %]}-->
<!--{[%row_vertical_interval = 10 -%]}-->

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

@ -57,34 +57,17 @@ function formSerialize(){
<button type="button" class="close mod_close">×</button>
</h3>
</div>
[%
PROCESS 'invoice/default/invoice_template_lorem.tt';
callsdata = invoice_details_calls.0.1;
zonesdata = invoice_details_zones.0.1;
%]
<div style="overflow:auto;height:85%;">
[%
FOREACH varname IN ['client','provider','invoice','bp','callsdata','zonesdata'];
tooltipvarindex = varname _ '_self';
%]
<div style="overflow:auto;height:85%;">
<ul> <span class="variable" [%IF template_variables.description.${varname}.${tooltipvarindex}%] rel="tooltip" data-original-title="[% c.loc(template_variables.description.${varname}.${tooltipvarindex}) %]" [%END%]>[%varname%]</span>
[% FOREACH varname IN ['rescontact', 'customer', 'custcontact', 'billprof', 'invoice']; %]
[%
FOREACH key IN ${varname}.keys().sort();
IF !key.match('^_');
%]
<ul> <span class="variable">[% varname %]</span>
[% FOREACH key IN ${varname}.keys().sort(); -%]
<li>[% varname %].<span class="variablekey">[%key%]</span></li>
[% END -%]
</ul>
[% END -%]
<li [%IF template_variables.description.${varname}.${key}%] rel="tooltip" data-original-title="[% c.loc(template_variables.description.${varname}.${key}) %]" [%END%]>[% varname %].<span class="variablekey">[%key%]</span></li>
[%
END;
END;
%]
</ul>
[%
END;
%]
</div>
<div class="modal-footer">
<a class="mod_close btn btn-primary btn-small">[%c.loc('Close')%]</a>
@ -101,3 +84,4 @@ END;
width="1024px" height="1500px" style="border-width:0px;"></iframe>
</div>
</form>
[% # vim: set tabstop=4 syntax=html expandtab: -%]

Loading…
Cancel
Save