1#=====================================================================
2# SQL-Ledger
3# Copyright (c) DWS Systems Inc.
4#
5#  Author: DWS Systems Inc.
6#     Web: http://www.sql-ledger.com
7#
8#======================================================================
9#
10# Inventory Control module
11#
12#======================================================================
13
14
15use SL::IC;
16
17require "$form->{path}/io.pl";
18require "$form->{path}/cm.pl";
19require "$form->{path}/js.pl";
20
211;
22# end of main
23
24
25
26sub add {
27
28  %label = ( part	=> 'Part',
29             service	=> 'Service',
30	     assembly	=> 'Assembly',
31             kit        => 'Kit',
32	     labor	=> 'Labor/Overhead', );
33
34# $locale->text('Add Part')
35# $locale->text('Add Service')
36# $locale->text('Add Assembly')
37# $locale->text('Add Kit')
38# $locale->text('Add Labor/Overhead')
39
40  $label = "Add $label{$form->{item}}";
41  $form->{title} = $locale->text($label);
42
43  $form->{callback} = "$form->{script}?action=add&item=$form->{item}&path=$form->{path}&login=$form->{login}" unless $form->{callback};
44
45  $form->{orphaned} = 1;
46
47  if ($form->{previousform}) {
48    $form->{callback} = "";
49  }
50
51  &link_part;
52
53  &display_form;
54
55}
56
57
58sub edit {
59
60  %label = ( part	=> 'Part',
61             service	=> 'Service',
62             assembly	=> 'Assembly',
63             kit        => 'Kit',
64	     labor	=> 'Labor/Overhead', );
65
66# $locale->text('Edit Part')
67# $locale->text('Edit Service')
68# $locale->text('Edit Assembly')
69# $locale->text('Edit Labor/Overhead')
70# $locale->text('Part Changeup')
71# $locale->text('Service Changeup')
72# $locale->text('Assembly Changeup')
73# $locale->text('Labor/Overhead Changeup')
74
75  IC->get_part(\%myconfig, \%$form);
76
77  $label = "Edit $label{$form->{item}}";
78  $label = "$label{$form->{item}} Changeup" if $form->{changeup};
79
80  $form->{title} = $locale->text($label);
81
82  $form->{previousform} = $form->escape($form->{previousform}, 1) if $form->{previousform};
83
84  &link_part;
85
86  &display_form;
87
88}
89
90
91
92sub link_part {
93
94  $partsgroupcode = $form->{partsgroupcode};
95
96  IC->create_links("IC", \%myconfig, \%$form);
97
98  $form->{partsgroupcode} = $partsgroupcode;
99  $form->{oldpartsgroupcode} = $partsgroupcode;
100
101  $form->{oldonhand} = $form->{onhand};
102
103  # currencies
104  $form->{selectcurrency} = "";
105  for (split /:/, $form->{currencies}) { $form->{selectcurrency} .= "$_\n" }
106
107
108  # readonly
109  if ($form->{changeup}) {
110    $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Changeup/;
111    $form->helpref("changeup_$form->{item}", $myconfig{countrycode});
112  } else {
113    $form->helpref($form->{item}, $myconfig{countrycode});
114  }
115
116  if ($form->{item} eq 'part') {
117    $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Part/;
118    $form->error($locale->text('Cannot create Part').";".$locale->text('Inventory account does not exist!')) if ! @{ $form->{IC_links}{IC} };
119    $form->error($locale->text('Cannot create Part').";".$locale->text('Income account does not exist!')) if ! @{ $form->{IC_links}{IC_sale} };
120    $form->error($locale->text('Cannot create Part').";".$locale->text('COGS account does not exist!')) if ! @{ $form->{IC_links}{IC_cogs} };
121  }
122
123  if ($form->{item} eq 'service') {
124    $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Service/;
125    $form->error($locale->text('Cannot create Service').";".$locale->text('Income account does not exist!')) if ! @{ $form->{IC_links}{IC_income} };
126    $form->error($locale->text('Cannot create Service').";".$locale->text('Expense account does not exist!')) if ! @{ $form->{IC_links}{IC_expense} };
127  }
128
129  if ($form->{item} eq 'assembly') {
130    $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Assembly/;
131    $form->error($locale->text('Cannot create Assembly').";".$locale->text('Income account does not exist!')) if ! @{ $form->{IC_links}{IC_income} };
132  }
133  if ($form->{item} eq 'kit') {
134    $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Kit/;
135    $form->error($locale->text('Cannot create Kit').";".$locale->text('Income account does not exist!')) if ! @{ $form->{IC_links}{IC_income} };
136  }
137
138  if ($form->{item} eq 'labor') {
139    $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Labor\/Overhead/;
140    $form->error($locale->text('Cannot create Labor').";".$locale->text('Inventory account does not exist!')) if ! @{ $form->{IC_links}{IC} };
141    $form->error($locale->text('Cannot create Labor').";".$locale->text('COGS account does not exist!')) if ! @{ $form->{IC_links}{IC_cogs} };
142  }
143
144  $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Goods \& Services/;
145
146  # parts, assemblies , labor and overhead have the same links
147  $taxpart = ($form->{item} eq 'service') ? "service" : "part";
148
149  # build the popup menus
150  $form->{taxaccounts} = "";
151  foreach $key (keys %{ $form->{IC_links} }) {
152
153    $form->{"select$key"} = "";
154    foreach $ref (@{ $form->{IC_links}{$key} }) {
155      # if this is a tax field
156      if ($key =~ /IC_tax/) {
157	if ($key =~ /$taxpart/) {
158
159	  $form->{taxaccounts} .= "$ref->{accno} ";
160	  $form->{"IC_tax_$ref->{accno}_description"} = "$ref->{accno}--$ref->{description}";
161
162	  if ($form->{id}) {
163	    if ($form->{amount}{$ref->{accno}}) {
164	      $form->{"IC_tax_$ref->{accno}"} = "checked";
165	    }
166	  } else {
167	    $form->{"IC_tax_$ref->{accno}"} = "checked";
168	  }
169
170	}
171      } else {
172
173	$form->{"select$key"} .= "$ref->{accno}--$ref->{description}\n";
174
175      }
176    }
177  }
178  chop $form->{taxaccounts};
179
180  $form->{selectIC_inventory} = $form->{selectIC};
181  if ($form->{item} !~ /service/) {
182    $form->{selectIC_income} = $form->{selectIC_sale};
183    $form->{selectIC_expense} = $form->{selectIC_cogs};
184    $form->{IC_income} = $form->{IC_sale};
185    $form->{IC_expense} = $form->{IC_cogs};
186  }
187
188  # set option
189  for (qw(IC_inventory IC_income IC_expense)) { $form->{$_} = "$form->{amount}{$_}{accno}--$form->{amount}{$_}{description}" if $form->{amount}{$_}{accno} }
190
191  delete $form->{IC_links};
192  delete $form->{amount};
193
194  if ($form->{partsgroup}) {
195    $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
196  }
197  $form->{oldpartsgroup} = $form->{partsgroup};
198
199  if (@{ $form->{all_partsgroup} }) {
200    $form->{selectpartsgroup} = qq|\n|;
201
202    for (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} .= qq|$_->{partsgroup}--$_->{id}\n| }
203    delete $form->{all_partsgroup};
204  }
205
206  # references
207  &all_references;
208
209  if ($form->{item} =~ /(assembly|kit)/) {
210    for (1 .. $form->{assembly_rows}) {
211      if ($form->{"partsgroup_id_$_"}) {
212	$form->{"partsgroup_$_"} = qq|$form->{"partsgroup_$_"}--$form->{"partsgroup_id_$_"}|;
213      }
214    }
215  }
216
217  # setup make and models
218  $i = 0;
219  foreach $ref (@{ $form->{makemodels} }) {
220    $i++;
221    for (qw(make model)) { $form->{"${_}_$i"} = $ref->{$_} }
222  }
223  $form->{makemodel_rows} = $i;
224  delete $form->{makemodels};
225
226  # onhand in warehouse
227  $i = 0;
228  foreach $ref (@{ $form->{inventory} }) {
229    $i++;
230    $form->{"warehouse_$i"} = $ref->{warehouse};
231    $form->{"wonhand_$i"} = $form->format_amount(\%myconfig, $ref->{onhand});
232  }
233  $form->{inventory_rows} = $i;
234  delete $form->{inventory};
235
236  # setup vendors
237  if (@{ $form->{all_vendor} }) {
238    $form->{selectvendor} = "\n";
239    for (@{ $form->{all_vendor} }) { $form->{selectvendor} .= qq|$_->{name}--$_->{id}\n| }
240    delete $form->{all_vendor};
241  }
242
243  # vendor matrix
244  $i = 0;
245  foreach $ref (@{ $form->{vendormatrix} }) {
246    $i++;
247    $form->{"vendor_$i"} = qq|$ref->{name}--$ref->{id}|;
248
249    for (qw(partnumber lastcost leadtime vendorcurr)) { $form->{"${_}_$i"} = $ref->{$_} }
250  }
251  $form->{vendor_rows} = $i;
252  delete $form->{vendormatrix};
253
254  # setup customers and groups
255  if (@{ $form->{all_customer} }) {
256    $form->{selectcustomer} = "\n";
257    for (@{ $form->{all_customer} }) { $form->{selectcustomer} .= qq|$_->{name}--$_->{id}\n| }
258    delete $form->{all_customer};
259  }
260
261  if (@{ $form->{all_pricegroup} }) {
262    $form->{selectpricegroup} = "\n";
263    for (@{ $form->{all_pricegroup} }) { $form->{selectpricegroup} .= qq|$_->{pricegroup}--$_->{id}\n| }
264    delete $form->{all_pricegroup};
265  }
266
267  $i = 0;
268  # customer matrix
269  foreach $ref (@{ $form->{customermatrix} }) {
270    $i++;
271    $form->{"customer_$i"} = "$ref->{name}--$ref->{cid}" if $ref->{cid};
272    $form->{"pricegroup_$i"} = "$ref->{pricegroup}--$ref->{gid}" if $ref->{gid};
273
274    for (qw(validfrom validto pricebreak customerprice customercurr)) { $form->{"${_}_$i"} = $ref->{$_} }
275
276  }
277  $form->{customer_rows} = $i;
278  delete $form->{customermatrix};
279
280  for (qw(currency partsgroup assemblypartsgroup vendor customer pricegroup IC_inventory IC_income IC_expense)) { $form->{"select$_"} = $form->escape($form->{"select$_"},1) }
281
282}
283
284
285
286sub form_header {
287
288  if ($form->{lastcost} > 0) {
289    $markup = $form->round_amount((($form->{sellprice}/$form->{lastcost} - 1) * 100), 1);
290    $form->{markup} = $form->format_amount(\%myconfig, $markup, 1);
291  }
292
293  ($dec) = ($form->{sellprice} =~ /\.(\d+)/);
294  $dec = length $dec;
295  $form->{decimalplacessell} = ($dec > $form->{precision}) ? $dec : $form->{precision};
296
297  for (qw(listprice sellprice)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $form->{decimalplacessell}) }
298
299  ($dec) = ($form->{lastcost} =~ /\.(\d+)/);
300  $dec = length $dec;
301  $form->{decimalplacescost} = ($dec > $form->{precision}) ? $dec : $form->{precision};
302
303  for (qw(lastcost avgcost)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $form->{decimalplacescost}) }
304
305  for (qw(weight rop onhand)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) }
306
307  for (qw(partnumber description unit notes)) { $form->{$_} = $form->quote($form->{$_}) }
308
309  for (qw(description notes)) {
310    if (($rows = $form->numtextrows($form->{$_}, 40)) < 2) {
311      $rows = 2;
312    }
313
314    $fld{$_} = qq|<textarea name=$_ rows=$rows cols=40 wrap=soft>$form->{$_}</textarea>|;
315  }
316
317  for (split / /, $form->{taxaccounts}) { $form->{"IC_tax_$_"} = ($form->{"IC_tax_$_"}) ? "checked" : "" }
318
319  # set option
320  for (qw(IC_inventory IC_income IC_expense)) {
321    if ($form->{$_}) {
322      if ($form->{changeup}) {
323	$select{$_} = $form->select_option($form->{"select$_"}, $form->{$_});
324      } else {
325	if ($form->{orphaned}) {
326	  $select{$_} = $form->select_option($form->{"select$_"}, $form->{$_});
327	} else {
328	  $select{$_} = qq|<option selected>$form->{$_}|;
329	}
330      }
331    }
332  }
333
334  if ($form->{selectpartsgroup}) {
335    $selectpartsgroup = qq|<select name=partsgroup onChange="javascript:document.main.submit()">|.$form->select_option($form->{selectpartsgroup}, $form->{partsgroup}, 1).qq|</select>
336    <br><input name=partsgroupcode size=10 value="$form->{partsgroupcode}">|;
337    $group = $locale->text('Group');
338  }
339
340  # tax fields
341  foreach $item (split / /, $form->{taxaccounts}) {
342    $tax .= qq|
343      <input class=checkbox type=checkbox name="IC_tax_$item" value=1 $form->{"IC_tax_$item"}>&nbsp;<b>$form->{"IC_tax_${item}_description"}</b>
344      <br>|.$form->hide_form("IC_tax_${item}_description");
345  }
346
347  $reference_documents = &references;
348
349  $sellprice = qq|
350	      <tr>
351		<th align="right" nowrap="true">|.$locale->text('Sell Price').qq|</th>
352		<td><input name=sellprice class="inputright" size=11 value=$form->{sellprice}> <a href=ic.pl?action=history&login=$form->{login}&path=$form->{path}&pickvar=sellprice&id=$form->{id} target=popup>?</a></td>
353	      </tr>
354|;
355
356  $listprice = qq|
357	      <tr>
358		<th align="right" nowrap="true">|.$locale->text('List Price').qq|</th>
359		<td><input name=listprice class="inputright" size=11 value=$form->{listprice}></td>
360	      </tr>
361|;
362
363  $avgcost = qq|
364 	      <tr>
365                <th align="right" nowrap="true">|.$locale->text('Average Cost').qq|</th>
366                <td><input type=hidden name=avgcost value=$form->{avgcost}>$form->{avgcost}</td>
367              </tr>
368|;
369
370  $lastcost = qq|
371 	      <tr>
372                <th align="right" nowrap="true">|.$locale->text('Last Cost').qq|</th>
373                <td><input name=lastcost class="inputright" size=11 value=$form->{lastcost}></td>
374              </tr>
375	      <tr>
376	        <th align="right" nowrap="true">|.$locale->text('Markup').qq| %</th>
377		<td><input name=markup class="inputright" size=5 value=$form->{markup}></td>
378		<input type=hidden name=oldmarkup value=$markup>
379	      </tr>
380|;
381
382  $rop = qq|
383	      <tr>
384		<th align="right" nowrap="true">|.$locale->text('ROP').qq|</th>
385		<td><input name=rop class="inputright" size=8 value=$form->{rop}></td>
386	      </tr>
387|;
388
389  if ($form->{item} =~ /(part|assembly)/) {
390    $onhand = qq|
391	      <tr>
392		<th align="right" nowrap>|.$locale->text('On Hand').qq|</th>
393|;
394
395    if ($form->{admin}) {
396      $onhand .= qq|
397		<td><input name=onhand class="inputright" size=8 value=$form->{onhand}></td>
398|;
399    } else {
400      $onhand .= qq|
401		<td>$form->{onhand}</td>|
402      .$form->hide_form(onhand);
403    }
404
405    $onhand .= qq|
406	      </tr>
407|;
408
409    for $i (1 .. $form->{inventory_rows}) {
410      $onhand .= qq|
411            <tr>
412              <th align=right nowrap>$form->{"warehouse_$i"}</th>
413              <td>$form->{"wonhand_$i"}</td>
414            </tr>|
415      .$form->hide_form("wonhand_$i", "warehouse_$i");
416    }
417
418    $bin = qq|
419	      <tr>
420		<th align="right" nowrap="true">|.$locale->text('Bin').qq|</th>
421		<td><input name=bin size=10 value="|.$form->quote($form->{bin}).qq|"></td>
422	      </tr>
423|;
424
425    $lot = qq|
426	      <tr>
427		<th align="right" nowrap="true">|.$locale->text('Lot').qq|</th>
428		<td><input name=lot size=10 value="|.$form->quote($form->{lot}).qq|"></td>
429	      </tr>
430|;
431
432    $expires = qq|
433	      <tr>
434		<th align="right" nowrap="true">|.$locale->text('Expires').qq|</th>
435		<td><input name=expires size=11 class=date title="$myconfig{dateformat}" value=$form->{expires}>|.&js_calendar("main", "expires").qq|</td>
436	      </tr>
437|;
438
439    $checked{checkinventory} = "checked" if $form->{checkinventory};
440    if ($form->{admin}) {
441      $checkinventory = qq|
442	      <tr>
443		<th align="right" nowrap="true">|.$locale->text('Check Inventory').qq|</th>
444		<td><input name=checkinventory type=checkbox class=checkbox value="1" $checked{checkinventory}></td>
445	      </tr>
446|;
447    } else {
448      $checked{checkinventory} = ($form->{checkinventory}) ? 'x' : '';
449      $checkinventory = qq|
450	      <tr>
451		<th align="right" nowrap="true">|.$locale->text('Check Inventory').qq|</th>
452		<td>&nbsp;$checked{checkinventory}</td>
453	      </tr>
454|.$form->hide_form(checkinventory);
455    }
456  }
457
458  $preview = ($form->{image}) ? " <a href=$images/$myconfig{dbname}/$form->{image}> ?" : qq| <a href="ic.pl?action=upload_image&login=$form->{login}&path=$form->{path}" target=popup>?</a>|;
459
460  $imagelinks = qq|
461  <tr>
462    <td>
463      <table width=100%>
464        <tr>
465	  <th align=right nowrap>|.$locale->text('Image').qq|</th>
466	  <td><input name=image size=40 value="$form->{image}">$preview</td>
467
468	  <th align=right nowrap>|.$locale->text('Country of Origin').qq|</th>
469	  <td><input name=countryorigin size=20 value="$form->{countryorigin}"></td>
470	</tr>
471	<tr>
472	  <th align=right nowrap>|.$locale->text('Drawing').qq|</th>
473	  <td><input name=drawing size=40 value="$form->{drawing}"></td>
474
475	  <th align=right nowrap>|.$locale->text('HS Code').qq|</th>
476	  <td><input name=tariff_hscode size=20 value="$form->{tariff_hscode}"></td>
477        </tr>
478	<tr>
479	  <th align=right nowrap>|.$locale->text('Microfiche').qq|</th>
480	  <td><input name=microfiche size=20 value="$form->{microfiche}"></td>
481	  <th align=right nowrap>|.$locale->text('Barcode').qq|</th>
482	  <td><input name=barcode size=30 value="$form->{barcode}"></td>
483	</tr>
484	<tr>
485	  <th align=right nowrap>|.$locale->text('Tool Number').qq|</th>
486	  <td><input name=toolnumber size=20 value="$form->{toolnumber}"></td>
487	</tr>
488      </table>
489    </td>
490  </tr>
491|;
492
493
494  if ($form->{item} eq "part") {
495
496    $linkaccounts = qq|
497	      <tr>
498		<th align=right>|.$locale->text('Inventory').qq|</th>
499		<td><select name=IC_inventory>$select{IC_inventory}</select></td>
500	      </tr>
501	      <tr>
502		<th align=right>|.$locale->text('Income').qq|</th>
503		<td><select name=IC_income>$select{IC_income}</select></td>
504	      </tr>
505	      <tr>
506		<th align=right>|.$locale->text('COGS').qq|</th>
507		<td><select name=IC_expense>$select{IC_expense}</select></td>
508	      </tr>
509|;
510
511    if ($tax) {
512      $linkaccounts .= qq|
513	      <tr>
514		<th align=right>|.$locale->text('Tax').qq|</th>
515		<td>$tax</td>
516	      </tr>
517|;
518    }
519
520    $weight = qq|
521	      <tr>
522		<th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
523		<td>
524		  <table>
525		    <tr>
526		      <td>
527			<input name=weight class="inputright" size=11 value=$form->{weight}>
528		      </td>
529		      <th>
530			&nbsp;
531			$form->{weightunit}|
532			.$form->hide_form(qw(weightunit))
533			.qq|
534		      </th>
535		    </tr>
536		  </table>
537		</td>
538	      </tr>
539|;
540
541  }
542
543
544  if ($form->{item} =~ /(assembly|kit)/) {
545
546    $avgcost = "";
547
548    if ($form->{project_id}) {
549      $weight = qq|
550	      <tr>
551		<th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
552		<td>
553		  <table>
554		    <tr>
555		      <td>
556			<input name=weight class="inputright" size=11 value=$form->{weight}>
557		      </td>
558		      <th>
559			&nbsp;
560			$form->{weightunit}|
561			.$form->hide_form(qw(weightunit))
562			.qq|
563		      </th>
564		    </tr>
565		  </table>
566		</td>
567	      </tr>
568|;
569    } else {
570
571      $weight = qq|
572	      <tr>
573		<th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
574		<td>
575		  <table>
576		    <tr>
577		      <td>
578			&nbsp;$form->{weight}
579			<input type=hidden name=weight value=$form->{weight}>
580		      </td>
581		      <th>
582			&nbsp;
583			$form->{weightunit}|
584			.$form->hide_form(qw(weightunit))
585			.qq|
586		      </th>
587		    </tr>
588		  </table>
589		</td>
590	      </tr>
591|;
592    }
593
594    if ($form->{project_id}) {
595
596      $lastcost = qq|
597 	      <tr>
598                <th align="right" nowrap="true">|.$locale->text('Last Cost').qq|</th>
599                <td>$form->{lastcost}</td>
600		<input type=hidden name=lastcost value=$form->{lastcost}>
601              </tr>
602|;
603
604      $avgcost = "";
605      $rop = "";
606
607    } else {
608      $lastcost = qq|
609              <tr>
610	        <th align="right" nowrap="true">|.$locale->text('Last Cost').qq|</th>
611		<td><input type=hidden name=lastcost value=$form->{lastcost}>$form->{lastcost}</td>
612	      </tr>
613	      <tr>
614	        <th align="right" nowrap="true">|.$locale->text('Markup').qq| %</th>
615		<td><input name=markup class="inputright" size=5 value=$form->{markup}></td>
616		<input type=hidden name=oldmarkup value=$markup>
617	      </tr>
618|;
619
620    }
621
622    if ($form->{item} eq 'assembly') {
623      $linkaccounts = qq|
624	      <tr>
625		<th align=right>|.$locale->text('Income').qq|</th>
626		<td><select name=IC_income>$select{IC_income}</select></td>
627	      </tr>
628|;
629
630      if ($tax) {
631        $linkaccounts .= qq|
632	      <tr>
633		<th align=right>|.$locale->text('Tax').qq|</th>
634		<td>$tax</td>
635	      </tr>
636|;
637      }
638    }
639
640  }
641
642
643  if ($form->{item} eq "service") {
644    $avgcost = "";
645    $rop = "";
646    $linkaccounts = qq|
647	      <tr>
648		<th align=right>|.$locale->text('Income').qq|</th>
649		<td><select name=IC_income>$select{IC_income}</select></td>
650	      </tr>
651	      <tr>
652		<th align=right>|.$locale->text('Expense').qq|</th>
653		<td><select name=IC_expense>$select{IC_expense}</select></td>
654	      </tr>
655|;
656
657    if ($tax) {
658      $linkaccounts .= qq|
659	      <tr>
660		<th align=right>|.$locale->text('Tax').qq|</th>
661		<td>$tax</td>
662	      </tr>
663|;
664    }
665
666  }
667
668  if ($form->{item} eq 'labor') {
669    $avgcost = "";
670    $rop = "";
671
672    $lastcost = "";
673    $listprice = "";
674    $imagelinks = "";
675
676    $linkaccounts = qq|
677	      <tr>
678		<th align=right>|.$locale->text('Labor/Overhead').qq|</th>
679		<td><select name=IC_inventory>$select{IC_inventory}</select></td>
680	      </tr>
681
682	      <tr>
683		<th align=right>|.$locale->text('COGS').qq|</th>
684		<td><select name=IC_expense>$select{IC_expense}</select></td>
685	      </tr>
686|;
687
688  }
689
690  if ($form->{id}) {
691    $checked = ($form->{obsolete}) ? "checked" : "";
692    $obsolete = qq|
693	      <tr>
694		<th align="right" nowrap="true">|.$locale->text('Obsolete').qq|</th>
695		<td><input name=obsolete type=checkbox class=checkbox value=1 $checked></td>
696	      </tr>
697|;
698    $obsolete = "<input type=hidden name=obsolete value=$form->{obsolete}>" if $form->{project_id};
699  }
700
701  $s = length $form->{partnumber};
702  $s = ($s > 20) ? $s : 20;
703  $fld{partnumber} = qq|<input name=partnumber value="|.$form->quote($form->{partnumber}).qq|" size=$s>|;
704
705  $linkaccounts = qq|$linkaccounts
706              <tr class="listheading">
707                <th class="listheading" align="center" colspan=2>|.$locale->text('Link Accounts').qq|</th>
708              </tr>
709| if $linkaccounts;
710
711  $form->header;
712
713  &calendar;
714
715  print qq|
716<body>
717
718<form method="post" name="main" action="$form->{script}">
719|;
720
721  $form->hide_form(qw(id item title makemodel alternate oldonhand orphaned taxaccounts rowcount project_id precision changeup oldpartsgroup oldpartsgroupcode helpref reference_rows referenceurl));
722
723  print qq|
724<input type=hidden name=action value="update">
725
726<table width="100%">
727  <tr>
728    <th class=listtop>$form->{helpref}$form->{title}</a></th>
729  </tr>
730  <tr height="5"></tr>
731  <tr>
732    <td>
733      <table width="100%">
734        <tr valign=top>
735          <th align=left width=20%>|.$locale->text('Number').qq|</th>
736          <th align=left width=50%>|.$locale->text('Description').qq|</th>
737	  <th align=left width=30%>$group</th>
738	</tr>
739	<tr valign=top>
740	  <td>$fld{partnumber}</td>
741          <td>$fld{description}</td>
742	  <td>$selectpartsgroup</td>
743	</tr>
744      </table>
745    </td>
746  </tr>
747  <tr>
748    <td>
749      <table width="100%" height="100%">
750        <tr valign=top>
751          <td width=70%>
752            <table width="100%" height="100%">
753              $linkaccounts
754	      <tr>
755	        <td colspan=2>
756		  $reference_documents
757		</td>
758	      </tr>
759              <tr>
760                <th align="left">|.$locale->text('Notes').qq|</th>
761              </tr>
762              <tr>
763                <td colspan=2>
764                  $fld{notes}
765                </td>
766              </tr>
767            </table>
768          </td>
769	  <td width="30%">
770	    <table width="100%">
771	      <tr>
772		<th align="right" nowrap="true">|.$locale->text('Updated').qq|</th>
773		<td><input name=priceupdate size=11 class=date title="$myconfig{dateformat}" value=$form->{priceupdate}>|.&js_calendar("main", "priceupdate").qq|</td>
774	      </tr>
775              $lot
776              $expires
777	      $sellprice
778              $listprice
779	      $lastcost
780	      $avgcost
781	      <tr>
782		<th align="right" nowrap="true">|.$locale->text('Unit').qq|</th>
783		<td><input name=unit size=5 value="|.$form->quote($form->{unit}).qq|"></td>
784	      </tr>
785	      $weight
786	      $onhand
787              $checkinventory
788	      $rop
789	      $bin
790	      $obsolete
791	    </table>
792	  </td>
793	</tr>
794      </table>
795    </td>
796  </tr>
797  $imagelinks
798|;
799
800  $form->hide_form(map { "select$_" } qw(currency partsgroup assemblypartsgroup vendor customer pricegroup IC_inventory IC_income IC_expense));
801
802}
803
804
805sub form_footer {
806
807  if (! $form->{project_id}) {
808    if ($form->{item} =~ /(assembly|kit)/) {
809      &assembly_row(++$form->{assembly_rows});
810    }
811  }
812
813  print qq|
814  <tr>
815    <td><hr size=3 noshade></td>
816  </tr>
817</table>
818|;
819
820  $form->hide_form(map { "${_}_rows" } qw(customer vendor makemodel inventory));
821
822  if (! $form->{readonly}) {
823
824    %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
825               'Save' => { ndx => 2, key => 'S', value => $locale->text('Save') },
826	       'New Number' => { ndx => 15, key => 'M', value => $locale->text('New Number') },
827	      );
828
829    if ($form->{id}) {
830
831      if (! ($form->{changeup} || $form->{project_id})) {
832	$button{'Save as new'} = { ndx => 7, key => 'N', value => $locale->text('Save as new') };
833      }
834
835      if ($form->{orphaned}) {
836	$button{'Delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') };
837      }
838    }
839
840    $form->print_button(\%button);
841
842  }
843
844  if ($form->{menubar}) {
845    require "$form->{path}/menu.pl";
846    &menubar;
847  }
848
849  $form->hide_form(qw(login path callback previousform));
850
851  print qq|
852</form>
853
854</body>
855</html>
856|;
857
858}
859
860
861sub search {
862
863  IC->get_warehouses(\%myconfig, \%$form);
864
865  if (@{ $form->{all_partsgroup} }) {
866    $partsgroup = qq|<option>\n|;
867
868    for (@{ $form->{all_partsgroup} }) { $partsgroup .= qq|<option value="|.$form->quote($_->{partsgroup}).qq|--$_->{id}">$_->{partsgroup}\n| }
869
870    $partsgroup = qq|
871        <th align=right nowrap>|.$locale->text('Group').qq|</th>
872	<td><select name=partsgroup>$partsgroup</select></td>
873|;
874
875    $l{partsgroup} = qq|<input name=l_partsgroup class=checkbox type=checkbox value=Y> |.$locale->text('Group');
876    $l{partsgroupcode} = qq|<input name=l_partsgroupcode class=checkbox type=checkbox value=Y> |.$locale->text('Group Code');
877  }
878
879
880  if (@{ $form->{all_years} }) {
881    # accounting years
882    $selectaccountingyear = "\n";
883    for (@{ $form->{all_years} }) { $selectaccountingyear .= qq|$_\n| }
884    $selectaccountingmonth = "\n";
885    for (sort keys %{ $form->{all_month} }) { $selectaccountingmonth .= qq|$_--| . $locale->text($form->{all_month}{$_}).qq|\n| }
886
887    $form->{interval} = "1" unless exists $form->{interval};
888    $checked{"$form->{interval}"} = "checked";
889
890    $selectfrom = qq|
891        <tr>
892          <td>
893            <table>
894              <tr>
895                <th align=right>|.$locale->text('Period').qq|</th>
896                <td>
897                <select name=month>|.$form->select_option($selectaccountingmonth, $form->{month}, 1, 1).qq|</select>
898                <select name=year>|.$form->select_option($selectaccountingyear, $form->{year}).qq|</select>
899                <input name=interval class=radio type=radio value=0 $checked{0}>&nbsp;|.$locale->text('Current').qq|
900                <input name=interval class=radio type=radio value=1 $checked{1}>&nbsp;|.$locale->text('Month').qq|
901                <input name=interval class=radio type=radio value=3 $checked{3}>&nbsp;|.$locale->text('Quarter').qq|
902                <input name=interval class=radio type=radio value=12 $checked{12}>&nbsp;|.$locale->text('Year').qq|
903                </td>
904              </tr>
905            </table>
906          </td>
907	</tr>
908|;
909  }
910
911  $method{accrual} = "checked" if $form->{method} eq 'accrual';
912  $method{cash} = "checked" if $form->{method} eq 'cash';
913
914  $l{listprice} = qq|<input name=l_listprice class=checkbox type=checkbox value=Y> |.$locale->text('List Price');
915  $l{sellprice} = qq|<input name=l_sellprice class=checkbox type=checkbox value=Y checked> |.$locale->text('Sell Price');
916  $l{linetotal} = qq|<input name=l_linetotal class=checkbox type=checkbox value=Y> |.$locale->text('Extended');
917  $l{lastcost} = qq|<input name=l_lastcost class=checkbox type=checkbox value=Y checked> |.$locale->text('Last Cost');
918  $l{avgcost} = qq|<input name=l_avgcost class=checkbox type=checkbox value=Y> |.$locale->text('Average Cost');
919  $l{markup} = qq|<input name=l_markup class=checkbox type=checkbox value=Y> |.$locale->text('Markup');
920  $l{account} = qq|<input name=l_account class=checkbox type=checkbox value=Y> |.$locale->text('Accounts');
921  $l{qty} = qq|<input name=l_qty class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Qty');
922
923  $bought = qq|
924          <td>
925	    <table>
926	      <tr>
927		<td><input name=bought class=checkbox type=checkbox value=1></td>
928		<td nowrap>|.$locale->text('Vendor Invoices').qq|</td>
929	      </tr>
930	      <tr>
931		<td><input name=onorder class=checkbox type=checkbox value=1></td>
932		<td nowrap>|.$locale->text('Purchase Orders').qq|</td>
933	      </tr>
934	      <tr>
935		<td><input name=rfq class=checkbox type=checkbox value=1></td>
936		<td nowrap>|.$locale->text('RFQ').qq|</td>
937	      </tr>
938	    </table>
939	  </td>
940|;
941
942  $sold = qq|
943	  <td>
944	    <table>
945	      <tr>
946		<td><input name=sold class=checkbox type=checkbox value=1></td>
947		<td nowrap>|.$locale->text('Sales Invoices').qq|</td>
948	      </tr>
949	      <tr>
950		<td><input name=ordered class=checkbox type=checkbox value=1></td>
951		<td nowrap>|.$locale->text('Sales Orders').qq|</td>
952	      </tr>
953	      <tr>
954		<td><input name=quoted class=checkbox type=checkbox value=1></td>
955		<td nowrap>|.$locale->text('Quotations').qq|</td>
956	      </tr>
957	    </table>
958	  </td>
959|;
960
961  $fromto = qq|
962	  <td>
963	    <table>
964	      <tr>
965		<td nowrap><b>|.$locale->text('From').qq|</b> <input name=transdatefrom size=11 class=date title="$myconfig{dateformat}">|.&js_calendar("main", "transdatefrom").qq|<b>|.$locale->text('To').qq|</b> <input name=transdateto size=11 class=date title="$myconfig{dateformat}">|.&js_calendar("main", "transdateto").qq|</td>
966	      </tr>
967              $selectfrom
968	      <tr>
969		<td nowrap><input name=method class=radio type=radio value=accrual $method{accrual}>|.$locale->text('Accrual').qq|
970		<input name=method class=radio type=radio value=cash $method{cash}>|.$locale->text('Cash').qq|</td>
971	      </tr>
972	      <tr>
973		<td nowrap>
974		<input name=open class=checkbox type=checkbox value=1 checked> |.$locale->text('Open').qq|
975		<input name=closed class=checkbox type=checkbox> |.$locale->text('Closed').qq|
976		<input name=summary type=radio class=radio value=1> |.$locale->text('Summary').qq|
977		<input name=summary type=radio class=radio value=0 checked> |.$locale->text('Detail').qq|
978		</td>
979	      </tr>
980	    </table>
981	  </td>
982|;
983
984  $l{name} = qq|<input name=l_name class=checkbox type=checkbox value=Y> |.$locale->text('Name');
985  $l{curr} = qq|<input name=l_curr class=checkbox type=checkbox value=Y> |.$locale->text('Currency');
986  $l{employee} = qq|<input name=l_employee class=checkbox type=checkbox value=Y> |.$locale->text('Employee');
987  $l{serialnumber} = qq|<input name=l_serialnumber class=checkbox type=checkbox value=Y> |.$locale->text('Serial Number');
988
989  $serialnumber = qq|
990          <th align=right nowrap>|.$locale->text('Serial Number').qq|</th>
991          <td><input name=serialnumber size=20></td>
992|;
993
994  $orphaned = qq|
995            <input name=itemstatus class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned');
996
997  $stocklevel = qq|
998            <input name=itemstatus class=radio type=radio value=stocklevel>&nbsp;|.$locale->text('Stock level') if $form->{searchitems} eq 'part';
999
1000  if ($form->{searchitems} =~ /(all|part|assembly|kit)/) {
1001
1002    $onhand = qq|
1003            <input name=itemstatus class=radio type=radio value=onhand>&nbsp;|.$locale->text('On Hand').qq|
1004            <input name=itemstatus class=radio type=radio value=short>&nbsp;|.$locale->text('Short').qq|
1005|;
1006
1007    $makemodel = qq|
1008        <tr>
1009          <th align=right nowrap>|.$locale->text('Make').qq|</th>
1010          <td><input name=make size=20></td>
1011          <th align=right nowrap>|.$locale->text('Model').qq|</th>
1012          <td><input name=model size=20></td>
1013        </tr>
1014|;
1015
1016    $l{make} = qq|<input name=l_make class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Make');
1017    $l{model} = qq|<input name=l_model class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Model');
1018
1019    $l{bin} = qq|<input name=l_bin class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Bin');
1020
1021    $l{rop} = qq|<input name=l_rop class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('ROP');
1022
1023    $l{weight} = qq|<input name=l_weight class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Weight');
1024
1025    $l{countryorigin} = qq|<input name=l_countryorigin class=checkbox type=checkbox value=Y> |.$locale->text('Country of Origin');
1026    $l{tariff_hscode} = qq|<input name=l_tariff_hscode class=checkbox type=checkbox value=Y> |.$locale->text('HS Code');
1027
1028    if (@{ $form->{all_warehouse} }) {
1029      $selectwarehouse = "\n";
1030
1031      for (@{ $form->{all_warehouse} }) { $selectwarehouse .= qq|$_->{description}--$_->{id}\n| }
1032
1033      $warehouse = qq|
1034          <th align=right nowrap>|.$locale->text('Warehouse').qq|</th>
1035          <td><select name=warehouse>|
1036          .$form->select_option($selectwarehouse, undef, 1)
1037          .qq|</select>
1038          </td>
1039|;
1040
1041      $l{warehouse} = qq|<input name=l_warehouse class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Warehouse');
1042
1043    }
1044
1045    $drawing = qq|
1046        <tr>
1047          <th align=right nowrap>|.$locale->text('Drawing').qq|</th>
1048          <td><input name=drawing size=20></td>
1049	  <th align=right nowrap>|.$locale->text('Tool Number').qq|</th>
1050	  <td><input name=toolnumber size=20></td>
1051        </tr>
1052        <tr>
1053          <th align=right nowrap>|.$locale->text('Microfiche').qq|</th>
1054          <td><input name=microfiche size=20></td>
1055          <th align=right nowrap>|.$locale->text('Barcode').qq|</th>
1056          <td><input name=barcode size=30></td>
1057        </tr>
1058|;
1059
1060    $l{toolnumber} = qq|<input name=l_toolnumber class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Tool Number');
1061
1062    $l{barcode} = qq|<input name=l_barcode class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Barcode');
1063
1064    $l{image} = qq|<input name=l_image class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Image');
1065
1066    $l{drawing} = qq|<input name=l_drawing class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Drawing');
1067    $l{microfiche} = qq|<input name=l_microfiche class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Microfiche');
1068
1069    $l{cost} = qq|<input name=l_cost class=checkbox type=checkbox value=Y> |.$locale->text('Cost');
1070
1071    $l{lot} = qq|<input name=l_lot class=checkbox type=checkbox value=Y> |.$locale->text('Lot');
1072
1073    $lot = qq|
1074          <th align=right nowrap>|.$locale->text('Lot').qq|</th>
1075          <td><input name=lot size=20></td>
1076|;
1077
1078    $l{expires} = qq|<input name=l_expires class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Expires');
1079    $l{checkinventory} = qq|<input name=l_checkinventory class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Check Inventory');
1080
1081  }
1082
1083  if ($form->{searchitems} =~ /(assembly|kit)/) {
1084
1085    $bought = "<td></td>";
1086
1087    $toplevel = qq|
1088        <tr>
1089	  <td></td>
1090          <td colspan=3>
1091	  <input name=null class=radio type=radio checked>&nbsp;|.$locale->text('Top Level').qq|
1092	  <input name=individual class=checkbox type=checkbox value=1>&nbsp;|.$locale->text('Individual Items').qq|
1093          </td>
1094        </tr>
1095|;
1096    $bom = qq|<input name=itemstatus type=radio value=bom>&nbsp;|.$locale->text('BOM');
1097
1098    if ($form->{searchitems} eq 'kit') {
1099      $onhand = "";
1100      $lot = "";
1101      $l{lot} = "";
1102      $l{expires} = "";
1103      $l{checkinventory} = "";
1104    }
1105
1106    if ($form->{changeup}) {
1107
1108      $sold = "";
1109      $fromto = "";
1110      delete $l{name};
1111
1112    }
1113
1114  }
1115
1116  if ($form->{searchitems} eq 'component') {
1117
1118    $bought = "";
1119    $sold = "";
1120    $fromto = "";
1121
1122    for (qw(name curr employee serialnumber warehouse account lot expires checkinventory)) { delete $l{$_} }
1123    $warehouse = "";
1124    $serialnumber = "";
1125    $orphaned = "";
1126    $lot = "";
1127
1128  }
1129
1130  if ($form->{searchitems} eq 'labor') {
1131
1132    $sold = "";
1133    $warehouse = "";
1134    $serialnumber = "";
1135    $lot = "";
1136
1137    for (qw(serialnumber markup qty listprice lastcost avgcost cost lot expires checkinventory)) { delete $l{$_} }
1138
1139  }
1140
1141  @f = ();
1142  push @f, qq|<input name=l_runningnumber class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('No.');
1143  push @f, qq|<input name=l_id class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('ID');
1144  push @f, qq|<input name=l_partnumber class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Number');
1145  push @f, qq|<input name=l_description class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Description');
1146  push @f, $l{qty} if $l{qty};
1147  push @f, qq|<input name=l_unit class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Unit');
1148  push @f, qq|<input name=l_priceupdate class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Updated');
1149
1150  for (qw(lot expires checkinventory partsgroup partsgroupcode cost sellprice listprice lastcost avgcost linetotal markup bin rop weight)) {
1151    push @f, $l{$_} if $l{$_};
1152  }
1153
1154  push @f, qq|<input name=l_notes class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Notes');
1155
1156  for (qw(image drawing toolnumber microfiche make model warehouse account name transdate curr employee serialnumber countryorigin tariff_hscode barcode)) {
1157    push @f, $l{$_} if $l{$_};
1158  }
1159
1160
1161  %title = ( all	=> 'Items',
1162             part	=> 'Parts',
1163	     labor	=> 'Labor/Overhead',
1164	     service	=> 'Services',
1165	     assembly	=> 'Assemblies',
1166             kit        => 'Kits',
1167	     component	=> 'Components'
1168	   );
1169
1170# $locale->text('Items')
1171# $locale->text('Parts')
1172# $locale->text('Labor/Overhead')
1173# $locale->text('Services')
1174# $locale->text('Assemblies')
1175# $locale->text('Kits')
1176# $locale->text('Components')
1177# $locale->text('Barcodes')
1178# $locale->text('Changeup Parts')
1179# $locale->text('Changeup Labor/Overhead')
1180# $locale->text('Changeup Services')
1181# $locale->text('Changeup Assemblies')
1182
1183  if ($form->{changeup}) {
1184    $form->helpref("changeup_items", $myconfig{countrycode});
1185    $form->{title} = $locale->text('Changeup' . ' ' .$title{$form->{searchitems}});
1186  } else {
1187    $form->helpref("search_items", $myconfig{countrycode});
1188    $form->{title} = $locale->text($title{$form->{searchitems}});
1189  }
1190
1191  $form->header;
1192
1193  &calendar;
1194
1195  print qq|
1196<body onLoad="document.main.partnumber.focus()" />
1197
1198<form method="post" name="main" action="$form->{script}">
1199|;
1200
1201  $form->hide_form(qw(changeup searchitems title));
1202
1203  print qq|
1204
1205<table width="100%">
1206  <tr><th class=listtop>$form->{helpref}$form->{title}</a></th></tr>
1207  <tr height="5"></tr>
1208  <tr valign=top>
1209    <td>
1210      <table>
1211        <tr>
1212          <th align=right nowrap>|.$locale->text('Number').qq|</th>
1213          <td><input name=partnumber size=20></td>
1214        </tr>
1215        <tr>
1216          <th align=right nowrap>|.$locale->text('Description').qq|</th>
1217          <td colspan=3><input name=description size=40></td>
1218        </tr>
1219	<tr>
1220	  $warehouse
1221          $lot
1222	</tr>
1223	<tr>
1224	  $partsgroup
1225	  $serialnumber
1226	</tr>
1227	$makemodel
1228	$drawing
1229	$toplevel
1230        <tr>
1231          <td></td>
1232          <td colspan=3>
1233            <input name=itemstatus class=radio type=radio value=active checked>&nbsp;|.$locale->text('Active').qq|
1234	    $onhand
1235            <input name=itemstatus class=radio type=radio value=obsolete>&nbsp;|.$locale->text('Obsolete').qq|
1236	    $orphaned
1237            $stocklevel
1238	    $bom
1239	  </td>
1240	</tr>
1241        <tr>
1242	  <td></td>
1243          <td colspan=3>
1244	    <hr size=1 noshade>
1245	  </td>
1246	</tr>
1247	<tr>
1248	  <td></td>
1249	  $sold
1250	  $bought
1251	  $fromto
1252        </tr>
1253	<tr>
1254	  <td></td>
1255          <td colspan=3>
1256	    <hr size=1 noshade>
1257	  </td>
1258	</tr>
1259	<tr>
1260          <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
1261          <td colspan=3>
1262            <table>
1263              <tr>
1264|;
1265
1266  while (@f) {
1267    print qq|<tr>\n|;
1268    for (1 .. 5) {
1269      print qq|<td nowrap>|. shift @f;
1270      print qq|</td>\n|;
1271    }
1272    print qq|</tr>\n|;
1273  }
1274
1275  print qq|
1276              </tr>
1277	      <tr>
1278                <td><input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|</td>
1279	      </tr>
1280            </table>
1281          </td>
1282        </tr>
1283      </table>
1284    </td>
1285  </tr>
1286  <tr><td colspan=4><hr size=3 noshade></td></tr>
1287</table>
1288
1289<input type=hidden name=nextsub value=generate_report>
1290
1291<br>
1292<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
1293|;
1294
1295  $form->hide_form(qw(path login));
1296
1297  print qq|
1298</form>
1299|;
1300
1301  if ($form->{menubar}) {
1302    require "$form->{path}/menu.pl";
1303    &menubar;
1304  }
1305
1306  print qq|
1307
1308</body>
1309</html>
1310|;
1311
1312}
1313
1314
1315
1316sub generate_report {
1317
1318  unless ($form->{sort}) {
1319    if ($form->{description} && !($form->{partnumber})) {
1320      $form->{sort} = "description";
1321    } else {
1322      $form->{sort} = "partnumber";
1323    }
1324  }
1325
1326  if ($form->{itemstatus} eq 'bom') {
1327    $form->{l_perassembly} = "Y" if $form->{l_qty} eq "Y";
1328    $form->{individual} = 1;
1329    $form->{title} = $locale->text('BOM');
1330  }
1331
1332  $callback = "$form->{script}?action=generate_report";
1333  for (qw(path login searchitems changeup itemstatus individual bom l_linetotal method)) { $callback .= qq|&$_=$form->{$_}| }
1334  for (qw(warehouse partsgroup title)) { $callback .= qq|&$_=|.$form->escape($form->{$_},1) }
1335
1336  # if we have a serialnumber limit search
1337  if ($form->{serialnumber} || $form->{l_serialnumber}) {
1338    $form->{l_serialnumber} = "Y";
1339    unless ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered}) {
1340      if ($form->{searchitems} eq 'assembly') {
1341        $form->{sold} = $form->{ordered} = 1;
1342      } else {
1343        $form->{bought} = $form->{sold} = $form->{onorder} = $form->{ordered} = 1;
1344      }
1345    }
1346  }
1347
1348  if ($form->{itemstatus} eq 'active') {
1349    $form->{option} .= $locale->text('Active')." : ";
1350  }
1351  if ($form->{itemstatus} eq 'obsolete') {
1352    $form->{option} .= $locale->text('Obsolete')." : ";
1353  }
1354  if ($form->{itemstatus} eq 'orphaned') {
1355    $form->{onhand} = $form->{short} = 0;
1356    $form->{bought} = $form->{sold} = 0;
1357    $form->{onorder} = $form->{ordered} = 0;
1358    $form->{rfq} = $form->{quoted} = 0;
1359
1360    $form->{l_qty} = 0;
1361    $form->{warehouse} = "";
1362    $form->{l_warehouse} = 0;
1363
1364    $form->{transdatefrom} = $form->{transdateto} = "";
1365
1366    $form->{option} .= $locale->text('Orphaned')." : ";
1367  }
1368  if ($form->{itemstatus} eq 'onhand') {
1369    $form->{option} .= $locale->text('On Hand')." : ";
1370    $form->{l_onhand} = "Y";
1371  }
1372  if ($form->{itemstatus} eq 'short') {
1373    $form->{option} .= $locale->text('Short')." : ";
1374    $form->{l_onhand} = "Y";
1375    $form->{l_rop} = "Y" unless $form->{searchitems} eq 'labor';
1376
1377    $form->{warehouse} = "";
1378    $form->{l_warehouse} = 0;
1379  }
1380
1381  if ($form->{itemstatus} eq 'stocklevel') {
1382    $form->{option} .= $locale->text('Stock level')." : ";
1383    $form->{l_onhand} = "Y";
1384    for (qw(onhand short onorder ordered rfq quoted)) { $form->{$_} = 0 }
1385    for (qw(bought sold open closed)) { $form->{$_} = 1 }
1386  }
1387
1388  if ($form->{l_account}) {
1389    for (qw(l_name l_curr l_employee)) { delete $form->{$_} }
1390  } else {
1391    $ok = 0;
1392    for $l (qw(l_name l_curr l_employee)) {
1393      if ($form->{$l}) {
1394	for $v (qw(onorder ordered rfq quoted bought sold)) {
1395	  if ($form->{$v}) {
1396	    $ok = 1;
1397	    last;
1398	  }
1399	}
1400	if (!$ok) {
1401	  for (qw(onorder ordered rfq quoted bought sold)) { $form->{$_} = 1 }
1402	}
1403	last;
1404      }
1405    }
1406  }
1407
1408  if ($form->{l_cost}) {
1409    for (qw(onorder ordered rfq quoted sold)) { $form->{$_} = "" }
1410    $form->{option} .= $locale->text('Inventory Value')." : ";
1411    for (qw(bought open closed)) { $form->{$_} = 1 }
1412    $form->{method} = "accrual";
1413  }
1414
1415  if ($form->{onorder}) {
1416    $form->{l_ordnumber} = "Y";
1417    $callback .= "&onorder=$form->{onorder}";
1418    $form->{option} .= $locale->text('Purchase Order')." : ";
1419  }
1420  if ($form->{ordered}) {
1421    $form->{l_ordnumber} = "Y";
1422    $callback .= "&ordered=$form->{ordered}";
1423    $form->{option} .= $locale->text('Sales Order')." : ";
1424  }
1425  if ($form->{rfq}) {
1426    $form->{l_quonumber} = "Y";
1427    $callback .= "&rfq=$form->{rfq}";
1428    $form->{option} .= $locale->text('RFQ')." : ";
1429  }
1430  if ($form->{quoted}) {
1431    $form->{l_quonumber} = "Y";
1432    $callback .= "&quoted=$form->{quoted}";
1433    $form->{option} .= $locale->text('Quotation')." : ";
1434  }
1435  if ($form->{bought}) {
1436    $form->{l_invnumber} = "Y";
1437    $callback .= "&bought=$form->{bought}";
1438    $form->{option} .= $locale->text('Vendor Invoice')." : ";
1439  }
1440  if ($form->{sold}) {
1441    $form->{l_invnumber} = "Y";
1442    $callback .= "&sold=$form->{sold}";
1443    $form->{option} .= $locale->text('Sales Invoice')." : ";
1444  }
1445  if ($form->{sold} || $form->{bought}) {
1446    $label = ucfirst $form->{method};
1447    $form->{option} .= $locale->text($label) ." : ";
1448  }
1449
1450  if ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered} || $form->{rfq} || $form->{quoted}) {
1451
1452    # warehouse stuff is meaningless
1453    $form->{warehouse} = "";
1454    $form->{l_warehouse} = 0;
1455
1456    $form->{l_account} = "";
1457
1458    if ($form->{open}) {
1459      $callback .= "&open=$form->{open}";
1460      $form->{option} .= $locale->text('Open');
1461    }
1462    if ($form->{closed}) {
1463      $callback .= "&closed=$form->{closed}";
1464      if ($form->{open}) {
1465	$form->{option} .= " : ".$locale->text('Closed');
1466      } else {
1467	$form->{option} .= $locale->text('Closed');
1468      }
1469    }
1470    if ($form->{summary}) {
1471      $callback .= "&summary=$form->{summary}";
1472      $form->{option} .= " : ".$locale->text('Summary');
1473      $form->{l_ordnumber} = "";
1474      $form->{l_quonumber} = "";
1475      $form->{l_invnumber} = "";
1476      $form->{l_transdate} = "";
1477    } else {
1478      $form->{option} .= " : ".$locale->text('Detail');
1479      $form->{l_transdate} = "Y";
1480    }
1481
1482    if ($form->{year} && $form->{month}) {
1483      ($form->{transdatefrom}, $form->{transdateto}) = $form->from_to($form->{year}, $form->{month}, $form->{interval});
1484    }
1485
1486    if ($form->{transdatefrom}) {
1487      $callback .= "&transdatefrom=$form->{transdatefrom}";
1488      $form->{option} .= "\n<br>".$locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
1489    }
1490    if ($form->{transdateto}) {
1491      $callback .= "&transdateto=$form->{transdateto}";
1492      $form->{option} .= "\n<br>".$locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 1);
1493    }
1494  }
1495
1496  if ($form->{warehouse}) {
1497    ($warehouse) = split /--/, $form->{warehouse};
1498    $form->{option} .= "<br>".$locale->text('Warehouse')." : $warehouse";
1499    $form->{l_warehouse} = 0;
1500  }
1501
1502  $form->{option} .= "<br>";
1503
1504  if ($form->{partnumber} ne "") {
1505    $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
1506    $form->{option} .= $locale->text('Number').qq| : $form->{partnumber}<br>|;
1507  }
1508  if ($form->{partsgroup}) {
1509    ($partsgroup) = split /--/, $form->{partsgroup};
1510    $form->{option} .= $locale->text('Group').qq| : $partsgroup<br>|;
1511  }
1512  if ($form->{serialnumber} ne "") {
1513    $callback .= "&serialnumber=".$form->escape($form->{serialnumber},1);
1514    $form->{option} .= $locale->text('Serial Number').qq| : $form->{serialnumber}<br>|;
1515  }
1516  if ($form->{description} ne "") {
1517    $callback .= "&description=".$form->escape($form->{description},1);
1518    $description = $form->{description};
1519    $description =~ s/\r?\n/<br>/g;
1520    $form->{option} .= $locale->text('Description').qq| : $form->{description}<br>|;
1521  }
1522  if ($form->{make} ne "") {
1523    $callback .= "&make=".$form->escape($form->{make},1);
1524    $form->{option} .= $locale->text('Make').qq| : $form->{make}<br>|;
1525  }
1526  if ($form->{model} ne "") {
1527    $callback .= "&model=".$form->escape($form->{model},1);
1528    $form->{option} .= $locale->text('Model').qq| : $form->{model}<br>|;
1529  }
1530  if ($form->{drawing} ne "") {
1531    $callback .= "&drawing=".$form->escape($form->{drawing},1);
1532    $form->{option} .= $locale->text('Drawing').qq| : $form->{drawing}<br>|;
1533  }
1534  if ($form->{toolnumber} ne "") {
1535    $callback .= "&toolnumber=".$form->escape($form->{toolnumber},1);
1536    $form->{option} .= $locale->text('Tool Number').qq| : $form->{toolnumber}<br>|;
1537  }
1538  if ($form->{microfiche} ne "") {
1539    $callback .= "&microfiche=".$form->escape($form->{microfiche},1);
1540    $form->{option} .= $locale->text('Microfiche').qq| : $form->{microfiche}<br>|;
1541  }
1542  if ($form->{barcode} ne "") {
1543    $callback .= "&barcode=".$form->escape($form->{barcode},1);
1544    $form->{option} .= $locale->text('Barcode').qq| : $form->{barcode}<br>|;
1545  }
1546  if ($form->{lot} ne "") {
1547    $callback .= "&lot=".$form->escape($form->{lot},1);
1548    $form->{option} .= $locale->text('Lot').qq| : $form->{lot}<br>|;
1549    $form->{l_lot} = "Y";
1550  }
1551
1552  if ($form->{l_markup}) {
1553    $callback .= "&l_markup=Y";
1554    $form->{l_sellprice} = "Y";
1555    $form->{l_lastcostmarkup} = "Y" if $form->{l_lastcost};
1556    $form->{l_avgcostmarkup} = "Y" if $form->{l_avgcost};
1557  }
1558
1559  @columns = $form->sort_columns(qw(partnumber description lot notes assemblypartnumber assemblydescription partsgroup partsgroupcode make model bin onhand perassembly rop unit cost linetotalcost sellprice linetotalsellprice listprice linetotallistprice lastcost linetotallastcost lastcostmarkup avgcost linetotalavgcost avgcostmarkup curr priceupdate expires weight image drawing toolnumber barcode microfiche invnumber ordnumber quonumber transdate name employee serialnumber warehouse countryorigin tariff_hscode checkinventory));
1560  unshift @columns, qw(runningnumber id);
1561
1562  if ($form->{l_linetotal}) {
1563    $form->{l_onhand} = "Y";
1564    for (qw(sellprice lastcost avgcost listprice cost)) { $form->{"l_linetotal$_"} = "Y" if $form->{"l_$_"} }
1565  }
1566
1567  if ($form->{searchitems} eq 'service') {
1568    # remove bin, weight, lot, expires, checkinventory and rop from list
1569    for (qw(bin weight lot expires checkinventory rop)) { $form->{"l_$_"} = "" }
1570
1571    $form->{l_onhand} = "";
1572    # qty is irrelevant unless bought or sold
1573    if ($form->{bought} || $form->{sold} || $form->{onorder} ||
1574        $form->{ordered} || $form->{rfq} || $form->{quoted}) {
1575      $form->{l_onhand} = "Y";
1576    } else {
1577      for (qw(sellprice lastcost avgcost listprice cost)) { $form->{"l_linetotal$_"} = "" }
1578    }
1579  } else {
1580    $form->{l_onhand} = "Y" if $form->{l_qty};
1581  }
1582
1583  foreach $item (@columns) {
1584    if ($form->{"l_$item"} eq "Y") {
1585      push @column_index, $item;
1586
1587      # add column to callback
1588      $callback .= "&l_$item=Y";
1589    }
1590  }
1591
1592  if ($form->{l_account} eq 'Y') {
1593    if ($form->{searchitems} =~ /(all|part|kit|assembly)/) {
1594      push @column_index, (qw(inventory income expense tax));
1595    } elsif ($form->{searchitems} eq 'service') {
1596      push @column_index, (qw(income expense tax));
1597    } else {
1598      push @column_index, (qw(inventory expense));
1599    }
1600
1601    $callback .= "&l_account=Y";
1602  }
1603
1604  if ($form->{l_subtotal} eq 'Y') {
1605    $callback .= "&l_subtotal=Y";
1606  }
1607
1608  IC->all_parts(\%myconfig, \%$form);
1609
1610  $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
1611
1612  $href = $callback;
1613
1614  if (@{ $form->{all_printer} }) {
1615    for (@{ $form->{all_printer} }) { $form->{selectprinter} .= "$_->{printer}\n" }
1616    chomp $form->{selectprinter};
1617  }
1618
1619  if (@{ $form->{all_language} }) {
1620    $form->{selectlanguage} = "\n";
1621    for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|$_->{code}--$_->{description}\n| }
1622  }
1623
1624  $form->sort_order();
1625
1626  $callback =~ s/(direction=).*?\&/$1$form->{direction}\&/;
1627
1628  if ($form->{searchitems} =~ /(assembly|kit)/) {
1629    if ($form->{l_partnumber}) {
1630      # replace partnumber with partnumber_
1631      $ndx = 0;
1632      foreach $item (@column_index) {
1633	$ndx++;
1634	last if $item eq 'partnumber';
1635      }
1636
1637      for (1 .. $form->{pncol}) { $hdr{"partnumber_$_"} = { align => l } }
1638
1639      splice @column_index, $ndx, 0, map { "partnumber_$_" } (1 .. $form->{pncol});
1640      $colspan = $form->{pncol} + 1;
1641    }
1642  }
1643
1644  if ($form->{searchitems} eq 'component') {
1645    if ($form->{l_partnumber}) {
1646      push @column_index, "assemblypartnumber";
1647    }
1648
1649    if ($form->{l_description}) {
1650      push @column_index, "assemblydescription";
1651    }
1652
1653  }
1654
1655  $column_data{runningnumber} = qq|<th a class=listheading>&nbsp;</th>|;
1656  $hdr{partnumber} = { label => $locale->text('Number'), align => l };
1657  $column_data{partnumber} = qq|<th nowrap colspan=$colspan><a class=listheading href=$href&sort=partnumber>$hdr{partnumber}{label}</a></th>|;
1658  $hdr{id} = { label => $locale->text('ID'), align => l };
1659  $column_data{id} = qq|<th><a class=listheading href=$href&sort=id>$hdr{id}{label}</a></th>|;
1660
1661  $hdr{description} = { label => $locale->text('Description'), align => p };
1662  $column_data{description} = qq|<th nowrap><a class=listheading href=$href&sort=description>$hdr{description}{label}</a></th>|;
1663  $hdr{notes} = { label => $locale->text('Notes'), align => p };
1664  $column_data{notes} = qq|<th nowrap><a class=listheading href=$href&sort=notes>$hdr{notes}{label}</a></th>|;
1665  $hdr{partsgroup} = { label => $locale->text('Group'), align => l };
1666  $column_data{partsgroup} = qq|<th nowrap><a class=listheading href=$href&sort=partsgroup>$hdr{partsgroup}{label}</a></th>|;
1667  $hdr{partsgroupcode} = { label => $locale->text('Group Code'), align => l };
1668  $column_data{partsgroupcode} = qq|<th nowrap><a class=listheading href=$href&sort=partsgroupcode>$hdr{partsgroupcode}{label}</a></th>|;
1669
1670  $hdr{bin} = { label => $locale->text('Bin'), align => l };
1671  $column_data{bin} = qq|<th><a class=listheading href=$href&sort=bin>$hdr{bin}{label}</a></th>|;
1672  $hdr{priceupdate} = { label => $locale->text('Updated'), align => l };
1673  $column_data{priceupdate} = qq|<th nowrap><a class=listheading href=$href&sort=priceupdate>$hdr{priceupdate}{label}</a></th>|;
1674  $hdr{onhand} = { label => $locale->text('Qty'), align => r, type => n };
1675  $column_data{onhand} = qq|<th class=listheading nowrap>$hdr{onhand}{label}</th>|;
1676  $hdr{perassembly} = { label => $locale->text('BOM'), align => r, type => n };
1677  $column_data{perassembly} = qq|<th class=listheading nowrap>$hdr{perassembly}{label}</th>|;
1678  $hdr{unit} = { label => $locale->text('Unit'), align => l };
1679  $column_data{unit} = qq|<th class=listheading nowrap>$hdr{unit}{label}</th>|;
1680  $hdr{cost} = { label => $locale->text('Cost'), align => r, type => n, precision => $form->{precision} };
1681  $column_data{cost} = qq|<th class=listheading nowrap>$hdr{cost}{label}</th>|;
1682  $hdr{listprice} = { label => $locale->text('List Price'), align => r, type => n, precision => $form->{precision} };
1683  $column_data{listprice} = qq|<th class=listheading nowrap>$hdr{listprice}{label}</th>|;
1684  $hdr{lastcost} = { label => $locale->text('Last Cost'), align => r, type => n, precision => $form->{precision} };
1685  $column_data{lastcost} = qq|<th class=listheading nowrap>$hdr{lastcost}{label}</th>|;
1686  $hdr{avgcost} = { label => $locale->text('Avg Cost'), align => r, type => n, precision => $form->{precision} };
1687  $column_data{avgcost} = qq|<th class=listheading nowrap>$hdr{avgcost}{label}</th>|;
1688  $hdr{rop} = { label => $locale->text('ROP'), align => r, type => n };
1689  $column_data{rop} = qq|<th class=listheading nowrap>$hdr{rop}{label}</th>|;
1690  $hdr{weight} = { label => $locale->text('Weight'), align => r, type => n };
1691  $column_data{weight} = qq|<th class=listheading nowrap>$hdr{weight}{label}</th>|;
1692  $hdr{avgcostmarkup} = { label => '%', align => r, type => n };
1693  $column_data{avgcostmarkup} = qq|<th class=listheading nowrap>%</th>|;
1694  $hdr{lastcostmarkup} = { label => '%', align => r, type => n };
1695  $column_data{lastcostmarkup} = qq|<th class=listheading nowrap>%</th>|;
1696
1697  $hdr{make} = { label => $locale->text('Make'), align => p, width => 0.1 };
1698  $column_data{make} = qq|<th nowrap><a class=listheading href=$href&sort=make>$hdr{make}{label}</a></th>|;
1699  $hdr{model} = { label => $locale->text('Model'), align => p, width => 0.1 };
1700  $column_data{model} = qq|<th nowrap><a class=listheading href=$href&sort=model>$hdr{model}{label}</a></th>|;
1701
1702  $hdr{invnumber} = { label => $locale->text('Invoice Number'), align => l };
1703  $column_data{invnumber} = qq|<th nowrap><a class=listheading href=$href&sort=invnumber>$hdr{invnumber}{label}</a></th>|;
1704  $hdr{ordnumber} = { label => $locale->text('Order Number'), align => l };
1705  $column_data{ordnumber} = qq|<th nowrap><a class=listheading href=$href&sort=ordnumber>$hdr{ordnumber}{label}</a></th>|;
1706  $hdr{quonumber} = { label => $locale->text('Quotation'), align => l };
1707  $column_data{quonumber} = qq|<th nowrap><a class=listheading href=$href&sort=quonumber>$hdr{quonumber}{label}</a></th>|;
1708
1709  $hdr{name} = { label => $locale->text('Name'), align => l };
1710  $column_data{name} = qq|<th nowrap><a class=listheading href=$href&sort=name>$hdr{name}{label}</a></th>|;
1711
1712  $hdr{transdate} = { label => $locale->text('Date'), align => l };
1713  $column_data{transdate} = qq|<th nowrap><a class=listheading href=$href&sort=transdate>$hdr{transdate}{label}</a></th>|;
1714
1715  $hdr{employee} = { label => $locale->text('Employee'), align => l };
1716  $column_data{employee} = qq|<th nowrap><a class=listheading href=$href&sort=employee>$hdr{employee}{label}</a></th>|;
1717
1718  $hdr{sellprice} = { label => $locale->text('Sell Price'), align => r, type => n, precision => $form->{precision} };
1719  $column_data{sellprice} = qq|<th class=listheading nowrap>$hdr{sellprice}{label}</th>|;
1720
1721  $extended = $locale->text('Extended');
1722  for (qw(sellprice lastcost avgcost listprice cost)) {
1723    $hdr{"linetotal$_"} = { label => $extended, align => r, type => n, precision => $form->{precision} };
1724    $column_data{"linetotal$_"} = qq|<th class=listheading nowrap>$hdr{"linetotal$_"}{label}</th>|;
1725  }
1726
1727  $hdr{curr} = { label => $locale->text('Curr'), align => l };
1728  $column_data{curr} = qq|<th nowrap><a class=listheading href=$href&sort=curr>$hdr{curr}{label}</a></th>|;
1729
1730  $hdr{image} = { label => $locale->text('Image'), align => l, image => 1 };
1731  $column_data{image} = qq|<th class=listheading nowrap>$hdr{image}{label}</th>|;
1732  $hdr{drawing} = { label => $locale->text('Drawing'), align => l };
1733  $column_data{drawing} = qq|<th nowrap><a class=listheading href=$href&sort=drawing>$hdr{drawing}{label}</a></th>|;
1734  $hdr{toolnumber} = { label => $locale->text('Tool Number'), align => l };
1735  $column_data{toolnumber} = qq|<th nowrap><a class=listheading href=$href&sort=toolnumber>$hdr{toolnumber}{label}</a></th>|;
1736
1737  $hdr{microfiche} = { label => $locale->text('Microfiche'), align => l };
1738  $column_data{microfiche} = qq|<th nowrap><a class=listheading href=$href&sort=microfiche>$hdr{microfiche}{label}</a></th>|;
1739
1740  $hdr{countryorigin} = { label => $locale->text('CO'), align => l };
1741  $column_data{countryorigin} = qq|<th nowrap><a class=listheading href=$href&sort=countryorigin>$hdr{countryorigin}{label}</a></th>|;
1742  $hdr{tariff_hscode} = { label => $locale->text('HS Code'), align => l };
1743  $column_data{tariff_hscode} = qq|<th nowrap><a class=listheading href=$href&sort=tariff_hscode>$hdr{tariff_hscode}{label}</a></th>|;
1744
1745  $hdr{barcode} = { label => $locale->text('Barcode'), align => l };
1746  $column_data{barcode} = qq|<th nowrap><a class=listheading href=$href&sort=barcode>$hdr{barcode}{label}</a></th>|;
1747
1748  $hdr{serialnumber} = { label => $locale->text('Serial Number'), align => l };
1749  $column_data{serialnumber} = qq|<th nowrap><a class=listheading href=$href&sort=serialnumber>$hdr{serialnumber}{label}</a></th>|;
1750
1751   $hdr{lot} = { label => $locale->text('Lot'), align => l };
1752  $column_data{lot} = qq|<th nowrap><a class=listheading href=$href&sort=lot>$hdr{lot}{label}</a></th>|;
1753
1754  $hdr{expires} = { label => $locale->text('Expires'), align => l };
1755  $column_data{expires} = qq|<th nowrap><a class=listheading href=$href&sort=expires>$hdr{expires}{label}</a></th>|;
1756
1757  $hdr{checkinventory} = { label => $locale->text('I'), align => l };
1758  $column_data{checkinventory} = qq|<th nowrap><a class=listheading>$hdr{checkinventory}{label}</a></th>|;
1759
1760  $hdr{assemblypartnumber} = { label => $locale->text('Assembly'), align => l };
1761  $column_data{assemblypartnumber} = qq|<th nowrap><a class=listheading href=$href&sort=assemblypartnumber>$hdr{assemblypartnumber}{label}</a></th>|;
1762  $column_data{assemblydescription} = qq|<th nowrap><a class=listheading href=$href&sort=assemblydescription>$hdr{description}{label}</a></th>|;
1763
1764  $hdr{warehouse} = { label => $locale->text('Warehouse'), align => l };
1765  $column_data{warehouse} = qq|<th nowrap class=listheading>$hdr{warehouse}{label}</th>|;
1766
1767  $hdr{inventory} = { label => $locale->text('Inventory'), align => l };
1768  $column_data{inventory} = qq|<th nowrap class=listheading>$hdr{inventory}{label}</th>|;
1769  $hdr{income} = { label => $locale->text('Income'), align => l };
1770  $column_data{income} = qq|<th nowrap class=listheading>$hdr{income}{label}</th>|;
1771  $hdr{expense} = { label => $locale->text('Expense'), align => l };
1772  $column_data{expense} = qq|<th nowrap class=listheading>$hdr{expense}{label}</th>|;
1773  $hdr{tax} = { label => $locale->text('Tax'), align => l };
1774  $column_data{tax} = qq|<th nowrap class=listheading>$hdr{tax}{label}</th>|;
1775
1776  $form->header;
1777
1778  $i = 1;
1779  if ($form->{changeup}) {
1780    $form->helpref("list_changeup", $myconfig{countrycode});
1781  } else {
1782    $form->helpref("list_items", $myconfig{countrycode});
1783    if ($form->{searchitems} eq 'part') {
1784      $button{'Goods & Services--Add Part'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Part').qq|"> |;
1785      $button{'Goods & Services--Add Part'}{order} = $i++;
1786    }
1787    if ($form->{searchitems} eq 'service') {
1788      $button{'Goods & Services--Add Service'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Service').qq|"> |;
1789      $button{'Goods & Services--Add Service'}{order} = $i++;
1790    }
1791    if ($form->{searchitems} eq 'assembly') {
1792      $button{'Goods & Services--Add Assembly'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Assembly').qq|"> |;
1793      $button{'Goods & Services--Add Assembly'}{order} = $i++;
1794    }
1795    if ($form->{searchitems} eq 'kit') {
1796      $button{'Goods & Services--Add Kit'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Kit').qq|"> |;
1797      $button{'Goods & Services--Add Kit'}{order} = $i++;
1798    }
1799    if ($form->{searchitems} eq 'labor') {
1800      $button{'Goods & Services--Add Labor/Overhead'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Labor/Overhead').qq|"> |;
1801      $button{'Goods & Services--Add Labor/Overhead'}{order} = $i++;
1802    }
1803
1804    $button{'Goods & Services--Preview'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Preview').qq|"> |;
1805    $button{'Goods & Services--Preview'}{order} = $i++;
1806
1807    $button{'Goods & Services--Print'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Print ').qq|"> |;
1808    $button{'Goods & Services--Print'}{order} = $i++;
1809  }
1810
1811  foreach $item (split /;/, $myconfig{acs}) {
1812    delete $button{$item};
1813  }
1814
1815  $title = "$form->{title} / $form->{company}";
1816
1817  print qq|
1818<body>
1819
1820<table width=100%>
1821  <tr>
1822    <th class=listtop>$form->{helpref}$title</a></th>
1823  </tr>
1824  <tr height="5"></tr>
1825
1826  <tr><td>$form->{option}</td></tr>
1827
1828  <tr>
1829    <td>
1830      <table width=100%>
1831        <tr class=listheading>
1832|;
1833
1834  $form->{column_index} = "";
1835  for (@column_index) {
1836    print "\n$column_data{$_}";
1837    $form->{column_index} .= "$_--label=$hdr{$_}{label}:align=$hdr{$_}{align}:type=$hdr{$_}{type}:precision=$hdr{$_}{precision}:width=$hdr{$_}{width}:image=$hdr{$_}{image};";
1838  }
1839  chop $form->{column_index};
1840
1841  print qq|
1842        </tr>
1843  |;
1844
1845
1846  # add order to callback
1847  $form->{callback} = $callback .= "&sort=$form->{sort}";
1848
1849  # escape callback for href
1850  $callback = $form->escape($callback);
1851
1852
1853  $k = $#{ $form->{parts} };
1854  @groupby = ($form->{sort});
1855
1856  if ($form->{summary}) {
1857    @groupby = ();
1858    for (qw(partnumber id description lot notes partsgroup partsgroupcode make model bin curr priceupdate image drawing toolnumber barcode microfiche invnumber ordnumber quonumber transdate name employee serialnumber warehouse countryorigin tariff_hscode expires)) { $f{$_} = 1 };
1859
1860    for (@column_index) {
1861      if ($f{$_}) {
1862	push @groupby, $_;
1863      }
1864    }
1865    push @groupby, "id";
1866  }
1867
1868  if ($k > 0) {
1869    $samegroup = "";
1870    for (@groupby) { $samegroup .= $form->{parts}->[0]->{$_} }
1871  }
1872
1873  $i = 0;
1874  $n = 0;
1875
1876  foreach $ref (@{ $form->{parts} }) {
1877
1878    $ref->{exchangerate} ||= 1;
1879    $ref->{discount} *= 1;
1880
1881    if ($form->{itemstatus} eq 'stocklevel') {
1882      $ref->{onhand} *= -1 if $ref->{module} eq 'is';
1883    }
1884
1885    if ($form->{summary}) {
1886
1887      $summary{$ref->{id}}{total} += $ref->{sellprice} * $ref->{onhand};
1888      $summary{$ref->{id}}{onhand} += $ref->{onhand};
1889      $summary{$ref->{id}}{cost} += $ref->{cost} * $ref->{onhand};
1890
1891      if ($n < $k) {
1892	$nextgroup = "";
1893	for (@groupby) { $nextgroup .= $form->{parts}->[$n+1]->{$_} }
1894	$n++;
1895
1896	$form->{parts}->[$n]->{exchangerate} ||= 1;
1897
1898        if ($samegroup eq $nextgroup) {
1899	  for (qw(exchangerate discount)) { $form->{parts}->[$n]->{$_} = ($ref->{$_} + $form->{parts}->[$n]->{$_}) / 2 }
1900	  next;
1901	}
1902	$samegroup = $nextgroup;
1903      }
1904
1905      $ref->{onhand} = $summary{$ref->{id}}{onhand};
1906      if ($ref->{onhand}) {
1907	$ref->{sellprice} = $summary{$ref->{id}}{total} / $ref->{onhand};
1908	$ref->{cost} = $summary{$ref->{id}}{cost} / $ref->{onhand};
1909      }
1910
1911      $summary{$ref->{id}}{total} = 0;
1912      $summary{$ref->{id}}{onhand} = 0;
1913      $summary{$ref->{id}}{cost} = 0;
1914
1915    }
1916
1917    if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
1918      if ($samesort ne $ref->{$form->{sort}}) {
1919	&parts_subtotal;
1920	$samesort = $ref->{$form->{sort}};
1921      }
1922    }
1923
1924    $i++;
1925
1926    if ($form->{l_curr}) {
1927      if ($ref->{module} eq 'oe') {
1928	$ref->{sellprice} = $ref->{sellprice} * (1 - $ref->{discount});
1929      } else {
1930	for (qw(sellprice listprice lastcost avgcost cost)) { $ref->{$_} /= $ref->{exchangerate} }
1931      }
1932    } else {
1933      if ($ref->{module} eq 'oe') {
1934	$ref->{sellprice} = $ref->{sellprice} * (1 - $ref->{discount});
1935	for (qw(sellprice listprice lastcost avgcost cost)) { $ref->{$_} *= $ref->{exchangerate} }
1936      }
1937    }
1938
1939    if (!$form->{summary}) {
1940      for (qw(sellprice listprice lastcost avgcost cost)) { $ref->{$_} = $form->round_amount($ref->{$_}, $form->{precision}) }
1941    }
1942
1943    if ($form->{l_markup}) {
1944      $ref->{lastcostmarkup} = (($ref->{sellprice} / $ref->{lastcost}) - 1) * 100 if $ref->{lastcost} != 0;
1945      $ref->{avgcostmarkup} = (($ref->{sellprice} / $ref->{avgcost}) - 1) * 100 if $ref->{avgcost} != 0;
1946    }
1947
1948    # use this for assemblies
1949    $onhand = $ref->{onhand};
1950
1951    for (qw(description assemblydescription notes)) { $ref->{$_} =~ s/\r?\n/<br>/g }
1952
1953    for (1 .. $form->{pncol}) { $column_data{"partnumber_$_"} = "<td>&nbsp;</td>" }
1954
1955    $column_data{runningnumber} = "<td align=right>$i</td>";
1956    $column_data{partnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&changeup=$form->{changeup}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
1957    $column_data{id} = "<td>$ref->{id}</td>";
1958
1959    for (qw(description assemblydescription notes partsgroup partsgroupcode employee curr)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
1960
1961    if ($ref->{assemblypartnumber}) {
1962      if ($sameid == $ref->{id}) {
1963	$i--;
1964	for (qw(runningnumber partnumber id description)) { $column_data{$_} = "<td>&nbsp;</td>" }
1965      }
1966    }
1967
1968    $column_data{assemblypartnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{assembly_id}&changeup=$form->{changeup}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{assemblypartnumber}&nbsp;</a></td>";
1969
1970    if ($ref->{assemblyitem}) {
1971      $onhand = 0 if $form->{sold};
1972
1973      for (qw(runningnumber partnumber)) { $column_data{$_} = "<td>&nbsp;</td>" }
1974      $i--;
1975
1976      $column_data{"partnumber_$ref->{stagger}"} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
1977
1978    }
1979
1980    $column_data{onhand} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand}, undef, "&nbsp;")."</td>";
1981    $column_data{perassembly} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{perassembly}, undef, "&nbsp;")."</td>";
1982
1983    if ($form->{summary} && $form->{l_linetotal}) {
1984      $column_data{sellprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{sellprice}, $form->{precision}, "&nbsp;") . "</td>";
1985    } else {
1986      $column_data{sellprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{sellprice}, $form->{precision}, "&nbsp;") . "</td>";
1987    }
1988    for (qw(listprice lastcost avgcost cost)) { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, $form->{precision}, "&nbsp;") . "</td>" }
1989
1990    for (qw(lastcost avgcost)) { $column_data{"${_}markup"} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{"${_}markup"}, 1, "&nbsp;")."</td>" }
1991
1992    if ($form->{l_linetotal}) {
1993      for (qw(sellprice lastcost avgcost listprice cost)) { $column_data{"linetotal$_"} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, $form->{precision}, "&nbsp;")."</td>" }
1994    }
1995
1996    if ($ref->{assemblyitem} && $ref->{stagger} > 1) {
1997      for (qw(sellprice lastcost avgcost listprice cost)) { $column_data{"linetotal$_"} = "<td>&nbsp;</td>" }
1998    }
1999
2000    if (!$ref->{assemblyitem}) {
2001      $totalcost += $onhand * $ref->{cost};
2002      $totalsellprice += $onhand * $ref->{sellprice};
2003      $totallastcost += $onhand * $ref->{lastcost};
2004      $totalavgcost += $onhand * $ref->{avgcost};
2005      $totallistprice += $onhand * $ref->{listprice};
2006
2007      $subtotalonhand += $onhand;
2008      $subtotalcost += $onhand * $ref->{cost};
2009      $subtotalsellprice += $onhand * $ref->{sellprice};
2010      $subtotallastcost += $onhand * $ref->{lastcost};
2011      $subtotalavgcost += $onhand * $ref->{avgcost};
2012      $subtotallistprice += $onhand * $ref->{listprice};
2013    }
2014
2015    for (qw(rop weight)) { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, undef, "&nbsp;")."</td>" }
2016    for (qw(unit bin)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
2017    $column_data{priceupdate} = "<td nowrap>$ref->{priceupdate}&nbsp;</td>";
2018    $column_data{expires} = "<td nowrap>$ref->{expires}&nbsp;</td>";
2019
2020    $ref->{module} = 'ps' if $ref->{till};
2021    $column_data{invnumber} = ($ref->{module} ne 'oe') ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{invnumber}&nbsp;</a></td>" : "<td>$ref->{invnumber}&nbsp;</td>";
2022    $column_data{ordnumber} = ($ref->{module} eq 'oe') ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{ordnumber}&nbsp;</a></td>" : "<td>$ref->{ordnumber}&nbsp;</td>";
2023    $column_data{quonumber} = ($ref->{module} eq 'oe' && !$ref->{ordnumber}) ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{quonumber}&nbsp;</a></td>" : "<td>$ref->{quonumber}&nbsp;</td>";
2024
2025    $column_data{name} = "<td>$ref->{name}</td>";
2026    $column_data{transdate} = "<td>$ref->{transdate}</td>";
2027
2028    if ($ref->{vc_id}) {
2029      $column_data{name} = qq|<td><a href=ct.pl?path=$form->{path}&login=$form->{login}&action=edit&id=$ref->{vc_id}&db=$ref->{vc}&callback=$callback>$ref->{name}</a></td>|;
2030    }
2031
2032    $column_data{image} = ($ref->{image}) ? "<td><a href=$images/$myconfig{dbname}/$ref->{image}><img src=$images/$myconfig{dbname}/$ref->{image} height=32 border=0></a></td>" : "<td>&nbsp;</td>";
2033    $column_data{drawing} = ($ref->{drawing}) ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>" : "<td>&nbsp;</td>";
2034    $column_data{microfiche} = ($ref->{microfiche}) ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>" : "<td>&nbsp;</td>";
2035    $column_data{checkinventory} = ($ref->{checkinventory}) ? "<td>&nbsp;x</td>" : "<td>&nbsp;</td>";
2036
2037    for (qw(make model)) { $ref->{$_} =~ s/\n/<br>/g }
2038    for (qw(make model lot serialnumber warehouse inventory income expense tax toolnumber countryorigin tariff_hscode barcode)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
2039
2040    $j++; $j %= 2;
2041    print "<tr class=listrow$j>";
2042
2043    for (@column_index) { print "\n$column_data{$_}" }
2044
2045    print qq|
2046    </tr>
2047|;
2048
2049    $sameid = $ref->{id};
2050
2051  }
2052
2053
2054  if ($form->{l_subtotal} eq 'Y') {
2055    &parts_subtotal;
2056  }
2057
2058  if ($form->{"l_linetotal"}) {
2059    for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
2060    $column_data{linetotalcost} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcost, $form->{precision}, "&nbsp;")."</th>";
2061    $column_data{linetotalsellprice} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalsellprice, $form->{precision}, "&nbsp;")."</th>";
2062    $column_data{linetotallastcost} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totallastcost, $form->{precision}, "&nbsp;")."</th>";
2063    $column_data{linetotalavgcost} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalavgcost, $form->{precision}, "&nbsp;")."</th>";
2064    $column_data{linetotallistprice} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totallistprice, $form->{precision}, "&nbsp;")."</th>";
2065
2066    print "<tr class=listtotal>";
2067
2068    for (@column_index) { print "\n$column_data{$_}" }
2069
2070    print qq|</tr>
2071    |;
2072  }
2073
2074  print qq|
2075      </table>
2076    </td>
2077  </tr>
2078  <tr><td><hr size=3 noshade></td></tr>
2079</table>
2080|;
2081
2082  print qq|
2083<br>
2084
2085<form method=post action=$form->{script}>
2086
2087<input type=hidden name=item value=$form->{searchitems}>
2088|;
2089
2090  $form->hide_form(qw(column_index callback path login option));
2091
2092  &ic_print_options unless $form->{changeup};
2093
2094  foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
2095    print $item->{code};
2096  }
2097
2098  if ($form->{menubar}) {
2099    require "$form->{path}/menu.pl";
2100    &menubar;
2101  }
2102
2103  print qq|
2104  </form>
2105
2106</body>
2107</html>
2108|;
2109
2110}
2111
2112
2113sub preview {
2114
2115  $form->{format} = "pdf";
2116  $form->{media} = "screen";
2117
2118  &print_;
2119
2120}
2121
2122
2123sub ic_print_options {
2124
2125  if (! $latex) {
2126    for (map { "Goods & Services--$_" } qw(Print Preview)) {
2127      delete $button{$_};
2128    }
2129    return;
2130  }
2131
2132  $form->{PD}{$form->{type}} = "selected";
2133
2134  if ($myconfig{printer}) {
2135    $form->{format} ||= "ps";
2136  } else {
2137    $form->{format} ||= "pdf";
2138  }
2139  $form->{media} ||= $myconfig{printer};
2140
2141  if ($form->{selectlanguage}) {
2142    $lang = qq|<select name=language_code>|.$form->select_option($form->{selectlanguage}, $form->{language_code}, undef, 1).qq|</select>|;
2143  }
2144
2145  $media = qq|<select name=media>
2146	  <option value=screen>|.$locale->text('Screen');
2147
2148  if ($form->{selectprinter} && $latex) {
2149    $media .= $form->select_option($form->{selectprinter}, $form->{media});
2150  }
2151
2152  $media .= qq|</select>|;
2153
2154  $format = qq|<select name=format>|;
2155
2156  $type = qq|<select name=formname>
2157	    <option value="partsreport" $form->{PD}{partsreport}>|.$locale->text('Parts Report');
2158  $type .= qq|
2159	    <option value="barcode" $form->{PD}{barcode}>|.$locale->text('Barcode') if $dvipdf;
2160  $type .= qq|</select>|;
2161
2162  if ($latex) {
2163    $format .= qq|
2164            <option value="ps">|.$locale->text('Postscript').qq|
2165	    <option value="pdf">|.$locale->text('PDF');
2166  }
2167
2168  $format .= qq|</select>|;
2169  $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
2170
2171
2172  print qq|
2173<table>
2174  <tr>
2175    <td>$type</td>
2176    <td>$lang</td>
2177    <td>$format</td>
2178    <td>$media</td>
2179|;
2180
2181  print qq|
2182  </tr>
2183</table>
2184<br>
2185|;
2186
2187}
2188
2189
2190sub print_ {
2191
2192  $form->error($locale->text('Nothing to print')) unless $form->{callback};
2193
2194  ($script, $argv) = split /\?/, $form->{callback};
2195
2196  for (split /&/, $argv) {
2197    ($key, $value) = split /=/, $_, 2;
2198    $form->{$key} = $form->unescape($value);
2199  }
2200
2201  IC->all_parts(\%myconfig, \%$form);
2202
2203  $form->error($locale->text('Nothing to print')) unless $form->{parts};
2204
2205  @columns = ();
2206  for (split /;/, $form->{column_index}) {
2207    ($column, $vars) = split /--/, $_;
2208    push @columns, $column;
2209    push @colndx, $column;
2210    $form->{$column} = ();
2211    %{ $hdr{$column} } = split /[:=]/, $vars;
2212  }
2213
2214  for (qw(sku number ship sell)) {
2215    push @columns, $_;
2216    $form->{$_} = ();
2217  }
2218  $hdr{sku} = { label => $hdr{partnumber}{label}, $hdr{partnumber}{align}, type => c };
2219  $hdr{number} = $hdr{sku};
2220  $hdr{ship} = { label => $hdr{onhand}{label}, $hdr{onhand}{align}, type => n };
2221
2222  $sameid = "";
2223
2224  foreach $ref (@{ $form->{parts} }) {
2225    $ref->{sku} = $ref->{partnumber};
2226    $ref->{number} = $ref->{sku};
2227    $ref->{sell} = $ref->{sellprice};
2228
2229    $ref->{image} =~ s/\..*$/.eps/;
2230    $filename = "$ref->{image}";
2231    $ref->{image} = (-f $filename) ? "\\includegraphics*\{../$filename\}" : "";
2232
2233    if ($form->{formname} eq 'barcode') {
2234      $ref->{onhand} = 1 if $ref->{onhand} <= 0;
2235    }
2236    $ref->{ship} = $ref->{onhand};
2237
2238    for (qw(sell sellprice listprice lastcost avgcost)) { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, $form->{precision}) }
2239    for (qw(qty rop ship onhand weight)) { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}) }
2240
2241    if ($form->{searchitems} eq 'assembly') {
2242      if ($form->{l_partnumber}) {
2243	if ($ref->{assemblyitem}) {
2244	  $ref->{"partnumber_$ref->{stagger}"} = $ref->{partnumber};
2245	  $ref->{partnumber} = "";
2246	}
2247      }
2248    }
2249
2250    if ($form->{searchitems} eq 'component') {
2251      if ($ref->{assemblypartnumber}) {
2252	$ref->{partnumber} = "" if $ref->{id} == $sameid;
2253      }
2254    }
2255
2256    @c = grep !/(onhand|make|model|warehouse)/, @columns;
2257    # build arrays
2258    if ($ref->{id} == $sameid) {
2259      for (@c) { push @{ $form->{$_} }, "" }
2260      push @{ $form->{make} }, $ref->{make};
2261      push @{ $form->{model} }, $ref->{model};
2262      push @{ $form->{warehouse} }, $ref->{warehouse};
2263      push @{ $form->{onhand} }, ($ref->{warehouse}) ? $ref->{onhand} : "";
2264    } else {
2265      for (@columns) { push @{ $form->{$_} }, $ref->{$_} }
2266    }
2267
2268    $sameid = $ref->{id};
2269
2270  }
2271  delete $form->{parts};
2272
2273  push @a, qw(company companyemail companywebsite address tel fax businessnumber);
2274  $form->format_string(@a);
2275
2276  for (@{ $form->{all_printer} }) { $form->{"$_->{printer}_printer"} = $_->{command} }
2277
2278  if ($form->{media} !~ /screen/) {
2279    $form->{OUT} = qq~| $form->{"$form->{media}_printer"}~;
2280  }
2281
2282  if ($form->{formname} eq 'barcode') {
2283    $form->{templates} = "$templates/$myconfig{templates}";
2284    $form->{IN} = "$form->{formname}.$form->{format}";
2285
2286    if ($form->{format} =~ /(ps|pdf)/) {
2287      $form->{IN} =~ s/$&$/tex/;
2288    }
2289
2290    for $temp (qw(description notes)) {
2291      for (@{ $form->{$temp} }) {
2292        $form->{"temp_$temp"} = $_;
2293        $form->format_string("temp_$temp");
2294        $_ = $form->{"temp_$temp"};
2295      }
2296    }
2297
2298    $form->parse_template(\%myconfig, $userspath, $dvipdf, $xelatex);
2299
2300  } else {
2301
2302    $form->gentex(\%myconfig, $templates, $userspath, $dvipdf, $xelatex, \@colndx, \%hdr);
2303
2304  }
2305
2306  if ($form->{callback}) {
2307    $form->redirect unless $form->{media} eq 'screen';
2308  } else {
2309    $form->error($locale->text('Report processed!'));
2310  }
2311
2312}
2313
2314
2315sub parts_subtotal {
2316
2317  for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
2318  $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{individual});
2319
2320  $column_data{onhand} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalonhand, undef, "&nbsp;")."</th>";
2321
2322  $column_data{linetotalsellprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalsellprice, $form->{precision}, "&nbsp;")."</th>";
2323  $column_data{linetotallistprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallistprice, $form->{precision}, "&nbsp;")."</th>";
2324  $column_data{linetotallastcost} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallastcost, $form->{precision}, "&nbsp;")."</th>";
2325  $column_data{linetotalavgcost} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalavgcost, $form->{precision}, "&nbsp;")."</th>";
2326
2327  $subtotalonhand = 0;
2328  $subtotalsellprice = 0;
2329  $subtotallistprice = 0;
2330  $subtotallastcost = 0;
2331  $subtotalavgcost = 0;
2332
2333  print "<tr class=listsubtotal>";
2334
2335  for (@column_index) { print "\n$column_data{$_}" }
2336
2337  print qq|
2338  </tr>
2339|;
2340
2341}
2342
2343
2344sub supply_demand {
2345
2346  $form->get_partsgroup(\%myconfig, { searchitems => 'parts'});
2347  $form->all_years(\%myconfig);
2348
2349  if (@{ $form->{all_partsgroup} }) {
2350    $partsgroup = qq|<option>\n|;
2351
2352    for (@{ $form->{all_partsgroup} }) { $partsgroup .= qq|<option value="|.$form->quote($_->{partsgroup}).qq|--$_->{id}">$_->{partsgroup}\n| }
2353
2354    $partsgroup = qq|
2355        <th align=right nowrap>|.$locale->text('Group').qq|</th>
2356	<td><select name=partsgroup>$partsgroup</select></td>
2357|;
2358
2359    $l{partsgroup} = qq|<input name=l_partsgroup class=checkbox type=checkbox value=Y> |.$locale->text('Group');
2360  }
2361
2362  if (@{ $form->{all_years} }) {
2363    $selectaccountingyear = "\n";
2364    for (@{ $form->{all_years} }) { $selectaccountingyear .= qq|$_\n| }
2365
2366    $selectfrom = qq|
2367        <tr>
2368 	  <th align=right>|.$locale->text('Year').qq|</th>
2369	  <td colspan=3>
2370	    <table>
2371	      <tr>
2372	        <td>
2373		<select name=year>|.$form->select_option($selectaccountingyear).qq|</select>
2374		</td>
2375		<td>
2376		  <table>
2377		    <tr>
2378|;
2379
2380    for (sort keys %{ $form->{all_month} }) {
2381      $i = ($_ * 1) - 1;
2382      if (($i % 3) == 0) {
2383	$selectfrom .= qq|
2384		    </tr>
2385		    <tr>
2386|;
2387      }
2388
2389      $i = $_ * 1;
2390
2391      $selectfrom .= qq|
2392		      <td nowrap><input name="l_month_$i" class checkbox type=checkbox value=Y>&nbsp;|.$locale->text($form->{all_month}{$_}).qq|</td>\n|;
2393    }
2394
2395    $selectfrom .= qq|
2396		    </tr>
2397		  </table>
2398		</td>
2399	      </tr>
2400	    </table>
2401	  </td>
2402        </tr>
2403|;
2404  } else {
2405    $form->error($locale->text('No History!'));
2406  }
2407
2408  $form->{title} = $locale->text('Supply & Demand');
2409  $form->helpref("supply_demand", $myconfig{countrycode});
2410
2411  $form->{sort} = "partnumber";
2412  $form->{nextsub} = "supply_demand_report";
2413
2414  $form->header;
2415
2416  print qq|
2417<body>
2418
2419<form method=post name=main action=$form->{script}>
2420
2421|;
2422
2423  print qq|
2424
2425<table width="100%">
2426
2427  <tr><th class=listtop>$form->{helpref}$form->{title}</a></th></tr>
2428  <tr height="5"></tr>
2429  <tr valign=top>
2430    <td>
2431      <table>
2432        <tr>
2433          <th align=right nowrap>|.$locale->text('Number').qq|</th>
2434          <td><input name=partnumber size=20></td>
2435        </tr>
2436        <tr>
2437          <th align=right nowrap>|.$locale->text('Description').qq|</th>
2438          <td colspan=3><input name=description size=40></td>
2439        </tr>
2440	<tr>
2441	  $partsgroup
2442	</tr>
2443	$selectfrom
2444      </table>
2445    </td>
2446  </tr>
2447  <tr>
2448    <td><hr size=3 noshade></td>
2449  </tr>
2450</table>
2451<br>
2452<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">|;
2453
2454  $form->hide_form(qw(sort nextsub path login));
2455
2456  if ($form->{menubar}) {
2457    require "$form->{path}/menu.pl";
2458    &menubar;
2459  }
2460
2461  print qq|
2462</form>
2463
2464</body>
2465</html>
2466|;
2467
2468}
2469
2470
2471
2472sub supply_demand_report {
2473
2474  $callback = "$form->{script}?action=supply_demand_report";
2475  for (qw(path login year)) { $callback .= qq|&$_=$form->{$_}| }
2476  for (qw(partsgroup)) { $callback .= qq|&$_=|.$form->escape($form->{$_},1) }
2477
2478  if ($form->{partnumber}) {
2479    $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
2480    $option = $locale->text('Number').qq| : $form->{partnumber}<br>|;
2481  }
2482  if ($form->{partsgroup}) {
2483    ($partsgroup) = split /--/, $form->{partsgroup};
2484    $option .= $locale->text('Group').qq| : $partsgroup<br>|;
2485  }
2486  if ($form->{description}) {
2487    $callback .= "&description=".$form->escape($form->{description},1);
2488    $description = $form->{description};
2489    $description =~ s/\r?\n/<br>/g;
2490    $option .= $locale->text('Description').qq| : $description<br>|;
2491  }
2492
2493  @column_index = $form->sort_columns(qw(partnumber description));
2494  unshift @column_index, "runningnumber";
2495
2496  for (1 .. 12) {
2497    if ($form->{"l_month_$_"}) {
2498      $callback .= qq|&l_month_$_=$form->{"l_month_$_"}|;
2499      push @column_index, $_;
2500      $month{$_} = 1;
2501    }
2502  }
2503
2504  push @column_index, "year" unless %month;
2505  push @column_index, qw(onhand rop so po required);
2506
2507  IC->supply_demand(\%myconfig, \%$form);
2508
2509  $form->sort_order();
2510
2511  $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
2512
2513  $href = $callback;
2514
2515  $callback =~ s/(direction=).*?\&/$1$form->{direction}\&/;
2516
2517  if (%month) {
2518    $option .= $locale->text('Year').qq| : $form->{year}<br>|;
2519  }
2520
2521
2522  $column_data{runningnumber} = qq|<th a class=listheading>&nbsp;</th>|;
2523  $column_data{partnumber} = qq|<th nowrap colspan=$colspan><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</a></th>|;
2524  $column_data{description} = qq|<th nowrap><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
2525  $column_data{onhand} = qq|<th class=listheading nowrap>|.$locale->text('On Hand').qq|</th>|;
2526  $column_data{rop} = qq|<th class=listheading nowrap>|.$locale->text('ROP').qq|</th>|;
2527  $column_data{so} = qq|<th class=listheading nowrap>|.$locale->text('SO').qq|</th>|;
2528  $column_data{po} = qq|<th class=listheading nowrap>|.$locale->text('PO').qq|</th>|;
2529  $column_data{required} = qq|<th class=listheading nowrap>|.$locale->text('Required').qq|</th>|;
2530  $column_data{year} = qq|<th class=listheading nowrap>|;
2531  if ($form->{year}) {
2532    $column_data{year} .= $form->{year};
2533  } else {
2534    $column_data{year} .= $locale->text('Total');
2535  }
2536  $column_data{year} .= qq|</th>|;
2537
2538  for (sort { $a <=> $b } keys %month) { $column_data{$_} = qq|<th class=listheading nowrap>|.$locale->text($locale->{SHORT_MONTH}[$_-1]).qq|</th>| }
2539
2540  $form->{title} = $locale->text('Supply & Demand');
2541
2542  $form->helpref("supply_demand_report", $myconfig{countrycode});
2543
2544  $form->header;
2545
2546  print qq|
2547<body>
2548
2549<table width=100%>
2550  <tr>
2551    <th class=listtop>$form->{helpref}$form->{title}</a></th>
2552  </tr>
2553  <tr height="5"></tr>
2554
2555  <tr><td>$option</td></tr>
2556
2557  <tr>
2558    <td>
2559      <table width=100%>
2560        <tr class=listheading>
2561|;
2562
2563  for (@column_index) { print "\n$column_data{$_}" }
2564
2565  print qq|
2566        </tr>
2567  |;
2568
2569
2570  # add order to callback
2571  $form->{callback} = $callback .= "&sort=$form->{sort}";
2572
2573  # escape callback for href
2574  $callback = $form->escape($callback);
2575
2576  if (@{ $form->{parts} }) {
2577    $sameid = $form->{parts}[0]->{id};
2578  }
2579
2580  for (keys %month) { $column_data{$_} = "<td>&nbsp;</td>" }
2581
2582  $i = 0;
2583  $qty = 0;
2584  foreach $ref (@{ $form->{parts} }) {
2585
2586    if ($ref->{id} != $sameid) {
2587
2588      $i++;
2589      $column_data{runningnumber} = "<td align=right>$i</td>";
2590
2591      $required = 0 if $required < 0;
2592      $column_data{required} = "<td align=right>".$form->format_amount(\%myconfig, $required, undef, "-")."</td>";
2593      $j++; $j %= 2;
2594      print "<tr class=listrow$j>";
2595
2596      for (@column_index) {
2597	print "\n$column_data{$_}";
2598	$column_data{$_} = "<td>&nbsp;</td>";
2599      }
2600
2601      print qq|
2602    </tr>
2603|;
2604      $qty = 0;
2605    }
2606
2607    $ref->{description} =~ s/\r?\n/<br>/g;
2608
2609    $column_data{partnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
2610
2611    $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
2612
2613    $column_data{onhand} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand}, undef, "&nbsp;")."</td>";
2614    $column_data{rop} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{rop}, undef, "&nbsp;")."</td>";
2615    $column_data{so} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{so}, undef, "&nbsp;")."</td>";
2616    $column_data{po} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{po}, undef, "&nbsp;")."</td>";
2617
2618    if (%month) {
2619      for (keys %month) {
2620	$column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, undef, "&nbsp;")."</td>";
2621	$qty += $ref->{$_};
2622      }
2623    } else {
2624      $qty = $ref->{qty};
2625    }
2626
2627    $column_data{year} = "<td align=right>".$form->format_amount(\%myconfig, $qty, undef, "&nbsp;")."</td>";
2628
2629    $required = $qty + $ref->{so} - $ref->{po} - $ref->{onhand} + $ref->{rop};
2630
2631    $sameid = $ref->{id};
2632
2633  }
2634
2635  if (@{ $form->{parts} }) {
2636    $i++;
2637    $column_data{runningnumber} = "<td align=right>$i</td>";
2638
2639    $required = 0 if $required < 0;
2640    $column_data{required} = "<td align=right>".$form->format_amount(\%myconfig, $required, undef, "-")."</td>";
2641    $j++; $j %= 2;
2642    print "<tr class=listrow$j>";
2643
2644    for (@column_index) { print "\n$column_data{$_}" }
2645
2646    print qq|
2647    </tr>
2648|;
2649  }
2650
2651  print qq|
2652      </table>
2653    </td>
2654  </tr>
2655  <tr><td><hr size=3 noshade></td></tr>
2656</table>
2657
2658|;
2659
2660  print qq|
2661
2662<br>
2663
2664<form method=post action=$form->{script}>
2665
2666|;
2667
2668  $form->hide_form(qw(callback path login));
2669
2670  if ($form->{menubar}) {
2671    require "$form->{path}/menu.pl";
2672    &menubar;
2673  }
2674
2675  print qq|
2676  </form>
2677
2678</body>
2679</html>
2680|;
2681
2682}
2683
2684
2685sub requirements {
2686
2687  $form->get_partsgroup(\%myconfig, { searchitems => 'partassemblykit', subgroup => 1});
2688
2689  if (@{ $form->{all_partsgroup} }) {
2690    $partsgroup = qq|<option>\n|;
2691
2692    for (@{ $form->{all_partsgroup} }) {
2693
2694      $partsgroup .= qq|<option value="|.$form->quote($_->{partsgroup}).qq|--$_->{id}">$_->{partsgroup}\n|;
2695    }
2696
2697    $partsgroup = qq|
2698        <th align=right nowrap>|.$locale->text('Group').qq|</th>
2699	<td><select name=partsgroup>$partsgroup</select></td>
2700|;
2701
2702  }
2703
2704  $form->{title} = $locale->text('Requirements');
2705  $form->helpref("requirements", $myconfig{countrycode});
2706
2707  $form->header;
2708
2709  print qq|
2710<body onLoad="document.main.partnumber.focus()" />
2711
2712<form method=post name=main action=$form->{script}>
2713
2714|;
2715
2716  print qq|
2717
2718<table width="100%">
2719
2720  <tr><th class=listtop>$form->{helpref}$form->{title}</a></th></tr>
2721  <tr height="5"></tr>
2722  <tr valign=top>
2723    <td>
2724      <table>
2725        <tr>
2726          <th align=right nowrap>|.$locale->text('Number').qq|</th>
2727          <td><input name=partnumber size=20></td>
2728        </tr>
2729        <tr>
2730          <th align=right nowrap>|.$locale->text('Description').qq|</th>
2731          <td colspan=3><input name=description size=40></td>
2732        </tr>
2733	<tr>
2734	  $partsgroup
2735	</tr>
2736      </table>
2737    </td>
2738  </tr>
2739  <tr>
2740    <td><hr size=3 noshade></td>
2741  </tr>
2742</table>
2743
2744<input type=hidden name=nextsub value=requirements_report>
2745<input type=hidden name=sort value=partnumber>
2746
2747<br>
2748<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">|;
2749
2750  $form->hide_form(qw(path login));
2751
2752  print qq|
2753</form>
2754|;
2755
2756  if ($form->{menubar}) {
2757    require "$form->{path}/menu.pl";
2758    &menubar;
2759  }
2760
2761  print qq|
2762
2763</body>
2764</html>
2765|;
2766
2767}
2768
2769
2770sub requirements_report {
2771
2772  $callback = "$form->{script}?action=requirements_report";
2773  for (qw(path login)) { $callback .= qq|&$_=$form->{$_}| }
2774  for (qw(partsgroup)) { $callback .= qq|&$_=|.$form->escape($form->{$_},1) }
2775
2776  if ($form->{partnumber}) {
2777    $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
2778    $option .= $locale->text('Number').qq| : $form->{partnumber}<br>|;
2779  }
2780  if ($form->{partsgroup}) {
2781    ($partsgroup) = split /--/, $form->{partsgroup};
2782    $option .= $locale->text('Group').qq| : $partsgroup<br>|;
2783  }
2784  if ($form->{description}) {
2785    $callback .= "&description=".$form->escape($form->{description},1);
2786    $description = $form->{description};
2787    $description =~ s/\r?\n/<br>/g;
2788    $option .= $locale->text('Description').qq| : $form->{description}<br>|;
2789  }
2790
2791  @column_index = $form->sort_columns(qw(partnumber description));
2792  unshift @column_index, "runningnumber";
2793
2794  push @column_index, qw(onhand rop so po required);
2795
2796  IC->requirements(\%myconfig, \%$form);
2797
2798  $form->sort_order();
2799
2800  $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
2801
2802  $href = $callback;
2803
2804  $callback =~ s/(direction=).*?\&/$1$form->{direction}\&/;
2805
2806  $column_data{runningnumber} = qq|<th a class=listheading>&nbsp;</th>|;
2807  $column_data{partnumber} = qq|<th nowrap colspan=$colspan><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</a></th>|;
2808  $column_data{description} = qq|<th nowrap><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
2809  $column_data{onhand} = qq|<th class=listheading nowrap width=5%>|.$locale->text('On Hand').qq|</th>|;
2810  $column_data{rop} = qq|<th class=listheading nowrap width=5%>|.$locale->text('ROP').qq|</th>|;
2811  $column_data{so} = qq|<th class=listheading nowrap width=5%>|.$locale->text('SO').qq|</th>|;
2812  $column_data{po} = qq|<th class=listheading nowrap width=5%>|.$locale->text('PO').qq|</th>|;
2813  $column_data{required} = qq|<th class=listheading nowrap width=5%>|.$locale->text('Required').qq|</th>|;
2814
2815  $form->{title} = $locale->text('Requirements');
2816
2817  $form->helpref("requirements_report", $myconfig{countrycode});
2818
2819  $form->header;
2820
2821  print qq|
2822<body>
2823
2824<table width=100%>
2825  <tr>
2826    <th class=listtop>$form->{helpref}$form->{title}</a></th>
2827  </tr>
2828  <tr height="5"></tr>
2829
2830  <tr><td>$option</td></tr>
2831
2832  <tr>
2833    <td>
2834      <table width=100%>
2835        <tr class=listheading>
2836|;
2837
2838  for (@column_index) { print "\n$column_data{$_}" }
2839
2840  print qq|
2841        </tr>
2842  |;
2843
2844
2845  # add order to callback
2846  $form->{callback} = $callback .= "&sort=$form->{sort}";
2847
2848  # escape callback for href
2849  $callback = $form->escape($callback);
2850
2851  $i = 0;
2852
2853  foreach $ref (@{ $form->{parts} }) {
2854
2855    $required = $ref->{so} - $ref->{po} - $ref->{onhand} + $ref->{rop};
2856    $required = 0 if $required < 0;
2857
2858    if ($required) {
2859
2860      $i++;
2861      $column_data{runningnumber} = "<td align=right>$i</td>";
2862
2863      $column_data{partnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
2864
2865      $ref->{description} =~ s/\r?\n/<br>/g;
2866      $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
2867
2868      $column_data{onhand} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand}, undef, "&nbsp;")."</td>";
2869      $column_data{rop} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{rop}, undef, "&nbsp;")."</td>";
2870      $column_data{so} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{so}, undef, "&nbsp;")."</td>";
2871      $column_data{po} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{po}, undef, "&nbsp;")."</td>";
2872      $column_data{required} = "<td align=right>".$form->format_amount(\%myconfig, $required, undef, "-")."</td>";
2873
2874      $j++; $j %= 2;
2875      print "<tr class=listrow$j>";
2876
2877      for (@column_index) {
2878	print "\n$column_data{$_}";
2879	$column_data{$_} = "<td>&nbsp;</td>";
2880      }
2881
2882      print qq|
2883    </tr>
2884|;
2885
2886
2887    }
2888  }
2889
2890
2891  print qq|
2892      </table>
2893    </td>
2894  </tr>
2895  <tr><td><hr size=3 noshade></td></tr>
2896</table>
2897
2898|;
2899
2900  print qq|
2901
2902<br>
2903
2904<form method=post action=$form->{script}>
2905
2906|;
2907
2908  $form->hide_form(qw(callback path login));
2909
2910  if ($form->{menubar}) {
2911    require "$form->{path}/menu.pl";
2912    &menubar;
2913  }
2914
2915  print qq|
2916  </form>
2917
2918</body>
2919</html>
2920|;
2921
2922}
2923
2924
2925sub so_requirements {
2926
2927  $form->{vc} = "customer";
2928
2929  $form->all_vc(\%myconfig, $form->{vc}, "AR", undef, undef, undef, undef, 1);
2930
2931  $form->all_years(\%myconfig);
2932
2933  $vcname = $locale->text('Customer');
2934  $vcnumber = $locale->text('Customer Number');
2935
2936  # setup customers
2937  if (@{ $form->{"all_$form->{vc}"} }) {
2938    $form->{"select$form->{vc}"} = "\n";
2939    for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|$_->{name}--$_->{id}\n| }
2940    delete $form->{"all_$form->{vc}"};
2941  }
2942
2943  $vc = qq|
2944              <tr>
2945	        <th align=right nowrap>$vcname</th>
2946|;
2947
2948  if ($form->{"select$form->{vc}"}) {
2949    $vc .= qq|
2950                <td><select name="$form->{vc}">|.$form->select_option($form->{"select$form->{vc}"}, $form->{$form->{vc}}, 1).qq|</select>
2951		</td>
2952              </tr>
2953|;
2954  } else {
2955    $vc .= qq|
2956               <td><input name="$form->{vc}" value="$form->{$form->{vc}}" size=35>
2957	       </td>
2958	     </tr>
2959	     <tr>
2960	       <th align=right nowrap>$vcnumber</th>
2961	       <td><input name="$form->{vc}number" value="$form->{"$form->{vc}number"}" size=35></td>
2962	     </tr>
2963|;
2964  }
2965
2966
2967  if (@{ $form->{all_years} }) {
2968    # accounting years
2969    $selectaccountingyear = "\n";
2970    for (@{ $form->{all_years} }) { $selectaccountingyear .= qq|$_\n| }
2971    $selectaccountingmonth = "\n";
2972    for (sort keys %{ $form->{all_month} }) { $selectaccountingmonth .= qq|$_--|.$locale->text($form->{all_month}{$_}).qq|\n| }
2973
2974    $selectfrom = qq|
2975      <tr>
2976	<th align=right>|.$locale->text('Period').qq|</th>
2977	<td>
2978	<select name=month>|.$form->select_option($selectaccountingmonth, undef, 1, 1).qq|</select>
2979	<select name=year>|.$form->select_option($selectaccountingyear).qq|</select>
2980	<input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
2981	<input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
2982	<input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
2983	<input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
2984	</td>
2985      </tr>
2986|;
2987  }
2988
2989  $form->{title} = $locale->text('Sales Order Requirements');
2990
2991  $form->helpref("so_requirements", $myconfig{countrycode});
2992
2993  $form->{sort} = "partnumber";
2994  $form->{nextsub} = "so_requirements_report";
2995
2996  $form->header;
2997
2998  &calendar;
2999
3000  print qq|
3001<body>
3002
3003<form method="post" name="main" action="$form->{script}">
3004
3005|;
3006
3007  print qq|
3008
3009<table width="100%">
3010
3011  <tr><th class=listtop>$form->{helpref}$form->{title}</a></th></tr>
3012  <tr height="5"></tr>
3013  <tr valign=top>
3014    <td>
3015      <table>
3016        <tr>
3017          <th align=right nowrap>|.$locale->text('Number').qq|</th>
3018          <td><input name=partnumber size=20></td>
3019        </tr>
3020        <tr>
3021          <th align=right nowrap>|.$locale->text('Description').qq|</th>
3022          <td><input name=description size=40></td>
3023        </tr>
3024	<tr>
3025	  $vc
3026	</tr>
3027	<tr>
3028	  <th align=right nowrap>|.$locale->text('From').qq|</th>
3029	  <td colspan=3 nowrap><input name=reqdatefrom size=11 class=date title="$myconfig{dateformat}"><b>|.&js_calendar("main", "reqdatefrom").qq|<b>|.$locale->text('To').qq| <input name=reqdateto size=11 class=date title="$myconfig{dateformat}">|.&js_calendar("main", "reqdateto").qq|</td>
3030	</tr>
3031	  $selectfrom
3032	<tr>
3033	  <td></td>
3034	  <td>
3035	  <input name=searchitems class=radio type=radio value=all checked>
3036	  <b>|.$locale->text('All').qq|</b>
3037	  <input name=searchitems class=radio type=radio value=part>
3038	  <b>|.$locale->text('Parts').qq|</b>
3039	  <input name=searchitems class=radio type=radio value=assembly>
3040	  <b>|.$locale->text('Assemblies').qq|</b>
3041	  <input name=searchitems class=radio type=radio value=kit>
3042	  <b>|.$locale->text('Kits').qq|</b>
3043	  <input name=searchitems class=radio type=radio value=service>
3044	  <b>|.$locale->text('Services').qq|</b>
3045	  </td>
3046      </table>
3047    </td>
3048  </tr>
3049  <tr>
3050    <td><hr size=3 noshade></td>
3051  </tr>
3052</table>
3053<br>
3054<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">|;
3055
3056  $form->hide_form(qw(sort nextsub vc path login));
3057
3058  if ($form->{menubar}) {
3059    require "$form->{path}/menu.pl";
3060    &menubar;
3061  }
3062
3063  print qq|
3064</form>
3065
3066</body>
3067</html>
3068|;
3069
3070}
3071
3072
3073sub so_requirements_report {
3074
3075  if ($form->{$form->{vc}}) {
3076    ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}});
3077  }
3078
3079  $form->{title} = $locale->text('Sales Order Requirements');
3080
3081  IC->so_requirements(\%myconfig, \%$form);
3082
3083  $href = "$form->{script}?action=so_requirements_report";
3084  for (qw(searchitems vc direction oldsort path login)) { $href .= qq|&$_=$form->{$_}| }
3085
3086  $form->sort_order();
3087
3088  $callback = "$form->{script}?action=so_requirements_report";
3089  for (qw(searchitems vc direction oldsort path login)) { $callback .= qq|&$_=$form->{$_}| }
3090
3091
3092  if ($form->{$form->{vc}}) {
3093    $callback .= "&$form->{vc}=".$form->escape($form->{$form->{vc}},1).qq|--$form->{"$form->{vc}_id"}|;
3094    $href .= "&$form->{vc}=".$form->escape($form->{$form->{vc}}).qq|--$form->{"$form->{vc}_id"}|;
3095    $option .= "\n<br>" if ($option);
3096    $name = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor');
3097    $option .= "$name : $form->{$form->{vc}}";
3098  }
3099  if ($form->{"$form->{vc}number"}) {
3100    $callback .= "&$form->{vc}number=".$form->escape($form->{"$form->{vc}number"},1);
3101    $href .= "&$form->{vc}number=".$form->escape($form->{"$form->{vc}number"});
3102    $option .= "\n<br>" if ($option);
3103    $name = ($form->{vc} eq 'customer') ? $locale->text('Customer Number') : $locale->text('Vendor Number');
3104    $option .= qq|$name : $form->{"$form->{vc}number"}|;
3105  }
3106
3107  if ($form->{partnumber}) {
3108    $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
3109    $href .= "&partnumber=".$form->escape($form->{partnumber});
3110    $option .= "\n<br>" if ($option);
3111    $option .= $locale->text('Number')." : $form->{partnumber}";
3112  }
3113  if ($form->{description}) {
3114    $callback .= "&description=".$form->escape($form->{description},1);
3115    $href .= "&description=".$form->escape($form->{description});
3116    $option .= "\n<br>" if ($option);
3117    $option .= $locale->text('Description')." : $form->{description}";
3118  }
3119
3120  if ($form->{reqdatefrom}) {
3121    $callback .= "&reqdatefrom=$form->{reqdatefrom}";
3122    $href .= "&reqdatefrom=$form->{reqdatefrom}";
3123    $option .= "\n<br>" if ($option);
3124    $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{reqdatefrom}, 1);
3125  }
3126  if ($form->{reqdateto}) {
3127    $callback .= "&reqdateto=$form->{reqdateto}";
3128    $href .= "&reqdateto=$form->{reqdateto}";
3129    $option .= "\n<br>" if ($option);
3130    $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{reqdateto}, 1);
3131  }
3132
3133  @column_index = $form->sort_columns(qw(reqdate id ordnumber name customernumber partnumber description qty));
3134
3135  $name = $locale->text('Customer');
3136  $namenumber = $locale->text('Customer Number');
3137  $namefld = "customernumber";
3138
3139  $column_data{reqdate} = "<th><a class=listheading href=$href&sort=reqdate>".$locale->text('Required by')."</a></th>";
3140  $column_data{ordnumber} = "<th><a class=listheading href=$href&sort=ordnumber>".$locale->text('Order')."</a></th>";
3141  $column_data{name} = "<th><a class=listheading href=$href&sort=name>$name</a></th>";
3142  $column_data{$namefld} = "<th><a class=listheading href=$href&sort=$namefld>$namenumber</a></th>";
3143  $column_data{partnumber} = "<th><a class=listheading href=$href&sort=partnumber>" . $locale->text('Part Number') . "</a></th>";
3144  $column_data{description} = "<th><a class=listheading href=$href&sort=description>" . $locale->text('Description') . "</a></th>";
3145  $column_data{qty} = "<th class=listheading>" . $locale->text('Qty') . "</th>";
3146
3147  $title = "$form->{title} / $form->{company}";
3148
3149  $form->helpref("so_requirements_report", $myconfig{countrycode});
3150
3151  $form->header;
3152
3153  print qq|
3154<body>
3155
3156<table width=100%>
3157  <tr>
3158    <th class=listtop>$form->{helpref}$title</a></th>
3159  </tr>
3160  <tr height="5"></tr>
3161  <tr>
3162    <td>$option</td>
3163  </tr>
3164  <tr>
3165    <td>
3166      <table width=100%>
3167	<tr class=listheading>
3168|;
3169
3170  for (@column_index) { print "\n$column_data{$_}" }
3171
3172  print qq|
3173	</tr>
3174|;
3175
3176
3177  # add sort and escape callback, this one we use for the add sub
3178  $form->{callback} = $callback .= "&sort=$form->{sort}";
3179
3180  # escape callback for href
3181  $callback = $form->escape($callback);
3182
3183  $i = 0;
3184  foreach $ref (@{ $form->{all_parts} }) {
3185
3186    $i++;
3187
3188    $column_data{qty} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{qty}, undef, "&nbsp;")."</td>";
3189
3190    $column_data{ordnumber} = "<td><a href=oe.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&type=sales_order&callback=$callback>$ref->{ordnumber}&nbsp;</a></td>";
3191
3192    $ref->{description} =~ s/\r?\n/<br>/g;
3193    $column_data{reqdate} = "<td nowrap>$ref->{reqdate}</td>";
3194    $column_data{description} = "<td>$ref->{description}</td>";
3195
3196    $column_data{partnumber} = qq|<td><a href=ic.pl?path=$form->{path}&login=$form->{login}&action=edit&id=$ref->{parts_id}&callback=$callback>$ref->{partnumber}</a></td>|;
3197
3198    $column_data{name} = qq|<td><a href=ct.pl?path=$form->{path}&login=$form->{login}&action=edit&id=$ref->{"$form->{vc}_id"}&db=$form->{vc}&callback=$callback>$ref->{name}</a></td>|;
3199
3200    $column_data{$namefld} = qq|<td>$ref->{$namefld}&nbsp;</td>|;
3201
3202    $j++; $j %= 2;
3203
3204    print "
3205        <tr class=listrow$j>
3206";
3207
3208    for (@column_index) { print "\n$column_data{$_}" }
3209
3210    print qq|
3211        </tr>
3212|;
3213  }
3214
3215  print qq|
3216	</tr>
3217      </table>
3218    </td>
3219  </tr>
3220  <tr>
3221    <td><hr size=3 noshade></td>
3222  </tr>
3223</table>
3224
3225</body>
3226</html>
3227|;
3228
3229
3230}
3231
3232
3233sub makemodel_row {
3234  my ($numrows) = @_;
3235
3236  for (qw(make model)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
3237
3238  print qq|
3239  <tr>
3240    <td>
3241      <table width=100%>
3242	<tr>
3243	  <th class="listheading">|.$locale->text('Make').qq|</th>
3244	  <th class="listheading">|.$locale->text('Model').qq|</th>
3245	</tr>
3246|;
3247
3248  for $i (1 .. $numrows) {
3249    print qq|
3250	<tr>
3251	  <td><input name="make_$i" size=30 value="|.$form->quote($form->{"make_$i"}).qq|"></td>
3252	  <td><input name="model_$i" size=30 value="|.$form->quote($form->{"model_$i"}).qq|"></td>
3253	</tr>
3254|;
3255  }
3256
3257  print qq|
3258      </table>
3259    </td>
3260  </tr>
3261|;
3262
3263}
3264
3265
3266sub vendor_row {
3267  my ($numrows) = @_;
3268
3269  $currency = qq|
3270	  <th class="listheading">|.$locale->text('Curr').qq|</th>| if $form->{selectcurrency};
3271
3272  print qq|
3273  <tr>
3274    <td>
3275      <table width=100%>
3276	<tr>
3277	  <th class="listheading">|.$locale->text('Vendor').qq|</th>
3278	  <th class="listheading">|.$locale->text('Number').qq|</th>
3279	  <th class="listheading">|.$locale->text('Cost').qq|</th>
3280	  $currency
3281	  <th class="listheading">|.$locale->text('Leadtime').qq|</th>
3282	</tr>
3283|;
3284
3285  for $i (1 .. $numrows) {
3286
3287    if ($form->{selectcurrency}) {
3288      $currency = qq|
3289	  <td><select name="vendorcurr_$i">|
3290	  .$form->select_option($form->{selectcurrency}, $form->{"vendorcurr_$i"})
3291	  .qq|</select></td>|;
3292    }
3293
3294    if ($i == $numrows) {
3295
3296      $vendor = qq|
3297          <td><input name="vendor_$i" size=35 value="|.$form->quote($form->{"vendor_$i"}).qq|"></td>
3298|;
3299
3300      if ($form->{selectvendor}) {
3301	$vendor = qq|
3302	  <td width=99%><select name="vendor_$i">|.$form->select_option($form->{selectvendor}, undef, 1).qq|</select></td>
3303|;
3304      }
3305
3306    } else {
3307
3308      $form->hide_form("vendor_$i");
3309
3310      ($vendor) = split /--/, $form->{"vendor_$i"};
3311      $vendor = qq|
3312          <td>$vendor</td>
3313|;
3314    }
3315
3316    $s = length $form->{"partnumber_$i"};
3317    $s = ($s > 20) ? $s : 20;
3318    $fld{partnumber} = qq|<input name="partnumber_$i" value="|.$form->quote($form->{"partnumber_$i"}).qq|" size=$s>|;
3319
3320
3321    print qq|
3322	<tr>
3323	  $vendor
3324	  <td>$fld{partnumber}</td>
3325	  <td><input name="lastcost_$i" class="inputright" size=11 value=|.$form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $form->{decimalplacescost}).qq|></td>
3326	  $currency
3327	  <td nowrap><input name="leadtime_$i" class="inputright" size=5 value=|.$form->format_amount(\%myconfig, $form->{"leadtime_$i"}).qq|> <b>|.$locale->text('days').qq|</b></td>
3328	</tr>
3329|;
3330
3331  }
3332
3333  print qq|
3334      </table>
3335    </td>
3336  </tr>
3337|;
3338
3339}
3340
3341
3342sub customer_row {
3343  my ($numrows) = @_;
3344
3345  if ($form->{selectpricegroup}) {
3346    $pricegroup = qq|
3347          <th class="listheading">|.$locale->text('Pricegroup').qq|
3348          </th>
3349|;
3350  }
3351
3352  $currency = qq|<th class="listheading">|.$locale->text('Curr').qq|</th>| if $form->{selectcurrency};
3353
3354  print qq|
3355  <tr>
3356    <td>
3357      <table width=100%>
3358	<tr>
3359	  <th class="listheading">|.$locale->text('Customer').qq|</th>
3360	  $pricegroup
3361	  <th class="listheading">|.$locale->text('Break').qq|</th>
3362	  <th class="listheading">|.$locale->text('Sell Price').qq|</th>
3363	  $currency
3364	  <th class="listheading">|.$locale->text('From').qq|</th>
3365	  <th class="listheading">|.$locale->text('To').qq|</th>
3366	</tr>
3367|;
3368
3369  for $i (1 .. $numrows) {
3370
3371    if ($form->{selectcurrency}) {
3372      $currency = qq|
3373	  <td><select name="customercurr_$i">|
3374	  .$form->select_option($form->{selectcurrency}, $form->{"customercurr_$i"})
3375	  .qq|</select></td>|;
3376    }
3377
3378    if ($i == $numrows) {
3379      $customer = qq|
3380          <td><input name="customer_$i" size=35 value="|.$form->quote($form->{"customer_$i"}).qq|"></td>
3381	  |;
3382
3383      if ($form->{selectcustomer}) {
3384	$customer = qq|
3385	  <td><select name="customer_$i">|.$form->select_option($form->{selectcustomer}, undef, 1).qq|</select></td>
3386|;
3387      }
3388
3389      if ($form->{selectpricegroup}) {
3390	$pricegroup = qq|
3391	  <td><select name="pricegroup_$i">|.$form->select_option($form->{selectpricegroup}, undef, 1).qq|</select></td>
3392|;
3393      }
3394
3395    } else {
3396      ($customer) = split /--/, $form->{"customer_$i"};
3397      $customer = qq|
3398          <td>$customer</td>|.$form->hide_form("customer_$i");
3399
3400      if ($form->{selectpricegroup}) {
3401	($pricegroup) = split /--/, $form->{"pricegroup_$i"};
3402	$pricegroup = qq|
3403	  <td>$pricegroup</td>|.$form->hide_form("pricegroup_$i");
3404      }
3405    }
3406
3407
3408    print qq|
3409	<tr>
3410	  $customer
3411	  $pricegroup
3412
3413	  <td><input name="pricebreak_$i" class="inputright" size=5 value=|.$form->format_amount(\%myconfig, $form->{"pricebreak_$i"}).qq|></td>
3414	  <td><input name="customerprice_$i" class="inputright" size=11 value=|.$form->format_amount(\%myconfig, $form->{"customerprice_$i"}, $form->{decimalplacessell}).qq|></td>
3415	  $currency
3416	  <td><input name="validfrom_$i" size=11 class=date title="$myconfig{dateformat}" value=$form->{"validfrom_$i"}>|.&js_calendar("main", "validfrom_$i").qq|</td>
3417	  <td><input name="validto_$i" size=11 class=date title="$myconfig{dateformat}" value=$form->{"validto_$i"}>|.&js_calendar("main", "validto_$i").qq|</td>
3418	</tr>
3419|;
3420  }
3421
3422  print qq|
3423      </table>
3424    </td>
3425  </tr>
3426|;
3427
3428}
3429
3430
3431
3432sub assembly_row {
3433  my ($numrows) = @_;
3434
3435  @column_index = qw(runningnumber qty unit onhand bom adj partnumber description sellprice listprice lastcost);
3436
3437  $form->{sellprice} = 0;
3438  $form->{listprice} = 0;
3439  $form->{lastcost} = 0;
3440  $form->{weight} = 0;
3441
3442  $column_data{runningnumber} = qq|<th nowrap width=5%>|.$locale->text('Item').qq|</th>|;
3443  $column_data{qty} = qq|<th align=left nowrap width=10%>|.$locale->text('Qty').qq|</th>|;
3444  $column_data{unit} = qq|<th align=left nowrap width=5%>|.$locale->text('Unit').qq|</th>|;
3445  $column_data{partnumber} = qq|<th align=left nowrap width=20%>|.$locale->text('Number').qq|</th>|;
3446  $column_data{description} = qq|<th nowrap width=50%>|.$locale->text('Description').qq|</th>|;
3447  $column_data{sellprice} = qq|<th align=right nowrap>|.$locale->text('Sell').qq|</th>|;
3448  $column_data{listprice} = qq|<th align=right nowrap>|.$locale->text('List').qq|</th>|;
3449  $column_data{lastcost} = qq|<th align=right nowrap>|.$locale->text('Cost').qq|</th>|;
3450  $column_data{bom} = qq|<th>|.$locale->text('BOM').qq|</th>|;
3451  $column_data{adj} = qq|<th>|.$locale->text('A').qq|</th>|;
3452  $column_data{onhand} = qq|<th>|.$locale->text('OH').qq|</th>|;
3453
3454  print qq|
3455  <tr>
3456    <td>
3457      <table width="100%">
3458      <tr class=listheading>
3459	<th class=listheading>|.$locale->text('Individual Items').qq|</th>
3460      </tr>
3461      <tr>
3462	<td>
3463	  <table width="100%">
3464	    <tr>
3465|;
3466
3467  for (@column_index) { print "\n$column_data{$_}" }
3468
3469  print qq|
3470        </tr>
3471|;
3472
3473  for $i (1 .. $numrows) {
3474    for (qw(partnumber description)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
3475
3476    $linetotalsellprice = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, $form->{decimalplacessell});
3477    $form->{sellprice} += $linetotalsellprice;
3478
3479    $linetotallistprice = $form->round_amount($form->{"listprice_$i"} * $form->{"qty_$i"}, $form->{decimalplacessell});
3480    $form->{listprice} += $linetotallistprice;
3481
3482    $linetotallastcost = $form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"}, $form->{decimalplacescost});
3483    $form->{lastcost} += $linetotallastcost;
3484
3485    if ($i == $numrows) {
3486      $linetotalsellprice = $linetotallistprice = $linetotallastcost = "";
3487
3488      for (qw(runningnumber unit onhand bom adj)) { $column_data{$_} = qq|<td></td>| }
3489
3490      if ($form->{changeup}) {
3491        $column_data{qty} = qq|<td><input name="qty_$i" class="inputright" size=6 value="$form->{"qty_$i"}" accesskey="$i" title="[$i]"></td>|;
3492        $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15></td>|;
3493        $column_data{description} = qq|<td><input name="description_$i" size=30></td>|;
3494      } else {
3495        if ($form->{orphaned}) {
3496          $column_data{qty} = qq|<td><input name="qty_$i" class="inputright" size=6 value="$form->{"qty_$i"}" accesskey="$i" title="[$i]"></td>|;
3497          $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15></td>|;
3498          $column_data{description} = qq|<td><input name="description_$i" size=30></td>|;
3499        } else {
3500          for (qw(qty partnumber description)) { $column_data{$_} = qq|<td></td>| }
3501        }
3502      }
3503
3504    } else {
3505
3506      $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
3507
3508      $linetotalsellprice = $form->format_amount(\%myconfig, $linetotalsellprice, $form->{decimalplacessell}, 0);
3509      $linetotallistprice = $form->format_amount(\%myconfig, $linetotallistprice, $form->{decimalplacessell}, 0);
3510      $linetotallastcost = $form->format_amount(\%myconfig, $linetotallastcost, $form->{decimalplacescost}, 0);
3511
3512      $column_data{partnumber} = qq|<td><a href="$form->{script}?login=$form->{login}&path=$form->{path}&action=edit&id=$form->{"id_$i"}" target=_blank>$form->{"partnumber_$i"}</a></td>|;
3513
3514      $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" class="inputright" size=3 value="$i"></td>|;
3515
3516      if ($form->{changeup}) {
3517        $column_data{qty} = qq|<td><input name="qty_$i" class="inputright" size=6 value="$form->{"qty_$i"}" accesskey="$i" title="[$i]"></td>|;
3518      } else {
3519        if ($form->{orphaned}) {
3520          $column_data{qty} = qq|<td><input name="qty_$i" class="inputright" size=6 value="$form->{"qty_$i"}" accesskey="$i" title="[$i]"></td>|;
3521        } else {
3522          $column_data{qty} = qq|<td>$form->{"qty_$i"}</td>|;
3523          $form->hide_form("qty_$i");
3524        }
3525      }
3526
3527      for (qw(bom adj)) { $form->{"${_}_$i"} = ($form->{"${_}_$i"}) ? "checked" : "" }
3528      $column_data{bom} = qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
3529      $column_data{adj} = qq|<td align=center><input name="adj_$i" type=checkbox class=checkbox value=1 $form->{"adj_$i"}></td>|;
3530
3531      $column_data{unit} = qq|<td>$form->{"unit_$i"}</td>|;
3532      $column_data{onhand} = qq|<td>|.$form->format_amount(\%myconfig, $form->{"onhand_$i"}).qq|</td>|;
3533      $column_data{description} = qq|<td>$form->{"description_$i"}</td>|;
3534
3535      $form->hide_form(map { "${_}_$i" } qw(partnumber description unit onhand));
3536    }
3537
3538    $column_data{sellprice} = qq|<td align=right>$linetotalsellprice</td>|;
3539    $column_data{listprice} = qq|<td align=right>$linetotallistprice</td>|;
3540    $column_data{lastcost} = qq|<td align=right>$linetotallastcost</td>|;
3541
3542    print qq|
3543        <tr valign=top>|;
3544
3545    for (@column_index) { print "\n$column_data{$_}" }
3546
3547    print qq|
3548        </tr>
3549|;
3550    $form->hide_form(map { "${_}_$i" } qw(id sellprice listprice lastcost weight assembly));
3551
3552  }
3553
3554  for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
3555
3556  $column_data{sellprice} = "<th align=right>".$form->format_amount(\%myconfig, $form->{sellprice}, $form->{decimalplacessell})."</th>";
3557  $column_data{listprice} = "<th align=right>".$form->format_amount(\%myconfig, $form->{listprice}, $form->{decimalplacessell})."</th>";
3558  $column_data{lastcost} = "<th align=right>".$form->format_amount(\%myconfig, $form->{lastcost}, $form->{decimalplacescost})."</th>";
3559
3560  print qq|
3561        <tr>|;
3562
3563  for (@column_index) { print "\n$column_data{$_}" }
3564
3565  print qq|
3566	      </tr>
3567	    </table>
3568	  </td>
3569	</tr>
3570      </table>
3571    </td>
3572  </tr>
3573|;
3574
3575  $form->hide_form(qw(assembly_rows));
3576
3577}
3578
3579
3580sub update {
3581
3582  if (($form->{partsgroup} ne $form->{oldpartsgroup}) || ($form->{partsgroupcode} ne $form->{oldpartsgroupcode})) {
3583    if ($form->{partsgroupcode} ne $form->{oldpartsgroupcode}) {
3584      $form->{partsgroup} = "";
3585      $form->{oldpartsgroup} = "";
3586      $form->{oldpartsgroupcode} = "";
3587    }
3588    if ($form->{partsgroup} ne $form->{oldpartsgroup}) {
3589      $form->{partsgroupcode} = "";
3590      $form->{oldpartsgroupcode} = "";
3591    }
3592
3593    $form->get_partsgroup(\%myconfig, { all => 1 });
3594    if (@{ $form->{all_partsgroup} }) {
3595      $form->{selectpartsgroup} = qq|\n|;
3596
3597      for (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} .= qq|$_->{partsgroup}--$_->{id}\n| }
3598      delete $form->{all_partsgroup};
3599    }
3600    $form->{selectpartsgroup} = $form->escape($form->{selectpartsgroup},1);
3601    $form->{oldpartsgroup} = $form->{partsgroup};
3602  }
3603
3604
3605  if ($form->{item} =~ /(assembly|kit)/) {
3606
3607    $i = $form->{assembly_rows};
3608
3609    # if last row is empty check the form otherwise retrieve item
3610    if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "")) {
3611
3612      &check_form;
3613
3614    } else {
3615
3616      IC->assembly_item(\%myconfig, \%$form);
3617
3618      $rows = scalar @{ $form->{item_list} };
3619
3620      if ($rows) {
3621	$form->{"adj_$i"} = 1;
3622
3623	if ($rows > 1) {
3624	  $form->{makemodel_rows}--;
3625	  $form->{customer_rows}--;
3626	  &select_item;
3627	  exit;
3628	} else {
3629	  $form->{"qty_$i"} = 1;
3630          $form->{"bom_$i"} = 1 if $form->{item} eq 'kit';
3631	  for (qw(partnumber description unit)) { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) }
3632	  for (keys %{ $form->{item_list}[0] }) { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
3633
3634	  $form->{"runningnumber_$i"} = $form->{assembly_rows};
3635	  $form->{assembly_rows}++;
3636
3637	  &check_form;
3638
3639	}
3640
3641      } else {
3642
3643        $form->{rowcount} = $i;
3644	$form->{assembly_rows}++;
3645
3646	&new_item;
3647
3648      }
3649    }
3650
3651  } else {
3652
3653    &check_form;
3654
3655  }
3656
3657}
3658
3659
3660sub check_vendor {
3661
3662  @flds = qw(vendor partnumber lastcost leadtime vendorcurr);
3663  @f = ();
3664  $count = 0;
3665
3666  for (qw(lastcost leadtime)) { $form->{"${_}_$form->{vendor_rows}"} = $form->parse_amount(\%myconfig, $form->{"${_}_$form->{vendor_rows}"}) }
3667
3668  for $i (1 .. $form->{vendor_rows} - 1) {
3669
3670    for (qw(lastcost leadtime)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
3671
3672    if ($form->{"lastcost_$i"} || $form->{"partnumber_$i"}) {
3673
3674      push @f, {};
3675      $j = $#f;
3676      for (@flds) { $f[$j]->{$_} = $form->{"${_}_$i"} }
3677      $count++;
3678
3679    }
3680  }
3681
3682  $i = $form->{vendor_rows};
3683
3684  if (!$form->{selectvendor}) {
3685
3686    if ($form->{"vendor_$i"} && !$form->{"vendor_id_$i"}) {
3687      ($form->{vendor}) = split /--/, $form->{"vendor_$i"};
3688      if (($j = $form->get_name(\%myconfig, vendor)) > 1) {
3689	&select_name(vendor, $i);
3690	exit;
3691      }
3692
3693      if ($j == 1) {
3694	# we got one name
3695	$form->{"vendor_$i"} = qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|;
3696      } else {
3697	# name is not on file
3698	$form->error(qq|$form->{"vendor_$i"} : |.$locale->text('Vendor not on file!'));
3699      }
3700    }
3701  }
3702
3703  if ($form->{"vendor_$i"}) {
3704    push @f, {};
3705    $j = $#f;
3706    for (@flds) { $f[$j]->{$_} = $form->{"${_}_$i"} }
3707    $count++;
3708  }
3709
3710  $form->redo_rows(\@flds, \@f, $count, $form->{vendor_rows});
3711  $form->{vendor_rows} = $count;
3712
3713}
3714
3715
3716sub check_customer {
3717
3718  @flds = qw(customer validfrom validto pricebreak customerprice pricegroup customercurr);
3719  @f = ();
3720  $count = 0;
3721
3722  for (qw(customerprice pricebreak)) { $form->{"${_}_$form->{customer_rows}"} = $form->parse_amount(\%myconfig, $form->{"${_}_$form->{customer_rows}"}) }
3723
3724  for $i (1 .. $form->{customer_rows} - 1) {
3725
3726    for (qw(customerprice pricebreak)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
3727
3728    if ($form->{"customerprice_$i"}) {
3729      if ($form->{"pricebreak_$i"} || $form->{"customer_$i"} || $form->{"pricegroup_$i"}) {
3730
3731	push @f, {};
3732	$j = $#f;
3733	for (@flds) { $f[$j]->{$_} = $form->{"${_}_$i"} }
3734	$count++;
3735
3736      }
3737    }
3738  }
3739
3740  $i = $form->{customer_rows};
3741
3742  if (!$form->{selectcustomer}) {
3743
3744    if ($form->{"customer_$i"} && !$form->{"customer_id_$i"}) {
3745      ($form->{customer}) = split /--/, $form->{"customer_$i"};
3746
3747      if (($j = $form->get_name(\%myconfig, customer)) > 1) {
3748	&select_name(customer, $i);
3749	exit;
3750      }
3751
3752      if ($j == 1) {
3753	# we got one name
3754	$form->{"customer_$i"} = qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|;
3755      } else {
3756	# name is not on file
3757	$form->error(qq|$form->{customer} : |.$locale->text('Customer not on file!'));
3758      }
3759    }
3760  }
3761
3762  if ($form->{"customer_$i"} || $form->{"pricegroup_$i"} || ($form->{"customerprice_$i"} || $form->{"pricebreak_$i"})) {
3763    push @f, {};
3764    $j = $#f;
3765    for (@flds) { $f[$j]->{$_} = $form->{"${_}_$i"} }
3766    $count++;
3767  }
3768
3769  $form->redo_rows(\@flds, \@f, $count, $form->{customer_rows});
3770  $form->{customer_rows} = $count;
3771
3772}
3773
3774
3775
3776sub select_name {
3777  my ($table, $vr) = @_;
3778
3779  @column_index = (ndx, name, "${table}number", address);
3780
3781# $locale->text('Customer Number')
3782# $locale->text('Vendor Number')
3783
3784  $label = ucfirst $table;
3785  $labelnumber = $locale->text("$label Number");
3786
3787  $column_data{ndx} = qq|<th class=listheading width=1%>&nbsp;</th>|;
3788  $column_data{name} = qq|<th class=listheading>|.$locale->text($label).qq|</th>|;
3789  $column_data{"${table}number"} = qq|<th class=listheading>|.$locale->text($labelnumber).qq|</th>|;
3790  $column_data{address} = qq|<th class=listheading colspan=5>|.$locale->text('Address').qq|</th>|;
3791
3792  $helpref = $form->{helpref};
3793  $form->helpref("select_name", $myconfig{countrycode});
3794
3795  # list items with radio button on a form
3796  $form->header;
3797
3798  $title = $locale->text('Select from one of the names below');
3799
3800  print qq|
3801<body>
3802
3803<form method=post action="$form->{script}">
3804
3805<input type=hidden name=vr value=$vr>
3806
3807<table width=100%>
3808  <tr>
3809    <th class=listtop>$form->{helpref}$title</a></th>
3810  </tr>
3811  <tr space=5></tr>
3812  <tr>
3813    <td>
3814      <table width=100%>
3815	<tr class=listheading>|;
3816
3817  for (@column_index) { print "\n$column_data{$_}" }
3818
3819  print qq|
3820	</tr>
3821|;
3822
3823  @column_index = (ndx, name, "${table}number", address, city, state, zipcode, country);
3824
3825  my $i = 0;
3826  foreach $ref (@{ $form->{name_list} }) {
3827    $checked = ($i++) ? "" : "checked";
3828
3829    $ref->{name} = $form->quote($ref->{name});
3830
3831   $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
3832   $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="|.$form->quote($ref->{name}).qq|">$ref->{name}</td>|;
3833   $column_data{"${table}number"} = qq|<td>$ref->{"${table}number"}</td>|;
3834   $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}|;
3835   for (qw(city state zipcode country)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
3836
3837    $j++; $j %= 2;
3838    print qq|
3839	<tr class=listrow$j>|;
3840
3841    for (@column_index) { print "\n$column_data{$_}" }
3842
3843    print qq|
3844	</tr>
3845
3846<input name="new_id_$i" type=hidden value=$ref->{id}>
3847
3848|;
3849
3850  }
3851
3852  print qq|
3853      </table>
3854    </td>
3855  </tr>
3856  <tr>
3857    <td><hr size=3 noshade></td>
3858  </tr>
3859</table>
3860
3861<input name=lastndx type=hidden value=$i>
3862
3863|;
3864
3865  # delete variables
3866  for (qw(action nextsub name_list)) { delete $form->{$_} }
3867  $form->{helpref} = $helpref;
3868
3869  $form->hide_form;
3870
3871  print qq|
3872<input type=hidden name=nextsub value=name_selected>
3873<input type=hidden name=vc value=$table>
3874<br>
3875<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
3876</form>
3877
3878</body>
3879</html>
3880|;
3881
3882}
3883
3884
3885
3886sub name_selected {
3887
3888  # replace the variable with the one checked
3889
3890  # index for new item
3891  $i = $form->{ndx};
3892
3893  $form->{"$form->{vc}_$form->{vr}"} = qq|$form->{"new_name_$i"}--$form->{"new_id_$i"}|;
3894  $form->{"$form->{vc}_id_$form->{vr}"} = $form->{"new_id_$i"};
3895
3896  # delete all the new_ variables
3897  for $i (1 .. $form->{lastndx}) {
3898    for (qw(id name)) { delete $form->{"new_${_}_$i"} }
3899  }
3900
3901  for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
3902
3903  &update;
3904
3905}
3906
3907
3908sub save {
3909
3910  $olditem = $form->{id};
3911
3912  $form->{userspath} = $userspath;
3913
3914  # save part
3915  $rc = IC->save(\%myconfig, \%$form);
3916
3917  $parts_id = $form->{id};
3918
3919  # load previous variables
3920  if ($form->{previousform} && !$form->{callback}) {
3921    # save the new form variables before splitting previousform
3922    for (keys %$form) { $newform{$_} = $form->{$_} }
3923
3924    $previousform = $form->unescape($form->{previousform});
3925
3926    # don't trample on previous variables
3927    for (keys %newform) { delete $form->{$_} }
3928
3929    # now take it apart and restore original values
3930    foreach $item (split /&/, $previousform) {
3931      ($key, $value) = split /=/, $item, 2;
3932      $value =~ s/%26/&/g;
3933      $form->{$key} = $value;
3934    }
3935
3936    if ($form->{item} =~ /(assembly|kit)/) {
3937
3938      # undo number formatting
3939      for (qw(weight listprice sellprice lastcost rop onhand)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
3940
3941      $form->{assembly_rows}-- if $olditem;
3942      $i = $newform{rowcount};
3943      $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
3944
3945      $form->{listprice} -= $form->{"listprice_$i"} * $form->{"qty_$i"};
3946      $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
3947      $form->{lastcost} -= $form->{"lastcost_$i"} * $form->{"qty_$i"};
3948      $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
3949
3950      # change/add values for assembly item
3951      for (qw(partnumber description bin unit weight listprice sellprice lastcost)) { $form->{"${_}_$i"} = $newform{$_} }
3952
3953      foreach $item (qw(listprice sellprice lastcost)) {
3954	$form->{$item} += $form->{"${item}_$i"} * $form->{"qty_$i"};
3955	$form->{$item} = $form->round_amount($form->{$item}, $form->{precision});
3956      }
3957
3958      $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
3959
3960      if (!$olditem) {
3961        $form->{"adj_$i"} = 1;
3962        $form->{"bom_$i"} = 1 if $form->{item} eq 'kit';
3963      }
3964
3965      $form->{customer_rows}--;
3966
3967    } else {
3968      # set values for last invoice/order item
3969      $i = $form->{rowcount};
3970      $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
3971
3972      for (qw(partnumber description bin unit listprice sellprice partsgroup lot expires checkinventory)) { $form->{"${_}_$i"} = $newform{$_} }
3973      $form->{"itemnotes_$i"} = $newform{notes};
3974      for (qw(inventory income expense)) {
3975	$form->{"${_}_accno_id_$i"} = $newform{"IC_$_"};
3976	$form->{"${_}_accno_id_$i"} =~ s/--.*//;
3977      }
3978
3979      if ($form->{vendor_id}) {
3980	$form->{"sellprice_$i"} = $newform{lastcost};
3981
3982	for ($j = 1; $j <= $newform{vendor_rows}; $j++) {
3983	  # if vendor matches and there is a number
3984	  if ($newform{"vendor_$j"} && $newform{"vendor_$j"} eq $form->{oldvendor}) {
3985	    if ($newform{"partnumber_$j"}) {
3986	      $form->{"partnumber_$i"} = $newform{"partnumber_$j"};
3987	      $form->{"sku_$i"} = $form->{"partnumber_$i"};
3988	    }
3989	    $form->{"sellprice_$i"} = $newform{"lastcost_$j"};
3990	  }
3991	}
3992      }
3993
3994      if ($form->{exchangerate} != 0) {
3995	$form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"} / $form->{exchangerate}, $form->{precision});
3996      }
3997
3998      for (split / /, $newform{taxaccounts}) { $form->{"taxaccounts_$i"} .= "$_ " if ($newform{"IC_tax_$_"}) }
3999      chop $form->{"taxaccounts_$i"};
4000
4001      # credit remaining calculation
4002      $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
4003      for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
4004      if (!$form->{taxincluded}) {
4005	for (split / /, $form->{"taxaccounts_$i"}) { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
4006      }
4007
4008      $ml = 1;
4009      if ($form->{type} =~ /invoice/) {
4010	$ml = -1 if $form->{type} =~ /(debit|credit)_invoice/;
4011      }
4012      $form->{creditremaining} -= ($amount * $ml);
4013
4014    }
4015
4016    $form->{"id_$i"} = $parts_id;
4017    delete $form->{action};
4018
4019    # restore original callback
4020    $callback = $form->unescape($form->{callback});
4021    $form->{callback} = $form->unescape($form->{oldcallback});
4022    delete $form->{oldcallback};
4023
4024    $form->{makemodel_rows}--;
4025
4026    # put callback together
4027    foreach $key (keys %$form) {
4028      # do single escape for Apache 2.0
4029      $value = $form->escape($form->{$key}, 1);
4030      $callback .= qq|&$key=$value|;
4031    }
4032    $form->{callback} = $callback;
4033  }
4034
4035  # redirect
4036  $form->redirect($locale->text('Item saved!'));
4037
4038}
4039
4040
4041sub save_as_new {
4042
4043  $form->{id} = 0;
4044  &save;
4045
4046}
4047
4048
4049sub delete {
4050
4051  # redirect
4052  if (IC->delete(\%myconfig, \%$form)) {
4053    $form->redirect($locale->text('Item deleted!'));
4054  } else {
4055    $form->error($locale->text('Cannot delete item!'));
4056  }
4057
4058}
4059
4060
4061sub stock_adjustment {
4062
4063  $form->{title} = $locale->text('Stock Adjustment');
4064
4065  $form->helpref("stock_adjustment", $myconfig{countrycode});
4066
4067  $form->get_partsgroup(\%myconfig, { searchitems => 'noservice', subgroup => 1 });
4068
4069  if (@{ $form->{all_partsgroup} }) {
4070    $form->{selectpartsgroup} = "<option>\n";
4071    for (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| }
4072
4073    $partsgroup = qq|
4074 	<tr>
4075	  <th align=right nowrap>|.$locale->text('Group').qq|</th>
4076	  <td><select name=partsgroup>$form->{selectpartsgroup}</select></td>
4077	</tr>
4078|;
4079  }
4080
4081  $form->{sort} = "partnumber";
4082  $form->{nextsub} = "list_inventory";
4083
4084  $form->header;
4085
4086  print qq|
4087<body>
4088
4089<form method=post action=$form->{script}>
4090
4091<table width="100%">
4092  <tr>
4093    <th class=listtop>$form->{helpref}$form->{title}</a></th>
4094  </tr>
4095  <tr height="5"></tr>
4096  <tr valign=top>
4097    <td>
4098      <table>
4099        <tr>
4100          <th align="right" nowrap="true">|.$locale->text('Number').qq|</th>
4101          <td><input name=partnumber size=20></td>
4102          <td>&nbsp;</td>
4103        </tr>
4104        <tr>
4105          <th align="right" nowrap="true">|.$locale->text('Description').qq|</th>
4106          <td><input name=description size=40></td>
4107        </tr>
4108        $partsgroup
4109      </table>
4110    </td>
4111  </tr>
4112  <tr><td><hr size=3 noshade></td></tr>
4113</table>
4114<br>
4115<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
4116|;
4117
4118  $form->hide_form(qw(sort nextsub path login));
4119
4120  if ($form->{menubar}) {
4121    require "$form->{path}/menu.pl";
4122    &menubar;
4123  }
4124
4125  print qq|
4126</form>
4127
4128</body>
4129</html>
4130|;
4131
4132}
4133
4134
4135sub list_inventory {
4136
4137  IC->retrieve_items(\%myconfig, \%$form);
4138
4139  $form->sort_order();
4140
4141  $callback = "$form->{script}?action=list_inventory&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}";
4142
4143  $form->sort_order();
4144
4145  $href = "$form->{script}?action=list_inventory&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}";
4146
4147  for (qw(partnumber description partsgroup)) {
4148    if ($form->{$_}) {
4149      $callback .= "&$_=".$form->escape($form->{$_},1);
4150      $href .= "&$_=".$form->escape($form->{$_});
4151      $form->{sort} ||= "$_";
4152    }
4153  }
4154
4155  $column_data{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</th>|;
4156  $column_data{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</th>|;
4157  $column_data{bin} = qq|<th><a class=listheading href=$href&sort=bin>|.$locale->text('Bin').qq|</th>|;
4158  $column_data{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
4159  $column_data{rop} = qq|<th class=listheading>|.$locale->text('ROP').qq|</th>|;
4160  $column_data{warehouse} = qq|<th class=listheading>|.$locale->text('Warehouse').qq|</th>|;
4161
4162  @column_index = $form->sort_columns(qw(partnumber description warehouse bin rop onhand));
4163
4164  $form->{title} = $locale->text('Inventory Count');
4165
4166  $form->helpref("inventory_count", $myconfig{countrycode});
4167
4168  $form->header;
4169
4170  print qq|
4171<body>
4172
4173<form method=post action=$form->{script}>
4174
4175<table width=100%>
4176  <tr>
4177    <th class=listtop>$form->{helpref}$form->{title}</a></th>
4178  </tr>
4179  <tr size=5></tr>
4180  <tr>
4181    <td>
4182      <table width=100%>
4183	<tr class=listheading>
4184|;
4185
4186  for (@column_index) { print "\n$column_data{$_}" }
4187
4188  print qq|
4189	</tr>
4190|;
4191
4192  # add sort and escape callback
4193  $form->{callback} = $callback .= "&sort=$form->{sort}";
4194
4195  # escape callback for href
4196  $callback = $form->escape($callback);
4197
4198
4199  $i = 1;
4200  foreach $ref (@{ $form->{all_items} }) {
4201
4202    for (qw(partnumber description warehouse)) { $ref->{$_} = $form->quote($ref->{$_}) }
4203
4204    $column_data{partnumber} = "<td width=20%><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
4205
4206    $column_data{description} = qq|<td width=50%>$ref->{description}&nbsp;</td>|;
4207    $column_data{warehouse} = qq|<td>$ref->{warehouse}&nbsp;</td>|;
4208    $column_data{bin} = qq|<td>$ref->{bin}&nbsp;</td>|;
4209    $column_data{rop} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{rop}, undef, "&nbsp;").qq|</td>|;
4210
4211    $onhand = $form->format_amount(\%myconfig, $ref->{onhand});
4212
4213    $column_data{onhand} = qq|<td width=10%><input name="onhand_$i" class="inputright" size="8" value="$onhand"></td>|;
4214
4215
4216    $j++; $j %= 2;
4217    print qq|<tr class=listrow$j>
4218    <input name="id_$i" type="hidden" value="$ref->{id}">
4219    <input name="oldonhand_$i" type="hidden" value="$ref->{onhand}">
4220    <input name="warehouseid_$i" type="hidden" value="$ref->{warehouse_id}">
4221|;
4222
4223    for (@column_index) { print "\n$column_data{$_}" }
4224
4225    print qq|
4226	</tr>
4227|;
4228
4229    $i++;
4230
4231  }
4232
4233  $i--;
4234  print qq|
4235      </td>
4236    </table>
4237  <tr>
4238    <td><hr size=3 noshade>
4239  </tr>
4240</table>
4241|;
4242
4243  $form->hide_form(qw(path login callback));
4244
4245  print qq|
4246<input type=hidden name=rowcount value="$i">
4247<input type=hidden name=nextsub value=adjust_onhand>
4248
4249<br>
4250<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
4251
4252</form>
4253
4254</body>
4255</html>
4256|;
4257
4258}
4259
4260
4261sub adjust_onhand {
4262
4263  IC->adjust_onhand(\%myconfig, \%$form);
4264  $form->redirect($locale->text('Items stocked!'));
4265
4266}
4267
4268
4269sub stock_assembly {
4270
4271  $form->all_warehouses(\%myconfig);
4272
4273  if (@{ $form->{all_warehouse} }) {
4274    $selectwarehouse = "\n";
4275
4276    for (@{ $form->{all_warehouse} }) { $selectwarehouse .= qq|$_->{description}--$_->{id}\n| }
4277
4278    $warehouse = qq|
4279      <tr>
4280	<th align=right nowrap>|.$locale->text('Warehouse').qq|</th>
4281	<td><select name=warehouse>|
4282        .$form->select_option($selectwarehouse, undef, 1)
4283        .qq|</select>
4284        </td>
4285      </tr>
4286|;
4287  }
4288
4289  $checked{checkinventory} = "checked" if $form->{checkinventory};
4290
4291  $form->{title} = $locale->text('Stock Assembly');
4292
4293  $form->helpref("stock_assembly", $myconfig{countrycode});
4294
4295  $form->header;
4296
4297  print qq|
4298<body>
4299
4300<form method=post action=$form->{script}>
4301
4302<table width="100%">
4303  <tr>
4304    <th class=listtop>$form->{helpref}$form->{title}</a></th>
4305  </tr>
4306  <tr height="5"></tr>
4307  <tr valign=top>
4308    <td>
4309      <table>
4310        $warehouse
4311        <tr>
4312          <th align="right" nowrap="true">|.$locale->text('Number').qq|</th>
4313          <td><input name=partnumber size=20></td>
4314          <td>&nbsp;</td>
4315        </tr>
4316        <tr>
4317          <th align="right" nowrap="true">|.$locale->text('Description').qq|</th>
4318          <td><input name=description size=40></td>
4319        </tr>
4320        <tr>
4321          <td></td>
4322	  <td><input name=checkinventory class=checkbox type=checkbox value=1 $checked{checkinventory}>&nbsp;|.$locale->text('Check Inventory').qq|</td>
4323        </tr>
4324      </table>
4325    </td>
4326  </tr>
4327  <tr><td><hr size=3 noshade></td></tr>
4328</table>
4329
4330<input type=hidden name=sort value=partnumber>
4331|;
4332
4333  $form->hide_form(qw(path login));
4334
4335  print qq|
4336<input type=hidden name=nextsub value=list_assemblies>
4337
4338<br>
4339<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
4340</form>
4341|;
4342
4343  if ($form->{menubar}) {
4344    require "$form->{path}/menu.pl";
4345    &menubar;
4346  }
4347
4348  print qq|
4349
4350</body>
4351</html>
4352|;
4353
4354}
4355
4356
4357sub list_assemblies {
4358
4359  IC->retrieve_assemblies(\%myconfig, \%$form);
4360
4361  $form->sort_order();
4362
4363  $callback = "$form->{script}?action=list_assemblies&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&checkinventory=$form->{checkinventory}";
4364
4365  $form->sort_order();
4366
4367  $href = "$form->{script}?action=list_assemblies&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&checkinventory=$form->{checkinventory}";
4368
4369  if ($form->{warehouse}) {
4370    $callback .= "&warehouse=".$form->escape($form->{warehouse},1);
4371    $href .= "&warehouse=".$form->escape($form->{warehouse});
4372    $form->{sort} ||= "warehouse";
4373    ($warehouse) = split /--/, $form->{warehouse};
4374    $option = $locale->text('Warehouse').qq| : $warehouse<br>|;
4375  }
4376  if ($form->{partnumber}) {
4377    $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
4378    $href .= "&partnumber=".$form->escape($form->{partnumber});
4379    $form->{sort} ||= "partnumber";
4380    $option .= $locale->text('Number').qq| : $form->{partnumber}<br>|;
4381  }
4382  if ($form->{description}) {
4383    $callback .= "&description=".$form->escape($form->{description},1);
4384    $href .= "&description=".$form->escape($form->{description});
4385    $form->{sort} ||= "description";
4386    $option .= $locale->text('Description').qq| : $form->{description}<br>|;
4387  }
4388
4389  $column_data{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</th>|;
4390  $column_data{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</th>|;
4391  $column_data{bin} = qq|<th><a class=listheading href=$href&sort=bin>|.$locale->text('Bin').qq|</th>|;
4392  $column_data{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
4393  $column_data{rop} = qq|<th class=listheading>|.$locale->text('ROP').qq|</th>|;
4394  $column_data{stock} = qq|<th class=listheading>|.$locale->text('Add').qq|</th>|;
4395
4396  @columns = qw(partnumber description);
4397  push @columns, qw(bin onhand rop stock);
4398  @column_index = $form->sort_columns(@columns);
4399
4400  $form->{title} = $locale->text('Stock Assembly');
4401
4402  $form->helpref("list_assemblies", $myconfig{countrycode});
4403
4404  $form->header;
4405
4406  print qq|
4407<body>
4408
4409<form method=post action=$form->{script}>
4410
4411<table width=100%>
4412  <tr>
4413    <th class=listtop>$form->{helpref}$form->{title}</a></th>
4414  </tr>
4415  <tr size=5></tr>
4416
4417  <tr><td>$option</td></tr>
4418
4419  <tr>
4420    <td>
4421      <table width=100%>
4422	<tr class=listheading>
4423|;
4424
4425  for (@column_index) { print "\n$column_data{$_}" }
4426
4427  print qq|
4428	</tr>
4429|;
4430
4431  # add sort and escape callback
4432  $form->{callback} = $callback .= "&sort=$form->{sort}";
4433
4434  # escape callback for href
4435  $callback = $form->escape($callback);
4436
4437  $i = 1;
4438  foreach $ref (@{ $form->{assembly_items} }) {
4439
4440    for (qw(partnumber description)) { $ref->{$_} = $form->quote($ref->{$_}) }
4441
4442    $column_data{partnumber} = "<td width=20%><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
4443
4444    $column_data{description} = qq|<td width=50%>$ref->{description}&nbsp;</td>|;
4445    $column_data{bin} = qq|<td>$ref->{bin}&nbsp;</td>|;
4446    $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, undef, "&nbsp;").qq|</td>|;
4447    $column_data{rop} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{rop}, undef, "&nbsp;").qq|</td>|;
4448    $column_data{stock} = qq|<td width=10%><input name="qty_$i" class="inputright" size=8 value="|.$form->format_amount(\%myconfig, $ref->{stock}).qq|"></td>
4449    <input type=hidden name="stock_$i" value="$ref->{stock}">|;
4450
4451    $j++; $j %= 2;
4452    print qq|<tr class=listrow$j><input name="id_$i" type="hidden" value="$ref->{id}">\n|;
4453
4454    for (@column_index) { print "\n$column_data{$_}" }
4455
4456    print qq|
4457	</tr>
4458|;
4459
4460    $i++;
4461
4462  }
4463
4464  $i--;
4465  print qq|
4466      </td>
4467    </table>
4468  <tr>
4469    <td><hr size=3 noshade>
4470  </tr>
4471</table>
4472|;
4473
4474  $form->hide_form(qw(warehouse checkinventory path login callback));
4475
4476  print qq|
4477<input type=hidden name=rowcount value="$i">
4478<input type=hidden name=nextsub value=restock_assemblies>
4479
4480<br>
4481<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
4482
4483</form>
4484
4485</body>
4486</html>
4487|;
4488
4489}
4490
4491
4492sub restock_assemblies {
4493
4494  if ($form->{checkinventory}) {
4495    for (1 .. $form->{rowcount}) { $form->error($locale->text('Quantity exceeds available units to stock!')) if $form->parse_amount($myconfig, $form->{"qty_$_"}) > $form->{"stock_$_"} }
4496  }
4497
4498  if (IC->stock_assemblies(\%myconfig, \%$form)) {
4499    $form->redirect($locale->text('Assemblies stocked!'));
4500  } else {
4501    $form->error($locale->text('Cannot stock assemblies!'));
4502  }
4503
4504}
4505
4506
4507sub history {
4508
4509  IC->history(\%myconfig, \%$form);
4510
4511  @column_index = qw(partnumber description name trn transdate sellprice);
4512  $colspan = $#column_index + 1;
4513
4514  $hdr{ar} = $locale->text('Sales Invoices');
4515  $hdr{ap} = $locale->text('Vendor Invoices');
4516  $hdr{so} = $locale->text('Sales Orders');
4517  $hdr{po} = $locale->text('Purchase Orders');
4518  $hdr{sq} = $locale->text('Quotations');
4519  $hdr{rfq} = $locale->text('RFQs');
4520
4521  $mdl{ar} = 'is.pl';
4522  $mdl{ap} = 'ir.pl';
4523  for (qw(so po sq rfq)) { $mdl{$_} = 'oe.pl' }
4524
4525  $form->{title} = $locale->text('History');
4526
4527  $form->header;
4528
4529  $title = "$form->{title} / $form->{company}";
4530
4531  &resize;
4532
4533  &pickvalue;
4534
4535  print qq|
4536<body>
4537
4538<table width=100%>
4539  <tr>
4540    <th class=listtop>$title</th>
4541  </tr>
4542  <tr height="5"></tr>
4543
4544  <tr>
4545    <td>
4546      <table width=100%>
4547|;
4548
4549  foreach $ref (@{ $form->{all_parts} }) {
4550
4551    if ($ref->{module} ne $module) {
4552      print qq|
4553         <tr class=listheading>
4554	   <th colspan=$colspan>$hdr{$ref->{module}}</th>
4555         </tr>
4556|;
4557    }
4558
4559    $module = $ref->{module};
4560    $ref->{description} =~ s/\r?\n/<br>/g;
4561
4562    for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
4563
4564    $amount = $form->format_amount(\%myconfig, $ref->{sellprice}, $form->{precision});
4565    $column_data{sellprice} = qq|<td align=right><a href="#" onClick="pickvalue('$form->{pickvar}','$amount'); window.close()">${amount}&nbsp;</a></td>|;
4566
4567    $column_data{trn} = qq|<td><a href="$mdl{$ref->{module}}?action=edit&type=$ref->{type}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&readonly=1">$ref->{trn}&nbsp;</a></td>|;
4568
4569    $j++; $j %= 2;
4570    print "<tr class=listrow$j>";
4571
4572    for (@column_index) { print "\n$column_data{$_}" }
4573
4574    print qq|
4575    </tr>
4576|;
4577
4578  }
4579
4580  print qq|
4581      </table>
4582    </td>
4583  </tr>
4584  <tr><td><hr size=3 noshade></td></tr>
4585</table>
4586
4587x <a href="javascript:window.close();">|.$locale->text('Close Window').qq|</a>
4588|;
4589
4590}
4591
4592
4593
4594sub search_transfer {
4595
4596  $form->{searchitems} = 'partandassembly';
4597
4598  IC->get_warehouses(\%myconfig, \%$form);
4599
4600  if (@{ $form->{all_warehouse} }) {
4601    $selectwarehouse = ($form->{forcewarehouse}) ? "" : "\n";
4602    for (@{ $form->{all_warehouse} }) { $selectwarehouse .= qq|$_->{description}--$_->{id}\n| }
4603
4604    $warehouse = qq|
4605        <tr>
4606          <th align=right nowrap>|.$locale->text('Warehouse').qq|</th>
4607          <td><select name=warehouse>|
4608          .$form->select_option($selectwarehouse, undef, 1)
4609          .qq|</select>
4610          </td>
4611        </tr>
4612|;
4613
4614  }
4615
4616  if (@{ $form->{all_partsgroup} }) {
4617    $form->{selectpartsgroup} = "\n";
4618    for (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} .= qq|$_->{partsgroup}--$_->{id}\n| }
4619
4620    $partsgroup = qq|
4621 	<tr>
4622	  <th align=right nowrap>|.$locale->text('Group').qq|</th>
4623	  <td><select name=partsgroup>|
4624          .$form->select_option($form->{selectpartsgroup}, undef, 1)
4625          .qq|</select>
4626          </td>
4627	</tr>
4628|;
4629  }
4630
4631  if ($form->{nextsub} eq 'transfer_report') {
4632
4633    $transferreport = qq|
4634          <tr>
4635	    <th align=right>|.$locale->text('From').qq|</th>
4636	    <td colspan=3 nowrap><input name=transdatefrom size=11 class=date title="$myconfig{dateformat}" value=$form->{transdatefrom}>|.&js_calendar("main", "transdatefrom").qq| <b>|.$locale->text('To').qq|</b> <input name=transdateto size=11 class=date title="$myconfig{dateformat}">|.&js_calendar("main", "transdateto").qq|</td>
4637	  </tr>
4638|;
4639
4640    if (@{ $form->{all_years} }) {
4641      $selectaccountingyear = "\n";
4642      for (@{ $form->{all_years} }) { $selectaccountingyear .= qq|$_\n| }
4643      $selectaccountingmonth = "\n";
4644      for (sort keys %{ $form->{all_month} }) { $selectaccountingmonth .= qq|$_--|.$locale->text($form->{all_month}{$_}).qq|\n| }
4645
4646      $transferreport .= qq|
4647          <tr>
4648	    <th align=right>|.$locale->text('Period').qq|</th>
4649	    <td colspan=3>
4650	    <select name=month>|.$form->select_option($selectaccountingmonth, $form->{month}, 1, 1).qq|</select>
4651	    <select name=year>|.$form->select_option($selectaccountingyear, $form->{year}, 1).qq|</select>
4652	    <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
4653	    <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
4654	    <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
4655	    <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
4656	    </td>
4657	  </tr>
4658|;
4659    }
4660
4661  }
4662
4663  $form->{title} = $locale->text('Warehouse Transfer');
4664  if ($form->{nextsub} eq 'transfer_report') {
4665    $form->helpref("warehouse_transfer_report", $myconfig{countrycode});
4666  } elsif ($form->{nextsub} eq 'transfer_list') {
4667    $form->helpref("warehouse_transfer", $myconfig{countrycode});
4668  }
4669
4670  $form->header;
4671
4672  &calendar;
4673
4674  print qq|
4675<body onLoad="document.main.partnumber.focus()" />
4676
4677<form method="post" name="main" action="$form->{script}">
4678
4679<table width=100%>
4680  <tr>
4681    <th class=listtop>$form->{helpref}$form->{title}</a></th>
4682  </tr>
4683  <tr height="5"></tr>
4684  <tr>
4685    <td>
4686      <table>
4687        $warehouse
4688	<tr>
4689	  <th align="right" nowrap="true">|.$locale->text('Part Number').qq|</th>
4690	  <td><input name=partnumber size=20></td>
4691	</tr>
4692	<tr>
4693	  <th align="right" nowrap="true">|.$locale->text('Description').qq|</th>
4694	  <td><input name=description size=40></td>
4695	</tr>
4696	$partsgroup
4697	$transferreport
4698      </table>
4699    </td>
4700  </tr>
4701  <tr>
4702    <td><hr size=3 noshade></td>
4703  </tr>
4704</table>
4705
4706<br>
4707
4708<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">|;
4709
4710  $form->hide_form(qw(nextsub path login));
4711
4712  print qq|
4713</form>
4714|;
4715
4716  if ($form->{menubar}) {
4717    require "$form->{path}/menu.pl";
4718    &menubar;
4719  }
4720
4721  print qq|
4722
4723</body>
4724</html>
4725|;
4726
4727}
4728
4729
4730sub transfer_list {
4731
4732  $form->{sort} ||= "partnumber";
4733
4734  IC->get_inventory(\%myconfig, \%$form);
4735
4736  # warehouses
4737  if (@{ $form->{all_warehouse} }) {
4738    $form->{selectwarehouse} = ($form->{forcewarehouse}) ? "" : "\n";
4739
4740    for (@{ $form->{all_warehouse} }) { $form->{selectwarehouse} .= qq|$_->{description}--$_->{id}\n| }
4741  } else {
4742    $form->error($locale->text('No warehouses!'));
4743  }
4744
4745  # construct href
4746  $href = "$form->{script}?action=transfer_list";
4747  for (qw(direction oldsort path login)) { $href .= "&$_=$form->{$_}" }
4748  for (qw(partnumber description unit partsgroup warehouse)) { $href .= "&$_=".$form->escape($form->{$_}) }
4749
4750  $form->sort_order();
4751
4752  # construct callback
4753  $callback = "$form->{script}?action=transfer_list";
4754  for (qw(direction oldsort path login)) { $callback .= "&$_=$form->{$_}" }
4755  for (qw(partnumber description unit partsgroup warehouse)) { $callback .= "&$_=".$form->escape($form->{$_},1) }
4756
4757  @column_index = $form->sort_columns(qw(partnumber description partsgroup qty unit warehouse transfer towarehouse));
4758
4759  $column_header{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Part Number').qq|</a></th>|;
4760  $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
4761  $column_header{partsgroup} = qq|<th><a class=listheading href=$href&sort=partsgroup>|.$locale->text('Group').qq|</a></th>|;
4762  $column_header{warehouse} = qq|<th><a class=listheading href=$href&sort=warehouse>|.$locale->text('Warehouse').qq|</a></th>|;
4763  $column_header{towarehouse} = qq|<th class=listheading>|.$locale->text('To').qq|</th>|;
4764  $column_header{qty} = qq|<th class=listheading>|.$locale->text('Qty').qq|</a></th>|;
4765  $column_header{unit} = qq|<th class=listheading>|.$locale->text('Unit').qq|</a></th>|;
4766  $column_header{transfer} = qq|<th class=listheading>|.$locale->text('Transfer').qq|</a></th>|;
4767
4768
4769  if ($form->{partnumber}) {
4770    $option .= "\n<br>" if ($option);
4771    $option .= $locale->text('Part Number')." : $form->{partnumber}";
4772  }
4773  if ($form->{description}) {
4774    $option .= "\n<br>" if ($option);
4775    $option .= $locale->text('Description')." : $form->{description}";
4776  }
4777  if ($form->{partsgroup}) {
4778    ($partsgroup) = split /--/, $form->{partsgroup};
4779    $option .= "\n<br>" if ($option);
4780    $option .= $locale->text('Group')." : $partsgroup";
4781  }
4782  if ($form->{warehouse}) {
4783    ($warehouse) = split /--/, $form->{warehouse};
4784    $option .= "\n<br>" if ($option);
4785    $option .= $locale->text('Warehouse')." : $warehouse";
4786
4787    $column_header{warehouse} = qq|<th class=listheading>|.$locale->text('Warehouse').qq|</th>|;
4788  }
4789
4790
4791  $form->{title} = $locale->text('Transfer Inventory');
4792
4793  $callback .= "&sort=$form->{sort}";
4794  $form->{callback} = $callback;
4795  $callback = $form->escape($callback);
4796
4797  $form->{shippingdate} = $form->current_date(\%myconfig);
4798
4799  $form->header;
4800
4801  &calendar;
4802
4803  print qq|
4804<body>
4805
4806<form method="post" name="main" action="$form->{script}" />
4807
4808<table width=100%>
4809  <tr>
4810    <th class=listtop>$form->{title}</th>
4811  </tr>
4812  <tr height="5"></tr>
4813  <tr>
4814    <td>$option</td>
4815  </tr>
4816  <tr>
4817    <td>
4818      <table width=100%>
4819	<tr class=listheading>|;
4820
4821  for (@column_index) { print "\n$column_header{$_}" }
4822
4823  print qq|
4824	</tr>
4825|;
4826
4827  if (@{ $form->{all_inventory} }) {
4828    $samesort = $form->{all_inventory}->[0]->{$form->{sort}};
4829  }
4830
4831  $selectwarehouse = $form->select_option($form->{selectwarehouse}, "", 1);
4832
4833  $i = 0;
4834  foreach $ref (@{ $form->{all_inventory} }) {
4835
4836    $i++;
4837
4838    if ($sameid != $ref->{id}) {
4839      $column_data{partnumber} = qq|<td><input type=hidden name="id_$i" value=$ref->{id}><a href=ic.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{partnumber}</td>|;
4840      $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
4841      $column_data{unit} = "<td>$ref->{unit}&nbsp;</td>";
4842      $column_data{partsgroup} = "<td>$ref->{partsgroup}&nbsp;</td>";
4843    } else {
4844      $column_data{partnumber} = qq|<td><input type=hidden name="id_$i" value=$ref->{id}></td>|;
4845      for (qw(description unit partsgroup)) { $column_data{$_} = "<td>&nbsp;</td>" }
4846    }
4847    $column_data{warehouse} = qq|<td><input type=hidden name="warehouse_id_$i" value=$ref->{warehouse_id}><input type=hidden name="warehouse_$i" value="$ref->{warehouse}">$ref->{warehouse}&nbsp;</td>|;
4848    $column_data{towarehouse} = qq|<td><select name="towarehouse_$i">$selectwarehouse
4849    </select>
4850    </td>|;
4851    $column_data{qty} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{qty}).qq|</td>|;
4852    $column_data{transfer} = qq|<td><input class="inputright" name="transfer_$i" size=4></td>|;
4853    $j++; $j %= 2;
4854    print "
4855        <tr class=listrow$j>";
4856
4857    for (@column_index) { print "\n$column_data{$_}" }
4858
4859    print qq|
4860	</tr>
4861|;
4862
4863    $sameid = $ref->{id};
4864
4865  }
4866
4867  print qq|
4868      </table>
4869    </td>
4870  </tr>
4871  <tr>
4872    <td><hr size=3 noshade></td>
4873  </tr>
4874  <tr>
4875    <td nowrap>|.$locale->text('Date').qq| <input name=shippingdate size=11 value="$form->{shippingdate}" class="date" title="$myconfig{dateformat}">|.&js_calendar("main", "shippingdate").qq|
4876    </td>
4877  </tr>
4878  <tr>
4879    <td><hr size=3 noshade></td>
4880  </tr>
4881</table>
4882
4883<br>
4884
4885|;
4886
4887  $form->{action} = "transfer";
4888  $form->{rowcount} = $i;
4889
4890  $form->hide_form(qw(employee path login action rowcount callback));
4891
4892  %button = (
4893	     'Transfer' => { ndx => 11, key => 'T', value => $locale->text('Transfer') },
4894	    );
4895
4896  $form->print_button(\%button);
4897
4898  if ($form->{menubar}) {
4899    require "$form->{path}/menu.pl";
4900    &menubar;
4901  }
4902
4903  print qq|
4904</form>
4905
4906</body>
4907</html>
4908|;
4909
4910
4911}
4912
4913
4914sub transfer {
4915
4916  for $i (1 .. $form->{rowcount}) {
4917    if ($form->{"transfer_$i"}) {
4918      $ok = 1;
4919      last;
4920    }
4921  }
4922
4923  $form->error($locale->text('Nothing to transfer!')) unless $ok;
4924
4925  if (IC->transfer(\%myconfig, \%$form)) {
4926    $form->redirect($locale->text('Inventory transferred!'));
4927  } else {
4928    $form->error($locale->text('Could not transfer Inventory!'));
4929  }
4930
4931}
4932
4933
4934sub transfer_report {
4935
4936  $form->{sort} ||= "shippingdate";
4937
4938  IC->transfer_report(\%myconfig, \%$form);
4939
4940  $href = "$form->{script}?action=transfer_report";
4941  for (qw(direction oldsort path login)) { $href .= qq|&$_=$form->{$_}| }
4942
4943  $form->sort_order();
4944
4945  $callback = "$form->{script}?action=transfer_report";
4946  for (qw(direction oldsort path login)) { $callback .= qq|&$_=$form->{$_}| }
4947
4948  if ($form->{partnumber}) {
4949    $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
4950    $href .= "&partnumber=".$form->escape($form->{partnumber});
4951    $option = $locale->text('Part Number').qq| : $form->{partnumber}|;
4952  }
4953  if ($form->{description}) {
4954    $callback .= "&description=".$form->escape($form->{description},1);
4955    $href .= "&description=".$form->escape($form->{description});
4956    $option .= "\n<br>" if ($option);
4957    $option .= $locale->text('Description').qq| : $form->{description}|;
4958  }
4959  if ($form->{warehouse}) {
4960    $callback .= "&warehouse=".$form->escape($form->{warehouse},1);
4961    $href .= "&warehouse=".$form->escape($form->{warehouse});
4962    ($warehouse) = split /--/, $form->{warehouse};
4963    $option .= "\n<br>" if ($option);
4964    $option .= $locale->text('Warehouse').qq| : $warehouse|;
4965  }
4966  if ($form->{partsgroup}) {
4967    $callback .= "&partsgroup=".$form->escape($form->{partsgroup},1);
4968    $href .= "&partsgroup=".$form->escape($form->{partsgroup});
4969    ($partsgroup) = split /--/, $form->{partsgroup};
4970    $option .= "\n<br>" if ($option);
4971    $option .= $locale->text('Group').qq| : $partsgroup|;
4972  }
4973  if ($form->{transdatefrom}) {
4974    $callback .= "&transdatefrom=$form->{transdatefrom}";
4975    $href .= "&transdatefrom=$form->{transdatefrom}";
4976    $option .= "\n<br>" if ($option);
4977    $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
4978  }
4979  if ($form->{transdateto}) {
4980    $callback .= "&transdateto=$form->{transdateto}";
4981    $href .= "&transdateto=$form->{transdateto}";
4982    $option .= "\n<br>" if ($option);
4983    $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 1);
4984  }
4985
4986  @column_index = $form->sort_columns(qw(shippingdate partnumber description fromwarehouse towarehouse qty unit employee));
4987
4988  $column_data{shippingdate} = "<th><a class=listheading href=$href&sort=shippingdate>".$locale->text('Date')."</a></th>";
4989  $column_data{partnumber} = "<th><a class=listheading href=$href&sort=partnumber>".$locale->text('Part Number')."</a></th>";
4990  $column_data{description} = "<th><a class=listheading href=$href&sort=description>".$locale->text('Description')."</a></th>";
4991  $column_data{employee} = "<th><a class=listheading href=$href&sort=employee>".$locale->text('Employee')."</a></th>";
4992  $column_data{qty} = "<th class=listheading>" . $locale->text('Qty') . "</th>";
4993  $column_data{unit} = "<th class=listheading>" . $locale->text('Unit') . "</th>";
4994  $column_data{fromwarehouse} = "<th>".$locale->text('From')."</a></th>";
4995  $column_data{towarehouse} = "<th>".$locale->text('To')."</a></th>";
4996
4997  $form->{title} = $locale->text('Warehouse Transfer Report');
4998
4999  $form->helpref("warehouse_transfer_report", $myconfig{countrycode});
5000
5001  $form->header;
5002
5003  print qq|
5004<body>
5005
5006<table width=100%>
5007  <tr>
5008    <th class=listtop>$form->{helpref}$form->{title}</a></th>
5009  </tr>
5010  <tr height="5"></tr>
5011  <tr>
5012    <td>$option</td>
5013  </tr>
5014  <tr>
5015    <td>
5016      <table width=100%>
5017        <tr class=listheading>
5018|;
5019
5020  for (@column_index) { print "\n$column_data{$_}" }
5021
5022  print qq|
5023        </tr>
5024|;
5025
5026  $callback .= "&sort=$form->{sort}";
5027
5028  # escape callback for href
5029  $callback = $form->escape($callback);
5030
5031  foreach $ref (@{ $form->{inventory_transfer} }) {
5032
5033    $ref->{description} =~ s/\r?\n/<br>/g;
5034    $column_data{shippingdate} = "<td nowrap>$ref->{shippingdate}</td>";
5035    for (qw(description towarehouse employee unit fromwarehouse)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
5036    $column_data{partnumber} = qq|<td><a href=ic.pl?action=edit&id=$ref->{id}&login=$form->{login}&path=$form->{path}&callback=$callback>$ref->{partnumber}</a></td>|;
5037    $column_data{qty} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{qty});
5038
5039    $j++; $j %= 2;
5040
5041    print "
5042        <tr class=listrow$j>
5043";
5044
5045    for (@column_index) { print "\n$column_data{$_}" }
5046
5047    print qq|
5048        </tr>
5049|;
5050
5051  }
5052
5053  print qq|
5054        </tr>
5055      </table>
5056    </td>
5057  </tr>
5058  <tr>
5059    <td><hr size=3 noshade></td>
5060  </tr>
5061</table>
5062
5063</body>
5064</html>
5065|;
5066
5067}
5068
5069
5070sub assembly_bom_transfer {
5071
5072  $form->{searchitems} = 'assembly';
5073
5074  IC->get_warehouses(\%myconfig, \%$form);
5075
5076  if (@{ $form->{all_warehouse} }) {
5077    $selecttowarehouse = ($form->{forcewarehouse}) ? "" : "\n";
5078
5079    for (@{ $form->{all_warehouse} }) { $selecttowarehouse .= qq|$_->{description}--$_->{id}\n| }
5080    $selectfromwarehouse = "$selecttowarehouse";
5081
5082    $warehouse = qq|
5083      <tr>
5084	<th align=right nowrap>|.$locale->text('From Warehouse').qq|</th>
5085	<td><select name=fromwarehouse>|
5086        .$form->select_option($selectfromwarehouse, undef, 1)
5087        .qq|</select>
5088	<b>|.$locale->text('To Warehouse').qq|</b>
5089	<select name=towarehouse>|
5090        .$form->select_option($selecttowarehouse, undef, 1)
5091        .qq|</select>
5092        </td>
5093      </tr>
5094|;
5095  } else {
5096    $form->error($locale->text('No warehouses!'));
5097  }
5098
5099  if (@{ $form->{all_partsgroup} }) {
5100    $form->{selectpartsgroup} = "\n";
5101    for (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} .= qq|$_->{partsgroup}--$_->{id}\n| }
5102
5103    $partsgroup = qq|
5104 	<tr>
5105	  <th align=right nowrap>|.$locale->text('Group').qq|</th>
5106	  <td><select name=partsgroup>|
5107          .$form->select_option($form->{selectpartsgroup}, undef, 1)
5108          .qq|</select>
5109          </td>
5110	</tr>
5111|;
5112  }
5113
5114  $form->{title} = $locale->text('Assembly BOM Transfer');
5115
5116  $form->helpref("assembly_bom_transfer", $myconfig{countrycode});
5117
5118  $form->header;
5119
5120  print qq|
5121<body onLoad="document.main.partnumber.focus()" />
5122
5123<form method=post name=main action=$form->{script}>
5124
5125<table width="100%">
5126  <tr>
5127    <th class=listtop>$form->{helpref}$form->{title}</a></th>
5128  </tr>
5129  <tr height="5"></tr>
5130  <tr valign=top>
5131    <td>
5132      <table>
5133        $warehouse
5134        <tr>
5135          <th align="right" nowrap="true">|.$locale->text('Number').qq|</th>
5136          <td><input name=partnumber size=20></td>
5137          <td>&nbsp;</td>
5138        </tr>
5139        <tr>
5140          <th align="right" nowrap="true">|.$locale->text('Description').qq|</th>
5141          <td><input name=description size=40></td>
5142        </tr>
5143        $partsgroup
5144        <tr>
5145          <th align="right" nowrap="true">|.$locale->text('Qty').qq|</th>
5146          <td><input name=qty class="inputright" size=4></td>
5147        </tr>
5148      </table>
5149    </td>
5150  </tr>
5151  <tr><td><hr size=3 noshade></td></tr>
5152</table>
5153
5154|;
5155
5156  $form->hide_form(qw(path login));
5157
5158  print qq|
5159<input type=hidden name=nextsub value=list_assembly_bom_transfer>
5160
5161<br>
5162<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
5163</form>
5164|;
5165
5166  if ($form->{menubar}) {
5167    require "$form->{path}/menu.pl";
5168    &menubar;
5169  }
5170
5171  print qq|
5172
5173</body>
5174</html>
5175|;
5176
5177}
5178
5179
5180sub list_assembly_bom_transfer {
5181
5182  $form->{sort} = "partnumber";
5183
5184  $form->error($locale->text('Cannot transfer to the same warehouse!')) if $form->{fromwarehouse} eq $form->{towarehouse};
5185
5186  $form->{qty} ||= 1;
5187
5188  IC->get_assembly_bom_transfer(\%myconfig, \%$form);
5189
5190  $callback = "$form->{script}?action=list_assembly_bom_transfer";
5191  for (qw(path login towarehouse)) { $callback .= qq|&$_=$form->{$_}| }
5192
5193  @column_index = qw(assemblynumber qty partnumber description partsgroup fromwarehouse fromonhand towarehouse toonhand unit transfer);
5194
5195  $column_header{assemblynumber} = qq|<th class=listheading>|.$locale->text('Assembly Number').qq|</th>|;
5196  $column_header{partnumber} = qq|<th class=listheading>|.$locale->text('Part Number').qq|</th>|;
5197  $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
5198  $column_header{partsgroup} = qq|<th class=listheading>|.$locale->text('Group').qq|</th>|;
5199  $column_header{fromwarehouse} = qq|<th class=listheading>|.$locale->text('From').qq|</th>|;
5200  $column_header{towarehouse} = qq|<th class=listheading>|.$locale->text('To').qq|</th>|;
5201  $column_header{fromonhand} = qq|<th class=listheading>|.$locale->text('OH').qq|</th>|;
5202  $column_header{toonhand} = qq|<th class=listheading>|.$locale->text('OH').qq|</th>|;
5203  $column_header{unit} = qq|<th class=listheading>|.$locale->text('Unit').qq|</th>|;
5204  $column_header{transfer} = qq|<th class=listheading>|.$locale->text('Transfer').qq|</th>|;
5205  $column_header{qty} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
5206
5207  if (($warehouse) = split /--/, $form->{fromwarehouse}) {
5208    $option = $locale->text('From Warehouse')." : $warehouse";
5209    $callback .= qq|&fromwarehouse=$form->{fromwarehouse}|;
5210  }
5211
5212  if ($form->{towarehouse}) {
5213    ($warehouse) = split /--/, $form->{towarehouse};
5214    $option .= "\n<br>" if ($option);
5215    $option .= $locale->text('To Warehouse')." : $warehouse";
5216    $callback .= qq|&towarehouse=$form->{towarehouse}|;
5217  }
5218
5219  if ($form->{partnumber}) {
5220    $option .= "\n<br>" if ($option);
5221    $option .= $locale->text('Part Number')." : $form->{partnumber}";
5222    $callback .= qq|&partnumber=$form->{partnumber}|;
5223  }
5224  if ($form->{description}) {
5225    $option .= "\n<br>" if ($option);
5226    $option .= $locale->text('Description')." : $form->{description}";
5227    $callback .= qq|&description=$form->{description}|;
5228  }
5229
5230  $option .= "\n<br>" if ($option);
5231  $option .= $locale->text('Quantity')." : $form->{qty}";
5232  $callback .= qq|&qty=$form->{qty}|;
5233
5234  $form->{title} = $locale->text('Assembly BOM Transfer');
5235
5236  $callback = $form->escape($callback);
5237
5238  $form->{shippingdate} = $form->current_date(\%myconfig);
5239
5240  unless (@{ $form->{all_inventory} }) {
5241    $form->error($locale->text('Nothing to transfer!'));
5242  }
5243
5244  $form->header;
5245
5246  &calendar;
5247
5248  print qq|
5249<body>
5250
5251<form method="post" name="main" action="$form->{script}" />
5252
5253<table width=100%>
5254  <tr>
5255    <th class=listtop>$form->{title}</th>
5256  </tr>
5257  <tr height="5"></tr>
5258  <tr>
5259    <td>$option</td>
5260  </tr>
5261  <tr>
5262    <td>
5263      <table width=100%>
5264	<tr class=listheading>|;
5265
5266  for (@column_index) { print "\n$column_header{$_}" }
5267
5268  print qq|
5269	</tr>
5270|;
5271
5272  $samesort = $form->{all_inventory}->[0]->{$form->{sort}};
5273
5274  $i = 0;
5275  foreach $ref (@{ $form->{all_inventory} }) {
5276
5277    $i++;
5278
5279    if ($sameid != $ref->{id}) {
5280      for (qw(assemblynumber partnumber fromonhand toonhand)) { $column_data{$_} = "<td>&nbsp;</td>" }
5281      if ($ref->{assemblyitem}) {
5282        $column_data{partnumber} = qq|<td><input type=hidden name="id_$i" value=$ref->{id}><a href=ic.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{partnumber}</td>|;
5283      } else {
5284        $column_data{assemblynumber} = qq|<td><input type=hidden name="id_$i" value=$ref->{id}><a href=ic.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{partnumber}</td>|;
5285      }
5286      $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
5287      $column_data{unit} = "<td>$ref->{unit}&nbsp;</td>";
5288      $column_data{partsgroup} = "<td>$ref->{partsgroup}&nbsp;</td>";
5289    } else {
5290      $column_data{partnumber} = qq|<td><input type=hidden name="id_$i" value=$ref->{id}></td>|;
5291      for (qw(description unit partsgroup)) { $column_data{$_} = "<td>&nbsp;</td>" }
5292    }
5293
5294    $column_data{fromwarehouse} = qq|<td><input type=hidden name="warehouse_id_$i" value=$ref->{fromwarehouse_id}><input type=hidden name="warehouse_$i" value="$ref->{fromwarehouse}">$ref->{fromwarehouse}</td>|;
5295    $pm = "";
5296    if ($ref->{assemblyitem}) {
5297      $pm = "<font color=";
5298      if ($ref->{fromonhand} >= $ref->{transfer}) {
5299        $pm .= "green";
5300      } else {
5301        $pm .= "red";
5302        if ($ref->{fromonhand} <= 0) {
5303          $ref->{transfer} = 0;
5304        } else {
5305          $ref->{transfer} = $ref->{fromonhand};
5306        }
5307      }
5308      $pm .= ">";
5309    }
5310    $column_data{fromonhand} = qq|<td align=right>$pm|.$form->format_amount(\%myconfig, $ref->{fromonhand}, undef, "0");
5311    $column_data{fromonhand} .= "</font>" if $pm;
5312    $column_data{fromonhand} .= qq|</td>|;
5313
5314    $column_data{towarehouse} = qq|<td><input type=hidden name="towarehouse_$i" value="$ref->{towarehouse}--$ref->{towarehouse_id}">$ref->{towarehouse}</td>|;
5315    $column_data{toonhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{toonhand}, undef, "0").qq|</td>|;
5316
5317    $column_data{qty} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{qty}, undef, "0").qq|</td>|;
5318
5319    $column_data{transfer} = qq|<td>&nbsp;</td>|;
5320    if ($ref->{assemblyitem}) {
5321      if ($ref->{inventory_accno_id}) {
5322        $column_data{transfer} = qq|<td><input class="inputright" name="transfer_$i" size=4 value=|.$form->format_amount(\%myconfig, $ref->{transfer}).qq|></td>|;
5323      }
5324    } else {
5325      $column_data{qty} = qq|<td align=right>|.$form->format_amount(\%myconfig, $form->{qty}, undef, "0").qq|</td>| unless $ref->{assemblyitem};
5326    }
5327
5328    $j++; $j %= 2;
5329    print "
5330        <tr class=listrow$j>";
5331
5332    for (@column_index) { print "\n$column_data{$_}" }
5333
5334    print qq|
5335	</tr>
5336|;
5337
5338    $sameid = $ref->{id};
5339
5340  }
5341
5342  print qq|
5343      </table>
5344    </td>
5345  </tr>
5346  <tr>
5347    <td><hr size=3 noshade></td>
5348  </tr>
5349   <tr>
5350    <td nowrap>|.$locale->text('Date').qq| <input name=shippingdate size=11 value="$form->{shippingdate}" class="date" title="$myconfig{dateformat}">|.&js_calendar("main", "shippingdate").qq|
5351    </td>
5352  </tr>
5353  <tr>
5354    <td><hr size=3 noshade></td>
5355  </tr>
5356</table>
5357
5358<br>
5359
5360|;
5361
5362  $form->{action} = "transfer";
5363  $form->{rowcount} = $i;
5364
5365  $form->hide_form(qw(employee path login action rowcount callback));
5366
5367  %button = (
5368	     'Transfer' => { ndx => 11, key => 'T', value => $locale->text('Transfer') },
5369	    );
5370
5371  $form->print_button(\%button);
5372
5373  if ($form->{menubar}) {
5374    require "$form->{path}/menu.pl";
5375    &menubar;
5376  }
5377
5378  print qq|
5379</form>
5380
5381</body>
5382</html>
5383|;
5384
5385}
5386
5387
5388sub new_number {
5389
5390  $form->{partnumber} = $form->update_defaults(\%myconfig, "partnumber");
5391
5392  &update;
5393
5394}
5395
5396
5397sub continue { &{ $form->{nextsub} } };
5398
5399sub add_part {
5400  $form->{item} = 'part';
5401  &add;
5402}
5403
5404sub add_service {
5405  $form->{item} = 'service';
5406  &add;
5407}
5408
5409sub add_assembly {
5410  $form->{item} = 'assembly';
5411  &add;
5412}
5413
5414sub add_labor_overhead {
5415  $form->{item} = 'labor';
5416  &add;
5417}
5418
5419sub add_kit {
5420  $form->{item} = 'kit';
5421  &add;
5422}
5423
5424
5425sub upload_image {
5426
5427  $form->{title} = $locale->text('Upload Image');
5428
5429  $form->helpref("upload_image", $myconfig{countrycode});
5430
5431  $form->header;
5432
5433  $form->{nextsub} = "upload_imagefile";
5434
5435  &resize;
5436
5437  print qq|
5438<body>
5439
5440<form enctype="multipart/form-data" method=post action=$form->{script}>
5441
5442<table width=100%>
5443  <tr>
5444    <th class=listtop>$form->{helpref}$form->{title}</a></th>
5445  </tr>
5446  <tr height="5"></tr>
5447  <tr>
5448    <td>
5449      <table>
5450        <tr>
5451          <th align="right">|.$locale->text('File').qq|</th>
5452          <td>
5453            <input name=data size=60 type=file>
5454          </td>
5455        </tr>
5456      </table>
5457    </td>
5458  </tr>
5459  <tr>
5460    <td><hr size=3 noshade></td>
5461  </tr>
5462
5463</table>
5464|;
5465
5466  $form->hide_form(qw(nextsub login path));
5467
5468  print qq|
5469<input name=action class=submit type=submit value="|.$locale->text('Continue').qq|">
5470</form>
5471
5472</body>
5473</html>
5474|;
5475
5476}
5477
5478
5479sub upload_imagefile {
5480
5481  if (-s "$userspath/$form->{tmpfile}") {
5482    open(IN, "$userspath/$form->{tmpfile}") or $form->error("$userspath/$form->{tmpfile} : $!\n");
5483    open(OUT, "> $images/$myconfig{dbname}/$form->{filename}") or $form->error("$images/$myconfig{dbname}/$form->{filename} : $!\n");
5484
5485    binmode(IN);
5486    binmode(OUT);
5487
5488    while (<IN>) {
5489      print OUT $_;
5490    }
5491
5492    close(IN);
5493    close(OUT);
5494
5495  }
5496
5497  unlink "$userspath/$form->{tmpfile}";
5498
5499  $form->header;
5500
5501  &pickvalue;
5502
5503  print qq|
5504<body onLoad="pickvalue('image', '$form->{filename}'); window.close()">
5505
5506</body>
5507</html>
5508|;
5509
5510}
5511
5512
5513