X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=bin%2Fmozilla%2Fio.pl;h=e7ba050a1d515efb8195726ae5406f0a9642d26f;hb=3b9c2119792ae678e9368a0141d7f8646fd6ef42;hp=1e380cdba020ae3a859bc317135f4dd9def84ede;hpb=34f5531fd67d118fcdeaf385d4077eabd328f00c;p=kivitendo-erp.git
diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl
index 1e380cdba..e7ba050a1 100644
--- a/bin/mozilla/io.pl
+++ b/bin/mozilla/io.pl
@@ -38,6 +38,7 @@
use Carp;
use CGI;
+use List::MoreUtils qw(any uniq);
use List::Util qw(min max first);
use SL::CVar;
@@ -46,8 +47,10 @@ use SL::CT;
use SL::IC;
use SL::IO;
+use SL::DB::Default;
use SL::DB::Language;
use SL::DB::Printer;
+use SL::Helper::Flash;
require "bin/mozilla/common.pl";
@@ -121,6 +124,10 @@ sub display_row {
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$/;
@@ -139,7 +146,7 @@ sub display_row {
}
# column_index
- my @header_sort = qw(runningnumber partnumber description ship qty unit sellprice_pg sellprice discount linetotal);
+ my @header_sort = qw(runningnumber partnumber description ship qty unit weight sellprice_pg sellprice discount linetotal);
my @HEADER = (
{ id => 'runningnumber', width => 5, value => $locale->text('No.'), display => 1, },
{ id => 'partnumber', width => 8, value => $locale->text('Number'), display => 1, },
@@ -148,6 +155,7 @@ sub display_row {
{ 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 => $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, },
@@ -185,12 +193,13 @@ sub display_row {
my $deliverydate = $locale->text('Required by');
# special alignings
- my %align = map { $_ => 'right' } qw(qty ship right sellprice_pg discount linetotal stock_in_out);
+ my %align = map { $_ => 'right' } qw(qty ship right sellprice_pg discount linetotal stock_in_out weight);
my %nowrap = map { $_ => 1 } qw(description unit);
$form->{marge_total} = 0;
$form->{sellprice_total} = 0;
$form->{lastcost_total} = 0;
+ $form->{totalweight} = 0;
my %projectnumber_labels = ();
my @projectnumber_values = ("");
@@ -203,6 +212,8 @@ sub display_row {
_update_ship() if ($is_s_p_order);
_update_custom_variables();
+ my $totalweight = 0;
+
# rows
my @ROWS;
@@ -225,6 +236,7 @@ sub display_row {
# adjust prices by unit, ignore if pricegroup changed
if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
$form->{"sellprice_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
+ $form->{"lastcost_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
$form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
}
my $this_unit = $form->{"unit_$i"};
@@ -243,11 +255,15 @@ sub display_row {
} else {
$column_data{price_factor} = ' ';
}
+ $form->{"weight_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"partunit_$i"}, $all_units) || 1;
$column_data{"unit"} = AM->unit_select_html($all_units, "unit_$i", $this_unit, $form->{"id_$i"} ? $form->{"unit_$i"} : undef);
# / unit ending
+#count the max of decimalplaces of sellprice and lastcost, so the same number of decimalplaces
+#is shown for lastcost and sellprice.
my $decimalplaces = ($form->{"sellprice_$i"} =~ /\.(\d+)/) ? max 2, length $1 : 2;
+ $decimalplaces = ($form->{"lastcost_$i"} =~ /\.(\d+)/) ? max $decimalplaces, length $1 : $decimalplaces;
my $price_factor = $price_factors{$form->{"price_factor_id_$i"}} || 1;
my $discount = $form->round_amount($form->{"qty_$i"} * $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100 / $price_factor, 2);
@@ -319,6 +335,8 @@ sub display_row {
$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} if $defaults->{show_weight};
+
if ($is_delivery_order) {
$column_data{stock_in_out} = calculate_stock_in_out($i);
}
@@ -354,7 +372,7 @@ sub display_row {
} else {
$real_sellprice = $linetotal;
};
- my $real_lastcost = $form->{"lastcost_$i"} * $form->{"qty_$i"} / ( $form->{"marge_price_factor_$i"} || 1 );
+ my $real_lastcost = $form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"} / $price_factor, 2);
my $marge_percent_warn = $myconfig{marge_percent_warn} * 1 || 15;
my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
@@ -376,13 +394,16 @@ sub display_row {
%s |,
$marge_color, $locale->text('Ertrag'),$form->{"marge_absolut_$i"}, $form->{"marge_percent_$i"},
$locale->text('LP'), $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2),
- $locale->text('EK'), $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2) }
+ $locale->text('EK'), $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces) }
if $form->{"id_$i"} && ($form->{type} =~ /^sales_/ || $form->{type} =~ /invoice/ || $form->{type} =~ /^credit_note$/ ) && !$is_delivery_order;
$form->{"listprice_$i"} = $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2)
if $form->{"id_$i"} && ($form->{type} =~ /^sales_/ || $form->{type} =~ /invoice/) ;
# / marge calculations ending
+# Calculate total weight
+ $totalweight += ($form->{"qty_$i"} * $form->{"weight_$i"});
+
# calculate onhand
if ($form->{"id_$i"}) {
my $part = IC->get_basic_part_info(id => $form->{"id_$i"});
@@ -410,7 +431,7 @@ sub display_row {
map { ($cgi->hidden("-name" => $_, "-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), @hidden_vars)
+ longdescription basefactor marge_absolut marge_percent marge_price_factor weight), @hidden_vars)
);
map { $form->{"${_}_base"} += $linetotal } (split(/ /, $form->{"taxaccounts_$i"}));
@@ -423,6 +444,8 @@ sub display_row {
push @ROWS, { ROW1 => \@ROW1, ROW2 => \@ROW2, HIDDENS => \@HIDDENS, colspan => $colspan, error => $form->{"row_error_$i"}, };
}
+ $form->{totalweight} = $totalweight;
+
print $form->parse_html_template('oe/sales_order', { ROWS => \@ROWS,
HEADER => \@HEADER,
});
@@ -483,7 +506,7 @@ sub select_item {
} @{ $::form->{item_list} };
# delete action variable
- delete @{$::form}{qw(action item_list header)};
+ delete @{$::form}{qw(action item_list)};
print $::form->parse_html_template('io/select_item', { PREVIOUS_FORM => $previous_form,
MODE => $mode,
@@ -565,7 +588,6 @@ sub item_selected {
map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
qw(sellprice listprice weight);
- $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
$form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
if ($form->{"not_discountable_$i"}) {
@@ -797,6 +819,7 @@ sub validate_items {
# check if items are valid
if ($form->{rowcount} == 1) {
+ flash('warning', $::locale->text('The action you\'ve chosen has not been executed because the document does not contain any item yet.'));
&update;
::end_of_request();
}
@@ -962,6 +985,9 @@ sub edit_e_mail {
$form->{"email"} = $form->{"cp_email"} if $form->{"cp_email"};
}
+ $form->{language} = $form->get_template_language(\%myconfig);
+ $form->{language} = "_" . $form->{language} if $form->{language};
+
my $title = $locale->text('E-mail') . " " . $form->get_formname_translation();
$form->{oldmedia} = $form->{media};
@@ -970,7 +996,6 @@ sub edit_e_mail {
my $attachment_filename = $form->generate_attachment_filename();
my $subject = $form->{subject} || $form->generate_email_subject();
- $form->{"fokus"} = $form->{"email"} ? "Form.subject" : "Form.email";
$form->header;
my (@dont_hide_key_list, %dont_hide_key, @hidden_keys);
@@ -1079,11 +1104,12 @@ sub print_options {
opthash("inline", $form->{SM}{inline}, $locale->text('In-line'))
if ($form->{media} eq 'email');
+ my $printable_templates = any { $::lx_office_conf{print_templates}->{$_} } qw(latex opendocument);
push @MEDIA, grep $_,
opthash("screen", $form->{OP}{screen}, $locale->text('Screen')),
- ($form->{printers} && scalar @{ $form->{printers} } && $::lx_office_conf{print_templates}->{latex}) ?
+ ($printable_templates && $form->{printers} && scalar @{ $form->{printers} }) ?
opthash("printer", $form->{OP}{printer}, $locale->text('Printer')) : undef,
- ($::lx_office_conf{print_templates}->{latex} && !$options{no_queue}) ?
+ ($printable_templates && !$options{no_queue}) ?
opthash("queue", $form->{OP}{queue}, $locale->text('Queue')) : undef
if ($form->{media} ne 'email');
@@ -1198,6 +1224,10 @@ sub print_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";
@@ -1325,7 +1355,7 @@ sub print_form {
call_sub($display_form);
# saving the history
if(!exists $form->{addition}) {
- $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
+ $form->{snumbers} = "${inv}number" . "_" . $form->{"${inv}number"};
$form->{addition} = "PRINTED";
$form->save_history;
}
@@ -1383,7 +1413,7 @@ sub print_form {
# create the form variables
if ($form->{type} =~ /_delivery_order$/) {
- DO->order_details();
+ DO->order_details(\%myconfig, \%$form);
} elsif ($order) {
OE->order_details(\%myconfig, \%$form);
} else {
@@ -1397,7 +1427,7 @@ sub print_form {
$form->get_shipto(\%myconfig);
}
- my @a = qw(name street zipcode city country contact);
+ my @a = qw(name department_1 department_2 street zipcode city country contact phone fax email);
my $shipto = 1;
@@ -1412,8 +1442,8 @@ sub print_form {
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;
}
@@ -1421,8 +1451,6 @@ sub print_form {
$form->{notes} =~ s/^\s+//g;
- $form->{templates} = "$myconfig{templates}";
-
delete $form->{printer_command};
$form->{language} = $form->get_template_language(\%myconfig);
@@ -1446,7 +1474,7 @@ sub print_form {
format_dates($output_dateformat, $output_longdates,
qw(invdate orddate quodate pldate duedate reqdate transdate
shippingdate deliverydate validitydate paymentdate
- datepaid transdate_oe deliverydate_oe
+ datepaid transdate_oe deliverydate_oe dodate
employee_startdate employee_enddate
),
grep({ /^datepaid_\d+$/ ||
@@ -1460,7 +1488,7 @@ sub print_form {
reformat_numbers($output_numberformat, 2,
qw(invtotal ordtotal quototal subtotal linetotal
listprice sellprice netprice discount
- tax taxbase total paid),
+ tax taxbase total paid payment),
grep({ /^(?:linetotal|nodiscount_linetotal|listprice|sellprice|netprice|taxbase|discount|p_discount|discount_sub|nodiscount_sub|paid|subtotal|total|tax)_\d+$/ } keys(%{$form})));
reformat_numbers($output_numberformat, undef,
@@ -1501,14 +1529,8 @@ sub print_form {
push @template_files, "$form->{formname}$form->{language}$printer_code.$extension";
push @template_files, "$form->{formname}.$extension";
push @template_files, "default.$extension";
-
- $form->{IN} = undef;
- for my $filename (@template_files) {
- if (-f "$myconfig{templates}/$filename") {
- $form->{IN} = $filename;
- last;
- }
- }
+ @template_files = uniq @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));
@@ -1517,7 +1539,6 @@ sub print_form {
delete $form->{OUT};
if ($form->{media} eq 'printer') {
- #$form->{OUT} = "| $form->{printer_command} &>/dev/null";
$form->{OUT} = $form->{printer_command};
$form->{OUT_MODE} = '|-';
$form->{printed} .= " $form->{formname}";
@@ -1535,32 +1556,45 @@ sub print_form {
my $emailed = $form->{emailed};
if ($form->{media} eq 'queue') {
- my %queued = map { s|.*/|| } split / /, $form->{queued};
+ my %queued = map { s|.*[/\\]||; $_ } split / /, $form->{queued};
my $filename;
+ my $suffix = ($form->{postscript}) ? '.ps' : '.pdf';
if ($filename = $queued{ $form->{formname} }) {
- $form->{queued} =~ s/\Q$form->{formname} $filename\E//;
unlink $::lx_office_conf{paths}->{spool} . "/$filename";
- $filename =~ s/\..*$//g;
+ delete $queued{ $form->{formname} };
+
+ $form->{queued} = join ' ', %queued;
+ $filename =~ s/\..*$//g;
+ $filename .= $suffix;
+ $form->{OUT} = $::lx_office_conf{paths}->{spool} . "/$filename";
+ $form->{OUT_MODE} = '>';
+
} else {
- $filename = time;
- $filename .= $$;
+ my $temp_fh;
+ ($temp_fh, $filename) = File::Temp::tempfile(
+ 'kivitendo-spoolXXXXXX',
+ SUFFIX => "$suffix",
+ DIR => $::lx_office_conf{paths}->{spool},
+ UNLINK => 0,
+ );
+ close $temp_fh;
+ $form->{OUT} = "$filename";
+ # use >> for OUT_MODE because file is already created by File::Temp
+ $form->{OUT_MODE} = '>>';
+ # strip directory so that only filename is stored in table status
+ ($filename) = $filename =~ /^$::lx_office_conf{paths}->{spool}\/(.*)/;
}
- $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
- $form->{OUT} = $::lx_office_conf{paths}->{spool} . "/$filename";
- $form->{OUT_MODE} = '>';
-
# add type
$form->{queued} .= " $form->{formname} $filename";
-
$form->{queued} =~ s/^ //;
}
my $queued = $form->{queued};
# saving the history
if(!exists $form->{addition}) {
- $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
+ $form->{snumbers} = "${inv}number" . "_" . $form->{"${inv}number"};
if($form->{media} =~ /printer/) {
$form->{addition} = "PRINTED";
}
@@ -1580,11 +1614,12 @@ sub print_form {
# 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}),
+ language => SL::DB::Manager::Language->find_by_or_create(id => $form->{language_id} || undef),
format => $form->{format},
media => $form->{media},
extension => $extension,
- printer => SL::DB::Manager::Printer->find_by_or_create(id => $form->{printer_id}),
+ printer => SL::DB::Manager::Printer->find_by_or_create(id => $form->{printer_id} || undef),
+ today => DateTime->today,
};
$form->parse_template(\%myconfig);
@@ -1752,7 +1787,7 @@ sub set_duedate {
my $invdate = $form->{invdate} eq 'undefined' ? undef : $form->{invdate};
my $duedate = $form->get_duedate(\%myconfig, $invdate);
- print $form->ajax_response_header() . $duedate;
+ print $form->ajax_response_header() . ($duedate || $invdate);
$main::lxdebug->leave_sub();
}
@@ -1772,6 +1807,7 @@ sub _update_part_information {
my $info = $form->{PART_INFORMATION}->{$form->{"id_${i}"}} || { };
$form->{"partunit_${i}"} = $info->{unit};
+ $form->{"weight_$i"} = $info->{weight};
}
$main::lxdebug->leave_sub();
@@ -1880,3 +1916,36 @@ sub _render_custom_variables_inputs {
$main::lxdebug->leave_sub(2);
}
+
+sub _remove_billed_or_delivered_rows {
+ my (%params) = @_;
+
+ croak "Missing parameter 'quantities'" if !$params{quantities};
+
+ my @fields = map { s/_1$//; $_ } grep { m/_1$/ } keys %{ $::form };
+ my @new_rows;
+
+ my $removed_rows = 0;
+ my $row = 0;
+ while ($row < $::form->{rowcount}) {
+ $row++;
+ next unless $::form->{"id_$row"};
+
+ 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;
+
+ 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);
+ push @new_rows, { map { $_ => $::form->{"${_}_${row}"} } @fields };
+
+ } else {
+ $removed_rows++;
+ }
+ }
+
+ $::form->redo_rows(\@fields, \@new_rows, scalar(@new_rows), $::form->{rowcount});
+ $::form->{rowcount} -= $removed_rows;
+}