summaryrefslogtreecommitdiff
path: root/bin/mozilla/pos.pl
blob: 53627496d754da3861fb50766699214c63998971 (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # http://www.ledgersmb.org/
  4. #
  5. # Copyright (C) 2006
  6. # This work contains copyrighted information from a number of sources all used
  7. # with permission.
  8. #
  9. # This file contains source code included with or based on SQL-Ledger which
  10. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  11. # under the GNU General Public License version 2 or, at your option, any later
  12. # version. For a full list including contact information of contributors,
  13. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  14. #
  15. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  16. # Copyright (c) 2003
  17. #
  18. # Author: DWS Systems Inc.
  19. # Web: http://www.sql-ledger.org
  20. #
  21. # Contributors: Steve Doerr <sdoerr907@everestkc.net>
  22. #
  23. #
  24. # This program is free software; you can redistribute it and/or modify
  25. # it under the terms of the GNU General Public License as published by
  26. # the Free Software Foundation; either version 2 of the License, or
  27. # (at your option) any later version.
  28. #
  29. # This program is distributed in the hope that it will be useful,
  30. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. # GNU General Public License for more details.
  33. # You should have received a copy of the GNU General Public License
  34. # along with this program; if not, write to the Free Software
  35. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  36. #=====================================================================
  37. #
  38. # POS
  39. #
  40. #=====================================================================
  41. 1;
  42. # end
  43. sub add {
  44. $form->{title} = $locale->text('Add POS Invoice');
  45. $form->{callback} = "$form->{script}?action=$form->{nextsub}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  46. &invoice_links;
  47. $form->{type} = "pos_invoice";
  48. $form->{format} = "txt";
  49. $form->{media} = ($myconfig{printer}) ? $myconfig{printer} : "screen";
  50. $form->{rowcount} = 0;
  51. $form->{readonly} = ($myconfig{acs} =~ /POS--Sale/) ? 1 : 0;
  52. $ENV{REMOTE_ADDR} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/;
  53. $form->{till} = $4;
  54. $form->{partsgroup} = "";
  55. for (@{ $form->{all_partsgroup} }) { $form->{partsgroup} .= "$_->{partsgroup}--$_->{translation}\n"; }
  56. &display_form;
  57. }
  58. sub openinvoices {
  59. $ENV{REMOTE_ADDR} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/;
  60. $form->{till} = $4;
  61. $form->{sort} = 'transdate';
  62. for (qw(open l_invnumber l_transdate l_name l_amount l_curr l_till l_subtotal)) { $form->{$_} = 'Y'; }
  63. if ($myconfig{role} ne 'user') {
  64. $form->{l_employee} = 'Y';
  65. }
  66. $form->{title} = $locale->text('Open');
  67. transactions;
  68. }
  69. sub edit {
  70. $form->{title} = $locale->text('Edit POS Invoice');
  71. $form->{callback} = "$form->{script}?action=$form->{nextsub}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  72. &invoice_links;
  73. &prepare_invoice;
  74. $form->{type} = "pos_invoice";
  75. $form->{format} = "txt";
  76. $form->{media} = ($myconfig{printer}) ? $myconfig{printer} : "screen";
  77. $form->{readonly} = ($myconfig{acs} =~ /POS--Sale/) ? 1 : 0;
  78. $form->{partsgroup} = "";
  79. for (@{ $form->{all_partsgroup} }) { $form->{partsgroup} .= "$_->{partsgroup}--$_->{translation}\n"; }
  80. &display_form;
  81. }
  82. sub form_header {
  83. # set option selected
  84. for (qw(AR currency)) {
  85. $form->{"select$_"} =~ s/ selected//;
  86. $form->{"select$_"} =~ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
  87. }
  88. for (qw(customer department employee)) {
  89. $form->{"select$_"} = $form->unescape($form->{"select$_"});
  90. $form->{"select$_"} =~ s/ selected//;
  91. $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
  92. }
  93. $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
  94. $exchangerate = qq|<tr>|;
  95. $exchangerate .= qq|
  96. <th align=right nowrap>|.$locale->text('Currency').qq|</th>
  97. <td><select name=currency>$form->{selectcurrency}</select></td> | if $form->{defaultcurrency};
  98. $exchangerate .= qq|
  99. <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
  100. <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
  101. |;
  102. if ($form->{defaultcurrency} && $form->{currency} ne $form->{defaultcurrency}) {
  103. if ($form->{forex}) {
  104. $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
  105. } else {
  106. $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
  107. }
  108. }
  109. $exchangerate .= qq|
  110. <input type=hidden name=forex value=$form->{forex}>
  111. </tr>
  112. |;
  113. if ($form->{selectcustomer}) {
  114. $customer = qq|<select name=customer>$form->{selectcustomer}</select>
  115. <input type=hidden name="selectcustomer" value="|.
  116. $form->escape($form->{selectcustomer},1).qq|">|;
  117. } else {
  118. $customer = qq|<input name=customer value="$form->{customer}" size=35>|;
  119. }
  120. $department = qq|
  121. <tr>
  122. <th align="right" nowrap>|.$locale->text('Department').qq|</th>
  123. <td colspan=3><select name=department>$form->{selectdepartment}</select>
  124. <input type=hidden name=selectdepartment value="|.
  125. $form->escape($form->{selectdepartment},1).qq|">
  126. </td>
  127. </tr>
  128. | if $form->{selectdepartment};
  129. $employee = qq|
  130. <tr>
  131. <th align=right nowrap>|.$locale->text('Salesperson').qq|</th>
  132. <td colspan=3><select name=employee>$form->{selectemployee}</select></td>
  133. <input type=hidden name=selectemployee value="|.
  134. $form->escape($form->{selectemployee},1).qq|">
  135. </tr>
  136. | if $form->{selectemployee};
  137. if ($form->{change} != $form->{oldchange}) {
  138. $form->{creditremaining} -= $form->{oldchange};
  139. }
  140. $n = ($form->{creditremaining} < 0) ? "0" : "1";
  141. if ($form->{business}) {
  142. $business = qq|
  143. <tr>
  144. <th align=right nowrap>|.$locale->text('Business').qq|</th>
  145. <td>$form->{business}</td>
  146. <td width=10></td>
  147. <th align=right nowrap>|.$locale->text('Trade Discount').qq|</th>
  148. <td>|.$form->format_amount(\%myconfig, $form->{tradediscount} * 100).qq| %</td>
  149. </tr>
  150. |;
  151. }
  152. if ($form->{selectlanguage}) {
  153. if ($form->{language_code} ne $form->{oldlanguage_code}) {
  154. # rebuild partsgroup
  155. $form->get_partsgroup(\%myconfig, { language_code => $form->{language_code}, searchitems => 'nolabor'});
  156. $form->{partsgroup} = "";
  157. for (@{ $form->{all_partsgroup} }) { $form->{partsgroup} .= "$_->{partsgroup}--$_->{translation}\n"; }
  158. $form->{oldlanguage_code} = $form->{language_code};
  159. }
  160. $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
  161. $form->{"selectlanguage"} =~ s/ selected//;
  162. $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
  163. $lang = qq|
  164. <tr>
  165. <th align=right>|.$locale->text('Language').qq|</th>
  166. <td colspan=3><select name=language_code>$form->{selectlanguage}</select></td>
  167. </tr>
  168. <input type=hidden name=oldlanguage_code value=$form->{oldlanguage_code}>
  169. <input type=hidden name=selectlanguage value="|.
  170. $form->escape($form->{selectlanguage},1).qq|">|;
  171. }
  172. $i = $form->{rowcount} + 1;
  173. $focus = "partnumber_$i";
  174. $form->header;
  175. print qq|
  176. <body onLoad="document.forms[0].${focus}.focus()" />
  177. <form method=post action="$form->{script}">
  178. |;
  179. $form->hide_form(qw(id till type format printed title discount creditlimit creditremaining tradediscount business closedto locked oldtransdate customer_id oldcustomer));
  180. print qq|
  181. <input type=hidden name=vc value="customer">
  182. <table width=100%>
  183. <tr class=listtop>
  184. <th class=listtop>$form->{title}</font></th>
  185. </tr>
  186. <tr height="5"></tr>
  187. <tr>
  188. <td>
  189. <table width=100%>
  190. <tr valign=top>
  191. <td>
  192. <table>
  193. <tr>
  194. <th align=right nowrap>|.$locale->text('Customer').qq|</th>
  195. <td colspan=3>$customer</td>
  196. </tr>
  197. <tr>
  198. <td></td>
  199. <td colspan=3>
  200. <table>
  201. <tr>
  202. <th align=right nowrap>|.$locale->text('Credit Limit').qq|</th>
  203. <td>$form->{creditlimit}</td>
  204. <td width=10></td>
  205. <th align=right nowrap>|.$locale->text('Remaining').qq|</th>
  206. <td class="plus$n">|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</font></td>
  207. </tr>
  208. $business
  209. </table>
  210. </td>
  211. </tr>
  212. <tr>
  213. <th align=right nowrap>|.$locale->text('Record in').qq|</th>
  214. <td colspan=3><select name=AR>$form->{selectAR}</select></td>
  215. <input type=hidden name=selectAR value="$form->{selectAR}">
  216. </tr>
  217. $department
  218. </table>
  219. </td>
  220. <td>
  221. <table>
  222. $employee
  223. $exchangerate
  224. $lang
  225. </table>
  226. </td>
  227. </tr>
  228. </table>
  229. </td>
  230. </tr>
  231. <tr>
  232. <td>
  233. </td>
  234. </tr>
  235. |;
  236. $form->hide_form(qw(taxaccounts duedate invnumber transdate selectcurrency defaultcurrency));
  237. for (split / /, $form->{taxaccounts}) {
  238. $form->hide_form("${_}_rate", "${_}_description", "${_}_taxnumber");
  239. }
  240. }
  241. sub form_footer {
  242. $form->{invtotal} = $form->{invsubtotal};
  243. $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
  244. $taxincluded = "";
  245. if ($form->{taxaccounts}) {
  246. $taxincluded = qq|
  247. <tr height="5"></tr>
  248. <tr>
  249. <td align=right>
  250. <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td><th align=left>|.$locale->text('Tax Included').qq|</th>
  251. </tr>
  252. |;
  253. }
  254. if (!$form->{taxincluded}) {
  255. for (split / /, $form->{taxaccounts}) {
  256. if ($form->{"${_}_base"}) {
  257. $form->{"${_}_total"} = $form->round_amount($form->{"${_}_base"} * $form->{"${_}_rate"}, 2);
  258. $form->{invtotal} += $form->{"${_}_total"};
  259. $form->{"${_}_total"} = $form->format_amount(\%myconfig, $form->{"${_}_total"}, 2, 0);
  260. $tax .= qq|
  261. <tr>
  262. <th align=right>$form->{"${_}_description"}</th>
  263. <td align=right>$form->{"${_}_total"}</td>
  264. </tr>
  265. |;
  266. }
  267. }
  268. $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
  269. $subtotal = qq|
  270. <tr>
  271. <th align=right>|.$locale->text('Subtotal').qq|</th>
  272. <td align=right>$form->{invsubtotal}</td>
  273. </tr>
  274. |;
  275. }
  276. @column_index = qw(paid source memo AR_paid);
  277. $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
  278. $column_data{source} = "<th>".$locale->text('Source')."</th>";
  279. $column_data{memo} = "<th>".$locale->text('Memo')."</th>";
  280. $column_data{AR_paid} = "<th>&nbsp;</th>";
  281. print qq|
  282. <tr>
  283. <td>
  284. <table width=100%>
  285. <tr valign=top>
  286. <td>
  287. <table>
  288. <tr>
  289. |;
  290. for (@column_index) { print "$column_data{$_}\n"; }
  291. print qq|
  292. </tr>
  293. |;
  294. $totalpaid = 0;
  295. $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
  296. for $i (1 .. $form->{paidaccounts}) {
  297. $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
  298. $form->{"selectAR_paid_$i"} =~ s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
  299. # format amounts
  300. $totalpaid += $form->{"paid_$i"};
  301. $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
  302. $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
  303. $column_data{paid} = qq|<td><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
  304. $column_data{source} = qq|<td><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|;
  305. $column_data{memo} = qq|<td><input name="memo_$i" size=10 value="$form->{"memo_$i"}"></td>|;
  306. $column_data{AR_paid} = qq|<td><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
  307. print qq|
  308. <tr>
  309. |;
  310. for (@column_index) { print "$column_data{$_}\n"; }
  311. print qq|
  312. </tr>
  313. |;
  314. $form->hide_form("cleared_$i", "exchangerate_$i", "forex_$i");
  315. }
  316. $form->{change} = 0;
  317. if ($totalpaid > $form->{invtotal}) {
  318. $form->{change} = $totalpaid - $form->{invtotal};
  319. }
  320. $form->{oldchange} = $form->{change};
  321. $form->{change} = $form->format_amount(\%myconfig, $form->{change}, 2, 0);
  322. $form->{totalpaid} = $form->format_amount(\%myconfig, $totalpaid, 2);
  323. $form->{oldinvtotal} = $form->{invtotal};
  324. $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
  325. print qq|
  326. <tr>
  327. <th align=right>|.$locale->text('Change').qq|</th>
  328. <th>$form->{change}</th>
  329. </tr>
  330. </table>
  331. </td>
  332. <td align=right>
  333. <table>
  334. $subtotal
  335. $tax
  336. <tr>
  337. <th align=right>|.$locale->text('Total').qq|</th>
  338. <td align=right>$form->{invtotal}</td>
  339. </tr>
  340. $taxincluded
  341. </table>
  342. </td>
  343. </tr>
  344. </table>
  345. </td>
  346. </tr>
  347. <input type=hidden name=oldtotalpaid value=$totalpaid>
  348. <input type=hidden name=datepaid value=$form->{transdate}>
  349. <tr>
  350. <td>
  351. |;
  352. $form->hide_form(qw(paidaccounts selectAR_paid oldinvtotal change oldchange invtotal));
  353. &print_options;
  354. print qq|
  355. </td>
  356. </tr>
  357. <tr>
  358. <td><hr size=3 noshade></td>
  359. </tr>
  360. </table>
  361. |;
  362. $transdate = $form->datetonum(\%myconfig, $form->{transdate});
  363. $closedto = $form->datetonum(\%myconfig, $form->{closedto});
  364. # type=submit $locale->text('Update')
  365. # type=submit $locale->text('Print')
  366. # type=submit $locale->text('Post')
  367. # type=submit $locale->text('Print and Post')
  368. # type=submit $locale->text('Delete')
  369. if (! $form->{readonly}) {
  370. %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  371. 'Print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
  372. 'Post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
  373. 'Print and Post' => { ndx => 4, key => 'R', value => $locale->text('Print and Post') },
  374. 'Delete' => { ndx => 5, key => 'D', value => $locale->text('Delete') },
  375. );
  376. if ($transdate > $closedto) {
  377. if (! $form->{id}) {
  378. delete $button{'Delete'};
  379. }
  380. delete $button{'Print and Post'} unless $latex;
  381. } else {
  382. for ('Print', 'Post', 'Print and Post', 'Delete') { delete $button{$_} }
  383. }
  384. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  385. print qq|<p>
  386. <input type=text size=1 value="B" accesskey="B" title="[Alt-B]">\n|;
  387. if ($form->{partsgroup}) {
  388. $form->{partsgroup} =~ s/\r//g;
  389. $form->{partsgroup} = $form->quote($form->{partsgroup});
  390. $spc = ($form->{path} =~ /lynx/) ? "." : " ";
  391. print qq|
  392. <input type=hidden name=nextsub value=lookup_partsgroup>
  393. <input type=hidden name=partsgroup value="$form->{partsgroup}">|;
  394. foreach $item (split /\n/, $form->{partsgroup}) {
  395. ($partsgroup, $translation) = split /--/, $item;
  396. $item = ($translation) ? $translation : $partsgroup;
  397. print qq| <input class=submit type=submit name=action value="$spc$item">\n| if $item;
  398. }
  399. }
  400. }
  401. if ($form->{menubar}) {
  402. require "$form->{path}/menu.pl";
  403. &menubar;
  404. }
  405. $form->hide_form(qw(rowcount callback path login sessionid));
  406. print qq|
  407. </form>
  408. </body>
  409. </html>
  410. |;
  411. }
  412. sub post {
  413. $form->isblank("customer", $locale->text('Customer missing!'));
  414. # if oldcustomer ne customer redo form
  415. $customer = $form->{customer};
  416. $customer =~ s/--.*//g;
  417. $customer .= "--$form->{customer_id}";
  418. if ($customer ne $form->{oldcustomer}) {
  419. &update;
  420. exit;
  421. }
  422. &validate_items;
  423. $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
  424. $paid = 0;
  425. for (1 .. $form->{paidaccounts}) { $paid += $form->parse_amount(\%myconfig, $form->{"paid_$_"}); }
  426. delete $form->{datepaid} unless $paid;
  427. $total = $form->parse_amount(\%myconfig, $form->{invtotal});
  428. # deduct change from first payment
  429. $form->{"paid_1"} = $form->format_amount(\%myconfig, $form->parse_amount(\%myconfig, $form->{"paid_1"}) - ($paid - $total), 2) if $paid > $total;
  430. ($form->{AR}) = split /--/, $form->{AR};
  431. if (IS->post_invoice(\%myconfig, \%$form)) {
  432. $form->redirect($locale->text('Posted!'));
  433. } else {
  434. $form->error($locale->text('Cannot post transaction!'));
  435. }
  436. }
  437. sub display_row {
  438. my $numrows = shift;
  439. @column_index = qw(partnumber description partsgroup qty unit sellprice discount linetotal);
  440. $form->{invsubtotal} = 0;
  441. for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0; }
  442. $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
  443. $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|;
  444. $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
  445. $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
  446. $column_data{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Price').qq|</th>|;
  447. $column_data{linetotal} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;
  448. $column_data{discount} = qq|<th class=listheading nowrap>%</th>|;
  449. print qq|
  450. <tr>
  451. <td>
  452. <table width=100%>
  453. <tr class=listheading>|;
  454. for (@column_index) { print "\n$column_data{$_}"; };
  455. print qq|
  456. </tr>
  457. |;
  458. $exchangerate = $form->parse_amount(\%myconfig, $form->{exchangerate});
  459. $exchangerate = ($exchangerate) ? $exchangerate : 1;
  460. for $i (1 .. $numrows) {
  461. # undo formatting
  462. for (qw(qty discount sellprice)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}); }
  463. ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
  464. $dec = length $dec;
  465. $decimalplaces = ($dec > 2) ? $dec : 2;
  466. if (($form->{"qty_$i"} != $form->{"oldqty_$i"}) || ($form->{currency} ne $form->{oldcurrency})) {
  467. # check for a pricematrix
  468. @a = split / /, $form->{"pricematrix_$i"};
  469. if (scalar @a) {
  470. foreach $item (@a) {
  471. ($q, $p) = split /:/, $item;
  472. if (($p * 1) && ($form->{"qty_$i"} >= ($q * 1))) {
  473. ($dec) = ($p =~ /\.(\d+)/);
  474. $dec = length $dec;
  475. $decimalplaces = ($dec > 2) ? $dec : 2;
  476. $form->{"sellprice_$i"} = $form->round_amount($p / $exchangerate, $decimalplaces);
  477. }
  478. }
  479. }
  480. }
  481. if ($i < $numrows) {
  482. $column_data{discount} = qq|<td align=right><input name="discount_$i" size=3 value=|.$form->format_amount(\%myconfig, $form->{"discount_$i"}).qq|></td>|;
  483. } else {
  484. $column_data{discount} = qq|<td></td>|;
  485. }
  486. $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces);
  487. $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
  488. $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
  489. for (qw(partnumber sku description partsgroup unit)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}); }
  490. $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=20 value="$form->{"partnumber_$i"}" accesskey="$i" title="[Alt-$i]"></td>|;
  491. if (($rows = $form->numtextrows($form->{"description_$i"}, 40, 6)) > 1) {
  492. $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=46 wrap=soft>$form->{"description_$i"}</textarea></td>|;
  493. } else {
  494. $column_data{description} = qq|<td><input name="description_$i" size=48 value="$form->{"description_$i"}"></td>|;
  495. }
  496. $column_data{qty} = qq|<td align=right><input name="qty_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|;
  497. $column_data{unit} = qq|<td>$form->{"unit_$i"}</td>|;
  498. $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;
  499. $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|;
  500. print qq|
  501. <tr valign=top>|;
  502. for (@column_index) { print "\n$column_data{$_}"; }
  503. print qq|
  504. </tr>
  505. |;
  506. $form->{"oldqty_$i"} = $form->{"qty_$i"};
  507. for (qw(id listprice lastcost taxaccounts pricematrix oldqty sku partsgroup unit inventory_accno_id income_accno_id expense_accno_id)) { $form->hide_form("${_}_$i") }
  508. for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $linetotal; }
  509. $form->{invsubtotal} += $linetotal;
  510. }
  511. print qq|
  512. </table>
  513. </td>
  514. </tr>
  515. <input type=hidden name=oldcurrency value=$form->{currency}>
  516. |;
  517. }
  518. sub print {
  519. if (!$form->{invnumber}) {
  520. $form->{invnumber} = $form->update_defaults(\%myconfig, "sinumber");
  521. if ($form->{media} eq 'screen') {
  522. &update;
  523. exit;
  524. }
  525. }
  526. $old_form = new Form;
  527. for (keys %$form) { $old_form->{$_} = $form->{$_}; }
  528. for (qw(employee department)) { $form->{$_} =~ s/--.*//g; }
  529. $form->{invdate} = $form->{transdate};
  530. $form->{dateprinted} = scalar localtime;
  531. &print_form($old_form);
  532. }
  533. sub print_form {
  534. my $old_form = shift;
  535. # if oldcustomer ne customer redo form
  536. $customer = $form->{customer};
  537. $customer =~ s/--.*//g;
  538. $customer .= "--$form->{customer_id}";
  539. if ($customer ne $form->{oldcustomer}) {
  540. &update;
  541. exit;
  542. }
  543. &validate_items;
  544. &{ "$form->{vc}_details" };
  545. @a = ();
  546. for (1 .. $form->{rowcount}) { push @a, ("partnumber_$_", "description_$_"); }
  547. for (split / /, $form->{taxaccounts}) { push @a, "${_}_description"; }
  548. $form->format_string(@a);
  549. # format payment dates
  550. for (1 .. $form->{paidaccounts}) { $form->{"datepaid_$_"} = $locale->date(\%myconfig, $form->{"datepaid_$_"}); }
  551. IS->invoice_details(\%myconfig, \%$form);
  552. if ($form->parse_amount(\%myconfig, $form->{total}) <= 0) {
  553. $form->{total} = 0;
  554. } else {
  555. $form->{change} = 0;
  556. }
  557. for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_}; }
  558. $form->{username} = $myconfig{name};
  559. $form->{address} =~ s/\\n/\n/g;
  560. push @a, qw(company address tel fax businessnumber username);
  561. $form->format_string(@a);
  562. $form->{templates} = "$myconfig{templates}";
  563. $form->{IN} = "$form->{type}.$form->{format}";
  564. if ($form->{format} =~ /(postscript|pdf)/) {
  565. $form->{IN} =~ s/$&$/tex/;
  566. }
  567. if ($form->{media} ne 'screen') {
  568. $form->{OUT} = "| $printer{$form->{media}}";
  569. }
  570. $form->{discount} = $form->format_amount(\%myconfig, $form->{discount} * 100);
  571. $form->{rowcount}--;
  572. $form->{pre} = "<body bgcolor=#ffffff>\n<pre>";
  573. delete $form->{stylesheet};
  574. $form->parse_template(\%myconfig, $userspath);
  575. if ($form->{printed} !~ /$form->{formname}/) {
  576. $form->{printed} .= " $form->{formname}";
  577. $form->{printed} =~ s/^ //;
  578. $form->update_status(\%myconfig);
  579. }
  580. $old_form->{printed} = $form->{printed};
  581. # if we got back here restore the previous form
  582. if ($form->{media} ne 'screen') {
  583. # restore and display form
  584. for (keys %$old_form) { $form->{$_} = $old_form->{$_}; }
  585. $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
  586. for $i (1 .. $form->{paidaccounts}) {
  587. for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}); }
  588. }
  589. delete $form->{pre};
  590. if (! $form->{printandpost}) {
  591. $form->{rowcount}--;
  592. &display_form;
  593. }
  594. }
  595. }
  596. sub print_and_post {
  597. $form->error($locale->text('Select a Printer!')) if ($form->{media} eq 'screen');
  598. $form->{printandpost} = 1;
  599. &print;
  600. &post;
  601. }
  602. sub lookup_partsgroup {
  603. $form->{action} =~ s/\r//;
  604. $form->{action} = substr($form->{action}, 1);
  605. if ($form->{language_code}) {
  606. # get english
  607. foreach $item (split /\n/, $form->{partsgroup}) {
  608. if ($item =~ /$form->{action}/) {
  609. ($partsgroup, $translation) = split /--/, $item;
  610. $form->{action} = $partsgroup;
  611. last;
  612. }
  613. }
  614. }
  615. $form->{"partsgroup_$form->{rowcount}"} = $form->{action};
  616. &update;
  617. }
  618. sub print_options {
  619. $form->{PD}{$form->{type}} = "checked";
  620. print qq|
  621. <input type=hidden name=format value=$form->{format}>
  622. <input type=hidden name=formname value=$form->{type}>
  623. <table width=100%>
  624. <tr>
  625. |;
  626. $media = qq|
  627. <td><input class=radio type=radio name=media value="screen"></td>
  628. <td>|.$locale->text('Screen').qq|</td>|;
  629. if (%printer) {
  630. for (keys %printer) {
  631. $media .= qq|
  632. <td><input class=radio type=radio name=media value="$_"></td>
  633. <td nowrap>$_</td>
  634. |;
  635. }
  636. }
  637. $media =~ s/(value="\Q$form->{media}\E")/$1 checked/;
  638. print qq|
  639. $media
  640. <td width=99%>&nbsp;</td>|;
  641. if ($form->{printed} =~ /$form->{type}/) {
  642. print qq|
  643. <th>\||.$locale->text('Printed').qq|\|</th>|;
  644. }
  645. print qq|
  646. </tr>
  647. </table>
  648. |;
  649. }
  650. sub receipts {
  651. $form->{title} = $locale->text('Receipts');
  652. $form->{db} = 'ar';
  653. RP->paymentaccounts(\%myconfig, \%$form);
  654. $paymentaccounts = "";
  655. for (@{ $form->{PR} } ) { $paymentaccounts .= "$_->{accno} "; }
  656. if (@{ $form->{all_years} }) {
  657. # accounting years
  658. $form->{selectaccountingyear} = "<option>\n";
  659. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n|; }
  660. $form->{selectaccountingmonth} = "<option>\n";
  661. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n|; }
  662. $selectfrom = qq|
  663. <tr>
  664. <th align=right>|.$locale->text('Period').qq|</th>
  665. <td colspan=3>
  666. <select name=month>$form->{selectaccountingmonth}</select>
  667. <select name=year>$form->{selectaccountingyear}</select>
  668. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  669. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  670. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  671. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  672. </td>
  673. </tr>
  674. |;
  675. }
  676. $form->header;
  677. print qq|
  678. <body>
  679. <form method=post action=$form->{script}>
  680. <input type=hidden name=title value="$form->{title}">
  681. <input type=hidden name=paymentaccounts value="$paymentaccounts">
  682. <input type=hidden name=till value=1>
  683. <input type=hidden name=subtotal value=1>
  684. <table width=100%>
  685. <tr>
  686. <th class=listtop>$form->{title}</th>
  687. </tr>
  688. <tr height="5"></tr>
  689. <tr>
  690. <td>
  691. <table>
  692. <input type=hidden name=nextsub value=list_payments>
  693. <tr>
  694. <th align=right>|.$locale->text('From').qq|</th>
  695. <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
  696. <th align=right>|.$locale->text('To').qq|</th>
  697. <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
  698. </tr>
  699. $selectfrom
  700. <input type=hidden name=sort value=transdate>
  701. <input type=hidden name=db value=$form->{db}>
  702. </table>
  703. </td>
  704. </tr>
  705. <tr>
  706. <td><hr size=3 noshade></td>
  707. </tr>
  708. </table>
  709. <br>
  710. <input type=hidden name=path value=$form->{path}>
  711. <input type=hidden name=login value=$form->{login}>
  712. <input type=hidden name=sessionid value=$form->{sessionid}>
  713. <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
  714. |;
  715. if ($form->{menubar}) {
  716. require "$form->{path}/menu.pl";
  717. &menubar;
  718. }
  719. print qq|
  720. </form>
  721. </body>
  722. </html>
  723. |;
  724. }