From 45a99ff918d0992da5e5d4f3fa9d385a6273b74b Mon Sep 17 00:00:00 2001 From: Irka Date: Thu, 31 Jul 2014 00:26:51 +0200 Subject: [PATCH] MT#8353 More freedom in money signs configuration. And fix fractional. --- lib/NGCP/Panel/Utils/InvoiceTemplate.pm | 11 +++++++++-- .../invoice/default/invoice_template_aux.tt | 12 +++++++----- .../invoice/default/invoice_template_svg.tt | 6 +++--- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/NGCP/Panel/Utils/InvoiceTemplate.pm b/lib/NGCP/Panel/Utils/InvoiceTemplate.pm index 3346615cd0..6516a52d7d 100644 --- a/lib/NGCP/Panel/Utils/InvoiceTemplate.pm +++ b/lib/NGCP/Panel/Utils/InvoiceTemplate.pm @@ -129,8 +129,15 @@ sub get_tt { if('HASH' eq ref $item){ return $item->{$col}; } - } + }, ); + $tt->context->define_vmethod( + 'scalar' => power => sub { + my($value,$power) = @_; + $c->log->debug('power: value='.$value.'; power='.$power.';'); + return $value ** $power; + }, + ); return $tt; } @@ -281,7 +288,7 @@ sub get_dummy_data { data => [ map {{ number => int(rand(200)), - cost => int(rand(100000)), + customercost => int(rand(100000)), duration => int(rand(10000)), free_time => 0, zone => "Zone $_", diff --git a/share/templates/invoice/default/invoice_template_aux.tt b/share/templates/invoice/default/invoice_template_aux.tt index df49a57bba..b83f0a8538 100644 --- a/share/templates/invoice/default/invoice_template_aux.tt +++ b/share/templates/invoice/default/invoice_template_aux.tt @@ -128,12 +128,14 @@ #Attention! usage supposes amount in CENTS! comma = comma || '.'; amount = amount ? amount : 0 ; + money_signs = money_signs || '2'; + base = 10; full = Math.int(amount / 100); - cent = Math.int(amount % 100); +# cent = Math.int( amount % 100) ; + cent = Math.int( amount % 100) * ( base.power( money_signs - 2) ) ; cents = String.new(cent); - money_signs = money_signs || '2'; - money_format_string = money_format_string || "%0" _ money_signs _ "d"; - cents = cents.format(money_format_string); + cents_format_string = "%0" _ money_signs _ "d"; + cents = cents.format(cents_format_string); aux.val = full _ comma _ cents; END; @@ -145,7 +147,7 @@ timestamp2time(timestamp=in); out = aux.val; ELSIF field.money_cents; - money_format(amount=in, comma=field.comma); + money_format(amount=in, comma=field.comma, money_signs=field.money_signs); out = aux.val; ELSE; out = in; diff --git a/share/templates/invoice/default/invoice_template_svg.tt b/share/templates/invoice/default/invoice_template_svg.tt index 8f84dac6e0..3997545e97 100644 --- a/share/templates/invoice/default/invoice_template_svg.tt +++ b/share/templates/invoice/default/invoice_template_svg.tt @@ -3,7 +3,7 @@ pagewidth = 210; pageheight = 297; server_process_units = 'none'; - money_signs = 3; +# money_signs = 3; PROCESS "invoice/default/invoice_template_aux.tt"; money_format(amount=(billprof.interval_charge * 100), comma='.'); fixfee = aux.val; @@ -90,7 +90,7 @@ Total Price in [% cur %] - + @@ -140,7 +140,7 @@ - +