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