1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger, Accounting
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
30 # Inventory Control module
32 #======================================================================
35 use POSIX qw(strftime);
36 use List::Util qw(max);
39 use SL::ReportGenerator;
47 our ($form, $locale, %myconfig, $lxdebug);
49 require "bin/mozilla/io.pl";
50 require "bin/mozilla/invoice_io.pl";
51 require "bin/mozilla/common.pl";
52 require "bin/mozilla/reportgenerator.pl";
57 # type=submit $locale->text('Add Part')
58 # type=submit $locale->text('Add Service')
59 # type=submit $locale->text('Add Assembly')
60 # type=submit $locale->text('Edit Part')
61 # type=submit $locale->text('Edit Service')
62 # type=submit $locale->text('Edit Assembly')
67 $lxdebug->enter_sub();
69 $auth->assert('part_service_assembly_edit');
71 $form->{title} = $locale->text('Add ' . ucfirst $form->{item});
74 "$form->{script}?action=add&item=$form->{item}"
75 unless $form->{callback};
77 $form->{"unit_changeable"} = 1;
79 IC->get_pricegroups(\%myconfig, \%$form);
83 $lxdebug->leave_sub();
87 $lxdebug->enter_sub();
89 $auth->assert('part_service_assembly_edit');
91 # switch for backward sorting
94 # memory for which table was sort at last time
95 $form->{lastsort} = "";
97 # counter for added entries to top100
98 $form->{ndxs_counter} = 0;
100 # $locale->text('Parts')
101 # $locale->text('Services')
103 my $is_service = $form->{searchitems} eq 'service';
104 my $is_assembly = $form->{searchitems} eq 'assembly';
106 $form->{title} = (ucfirst $form->{searchitems}) . "s";
107 $form->{title} = $locale->text($form->{title});
108 $form->{title} = $locale->text('Assemblies') if $is_assembly;
110 $form->{jsscript} = 1;
114 print $form->parse_html_template('ic/search', { is_assembly => $is_assembly,
115 is_service => $is_service,
116 dateformat => $myconfig{dateformat}, });
118 $lxdebug->leave_sub();
121 sub search_update_prices {
122 $lxdebug->enter_sub();
124 $auth->assert('part_service_assembly_edit');
126 my $pricegroups = IC->get_pricegroups(\%myconfig, \%$form);
130 print $form->parse_html_template('ic/search_update_prices', { PRICE_ROWS => $pricegroups });
132 $lxdebug->leave_sub();
135 sub confirm_price_update {
136 $lxdebug->enter_sub();
138 $auth->assert('part_service_assembly_edit');
140 $form->{nextsub} = "update_prices";
143 map { delete $form->{$_} } qw(action header);
145 print $form->parse_html_template('ic/confirm_price_update', { HIDDENS => [ map { name => $_, value => $form->{$_} }, keys %$form ] });
147 $lxdebug->leave_sub();
151 $lxdebug->enter_sub();
153 $auth->assert('part_service_assembly_edit');
155 if (IC->update_prices(\%myconfig, \%$form)) {
156 $form->redirect($form->{update_count} . $locale->text('prices updated!'));
158 $form->error($locale->text('Could not update prices!'));
161 $lxdebug->leave_sub();
165 $lxdebug->enter_sub();
167 $auth->assert('part_service_assembly_edit');
172 $form->{title} = $locale->text('Top 100 hinzufuegen');
176 push @custom_hiddens, qw(searchitems title bom titel revers lastsort sort ndxs_counter extras);
177 push @custom_hiddens, qw(itemstatus l_linetotal l_partnumber l_description l_onhand l_unit l_sellprice l_linetotalsellprice);
179 +{ name => 'row', value => $j },
180 +{ name => 'nextsub', value => 'item_selected' },
181 +{ name => 'test', value => 'item_selected' },
182 +{ name => 'lastndx', value => $lastndx },
183 map(+{ name => $_, value => $form->{$_} }, @custom_hiddens),
186 my ($partnumber, $description, $unit, $sellprice, $soldtotal);
188 # if ($form->{ndx}) {
189 # for my $i (0 .. $form->{ndxs_counter}) {
191 # # insert data into top100
192 # push @{ $form->{parts} },
194 # partnumber => $form->{"totop100_partnumber_$j"},
195 # description => $form->{"totop100_description_$j"},
196 # unit => $form->{"totop100_unit_$j"},
197 # sellprice => $form->{"totop100_sellprice_$j"},
198 # soldtotal => $form->{"totop100_soldtotal_$j"},
205 # set data for next page
206 for my $i (1 .. $form->{ndxs_counter}) {
207 $partnumber = $form->{"totop100_partnumber_$i"};
208 $description = $form->{"totop100_description_$i"};
209 $unit = $form->{"totop100_unit_$i"};
210 $sellprice = $form->{"totop100_sellprice_$i"};
211 $soldtotal = $form->{"totop100_soldtotal_$i"};
214 totop100_partnumber => $form->{"totop100_partnumber_$i"},
215 totop100_description => $form->{"totop100_description_$i"},
216 totop100_unit => $form->{"totop100_unit_$i"},
217 totop100_sellprice => $form->{"totop100_sellprice_$i"},
218 totop100_soldtotal => $form->{"totop100_soldtotal_$i"},
222 #<input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
223 #<input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
224 #<input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
225 #<input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
226 #<input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
230 print $form->parse_html_template('ic/choice', +{ HIDDENS => \@HIDDENS, PARTS => \@PARTS });
232 $lxdebug->leave_sub();
236 $lxdebug->enter_sub();
238 $auth->assert('part_service_assembly_edit');
241 our ($partnumber, $description, $unit, $sellprice, $soldtotal);
243 my @sortorders = ("", "partnumber", "description", "all");
244 my $sortorder = $sortorders[($form->{description} ? 2 : 0) + ($form->{partnumber} ? 1 : 0)];
245 IC->get_parts(\%myconfig, \%$form, $sortorder);
247 $form->{title} = $locale->text('Top 100 hinzufuegen');
253 <form method=post action=ic.pl>
256 <th class=listtop colspan=6>| . $locale->text('choice part') . qq|</th>
259 <tr class=listheading>
261 <th class=listheading>| . $locale->text('Part Number') . qq|</th>
262 <th class=listheading>| . $locale->text('Part Description') . qq|</th>
263 <th class=listheading>| . $locale->text('Unit of measure') . qq|</th>
264 <th class=listheading>| . $locale->text('Sell Price') . qq|</th>
265 <th class=listheading>| . $locale->text('soldtotal') . qq|</th>
269 my $i = $form->{rows};
271 for ($j = 1; $j <= $i; $j++) {
274 <tr class=listrow| . ($j % 2) . qq|>|;
277 <td><input name=ndx class=radio type=radio value=$j checked></td>|;
280 <td><input name=ndx class=radio type=radio value=$j></td>|;
283 <td><input name="new_partnumber_$j" type=hidden value="$form->{"partnumber_$j"}">$form->{"partnumber_$j"}</td>
284 <td><input name="new_description_$j" type=hidden value="$form->{"description_$j"}">$form->{"description_$j"}</td>
285 <td><input name="new_unit_$j" type=hidden value="$form->{"unit_$j"}">$form->{"unit_$j"}</td>
286 <td><input name="new_sellprice_$j" type=hidden value="$form->{"sellprice_$j"}">$form->{"sellprice_$j"}</td>
287 <td><input name="new_soldtotal_$j" type=hidden value="$form->{"soldtotal_$j"}">$form->{"soldtotal_$j"}</td>
290 <input name="new_id_$j" type=hidden value="$form->{"id_$j"}">|;
300 <input type=hidden name=itemstatus value="$form->{itemstatus}">
301 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
302 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
303 <input type=hidden name=l_description value="$form->{l_description}">
304 <input type=hidden name=l_onhand value="$form->{l_onhand}">
305 <input type=hidden name=l_unit value="$form->{l_unit}">
306 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
307 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
308 <input type=hidden name=sort value="$form->{sort}">
309 <input type=hidden name=revers value="$form->{revers}">
310 <input type=hidden name=lastsort value="$form->{lastsort}">
312 <input type=hidden name=bom value="$form->{bom}">
313 <input type=hidden name=titel value="$form->{titel}">
314 <input type=hidden name=searchitems value="$form->{searchitems}">
316 <input type=hidden name=row value=$j>
318 <input type=hidden name=nextsub value=item_selected>
320 <input name=lastndx type=hidden value=$lastndx>
322 <input name=ndxs_counter type=hidden value=$form->{ndxs_counter}>|;
326 if (($form->{ndxs_counter}) > 0) {
327 for ($i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
329 $partnumber = $form->{"totop100_partnumber_$i"};
330 $description = $form->{"totop100_description_$i"};
331 $unit = $form->{"totop100_unit_$i"};
332 $sellprice = $form->{"totop100_sellprice_$i"};
333 $soldtotal = $form->{"totop100_soldtotal_$i"};
336 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
337 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
338 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
339 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
340 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
348 <input class=submit type=submit name=action value="|
349 . $locale->text('TOP100') . qq|">
355 $lxdebug->leave_sub();
359 $lxdebug->enter_sub();
361 $auth->assert('part_service_assembly_edit');
364 $form->{ndxs_counter}++;
366 if ($form->{ndxs_counter} > 0) {
368 my $index = $form->{ndx};
370 $form->{"totop100_partnumber_$form->{ndxs_counter}"} = $form->{"new_partnumber_$index"};
371 $form->{"totop100_description_$form->{ndxs_counter}"} = $form->{"new_description_$index"};
372 $form->{"totop100_unit_$form->{ndxs_counter}"} = $form->{"new_unit_$index"};
373 $form->{"totop100_sellprice_$form->{ndxs_counter}"} = $form->{"new_sellprice_$index"};
374 $form->{"totop100_soldtotal_$form->{ndxs_counter}"} = $form->{"new_soldtotal_$index"};
378 $lxdebug->leave_sub();
382 $lxdebug->enter_sub();
384 $auth->assert('part_service_assembly_edit');
386 my ($revers, $lastsort, $callback, $option, $description, $sameitem,
387 $partnumber, $unit, $sellprice, $soldtotal, $totop100, $onhand, $align);
388 my (@column_index, %column_header, %column_data);
389 my ($totalsellprice, $totallastcost, $totallistprice, $subtotalonhand, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
391 $form->{top100} = "top100";
392 $form->{l_soldtotal} = "Y";
393 # $form->{soldtotal} = "soldtotal";
394 $form->{sort} = "soldtotal";
395 $form->{l_qty} = "N";
396 $form->{l_linetotal} = "";
398 $form->{number} = "position";
399 $form->{l_number} = "Y";
403 $form->{title} = $locale->text('Top 100');
405 $revers = $form->{revers};
406 $lastsort = $form->{lastsort};
408 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
410 $form->{lastsort} = "partnumber";
411 $form->{sort} = "partnumber";
415 "$form->{script}?action=top100&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&title="
416 . $form->escape($form->{title}, 1);
418 # if we have a serialnumber limit search
419 if ($form->{serialnumber} || $form->{l_serialnumber}) {
420 $form->{l_serialnumber} = "Y";
421 unless ( $form->{bought}
424 || $form->{quoted}) {
425 $form->{bought} = $form->{sold} = 1;
428 IC->all_parts(\%myconfig, \%$form);
430 if ($form->{itemstatus} eq 'active') {
431 $option .= $locale->text('Active') . " : ";
433 if ($form->{itemstatus} eq 'obsolete') {
434 $option .= $locale->text('Obsolete') . " : ";
436 if ($form->{itemstatus} eq 'orphaned') {
437 $option .= $locale->text('Orphaned') . " : ";
439 if ($form->{itemstatus} eq 'onhand') {
440 $option .= $locale->text('On Hand') . " : ";
441 $form->{l_onhand} = "Y";
443 if ($form->{itemstatus} eq 'short') {
444 $option .= $locale->text('Short') . " : ";
445 $form->{l_onhand} = "Y";
447 if ($form->{onorder}) {
448 $form->{l_ordnumber} = "Y";
449 $callback .= "&onorder=$form->{onorder}";
450 $option .= $locale->text('On Order') . " : ";
452 if ($form->{ordered}) {
453 $form->{l_ordnumber} = "Y";
454 $callback .= "&ordered=$form->{ordered}";
455 $option .= $locale->text('Ordered') . " : ";
458 $form->{l_quonumber} = "Y";
459 $callback .= "&rfq=$form->{rfq}";
460 $option .= $locale->text('RFQ') . " : ";
462 if ($form->{quoted}) {
463 $form->{l_quonumber} = "Y";
464 $callback .= ""ed=$form->{quoted}";
465 $option .= $locale->text('Quoted') . " : ";
467 if ($form->{bought}) {
468 $form->{l_invnumber} = "Y";
469 $callback .= "&bought=$form->{bought}";
470 $option .= $locale->text('Bought') . " : ";
473 $form->{l_invnumber} = "Y";
474 $callback .= "&sold=$form->{sold}";
475 $option .= $locale->text('Sold') . " : ";
482 || $form->{quoted}) {
484 $form->{l_lastcost} = "";
485 $form->{l_name} = "Y";
486 if ($form->{transdatefrom}) {
487 $callback .= "&transdatefrom=$form->{transdatefrom}";
489 . $locale->text('From')
491 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
493 if ($form->{transdateto}) {
494 $callback .= "&transdateto=$form->{transdateto}";
496 . $locale->text('To')
498 . $locale->date(\%myconfig, $form->{transdateto}, 1);
504 if ($form->{partnumber}) {
505 $callback .= "&partnumber=$form->{partnumber}";
506 $option .= $locale->text('Part Number') . qq| : $form->{partnumber}<br>|;
509 $callback .= "&partnumber=$form->{ean}";
510 $option .= $locale->text('EAN') . qq| : $form->{ean}<br>|;
512 if ($form->{partsgroup}) {
513 $callback .= "&partsgroup=$form->{partsgroup}";
514 $option .= $locale->text('Group') . qq| : $form->{partsgroup}<br>|;
516 if ($form->{serialnumber}) {
517 $callback .= "&serialnumber=$form->{serialnumber}";
518 $option .= $locale->text('Serial Number') . qq| : $form->{serialnumber}<br>|;
520 if ($form->{description}) {
521 $callback .= "&description=$form->{description}";
522 $description = $form->{description};
523 $description =~ s/\n/<br>/g;
524 $option .= $locale->text('Part Description') . qq| : $form->{description}<br>|;
527 $callback .= "&make=$form->{make}";
528 $option .= $locale->text('Make') . qq| : $form->{make}<br>|;
530 if ($form->{model}) {
531 $callback .= "&model=$form->{model}";
532 $option .= $locale->text('Model') . qq| : $form->{model}<br>|;
534 if ($form->{drawing}) {
535 $callback .= "&drawing=$form->{drawing}";
536 $option .= $locale->text('Drawing') . qq| : $form->{drawing}<br>|;
538 if ($form->{microfiche}) {
539 $callback .= "µfiche=$form->{microfiche}";
540 $option .= $locale->text('Microfiche') . qq| : $form->{microfiche}<br>|;
542 if ($form->{l_soldtotal}) {
543 $callback .= "&soldtotal=$form->{soldtotal}";
544 $option .= $locale->text('soldtotal') . qq| : $form->{soldtotal}<br>|;
547 my @columns = $form->sort_columns(
548 qw(number partnumber ean description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal)
551 if ($form->{l_linetotal}) {
552 $form->{l_onhand} = "Y";
553 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
554 if ($form->{l_lastcost}) {
555 $form->{l_linetotallastcost} = "Y";
556 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
557 $form->{l_linetotallastcost} = "";
560 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
563 if ($form->{searchitems} eq 'service') {
565 # remove bin, weight and rop from list
566 map { $form->{"l_$_"} = "" } qw(bin weight rop);
568 $form->{l_onhand} = "";
570 # qty is irrelevant unless bought or sold
576 || $form->{quoted}) {
577 $form->{l_onhand} = "Y";
579 $form->{l_linetotalsellprice} = "";
580 $form->{l_linetotallastcost} = "";
584 $form->{l_lastcost} = ""
585 if ($form->{searchitems} eq 'assembly' && !$form->{bom});
587 foreach my $item (@columns) {
588 if ($form->{"l_$item"} eq "Y") {
589 push @column_index, $item;
591 # add column to callback
592 $callback .= "&l_$item=Y";
596 if ($form->{l_subtotal} eq 'Y') {
597 $callback .= "&l_subtotal=Y";
600 $column_header{number} =
601 qq|<th class=listheading nowrap>| . $locale->text('number') . qq|</th>|;
602 $column_header{partnumber} =
603 qq|<th nowrap><a class=listheading href=$callback&sort=partnumber&revers=$form->{revers}&lastsort=$form->{lastsort}>|
604 . $locale->text('Part Number')
606 $column_header{description} =
607 qq|<th nowrap><a class=listheading href=$callback&sort=description&revers=$form->{revers}&lastsort=$form->{lastsort}>|
608 . $locale->text('Part Description')
610 $column_header{partsgroup} =
611 qq|<th nowrap><a class=listheading href=$callback&sort=partsgroup>|
612 . $locale->text('Group')
614 $column_header{bin} =
615 qq|<th><a class=listheading href=$callback&sort=bin>|
616 . $locale->text('Bin')
618 $column_header{priceupdate} =
619 qq|<th nowrap><a class=listheading href=$callback&sort=priceupdate>|
620 . $locale->text('Updated')
622 $column_header{onhand} =
623 qq|<th nowrap><a class=listheading href=$callback&sort=onhand&revers=$form->{revers}&lastsort=$form->{lastsort}>|
624 . $locale->text('Qty')
626 $column_header{unit} =
627 qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
628 $column_header{listprice} =
629 qq|<th class=listheading nowrap>|
630 . $locale->text('List Price')
632 $column_header{lastcost} =
633 qq|<th class=listheading nowrap>| . $locale->text('Last Cost') . qq|</th>|;
634 $column_header{rop} =
635 qq|<th class=listheading nowrap>| . $locale->text('ROP') . qq|</th>|;
636 $column_header{weight} =
637 qq|<th class=listheading nowrap>| . $locale->text('Weight') . qq|</th>|;
639 $column_header{invnumber} =
640 qq|<th nowrap><a class=listheading href=$callback&sort=invnumber>|
641 . $locale->text('Invoice Number')
643 $column_header{ordnumber} =
644 qq|<th nowrap><a class=listheading href=$callback&sort=ordnumber>|
645 . $locale->text('Order Number')
647 $column_header{quonumber} =
648 qq|<th nowrap><a class=listheading href=$callback&sort=quonumber>|
649 . $locale->text('Quotation')
652 $column_header{name} =
653 qq|<th nowrap><a class=listheading href=$callback&sort=name>|
654 . $locale->text('Name')
657 $column_header{sellprice} =
658 qq|<th class=listheading nowrap>|
659 . $locale->text('Sell Price')
661 $column_header{linetotalsellprice} =
662 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
663 $column_header{linetotallastcost} =
664 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
665 $column_header{linetotallistprice} =
666 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
668 $column_header{image} =
669 qq|<th class=listheading nowrap>| . $locale->text('Image') . qq|</a></th>|;
670 $column_header{drawing} =
671 qq|<th nowrap><a class=listheading href=$callback&sort=drawing>|
672 . $locale->text('Drawing')
674 $column_header{microfiche} =
675 qq|<th nowrap><a class=listheading href=$callback&sort=microfiche>|
676 . $locale->text('Microfiche')
679 $column_header{serialnumber} =
680 qq|<th nowrap><a class=listheading href=$callback&sort=serialnumber>|
681 . $locale->text('Serial Number')
683 $column_header{soldtotal} =
684 qq|<th nowrap><a class=listheading href=$callback&sort=soldtotal&revers=$form->{revers}&lastsort=$form->{lastsort}>|
685 . $locale->text('soldtotal')
689 my $colspan = $#column_index + 1;
696 <th class=listtop colspan=$colspan>$form->{title}</th>
700 <tr><td colspan=$colspan>$option</td></tr>
702 <tr class=listheading>
705 map { print "\n$column_header{$_}" } @column_index;
711 # add order to callback
712 $form->{callback} = $callback .= "&sort=$form->{sort}";
714 # escape callback for href
715 $callback = $form->escape($callback);
717 if (@{ $form->{parts} }) {
718 $sameitem = $form->{parts}->[0]->{ $form->{sort} };
721 # insert numbers for top100
723 foreach my $ref (@{ $form->{parts} }) {
728 # if avaible -> insert choice here
729 if (($form->{ndxs_counter}) > 0) {
730 for (my $i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
731 $partnumber = $form->{"totop100_partnumber_$i"};
732 $description = $form->{"totop100_description_$i"};
733 $unit = $form->{"totop100_unit_$i"};
734 $sellprice = $form->{"totop100_sellprice_$i"};
735 $soldtotal = $form->{"totop100_soldtotal_$i"};
738 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
739 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
740 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
741 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
742 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
746 push @{ $form->{parts} },
748 partnumber => "$partnumber",
749 description => "$description",
751 sellprice => "$sellprice",
752 soldtotal => "$soldtotal" };
755 # build data for columns
757 foreach my $ref (@{ $form->{parts} }) {
759 if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
760 if ($sameitem ne $ref->{ $form->{sort} }) {
762 $sameitem = $ref->{ $form->{sort} };
766 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
767 $ref->{sellprice} *= $ref->{exchangerate};
768 $ref->{listprice} *= $ref->{exchangerate};
769 $ref->{lastcost} *= $ref->{exchangerate};
771 # use this for assemblies
772 $onhand = $ref->{onhand};
775 if ($ref->{assemblyitem}) {
777 $onhand = 0 if ($form->{sold});
780 $ref->{description} =~ s/\n/<br>/g;
782 $column_data{number} =
784 . $form->format_amount(\%myconfig, $ref->{number})
786 $column_data{partnumber} =
787 "<td align=$align>$ref->{partnumber} </a></td>";
788 $column_data{description} = "<td>$ref->{description} </td>";
789 $column_data{partsgroup} = "<td>$ref->{partsgroup} </td>";
791 $column_data{onhand} =
793 . $form->format_amount(\%myconfig, $ref->{onhand})
795 $column_data{sellprice} =
797 . $form->format_amount(\%myconfig, $ref->{sellprice})
799 $column_data{listprice} =
801 . $form->format_amount(\%myconfig, $ref->{listprice})
803 $column_data{lastcost} =
805 . $form->format_amount(\%myconfig, $ref->{lastcost})
808 $column_data{linetotalsellprice} = "<td align=right>"
809 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2)
811 $column_data{linetotallastcost} = "<td align=right>"
812 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2)
814 $column_data{linetotallistprice} = "<td align=right>"
815 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2)
818 if (!$ref->{assemblyitem}) {
819 $totalsellprice += $onhand * $ref->{sellprice};
820 $totallastcost += $onhand * $ref->{lastcost};
821 $totallistprice += $onhand * $ref->{listprice};
823 $subtotalonhand += $onhand;
824 $subtotalsellprice += $onhand * $ref->{sellprice};
825 $subtotallastcost += $onhand * $ref->{lastcost};
826 $subtotallistprice += $onhand * $ref->{listprice};
831 . $form->format_amount(\%myconfig, $ref->{rop}) . "</td>";
832 $column_data{weight} =
834 . $form->format_amount(\%myconfig, $ref->{weight})
836 $column_data{unit} = "<td>$ref->{unit} </td>";
837 $column_data{bin} = "<td>$ref->{bin} </td>";
838 $column_data{priceupdate} = "<td>$ref->{priceupdate} </td>";
840 $column_data{invnumber} =
841 ($ref->{module} ne 'oe')
842 ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&callback=$callback>$ref->{invnumber}</a></td>"
843 : "<td>$ref->{invnumber}</td>";
844 $column_data{ordnumber} =
845 ($ref->{module} eq 'oe')
846 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&callback=$callback>$ref->{ordnumber}</a></td>"
847 : "<td>$ref->{ordnumber}</td>";
848 $column_data{quonumber} =
849 ($ref->{module} eq 'oe' && !$ref->{ordnumber})
850 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&callback=$callback>$ref->{quonumber}</a></td>"
851 : "<td>$ref->{quonumber}</td>";
853 $column_data{name} = "<td>$ref->{name}</td>";
855 $column_data{image} =
857 ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>"
859 $column_data{drawing} =
861 ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>"
863 $column_data{microfiche} =
865 ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>"
868 $column_data{serialnumber} = "<td>$ref->{serialnumber}</td>";
870 $column_data{soldtotal} = "<td align=right>$ref->{soldtotal}</td>";
874 print "<tr class=listrow$i>";
876 map { print "\n$column_data{$_}" } @column_index;
883 if ($form->{l_subtotal} eq 'Y') {
887 if ($form->{"l_linetotal"}) {
888 map { $column_data{$_} = "<td> </td>" } @column_index;
889 $column_data{linetotalsellprice} =
890 "<th class=listtotal align=right>"
891 . $form->format_amount(\%myconfig, $totalsellprice, 2)
893 $column_data{linetotallastcost} =
894 "<th class=listtotal align=right>"
895 . $form->format_amount(\%myconfig, $totallastcost, 2)
897 $column_data{linetotallistprice} =
898 "<th class=listtotal align=right>"
899 . $form->format_amount(\%myconfig, $totallistprice, 2)
902 print "<tr class=listtotal>";
904 map { print "\n$column_data{$_}" } @column_index;
911 <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
920 <form method=post action=$form->{script}>
922 <input type=hidden name=itemstatus value="$form->{itemstatus}">
923 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
924 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
925 <input type=hidden name=l_description value="$form->{l_description}">
926 <input type=hidden name=l_onhand value="$form->{l_onhand}">
927 <input type=hidden name=l_unit value="$form->{l_unit}">
928 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
929 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
930 <input type=hidden name=sort value="$form->{sort}">
931 <input type=hidden name=revers value="$form->{revers}">
932 <input type=hidden name=lastsort value="$form->{lastsort}">
933 <input type=hidden name=parts value="$form->{parts}">
935 <input type=hidden name=bom value="$form->{bom}">
936 <input type=hidden name=titel value="$form->{titel}">
937 <input type=hidden name=searchitems value="$form->{searchitems}">|;
942 <input type=hidden name=ndxs_counter value="$form->{ndxs_counter}">
944 <input class=submit type=submit name=action value="|
945 . $locale->text('choice') . qq|">
953 $lxdebug->leave_sub();
958 # Warning, deep magic ahead.
959 # This function parses the requested details, sanity checks them, and converts them into a format thats usable for IC->all_parts
961 # flags coming from the form:
963 # searchitems=part revers=0 lastsort=''
966 # partnumber ean description partsgroup serialnumber make model drawing microfiche
967 # transdatefrom transdateto
970 # itemstatus = active | onhand | short | obsolete | orphaned
971 # action = continue | top100
974 # bought sold onorder ordered rfq quoted
975 # l_partnumber l_description l_serialnumber l_unit l_listprice l_sellprice l_lastcost
976 # l_linetotal l_priceupdate l_bin l_rop l_weight l_image l_drawing l_microfiche
977 # l_partsgroup l_subtotal l_soldtotal l_deliverydate
980 # nextsub revers lastsort sort ndxs_counter
982 sub generate_report {
983 $lxdebug->enter_sub();
985 $auth->assert('part_service_assembly_edit');
987 my ($revers, $lastsort, $description);
989 $form->{title} = (ucfirst $form->{searchitems}) . "s";
990 $form->{title} = $locale->text($form->{title});
992 my $revers = $form->{revers};
993 my $lastsort = $form->{lastsort};
995 # sorting and direction of sorting
996 # ToDO: change this to the simpler field+direction method
997 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
999 $form->{lastsort} = "partnumber";
1000 $form->{sort} = "partnumber";
1002 if ($form->{lastsort} eq $form->{sort}) {
1003 $form->{revers} = 1 - $form->{revers};
1005 $form->{revers} = 0;
1006 $form->{lastsort} = $form->{sort};
1010 # special case if we have a serialnumber limit search
1011 # serialnumbers are only given in invoices and orders,
1012 # so they can only pop up in bought, sold, rfq, and quoted stuff
1013 $form->{no_sn_joins} = 'Y' if ( !$form->{bought} && !$form->{sold}
1014 && !$form->{rfq} && !$form->{quoted}
1015 && ($form->{l_serialnumber} || $form->{serialnumber}));
1017 # special case for any checkbox of bought | sold | onorder | ordered | rfq | quoted.
1018 # if any of these are ticked the behavior changes slightly for lastcost
1019 # since all those are aggregation checks for the legder tables this is an internal switch
1020 # refered to as ledgerchecks
1021 $form->{ledgerchecks} = 'Y' if ( $form->{bought} || $form->{sold} || $form->{onorder}
1022 || $form->{ordered} || $form->{rfq} || $form->{quoted});
1024 # if something should be activated if something else is active, enter it here
1025 my %dependencies = (
1026 onhand => [ qw(l_onhand) ],
1027 short => [ qw(l_onhand) ],
1028 onorder => [ qw(l_ordnumber) ],
1029 ordered => [ qw(l_ordnumber) ],
1030 rfq => [ qw(l_quonumber) ],
1031 quoted => [ qw(l_quonumber) ],
1032 bought => [ qw(l_invnumber) ],
1033 sold => [ qw(l_invnumber) ],
1034 ledgerchecks => [ qw(l_name) ],
1035 serialnumber => [ qw(l_serialnumber) ],
1036 no_sn_joins => [ qw(bought sold) ],
1039 # these strings get displayed at the top of the results to indicate the user which switches were used
1041 active => $locale->text('Active'),
1042 obsolete => $locale->text('Obsolete'),
1043 orphaned => $locale->text('Orphaned'),
1044 onhand => $locale->text('On Hand'),
1045 short => $locale->text('Short'),
1046 onorder => $locale->text('On Order'),
1047 ordered => $locale->text('Ordered'),
1048 rfq => $locale->text('RFQ'),
1049 quoted => $locale->text('Quoted'),
1050 bought => $locale->text('Bought'),
1051 sold => $locale->text('Sold'),
1052 transdatefrom => $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1),
1053 transdateto => $locale->text('To (time)') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1),
1054 partnumber => $locale->text('Part Number') . ": '$form->{partnumber}'",
1055 partsgroup => $locale->text('Group') . ": '$form->{partsgroup}'",
1056 serialnumber => $locale->text('Serial Number') . ": '$form->{serialnumber}'",
1057 description => $locale->text('Part Description') . ": '$form->{description}'",
1058 make => $locale->text('Make') . ": '$form->{make}'",
1059 model => $locale->text('Model') . ": '$form->{model}'",
1060 drawing => $locale->text('Drawing') . ": '$form->{drawing}'",
1061 microfiche => $locale->text('Microfiche') . ": '$form->{microfiche}'",
1062 l_soldtotal => $locale->text('soldtotal'),
1065 my @itemstatus_keys = qw(active obsolete orphaned onhand short);
1066 my @callback_keys = qw(onorder ordered rfq quoted bought sold partnumber partsgroup serialnumber description make model
1067 drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto ean);
1069 # calculate dependencies
1070 for (@itemstatus_keys, @callback_keys) {
1071 next if ($form->{itemstatus} ne $_ && !$form->{$_});
1072 map { $form->{$_} = 'Y' } @{ $dependencies{$_} } if $dependencies{$_};
1075 # generate callback and optionstrings
1077 for my $key (@itemstatus_keys, @callback_keys) {
1078 next if ($form->{itemstatus} ne $key && !$form->{$key});
1079 push @options, $optiontexts{$key};
1082 # special case for lastcost
1083 $form->{l_lastcost} = "" if $form->{ledgerchecks};
1085 if ($form->{description}) {
1086 $description = $form->{description};
1087 $description =~ s/\n/<br>/g;
1090 if ($form->{l_linetotal}) {
1091 $form->{l_onhand} = "Y";
1092 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
1093 if ($form->{l_lastcost}) {
1094 $form->{l_linetotallastcost} = "Y";
1095 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
1096 $form->{l_linetotallastcost} = "";
1099 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
1102 if ($form->{searchitems} eq 'service') {
1104 # remove bin, weight and rop from list
1105 map { $form->{"l_$_"} = "" } qw(bin weight rop);
1107 $form->{l_onhand} = "";
1109 # qty is irrelevant unless bought or sold
1110 if ( $form->{bought}
1115 || $form->{quoted}) {
1116 $form->{l_onhand} = "Y";
1118 $form->{l_linetotalsellprice} = "";
1119 $form->{l_linetotallastcost} = "";
1123 $form->{l_lastcost} = "" if ($form->{searchitems} eq 'assembly' && !$form->{bom});
1125 IC->all_parts(\%myconfig, \%$form);
1128 qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost
1129 priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal deliverydate);
1132 'bin' => { 'text' => $locale->text('Bin'), },
1133 'deliverydate' => { 'text' => $locale->text('deliverydate'), },
1134 'description' => { 'text' => $locale->text('Part Description'), },
1135 'drawing' => { 'text' => $locale->text('Drawing'), },
1136 'image' => { 'text' => $locale->text('Image'), },
1137 'invnumber' => { 'text' => $locale->text('Invoice Number'), },
1138 'lastcost' => { 'text' => $locale->text('Last Cost'), },
1139 'linetotallastcost' => { 'text' => $locale->text('Extended'), },
1140 'linetotallistprice' => { 'text' => $locale->text('Extended'), },
1141 'linetotalsellprice' => { 'text' => $locale->text('Extended'), },
1142 'listprice' => { 'text' => $locale->text('List Price'), },
1143 'microfiche' => { 'text' => $locale->text('Microfiche'), },
1144 'name' => { 'text' => $locale->text('Name'), },
1145 'onhand' => { 'text' => $locale->text('Qty'), },
1146 'ordnumber' => { 'text' => $locale->text('Order Number'), },
1147 'partnumber' => { 'text' => $locale->text('Part Number'), },
1148 'partsgroup' => { 'text' => $locale->text('Group'), },
1149 'priceupdate' => { 'text' => $locale->text('Updated'), },
1150 'quonumber' => { 'text' => $locale->text('Quotation'), },
1151 'rop' => { 'text' => $locale->text('ROP'), },
1152 'sellprice' => { 'text' => $locale->text('Sell Price'), },
1153 'serialnumber' => { 'text' => $locale->text('Serial Number'), },
1154 'soldtotal' => { 'text' => $locale->text('soldtotal'), },
1155 'unit' => { 'text' => $locale->text('Unit'), },
1156 'weight' => { 'text' => $locale->text('Weight'), },
1159 map { $column_defs{$_}->{visible} = $form->{"l_$_"} ? 1 : 0 } @columns;
1160 map { $column_defs{$_}->{align} = 'right' } qw(onhand sellprice listprice lastcost linetotalsellprice linetotallastcost linetotallistprice rop weight soldtotal);
1162 my @hidden_variables = (qw(l_subtotal l_linetotal searchitems itemstatus bom), @itemstatus_keys, @callback_keys, map { "l_$_" } @columns);
1163 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
1165 my @sort_full = qw(partnumber description onhand soldtotal deliverydate);
1166 my @sort_no_revers = qw(partsgroup bin priceupdate invnumber ordnumber quonumber name image drawing serialnumber);
1168 foreach my $col (@sort_full) {
1169 $column_defs{$col}->{link} = join '&', $callback, "sort=$col", map { "$_=" . E($form->{$_}) } qw(revers lastsort);
1171 map { $column_defs{$_}->{link} = "${callback}&sort=$_" } @sort_no_revers;
1173 # add order to callback
1174 $form->{callback} = join '&', ($callback, map { "${_}=" . E($form->{$_}) } qw(sort revers));
1176 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1178 my %attachment_basenames = (
1179 'part' => $locale->text('part_list'),
1180 'service' => $locale->text('service_list'),
1181 'assembly' => $locale->text('assembly_list'),
1184 $report->set_options('top_info_text' => $locale->text('Options') . ': ' . join(', ', grep $_, @options),
1185 'raw_bottom_info_text' => $form->parse_html_template('ic/generate_report_bottom'),
1186 'output_format' => 'HTML',
1187 'title' => $form->{title},
1188 'attachment_basename' => $attachment_basenames{$form->{searchitems}} . strftime('_%Y%m%d', localtime time),
1190 $report->set_options_from_form();
1192 $report->set_columns(%column_defs);
1193 $report->set_column_order(@columns);
1195 $report->set_export_options('generate_report', @hidden_variables, qw(sort revers));
1197 $report->set_sort_indicator($form->{sort}, $form->{revers} ? 0 : 1);
1199 my @subtotal_columns = qw(sellprice listprice lastcost);
1200 my %subtotals = map { $_ => 0 } ('onhand', @subtotal_columns);
1201 my %totals = map { $_ => 0 } @subtotal_columns;
1203 my $same_item = $form->{parts}[0]{ $form->{sort} } if (scalar @{ $form->{parts} });
1206 foreach my $ref (@{ $form->{parts} }) {
1208 # fresh row, for inserting later
1209 my $row = { map { $_ => { 'data' => $ref->{$_} } } @columns };
1211 $ref->{exchangerate} ||= 1;
1212 $ref->{price_factor} ||= 1;
1213 $ref->{sellprice} *= $ref->{exchangerate} / $ref->{price_factor};
1214 $ref->{listprice} *= $ref->{exchangerate} / $ref->{price_factor};
1215 $ref->{lastcost} *= $ref->{exchangerate} / $ref->{price_factor};
1217 # use this for assemblies
1218 my $onhand = $ref->{onhand};
1220 if ($ref->{assemblyitem}) {
1221 $row->{partnumber}{align} = 'right';
1222 $row->{onhand}{data} = 0;
1223 $onhand = 0 if ($form->{sold});
1226 my $edit_link = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback');
1227 $row->{partnumber}->{link} = $edit_link;
1228 $row->{description}->{link} = $edit_link;
1230 foreach (qw(sellprice listprice lastcost)) {
1231 $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}, -2);
1232 $row->{"linetotal$_"}{data} = $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2);
1235 map { $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}); } qw(onhand rop weight soldtotal);
1237 if (!$ref->{assemblyitem}) {
1238 foreach my $col (@subtotal_columns) {
1239 $totals{$col} += $onhand * $ref->{$col};
1240 $subtotals{$col} += $onhand * $ref->{$col};
1243 $subtotals{onhand} += $onhand;
1247 if ($ref->{module} eq 'oe') {
1248 my $edit_oe_link = build_std_url("script=oe.pl", 'action=edit', 'type=' . E($ref->{type}), 'id=' . E($ref->{trans_id}), 'callback');
1249 $row->{ordnumber}{link} = $edit_oe_link;
1250 $row->{quonumber}{link} = $edit_oe_link if (!$ref->{ordnumber});
1253 $row->{invnumber}{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'type=invoice', 'id=' . E($ref->{trans_id}), 'callback');
1256 # set properties of images
1257 if ($ref->{image} && (lc $report->{options}->{output_format} eq 'html')) {
1258 $row->{image}{data} = '';
1259 $row->{image}{raw_data} = '<a href="' . H($ref->{image}) . '"><img src="' . H($ref->{image}) . '" height="32" border="0"></a>';
1261 map { $row->{$_}{link} = $ref->{$_} } qw(drawing microfiche);
1263 $report->add_data($row);
1265 my $next_ref = $form->{parts}[$idx + 1];
1267 # insert subtotal rows
1268 if (($form->{l_subtotal} eq 'Y') &&
1270 (!$next_ref->{assemblyitem} && ($same_item ne $next_ref->{ $form->{sort} })))) {
1271 my $row = { map { $_ => { 'class' => 'listsubtotal', } } @columns };
1273 if (($form->{searchitems} ne 'assembly') || !$form->{bom}) {
1274 $row->{onhand}->{data} = $form->format_amount(\%myconfig, $subtotals{onhand});
1277 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $subtotals{$_}, 2) } @subtotal_columns;
1278 map { $subtotals{$_} = 0 } ('onhand', @subtotal_columns);
1280 $report->add_data($row);
1282 $same_item = $next_ref->{ $form->{sort} };
1288 if ($form->{"l_linetotal"}) {
1289 my $row = { map { $_ => { 'class' => 'listtotal', } } @columns };
1291 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } @subtotal_columns;
1293 $report->add_separator();
1294 $report->add_data($row);
1297 $report->generate_with_headers();
1299 $lxdebug->leave_sub();
1300 } #end generate_report
1302 sub parts_subtotal {
1303 $lxdebug->enter_sub();
1305 $auth->assert('part_service_assembly_edit');
1308 our (%column_data, @column_index);
1309 our ($subtotalonhand, $totalsellprice, $totallastcost, $totallistprice, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
1311 map { $column_data{$_} = "<td> </td>" } @column_index;
1312 $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});
1314 $column_data{onhand} =
1315 "<th class=listsubtotal align=right>"
1316 . $form->format_amount(\%myconfig, $subtotalonhand)
1319 $column_data{linetotalsellprice} =
1320 "<th class=listsubtotal align=right>"
1321 . $form->format_amount(\%myconfig, $subtotalsellprice, 2)
1323 $column_data{linetotallistprice} =
1324 "<th class=listsubtotal align=right>"
1325 . $form->format_amount(\%myconfig, $subtotallistprice, 2)
1327 $column_data{linetotallastcost} =
1328 "<th class=listsubtotal align=right>"
1329 . $form->format_amount(\%myconfig, $subtotallastcost, 2)
1332 $subtotalonhand = 0;
1333 $subtotalsellprice = 0;
1334 $subtotallistprice = 0;
1335 $subtotallastcost = 0;
1337 print "<tr class=listsubtotal>";
1339 map { print "\n$column_data{$_}" } @column_index;
1345 $lxdebug->leave_sub();
1349 $lxdebug->enter_sub();
1351 $auth->assert('part_service_assembly_edit');
1353 # show history button
1354 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
1355 #/show hhistory button
1356 IC->get_part(\%myconfig, \%$form);
1358 $form->{"original_partnumber"} = $form->{"partnumber"};
1360 $form->{title} = $locale->text('Edit ' . ucfirst $form->{item});
1365 $lxdebug->leave_sub();
1369 $lxdebug->enter_sub();
1371 $auth->assert('part_service_assembly_edit');
1373 IC->create_links("IC", \%myconfig, \%$form);
1376 map({ $form->{selectcurrency} .= "<option>$_\n" }
1377 split(/:/, $form->{currencies}));
1379 # parts and assemblies have the same links
1380 my $item = $form->{item};
1381 if ($form->{item} eq 'assembly') {
1385 # build the popup menus
1386 $form->{taxaccounts} = "";
1387 foreach my $key (keys %{ $form->{IC_links} }) {
1388 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1390 # if this is a tax field
1391 if ($key =~ /IC_tax/) {
1392 if ($key =~ /\Q$item\E/) {
1393 $form->{taxaccounts} .= "$ref->{accno} ";
1394 $form->{"IC_tax_$ref->{accno}_description"} =
1395 "$ref->{accno}--$ref->{description}";
1398 if ($form->{amount}{ $ref->{accno} }) {
1399 $form->{"IC_tax_$ref->{accno}"} = "checked";
1402 $form->{"IC_tax_$ref->{accno}"} = "checked";
1407 $form->{"select$key"} .=
1408 "<option $ref->{selected}>$ref->{accno}--$ref->{description}\n";
1409 if ($form->{amount}{$key} eq $ref->{accno}) {
1410 $form->{$key} = "$ref->{accno}--$ref->{description}";
1416 chop $form->{taxaccounts};
1418 if (($form->{item} eq "part") || ($form->{item} eq "assembly")) {
1419 $form->{selectIC_income} = $form->{selectIC_sale};
1420 $form->{selectIC_expense} = $form->{selectIC_cogs};
1421 $form->{IC_income} = $form->{IC_sale};
1422 $form->{IC_expense} = $form->{IC_cogs};
1425 delete $form->{IC_links};
1426 delete $form->{amount};
1428 $form->get_partsgroup(\%myconfig, { all => 1 });
1430 $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
1432 if (@{ $form->{all_partsgroup} }) {
1433 $form->{selectpartsgroup} = qq|<option>\n|;
1434 map { $form->{selectpartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} };
1437 if ($form->{item} eq 'assembly') {
1439 foreach my $i (1 .. $form->{assembly_rows}) {
1440 if ($form->{"partsgroup_id_$i"}) {
1441 $form->{"partsgroup_$i"} =
1442 qq|$form->{"partsgroup_$i"}--$form->{"partsgroup_id_$i"}|;
1445 $form->get_partsgroup(\%myconfig);
1447 if (@{ $form->{all_partsgroup} }) {
1448 $form->{selectassemblypartsgroup} = qq|<option>\n|;
1451 $form->{selectassemblypartsgroup} .=
1452 qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
1453 } @{ $form->{all_partsgroup} };
1456 $lxdebug->leave_sub();
1460 $lxdebug->enter_sub();
1462 $auth->assert('part_service_assembly_edit');
1464 $form->{eur} = $eur; # config dumps into namespace - yuck
1465 $form->{pg_keys} = sub { "$_[0]->{partsgroup}--$_[0]->{id}" };
1466 $form->{description_area} = ($form->{rows} = $form->numtextrows($form->{description}, 40)) > 1;
1467 $form->{notes_rows} = max 4, $form->numtextrows($form->{notes}, 40), $form->numtextrows($form->{formel}, 40);
1469 map { $form->{"is_$_"} = ($form->{item} eq $_) } qw(part service assembly);
1470 map { $form->{$_} =~ s/"/"/g; } qw(unit);
1472 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS',
1473 'partsgroup' => 'all_partsgroup');
1475 IC->retrieve_buchungsgruppen(\%myconfig, $form);
1476 @{ $form->{BUCHUNGSGRUPPEN} } = grep { $_->{id} eq $form->{buchungsgruppen_id} || ($form->{id} && $form->{orphaned}) || !$form->{id} } @{ $form->{BUCHUNGSGRUPPEN} };
1478 # use JavaScript Calendar or not (yes!)
1479 $form->{jsscript} = 1;
1481 $units = AM->retrieve_units(\%myconfig, $form, $form->{"item"} eq "service" ? "service" : "dimension");
1482 $form->{ALL_UNITS} = [ map +{ name => $_ }, sort { $units->{$a}{sortkey} <=> $units->{$b}{sortkey} } keys %$units ];
1484 $form->{fokus} = "ic.partnumber";
1487 print $form->parse_html_template('ic/form_header', { ALL_PRICE_FACTORS => $form->{ALL_PRICE_FACTORS},
1488 ALL_UNITS => $form->{ALL_UNITS},
1489 BUCHUNGSGRUPPEN => $form->{BUCHUNGSGRUPPEN},
1490 payment_terms => $form->{payment_terms},
1491 all_partsgroup => $form->{all_partsgroup}});
1492 $lxdebug->leave_sub();
1496 $lxdebug->enter_sub();
1498 $auth->assert('part_service_assembly_edit');
1500 if ($form->{item} eq "assembly") {
1505 <table width="100%">
1507 <th colspan=2 align=right>| . $locale->text('Total') . qq| </th>
1508 <th align=right>| . $form->format_amount(\%myconfig, $form->{assemblytotal}, 2) . qq|</th>
1513 <input type=hidden name=assembly_rows value=$form->{assembly_rows}>
1518 <input type=hidden name=callback value="$form->{callback}">
1519 <input type=hidden name=previousform value="$form->{previousform}">
1520 <input type=hidden name=taxaccount2 value="$form->{taxaccount2}">
1521 <input type=hidden name=vc value=$form->{vc}>
1523 <td><hr size=3 noshade></td>
1528 <input class=submit type=submit name=action value="|
1529 . $locale->text('Update') . qq|">
1532 unless ($form->{item} eq "service") {
1534 <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}>
1539 <input type=hidden name=price_rows value=$form->{price_rows}>|;
1542 <input class=submit type=submit name=action value="|
1543 . $locale->text('Save') . qq|">|;
1547 if (!$form->{previousform}) {
1549 <input class=submit type=submit name=action value="|
1550 . $locale->text('Save as new') . qq|">|;
1553 if ($form->{orphaned}) {
1554 if (!$form->{previousform}) {
1555 if ($form->{item} eq 'assembly') {
1556 if (!$form->{onhand}) {
1558 <input class=submit type=submit name=action value="|
1559 . $locale->text('Delete') . qq|">|;
1563 <input class=submit type=submit name=action value="|
1564 . $locale->text('Delete') . qq|">|;
1570 if (!$form->{previousform}) {
1571 if ($form->{menubar}) {
1572 require "bin/mozilla/menu.pl";
1576 # button for saving history
1577 if($form->{id} ne "") {
1579 <input type=button class=submit onclick=set_history_window(|
1581 . qq|); name=history id=history value=|
1582 . $locale->text('history')
1585 # /button for saving history
1590 <script type="text/javascript" src="js/wz_tooltip.js"></script>
1596 $lxdebug->leave_sub();
1600 $lxdebug->enter_sub();
1608 <th class="listheading">| . $locale->text('Make') . qq|</th>
1609 <th class="listheading">| . $locale->text('Model') . qq|</th>
1613 for my $i (1 .. $numrows) {
1614 $form->{"make_$i"} =~ s/\"/"/g;
1615 $form->{"model_$i"} =~ s/\"/"/g;
1618 <td width=50%><input name="make_$i" size=30 value="$form->{"make_$i"}"></td>
1619 <td width=50%><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>
1630 $lxdebug->leave_sub();
1634 $lxdebug->enter_sub();
1636 my (@column_index, %column_data, %column_header);
1637 my ($nochange, $callback, $previousform, $linetotal, $href);
1639 our ($deliverydate); # ToDO: cjeck if this indeed comes from global context
1642 qw(runningnumber qty unit bom partnumber description partsgroup total);
1644 if ($form->{previousform}) {
1646 @column_index = qw(qty unit bom partnumber description partsgroup total);
1650 $form->{old_callback} = $form->{callback};
1651 $callback = $form->{callback};
1652 $form->{callback} = "$form->{script}?action=display_form";
1655 map { delete $form->{$_} } qw(action header);
1659 # save form variables in a previousform variable
1660 foreach my $key (sort keys %$form) {
1663 $form->{$key} =~ s/&/%26/g;
1664 $previousform .= qq|$key=$form->{$key}&|;
1667 $previousform = $form->escape($form->escape($previousform, 1));
1668 $form->{callback} = $callback;
1670 $form->{assemblytotal} = 0;
1671 $form->{weight} = 0;
1674 $column_header{runningnumber} =
1675 qq|<th nowrap width=5%>| . $locale->text('No.') . qq|</th>|;
1676 $column_header{qty} =
1677 qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
1678 $column_header{unit} =
1679 qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
1680 $column_header{partnumber} =
1681 qq|<th align=left nowrap width=20%>|
1682 . $locale->text('Part Number')
1684 $column_header{description} =
1685 qq|<th nowrap width=50%>| . $locale->text('Part Description') . qq|</th>|;
1686 $column_header{total} =
1687 qq|<th align=right nowrap>| . $locale->text('Extended') . qq|</th>|;
1688 $column_header{bom} = qq|<th>| . $locale->text('BOM') . qq|</th>|;
1689 $column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
1692 <tr class=listheading>
1693 <th class=listheading>| . $locale->text('Individual Items') . qq|</th>
1701 map { print "\n$column_header{$_}" } @column_index;
1707 for my $i (1 .. $numrows) {
1708 $form->{"partnumber_$i"} =~ s/\"/"/g;
1711 $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
1712 $form->{assemblytotal} += $linetotal;
1714 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1716 $linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
1718 if (($i >= 1) && ($i == $numrows)) {
1721 map { $column_data{$_} = qq|<td></td>| }
1722 qw(qty unit partnumber description bom partsgroup);
1725 map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom);
1728 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
1729 $column_data{partnumber} =
1730 qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
1731 $column_data{description} =
1732 qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
1733 $column_data{partsgroup} =
1734 qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|;
1740 if ($form->{previousform}) {
1741 $column_data{partnumber} =
1742 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|;
1744 qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|;
1747 qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|;
1748 $column_data{bom} .= ($form->{"bom_$i"}) ? "x" : " ";
1749 $column_data{bom} .= qq|</td>|;
1751 $column_data{partsgroup} =
1752 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
1756 qq|$form->{script}?action=edit&id=$form->{"id_$i"}&rowcount=$i&previousform=$previousform|;
1757 $column_data{partnumber} =
1758 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|;
1759 $column_data{runningnumber} =
1760 qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
1762 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
1764 $form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : "";
1766 qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
1768 $column_data{partsgroup} =
1769 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
1772 $column_data{unit} =
1773 qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
1774 $column_data{description} =
1775 qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
1778 $column_data{total} = qq|<td align=right>$linetotal</td>|;
1780 $column_data{deliverydate} = qq|<td align=right>$deliverydate</td>|;
1785 map { print "\n$column_data{$_}" } @column_index;
1789 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
1790 <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
1791 <input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
1801 $lxdebug->leave_sub();
1805 $lxdebug->enter_sub();
1807 if ($form->{item} eq "assembly") {
1808 my $i = $form->{assembly_rows};
1810 # if last row is empty check the form otherwise retrieve item
1811 if ( ($form->{"partnumber_$i"} eq "")
1812 && ($form->{"description_$i"} eq "")
1813 && ($form->{"partsgroup_$i"} eq "")) {
1819 IC->assembly_item(\%myconfig, \%$form);
1821 my $rows = scalar @{ $form->{item_list} };
1824 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1827 $form->{makemodel_rows}--;
1831 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1832 qw(partnumber description unit partsgroup);
1833 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1834 keys %{ $form->{item_list}[0] };
1835 $form->{"runningnumber_$i"} = $form->{assembly_rows};
1836 $form->{assembly_rows}++;
1844 $form->{rowcount} = $i;
1845 $form->{assembly_rows}++;
1852 } elsif (($form->{item} eq 'part') || ($form->{item} eq 'service')) {
1856 $lxdebug->leave_sub();
1860 $lxdebug->enter_sub();
1862 $auth->assert('part_service_assembly_edit');
1864 my ($parts_id, %newform, $previousform, $amount, $callback);
1866 # check if there is a part number - commented out, cause there is an automatic allocation of numbers
1867 # $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Part Number missing!"));
1869 # check if there is a description
1870 $form->isblank("description", $locale->text("Part Description missing!"));
1872 if ($form->{obsolete}) {
1875 "Inventory quantity must be zero before you can set this $form->{item} obsolete!"
1877 if ($form->{onhand} * 1);
1880 if (!$form->{buchungsgruppen_id}) {
1881 $form->error($locale->text("Parts must have an entry type.") . " " .
1882 $locale->text("If you see this message, you most likely just setup your LX-Office and haven't added any entry types. If this is the case, the option is accessible for administrators in the System menu.")
1886 $form->error($locale->text('Description must not be empty!')) unless $form->{description};
1887 $form->error($locale->text('Partnumber must not be set to empty!')) if $form->{id} && !$form->{partnumber};
1889 # expand dynamic strings
1890 # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
1891 # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
1892 # $locale->text('Part Number missing!')
1893 # $locale->text('Service Number missing!')
1894 # $locale->text('Assembly Number missing!')
1897 $lxdebug->message($LXDebug::DEBUG1, "ic.pl: sellprice in save = $form->{sellprice}\n");
1898 if (IC->save(\%myconfig, \%$form) == 3) {
1899 $form->error($locale->text('Partnumber not unique!'));
1901 # saving the history
1902 if(!exists $form->{addition}) {
1903 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
1904 $form->{addition} = "SAVED";
1905 $form->save_history($form->dbconnect(\%myconfig));
1907 # /saving the history
1908 $parts_id = $form->{id};
1911 # load previous variables
1912 if ($form->{previousform}) {
1914 # save the new form variables before splitting previousform
1915 map { $newform{$_} = $form->{$_} } keys %$form;
1917 $previousform = $form->unescape($form->{previousform});
1919 # don't trample on previous variables
1920 map { delete $form->{$_} } keys %newform;
1922 # now take it apart and restore original values
1923 foreach my $item (split /&/, $previousform) {
1924 my ($key, $value) = split m/=/, $item, 2;
1925 $value =~ s/%26/&/g;
1926 $form->{$key} = $value;
1928 $form->{taxaccounts} = $newform{taxaccount2};
1930 if ($form->{item} eq 'assembly') {
1932 # undo number formatting
1933 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1934 qw(weight listprice sellprice rop);
1936 $form->{assembly_rows}--;
1937 $i = $newform{rowcount};
1938 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1940 $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
1941 $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
1943 # change/add values for assembly item
1944 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno price_factor_id);
1946 $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
1947 $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
1951 # set values for last invoice/order item
1952 $i = $form->{rowcount};
1953 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1955 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice lastcost price_factor_id);
1957 $form->{"longdescription_$i"} = $newform{notes};
1959 $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
1961 if ($form->{exchangerate} != 0) {
1962 $form->{"sellprice_$i"} /= $form->{exchangerate};
1965 $lxdebug->message($LXDebug::DEBUG1, qq|sellprice_$i in previousform 2 = | . $form->{"sellprice_$i"} . qq|\n|);
1967 map { $form->{"taxaccounts_$i"} .= "$_ " } split / /, $newform{taxaccount};
1968 chop $form->{"taxaccounts_$i"};
1969 foreach my $item (qw(description rate taxnumber)) {
1970 my $index = $form->{"taxaccounts_$i"} . "_$item";
1971 $form->{$index} = $newform{$index};
1974 # credit remaining calculation
1975 $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
1977 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
1978 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1980 $form->{creditremaining} -= $amount;
1982 # redo number formatting, because invoice parse them!
1983 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(weight listprice sellprice rop);
1986 $form->{"id_$i"} = $parts_id;
1988 # Get the actual price factor (not just the ID) for the marge calculation.
1989 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
1990 foreach my $pfac (@{ $form->{ALL_PRICE_FACTORS} }) {
1991 next if ($pfac->{id} != $newform{price_factor_id});
1992 $form->{"marge_price_factor_$i"} = $pfac->{factor};
1995 delete $form->{ALL_PRICE_FACTORS};
1997 delete $form->{action};
1999 # restore original callback
2000 $callback = $form->unescape($form->{callback});
2001 $form->{callback} = $form->unescape($form->{old_callback});
2002 delete $form->{old_callback};
2004 $form->{makemodel_rows}--;
2006 # put callback together
2007 foreach my $key (keys %$form) {
2009 # do single escape for Apache 2.0
2010 my $value = $form->escape($form->{$key}, 1);
2011 $callback .= qq|&$key=$value|;
2013 $form->{callback} = $callback;
2015 $lxdebug->message($LXDebug::DEBUG1, qq|ic.pl: sellprice_$i nach sub save = | . $form->{"sellprice_$i"} . qq|\n|);
2020 $lxdebug->leave_sub();
2024 $lxdebug->enter_sub();
2026 $auth->assert('part_service_assembly_edit');
2028 # saving the history
2029 if(!exists $form->{addition}) {
2030 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2031 $form->{addition} = "SAVED AS NEW";
2032 $form->save_history($form->dbconnect(\%myconfig));
2034 # /saving the history
2036 if ($form->{"original_partnumber"} &&
2037 ($form->{"partnumber"} eq $form->{"original_partnumber"})) {
2038 $form->{partnumber} = "";
2041 $lxdebug->leave_sub();
2045 $lxdebug->enter_sub();
2047 $auth->assert('part_service_assembly_edit');
2049 # saving the history
2050 if(!exists $form->{addition}) {
2051 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2052 $form->{addition} = "DELETED";
2053 $form->save_history($form->dbconnect(\%myconfig));
2055 # /saving the history
2056 my $rc = IC->delete(\%myconfig, \%$form);
2059 $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
2060 $form->error($locale->text('Cannot delete item!'));
2062 $lxdebug->leave_sub();
2066 $lxdebug->enter_sub();
2068 $auth->assert('part_service_assembly_edit');
2073 pricegroup => $form->{"pricegroup_$_"},
2074 pricegroup_id => $form->{"pricegroup_id_$_"},
2075 price => $form->{"price_$_"},
2078 print $form->parse_html_template('ic/price_row', { PRICES => \@PRICES });
2080 $lxdebug->leave_sub();
2083 sub parts_language_selection {
2084 $lxdebug->enter_sub();
2086 $auth->assert('part_service_assembly_edit');
2090 my $languages = IC->retrieve_languages(\%myconfig, $form);
2092 if ($form->{language_values} ne "") {
2093 foreach $item (split(/---\+\+\+---/, $form->{language_values})) {
2094 my ($language_id, $translation, $longdescription) = split(/--\+\+--/, $item);
2096 foreach my $language (@{ $languages }) {
2097 next unless ($language->{id} == $language_id);
2099 $language->{translation} = $translation;
2100 $language->{longdescription} = $longdescription;
2106 my @header_sort = qw(name longdescription);
2107 my %header_title = ( "name" => $locale->text("Name"),
2108 "longdescription" => $locale->text("Long Description"),
2112 map(+{ "column_title" => $header_title{$_},
2114 "callback" => $callback,
2118 $form->{"title"} = $locale->text("Language Values");
2120 print $form->parse_html_template("ic/parts_language_selection", { "HEADER" => \@header,
2121 "LANGUAGES" => $languages,
2122 "onload" => $onload });
2124 $lxdebug->leave_sub();
2127 sub continue { call_sub($form->{"nextsub"}); }