summaryrefslogtreecommitdiff
path: root/bin/io.pl
blob: 46e30120cb1ecb14f8f8ec9fb6503e024de2eb09 (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"} unless $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. $amount += Tax::calculate_taxes(\@taxlist, $form, $amount, 0);
  402. }
  403. $form->{creditremaining} -= $amount;
  404. $form->{"runningnumber_$i"} = $i;
  405. # format amounts
  406. if ($form->{item} ne 'assembly') {
  407. for (qw(sellprice listprice)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces1) }
  408. $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces2);
  409. }
  410. $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"});
  411. }
  412. }
  413. $form->{rowcount} = $i;
  414. $form->{assembly_rows} = $i if ($form->{item} eq 'assembly');
  415. $form->{focus} = "description_$i";
  416. # delete all the new_ variables
  417. for $i (1 .. $form->{lastndx}) {
  418. 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)) {
  419. delete $form->{"new_${_}_$i"};
  420. }
  421. }
  422. for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
  423. &display_form;
  424. }
  425. sub new_item {
  426. if ($form->{language_code} && $form->{"description_$form->{rowcount}"}) {
  427. $form->error($locale->text('Translation not on file!'));
  428. }
  429. # change callback
  430. $form->{old_callback} = $form->escape($form->{callback},1);
  431. $form->{callback} = $form->escape("$form->{script}?action=display_form",1);
  432. # delete action
  433. delete $form->{action};
  434. # save all other form variables in a previousform variable
  435. if (!$form->{previousform}) {
  436. foreach $key (keys %$form) {
  437. # escape ampersands
  438. $form->{$key} =~ s/&/%26/g;
  439. $form->{previousform} .= qq|$key=$form->{$key}&|;
  440. }
  441. chop $form->{previousform};
  442. $form->{previousform} = $form->escape($form->{previousform}, 1);
  443. }
  444. $i = $form->{rowcount};
  445. for (qw(partnumber description sellprice unit)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
  446. $form->header;
  447. print qq|
  448. <body>
  449. <h4 class=error>|.$locale->text('Item not on file!').qq|</h4>|;
  450. if ($myconfig{acs} !~ /(Goods \& Services--Add Part|Goods \& Services--Add Service)/) {
  451. print qq|
  452. <h4>|.$locale->text('What type of item is this?').qq|</h4>
  453. <form method=post action=ic.pl>
  454. <p>
  455. <input class=radio type=radio name=item value=part checked>&nbsp;|.$locale->text('Part')
  456. .qq|<br>
  457. <input class=radio type=radio name=item value=service>&nbsp;|.$locale->text('Service')
  458. .qq|
  459. <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
  460. <input type=hidden name=description value="$form->{"description_$i"}">
  461. <input type=hidden name=nextsub value=add>
  462. <input type=hidden name=action value=add>
  463. |;
  464. $form->hide_form(qw(previousform rowcount path login sessionid));
  465. print qq|
  466. <p>
  467. <button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  468. </form>
  469. |;
  470. }
  471. print qq|
  472. </body>
  473. </html>
  474. |;
  475. }
  476. sub display_form {
  477. # if we have a display_form
  478. if ($form->{display_form}) {
  479. &{ "$form->{display_form}" };
  480. exit;
  481. }
  482. &form_header;
  483. $numrows = ++$form->{rowcount};
  484. $subroutine = "display_row";
  485. if ($form->{item} eq 'part') {
  486. # create makemodel rows
  487. &makemodel_row(++$form->{makemodel_rows});
  488. &vendor_row(++$form->{vendor_rows});
  489. $numrows = ++$form->{customer_rows};
  490. $subroutine = "customer_row";
  491. }
  492. if ($form->{item} eq 'assembly') {
  493. # create makemodel rows
  494. &makemodel_row(++$form->{makemodel_rows});
  495. $numrows = ++$form->{customer_rows};
  496. $subroutine = "customer_row";
  497. }
  498. if ($form->{item} eq 'service') {
  499. &vendor_row(++$form->{vendor_rows});
  500. $numrows = ++$form->{customer_rows};
  501. $subroutine = "customer_row";
  502. }
  503. if ($form->{item} eq 'labor') {
  504. $numrows = 0;
  505. }
  506. # create rows
  507. &{ $subroutine }($numrows) if $numrows;
  508. &form_footer;
  509. }
  510. sub check_form {
  511. my @a = ();
  512. my $count = 0;
  513. my $i;
  514. my $j;
  515. 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);
  516. # remove any makes or model rows
  517. if ($form->{item} eq 'part') {
  518. for (qw(listprice sellprice lastcost avgcost weight rop markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  519. &calc_markup;
  520. @flds = qw(make model);
  521. $count = 0;
  522. @a = ();
  523. for $i (1 .. $form->{makemodel_rows}) {
  524. if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
  525. push @a, {};
  526. $j = $#a;
  527. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  528. $count++;
  529. }
  530. }
  531. $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
  532. $form->{makemodel_rows} = $count;
  533. &check_vendor;
  534. &check_customer;
  535. }
  536. if ($form->{item} eq 'service') {
  537. for (qw(sellprice listprice lastcost avgcost markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  538. &calc_markup;
  539. &check_vendor;
  540. &check_customer;
  541. }
  542. if ($form->{item} eq 'assembly') {
  543. if (!$form->{project_id}) {
  544. $form->{sellprice} = 0;
  545. $form->{listprice} = 0;
  546. $form->{lastcost} = 0;
  547. $form->{weight} = 0;
  548. }
  549. for (qw(rop stock markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  550. @flds = qw(id qty unit bom adj partnumber description sellprice listprice lastcost weight assembly runningnumber partsgroup);
  551. $count = 0;
  552. @a = ();
  553. for $i (1 .. ($form->{assembly_rows} - 1)) {
  554. if ($form->{"qty_$i"}) {
  555. push @a, {};
  556. my $j = $#a;
  557. $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
  558. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  559. if (! $form->{project_id}) {
  560. for (qw(sellprice listprice weight lastcost)) { $form->{$_} += ($form->{"${_}_$i"} * $form->{"qty_$i"}) }
  561. }
  562. $count++;
  563. }
  564. }
  565. if ($form->{markup} && $form->{markup} != $form->{oldmarkup}) {
  566. $form->{sellprice} = 0;
  567. &calc_markup;
  568. }
  569. for (qw(sellprice lastcost listprice)) { $form->{$_} = $form->round_amount($form->{$_}, 2) }
  570. $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
  571. $form->{assembly_rows} = $count;
  572. $count = 0;
  573. @flds = qw(make model);
  574. @a = ();
  575. for $i (1 .. ($form->{makemodel_rows})) {
  576. if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
  577. push @a, {};
  578. my $j = $#a;
  579. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  580. $count++;
  581. }
  582. }
  583. $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
  584. $form->{makemodel_rows} = $count;
  585. &check_customer;
  586. }
  587. if ($form->{type}) {
  588. # this section applies to invoices and orders
  589. # remove any empty numbers
  590. $count = 0;
  591. @a = ();
  592. if ($form->{rowcount}) {
  593. for $i (1 .. $form->{rowcount} - 1) {
  594. if ($form->{"partnumber_$i"}) {
  595. push @a, {};
  596. my $j = $#a;
  597. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  598. $count++;
  599. }
  600. }
  601. $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
  602. $form->{rowcount} = $count;
  603. $form->{creditremaining} -= &invoicetotal;
  604. }
  605. }
  606. &display_form;
  607. }
  608. sub calc_markup {
  609. if ($form->{markup}) {
  610. if ($form->{markup} != $form->{oldmarkup}) {
  611. if ($form->{lastcost}) {
  612. $form->{sellprice} = $form->{lastcost} * (1 + $form->{markup}/100);
  613. $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
  614. } else {
  615. $form->{lastcost} = $form->{sellprice} / (1 + $form->{markup}/100);
  616. $form->{lastcost} = $form->round_amount($form->{lastcost}, 2);
  617. }
  618. }
  619. } else {
  620. if ($form->{lastcost}) {
  621. $form->{markup} = $form->round_amount(((1 - $form->{sellprice} / $form->{lastcost}) * 100), 1);
  622. }
  623. $form->{markup} = "" if $form->{markup} == 0;
  624. }
  625. }
  626. sub invoicetotal {
  627. $form->{oldinvtotal} = 0;
  628. # add all parts and deduct paid
  629. for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
  630. my ($amount, $sellprice, $discount, $qty);
  631. for $i (1 .. $form->{rowcount}) {
  632. $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
  633. $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
  634. $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
  635. $amount = $sellprice * (1 - $discount / 100) * $qty;
  636. for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
  637. $form->{oldinvtotal} += $amount;
  638. }
  639. if (!$form->{taxincluded}) {
  640. my @taxlist= Tax::init_taxes($form, $form->{taxaccounts});
  641. $form->{oldinvtotal} += Tax::calculate_taxes(\@taxlist, $form,
  642. $amount, 0);
  643. }
  644. $form->{oldtotalpaid} = 0;
  645. for $i (1 .. $form->{paidaccounts}) {
  646. $form->{oldtotalpaid} += $form->{"paid_$i"};
  647. }
  648. # return total
  649. ($form->{oldinvtotal} - $form->{oldtotalpaid});
  650. }
  651. sub validate_items {
  652. # check if items are valid
  653. if ($form->{rowcount} == 1) {
  654. &update;
  655. exit;
  656. }
  657. for $i (1 .. $form->{rowcount} - 1) {
  658. $form->isblank("partnumber_$i", $locale->text('Number missing in Row [_1]', $i));
  659. }
  660. }
  661. sub purchase_order {
  662. $form->{title} = $locale->text('Add Purchase Order');
  663. $form->{vc} = 'vendor';
  664. $form->{type} = 'purchase_order';
  665. $buysell = 'sell';
  666. &create_form;
  667. }
  668. sub sales_order {
  669. $form->{title} = $locale->text('Add Sales Order');
  670. $form->{vc} = 'customer';
  671. $form->{type} = 'sales_order';
  672. $buysell = 'buy';
  673. &create_form;
  674. }
  675. sub rfq {
  676. $form->{title} = $locale->text('Add Request for Quotation');
  677. $form->{vc} = 'vendor';
  678. $form->{type} = 'request_quotation';
  679. $buysell = 'sell';
  680. &create_form;
  681. }
  682. sub quotation {
  683. $form->{title} = $locale->text('Add Quotation');
  684. $form->{vc} = 'customer';
  685. $form->{type} = 'sales_quotation';
  686. $buysell = 'buy';
  687. &create_form;
  688. }
  689. sub create_form {
  690. for (qw(id printed emailed queued)) { delete $form->{$_} }
  691. $form->{script} = 'oe.pl';
  692. $form->{shipto} = 1;
  693. $form->{rowcount}-- if $form->{rowcount};
  694. $form->{rowcount} = 0 if ! $form->{"$form->{vc}_id"};
  695. do "bin/$form->{script}";
  696. for ("$form->{vc}", "currency") { $form->{"select$_"} = "" }
  697. for (qw(currency employee department intnotes notes language_code taxincluded)) { $temp{$_} = $form->{$_} }
  698. &order_links;
  699. for (keys %temp) { $form->{$_} = $temp{$_} if $temp{$_} }
  700. $form->{exchangerate} = "";
  701. $form->{forex} = "";
  702. if ($form->{currency} ne $form->{defaultcurrency}) {
  703. $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell)));
  704. }
  705. &prepare_order;
  706. &display_form;
  707. }
  708. sub e_mail {
  709. $bcc = qq|<input type=hidden name=bcc value="$form->{bcc}">|;
  710. if ($myconfig{role} =~ /(admin|manager)/) {
  711. $bcc = qq|
  712. <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
  713. <td><input name=bcc size=30 value="$form->{bcc}"></td>
  714. |;
  715. }
  716. if ($form->{formname} =~ /(pick|packing|bin)_list/) {
  717. $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
  718. }
  719. $name = $form->{$form->{vc}};
  720. $name =~ s/--.*//g;
  721. $title = $locale->text('E-mail')." $name";
  722. $form->header;
  723. print qq|
  724. <body>
  725. <form method=post action="$form->{script}">
  726. <table width=100%>
  727. <tr class=listtop>
  728. <th class=listtop>$title</th>
  729. </tr>
  730. <tr height="5"></tr>
  731. <tr>
  732. <td>
  733. <table width=100%>
  734. <tr>
  735. <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
  736. <td><input name=email size=30 value="$form->{email}"></td>
  737. <th align=right nowrap>|.$locale->text('Cc').qq|</th>
  738. <td><input name=cc size=30 value="$form->{cc}"></td>
  739. </tr>
  740. <tr>
  741. <th align=right nowrap>|.$locale->text('Subject').qq|</th>
  742. <td><input name=subject size=30 value="$form->{subject}"></td>
  743. $bcc
  744. </tr>
  745. </table>
  746. </td>
  747. </tr>
  748. <tr>
  749. <td>
  750. <table width=100%>
  751. <tr>
  752. <th align=left nowrap>|.$locale->text('Message').qq|</th>
  753. </tr>
  754. <tr>
  755. <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
  756. </tr>
  757. </table>
  758. </td>
  759. </tr>
  760. <tr>
  761. <td>
  762. |;
  763. $form->{oldmedia} = $form->{media};
  764. $form->{media} = "email";
  765. $form->{format} = "pdf";
  766. &print_options;
  767. for (qw(email cc bcc subject message formname sendmode format language_code action nextsub)) { delete $form->{$_} }
  768. $form->hide_form;
  769. print qq|
  770. </td>
  771. </tr>
  772. <tr>
  773. <td><hr size=3 noshade></td>
  774. </tr>
  775. </table>
  776. <input type="hidden" name="nextsub" value="send_email">
  777. <br>
  778. <button name="action" class="submit" type="submit" value="continue">|.$locale->text('Continue').qq|</button>
  779. </form>
  780. </body>
  781. </html>
  782. |;
  783. }
  784. sub send_email {
  785. $old_form = new Form;
  786. for (keys %$form) { $old_form->{$_} = $form->{$_} }
  787. $old_form->{media} = $old_form->{oldmedia};
  788. &print_form($old_form);
  789. }
  790. sub print_options {
  791. $form->{sendmode} = "attachment";
  792. $form->{copies} = 1 unless $form->{copies};
  793. $form->{SM}{$form->{sendmode}} = "selected";
  794. if ($form->{selectlanguage}) {
  795. $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
  796. $form->{"selectlanguage"} =~ s/ selected//;
  797. $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
  798. $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
  799. <input type=hidden name=oldlanguage_code value=$form->{oldlanguage_code}>
  800. <input type=hidden name=selectlanguage value="|.$form->escape($form->{selectlanguage},1).qq|">|;
  801. }
  802. $form->{selectformname} = $form->unescape($form->{selectformname});
  803. $form->{selectformname} =~ s/ selected//;
  804. $form->{selectformname} =~ s/(<option value="\Q$form->{formname}\E")/$1 selected/;
  805. $type = qq|<select name=formname>$form->{selectformname}</select>
  806. <input type=hidden name=selectformname value="|.$form->escape($form->{selectformname},1).qq|">|;
  807. if ($form->{media} eq 'email') {
  808. $media = qq|<select name=sendmode>
  809. <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq|
  810. <option value=inline $form->{SM}{inline}>|.$locale->text('In-line').qq|</select>|;
  811. } else {
  812. $media = qq|<select name=media>
  813. <option value="screen">|.$locale->text('Screen');
  814. if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
  815. for (sort keys %{LedgerSMB::Sysconfig::printer}) { $media .= qq|
  816. <option value="$_">$_| }
  817. }
  818. if (${LedgerSMB::Sysconfig::latex}) {
  819. $media .= qq|
  820. <option value="queue">|.$locale->text('Queue');
  821. }
  822. $media .= qq|</select>|;
  823. # set option selected
  824. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  825. }
  826. $form->{selectformat} = qq|<option value="html">html\n|;
  827. # <option value="txt">|.$locale->text('Text');
  828. if (${LedgerSMB::Sysconfig::latex}) {
  829. $form->{selectformat} .= qq|
  830. <option value="postscript">|.$locale->text('Postscript').qq|
  831. <option value="pdf">|.$locale->text('PDF');
  832. }
  833. $format = qq|<select name=format>$form->{selectformat}</select>|;
  834. $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
  835. $format .= qq|
  836. <input type=hidden name=selectformat value="|.$form->escape($form->{selectformat},1).qq|">|;
  837. print qq|
  838. <table width=100%>
  839. <tr>
  840. <td>$type</td>
  841. <td>$lang</td>
  842. <td>$format</td>
  843. <td>$media</td>
  844. |;
  845. if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} && $form->{media} ne 'email') {
  846. print qq|
  847. <td nowrap>|.$locale->text('Copies').qq|
  848. <input name=copies size=2 value=$form->{copies}></td>
  849. |;
  850. }
  851. # $locale->text('Printed')
  852. # $locale->text('E-mailed')
  853. # $locale->text('Queued')
  854. # $locale->text('Scheduled')
  855. %status = ( printed => 'Printed',
  856. emailed => 'E-mailed',
  857. queued => 'Queued',
  858. recurring => 'Scheduled' );
  859. print qq|<td align=right width=90%>|;
  860. for (qw(printed emailed queued recurring)) {
  861. if ($form->{$_} =~ /$form->{formname}/) {
  862. print $locale->text($status{$_}).qq|<br>|;
  863. }
  864. }
  865. print qq|
  866. </td>
  867. </tr>
  868. |;
  869. $form->{groupprojectnumber} = "checked" if $form->{groupprojectnumber};
  870. $form->{grouppartsgroup} = "checked" if $form->{grouppartsgroup};
  871. for (qw(runningnumber partnumber description bin)) { $sortby{$_} = "checked" if $form->{sortby} eq $_ }
  872. print qq|
  873. <tr>
  874. <td colspan=6>|.$locale->text('Group by').qq| ->
  875. <input name=groupprojectnumber type=checkbox class=checkbox $form->{groupprojectnumber}>
  876. |.$locale->text('Project').qq|
  877. <input name=grouppartsgroup type=checkbox class=checkbox $form->{grouppartsgroup}>
  878. |.$locale->text('Group').qq|
  879. </td>
  880. </tr>
  881. <tr>
  882. <td colspan=6>|.$locale->text('Sort by').qq| ->
  883. <input name=sortby type=radio class=radio value=runningnumber $sortby{runningnumber}>
  884. |.$locale->text('Item').qq|
  885. <input name=sortby type=radio class=radio value=partnumber $sortby{partnumber}>
  886. |.$locale->text('Number').qq|
  887. <input name=sortby type=radio class=radio value=description $sortby{description}>
  888. |.$locale->text('Description').qq|
  889. <input name=sortby type=radio class=radio value=bin $sortby{bin}>
  890. |.$locale->text('Bin').qq|
  891. </td>
  892. </tr>
  893. </table>
  894. |;
  895. }
  896. sub print {
  897. # if this goes to the printer pass through
  898. if ($form->{media} !~ /(screen|email)/) {
  899. $form->error($locale->text('Select txt, postscript or PDF!')) if ($form->{format} !~ /(txt|postscript|pdf)/);
  900. $old_form = new Form;
  901. for (keys %$form) { $old_form->{$_} = $form->{$_} }
  902. }
  903. &print_form($old_form);
  904. }
  905. sub print_form {
  906. my ($old_form) = @_;
  907. $inv = "inv";
  908. $due = "due";
  909. $numberfld = "sinumber";
  910. $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
  911. if ($form->{formname} eq "invoice") {
  912. $form->{label} = $locale->text('Invoice');
  913. }
  914. if ($form->{formname} eq 'sales_order') {
  915. $inv = "ord";
  916. $due = "req";
  917. $form->{label} = $locale->text('Sales Order');
  918. $numberfld = "sonumber";
  919. $order = 1;
  920. }
  921. if ($form->{formname} eq 'work_order') {
  922. $inv = "ord";
  923. $due = "req";
  924. $form->{label} = $locale->text('Work Order');
  925. $numberfld = "sonumber";
  926. $order = 1;
  927. }
  928. if ($form->{formname} eq 'packing_list') {
  929. # we use the same packing list as from an invoice
  930. $form->{label} = $locale->text('Packing List');
  931. if ($form->{type} ne 'invoice') {
  932. $inv = "ord";
  933. $due = "req";
  934. $numberfld = "sonumber";
  935. $order = 1;
  936. $filled = 0;
  937. for ($i = 1; $i < $form->{rowcount}; $i++) {
  938. if ($form->{"ship_$i"}) {
  939. $filled = 1;
  940. last;
  941. }
  942. }
  943. if (!$filled) {
  944. for (1 .. $form->{rowcount}) { $form->{"ship_$_"} = $form->{"qty_$_"} }
  945. }
  946. }
  947. }
  948. if ($form->{formname} eq 'pick_list') {
  949. $form->{label} = $locale->text('Pick List');
  950. if ($form->{type} ne 'invoice') {
  951. $inv = "ord";
  952. $due = "req";
  953. $order = 1;
  954. $numberfld = "sonumber";
  955. }
  956. }
  957. if ($form->{formname} eq 'purchase_order') {
  958. $inv = "ord";
  959. $due = "req";
  960. $form->{label} = $locale->text('Purchase Order');
  961. $numberfld = "ponumber";
  962. $order = 1;
  963. }
  964. if ($form->{formname} eq 'bin_list') {
  965. $inv = "ord";
  966. $due = "req";
  967. $form->{label} = $locale->text('Bin List');
  968. $numberfld = "ponumber";
  969. $order = 1;
  970. }
  971. if ($form->{formname} eq 'sales_quotation') {
  972. $inv = "quo";
  973. $due = "req";
  974. $form->{label} = $locale->text('Quotation');
  975. $numberfld = "sqnumber";
  976. $order = 1;
  977. }
  978. if ($form->{formname} eq 'request_quotation') {
  979. $inv = "quo";
  980. $due = "req";
  981. $form->{label} = $locale->text('Quotation');
  982. $numberfld = "rfqnumber";
  983. $order = 1;
  984. }
  985. &validate_items;
  986. $form->{"${inv}date"} = $form->{transdate};
  987. $form->isblank("email", $locale->text('E-mail address missing!')) if ($form->{media} eq 'email');
  988. $form->isblank("${inv}date", $locale->text($form->{label} .' Date missing!'));
  989. # get next number
  990. if (! $form->{"${inv}number"}) {
  991. $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
  992. if ($form->{media} eq 'screen') {
  993. &update;
  994. exit;
  995. }
  996. }
  997. # $locale->text('Invoice Number missing!')
  998. # $locale->text('Invoice Date missing!')
  999. # $locale->text('Packing List Number missing!')
  1000. # $locale->text('Packing List Date missing!')
  1001. # $locale->text('Order Number missing!')
  1002. # $locale->text('Order Date missing!')
  1003. # $locale->text('Quotation Number missing!')
  1004. # $locale->text('Quotation Date missing!')
  1005. &{ "$form->{vc}_details" };
  1006. @a = ();
  1007. foreach $i (1 .. $form->{rowcount}) {
  1008. push @a, ("partnumber_$i", "description_$i", "projectnumber_$i", "partsgroup_$i", "serialnumber_$i", "bin_$i", "unit_$i", "notes_$i");
  1009. }
  1010. for (split / /, $form->{taxaccounts}) { push @a, "${_}_description" }
  1011. $ARAP = ($form->{vc} eq 'customer') ? "AR" : "AP";
  1012. push @a, $ARAP;
  1013. # format payment dates
  1014. for $i (1 .. $form->{paidaccounts} - 1) {
  1015. if (exists $form->{longformat}) {
  1016. $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
  1017. }
  1018. push @a, "${ARAP}_paid_$i", "source_$i", "memo_$i";
  1019. }
  1020. $form->format_string(@a);
  1021. ($form->{employee}) = split /--/, $form->{employee};
  1022. ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
  1023. # this is a label for the subtotals
  1024. $form->{groupsubtotaldescription} = $locale->text('Subtotal') if not exists $form->{groupsubtotaldescription};
  1025. delete $form->{groupsubtotaldescription} if $form->{deletegroupsubtotal};
  1026. $duedate = $form->{"${due}date"};
  1027. # create the form variables
  1028. if ($order) {
  1029. OE->order_details(\%myconfig, \%$form);
  1030. } else {
  1031. IS->invoice_details(\%myconfig, \%$form);
  1032. }
  1033. if (exists $form->{longformat}) {
  1034. $form->{"${due}date"} = $duedate;
  1035. for ("${inv}date", "${due}date", "shippingdate", "transdate") { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) }
  1036. }
  1037. @a = qw(name address1 address2 city state zipcode country contact phone fax email);
  1038. $shipto = 1;
  1039. # if there is no shipto fill it in from billto
  1040. foreach $item (@a) {
  1041. if ($form->{"shipto$item"}) {
  1042. $shipto = 0;
  1043. last;
  1044. }
  1045. }
  1046. if ($shipto) {
  1047. if ($form->{formname} eq 'purchase_order' || $form->{formname} eq 'request_quotation') {
  1048. $form->{shiptoname} = $myconfig{company};
  1049. $form->{shiptoaddress1} = $myconfig{address};
  1050. $form->{shiptoaddress1} =~ s/\\n/\n/g;
  1051. } else {
  1052. if ($form->{formname} !~ /bin_list/) {
  1053. for (@a) { $form->{"shipto$_"} = $form->{$_} }
  1054. }
  1055. }
  1056. }
  1057. # some of the stuff could have umlauts so we translate them
  1058. push @a, qw(contact shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptoemail shippingpoint shipvia notes intnotes employee warehouse);
  1059. push @a, ("${inv}number", "${inv}date", "${due}date");
  1060. for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
  1061. $form->{address} =~ s/\\n/\n/g;
  1062. for (qw(name email)) { $form->{"user$_"} = $myconfig{$_} }
  1063. push @a, qw(company address tel fax businessnumber username useremail);
  1064. for (qw(notes intnotes)) { $form->{$_} =~ s/^\s+//g }
  1065. # before we format replace <%var%>
  1066. for (qw(notes intnotes message)) { $form->{$_} =~ s/<%(.*?)%>/$form->{$1}/g }
  1067. $form->format_string(@a);
  1068. $form->{templates} = "$myconfig{templates}";
  1069. $form->{IN} = "$form->{formname}.$form->{format}";
  1070. if ($form->{format} =~ /(postscript|pdf)/) {
  1071. $form->{IN} =~ s/$&$/tex/;
  1072. }
  1073. $form->{pre} = "<body bgcolor=#ffffff>\n<pre>" if $form->{format} eq 'txt';
  1074. if ($form->{media} !~ /(screen|queue|email)/) {
  1075. $form->{OUT} = "${LedgerSMB::SysConfig::printer}{$form->{media}}";
  1076. $form->{printmode} = '|-';
  1077. $form->{OUT} =~ s/<%(fax)%>/<%$form->{vc}$1%>/;
  1078. $form->{OUT} =~ s/<%(.*?)%>/$form->{$1}/g;
  1079. if ($form->{printed} !~ /$form->{formname}/) {
  1080. $form->{printed} .= " $form->{formname}";
  1081. $form->{printed} =~ s/^ //;
  1082. $form->update_status(\%myconfig);
  1083. }
  1084. $old_form->{printed} = $form->{printed} if defined %$old_form;
  1085. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  1086. reference => $form->{"${inv}number"},
  1087. formname => $form->{formname},
  1088. action => 'printed',
  1089. id => $form->{id} );
  1090. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if defined %$old_form;
  1091. }
  1092. if ($form->{media} eq 'email') {
  1093. $form->{subject} = qq|$form->{label} $form->{"${inv}number"}| unless $form->{subject};
  1094. $form->{plainpaper} = 1;
  1095. $form->{OUT} = "${LedgerSMB::Sysconfig::sendmail}";
  1096. $form->{printmode} = '|-';
  1097. if ($form->{emailed} !~ /$form->{formname}/) {
  1098. $form->{emailed} .= " $form->{formname}";
  1099. $form->{emailed} =~ s/^ //;
  1100. # save status
  1101. $form->update_status(\%myconfig);
  1102. }
  1103. $now = scalar localtime;
  1104. $cc = $locale->text('Cc: [_1]', $form->{cc}).qq|\n| if $form->{cc};
  1105. $bcc = $locale->text('Bcc: [_1]', $form->{bcc}).qq|\n| if $form->{bcc};
  1106. if (defined %$old_form) {
  1107. $old_form->{intnotes} = qq|$old_form->{intnotes}\n\n| if $old_form->{intnotes};
  1108. $old_form->{intnotes} .= qq|[email]\n|
  1109. .$locale->text('Date: [_1]', $now).qq|\n|
  1110. .$locale->text('To: [_1]', $form->{email}).qq|\n${cc}${bcc}|
  1111. .$locale->text('Subject: [_1]', $form->{subject}).qq|\n|;
  1112. $old_form->{intnotes} .= qq|\n|.$locale->text('Message').qq|: |;
  1113. $old_form->{intnotes} .= ($form->{message}) ? $form->{message} : $locale->text('sent');
  1114. $old_form->{message} = $form->{message};
  1115. $old_form->{emailed} = $form->{emailed};
  1116. $old_form->{format} = "postscript" if $myconfig{printer};
  1117. $old_form->{media} = $myconfig{printer};
  1118. $old_form->save_intnotes(\%myconfig, ($order) ? 'oe' : lc $ARAP);
  1119. }
  1120. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  1121. reference => $form->{"${inv}number"},
  1122. formname => $form->{formname},
  1123. action => 'emailed',
  1124. id => $form->{id} );
  1125. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if defined %$old_form;
  1126. }
  1127. if ($form->{media} eq 'queue') {
  1128. %queued = split / /, $form->{queued};
  1129. if ($filename = $queued{$form->{formname}}) {
  1130. $form->{queued} =~ s/$form->{formname} $filename//;
  1131. unlink "${LedgerSMB::Sysconfig::spool}/$filename";
  1132. $filename =~ s/\..*$//g;
  1133. } else {
  1134. $filename = time;
  1135. $filename .= $$;
  1136. }
  1137. $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
  1138. $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
  1139. $form->{printmode} = '>';
  1140. $form->{queued} .= " $form->{formname} $filename";
  1141. $form->{queued} =~ s/^ //;
  1142. # save status
  1143. $form->update_status(\%myconfig);
  1144. $old_form->{queued} = $form->{queued};
  1145. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  1146. reference => $form->{"${inv}number"},
  1147. formname => $form->{formname},
  1148. action => 'queued',
  1149. id => $form->{id} );
  1150. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
  1151. }
  1152. $form->format_string("email", "cc", "bcc");
  1153. $form->{fileid} = $form->{"${inv}number"};
  1154. $form->{fileid} =~ s/(\s|\W)+//g;
  1155. $form->parse_template(\%myconfig, ${LedgerSMB::Sysconfig::userspath});
  1156. # if we got back here restore the previous form
  1157. if (defined %$old_form) {
  1158. $old_form->{"${inv}number"} = $form->{"${inv}number"};
  1159. # restore and display form
  1160. for (keys %$old_form) { $form->{$_} = $old_form->{$_} }
  1161. delete $form->{pre};
  1162. $form->{rowcount}--;
  1163. for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  1164. for $i (1 .. $form->{paidaccounts}) {
  1165. for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  1166. }
  1167. &{ "$display_form" };
  1168. }
  1169. }
  1170. sub customer_details {
  1171. IS->customer_details(\%myconfig, \%$form);
  1172. }
  1173. sub vendor_details {
  1174. IR->vendor_details(\%myconfig, \%$form);
  1175. }
  1176. sub ship_to {
  1177. $title = $form->{title};
  1178. $form->{title} = $locale->text('Ship to');
  1179. for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  1180. for (1 .. $form->{paidaccounts}) { $form->{"paid_$_"} = $form->parse_amount(\%myconfig, $form->{"paid_$_"}) }
  1181. # get details for name
  1182. &{ "$form->{vc}_details" };
  1183. $number = ($form->{vc} eq 'customer') ? $locale->text('Customer Number') : $locale->text('Vendor Number');
  1184. $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
  1185. $form->{rowcount}--;
  1186. $form->header;
  1187. print qq|
  1188. <body>
  1189. <form method=post action=$form->{script}>
  1190. <table width=100%>
  1191. <tr>
  1192. <td>
  1193. <table>
  1194. <tr class=listheading>
  1195. <th class=listheading colspan=2 width=50%>|.$locale->text('Billing Address').qq|</th>
  1196. <th class=listheading width=50%>|.$locale->text('Shipping Address').qq|</th>
  1197. </tr>
  1198. <tr height="5"></tr>
  1199. <tr>
  1200. <th align=right nowrap>$number</th>
  1201. <td>$form->{"$form->{vc}number"}</td>
  1202. </tr>
  1203. <tr>
  1204. <th align=right nowrap>|.$locale->text('Company Name').qq|</th>
  1205. <td>$form->{name}</td>
  1206. <td><input name=shiptoname size=35 maxlength=64 value="$form->{shiptoname}"></td>
  1207. </tr>
  1208. <tr>
  1209. <th align=right nowrap>|.$locale->text('Address').qq|</th>
  1210. <td>$form->{address1}</td>
  1211. <td><input name=shiptoaddress1 size=35 maxlength=32 value="$form->{shiptoaddress1}"></td>
  1212. </tr>
  1213. <tr>
  1214. <th></th>
  1215. <td>$form->{address2}</td>
  1216. <td><input name=shiptoaddress2 size=35 maxlength=32 value="$form->{shiptoaddress2}"></td>
  1217. </tr>
  1218. <tr>
  1219. <th align=right nowrap>|.$locale->text('City').qq|</th>
  1220. <td>$form->{city}</td>
  1221. <td><input name=shiptocity size=35 maxlength=32 value="$form->{shiptocity}"></td>
  1222. </tr>
  1223. <tr>
  1224. <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
  1225. <td>$form->{state}</td>
  1226. <td><input name=shiptostate size=35 maxlength=32 value="$form->{shiptostate}"></td>
  1227. </tr>
  1228. <tr>
  1229. <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
  1230. <td>$form->{zipcode}</td>
  1231. <td><input name=shiptozipcode size=10 maxlength=10 value="$form->{shiptozipcode}"></td>
  1232. </tr>
  1233. <tr>
  1234. <th align=right nowrap>|.$locale->text('Country').qq|</th>
  1235. <td>$form->{country}</td>
  1236. <td><input name=shiptocountry size=35 maxlength=32 value="$form->{shiptocountry}"></td>
  1237. </tr>
  1238. <tr>
  1239. <th align=right nowrap>|.$locale->text('Contact').qq|</th>
  1240. <td>$form->{contact}</td>
  1241. <td><input name=shiptocontact size=35 maxlength=64 value="$form->{shiptocontact}"></td>
  1242. </tr>
  1243. <tr>
  1244. <th align=right nowrap>|.$locale->text('Phone').qq|</th>
  1245. <td>$form->{"$form->{vc}phone"}</td>
  1246. <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
  1247. </tr>
  1248. <tr>
  1249. <th align=right nowrap>|.$locale->text('Fax').qq|</th>
  1250. <td>$form->{"$form->{vc}fax"}</td>
  1251. <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
  1252. </tr>
  1253. <tr>
  1254. <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
  1255. <td>$form->{email}</td>
  1256. <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
  1257. </tr>
  1258. </table>
  1259. </td>
  1260. </tr>
  1261. </table>
  1262. <input type=hidden name=nextsub value=$nextsub>
  1263. |;
  1264. # delete shipto
  1265. for (qw(action nextsub)) { delete $form->{$_} }
  1266. for (qw(name address1 address2 city state zipcode country contact phone fax email)) { delete $form->{"shipto$_"} }
  1267. $form->{title} = $title;
  1268. $form->hide_form;
  1269. print qq|
  1270. <hr size=3 noshade>
  1271. <br>
  1272. <button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  1273. </form>
  1274. </body>
  1275. </html>
  1276. |;
  1277. }