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