use SL::IC;
use SL::IO;
+use SL::DB::Default;
use SL::DB::Language;
use SL::DB::Printer;
use SL::Helper::Flash;
sub _check_io_auth {
$main::auth->assert('part_service_assembly_edit | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
'request_quotation_edit | sales_quotation_edit | purchase_order_edit | ' .
- 'purchase_delivery_order_edit | sales_delivery_order_edit');
+ 'purchase_delivery_order_edit | sales_delivery_order_edit | part_service_assembly_details');
}
########################################
my ($stock_in_out, $stock_in_out_title);
+ my $defaults = AM->get_defaults();
+ $form->{show_weight} = $defaults->{show_weight};
+ $form->{weightunit} = $defaults->{weightunit};
+
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_delivery_order = $form->{type} =~ /_delivery_order$/;
{ id => 'qty', width => 5, value => $locale->text('Qty'), display => 1, },
{ id => 'price_factor', width => 5, value => $locale->text('Price Factor'), display => !$is_delivery_order, },
{ id => 'unit', width => 5, value => $locale->text('Unit'), display => 1, },
- { id => 'weight', width => 5, value => $locale->text('Weight'), display => 1, },
+ { id => 'weight', width => 5, value => $locale->text('Weight'), display => $defaults->{show_weight}, },
{ id => 'serialnr', width => 10, value => $locale->text('Serial No.'), display => 0, },
{ id => 'projectnr', width => 10, value => $locale->text('Project'), display => 0, },
{ id => 'sellprice', width => 15, value => $locale->text('Price'), display => !$is_delivery_order, },
_update_custom_variables();
my $totalweight = 0;
- my $defaults = AM->get_defaults();
- $form->{weightunit} = $defaults->{weightunit};
# rows
my @ROWS;
qw(qty discount sellprice lastcost price_new price_old)
unless ($form->{simple_save});
+ if ($form->{"prices_$i"} && ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"})) {
+ $form->{"sellprice_$i"} = $form->{"price_new_$i"};
+ }
+
# unit begin
$form->{"unit_old_$i"} ||= $form->{"unit_$i"};
$form->{"selected_unit_$i"} ||= $form->{"unit_$i"};
my $linetotal = $form->round_amount($form->{"qty_$i"} * $form->{"sellprice_$i"} * (100 - $form->{"discount_$i"}) / 100 / $price_factor, 2);
my $rows = $form->numtextrows($form->{"description_$i"}, 30, 6);
- $column_data{runningnumber} = $cgi->textfield(-name => "runningnumber_$i", -size => 5, -value => $i); # HuT
- $column_data{partnumber} = $cgi->textfield(-name => "partnumber_$i", -size => 12, -value => $form->{"partnumber_$i"});
+ $column_data{runningnumber} = $cgi->textfield(-name => "runningnumber_$i", -id => "runningnumber_$i", -size => 5, -value => $i); # HuT
+ $column_data{partnumber} = $cgi->textfield(-name => "partnumber_$i", -id => "partnumber_$i", -size => 12, -value => $form->{"partnumber_$i"});
$column_data{description} = (($rows > 1) # if description is too large, use a textbox instead
- ? $cgi->textarea( -name => "description_$i", -default => $form->{"description_$i"}, -rows => $rows, -columns => 30)
- : $cgi->textfield(-name => "description_$i", -size => 30, -value => $form->{"description_$i"}))
- . $cgi->button(-value => $locale->text('L'), -onClick => "set_longdescription_window('longdescription_$i')");
+ ? $cgi->textarea( -name => "description_$i", -id => "description_$i", -default => $form->{"description_$i"}, -rows => $rows, -columns => 30)
+ : $cgi->textfield(-name => "description_$i", -id => "description_$i", -value => $form->{"description_$i"}, -size => 30))
+ . $cgi->button(-value => $locale->text('L'), -onClick => "kivi.SalesPurchase.edit_longdescription($i)");
my $qty_dec = ($form->{"qty_$i"} =~ /\.(\d+)/) ? length $1 : 2;
$column_data{linetotal} = $form->format_amount(\%myconfig, $linetotal, 2);
$column_data{bin} = $form->{"bin_$i"};
- $column_data{weight} = $form->format_amount(\%myconfig, $form->{"qty_$i"} * $form->{"weight_$i"}, 3) . ' ' . $defaults->{weightunit};
- #To add the hidden variable lineweight:
- $form->{"lineweight_$i"} = $column_data{weight};
+ $column_data{weight} = $form->format_amount(\%myconfig, $form->{"qty_$i"} * $form->{"weight_$i"}, 3) . ' ' . $defaults->{weightunit} if $defaults->{show_weight};
if ($is_delivery_order) {
$column_data{stock_in_out} = calculate_stock_in_out($i);
if ($is_delivery_order) {
map { $form->{"${_}_${i}"} = $form->format_amount(\%myconfig, $form->{"${_}_${i}"}) } qw(sellprice discount lastcost);
- push @hidden_vars, qw(sellprice discount not_discountable price_factor_id lastcost pricegroup_id);
+ $form->{"pricegroup_id_$i"} = $form->{"pricegroup_old_$i"} if $form->{"pricegroup_old_$i"};
+ $form->{"sellprice_pg_$i"} = $form->{"hidden_prices_$i"} if $form->{"hidden_prices_$i"};
+ push @hidden_vars, grep { defined $form->{"${_}_${i}"} } qw(sellprice discount not_discountable price_factor_id lastcost pricegroup_id sellprice_pg);
push @hidden_vars, "stock_${stock_in_out}_sum_qty", "stock_${stock_in_out}";
}
my @HIDDENS = map { value => $_}, (
$cgi->hidden("-name" => "unit_old_$i", "-value" => $form->{"selected_unit_$i"}),
$cgi->hidden("-name" => "price_new_$i", "-value" => $form->format_amount(\%myconfig, $form->{"price_new_$i"})),
- map { ($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } map { $_."_$i" }
+ map { ($cgi->hidden("-name" => $_, "-id" => $_, "-value" => $form->{$_})); } map { $_."_$i" }
(qw(orderitems_id bo pricegroup_old price_old id inventory_accno bin partsgroup partnotes
income_accno expense_accno listprice assembly taxaccounts ordnumber transdate cusordnumber
- longdescription basefactor marge_absolut marge_percent marge_price_factor weight lineweight), @hidden_vars)
+ longdescription basefactor marge_absolut marge_percent marge_price_factor weight), @hidden_vars)
);
map { $form->{"${_}_base"} += $linetotal } (split(/ /, $form->{"taxaccounts_$i"}));
$form->{"sellprice_$j"} = $item->{price} if $item->{selected} && $item->{pricegroup_id};
$form->{"price_new_$j"} = $form->{"sellprice_$j"} if $item->{selected} || !$item->{pricegroup_id};
}
+
+ # save hidden pricegroups for delivery_orders
+ next unless my @selected_prices = grep { $_->{selected} } @{ $form->{PRICES}{$j} };
+ $form->{"hidden_prices_$j"} = $selected_prices[-1]{price} . "--" . $selected_prices[-1]{pricegroup_id};
}
$main::lxdebug->leave_sub();
}
my $count = 0;
# remove any makes or model rows
- if ($form->{item} eq 'part') {
- map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
- qw(listprice sellprice lastcost weight rop);
-
- } elsif ($form->{item} eq 'assembly') {
+ if ($form->{item} eq 'assembly') {
# fuer assemblies auskommentiert. seiteneffekte? ;-) wird die woanders benoetigt?
#$form->{sellprice} = 0;
$form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
$form->{assembly_rows} = $count;
- } elsif ($form->{item} eq 'service') {
- map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice sellprice lastcost);
-
- } else {
+ } elsif ($form->{item} !~ m{^(?:part|service)$}) {
remove_emptied_rows(1);
$form->{creditremaining} -= &invoicetotal;
map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
$form->{"${_}_${i}"})
if ($form->{"${_}_${i}"}) }
- qw(ship qty sellprice listprice basefactor discount));
+ qw(ship qty sellprice listprice basefactor discount lastcost));
}
&prepare_order;
my $attachment_filename = $form->generate_attachment_filename();
my $subject = $form->{subject} || $form->generate_email_subject();
- $::request->{layout}->focus($form->{"email"} ? "#subject" : "#email");
$form->header;
my (@dont_hide_key_list, %dont_hide_key, @hidden_keys);
}
$form->{print_and_save} = 1;
my $formname = $form->{formname};
- &save();
+ save();
$form->{formname} = $formname;
- &edit();
+ edit();
$::lxdebug->leave_sub();
::end_of_request();
}
+ elsif (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)) {
+ $form->{print_and_save} = 1;
+ save();
+ }
+
&print_form($old_form);
_check_io_auth();
+ my $defaults = SL::DB::Default->get;
+ $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
+ $form->{templates} = $defaults->templates;
+
my ($old_form) = @_;
my $inv = "inv";
# $locale->text('Quotation Number missing!')
# $locale->text('Quotation Date missing!')
- # assign number
$form->{what_done} = $form->{formname};
- if (!$form->{"${inv}number"} && !$form->{preview} && !$form->{id}) {
- $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
- if ($form->{media} ne 'email') {
-
- # get pricegroups for parts
- IS->get_pricegroups_for_parts(\%myconfig, \%$form);
-
- # build up html code for prices_$i
- set_pricegroup($form->{rowcount});
-
- $form->{rowcount}--;
-
- call_sub($display_form);
- # saving the history
- if(!exists $form->{addition}) {
- $form->{snumbers} = "${inv}number" . "_" . $form->{"${inv}number"};
- $form->{addition} = "PRINTED";
- $form->save_history;
- }
- # /saving the history
- ::end_of_request();
- }
- }
&validate_items;
my $language_saved = $form->{language_id};
my $payment_id_saved = $form->{payment_id};
+ my $delivery_term_id_saved = $form->{delivery_term_id};
my $salesman_id_saved = $form->{salesman_id};
my $cp_id_saved = $form->{cp_id};
my $taxzone_id_saved = $form->{taxzone_id};
$form->{language_id} = $language_saved;
$form->{payment_id} = $payment_id_saved;
+ $form->{delivery_term_id} = $delivery_term_id_saved;
$form->{taxzone_id} = $taxzone_id_saved;
$form->{currency} = $currency_saved;
if ($shipto) {
if ( $form->{formname} eq 'purchase_order'
|| $form->{formname} eq 'request_quotation') {
- $form->{shiptoname} = $myconfig{company};
- $form->{shiptostreet} = $myconfig{address};
+ $form->{shiptoname} = $defaults->company;
+ $form->{shiptostreet} = $defaults->address;
} else {
map { $form->{"shipto$_"} = $form->{$_} } @a;
}
$form->{notes} =~ s/^\s+//g;
- $form->{templates} = "$myconfig{templates}";
-
delete $form->{printer_command};
$form->{language} = $form->get_template_language(\%myconfig);
push @template_files, "$form->{formname}.$extension";
push @template_files, "default.$extension";
@template_files = uniq @template_files;
- $form->{IN} = first { -f "$myconfig{templates}/$_" } @template_files;
+ $form->{IN} = first { -f ($defaults->templates . "/$_") } @template_files;
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));
my @fields = map { s/_1$//; $_ } grep { m/_1$/ } keys %{ $::form };
my @new_rows;
+ my $make_key = sub {
+ my ($row) = @_;
+ return $::form->{"id_${row}"} unless $::form->{"serialnumber_${row}"};
+ my $key = $::form->{"id_${row}"} . ':' . $::form->{"serialnumber_${row}"};
+ return exists $params{quantities}->{$key} ? $key : $::form->{"id_${row}"};
+ };
+
my $removed_rows = 0;
my $row = 0;
while ($row < $::form->{rowcount}) {
my $parts_id = $::form->{"id_$row"};
my $base_qty = $::form->parse_amount(\%::myconfig, $::form->{"qty_$row"}) * SL::DB::Manager::Unit->find_by(name => $::form->{"unit_$row"})->base_factor;
- my $sub_qty = min($base_qty, $params{quantities}->{$parts_id});
- $params{quantities}->{$parts_id} -= $sub_qty;
+ my $key = $make_key->($row);
+ my $sub_qty = min($base_qty, $params{quantities}->{$key});
+ $params{quantities}->{$key} -= $sub_qty;
if (!$sub_qty || ($sub_qty != $base_qty)) {
$::form->{"qty_${row}"} = $::form->format_amount(\%::myconfig, ($base_qty - $sub_qty) / SL::DB::Manager::Unit->find_by(name => $::form->{"unit_$row"})->base_factor);