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