This commit was generated by cvs2svn to compensate for changes in r3880,
[freeside.git] / sql-ledger / old / sql-ledger / bin / mozilla / ct.pl
1 #=====================================================================
2 # SQL-Ledger Accounting
3 # Copyright (c) 1998-2002
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 # $locale->text('Customers')
30 # $locale->text('Vendors')
31
32 use SL::CT;
33
34 1;
35 # end of main
36
37
38
39 sub add {
40
41   $form->{title} = "Add";
42
43   $form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback};
44
45   CT->taxaccounts(\%myconfig, \%$form);
46   
47   &form_header;
48   &form_footer;
49   
50 }
51
52
53 sub search {
54
55   $label = ucfirst $form->{db};
56   $form->{title} = $locale->text($label."s");
57  
58   $form->header;
59   
60   print qq|
61 <body>
62
63 <form method=post action=$form->{script}>
64
65 <input type=hidden name=db value=$form->{db}>
66
67 <table width=100%>
68   <tr>
69     <th class=listtop>$form->{title}</th>
70   </tr>
71   <tr height="5"></tr>
72   <tr valign=top>
73     <td>
74       <table>
75         <tr>
76           <th align=right nowrap>|.$locale->text('Number').qq|</th>
77           <td><input name=$form->{db}number size=35></td>
78         </tr>
79         <tr>
80           <th align=right nowrap>|.$locale->text('Name').qq|</th>
81           <td><input name=name size=35></td>
82         </tr>
83         <tr>
84           <th align=right nowrap>|.$locale->text('Contact').qq|</th>
85           <td><input name=contact size=35></td>
86         </tr>
87         <tr>
88           <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
89           <td><input name=email size=35></td>
90         </tr>
91         <tr>
92           <td></td>
93           <td><input name=status class=radio type=radio value=all checked>&nbsp;|.$locale->text('All').qq|
94           <input name=status class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned').qq|</td>
95         </tr>
96         <tr>
97           <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
98           <td>
99           <input name="l_$form->{db}number" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Number').qq|
100           <input name="l_name" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Name').qq|
101           <input name="l_address" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Address').qq|<br>
102           <input name="l_contact" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Contact').qq|
103           <input name="l_phone" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Phone').qq|
104           <input name="l_fax" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Fax').qq|
105           <input name="l_email" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('E-mail').qq|
106           <input name="l_cc" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Cc').qq|
107           </td>
108         </tr>
109       </table>
110     </td>
111   </tr>
112   <tr>
113     <td><hr size=3 noshade></td>
114   </tr>
115 </table>
116
117 <input type=hidden name=nextsub value=list_names>
118
119 <input type=hidden name=path value=$form->{path}>
120 <input type=hidden name=login value=$form->{login}>
121 <input type=hidden name=password value=$form->{password}>
122
123 <br>
124 <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
125 </form>
126
127 </body>
128 </html>
129 |;
130 }
131
132
133 sub list_names {
134   
135   CT->search(\%myconfig, \%$form);
136   
137   $callback = "$form->{script}?action=list_names&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
138   $href = $callback;
139   
140   @columns = $form->sort_columns(name, "$form->{db}number", address, contact, phone, fax, email, cc);
141
142   foreach $item (@columns) {
143     if ($form->{"l_$item"} eq "Y") {
144       push @column_index, $item;
145
146       # add column to href and callback
147       $callback .= "&l_$item=Y";
148       $href .= "&l_$item=Y";
149     }
150   }
151   
152   if ($form->{status} eq 'all') {
153     $option = $locale->text('All');
154   }
155   if ($form->{status} eq 'orphaned') {
156     $option .= $locale->text('Orphaned');
157   }
158   if ($form->{name}) {
159     $callback .= "&name=$form->{name}";
160     $href .= "&name=".$form->escape($form->{name});
161     $option .= "\n<br>".$locale->text('Name')." : $form->{name}";
162   }
163   if ($form->{contact}) {
164     $callback .= "&contact=$form->{contact}";
165     $href .= "&contact=".$form->escape($form->{contact});
166     $option .= "\n<br>".$locale->text('Contact')." : $form->{contact}";
167   }
168   if ($form->{"$form->{db}number"}) {
169     $callback .= qq|&$form->{db}number=$form->{"$form->{db}number"}|;
170     $href .= "&$form->{db}number=".$form->escape($form->{"$form->{db}number"});
171     $option .= "\n<br>".$locale->text('Number').qq| : $form->{"$form->{db}number"}|;
172   }
173   if ($form->{email}) {
174     $callback .= "&email=$form->{email}";
175     $href .= "&email=".$form->escape($form->{email});
176     $option .= "\n<br>".$locale->text('E-mail')." : $form->{email}";
177   }
178
179   $form->{callback} = "$callback&sort=$form->{sort}";
180   $callback = $form->escape($form->{callback});
181   
182   $column_header{"$form->{db}number"} = qq|<th><a class=listheading href=$href&sort=$form->{db}number>|.$locale->text('Number').qq|</a></th>|;
183   $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|;
184   $column_header{address} = qq|<th><a class=listheading href=$href&sort=address>|.$locale->text('Address').qq|</a></th>|;
185   $column_header{contact} = qq|<th><a class=listheading href=$href&sort=contact>|.$locale->text('Contact').qq|</a></th>|;
186   $column_header{phone} = qq|<th><a class=listheading href=$href&sort=phone>|.$locale->text('Phone').qq|</a></th>|;
187   $column_header{fax} = qq|<th><a class=listheading href=$href&sort=fax>|.$locale->text('Fax').qq|</a></th>|;
188   $column_header{email} = qq|<th><a class=listheading href=$href&sort=email>|.$locale->text('E-mail').qq|</a></th>|;
189   $column_header{cc} = qq|<th><a class=listheading href=$href&sort=cc>|.$locale->text('Cc').qq|</a></th>|;
190   
191   $label = ucfirst $form->{db}."s";
192   $form->{title} = $locale->text($label);
193
194   $form->header;
195
196   print qq|
197 <body>
198
199 <table width=100%>
200   <tr>
201     <th class=listtop>$form->{title}</th>
202   </tr>
203   <tr height="5"></tr>
204   <tr>
205     <td>$option</td>
206   </tr>
207   <tr>
208     <td>
209       <table width=100%>
210         <tr class=listheading>
211 |;
212
213   map { print "$column_header{$_}\n" } @column_index;
214   
215   print qq|
216         </tr>
217 |;
218
219   foreach $ref (@{ $form->{CT} }) {
220
221     map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } ("$form->{db}number", address, contact, phone, fax);
222     
223     $column_data{name} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}&callback=$callback>$ref->{name}&nbsp;</td>";
224     
225     $column_data{email} = ($ref->{email}) ? qq|<td><a href="mailto:$ref->{email}">$ref->{email}</a></td>| : "<td>&nbsp;</td>";
226     $column_data{cc} = ($ref->{cc}) ? qq|<td><a href="mailto:$ref->{cc}">$ref->{cc}</a></td>| : "<td>&nbsp;</td>";
227     
228     $i++; $i %= 2;
229     print "
230         <tr class=listrow$i>
231 ";
232
233     map { print "$column_data{$_}\n" } @column_index;
234
235     print qq|
236         </tr>
237 |;
238     
239   }
240
241   print qq|
242       </table>
243     </td>
244   </tr>
245   <tr>
246     <td><hr size=3 noshade></td>
247   </tr>
248 </table>
249
250 <br>
251 <form method=post action=$form->{script}>
252
253 <input name=callback type=hidden value="$form->{callback}">
254 <input name=db type=hidden value=$form->{db}>
255
256 <input type=hidden name=path value=$form->{path}>
257 <input type=hidden name=login value=$form->{login}>
258 <input type=hidden name=password value=$form->{password}>
259
260 <input class=submit type=submit name=action value="|.$locale->text('Add').qq|">
261
262 </form>
263
264 </body>
265 </html>
266 |;
267  
268 }
269
270
271 sub edit {
272
273 # $locale->text('Edit Customer')
274 # $locale->text('Edit Vendor')
275
276   CT->get_tuple(\%myconfig, \%$form);
277
278   # format " into &quot;
279   map { $form->{$_} =~ s/"/&quot;/g } keys %$form;
280
281   $form->{title} = "Edit";
282
283   # format discount
284   $form->{discount} *= 100;
285   
286   &form_header;
287   &form_footer;
288
289 }
290
291
292 sub form_header {
293
294   foreach $item (split / /, $form->{taxaccounts}) {
295     if (($form->{tax}{$item}{taxable}) || !($form->{id})) {
296       $taxable .= qq| <input name="tax_$item" value=1 class=checkbox type=checkbox checked>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
297     } else {
298       $taxable .= qq| <input name="tax_$item" value=1 class=checkbox type=checkbox>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
299     }
300   }
301
302   $tax = qq|
303   <tr>
304     <td>
305       <table>
306         <tr>
307           <th align=right>|.$locale->text('Taxable').qq|</th>
308           <td>$taxable</td>
309         </tr>
310       </table>
311     </td>
312   </tr>
313 |;
314
315   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
316   $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0);
317   
318   if ($myconfig{admin}) {
319     $bcc = qq|
320         <tr>
321           <th align=right nowrap>|.$locale->text('Bcc').qq|</th>
322           <td><input name=bcc size=35 value="$form->{bcc}"></td>
323         </tr>
324 |;
325   }
326   
327   
328   $label = ucfirst $form->{db};
329   $form->{title} = $locale->text("$form->{title} $label");
330
331   if ($form->{db} eq 'customer') {
332     $creditlimit = qq|
333           <th align=right>|.$locale->text('Credit Limit').qq|</th>
334           <td><input name=creditlimit size=9 value="$form->{creditlimit}"></td>
335           <th align=right>|.$locale->text('Discount').qq|</th>
336           <td><input name=discount size=4 value="$form->{discount}"></td>
337           <th>%</th>
338 |;
339   }
340
341   $form->header;
342
343   print qq|
344 <body>
345
346 <form method=post action=$form->{script}>
347
348 <table width=100%>
349   <tr>
350     <th class=listtop>$form->{title}</th>
351   </tr>
352   <tr>
353     <td>
354       <table width=100%>
355         <tr class=listheading>
356           <th class=listheading colspan=2 width=50%">&nbsp;</th>
357           <th class=listheading width=50%">|.$locale->text('Ship to').qq|</th>
358         </tr>
359         <tr height="5"></tr>
360         <tr>
361           <th align=right nowrap>|.$locale->text('Number').qq|</th>
362           <td><input name="$form->{db}number" size=35 maxsize=35 value="$form->{"$form->{db}number"}"></td>
363         </tr>
364         <tr>
365           <th align=right nowrap>|.$locale->text('Name').qq|</th>
366           <td><input name=name size=35 maxsize=35 value="$form->{name}"></td>
367           <td><input name=shiptoname size=35 maxsize=35 value="$form->{shiptoname}"></td>
368         </tr>
369         <tr>
370           <th align=right nowrap>|.$locale->text('Address').qq|</th>
371           <td><input name=addr1 size=35 maxsize=35 value="$form->{addr1}"></td>
372           <td><input name=shiptoaddr1 size=35 maxsize=35 value="$form->{shiptoaddr1}"></td>
373         </tr>
374         <tr>
375           <th></th>
376           <td><input name=addr2 size=35 maxsize=35 value="$form->{addr2}"></td>
377           <td><input name=shiptoaddr2 size=35 maxsize=35 value="$form->{shiptoaddr2}"></td>
378         </tr>
379         <tr>
380           <th></th>
381           <td><input name=addr3 size=35 maxsize=35 value="$form->{addr3}"></td>
382           <td><input name=shiptoaddr3 size=35 maxsize=35 value="$form->{shiptoaddr3}"></td>
383         </tr>
384         <tr>
385           <th></th>
386           <td><input name=addr4 size=35 maxsize=35 value="$form->{addr4}"></td>
387           <td><input name=shiptoaddr4 size=35 maxsize=35 value="$form->{shiptoaddr4}"></td>
388         </tr>
389         <tr>
390           <th align=right nowrap>|.$locale->text('Contact').qq|</th>
391           <td><input name=contact size=35 maxsize=35 value="$form->{contact}"></td>
392           <td><input name=shiptocontact size=35 maxsize=35 value="$form->{shiptocontact}"></td>
393         </tr>
394         <tr>
395           <th align=right nowrap>|.$locale->text('Phone').qq|</th>
396           <td><input name=phone size=20 maxsize=20 value="$form->{phone}"></td>
397           <td><input name=shiptophone size=20 maxsize=20 value="$form->{shiptophone}"></td>
398         </tr>
399         <tr>
400           <th align=right nowrap>|.$locale->text('Fax').qq|</th>
401           <td><input name=fax size=20 maxsize=20 value="$form->{fax}"></td>
402           <td><input name=shiptofax size=20 maxsize=20 value="$form->{shiptofax}"></td>
403         </tr>
404         <tr>
405           <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
406           <td><input name=email size=35 value="$form->{email}"></td>
407           <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
408         </tr>
409         <tr>
410           <th align=right nowrap>|.$locale->text('Cc').qq|</th>
411           <td><input name=cc size=35 value="$form->{cc}"></td>
412         </tr>
413         $bcc
414       </table>
415     </td>
416   </tr>
417   <tr>
418     <td>
419       <table width=100%>
420         <tr>
421           <th align=right>|.$locale->text('Terms: Net').qq|</th>
422           <td><input name=terms size=2 value="$form->{terms}"></td>
423           <th>|.$locale->text('days').qq|</th>
424           $creditlimit
425           <td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
426           <th align=left>|.$locale->text('Tax Included').qq|</th>
427         </tr>
428       </table>
429     </td>
430   </tr>
431   $tax
432   <tr>
433     <th align=left nowrap>|.$locale->text('Notes').qq|</th>
434   </tr>
435   <tr>
436     <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
437   </tr>
438   <tr>
439     <td><hr size=3 noshade></td>
440   </tr>
441 </table>
442 |;
443
444 }
445
446
447
448 sub form_footer {
449
450   $label = ucfirst $form->{db};
451
452   print qq|
453 <input name=id type=hidden value=$form->{id}>
454 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
455
456 <input type=hidden name=path value=$form->{path}>
457 <input type=hidden name=login value=$form->{login}>
458 <input type=hidden name=password value=$form->{password}>
459
460 <input type=hidden name=callback value="$form->{callback}">
461 <input type=hidden name=db value=$form->{db}>
462
463 <br>
464
465 <input class=submit type=submit name=action value="|.$locale->text("Save").qq|">
466 <input class=submit type=submit name=action value="|.$locale->text("Invoice").qq|">
467 <input class=submit type=submit name=action value="|.$locale->text('Order').qq|">
468 |;
469
470   if ($form->{id} && $form->{status} eq 'orphaned') {
471     print qq|<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">\n|;
472   }
473
474   print qq|
475  
476   </form>
477
478 </body>
479 </html>
480 |;
481
482 }
483
484
485 sub invoice { &{ "$form->{db}_invoice" } };
486
487 sub customer_invoice {
488
489   $form->isblank("name", $locale->text("Name missing!"));
490   CT->save_customer(\%myconfig, \%$form);
491   
492   delete $form->{script};
493   
494   $form->{action} = "add";
495   $form->{callback} = $form->escape($form->{callback},1);
496
497   $form->{customer} = $form->{name};
498   $form->{customer_id} = $form->{id};
499   $form->{vc} = 'customer';
500
501   delete $form->{id};
502
503   map { $argv .= "$_=$form->{$_}&" } keys %$form;
504   
505   exec ("perl", "is.pl", $argv);
506
507 }
508
509
510 sub vendor_invoice {
511
512   $form->isblank("name", $locale->text("Name missing!"));
513   CT->save_vendor(\%myconfig, \%$form);
514   
515   delete $form->{script};
516   
517   $form->{action} = "add";
518   $form->{callback} = $form->escape($form->{callback},1);
519
520   $form->{vendor} = $form->{name};
521   $form->{vendor_id} = $form->{id};
522   $form->{vc} = 'vendor';
523   
524   delete $form->{id};
525
526   map { $argv .= "$_=$form->{$_}&" } keys %$form;
527   
528   exec ("perl", "ir.pl", $argv);
529
530 }
531
532
533 sub order { &{ "$form->{db}_order" } };
534
535 sub customer_order {
536
537   $form->isblank("name", $locale->text("Name missing!"));
538   CT->save_customer(\%myconfig, \%$form);
539   
540   delete $form->{script};
541   
542   $form->{action} = "add";
543   $form->{callback} = $form->escape($form->{callback},1);
544   
545   $form->{customer} = $form->{name};
546   $form->{customer_id} = $form->{id};
547   $form->{vc} = 'customer';
548
549   $form->{type} = 'sales_order';
550   
551   delete $form->{id};
552
553   map { $argv .= "$_=$form->{$_}&" } keys %$form;
554   
555   exec ("perl", "oe.pl", $argv);
556
557 }
558
559
560 sub vendor_order {
561
562   $form->isblank("name", $locale->text("Name missing!"));
563   CT->save_vendor(\%myconfig, \%$form);
564   
565   delete $form->{script};
566   
567   $form->{action} = "add";
568   $form->{callback} = $form->escape($form->{callback},1);
569   
570   $form->{vendor} = $form->{name};
571   $form->{vendor_id} = $form->{id};
572   $form->{vc} = 'vendor';
573
574   $form->{type} = 'purchase_order';
575
576   delete $form->{id};
577
578   map { $argv .= "$_=$form->{$_}&" } keys %$form;
579   
580   exec ("perl", "oe.pl", $argv);
581
582 }
583
584
585 sub save { &{ "save_$form->{db}" } };
586
587 sub save_customer {
588
589   $form->isblank("name", $locale->text("Name missing!"));
590   CT->save_customer(\%myconfig, \%$form);
591   $form->redirect($locale->text('Customer saved!'));
592   
593 }
594
595
596 sub save_vendor {
597
598   $form->isblank("name", $locale->text("Name missing!"));
599   CT->save_vendor(\%myconfig, \%$form);
600   $form->redirect($locale->text('Vendor saved!'));
601   
602 }
603
604
605 sub delete { &{ "delete_$form->{db}" } };
606
607 sub delete_customer {
608
609   $rc = CT->delete_customer(\%myconfig, \%$form);
610   
611   $form->error($locale->text('Transactions exist, cannot delete customer!')) if ($rc == -1);
612   $form->redirect($locale->text('Customer deleted!')) if $rc;
613   $form->error($locale->text('Cannot delete customer!'));
614
615 }
616
617
618 sub delete_vendor {
619
620   $rc = CT->delete_vendor(\%myconfig, \%$form);
621   
622   $form->error($locale->text('Transactions exist, cannot delete vendor!')) if ($rc == -1);
623   $form->redirect($locale->text('Vendor deleted!')) if $rc;
624   $form->error($locale->text('Cannot delete vendor!'));
625
626 }
627
628
629 sub continue { &{ $form->{nextsub} } };
630
631