1 #=====================================================================
2 # SQL-Ledger Accounting
3 # Copyright (c) 1998-2002
5 # Author: Dieter Simader
6 # Email: dsimader@sql-ledger.org
7 # Web: http://www.sql-ledger.org
9 # Contributors: Reed White <alta@alta-research.com>
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.
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 #======================================================================
25 # customer/vendor module
27 #======================================================================
29 # $locale->text('Customers')
30 # $locale->text('Vendors')
41 $form->{title} = "Add";
43 $form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback};
45 CT->taxaccounts(\%myconfig, \%$form);
55 $label = ucfirst $form->{db};
56 $form->{title} = $locale->text($label."s");
63 <form method=post action=$form->{script}>
65 <input type=hidden name=db value=$form->{db}>
69 <th class=listtop>$form->{title}</th>
76 <th align=right nowrap>|.$locale->text('Number').qq|</th>
77 <td><input name=$form->{db}number size=35></td>
80 <th align=right nowrap>|.$locale->text('Name').qq|</th>
81 <td><input name=name size=35></td>
84 <th align=right nowrap>|.$locale->text('Contact').qq|</th>
85 <td><input name=contact size=35></td>
88 <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
89 <td><input name=email size=35></td>
93 <td><input name=status class=radio type=radio value=all checked> |.$locale->text('All').qq|
94 <input name=status class=radio type=radio value=orphaned> |.$locale->text('Orphaned').qq|</td>
97 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
99 <input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |.$locale->text('Number').qq|
100 <input name="l_name" type=checkbox class=checkbox value=Y checked> |.$locale->text('Name').qq|
101 <input name="l_address" type=checkbox class=checkbox value=Y> |.$locale->text('Address').qq|<br>
102 <input name="l_contact" type=checkbox class=checkbox value=Y checked> |.$locale->text('Contact').qq|
103 <input name="l_phone" type=checkbox class=checkbox value=Y checked> |.$locale->text('Phone').qq|
104 <input name="l_fax" type=checkbox class=checkbox value=Y> |.$locale->text('Fax').qq|
105 <input name="l_email" type=checkbox class=checkbox value=Y checked> |.$locale->text('E-mail').qq|
106 <input name="l_cc" type=checkbox class=checkbox value=Y> |.$locale->text('Cc').qq|
113 <td><hr size=3 noshade></td>
117 <input type=hidden name=nextsub value=list_names>
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}>
124 <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
135 CT->search(\%myconfig, \%$form);
137 $callback = "$form->{script}?action=list_names&db=$form->{db}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
140 @columns = $form->sort_columns(name, "$form->{db}number", address, contact, phone, fax, email, cc);
142 foreach $item (@columns) {
143 if ($form->{"l_$item"} eq "Y") {
144 push @column_index, $item;
146 # add column to href and callback
147 $callback .= "&l_$item=Y";
148 $href .= "&l_$item=Y";
152 if ($form->{status} eq 'all') {
153 $option = $locale->text('All');
155 if ($form->{status} eq 'orphaned') {
156 $option .= $locale->text('Orphaned');
159 $callback .= "&name=$form->{name}";
160 $href .= "&name=".$form->escape($form->{name});
161 $option .= "\n<br>".$locale->text('Name')." : $form->{name}";
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}";
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"}|;
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}";
179 $form->{callback} = "$callback&sort=$form->{sort}";
180 $callback = $form->escape($form->{callback});
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>|;
191 $label = ucfirst $form->{db}."s";
192 $form->{title} = $locale->text($label);
201 <th class=listtop>$form->{title}</th>
210 <tr class=listheading>
213 map { print "$column_header{$_}\n" } @column_index;
219 foreach $ref (@{ $form->{CT} }) {
221 map { $column_data{$_} = "<td>$ref->{$_} </td>" } ("$form->{db}number", address, contact, phone, fax);
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} </td>";
225 $column_data{email} = ($ref->{email}) ? qq|<td><a href="mailto:$ref->{email}">$ref->{email}</a></td>| : "<td> </td>";
226 $column_data{cc} = ($ref->{cc}) ? qq|<td><a href="mailto:$ref->{cc}">$ref->{cc}</a></td>| : "<td> </td>";
233 map { print "$column_data{$_}\n" } @column_index;
246 <td><hr size=3 noshade></td>
251 <form method=post action=$form->{script}>
253 <input name=callback type=hidden value="$form->{callback}">
254 <input name=db type=hidden value=$form->{db}>
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}>
260 <input class=submit type=submit name=action value="|.$locale->text('Add').qq|">
273 # $locale->text('Edit Customer')
274 # $locale->text('Edit Vendor')
276 CT->get_tuple(\%myconfig, \%$form);
278 # format " into "
279 map { $form->{$_} =~ s/"/"/g } keys %$form;
281 $form->{title} = "Edit";
284 $form->{discount} *= 100;
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> <b>$form->{tax}{$item}{description}</b>|;
298 $taxable .= qq| <input name="tax_$item" value=1 class=checkbox type=checkbox> <b>$form->{tax}{$item}{description}</b>|;
307 <th align=right>|.$locale->text('Taxable').qq|</th>
315 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
316 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0);
318 if ($myconfig{admin}) {
321 <th align=right nowrap>|.$locale->text('Bcc').qq|</th>
322 <td><input name=bcc size=35 value="$form->{bcc}"></td>
328 $label = ucfirst $form->{db};
329 $form->{title} = $locale->text("$form->{title} $label");
331 if ($form->{db} eq 'customer') {
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>
346 <form method=post action=$form->{script}>
350 <th class=listtop>$form->{title}</th>
355 <tr class=listheading>
356 <th class=listheading colspan=2 width=50%"> </th>
357 <th class=listheading width=50%">|.$locale->text('Ship to').qq|</th>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
410 <th align=right nowrap>|.$locale->text('Cc').qq|</th>
411 <td><input name=cc size=35 value="$form->{cc}"></td>
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>
425 <td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
426 <th align=left>|.$locale->text('Tax Included').qq|</th>
433 <th align=left nowrap>|.$locale->text('Notes').qq|</th>
436 <td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
439 <td><hr size=3 noshade></td>
450 $label = ucfirst $form->{db};
453 <input name=id type=hidden value=$form->{id}>
454 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
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}>
460 <input type=hidden name=callback value="$form->{callback}">
461 <input type=hidden name=db value=$form->{db}>
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|">
470 if ($form->{id} && $form->{status} eq 'orphaned') {
471 print qq|<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">\n|;
485 sub invoice { &{ "$form->{db}_invoice" } };
487 sub customer_invoice {
489 $form->isblank("name", $locale->text("Name missing!"));
490 CT->save_customer(\%myconfig, \%$form);
492 delete $form->{script};
494 $form->{action} = "add";
495 $form->{callback} = $form->escape($form->{callback},1);
497 $form->{customer} = $form->{name};
498 $form->{customer_id} = $form->{id};
499 $form->{vc} = 'customer';
503 map { $argv .= "$_=$form->{$_}&" } keys %$form;
505 exec ("perl", "is.pl", $argv);
512 $form->isblank("name", $locale->text("Name missing!"));
513 CT->save_vendor(\%myconfig, \%$form);
515 delete $form->{script};
517 $form->{action} = "add";
518 $form->{callback} = $form->escape($form->{callback},1);
520 $form->{vendor} = $form->{name};
521 $form->{vendor_id} = $form->{id};
522 $form->{vc} = 'vendor';
526 map { $argv .= "$_=$form->{$_}&" } keys %$form;
528 exec ("perl", "ir.pl", $argv);
533 sub order { &{ "$form->{db}_order" } };
537 $form->isblank("name", $locale->text("Name missing!"));
538 CT->save_customer(\%myconfig, \%$form);
540 delete $form->{script};
542 $form->{action} = "add";
543 $form->{callback} = $form->escape($form->{callback},1);
545 $form->{customer} = $form->{name};
546 $form->{customer_id} = $form->{id};
547 $form->{vc} = 'customer';
549 $form->{type} = 'sales_order';
553 map { $argv .= "$_=$form->{$_}&" } keys %$form;
555 exec ("perl", "oe.pl", $argv);
562 $form->isblank("name", $locale->text("Name missing!"));
563 CT->save_vendor(\%myconfig, \%$form);
565 delete $form->{script};
567 $form->{action} = "add";
568 $form->{callback} = $form->escape($form->{callback},1);
570 $form->{vendor} = $form->{name};
571 $form->{vendor_id} = $form->{id};
572 $form->{vc} = 'vendor';
574 $form->{type} = 'purchase_order';
578 map { $argv .= "$_=$form->{$_}&" } keys %$form;
580 exec ("perl", "oe.pl", $argv);
585 sub save { &{ "save_$form->{db}" } };
589 $form->isblank("name", $locale->text("Name missing!"));
590 CT->save_customer(\%myconfig, \%$form);
591 $form->redirect($locale->text('Customer saved!'));
598 $form->isblank("name", $locale->text("Name missing!"));
599 CT->save_vendor(\%myconfig, \%$form);
600 $form->redirect($locale->text('Vendor saved!'));
605 sub delete { &{ "delete_$form->{db}" } };
607 sub delete_customer {
609 $rc = CT->delete_customer(\%myconfig, \%$form);
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!'));
620 $rc = CT->delete_vendor(\%myconfig, \%$form);
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!'));
629 sub continue { &{ $form->{nextsub} } };