use SL::IC;
use SL::IO;
+use SL::DB::Language;
+use SL::DB::Printer;
+
require "bin/mozilla/common.pl";
use strict;
my $numrows = shift;
- my ($readonly, $stock_in_out, $stock_in_out_title);
+ my ($stock_in_out, $stock_in_out_title);
my $is_purchase = (first { $_ eq $form->{type} } qw(request_quotation purchase_order purchase_delivery_order)) || ($form->{script} eq 'ir.pl');
my $show_min_order_qty = first { $_ eq $form->{type} } qw(request_quotation purchase_order);
my $is_s_p_order = (first { $_ eq $form->{type} } qw(sales_order purchase_order));
if ($is_delivery_order) {
- $readonly = ' readonly' if ($form->{closed});
-
if ($form->{type} eq 'sales_delivery_order') {
$stock_in_out_title = $locale->text('Release From Stock');
$stock_in_out = 'out';
}
# build in drop down list for pricesgroups
+ # $sellprice_value setzt den Wert etwas unabhängiger von der Darstellung.
+ # Hintergrund: Preisgruppen werden hier überprüft und neu berechnet.
+ # Vorher wurde der ganze cgi->textfield Block zweimal identisch eingebaut, dass passiert
+ # jetzt nach der Abfrage.
+ my $sellprice_value;
if ($form->{"prices_$i"}) {
$column_data{sellprice_pg} = qq|<select name="sellprice_pg_$i" style="width: 8em">$form->{"prices_$i"}</select>|;
- $column_data{sellprice} = $cgi->textfield(-name => "sellprice_$i", -size => 10, -onBlur => 'check_right_number_format(this)', -value =>
- (($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"})
+ $sellprice_value =($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"})
? $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces)
- : $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces)));
+ : $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
} else {
# for last row and report
# set pricegroup drop down list from report menu
} else {
$column_data{sellprice_pg} = qq| |;
}
- $column_data{sellprice} = $cgi->textfield(-name => "sellprice_$i", -size => 10, -onBlur => "check_right_number_format(this)", -value =>
- $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces));
+ $sellprice_value = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
}
- $column_data{discount} = $cgi->textfield(-name => "discount_$i", -size => 3, -value => $form->format_amount(\%myconfig, $form->{"discount_$i"}));
+ # Falls der Benutzer die Preise nicht anpassen sollte, wird das entsprechende
+ # Textfield auf readonly gesetzt. Anm. von Sven: Manipulation der Preise ist
+ # immer noch möglich, konsequenterweise sollten diese NUR aus der Datenbank
+ # geholt werden.
+ my $edit_prices = $main::auth->assert('edit_prices', 1);
+ $column_data{sellprice} = (!$edit_prices)
+ ? $cgi->textfield(-readonly => "readonly",
+ -name => "sellprice_$i", -size => 10, -onBlur => "check_right_number_format(this)", -value => $sellprice_value)
+ : $cgi->textfield(-name => "sellprice_$i", -size => 10, -onBlur => "check_right_number_format(this)", -value => $sellprice_value);
+ $column_data{discount} = (!$edit_prices)
+ ? $cgi->textfield(-readonly => "readonly",
+ -name => "discount_$i", -size => 3, -value => $form->format_amount(\%myconfig, $form->{"discount_$i"}))
+ : $cgi->textfield(-name => "discount_$i", -size => 3, -value => $form->format_amount(\%myconfig, $form->{"discount_$i"}));
$column_data{linetotal} = $form->format_amount(\%myconfig, $linetotal, 2);
$column_data{bin} = $form->{"bin_$i"};
$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} = "";