summaryrefslogtreecommitdiff
path: root/bin/io.pl
blob: 2caae7d7edbcb96939390f31efb1f524d609f38c (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. $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)) { $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=3>|.$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. <td colspan=3>|.$locale->text('Sort by').qq| ->
  881. <input name=sortby type=radio class=radio value=runningnumber $sortby{runningnumber}>
  882. |.$locale->text('Item').qq|
  883. <input name=sortby type=radio class=radio value=partnumber $sortby{partnumber}>
  884. |.$locale->text('Number').qq|
  885. <input name=sortby type=radio class=radio value=description $sortby{description}>
  886. |.$locale->text('Description').qq|
  887. <input name=sortby type=radio class=radio value=bin $sortby{bin}>
  888. |.$locale->text('Bin').qq|
  889. </td>
  890. </tr>
  891. </table>
  892. |;
  893. }
  894. sub print {
  895. # if this goes to the printer pass through
  896. if ($form->{media} !~ /(screen|email)/) {
  897. $form->error($locale->text('Select txt, postscript or PDF!')) if ($form->{format} !~ /(txt|postscript|pdf)/);
  898. $old_form = new Form;
  899. for (keys %$form) { $old_form->{$_} = $form->{$_} }
  900. }
  901. &print_form($old_form);
  902. }
  903. sub print_form {
  904. my ($old_form) = @_;
  905. $inv = "inv";
  906. $due = "due";
  907. $numberfld = "sinumber";
  908. $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
  909. if ($form->{formname} eq "invoice") {
  910. $form->{label} = $locale->text('Invoice');
  911. }
  912. if ($form->{formname} eq 'sales_order') {
  913. $inv = "ord";
  914. $due = "req";
  915. $form->{label} = $locale->text('Sales Order');
  916. $numberfld = "sonumber";
  917. $order = 1;
  918. }
  919. if ($form->{formname} eq 'work_order') {
  920. $inv = "ord";
  921. $due = "req";
  922. $form->{label} = $locale->text('Work Order');
  923. $numberfld = "sonumber";
  924. $order = 1;
  925. }
  926. if ($form->{formname} eq 'packing_list') {
  927. # we use the same packing list as from an invoice
  928. $form->{label} = $locale->text('Packing List');
  929. if ($form->{type} ne 'invoice') {
  930. $inv = "ord";
  931. $due = "req";
  932. $numberfld = "sonumber";
  933. $order = 1;
  934. $filled = 0;
  935. for ($i = 1; $i < $form->{rowcount}; $i++) {
  936. if ($form->{"ship_$i"}) {
  937. $filled = 1;
  938. last;
  939. }
  940. }
  941. if (!$filled) {
  942. for (1 .. $form->{rowcount}) { $form->{"ship_$_"} = $form->{"qty_$_"} }
  943. }
  944. }
  945. }
  946. if ($form->{formname} eq 'pick_list') {
  947. $form->{label} = $locale->text('Pick List');
  948. if ($form->{type} ne 'invoice') {
  949. $inv = "ord";
  950. $due = "req";
  951. $order = 1;
  952. $numberfld = "sonumber";
  953. }
  954. }
  955. if ($form->{formname} eq 'purchase_order') {
  956. $inv = "ord";
  957. $due = "req";
  958. $form->{label} = $locale->text('Purchase Order');
  959. $numberfld = "ponumber";
  960. $order = 1;
  961. }
  962. if ($form->{formname} eq 'bin_list') {
  963. $inv = "ord";
  964. $due = "req";
  965. $form->{label} = $locale->text('Bin List');
  966. $numberfld = "ponumber";
  967. $order = 1;
  968. }
  969. if ($form->{formname} eq 'sales_quotation') {
  970. $inv = "quo";
  971. $due = "req";
  972. $form->{label} = $locale->text('Quotation');
  973. $numberfld = "sqnumber";
  974. $order = 1;
  975. }
  976. if ($form->{formname} eq 'request_quotation') {
  977. $inv = "quo";
  978. $due = "req";
  979. $form->{label} = $locale->text('Quotation');
  980. $numberfld = "rfqnumber";
  981. $order = 1;
  982. }
  983. &validate_items;
  984. $form->{"${inv}date"} = $form->{transdate};
  985. $form->isblank("email", $locale->text('E-mail address missing!')) if ($form->{media} eq 'email');
  986. $form->isblank("${inv}date", $locale->text($form->{label} .' Date missing!'));
  987. # get next number
  988. if (! $form->{"${inv}number"}) {
  989. $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
  990. if ($form->{media} eq 'screen') {
  991. &update;
  992. exit;
  993. }
  994. }
  995. # $locale->text('Invoice Number missing!')
  996. # $locale->text('Invoice Date missing!')
  997. # $locale->text('Packing List Number missing!')
  998. # $locale->text('Packing List Date missing!')
  999. # $locale->text('Order Number missing!')
  1000. # $locale->text('Order Date missing!')
  1001. # $locale->text('Quotation Number missing!')
  1002. # $locale->text('Quotation Date missing!')
  1003. &{ "$form->{vc}_details" };
  1004. @a = ();
  1005. foreach $i (1 .. $form->{rowcount}) {
  1006. push @a, ("partnumber_$i", "description_$i", "projectnumber_$i", "partsgroup_$i", "serialnumber_$i", "bin_$i", "unit_$i", "notes_$i");
  1007. }
  1008. for (split / /, $form->{taxaccounts}) { push @a, "${_}_description" }
  1009. $ARAP = ($form->{vc} eq 'customer') ? "AR" : "AP";
  1010. push @a, $ARAP;
  1011. # format payment dates
  1012. for $i (1 .. $form->{paidaccounts} - 1) {
  1013. if (exists $form->{longformat}) {
  1014. $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
  1015. }
  1016. push @a, "${ARAP}_paid_$i", "source_$i", "memo_$i";
  1017. }
  1018. $form->format_string(@a);
  1019. ($form->{employee}) = split /--/, $form->{employee};
  1020. ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
  1021. # this is a label for the subtotals
  1022. $form->{groupsubtotaldescription} = $locale->text('Subtotal') if not exists $form->{groupsubtotaldescription};
  1023. delete $form->{groupsubtotaldescription} if $form->{deletegroupsubtotal};
  1024. $duedate = $form->{"${due}date"};
  1025. # create the form variables
  1026. if ($order) {
  1027. OE->order_details(\%myconfig, \%$form);
  1028. } else {
  1029. IS->invoice_details(\%myconfig, \%$form);
  1030. }
  1031. if (exists $form->{longformat}) {
  1032. $form->{"${due}date"} = $duedate;
  1033. for ("${inv}date", "${due}date", "shippingdate", "transdate") { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) }
  1034. }
  1035. @a = qw(name address1 address2 city state zipcode country contact phone fax email);
  1036. $shipto = 1;
  1037. # if there is no shipto fill it in from billto
  1038. foreach $item (@a) {
  1039. if ($form->{"shipto$item"}) {
  1040. $shipto = 0;
  1041. last;
  1042. }
  1043. }
  1044. if ($shipto) {
  1045. if ($form->{formname} eq 'purchase_order' || $form->{formname} eq 'request_quotation') {
  1046. $form->{shiptoname} = $myconfig{company};
  1047. $form->{shiptoaddress1} = $myconfig{address};
  1048. $form->{shiptoaddress1} =~ s/\\n/\n/g;
  1049. } else {
  1050. if ($form->{formname} !~ /bin_list/) {
  1051. for (@a) { $form->{"shipto$_"} = $form->{$_} }
  1052. }
  1053. }
  1054. }
  1055. # some of the stuff could have umlauts so we translate them
  1056. push @a, qw(contact shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptoemail shippingpoint shipvia notes intnotes employee warehouse);
  1057. push @a, ("${inv}number", "${inv}date", "${due}date");
  1058. for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
  1059. $form->{address} =~ s/\\n/\n/g;
  1060. for (qw(name email)) { $form->{"user$_"} = $myconfig{$_} }
  1061. push @a, qw(company address tel fax businessnumber username useremail);
  1062. for (qw(notes intnotes)) { $form->{$_} =~ s/^\s+//g }
  1063. # before we format replace <%var%>
  1064. for (qw(notes intnotes message)) { $form->{$_} =~ s/<%(.*?)%>/$form->{$1}/g }
  1065. $form->format_string(@a);
  1066. $form->{templates} = "$myconfig{templates}";
  1067. $form->{IN} = "$form->{formname}.$form->{format}";
  1068. if ($form->{format} =~ /(postscript|pdf)/) {
  1069. $form->{IN} =~ s/$&$/tex/;
  1070. }
  1071. $form->{pre} = "<body bgcolor=#ffffff>\n<pre>" if $form->{format} eq 'txt';
  1072. if ($form->{media} !~ /(screen|queue|email)/) {
  1073. $form->{OUT} = "${LedgerSMB::SysConfig::printer}{$form->{media}}";
  1074. $form->{printmode} = '|-';
  1075. $form->{OUT} =~ s/<%(fax)%>/<%$form->{vc}$1%>/;
  1076. $form->{OUT} =~ s/<%(.*?)%>/$form->{$1}/g;
  1077. if ($form->{printed} !~ /$form->{formname}/) {
  1078. $form->{printed} .= " $form->{formname}";
  1079. $form->{printed} =~ s/^ //;
  1080. $form->update_status(\%myconfig);
  1081. }
  1082. $old_form->{printed} = $form->{printed} if defined %$old_form;
  1083. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  1084. reference => $form->{"${inv}number"},
  1085. formname => $form->{formname},
  1086. action => 'printed',
  1087. id => $form->{id} );
  1088. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if defined %$old_form;
  1089. }
  1090. if ($form->{media} eq 'email') {
  1091. $form->{subject} = qq|$form->{label} $form->{"${inv}number"}| unless $form->{subject};
  1092. $form->{plainpaper} = 1;
  1093. $form->{OUT} = "${LedgerSMB::Sysconfig::sendmail}";
  1094. $form->{printmode} = '|-';
  1095. if ($form->{emailed} !~ /$form->{formname}/) {
  1096. $form->{emailed} .= " $form->{formname}";
  1097. $form->{emailed} =~ s/^ //;
  1098. # save status
  1099. $form->update_status(\%myconfig);
  1100. }
  1101. $now = scalar localtime;
  1102. $cc = $locale->text('Cc: [_1]', $form->{cc}).qq|\n| if $form->{cc};
  1103. $bcc = $locale->text('Bcc: [_1]', $form->{bcc}).qq|\n| if $form->{bcc};
  1104. if (defined %$old_form) {
  1105. $old_form->{intnotes} = qq|$old_form->{intnotes}\n\n| if $old_form->{intnotes};
  1106. $old_form->{intnotes} .= qq|[email]\n|
  1107. .$locale->text('Date: [_1]', $now).qq|\n|
  1108. .$locale->text('To: [_1]', $form->{email}).qq|\n${cc}${bcc}|
  1109. .$locale->text('Subject: [_1]', $form->{subject}).qq|\n|;
  1110. $old_form->{intnotes} .= qq|\n|.$locale->text('Message').qq|: |;
  1111. $old_form->{intnotes} .= ($form->{message}) ? $form->{message} : $locale->text('sent');
  1112. $old_form->{message} = $form->{message};
  1113. $old_form->{emailed} = $form->{emailed};
  1114. $old_form->{format} = "postscript" if $myconfig{printer};
  1115. $old_form->{media} = $myconfig{printer};
  1116. $old_form->save_intnotes(\%myconfig, ($order) ? 'oe' : lc $ARAP);
  1117. }
  1118. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  1119. reference => $form->{"${inv}number"},
  1120. formname => $form->{formname},
  1121. action => 'emailed',
  1122. id => $form->{id} );
  1123. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if defined %$old_form;
  1124. }
  1125. if ($form->{media} eq 'queue') {
  1126. %queued = split / /, $form->{queued};
  1127. if ($filename = $queued{$form->{formname}}) {
  1128. $form->{queued} =~ s/$form->{formname} $filename//;
  1129. unlink "${LedgerSMB::Sysconfig::spool}/$filename";
  1130. $filename =~ s/\..*$//g;
  1131. } else {
  1132. $filename = time;
  1133. $filename .= $$;
  1134. }
  1135. $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
  1136. $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
  1137. $form->{printmode} = '>';
  1138. $form->{queued} .= " $form->{formname} $filename";
  1139. $form->{queued} =~ s/^ //;
  1140. # save status
  1141. $form->update_status(\%myconfig);
  1142. $old_form->{queued} = $form->{queued};
  1143. %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
  1144. reference => $form->{"${inv}number"},
  1145. formname => $form->{formname},
  1146. action => 'queued',
  1147. id => $form->{id} );
  1148. $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
  1149. }
  1150. $form->format_string("email", "cc", "bcc");
  1151. $form->{fileid} = $form->{"${inv}number"};
  1152. $form->{fileid} =~ s/(\s|\W)+//g;
  1153. $form->parse_template(\%myconfig, ${LedgerSMB::Sysconfig::userspath});
  1154. # if we got back here restore the previous form
  1155. if (defined %$old_form) {
  1156. $old_form->{"${inv}number"} = $form->{"${inv}number"};
  1157. # restore and display form
  1158. for (keys %$old_form) { $form->{$_} = $old_form->{$_} }
  1159. delete $form->{pre};
  1160. $form->{rowcount}--;
  1161. for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  1162. for $i (1 .. $form->{paidaccounts}) {
  1163. for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  1164. }
  1165. &{ "$display_form" };
  1166. }
  1167. }
  1168. sub customer_details {
  1169. IS->customer_details(\%myconfig, \%$form);
  1170. }
  1171. sub vendor_details {
  1172. IR->vendor_details(\%myconfig, \%$form);
  1173. }
  1174. sub ship_to {
  1175. $title = $form->{title};
  1176. $form->{title} = $locale->text('Ship to');
  1177. for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  1178. for (1 .. $form->{paidaccounts}) { $form->{"paid_$_"} = $form->parse_amount(\%myconfig, $form->{"paid_$_"}) }
  1179. # get details for name
  1180. &{ "$form->{vc}_details" };
  1181. $number = ($form->{vc} eq 'customer') ? $locale->text('Customer Number') : $locale->text('Vendor Number');
  1182. $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
  1183. $form->{rowcount}--;
  1184. $form->header;
  1185. print qq|
  1186. <body>
  1187. <form method=post action=$form->{script}>
  1188. <table width=100%>
  1189. <tr>
  1190. <td>
  1191. <table>
  1192. <tr class=listheading>
  1193. <th class=listheading colspan=2 width=50%>|.$locale->text('Billing Address').qq|</th>
  1194. <th class=listheading width=50%>|.$locale->text('Shipping Address').qq|</th>
  1195. </tr>
  1196. <tr height="5"></tr>
  1197. <tr>
  1198. <th align=right nowrap>$number</th>
  1199. <td>$form->{"$form->{vc}number"}</td>
  1200. </tr>
  1201. <tr>
  1202. <th align=right nowrap>|.$locale->text('Company Name').qq|</th>
  1203. <td>$form->{name}</td>
  1204. <td><input name=shiptoname size=35 maxlength=64 value="$form->{shiptoname}"></td>
  1205. </tr>
  1206. <tr>
  1207. <th align=right nowrap>|.$locale->text('Address').qq|</th>
  1208. <td>$form->{address1}</td>
  1209. <td><input name=shiptoaddress1 size=35 maxlength=32 value="$form->{shiptoaddress1}"></td>
  1210. </tr>
  1211. <tr>
  1212. <th></th>
  1213. <td>$form->{address2}</td>
  1214. <td><input name=shiptoaddress2 size=35 maxlength=32 value="$form->{shiptoaddress2}"></td>
  1215. </tr>
  1216. <tr>
  1217. <th align=right nowrap>|.$locale->text('City').qq|</th>
  1218. <td>$form->{city}</td>
  1219. <td><input name=shiptocity size=35 maxlength=32 value="$form->{shiptocity}"></td>
  1220. </tr>
  1221. <tr>
  1222. <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
  1223. <td>$form->{state}</td>
  1224. <td><input name=shiptostate size=35 maxlength=32 value="$form->{shiptostate}"></td>
  1225. </tr>
  1226. <tr>
  1227. <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
  1228. <td>$form->{zipcode}</td>
  1229. <td><input name=shiptozipcode size=10 maxlength=10 value="$form->{shiptozipcode}"></td>
  1230. </tr>
  1231. <tr>
  1232. <th align=right nowrap>|.$locale->text('Country').qq|</th>
  1233. <td>$form->{country}</td>
  1234. <td><input name=shiptocountry size=35 maxlength=32 value="$form->{shiptocountry}"></td>
  1235. </tr>
  1236. <tr>
  1237. <th align=right nowrap>|.$locale->text('Contact').qq|</th>
  1238. <td>$form->{contact}</td>
  1239. <td><input name=shiptocontact size=35 maxlength=64 value="$form->{shiptocontact}"></td>
  1240. </tr>
  1241. <tr>
  1242. <th align=right nowrap>|.$locale->text('Phone').qq|</th>
  1243. <td>$form->{"$form->{vc}phone"}</td>
  1244. <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
  1245. </tr>
  1246. <tr>
  1247. <th align=right nowrap>|.$locale->text('Fax').qq|</th>
  1248. <td>$form->{"$form->{vc}fax"}</td>
  1249. <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
  1250. </tr>
  1251. <tr>
  1252. <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
  1253. <td>$form->{email}</td>
  1254. <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
  1255. </tr>
  1256. </table>
  1257. </td>
  1258. </tr>
  1259. </table>
  1260. <input type=hidden name=nextsub value=$nextsub>
  1261. |;
  1262. # delete shipto
  1263. for (qw(action nextsub)) { delete $form->{$_} }
  1264. for (qw(name address1 address2 city state zipcode country contact phone fax email)) { delete $form->{"shipto$_"} }
  1265. $form->{title} = $title;
  1266. $form->hide_form;
  1267. print qq|
  1268. <hr size=3 noshade>
  1269. <br>
  1270. <button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  1271. </form>
  1272. </body>
  1273. </html>
  1274. |;
  1275. }