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 $form->{title} = $locale->text('Add ' . ucfirst $form->{item});
71 "$form->{script}?action=add&item=$form->{item}&login=$form->{login}&password=$form->{password}"
72 unless $form->{callback};
74 $form->{"unit_changeable"} = 1;
76 IC->get_pricegroups(\%myconfig, \%$form);
80 $lxdebug->leave_sub();
84 $lxdebug->enter_sub();
86 # switch for backward sorting
89 # memory for which table was sort at last time
90 $form->{lastsort} = "";
92 # counter for added entries to top100
93 $form->{ndxs_counter} = 0;
95 # $locale->text('Parts')
96 # $locale->text('Services')
98 my $is_service = $form->{searchitems} eq 'service';
99 my $is_assembly = $form->{searchitems} eq 'assembly';
101 $form->{title} = (ucfirst $form->{searchitems}) . "s";
102 $form->{title} = $locale->text($form->{title});
103 $form->{title} = $locale->text('Assemblies') if $is_assembly;
105 $form->{jsscript} = 1;
109 print $form->parse_html_template('ic/search', { is_assembly => $is_assembly,
110 is_service => $is_service,
111 dateformat => $myconfig{dateformat}, });
113 $lxdebug->leave_sub();
116 sub search_update_prices {
117 $lxdebug->enter_sub();
119 my $pricegroups = IC->get_pricegroups(\%myconfig, \%$form);
123 print $form->parse_html_template('ic/search_update_prices', { PRICE_ROWS => $pricegroups });
125 $lxdebug->leave_sub();
128 sub confirm_price_update {
129 $lxdebug->enter_sub();
131 $form->{nextsub} = "update_prices";
134 map { delete $form->{$_} } qw(action header);
136 print $form->parse_html_template('ic/confirm_price_update', { HIDDENS => [ map { name => $_, value => $form->{$_} }, keys %$form ] });
138 $lxdebug->leave_sub();
142 $lxdebug->enter_sub();
144 if (IC->update_prices(\%myconfig, \%$form)) {
145 $form->redirect($form->{update_count} . $locale->text('prices updated!'));
147 $form->error($locale->text('Could not update prices!'));
150 $lxdebug->leave_sub();
154 $lxdebug->enter_sub();
159 $form->{title} = $locale->text('Top 100 hinzufuegen');
163 push @custom_hiddens, qw(login password searchitems title bom titel revers lastsort sort ndxs_counter extras);
164 push @custom_hiddens, qw(itemstatus l_linetotal l_partnumber l_description l_onhand l_unit l_sellprice l_linetotalsellprice);
166 +{ name => 'row', value => $j },
167 +{ name => 'nextsub', value => 'item_selected' },
168 +{ name => 'test', value => 'item_selected' },
169 +{ name => 'lastndx', value => $lastndx },
170 map(+{ name => $_, value => $form->{$_} }, @custom_hiddens),
173 my ($partnumber, $description, $unit, $sellprice, $soldtotal);
175 # if ($form->{ndx}) {
176 # for my $i (0 .. $form->{ndxs_counter}) {
178 # # insert data into top100
179 # push @{ $form->{parts} },
181 # partnumber => $form->{"totop100_partnumber_$j"},
182 # description => $form->{"totop100_description_$j"},
183 # unit => $form->{"totop100_unit_$j"},
184 # sellprice => $form->{"totop100_sellprice_$j"},
185 # soldtotal => $form->{"totop100_soldtotal_$j"},
192 # set data for next page
193 for my $i (1 .. $form->{ndxs_counter}) {
194 $partnumber = $form->{"totop100_partnumber_$i"};
195 $description = $form->{"totop100_description_$i"};
196 $unit = $form->{"totop100_unit_$i"};
197 $sellprice = $form->{"totop100_sellprice_$i"};
198 $soldtotal = $form->{"totop100_soldtotal_$i"};
201 totop100_partnumber => $form->{"totop100_partnumber_$i"},
202 totop100_description => $form->{"totop100_description_$i"},
203 totop100_unit => $form->{"totop100_unit_$i"},
204 totop100_sellprice => $form->{"totop100_sellprice_$i"},
205 totop100_soldtotal => $form->{"totop100_soldtotal_$i"},
209 #<input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
210 #<input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
211 #<input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
212 #<input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
213 #<input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
217 print $form->parse_html_template('ic/choice', +{ HIDDENS => \@HIDDENS, PARTS => \@PARTS });
219 $lxdebug->leave_sub();
223 $lxdebug->enter_sub();
226 our ($partnumber, $description, $unit, $sellprice, $soldtotal);
228 my @sortorders = ("", "partnumber", "description", "all");
229 my $sortorder = $sortorders[($form->{description} ? 2 : 0) + ($form->{partnumber} ? 1 : 0)];
230 IC->get_parts(\%myconfig, \%$form, $sortorder);
232 $form->{title} = $locale->text('Top 100 hinzufuegen');
238 <form method=post action=ic.pl>
241 <th class=listtop colspan=6>| . $locale->text('choice part') . qq|</th>
244 <tr class=listheading>
246 <th class=listheading>| . $locale->text('Part Number') . qq|</th>
247 <th class=listheading>| . $locale->text('Part Description') . qq|</th>
248 <th class=listheading>| . $locale->text('Unit of measure') . qq|</th>
249 <th class=listheading>| . $locale->text('Sell Price') . qq|</th>
250 <th class=listheading>| . $locale->text('soldtotal') . qq|</th>
254 my $i = $form->{rows};
256 for ($j = 1; $j <= $i; $j++) {
259 <tr class=listrow1>|;
262 <td><input name=ndx class=radio type=radio value=$j checked></td>|;
265 <td><input name=ndx class=radio type=radio value=$j></td>|;
268 <td><input name="new_partnumber_$j" type=hidden value="$form->{"partnumber_$j"}">$form->{"partnumber_$j"}</td>
269 <td><input name="new_description_$j" type=hidden value="$form->{"description_$j"}">$form->{"description_$j"}</td>
270 <td><input name="new_unit_$j" type=hidden value="$form->{"unit_$j"}">$form->{"unit_$j"}</td>
271 <td><input name="new_sellprice_$j" type=hidden value="$form->{"sellprice_$j"}">$form->{"sellprice_$j"}</td>
272 <td><input name="new_soldtotal_$j" type=hidden value="$form->{"soldtotal_$j"}">$form->{"soldtotal_$j"}</td>
275 <input name="new_id_$j" type=hidden value="$form->{"id_$j"}">|;
285 <input type=hidden name=login value=$form->{login}>
286 <input type=hidden name=password value=$form->{password}>
288 <input type=hidden name=itemstatus value="$form->{itemstatus}">
289 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
290 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
291 <input type=hidden name=l_description value="$form->{l_description}">
292 <input type=hidden name=l_onhand value="$form->{l_onhand}">
293 <input type=hidden name=l_unit value="$form->{l_unit}">
294 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
295 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
296 <input type=hidden name=sort value="$form->{sort}">
297 <input type=hidden name=revers value="$form->{revers}">
298 <input type=hidden name=lastsort value="$form->{lastsort}">
300 <input type=hidden name=bom value="$form->{bom}">
301 <input type=hidden name=titel value="$form->{titel}">
302 <input type=hidden name=searchitems value="$form->{searchitems}">
304 <input type=hidden name=row value=$j>
306 <input type=hidden name=nextsub value=item_selected>
308 <input name=lastndx type=hidden value=$lastndx>
310 <input name=ndxs_counter type=hidden value=$form->{ndxs_counter}>|;
314 if (($form->{ndxs_counter}) > 0) {
315 for ($i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
317 $partnumber = $form->{"totop100_partnumber_$i"};
318 $description = $form->{"totop100_description_$i"};
319 $unit = $form->{"totop100_unit_$i"};
320 $sellprice = $form->{"totop100_sellprice_$i"};
321 $soldtotal = $form->{"totop100_soldtotal_$i"};
324 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
325 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
326 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
327 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
328 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
336 <input class=submit type=submit name=action value="|
337 . $locale->text('TOP100') . qq|">
343 $lxdebug->leave_sub();
347 $lxdebug->enter_sub();
350 $form->{ndxs_counter}++;
352 if ($form->{ndxs_counter} > 0) {
354 my $index = $form->{ndx};
356 $form->{"totop100_partnumber_$form->{ndxs_counter}"} = $form->{"new_partnumber_$index"};
357 $form->{"totop100_description_$form->{ndxs_counter}"} = $form->{"new_description_$index"};
358 $form->{"totop100_unit_$form->{ndxs_counter}"} = $form->{"new_unit_$index"};
359 $form->{"totop100_sellprice_$form->{ndxs_counter}"} = $form->{"new_sellprice_$index"};
360 $form->{"totop100_soldtotal_$form->{ndxs_counter}"} = $form->{"new_soldtotal_$index"};
364 $lxdebug->leave_sub();
368 $lxdebug->enter_sub();
370 my ($revers, $lastsort, $callback, $option, $description, $sameitem,
371 $partnumber, $unit, $sellprice, $soldtotal, $totop100, $onhand, $align);
372 my (@column_index, %column_header, %column_data);
373 my ($totalsellprice, $totallastcost, $totallistprice, $subtotalonhand, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
375 $form->{top100} = "top100";
376 $form->{l_soldtotal} = "Y";
377 # $form->{soldtotal} = "soldtotal";
378 $form->{sort} = "soldtotal";
379 $form->{l_qty} = "N";
380 $form->{l_linetotal} = "";
382 $form->{number} = "position";
383 $form->{l_number} = "Y";
387 $form->{title} = $locale->text('Top 100');
389 $revers = $form->{revers};
390 $lastsort = $form->{lastsort};
392 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
394 $form->{lastsort} = "partnumber";
395 $form->{sort} = "partnumber";
399 "$form->{script}?action=top100&login=$form->{login}&password=$form->{password}&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&title="
400 . $form->escape($form->{title}, 1);
402 # if we have a serialnumber limit search
403 if ($form->{serialnumber} || $form->{l_serialnumber}) {
404 $form->{l_serialnumber} = "Y";
405 unless ( $form->{bought}
408 || $form->{quoted}) {
409 $form->{bought} = $form->{sold} = 1;
412 IC->all_parts(\%myconfig, \%$form);
414 if ($form->{itemstatus} eq 'active') {
415 $option .= $locale->text('Active') . " : ";
417 if ($form->{itemstatus} eq 'obsolete') {
418 $option .= $locale->text('Obsolete') . " : ";
420 if ($form->{itemstatus} eq 'orphaned') {
421 $option .= $locale->text('Orphaned') . " : ";
423 if ($form->{itemstatus} eq 'onhand') {
424 $option .= $locale->text('On Hand') . " : ";
425 $form->{l_onhand} = "Y";
427 if ($form->{itemstatus} eq 'short') {
428 $option .= $locale->text('Short') . " : ";
429 $form->{l_onhand} = "Y";
431 if ($form->{onorder}) {
432 $form->{l_ordnumber} = "Y";
433 $callback .= "&onorder=$form->{onorder}";
434 $option .= $locale->text('On Order') . " : ";
436 if ($form->{ordered}) {
437 $form->{l_ordnumber} = "Y";
438 $callback .= "&ordered=$form->{ordered}";
439 $option .= $locale->text('Ordered') . " : ";
442 $form->{l_quonumber} = "Y";
443 $callback .= "&rfq=$form->{rfq}";
444 $option .= $locale->text('RFQ') . " : ";
446 if ($form->{quoted}) {
447 $form->{l_quonumber} = "Y";
448 $callback .= ""ed=$form->{quoted}";
449 $option .= $locale->text('Quoted') . " : ";
451 if ($form->{bought}) {
452 $form->{l_invnumber} = "Y";
453 $callback .= "&bought=$form->{bought}";
454 $option .= $locale->text('Bought') . " : ";
457 $form->{l_invnumber} = "Y";
458 $callback .= "&sold=$form->{sold}";
459 $option .= $locale->text('Sold') . " : ";
466 || $form->{quoted}) {
468 $form->{l_lastcost} = "";
469 $form->{l_name} = "Y";
470 if ($form->{transdatefrom}) {
471 $callback .= "&transdatefrom=$form->{transdatefrom}";
473 . $locale->text('From')
475 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
477 if ($form->{transdateto}) {
478 $callback .= "&transdateto=$form->{transdateto}";
480 . $locale->text('To')
482 . $locale->date(\%myconfig, $form->{transdateto}, 1);
488 if ($form->{partnumber}) {
489 $callback .= "&partnumber=$form->{partnumber}";
490 $option .= $locale->text('Part Number') . qq| : $form->{partnumber}<br>|;
493 $callback .= "&partnumber=$form->{ean}";
494 $option .= $locale->text('EAN') . qq| : $form->{ean}<br>|;
496 if ($form->{partsgroup}) {
497 $callback .= "&partsgroup=$form->{partsgroup}";
498 $option .= $locale->text('Group') . qq| : $form->{partsgroup}<br>|;
500 if ($form->{serialnumber}) {
501 $callback .= "&serialnumber=$form->{serialnumber}";
502 $option .= $locale->text('Serial Number') . qq| : $form->{serialnumber}<br>|;
504 if ($form->{description}) {
505 $callback .= "&description=$form->{description}";
506 $description = $form->{description};
507 $description =~ s/\n/<br>/g;
508 $option .= $locale->text('Part Description') . qq| : $form->{description}<br>|;
511 $callback .= "&make=$form->{make}";
512 $option .= $locale->text('Make') . qq| : $form->{make}<br>|;
514 if ($form->{model}) {
515 $callback .= "&model=$form->{model}";
516 $option .= $locale->text('Model') . qq| : $form->{model}<br>|;
518 if ($form->{drawing}) {
519 $callback .= "&drawing=$form->{drawing}";
520 $option .= $locale->text('Drawing') . qq| : $form->{drawing}<br>|;
522 if ($form->{microfiche}) {
523 $callback .= "µfiche=$form->{microfiche}";
524 $option .= $locale->text('Microfiche') . qq| : $form->{microfiche}<br>|;
526 if ($form->{l_soldtotal}) {
527 $callback .= "&soldtotal=$form->{soldtotal}";
528 $option .= $locale->text('soldtotal') . qq| : $form->{soldtotal}<br>|;
531 my @columns = $form->sort_columns(
532 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)
535 if ($form->{l_linetotal}) {
536 $form->{l_onhand} = "Y";
537 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
538 if ($form->{l_lastcost}) {
539 $form->{l_linetotallastcost} = "Y";
540 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
541 $form->{l_linetotallastcost} = "";
544 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
547 if ($form->{searchitems} eq 'service') {
549 # remove bin, weight and rop from list
550 map { $form->{"l_$_"} = "" } qw(bin weight rop);
552 $form->{l_onhand} = "";
554 # qty is irrelevant unless bought or sold
560 || $form->{quoted}) {
561 $form->{l_onhand} = "Y";
563 $form->{l_linetotalsellprice} = "";
564 $form->{l_linetotallastcost} = "";
568 $form->{l_lastcost} = ""
569 if ($form->{searchitems} eq 'assembly' && !$form->{bom});
571 foreach my $item (@columns) {
572 if ($form->{"l_$item"} eq "Y") {
573 push @column_index, $item;
575 # add column to callback
576 $callback .= "&l_$item=Y";
580 if ($form->{l_subtotal} eq 'Y') {
581 $callback .= "&l_subtotal=Y";
584 $column_header{number} =
585 qq|<th class=listheading nowrap>| . $locale->text('number') . qq|</th>|;
586 $column_header{partnumber} =
587 qq|<th nowrap><a class=listheading href=$callback&sort=partnumber&revers=$form->{revers}&lastsort=$form->{lastsort}>|
588 . $locale->text('Part Number')
590 $column_header{description} =
591 qq|<th nowrap><a class=listheading href=$callback&sort=description&revers=$form->{revers}&lastsort=$form->{lastsort}>|
592 . $locale->text('Part Description')
594 $column_header{partsgroup} =
595 qq|<th nowrap><a class=listheading href=$callback&sort=partsgroup>|
596 . $locale->text('Group')
598 $column_header{bin} =
599 qq|<th><a class=listheading href=$callback&sort=bin>|
600 . $locale->text('Bin')
602 $column_header{priceupdate} =
603 qq|<th nowrap><a class=listheading href=$callback&sort=priceupdate>|
604 . $locale->text('Updated')
606 $column_header{onhand} =
607 qq|<th nowrap><a class=listheading href=$callback&sort=onhand&revers=$form->{revers}&lastsort=$form->{lastsort}>|
608 . $locale->text('Qty')
610 $column_header{unit} =
611 qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
612 $column_header{listprice} =
613 qq|<th class=listheading nowrap>|
614 . $locale->text('List Price')
616 $column_header{lastcost} =
617 qq|<th class=listheading nowrap>| . $locale->text('Last Cost') . qq|</th>|;
618 $column_header{rop} =
619 qq|<th class=listheading nowrap>| . $locale->text('ROP') . qq|</th>|;
620 $column_header{weight} =
621 qq|<th class=listheading nowrap>| . $locale->text('Weight') . qq|</th>|;
623 $column_header{invnumber} =
624 qq|<th nowrap><a class=listheading href=$callback&sort=invnumber>|
625 . $locale->text('Invoice Number')
627 $column_header{ordnumber} =
628 qq|<th nowrap><a class=listheading href=$callback&sort=ordnumber>|
629 . $locale->text('Order Number')
631 $column_header{quonumber} =
632 qq|<th nowrap><a class=listheading href=$callback&sort=quonumber>|
633 . $locale->text('Quotation')
636 $column_header{name} =
637 qq|<th nowrap><a class=listheading href=$callback&sort=name>|
638 . $locale->text('Name')
641 $column_header{sellprice} =
642 qq|<th class=listheading nowrap>|
643 . $locale->text('Sell Price')
645 $column_header{linetotalsellprice} =
646 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
647 $column_header{linetotallastcost} =
648 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
649 $column_header{linetotallistprice} =
650 qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
652 $column_header{image} =
653 qq|<th class=listheading nowrap>| . $locale->text('Image') . qq|</a></th>|;
654 $column_header{drawing} =
655 qq|<th nowrap><a class=listheading href=$callback&sort=drawing>|
656 . $locale->text('Drawing')
658 $column_header{microfiche} =
659 qq|<th nowrap><a class=listheading href=$callback&sort=microfiche>|
660 . $locale->text('Microfiche')
663 $column_header{serialnumber} =
664 qq|<th nowrap><a class=listheading href=$callback&sort=serialnumber>|
665 . $locale->text('Serial Number')
667 $column_header{soldtotal} =
668 qq|<th nowrap><a class=listheading href=$callback&sort=soldtotal&revers=$form->{revers}&lastsort=$form->{lastsort}>|
669 . $locale->text('soldtotal')
673 my $colspan = $#column_index + 1;
680 <th class=listtop colspan=$colspan>$form->{title}</th>
684 <tr><td colspan=$colspan>$option</td></tr>
686 <tr class=listheading>
689 map { print "\n$column_header{$_}" } @column_index;
695 # add order to callback
696 $form->{callback} = $callback .= "&sort=$form->{sort}";
698 # escape callback for href
699 $callback = $form->escape($callback);
701 if (@{ $form->{parts} }) {
702 $sameitem = $form->{parts}->[0]->{ $form->{sort} };
705 # insert numbers for top100
707 foreach my $ref (@{ $form->{parts} }) {
712 # if avaible -> insert choice here
713 if (($form->{ndxs_counter}) > 0) {
714 for (my $i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
715 $partnumber = $form->{"totop100_partnumber_$i"};
716 $description = $form->{"totop100_description_$i"};
717 $unit = $form->{"totop100_unit_$i"};
718 $sellprice = $form->{"totop100_sellprice_$i"};
719 $soldtotal = $form->{"totop100_soldtotal_$i"};
722 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
723 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
724 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
725 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
726 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
730 push @{ $form->{parts} },
732 partnumber => "$partnumber",
733 description => "$description",
735 sellprice => "$sellprice",
736 soldtotal => "$soldtotal" };
739 # build data for columns
740 foreach my $ref (@{ $form->{parts} }) {
743 if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
744 if ($sameitem ne $ref->{ $form->{sort} }) {
746 $sameitem = $ref->{ $form->{sort} };
750 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
751 $ref->{sellprice} *= $ref->{exchangerate};
752 $ref->{listprice} *= $ref->{exchangerate};
753 $ref->{lastcost} *= $ref->{exchangerate};
755 # use this for assemblies
756 $onhand = $ref->{onhand};
759 if ($ref->{assemblyitem}) {
761 $onhand = 0 if ($form->{sold});
764 $ref->{description} =~ s/\n/<br>/g;
766 $column_data{number} =
768 . $form->format_amount(\%myconfig, $ref->{number})
770 $column_data{partnumber} =
771 "<td align=$align>$ref->{partnumber} </a></td>";
772 $column_data{description} = "<td>$ref->{description} </td>";
773 $column_data{partsgroup} = "<td>$ref->{partsgroup} </td>";
775 $column_data{onhand} =
777 . $form->format_amount(\%myconfig, $ref->{onhand})
779 $column_data{sellprice} =
781 . $form->format_amount(\%myconfig, $ref->{sellprice})
783 $column_data{listprice} =
785 . $form->format_amount(\%myconfig, $ref->{listprice})
787 $column_data{lastcost} =
789 . $form->format_amount(\%myconfig, $ref->{lastcost})
792 $column_data{linetotalsellprice} = "<td align=right>"
793 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2)
795 $column_data{linetotallastcost} = "<td align=right>"
796 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2)
798 $column_data{linetotallistprice} = "<td align=right>"
799 . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2)
802 if (!$ref->{assemblyitem}) {
803 $totalsellprice += $onhand * $ref->{sellprice};
804 $totallastcost += $onhand * $ref->{lastcost};
805 $totallistprice += $onhand * $ref->{listprice};
807 $subtotalonhand += $onhand;
808 $subtotalsellprice += $onhand * $ref->{sellprice};
809 $subtotallastcost += $onhand * $ref->{lastcost};
810 $subtotallistprice += $onhand * $ref->{listprice};
815 . $form->format_amount(\%myconfig, $ref->{rop}) . "</td>";
816 $column_data{weight} =
818 . $form->format_amount(\%myconfig, $ref->{weight})
820 $column_data{unit} = "<td>$ref->{unit} </td>";
821 $column_data{bin} = "<td>$ref->{bin} </td>";
822 $column_data{priceupdate} = "<td>$ref->{priceupdate} </td>";
824 $column_data{invnumber} =
825 ($ref->{module} ne 'oe')
826 ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}</a></td>"
827 : "<td>$ref->{invnumber}</td>";
828 $column_data{ordnumber} =
829 ($ref->{module} eq 'oe')
830 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{ordnumber}</a></td>"
831 : "<td>$ref->{ordnumber}</td>";
832 $column_data{quonumber} =
833 ($ref->{module} eq 'oe' && !$ref->{ordnumber})
834 ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{quonumber}</a></td>"
835 : "<td>$ref->{quonumber}</td>";
837 $column_data{name} = "<td>$ref->{name}</td>";
839 $column_data{image} =
841 ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>"
843 $column_data{drawing} =
845 ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>"
847 $column_data{microfiche} =
849 ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>"
852 $column_data{serialnumber} = "<td>$ref->{serialnumber}</td>";
854 $column_data{soldtotal} = "<td align=right>$ref->{soldtotal}</td>";
858 print "<tr class=listrow$i>";
860 map { print "\n$column_data{$_}" } @column_index;
867 if ($form->{l_subtotal} eq 'Y') {
871 if ($form->{"l_linetotal"}) {
872 map { $column_data{$_} = "<td> </td>" } @column_index;
873 $column_data{linetotalsellprice} =
874 "<th class=listtotal align=right>"
875 . $form->format_amount(\%myconfig, $totalsellprice, 2)
877 $column_data{linetotallastcost} =
878 "<th class=listtotal align=right>"
879 . $form->format_amount(\%myconfig, $totallastcost, 2)
881 $column_data{linetotallistprice} =
882 "<th class=listtotal align=right>"
883 . $form->format_amount(\%myconfig, $totallistprice, 2)
886 print "<tr class=listtotal>";
888 map { print "\n$column_data{$_}" } @column_index;
895 <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
904 <form method=post action=$form->{script}>
906 <input type=hidden name=login value=$form->{login}>
907 <input type=hidden name=password value=$form->{password}>
909 <input type=hidden name=itemstatus value="$form->{itemstatus}">
910 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
911 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
912 <input type=hidden name=l_description value="$form->{l_description}">
913 <input type=hidden name=l_onhand value="$form->{l_onhand}">
914 <input type=hidden name=l_unit value="$form->{l_unit}">
915 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
916 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
917 <input type=hidden name=sort value="$form->{sort}">
918 <input type=hidden name=revers value="$form->{revers}">
919 <input type=hidden name=lastsort value="$form->{lastsort}">
920 <input type=hidden name=parts value="$form->{parts}">
922 <input type=hidden name=bom value="$form->{bom}">
923 <input type=hidden name=titel value="$form->{titel}">
924 <input type=hidden name=searchitems value="$form->{searchitems}">|;
929 <input type=hidden name=ndxs_counter value="$form->{ndxs_counter}">
931 <input class=submit type=submit name=action value="|
932 . $locale->text('choice') . qq|">
940 $lxdebug->leave_sub();
945 # Warning, deep magic ahead.
946 # This function parses the requested details, sanity checks them, and converts them into a format thats usable for IC->all_parts
948 # flags coming from the form:
950 # searchitems=part revers=0 lastsort=''
953 # partnumber ean description partsgroup serialnumber make model drawing microfiche
954 # transdatefrom transdateto
957 # itemstatus = active | onhand | short | obsolete | orphaned
958 # action = continue | top100
961 # bought sold onorder ordered rfq quoted
962 # l_partnumber l_description l_serialnumber l_unit l_listprice l_sellprice l_lastcost
963 # l_linetotal l_priceupdate l_bin l_rop l_weight l_image l_drawing l_microfiche
964 # l_partsgroup l_subtotal l_soldtotal l_deliverydate
967 # nextsub login password revers lastsort sort ndxs_counter
969 sub generate_report {
970 $lxdebug->enter_sub();
972 my ($revers, $lastsort, $description);
974 $form->{title} = (ucfirst $form->{searchitems}) . "s";
975 $form->{title} = $locale->text($form->{title});
977 my $revers = $form->{revers};
978 my $lastsort = $form->{lastsort};
980 # sorting and direction of sorting
981 # ToDO: change this to the simpler field+direction method
982 if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
984 $form->{lastsort} = "partnumber";
985 $form->{sort} = "partnumber";
987 if ($form->{lastsort} eq $form->{sort}) {
988 $form->{revers} = 1 - $form->{revers};
991 $form->{lastsort} = $form->{sort};
995 # special case if we have a serialnumber limit search
996 # serialnumbers are only given in invoices and orders,
997 # so they can only pop up in bought, sold, rfq, and quoted stuff
998 $form->{no_sn_joins} = 'Y' if ( !$form->{bought} && !$form->{sold}
999 && !$form->{rfq} && !$form->{quoted}
1000 && ($form->{l_serialnumber} || $form->{serialnumber}));
1002 # special case for any checkbox of bought | sold | onorder | ordered | rfq | quoted.
1003 # if any of these are ticked the behavior changes slightly for lastcost
1004 # since all those are aggregation checks for the legder tables this is an internal switch
1005 # refered to as ledgerchecks
1006 $form->{ledgerchecks} = 'Y' if ( $form->{bought} || $form->{sold} || $form->{onorder}
1007 || $form->{ordered} || $form->{rfq} || $form->{quoted});
1009 # if something should be activated if something else is active, enter it here
1010 my %dependencies = (
1011 onhand => [ qw(l_onhand) ],
1012 short => [ qw(l_onhand) ],
1013 onorder => [ qw(l_ordnumber) ],
1014 ordered => [ qw(l_ordnumber) ],
1015 rfq => [ qw(l_quonumber) ],
1016 quoted => [ qw(l_quonumber) ],
1017 bought => [ qw(l_invnumber) ],
1018 sold => [ qw(l_invnumber) ],
1019 ledgerchecks => [ qw(l_name) ],
1020 serialnumber => [ qw(l_serialnumber) ],
1021 no_sn_joins => [ qw(bought sold) ],
1024 # these strings get displayed at the top of the results to indicate the user which switches were used
1026 active => $locale->text('Active'),
1027 obsolete => $locale->text('Obsolete'),
1028 orphaned => $locale->text('Orphaned'),
1029 onhand => $locale->text('On Hand'),
1030 short => $locale->text('Short'),
1031 onorder => $locale->text('On Order'),
1032 ordered => $locale->text('Ordered'),
1033 rfq => $locale->text('RFQ'),
1034 quoted => $locale->text('Quoted'),
1035 bought => $locale->text('Bought'),
1036 sold => $locale->text('Sold'),
1037 transdatefrom => $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1),
1038 transdateto => $locale->text('To (time)') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1),
1039 partnumber => $locale->text('Part Number') . ": '$form->{partnumber}'",
1040 partsgroup => $locale->text('Group') . ": '$form->{partsgroup}'",
1041 serialnumber => $locale->text('Serial Number') . ": '$form->{serialnumber}'",
1042 description => $locale->text('Part Description') . ": '$form->{description}'",
1043 make => $locale->text('Make') . ": '$form->{make}'",
1044 model => $locale->text('Model') . ": '$form->{model}'",
1045 drawing => $locale->text('Drawing') . ": '$form->{drawing}'",
1046 microfiche => $locale->text('Microfiche') . ": '$form->{microfiche}'",
1047 l_soldtotal => $locale->text('soldtotal'),
1050 my @itemstatus_keys = qw(active obsolete orphaned onhand short);
1051 my @callback_keys = qw(onorder ordered rfq quoted bought sold partnumber partsgroup serialnumber description make model
1052 drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto ean);
1054 # calculate dependencies
1055 for (@itemstatus_keys, @callback_keys) {
1056 next if ($form->{itemstatus} ne $_ && !$form->{$_});
1057 map { $form->{$_} = 'Y' } @{ $dependencies{$_} } if $dependencies{$_};
1060 # generate callback and optionstrings
1062 for my $key (@itemstatus_keys, @callback_keys) {
1063 next if ($form->{itemstatus} ne $key && !$form->{$key});
1064 push @options, $optiontexts{$key};
1067 # special case for lastcost
1068 $form->{l_lastcost} = "" if $form->{ledgerchecks};
1070 if ($form->{description}) {
1071 $description = $form->{description};
1072 $description =~ s/\n/<br>/g;
1075 if ($form->{l_linetotal}) {
1076 $form->{l_onhand} = "Y";
1077 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
1078 if ($form->{l_lastcost}) {
1079 $form->{l_linetotallastcost} = "Y";
1080 if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
1081 $form->{l_linetotallastcost} = "";
1084 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
1087 if ($form->{searchitems} eq 'service') {
1089 # remove bin, weight and rop from list
1090 map { $form->{"l_$_"} = "" } qw(bin weight rop);
1092 $form->{l_onhand} = "";
1094 # qty is irrelevant unless bought or sold
1095 if ( $form->{bought}
1100 || $form->{quoted}) {
1101 $form->{l_onhand} = "Y";
1103 $form->{l_linetotalsellprice} = "";
1104 $form->{l_linetotallastcost} = "";
1108 $form->{l_lastcost} = "" if ($form->{searchitems} eq 'assembly' && !$form->{bom});
1110 IC->all_parts(\%myconfig, \%$form);
1113 qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost
1114 priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal deliverydate);
1117 'bin' => { 'text' => $locale->text('Bin'), },
1118 'deliverydate' => { 'text' => $locale->text('deliverydate'), },
1119 'description' => { 'text' => $locale->text('Part Description'), },
1120 'drawing' => { 'text' => $locale->text('Drawing'), },
1121 'image' => { 'text' => $locale->text('Image'), },
1122 'invnumber' => { 'text' => $locale->text('Invoice Number'), },
1123 'lastcost' => { 'text' => $locale->text('Last Cost'), },
1124 'linetotallastcost' => { 'text' => $locale->text('Extended'), },
1125 'linetotallistprice' => { 'text' => $locale->text('Extended'), },
1126 'linetotalsellprice' => { 'text' => $locale->text('Extended'), },
1127 'listprice' => { 'text' => $locale->text('List Price'), },
1128 'microfiche' => { 'text' => $locale->text('Microfiche'), },
1129 'name' => { 'text' => $locale->text('Name'), },
1130 'onhand' => { 'text' => $locale->text('Qty'), },
1131 'ordnumber' => { 'text' => $locale->text('Order Number'), },
1132 'partnumber' => { 'text' => $locale->text('Part Number'), },
1133 'partsgroup' => { 'text' => $locale->text('Group'), },
1134 'priceupdate' => { 'text' => $locale->text('Updated'), },
1135 'quonumber' => { 'text' => $locale->text('Quotation'), },
1136 'rop' => { 'text' => $locale->text('ROP'), },
1137 'sellprice' => { 'text' => $locale->text('Sell Price'), },
1138 'serialnumber' => { 'text' => $locale->text('Serial Number'), },
1139 'soldtotal' => { 'text' => $locale->text('soldtotal'), },
1140 'unit' => { 'text' => $locale->text('Unit'), },
1141 'weight' => { 'text' => $locale->text('Weight'), },
1144 map { $column_defs{$_}->{visible} = $form->{"l_$_"} ? 1 : 0 } @columns;
1145 map { $column_defs{$_}->{align} = 'right' } qw(onhand sellprice listprice lastcost linetotalsellprice linetotallastcost linetotallistprice rop weight soldtotal);
1147 my @hidden_variables = (qw(l_subtotal l_linetotal searchitems itemstatus bom), @itemstatus_keys, @callback_keys, map { "l_$_" } @columns);
1148 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
1150 my @sort_full = qw(partnumber description onhand soldtotal deliverydate);
1151 my @sort_no_revers = qw(partsgroup bin priceupdate invnumber ordnumber quonumber name image drawing serialnumber);
1153 foreach my $col (@sort_full) {
1154 $column_defs{$col}->{link} = join '&', $callback, "sort=$col", map { "$_=" . E($form->{$_}) } qw(revers lastsort);
1156 map { $column_defs{$_}->{link} = "${callback}&sort=$_" } @sort_no_revers;
1158 # add order to callback
1159 $form->{callback} = join '&', ($callback, map { "${_}=" . E($form->{$_}) } qw(sort revers));
1161 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1163 my %attachment_basenames = (
1164 'part' => $locale->text('part_list'),
1165 'service' => $locale->text('service_list'),
1166 'assembly' => $locale->text('assembly_list'),
1169 $report->set_options('top_info_text' => $locale->text('Options') . ': ' . join(', ', grep $_, @options),
1170 'raw_bottom_info_text' => $form->parse_html_template('ic/generate_report_bottom'),
1171 'output_format' => 'HTML',
1172 'title' => $form->{title},
1173 'attachment_basename' => $attachment_basenames{$form->{searchitems}} . strftime('_%Y%m%d', localtime time),
1175 $report->set_options_from_form();
1177 $report->set_columns(%column_defs);
1178 $report->set_column_order(@columns);
1180 $report->set_export_options('generate_report', @hidden_variables, qw(sort revers));
1182 $report->set_sort_indicator($form->{sort}, $form->{revers} ? 0 : 1);
1184 my @subtotal_columns = qw(sellprice listprice lastcost);
1185 my %subtotals = map { $_ => 0 } ('onhand', @subtotal_columns);
1186 my %totals = map { $_ => 0 } @subtotal_columns;
1188 my $same_item = $form->{parts}[0]{ $form->{sort} } if (scalar @{ $form->{parts} });
1191 foreach my $ref (@{ $form->{parts} }) {
1193 # fresh row, for inserting later
1194 my $row = { map { $_ => { 'data' => $ref->{$_} } } @columns };
1196 $ref->{exchangerate} ||= 1;
1197 $ref->{price_factor} ||= 1;
1198 $ref->{sellprice} *= $ref->{exchangerate} / $ref->{price_factor};
1199 $ref->{listprice} *= $ref->{exchangerate} / $ref->{price_factor};
1200 $ref->{lastcost} *= $ref->{exchangerate} / $ref->{price_factor};
1202 # use this for assemblies
1203 my $onhand = $ref->{onhand};
1205 if ($ref->{assemblyitem}) {
1206 $row->{partnumber}{align} = 'right';
1207 $row->{onhand}{data} = 0;
1208 $onhand = 0 if ($form->{sold});
1211 my $edit_link = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback');
1212 $row->{partnumber}->{link} = $edit_link;
1213 $row->{description}->{link} = $edit_link;
1215 foreach (qw(sellprice listprice lastcost)) {
1216 $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}, -2);
1217 $row->{"linetotal$_"}{data} = $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2);
1220 map { $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}); } qw(onhand rop weight soldtotal);
1222 if (!$ref->{assemblyitem}) {
1223 foreach my $col (@subtotal_columns) {
1224 $totals{$col} += $onhand * $ref->{$col};
1225 $subtotals{$col} += $onhand * $ref->{$col};
1228 $subtotals{onhand} += $onhand;
1232 if ($ref->{module} eq 'oe') {
1233 my $edit_oe_link = build_std_url("script=oe.pl", 'action=edit', 'type=' . E($ref->{type}), 'id=' . E($ref->{trans_id}), 'callback');
1234 $row->{ordnumber}{link} = $edit_oe_link;
1235 $row->{quonumber}{link} = $edit_oe_link if (!$ref->{ordnumber});
1238 $row->{invnumber}{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'type=invoice', 'id=' . E($ref->{trans_id}), 'callback');
1241 # set properties of images
1242 if ($ref->{image} && (lc $report->{options}->{output_format} eq 'html')) {
1243 $row->{image}{data} = '';
1244 $row->{image}{raw_data} = '<a href="' . H($ref->{image}) . '"><img src="' . H($ref->{image}) . '" height="32" border="0"></a>';
1246 map { $row->{$_}{link} = $ref->{$_} } qw(drawing microfiche);
1248 $report->add_data($row);
1250 my $next_ref = $form->{parts}[$idx + 1];
1252 # insert subtotal rows
1253 if (($form->{l_subtotal} eq 'Y') &&
1255 (!$next_ref->{assemblyitem} && ($same_item ne $next_ref->{ $form->{sort} })))) {
1256 my $row = { map { $_ => { 'class' => 'listsubtotal', } } @columns };
1258 if (($form->{searchitems} ne 'assembly') || !$form->{bom}) {
1259 $row->{onhand}->{data} = $form->format_amount(\%myconfig, $subtotals{onhand});
1262 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $subtotals{$_}, 2) } @subtotal_columns;
1263 map { $subtotals{$_} = 0 } ('onhand', @subtotal_columns);
1265 $report->add_data($row);
1267 $same_item = $next_ref->{ $form->{sort} };
1273 if ($form->{"l_linetotal"}) {
1274 my $row = { map { $_ => { 'class' => 'listtotal', } } @columns };
1276 map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } @subtotal_columns;
1278 $report->add_separator();
1279 $report->add_data($row);
1282 $report->generate_with_headers();
1284 $lxdebug->leave_sub();
1285 } #end generate_report
1287 sub parts_subtotal {
1288 $lxdebug->enter_sub();
1291 our (%column_data, @column_index);
1292 our ($subtotalonhand, $totalsellprice, $totallastcost, $totallistprice, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
1294 map { $column_data{$_} = "<td> </td>" } @column_index;
1295 $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});
1297 $column_data{onhand} =
1298 "<th class=listsubtotal align=right>"
1299 . $form->format_amount(\%myconfig, $subtotalonhand)
1302 $column_data{linetotalsellprice} =
1303 "<th class=listsubtotal align=right>"
1304 . $form->format_amount(\%myconfig, $subtotalsellprice, 2)
1306 $column_data{linetotallistprice} =
1307 "<th class=listsubtotal align=right>"
1308 . $form->format_amount(\%myconfig, $subtotallistprice, 2)
1310 $column_data{linetotallastcost} =
1311 "<th class=listsubtotal align=right>"
1312 . $form->format_amount(\%myconfig, $subtotallastcost, 2)
1315 $subtotalonhand = 0;
1316 $subtotalsellprice = 0;
1317 $subtotallistprice = 0;
1318 $subtotallastcost = 0;
1320 print "<tr class=listsubtotal>";
1322 map { print "\n$column_data{$_}" } @column_index;
1328 $lxdebug->leave_sub();
1332 $lxdebug->enter_sub();
1333 # show history button
1334 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
1335 #/show hhistory button
1336 IC->get_part(\%myconfig, \%$form);
1338 $form->{"original_partnumber"} = $form->{"partnumber"};
1340 $form->{title} = $locale->text('Edit ' . ucfirst $form->{item});
1345 $lxdebug->leave_sub();
1349 $lxdebug->enter_sub();
1351 IC->create_links("IC", \%myconfig, \%$form);
1354 map({ $form->{selectcurrency} .= "<option>$_\n" }
1355 split(/:/, $form->{currencies}));
1357 # parts and assemblies have the same links
1358 my $item = $form->{item};
1359 if ($form->{item} eq 'assembly') {
1363 # build the popup menus
1364 $form->{taxaccounts} = "";
1365 foreach my $key (keys %{ $form->{IC_links} }) {
1366 foreach my $ref (@{ $form->{IC_links}{$key} }) {
1368 # if this is a tax field
1369 if ($key =~ /IC_tax/) {
1370 if ($key =~ /\Q$item\E/) {
1371 $form->{taxaccounts} .= "$ref->{accno} ";
1372 $form->{"IC_tax_$ref->{accno}_description"} =
1373 "$ref->{accno}--$ref->{description}";
1376 if ($form->{amount}{ $ref->{accno} }) {
1377 $form->{"IC_tax_$ref->{accno}"} = "checked";
1380 $form->{"IC_tax_$ref->{accno}"} = "checked";
1385 $form->{"select$key"} .=
1386 "<option $ref->{selected}>$ref->{accno}--$ref->{description}\n";
1387 if ($form->{amount}{$key} eq $ref->{accno}) {
1388 $form->{$key} = "$ref->{accno}--$ref->{description}";
1394 chop $form->{taxaccounts};
1396 if (($form->{item} eq "part") || ($form->{item} eq "assembly")) {
1397 $form->{selectIC_income} = $form->{selectIC_sale};
1398 $form->{selectIC_expense} = $form->{selectIC_cogs};
1399 $form->{IC_income} = $form->{IC_sale};
1400 $form->{IC_expense} = $form->{IC_cogs};
1403 delete $form->{IC_links};
1404 delete $form->{amount};
1406 $form->get_partsgroup(\%myconfig, { all => 1 });
1408 $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
1410 if (@{ $form->{all_partsgroup} }) {
1411 $form->{selectpartsgroup} = qq|<option>\n|;
1412 map { $form->{selectpartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} };
1415 if ($form->{item} eq 'assembly') {
1417 foreach my $i (1 .. $form->{assembly_rows}) {
1418 if ($form->{"partsgroup_id_$i"}) {
1419 $form->{"partsgroup_$i"} =
1420 qq|$form->{"partsgroup_$i"}--$form->{"partsgroup_id_$i"}|;
1423 $form->get_partsgroup(\%myconfig);
1425 if (@{ $form->{all_partsgroup} }) {
1426 $form->{selectassemblypartsgroup} = qq|<option>\n|;
1429 $form->{selectassemblypartsgroup} .=
1430 qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
1431 } @{ $form->{all_partsgroup} };
1434 $lxdebug->leave_sub();
1438 $lxdebug->enter_sub();
1440 $form->{eur} = $eur; # config dumps into namespace - yuck
1441 $form->{pg_keys} = sub { "$_[0]->{partsgroup}--$_[0]->{id}" };
1442 $form->{description_area} = ($form->{rows} = $form->numtextrows($form->{description}, 40)) > 1;
1444 map { $form->{"is_$_"} = ($form->{item} eq $_) } qw(part service assembly);
1445 map { $form->{$_} =~ s/"/"/g; } qw(unit);
1447 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
1449 $rows = 4 if $rows = $form->numtextrows($form->{notes}, 40) < 2;
1450 $form->{notes_rows} = $rows;
1452 IC->retrieve_buchungsgruppen(\%myconfig, $form);
1453 @{ $form->{BUCHUNGSGRUPPEN} } = grep { $_->{id} eq $form->{buchungsgruppen_id} || ($form->{id} && $form->{orphaned}) || $form->{id} } @{ $form->{BUCHUNGSGRUPPEN} };
1455 # use JavaScript Calendar or not (yes!)
1456 $form->{jsscript} = 1;
1458 $units = AM->retrieve_units(\%myconfig, $form, $form->{"item"} eq "service" ? "service" : "dimension");
1459 $form->{ALL_UNITS} = [ map +{ name => $_ }, sort { $units->{$a}{sortkey} <=> $units->{$b}{sortkey} } keys %$units ];
1461 $form->{fokus} = "ic.partnumber";
1464 print $form->parse_html_template('ic/form_header', { ALL_PRICE_FACTORS => $form->{ALL_PRICE_FACTORS},
1465 ALL_UNITS => $form->{ALL_UNITS},
1466 BUCHUNGSGRUPPEN => $form->{BUCHUNGSGRUPPEN},
1467 payment_terms => $form->{payment_terms},
1468 all_partsgroup => $form->{all_partsgroup}});
1469 $lxdebug->leave_sub();
1473 $lxdebug->enter_sub();
1475 if ($form->{item} eq "assembly") {
1480 <table width="100%">
1482 <th colspan=2 align=right>| . $locale->text('Total') . qq| </th>
1483 <th align=right>| . $form->format_amount(\%myconfig, $form->{assemblytotal}, 2) . qq|</th>
1488 <input type=hidden name=assembly_rows value=$form->{assembly_rows}>
1493 <input type=hidden name=login value=$form->{login}>
1494 <input type=hidden name=password value=$form->{password}>
1495 <input type=hidden name=callback value="$form->{callback}">
1496 <input type=hidden name=previousform value="$form->{previousform}">
1497 <input type=hidden name=taxaccount2 value="$form->{taxaccount2}">
1498 <input type=hidden name=vc value=$form->{vc}>
1500 <td><hr size=3 noshade></td>
1505 <input class=submit type=submit name=action value="|
1506 . $locale->text('Update') . qq|">
1509 unless ($form->{item} eq "service") {
1511 <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}>
1516 <input type=hidden name=price_rows value=$form->{price_rows}>|;
1519 <input class=submit type=submit name=action value="|
1520 . $locale->text('Save') . qq|">|;
1524 if (!$form->{previousform}) {
1526 <input class=submit type=submit name=action value="|
1527 . $locale->text('Save as new') . qq|">|;
1530 if ($form->{orphaned}) {
1531 if (!$form->{previousform}) {
1532 if ($form->{item} eq 'assembly') {
1533 if (!$form->{onhand}) {
1535 <input class=submit type=submit name=action value="|
1536 . $locale->text('Delete') . qq|">|;
1540 <input class=submit type=submit name=action value="|
1541 . $locale->text('Delete') . qq|">|;
1547 if (!$form->{previousform}) {
1548 if ($form->{menubar}) {
1549 require "bin/mozilla/menu.pl";
1553 # button for saving history
1554 if($form->{id} ne "") {
1556 <input type=button class=submit onclick=set_history_window(|
1558 . qq|); name=history id=history value=|
1559 . $locale->text('history')
1562 # /button for saving history
1567 <script type="text/javascript" src="js/wz_tooltip.js"></script>
1573 $lxdebug->leave_sub();
1577 $lxdebug->enter_sub();
1585 <th class="listheading">| . $locale->text('Make') . qq|</th>
1586 <th class="listheading">| . $locale->text('Model') . qq|</th>
1590 for my $i (1 .. $numrows) {
1591 $form->{"make_$i"} =~ s/\"/"/g;
1592 $form->{"model_$i"} =~ s/\"/"/g;
1595 <td width=50%><input name="make_$i" size=30 value="$form->{"make_$i"}"></td>
1596 <td width=50%><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>
1607 $lxdebug->leave_sub();
1611 $lxdebug->enter_sub();
1613 my (@column_index, %column_data, %column_header);
1614 my ($nochange, $callback, $previousform, $linetotal, $href);
1616 our ($deliverydate); # ToDO: cjeck if this indeed comes from global context
1619 qw(runningnumber qty unit bom partnumber description partsgroup total);
1621 if ($form->{previousform}) {
1623 @column_index = qw(qty unit bom partnumber description partsgroup total);
1627 $form->{old_callback} = $form->{callback};
1628 $callback = $form->{callback};
1629 $form->{callback} = "$form->{script}?action=display_form";
1632 map { delete $form->{$_} } qw(action header);
1636 # save form variables in a previousform variable
1637 foreach my $key (sort keys %$form) {
1640 $form->{$key} =~ s/&/%26/g;
1641 $previousform .= qq|$key=$form->{$key}&|;
1644 $previousform = $form->escape($form->escape($previousform, 1));
1645 $form->{callback} = $callback;
1647 $form->{assemblytotal} = 0;
1648 $form->{weight} = 0;
1651 $column_header{runningnumber} =
1652 qq|<th nowrap width=5%>| . $locale->text('No.') . qq|</th>|;
1653 $column_header{qty} =
1654 qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
1655 $column_header{unit} =
1656 qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
1657 $column_header{partnumber} =
1658 qq|<th align=left nowrap width=20%>|
1659 . $locale->text('Part Number')
1661 $column_header{description} =
1662 qq|<th nowrap width=50%>| . $locale->text('Part Description') . qq|</th>|;
1663 $column_header{total} =
1664 qq|<th align=right nowrap>| . $locale->text('Extended') . qq|</th>|;
1665 $column_header{bom} = qq|<th>| . $locale->text('BOM') . qq|</th>|;
1666 $column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
1669 <tr class=listheading>
1670 <th class=listheading>| . $locale->text('Individual Items') . qq|</th>
1678 map { print "\n$column_header{$_}" } @column_index;
1684 for my $i (1 .. $numrows) {
1685 $form->{"partnumber_$i"} =~ s/\"/"/g;
1688 $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
1689 $form->{assemblytotal} += $linetotal;
1691 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1693 $linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
1695 if (($i >= 1) && ($i == $numrows)) {
1698 map { $column_data{$_} = qq|<td></td>| }
1699 qw(qty unit partnumber description bom partsgroup);
1702 map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom);
1705 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
1706 $column_data{partnumber} =
1707 qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
1708 $column_data{description} =
1709 qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
1710 $column_data{partsgroup} =
1711 qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|;
1717 if ($form->{previousform}) {
1718 $column_data{partnumber} =
1719 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|;
1721 qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|;
1724 qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|;
1725 $column_data{bom} .= ($form->{"bom_$i"}) ? "x" : " ";
1726 $column_data{bom} .= qq|</td>|;
1728 $column_data{partsgroup} =
1729 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
1733 qq|$form->{script}?action=edit&id=$form->{"id_$i"}&login=$form->{login}&password=$form->{password}&rowcount=$i&previousform=$previousform|;
1734 $column_data{partnumber} =
1735 qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|;
1736 $column_data{runningnumber} =
1737 qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
1739 qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
1741 $form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : "";
1743 qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
1745 $column_data{partsgroup} =
1746 qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
1749 $column_data{unit} =
1750 qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
1751 $column_data{description} =
1752 qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
1755 $column_data{total} = qq|<td align=right>$linetotal</td>|;
1757 $column_data{deliverydate} = qq|<td align=right>$deliverydate</td>|;
1762 map { print "\n$column_data{$_}" } @column_index;
1766 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
1767 <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
1768 <input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
1778 $lxdebug->leave_sub();
1782 $lxdebug->enter_sub();
1784 if ($form->{item} eq "assembly") {
1785 my $i = $form->{assembly_rows};
1787 # if last row is empty check the form otherwise retrieve item
1788 if ( ($form->{"partnumber_$i"} eq "")
1789 && ($form->{"description_$i"} eq "")
1790 && ($form->{"partsgroup_$i"} eq "")) {
1796 IC->assembly_item(\%myconfig, \%$form);
1798 my $rows = scalar @{ $form->{item_list} };
1801 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1804 $form->{makemodel_rows}--;
1808 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1809 qw(partnumber description unit partsgroup);
1810 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1811 keys %{ $form->{item_list}[0] };
1812 $form->{"runningnumber_$i"} = $form->{assembly_rows};
1813 $form->{assembly_rows}++;
1821 $form->{rowcount} = $i;
1822 $form->{assembly_rows}++;
1829 } elsif (($form->{item} eq 'part') || ($form->{item} eq 'service')) {
1833 $lxdebug->leave_sub();
1837 $lxdebug->enter_sub();
1839 my ($parts_id, %newform, $previousform, $amount, $callback);
1841 # check if there is a part number - commented out, cause there is an automatic allocation of numbers
1842 # $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Part Number missing!"));
1844 # check if there is a description
1845 $form->isblank("description", $locale->text("Part Description missing!"));
1847 if ($form->{obsolete}) {
1850 "Inventory quantity must be zero before you can set this $form->{item} obsolete!"
1852 if ($form->{onhand} * 1);
1855 if (!$form->{buchungsgruppen_id}) {
1856 $form->error($locale->text("Parts must have an entry type.") . " " .
1857 $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.")
1861 $form->error($locale->text('Description must not be empty!')) unless $form->{description};
1862 $form->error($locale->text('Partnumber must not be set to empty!')) if $form->{id} && !$form->{partnumber};
1864 # expand dynamic strings
1865 # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
1866 # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
1867 # $locale->text('Part Number missing!')
1868 # $locale->text('Service Number missing!')
1869 # $locale->text('Assembly Number missing!')
1872 $lxdebug->message($LXDebug::DEBUG1, "ic.pl: sellprice in save = $form->{sellprice}\n");
1873 if (IC->save(\%myconfig, \%$form) == 3) {
1874 $form->error($locale->text('Partnumber not unique!'));
1876 # saving the history
1877 if(!exists $form->{addition}) {
1878 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
1879 $form->{addition} = "SAVED";
1880 $form->save_history($form->dbconnect(\%myconfig));
1882 # /saving the history
1883 $parts_id = $form->{id};
1886 # load previous variables
1887 if ($form->{previousform}) {
1889 # save the new form variables before splitting previousform
1890 map { $newform{$_} = $form->{$_} } keys %$form;
1892 $previousform = $form->unescape($form->{previousform});
1894 # don't trample on previous variables
1895 map { delete $form->{$_} } keys %newform;
1897 # now take it apart and restore original values
1898 foreach my $item (split /&/, $previousform) {
1899 my ($key, $value) = split m/=/, $item, 2;
1900 $value =~ s/%26/&/g;
1901 $form->{$key} = $value;
1903 $form->{taxaccounts} = $newform{taxaccount2};
1905 if ($form->{item} eq 'assembly') {
1907 # undo number formatting
1908 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1909 qw(weight listprice sellprice rop);
1911 $form->{assembly_rows}--;
1912 $i = $newform{rowcount};
1913 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1915 $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
1916 $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
1918 # change/add values for assembly item
1919 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno price_factor_id);
1921 $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
1922 $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
1926 # set values for last invoice/order item
1927 $i = $form->{rowcount};
1928 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1930 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice lastcost price_factor_id);
1932 $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
1934 if ($form->{exchangerate} != 0) {
1935 $form->{"sellprice_$i"} /= $form->{exchangerate};
1938 $lxdebug->message($LXDebug::DEBUG1, qq|sellprice_$i in previousform 2 = | . $form->{"sellprice_$i"} . qq|\n|);
1940 map { $form->{"taxaccounts_$i"} .= "$_ " } split / /, $newform{taxaccount};
1941 chop $form->{"taxaccounts_$i"};
1942 foreach my $item (qw(description rate taxnumber)) {
1943 my $index = $form->{"taxaccounts_$i"} . "_$item";
1944 $form->{$index} = $newform{$index};
1947 # credit remaining calculation
1948 $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
1950 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
1951 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
1953 $form->{creditremaining} -= $amount;
1955 # redo number formatting, because invoice parse them!
1956 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(weight listprice sellprice rop);
1959 $form->{"id_$i"} = $parts_id;
1961 # Get the actual price factor (not just the ID) for the marge calculation.
1962 $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
1963 foreach my $pfac (@{ $form->{ALL_PRICE_FACTORS} }) {
1964 next if ($pfac->{id} != $newform{price_factor_id});
1965 $form->{"marge_price_factor_$i"} = $pfac->{factor};
1968 delete $form->{ALL_PRICE_FACTORS};
1970 delete $form->{action};
1972 # restore original callback
1973 $callback = $form->unescape($form->{callback});
1974 $form->{callback} = $form->unescape($form->{old_callback});
1975 delete $form->{old_callback};
1977 $form->{makemodel_rows}--;
1979 # put callback together
1980 foreach my $key (keys %$form) {
1982 # do single escape for Apache 2.0
1983 my $value = $form->escape($form->{$key}, 1);
1984 $callback .= qq|&$key=$value|;
1986 $form->{callback} = $callback;
1988 $lxdebug->message($LXDebug::DEBUG1, qq|ic.pl: sellprice_$i nach sub save = | . $form->{"sellprice_$i"} . qq|\n|);
1993 $lxdebug->leave_sub();
1997 $lxdebug->enter_sub();
1999 # saving the history
2000 if(!exists $form->{addition}) {
2001 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2002 $form->{addition} = "SAVED AS NEW";
2003 $form->save_history($form->dbconnect(\%myconfig));
2005 # /saving the history
2007 if ($form->{"original_partnumber"} &&
2008 ($form->{"partnumber"} eq $form->{"original_partnumber"})) {
2009 $form->{partnumber} = "";
2012 $lxdebug->leave_sub();
2016 $lxdebug->enter_sub();
2017 # saving the history
2018 if(!exists $form->{addition}) {
2019 $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2020 $form->{addition} = "DELETED";
2021 $form->save_history($form->dbconnect(\%myconfig));
2023 # /saving the history
2024 my $rc = IC->delete(\%myconfig, \%$form);
2027 $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
2028 $form->error($locale->text('Cannot delete item!'));
2030 $lxdebug->leave_sub();
2034 $lxdebug->enter_sub();
2043 <th class="listheading">| . $locale->text('Preisklasse') . qq|</th>
2044 <th class="listheading">| . $locale->text('Preis') . qq|</th>
2047 for my $i (1 .. $numrows) {
2050 <td width=50%><input type=hidden name="pricegroup_$i" size=30 value="$form->{"pricegroup_$i"}">$form->{"pricegroup_$i"}</td>
2051 <td width=50%><input name="price_$i" size=11 value="$form->{"price_$i"}"></td>
2052 <input type=hidden name="pricegroup_id_$i" value="$form->{"pricegroup_id_$i"}">
2063 $lxdebug->leave_sub();
2066 sub parts_language_selection {
2067 $lxdebug->enter_sub();
2071 my $languages = IC->retrieve_languages(\%myconfig, $form);
2073 if ($form->{language_values} ne "") {
2074 foreach $item (split(/---\+\+\+---/, $form->{language_values})) {
2075 my ($language_id, $translation, $longdescription) = split(/--\+\+--/, $item);
2077 foreach my $language (@{ $languages }) {
2078 next unless ($language->{id} == $language_id);
2080 $language->{translation} = $translation;
2081 $language->{longdescription} = $longdescription;
2087 my @header_sort = qw(name longdescription);
2088 my %header_title = ( "name" => $locale->text("Name"),
2089 "longdescription" => $locale->text("Long Description"),
2093 map(+{ "column_title" => $header_title{$_},
2095 "callback" => $callback,
2099 $form->{"title"} = $locale->text("Language Values");
2101 print $form->parse_html_template("ic/parts_language_selection", { "HEADER" => \@header,
2102 "LANGUAGES" => $languages,
2103 "onload" => $onload });
2105 $lxdebug->leave_sub();
2108 sub continue { call_sub($form->{"nextsub"}); }