summaryrefslogtreecommitdiff
path: root/bin/io.pl
blob: fb65748433bb1dbf870e567cf4c52b41418d0d7b (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) 2002
  17. #
  18. # Author: DWS Systems Inc.
  19. # Web: http://www.sql-ledger.org
  20. #
  21. #
  22. # This program is free software; you can redistribute it and/or modify
  23. # it under the terms of the GNU General Public License as published by
  24. # the Free Software Foundation; either version 2 of the License, or
  25. # (at your option) any later version.
  26. #
  27. # This program is distributed in the hope that it will be useful,
  28. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. # GNU General Public License for more details.
  31. # You should have received a copy of the GNU General Public License
  32. # along with this program; if not, write to the Free Software
  33. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  34. #######################################################################
  35. #
  36. # common routines used in is, ir, oe
  37. #
  38. #######################################################################
  39. use LedgerSMB::Tax;
  40. # any custom scripts for this one
  41. if (-f "bin/custom/io.pl") {
  42. eval { require "bin/custom/io.pl"; };
  43. }
  44. if (-f "bin/custom/$form->{login}_io.pl") {
  45. eval { require "bin/custom/$form->{login}_io.pl"; };
  46. }
  47. 1;
  48. # end of main
  49. # this is for our long dates
  50. # $locale->text('January')
  51. # $locale->text('February')
  52. # $locale->text('March')
  53. # $locale->text('April')
  54. # $locale->text('May ')
  55. # $locale->text('June')
  56. # $locale->text('July')
  57. # $locale->text('August')
  58. # $locale->text('September')
  59. # $locale->text('October')
  60. # $locale->text('November')
  61. # $locale->text('December')
  62. # this is for our short month
  63. # $locale->text('Jan')
  64. # $locale->text('Feb')
  65. # $locale->text('Mar')
  66. # $locale->text('Apr')
  67. # $locale->text('May')
  68. # $locale->text('Jun')
  69. # $locale->text('Jul')
  70. # $locale->text('Aug')
  71. # $locale->text('Sep')
  72. # $locale->text('Oct')
  73. # $locale->text('Nov')
  74. # $locale->text('Dec')
  75. sub display_row {
  76. my $numrows = shift;
  77. @column_index = qw(runningnumber partnumber description qty);
  78. if ($form->{type} eq "sales_order") {
  79. push @column_index, "ship";
  80. $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Ship').qq|</th>|;
  81. }
  82. if ($form->{type} eq "purchase_order") {
  83. push @column_index, "ship";
  84. $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Recd').qq|</th>|;
  85. }
  86. for (qw(projectnumber partsgroup)) {
  87. $form->{"select$_"} = $form->unescape($form->{"select$_"}) if $form->{"select$_"};
  88. }
  89. if ($form->{language_code} ne $form->{oldlanguage_code}) {
  90. # rebuild partsgroup
  91. $l{language_code} = $form->{language_code};
  92. $l{searchitems} = 'nolabor' if $form->{vc} eq 'customer';
  93. $form->get_partsgroup(\%myconfig, \%l);
  94. if (@ { $form->{all_partsgroup} }) {
  95. $form->{selectpartsgroup} = "<option>\n";
  96. foreach $ref (@ { $form->{all_partsgroup} }) {
  97. if ($ref->{translation}) {
  98. $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{translation}\n|;
  99. } else {
  100. $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|;
  101. }
  102. }
  103. }
  104. $form->{oldlanguage_code} = $form->{language_code};
  105. }
  106. push @column_index, qw(unit onhand sellprice discount linetotal);
  107. my $colspan = $#column_index + 1;
  108. $form->{invsubtotal} = 0;
  109. for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
  110. $column_data{runningnumber} = qq|<th class=listheading nowrap>|.$locale->text('Item').qq|</th>|;
  111. $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
  112. $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|;
  113. $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
  114. $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
  115. $column_data{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Price').qq|</th>|;
  116. $column_data{discount} = qq|<th class=listheading>%</th>|;
  117. $column_data{linetotal} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;
  118. $column_data{bin} = qq|<th class=listheading nowrap>|.$locale->text('Bin').qq|</th>|;
  119. $column_data{onhand} = qq|<th class=listheading nowrap>|.$locale->text('OH').qq|</th>|;
  120. print qq|
  121. <tr>
  122. <td>
  123. <table width=100%>
  124. <tr class=listheading>|;
  125. for (@column_index) { print "\n$column_data{$_}" }
  126. print qq|
  127. </tr>
  128. |;
  129. $deliverydate = $locale->text('Delivery Date');
  130. $serialnumber = $locale->text('Serial No.');
  131. $projectnumber = $locale->text('Project');
  132. $group = $locale->text('Group');
  133. $sku = $locale->text('SKU');
  134. $delvar = 'deliverydate';
  135. if ($form->{type} =~ /_(order|quotation)$/) {
  136. $reqdate = $locale->text('Required by');
  137. $delvar = 'reqdate';
  138. }
  139. $exchangerate = $form->parse_amount(\%myconfig, $form->{exchangerate});
  140. $exchangerate = ($exchangerate) ? $exchangerate : 1;
  141. $spc = substr($myconfig{numberformat},-3,1);
  142. for $i (1 .. $numrows) {
  143. if ($spc eq '.') {
  144. ($null, $dec) = split /\./, $form->{"sellprice_$i"};
  145. } else {
  146. ($null, $dec) = split /,/, $form->{"sellprice_$i"};
  147. }
  148. $dec = length $dec;
  149. $decimalplaces = ($dec > 2) ? $dec : 2;
  150. # undo formatting
  151. for (qw(qty oldqty ship discount sellprice)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  152. if ($form->{"qty_$i"} != $form->{"oldqty_$i"}) {
  153. # check pricematrix
  154. @a = split / /, $form->{"pricematrix_$i"};
  155. if (scalar @a > 2) {
  156. foreach $item (@a) {
  157. ($q, $p) = split /:/, $item;
  158. if (($p * 1) && ($form->{"qty_$i"} >= ($q * 1))) {
  159. ($dec) = ($p =~ /\.(\d+)/);
  160. $dec = length $dec;
  161. $decimalplaces = ($dec > 2) ? $dec : 2;
  162. $form->{"sellprice_$i"} = $form->round_amount($p / $exchangerate, $decimalplaces);
  163. }
  164. }
  165. }
  166. }
  167. $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces);
  168. $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
  169. $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
  170. if (($rows = $form->numtextrows($form->{"description_$i"}, 46, 6)) > 1) {
  171. $form->{"description_$i"} = $form->quote($form->{"description_$i"});
  172. $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=46 wrap=soft>$form->{"description_$i"}</textarea></td>|;
  173. } else {
  174. $form->{"description_$i"} = $form->quote($form->{"description_$i"});
  175. $column_data{description} = qq|<td><input name="description_$i" size=48 value="$form->{"description_$i"}"></td>|;
  176. }
  177. for (qw(partnumber sku unit)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
  178. $skunumber = qq|
  179. <p><b>$sku</b> $form->{"sku_$i"}| if ($form->{vc} eq 'vendor' && $form->{"sku_$i"});
  180. if ($form->{selectpartsgroup}) {
  181. if ($i < $numrows) {
  182. $partsgroup = qq|
  183. <b>$group</b>
  184. <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">|;
  185. ($form->{"partsgroup_$i"}) = split /--/, $form->{"partsgroup_$i"};
  186. $partsgroup .= $form->{"partsgroup_$i"};
  187. $partsgroup = "" unless $form->{"partsgroup_$i"};
  188. }
  189. }
  190. $delivery = qq|
  191. <td colspan=2 nowrap>
  192. <b>${$delvar}</b>
  193. <input name="${delvar}_$i" size=11 title="$myconfig{dateformat}" value="$form->{"${delvar}_$i"}"></td>
  194. |;
  195. $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=3 value=$i></td>|;
  196. $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}" accesskey="$i" title="[Alt-$i]">$skunumber</td>|;
  197. $column_data{qty} = qq|<td align=right><input name="qty_$i" title="$form->{"onhand_$i"}" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|;
  198. $column_data{ship} = qq|<td align=right><input name="ship_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"ship_$i"}).qq|></td>|;
  199. $column_data{unit} = qq|<td><input name="unit_$i" size=5 value="$form->{"unit_$i"}"></td>|;
  200. $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;
  201. $column_data{discount} = qq|<td align=right><input name="discount_$i" size=3 value=|.$form->format_amount(\%myconfig, $form->{"discount_$i"}).qq|></td>|;
  202. $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|;
  203. $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
  204. $column_data{onhand} = qq|<td>$form->{"onhand_$i"}</td>|;
  205. print qq|
  206. <tr valign=top>|;
  207. for (@column_index) {
  208. print "\n$column_data{$_}";
  209. }
  210. print qq|
  211. </tr>
  212. <input type=hidden name="oldqty_$i" value="$form->{"qty_$i"}">
  213. |;
  214. for (qw(orderitems_id id bin weight listprice lastcost taxaccounts pricematrix sku onhand assembly inventory_accno_id income_accno_id expense_accno_id)) {
  215. $form->hide_form("${_}_$i");
  216. }
  217. $form->{selectprojectnumber} =~ s/ selected//;
  218. $form->{selectprojectnumber} =~ s/(<option value="\Q$form->{"projectnumber_$i"}\E")/$1 selected/;
  219. $project = qq|
  220. <b>$projectnumber</b>
  221. <select name="projectnumber_$i">$form->{selectprojectnumber}</select>
  222. | if $form->{selectprojectnumber};
  223. if (($rows = $form->numtextrows($form->{"notes_$i"}, 46, 6)) > 1) {
  224. $form->{"notes_$i"} = $form->quote($form->{"notes_$i"});
  225. $notes = qq|<td><textarea name="notes_$i" rows=$rows cols=46 wrap=soft>$form->{"notes_$i"}</textarea></td>|;
  226. } else {
  227. $form->{"notes_$i"} = $form->quote($form->{"notes_$i"});
  228. $notes = qq|<td><input name="notes_$i" size=48 value="$form->{"notes_$i"}"></td>|;
  229. }
  230. $serial = qq|
  231. <td colspan=6 nowrap><b>$serialnumber</b> <input name="serialnumber_$i" value="$form->{"serialnumber_$i"}"></td>| if $form->{type} !~ /_quotation/;
  232. if ($i == $numrows) {
  233. $partsgroup = "";
  234. if ($form->{selectpartsgroup}) {
  235. $partsgroup = qq|
  236. <b>$group</b>
  237. <select name="partsgroup_$i">$form->{selectpartsgroup}</select>
  238. |;
  239. }
  240. $serial = "";
  241. $project = "";
  242. $delivery = "";
  243. $notes = "";
  244. }
  245. # print second and third row
  246. print qq|
  247. <tr valign=top>
  248. $delivery
  249. $notes
  250. $serial
  251. </tr>
  252. <tr valign=top>
  253. <td colspan=$colspan>
  254. $project
  255. $partsgroup
  256. </td>
  257. </tr>
  258. <tr>
  259. <td colspan=$colspan><hr size=1 noshade></td>
  260. </tr>
  261. |;
  262. $skunumber = "";
  263. for (split / /, $form->{"taxaccounts_$i"}) {
  264. $form->{"${_}_base"} += $linetotal;
  265. }
  266. $form->{invsubtotal} += $linetotal;
  267. }
  268. print qq|
  269. </table>
  270. </td>
  271. </tr>
  272. |;
  273. $form->hide_form(qw(audittrail));
  274. print qq|
  275. <input type=hidden name=oldcurrency value=$form->{currency}>
  276. <input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|">
  277. <input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">
  278. |;
  279. }
  280. sub select_item {
  281. if ($form->{vc} eq "vendor") {
  282. @column_index = qw(ndx partnumber sku description partsgroup onhand sellprice);
  283. } else {
  284. @column_index = qw(ndx partnumber description partsgroup onhand sellprice);
  285. }
  286. $column_data{ndx} = qq|<th>&nbsp;</th>|;
  287. $column_data{partnumber} = qq|<th class=listheading>|.$locale->text('Number').qq|</th>|;
  288. $column_data{sku} = qq|<th class=listheading>|.$locale->text('SKU').qq|</th>|;
  289. $column_data{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
  290. $column_data{partsgroup} = qq|<th class=listheading>|.$locale->text('Group').qq|</th>|;
  291. $column_data{sellprice} = qq|<th class=listheading>|.$locale->text('Price').qq|</th>|;
  292. $column_data{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
  293. $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
  294. # list items with radio button on a form
  295. $form->header;
  296. $title = $locale->text('Select items');
  297. print qq|
  298. <body>
  299. <form method=post action="$form->{script}">
  300. <table width=100%>
  301. <tr>
  302. <th class=listtop>$title</th>
  303. </tr>
  304. <tr height="5"></tr>
  305. <tr>
  306. <td>$option</td>
  307. </tr>
  308. <tr>
  309. <td>
  310. <table width=100%>
  311. <tr class=listheading>|;
  312. for (@column_index) { print "\n$column_data{$_}" }
  313. print qq|
  314. </tr>
  315. |;
  316. my $i = 0;
  317. foreach $ref (@{ $form->{item_list} }) {
  318. $i++;
  319. for (qw(sku partnumber description unit notes partsgroup)) {
  320. $ref->{$_} = $form->quote($ref->{$_});
  321. }
  322. $column_data{ndx} = qq|<td><input name="ndx_$i" class=checkbox type=checkbox value=$i></td>|;
  323. for (qw(partnumber sku description partsgroup)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
  324. $column_data{sellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{sellprice} / $exchangerate, 2, "&nbsp;").qq|</td>|;
  325. $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;").qq|</td>|;
  326. $j++; $j %= 2;
  327. print qq|
  328. <tr class=listrow$j>|;
  329. for (@column_index) {
  330. print "\n$column_data{$_}";
  331. }
  332. print qq|
  333. </tr>
  334. |;
  335. for (qw(partnumber sku description partsgroup partsgroup_id bin weight sellprice listprice lastcost onhand unit assembly taxaccounts inventory_accno_id income_accno_id expense_accno_id pricematrix id notes)) {
  336. print qq|<input type=hidden name="new_${_}_$i" value="$ref->{$_}">\n|;
  337. }
  338. }
  339. print qq|
  340. </table>
  341. </td>
  342. </tr>
  343. <tr>
  344. <td><hr size=3 noshade></td>
  345. </tr>
  346. </table>
  347. <input name=lastndx type=hidden value=$i>
  348. |;
  349. # delete variables
  350. for (qw(nextsub item_list)) { delete $form->{$_} }
  351. $form->{action} = "item_selected";
  352. $form->hide_form;
  353. print qq|
  354. <input type=hidden name=nextsub value=item_selected>
  355. <br>
  356. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  357. </form>
  358. </body>
  359. </html>
  360. |;
  361. }
  362. sub item_selected {
  363. $i = $form->{rowcount} - 1;
  364. $i = $form->{assembly_rows} - 1 if ($form->{item} eq 'assembly');
  365. $qty = ($form->{"qty_$form->{rowcount}"}) ? $form->{"qty_$form->{rowcount}"} : 1;
  366. for $j (1 .. $form->{lastndx}) {
  367. if ($form->{"ndx_$j"}) {
  368. $i++;
  369. $form->{"qty_$i"} = $qty;
  370. $form->{"discount_$i"} = $form->{discount} * 100;
  371. $form->{"reqdate_$i"} = $form->{reqdate} if $form->{type} !~ /_quotation/;
  372. for (qw(id partnumber sku description sellprice listprice lastcost bin unit weight assembly taxaccounts pricematrix onhand notes inventory_accno_id income_accno_id expense_accno_id)) {
  373. $form->{"${_}_$i"} = $form->{"new_${_}_$j"};
  374. }
  375. $form->{"partsgroup_$i"} = qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|;
  376. ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
  377. $dec = length $dec;
  378. $decimalplaces1 = ($dec > 2) ? $dec : 2;
  379. ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/);
  380. $dec = length $dec;
  381. $decimalplaces2 = ($dec > 2) ? $dec : 2;
  382. # if there is an exchange rate adjust sellprice
  383. if (($form->{exchangerate} * 1)) {
  384. for (qw(sellprice listprice lastcost)) { $form->{"${_}_$i"} /= $form->{exchangerate} }
  385. # don't format list and cost
  386. $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"}, $decimalplaces1);
  387. }
  388. # this is for the assembly
  389. if ($form->{item} eq 'assembly') {
  390. $form->{"adj_$i"} = 1;
  391. for (qw(sellprice listprice weight)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  392. $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
  393. $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
  394. }
  395. $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
  396. for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
  397. if (!$form->{taxincluded}) {
  398. my @taxlist= Tax::init_taxes($form, $form->{"taxaccounts_$i"});
  399. $amount += Tax::calculate_taxes(\@taxlist, $form, $amount, 0);
  400. }
  401. $form->{creditremaining} -= $amount;
  402. $form->{"runningnumber_$i"} = $i;
  403. # format amounts
  404. if ($form->{item} ne 'assembly') {
  405. for (qw(sellprice listprice)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces1) }
  406. $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces2);
  407. }
  408. $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"});
  409. }
  410. }
  411. $form->{rowcount} = $i;
  412. $form->{assembly_rows} = $i if ($form->{item} eq 'assembly');
  413. $form->{focus} = "description_$i";
  414. # delete all the new_ variables
  415. for $i (1 .. $form->{lastndx}) {
  416. for (qw(id partnumber sku description sellprice listprice lastcost bin unit weight assembly taxaccounts pricematrix onhand notes inventory_accno_id income_accno_id expense_accno_id)) {
  417. delete $form->{"new_${_}_$i"};
  418. }
  419. }
  420. for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
  421. &display_form;
  422. }
  423. sub new_item {
  424. if ($form->{language_code} && $form->{"description_$form->{rowcount}"}) {
  425. $form->error($locale->text('Translation not on file!'));
  426. }
  427. # change callback
  428. $form->{old_callback} = $form->escape($form->{callback},1);
  429. $form->{callback} = $form->escape("$form->{script}?action=display_form",1);
  430. # delete action
  431. delete $form->{action};
  432. # save all other form variables in a previousform variable
  433. if (!$form->{previousform}) {
  434. foreach $key (keys %$form) {
  435. # escape ampersands
  436. $form->{$key} =~ s/&/%26/g;
  437. $form->{previousform} .= qq|$key=$form->{$key}&|;
  438. }
  439. chop $form->{previousform};
  440. $form->{previousform} = $form->escape($form->{previousform}, 1);
  441. }
  442. $i = $form->{rowcount};
  443. for (qw(partnumber description)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
  444. $form->header;
  445. print qq|
  446. <body>
  447. <h4 class=error>|.$locale->text('Item not on file!').qq|</h4>|;
  448. if ($myconfig{acs} !~ /(Goods \& Services--Add Part|Goods \& Services--Add Service)/) {
  449. print qq|
  450. <h4>|.$locale->text('What type of item is this?').qq|</h4>
  451. <form method=post action=ic.pl>
  452. <p>
  453. <input class=radio type=radio name=item value=part checked>&nbsp;|.$locale->text('Part')
  454. .qq|<br>
  455. <input class=radio type=radio name=item value=service>&nbsp;|.$locale->text('Service')
  456. .qq|
  457. <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
  458. <input type=hidden name=description value="$form->{"description_$i"}">
  459. <input type=hidden name=nextsub value=add>
  460. <input type=hidden name=action value=add>
  461. |;
  462. $form->hide_form(qw(previousform rowcount path login sessionid));
  463. print qq|
  464. <p>
  465. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  466. </form>
  467. |;
  468. }
  469. print qq|
  470. </body>
  471. </html>
  472. |;
  473. }
  474. sub display_form {
  475. # if we have a display_form
  476. if ($form->{display_form}) {
  477. &{ "$form->{display_form}" };
  478. exit;
  479. }
  480. &form_header;
  481. $numrows = ++$form->{rowcount};
  482. $subroutine = "display_row";
  483. if ($form->{item} eq 'part') {
  484. # create makemodel rows
  485. &makemodel_row(++$form->{makemodel_rows});
  486. &vendor_row(++$form->{vendor_rows});
  487. $numrows = ++$form->{customer_rows};
  488. $subroutine = "customer_row";
  489. }
  490. if ($form->{item} eq 'assembly') {
  491. # create makemodel rows
  492. &makemodel_row(++$form->{makemodel_rows});
  493. $numrows = ++$form->{customer_rows};
  494. $subroutine = "customer_row";
  495. }
  496. if ($form->{item} eq 'service') {
  497. &vendor_row(++$form->{vendor_rows});
  498. $numrows = ++$form->{customer_rows};
  499. $subroutine = "customer_row";
  500. }
  501. if ($form->{item} eq 'labor') {
  502. $numrows = 0;
  503. }
  504. # create rows
  505. &{ $subroutine }($numrows) if $numrows;
  506. &form_footer;
  507. }
  508. sub check_form {
  509. my @a = ();
  510. my $count = 0;
  511. my $i;
  512. my $j;
  513. my @flds = qw(id runningnumber partnumber description partsgroup qty ship unit sellprice discount oldqty orderitems_id bin weight listprice lastcost taxaccounts pricematrix sku onhand assembly inventory_accno_id income_accno_id expense_accno_id notes reqdate deliverydate serialnumber projectnumber);
  514. # remove any makes or model rows
  515. if ($form->{item} eq 'part') {
  516. for (qw(listprice sellprice lastcost avgcost weight rop markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  517. &calc_markup;
  518. @flds = qw(make model);
  519. $count = 0;
  520. @a = ();
  521. for $i (1 .. $form->{makemodel_rows}) {
  522. if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
  523. push @a, {};
  524. $j = $#a;
  525. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  526. $count++;
  527. }
  528. }
  529. $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
  530. $form->{makemodel_rows} = $count;
  531. &check_vendor;
  532. &check_customer;
  533. }
  534. if ($form->{item} eq 'service') {
  535. for (qw(sellprice listprice lastcost avgcost markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  536. &calc_markup;
  537. &check_vendor;
  538. &check_customer;
  539. }
  540. if ($form->{item} eq 'assembly') {
  541. if (!$form->{project_id}) {
  542. $form->{sellprice} = 0;
  543. $form->{listprice} = 0;
  544. $form->{lastcost} = 0;
  545. $form->{weight} = 0;
  546. }
  547. for (qw(rop stock markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  548. @flds = qw(id qty unit bom adj partnumber description sellprice listprice lastcost weight assembly runningnumber partsgroup);
  549. $count = 0;
  550. @a = ();
  551. for $i (1 .. ($form->{assembly_rows} - 1)) {
  552. if ($form->{"qty_$i"}) {
  553. push @a, {};
  554. my $j = $#a;
  555. $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
  556. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  557. if (! $form->{project_id}) {
  558. for (qw(sellprice listprice weight lastcost)) { $form->{$_} += ($form->{"${_}_$i"} * $form->{"qty_$i"}) }
  559. }
  560. $count++;
  561. }
  562. }
  563. if ($form->{markup} && $form->{markup} != $form->{oldmarkup}) {
  564. $form->{sellprice} = 0;
  565. &calc_markup;
  566. }
  567. for (qw(sellprice lastcost listprice)) { $form->{$_} = $form->round_amount($form->{$_}, 2) }
  568. $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
  569. $form->{assembly_rows} = $count;
  570. $count = 0;
  571. @flds = qw(make model);
  572. @a = ();
  573. for $i (1 .. ($form->{makemodel_rows})) {
  574. if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
  575. push @a, {};
  576. my $j = $#a;
  577. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  578. $count++;
  579. }
  580. }
  581. $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
  582. $form->{makemodel_rows} = $count;
  583. &check_customer;
  584. }
  585. if ($form->{type}) {
  586. # this section applies to invoices and orders
  587. # remove any empty numbers
  588. $count = 0;
  589. @a = ();
  590. if ($form->{rowcount}) {
  591. for $i (1 .. $form->{rowcount} - 1) {
  592. if ($form->{"partnumber_$i"}) {
  593. push @a, {};
  594. my $j = $#a;
  595. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  596. $count++;
  597. }
  598. }
  599. $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
  600. $form->{rowcount} = $count;
  601. $form->{creditremaining} -= &invoicetotal;
  602. }
  603. }
  604. &display_form;
  605. }
  606. sub calc_markup {
  607. if ($form->{markup}) {
  608. if ($form->{markup} != $form->{oldmarkup}) {
  609. if ($form->{lastcost}) {
  610. $form->{sellprice} = $form->{lastcost} * (1 + $form->{markup}/100);
  611. $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
  612. } else {
  613. $form->{lastcost} = $form->{sellprice} / (1 + $form->{markup}/100);
  614. $form->{lastcost} = $form->round_amount($form->{lastcost}, 2);
  615. }
  616. }
  617. } else {
  618. if ($form->{lastcost}) {
  619. $form->{markup} = $form->round_amount(((1 - $form->{sellprice} / $form->{lastcost}) * 100), 1);
  620. }
  621. $form->{markup} = "" if $form->{markup} == 0;
  622. }
  623. }
  624. sub invoicetotal {
  625. $form->{oldinvtotal} = 0;
  626. # add all parts and deduct paid
  627. for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
  628. my ($amount, $sellprice, $discount, $qty);
  629. for $i (1 .. $form->{rowcount}) {
  630. $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
  631. $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
  632. $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
  633. $amount = $sellprice * (1 - $discount / 100) * $qty;
  634. for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
  635. $form->{oldinvtotal} += $amount;
  636. }
  637. if (!$form->{taxincluded}) {
  638. my @taxlist= Tax::init_taxes($form, $form->{taxaccounts});
  639. $form->{oldinvtotal} += Tax::calculate_taxes(\@taxlist, $form,
  640. $amount, 0);
  641. }
  642. $form->{oldtotalpaid} = 0;
  643. for $i (1 .. $form->{paidaccounts}) {
  644. $form->{oldtotalpaid} += $form->{"paid_$i"};
  645. }
  646. # return total
  647. ($form->{oldinvtotal} - $form->{oldtotalpaid});
  648. }
  649. sub validate_items {
  650. # check if items are valid
  651. if ($form->{rowcount} == 1) {
  652. &update;
  653. exit;
  654. }
  655. for $i (1 .. $form->{rowcount} - 1) {
  656. $form->isblank("partnumber_$i", $locale->text('Number missing in Row') . " $i");
  657. }
  658. }
  659. sub purchase_order {
  660. $form->{title} = $locale->text('Add Purchase Order');
  661. $form->{vc} = 'vendor';
  662. $form->{type} = 'purchase_order';
  663. $buysell = 'sell';
  664. &create_form;
  665. }
  666. sub sales_order {
  667. $form->{title} = $locale->text('Add Sales Order');
  668. $form->{vc} = 'customer';
  669. $form->{type} = 'sales_order';
  670. $buysell = 'buy';
  671. &create_form;
  672. }
  673. sub rfq {
  674. $form->{title} = $locale->text('Add Request for Quotation');
  675. $form->{vc} = 'vendor';
  676. $form->{type} = 'request_quotation';
  677. $buysell = 'sell';
  678. &create_form;
  679. }
  680. sub quotation {
  681. $form->{title} = $locale->text('Add Quotation');
  682. $form->{vc} = 'customer';
  683. $form->{type} = 'sales_quotation';
  684. $buysell = 'buy';
  685. &create_form;
  686. }
  687. sub create_form {
  688. for (qw(id printed emailed queued)) { delete $form->{$_} }
  689. $form->{script} = 'oe.pl';
  690. $form->{shipto} = 1;
  691. $form->{rowcount}-- if $form->{rowcount};
  692. $form->{rowcount} = 0 if ! $form->{"$form->{vc}_id"};
  693. do "bin/$form->{script}";
  694. for ("$form->{vc}", "currency") { $form->{"select$_"} = "" }
  695. for (qw(currency employee department intnotes notes language_code taxincluded)) { $temp{$_} = $form->{$_} }
  696. &order_links;
  697. for (keys %temp) { $form->{$_} = $temp{$_} if $temp{$_} }
  698. $form->{exchangerate} = "";
  699. $form->{forex} = "";
  700. if ($form->{currency} ne $form->{defaultcurrency}) {
  701. $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell)));
  702. }
  703. &prepare_order;
  704. &display_form;
  705. }
  706. sub e_mail {
  707. $bcc = qq|<input type=hidden name=bcc value="$form->{bcc}">|;
  708. if ($myconfig{role} =~ /(admin|manager)/) {
  709. $bcc = qq|
  710. <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
  711. <td><input name=bcc size=30 value="$form->{bcc}"></td>
  712. |;
  713. }
  714. if ($form->{formname} =~ /(pick|packing|bin)_list/) {
  715. $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
  716. }
  717. $name = $form->{$form->{vc}};
  718. $name =~ s/--.*//g;
  719. $title = $locale->text('E-mail')." $name";
  720. $form->header;
  721. print qq|
  722. <body>
  723. <form method=post action="$form->{script}">
  724. <table width=100%>
  725. <tr class=listtop>
  726. <th class=listtop>$title</th>
  727. </tr>
  728. <tr height="5"></tr>
  729. <tr>
  730. <td>
  731. <table width=100%>
  732. <tr>
  733. <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
  734. <td><input name=email size=30 value="$form->{email}"></td>
  735. <th align=right nowrap>|.$locale->text('Cc').qq|</th>
  736. <td><input name=cc size=30 value="$form->{cc}"></td>
  737. </tr>
  738. <tr>
  739. <th align=right nowrap>|.$locale->text('Subject').qq|</th>
  740. <td><input name=subject size=30 value="$form->{subject}"></td>
  741. $bcc
  742. </tr>
  743. </table>
  744. </td>
  745. </tr>
  746. <tr>
  747. <td>
  748. <table width=100%>
  749. <tr>
  750. <th align=left nowrap>|.$locale->text('Message').qq|</th>
  751. </tr>
  752. <tr>
  753. <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
  754. </tr>
  755. </table>
  756. </td>
  757. </tr>
  758. <tr>
  759. <td>
  760. |;
  761. $form->{oldmedia} = $form->{media};
  762. $form->{media} = "email";
  763. $form->{format} = "pdf";
  764. &print_options;
  765. for (qw(email cc bcc subject message formname sendmode format language_code action nextsub)) { delete $form->{$_} }
  766. $form->hide_form;
  767. print qq|
  768. </td>
  769. </tr>
  770. <tr>
  771. <td><hr size=3 noshade></td>
  772. </tr>
  773. </table>
  774. <input type=hidden name=nextsub value=send_email>
  775. <br>
  776. <input name=action class=submit type=submit value="|.$locale->text('Continue').qq|">
  777. </form>
  778. </body>
  779. </html>
  780. |;
  781. }
  782. sub send_email {
  783. $old_form = new Form;
  784. for (keys %$form) { $old_form->{$_} = $form->{$_} }
  785. $old_form->{media} = $old_form->{oldmedia};
  786. &print_form($old_form);
  787. }
  788. sub print_options {
  789. $form->{sendmode} = "attachment";
  790. $form->{copies} = 1 unless $form->{copies};
  791. $form->{SM}{$form->{sendmode}} = "selected";
  792. if ($form->{selectlanguage}) {
  793. $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
  794. $form->{"selectlanguage"} =~ s/ selected//;
  795. $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
  796. $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
  797. <input type=hidden name=oldlanguage_code value=$form->{oldlanguage_code}>
  798. <input type=hidden name=selectlanguage value="|.$form->escape($form->{selectlanguage},1).qq|">|;
  799. }
  800. $form->{selectformname} = $form->unescape($form->{selectformname});
  801. $form->{selectformname} =~ s/ selected//;
  802. $form->{selectformname} =~ s/(<option value="\Q$form->{formname}\E")/$1 selected/;
  803. $type = qq|<select name=formname>$form->{selectformname}</select>
  804. <input type=hidden name=selectformname value="|.$form->escape($form->{selectformname},1).qq|">|;
  805. if ($form->{media} eq 'email') {
  806. $media = qq|<select name=sendmode>
  807. <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq|
  808. <option value=inline $form->{SM}{inline}>|.$locale->text('In-line').qq|</select>|;
  809. } else {
  810. $media = qq|<select name=media>
  811. <option value="screen">|.$locale->text('Screen');
  812. if (%printer && $latex) {
  813. for (sort keys %printer) { $media .= qq|
  814. <option value="$_">$_| }
  815. }
  816. if ($latex) {
  817. $media .= qq|
  818. <option value="queue">|.$locale->text('Queue');
  819. }
  820. $media .= qq|</select>|;
  821. # set option selected
  822. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  823. }
  824. $form->{selectformat} = qq|<option value="html">html\n|;
  825. # <option value="txt">|.$locale->text('Text');
  826. if ($latex) {
  827. $form->{selectformat} .= qq|
  828. <option value="postscript">|.$locale->text('Postscript').qq|
  829. <option value="pdf">|.$locale->text('PDF');
  830. }
  831. $format = qq|<select name=format>$form->{selectformat}</select>|;
  832. $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
  833. $format .= qq|
  834. <input type=hidden name=selectformat value="|.$form->escape($form->{selectformat},1).qq|">|;
  835. print qq|
  836. <table width=100%>
  837. <tr>
  838. <td>$type</td>
  839. <td>$lang</td>
  840. <td>$format</td>
  841. <td>$media</td>
  842. |;
  843. if (%printer && $latex && $form->{media} ne 'email') {
  844. print qq|
  845. <td nowrap>|.$locale->text('Copies').qq|
  846. <input name=copies size=2 value=$form->{copies}></td>
  847. |;
  848. }
  849. # $locale->text('Printed')
  850. # $locale->text('E-mailed')
  851. # $locale->text('Queued')
  852. # $locale->text('Scheduled')
  853. %status = ( printed => 'Printed',
  854. emailed => 'E-mailed',
  855. queued => 'Queued',
  856. recurring => 'Scheduled' );
  857. print qq|<td align=right width=90%>|;
  858. for (qw(printed emailed queued recurring)) {
  859. if ($form->{$_} =~ /$form->{formname}/) {
  860. print $locale->text($status{$_}).qq|<br>|;
  861. }
  862. }
  863. print qq|
  864. </td>
  865. </tr>
  866. |;
  867. $form->{groupprojectnumber} = "checked" if $form->{groupprojectnumber};
  868. $form->{grouppartsgroup} = "checked" if $form->{grouppartsgroup};
  869. for (qw(runningnumber partnumber description bin)) { $sortby{$_} = "checked" if $form->{sortby} eq $_ }
  870. print qq|
  871. <tr>
  872. <td colspan=3>|.$locale->text('Group by').qq| ->
  873. <input name=groupprojectnumber type=checkbox class=checkbox $form->{groupprojectnumber}>
  874. |.$locale->text('Project').qq|
  875. <input name=grouppartsgroup type=checkbox class=checkbox $form->{grouppartsgroup}>
  876. |.$locale->text('Group').qq|
  877. </td>
  878. <td colspan=3>|.$locale->text('Sort by').qq| ->
  879. <input name=sortby type=radio class=radio value=runningnumber $sortby{runningnumber}>
  880. |.$locale->text('Item').qq|
  881. <input name=sortby type=radio class=radio value=partnumber $sortby{partnumber}>
  882. |.$locale->text('Number').qq|
  883. <input name=sortby type=radio class=radio value=description $sortby{description}>
  884. |.$locale->text('Description').qq|
  885. <input name=sortby type=radio class=radio value=bin $sortby{bin}>
  886. |.$locale->text('Bin').qq|
  887. </td>
  888. </tr>
  889. </table>
  890. |;
  891. }
  892. sub print {
  893. # if this goes to the printer pass through
  894. if ($form->{media} !~ /(screen|email)/) {
  895. $form->error($locale->text('Select txt, postscript or PDF!')) if ($form->{format} !~ /(txt|postscript|pdf)/);
  896. $old_form = new Form;
  897. for (keys %$form) { $old_form->{$_} = $form->{$_} }
  898. }
  899. &print_form($old_form);
  900. }
  901. sub print_form {
  902. my ($old_form) = @_;
  903. $inv = "inv";
  904. $due = "due";
  905. $numberfld = "sinumber";
  906. $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
  907. if ($form->{formname} eq "invoice") {
  908. $form->{label} = $locale->text('Invoice');
  909. }
  910. if ($form->{formname} eq 'sales_order') {
  911. $inv = "ord";
  912. $due = "req";
  913. $form->{label} = $locale->text('Sales Order');
  914. $numberfld = "sonumber";
  915. $order = 1;
  916. }
  917. if ($form->{formname} eq 'work_order') {
  918. $inv = "ord";
  919. $due = "req";
  920. $form->{label} = $locale->text('Work Order');
  921. $numberfld = "sonumber";
  922. $order = 1;
  923. }
  924. if ($form->{formname} eq 'packing_list') {
  925. # we use the same packing list as from an invoice
  926. $form->{label} = $locale->text('Packing List');
  927. if ($form->{type} ne 'invoice') {
  928. $inv = "ord";
  929. $due = "req";
  930. $numberfld = "sonumber";
  931. $order = 1;
  932. $filled = 0;
  933. for ($i = 1; $i < $form->{rowcount}; $i++) {
  934. if ($form->{"ship_$i"}) {
  935. $filled = 1;
  936. last;
  937. }
  938. }
  939. if (!$filled) {
  940. for (1 .. $form->{rowcount}) { $form->{"ship_$_"} = $form->{"qty_$_"} }
  941. }
  942. }
  943. }
  944. if ($form->{formname} eq 'pick_list') {
  945. $form->{label} = $locale->text('Pick List');
  946. if ($form->{type} ne 'invoice') {
  947. $inv = "ord";
  948. $due = "req";
  949. $order = 1;
  950. $numberfld = "sonumber";
  951. }
  952. }
  953. if ($form->{formname} eq 'purchase_order') {
  954. $inv = "ord";
  955. $due = "req";
  956. $form->{label} = $locale->text('Purchase Order');
  957. $numberfld = "ponumber";
  958. $order = 1;
  959. }
  960. if ($form->{formname} eq 'bin_list') {
  961. $inv = "ord";
  962. $due = "req";
  963. $form->{label} = $locale->text('Bin List');
  964. $numberfld = "ponumber";
  965. $order = 1;
  966. }
  967. if ($form->{formname} eq 'sales_quotation') {
  968. $inv = "quo";
  969. $due = "req";
  970. $form->{label} = $locale->text('Quotation');
  971. $numberfld = "sqnumber";
  972. $order = 1;
  973. }
  974. if ($form->{formname} eq 'request_quotation') {
  975. $inv = "quo";
  976. $due = "req";
  977. $form->{label} = $locale->text('Quotation');
  978. $numberfld = "rfqnumber";
  979. $order = 1;
  980. }
  981. &validate_items;
  982. $form->{"${inv}date"} = $form->{transdate};
  983. $form->isblank("email", $locale->text('E-mail address missing!')) if ($form->{media} eq 'email');
  984. $form->isblank("${inv}date", $locale->text($form->{label} .' Date missing!'));
  985. # get next number
  986. if (! $form->{"${inv}number"}) {
  987. $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
  988. if ($form->{media} eq 'screen') {
  989. &update;
  990. exit;
  991. }
  992. }
  993. # $locale->text('Invoice Number missing!')
  994. # $locale->text('Invoice Date missing!')
  995. # $locale->text('Packing List Number missing!')
  996. # $locale->text('Packing List Date missing!')
  997. # $locale->text('Order Number missing!')
  998. # $locale->text('Order Date missing!')
  999. # $locale->text('Quotation Number missing!')
  1000. # $locale->text('Quotation Date missing!')
  1001. &{ "$form->{vc}_details" };
  1002. @a = ();
  1003. foreach $i (1 .. $form->{rowcount}) {
  1004. push @a, ("partnumber_$i", "description_$i", "projectnumber_$i", "partsgroup_$i", "serialnumber_$i", "bin_$i", "unit_$i", "notes_$i");
  1005. }
  1006. for (split / /, $form->{taxaccounts}) { push @a, "${_}_description" }
  1007. $ARAP = ($form->{vc} eq 'customer') ? "AR" : "AP";
  1008. push @a, $ARAP;
  1009. # format payment dates
  1010. for $i (1 .. $form->{paidaccounts} - 1) {
  1011. if (exists $form->{longformat}) {
  1012. $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
  1013. }
  1014. push @a, "${ARAP}_paid_$i", "source_$i", "memo_$i";
  1015. }
  1016. $form->format_string(@a);
  1017. ($form->{employee}) = split /--/, $form->{employee};
  1018. ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
  1019. # this is a label for the subtotals
  1020. $form->{groupsubtotaldescription} = $locale->text('Subtotal') if not exists $form->{groupsubtotaldescription};
  1021. delete $form->{groupsubtotaldescription} if $form->{deletegroupsubtotal};
  1022. $duedate = $form->{"${due}date"};
  1023. # create the form variables
  1024. if ($order) {
  1025. OE->order_details(\%myconfig, \%$form);
  1026. } else {
  1027. IS->invoice_details(\%myconfig, \%$form);
  1028. }
  1029. if (exists $form->{longformat}) {
  1030. $form->{"${due}date"} = $duedate;
  1031. for ("${inv}date", "${due}date", "shippingdate", "transdate") { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) }
  1032. }
  1033. @a = qw(name address1 address2 city state zipcode country contact phone fax email);
  1034. $shipto = 1;
  1035. # if there is no shipto fill it in from billto
  1036. foreach $item (@a) {
  1037. if ($form->{"shipto$item"}) {
  1038. $shipto = 0;
  1039. last;
  1040. }
  1041. }
  1042. if ($shipto) {
  1043. if ($form->{formname} eq 'purchase_order' || $form->{formname} eq 'request_quotation') {
  1044. $form->{shiptoname} = $myconfig{company};
  1045. $form->{shiptoaddress1} = $myconfig{address};
  1046. $form->{shiptoaddress1} =~ s/\\n/\n/g;
  1047. } else {
  1048. if ($form->{formname} !~ /bin_list/) {
  1049. for (@a) { $form->{"shipto$_"} = $form->{$_} }
  1050. }
  1051. }
  1052. }
  1053. # some of the stuff could have umlauts so we translate them
  1054. push @a, qw(contact shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptoemail shippingpoint shipvia notes intnotes employee warehouse);
  1055. push @a, ("${inv}number", "${inv}date", "${due}date");
  1056. for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
  1057. $form->{address} =~ s/\\n/\n/g;
  1058. for (qw(name email)) { $form->{"user$_"} = $myconfig{$_} }
  1059. push @a, qw(company address tel fax businessnumber username useremail);
  1060. for (qw(notes intnotes)) { $form->{$_} =~ s/^\s+//g }
  1061. # before we format replace <%var%>
  1062. for (qw(notes intnotes message)) { $form->{$_} =~ s/<%(.*?)%>/$form->{$1}/g }
  1063. $form->format_string(@a);
  1064. $form->{templates} = "$myconfig{templates}";
  1065. $form->{IN} = "$form->{formname}.$form->{format}";
  1066. if ($form->{format} =~ /(postscript|pdf)/) {
  1067. $form->{IN} =~ s/$&$/tex/;
  1068. }
  1069. $form->{pre} = "<body bgcolor=#ffffff>\n<pre>" if $form->{format} eq 'txt';
  1070. if ($form->{media} !~ /(screen|queue|email)/) {
  1071. $form->{OUT} = "| $printer{$form->{media}}";
  1072. $form->{OUT} =~ s/<%(fax)%>/<%$form->{vc}$1%>/;
  1073. $form->{OUT} =~ s/<%(.*?)%>/$form->{$1}/g;
  1074. if ($form->{printed} !~ /$form->{formname}/) {
  1075. $form->{printed} .= " $form->{formname}";
  1076. $form->{printed} =~ s/^ //;
  1077. $form->update_status(\%myconfig);
  1078. }
  1079. $old_form->{printed} = $form->{printed} if defined %$old_form;
  1080. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  1081. reference => $form->{"${inv}number"},
  1082. formname => $form->{formname},
  1083. action => 'printed',
  1084. id => $form->{id} );
  1085. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if defined %$old_form;
  1086. }
  1087. if ($form->{media} eq 'email') {
  1088. $form->{subject} = qq|$form->{label} $form->{"${inv}number"}| unless $form->{subject};
  1089. $form->{plainpaper} = 1;
  1090. $form->{OUT} = "$sendmail";
  1091. if ($form->{emailed} !~ /$form->{formname}/) {
  1092. $form->{emailed} .= " $form->{formname}";
  1093. $form->{emailed} =~ s/^ //;
  1094. # save status
  1095. $form->update_status(\%myconfig);
  1096. }
  1097. $now = scalar localtime;
  1098. $cc = $locale->text('Cc').qq|: $form->{cc}\n| if $form->{cc};
  1099. $bcc = $locale->text('Bcc').qq|: $form->{bcc}\n| if $form->{bcc};
  1100. if (defined %$old_form) {
  1101. $old_form->{intnotes} = qq|$old_form->{intnotes}\n\n| if $old_form->{intnotes};
  1102. $old_form->{intnotes} .= qq|[email]\n|
  1103. .$locale->text('Date').qq|: $now\n|
  1104. .$locale->text('To').qq|: $form->{email}\n${cc}${bcc}|
  1105. .$locale->text('Subject').qq|: $form->{subject}\n|;
  1106. $old_form->{intnotes} .= qq|\n|.$locale->text('Message').qq|: |;
  1107. $old_form->{intnotes} .= ($form->{message}) ? $form->{message} : $locale->text('sent');
  1108. $old_form->{message} = $form->{message};
  1109. $old_form->{emailed} = $form->{emailed};
  1110. $old_form->{format} = "postscript" if $myconfig{printer};
  1111. $old_form->{media} = $myconfig{printer};
  1112. $old_form->save_intnotes(\%myconfig, ($order) ? 'oe' : lc $ARAP);
  1113. }
  1114. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  1115. reference => $form->{"${inv}number"},
  1116. formname => $form->{formname},
  1117. action => 'emailed',
  1118. id => $form->{id} );
  1119. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if defined %$old_form;
  1120. }
  1121. if ($form->{media} eq 'queue') {
  1122. %queued = split / /, $form->{queued};
  1123. if ($filename = $queued{$form->{formname}}) {
  1124. $form->{queued} =~ s/$form->{formname} $filename//;
  1125. unlink "$spool/$filename";
  1126. $filename =~ s/\..*$//g;
  1127. } else {
  1128. $filename = time;
  1129. $filename .= $$;
  1130. }
  1131. $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
  1132. $form->{OUT} = ">$spool/$filename";
  1133. $form->{queued} .= " $form->{formname} $filename";
  1134. $form->{queued} =~ s/^ //;
  1135. # save status
  1136. $form->update_status(\%myconfig);
  1137. $old_form->{queued} = $form->{queued};
  1138. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  1139. reference => $form->{"${inv}number"},
  1140. formname => $form->{formname},
  1141. action => 'queued',
  1142. id => $form->{id} );
  1143. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
  1144. }
  1145. $form->format_string("email", "cc", "bcc");
  1146. $form->{fileid} = $form->{"${inv}number"};
  1147. $form->{fileid} =~ s/(\s|\W)+//g;
  1148. $form->parse_template(\%myconfig, $userspath);
  1149. # if we got back here restore the previous form
  1150. if (defined %$old_form) {
  1151. $old_form->{"${inv}number"} = $form->{"${inv}number"};
  1152. # restore and display form
  1153. for (keys %$old_form) { $form->{$_} = $old_form->{$_} }
  1154. delete $form->{pre};
  1155. $form->{rowcount}--;
  1156. for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  1157. for $i (1 .. $form->{paidaccounts}) {
  1158. for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  1159. }
  1160. &{ "$display_form" };
  1161. }
  1162. }
  1163. sub customer_details {
  1164. IS->customer_details(\%myconfig, \%$form);
  1165. }
  1166. sub vendor_details {
  1167. IR->vendor_details(\%myconfig, \%$form);
  1168. }
  1169. sub ship_to {
  1170. $title = $form->{title};
  1171. $form->{title} = $locale->text('Ship to');
  1172. for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  1173. for (1 .. $form->{paidaccounts}) { $form->{"paid_$_"} = $form->parse_amount(\%myconfig, $form->{"paid_$_"}) }
  1174. # get details for name
  1175. &{ "$form->{vc}_details" };
  1176. $number = ($form->{vc} eq 'customer') ? $locale->text('Customer Number') : $locale->text('Vendor Number');
  1177. $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
  1178. $form->{rowcount}--;
  1179. $form->header;
  1180. print qq|
  1181. <body>
  1182. <form method=post action=$form->{script}>
  1183. <table width=100%>
  1184. <tr>
  1185. <td>
  1186. <table>
  1187. <tr class=listheading>
  1188. <th class=listheading colspan=2 width=50%>|.$locale->text('Billing Address').qq|</th>
  1189. <th class=listheading width=50%>|.$locale->text('Shipping Address').qq|</th>
  1190. </tr>
  1191. <tr height="5"></tr>
  1192. <tr>
  1193. <th align=right nowrap>$number</th>
  1194. <td>$form->{"$form->{vc}number"}</td>
  1195. </tr>
  1196. <tr>
  1197. <th align=right nowrap>|.$locale->text('Company Name').qq|</th>
  1198. <td>$form->{name}</td>
  1199. <td><input name=shiptoname size=35 maxlength=64 value="$form->{shiptoname}"></td>
  1200. </tr>
  1201. <tr>
  1202. <th align=right nowrap>|.$locale->text('Address').qq|</th>
  1203. <td>$form->{address1}</td>
  1204. <td><input name=shiptoaddress1 size=35 maxlength=32 value="$form->{shiptoaddress1}"></td>
  1205. </tr>
  1206. <tr>
  1207. <th></th>
  1208. <td>$form->{address2}</td>
  1209. <td><input name=shiptoaddress2 size=35 maxlength=32 value="$form->{shiptoaddress2}"></td>
  1210. </tr>
  1211. <tr>
  1212. <th align=right nowrap>|.$locale->text('City').qq|</th>
  1213. <td>$form->{city}</td>
  1214. <td><input name=shiptocity size=35 maxlength=32 value="$form->{shiptocity}"></td>
  1215. </tr>
  1216. <tr>
  1217. <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
  1218. <td>$form->{state}</td>
  1219. <td><input name=shiptostate size=35 maxlength=32 value="$form->{shiptostate}"></td>
  1220. </tr>
  1221. <tr>
  1222. <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
  1223. <td>$form->{zipcode}</td>
  1224. <td><input name=shiptozipcode size=10 maxlength=10 value="$form->{shiptozipcode}"></td>
  1225. </tr>
  1226. <tr>
  1227. <th align=right nowrap>|.$locale->text('Country').qq|</th>
  1228. <td>$form->{country}</td>
  1229. <td><input name=shiptocountry size=35 maxlength=32 value="$form->{shiptocountry}"></td>
  1230. </tr>
  1231. <tr>
  1232. <th align=right nowrap>|.$locale->text('Contact').qq|</th>
  1233. <td>$form->{contact}</td>
  1234. <td><input name=shiptocontact size=35 maxlength=64 value="$form->{shiptocontact}"></td>
  1235. </tr>
  1236. <tr>
  1237. <th align=right nowrap>|.$locale->text('Phone').qq|</th>
  1238. <td>$form->{"$form->{vc}phone"}</td>
  1239. <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
  1240. </tr>
  1241. <tr>
  1242. <th align=right nowrap>|.$locale->text('Fax').qq|</th>
  1243. <td>$form->{"$form->{vc}fax"}</td>
  1244. <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
  1245. </tr>
  1246. <tr>
  1247. <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
  1248. <td>$form->{email}</td>
  1249. <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
  1250. </tr>
  1251. </table>
  1252. </td>
  1253. </tr>
  1254. </table>
  1255. <input type=hidden name=nextsub value=$nextsub>
  1256. |;
  1257. # delete shipto
  1258. for (qw(action nextsub)) { delete $form->{$_} }
  1259. for (qw(name address1 address2 city state zipcode country contact phone fax email)) { delete $form->{"shipto$_"} }
  1260. $form->{title} = $title;
  1261. $form->hide_form;
  1262. print qq|
  1263. <hr size=3 noshade>
  1264. <br>
  1265. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  1266. </form>
  1267. </body>
  1268. </html>
  1269. |;
  1270. }