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