1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #############################################################################
7 # Changelog: Wann - Wer - Was
8 # Veraendert 2005-01-05 - Marco Welter <mawe@linux-studio.de> - Neue Optik
9 # 08.11.2008 - information@richardson-bueren.de jb - Backport von Revision 7339 xplace - E-Mail-Vorlage automatisch auswählen
10 # 02.02.2009 - information@richardson-bueren.de jb - Backport von Revision 8535 xplace - Erweiterung der Waren bei Lieferantenauftrag um den Eintrag Mindestlagerbestand. Offen: Auswahlliste auf Lieferantenaufträge einschränken -> Erledigt 2.2.09 Prüfung wie das Skript heisst (oe.pl) -> das ist nur die halbe Miete, nochmal mb fragen -> mb gefragt und es gibt die variable is_purchase
11 #############################################################################
12 # SQL-Ledger, Accounting
13 # Copyright (c) 1998-2002
15 # Author: Dieter Simader
16 # Email: dsimader@sql-ledger.org
17 # Web: http://www.sql-ledger.org
20 # This program is free software; you can redistribute it and/or modify
21 # it under the terms of the GNU General Public License as published by
22 # the Free Software Foundation; either version 2 of the License, or
23 # (at your option) any later version.
25 # This program is distributed in the hope that it will be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 # GNU General Public License for more details.
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write to the Free Software
31 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #######################################################################
35 # common routines used in is, ir, oe
37 #######################################################################
41 use List::MoreUtils qw(any uniq apply);
42 use List::Util qw(min max first);
56 use SL::Helper::CreatePDF;
57 use SL::Helper::Flash;
59 require "bin/mozilla/common.pl";
63 # any custom scripts for this one
64 if (-f "bin/mozilla/custom_io.pl") {
65 eval { require "bin/mozilla/custom_io.pl"; };
67 if (-f "bin/mozilla/$::form->{login}_io.pl") {
68 eval { require "bin/mozilla/$::form->{login}_io.pl"; };
75 # this is for our long dates
76 # $locale->text('January')
77 # $locale->text('February')
78 # $locale->text('March')
79 # $locale->text('April')
80 # $locale->text('May ')
81 # $locale->text('June')
82 # $locale->text('July')
83 # $locale->text('August')
84 # $locale->text('September')
85 # $locale->text('October')
86 # $locale->text('November')
87 # $locale->text('December')
89 # this is for our short month
90 # $locale->text('Jan')
91 # $locale->text('Feb')
92 # $locale->text('Mar')
93 # $locale->text('Apr')
94 # $locale->text('May')
95 # $locale->text('Jun')
96 # $locale->text('Jul')
97 # $locale->text('Aug')
98 # $locale->text('Sep')
99 # $locale->text('Oct')
100 # $locale->text('Nov')
101 # $locale->text('Dec')
108 $main::auth->assert('part_service_assembly_edit | vendor_invoice_edit | sales_order_edit | invoice_edit |' .
109 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | ' .
110 'purchase_delivery_order_edit | sales_delivery_order_edit | part_service_assembly_details');
113 ########################################
114 # Eintrag fuer Version 2.2.0 geaendert #
115 # neue Optik im Rechnungsformular #
116 ########################################
118 $main::lxdebug->enter_sub();
122 my $form = $main::form;
123 my %myconfig = %main::myconfig;
124 my $locale = $main::locale;
125 my $cgi = $::request->{cgi};
129 my ($stock_in_out, $stock_in_out_title);
131 my $defaults = AM->get_defaults();
132 $form->{show_weight} = $defaults->{show_weight};
133 $form->{weightunit} = $defaults->{weightunit};
135 my $is_purchase = (first { $_ eq $form->{type} } qw(request_quotation purchase_order purchase_delivery_order)) || ($form->{script} eq 'ir.pl');
136 my $show_min_order_qty = first { $_ eq $form->{type} } qw(request_quotation purchase_order);
137 my $is_delivery_order = $form->{type} =~ /_delivery_order$/;
138 my $is_s_p_order = (first { $_ eq $form->{type} } qw(sales_order purchase_order));
140 if ($is_delivery_order) {
141 if ($form->{type} eq 'sales_delivery_order') {
142 $stock_in_out_title = $locale->text('Release From Stock');
143 $stock_in_out = 'out';
145 $stock_in_out_title = $locale->text('Transfer To Stock');
146 $stock_in_out = 'in';
149 retrieve_partunits();
153 my @header_sort = qw(runningnumber partnumber description ship qty unit weight sellprice discount linetotal);
155 { id => 'runningnumber', width => 5, value => $locale->text('No.'), display => 1, },
156 { id => 'partnumber', width => 8, value => $locale->text('Number'), display => 1, },
157 { id => 'description', width => 30, value => $locale->text('Part Description'), display => 1, },
158 { id => 'ship', width => 5, value => $locale->text('Delivered'), display => $is_s_p_order, },
159 { id => 'qty', width => 5, value => $locale->text('Qty'), display => 1, },
160 { id => 'price_factor', width => 5, value => $locale->text('Price Factor'), display => !$is_delivery_order, },
161 { id => 'unit', width => 5, value => $locale->text('Unit'), display => 1, },
162 { id => 'weight', width => 5, value => $locale->text('Weight'), display => $defaults->{show_weight}, },
163 { id => 'serialnr', width => 10, value => $locale->text('Serial No.'), display => 0, },
164 { id => 'projectnr', width => 10, value => $locale->text('Project'), display => 0, },
165 { id => 'sellprice', width => 15, value => $locale->text('Price'), display => !$is_delivery_order, },
166 { id => 'price_source', width => 5, value => $locale->text('Price Source'), display => !$is_delivery_order, },
167 { id => 'discount', width => 5, value => $locale->text('Discount'), display => !$is_delivery_order, },
168 { id => 'linetotal', width => 10, value => $locale->text('Extended'), display => !$is_delivery_order, },
169 { id => 'bin', width => 10, value => $locale->text('Bin'), display => 0, },
170 { id => 'stock_in_out', width => 10, value => $stock_in_out_title, display => $is_delivery_order, },
172 my @column_index = map { $_->{id} } grep { $_->{display} } @HEADER;
176 my $all_units = AM->retrieve_units(\%myconfig, $form);
178 my %price_factors = map { $_->{id} => $_->{factor} } @{ $form->{ALL_PRICE_FACTORS} };
180 my $colspan = scalar @column_index;
182 $form->{invsubtotal} = 0;
183 map { $form->{"${_}_base"} = 0 } (split(/ /, $form->{taxaccounts}));
186 $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
187 $form->{show_details} = $myconfig{show_form_details} unless (defined($form->{show_details}));
190 # translations, unused commented out
191 # $runningnumber = $locale->text('No.');
192 # my $deliverydate = $locale->text('Delivery Date');
193 my $serialnumber = $locale->text('Serial No.');
194 my $projectnumber = $locale->text('Project');
195 # $partsgroup = $locale->text('Group');
196 my $reqdate = $locale->text('Reqdate');
197 my $deliverydate = $locale->text('Required by');
200 my %align = map { $_ => 'right' } qw(qty ship right discount linetotal stock_in_out weight);
201 my %nowrap = map { $_ => 1 } qw(description unit);
203 $form->{marge_total} = 0;
204 $form->{sellprice_total} = 0;
205 $form->{lastcost_total} = 0;
206 $form->{totalweight} = 0;
207 my %projectnumber_labels = ();
208 my @projectnumber_values = ("");
210 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
211 push(@projectnumber_values, $item->{"id"});
212 $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
215 _update_part_information();
216 _update_ship() if ($is_s_p_order);
217 _update_custom_variables();
221 my $record = _make_record();
225 for my $i (1 .. $numrows) {
226 my %column_data = ();
229 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
230 qw(qty discount sellprice lastcost price_new price_old)
231 unless ($form->{simple_save});
233 if ($form->{"prices_$i"} && ($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"})) {
234 $form->{"sellprice_$i"} = $form->{"price_new_$i"};
237 my $record_item = $record->id && $record->items ? $record->items->[$i-1] : _make_record_item($i);
240 $form->{"unit_old_$i"} ||= $form->{"unit_$i"};
241 $form->{"selected_unit_$i"} ||= $form->{"unit_$i"};
243 if ( !$all_units->{$form->{"selected_unit_$i"}} # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
244 || !AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units)) { # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
245 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"}; # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
248 $form->{"sellprice_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
249 $form->{"lastcost_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
250 $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
252 my $this_unit = $form->{"unit_$i"};
253 $this_unit = $form->{"selected_unit_$i"} if AM->convert_unit($this_unit, $form->{"selected_unit_$i"}, $all_units);
255 if (0 < scalar @{ $form->{ALL_PRICE_FACTORS} }) {
256 my @values = ('', map { $_->{id} } @{ $form->{ALL_PRICE_FACTORS} });
257 my %labels = map { $_->{id} => $_->{description} } @{ $form->{ALL_PRICE_FACTORS} };
259 $column_data{price_factor} =
260 NTI($cgi->popup_menu('-name' => "price_factor_id_$i",
261 '-default' => $form->{"price_factor_id_$i"},
262 '-values' => \@values,
263 '-labels' => \%labels,
264 '-style' => 'width:90px'));
266 $column_data{price_factor} = ' ';
268 $form->{"weight_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"partunit_$i"}, $all_units) || 1;
270 $column_data{"unit"} = AM->unit_select_html($all_units, "unit_$i", $this_unit, $form->{"id_$i"} ? $form->{"unit_$i"} : undef);
273 #count the max of decimalplaces of sellprice and lastcost, so the same number of decimalplaces
274 #is shown for lastcost and sellprice.
275 my $decimalplaces = ($form->{"sellprice_$i"} =~ /\.(\d+)/) ? max 2, length $1 : 2;
276 $decimalplaces = ($form->{"lastcost_$i"} =~ /\.(\d+)/) ? max $decimalplaces, length $1 : $decimalplaces;
278 my $price_factor = $price_factors{$form->{"price_factor_id_$i"}} || 1;
279 my $discount = $form->round_amount($form->{"qty_$i"} * $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100 / $price_factor, 2);
280 my $linetotal = $form->round_amount($form->{"qty_$i"} * $form->{"sellprice_$i"} * (100 - $form->{"discount_$i"}) / 100 / $price_factor, 2);
281 my $rows = $form->numtextrows($form->{"description_$i"}, 30, 6);
283 # quick delete single row
284 $column_data{runningnumber} .= q|<a onclick= "$('#partnumber_| . $i . q|').val(''); $('#update_button').click();">| .
285 q|<img height="10px" width="10px" src="image/cross.png" alt="| . $locale->text('Remove') . q|"></a> |;
286 $column_data{runningnumber} .= $cgi->textfield(-name => "runningnumber_$i", -id => "runningnumber_$i", -size => 5, -value => $i); # HuT
289 $column_data{partnumber} = $cgi->textfield(-name => "partnumber_$i", -id => "partnumber_$i", -size => 12, -value => $form->{"partnumber_$i"});
290 $column_data{description} = (($rows > 1) # if description is too large, use a textbox instead
291 ? $cgi->textarea( -name => "description_$i", -id => "description_$i", -default => $form->{"description_$i"}, -rows => $rows, -columns => 30)
292 : $cgi->textfield(-name => "description_$i", -id => "description_$i", -value => $form->{"description_$i"}, -size => 30))
293 . $cgi->button(-value => $locale->text('L'), -onClick => "kivi.SalesPurchase.edit_longdescription($i)");
295 my $qty_dec = ($form->{"qty_$i"} =~ /\.(\d+)/) ? length $1 : 2;
297 $column_data{qty} = $cgi->textfield(-name => "qty_$i", -size => 5, -value => $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec));
298 $column_data{qty} .= $cgi->button(-onclick => "calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)", -value => $locale->text('*/'))
299 . $cgi->hidden(-name => "formel_$i", -value => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"})
300 if $form->{"formel_$i"};
302 $column_data{ship} = '';
303 if ($form->{"id_$i"}) {
304 my $ship_qty = $form->{"ship_$i"} * 1;
305 $ship_qty *= $all_units->{$form->{"partunit_$i"}}->{factor};
306 $ship_qty /= ( $all_units->{$form->{"unit_$i"}}->{factor} || 1 );
308 $column_data{ship} = $form->format_amount(\%myconfig, $form->round_amount($ship_qty, 2) * 1) . ' ' . $form->{"unit_$i"};
311 my $sellprice_value = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
312 my $edit_prices = $main::auth->assert('edit_prices', 1) && !$::form->{"active_price_source_$i"};
313 $column_data{sellprice} = (!$edit_prices)
314 ? $cgi->hidden( -name => "sellprice_$i", -id => "sellprice_$i", -value => $sellprice_value) . $sellprice_value
315 : $cgi->textfield(-name => "sellprice_$i", -id => "sellprice_$i", -size => 10, -onBlur => "check_right_number_format(this)", -value => $sellprice_value);
316 $column_data{discount} = (!$edit_prices)
317 ? $cgi->textfield(-readonly => "readonly",
318 -name => "discount_$i", -size => 3, -value => $form->format_amount(\%myconfig, $form->{"discount_$i"}))
319 : $cgi->textfield(-name => "discount_$i", -size => 3, -value => $form->format_amount(\%myconfig, $form->{"discount_$i"}));
320 $column_data{linetotal} = $form->format_amount(\%myconfig, $linetotal, 2);
321 $column_data{bin} = $form->{"bin_$i"};
323 $column_data{weight} = $form->format_amount(\%myconfig, $form->{"qty_$i"} * $form->{"weight_$i"}, 3) . ' ' . $defaults->{weightunit} if $defaults->{show_weight};
325 if ($form->{"id_${i}"}) {
326 my $price_source = SL::PriceSource->new(record_item => $record_item, record => $record);
327 my $price = $price_source->price_from_source($::form->{"active_price_source_$i"});
328 $::form->{price_sources}[$i] = $price_source;
329 $column_data{price_source} .= $cgi->button(-value => $price->full_description, -onClick => "toggle_price_source($i)");
332 if ($is_delivery_order) {
333 $column_data{stock_in_out} = calculate_stock_in_out($i);
336 my @ROW1 = map { value => $column_data{$_}, align => $align{$_}, nowrap => $nowrap{$_} }, @column_index;
340 push @ROW2, { value => qq|<b>$serialnumber</b> <input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}">| }
341 if $form->{type} !~ /_quotation/;
342 push @ROW2, { value => qq|<b>$projectnumber</b> | . NTI($cgi->popup_menu('-name' => "project_id_$i", '-values' => \@projectnumber_values,
343 '-labels' => \%projectnumber_labels, '-default' => $form->{"project_id_$i"})) };
344 push @ROW2, { value => qq|<b>$reqdate</b> <input name="reqdate_$i" size="11" onBlur="check_right_date_format(this)" value="$form->{"reqdate_$i"}">| }
345 if ($form->{type} =~ /order/ || $form->{type} =~ /invoice/);
346 push @ROW2, { value => sprintf qq|<b>%s</b> <input type="checkbox" name="subtotal_$i" value="1" %s>|,
347 $locale->text('Subtotal'), $form->{"subtotal_$i"} ? 'checked' : '' };
349 # begin marge calculations
350 $form->{"lastcost_$i"} *= 1;
351 $form->{"marge_percent_$i"} = 0;
355 if ( $form->{taxincluded} and $form->{"qty_$i"} * 1 and $form->{$form->{"taxaccounts_$i"} . "_rate"} * 1) {
356 # if we use taxincluded we need to calculate the marge from the net_value
357 # all the marge calculations are based on linetotal which we need to
358 # convert to net first
360 # there is no direct form value for the tax_rate of the item, but
361 # form->{taxaccounts_$i} gives the tax account (e.g. 3806) and 3806_rate
362 # gives the tax percentage (e.g. 0.19)
363 $real_sellprice = $linetotal / (1 + $form->{$form->{"taxaccounts_$i"} . "_rate"});
365 $real_sellprice = $linetotal;
367 my $real_lastcost = $form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"} / $price_factor, 2);
368 my $marge_percent_warn = $myconfig{marge_percent_warn} * 1 || 15;
369 my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
371 if ($real_sellprice * 1 && ($form->{"qty_$i"} * 1)) {
372 $form->{"marge_percent_$i"} = ($real_sellprice - $real_lastcost) * 100 / $real_sellprice;
373 $marge_color = 'color="#ff0000"' if $form->{"id_$i"} && $form->{"marge_percent_$i"} < $marge_percent_warn;
376 $form->{"marge_absolut_$i"} = ($real_sellprice - $real_lastcost) * $marge_adjust_credit_note;
377 $form->{"marge_total"} += $form->{"marge_absolut_$i"};
378 $form->{"lastcost_total"} += $real_lastcost;
379 $form->{"sellprice_total"} += $real_sellprice;
381 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(marge_absolut marge_percent);
383 push @ROW2, { value => sprintf qq|
384 <font %s><b>%s</b> %s %s%% </font>
386 <b>%s</b> <input size="5" name="lastcost_$i" value="%s">|,
387 $marge_color, $locale->text('Ertrag'),$form->{"marge_absolut_$i"}, $form->{"marge_percent_$i"},
388 $locale->text('LP'), $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2),
389 $locale->text('EK'), $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces) }
390 if $form->{"id_$i"} && ($form->{type} =~ /^sales_/ || $form->{type} =~ /invoice/ || $form->{type} =~ /^credit_note$/ ) && !$is_delivery_order;
392 $form->{"listprice_$i"} = $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2)
393 if $form->{"id_$i"} && ($form->{type} =~ /^sales_/ || $form->{type} =~ /invoice/) ;
394 # / marge calculations ending
396 # Calculate total weight
397 $totalweight += ($form->{"qty_$i"} * $form->{"weight_$i"});
400 if ($form->{"id_$i"}) {
401 my $part = IC->get_basic_part_info(id => $form->{"id_$i"});
402 my $onhand_color = $part->{onhand} < $part->{rop} ? 'color="#ff0000"' : '';
403 push @ROW2, { value => sprintf "<b>%s</b> <font %s>%s %s</font>",
404 $locale->text('On Hand'),
406 $form->format_amount(\%myconfig, $part->{onhand}, 2),
414 if ($is_delivery_order) {
415 map { $form->{"${_}_${i}"} = $form->format_amount(\%myconfig, $form->{"${_}_${i}"}) } qw(sellprice discount lastcost);
416 push @hidden_vars, grep { defined $form->{"${_}_${i}"} } qw(sellprice discount not_discountable price_factor_id lastcost);
417 push @hidden_vars, "stock_${stock_in_out}_sum_qty", "stock_${stock_in_out}";
420 my @HIDDENS = map { value => $_}, (
421 $cgi->hidden("-name" => "unit_old_$i", "-value" => $form->{"selected_unit_$i"}),
422 $cgi->hidden("-name" => "price_new_$i", "-value" => $form->format_amount(\%myconfig, $form->{"price_new_$i"})),
423 map { ($cgi->hidden("-name" => $_, "-id" => $_, "-value" => $form->{$_})); } map { $_."_$i" }
424 (qw(orderitems_id bo price_old id inventory_accno bin partsgroup partnotes active_price_source
425 income_accno expense_accno listprice assembly taxaccounts ordnumber donumber transdate cusordnumber
426 longdescription basefactor marge_absolut marge_percent marge_price_factor weight), @hidden_vars)
429 map { $form->{"${_}_base"} += $linetotal } (split(/ /, $form->{"taxaccounts_$i"}));
431 $form->{invsubtotal} += $linetotal;
433 # Benutzerdefinierte Variablen für Waren/Dienstleistungen/Erzeugnisse
434 _render_custom_variables_inputs(ROW2 => \@ROW2, row => $i, part_id => $form->{"id_$i"});
436 push @ROWS, { ROW1 => \@ROW1, ROW2 => \@ROW2, HIDDENS => \@HIDDENS, colspan => $colspan, error => $form->{"row_error_$i"}, obj => $record_item };
439 $form->{totalweight} = $totalweight;
441 print $form->parse_html_template('oe/sales_order', { ROWS => \@ROWS,
445 if (0 != ($form->{sellprice_total} * 1)) {
446 $form->{marge_percent} = ($form->{sellprice_total} - $form->{lastcost_total}) / $form->{sellprice_total} * 100;
449 $main::lxdebug->leave_sub();
453 $main::lxdebug->enter_sub();
456 my $mode = $params{mode} || croak "Missing parameter 'mode'";
460 my $previous_form = $::auth->save_form_in_session(form => $::form);
461 $::form->{title} = $::locale->text('Select from one of the items below');
464 my @item_list = map {
465 $_->{display_sellprice} = $_->{sellprice} * (1 - $::form->{tradediscount});
466 $_->{display_sellprice} /= $_->{price_factor} if ($_->{price_factor});
468 } @{ $::form->{item_list} };
470 # delete action variable
471 delete @{$::form}{qw(action item_list)};
473 print $::form->parse_html_template('io/select_item', { PREVIOUS_FORM => $previous_form,
475 ITEM_LIST => \@item_list,
476 IS_PURCHASE => $mode eq 'IS' });
478 $main::lxdebug->leave_sub();
482 $main::lxdebug->enter_sub();
484 my $form = $main::form;
485 my %myconfig = %main::myconfig;
489 $::auth->restore_form_from_session($form->{select_item_previous_form} || croak('Missing previous form ID'), form => $form);
491 my $mode = delete($form->{select_item_mode}) || croak 'Missing item selection mode';
492 my $id = delete($form->{select_item_id}) || croak 'Missing item selection ID';
493 my $i = $form->{ $mode eq 'IC' ? 'assembly_rows' : 'rowcount' };
495 $form->{"id_${i}"} = $id;
498 IS->retrieve_item(\%myconfig, \%$form);
499 } elsif ($mode eq 'IR') {
500 IR->retrieve_item(\%myconfig, \%$form);
501 } elsif ($mode eq 'IC') {
502 IC->assembly_item(\%myconfig, \%$form);
504 croak "Invalid item selection mode '${mode}'";
507 my $new_item = $form->{item_list}->[0] || croak "No item found for mode '${mode}' and ID '${id}'";
509 # if there was a price entered, override it
510 my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
513 qw(id partnumber description sellprice listprice inventory_accno
514 income_accno expense_accno bin unit weight assembly taxaccounts
515 partsgroup formel longdescription not_discountable partnotes lastcost
516 price_factor_id price_factor);
518 my $ic_cvar_configs = CVar->get_configs(module => 'IC');
519 push @new_fields, map { "ic_cvar_$_->{name}" } @{ $ic_cvar_configs };
521 map { $form->{"${_}_$i"} = $new_item->{$_} } @new_fields;
523 my $record = _make_record();
524 my $price_source = SL::PriceSource->new(record_item => $record->items->[$i-1], record => $record);
525 my $best_price = $price_source->best_price;
528 $::form->{"sellprice_$i"} = $best_price->price;
529 $::form->{"active_price_source_$i"} = $best_price->source;
533 $form->{"marge_price_factor_$i"} = $new_item->{price_factor};
535 if ($form->{"part_payment_id_$i"} ne "") {
536 $form->{payment_id} = $form->{"part_payment_id_$i"};
539 my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
541 my $decimalplaces = ($dec > 2) ? $dec : 2;
544 $form->{"sellprice_$i"} = $sellprice;
547 # if there is an exchange rate adjust sellprice
548 if (($form->{exchangerate} * 1) != 0) {
549 $form->{"sellprice_$i"} /= $form->{exchangerate};
550 $form->{"sellprice_$i"} =
551 $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
555 if ($::form->{tradediscount}) {
556 $::form->{"sellprice_$i"} *= 1 - $::form->{tradediscount};
560 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
561 qw(sellprice listprice weight);
563 $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
565 if ($form->{"not_discountable_$i"}) {
566 $form->{"discount_$i"} = 0;
570 $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
572 map { $form->{"${_}_base"} += $amount }
573 (split / /, $form->{"taxaccounts_$i"});
574 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
575 $form->{"taxaccounts_$i"}
576 if !$form->{taxincluded};
578 $form->{creditremaining} -= $amount;
580 $form->{"runningnumber_$i"} = $i;
582 delete $form->{nextsub};
587 $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
588 } qw(sellprice listprice lastcost) if $form->{item} ne 'assembly';
592 $main::lxdebug->leave_sub();
596 $main::lxdebug->enter_sub();
598 my $form = $main::form;
599 my %myconfig = %main::myconfig;
603 my $price_key = ($form->{type} =~ m/request_quotation|purchase_order/) || ($form->{script} eq 'ir.pl') ? 'lastcost' : 'sellprice';
606 $form->{old_callback} = $form->escape($form->{callback}, 1);
607 $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
609 # save all form variables except action in the session and keep the key in the previousform variable
610 my $previousform = $::auth->save_form_in_session(skip_keys => [ qw(action) ]);
613 push @HIDDENS, { 'name' => 'previousform', 'value' => $previousform };
614 push @HIDDENS, map +{ 'name' => $_, 'value' => $form->{$_} }, qw(rowcount vc);
615 push @HIDDENS, map +{ 'name' => $_, 'value' => $form->{"${_}_$form->{rowcount}"} }, qw(partnumber description unit);
616 push @HIDDENS, { 'name' => 'taxaccount2', 'value' => $form->{taxaccounts} };
617 push @HIDDENS, { 'name' => $price_key, 'value' => $form->parse_amount(\%myconfig, $form->{"sellprice_$form->{rowcount}"}) };
618 push @HIDDENS, { 'name' => 'notes', 'value' => $form->{"longdescription_$form->{rowcount}"} };
621 print $form->parse_html_template("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } );
623 $main::lxdebug->leave_sub();
627 $main::lxdebug->enter_sub();
629 my $form = $main::form;
630 my %myconfig = %main::myconfig;
637 # remove any makes or model rows
638 if ($form->{item} eq 'assembly') {
640 # fuer assemblies auskommentiert. seiteneffekte? ;-) wird die woanders benoetigt?
641 #$form->{sellprice} = 0;
643 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
644 qw(listprice sellprice rop stock);
646 my @flds = qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup lastcost);
648 for my $i (1 .. ($form->{assembly_rows} - 1)) {
649 if ($form->{"qty_$i"}) {
653 $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
655 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
657 #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
659 # fuer assemblies auskommentiert. siehe oben
660 # $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"} / ($form->{"price_factor_$i"} || 1));
661 $form->{weight} += ($form->{"qty_$i"} * $form->{"weight_$i"} / ($form->{"price_factor_$i"} || 1));
665 # kann das hier auch weg? s.o. jb
666 $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
668 $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
669 $form->{assembly_rows} = $count;
671 } elsif ($form->{item} !~ m{^(?:part|service)$}) {
672 remove_emptied_rows(1);
674 $form->{creditremaining} -= &invoicetotal;
679 if ( $form->{type} =~ (/sales_quotation/)
680 or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/))
681 or (($form->{level} eq undef) and ($form->{type} =~ /invoice/))
682 or ($form->{type} =~ /sales_order/)) {
688 $main::lxdebug->leave_sub();
691 sub remove_emptied_rows {
692 my $dont_add_empty = shift;
695 return unless $form->{rowcount};
697 my @flds = qw(id partnumber description qty ship sellprice unit
698 discount inventory_accno income_accno expense_accno listprice
699 taxaccounts bin assembly weight projectnumber project_id
700 oldprojectnumber runningnumber serialnumber partsgroup payment_id
701 not_discountable shop ve gv buchungsgruppen_id language_values
702 price_old price_new unit_old ordnumber donumber
703 transdate longdescription basefactor marge_total marge_percent
704 marge_price_factor lastcost price_factor_id partnotes
705 stock_out stock_in has_sernumber reqdate orderitems_id);
707 my $ic_cvar_configs = CVar->get_configs(module => 'IC');
708 push @flds, map { "ic_cvar_$_->{name}" } @{ $ic_cvar_configs };
711 for my $i (1 .. $form->{rowcount} - 1) {
712 next unless $form->{"partnumber_$i"};
714 push @new_rows, { map { $_ => $form->{"${_}_$i" } } @flds };
717 my $new_rowcount = scalar @new_rows;
718 $form->redo_rows(\@flds, \@new_rows, $new_rowcount, $form->{rowcount});
719 $form->{rowcount} = $new_rowcount + ($dont_add_empty ? 0 : 1);
723 $main::lxdebug->enter_sub();
725 my $form = $main::form;
726 my %myconfig = %main::myconfig;
730 $form->{oldinvtotal} = 0;
732 # add all parts and deduct paid
733 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
735 my ($amount, $sellprice, $discount, $qty);
737 for my $i (1 .. $form->{rowcount}) {
738 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
739 $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
740 $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
742 #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
744 $amount = $sellprice * (1 - $discount / 100) * $qty;
745 map { $form->{"${_}_base"} += $amount }
746 (split (/ /, $form->{"taxaccounts_$i"}));
747 $form->{oldinvtotal} += $amount;
750 map { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
751 split(/ /, $form->{taxaccounts})
752 if !$form->{taxincluded};
754 $form->{oldtotalpaid} = 0;
755 for my $i (1 .. $form->{paidaccounts}) {
756 $form->{oldtotalpaid} += $form->{"paid_$i"};
759 $main::lxdebug->leave_sub();
762 return ($form->{oldinvtotal} - $form->{oldtotalpaid});
766 $main::lxdebug->enter_sub();
768 my $form = $main::form;
769 my $locale = $main::locale;
773 # check if items are valid
774 if ($form->{rowcount} == 1) {
775 flash('warning', $::locale->text('The action you\'ve chosen has not been executed because the document does not contain any item yet.'));
780 for my $i (1 .. $form->{rowcount} - 1) {
781 $form->isblank("partnumber_$i",
782 $locale->text('Number missing in Row') . " $i");
785 $main::lxdebug->leave_sub();
789 $main::lxdebug->enter_sub();
791 my $form = $main::form;
792 my %myconfig = %main::myconfig;
793 my $locale = $main::locale;
797 if ($form->{second_run}) {
798 $form->{print_and_post} = 0;
800 $form->{ordnumber} = $form->{invnumber};
802 $form->{old_employee_id} = $form->{employee_id};
803 $form->{old_salesman_id} = $form->{salesman_id};
805 map { delete $form->{$_} } qw(id printed emailed queued);
807 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
808 $form->{title} = $locale->text('Add Purchase Order');
809 $form->{vc} = 'vendor';
810 $form->{type} = 'purchase_order';
813 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_quotation') {
814 $form->{title} = $locale->text('Add Sales Order');
815 $form->{vc} = 'customer';
816 $form->{type} = 'sales_order';
819 $form->{script} = 'oe.pl';
825 require "bin/mozilla/$form->{script}";
826 my $script = $form->{"script"};
829 $locale = new Locale($::lx_office_conf{system}->{language}, $script);
831 map { $form->{"select$_"} = "" } ($form->{vc}, "currency");
833 my $currency = $form->{currency};
837 $form->{currency} = $currency;
838 $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
839 $form->{exchangerate} = $form->{forex} || '';
841 for my $i (1 .. $form->{rowcount}) {
842 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"})
843 if ($form->{"${_}_${i}"}) }
844 qw(ship qty sellprice listprice basefactor discount));
850 $main::lxdebug->leave_sub();
854 $main::lxdebug->enter_sub();
856 my $form = $main::form;
857 my %myconfig = %main::myconfig;
858 my $locale = $main::locale;
862 # we are coming from *_order and convert to quotation
863 # it seems that quotation is only called if we have a existing order
864 if ($form->{type} =~ /(sales|purchase)_order/) {
865 delete $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"};
867 if ($form->{second_run}) {
868 $form->{print_and_post} = 0;
870 map { delete $form->{$_} } qw(id printed emailed queued);
873 if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
874 $form->{title} = $locale->text('Add Request for Quotation');
875 $form->{vc} = 'vendor';
876 $form->{type} = 'request_quotation';
879 if ($form->{script} eq 'is.pl' || $form->{type} eq 'sales_order') {
880 $form->{title} = $locale->text('Add Quotation');
881 $form->{vc} = 'customer';
882 $form->{type} = 'sales_quotation';
888 $form->{script} = 'oe.pl';
892 require "bin/mozilla/$form->{script}";
894 map { $form->{"select$_"} = "" } ($form->{vc}, "currency");
896 my $currency = $form->{currency};
900 $form->{currency} = $currency;
901 $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, $buysell);
902 $form->{exchangerate} = $form->{forex} || '';
904 for my $i (1 .. $form->{rowcount}) {
905 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
906 $form->{"${_}_${i}"})
907 if ($form->{"${_}_${i}"}) }
908 qw(ship qty sellprice listprice basefactor discount lastcost));
914 $main::lxdebug->leave_sub();
917 sub request_for_quotation {
922 $main::lxdebug->enter_sub();
924 my $form = $main::form;
925 my %myconfig = %main::myconfig;
926 my $locale = $main::locale;
930 if ($form->{second_run}) {
931 $form->{print_and_post} = 0;
932 $form->{resubmit} = 0;
935 $form->{email} = $form->{shiptoemail} if $form->{shiptoemail} && $form->{formname} =~ /(pick|packing|bin)_list/;
937 if ($form->{"cp_id"}) {
938 CT->get_contact(\%myconfig, $form);
939 $form->{"email"} = $form->{"cp_email"} if $form->{"cp_email"};
942 $form->{language} = $form->get_template_language(\%myconfig);
943 $form->{language} = "_" . $form->{language} if $form->{language};
945 my $title = $locale->text('E-mail') . " " . $form->get_formname_translation();
947 $form->{oldmedia} = $form->{media};
948 $form->{media} = "email";
950 my $global_bcc = AM->get_defaults()->{global_bcc};
952 $form->{bcc} = join ', ', grep $_, $form->{bcc}, $global_bcc;
954 my $attachment_filename = $form->generate_attachment_filename();
955 my $subject = $form->{subject} || $form->generate_email_subject();
959 my (@dont_hide_key_list, %dont_hide_key, @hidden_keys);
960 @dont_hide_key_list = qw(action email cc bcc subject message sendmode format header override login password);
961 @dont_hide_key{@dont_hide_key_list} = (1) x @dont_hide_key_list;
962 @hidden_keys = sort grep { !$dont_hide_key{$_} } grep { !ref $form->{$_} } keys %$form;
964 print $form->parse_html_template('generic/edit_email',
966 a_filename => $attachment_filename,
968 print_options => print_options('inline' => 1),
969 HIDDEN => [ map +{ name => $_, value => $form->{$_} }, @hidden_keys ],
970 SHOW_BCC => $::auth->assert('email_bcc', 'may fail') });
972 $main::lxdebug->leave_sub();
976 $main::lxdebug->enter_sub();
978 my $form = $main::form;
979 my %myconfig = %main::myconfig;
983 my $callback = $form->{script} . "?action=edit";
984 map({ $callback .= "\&${_}=" . E($form->{$_}); } qw(type id));
986 print_form("return");
988 Common->save_email_status(\%myconfig, $form);
990 $form->{callback} = $callback;
993 $main::lxdebug->leave_sub();
996 # generate the printing options displayed at the bottom of oe and is forms.
997 # this function will attempt to guess what type of form is displayed, and will generate according options
1000 # this version builds the arrays of options pretty directly. if you have trouble understanding how,
1001 # the opthash function builds hashrefs which are then pieced together for the template arrays.
1002 # unneeded options are "undef"ed out, and then grepped out.
1004 # the inline options is untested, but intended to be used later in metatemplating
1006 $main::lxdebug->enter_sub();
1008 my $form = $main::form;
1009 my %myconfig = %main::myconfig;
1010 my $locale = $main::locale;
1016 # names 3 parameters and returns a hashref, for use in templates
1017 sub opthash { +{ value => shift, selected => shift, oname => shift } }
1018 my (@FORMNAME, @LANGUAGE_ID, @FORMAT, @SENDMODE, @MEDIA, @PRINTER_ID, @SELECTS) = ();
1020 # note: "||"-selection is only correct for values where "0" is _not_ a correct entry
1021 $form->{sendmode} = "attachment";
1022 $form->{format} = $form->{format} || $myconfig{template_format} || "pdf";
1023 $form->{copies} = $form->{copies} || $myconfig{copies} || 3;
1024 $form->{media} = $form->{media} || $myconfig{default_media} || "screen";
1025 $form->{printer_id} = defined $form->{printer_id} ? $form->{printer_id} :
1026 defined $myconfig{default_printer_id} ? $myconfig{default_printer_id} : "";
1028 $form->{PD}{ $form->{formname} } = "selected";
1029 $form->{DF}{ $form->{format} } = "selected";
1030 $form->{OP}{ $form->{media} } = "selected";
1031 $form->{SM}{ $form->{formname} } = "selected";
1033 push @FORMNAME, grep $_,
1034 ($form->{type} eq 'purchase_order') ? (
1035 opthash("purchase_order", $form->{PD}{purchase_order}, $locale->text('Purchase Order')),
1036 opthash("bin_list", $form->{PD}{bin_list}, $locale->text('Bin List'))
1038 ($form->{type} eq 'credit_note') ?
1039 opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef,
1040 ($form->{type} eq 'sales_order') ? (
1041 opthash("sales_order", $form->{PD}{sales_order}, $locale->text('Confirmation')),
1042 opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
1044 ($form->{type} =~ /sales_quotation$/) ?
1045 opthash('sales_quotation', $form->{PD}{sales_quotation}, $locale->text('Quotation')) : undef,
1046 ($form->{type} =~ /request_quotation$/) ?
1047 opthash('request_quotation', $form->{PD}{request_quotation}, $locale->text('Request for Quotation')) : undef,
1048 ($form->{type} eq 'invoice') ? (
1049 opthash("invoice", $form->{PD}{invoice}, $locale->text('Invoice')),
1050 opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
1052 ($form->{type} eq 'invoice' && $form->{storno}) ? (
1053 opthash("storno_invoice", $form->{PD}{storno_invoice}, $locale->text('Storno Invoice')),
1055 ($form->{type} =~ /_delivery_order$/) ? (
1056 opthash($form->{type}, $form->{PD}{$form->{type}}, $locale->text('Delivery Order')),
1057 opthash('pick_list', $form->{PD}{pick_list}, $locale->text('Pick List')),
1061 opthash("attachment", $form->{SM}{attachment}, $locale->text('Attachment')),
1062 opthash("inline", $form->{SM}{inline}, $locale->text('In-line'))
1063 if ($form->{media} eq 'email');
1065 my $printable_templates = any { $::lx_office_conf{print_templates}->{$_} } qw(latex opendocument);
1066 push @MEDIA, grep $_,
1067 opthash("screen", $form->{OP}{screen}, $locale->text('Screen')),
1068 ($printable_templates && $form->{printers} && scalar @{ $form->{printers} }) ?
1069 opthash("printer", $form->{OP}{printer}, $locale->text('Printer')) : undef,
1070 ($printable_templates && !$options{no_queue}) ?
1071 opthash("queue", $form->{OP}{queue}, $locale->text('Queue')) : undef
1072 if ($form->{media} ne 'email');
1074 push @FORMAT, grep $_,
1075 ($::lx_office_conf{print_templates}->{opendocument} && $::lx_office_conf{applications}->{openofficeorg_writer} && $::lx_office_conf{applications}->{xvfb}
1076 && (-x $::lx_office_conf{applications}->{openofficeorg_writer}) && (-x $::lx_office_conf{applications}->{xvfb})
1077 && !$options{no_opendocument_pdf}) ?
1078 opthash("opendocument_pdf", $form->{DF}{"opendocument_pdf"}, $locale->text("PDF (OpenDocument/OASIS)")) : undef,
1079 ($::lx_office_conf{print_templates}->{latex}) ?
1080 opthash("pdf", $form->{DF}{pdf}, $locale->text('PDF')) : undef,
1081 ($::lx_office_conf{print_templates}->{latex} && !$options{no_postscript}) ?
1082 opthash("postscript", $form->{DF}{postscript}, $locale->text('Postscript')) : undef,
1083 (!$options{no_html}) ?
1084 opthash("html", $form->{DF}{html}, "HTML") : undef,
1085 ($::lx_office_conf{print_templates}->{opendocument} && !$options{no_opendocument}) ?
1086 opthash("opendocument", $form->{DF}{opendocument}, $locale->text("OpenDocument/OASIS")) : undef,
1087 ($::lx_office_conf{print_templates}->{excel} && !$options{no_excel}) ?
1088 opthash("excel", $form->{DF}{excel}, $locale->text("Excel")) : undef;
1091 map { opthash($_->{id}, ($_->{id} eq $form->{language_id} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{languages} }
1092 if (ref $form->{languages} eq 'ARRAY');
1095 map { opthash($_->{id}, ($_->{id} eq $form->{printer_id} ? 'selected' : ''), $_->{printer_description}) } +{}, @{ $form->{printers} }
1096 if ((ref $form->{printers} eq 'ARRAY') && scalar @{ $form->{printers } });
1101 show => !$options{"hide_" . $_->[1]} && scalar @{ $_->[0] }
1103 [ \@FORMNAME, 'formname', ],
1104 [ \@LANGUAGE_ID, 'language_id', ],
1105 [ \@FORMAT, 'format', ],
1106 [ \@SENDMODE, 'sendmode', ],
1107 [ \@MEDIA, 'media', ],
1108 [ \@PRINTER_ID, 'printer_id', ];
1110 my %dont_display_groupitems = (
1114 my %template_vars = (
1115 display_copies => scalar @{ $form->{printers} || [] } && $::lx_office_conf{print_templates}->{latex} && $form->{media} ne 'email',
1116 display_remove_draft => (!$form->{id} && $form->{draft_id}),
1117 display_groupitems => !$dont_display_groupitems{$form->{type}},
1118 groupitems_checked => $form->{groupitems} ? "checked" : '',
1119 remove_draft_checked => $form->{remove_draft} ? "checked" : ''
1122 my $print_options = $form->parse_html_template("generic/print_options", { SELECTS => \@SELECTS, %template_vars } );
1124 if ($options{inline}) {
1125 $main::lxdebug->leave_sub();
1126 return $print_options;
1129 print $print_options;
1131 $main::lxdebug->leave_sub();
1135 $main::lxdebug->enter_sub();
1137 my $form = $main::form;
1138 my $locale = $main::locale;
1142 if ($form->{print_nextsub}) {
1143 call_sub($form->{print_nextsub});
1144 $main::lxdebug->leave_sub();
1148 # if this goes to the printer pass through
1150 if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
1151 $form->error($locale->text('Select postscript or PDF!'))
1152 if ($form->{format} !~ /(postscript|pdf)/);
1154 $old_form = new Form;
1155 map { $old_form->{$_} = $form->{$_} } keys %$form;
1158 if (!$form->{id} || (($form->{formname} eq "proforma") && !$form->{proforma} && (($form->{type} =~ /_order$/) || ($form->{type} =~ /_quotation$/)))) {
1159 if ($form->{formname} eq "proforma") {
1160 $form->{proforma} = 1;
1162 $form->{print_and_save} = 1;
1163 my $formname = $form->{formname};
1165 $form->{formname} = $formname;
1167 $::lxdebug->leave_sub();
1171 &print_form($old_form);
1173 $main::lxdebug->leave_sub();
1177 $main::lxdebug->enter_sub();
1179 my $form = $main::form;
1180 my %myconfig = %main::myconfig;
1181 my $locale = $main::locale;
1185 my $defaults = SL::DB::Default->get;
1186 $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
1187 $form->{templates} = $defaults->templates;
1189 my ($old_form, %params) = @_;
1193 my $numberfld = "invnumber";
1197 ($form->{display_form}) ? $form->{display_form} : "display_form";
1199 # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
1200 $form->{ $form->{"formname"} . "notes" } = $form->{"notes"};
1202 if ($form->{formname} eq "invoice") {
1203 $form->{label} = $locale->text('Invoice');
1205 if ($form->{formname} eq 'sales_order') {
1208 $form->{"${inv}date"} = $form->{transdate};
1209 $form->{label} = $locale->text('Confirmation');
1210 $numberfld = "sonumber";
1214 if (($form->{type} eq 'invoice') && ($form->{formname} eq 'proforma') ) {
1217 $form->{"${inv}date"} = $form->{invdate};
1218 $form->{label} = $locale->text('Proforma Invoice');
1219 $numberfld = "sonumber";
1223 if (($form->{type} eq 'sales_order') && ($form->{formname} eq 'proforma') ) {
1226 $form->{"${inv}date"} = $form->{transdate};
1227 $form->{"invdate"} = $form->{transdate};
1228 $form->{invnumber} = $form->{ordnumber};
1229 $form->{label} = $locale->text('Proforma Invoice');
1230 $numberfld = "sonumber";
1234 if ($form->{formname} eq 'purchase_order') {
1237 $form->{"${inv}date"} = $form->{transdate};
1238 $form->{label} = $locale->text('Purchase Order');
1239 $numberfld = "ponumber";
1242 if ($form->{formname} eq 'bin_list') {
1245 $form->{"${inv}date"} = $form->{transdate};
1246 $form->{label} = $locale->text('Bin List');
1249 if ($form->{formname} eq 'sales_quotation') {
1252 $form->{"${inv}date"} = $form->{transdate};
1253 $form->{label} = $locale->text('Quotation');
1254 $numberfld = "sqnumber";
1258 if (($form->{type} eq 'sales_quotation') && ($form->{formname} eq 'proforma') ) {
1261 $form->{"${inv}date"} = $form->{transdate};
1262 $form->{"invdate"} = $form->{transdate};
1263 $form->{label} = $locale->text('Proforma Invoice');
1264 $numberfld = "sqnumber";
1268 if ($form->{formname} eq 'request_quotation') {
1271 $form->{"${inv}date"} = $form->{transdate};
1272 $form->{label} = $locale->text('RFQ');
1273 $numberfld = "rfqnumber";
1277 if ($form->{type} =~ /_delivery_order$/) {
1280 $form->{"${inv}date"} = $form->{transdate};
1281 $numberfld = $form->{type} =~ /^sales/ ? 'sdonumber' : 'pdonumber';
1282 $form->{label} = $form->{formname} eq 'pick_list' ? $locale->text('Pick List') : $locale->text('Delivery Order');
1285 $form->{TEMPLATE_DRIVER_OPTIONS} = { };
1286 if (any { $form->{type} eq $_ } qw(sales_quotation sales_order sales_delivery_order invoice request_quotation purchase_order purchase_delivery_order)) {
1287 $form->{TEMPLATE_DRIVER_OPTIONS}->{variable_content_types} = {
1288 longdescription => 'html',
1289 partnotes => 'html',
1293 $form->isblank("email", $locale->text('E-mail address missing!'))
1294 if ($form->{media} eq 'email');
1295 $form->isblank("${inv}date",
1296 $locale->text($form->{label})
1298 . $locale->text(' Date missing!'));
1300 # $locale->text('Invoice Number missing!')
1301 # $locale->text('Invoice Date missing!')
1302 # $locale->text('Order Number missing!')
1303 # $locale->text('Order Date missing!')
1304 # $locale->text('Quotation Number missing!')
1305 # $locale->text('Quotation Date missing!')
1307 $form->{what_done} = $form->{formname};
1311 # Save the email address given in the form because it should override the setting saved for the customer/vendor.
1312 my ($saved_email, $saved_cc, $saved_bcc) =
1313 ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
1315 my $language_saved = $form->{language_id};
1316 my $payment_id_saved = $form->{payment_id};
1317 my $delivery_term_id_saved = $form->{delivery_term_id};
1318 my $salesman_id_saved = $form->{salesman_id};
1319 my $cp_id_saved = $form->{cp_id};
1320 my $taxzone_id_saved = $form->{taxzone_id};
1321 my $currency_saved = $form->{currency};
1323 call_sub("$form->{vc}_details") if ($form->{vc});
1325 $form->{language_id} = $language_saved;
1326 $form->{payment_id} = $payment_id_saved;
1327 $form->{delivery_term_id} = $delivery_term_id_saved;
1328 $form->{taxzone_id} = $taxzone_id_saved;
1329 $form->{currency} = $currency_saved;
1331 $form->{"email"} = $saved_email if ($saved_email);
1332 $form->{"cc"} = $saved_cc if ($saved_cc);
1333 $form->{"bcc"} = $saved_bcc if ($saved_bcc);
1335 if (!$cp_id_saved) {
1336 # No contact was selected. Delete all contact variables because
1337 # IS->customer_details() and IR->vendor_details() get the default
1339 map({ delete($form->{$_}); } grep(/^cp_/, keys(%{ $form })));
1342 my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
1343 if ($form->{"language_id"}) {
1344 ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) =
1345 AM->get_language_details(\%myconfig, $form, $form->{language_id});
1347 $output_dateformat = $myconfig{"dateformat"};
1348 $output_numberformat = $myconfig{"numberformat"};
1349 $output_longdates = 1;
1352 # Store the output number format so that the template modules know
1353 # how to parse the amounts back if requested.
1354 $myconfig{output_numberformat} = $output_numberformat || $myconfig{numberformat};
1356 ($form->{employee}) = split /--/, $form->{employee};
1358 # create the form variables
1359 if ($form->{type} =~ /_delivery_order$/) {
1360 DO->order_details(\%myconfig, \%$form);
1362 OE->order_details(\%myconfig, \%$form);
1364 IS->invoice_details(\%myconfig, \%$form, $locale);
1367 $form->get_employee_data('prefix' => 'employee', 'id' => $form->{employee_id});
1368 $form->get_employee_data('prefix' => 'salesman', 'id' => $salesman_id_saved);
1370 if ($form->{shipto_id}) {
1371 $form->get_shipto(\%myconfig);
1374 $form->{notes} =~ s/^\s+//g;
1376 delete $form->{printer_command};
1378 $form->{language} = $form->get_template_language(\%myconfig);
1381 if ($form->{media} ne 'email') {
1382 $printer_code = $form->get_printer_code(\%myconfig);
1383 if ($printer_code ne "") {
1384 $printer_code = "_" . $printer_code;
1388 if ($form->{language} ne "") {
1389 my $template_arrays = $form->{TEMPLATE_ARRAYS} || $form;
1390 map { $template_arrays->{unit}->[$_] = AM->translate_units($form, $form->{language}, $template_arrays->{unit}->[$_], $template_arrays->{qty}->[$_]); } (0..scalar(@{ $template_arrays->{unit} }) - 1);
1392 $form->{language} = "_" . $form->{language};
1396 format_dates($output_dateformat, $output_longdates,
1397 qw(invdate orddate quodate pldate duedate reqdate transdate
1398 shippingdate deliverydate validitydate paymentdate
1399 datepaid transdate_oe deliverydate_oe dodate
1400 employee_startdate employee_enddate
1402 grep({ /^datepaid_\d+$/ ||
1403 /^transdate_oe_\d+$/ ||
1404 /^deliverydate_oe_\d+$/ ||
1406 /^deliverydate_\d+$/ ||
1410 reformat_numbers($output_numberformat, 2,
1411 qw(invtotal ordtotal quototal subtotal linetotal
1412 listprice sellprice netprice discount
1413 tax taxbase total paid payment),
1414 grep({ /^(?:linetotal|nodiscount_linetotal|listprice|sellprice|netprice|taxbase|discount|p_discount|discount_sub|nodiscount_sub|paid|subtotal|total|tax)_\d+$/ } keys(%{$form})));
1416 reformat_numbers($output_numberformat, undef,
1417 qw(qty price_factor),
1421 my ($cvar_date_fields, $cvar_number_fields) = CVar->get_field_format_list('module' => 'CT', 'prefix' => 'vc_');
1423 if (scalar @{ $cvar_date_fields }) {
1424 format_dates($output_dateformat, $output_longdates, @{ $cvar_date_fields });
1427 while (my ($precision, $field_list) = each %{ $cvar_number_fields }) {
1428 reformat_numbers($output_numberformat, $precision, @{ $field_list });
1431 my $extension = 'html';
1432 if ($form->{format} eq 'postscript') {
1433 $form->{postscript} = 1;
1436 } elsif ($form->{"format"} =~ /pdf/) {
1438 $extension = $form->{'format'} =~ m/opendocument/i ? 'odt' : 'tex';
1440 } elsif ($form->{"format"} =~ /opendocument/) {
1441 $form->{opendocument} = 1;
1443 } elsif ($form->{"format"} =~ /excel/) {
1448 # search for the template
1449 my ($template_file, @template_files) = SL::Helper::CreatePDF->find_template(
1450 name => $form->{formname},
1451 email => $form->{media} eq 'email',
1452 language_id => $form->{language_id},
1453 printer_id => $form->{printer_id},
1454 extension => $extension,
1457 if (!defined $template_file) {
1458 $::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));
1461 $form->{IN} = $template_file;
1463 delete $form->{OUT};
1465 if ($form->{media} eq 'printer') {
1466 $form->{OUT} = $form->{printer_command};
1467 $form->{OUT_MODE} = '|-';
1468 $form->{printed} .= " $form->{formname}";
1469 $form->{printed} =~ s/^ //;
1471 my $printed = $form->{printed};
1473 if ($form->{media} eq 'email') {
1474 $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
1475 unless $form->{subject};
1477 $form->{emailed} .= " $form->{formname}";
1478 $form->{emailed} =~ s/^ //;
1480 my $emailed = $form->{emailed};
1482 if ($form->{media} eq 'queue') {
1483 my %queued = map { s|.*[/\\]||; $_ } split / /, $form->{queued};
1486 my $suffix = ($form->{postscript}) ? '.ps' : '.pdf';
1487 if ($filename = $queued{ $form->{formname} }) {
1488 unlink $::lx_office_conf{paths}->{spool} . "/$filename";
1489 delete $queued{ $form->{formname} };
1491 $form->{queued} = join ' ', %queued;
1492 $filename =~ s/\..*$//g;
1493 $filename .= $suffix;
1494 $form->{OUT} = $::lx_office_conf{paths}->{spool} . "/$filename";
1495 $form->{OUT_MODE} = '>';
1499 ($temp_fh, $filename) = File::Temp::tempfile(
1500 'kivitendo-spoolXXXXXX',
1501 SUFFIX => "$suffix",
1502 DIR => $::lx_office_conf{paths}->{spool},
1506 $form->{OUT} = "$filename";
1507 # use >> for OUT_MODE because file is already created by File::Temp
1508 $form->{OUT_MODE} = '>>';
1509 # strip directory so that only filename is stored in table status
1510 ($filename) = $filename =~ /^$::lx_office_conf{paths}->{spool}\/(.*)/;
1514 $form->{queued} .= " $form->{formname} $filename";
1515 $form->{queued} =~ s/^ //;
1517 my $queued = $form->{queued};
1519 # saving the history
1520 if(!exists $form->{addition}) {
1521 $form->{snumbers} = "${inv}number" . "_" . $form->{"${inv}number"};
1522 if($form->{media} =~ /printer/) {
1523 $form->{addition} = "PRINTED";
1525 elsif($form->{media} =~ /email/) {
1526 $form->{addition} = "MAILED";
1528 elsif($form->{media} =~ /queue/) {
1529 $form->{addition} = "QUEUED";
1531 elsif($form->{media} =~ /screen/) {
1532 $form->{addition} = "SCREENED";
1534 $form->save_history;
1536 # /saving the history
1538 # prepare meta information for template introspection
1539 $form->{template_meta} = {
1540 formname => $form->{formname},
1541 language => SL::DB::Manager::Language->find_by_or_create(id => $form->{language_id} || undef),
1542 format => $form->{format},
1543 media => $form->{media},
1544 extension => $extension,
1545 printer => SL::DB::Manager::Printer->find_by_or_create(id => $form->{printer_id} || undef),
1546 today => DateTime->today,
1549 $form->parse_template(\%myconfig);
1551 $form->{callback} = "";
1553 if ($form->{media} eq 'email') {
1554 $form->{message} = $locale->text('sent') unless $form->{message};
1556 my $message = $form->{message};
1558 # if we got back here restore the previous form
1559 if ($form->{media} =~ /(printer|email|queue)/) {
1561 $form->update_status(\%myconfig)
1562 if ($form->{media} eq 'queue' && $form->{id});
1564 return $main::lxdebug->leave_sub() if ($old_form eq "return");
1568 $old_form->{"${inv}number"} = $form->{"${inv}number"};
1570 # restore and display form
1571 map { $form->{$_} = $old_form->{$_} } keys %$old_form;
1573 $form->{queued} = $queued;
1574 $form->{printed} = $printed;
1575 $form->{emailed} = $emailed;
1576 $form->{message} = $message;
1578 $form->{rowcount}--;
1579 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1580 qw(exchangerate creditlimit creditremaining);
1582 for my $i (1 .. $form->{paidaccounts}) {
1584 $form->{"${_}_$i"} =
1585 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1586 } qw(paid exchangerate);
1589 call_sub($display_form);
1594 ($form->{media} eq 'printer')
1595 ? $locale->text('sent to printer')
1596 : $locale->text('emailed to') . " $form->{email}";
1598 if (!$params{no_redirect}) {
1599 $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
1602 if ($form->{printing}) {
1603 call_sub($display_form);
1607 $main::lxdebug->leave_sub();
1610 sub customer_details {
1611 $main::lxdebug->enter_sub();
1613 my $form = $main::form;
1614 my %myconfig = %main::myconfig;
1616 IS->customer_details(\%myconfig, \%$form, @_);
1618 $main::lxdebug->leave_sub();
1621 sub vendor_details {
1622 $main::lxdebug->enter_sub();
1624 my $form = $main::form;
1625 my %myconfig = %main::myconfig;
1627 IR->vendor_details(\%myconfig, \%$form, @_);
1629 $main::lxdebug->leave_sub();
1633 $main::lxdebug->enter_sub();
1635 my $form = $main::form;
1639 $form->{postasnew} = 1;
1640 map { delete $form->{$_} } qw(printed emailed queued);
1644 $main::lxdebug->leave_sub();
1648 $main::lxdebug->enter_sub();
1652 $::form->{print_and_post} = 0 if $::form->{second_run};
1654 map { $::form->{$_} = $::form->parse_amount(\%::myconfig, $::form->{$_}) } qw(exchangerate creditlimit creditremaining);
1656 # get details for customer/vendor
1657 call_sub($::form->{vc} . "_details", qw(name department_1 department_2 street zipcode city country contact email phone fax), $::form->{vc} . "number");
1659 $::form->{rowcount}--;
1661 my @shipto_vars = qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry
1662 shiptocontact shiptocp_gender shiptophone shiptofax shiptoemail
1663 shiptodepartment_1 shiptodepartment_2);
1664 my $previous_form = $::auth->save_form_in_session(skip_keys => [ @shipto_vars, qw(header shipto_id) ]);
1665 $::form->{title} = $::locale->text('Ship to');
1668 my $vc_obj = ($::form->{vc} eq 'customer' ? "SL::DB::Customer" : "SL::DB::Vendor")->new(id => $::form->{$::form->{vc} . "_id"})->load;
1670 print $::form->parse_html_template('io/ship_to', { previousform => $previous_form,
1671 nextsub => $::form->{display_form} || 'display_form',
1675 $main::lxdebug->leave_sub();
1678 sub ship_to_entered {
1679 $::auth->restore_form_from_session(delete $::form->{previousform});
1680 call_sub($::form->{nextsub});
1683 sub relink_accounts {
1684 $main::lxdebug->enter_sub();
1686 my $form = $main::form;
1687 my %myconfig = %main::myconfig;
1691 $form->{"taxaccounts"} =~ s/\s*$//;
1692 $form->{"taxaccounts"} =~ s/^\s*//;
1693 foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
1694 map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
1696 $form->{"taxaccounts"} = "";
1698 IC->retrieve_accounts(\%myconfig, $form, map { $_ => $form->{"id_$_"} } 1 .. $form->{rowcount});
1700 $main::lxdebug->leave_sub();
1704 $main::lxdebug->enter_sub();
1706 my $form = $main::form;
1707 my %myconfig = %main::myconfig;
1711 my $invdate = $form->{invdate} eq 'undefined' ? undef : $form->{invdate};
1712 my $duedate = $form->get_duedate(\%myconfig, $invdate);
1714 print $form->ajax_response_header() . ($duedate || $invdate);
1716 $main::lxdebug->leave_sub();
1719 sub _update_part_information {
1720 $main::lxdebug->enter_sub();
1722 my $form = $main::form;
1724 my %part_information = IC->get_basic_part_info('id' => [ grep { $_ } map { $form->{"id_${_}"} } (1..$form->{rowcount}) ],
1725 'vendor_id' => $form->{vendor_id});
1727 $form->{PART_INFORMATION} = \%part_information;
1729 foreach my $i (1..$form->{rowcount}) {
1730 next unless ($form->{"id_${i}"});
1732 my $info = $form->{PART_INFORMATION}->{$form->{"id_${i}"}} || { };
1733 $form->{"partunit_${i}"} = $info->{unit};
1734 $form->{"weight_$i"} = $info->{weight};
1737 $main::lxdebug->leave_sub();
1741 $main::lxdebug->enter_sub();
1743 my $form = $main::form;
1744 my %myconfig = %main::myconfig;
1746 if (!$form->{ordnumber} || !$form->{id}) {
1747 map { $form->{"ship_$_"} = 0 } (1..$form->{rowcount});
1748 $main::lxdebug->leave_sub();
1752 my $all_units = AM->retrieve_all_units();
1754 my %ship = DO->get_shipped_qty('type' => ($form->{type} eq 'purchase_order') ? 'purchase' : 'sales',
1755 'oe_id' => $form->{id},);
1757 foreach my $i (1..$form->{rowcount}) {
1758 next unless ($form->{"id_${i}"});
1760 $form->{"ship_$i"} = 0;
1762 my $ship_entry = $ship{$form->{"id_$i"}};
1764 next if (!$ship_entry || ($ship_entry->{qty} <= 0));
1767 ($form->{simple_save} ? $form->{"qty_$i"} : $form->parse_amount(\%myconfig, $form->{"qty_$i"}))
1768 * $all_units->{$form->{"unit_$i"}}->{factor}
1769 / $all_units->{$form->{"partunit_$i"}}->{factor};
1771 $form->{"ship_$i"} = min($rowqty, $ship_entry->{qty});
1772 $ship_entry->{qty} -= $form->{"ship_$i"};
1775 foreach my $i (1..$form->{rowcount}) {
1776 next unless ($form->{"id_${i}"});
1778 my $ship_entry = $ship{$form->{"id_$i"}};
1780 next if (!$ship_entry || ($ship_entry->{qty} <= 0.01));
1782 $form->{"ship_$i"} += $ship_entry->{qty};
1783 $ship_entry->{qty} = 0;
1786 $main::lxdebug->leave_sub();
1789 sub _update_custom_variables {
1790 $main::lxdebug->enter_sub();
1792 my $form = $main::form;
1794 $form->{CVAR_CONFIGS} = { } unless ref $form->{CVAR_CONFIGS} eq 'HASH';
1795 $form->{CVAR_CONFIGS}->{IC} ||= CVar->get_configs(module => 'IC');
1797 $main::lxdebug->leave_sub();
1800 sub _render_custom_variables_inputs {
1801 $main::lxdebug->enter_sub(2);
1803 my $form = $main::form;
1807 if (!$form->{CVAR_CONFIGS}->{IC}) {
1808 $main::lxdebug->leave_sub();
1812 my $valid = CVar->custom_variables_validity_by_trans_id(trans_id => $params{part_id});
1814 # get partsgroup_id from part
1816 if ($params{part_id}) {
1817 $partsgroup_id = SL::DB::Part->new(id => $params{part_id})->load->partsgroup_id;
1820 my $num_visible_cvars = 0;
1821 foreach my $cvar (@{ $form->{CVAR_CONFIGS}->{IC} }) {
1822 $cvar->{valid} = $params{part_id} && $valid->($cvar->{id});
1824 # set partsgroup filter
1825 my $partsgroup_filtered = 0;
1826 if ($cvar->{flag_partsgroup_filter}) {
1827 if (!$partsgroup_id || (!grep {$partsgroup_id == $_} @{ $cvar->{partsgroups} })) {
1828 $partsgroup_filtered = 1;
1832 my $hide_non_editable = 1;
1835 my $description = '';
1836 if (( ($cvar->{flag_editable} || !$hide_non_editable) && $cvar->{valid}) && !$partsgroup_filtered) {
1837 $num_visible_cvars++;
1838 $description = $cvar->{description} . ' ';
1842 my $form_key = "ic_cvar_" . $cvar->{name} . "_$params{row}";
1844 push @{ $params{ROW2} }, {
1845 line_break => $show && !(($num_visible_cvars - 1) % ($::myconfig{form_cvars_nr_cols}*1 || 3)),
1846 description => $description,
1849 hide_non_editable => $hide_non_editable,
1851 name_prefix => 'ic_',
1852 name_postfix => "_$params{row}",
1853 valid => $cvar->{valid},
1854 value => CVar->parse($::form->{$form_key}, $cvar),
1855 partsgroup_filtered => $partsgroup_filtered,
1860 $main::lxdebug->leave_sub(2);
1863 sub _remove_billed_or_delivered_rows {
1866 croak "Missing parameter 'quantities'" if !$params{quantities};
1868 my @fields = map { s/_1$//; $_ } grep { m/_1$/ } keys %{ $::form };
1871 my $make_key = sub {
1873 return $::form->{"id_${row}"} unless $::form->{"serialnumber_${row}"};
1874 my $key = $::form->{"id_${row}"} . ':' . $::form->{"serialnumber_${row}"};
1875 return exists $params{quantities}->{$key} ? $key : $::form->{"id_${row}"};
1878 my $removed_rows = 0;
1880 while ($row < $::form->{rowcount}) {
1882 next unless $::form->{"id_$row"};
1884 my $parts_id = $::form->{"id_$row"};
1885 my $base_qty = $::form->parse_amount(\%::myconfig, $::form->{"qty_$row"}) * SL::DB::Manager::Unit->find_by(name => $::form->{"unit_$row"})->base_factor;
1887 my $key = $make_key->($row);
1888 my $sub_qty = min($base_qty, $params{quantities}->{$key});
1889 $params{quantities}->{$key} -= $sub_qty;
1891 if (!$sub_qty || ($sub_qty != $base_qty)) {
1892 $::form->{"qty_${row}"} = $::form->format_amount(\%::myconfig, ($base_qty - $sub_qty) / SL::DB::Manager::Unit->find_by(name => $::form->{"unit_$row"})->base_factor);
1893 push @new_rows, { map { $_ => $::form->{"${_}_${row}"} } @fields };
1900 $::form->redo_rows(\@fields, \@new_rows, scalar(@new_rows), $::form->{rowcount});
1901 $::form->{rowcount} -= $removed_rows;
1904 # TODO: both of these are makeshift so that price sources can operate on rdbo objects. if
1905 # this ever gets rewritten in controller style, throw this out
1906 sub _make_record_item {
1910 sales_order => 'OrderItem',
1911 purchase_oder => 'OrderItem',
1912 sales_quotation => 'OrderItem',
1913 request_quotation => 'OrderItem',
1914 invoice => 'InvoiceItem',
1915 purchase_invoice => 'InvoiceItem',
1916 purchase_delivery_order => 'DeliveryOrderItem',
1917 sales_delivery_order => 'DeliveryOrderItem',
1918 }->{$::form->{type}};
1920 return unless $class;
1922 $class = 'SL::DB::' . $class;
1924 eval "require $class";
1926 my $obj = $::form->{"orderitems_id_$row"}
1927 ? $class->meta->convention_manager->auto_manager_class_name->find_by(id => $::form->{"orderitems_id_$row"})
1930 for my $method (apply { s/_$row$// } grep { /_$row$/ } keys %$::form) {
1931 next unless $obj->meta->column($method);
1932 if ($obj->meta->column($method)->isa('Rose::DB::Object::Metadata::Column::Date')) {
1933 $obj->${\"$method\_as_date"}($::form->{"$method\_$row"});
1934 } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Numeric|Float|DoublePrecsion)$/) {
1935 $obj->${\"$method\_as\_number"}($::form->{$method});
1937 $obj->$method($::form->{"$method\_$row"});
1941 if ($::form->{"id_$row"}) {
1942 $obj->part(SL::DB::Part->load_cached($::form->{"id_$row"}));
1950 sales_order => 'Order',
1951 purchase_oder => 'Order',
1952 sales_quotation => 'Order',
1953 request_quotation => 'Order',
1954 purchase_delivery_order => 'DeliveryOrder',
1955 sales_delivery_order => 'DeliveryOrder',
1956 }->{$::form->{type}};
1958 if ($::form->{type} eq 'invoice') {
1959 $class = $::form->{vc} eq 'customer' ? 'Invoice'
1960 : $::form->{vc} eq 'vendor' ? 'PurchaseInvoice'
1961 : do { die 'unknown invoice type' };
1964 return unless $class;
1966 $class = 'SL::DB::' . $class;
1968 eval "require $class";
1970 my $obj = $::form->{id}
1971 ? $class->meta->convention_manager->auto_manager_class_name->find_by(id => $::form->{id})
1974 for my $method (keys %$::form) {
1975 next unless $obj->can($method);
1976 next unless $obj->meta->column($method);
1978 if ($obj->meta->column($method)->isa('Rose::DB::Object::Metadata::Column::Date')) {
1979 $obj->${\"$method\_as_date"}($::form->{$method});
1980 } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Numeric|Float|DoublePrecsion)$/) {
1981 $obj->${\"$method\_as\_number"}($::form->{$method});
1983 $obj->$method($::form->{$method});
1988 for my $i (1 .. $::form->{rowcount}) {
1989 next unless $::form->{"id_$i"};
1990 push @items, _make_record_item($i)
1993 $obj->items(@items) if @items;