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