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