import sql-ledger 2.4.4
[freeside.git] / sql-ledger / sql-ledger / bin / mozilla / ct.pl
1 #=====================================================================
2 # SQL-Ledger Accounting
3 # Copyright (c) 2001
4 #
5 #  Author: Dieter Simader
6 #   Email: dsimader@sql-ledger.org
7 #     Web: http://www.sql-ledger.org
8 #
9 #  Contributors: Reed White <alta@alta-research.com>
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #======================================================================
24 #
25 # customer/vendor module
26 #
27 #======================================================================
28
29 use SL::CT;
30
31 1;
32 # end of main
33
34
35
36 sub add {
37
38   $form->{title} = "Add";
39 # $locale->text('Add Customer')
40 # $locale->text('Add Vendor')
41
42   $form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
43
44   CT->create_links(\%myconfig, \%$form);
45   
46   &form_header;
47   &form_footer;
48   
49 }
50
51
52 sub history {
53
54 # $locale->text('Customer History')
55 # $locale->text('Vendor History')
56
57   $history = 1;
58   $label = ucfirst $form->{db};
59   $label .= " History";
60
61   if ($form->{db} eq 'customer') {
62     $invlabel = $locale->text('Sales Invoices');
63     $ordlabel = $locale->text('Sales Orders');
64     $quolabel = $locale->text('Quotations');
65   } else {
66     $invlabel = $locale->text('Vendor Invoices');
67     $ordlabel = $locale->text('Purchase Orders');
68     $quolabel = $locale->text('Request for Quotations');
69   }
70   
71   $form->{title} = $locale->text($label);
72   
73   $form->{nextsub} = "list_history";
74
75   $transactions = qq|
76         <tr>
77           <td></td>
78           <td>
79             <table>
80               <tr>
81                 <td>
82                   <table>
83                     <tr>
84                       <td><input name=type type=radio class=radio value=invoice checked> $invlabel</td>
85                     </tr>
86                     <tr>
87                       <td><input name=type type=radio class=radio value=order> $ordlabel</td>
88                     </tr>
89                     <tr>
90                       <td><input name="type" type=radio class=radio value=quotation> $quolabel</td>
91                     </tr>
92                   </table>
93                 </td>
94                 <td>
95                   <table>
96                     <tr>
97                       <th>|.$locale->text('From').qq|</th>
98                       <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
99                       <th>|.$locale->text('To').qq|</th>
100                       <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
101                     </tr>
102                     <tr>
103                       <td></td>
104                       <td colspan=3>
105                       <input name="open" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Open').qq|
106                       <input name="closed" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Closed').qq|
107                       </td>
108                     </tr>
109                   </table>
110                 </td>
111               </tr>
112             </table>
113           </td>
114         </tr>
115 |;
116
117   $include = qq|
118         <tr>
119           <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
120           <td>
121             <table>
122               <tr>
123                 <td><input name=history type=radio class=radio value=summary checked> |.$locale->text('Summary').qq|</td>
124                 <td><input name=history type=radio class=radio value=detail> |.$locale->text('Detail').qq|
125                 </td>
126               </tr>
127               <tr>
128                 <td>
129                 <input name="l_partnumber" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Part Number').qq|
130                 </td>
131                 <td>
132                 <input name="l_description" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Description').qq|
133                 </td>
134                 <td>
135                 <input name="l_sellprice" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Sell Price').qq|
136                 </td>
137                 <td>
138                 <input name="l_curr" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Currency').qq|
139                 </td>
140               </tr>
141               <tr>
142                 <td>
143                 <input name="l_qty" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Qty').qq|
144                 </td>
145                 <td>
146                 <input name="l_unit" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Unit').qq|
147                 </td>
148                 <td>
149                 <input name="l_discount" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Discount').qq|
150                 </td>
151               <tr>
152               </tr>
153                 <td>
154                 <input name="l_deliverydate" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Delivery Date').qq|
155                 </td>
156                 <td>
157                 <input name="l_projectnumber" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Project Number').qq|
158                 </td>
159                 <td>
160                 <input name="l_serialnumber" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Serial Number').qq|
161                 </td>
162               </tr>
163             </table>
164           </td>
165         </tr>
166 |;
167
168   &search_name;
169
170 }
171
172
173 sub transactions {
174
175   if ($form->{db} eq 'customer') {
176     $translabel = $locale->text('AR Transactions');
177     $invlabel = $locale->text('Sales Invoices');
178     $ordlabel = $locale->text('Sales Orders');
179     $quolabel = $locale->text('Quotations');
180   } else {
181     $translabel = $locale->text('AP Transactions');
182     $invlabel = $locale->text('Vendor Invoices');
183     $ordlabel = $locale->text('Purchase Orders');
184     $quolabel = $locale->text('Request for Quotations');
185   }
186
187  
188   $transactions = qq|
189         <tr>
190           <td></td>
191           <td>
192             <table>
193               <tr>
194                 <td>
195                   <table>
196                     <tr>
197                       <td><input name="l_transnumber" type=checkbox class=checkbox value=Y> $translabel</td>
198                     </tr>
199                     <tr>
200                       <td><input name="l_invnumber" type=checkbox class=checkbox value=Y> $invlabel</td>
201                     </tr>
202                     <tr>
203                       <td><input name="l_ordnumber" type=checkbox class=checkbox value=Y> $ordlabel</td>
204                     </tr>
205                     <tr>
206                       <td><input name="l_quonumber" type=checkbox class=checkbox value=Y> $quolabel</td>
207                     </tr>
208                   </table>
209                 </td>
210                 <td>
211                   <table>
212                     <tr>
213                       <th>|.$locale->text('From').qq|</th>
214                       <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
215                       <th>|.$locale->text('To').qq|</th>
216                       <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
217                     </tr>
218                     <tr>
219                       <td></td>
220                       <td colspan=3>
221                       <input name="open" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Open').qq|
222                       <input name="closed" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Closed').qq|
223                       </td>
224                     </tr>
225                     <tr>
226                       <td></td>
227                       <td colspan=3>
228                       <input name="l_amount" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Amount').qq|
229                       <input name="l_tax" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Tax').qq|
230                       <input name="l_total" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Total').qq|
231                       <input name="l_subtotal" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
232                       </td>
233                     </tr>
234                   </table>
235                 </td>
236               </tr>
237             </table>
238           </td>
239         </tr>
240 |;
241
242 }
243
244
245 sub include_in_report {
246   
247   $label = ucfirst $form->{db};
248   
249   if ($myconfig{role} =~ /(admin|manager)/) {
250     $bcc = qq|
251                 <td><input name="l_bcc" type=checkbox class=checkbox value=Y> |.$locale->text('Bcc').qq|</td>
252 |;
253   }
254
255   if ($form->{db} eq 'customer') {
256     $employee = qq|
257                 <td><input name="l_employee" type=checkbox class=checkbox value=Y> |.$locale->text('Salesperson').qq|</td>
258 |;
259
260     $pricegroup = qq|
261                 <td><input name="l_pricegroup" type=checkbox class=checkbox value=Y> |.$locale->text('Pricegroup').qq|</td>
262 |;
263
264   } else {
265     $employee = qq|
266                 <td><input name="l_employee" type=checkbox class=checkbox value=Y> |.$locale->text('Employee').qq|</td>
267 |;
268   }
269
270   $employee .= qq|
271                 <td><input name="l_manager" type=checkbox class=checkbox value=Y> |.$locale->text('Manager').qq|</td>
272 |;
273     
274   $include = qq|
275         <tr>
276           <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
277           <td>
278             <table>
279               <tr>
280                 <td><input name="l_id" type=checkbox class=checkbox value=Y> |.$locale->text('ID').qq|</td>
281                 <td><input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |.$locale->text($label . ' Number').qq|</td>
282                 <td><input name="l_name" type=checkbox class=checkbox value=Y $form->{l_name}> |.$locale->text('Company Name').qq|</td>
283                 <td><input name="l_contact" type=checkbox class=checkbox value=Y $form->{l_contact}> |.$locale->text('Contact').qq|</td>
284                 <td><input name="l_email" type=checkbox class=checkbox value=Y $form->{l_email}> |.$locale->text('E-mail').qq|</td>
285               </tr>
286               <tr>
287                 <td><input name="l_address" type=checkbox class=checkbox value=Y> |.$locale->text('Address').qq|</td>
288                 <td><input name="l_city" type=checkbox class=checkbox value=Y> |.$locale->text('City').qq|</td>
289                 <td><input name="l_state" type=checkbox class=checkbox value=Y> |.$locale->text('State/Province').qq|</td>
290                 <td><input name="l_zipcode" type=checkbox class=checkbox value=Y> |.$locale->text('Zip/Postal Code').qq|</td>
291                 <td><input name="l_country" type=checkbox class=checkbox value=Y> |.$locale->text('Country').qq|</td>
292               </tr>
293               <tr>
294                 <td><input name="l_phone" type=checkbox class=checkbox value=Y $form->{l_phone}> |.$locale->text('Phone').qq|</td>
295                 <td><input name="l_fax" type=checkbox class=checkbox value=Y> |.$locale->text('Fax').qq|</td>
296                 <td><input name="l_cc" type=checkbox class=checkbox value=Y> |.$locale->text('Cc').qq|</td>
297                 $bcc
298                 <td><input name="l_notes" type=checkbox class=checkbox value=Y> |.$locale->text('Notes').qq|</td>
299                 <td><input name="l_discount" type=checkbox class=checkbox value=Y> |.$locale->text('Discount').qq|</td>
300               </tr>
301               <tr>
302                 <td><input name="l_taxnumber" type=checkbox class=checkbox value=Y> |.$locale->text('Tax Number').qq|</td>
303                 $gifi
304                 <td><input name="l_sic_code" type=checkbox class=checkbox value=Y> |.$locale->text('SIC').qq|</td>
305                 <td><input name="l_iban" type=checkbox class=checkbox value=Y> |.$locale->text('IBAN').qq|</td>
306                 <td><input name="l_bic" type=checkbox class=checkbox value=Y> |.$locale->text('BIC').qq|</td>
307               </tr>
308               <tr>
309                 $employee
310                 <td><input name="l_business" type=checkbox class=checkbox value=Y> |.$locale->text('Type of Business').qq|</td>
311                 $pricegroup
312                 <td><input name="l_language" type=checkbox class=checkbox value=Y> |.$locale->text('Language').qq|</td>
313               </tr>
314               <tr>
315                 <td><input name="l_startdate" type=checkbox class=checkbox value=Y> |.$locale->text('Startdate').qq|</td>
316                 <td><input name="l_enddate" type=checkbox class=checkbox value=Y> |.$locale->text('Enddate').qq|</td>
317               </tr>
318             </table>
319           </td>
320         </tr>
321 |;
322
323 }
324
325
326 sub search {
327
328 # $locale->text('Customers')
329 # $locale->text('Vendors')
330
331   $form->{title} = $locale->text('Search') unless $form->{title};
332   
333   map { $form->{"l_$_"} = 'checked' } qw(name contact phone email);
334
335   $form->{nextsub} = "list_names";
336
337   $orphan = qq|
338         <tr>
339           <td></td>
340           <td><input name=status class=radio type=radio value=all checked>&nbsp;|.$locale->text('All').qq|
341           <input name=status class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned').qq|</td>
342         </tr>
343 |;
344
345   if ($form->{db} eq 'vendor') {
346     $gifi = qq|
347                 <td><input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |.$locale->text('GIFI').qq|</td>
348 |;
349   }
350  
351   &transactions;
352   &include_in_report;
353   &search_name;
354
355 }
356
357
358 sub search_name {
359
360   $label = ucfirst $form->{db};
361   
362  
363   $form->header;
364   
365   print qq|
366 <body>
367
368 <form method=post action=$form->{script}>
369
370 <input type=hidden name=db value=$form->{db}>
371
372 <table width=100%>
373   <tr>
374     <th class=listtop>$form->{title}</th>
375   </tr>
376   <tr height="5"></tr>
377   <tr valign=top>
378     <td>
379       <table>
380         <tr>
381           <th align=right nowrap>|.$locale->text($label . ' Number').qq|</th>
382           <td><input name=$form->{db}number size=32></td>
383         </tr>
384         <tr>
385           <th align=right nowrap>|.$locale->text('Company Name').qq|</th>
386           <td><input name=name size=64></td>
387         </tr>
388         <tr>
389           <th align=right nowrap>|.$locale->text('Address').qq|</th>
390           <td><input name=address size=64></td>
391         </tr>
392         <tr>
393           <th align=right nowrap>|.$locale->text('City').qq|</th>
394           <td><input name=city size=32></td>
395         </tr>
396         <tr>
397           <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
398           <td><input name=state size=32></td>
399         </tr>
400         <tr>
401           <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
402           <td><input name=zipcode size=10></td>
403         </tr>
404         <tr>
405           <th align=right nowrap>|.$locale->text('Country').qq|</th>
406           <td><input name=country size=32></td>
407         </tr>
408         <tr>
409           <th align=right nowrap>|.$locale->text('Contact').qq|</th>
410           <td><input name=contact size=64></td>
411         </tr>
412         <tr>
413           <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
414           <td><input name=email size=32></td>
415         </tr>
416         <tr>
417           <th align=right nowrap>|.$locale->text('Notes').qq|</th>
418           <td><input name=notes size=64></td>
419         </tr>
420
421         $invnumber
422         $orphan
423         $transactions
424         $include
425
426       </table>
427     </td>
428   </tr>
429
430   <tr>
431     <td><hr size=3 noshade></td>
432   </tr>
433 </table>
434
435 <input type=hidden name=nextsub value=$form->{nextsub}>
436
437 <input type=hidden name=path value=$form->{path}>
438 <input type=hidden name=login value=$form->{login}>
439 <input type=hidden name=sessionid value=$form->{sessionid}>
440
441 <br>
442 <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
443 </form>
444
445 </body>
446 </html>
447 |;
448 }
449
450
451 sub list_names {
452
453   CT->search(\%myconfig, \%$form);
454   
455   $href = "$form->{script}?action=list_names&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&l_subtotal=$form->{l_subtotal}";
456   
457   $form->sort_order();
458   
459   $callback = "$form->{script}?action=list_names&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&l_subtotal=$form->{l_subtotal}";
460   
461   @columns = $form->sort_columns(id, name, "$form->{db}number", address,
462                                  city, state, zipcode, country, contact,
463                                  phone, fax, email, cc, bcc, employee,
464                                  manager, notes, discount,
465                                  taxnumber, gifi_accno, sic_code, business,
466                                  pricegroup, language, iban, bic,
467                                  startdate, enddate,
468                                  invnumber, invamount, invtax, invtotal,
469                                  ordnumber, ordamount, ordtax, ordtotal,
470                                  quonumber, quoamount, quotax, quototal);
471
472   foreach $item (qw(inv ord quo)) {
473     if ($form->{"l_${item}number"}) {
474       map { $form->{"l_$item$_"} = $form->{"l_$_"} } qw(amount tax total);
475       $removeemployee = 1;
476       $openclosed = 1;
477     }
478   }
479   $form->{open} = $form->{closed} = "" if !$openclosed;
480
481   if ($form->{l_transnumber}) {
482     map { $form->{"l_inv$_"} = $form->{"l_$_"} } qw(amount tax total);
483     $removeemployee = 1;
484   }
485
486   if ($removeemployee) {
487     @columns = grep !/(employee|manager)/, @columns;
488   }
489
490
491   foreach $item (@columns) {
492     if ($form->{"l_$item"} eq "Y") {
493       push @column_index, $item;
494
495       # add column to href and callback
496       $callback .= "&l_$item=Y";
497       $href .= "&l_$item=Y";
498     }
499   }
500   
501   foreach $item (qw(amount tax total transnumber)) {
502     if ($form->{"l_$item"} eq "Y") { 
503       $callback .= "&l_$item=Y"; 
504       $href .= "&l_$item=Y"; 
505     }
506   }
507
508
509   if ($form->{status} eq 'all') {
510     $option = $locale->text('All');
511   }
512   if ($form->{status} eq 'orphaned') {
513     $option .= $locale->text('Orphaned');
514   }
515   if ($form->{name}) {
516     $callback .= "&name=".$form->escape($form->{name},1);
517     $href .= "&name=".$form->escape($form->{name});
518     $option .= "\n<br>".$locale->text('Name')." : $form->{name}";
519   }
520   if ($form->{address}) {
521     $callback .= "&address=".$form->escape($form->{address},1);
522     $href .= "&address=".$form->escape($form->{address});
523     $option .= "\n<br>".$locale->text('Address')." : $form->{address}";
524   }
525   if ($form->{city}) {
526     $callback .= "&city=".$form->escape($form->{city},1);
527     $href .= "&city=".$form->escape($form->{city});
528     $option .= "\n<br>".$locale->text('City')." : $form->{city}";
529   }
530   if ($form->{state}) {
531     $callback .= "&state=".$form->escape($form->{state},1);
532     $href .= "&state=".$form->escape($form->{state});
533     $option .= "\n<br>".$locale->text('State')." : $form->{state}";
534   }
535   if ($form->{zipcode}) {
536     $callback .= "&zipcode=".$form->escape($form->{zipcode},1);
537     $href .= "&zipcode=".$form->escape($form->{zipcode});
538     $option .= "\n<br>".$locale->text('Zip/Postal Code')." : $form->{zipcode}";
539   }
540   if ($form->{country}) {
541     $callback .= "&country=".$form->escape($form->{country},1);
542     $href .= "&country=".$form->escape($form->{country});
543     $option .= "\n<br>".$locale->text('Country')." : $form->{country}";
544   }
545   if ($form->{contact}) {
546     $callback .= "&contact=".$form->escape($form->{contact},1);
547     $href .= "&contact=".$form->escape($form->{contact});
548     $option .= "\n<br>".$locale->text('Contact')." : $form->{contact}";
549   }
550   if ($form->{notes}) {
551     $callback .= "&notes=".$form->escape($form->{notes},1);
552     $href .= "&notes=".$form->escape($form->{notes});
553     $option .= "\n<br>".$locale->text('Notes')." : $form->{notes}";
554   }
555   if ($form->{"$form->{db}number"}) {
556     $callback .= qq|&$form->{db}number=|.$form->escape($form->{"$form->{db}number"},1);
557     $href .= "&$form->{db}number=".$form->escape($form->{"$form->{db}number"});
558     $option .= "\n<br>".$locale->text('Number').qq| : $form->{"$form->{db}number"}|;
559   }
560   if ($form->{email}) {
561     $callback .= "&email=".$form->escape($form->{email},1);
562     $href .= "&email=".$form->escape($form->{email});
563     $option .= "\n<br>".$locale->text('E-mail')." : $form->{email}";
564   }
565   if ($form->{transdatefrom}) {
566     $callback .= "&transdatefrom=$form->{transdatefrom}";
567     $href .= "&transdatefrom=$form->{transdatefrom}";
568     $option .= "\n<br>" if ($option);
569     $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
570   }
571   if ($form->{transdateto}) {
572     $callback .= "&transdateto=$form->{transdateto}";
573     $href .= "&transdateto=$form->{transdateto}";
574     if ($form->{transdatefrom}) {
575       $option .= " ";
576     } else {
577       $option .= "\n<br>" if ($option);
578     }
579     $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 1);
580   }
581   if ($form->{open}) {
582     $callback .= "&open=$form->{open}";
583     $href .= "&open=$form->{open}";
584     $option .= "\n<br>" if ($option);
585     $option .= $locale->text('Open');
586   }
587   if ($form->{closed}) {
588     $callback .= "&closed=$form->{closed}";
589     $href .= "&closed=$form->{closed}";
590     $option .= "\n<br>" if ($option);
591     $option .= $locale->text('Closed');
592   }
593   
594
595   $form->{callback} = "$callback&sort=$form->{sort}";
596   $callback = $form->escape($form->{callback});
597   
598   $column_header{id} = qq|<th class=listheading>|.$locale->text('ID').qq|</th>|;
599   $column_header{"$form->{db}number"} = qq|<th><a class=listheading href=$href&sort=$form->{db}number>|.$locale->text('Number').qq|</a></th>|;
600   $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|;
601   $column_header{address} = qq|<th class=listheading>|.$locale->text('Address').qq|</th>|;
602   $column_header{city} = qq|<th><a class=listheading href=$href&sort=city>|.$locale->text('City').qq|</a></th>|;
603   $column_header{state} = qq|<th><a class=listheading href=$href&sort=state>|.$locale->text('State/Province').qq|</a></th>|;
604   $column_header{zipcode} = qq|<th><a class=listheading href=$href&sort=zipcode>|.$locale->text('Zip/Postal Code').qq|</a></th>|;
605   $column_header{country} = qq|<th><a class=listheading href=$href&sort=country>|.$locale->text('Country').qq|</a></th>|;
606   $column_header{contact} = qq|<th><a class=listheading href=$href&sort=contact>|.$locale->text('Contact').qq|</a></th>|;
607   $column_header{phone} = qq|<th><a class=listheading href=$href&sort=phone>|.$locale->text('Phone').qq|</a></th>|;
608   $column_header{fax} = qq|<th><a class=listheading href=$href&sort=fax>|.$locale->text('Fax').qq|</a></th>|;
609   $column_header{email} = qq|<th><a class=listheading href=$href&sort=email>|.$locale->text('E-mail').qq|</a></th>|;
610   $column_header{cc} = qq|<th><a class=listheading href=$href&sort=cc>|.$locale->text('Cc').qq|</a></th>|;
611   $column_header{bcc} = qq|<th><a class=listheading href=$href&sort=cc>|.$locale->text('Bcc').qq|</a></th>|;
612   $column_header{notes} = qq|<th><a class=listheading href=$href&sort=notes>|.$locale->text('Notes').qq|</a></th>|;
613   $column_header{discount} = qq|<th class=listheading>%</th>|;
614   
615   $column_header{taxnumber} = qq|<th><a class=listheading href=$href&sort=taxnumber>|.$locale->text('Tax Number').qq|</a></th>|;
616   $column_header{gifi_accno} = qq|<th><a class=listheading href=$href&sort=gifi_accno>|.$locale->text('GIFI').qq|</a></th>|;
617   $column_header{sic_code} = qq|<th><a class=listheading href=$href&sort=sic_code>|.$locale->text('SIC').qq|</a></th>|;
618   $column_header{business} = qq|<th><a class=listheading href=$href&sort=business>|.$locale->text('Type of Business').qq|</a></th>|;
619   $column_header{iban} = qq|<th class=listheading>|.$locale->text('IBAN').qq|</th>|;
620   $column_header{bic} = qq|<th class=listheading>|.$locale->text('BIC').qq|</th>|;
621   $column_header{startdate} = qq|<th><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|;
622   $column_header{enddate} = qq|<th><a class=listheading href=$href&sort=enddate>|.$locale->text('Enddate').qq|</a></th>|;
623   
624   $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice').qq|</a></th>|;
625   $column_header{ordnumber} = qq|<th><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order').qq|</a></th>|;
626   $column_header{quonumber} = qq|<th><a class=listheading href=$href&sort=quonumber>|.$locale->text('Quotation').qq|</a></th>|;
627
628   if ($form->{db} eq 'customer') {
629     $column_header{employee} = qq|<th><a class=listheading href=$href&sort=employee>|.$locale->text('Salesperson').qq|</a></th>|;
630   } else {
631     $column_header{employee} = qq|<th><a class=listheading href=$href&sort=employee>|.$locale->text('Employee').qq|</a></th>|;
632   }
633   $column_header{manager} = qq|<th><a class=listheading href=$href&sort=manager>|.$locale->text('Manager').qq|</a></th>|;
634
635   $column_header{pricegroup} = qq|<th><a class=listheading href=$href&sort=pricegroup>|.$locale->text('Pricegroup').qq|</a></th>|;
636   $column_header{language} = qq|<th><a class=listheading href=$href&sort=language>|.$locale->text('Language').qq|</a></th>|;
637   
638
639   $amount = $locale->text('Amount');
640   $tax = $locale->text('Tax');
641   $total = $locale->text('Total');
642   
643   $column_header{invamount} = qq|<th class=listheading>$amount</th>|;
644   $column_header{ordamount} = qq|<th class=listheading>$amount</th>|;
645   $column_header{quoamount} = qq|<th class=listheading>$amount</th>|;
646   
647   $column_header{invtax} = qq|<th class=listheading>$tax</th>|;
648   $column_header{ordtax} = qq|<th class=listheading>$tax</th>|;
649   $column_header{quotax} = qq|<th class=listheading>$tax</th>|;
650   
651   $column_header{invtotal} = qq|<th class=listheading>$total</th>|;
652   $column_header{ordtotal} = qq|<th class=listheading>$total</th>|;
653   $column_header{quototal} = qq|<th class=listheading>$total</th>|;
654  
655
656   if ($form->{status}) {
657     $label = ucfirst $form->{db}."s";
658     $form->{title} = $locale->text($label);
659   } else {
660     $label = ucfirst $form->{db};
661     $form->{title} = $locale->text($label ." Transactions");
662   }
663
664   $form->header;
665
666   print qq|
667 <body>
668
669 <table width=100%>
670   <tr>
671     <th class=listtop>$form->{title}</th>
672   </tr>
673   <tr height="5"></tr>
674   <tr>
675     <td>$option</td>
676   </tr>
677   <tr>
678     <td>
679       <table width=100%>
680         <tr class=listheading>
681 |;
682
683   map { print "$column_header{$_}\n" } @column_index;
684
685   print qq|
686         </tr>
687 |;
688
689   $ordertype = ($form->{db} eq 'customer') ? 'sales_order' : 'purchase_order';
690   $quotationtype = ($form->{db} eq 'customer') ? 'sales_quotation' : 'request_quotation';
691   $subtotal = 0;
692
693   foreach $ref (@{ $form->{CT} }) {
694
695     if ("$ref->{$form->{sort}}$ref->{id}" ne $sameitem && $form->{l_subtotal}) {
696       # print subtotal
697       if ($subtotal) {
698         map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
699         &list_subtotal;
700       }
701     }
702
703     if ("$ref->{$form->{sort}}$ref->{id}" eq $sameitem && $form->{sort} eq 'name') {
704       map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
705     } else {
706       
707       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
708       $column_data{$form->{sort}} = "<td>&nbsp;</td>" if $ref->{$form->{sort}} eq $sameitem && $form->{l_subtotal};
709       
710       $column_data{address} = "<td>$ref->{address1} $ref->{address2}&nbsp;</td>";
711       $column_data{name} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&callback=$callback>$ref->{name}&nbsp;</td>";
712
713       $email = "";
714       if ($form->{sort} =~ /(email|cc)/) {
715         if ("$ref->{$form->{sort}}$ref->{id}" ne $sameitem) {
716           $email = 1;
717         }
718       } else {
719         $email = 1;
720       }
721       
722       if ($email) {
723       foreach $item (qw(email cc bcc)) {
724         if ($ref->{$item}) {
725           $email = $ref->{$item};
726           $email =~ s/</\&lt;/;
727           $email =~ s/>/\&gt;/;
728           
729           $column_data{$item} = qq|<td><a href="mailto:$ref->{$item}">$email</a></td>|;
730         }
731       }
732       }
733     }
734     
735     if ($ref->{formtype} eq 'invoice') {
736       $column_data{invnumber} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}&nbsp;</td>";
737       
738       $column_data{invamount} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{netamount}, 2, "&nbsp;")."</td>";
739       $column_data{invtax} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} - $ref->{netamount}, 2, "&nbsp;")."</td>";
740       $column_data{invtotal} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")."</td>";
741
742       $invamountsubtotal += $ref->{netamount};
743       $invtaxsubtotal += ($ref->{amount} - $ref->{netamount});
744       $invtotalsubtotal += $ref->{amount};
745     }
746      
747     if ($ref->{formtype} eq 'order') {
748       $column_data{ordnumber} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{ordnumber}&nbsp;</td>";
749       
750       $column_data{ordamount} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{netamount}, 2, "&nbsp;")."</td>";
751       $column_data{ordtax} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} - $ref->{netamount}, 2, "&nbsp;")."</td>";
752       $column_data{ordtotal} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")."</td>";
753
754       $ordamountsubtotal += $ref->{netamount};
755       $ordtaxsubtotal += ($ref->{amount} - $ref->{netamount});
756       $ordtotalsubtotal += $ref->{amount};
757     }
758
759     if ($ref->{formtype} eq 'quotation') {
760       $column_data{quonumber} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{quonumber}&nbsp;</td>";
761       
762       $column_data{quoamount} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{netamount}, 2, "&nbsp;")."</td>";
763       $column_data{quotax} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} - $ref->{netamount}, 2, "&nbsp;")."</td>";
764       $column_data{quototal} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")."</td>";
765
766       $quoamountsubtotal += $ref->{netamount};
767       $quotaxsubtotal += ($ref->{amount} - $ref->{netamount});
768       $quototalsubtotal += $ref->{amount};
769     }
770     
771     if ($form->{l_discount}) {
772       $column_data{discount} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{discount} * 100, "", "&nbsp;")."</td>";
773     }
774    
775     $i++; $i %= 2;
776     print "
777         <tr class=listrow$i>
778 ";
779
780     map { print "$column_data{$_}\n" } @column_index;
781
782     print qq|
783         </tr>
784 |;
785     
786     $sameitem = "$ref->{$form->{sort}}$ref->{id}";
787     $subtotal = 1;
788
789   }
790
791   if ($form->{l_subtotal}) {
792     map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
793     &list_subtotal;
794   }
795   
796   $i = 1;
797   if ($myconfig{acs} !~ /AR--AR/) {
798     if ($form->{db} eq 'customer') {
799       $button{'AR--Customers-Add Customer'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Customer').qq|"> |;
800       $button{'AR--Customers--Add Customer'}{order} = $i++;
801     }
802   }
803   if ($myconfig{acs} !~ /AP--AP/) {
804     if ($form->{db} eq 'vendor') {
805       $button{'AP--Vendors--Add Vendor'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Vendor').qq|"> |;
806       $button{'AP--Vendors--Add Vendor'}{order} = $i++;
807     }
808   }
809   
810   foreach $item (split /;/, $myconfig{acs}) {
811     delete $button{$item};
812   }
813   
814   print qq|
815       </table>
816     </td>
817   </tr>
818   <tr>
819     <td><hr size=3 noshade></td>
820   </tr>
821 </table>
822
823 <br>
824 <form method=post action=$form->{script}>
825
826 <input name=callback type=hidden value="$form->{callback}">
827 <input name=db type=hidden value=$form->{db}>
828
829 <input type=hidden name=path value=$form->{path}>
830 <input type=hidden name=login value=$form->{login}>
831 <input type=hidden name=sessionid value=$form->{sessionid}>
832 |;
833
834   if ($form->{status}) {
835     foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
836       print $item->{code};
837     }
838   }
839
840   if ($form->{menubar}) {
841     require "$form->{path}/menu.pl";
842     &menubar;
843   }
844
845   print qq|
846   </form>
847
848 </body>
849 </html>
850 |;
851  
852 }
853
854
855 sub list_subtotal {
856
857         $column_data{invamount} = "<td align=right>".$form->format_amount(\%myconfig, $invamountsubtotal, 2, "&nbsp;")."</td>";
858         $column_data{invtax} = "<td align=right>".$form->format_amount(\%myconfig, $invtaxsubtotal, 2, "&nbsp;")."</td>";
859         $column_data{invtotal} = "<td align=right>".$form->format_amount(\%myconfig, $invtotalsubtotal, 2, "&nbsp;")."</td>";
860
861         $invamountsubtotal = 0;
862         $invtaxsubtotal = 0;
863         $invtotalsubtotal = 0;
864
865         $column_data{ordamount} = "<td align=right>".$form->format_amount(\%myconfig, $ordamountsubtotal, 2, "&nbsp;")."</td>";
866         $column_data{ordtax} = "<td align=right>".$form->format_amount(\%myconfig, $ordtaxsubtotal, 2, "&nbsp;")."</td>";
867         $column_data{ordtotal} = "<td align=right>".$form->format_amount(\%myconfig, $ordtotalsubtotal, 2, "&nbsp;")."</td>";
868
869         $ordamountsubtotal = 0;
870         $ordtaxsubtotal = 0;
871         $ordtotalsubtotal = 0;
872
873         $column_data{quoamount} = "<td align=right>".$form->format_amount(\%myconfig, $quoamountsubtotal, 2, "&nbsp;")."</td>";
874         $column_data{quotax} = "<td align=right>".$form->format_amount(\%myconfig, $quotaxsubtotal, 2, "&nbsp;")."</td>";
875         $column_data{quototal} = "<td align=right>".$form->format_amount(\%myconfig, $quototalsubtotal, 2, "&nbsp;")."</td>";
876
877         $quoamountsubtotal = 0;
878         $quotaxsubtotal = 0;
879         $quototalsubtotal = 0;
880         
881         print "
882         <tr class=listsubtotal>
883 ";
884         map { print "$column_data{$_}\n" } @column_index;
885
886         print qq|
887         </tr>
888 |;
889  
890
891 }
892
893
894 sub list_history {
895   
896   CT->get_history(\%myconfig, \%$form);
897   
898   $href = "$form->{script}?action=list_history&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&history=$form->{history}";
899
900   $form->sort_order();
901   
902   $callback = "$form->{script}?action=list_history&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&history=$form->{history}";
903   
904   $form->{l_fxsellprice} = $form->{l_curr};
905   @columns = $form->sort_columns(partnumber, description, qty, unit, sellprice, fxsellprice, curr, discount, deliverydate, projectnumber, serialnumber);
906
907   if ($form->{history} eq 'summary') {
908     @columns = $form->sort_columns(partnumber, description, qty, unit, sellprice, curr);
909   }
910
911   foreach $item (@columns) {
912     if ($form->{"l_$item"} eq "Y") {
913       push @column_index, $item;
914
915       # add column to href and callback
916       $callback .= "&l_$item=Y";
917       $href .= "&l_$item=Y";
918     }
919   }
920   
921   if ($form->{history} eq 'detail') {
922     $option = $locale->text('Detail');
923   }
924   if ($form->{history} eq 'summary') {
925     $option .= $locale->text('Summary');
926   }
927   if ($form->{name}) {
928     $callback .= "&name=".$form->escape($form->{name},1);
929     $href .= "&name=".$form->escape($form->{name});
930     $option .= "\n<br>".$locale->text('Name')." : $form->{name}";
931   }
932   if ($form->{contact}) {
933     $callback .= "&contact=".$form->escape($form->{contact},1);
934     $href .= "&contact=".$form->escape($form->{contact});
935     $option .= "\n<br>".$locale->text('Contact')." : $form->{contact}";
936   }
937   if ($form->{"$form->{db}number"}) {
938     $callback .= qq|&$form->{db}number=|.$form->escape($form->{"$form->{db}number"},1);
939     $href .= "&$form->{db}number=".$form->escape($form->{"$form->{db}number"});
940     $option .= "\n<br>".$locale->text('Number').qq| : $form->{"$form->{db}number"}|;
941   }
942   if ($form->{email}) {
943     $callback .= "&email=".$form->escape($form->{email},1);
944     $href .= "&email=".$form->escape($form->{email});
945     $option .= "\n<br>".$locale->text('E-mail')." : $form->{email}";
946   }
947   if ($form->{transdatefrom}) {
948     $callback .= "&transdatefrom=$form->{transdatefrom}";
949     $href .= "&transdatefrom=$form->{transdatefrom}";
950     $option .= "\n<br>" if ($option);
951     $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
952   }
953   if ($form->{transdateto}) {
954     $callback .= "&transdateto=$form->{transdateto}";
955     $href .= "&transdateto=$form->{transdateto}";
956     if ($form->{transdatefrom}) {
957       $option .= " ";
958     } else {
959       $option .= "\n<br>" if ($option);
960     }
961     $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 1);
962   }
963   if ($form->{open}) {
964     $callback .= "&open=$form->{open}";
965     $href .= "&open=$form->{open}";
966     $option .= "\n<br>" if ($option);
967     $option .= $locale->text('Open');
968   }
969   if ($form->{closed}) {
970     $callback .= "&closed=$form->{closed}";
971     $href .= "&closed=$form->{closed}";
972     $option .= "\n<br>" if ($option);
973     $option .= $locale->text('Closed');
974   }
975
976
977   $form->{callback} = "$callback&sort=$form->{sort}";
978   $callback = $form->escape($form->{callback});
979
980   $column_header{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Part Number').qq|</a></th>|;
981   $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
982
983   if ($form->{history} eq 'summary') {
984     $column_header{sellprice} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;
985   } else {
986     $column_header{sellprice} = qq|<th class=listheading>|.$locale->text('Sell Price').qq|</th>|;
987   }
988   $column_header{fxsellprice} = qq|<th>&nbsp;</th>|;
989   
990   $column_header{curr} = qq|<th class=listheading>|.$locale->text('Curr').qq|</th>|;
991   $column_header{discount} = qq|<th class=listheading>|.$locale->text('Discount').qq|</th>|;
992   $column_header{qty} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
993   $column_header{unit} = qq|<th class=listheading>|.$locale->text('Unit').qq|</th>|;
994   $column_header{deliverydate} = qq|<th><a class=listheading href=$href&sort=deliverydate>|.$locale->text('Delivery Date').qq|</a></th>|;
995   $column_header{projectnumber} = qq|<th><a class=listheading href=$href&sort=projectnumber>|.$locale->text('Project Number').qq|</a></th>|;
996   $column_header{serialnumber} = qq|<th><a class=listheading href=$href&sort=serialnumber>|.$locale->text('Serial Number').qq|</a></th>|;
997   
998
999 # $locale->text('Customer History')
1000 # $locale->text('Vendor History')
1001
1002   $label = ucfirst $form->{db};
1003   $form->{title} = $locale->text($label." History");
1004
1005   $colspan = $#column_index + 1;
1006
1007   $form->header;
1008
1009   print qq|
1010 <body>
1011
1012 <table width=100%>
1013   <tr>
1014     <th class=listtop>$form->{title}</th>
1015   </tr>
1016   <tr height="5"></tr>
1017   <tr>
1018     <td>$option</td>
1019   </tr>
1020   <tr>
1021     <td>
1022       <table width=100%>
1023         <tr class=listheading>
1024 |;
1025
1026   map { print "$column_header{$_}\n" } @column_index;
1027
1028   print qq|
1029         </tr>
1030 |;
1031
1032
1033   $module = 'oe';
1034   if ($form->{db} eq 'customer') {
1035     $invlabel = $locale->text('Sales Invoice');
1036     $ordlabel = $locale->text('Sales Order');
1037     $quolabel = $locale->text('Quotation');
1038     
1039     $ordertype = 'sales_order';
1040     $quotationtype = 'sales_quotation';
1041     if ($form->{type} eq 'invoice') {
1042       $module = 'is';
1043     }
1044   } else {
1045     $invlabel = $locale->text('Vendor Invoice');
1046     $ordlabel = $locale->text('Purchase Order');
1047     $quolabel = $locale->text('RFQ');
1048     
1049     $ordertype = 'purchase_order';
1050     $quotationtype = 'request_quotation';
1051     if ($form->{type} eq 'invoice') {
1052       $module = 'ir';
1053     }
1054   }
1055     
1056   
1057   foreach $ref (@{ $form->{CT} }) {
1058
1059     if ($ref->{id} ne $sameid) {
1060       # print the header
1061       print qq|
1062         <tr class=listheading>
1063           <th colspan=$colspan><a class=listheading href=$form->{script}?action=edit&id=$ref->{ctid}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{name} $ref->{address}</a></th>
1064         </tr>
1065 |;
1066     }
1067
1068     if ($form->{type} ne 'invoice') {
1069       $ref->{fxsellprice} = $ref->{sellprice};
1070       $ref->{sellprice} *= $ref->{exchangerate};
1071     }
1072         
1073     if ($form->{history} eq 'detail' and $ref->{invid} ne $sameinvid) {
1074       # print inv, ord, quo number
1075       $i++; $i %= 2;
1076       
1077       print qq|
1078           <tr class=listrow$i>
1079 |;
1080
1081       if ($form->{type} eq 'invoice') {
1082         print qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$invlabel $ref->{invnumber} / $ref->{employee}</a></th>|;
1083       }
1084        
1085       if ($form->{type} eq 'order') {
1086         print qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ordlabel $ref->{ordnumber} / $ref->{employee}</a></th>|;
1087       }
1088
1089       if ($form->{type} eq 'quotation') {
1090         print qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$quolabel $ref->{quonumber} / $ref->{employee}</a></th>|;
1091       }
1092
1093       print qq|
1094           </tr>
1095 |;
1096     }
1097
1098     map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
1099
1100     if ($form->{l_curr}) {
1101       $column_data{fxsellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{fxsellprice}, 2)."</td>";
1102     }
1103     $column_data{sellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{sellprice}, 2)."</td>";
1104       
1105     $column_data{qty} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{qty})."</td>";
1106     $column_data{discount} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{discount} * 100, "", "&nbsp;")."</td>";
1107     $column_data{partnumber} = qq|<td><a href=ic.pl?action=edit&id=$ref->{pid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}</td>|;
1108     
1109    
1110     $i++; $i %= 2;
1111     print qq|
1112         <tr class=listrow$i>
1113 |;
1114
1115     map { print "$column_data{$_}\n" } @column_index;
1116
1117     print qq|
1118         </tr>
1119 |;
1120     
1121     $sameid = $ref->{id};
1122     $sameinvid = $ref->{invid};
1123
1124   }
1125
1126  
1127   print qq|
1128       </table>
1129     </td>
1130   </tr>
1131   <tr>
1132     <td><hr size=3 noshade></td>
1133   </tr>
1134 </table>
1135
1136 |;
1137
1138   if ($form->{menubar}) {
1139     require "$form->{path}/menu.pl";
1140     &menubar;
1141   }
1142
1143   print qq|
1144   </form>
1145
1146 </body>
1147 </html>
1148 |;
1149  
1150 }
1151
1152
1153
1154 sub edit {
1155
1156 # $locale->text('Edit Customer')
1157 # $locale->text('Edit Vendor')
1158
1159   CT->create_links(\%myconfig, \%$form);
1160
1161   map { $form->{$_} = $form->quote($form->{$_}) } keys %$form;
1162
1163   $form->{title} = "Edit";
1164
1165   # format discount
1166   $form->{discount} *= 100;
1167   
1168   &form_header;
1169   &form_footer;
1170
1171 }
1172
1173
1174 sub form_header {
1175
1176   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
1177   $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0);
1178   
1179   if ($myconfig{role} =~ /(admin|manager)/) {
1180     $bcc = qq|
1181         <tr>
1182           <th align=right nowrap>|.$locale->text('Bcc').qq|</th>
1183           <td><input name=bcc size=35 value="$form->{bcc}"></td>
1184         </tr>
1185 |;
1186   }
1187   
1188   # currencies
1189   map { $form->{selectcurrency} .= "<option>$_\n" } split /:/, $form->{currencies};
1190   $form->{selectcurrency} =~ s/option>($form->{curr})/option selected>$1/;
1191   
1192   foreach $item (split / /, $form->{taxaccounts}) {
1193     if ($form->{tax}{$item}{taxable}) {
1194       $taxable .= qq| <input name="tax_$item" value=1 class=checkbox type=checkbox checked>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
1195     } else {
1196       $taxable .= qq| <input name="tax_$item" value=1 class=checkbox type=checkbox>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
1197     }
1198   }
1199
1200   if ($taxable) {
1201     $tax = qq|
1202         <tr>
1203           <th align=right>|.$locale->text('Taxable').qq|</th>
1204           <td colspan=5>
1205             <table>
1206               <tr>
1207                 <td>$taxable</td>
1208                 <td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
1209                 <th align=left>|.$locale->text('Tax Included').qq|</th>
1210               </tr>
1211             </table>
1212           </td>
1213         </tr>
1214 |;
1215   }
1216
1217   $typeofbusiness = qq|
1218           <th></th>
1219           <td></td>
1220 |;
1221
1222   if (@{ $form->{all_business} }) {
1223     $form->{selectbusiness} = qq|<option>\n|;
1224     map { $form->{selectbusiness} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } @{ $form->{all_business} };
1225
1226     $form->{selectbusiness} =~ s/(<option value="\Q$form->{business}--$form->{business_id}\E")>/$1 selected>/;
1227
1228     $typeofbusiness = qq|
1229           <th align=right>|.$locale->text('Type of Business').qq|</th>
1230           <td><select name=business>$form->{selectbusiness}</select></td>
1231 |;
1232
1233
1234   }
1235
1236   $pricegroup = qq|
1237           <th></th>
1238           <td></td>
1239 |;
1240
1241   if (@{ $form->{all_pricegroup} } && $form->{db} eq 'customer') {
1242     $form->{selectpricegroup} = qq|<option>\n|;
1243     map { $form->{selectpricegroup} .= qq|<option value="$_->{pricegroup}--$_->{id}">$_->{pricegroup}\n| } @{ $form->{all_pricegroup} };
1244     
1245     $form->{selectpricegroup} =~ s/(<option value="\Q$form->{pricegroup}--$form->{pricegroup_id}\E")/$1 selected/;
1246
1247     $pricegroup = qq|
1248           <th align=right>|.$locale->text('Pricegroup').qq|</th>
1249           <td><select name=pricegroup>$form->{selectpricegroup}</select></td>
1250 |;
1251   }
1252   
1253   $lang = qq|
1254           <th></th>
1255           <td></td>
1256 |;
1257
1258   if (@{ $form->{all_language} }) {
1259     $form->{selectlanguage} = qq|<option>\n|;
1260     map { $form->{selectlanguage} .= qq|<option value="$_->{description}--$_->{code}">$_->{description}\n| } @{ $form->{all_language} };
1261     
1262     $form->{selectlanguage} =~ s/(<option value="\Q$form->{language}--$form->{language_code}\E")/$1 selected/;
1263
1264     $lang = qq|
1265           <th align=right>|.$locale->text('Language').qq|</th>
1266           <td><select name=language>$form->{selectlanguage}</select></td>
1267 |;
1268   }
1269
1270  
1271   $employeelabel = $locale->text('Salesperson');
1272   
1273   $form->{selectemployee} = qq|<option>\n|;
1274   map { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{all_employee} };
1275   
1276   $form->{selectemployee} =~ s/(<option value="\Q$form->{employee}--$form->{employee_id}\E")/$1 selected/;
1277   
1278   if ($form->{db} eq 'vendor') {
1279     $gifi = qq|
1280           <th align=right>|.$locale->text('Sub-contract GIFI').qq|</th>
1281           <td><input name=gifi_accno size=9 value="$form->{gifi_accno}"></td>
1282 |;
1283     $employeelabel = $locale->text('Employee');
1284   }
1285
1286
1287   if (@{ $form->{all_employee} }) {
1288     $employee = qq|
1289                 <th align=right>$employeelabel</th>|;
1290                 
1291     if ($myconfig{role} ne 'user' || !$form->{id}) {
1292       $employee .= qq|
1293                 <td><select name=employee>$form->{selectemployee}</select></td>
1294 |;
1295     } else {
1296       $employee .= qq|
1297                 <td>$form->{employee}</td>
1298                 <input type=hidden name=employee value="$form->{employee}--$form->{employee_id}">|;
1299     }
1300   }
1301
1302
1303 # $locale->text('Customer Number')
1304 # $locale->text('Vendor Number')
1305
1306   $label = ucfirst $form->{db};
1307   $form->{title} = $locale->text("$form->{title} $label");
1308  
1309   $form->header;
1310
1311   print qq|
1312 <body>
1313
1314 <form method=post action=$form->{script}>
1315
1316 <table width=100%>
1317   <tr>
1318     <th class=listtop>$form->{title}</th>
1319   </tr>
1320   <tr height="5"></tr>
1321   <tr>
1322     <td>
1323       <table width=100%>
1324         <tr valign=top>
1325           <td width=50%>
1326             <table width=100%>
1327               <tr class=listheading>
1328                 <th class=listheading colspan=2 width=50%>|.$locale->text('Billing Address').qq|</th>
1329               <tr>
1330                 <th align=right nowrap>|.$locale->text($label .' Number').qq|</th>
1331                 <td><input name="$form->{db}number" size=35 maxlength=32 value="$form->{"$form->{db}number"}"></td>
1332               </tr>
1333               <tr>
1334                 <th align=right nowrap>|.$locale->text('Company Name').qq|</th>
1335                 <td><input name=name size=35 maxlength=64 value="$form->{name}"></td>
1336               </tr>
1337               <tr>
1338                 <th align=right nowrap>|.$locale->text('Address').qq|</th>
1339                 <td><input name=address1 size=35 maxlength=32 value="$form->{address1}"></td>
1340               </tr>
1341               <tr>
1342                 <th></th>
1343                 <td><input name=address2 size=35 maxlength=32 value="$form->{address2}"></td>
1344               </tr>
1345               <tr>
1346                 <th align=right nowrap>|.$locale->text('City').qq|</th>
1347                 <td><input name=city size=35 maxlength=32 value="$form->{city}"></td>
1348               </tr>
1349               <tr>
1350                 <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
1351                 <td><input name=state size=35 maxlength=32 value="$form->{state}"></td>
1352               </tr>
1353               <tr>
1354                 <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
1355                 <td><input name=zipcode size=10 maxlength=10 value="$form->{zipcode}"></td>
1356               </tr>
1357               <tr>
1358                 <th align=right nowrap>|.$locale->text('Country').qq|</th>
1359                 <td><input name=country size=35 maxlength=32 value="$form->{country}"></td>
1360               </tr>
1361               <tr>
1362                 <th align=right nowrap>|.$locale->text('Contact').qq|</th>
1363                 <td><input name=contact size=35 maxlength=64 value="$form->{contact}"></td>
1364               </tr>
1365               <tr>
1366                 <th align=right nowrap>|.$locale->text('Phone').qq|</th>
1367                 <td><input name=phone size=20 maxlength=20 value="$form->{phone}"></td>
1368               </tr>
1369               <tr>
1370                 <th align=right nowrap>|.$locale->text('Fax').qq|</th>
1371                 <td><input name=fax size=20 maxlength=20 value="$form->{fax}"></td>
1372               </tr>
1373               <tr>
1374                 <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
1375                 <td><input name=email size=35 value="$form->{email}"></td>
1376               </tr>
1377               <tr>
1378                 <th align=right nowrap>|.$locale->text('Cc').qq|</th>
1379                 <td><input name=cc size=35 value="$form->{cc}"></td>
1380               </tr>
1381               $bcc
1382             </table>
1383           </td>
1384           <td width=50%>
1385             <table width=100%>
1386               <tr>
1387                 <th class=listheading colspan=2>|.$locale->text('Shipping Address').qq|</th>
1388               </tr>
1389               <tr>
1390                 <td><input name=none size=35 value=|. ("=" x 35) .qq|></td>
1391               </tr>
1392               <tr>
1393                 <td><input name=shiptoname size=35 maxlength=64 value="$form->{shiptoname}"></td>
1394               </tr>
1395               <tr>
1396                 <td><input name=shiptoaddress1 size=35 maxlength=32 value="$form->{shiptoaddress1}"></td>
1397               </tr>
1398               <tr>
1399                 <td><input name=shiptoaddress2 size=35 maxlength=32 value="$form->{shiptoaddress2}"></td>
1400               </tr>
1401               <tr>
1402                 <td><input name=shiptocity size=35 maxlength=32 value="$form->{shiptocity}"></td>
1403               </tr>
1404               <tr>
1405                 <td><input name=shiptostate size=35 maxlength=32 value="$form->{shiptostate}"></td>
1406               </tr>
1407               <tr>
1408                 <td><input name=shiptozipcode size=10 maxlength=10 value="$form->{shiptozipcode}"></td>
1409               </tr>
1410               <tr>
1411                 <td><input name=shiptocountry size=35 maxlength=32 value="$form->{shiptocountry}"></td>
1412               </tr>
1413               <tr>
1414                 <td><input name=shiptocontact size=35 maxlength=64 value="$form->{shiptocontact}"></td>
1415               </tr>
1416               <tr>
1417                 <td><input name=shiptophone size=20 maxlength=20 value="$form->{shiptophone}"></td>
1418               </tr>
1419               <tr>
1420                 <td><input name=shiptofax size=20 maxlength=20 value="$form->{shiptofax}"></td>
1421               </tr>
1422               <tr>
1423                 <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
1424               </tr>
1425             </table>
1426           </td>
1427         </tr>
1428       </table>
1429     </td>
1430   </tr>
1431   <tr>
1432     <td>
1433       <table>
1434         $tax
1435         <tr>
1436           <th align=right>|.$locale->text('Startdate').qq|</th>
1437           <td><input name=startdate size=11 title="$myconfig{dateformat}" value=$form->{startdate}></td>
1438           <th align=right>|.$locale->text('Enddate').qq|</th>
1439           <td><input name=enddate size=11 title="$myconfig{dateformat}" value=$form->{enddate}></td>
1440         </tr>
1441         <tr>
1442           <th align=right>|.$locale->text('Credit Limit').qq|</th>
1443           <td><input name=creditlimit size=9 value="$form->{creditlimit}"></td>
1444           <th align=right>|.$locale->text('Terms').qq|</th>
1445           <td><input name=terms size=2 value="$form->{terms}"> <b>|.$locale->text('days').qq|</b></td>
1446           <th align=right>|.$locale->text('Discount').qq|</th>
1447           <td><input name=discount size=4 value="$form->{discount}">
1448           <b>%</b></td>
1449         </tr>
1450         <tr>
1451           <th align=right>|.$locale->text('Tax Number / SSN').qq|</th>
1452           <td><input name=taxnumber size=20 value="$form->{taxnumber}"></td>
1453           $gifi
1454           <th align=right>|.$locale->text('SIC').qq|</th>
1455           <td><input name=sic size=6 maxlength=6 value="$form->{sic}"></td>
1456         </tr>
1457         <tr>
1458           $typeofbusiness
1459           <th align=right>|.$locale->text('BIC').qq|</th>
1460           <td><input name=bic size=11 maxlength=11 value="$form->{bic}"></td>
1461           <th align=right>|.$locale->text('IBAN').qq|</th>
1462           <td><input name=iban size=24 maxlength=34 value="$form->{iban}"></td>
1463         </tr>
1464         <tr>
1465           $pricegroup
1466           $lang
1467           <th>|.$locale->text('Currency').qq|</th>
1468           <td><select name=curr>$form->{selectcurrency}</select></td>
1469         </tr>
1470         <tr valign=top>
1471           $employee
1472           <td colspan=4>
1473             <table>
1474               <tr valign=top>
1475                 <th align=left nowrap>|.$locale->text('Notes').qq|</th>
1476                 <td><textarea name=notes rows=3 cols=40 wrap=soft>$form->{notes}</textarea></td>
1477               </tr>
1478             </table>
1479           </td>
1480         </tr>
1481       </table>
1482     </td>
1483   </tr>
1484   <tr>
1485     <td><hr size=3 noshade></td>
1486   </tr>
1487 </table>
1488 |;
1489
1490 }
1491
1492
1493
1494 sub form_footer {
1495
1496   $i = 1;
1497   if ($form->{db} eq 'customer') {
1498     if ($myconfig{acs} !~ /AR--AR/) {
1499       $button{'AR--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|"> |;
1500       $button{'AR--Add Transaction'}{order} = $i++;
1501       $button{'AR--Sales Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice').qq|"> |;
1502       $button{'AR--Sales Invoice'}{order} = $i++;
1503     }
1504     if ($myconfig{acs} !~ /Order Entry--Order Entry/) {
1505       $button{'Order Entry--Sales Order'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Order').qq|"> |;
1506       $button{'Order Entry--Sales Order'}{order} = $i++;
1507     }
1508     if ($myconfig{acs} !~ /Quotations--Quotations/) {
1509       $button{'Quotations--Quotation'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Quotation').qq|"> |;
1510       $button{'Quotations--Quotation'}{order} = $i++;
1511     }
1512   }
1513   if ($form->{db} eq 'vendor') {
1514     if ($myconfig{acs} !~ /AP--AP/) {
1515       $button{'AP--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|"> |;
1516       $button{'AP--Add Transaction'}{order} = $i++;
1517       $button{'AP--Vendor Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice').qq|"> |;
1518       $button{'AP--Vendor Invoice'}{order} = $i++;
1519     }
1520     if ($myconfig{acs} !~ /Order Entry--Order Entry/) {
1521       $button{'Order Entry--Purchase Order'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Purchase Order').qq|"> |;
1522       $button{'Order Entry--Purchase Order'}{order} = $i++;
1523     }
1524     if ($myconfig{acs} !~ /Quotations--Quotations/) {
1525       $button{'Quotations--RFQ'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('RFQ').qq|"> |;
1526       $button{'Quotations--RFQ'}{order} = $i++;
1527     }
1528   }
1529   if ($myconfig{acs} !~ /Goods & Services--Goods & Services/) {
1530     $myconfig{acs} =~ s/(Goods & Services--Add )(Service|Assembly).*;/$1--Add Part/g;
1531     $button{'Goods & Services--Add Part'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Pricelist').qq|"> |;
1532     $button{'Goods & Services--Add Part'}{order} = $i++;
1533   }
1534
1535   foreach $item (split /;/, $myconfig{acs}) {
1536     delete $button{$item};
1537   }
1538  
1539   print qq|
1540 <input name=id type=hidden value=$form->{id}>
1541 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
1542
1543 <input type=hidden name=path value=$form->{path}>
1544 <input type=hidden name=login value=$form->{login}>
1545 <input type=hidden name=sessionid value=$form->{sessionid}>
1546
1547 <input type=hidden name=callback value="$form->{callback}">
1548 <input type=hidden name=db value=$form->{db}>
1549
1550 <br>
1551 |;
1552
1553   if ($form->{db} eq 'customer') {
1554     $item = 'AR--Customers--Add Customer';
1555   } 
1556   if ($form->{db} eq 'vendor') {
1557     $item = 'AP--Vendors--Add Vendor';
1558   } 
1559   
1560   if ($myconfig{acs} !~ /$item/) {
1561     print qq|
1562 <input class=submit type=submit name=action value="|.$locale->text("Save").qq|">
1563 |;
1564     if ($form->{id} && $form->{status} eq 'orphaned') {
1565       print qq|<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">\n|;
1566     }
1567   }
1568
1569   foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
1570     print $item->{code};
1571   }
1572   
1573   if ($form->{menubar}) {
1574     require "$form->{path}/menu.pl";
1575     &menubar;
1576   }
1577
1578   print qq|
1579  
1580   </form>
1581
1582 </body>
1583 </html>
1584 |;
1585
1586 }
1587
1588
1589 sub pricelist {
1590
1591   $form->isblank("name", $locale->text('Name missing!'));
1592
1593   CT->pricelist(\%myconfig, \%$form);
1594
1595   foreach $ref (@{ $form->{"all_partspricelist"} }) {
1596     $i++;
1597     map { $form->{"${_}_$i"} = $ref->{$_} } keys %$ref;
1598   }
1599   $form->{rowcount} = $i;
1600
1601   # currencies
1602   @curr = split /:/, $form->{currencies};
1603   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
1604   
1605   if (@ { $form->{all_partsgroup} }) {
1606     $form->{selectpartsgroup} = "<option>\n";
1607     foreach $ref (@ { $form->{all_partsgroup} }) {
1608       $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|;
1609     }
1610   }
1611
1612   map { delete $form->{$_} } ("currencies", "all_partsgroup", "all_partspricelist");
1613
1614   foreach $i (1 .. $form->{rowcount}) {
1615     
1616     if ($form->{db} eq 'customer') {
1617       
1618       $form->{"pricebreak_$i"} = $form->format_amount(\%myconfig, $form->{"pricebreak_$i"});
1619
1620       ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
1621       $dec = length $dec;
1622       $decimalplaces = ($dec > 2) ? $dec : 2;
1623       
1624       $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
1625       
1626     }
1627     
1628     if ($form->{db} eq 'vendor') {
1629       
1630       $form->{"leadtime_$i"} = $form->format_amount(\%myconfig, $form->{"leadtime_$i"});
1631       ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/);
1632       $dec = length $dec;
1633       $decimalplaces = ($dec > 2) ? $dec : 2;
1634       
1635       $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces);
1636       
1637     }
1638   }
1639
1640   $form->{rowcount}++;
1641   &{ "$form->{db}_pricelist" };
1642
1643 }
1644   
1645
1646 sub customer_pricelist {
1647
1648   @flds = qw(runningnumber id partnumber description sellprice unit partsgroup pricebreak curr validfrom validto);
1649
1650   $form->{rowcount}--;
1651   
1652   # remove empty rows
1653   if ($form->{rowcount}) {
1654
1655     foreach $i (1 .. $form->{rowcount}) {
1656
1657       map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(pricebreak sellprice);
1658       
1659       ($a, $b) = split /\./, $form->{"pricebreak_$i"};
1660       $a = length $a;
1661       $b = length $b;
1662       $whole = ($whole > $a) ? $whole : $a;
1663       $dec = ($dec > $b) ? $dec : $b;
1664     }
1665     $pad1 = '0' x $whole;
1666     $pad2 = '0' x $dec;
1667
1668     foreach $i (1 .. $form->{rowcount}) {
1669       ($a, $b) = split /\./, $form->{"pricebreak_$i"};
1670       
1671       $a = substr("$pad1$a", -$whole);
1672       $b = substr("$b$pad2", 0, $dec);
1673       $ndx{qq|$form->{"partnumber_$i"}_$form->{"id_$i"}_$a$b|} = $i;
1674     }
1675     
1676     $i = 1;
1677     map { $form->{"runningnumber_$ndx{$_}"} = $i++ } sort keys %ndx;
1678       
1679     foreach $i (1 .. $form->{rowcount}) {
1680       if ($form->{"partnumber_$i"} && $form->{"sellprice_$i"}) {
1681         if ($form->{"id_$i"} eq $sameid) {
1682           $j = $i + 1;
1683           next if ($form->{"id_$j"} eq $sameid && !$form->{"pricebreak_$i"});
1684         }
1685         
1686         push @a, {};
1687         $j = $#a;
1688
1689         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1690         $count++;
1691       }
1692       $sameid = $form->{"id_$i"};
1693     }
1694    
1695     $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1696     $form->{rowcount} = $count;
1697
1698   }
1699
1700   $form->{rowcount}++;
1701
1702   &pricelist_header;
1703   $form->hide_form();
1704   &pricelist_footer;
1705   
1706 }
1707
1708
1709 sub vendor_pricelist {
1710
1711   @flds = qw(runningnumber id sku partnumber description lastcost unit partsgroup curr leadtime);
1712
1713   $form->{rowcount}--;
1714   
1715   # remove empty rows
1716   if ($form->{rowcount}) {
1717
1718     foreach $i (1 .. $form->{rowcount}) {
1719
1720       map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(leadtime lastcost);
1721       $var = ($form->{"partnumber_$i"}) ? $form->{"sku_$i"} : qq|_$form->{"sku_$i"}|;
1722       $ndx{$var} = $i;
1723       
1724     }
1725
1726     $i = 1;
1727     map { $form->{"runningnumber_$ndx{$_}"} = $i++ } sort keys %ndx;
1728       
1729     foreach $i (1 .. $form->{rowcount}) {
1730       if ($form->{"sku_$i"}) {
1731         push @a, {};
1732         $j = $#a;
1733
1734         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
1735         $count++;
1736       }
1737     }
1738    
1739     $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
1740     $form->{rowcount} = $count;
1741
1742   }
1743
1744   $form->{rowcount}++;
1745
1746   &pricelist_header;
1747   $form->hide_form();
1748   &pricelist_footer;
1749   
1750 }
1751
1752
1753
1754 sub pricelist_header {
1755   
1756   $form->{title} = $form->{name};
1757  
1758   $form->header;
1759
1760   print qq|
1761 <body>
1762
1763 <form method=post action="$form->{script}">
1764
1765 <table width=100%>
1766   <tr>
1767     <th class=listtop>$form->{title}</th>
1768   </tr>
1769   <tr height="5"></tr>
1770 |;
1771
1772   if ($form->{db} eq 'customer') {
1773     @column_index = qw(partnumber description);
1774     push @column_index, "partsgroup" if $form->{selectpartsgroup};
1775     push @column_index, qw(pricebreak sellprice curr validfrom validto);
1776
1777     $column_header{pricebreak} = qq|<th class=listheading nowrap>|.$locale->text('Break').qq|</th>|;
1778     $column_header{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Sell Price').qq|</th>|;
1779     $column_header{validfrom} = qq|<th class=listheading nowrap>|.$locale->text('From').qq|</th>|;
1780     $column_header{validto} = qq|<th class=listheading nowrap>|.$locale->text('To').qq|</th>|;
1781   }
1782
1783   if ($form->{db} eq 'vendor') {
1784     @column_index = qw(sku partnumber description);
1785     push @column_index, "partsgroup" if $form->{selectpartsgroup};
1786     push @column_index, qw(lastcost curr leadtime);
1787
1788
1789     $column_header{sku} = qq|<th class=listheading nowrap>|.$locale->text('SKU').qq|</th>|;
1790     $column_header{leadtime} = qq|<th class=listheading nowrap>|.$locale->text('Leadtime').qq|</th>|;
1791     $column_header{lastcost} = qq|<th class=listheading nowrap>|.$locale->text('Cost').qq|</th>|;
1792   }
1793
1794   $column_header{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
1795   $column_header{description} = qq|<th class=listheading nowrap width=80%>|.$locale->text('Description').qq|</th>|;
1796   $column_header{partsgroup} = qq|<th class=listheading nowrap>|.$locale->text('Group').qq|</th>|;
1797   $column_header{curr} = qq|<th class=listheading nowrap>|.$locale->text('Curr').qq|</th>|;
1798
1799   print qq|
1800   <tr>
1801     <td>
1802       <table width=100%>
1803         <tr class=listheading>
1804 |;
1805
1806   map { print "\n$column_header{$_}" } @column_index;
1807   
1808   print qq|
1809        </tr>
1810 |;
1811
1812   $sameid = "";
1813   foreach $i (1 .. $form->{rowcount}) {
1814     
1815     $selectcurrency = $form->{selectcurrency};
1816     $selectcurrency =~ s/option>\Q$form->{"curr_$i"}\E/option selected>$form->{"curr_$i"}/;
1817
1818     if ($form->{selectpartsgroup}) {
1819       if ($i < $form->{rowcount}) {
1820         ($partsgroup) = split /--/, $form->{"partsgroup_$i"};
1821         $column_data{partsgroup} = qq|<td>$partsgroup</td>
1822         <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">|;
1823       }
1824     }
1825
1826
1827     if ($i < $form->{rowcount}) {
1828       
1829       if ($form->{"id_$i"} eq $sameid) {
1830         map { $column_data{$_} = qq|<td>&nbsp;</td>
1831         <input type=hidden name="${_}_$i" value="|.$form->quote($form->{"${_}_$i"}).qq|">| } qw(partnumber description partsgroup);
1832       
1833       } else {
1834         
1835         $column_data{sku} = qq|<td><input name="sku_$i" value="$form->{"sku_$i"}"></td>|;
1836         $column_data{partnumber} = qq|<td><input name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
1837
1838         $column_data{description} = qq|<td>$form->{"description_$i"}&nbsp;</td>
1839         <input type=hidden name="description_$i" value="|.$form->quote($form->{"description_$i"}).qq|">|;
1840       
1841       }
1842
1843       $column_data{partnumber} .= qq|
1844         <input type=hidden name="id_$i" value="$form->{"id_$i"}">|;
1845  
1846     } else {
1847    
1848       if ($form->{db} eq 'customer') {
1849         $column_data{partnumber} = qq|<td><input name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
1850       } else {
1851         $column_data{partnumber} = qq|<td>&nbsp;</td>|;
1852       }
1853
1854       $column_data{partnumber} .= qq|
1855         <input type=hidden name="id_$i" value="$form->{"id_$i"}">|;
1856       
1857       $column_data{sku} = qq|<td><input name="sku_$i" value="$form->{"sku_$i"}"></td>|;
1858       $column_data{description} = qq|<td><input name="description_$i" value="$form->{"description_$i"}"></td>|;
1859       
1860       if ($form->{selectpartsgroup}) {
1861         $column_data{partsgroup} = qq|<td><select name="partsgroup_$i">$form->{selectpartsgroup}</select></td>|;
1862       }
1863       
1864     }
1865
1866
1867     if ($form->{db} eq 'customer') {
1868       ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
1869       $dec = length $dec;
1870       $decimalplaces = ($dec > 2) ? $dec : 2;
1871       
1872       $column_data{pricebreak} = qq|<td align=right><input name="pricebreak_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"pricebreak_$i"}).qq|></td>|;
1873       $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;
1874       
1875       $column_data{validfrom} = qq|<td><input name="validfrom_$i" size=11 value=$form->{"validfrom_$i"}></td>|;
1876       $column_data{validto} = qq|<td><input name="validto_$i" size=11 value=$form->{"validto_$i"}></td>|;
1877     }
1878     
1879     if ($form->{db} eq 'vendor') {
1880       ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/);
1881       $dec = length $dec;
1882       $decimalplaces = ($dec > 2) ? $dec : 2;
1883       
1884       $column_data{leadtime} = qq|<td align=right><input name="leadtime_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"leadtime_$i"}).qq|></td>|;
1885       $column_data{lastcost} = qq|<td align=right><input name="lastcost_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces).qq|></td>|;
1886     }
1887       
1888
1889     $column_data{curr} = qq|<td><select name="curr_$i">$selectcurrency</select></td>|;
1890
1891     
1892     print qq|<tr valign=top>|;
1893     
1894     map { print "\n$column_data{$_}" } @column_index;
1895
1896     print qq|</tr>|;
1897
1898     $sameid = $form->{"id_$i"};
1899
1900   }
1901   
1902   print qq|
1903       </table>
1904     </td>
1905   </tr>
1906   <tr>
1907     <td><hr size=3 noshade></td>
1908   </tr>
1909 </table>
1910 |;
1911
1912   # delete variables
1913   foreach $i (1 .. $form->{rowcount}) {
1914     map { delete $form->{"${_}_$i"} } (@column_index, "id");
1915   }
1916   map { delete $form->{$_} } qw(title titlebar script none header action);
1917
1918 }
1919
1920
1921 sub pricelist_footer {
1922   
1923   print qq|
1924     <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
1925     <input class=submit type=submit name=action value="|.$locale->text('Save Pricelist').qq|">|;
1926     
1927   print qq|
1928 </form>
1929
1930 <a name="end"></a>
1931   
1932   </body>
1933   </html>
1934 |;  
1935
1936 }
1937
1938
1939 sub update {
1940   
1941   $i = $form->{rowcount};
1942   $additem = 0;
1943
1944   if ($form->{db} eq 'customer') {
1945     $additem = 1 if ! (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq ""));
1946   }
1947   if ($form->{db} eq 'vendor') {
1948     if (! (($form->{"sku_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq ""))) {
1949       $additem = 1;
1950       $form->{"partnumber_$i"} = $form->{"sku_$i"};
1951     }
1952   }
1953
1954   if ($additem) {
1955
1956     CT->retrieve_item(\%myconfig, \%$form);
1957
1958     $rows = scalar @{ $form->{item_list} };
1959
1960     if ($rows > 0) {
1961       
1962       if ($rows > 1) {
1963         
1964         &select_item;
1965         exit;
1966         
1967       } else {
1968         
1969         $sellprice = $form->{"sellprice_$i"};
1970         $pricebreak = $form->{"pricebreak_$i"};
1971         $lastcost = $form->{"lastcost_$i"};
1972         
1973         map { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) } qw(partnumber description);
1974         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
1975
1976         if ($form->{db} eq 'customer') {
1977           
1978           if ($sellprice) {
1979             $form->{"sellprice_$i"} = $sellprice;
1980           }
1981           
1982           ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
1983           $dec = length $dec;
1984           $decimalplaces = ($dec > 2) ? $dec : 2;
1985               
1986           $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
1987           
1988           $form->{"pricebreak_$i"} = $pricebreak;
1989           
1990         } else {
1991
1992           foreach $j (1 .. $form->{rowcount}) {
1993             if ($form->{"sku_$j"} eq $form->{"partnumber_$i"}) {
1994               $form->error($locale->text('Item already on pricelist!'));
1995             }
1996           }
1997
1998           if ($lastcost) {
1999             $form->{"lastcost_$i"} = $lastcost;
2000           }
2001            
2002           ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/);
2003           $dec = length $dec;
2004           $decimalplaces = ($dec > 2) ? $dec : 2;
2005               
2006           $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces);
2007
2008           $form->{"sku_$i"} = $form->{"partnumber_$i"};
2009           delete $form->{"partnumber_$i"};
2010           
2011         }
2012
2013         $form->{rowcount}++;
2014
2015       }
2016         
2017     } else {
2018
2019       $form->error($locale->text('Item not on file!'));
2020       
2021     }
2022   }
2023
2024   &{ "$form->{db}_pricelist" };
2025   
2026 }
2027
2028
2029
2030 sub select_item {
2031
2032   @column_index = qw(ndx partnumber description partsgroup unit sellprice lastcost);
2033
2034   $column_data{ndx} = qq|<th>&nbsp;</th>|;
2035   $column_data{partnumber} = qq|<th class=listheading>|.$locale->text('Number').qq|</th>|;
2036   $column_data{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
2037   $column_data{partsgroup} = qq|<th class=listheading>|.$locale->text('Group').qq|</th>|;
2038   $column_data{unit} = qq|<th class=listheading>|.$locale->text('Unit').qq|</th>|;
2039   $column_data{sellprice} = qq|<th class=listheading>|.$locale->text('Sell Price').qq|</th>|;
2040   $column_data{lastcost} = qq|<th class=listheading>|.$locale->text('Cost').qq|</th>|;
2041   
2042   $form->header;
2043   
2044   $title = $locale->text('Select from one of the items below');
2045   
2046   print qq|
2047 <body>
2048
2049 <form method=post action="$form->{script}">
2050
2051 <table width=100%>
2052   <tr>
2053     <th class=listtop>$title</th>
2054   </tr>
2055   <tr height="5"></tr>
2056   <tr>
2057     <td>$option</td>
2058   </tr>
2059   <tr>
2060     <td>
2061       <table width=100%>
2062         <tr class=listheading>|;
2063
2064   map { print "\n$column_data{$_}" } @column_index;
2065
2066   print qq|
2067         </tr>
2068 |;
2069
2070   my $i = 0;
2071   foreach $ref (@{ $form->{item_list} }) {
2072     $checked = ($i++) ? "" : "checked";
2073
2074     map { $ref->{$_} = $form->quote($ref->{$_}) } qw(partnumber description unit);
2075     
2076     $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
2077
2078     map { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| } qw(partnumber description partsgroup unit);
2079
2080     $column_data{sellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{sellprice}, 2, "&nbsp;").qq|</td>|;
2081     $column_data{lastcost} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{lastcost}, 2, "&nbsp;").qq|</td>|;
2082
2083     $j++; $j %= 2;
2084
2085     print qq|
2086         <tr class=listrow$j>|;
2087
2088     map { print "\n$column_data{$_}" } @column_index;
2089
2090     print qq|
2091         </tr>
2092
2093 <input name="new_partnumber_$i" type=hidden value="$ref->{partnumber}">
2094 <input name="new_description_$i" type=hidden value="$ref->{description}">
2095 <input name="new_partsgroup_$i" type=hidden value="$ref->{partsgroup}">
2096 <input name="new_partsgroup_id_$i" type=hidden value="$ref->{partsgroup_id}">
2097 <input name="new_sellprice_$i" type=hidden value=$ref->{sellprice}>
2098 <input name="new_lastcost_$i" type=hidden value=$ref->{lastcost}>
2099 <input name="new_unit_$i" type=hidden value="$ref->{unit}">
2100
2101 <input name="new_id_$i" type=hidden value=$ref->{id}>
2102
2103 |;
2104
2105   }
2106
2107   print qq|
2108       </table>
2109     </td>
2110   </tr>
2111   <tr>
2112     <td><hr size=3 noshade></td>
2113   </tr>
2114 </table>
2115
2116 <input name=lastndx type=hidden value=$i>
2117
2118 |;
2119
2120   # delete action variable
2121   map { delete $form->{$_} } qw(action item_list header);
2122
2123   $form->hide_form();
2124
2125   print qq|
2126 <input type=hidden name=nextsub value=item_selected>
2127
2128 <br>
2129 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
2130 </form>
2131
2132 </body>
2133 </html>
2134 |;
2135 }
2136
2137
2138
2139 sub item_selected {
2140
2141   # replace the last row with the checked row
2142   $i = $form->{rowcount};
2143
2144   # index for new item
2145   $j = $form->{ndx};
2146
2147   @new = qw(id partnumber description unit);
2148   push @new, "sellprice" if ! $form->{"sellprice_$i"};
2149   push @new, "lastcost" if ! $form->{"lastcost_$i"};
2150   
2151   map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } @new;
2152
2153   $form->{"partsgroup_$i"} = qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|;
2154
2155   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice lastcost);
2156   
2157   push @new, qw(partsgroup partsgroup_id);
2158
2159   # delete all the new_ variables
2160   for $i (1 .. $form->{lastndx}) {
2161     map { delete $form->{"new_${_}_$i"} } @new;
2162   }
2163   
2164   map { delete $form->{$_} } qw(ndx lastndx nextsub);
2165
2166   # format amounts
2167   map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(sellprice lastcost);
2168   
2169   foreach $j (1 .. $form->{rowcount}) {
2170     if ($form->{"sku_$j"} eq $form->{"partnumber_$i"}) {
2171       $form->error($locale->text('Item already on pricelist!'));
2172     }
2173   }
2174   
2175   $form->{"sku_$i"} = $form->{"partnumber_$i"};
2176   delete $form->{"partnumber_$i"} if $form->{db} eq 'vendor';
2177
2178   $form->{rowcount}++;
2179   &{ "$form->{db}_pricelist" };
2180
2181 }
2182
2183
2184
2185     
2186 sub save_pricelist {
2187  
2188   &{ "CT::save_$form->{db}" }("", \%myconfig, \%$form);
2189
2190   $rc = CT->save_pricelist(\%myconfig, \%$form);
2191
2192   $form->{callback} = "$form->{script}?action=edit&db=$form->{db}&id=$form->{id}&login=$form->{login}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
2193   
2194   $form->redirect if $rc;
2195   $form->error($locale->text('Could not save pricelist!'));
2196
2197 }
2198
2199
2200
2201 sub add_transaction {
2202   
2203   $form->isblank("name", $locale->text("Name missing!"));
2204
2205   &{ "CT::save_$form->{db}" }("", \%myconfig, \%$form);
2206   
2207   $form->{callback} = $form->escape($form->{callback},1);
2208   $name = $form->escape($form->{name},1);
2209
2210   $form->{callback} = "$form->{script}?login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}";
2211
2212   $form->redirect;
2213   
2214 }
2215
2216 sub ap_transaction {
2217
2218   $form->{script} = "ap.pl";
2219   $form->{type} = "ap_transaction";
2220   &add_transaction;
2221
2222 }
2223
2224
2225 sub ar_transaction {
2226
2227   $form->{script} = "ar.pl";
2228   $form->{type} = "ar_transaction";
2229   &add_transaction;
2230
2231 }
2232
2233
2234 sub sales_invoice {
2235
2236   $form->{script} = "is.pl";
2237   $form->{type} = "invoice";
2238   &add_transaction;
2239   
2240 }
2241
2242
2243 sub vendor_invoice {
2244
2245   $form->{script} = "ir.pl";
2246   $form->{type} = "invoice";
2247   &add_transaction;
2248   
2249 }
2250
2251
2252 sub rfq {
2253
2254   $form->{script} = "oe.pl";
2255   $form->{type} = "request_quotation";
2256   &add_transaction;
2257
2258 }
2259
2260
2261 sub quotation {
2262   
2263   $form->{script} = "oe.pl";
2264   $form->{type} = "sales_quotation";
2265   &add_transaction;
2266
2267 }
2268
2269
2270 sub sales_order {
2271   
2272   $form->{script} = "oe.pl";
2273   $form->{type} = "sales_order";
2274   &add_transaction;
2275
2276 }
2277
2278
2279 sub purchase_order {
2280
2281   $form->{script} = "oe.pl";
2282   $form->{type} = "purchase_order";
2283   &add_transaction;
2284   
2285 }
2286
2287
2288 sub save {
2289
2290 # $locale->text('Customer saved!')
2291 # $locale->text('Vendor saved!')
2292
2293   $msg = ucfirst $form->{db};
2294   $msg .= " saved!";
2295   
2296   $form->isblank("name", $locale->text("Name missing!"));
2297   &{ "CT::save_$form->{db}" }("", \%myconfig, \%$form);
2298   
2299   $form->redirect($locale->text($msg));
2300   
2301 }
2302
2303
2304 sub delete {
2305
2306 # $locale->text('Customer deleted!')
2307 # $locale->text('Cannot delete customer!')
2308 # $locale->text('Vendor deleted!')
2309 # $locale->text('Cannot delete vendor!')
2310
2311   CT->delete(\%myconfig, \%$form);
2312   
2313   $msg = ucfirst $form->{db};
2314   $msg .= " deleted!";
2315   $form->redirect($locale->text($msg));
2316   
2317   $msg = "Cannot delete $form->{db}";
2318   $form->error($locale->text($msg));
2319
2320 }
2321
2322
2323 sub continue { &{ $form->{nextsub} } };
2324
2325 sub add_customer { &add };
2326 sub add_vendor { &add };
2327