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