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