use SL::IC;
use SL::IO;
+use SL::DB::Language;
+use SL::DB::Printer;
+
require "bin/mozilla/common.pl";
use strict;
$form->{"marge_percent_$i"} = 0;
my $marge_color;
- my $real_sellprice = $linetotal;
+ my $real_sellprice;
+ if ( $form->{taxincluded} and $form->{"qty_$i"} * 1 and $form->{$form->{"taxaccounts_$i"} . "_rate"} * 1) {
+ # if we use taxincluded we need to calculate the marge from the net_value
+ # all the marge calculations are based on linetotal which we need to
+ # convert to net first
+
+ # there is no direct form value for the tax_rate of the item, but
+ # form->{taxaccounts_$i} gives the tax account (e.g. 3806) and 3806_rate
+ # gives the tax percentage (e.g. 0.19)
+ $real_sellprice = $linetotal / (1 + $form->{$form->{"taxaccounts_$i"} . "_rate"});
+ } else {
+ $real_sellprice = $linetotal;
+ };
my $real_lastcost = $form->{"lastcost_$i"} * $form->{"qty_$i"} / ( $form->{"marge_price_factor_$i"} || 1 );
my $marge_percent_warn = $myconfig{marge_percent_warn} * 1 || 15;
my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
$form->{"sellprice_$i"} =
$form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
}
+
+ # tradediscount
+ if ($::form->{tradediscount}) {
+ $::form->{"sellprice_$i"} *= 1 - $::form->{tradediscount};
+ }
}
map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
my $salesman_id_saved = $form->{salesman_id};
my $cp_id_saved = $form->{cp_id};
my $taxzone_id_saved = $form->{taxzone_id};
+ my $currency_saved = $form->{currency};
call_sub("$form->{vc}_details") if ($form->{vc});
$form->{language_id} = $language_saved;
$form->{payment_id} = $payment_id_saved;
$form->{taxzone_id} = $taxzone_id_saved;
+ $form->{currency} = $currency_saved;
$form->{"email"} = $saved_email if ($saved_email);
$form->{"cc"} = $saved_cc if ($saved_cc);
$extension = 'xls';
}
- my $email_extension = (($form->{media} eq 'email') && (-f "$myconfig{templates}/$form->{formname}_email$form->{language}${printer_code}.${extension}")) ? '_email' : '';
+ # search for the template
+ my @template_files;
+ push @template_files, "$form->{formname}_email$form->{language}$printer_code.$extension" if $form->{media} eq 'email';
+ push @template_files, "$form->{formname}$form->{language}$printer_code.$extension";
+ push @template_files, "$form->{formname}.$extension";
+ push @template_files, "default.$extension";
- $form->{IN} = "$form->{formname}${email_extension}$form->{language}${printer_code}.${extension}";
+ $form->{IN} = undef;
+ for my $filename (@template_files) {
+ if (-f "$myconfig{templates}/$filename") {
+ $form->{IN} = $filename;
+ last;
+ }
+ }
+
+ if (!defined $form->{IN}) {
+ $::form->error($::locale->text('Cannot find matching template for this print request. Please contact your template maintainer. I tried these: #1.', join ', ', map { "'$_'"} @template_files));
+ }
delete $form->{OUT};
if ($form->{media} eq 'printer') {
#$form->{OUT} = "| $form->{printer_command} &>/dev/null";
- $form->{OUT} = "| $form->{printer_command} ";
+ $form->{OUT} = $form->{printer_command};
+ $form->{OUT_MODE} = '|-';
$form->{printed} .= " $form->{formname}";
- $form->{printed} =~ s/^ //;
+ $form->{printed} =~ s/^ //;
}
my $printed = $form->{printed};
}
$filename .= ($form->{postscript}) ? '.ps' : '.pdf';
- $form->{OUT} = ">" . $::lx_office_conf{paths}->{spool} . "/$filename";
+ $form->{OUT} = $::lx_office_conf{paths}->{spool} . "/$filename";
+ $form->{OUT_MODE} = '>';
# add type
$form->{queued} .= " $form->{formname} $filename";
}
# /saving the history
+ # prepare meta information for template introspection
+ $form->{template_meta} = {
+ formname => $form->{formname},
+ language => SL::DB::Manager::Language->find_by_or_create(id => $form->{language_id}),
+ format => $form->{format},
+ media => $form->{media},
+ extension => $extension,
+ printer => SL::DB::Manager::Printer->find_by_or_create(id => $form->{printer_id}),
+ };
+
$form->parse_template(\%myconfig);
$form->{callback} = "";