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# project/job administration
11# partsgroup administration
12# translation maintainance
13#
14#======================================================================
15
16
17use SL::PE;
18use SL::AA;
19use SL::OE;
20
21require "$form->{path}/cm.pl";
22require "$form->{path}/sr.pl";
23require "$form->{path}/js.pl";
24
251;
26# end of main
27
28# this is for our long dates
29# $locale->text('January')
30# $locale->text('February')
31# $locale->text('March')
32# $locale->text('April')
33# $locale->text('May ')
34# $locale->text('June')
35# $locale->text('July')
36# $locale->text('August')
37# $locale->text('September')
38# $locale->text('October')
39# $locale->text('November')
40# $locale->text('December')
41
42# this is for our short month
43# $locale->text('Jan')
44# $locale->text('Feb')
45# $locale->text('Mar')
46# $locale->text('Apr')
47# $locale->text('May')
48# $locale->text('Jun')
49# $locale->text('Jul')
50# $locale->text('Aug')
51# $locale->text('Sep')
52# $locale->text('Oct')
53# $locale->text('Nov')
54# $locale->text('Dec')
55
56
57sub add {
58
59  # construct callback
60  $form->{callback} = "$form->{script}?action=add&type=$form->{type}&path=$form->{path}&login=$form->{login}" unless $form->{callback};
61
62  &{ "prepare_$form->{type}" };
63
64  $form->{orphaned} = 1;
65  &display_form;
66
67}
68
69
70sub edit {
71
72  &{ "prepare_$form->{type}" };
73  &display_form;
74
75}
76
77
78sub prepare_partsgroup { PE->get_partsgroup(\%myconfig, \%$form) if $form->{id} }
79sub prepare_pricegroup { PE->get_pricegroup(\%myconfig, \%$form) if $form->{id} }
80
81sub prepare_job {
82
83# $locale->text('Add Job')
84# $locale->text('Edit Job')
85
86  $form->{vc} = 'customer';
87
88  PE->get_job(\%myconfig, \%$form);
89
90  $form->helpref("jobs", $myconfig{countrycode});
91
92  $form->{taxaccounts} = "";
93  for (keys %{ $form->{IC_links} }) {
94
95    $form->{"select$_"} = "";
96    foreach $ref (@{ $form->{IC_links}{$_} }) {
97      if (/IC_tax/) {
98        if (/taxpart/) {
99          $form->{taxaccounts} .= "$ref->{accno} ";
100          $form->{"IC_tax_$ref->{accno}_description"} = "$ref->{accno}--$ref->{description}";
101          if ($form->{id}) {
102            if ($form->{amount}{$ref->{accno}}) {
103              $form->{"IC_tax_$ref->{accno}"} = "checked";
104            }
105          } else {
106            $form->{"IC_tax_$ref->{accno}"} = "checked";
107          }
108        }
109      } else {
110        $form->{"select$_"} .= "$ref->{accno}--$ref->{description}\n";
111      }
112    }
113    $form->{"select$_"} = $form->escape($form->{"select$_"}, 1);
114  }
115  chop $form->{taxaccounts};
116
117  $form->{selectIC_income} = $form->{selectIC_sale};
118  $form->{IC_income} = $form->{IC_sale};
119
120  $form->{IC_income} = qq|$form->{income_accno}--$form->{income_description}|;
121
122  delete $form->{IC_links};
123
124  $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
125
126  if (@{ $form->{"all_$form->{vc}"} }) {
127    $form->{"$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
128    $form->{"select$form->{vc}"} = qq|\n|;
129    for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|$_->{name}--$_->{id}\n| }
130  }
131
132  $form->get_partsgroup(\%myconfig, {all => 1});
133  $form->{partsgroup} = $form->quote($form->{partsgroup})."--$form->{partsgroup_id}";
134  if (@{ $form->{all_partsgroup} }) {
135    $form->{selectpartsgroup} = qq|\n|;
136    for (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} .= qq|$_->{partsgroup}--$_->{id}\n| }
137  }
138
139  $form->{"select$form->{vc}"} = $form->escape($form->{"select$form->{vc}"},1);
140  for (qw(partsgroup)) { $form->{"select$_"} = $form->escape($form->{"select$_"},1) }
141
142  $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->{closedto});
143
144  $form->{readonly} = 1 if $myconfig{acs} =~ /Job Costing--Add Job/;
145
146  &all_references;
147
148}
149
150
151sub job_header {
152
153  for (qw(partnumber partdescription description notes unit)) { $form->{$_} = $form->quote($form->{$_}) }
154
155  for (qw(production completed weight)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) }
156  for (qw(listprice sellprice)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $form->{precision}) }
157
158  $reference_documents = &references;
159
160  if (($rows = $form->numtextrows($form->{partdescription}, 60)) > 1) {
161    $partdescription = qq|<textarea name="partdescription" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{partdescription}</textarea>|;
162  } else {
163    $partdescription = qq|<input name=partdescription size=60 value="|.$form->quote($form->{partdescription}).qq|">|;
164  }
165
166  if (($rows = $form->numtextrows($form->{description}, 60)) < 2) {
167    $rows = 1;
168  }
169
170  $description = qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
171
172  if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
173    $rows = 2;
174  }
175
176  $notes = qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|;
177
178  $label = ucfirst $form->{vc};
179  $vcref = qq|<a href=ct.pl?action=edit&db=$form->{vc}&id=$form->{"$form->{vc}_id"}&login=$form->{login}&path=$form->{path} target=_blank>?</a>|;
180
181  if ($form->{"select$form->{vc}"}) {
182    $name = qq|
183	<tr>
184	  <th align=right nowrap>|.$locale->text($label).qq|</th>
185	  <td colspan=3><select name="$form->{vc}"
186          onChange="javascript:document.main.submit()">|
187          .$form->select_option($form->{"select$form->{vc}"}, $form->{$form->{vc}}, 1).qq|</select>
188          $vcref
189	  </td>
190          <input name=action type=hidden value=update>
191	</tr>
192|;
193  } else {
194    $name = qq|
195	<tr>
196	  <th align=right nowrap>|.$locale->text($label).qq|</th>
197	  <td colspan=3><input name="$form->{vc}" value="|.$form->quote($form->{"$form->{vc}"}).qq|" size=35> $vcref</td>
198	</tr>
199|;
200  }
201
202  if ($form->{orphaned}) {
203
204    $production = qq|
205	<tr>
206	  <th align=right nowrap>|.$locale->text('Production').qq|</th>
207	  <td><input name=production class="inputright" size=11 value="$form->{production}"></td>
208	  <th align=right nowrap>|.$locale->text('Completed').qq|</th>
209	  <td>$form->{completed}</td>
210	</tr>
211|;
212    $production .= $form->hide_form(completed);
213
214  } else {
215
216    $form->{selectIC_income} = $form->{IC_income};
217
218    $production = qq|
219	<tr>
220	  <th align=right nowrap>|.$locale->text('Production').qq|</th>
221	  <td>$form->{production}</td>
222	  <th align=right nowrap>|.$locale->text('Completed').qq|</th>
223	  <td>$form->{completed}</td>
224	</tr>
225|;
226    $production .= $form->hide_form(qw(production completed));
227
228  }
229
230    for (split / /, $form->{taxaccounts}) { $form->{"IC_tax_$_"} = ($form->{"IC_tax_$_"}) ? "checked" : "" }
231
232    if ($form->{selectpartsgroup}) {
233      $partsgroup = qq|\n<select name=partsgroup>|
234      .$form->select_option($form->{selectpartsgroup}, $form->{partsgroup}, 1)
235      .qq|</select>|;
236      $group = $locale->text('Group');
237    }
238
239    $linkaccounts = qq|
240	<tr>
241	  <th align=right nowrap>|.$locale->text('Income').qq|</th>
242	  <td><select name=IC_income>|
243	  .$form->select_option($form->{selectIC_income}, $form->{IC_income})
244	  .qq|</select>
245	  </td>
246	</tr>
247|;
248
249    for (split / /, $form->{taxaccounts}) {
250      $tax .= qq|
251        <input class=checkbox type=checkbox name="IC_tax_$_" value=1 $form->{"IC_tax_$_"}>&nbsp;<b>$form->{"IC_tax_${_}_description"}</b>
252	<br><input type=hidden name=IC_tax_${_}_description value="|.$form->quote($form->{"IC_tax_${_}_description"}).qq|">
253|;
254    }
255
256    if ($tax) {
257      $linkaccounts .= qq|
258              <tr>
259	        <th align=right>|.$locale->text('Tax').qq|</th>
260		<td>$tax</td>
261	      </tr>
262|;
263    }
264
265    $partnumber = qq|
266	<tr>
267	  <td>
268	    <table>
269	      <tr valign=top>
270	        <th align=left>|.$locale->text('Number').qq|</th>
271          <th align=left>|.$locale->text('Description').qq|</th>
272          <th align=left>$group</th>
273	      </tr>
274	      <tr valign=top valign=top>
275	        <td><input name=partnumber value="|.$form->quote($form->{partnumber}).qq|" size=20></td>
276          <td>$partdescription</td>
277          <td>$partsgroup</td>
278	      </tr>
279	    </table>
280	  </td>
281	</tr>
282|;
283
284  $form->{title} = ($form->{id}) ? $locale->text('Edit Job') : $locale->text('Add Job');
285
286  $form->header;
287
288  &calendar;
289
290  print qq|
291<body>
292
293<form method="post" name="main" action="$form->{script}" />
294|;
295
296  for (qw(partnumber startdate enddate)) { $form->{"old$_"} = $form->{$_} }
297
298  $form->hide_form(map { "select$_" } ("IC_income", "$form->{vc}", "partsgroup"));
299  $form->hide_form("old$form->{vc}", "$form->{vc}_id");
300  $form->hide_form(qw(id type orphaned taxaccounts vc project precision));
301
302  print qq|
303
304<table width=100%>
305  <tr>
306    <th class=listtop>$form->{helpref}$form->{title}</a></th>
307  </tr>
308  <tr height="5"></tr>
309  <tr>
310    <td>
311      <table>
312        <tr valign=top>
313          <th align=right>|.$locale->text('Number').qq|</th>
314          <td><input name=projectnumber size=20 value="|.$form->quote($form->{projectnumber}).qq|"></td>
315          <th align=right>|.$locale->text('Description').qq|</th>
316          <td>$description</td>
317        </tr>
318        $name
319        <tr>
320          <th align=right>|.$locale->text('Startdate').qq|</th>
321          <td><input name=startdate size=11 class=date title="$myconfig{dateformat}" value=$form->{startdate}>|.&js_calendar("main", "startdate").qq|</td>
322          <th align=right>|.$locale->text('Enddate').qq|</th>
323          <td><input name=enddate size=11 class=date title="$myconfig{dateformat}" value=$form->{enddate}>|.&js_calendar("main", "enddate").qq|</td>
324        </tr>
325        $production
326      </table>
327    </td>
328  </tr>
329  <tr class="listheading">
330    <th class="listheading" align="center">|.$locale->text('Assembly').qq|</th>
331  </tr>
332  <tr>
333    <td>
334      <table width=100%>
335        $partnumber
336        <tr>
337          <td colspan=3>
338            <table width=100%>
339              <tr>
340                <td width=70%>
341                  <table width=100%>
342                    <tr class="listheading">
343                      <th class="listheading" align="center" colspan=2>|.$locale->text('Link Accounts').qq|</th>
344                    </tr>
345                    $linkaccounts
346                    <tr>
347                      <th align="left">|.$locale->text('Notes').qq|</th>
348                    </tr>
349                    <tr>
350                      <td colspan=2>
351                        $notes
352                      </td>
353                    </tr>
354                  </table>
355                </td>
356                <td align=right>
357                  <table>
358                    <tr>
359                      <th align="right" nowrap="true">|.$locale->text('Updated').qq|</th>
360                      <td><input name=priceupdate size=11 class=date title="$myconfig{dateformat}" value=$form->{priceupdate}>|.&js_calendar("main", "priceupdate").qq|</td>
361                    </tr>
362                    <tr>
363                      <th align="right" nowrap="true">|.$locale->text('Lot').qq|</th>
364                      <td><input name=lot size=10 value="|.$form->quote($form->{lot}).qq|"></td>
365                    </tr>
366                    <tr>
367                      <th align="right" nowrap="true">|.$locale->text('Expires').qq|</th>
368                      <td><input name=expires size=11 class=date title="$myconfig{dateformat}" value=$form->{expires}>|.&js_calendar("main", "expires").qq|</td>
369                    </tr>
370                    <tr>
371                      <th align="right" nowrap="true">|.$locale->text('List Price').qq|</th>
372                      <td><input name=listprice class="inputright" size=11 value=$form->{listprice}></td>
373                    </tr>
374                    <tr>
375                      <th align="right" nowrap="true">|.$locale->text('Sell Price').qq|</th>
376                      <td><input name=sellprice class="inputright" size=11 value=$form->{sellprice}></td>
377                    </tr>
378                    <tr>
379                      <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
380                      <td>
381                  <table>
382                    <tr>
383                      <td>
384                        <input name=weight class="inputright" size=11 value=$form->{weight}>
385                      </td>
386                      <th>
387                        &nbsp;
388                        $form->{weightunit}|
389                        .$form->hide_form(qw(weightunit))
390                        .qq|
391                      </th>
392                    </tr>
393                  </table>
394                      </td>
395                    <tr>
396                      <th align="right" nowrap="true">|.$locale->text('Bin').qq|</th>
397                      <td><input name=bin size=10 value="|.$form->quote($form->{bin}).qq|"></td>
398                    </tr>
399                    <tr>
400                      <th align="right" nowrap="true">|.$locale->text('Unit').qq|</th>
401                      <td><input name=unit size=5 value="|.$form->quote($form->{unit}).qq|"></td>
402                    </tr>
403                  </table>
404                </td>
405              </tr>
406            </table>
407          </td>
408        </tr>
409      </table>
410    </td>
411  </tr>
412  <tr>
413    <td>
414      $reference_documents
415    </td>
416  </tr>
417  <tr>
418    <td><hr size=3 noshade></td>
419  </tr>
420</table>
421|;
422
423}
424
425
426sub job_footer {
427
428  $form->hide_form(qw(reference_rows callback path login));
429
430  %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
431	    );
432
433  if ($myconfig{acs} !~ /Job Costing--Add Job/) {
434    $button{'Save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
435
436    if ($form->{id} && $form->{orphaned}) {
437      $button{'Delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') };
438    }
439  }
440
441  $form->print_button(\%button);
442
443  if ($form->{menubar}) {
444    require "$form->{path}/menu.pl";
445    &menubar;
446  }
447
448  print qq|
449</form>
450
451</body>
452</html>
453|;
454
455}
456
457
458sub list_stock {
459
460  PE->list_stock(\%myconfig, \%$form);
461
462  $form->{title} = $locale->text('Stock Finished Goods');
463  $form->{action} = "list_stock";
464
465  $href = "$form->{script}?";
466  for (qw(action direction oldsort type path login status)) { $href .= "$_=$form->{$_}&" }
467
468  $form->sort_order();
469
470  $callback = "$form->{script}?";
471  for (qw(action direction oldsort type path login status)) { $callback .= "$_=$form->{$_}&" }
472
473  @column_index = $form->sort_columns(qw(projectnumber description startdate partnumber production completed stock));
474
475  if ($form->{projectnumber}) {
476    $href .= "&projectnumber=".$form->escape($form->{projectnumber});
477    $callback .= "&projectnumber=".$form->escape($form->{projectnumber},1);
478    ($var) = split /--/, $form->{projectnumber};
479    $option .= "\n<br>".$locale->text('Job Number')." : $var";
480  }
481  if ($form->{stockingdate}) {
482    $href .= "&stockingdate=$form->{stockingdate}";
483    $callback .= "&stockingdate=$form->{stockingdate}";
484    $option .= "\n<br>".$locale->text('As of')." : ".$locale->date(\%myconfig, $form->{stockingdate}, 1);
485  }
486
487  $column_header{projectnumber} = qq|<th width=30%><a class=listheading href=$href&sort=projectnumber>|.$locale->text('Number').qq|</a></th>|;
488  $column_header{description} = qq|<th width=50%><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
489  $column_header{startdate} = qq|<th width=10%><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|;
490  $column_header{partnumber} = "<th><a class=listheading href=$href&sort=partnumber>" . $locale->text('Assembly') . "</a></th>";
491  $column_header{production} = "<th class=listheading>" . $locale->text('Production') . "</th>";
492  $column_header{completed} = "<th class=listheading>" . $locale->text('Completed') . "</th>";
493  $column_header{stock} = "<th class=listheading>" . $locale->text('Add') . "</th>";
494  $column_header{warehouse} = "<th class=listheading>" . $locale->text('Warehouse') . "</th>";
495
496
497  $form->helpref("list_stock", $myconfig{countrycode});
498
499  $form->header;
500
501  if (@{ $form->{all_project} }) {
502    $sameitem = $form->{all_project}->[0]->{$form->{sort}};
503  }
504
505  if (@{ $form->{all_warehouse} }) {
506    push @column_index, "warehouse";
507    $form->{selectwarehouse} = ($form->{forcewarehouse}) ? "" : "\n";
508    for (@{ $form->{all_warehouse} }) { $form->{selectwarehouse} .= qq|$_->{description}--$_->{id}\n| }
509  }
510
511  print qq|
512<body>
513
514<form method=post action=$form->{script}>
515
516<table width=100%>
517  <tr>
518    <th class=listtop>$form->{helpref}$form->{title}</a></th>
519  </tr>
520  <tr height="5"></tr>
521  <tr>
522    <td>$option</td>
523  </tr>
524  <tr>
525    <td>
526      <table width=100%>
527	<tr class=listheading>
528|;
529
530  for (@column_index) { print "$column_header{$_}\n" }
531
532  print qq|
533        </tr>
534|;
535
536  # escape callback
537  $form->{callback} = $callback .= "&sort=$form->{sort}";
538
539  # escape callback for href
540  $callback = $form->escape($callback);
541
542  $i = 0;
543  foreach $ref (@{ $form->{all_project} }) {
544
545    $i++;
546
547    for (qw(startdate enddate)) { $column_data{$_} = qq|<td nowrap>$ref->{$_}&nbsp;</td>| }
548    for (qw(projectnumber description partnumber)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
549    for (qw(production completed)) { $column_data{$_} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{$_}).qq|</td>| }
550    $column_data{stock} = qq|<td><input name="stock_$i" class="inputright" size=6></td>|;
551    $column_data{warehouse} = qq|<td><select name="warehouse_$i">|.$form->select_option($form->{selectwarehouse}, undef, 1).qq|</td>|;
552
553    $j++; $j %= 2;
554
555    print qq|
556        <tr valign=top class=listrow$j>
557          <input type=hidden name="id_$i" value=$ref->{id}>
558|;
559
560    for (@column_index) { print "$column_data{$_}\n" }
561
562    print "
563        </tr>
564";
565  }
566
567  print qq|
568      </table>
569    </td>
570  </tr>
571  <tr>
572    <td><hr size=3 noshade></td>
573  </tr>
574</table>
575|;
576
577  $form->hide_form(qw(callback type path login status stockingdate));
578
579  print qq|
580<input type=hidden name=nextsub value="stock">
581<br>
582<input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
583</form>
584
585</body>
586</html>
587|;
588
589}
590
591
592sub stock {
593
594  if (PE->stock_assembly(\%myconfig, \%$form)) {
595    $form->redirect($locale->text('Assembly stocked!'));
596  } else {
597    $form->error($locale->text('Cannot stock Assembly!'));
598  }
599
600}
601
602
603sub prepare_project {
604
605  $form->{vc} = 'customer';
606
607  PE->get_project(\%myconfig, \%$form);
608
609  $form->helpref("projects", $myconfig{countrycode});
610
611  $form->{title} = ($form->{id}) ? $locale->text('Edit Project') : $locale->text('Add Project');
612
613  $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
614
615  if (@{ $form->{"all_$form->{vc}"} }) {
616    $form->{"$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
617    $form->{"select$form->{vc}"} = qq|\n|;
618    for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|$_->{name}--$_->{id}\n| }
619  }
620
621  &all_references;
622
623}
624
625
626sub search {
627
628  # accounting years
629  $form->all_years(\%myconfig);
630
631  if (@{ $form->{all_years} }) {
632    $selectaccountingyear = "\n";
633    for (@{ $form->{all_years} }) { $selectaccountingyear .= qq|$_\n| }
634    $selectaccountingmonth = "\n";
635    for (sort keys %{ $form->{all_month} }) { $selectaccountingmonth .= qq|$_--|.$locale->text($form->{all_month}{$_}).qq|\n| }
636
637    $fromto = qq|
638 	<tr>
639	  <th align=right>|.$locale->text('Startdate').qq|</th>
640	  <td>|.$locale->text('From').qq| <input name=startdatefrom size=11 class=date title="$myconfig{dateformat}">|.&js_calendar("main", "startdatefrom")
641	  .$locale->text('To').qq| <input name=startdateto size=11 class=date title="$myconfig{dateformat}">|.&js_calendar("main", "startdateto").qq|</td>
642	</tr>
643|;
644
645  $selectperiod = qq|
646        <tr>
647          <th align=right>|.$locale->text('Period').qq|</th>
648          <td colspan=3>
649          <select name=month>|.$form->select_option($selectaccountingmonth, $form->{month}, 1, 1).qq|</select>
650          <select name=year>|.$form->select_option($selectaccountingyear, $form->{year}).qq|</select>
651          <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
652          <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
653          <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
654          <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
655          </td>
656        </tr>
657|;
658  }
659
660
661  $orphaned = qq|
662	  <input name=status class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned');
663
664  if ($form->{type} eq 'project') {
665    $form->{nextsub} = "project_report";
666    $form->{sort} = "projectnumber";
667    $form->{title} = $locale->text('Projects');
668
669    $number = qq|
670	<tr>
671	  <th align=right>|.$locale->text('Project Number').qq|</th>
672	  <td><input name=projectnumber size=20></td>
673	</tr>
674	<tr>
675	  <th align=right>|.$locale->text('Description').qq|</th>
676	  <td><input name=description size=60></td>
677	</tr>
678|;
679  }
680
681  $form->{reportcode} = $form->{type};
682  $form->reports(\%myconfig, undef, $form->{login});
683
684  if ($form->{type} eq 'stock') {
685    $form->{nextsub} = "list_stock";
686    $form->{title} = $locale->text('Stock Finished Goods');
687    PE->list_stock(\%myconfig, \%$form);
688
689    $selectperiod = "";
690    $orphaned = "";
691    $fromto = qq|
692        <tr>
693          <th align=right nowrap>|.$locale->text('As of').qq|</th>
694          <td><input name=stockingdate size=11 class=date title="$myconfig{dateformat}" value=$form->{stockingdate}>|.&js_calendar("main", "stockingdate").qq|</td>
695        </tr>
696|;
697
698    $number = qq|
699        <tr>
700          <th align=right>|.$locale->text('Job Number').qq|</th>
701          <td><input name=projectnumber size=20></td>
702        </tr>
703        <tr>
704          <th align=right>|.$locale->text('Description').qq|</th>
705          <td><input name=description size=60></td>
706        </tr>
707|;
708
709    @input = qw(projectnumber description stockingdate sort direction reportlogin);
710
711    %radio = ( status => { all => 0, active => 1, inactive => 2 }
712	     );
713
714  }
715
716  if ($form->{type} eq 'job') {
717    $form->{nextsub} = "job_report";
718    $form->{sort} = "projectnumber";
719    $form->{title} = $locale->text('Jobs');
720
721    $number = qq|
722        <tr>
723          <th align=right>|.$locale->text('Job Number').qq|</th>
724          <td><input name=projectnumber size=20></td>
725        </tr>
726        <tr>
727          <th align=right>|.$locale->text('Description').qq|</th>
728          <td><input name=description size=60></td>
729        </tr>
730|;
731
732    @input = qw(projectnumber description startdatefrom startdateto month year sort direction reportlogin);
733
734    %radio = ( interval => { 0 => 0, 1 => 1, 3 => 2, 12 => 3 },
735               status => { all => 0, active => 1, inactive => 2, orphaned => 3 }
736	     );
737
738  }
739
740  if ($form->{type} eq 'partsgroup') {
741    $form->{nextsub} = "partsgroup_report";
742    $form->{sort} = 'partsgroup';
743    $form->{title} = $locale->text('Groups');
744
745    $fromto = "";
746    $selectperiod = "";
747    $number = qq|
748        <tr>
749          <th align=right>|.$locale->text('Group').qq|</th>
750          <td><input name=partsgroup size=20></td>
751        </tr>
752        <tr>
753          <th align=right>|.$locale->text('Code').qq|</th>
754          <td><input name=partsgroupcode size=20></td>
755        </tr>
756|;
757  }
758
759  if ($form->{type} eq 'pricegroup') {
760    $form->{nextsub} = "pricegroup_report";
761    $form->{sort} = 'pricegroup';
762    $form->{title} = $locale->text('Pricegroups');
763
764    $fromto = "";
765    $selectperiod = "";
766    $number = qq|
767        <tr>
768          <th align=right>|.$locale->text('Pricegroup').qq|</th>
769          <td><input name=pricegroup size=20></td>
770        </tr>
771|;
772  }
773
774  if (@{ $form->{all_report} }) {
775    $form->{selectreportform} = "\n";
776    for (@{ $form->{all_report} }) { $form->{selectreportform} .= qq|$_->{reportdescription}--$_->{reportid}\n| }
777
778    $reportform = qq|
779      <tr>
780        <th align=right>|.$locale->text('Report').qq|</th>
781        <td>
782          <select name=report onChange="ChangeReport();">|.$form->select_option($form->{selectreportform}, undef, 1)
783          .qq|</select>
784        </td>
785      </tr>
786|;
787  }
788
789  $form->helpref("search_$form->{type}", $myconfig{countrycode});
790
791  $form->header;
792
793  &calendar;
794
795  &change_report(\%$form, \@input, \@checked, \%radio);
796
797  print qq|
798<body>
799
800<form method=post name=main action=$form->{script}>
801
802<table width=100%>
803  <tr>
804    <th class=listtop>$form->{helpref}$form->{title}</a></th>
805  </tr>
806  <tr height="5"></tr>
807  <tr>
808    <td>
809      <table width=100%>
810        $reportform
811        $number
812        $fromto
813        $selectperiod
814        <tr>
815          <td></td>
816          <td><input name=status class=radio type=radio value=all checked>&nbsp;|.$locale->text('All').qq|
817          <input name=status class=radio type=radio value=active>&nbsp;|.$locale->text('Active').qq|
818          <input name=status class=radio type=radio value=inactive>&nbsp;|.$locale->text('Inactive').qq|
819          $orphaned</td>
820        </tr>
821      </table>
822    </td>
823  </tr>
824  <tr>
825    <td><hr size=3 noshade></td>
826  </tr>
827</table>
828
829|;
830
831  $form->hide_form(qw(path login title sort direction type nextsub reportcode reportlogin));
832
833  print qq|
834<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
835</form>
836|;
837
838  if ($form->{menubar}) {
839    require "$form->{path}/menu.pl";
840    &menubar;
841  }
842
843  print qq|
844
845</body>
846</html>
847|;
848
849}
850
851
852sub job_report {
853
854  for (qw(projectnumber description)) { $form->{$_} = $form->unescape($form->{$_}) }
855  PE->jobs(\%myconfig, \%$form);
856
857  $form->{action} = "job_report";
858  &list_projects;
859
860}
861
862
863sub project_report {
864
865  for (qw(projectnumber description)) { $form->{$_} = $form->unescape($form->{$_}) }
866  PE->projects(\%myconfig, \%$form);
867
868  $form->{action} = "project_report";
869  &list_projects;
870
871}
872
873
874sub list_projects {
875
876  $href = "$form->{script}?";
877  for (qw(action sort direction oldsort type path login status startdatefrom startdateto)) { $href .= "$_=$form->{$_}&" }
878  chop $href;
879
880  $form->sort_order();
881
882  $callback = "$form->{script}?";
883  for (qw(action sort direction oldsort type path login status startdatefrom startdateto)) { $callback .= "$_=$form->{$_}&" }
884  chop $callback;
885
886  @column_index = $form->sort_columns(qw(projectnumber description name startdate enddate));
887
888  if ($form->{status} eq 'all') {
889    $option = $locale->text('All');
890  }
891  if ($form->{status} eq 'orphaned') {
892    $option .= $locale->text('Orphaned');
893  }
894  if ($form->{status} eq 'active') {
895    $option = $locale->text('Active');
896    @column_index = $form->sort_columns(qw(projectnumber description name startdate));
897  }
898  if ($form->{status} eq 'inactive') {
899    $option = $locale->text('Inactive');
900  }
901
902  if ($form->{type} eq 'project') {
903    $label = $locale->text('Project');
904    $form->{title} = $locale->text('Projects');
905  } else {
906    $label = $locale->text('Job');
907    push @column_index, qw(partnumber production completed);
908    $form->{title} = $locale->text('Jobs');
909  }
910
911  if ($form->{projectnumber}) {
912    $href .= "&projectnumber=".$form->escape($form->{projectnumber});
913    $callback .= "&projectnumber=$form->{projectnumber}";
914    $option .= "\n<br>$label : $form->{projectnumber}";
915  }
916  if ($form->{description}) {
917    $href .= "&description=".$form->escape($form->{description});
918    $callback .= "&description=$form->{description}";
919    $option .= "\n<br>".$locale->text('Description')." : $form->{description}";
920  }
921  if ($form->{startdatefrom}) {
922    $href .= "&startdatefrom=$form->{startdatefrom}";
923    $option .= "\n<br>".$locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{startdatefrom}, 1);
924  }
925  if ($form->{startdateto}) {
926    $href .= "&startdateto=$form->{startdateto}";
927    if ($form->{startdatefrom}) {
928      $option .= " ";
929    } else {
930      $option .= "\n<br>" if ($option);
931    }
932    $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{startdateto}, 1);
933  }
934
935
936  $column_header{projectnumber} = qq|<th><a class=listheading href=$href&sort=projectnumber>|.$locale->text('Number').qq|</a></th>|;
937  $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
938  $column_header{startdate} = qq|<th width=10><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|;
939  $column_header{enddate} = qq|<th width=10><a class=listheading href=$href&sort=enddate>|.$locale->text('Enddate').qq|</a></th>|;
940
941  $column_header{partnumber} = "<th><a class=listheading href=$href&sort=partnumber>" . $locale->text('Assembly') . "</a></th>";
942  $column_header{production} = "<th width=10 class=listheading>" . $locale->text('Production') . "</th>";
943  $column_header{completed} = "<th width=10 class=listheading>" . $locale->text('Completed') . "</th>";
944  $column_header{name} = "<th class=listheading>" . $locale->text('Customer') . "</th>";
945
946  $form->helpref("list_$form->{type}", $myconfig{countrycode});
947
948  $form->header;
949
950  if (@{ $form->{all_project} }) {
951    $sameitem = $form->{all_project}->[0]->{$form->{sort}};
952  }
953
954  print qq|
955<body>
956
957<table width=100%>
958  <tr>
959    <th class=listtop>$form->{helpref}$form->{title}</a></th>
960  </tr>
961  <tr height="5"></tr>
962  <tr>
963    <td>$option</td>
964  </tr>
965  <tr>
966    <td>
967      <table width=100%>
968	<tr class=listheading>
969|;
970
971  for (@column_index) { print "$column_header{$_}\n" }
972
973  print qq|
974        </tr>
975|;
976
977  # escape callback
978  $form->{callback} = $callback .= "&sort=$form->{sort}";
979
980  # escape callback for href
981  $callback = $form->escape($callback);
982
983  foreach $ref (@{ $form->{all_project} }) {
984
985    for (qw(startdate enddate)) { $column_data{$_} = qq|<td nowrap>$ref->{$_}&nbsp;</td>| }
986    for (qw(description name)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
987
988    if ($ref->{name}) {
989      $column_data{name} = qq|<td><a href=ct.pl?action=edit&db=customer&id=$ref->{customer_id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{name}</td>|;
990    }
991
992    for (qw(production completed)) { $column_data{$_} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{$_}) }
993
994    $column_data{projectnumber} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&project=$form->{project}&callback=$callback>$ref->{projectnumber}</td>|;
995    $column_data{partnumber} = qq|<td><a href=ic.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{partnumber}</td>|;
996
997    $j++; $j %= 2;
998
999    print qq|
1000        <tr valign=top class=listrow$j>
1001|;
1002
1003    for (@column_index) { print "$column_data{$_}\n" }
1004
1005    print "
1006        </tr>
1007";
1008  }
1009
1010
1011  $i = 1;
1012  if ($form->{type} eq 'project') {
1013    if ($myconfig{acs} !~ /Projects--Projects/) {
1014      $button{'Projects--Add Project'} = { ndx => $i++, key => 'A',  value => $locale->text('Add Project') };
1015    }
1016  } else {
1017    if ($myconfig{acs} !~ /Job Costing--Job Costing/) {
1018      $button{'Job Costing--Add Job'} = { ndx => $i++, key => 'A',  value => $locale->text('Add Job') };
1019    }
1020  }
1021
1022  $button{'Save Report'} = { ndx => $i++, key => 'S', value => $locale->text('Save Report') };
1023
1024  if (!$form->{admin}) {
1025    if ($form->{reportid}) {
1026      $login = $form->{login};
1027      $login =~ s/\@.*//;
1028      if ($form->{reportlogin} ne $login) {
1029        delete $button{'Save Report'};
1030      }
1031    }
1032  }
1033
1034  for (split /;/, $myconfig{acs}) { delete $button{$_} }
1035
1036
1037  print qq|
1038      </table>
1039    </td>
1040  </tr>
1041  <tr>
1042    <td><hr size=3 noshade></td>
1043  </tr>
1044</table>
1045
1046<br>
1047<form method=post action=$form->{script}>
1048|;
1049
1050  if ($form->{year} && $form->{month}) {
1051    for (qw(startdatefrom startdateto)) { delete $form->{$_} }
1052  }
1053  $form->hide_form(qw(projectnumber description startdatefrom startdateto month year sort direction status interval));
1054
1055  $form->hide_form(qw(callback type path login report reportcode reportlogin));
1056
1057  $form->print_button(\%button);
1058
1059  if ($form->{menubar}) {
1060    require "$form->{path}/menu.pl";
1061    &menubar;
1062  }
1063
1064  print qq|
1065  </form>
1066
1067</body>
1068</html>
1069|;
1070
1071}
1072
1073
1074sub project_header {
1075
1076  $reference_documents = &references;
1077
1078  $form->{description} = $form->quote($form->{description});
1079
1080  if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
1081    $description = qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
1082  } else {
1083    $description = qq|<input name=description size=60 value="|.$form->quote($form->{description}).qq|">|;
1084  }
1085
1086  $label = ucfirst $form->{vc};
1087  $vcref = qq|<a href=ct.pl?action=edit&db=$form->{vc}&id=$form->{"$form->{vc}_id"}&login=$form->{login}&path=$form->{path} target=_blank>?</a>|;
1088
1089  if ($form->{"select$form->{vc}"}) {
1090    $name = qq|
1091	<tr>
1092	  <th align=right nowrap>|.$locale->text($label).qq|</th>
1093	  <td colspan=3>
1094          <select name="$form->{vc}"
1095          onChange="javascript:document.main.submit()">|
1096          .$form->select_option($form->{"select$form->{vc}"}, $form->{$form->{vc}}, 1).qq|</select>
1097          $vcref
1098	  </td>
1099          <input name=action type=hidden value=update>
1100	</tr>
1101|;
1102  } else {
1103    $name = qq|
1104	<tr>
1105	  <th align=right nowrap>|.$locale->text($label).qq|</th>
1106	  <td colspan=3><input name="$form->{vc}" value="|.$form->quote($form->{"$form->{vc}"}).qq|" size=35> $vcref</td>
1107	</tr>
1108|;
1109  }
1110
1111
1112  $form->header;
1113
1114  &calendar;
1115
1116  print qq|
1117<body>
1118
1119<form method="post" name="main" action="$form->{script}" />
1120|;
1121
1122  $form->hide_form("select$form->{vc}", "old$form->{vc}", "$form->{vc}_id");
1123  $form->hide_form(qw(id type orphaned vc title helpref));
1124
1125  print qq|
1126<table width=100%>
1127  <tr>
1128    <th class=listtop>$form->{helpref}$form->{title}</a></th>
1129  </tr>
1130  <tr height="5"></tr>
1131  <tr>
1132    <td>
1133      <table>
1134        <tr>
1135          <th align=right>|.$locale->text('Number').qq|</th>
1136          <td><input name=projectnumber size=20 value="|.$form->quote($form->{projectnumber}).qq|"></td>
1137        </tr>
1138        <tr>
1139          <th align=right>|.$locale->text('Description').qq|</th>
1140          <td>$description</td>
1141        </tr>
1142        $name
1143        <tr>
1144          <th align=right>|.$locale->text('Startdate').qq|</th>
1145          <td>
1146          <table>
1147            <tr>
1148              <td><input name=startdate size=11 class=date title="$myconfig{dateformat}" value=$form->{startdate}>|.&js_calendar("main", "startdate").qq|</td>
1149              <th align=right>|.$locale->text('Enddate').qq|</th>
1150              <td><input name=enddate size=11 class=date title="$myconfig{dateformat}" value=$form->{enddate}>|.&js_calendar("main", "enddate").qq|</td>
1151              </tr>
1152            </table>
1153          </td>
1154        </tr>
1155      </table>
1156    </td>
1157  </tr>
1158  <tr>
1159    <td>
1160      $reference_documents
1161    </td>
1162  </tr>
1163  <tr>
1164    <td><hr size=3 noshade></td>
1165  </tr>
1166</table>
1167|;
1168
1169}
1170
1171
1172sub project_footer {
1173
1174  $form->hide_form(qw(reference_rows callback path login));
1175
1176  %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
1177	    );
1178
1179  if ($myconfig{acs} !~ /Projects--Add Project/) {
1180    $button{'Save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
1181
1182    if ($form->{id} && $form->{orphaned}) {
1183      $button{'Delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') };
1184    }
1185  }
1186
1187  $form->print_button(\%button);
1188
1189  if ($form->{menubar}) {
1190    require "$form->{path}/menu.pl";
1191    &menubar;
1192  }
1193
1194  print qq|
1195</form>
1196
1197</body>
1198</html>
1199|;
1200
1201}
1202
1203
1204sub save {
1205
1206  $form->{userspath} = $userspath;
1207
1208  if ($form->{translation}) {
1209    PE->save_translation(\%myconfig, \%$form);
1210    $form->redirect($locale->text('Translations saved!'));
1211    exit;
1212  }
1213
1214  if ($form->{type} eq 'project') {
1215
1216    if ($form->{"select$form->{vc}"}) {
1217      (undef, $form->{"$form->{vc}_id"}) = split /--/, $form->{"$form->{vc}"};
1218    } else {
1219      if ($form->{"old$form->{vc}"} ne qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|) {
1220
1221        if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{startdate})) > 1) {
1222          &select_name;
1223          exit;
1224        }
1225
1226        if ($rv == 1) {
1227          $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
1228          $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
1229          $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
1230        }
1231      }
1232    }
1233
1234    PE->save_project(\%myconfig, \%$form);
1235    $form->redirect($locale->text('Project saved!'));
1236  }
1237
1238  if ($form->{type} eq 'partsgroup') {
1239    $form->isblank("partsgroup", $locale->text('Group missing!'));
1240    PE->save_partsgroup(\%myconfig, \%$form);
1241    $form->redirect($locale->text('Group saved!'));
1242  }
1243
1244  if ($form->{type} eq 'pricegroup') {
1245    $form->isblank("pricegroup", $locale->text('Pricegroup missing!'));
1246    PE->save_pricegroup(\%myconfig, \%$form);
1247    $form->redirect($locale->text('Pricegroup saved!'));
1248  }
1249
1250
1251  if ($form->{type} eq 'job') {
1252
1253    if ($form->{"select$form->{vc}"}) {
1254      (undef, $form->{"$form->{vc}_id"}) = split /--/, $form->{"$form->{vc}"};
1255      $form->error($locale->text('Customer missing!')) unless $form->{"$form->{vc}_id"};
1256    } else {
1257      if ($form->{"old$form->{vc}"} ne qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|) {
1258
1259        if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{startdate})) > 1) {
1260          &select_name;
1261          exit;
1262        }
1263
1264        if ($rv == 1) {
1265          $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
1266          $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
1267          $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
1268        }
1269      }
1270    }
1271
1272    PE->save_job(\%myconfig, \%$form);
1273    $form->redirect($locale->text('Job saved!'));
1274  }
1275
1276}
1277
1278
1279sub save_as_new {
1280
1281  delete $form->{id};
1282  &save;
1283
1284}
1285
1286
1287sub delete {
1288
1289  if ($form->{translation}) {
1290    PE->delete_translation(\%myconfig, \%$form);
1291    $form->redirect($locale->text('Translation deleted!'));
1292
1293  } else {
1294
1295    if ($form->{type} eq 'project') {
1296      PE->delete_project(\%myconfig, \%$form);
1297      $form->redirect($locale->text('Project deleted!'));
1298    }
1299    if ($form->{type} eq 'job') {
1300      PE->delete_job(\%myconfig, \%$form);
1301      $form->redirect($locale->text('Job deleted!'));
1302    }
1303    if ($form->{type} eq 'partsgroup') {
1304      PE->delete_partsgroup(\%myconfig, \%$form);
1305      $form->redirect($locale->text('Group deleted!'));
1306    }
1307    if ($form->{type} eq 'pricegroup') {
1308      PE->delete_pricegroup(\%myconfig, \%$form);
1309      $form->redirect($locale->text('Pricegroup deleted!'));
1310    }
1311  }
1312
1313}
1314
1315
1316sub partsgroup_report {
1317
1318  for (qw(partsgroup partsgroupcode)) { $form->{$_} = $form->unescape($form->{$_}) }
1319  PE->partsgroups(\%myconfig, \%$form);
1320
1321  $href = "$form->{script}?action=partsgroup_report&sort=$form->{sort}&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&status=$form->{status}";
1322
1323  $form->sort_order();
1324
1325  $callback = "$form->{script}?action=partsgroup_report&sort=$form->{sort}&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&status=$form->{status}";
1326
1327  if ($form->{status} eq 'all') {
1328    $option = $locale->text('All');
1329  }
1330  if ($form->{status} eq 'orphaned') {
1331    $option .= $locale->text('Orphaned');
1332  }
1333  if ($form->{partsgroup}) {
1334    $href .= "&partsgroup=".$form->escape($form->{partsgroup});
1335    $callback .= "&partsgroup=$form->{partsgroup}";
1336    $option .= "\n<br>".$locale->text('Group')." : $form->{partsgroup}";
1337  }
1338  if ($form->{partsgroupcode}) {
1339    $href .= "&partsgroupcode=".$form->escape($form->{partsgroupcode});
1340    $callback .= "&partsgroupcode=$form->{partsgroupcode}";
1341    $option .= "\n<br>".$locale->text('Code')." : $form->{partsgroupcode}";
1342  }
1343
1344  @column_index = $form->sort_columns(qw(partsgroup code image pos));
1345
1346  $column_header{partsgroup} = qq|<th><a class=listheading href=$href&sort=partsgroup width=90%>|.$locale->text('Group').qq|</a></th>|;
1347  $column_header{code} = qq|<th><a class=listheading href=$href&sort=code>|.$locale->text('Code').qq|</a></th>|;
1348  $column_header{pos} = qq|<th class=listheading>|.$locale->text('POS').qq|</th>|;
1349  $column_header{image} = qq|<th class=listheading>|.$locale->text('Image').qq|</th>|;
1350
1351  $form->{title} = $locale->text('Groups') . " / $form->{company}";
1352
1353  $form->helpref("partsgroup_report", $myconfig{countrycode});
1354
1355  $form->header;
1356
1357  print qq|
1358<body>
1359
1360<table width=100%>
1361  <tr>
1362    <th class=listtop>$form->{helpref}$form->{title}</a></th>
1363  </tr>
1364  <tr height="5"></tr>
1365  <tr>
1366    <td>$option</td>
1367  </tr>
1368  <tr>
1369    <td>
1370      <table width=100%>
1371	<tr class=listheading>
1372|;
1373
1374  for (@column_index) { print "$column_header{$_}\n" }
1375
1376  print qq|
1377        </tr>
1378|;
1379
1380  # escape callback
1381  $form->{callback} = $callback;
1382
1383  # escape callback for href
1384  $callback = $form->escape($callback);
1385
1386  foreach $ref (@{ $form->{item_list} }) {
1387
1388    $i++; $i %= 2;
1389
1390    print qq|
1391        <tr valign=top class=listrow$i>
1392|;
1393
1394    $column_data{partsgroup} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{partsgroup}</td>|;
1395    $column_data{code} = qq|<td>$ref->{code}</td>|;
1396    $pos = ($ref->{pos}) ? "*" : "&nbsp;";
1397    $column_data{pos} = qq|<td align=center>$pos</td>|;
1398    $column_data{image} = ($ref->{image}) ? "<td width=10%><a href=$images/$myconfig{dbname}/$ref->{image}><img src=$images/$myconfig{dbname}/$ref->{image} height=32 border=0></a></td>" : "<td>&nbsp;</td>";
1399
1400    for (@column_index) { print "$column_data{$_}\n" }
1401
1402    print "
1403        </tr>
1404";
1405  }
1406
1407  if ($myconfig{acs} !~ /Goods \& Services--Goods \& Services/) {
1408    $button{'Goods & Services--Add Group'} = { ndx => 1, key => 'A', value => $locale->text('Add Group') };
1409
1410    foreach $item (split /;/, $myconfig{acs}) {
1411      delete $button{$item};
1412    }
1413  }
1414
1415  print qq|
1416      </table>
1417    </td>
1418  </tr>
1419  <tr>
1420    <td><hr size=3 noshade></td>
1421  </tr>
1422</table>
1423
1424<br>
1425<form method=post action=$form->{script}>
1426|;
1427
1428  $form->{code} = $form->{partsgroupcode};
1429  $form->hide_form(qw(partsgroup code callback type path login));
1430
1431  $form->print_button(\%button);
1432
1433  if ($form->{menubar}) {
1434    require "$form->{path}/menu.pl";
1435    &menubar;
1436  }
1437
1438  print qq|
1439  </form>
1440
1441</body>
1442</html>
1443|;
1444
1445}
1446
1447
1448sub partsgroup_header {
1449
1450  $form->{action} =~ s/_.*//g;
1451  $form->{title} = $locale->text(ucfirst $form->{action}." ".$locale->text('Group'));
1452
1453# $locale->text('Add Group')
1454# $locale->text('Edit Group')
1455
1456  for (qw(partsgroup code)) { $form->{$_} = $form->quote($form->{$_}) }
1457  $form->{pos} = ($form->{pos}) ? "checked" : "";
1458
1459  $form->helpref("partsgroup", $myconfig{countrycode});
1460
1461  $preview = ($form->{image}) ? qq|<a href=$images/$myconfig{dbname}/$form->{image}> ?| : qq| <a href="ic.pl?action=upload_image&login=$form->{login}&path=$form->{path}" target=popup>?</a>|;
1462
1463  $form->header;
1464
1465  print qq|
1466<body>
1467
1468<form method=post action=$form->{script}>
1469
1470<table width=100%>
1471  <tr>
1472    <th class=listtop>$form->{helpref}$form->{title}</a></th>
1473  </tr>
1474  <tr height="5"></tr>
1475  <tr>
1476    <td>
1477      <table>
1478        <tr>
1479          <th align=right nowrap>|.$locale->text('Group').qq| <font color=red>*</font></th>
1480
1481          <td><input name=partsgroup size=40 value="$form->{partsgroup}"></td>
1482        </tr>
1483        <tr>
1484          <th align=right nowrap>|.$locale->text('Code').qq|</th>
1485                <td><input name=code size=10 value="$form->{code}"></td>
1486        </tr>
1487        <tr>
1488          <th align=right nowrap>|.$locale->text('Image').qq|</th>
1489          <td><input name=image size=20 value="$form->{image}">$preview</td>
1490        </tr>
1491        <tr>
1492          <th align=right nowrap>|.$locale->text('POS Button').qq|</th>
1493                <td><input name=pos class=checkbox type=checkbox value=1 $form->{pos}></td>
1494        </tr>
1495      </table>
1496    </td>
1497  </tr>
1498  <tr>
1499    <td colspan=2><hr size=3 noshade></td>
1500  </tr>
1501</table>
1502|;
1503
1504  $form->hide_form(qw(id type));
1505
1506}
1507
1508
1509sub partsgroup_footer {
1510
1511  $form->hide_form(qw(callback path login));
1512
1513  if ($myconfig{acs} !~ /Goods \& Services--Add Group/) {
1514    print qq|
1515<input type=submit class=submit name=action value="|.$locale->text('Save').qq|">
1516|;
1517
1518    if ($form->{id}) {
1519
1520      print qq|
1521<input type=submit class=submit name=action value="|.$locale->text('Save as new').qq|">
1522|;
1523      if ($form->{orphaned}) {
1524        print qq|
1525<input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|;
1526      }
1527    }
1528  }
1529
1530  if ($form->{menubar}) {
1531    require "$form->{path}/menu.pl";
1532    &menubar;
1533  }
1534
1535  print qq|
1536</form>
1537
1538</body>
1539</html>
1540|;
1541
1542}
1543
1544
1545sub pricegroup_report {
1546
1547  $form->{pricegroup} = $form->unescape($form->{pricegroup});
1548  PE->pricegroups(\%myconfig, \%$form);
1549
1550  $href = "$form->{script}?action=pricegroup_report&sort=$form->{sort}&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&status=$form->{status}";
1551
1552  $form->sort_order();
1553
1554  $callback = "$form->{script}?action=pricegroup_report&sort=$form->{sort}&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&status=$form->{status}";
1555
1556  if ($form->{status} eq 'all') {
1557    $option = $locale->text('All');
1558  }
1559  if ($form->{status} eq 'orphaned') {
1560    $option .= $locale->text('Orphaned');
1561  }
1562  if ($form->{pricegroup}) {
1563    $callback .= "&pricegroup=$form->{pricegroup}";
1564    $option .= "\n<br>".$locale->text('Pricegroup')." : $form->{pricegroup}";
1565  }
1566
1567
1568  @column_index = $form->sort_columns(qw(pricegroup));
1569
1570  $column_header{pricegroup} = qq|<th><a class=listheading href=$href&sort=pricegroup width=90%>|.$locale->text('Pricegroup').qq|</th>|;
1571
1572  $form->{title} = $locale->text('Pricegroups') . " / $form->{company}";
1573
1574  $form->helpref("pricegroup_report", $myconfig{countrycode});
1575
1576  $form->header;
1577
1578  print qq|
1579<body>
1580
1581<table width=100%>
1582  <tr>
1583    <th class=listtop>$form->{helpref}$form->{title}</a></th>
1584  </tr>
1585  <tr height="5"></tr>
1586  <tr>
1587    <td>$option</td>
1588  </tr>
1589  <tr>
1590    <td>
1591      <table width=100%>
1592        <tr class=listheading>
1593|;
1594
1595  for (@column_index) { print "$column_header{$_}\n" }
1596
1597  print qq|
1598        </tr>
1599|;
1600
1601  # escape callback
1602  $form->{callback} = $callback;
1603
1604  # escape callback for href
1605  $callback = $form->escape($callback);
1606
1607  foreach $ref (@{ $form->{item_list} }) {
1608
1609    $i++; $i %= 2;
1610
1611    print qq|
1612        <tr valign=top class=listrow$i>
1613|;
1614
1615    $column_data{pricegroup} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&callback=$callback>$ref->{pricegroup}</td>|;
1616    for (@column_index) { print "$column_data{$_}\n" }
1617
1618    print "
1619        </tr>
1620";
1621  }
1622
1623  if ($myconfig{acs} !~ /Goods \& Services--Goods \& Services/) {
1624    $button{'Goods & Services--Add Pricegroup'} = { ndx => 1, key => 'A', value => $locale->text('Add Pricegroup') };
1625
1626    foreach $item (split /;/, $myconfig{acs}) {
1627      delete $button{$item};
1628    }
1629  }
1630
1631  print qq|
1632      </table>
1633    </td>
1634  </tr>
1635  <tr>
1636    <td><hr size=3 noshade></td>
1637  </tr>
1638</table>
1639
1640<br>
1641<form method=post action=$form->{script}>
1642|;
1643
1644  $form->hide_form(qw(callback type path login));
1645
1646  $form->print_button(\%button);
1647
1648  if ($form->{menubar}) {
1649    require "$form->{path}/menu.pl";
1650    &menubar;
1651  }
1652
1653  print qq|
1654  </form>
1655
1656</body>
1657</html>
1658|;
1659
1660}
1661
1662
1663sub pricegroup_header {
1664
1665  $form->{title} = $locale->text(ucfirst $form->{action}." ".$locale->text('Pricegroup'));
1666
1667# $locale->text('Add Pricegroup')
1668# $locale->text('Edit Pricegroup')
1669
1670  $form->{pricegroup} = $form->quote($form->{pricegroup});
1671
1672  $form->helpref("pricegroup", $myconfig{countrycode});
1673
1674  $form->header;
1675
1676  print qq|
1677<body>
1678
1679<form method=post action=$form->{script}>
1680
1681<table width=100%>
1682  <tr>
1683    <th class=listtop>$form->{helpref}$form->{title}</a></th>
1684  </tr>
1685  <tr height="5"></tr>
1686  <tr>
1687    <td>
1688      <table>
1689        <tr>
1690          <th align=right nowrap>|.$locale->text('Pricegroup').qq| <font color=red>*</font></th>
1691
1692          <td><input name=pricegroup size=30 value="|.$form->quote($form->{pricegroup}).qq|"></td>
1693        </tr>
1694      </table>
1695    </td>
1696  </tr>
1697  <tr>
1698    <td colspan=2><hr size=3 noshade></td>
1699  </tr>
1700</table>
1701|;
1702
1703  $form->hide_form(qw(id type));
1704
1705}
1706
1707
1708sub pricegroup_footer {
1709
1710  $form->hide_form(qw(callback path login));
1711
1712  if ($myconfig{acs} !~ /Goods \& Services--Add Pricegroup/) {
1713    print qq|
1714<input type=submit class=submit name=action value="|.$locale->text('Save').qq|">
1715|;
1716
1717    if ($form->{id} && $form->{orphaned}) {
1718      print qq|
1719<input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|;
1720    }
1721  }
1722
1723  if ($form->{menubar}) {
1724    require "$form->{path}/menu.pl";
1725    &menubar;
1726  }
1727
1728  print qq|
1729</form>
1730
1731</body>
1732</html>
1733|;
1734
1735}
1736
1737
1738sub translation {
1739
1740  if ($form->{translation} eq 'description') {
1741    $form->{title} = $locale->text('Description Translations');
1742    $form->helpref("item_translation", $myconfig{countrycode});
1743
1744    $sort = qq|<input type=hidden name=sort value=partnumber>|;
1745    $form->{number} = "partnumber";
1746    $number = qq|
1747        <tr>
1748          <th align=right nowrap>|.$locale->text('Number').qq|</th>
1749          <td><input name=partnumber size=20></td>
1750        </tr>
1751|;
1752  }
1753
1754  if ($form->{translation} eq 'partsgroup') {
1755    $form->{title} = $locale->text('Group Translations');
1756    $sort = qq|<input type=hidden name=sort value=partsgroup>|;
1757    $form->helpref("group_translation", $myconfig{countrycode});
1758  }
1759
1760  if ($form->{translation} eq 'project') {
1761    $form->{title} = $locale->text('Project/Job Description Translations');
1762    $form->helpref("project_job_translation", $myconfig{countrycode});
1763    $form->{number} = "projectnumber";
1764    $sort = qq|<input type=hidden name=sort value=projectnumber>|;
1765    $number = qq|
1766        <tr>
1767          <th align=right nowrap>|.$locale->text('Project/Job Number').qq|</th>
1768          <td><input name=projectnumber size=20></td>
1769        </tr>
1770|;
1771  }
1772
1773  if ($form->{translation} eq 'chart') {
1774    $form->{title} = $locale->text('Chart of Accounts Translations');
1775    $form->helpref("coa_translation", $myconfig{countrycode});
1776    $form->{number} = "accno";
1777    $sort = qq|<input type=hidden name=sort value=accno>|;
1778    $number = qq|
1779        <tr>
1780          <th align=right nowrap>|.$locale->text('Account').qq|</th>
1781          <td><input name=accno size=20></td>
1782        </tr>
1783|;
1784  }
1785
1786
1787  $form->header;
1788
1789  print qq|
1790<body>
1791
1792<form method=post action=$form->{script}>
1793|;
1794
1795  $form->hide_form(qw(translation title number));
1796
1797  print qq|
1798
1799<table width="100%">
1800  <tr><th class=listtop>$form->{helpref}$form->{title}</a></th></tr>
1801  <tr height="5"></tr>
1802  <tr valign=top>
1803    <td>
1804      <table>
1805        $number
1806        <tr>
1807          <th align=right nowrap>|.$locale->text('Description').qq|</th>
1808          <td colspan=3><input name=description size=40></td>
1809        </tr>
1810      </table>
1811    </td>
1812  </tr>
1813  <tr><td><hr size=3 noshade></td></tr>
1814</table>
1815
1816<input type=hidden name=nextsub value=list_translations>
1817$sort
1818|;
1819
1820  $form->hide_form(qw(path login));
1821
1822  print qq|
1823
1824<br>
1825<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
1826</form>
1827
1828</body>
1829</html>
1830|;
1831
1832}
1833
1834
1835sub list_translations {
1836
1837  $title = $form->escape($form->{title},1);
1838
1839  $callback = "$form->{script}?action=list_translations&path=$form->{path}&login=$form->{login}&translation=$form->{translation}&number=$form->{number}&title=$title";
1840
1841  if ($form->{"$form->{number}"}) {
1842    $callback .= qq|&$form->{number}=$form->{"$form->{number}"}|;
1843    $option .= $locale->text('Number').qq| : $form->{"$form->{number}"}<br>|;
1844  }
1845  if ($form->{description}) {
1846    $callback .= "&description=$form->{description}";
1847    $description = $form->{description};
1848    $description =~ s/\r?\n/<br>/g;
1849    $option .= $locale->text('Description').qq| : $form->{description}<br>|;
1850  }
1851
1852  if ($form->{translation} eq 'partsgroup') {
1853    @column_index = qw(description language translation);
1854    $form->{sort} = "";
1855  } else {
1856    @column_index = $form->sort_columns("$form->{number}", "description", "language", "translation");
1857  }
1858
1859  &{ "PE::$form->{translation}_translations" }("", \%myconfig, \%$form);
1860
1861  $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
1862
1863  $href = $callback;
1864
1865  $form->sort_order();
1866
1867  $callback =~ s/(direction=).*\&{1}/$1$form->{direction}\&/;
1868
1869  $column_header{"$form->{number}"} = qq|<th nowrap><a class=listheading href=$href&sort=$form->{number}>|.$locale->text('Number').qq|</a></th>|;
1870  $column_header{description} = qq|<th nowrap width=40%><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
1871  $column_header{language} = qq|<th nowrap class=listheading>|.$locale->text('Language').qq|</a></th>|;
1872  $column_header{translation} = qq|<th nowrap width=40% class=listheading>|.$locale->text('Translation').qq|</a></th>|;
1873
1874  $form->header;
1875
1876  $form->helpref("list_$form->{translation}_translations", $myconfig{countrycode});
1877
1878  print qq|
1879<body>
1880
1881<table width=100%>
1882  <tr>
1883    <th class=listtop>$form->{helpref}$form->{title}</a></th>
1884  </tr>
1885  <tr height="5"></tr>
1886
1887  <tr><td>$option</td></tr>
1888
1889  <tr>
1890    <td>
1891      <table width=100%>
1892        <tr class=listheading>
1893|;
1894
1895  for (@column_index) { print "\n$column_header{$_}" }
1896
1897  print qq|
1898        </tr>
1899  |;
1900
1901
1902  # add order to callback
1903  $form->{callback} = $callback .= "&sort=$form->{sort}";
1904
1905  # escape callback for href
1906  $callback = $form->escape($callback);
1907
1908  if (@{ $form->{translations} }) {
1909    $sameitem = $form->{translations}->[0]->{$form->{sort}};
1910  }
1911
1912  foreach $ref (@{ $form->{translations} }) {
1913
1914    $ref->{description} =~ s/\r?\n/<br>/g;
1915
1916    for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
1917
1918    $column_data{description} = "<td><a href=$form->{script}?action=edit_translation&translation=$form->{translation}&number=$form->{number}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&title=$title&callback=$callback>$ref->{description}&nbsp;</a></td>";
1919
1920    $i++; $i %= 2;
1921    print "<tr class=listrow$i>";
1922
1923    for (@column_index) { print "\n$column_data{$_}" }
1924
1925    print qq|
1926    </tr>
1927|;
1928
1929  }
1930
1931  print qq|
1932      </table>
1933    </td>
1934  </tr>
1935  <tr><td><hr size=3 noshade></td></tr>
1936</table>
1937
1938|;
1939
1940  print qq|
1941
1942<br>
1943
1944<form method=post action=$form->{script}>
1945
1946|;
1947
1948  $form->hide_form(qw(path login callback));
1949
1950  if ($form->{menubar}) {
1951    require "$form->{path}/menu.pl";
1952    &menubar;
1953  }
1954
1955  print qq|
1956  </form>
1957
1958</body>
1959</html>
1960|;
1961
1962}
1963
1964
1965sub edit_translation {
1966
1967  &{ "PE::$form->{translation}_translations" }("", \%myconfig, \%$form);
1968
1969  $form->error($locale->text('Languages not defined!')) unless @{ $form->{all_language} };
1970
1971  $form->helpref("$form->{translation}_translations", $myconfig{countrycode});
1972
1973  $form->{selectlanguage} = qq|\n|;
1974  for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|$_->{code}--$_->{description}\n| }
1975
1976  $form->{"$form->{number}"} = $form->{translations}->[0]->{"$form->{number}"};
1977  $form->{description} = $form->{translations}->[0]->{description};
1978  $form->{description} =~ s/\r?\n/<br>/g;
1979
1980  shift @{ $form->{translations} };
1981
1982  $i = 1;
1983  foreach $row (@{ $form->{translations} }) {
1984    $form->{"language_code_$i"} = $row->{code};
1985    $form->{"translation_$i"} = $row->{translation};
1986    $i++;
1987  }
1988  $form->{translation_rows} = $i - 1;
1989
1990# $locale->text('Edit Project Description Translations')
1991# $locale->text('Edit Description Translations')
1992# $locale->text('Edit Group Translations')
1993
1994  $form->{title} = "Edit $form->{title}";
1995
1996  $form->{selectlanguage} = $form->escape($form->{selectlanguage},1);
1997
1998  &translation_header;
1999  &translation_footer;
2000
2001}
2002
2003
2004sub translation_header {
2005
2006  $form->{translation_rows}++;
2007
2008  $form->header;
2009
2010  print qq|
2011<body>
2012
2013<form method=post action=$form->{script}>
2014|;
2015
2016  $form->hide_form("$form->{number}", "description");
2017  $form->hide_form(qw(id trans_id selectlanguage translation_rows number translation title helpref));
2018
2019  print qq|
2020
2021<table width="100%">
2022  <tr><th class=listtop>$form->{helpref}$form->{title}</a></th></tr>
2023  <tr height="5"></tr>
2024  <tr valign=top>
2025    <td>
2026      <table width=100%>
2027        <tr>
2028          <td align=left>$form->{"$form->{number}"}</th>
2029          <td align=left>$form->{description}</th>
2030        </tr>
2031        <tr>
2032        <tr>
2033          <th class=listheading>|.$locale->text('Language').qq|</th>
2034          <th class=listheading>|.$locale->text('Translation').qq|</th>
2035        </tr>
2036|;
2037
2038  for $i (1 .. $form->{translation_rows}) {
2039
2040    if (($rows = $form->numtextrows($form->{"translation_$i"}, 40)) > 1) {
2041      $translation = qq|<textarea name="translation_$i" rows=$rows cols=40 wrap=soft>$form->{"translation_$i"}</textarea>|;
2042    } else {
2043      $translation = qq|<input name="translation_$i" size=40 value="|.$form->quote($form->{"translation_$i"}).qq|">|;
2044    }
2045
2046    print qq|
2047	<tr valign=top>
2048	  <td><select name="language_code_$i">|
2049	  .$form->select_option($form->{selectlanguage}, $form->{"language_code_$i"}, undef, 1)
2050	  .qq|</select>
2051	  </td>
2052	  <td>$translation</td>
2053	</tr>
2054|;
2055  }
2056
2057  print qq|
2058      </table>
2059    </td>
2060  </tr>
2061  <tr>
2062    <td><hr size=3 noshade></td>
2063  </tr>
2064</table>
2065|;
2066
2067}
2068
2069
2070sub translation_footer {
2071
2072  $form->hide_form(qw(path login callback));
2073
2074  %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
2075	     'Save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
2076	     'Delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') },
2077	    );
2078
2079  if (! $form->{trans_id}) {
2080    delete $button{'Delete'};
2081  }
2082
2083  $form->print_button(\%button);
2084
2085  if ($form->{menubar}) {
2086    require "$form->{path}/menu.pl";
2087    &menubar;
2088  }
2089
2090  print qq|
2091
2092  </form>
2093
2094</body>
2095</html>
2096|;
2097
2098}
2099
2100
2101sub update {
2102
2103  if ($form->{translation}) {
2104    @flds = qw(language translation);
2105    $count = 0;
2106    @f = ();
2107    for $i (1 .. $form->{translation_rows}) {
2108      if ($form->{"language_code_$i"} ne "") {
2109        push @f, {};
2110        $j = $#f;
2111
2112        for (@flds) { $f[$j]->{$_} = $form->{"${_}_$i"} }
2113        $count++;
2114      }
2115    }
2116    $form->redo_rows(\@flds, \@f, $count, $form->{translation_rows});
2117    $form->{translation_rows} = $count;
2118
2119    &translation_header;
2120    &translation_footer;
2121
2122    exit;
2123
2124  }
2125
2126  if ($form->{type} =~ /(job|project)/) {
2127
2128# $locale->text('Customer not on file!')
2129# $locale->text('Vendor not on file!')
2130
2131    for (qw(listprice sellprice weight)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2132
2133    if ($form->{"select$form->{vc}"}) {
2134
2135      (undef, $form->{"$form->{vc}_id"}) = split /--/, $form->{"$form->{vc}"};
2136      $form->{"old$form->{vc}"} = $form->{"$form->{vc}"};
2137
2138      if ($form->{startdate} ne $form->{oldstartdate} || $form->{enddate} ne $form->{oldenddate}) {
2139
2140        PE->get_customer(\%myconfig, \%$form);
2141
2142        if (@{ $form->{"all_$form->{vc}"} }) {
2143          $form->{"select$form->{vc}"} = qq|\n|;
2144          for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|$_->{name}--$_->{id}\n| }
2145          $form->{"select$form->{vc}"} = $form->escape($form->{"select$form->{vc}"},1);
2146        }
2147      }
2148
2149    } else {
2150
2151      if ($form->{"old$form->{vc}"} ne qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|) {
2152
2153        if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{startdate})) > 1) {
2154          &select_name;
2155          exit;
2156        }
2157
2158        if ($rv == 1) {
2159          $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
2160          $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
2161          $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
2162        } else {
2163          $msg = ucfirst $form->{vc} ." not on file!";
2164          $form->error($locale->text($msg));
2165        }
2166      }
2167    }
2168  }
2169
2170  &display_form;
2171
2172}
2173
2174
2175sub select_name {
2176
2177  $label = ucfirst $form->{vc};
2178# $locale->text('Customer Number')
2179# $locale->text('Vendor Number')
2180
2181  $labelnumber = $locale->text("$label Number");
2182  @column_index = (ndx, name, "$form->{vc}number", address);
2183
2184  $column_data{ndx} = qq|<th class=listheading width=1%>&nbsp;</th>|;
2185  $column_data{name} = qq|<th class=listheading>|.$locale->text($label).qq|</th>|;
2186  $column_data{"$form->{vc}number"} = qq|<th class=listheading>$labelnumber</th>|;
2187  $column_data{address} = qq|<th class=listheading colspan=5>|.$locale->text('Address').qq|</th>|;
2188
2189  $form->header;
2190  $title = $locale->text('Select from one of the names below');
2191  print qq|
2192<body>
2193
2194<form method=post action=$form->{script}>
2195
2196<table width=100%>
2197  <tr>
2198    <th class=listtop>$title</th>
2199  </tr>
2200  <tr space=5></tr>
2201  <tr>
2202    <td>
2203      <table width=100%>
2204        <tr class=listheading>|;
2205
2206  for (@column_index) { print "\n$column_data{$_}" }
2207
2208  print qq|
2209	</tr>
2210|;
2211
2212  push @column_index, (city, state, zipcode, country);
2213
2214  my $i = 0;
2215  foreach $ref (@{ $form->{name_list} }) {
2216    $checked = ($i++) ? "" : "checked";
2217
2218    $ref->{name} = $form->quote($ref->{name});
2219
2220    $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
2221    $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="|.$form->quote($ref->{name}).qq|">$ref->{name}</td>|;
2222
2223    $column_data{"$form->{vc}number"} = qq|<td><input name="new_$form->{vc}number{_}_$i" type=hidden value="|.$form->quote($ref->{"$form->{vc}number"}).qq|">$ref->{"$form->{vc}number"}</td>|;
2224    $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}</td>|;
2225    for (qw(city state zipcode country)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
2226
2227    $j++; $j %= 2;
2228    print qq|
2229	<tr class=listrow$j>|;
2230
2231    for (@column_index) { print "\n$column_data{$_}" }
2232
2233    print qq|
2234	</tr>
2235
2236<input name="new_id_$i" type=hidden value=$ref->{id}>
2237
2238|;
2239
2240  }
2241
2242  print qq|
2243      </table>
2244    </td>
2245  </tr>
2246  <tr>
2247    <td><hr size=3 noshade></td>
2248  </tr>
2249</table>
2250
2251<input name=lastndx type=hidden value=$i>
2252
2253|;
2254
2255  # delete variables
2256  for (qw(action nextsub name_list)) { delete $form->{$_} }
2257
2258  $form->hide_form;
2259
2260  print qq|
2261<input type=hidden name=nextsub value=name_selected>
2262<br>
2263<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
2264</form>
2265
2266</body>
2267</html>
2268|;
2269
2270}
2271
2272
2273sub name_selected {
2274
2275  # replace the variable with the one checked
2276
2277  # index for new item
2278  $i = $form->{ndx};
2279
2280  $form->{$form->{vc}} = $form->{"new_name_$i"};
2281  $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
2282  $form->{"$form->{vc}number"} = $form->{"new_$form->{vc}number{_}_$i"};
2283  $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
2284
2285  # delete all the new_ variables
2286  for $i (1 .. $form->{lastndx}) {
2287    for (qw(id name)) { delete $form->{"new_${_}_$i"} }
2288  }
2289
2290  for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
2291
2292  &display_form;
2293
2294}
2295
2296
2297sub display_form {
2298
2299  &{ "$form->{type}_header" };
2300  &{ "$form->{type}_footer" };
2301
2302}
2303
2304sub continue { &{ $form->{nextsub} } };
2305
2306sub add_group { &add }
2307sub add_project { &add }
2308sub add_job { &add }
2309sub add_pricegroup { &add }
2310
2311
2312
2313sub project_sales_order {
2314
2315  PE->project_sales_order(\%myconfig, \%$form);
2316
2317  if (@{ $form->{all_years} }) {
2318    $selectaccountingyear = "\n";
2319    for (@{ $form->{all_years} }) { $selectaccountingyear .= qq|$_\n| }
2320    $selectaccountingmonth = "\n";
2321    for (sort keys %{ $form->{all_month} }) { $selectaccountingmonth .= qq|$_--|.$locale->text($form->{all_month}{$_}).qq|\n| }
2322
2323    $selectfrom = qq|
2324        <tr>
2325          <th align=right>|.$locale->text('Period').qq|</th>
2326          <td colspan=3>
2327          <select name=month>|.$form->select_option($selectaccountingmonth, undef, 1, 1).qq|</select>
2328          <select name=year>|.$form->select_option($selectaccountingyear).qq|</select>
2329          <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
2330          <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
2331          <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
2332          <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
2333          </td>
2334        </tr>
2335|;
2336  }
2337
2338  $fromto = qq|
2339        <tr>
2340          <th align=right nowrap>|.$locale->text('Transaction Dates').qq|</th>
2341          <td>|.$locale->text('From').qq| <input name=transdatefrom size=11 class=date title="$myconfig{dateformat}" value=$form->{transdatefrom}>|.&js_calendar("main", "transdatefrom")
2342          .qq| |.$locale->text('To').qq| <input name=transdateto size=11 class=date title="$myconfig{dateformat}" value=$form->{transdateto}>|.&js_calendar("main", "transdateto").qq|</td>
2343        </tr>
2344        $selectfrom
2345|;
2346
2347  if (@{ $form->{all_project} }) {
2348    $form->{selectprojectnumber} = "\n";
2349    $form->{projectnumber} ||= "";
2350    for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|$_->{projectnumber}--$_->{id}\n| }
2351  } else {
2352    $form->error($locale->text('No open Projects!'));
2353  }
2354
2355  if (@{ $form->{all_employee} }) {
2356    $form->{selectemployee} = "\n";
2357    $form->{employee} ||= "";
2358    for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|$_->{name}--$_->{id}\n| }
2359
2360    $employee = qq|
2361              <tr>
2362                <th align=right nowrap>|.$locale->text('Employee').qq|</th>
2363                <td><select name=employee>|
2364                .$form->select_option($form->{selectemployee}, $form->{employee}, 1)
2365                .qq|</select></td>
2366              </tr>
2367|;
2368  }
2369
2370  $form->{title} = $locale->text('Generate Sales Orders');
2371  $form->{vc} = "customer";
2372  $form->{type} = "sales_order";
2373
2374  $form->header;
2375
2376  &calendar;
2377
2378  print qq|
2379<body>
2380
2381<form method="post" name="main" action="$form->{script}" />
2382
2383<table width=100%>
2384  <tr>
2385    <th class=listtop>$form->{title}</th>
2386  </tr>
2387  <tr height="5"></tr>
2388  <tr valign=top>
2389    <td>
2390      <table>
2391        <tr>
2392          <th align=right>|.$locale->text('Project').qq|</th>
2393          <td colspan=3><select name=projectnumber>|
2394          .$form->select_option($form->{selectprojectnumber}, $form->{"projectnumber"}, 1)
2395          .qq|</select></td>
2396        </tr>
2397        $employee
2398        $fromto
2399        <tr>
2400          <th></th>
2401            <td><input name=summary type=radio class=radio value=1 checked> |.$locale->text('Summary').qq|
2402            <input name=summary type=radio class=radio value=0> |.$locale->text('Detail').qq|
2403            </td>
2404          </tr>
2405      </table>
2406    </td>
2407  </tr>
2408  <tr>
2409    <td><hr size=3 noshade></td>
2410  </tr>
2411</table>
2412
2413|;
2414
2415  $form->{nextsub} = "project_jcitems_list";
2416  $form->hide_form(qw(path login nextsub type vc));
2417
2418  print qq|
2419<input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
2420
2421</form>
2422|;
2423
2424  if ($form->{menubar}) {
2425    require "$form->{path}/menu.pl";
2426    &menubar;
2427  }
2428
2429  print qq|
2430
2431</body>
2432</html>
2433|;
2434
2435}
2436
2437
2438sub project_jcitems_list {
2439
2440  $form->{projectnumber} = $form->unescape($form->{projectnumber});
2441  $form->{employee} = $form->unescape($form->{employee});
2442
2443  $form->{callback} = "$form->{script}?action=project_jcitems_list";
2444  for (qw(month year interval summary transdatefrom transdateto login path nextsub type vc)) { $form->{callback} .= "&$_=$form->{$_}" }
2445  for (qw(employee projectnumber)) { $form->{callback} .= "&$_=".$form->escape($form->{$_},1) }
2446
2447  PE->get_jcitems(\%myconfig, \%$form);
2448
2449  # flatten array
2450  $i = 1;
2451  foreach $ref (@{ $form->{jcitems} }) {
2452
2453    $form->{"employee_$i"} = $ref->{employee};
2454    $form->{"$form->{vc}_$i"} = $ref->{$form->{vc}};
2455    $form->{"$form->{vc}number{_}$i"} = $ref->{"$form->{vc}number"};
2456
2457    if ($form->{summary}) {
2458
2459      $thisitem = qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|;
2460
2461      if ($thisitem eq $sameitem) {
2462
2463        $i--;
2464        for (qw(qty amount)) { $form->{"${_}_$i"} += $ref->{$_} }
2465        $form->{"id_$i"} .= " $ref->{id}:$ref->{qty}";
2466        if ($form->{"itemnotes_$i"}) {
2467          $form->{"itemnotes_$i"} .= qq|\n\n$ref->{notes}|;
2468        } else {
2469          $form->{"itemnotes_$i"} = $ref->{notes};
2470        }
2471
2472      } else {
2473
2474        for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
2475
2476        $form->{"itemnotes_$i"} = $ref->{notes};
2477        $form->{"checked_$i"} = 1;
2478        $form->{"id_$i"} = "$ref->{id}:$ref->{qty}";
2479
2480      }
2481
2482      $sameitem = qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|;
2483    } else {
2484
2485      for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
2486      $form->{"itemnotes_$i"} = $ref->{notes};
2487      $form->{"checked_$i"} = 1;
2488      $form->{"id_$i"} = "$ref->{id}:$ref->{qty}";
2489
2490    }
2491
2492    $i++;
2493
2494  }
2495
2496  $form->error($locale->text('Nothing to generate!')) unless $i > 1;
2497
2498  $form->{rowcount} = $i - 1;
2499
2500  for $i (1 .. $form->{rowcount}) {
2501    for (qw(qty allocated)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) }
2502    for (qw(amount sellprice)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $form->{precision}) }
2503  }
2504
2505  &jcitems;
2506
2507}
2508
2509
2510sub jcitems {
2511
2512# $locale->text('Customer')
2513# $locale->text('Vendor')
2514# $locale->text->('Customer Number')
2515# $locale->text('Vendor Number')
2516
2517  $vc = ucfirst $form->{vc};
2518  $vcnumber = "$vc Number";
2519
2520  @column_index = qw(id projectnumber name);
2521  push @column_index, "$form->{vc}number";
2522
2523  if (!$form->{summary}) {
2524    push @column_index, qw(transdate);
2525  }
2526  push @column_index, qw(partnumber description);
2527  push @column_index, "itemnotes" if !$form->{summary};
2528  push @column_index, qw(employee qty amount);
2529
2530  $column_header{id} = qq|<th class=listheading width=1%><input name="allbox" type=checkbox class=checkbox value="1" checked onChange="CheckAll();"></th>|;
2531  $column_header{transdate} = qq|<th class=listheading>|.$locale->text('Date').qq|</th>|;
2532  $column_header{partnumber} = qq|<th class=listheading>|.$locale->text('Service Code').qq|<br>|.$locale->text('Part Number').qq|</th>|;
2533  $column_header{projectnumber} = qq|<th class=listheading>|.$locale->text('Project Number').qq|</th>|;
2534  $column_header{employee} = qq|<th class=listheading>|.$locale->text('Employee').qq|</th>|;
2535  $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
2536  $column_header{itemnotes} = qq|<th class=listheading>|.$locale->text('Notes').qq|</th>|;
2537  $column_header{name} = qq|<th class=listheading>$vc</th>|;
2538  $column_header{"$form->{vc}number"} = qq|<th class=listheading>|.$locale->text($vcnumber).qq|</th>|;
2539  $column_header{qty} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
2540  $column_header{amount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
2541
2542  if ($form->{type} eq 'sales_order') {
2543    $form->{title} = $locale->text('Generate Sales Orders');
2544  }
2545
2546  $form->header;
2547
2548  &check_all(qw(allbox checked_));
2549
2550  print qq|
2551<body>
2552
2553<form method="post" name="main" action="$form->{script}" />
2554
2555<table width=100%>
2556  <tr>
2557    <th class=listtop>$form->{title}</th>
2558  </tr>
2559  <tr height="5"></tr>
2560  <tr>
2561    <td>
2562      <table width=100%>
2563        <tr class=listheading>|;
2564
2565  for (@column_index) { print "\n$column_header{$_}" }
2566
2567  print qq|
2568        </tr>
2569|;
2570
2571  for $i (1 .. $form->{rowcount}) {
2572
2573    for (qw(description itemnotes)) { $form->{"${_}_$i"} =~ s/\r?\n/<br>/g }
2574    for (@column_index) { $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>| }
2575    for (qw(qty amount)) { $column_data{$_} = qq|<td align=right>$form->{"${_}_$i"}</td>| }
2576
2577    $checked = ($form->{"checked_$i"}) ? "checked" : "";
2578    $column_data{id} = qq|<td><input name="checked_$i" class=checkbox type=checkbox value="1" $checked></td>|;
2579
2580    if ($form->{"$form->{vc}_id_$i"}) {
2581
2582      $column_data{name} = qq|<td>$form->{"$form->{vc}_$i"}</td>|;
2583      $column_data{"$form->{vc}number"} = qq|<td>$form->{"$form->{vc}number_$i"}</td>|;
2584      $form->hide_form("$form->{vc}_id_$i", "$form->{vc}_$i", "$form->{vc}number_$i");
2585    } else {
2586      $column_data{name} = qq|<td><input name="ndx_$i" class=checkbox type=checkbox value="1"></td>|;
2587    }
2588
2589    $form->hide_form(map {"${_}_$i"} qw(id project_id parts_id projectnumber transdate partnumber description itemnotes qty unit amount taxaccounts sellprice));
2590
2591    $j++; $j %= 2;
2592    print "
2593        <tr class=listrow$j>";
2594
2595    for (@column_index) { print "\n$column_data{$_}" }
2596
2597    print qq|
2598        </tr>
2599|;
2600
2601  }
2602
2603  print qq|
2604      </table>
2605    </td>
2606  </tr>
2607
2608  <tr>
2609    <td><hr size=3 noshade></td>
2610  </tr>
2611</table>
2612
2613<br>
2614|;
2615
2616  $form->hide_form(qw(path login vc nextsub rowcount type currency defaultcurrency taxaccounts summary callback));
2617  $form->hide_form(map { "${_}_rate" } split / /, $form->{taxaccounts});
2618
2619  if ($form->{rowcount}) {
2620    print qq|
2621<input class=submit type=submit name=action value="|.$locale->text('Generate Sales Orders').qq|">|;
2622
2623    print qq|
2624<input class=submit type=submit name=action value="|.$locale->text('Select Customer').qq|">|;
2625
2626  }
2627
2628  if ($form->{menubar}) {
2629    require "$form->{path}/menu.pl";
2630    &menubar;
2631  }
2632
2633  print qq|
2634</form>
2635
2636</body>
2637</html>
2638|;
2639
2640}
2641
2642
2643sub select_customer {
2644
2645  for (1 .. $form->{rowcount}) {
2646    last if ($ok = $form->{"ndx_$_"});
2647  }
2648
2649  $form->error($locale->text('All selected!')) unless $ok;
2650
2651  $label = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor');
2652
2653  $form->header;
2654
2655  print qq|
2656<body onLoad="document.main.$form->{vc}.focus()" />
2657
2658<form method=post name=main action=$form->{script}>
2659
2660<b>$label</b> <input name=$form->{vc} size=40>
2661
2662|;
2663
2664  $form->{nextsub} = "$form->{vc}_selected";
2665  $form->{action} = "$form->{vc}_selected";
2666
2667  $form->hide_form;
2668
2669  print qq|
2670<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
2671
2672</form>
2673|;
2674
2675  print qq|
2676
2677</body>
2678</html>
2679|;
2680
2681}
2682
2683
2684sub customer_selected {
2685
2686  if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{startdate})) > 1) {
2687    &select_name($form->{vc});
2688    exit;
2689  }
2690
2691  if ($rv == 1) {
2692    $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
2693    $form->{"$form->{vc}number"} = $form->{name_list}[0]->{"$form->{vc}number"};
2694    $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
2695  } else {
2696    $msg = ($form->{vc} eq 'customer') ? $locale->text('Customer not on file!') : $locale->text('Vendor not on file!');
2697    $form->error($locale->text($msg));
2698  }
2699
2700  &display_form;
2701
2702}
2703
2704
2705sub sales_order_header {
2706
2707  for (1 .. $form->{rowcount}) {
2708    if ($form->{"ndx_$_"}) {
2709      $form->{"$form->{vc}_id_$_"} = $form->{"$form->{vc}_id"};
2710      $form->{"$form->{vc}_$_"} = $form->{"$form->{vc}"};
2711      $form->{"$form->{vc}number_$_"} = $form->{"$form->{vc}number"};
2712    }
2713  }
2714
2715}
2716
2717sub sales_order_footer { &jcitems }
2718
2719
2720sub generate_sales_orders {
2721
2722  for $i (1 .. $form->{rowcount}) {
2723    $form->error($locale->text('Customer missing!')) if ($form->{"checked_$i"} && !$form->{"customer_$i"});
2724  }
2725
2726  for $i (1 .. $form->{rowcount}) {
2727    if ($form->{"checked_$i"}) {
2728      for (qw(description itemnotes)) { $form->{"${_}_$i"} =~ s/<br>/\r\n/g }
2729      push @{ $form->{order}{qq|$form->{"customer_id_$i"}|} }, {
2730      partnumber => $form->{"partnumber_$i"},
2731      id => $form->{"parts_id_$i"},
2732      description => $form->{"description_$i"},
2733      qty => $form->{"qty_$i"},
2734      unit => $form->{"unit_$i"},
2735      sellprice => $form->{"sellprice_$i"},
2736      projectnumber => qq|--$form->{"project_id_$i"}|,
2737      reqdate => $form->{"transdate_$i"},
2738      taxaccounts => $form->{"taxaccounts_$i"},
2739      jcitems => $form->{"id_$i"},
2740      itemnotes => $form->{"itemnotes_$i"},
2741      }
2742    }
2743  }
2744
2745  $order = new Form;
2746  for (keys %{ $form->{order} }) {
2747
2748    for (qw(type vc defaultcurrency login)) { $order->{$_} = $form->{$_} }
2749    for (split / /, $form->{taxaccounts}) { $order->{"${_}_rate"} = $form->{"${_}_rate"} }
2750
2751    $i = 0;
2752    $order->{"$order->{vc}_id"} = $_;
2753
2754    AA->get_name(\%myconfig, \%$order);
2755
2756    foreach $ref (@ {$form->{order}{$_} }) {
2757      $i++;
2758
2759      for (keys %$ref) { $order->{"${_}_$i"} = $ref->{$_} }
2760
2761      $taxaccounts = "";
2762      for (split / /, $order->{taxaccounts}) { $taxaccounts .= qq|$_ | if ($_ =~ /$order->{"taxaccounts_$i"}/) }
2763      $order->{"taxaccounts_$i"} = $taxaccounts;
2764
2765    }
2766    $order->{rowcount} = $i;
2767
2768    $order->{ordnumber} = $order->update_defaults(\%myconfig, 'sonumber');
2769    $order->{transdate} = $order->current_date(\%myconfig);
2770    $order->{reqdate} = $order->{transdate};
2771    $order->{exchangerate} = $order->get_exchangerate(\%myconfig, undef, $order->{currency}, $order->{transdate}) unless $order->{currency} eq $order->{defaultcurrency};
2772
2773    for (qw(employee employee_id)) { delete $order->{$_} }
2774
2775    if (OE->save(\%myconfig, \%$order)) {
2776      if (! PE->allocate_projectitems(\%myconfig, \%$order)) {
2777        OE->delete(\%myconfig, \%$order, $spool);
2778      }
2779    } else {
2780      $order->error($locale->text('Failed to save order!'));
2781    }
2782
2783    for (keys %$order) { delete $order->{$_} }
2784
2785  }
2786
2787  delete $form->{callback};
2788
2789  $form->redirect($locale->text('Orders generated!'));
2790
2791}
2792
2793
2794