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