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