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