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);
38 use SL::ReportGenerator;
46 our ($form, $locale, %myconfig, $lxdebug);
48 require "bin/mozilla/io.pl";
49 require "bin/mozilla/invoice_io.pl";
50 require "bin/mozilla/common.pl";
51 require "bin/mozilla/reportgenerator.pl";
56 # type=submit $locale->text('Add Part')
57 # type=submit $locale->text('Add Service')
58 # type=submit $locale->text('Add Assembly')
59 # type=submit $locale->text('Edit Part')
60 # type=submit $locale->text('Edit Service')
61 # type=submit $locale->text('Edit Assembly')
66 $lxdebug->enter_sub();
68 $auth->assert('part_service_assembly_edit');
70 $form->{title} = $locale->text('Add ' . ucfirst $form->{item});
73 "$form->{script}?action=add&item=$form->{item}"
74 unless $form->{callback};
76 $form->{"unit_changeable"} = 1;
78 IC->get_pricegroups(\%myconfig, \%$form);
82 $lxdebug->leave_sub();
86 $lxdebug->enter_sub();
88 $auth->assert('part_service_assembly_edit');
90 # switch for backward sorting
93 # memory for which table was sort at last time
94 $form->{lastsort} = "";
96 # counter for added entries to top100
97 $form->{ndxs_counter} = 0;
99 # $locale->text('Parts')
100 # $locale->text('Services')
102 my $is_service = $form->{searchitems} eq 'service';
103 my $is_assembly = $form->{searchitems} eq 'assembly';
105 $form->{title} = (ucfirst $form->{searchitems}) . "s";
106 $form->{title} = $locale->text($form->{title});
107 $form->{title} = $locale->text('Assemblies') if $is_assembly;
109 $form->{jsscript} = 1;
113 print $form->parse_html_template('ic/search', { is_assembly => $is_assembly,
114 is_service => $is_service,
115 dateformat => $myconfig{dateformat}, });
117 $lxdebug->leave_sub();
120 sub search_update_prices {
121 $lxdebug->enter_sub();
123 $auth->assert('part_service_assembly_edit');
125 my $pricegroups = IC->get_pricegroups(\%myconfig, \%$form);
129 print $form->parse_html_template('ic/search_update_prices', { PRICE_ROWS => $pricegroups });
131 $lxdebug->leave_sub();
134 sub confirm_price_update {
135 $lxdebug->enter_sub();
137 $auth->assert('part_service_assembly_edit');
139 $form->{nextsub} = "update_prices";
142 map { delete $form->{$_} } qw(action header);
144 print $form->parse_html_template('ic/confirm_price_update', { HIDDENS => [ map { name => $_, value => $form->{$_} }, keys %$form ] });
146 $lxdebug->leave_sub();
150 $lxdebug->enter_sub();
152 $auth->assert('part_service_assembly_edit');
154 if (IC->update_prices(\%myconfig, \%$form)) {
155 $form->redirect($form->{update_count} . $locale->text('prices updated!'));
157 $form->error($locale->text('Could not update prices!'));
160 $lxdebug->leave_sub();
164 $lxdebug->enter_sub();
166 $auth->assert('part_service_assembly_edit');
171 $form->{title} = $locale->text('Top 100 hinzufuegen');
175 push @custom_hiddens, qw(searchitems title bom titel revers lastsort sort ndxs_counter extras);
176 push @custom_hiddens, qw(itemstatus l_linetotal l_partnumber l_description l_onhand l_unit l_sellprice l_linetotalsellprice);
178 +{ name => 'row', value => $j },
179 +{ name => 'nextsub', value => 'item_selected' },
180 +{ name => 'test', value => 'item_selected' },
181 +{ name => 'lastndx', value => $lastndx },
182 map(+{ name => $_, value => $form->{$_} }, @custom_hiddens),
185 my ($partnumber, $description, $unit, $sellprice, $soldtotal);
187 # if ($form->{ndx}) {
188 # for my $i (0 .. $form->{ndxs_counter}) {
190 # # insert data into top100
191 # push @{ $form->{parts} },
193 # partnumber => $form->{"totop100_partnumber_$j"},
194 # description => $form->{"totop100_description_$j"},
195 # unit => $form->{"totop100_unit_$j"},
196 # sellprice => $form->{"totop100_sellprice_$j"},
197 # soldtotal => $form->{"totop100_soldtotal_$j"},
204 # set data for next page
205 for my $i (1 .. $form->{ndxs_counter}) {
206 $partnumber = $form->{"totop100_partnumber_$i"};
207 $description = $form->{"totop100_description_$i"};
208 $unit = $form->{"totop100_unit_$i"};
209 $sellprice = $form->{"totop100_sellprice_$i"};
210 $soldtotal = $form->{"totop100_soldtotal_$i"};
213 totop100_partnumber => $form->{"totop100_partnumber_$i"},
214 totop100_description => $form->{"totop100_description_$i"},
215 totop100_unit => $form->{"totop100_unit_$i"},
216 totop100_sellprice => $form->{"totop100_sellprice_$i"},
217 totop100_soldtotal => $form->{"totop100_soldtotal_$i"},
221 #<input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
222 #<input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
223 #<input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
224 #<input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
225 #<input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
229 print $form->parse_html_template('ic/choice', +{ HIDDENS => \@HIDDENS, PARTS => \@PARTS });
231 $lxdebug->leave_sub();
235 $lxdebug->enter_sub();
237 $auth->assert('part_service_assembly_edit');
240 our ($partnumber, $description, $unit, $sellprice, $soldtotal);
242 my @sortorders = ("", "partnumber", "description", "all");
243 my $sortorder = $sortorders[($form->{description} ? 2 : 0) + ($form->{partnumber} ? 1 : 0)];
244 IC->get_parts(\%myconfig, \%$form, $sortorder);
246 $form->{title} = $locale->text('Top 100 hinzufuegen');
252 <form method=post action=ic.pl>
255 <th class=listtop colspan=6>| . $locale->text('choice part') . qq|</th>
258 <tr class=listheading>
260 <th class=listheading>| . $locale->text('Part Number') . qq|</th>
261 <th class=listheading>| . $locale->text('Part Description') . qq|</th>
262 <th class=listheading>| . $locale->text('Unit of measure') . qq|</th>
263 <th class=listheading>| . $locale->text('Sell Price') . qq|</th>
264 <th class=listheading>| . $locale->text('soldtotal') . qq|</th>
268 my $i = $form->{rows};
270 for ($j = 1; $j <= $i; $j++) {
273 <tr class=listrow| . ($j % 2) . qq|>|;
276 <td><input name=ndx class=radio type=radio value=$j checked></td>|;
279 <td><input name=ndx class=radio type=radio value=$j></td>|;
282 <td><input name="new_partnumber_$j" type=hidden value="$form->{"partnumber_$j"}">$form->{"partnumber_$j"}</td>
283 <td><input name="new_description_$j" type=hidden value="$form->{"description_$j"}">$form->{"description_$j"}</td>
284 <td><input name="new_unit_$j" type=hidden value="$form->{"unit_$j"}">$form->{"unit_$j"}</td>
285 <td><input name="new_sellprice_$j" type=hidden value="$form->{"sellprice_$j"}">$form->{"sellprice_$j"}</td>
286 <td><input name="new_soldtotal_$j" type=hidden value="$form->{"soldtotal_$j"}">$form->{"soldtotal_$j"}</td>
289 <input name="new_id_$j" type=hidden value="$form->{"id_$j"}">|;
299 <input type=hidden name=itemstatus value="$form->{itemstatus}">
300 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
301 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
302 <input type=hidden name=l_description value="$form->{l_description}">
303 <input type=hidden name=l_onhand value="$form->{l_onhand}">
304 <input type=hidden name=l_unit value="$form->{l_unit}">
305 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
306 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
307 <input type=hidden name=sort value="$form->{sort}">
308 <input type=hidden name=revers value="$form->{revers}">
309 <input type=hidden name=lastsort value="$form->{lastsort}">
311 <input type=hidden name=bom value="$form->{bom}">
312 <input type=hidden name=titel value="$form->{titel}">
313 <input type=hidden name=searchitems value="$form->{searchitems}">
315 <input type=hidden name=row value=$j>
317 <input type=hidden name=nextsub value=item_selected>
319 <input name=lastndx type=hidden value=$lastndx>
321 <input name=ndxs_counter type=hidden value=$form->{ndxs_counter}>|;
325 if (($form->{ndxs_counter}) > 0) {
326 for ($i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
328 $partnumber = $form->{"totop100_partnumber_$i"};
329 $description = $form->{"totop100_description_$i"};
330 $unit = $form->{"totop100_unit_$i"};
331 $sellprice = $form->{"totop100_sellprice_$i"};
332 $soldtotal = $form->{"totop100_soldtotal_$i"};
335 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
336 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
337 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
338 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
339 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
347 <input class=submit type=submit name=action value="|
348 . $locale->text('TOP100') . qq|">
354 $lxdebug->leave_sub();
358 $lxdebug->enter_sub();
360 $auth->assert('part_service_assembly_edit');
363 $form->{ndxs_counter}++;
365 if ($form->{ndxs_counter} > 0) {
367 my $index = $form->{ndx};
369 $form->{"totop100_partnumber_$form->{ndxs_counter}"} = $form->{"new_partnumber_$index"};
370 $form->{"totop100_description_$form->{ndxs_counter}"} = $form->{"new_description_$index"};
371 $form->{"totop100_unit_$form->{ndxs_counter}"} = $form->{"new_unit_$index"};
372 $form->{"totop100_sellprice_$form->{ndxs_counter}"} = $form->{"new_sellprice_$index"};
373 $form->{"totop100_soldtotal_$form->{ndxs_counter}"} = $form->{"new_soldtotal_$index"};
377 $lxdebug->leave_sub();
381 $lxdebug->enter_sub();
383 $auth->assert('part_service_assembly_edit');
385 my ($revers, $lastsort, $callback, $option, $description, $sameitem,
386 $partnumber, $unit, $sellprice, $soldtotal, $totop100, $onhand, $align);
387 my (@column_index, %column_header, %column_data);
388 my ($totalsellprice, $totallastcost, $totallistprice, $subtotalonhand, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
390 $form->{top100} = "top100";
391 $form->{l_soldtotal} = "Y";
392 # $form->{soldtotal} = "soldtotal";
393 $form->{sort} = "soldtotal";
394 $form->{l_qty} = "N";
395 $form->{l_linetotal} = "";
397 $form->{number} = "position";
398 $form->{l_number} = "Y";
402 $form->{title} = $locale->text('Top 100');
404 $revers = $form->{revers};
405 $lastsort = $form->{lastsort};
407 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
409 $form->{lastsort} = "partnumber";
410 $form->{sort} = "partnumber";
414 "$form->{script}?action=top100&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&title="
415 . $form->escape($form->{title}, 1);
417 # if we have a serialnumber limit search
418 if ($form->{serialnumber} || $form->{l_serialnumber}) {
419 $form->{l_serialnumber} = "Y";
420 unless ( $form->{bought}
423 || $form->{quoted}) {
424 $form->{bought} = $form->{sold} = 1;
427 IC->all_parts(\%myconfig, \%$form);
429 if ($form->{itemstatus} eq 'active') {
430 $option .= $locale->text('Active') . " : ";
432 if ($form->{itemstatus} eq 'obsolete') {
433 $option .= $locale->text('Obsolete') . " : ";
435 if ($form->{itemstatus} eq 'orphaned') {
436 $option .= $locale->text('Orphaned') . " : ";
438 if ($form->{itemstatus} eq 'onhand') {
439 $option .= $locale->text('On Hand') . " : ";
440 $form->{l_onhand} = "Y";
442 if ($form->{itemstatus} eq 'short') {
443 $option .= $locale->text('Short') . " : ";
444 $form->{l_onhand} = "Y";
446 if ($form->{onorder}) {
447 $form->{l_ordnumber} = "Y";
448 $callback .= "&onorder=$form->{onorder}";
449 $option .= $locale->text('On Order') . " : ";
451 if ($form->{ordered}) {
452 $form->{l_ordnumber} = "Y";
453 $callback .= "&ordered=$form->{ordered}";
454 $option .= $locale->text('Ordered') . " : ";
457 $form->{l_quonumber} = "Y";
458 $callback .= "&rfq=$form->{rfq}";
459 $option .= $locale->text('RFQ') . " : ";
461 if ($form->{quoted}) {
462 $form->{l_quonumber} = "Y";
463 $callback .= ""ed=$form->{quoted}";
464 $option .= $locale->text('Quoted') . " : ";
466 if ($form->{bought}) {
467 $form->{l_invnumber} = "Y";
468 $callback .= "&bought=$form->{bought}";
469 $option .= $locale->text('Bought') . " : ";
472 $form->{l_invnumber} = "Y";
473 $callback .= "&sold=$form->{sold}";
474 $option .= $locale->text('Sold') . " : ";
481 || $form->{quoted}) {
483 $form->{l_lastcost} = "";
484 $form->{l_name} = "Y";
485 if ($form->{transdatefrom}) {
486 $callback .= "&transdatefrom=$form->{transdatefrom}";
488 . $locale->text('From')
490 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
492 if ($form->{transdateto}) {
493 $callback .= "&transdateto=$form->{transdateto}";
495 . $locale->text('To')
497 . $locale->date(\%myconfig, $form->{transdateto}, 1);
503 if ($form->{partnumber}) {
504 $callback .= "&partnumber=$form->{partnumber}";
505 $option .= $locale->text('Part Number') . qq| : $form->{partnumber}<br>|;
508 $callback .= "&partnumber=$form->{ean}";
509 $option .= $locale->text('EAN') . qq| : $form->{ean}<br>|;
511 if ($form->{partsgroup}) {
512 $callback .= "&partsgroup=$form->{partsgroup}";
513 $option .= $locale->text('Group') . qq| : $form->{partsgroup}<br>|;
515 if ($form->{serialnumber}) {
516 $callback .= "&serialnumber=$form->{serialnumber}";
517 $option .= $locale->text('Serial Number') . qq| : $form->{serialnumber}<br>|;
519 if ($form->{description}) {
520 $callback .= "&description=$form->{description}";
521 $description = $form->{description};
522 $description =~ s/\n/<br>/g;
523 $option .= $locale->text('Part Description') . qq| : $form->{description}<br>|;
526 $callback .= "&make=$form->{make}";
527 $option .= $locale->text('Make') . qq| : $form->{make}<br>|;
529 if ($form->{model}) {
530 $callback .= "&model=$form->{model}";
531 $option .= $locale->text('Model') . qq| : $form->{model}<br>|;
533 if ($form->{drawing}) {
534 $callback .= "&drawing=$form->{drawing}";
535 $option .= $locale->text('Drawing') . qq| : $form->{drawing}<br>|;
537 if ($form->{microfiche}) {
538 $callback .= "µfiche=$form->{microfiche}";
539 $option .= $locale->text('Microfiche') . qq| : $form->{microfiche}<br>|;
541 if ($form->{l_soldtotal}) {
542 $callback .= "&soldtotal=$form->{soldtotal}";
543 $option .= $locale->text('soldtotal') . qq| : $form->{soldtotal}<br>|;
546 my @columns = $form->sort_columns(
547 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)
550 if ($form->{l_linetotal}) {
551 $form->{l_onhand} = "Y";
552 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
553 if ($form->{l_lastcost}) {
554 $form->{l_linetotallastcost} = "Y";
555 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
556 $form->{l_linetotallastcost} = "";
559 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
562 if ($form->{searchitems} eq 'service') {
564 # remove bin, weight and rop from list
565 map { $form->{"l_$_"} = "" } qw(bin weight rop);
567 $form->{l_onhand} = "";
569 # qty is irrelevant unless bought or sold
575 || $form->{quoted}) {
576 $form->{l_onhand} = "Y";
578 $form->{l_linetotalsellprice} = "";
579 $form->{l_linetotallastcost} = "";
583 $form->{l_lastcost} = ""
584 if ($form->{searchitems} eq 'assembly' && !$form->{bom});
586 foreach my $item (@columns) {
587 if ($form->{"l_$item"} eq "Y") {
588 push @column_index, $item;
590 # add column to callback
591 $callback .= "&l_$item=Y";
595 if ($form->{l_subtotal} eq 'Y') {
596 $callback .= "&l_subtotal=Y";
599 $column_header{number} =
600 qq|<th class=listheading nowrap>| . $locale->text('number') . qq|</th>|;
601 $column_header{partnumber} =
602 qq|<th nowrap><a class=listheading href=$callback&sort=partnumber&revers=$form->{revers}&lastsort=$form->{lastsort}>|
603 . $locale->text('Part Number')
605 $column_header{description} =
606 qq|<th nowrap><a class=listheading href=$callback&sort=description&revers=$form->{revers}&lastsort=$form->{lastsort}>|
607 . $locale->text('Part Description')
609 $column_header{partsgroup} =
610 qq|<th nowrap><a class=listheading href=$callback&sort=partsgroup>|
611 . $locale->text('Group')
613 $column_header{bin} =
614 qq|<th><a class=listheading href=$callback&sort=bin>|
615 . $locale->text('Bin')
617 $column_header{priceupdate} =
618 qq|<th nowrap><a class=listheading href=$callback&sort=priceupdate>|
619 . $locale->text('Updated')
621 $column_header{onhand} =
622 qq|<th nowrap><a class=listheading href=$callback&sort=onhand&revers=$form->{revers}&lastsort=$form->{lastsort}>|
623 . $locale->text('Qty')
625 $column_header{unit} =
626 qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
627 $column_header{listprice} =
628 qq|<th class=listheading nowrap>|
629 . $locale->text('List Price')
631 $column_header{lastcost} =
632 qq|<th class=listheading nowrap>| . $locale->text('Last Cost') . qq|</th>|;
633 $column_header{rop} =
634 qq|<th class=listheading nowrap>| . $locale->text('ROP') . qq|</th>|;
635 $column_header{weight} =
636 qq|<th class=listheading nowrap>| . $locale->text('Weight') . qq|</th>|;
638 $column_header{invnumber} =
639 qq|<th nowrap><a class=listheading href=$callback&sort=invnumber>|
640 . $locale->text('Invoice Number')
642 $column_header{ordnumber} =
643 qq|<th nowrap><a class=listheading href=$callback&sort=ordnumber>|
644 . $locale->text('Order Number')
646 $column_header{quonumber} =
647 qq|<th nowrap><a class=listheading href=$callback&sort=quonumber>|
648 . $locale->text('Quotation')
651 $column_header{name} =
652 qq|<th nowrap><a class=listheading href=$callback&sort=name>|
653 . $locale->text('Name')
656 $column_header{sellprice} =
657 qq|<th class=listheading nowrap>|
658 . $locale->text('Sell Price')
660 $column_header{linetotalsellprice} =
661 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
662 $column_header{linetotallastcost} =
663 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
664 $column_header{linetotallistprice} =
665 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
667 $column_header{image} =
668 qq|<th class=listheading nowrap>| . $locale->text('Image') . qq|</a></th>|;
669 $column_header{drawing} =
670 qq|<th nowrap><a class=listheading href=$callback&sort=drawing>|
671 . $locale->text('Drawing')
673 $column_header{microfiche} =
674 qq|<th nowrap><a class=listheading href=$callback&sort=microfiche>|
675 . $locale->text('Microfiche')
678 $column_header{serialnumber} =
679 qq|<th nowrap><a class=listheading href=$callback&sort=serialnumber>|
680 . $locale->text('Serial Number')
682 $column_header{soldtotal} =
683 qq|<th nowrap><a class=listheading href=$callback&sort=soldtotal&revers=$form->{revers}&lastsort=$form->{lastsort}>|
684 . $locale->text('soldtotal')
688 my $colspan = $#column_index + 1;
695 <th class=listtop colspan=$colspan>$form->{title}</th>
699 <tr><td colspan=$colspan>$option</td></tr>
701 <tr class=listheading>
704 map { print "\n$column_header{$_}" } @column_index;
710 # add order to callback
711 $form->{callback} = $callback .= "&sort=$form->{sort}";
713 # escape callback for href
714 $callback = $form->escape($callback);
716 if (@{ $form->{parts} }) {
717 $sameitem = $form->{parts}->[0]->{ $form->{sort} };
720 # insert numbers for top100
722 foreach my $ref (@{ $form->{parts} }) {
727 # if avaible -> insert choice here
728 if (($form->{ndxs_counter}) > 0) {
729 for (my $i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
730 $partnumber = $form->{"totop100_partnumber_$i"};
731 $description = $form->{"totop100_description_$i"};
732 $unit = $form->{"totop100_unit_$i"};
733 $sellprice = $form->{"totop100_sellprice_$i"};
734 $soldtotal = $form->{"totop100_soldtotal_$i"};
737 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
738 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
739 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
740 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
741 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
745 push @{ $form->{parts} },
747 partnumber => "$partnumber",
748 description => "$description",
750 sellprice => "$sellprice",
751 soldtotal => "$soldtotal" };
754 # build data for columns
756 foreach my $ref (@{ $form->{parts} }) {
758 if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
759 if ($sameitem ne $ref->{ $form->{sort} }) {
761 $sameitem = $ref->{ $form->{sort} };
765 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
766 $ref->{sellprice} *= $ref->{exchangerate};
767 $ref->{listprice} *= $ref->{exchangerate};
768 $ref->{lastcost} *= $ref->{exchangerate};
770 # use this for assemblies
771 $onhand = $ref->{onhand};
774 if ($ref->{assemblyitem}) {
776 $onhand = 0 if ($form->{sold});
779 $ref->{description} =~ s/\n/<br>/g;
781 $column_data{number} =
783 . $form->format_amount(\%myconfig, $ref->{number})
785 $column_data{partnumber} =
786 "<td align=$align>$ref->{partnumber} </a></td>";
787 $column_data{description} = "<td>$ref->{description} </td>";
788 $column_data{partsgroup} = "<td>$ref->{partsgroup} </td>";
790 $column_data{onhand} =
792 . $form->format_amount(\%myconfig, $ref->{onhand})
794 $column_data{sellprice} =
796 . $form->format_amount(\%myconfig, $ref->{sellprice})
798 $column_data{listprice} =
800 . $form->format_amount(\%myconfig, $ref->{listprice})
802 $column_data{lastcost} =
804 . $form->format_amount(\%myconfig, $ref->{lastcost})
807 $column_data{linetotalsellprice} = "<td align=right>"
808 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2)
810 $column_data{linetotallastcost} = "<td align=right>"
811 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2)
813 $column_data{linetotallistprice} = "<td align=right>"
814 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2)
817 if (!$ref->{assemblyitem}) {
818 $totalsellprice += $onhand * $ref->{sellprice};
819 $totallastcost += $onhand * $ref->{lastcost};
820 $totallistprice += $onhand * $ref->{listprice};
822 $subtotalonhand += $onhand;
823 $subtotalsellprice += $onhand * $ref->{sellprice};
824 $subtotallastcost += $onhand * $ref->{lastcost};
825 $subtotallistprice += $onhand * $ref->{listprice};
830 . $form->format_amount(\%myconfig, $ref->{rop}) . "</td>";
831 $column_data{weight} =
833 . $form->format_amount(\%myconfig, $ref->{weight})
835 $column_data{unit} = "<td>$ref->{unit} </td>";
836 $column_data{bin} = "<td>$ref->{bin} </td>";
837 $column_data{priceupdate} = "<td>$ref->{priceupdate} </td>";
839 $column_data{invnumber} =
840 ($ref->{module} ne 'oe')
841 ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&callback=$callback>$ref->{invnumber}</a></td>"
842 : "<td>$ref->{invnumber}</td>";
843 $column_data{ordnumber} =
844 ($ref->{module} eq 'oe')
845 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&callback=$callback>$ref->{ordnumber}</a></td>"
846 : "<td>$ref->{ordnumber}</td>";
847 $column_data{quonumber} =
848 ($ref->{module} eq 'oe' && !$ref->{ordnumber})
849 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&callback=$callback>$ref->{quonumber}</a></td>"
850 : "<td>$ref->{quonumber}</td>";
852 $column_data{name} = "<td>$ref->{name}</td>";
854 $column_data{image} =
856 ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>"
858 $column_data{drawing} =
860 ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>"
862 $column_data{microfiche} =
864 ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>"
867 $column_data{serialnumber} = "<td>$ref->{serialnumber}</td>";
869 $column_data{soldtotal} = "<td align=right>$ref->{soldtotal}</td>";
873 print "<tr class=listrow$i>";
875 map { print "\n$column_data{$_}" } @column_index;
882 if ($form->{l_subtotal} eq 'Y') {
886 if ($form->{"l_linetotal"}) {
887 map { $column_data{$_} = "<td> </td>" } @column_index;
888 $column_data{linetotalsellprice} =
889 "<th class=listtotal align=right>"
890 . $form->format_amount(\%myconfig, $totalsellprice, 2)
892 $column_data{linetotallastcost} =
893 "<th class=listtotal align=right>"
894 . $form->format_amount(\%myconfig, $totallastcost, 2)
896 $column_data{linetotallistprice} =
897 "<th class=listtotal align=right>"
898 . $form->format_amount(\%myconfig, $totallistprice, 2)
901 print "<tr class=listtotal>";
903 map { print "\n$column_data{$_}" } @column_index;
910 <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
919 <form method=post action=$form->{script}>
921 <input type=hidden name=itemstatus value="$form->{itemstatus}">
922 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
923 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
924 <input type=hidden name=l_description value="$form->{l_description}">
925 <input type=hidden name=l_onhand value="$form->{l_onhand}">
926 <input type=hidden name=l_unit value="$form->{l_unit}">
927 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
928 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
929 <input type=hidden name=sort value="$form->{sort}">
930 <input type=hidden name=revers value="$form->{revers}">
931 <input type=hidden name=lastsort value="$form->{lastsort}">
932 <input type=hidden name=parts value="$form->{parts}">
934 <input type=hidden name=bom value="$form->{bom}">
935 <input type=hidden name=titel value="$form->{titel}">
936 <input type=hidden name=searchitems value="$form->{searchitems}">|;
941 <input type=hidden name=ndxs_counter value="$form->{ndxs_counter}">
943 <input class=submit type=submit name=action value="|
944 . $locale->text('choice') . qq|">
952 $lxdebug->leave_sub();
957 # Warning, deep magic ahead.
958 # This function parses the requested details, sanity checks them, and converts them into a format thats usable for IC->all_parts
960 # flags coming from the form:
962 # searchitems=part revers=0 lastsort=''
965 # partnumber ean description partsgroup serialnumber make model drawing microfiche
966 # transdatefrom transdateto
969 # itemstatus = active | onhand | short | obsolete | orphaned
970 # action = continue | top100
973 # bought sold onorder ordered rfq quoted
974 # l_partnumber l_description l_serialnumber l_unit l_listprice l_sellprice l_lastcost
975 # l_linetotal l_priceupdate l_bin l_rop l_weight l_image l_drawing l_microfiche
976 # l_partsgroup l_subtotal l_soldtotal l_deliverydate
979 # nextsub revers lastsort sort ndxs_counter
981 sub generate_report {
982 $lxdebug->enter_sub();
984 $auth->assert('part_service_assembly_edit');
986 my ($revers, $lastsort, $description);
988 $form->{title} = (ucfirst $form->{searchitems}) . "s";
989 $form->{title} = $locale->text($form->{title});
991 my $revers = $form->{revers};
992 my $lastsort = $form->{lastsort};
994 # sorting and direction of sorting
995 # ToDO: change this to the simpler field+direction method
996 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
998 $form->{lastsort} = "partnumber";
999 $form->{sort} = "partnumber";
1001 if ($form->{lastsort} eq $form->{sort}) {
1002 $form->{revers} = 1 - $form->{revers};
1004 $form->{revers} = 0;
1005 $form->{lastsort} = $form->{sort};
1009 # special case if we have a serialnumber limit search
1010 # serialnumbers are only given in invoices and orders,
1011 # so they can only pop up in bought, sold, rfq, and quoted stuff
1012 $form->{no_sn_joins} = 'Y' if ( !$form->{bought} && !$form->{sold}
1013 && !$form->{rfq} && !$form->{quoted}
1014 && ($form->{l_serialnumber} || $form->{serialnumber}));
1016 # special case for any checkbox of bought | sold | onorder | ordered | rfq | quoted.
1017 # if any of these are ticked the behavior changes slightly for lastcost
1018 # since all those are aggregation checks for the legder tables this is an internal switch
1019 # refered to as ledgerchecks
1020 $form->{ledgerchecks} = 'Y' if ( $form->{bought} || $form->{sold} || $form->{onorder}
1021 || $form->{ordered} || $form->{rfq} || $form->{quoted});
1023 # if something should be activated if something else is active, enter it here
1024 my %dependencies = (
1025 onhand => [ qw(l_onhand) ],
1026 short => [ qw(l_onhand) ],
1027 onorder => [ qw(l_ordnumber) ],
1028 ordered => [ qw(l_ordnumber) ],
1029 rfq => [ qw(l_quonumber) ],
1030 quoted => [ qw(l_quonumber) ],
1031 bought => [ qw(l_invnumber) ],
1032 sold => [ qw(l_invnumber) ],
1033 ledgerchecks => [ qw(l_name) ],
1034 serialnumber => [ qw(l_serialnumber) ],
1035 no_sn_joins => [ qw(bought sold) ],
1038 # these strings get displayed at the top of the results to indicate the user which switches were used
1040 active => $locale->text('Active'),
1041 obsolete => $locale->text('Obsolete'),
1042 orphaned => $locale->text('Orphaned'),
1043 onhand => $locale->text('On Hand'),
1044 short => $locale->text('Short'),
1045 onorder => $locale->text('On Order'),
1046 ordered => $locale->text('Ordered'),
1047 rfq => $locale->text('RFQ'),
1048 quoted => $locale->text('Quoted'),
1049 bought => $locale->text('Bought'),
1050 sold => $locale->text('Sold'),
1051 transdatefrom => $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1),
1052 transdateto => $locale->text('To (time)') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1),
1053 partnumber => $locale->text('Part Number') . ": '$form->{partnumber}'",
1054 partsgroup => $locale->text('Group') . ": '$form->{partsgroup}'",
1055 serialnumber => $locale->text('Serial Number') . ": '$form->{serialnumber}'",
1056 description => $locale->text('Part Description') . ": '$form->{description}'",
1057 make => $locale->text('Make') . ": '$form->{make}'",
1058 model => $locale->text('Model') . ": '$form->{model}'",
1059 drawing => $locale->text('Drawing') . ": '$form->{drawing}'",
1060 microfiche => $locale->text('Microfiche') . ": '$form->{microfiche}'",
1061 l_soldtotal => $locale->text('soldtotal'),
1064 my @itemstatus_keys = qw(active obsolete orphaned onhand short);
1065 my @callback_keys = qw(onorder ordered rfq quoted bought sold partnumber partsgroup serialnumber description make model
1066 drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto ean);
1068 # calculate dependencies
1069 for (@itemstatus_keys, @callback_keys) {
1070 next if ($form->{itemstatus} ne $_ && !$form->{$_});
1071 map { $form->{$_} = 'Y' } @{ $dependencies{$_} } if $dependencies{$_};
1074 # generate callback and optionstrings
1076 for my $key (@itemstatus_keys, @callback_keys) {
1077 next if ($form->{itemstatus} ne $key && !$form->{$key});
1078 push @options, $optiontexts{$key};
1081 # special case for lastcost
1082 $form->{l_lastcost} = "" if $form->{ledgerchecks};
1084 if ($form->{description}) {
1085 $description = $form->{description};
1086 $description =~ s/\n/<br>/g;
1089 if ($form->{l_linetotal}) {
1090 $form->{l_onhand} = "Y";
1091 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
1092 if ($form->{l_lastcost}) {
1093 $form->{l_linetotallastcost} = "Y";
1094 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
1095 $form->{l_linetotallastcost} = "";
1098 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
1101 if ($form->{searchitems} eq 'service') {
1103 # remove bin, weight and rop from list
1104 map { $form->{"l_$_"} = "" } qw(bin weight rop);
1106 $form->{l_onhand} = "";
1108 # qty is irrelevant unless bought or sold
1109 if ( $form->{bought}
1114 || $form->{quoted}) {
1115 $form->{l_onhand} = "Y";
1117 $form->{l_linetotalsellprice} = "";
1118 $form->{l_linetotallastcost} = "";
1122 $form->{l_lastcost} = "" if ($form->{searchitems} eq 'assembly' && !$form->{bom});
1124 IC->all_parts(\%myconfig, \%$form);
1127 qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost
1128 priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal deliverydate);
1131 'bin' => { 'text' => $locale->text('Bin'), },
1132 'deliverydate' => { 'text' => $locale->text('deliverydate'), },
1133 'description' => { 'text' => $locale->text('Part Description'), },
1134 'drawing' => { 'text' => $locale->text('Drawing'), },
1135 'image' => { 'text' => $locale->text('Image'), },
1136 'invnumber' => { 'text' => $locale->text('Invoice Number'), },
1137 'lastcost' => { 'text' => $locale->text('Last Cost'), },
1138 'linetotallastcost' => { 'text' => $locale->text('Extended'), },
1139 'linetotallistprice' => { 'text' => $locale->text('Extended'), },
1140 'linetotalsellprice' => { 'text' => $locale->text('Extended'), },
1141 'listprice' => { 'text' => $locale->text('List Price'), },
1142 'microfiche' => { 'text' => $locale->text('Microfiche'), },
1143 'name' => { 'text' => $locale->text('Name'), },
1144 'onhand' => { 'text' => $locale->text('Qty'), },
1145 'ordnumber' => { 'text' => $locale->text('Order Number'), },
1146 'partnumber' => { 'text' => $locale->text('Part Number'), },
1147 'partsgroup' => { 'text' => $locale->text('Group'), },
1148 'priceupdate' => { 'text' => $locale->text('Updated'), },
1149 'quonumber' => { 'text' => $locale->text('Quotation'), },
1150 'rop' => { 'text' => $locale->text('ROP'), },
1151 'sellprice' => { 'text' => $locale->text('Sell Price'), },
1152 'serialnumber' => { 'text' => $locale->text('Serial Number'), },
1153 'soldtotal' => { 'text' => $locale->text('soldtotal'), },
1154 'unit' => { 'text' => $locale->text('Unit'), },
1155 'weight' => { 'text' => $locale->text('Weight'), },
1158 map { $column_defs{$_}->{visible} = $form->{"l_$_"} ? 1 : 0 } @columns;
1159 map { $column_defs{$_}->{align} = 'right' } qw(onhand sellprice listprice lastcost linetotalsellprice linetotallastcost linetotallistprice rop weight soldtotal);
1161 my @hidden_variables = (qw(l_subtotal l_linetotal searchitems itemstatus bom), @itemstatus_keys, @callback_keys, map { "l_$_" } @columns);
1162 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
1164 my @sort_full = qw(partnumber description onhand soldtotal deliverydate);
1165 my @sort_no_revers = qw(partsgroup bin priceupdate invnumber ordnumber quonumber name image drawing serialnumber);
1167 foreach my $col (@sort_full) {
1168 $column_defs{$col}->{link} = join '&', $callback, "sort=$col", map { "$_=" . E($form->{$_}) } qw(revers lastsort);
1170 map { $column_defs{$_}->{link} = "${callback}&sort=$_" } @sort_no_revers;
1172 # add order to callback
1173 $form->{callback} = join '&', ($callback, map { "${_}=" . E($form->{$_}) } qw(sort revers));
1175 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1177 my %attachment_basenames = (
1178 'part' => $locale->text('part_list'),
1179 'service' => $locale->text('service_list'),
1180 'assembly' => $locale->text('assembly_list'),
1183 $report->set_options('top_info_text' => $locale->text('Options') . ': ' . join(', ', grep $_, @options),
1184 'raw_bottom_info_text' => $form->parse_html_template('ic/generate_report_bottom'),
1185 'output_format' => 'HTML',
1186 'title' => $form->{title},
1187 'attachment_basename' => $attachment_basenames{$form->{searchitems}} . strftime('_%Y%m%d', localtime time),
1189 $report->set_options_from_form();
1191 $report->set_columns(%column_defs);
1192 $report->set_column_order(@columns);
1194 $report->set_export_options('generate_report', @hidden_variables, qw(sort revers));
1196 $report->set_sort_indicator($form->{sort}, $form->{revers} ? 0 : 1);
1198 my @subtotal_columns = qw(sellprice listprice lastcost);
1199 my %subtotals = map { $_ => 0 } ('onhand', @subtotal_columns);
1200 my %totals = map { $_ => 0 } @subtotal_columns;
1202 my $same_item = $form->{parts}[0]{ $form->{sort} } if (scalar @{ $form->{parts} });
1205 foreach my $ref (@{ $form->{parts} }) {
1207 # fresh row, for inserting later
1208 my $row = { map { $_ => { 'data' => $ref->{$_} } } @columns };
1210 $ref->{exchangerate} ||= 1;
1211 $ref->{price_factor} ||= 1;
1212 $ref->{sellprice} *= $ref->{exchangerate} / $ref->{price_factor};
1213 $ref->{listprice} *= $ref->{exchangerate} / $ref->{price_factor};
1214 $ref->{lastcost} *= $ref->{exchangerate} / $ref->{price_factor};
1216 # use this for assemblies
1217 my $onhand = $ref->{onhand};
1219 if ($ref->{assemblyitem}) {
1220 $row->{partnumber}{align} = 'right';
1221 $row->{onhand}{data} = 0;
1222 $onhand = 0 if ($form->{sold});
1225 my $edit_link = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback');
1226 $row->{partnumber}->{link} = $edit_link;
1227 $row->{description}->{link} = $edit_link;
1229 foreach (qw(sellprice listprice lastcost)) {
1230 $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}, -2);
1231 $row->{"linetotal$_"}{data} = $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2);
1234 map { $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}); } qw(onhand rop weight soldtotal);
1236 if (!$ref->{assemblyitem}) {
1237 foreach my $col (@subtotal_columns) {
1238 $totals{$col} += $onhand * $ref->{$col};
1239 $subtotals{$col} += $onhand * $ref->{$col};
1242 $subtotals{onhand} += $onhand;
1246 if ($ref->{module} eq 'oe') {
1247 my $edit_oe_link = build_std_url("script=oe.pl", 'action=edit', 'type=' . E($ref->{type}), 'id=' . E($ref->{trans_id}), 'callback');
1248 $row->{ordnumber}{link} = $edit_oe_link;
1249 $row->{quonumber}{link} = $edit_oe_link if (!$ref->{ordnumber});
1252 $row->{invnumber}{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'type=invoice', 'id=' . E($ref->{trans_id}), 'callback');
1255 # set properties of images
1256 if ($ref->{image} && (lc $report->{options}->{output_format} eq 'html')) {
1257 $row->{image}{data} = '';
1258 $row->{image}{raw_data} = '<a href="' . H($ref->{image}) . '"><img src="' . H($ref->{image}) . '" height="32" border="0"></a>';
1260 map { $row->{$_}{link} = $ref->{$_} } qw(drawing microfiche);
1262 $report->add_data($row);
1264 my $next_ref = $form->{parts}[$idx + 1];
1266 # insert subtotal rows
1267 if (($form->{l_subtotal} eq 'Y') &&
1269 (!$next_ref->{assemblyitem} && ($same_item ne $next_ref->{ $form->{sort} })))) {
1270 my $row = { map { $_ => { 'class' => 'listsubtotal', } } @columns };
1272 if (($form->{searchitems} ne 'assembly') || !$form->{bom}) {
1273 $row->{onhand}->{data} = $form->format_amount(\%myconfig, $subtotals{onhand});
1276 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $subtotals{$_}, 2) } @subtotal_columns;
1277 map { $subtotals{$_} = 0 } ('onhand', @subtotal_columns);
1279 $report->add_data($row);
1281 $same_item = $next_ref->{ $form->{sort} };
1287 if ($form->{"l_linetotal"}) {
1288 my $row = { map { $_ => { 'class' => 'listtotal', } } @columns };
1290 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } @subtotal_columns;
1292 $report->add_separator();
1293 $report->add_data($row);
1296 $report->generate_with_headers();
1298 $lxdebug->leave_sub();
1299 } #end generate_report
1301 sub parts_subtotal {
1302 $lxdebug->enter_sub();
1304 $auth->assert('part_service_assembly_edit');
1307 our (%column_data, @column_index);
1308 our ($subtotalonhand, $totalsellprice, $totallastcost, $totallistprice, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
1310 map { $column_data{$_} = "<td> </td>" } @column_index;
1311 $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});
1313 $column_data{onhand} =
1314 "<th class=listsubtotal align=right>"
1315 . $form->format_amount(\%myconfig, $subtotalonhand)
1318 $column_data{linetotalsellprice} =
1319 "<th class=listsubtotal align=right>"
1320 . $form->format_amount(\%myconfig, $subtotalsellprice, 2)
1322 $column_data{linetotallistprice} =
1323 "<th class=listsubtotal align=right>"
1324 . $form->format_amount(\%myconfig, $subtotallistprice, 2)
1326 $column_data{linetotallastcost} =
1327 "<th class=listsubtotal align=right>"
1328 . $form->format_amount(\%myconfig, $subtotallastcost, 2)
1331 $subtotalonhand = 0;
1332 $subtotalsellprice = 0;
1333 $subtotallistprice = 0;
1334 $subtotallastcost = 0;
1336 print "<tr class=listsubtotal>";
1338 map { print "\n$column_data{$_}" } @column_index;
1344 $lxdebug->leave_sub();
1348 $lxdebug->enter_sub();
1350 $auth->assert('part_service_assembly_edit');
1352 # show history button
1353 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
1354 #/show hhistory button
1355 IC->get_part(\%myconfig, \%$form);
1357 $form->{"original_partnumber"} = $form->{"partnumber"};
1359 $form->{title} = $locale->text('Edit ' . ucfirst $form->{item});
1364 $lxdebug->leave_sub();
1368 $lxdebug->enter_sub();
1370 $auth->assert('part_service_assembly_edit');
1372 IC->create_links("IC", \%myconfig, \%$form);
1375 map({ $form->{selectcurrency} .= "<option>$_\n" }
1376 split(/:/, $form->{currencies}));
1378 # parts and assemblies have the same links
1379 my $item = $form->{item};
1380 if ($form->{item} eq 'assembly') {
1384 # build the popup menus
1385 $form->{taxaccounts} = "";
1386 foreach my $key (keys %{ $form->{IC_links} }) {
1387 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1389 # if this is a tax field
1390 if ($key =~ /IC_tax/) {
1391 if ($key =~ /\Q$item\E/) {
1392 $form->{taxaccounts} .= "$ref->{accno} ";
1393 $form->{"IC_tax_$ref->{accno}_description"} =
1394 "$ref->{accno}--$ref->{description}";
1397 if ($form->{amount}{ $ref->{accno} }) {
1398 $form->{"IC_tax_$ref->{accno}"} = "checked";
1401 $form->{"IC_tax_$ref->{accno}"} = "checked";
1406 $form->{"select$key"} .=
1407 "<option $ref->{selected}>$ref->{accno}--$ref->{description}\n";
1408 if ($form->{amount}{$key} eq $ref->{accno}) {
1409 $form->{$key} = "$ref->{accno}--$ref->{description}";
1415 chop $form->{taxaccounts};
1417 if (($form->{item} eq "part") || ($form->{item} eq "assembly")) {
1418 $form->{selectIC_income} = $form->{selectIC_sale};
1419 $form->{selectIC_expense} = $form->{selectIC_cogs};
1420 $form->{IC_income} = $form->{IC_sale};
1421 $form->{IC_expense} = $form->{IC_cogs};
1424 delete $form->{IC_links};
1425 delete $form->{amount};
1427 $form->get_partsgroup(\%myconfig, { all => 1 });
1429 $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
1431 if (@{ $form->{all_partsgroup} }) {
1432 $form->{selectpartsgroup} = qq|<option>\n|;
1433 map { $form->{selectpartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} };
1436 if ($form->{item} eq 'assembly') {
1438 foreach my $i (1 .. $form->{assembly_rows}) {
1439 if ($form->{"partsgroup_id_$i"}) {
1440 $form->{"partsgroup_$i"} =
1441 qq|$form->{"partsgroup_$i"}--$form->{"partsgroup_id_$i"}|;
1444 $form->get_partsgroup(\%myconfig);
1446 if (@{ $form->{all_partsgroup} }) {
1447 $form->{selectassemblypartsgroup} = qq|<option>\n|;
1450 $form->{selectassemblypartsgroup} .=
1451 qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
1452 } @{ $form->{all_partsgroup} };
1455 $lxdebug->leave_sub();
1459 $lxdebug->enter_sub();
1461 $auth->assert('part_service_assembly_edit');
1463 $form->{eur} = $eur; # config dumps into namespace - yuck
1464 $form->{pg_keys} = sub { "$_[0]->{partsgroup}--$_[0]->{id}" };
1465 $form->{description_area} = ($form->{rows} = $form->numtextrows($form->{description}, 40)) > 1;
1467 map { $form->{"is_$_"} = ($form->{item} eq $_) } qw(part service assembly);
1468 map { $form->{$_} =~ s/"/"/g; } qw(unit);
1470 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
1472 $rows = 4 if $rows = $form->numtextrows($form->{notes}, 40) < 2;
1473 $form->{notes_rows} = $rows;
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"}); }