/doc/plugins/rawhtml/

ript>
summaryrefslogtreecommitdiff
path: root/bin/oe.pl
blob: af15f373bb890a93ab5e22f7cd31c6a561d8a816 (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) 2001
  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. # Order entry module
  37. # Quotation module
  38. #
  39. #======================================================================
  40. use LedgerSMB::OE;
  41. use LedgerSMB::IR;
  42. use LedgerSMB::IS;
  43. use LedgerSMB::PE;
  44. use LedgerSMB::Tax;
  45. use LedgerSMB::Locale;
  46. require "bin/arap.pl";
  47. require "bin/io.pl";
  48. 1;
  49. # end of main
  50. sub add {
  51. if ( $form->{type} eq 'purchase_order' ) {
  52. $form->{title} = $locale->text('Add Purchase Order');
  53. $form->{vc} = 'vendor';
  54. }
  55. if ( $form->{type} eq 'sales_order' ) {
  56. $form->{title} = $locale->text('Add Sales Order');
  57. $form->{vc} = 'customer';
  58. }
  59. if ( $form->{type} eq 'request_quotation' ) {
  60. $form->{title} = $locale->text('Add Request for Quotation');
  61. $form->{vc} = 'vendor';
  62. }
  63. if ( $form->{type} eq 'sales_quotation' ) {
  64. $form->{title} = $locale->text('Add Quotation');
  65. $form->{vc} = 'customer';
  66. }
  67. $form->{callback} =
  68. "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}"
  69. unless $form->{callback};
  70. $form->{rowcount} = 0;
  71. &order_links;
  72. &prepare_order;
  73. &display_form;
  74. }
  75. sub edit {
  76. if ( $form->{type} =~ /(purchase_order|bin_list)/ ) {
  77. $form->{title} = $locale->text('Edit Purchase Order');
  78. $form->{vc} = 'vendor';
  79. $form->{type} = 'purchase_order';
  80. }
  81. if ( $form->{type} =~ /((sales|work)_order|(packing|pick)_list)/ ) {
  82. $form->{title} = $locale->text('Edit Sales Order');
  83. $form->{vc} = 'customer';
  84. $form->{type} = 'sales_order';
  85. }
  86. if ( $form->{type} eq 'request_quotation' ) {
  87. $form->{title} = $locale->text('Edit Request for Quotation');
  88. $form->{vc} = 'vendor';
  89. }
  90. if ( $form->{type} eq 'sales_quotation' ) {
  91. $form->{title} = $locale->text('Edit Quotation');
  92. $form->{vc} = 'customer';
  93. }
  94. &order_links;
  95. &prepare_order;
  96. &display_form;
  97. }
  98. sub order_links {
  99. # retrieve order/quotation
  100. OE->retrieve( \%myconfig, \%$form );
  101. # get customer/vendor
  102. $form->all_vc( \%myconfig, $form->{vc},
  103. ( $form->{vc} eq 'customer' ) ? "AR" : "AP",
  104. undef, $form->{transdate}, 1 );
  105. # currencies
  106. @curr = split /:/, $form->{currencies};
  107. $form->{defaultcurrency} = $curr[0];
  108. chomp $form->{defaultcurrency};
  109. $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
  110. for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
  111. $form->{oldlanguage_code} = $form->{language_code};
  112. $l{language_code} = $form->{language_code};
  113. $l{searchitems} = 'nolabor' if $form->{vc} eq 'customer';
  114. $form->get_partsgroup( \%myconfig, \%l );
  115. if ( @{ $form->{all_partsgroup} } ) {
  116. $form->{selectpartsgroup} = "<option>\n";
  117. foreach $ref ( @{ $form->{all_partsgroup} } ) {
  118. if ( $ref->{translation} ) {
  119. $form->{selectpartsgroup} .=
  120. qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{translation}\n|;
  121. }
  122. else {
  123. $form->{selectpartsgroup} .=
  124. qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|;
  125. }
  126. }
  127. }
  128. if ( @{ $form->{all_project} } ) {
  129. $form->{selectprojectnumber} = "<option>\n";
  130. for ( @{ $form->{all_project} } ) {
  131. $form->{selectprojectnumber} .=
  132. qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
  133. }
  134. }
  135. if ( @{ $form->{"all_$form->{vc}"} } ) {
  136. unless ( $form->{"$form->{vc}_id"} ) {
  137. $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
  138. }
  139. }
  140. for (qw(terms taxincluded)) { $temp{$_} = $form->{$_} }
  141. $form->{shipto} = 1 if $form->{id};
  142. # get customer / vendor
  143. AA->get_name( \%myconfig, \%$form );
  144. if ( $form->{id} ) {
  145. for (qw(terms taxincluded)) { $form->{$_} = $temp{$_} }
  146. }
  147. ( $form->{ $form->{vc} } ) = split /--/, $form->{ $form->{vc} };
  148. $form->{"old$form->{vc}"} =
  149. qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
  150. # build selection list
  151. $form->{"select$form->{vc}"} = "";
  152. if ( @{ $form->{"all_$form->{vc}"} } ) {
  153. $form->{ $form->{vc} } =
  154. qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
  155. for ( @{ $form->{"all_$form->{vc}"} } ) {
  156. $form->{"select$form->{vc}"} .=
  157. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  158. }
  159. }
  160. # departments
  161. if ( @{ $form->{all_department} } ) {
  162. $form->{selectdepartment} = "<option>\n";
  163. $form->{department} = "$form->{department}--$form->{department_id}"
  164. if $form->{department_id};
  165. for ( @{ $form->{all_department} } ) {
  166. $form->{selectdepartment} .=
  167. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  168. }
  169. }
  170. $form->{employee} = "$form->{employee}--$form->{employee_id}";
  171. # sales staff
  172. if ( @{ $form->{all_employee} } ) {
  173. $form->{selectemployee} = "";
  174. for ( @{ $form->{all_employee} } ) {
  175. $form->{selectemployee} .=
  176. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  177. }
  178. }
  179. if ( @{ $form->{all_language} } ) {
  180. $form->{selectlanguage} = "<option>\n";
  181. for ( @{ $form->{all_language} } ) {
  182. $form->{selectlanguage} .=
  183. qq|<option value="$_->{code}">$_->{description}\n|;
  184. }
  185. }
  186. # forex
  187. $form->{forex} = $form->{exchangerate};
  188. }
  189. sub prepare_order {
  190. $form->{format} = "postscript" if $myconfig{printer};
  191. $form->{media} = $myconfig{printer};
  192. $form->{formname} = $form->{type};
  193. $form->{sortby} ||= "runningnumber";
  194. $form->{currency} =~ s/ //g;
  195. $form->{oldcurrency} = $form->{currency};
  196. if ( $form->{id} ) {
  197. for (
  198. qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact)
  199. )
  200. {
  201. $form->{$_} = $form->quote( $form->{$_} );
  202. }
  203. foreach $ref ( @{ $form->{form_details} } ) {
  204. $i++;
  205. for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
  206. $form->{"projectnumber_$i"} =
  207. qq|$ref->{projectnumber}--$ref->{project_id}|
  208. if $ref->{project_id};
  209. $form->{"partsgroup_$i"} =
  210. qq|$ref->{partsgroup}--$ref->{partsgroup_id}|
  211. if $ref->{partsgroup_id};
  212. $form->{"discount_$i"} =
  213. $form->format_amount( \%myconfig, $form->{"discount_$i"} * 100 );
  214. ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
  215. $dec = length $dec;
  216. $decimalplaces = ( $dec > 2 ) ? $dec : 2;
  217. for ( map { "${_}_$i" } qw(sellprice listprice) ) {
  218. $form->{$_} =
  219. $form->format_amount( \%myconfig, $form->{$_},
  220. $decimalplaces );
  221. }
  222. ($dec) = ( $form->{"lastcost_$i"} =~ /\.(\d+)/ );
  223. $dec = length $dec;
  224. $decimalplaces = ( $dec > 2 ) ? $dec : 2;
  225. $form->{"lastcost_$i"} =
  226. $form->format_amount( \%myconfig, $form->{"lastcost_$i"},
  227. $decimalplaces );
  228. $form->{"qty_$i"} =
  229. $form->format_amount( \%myconfig, $form->{"qty_$i"} );
  230. $form->{"oldqty_$i"} = $form->{"qty_$i"};
  231. for (qw(partnumber sku description unit)) {
  232. $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} );
  233. }
  234. $form->{rowcount} = $i;
  235. }
  236. }
  237. $form->{oldtransdate} = $form->{transdate};
  238. if ( $form->{type} eq 'sales_quotation' ) {
  239. if ( !$form->{readonly} ) {
  240. $form->{readonly} = 1 if $myconfig{acs} =~ /Quotations--Quotation/;
  241. }
  242. $form->{selectformname} =
  243. qq|<option value="sales_quotation">| . $locale->text('Quotation');
  244. }
  245. if ( $form->{type} eq 'request_quotation' ) {
  246. if ( !$form->{readonly} ) {
  247. $form->{readonly} = 1 if $myconfig{acs} =~ /Quotations--RFQ/;
  248. }
  249. $form->{selectformname} =
  250. qq|<option value="request_quotation">| . $locale->text('RFQ');
  251. }
  252. if ( $form->{type} eq 'sales_order' ) {
  253. if ( !$form->{readonly} ) {
  254. $form->{readonly} = 1
  255. if $myconfig{acs} =~ /Order Entry--Sales Order/;
  256. }
  257. $form->{selectformname} =
  258. qq|<option value="sales_order">|
  259. . $locale->text('Sales Order') . qq|
  260. <option value="work_order">| . $locale->text('Work Order') . qq|
  261. <option value="pick_list">| . $locale->text('Pick List') . qq|
  262. <option value="packing_list">| . $locale->text('Packing List');
  263. }
  264. if ( $form->{type} eq 'purchase_order' ) {
  265. if ( !$form->{readonly} ) {
  266. $form->{readonly} = 1
  267. if $myconfig{acs} =~ /Order Entry--Purchase Order/;
  268. }
  269. $form->{selectformname} =
  270. qq|<option value="purchase_order">|
  271. . $locale->text('Purchase Order') . qq|
  272. <option value="bin_list">| . $locale->text('Bin List');
  273. }
  274. if ( $form->{type} eq 'ship_order' ) {
  275. $form->{selectformname} =
  276. qq|<option value="pick_list">|
  277. . $locale->text('Pick List') . qq|
  278. <option value="packing_list">| . $locale->text('Packing List');
  279. }
  280. if ( $form->{type} eq 'receive_order' ) {
  281. $form->{selectformname} =
  282. qq|<option value="bin_list">| . $locale->text('Bin List');
  283. }
  284. }
  285. sub form_header {
  286. $checkedopen = ( $form->{closed} ) ? "" : "checked";
  287. $checkedclosed = ( $form->{closed} ) ? "checked" : "";
  288. if ( $form->{id} ) {
  289. $openclosed = qq|
  290. <tr>
  291. <th nowrap align="right"><input name="closed" type="radio" class="radio" value="0" $checkedopen> |
  292. . $locale->text('Open')
  293. . qq|</th>
  294. <th nowrap align="left"><input name="closed" type="radio" class="radio" value="1" $checkedclosed> |
  295. . $locale->text('Closed')
  296. . qq|</th>
  297. </tr>
  298. |;
  299. }
  300. # set option selected
  301. $form->{selectcurrency} =~ s/ selected//;
  302. $form->{selectcurrency} =~
  303. s/option>\Q$form->{currency}\E/option selected>$form->{currency}/;
  304. for ( "$form->{vc}", "department", "employee" ) {
  305. $form->{"select$_"} = $form->unescape( $form->{"select$_"} );
  306. $form->{"select$_"} =~ s/ selected//;
  307. $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
  308. }
  309. $form->{exchangerate} =
  310. $form->format_amount( \%myconfig, $form->{exchangerate} );
  311. $exchangerate = qq|<tr>|;
  312. $exchangerate .= qq|
  313. <th align="right" nowrap>| . $locale->text('Currency') . qq|</th>
  314. <td><select name="currency">$form->{selectcurrency}</select></td> |
  315. if $form->{defaultcurrency};
  316. $exchangerate .= qq|
  317. <input type="hidden" name="selectcurrency" value="$form->{selectcurrency}">
  318. <input type="hidden" name="defaultcurrency" value="$form->{defaultcurrency}">
  319. |;
  320. if ( $form->{defaultcurrency}
  321. && $form->{currency} ne $form->{defaultcurrency} )
  322. {
  323. if ( $form->{forex} ) {
  324. $exchangerate .=
  325. qq|<th align="right">|
  326. . $locale->text('Exchange Rate')
  327. . qq|</th><td>$form->{exchangerate}</td>
  328. <input type="hidden" name="exchangerate" value="$form->{exchangerate}">
  329. |;
  330. }
  331. else {
  332. $exchangerate .=
  333. qq|<th align="right">|
  334. . $locale->text('Exchange Rate')
  335. . qq|</th><td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
  336. }
  337. }
  338. $exchangerate .= qq|
  339. <input type="hidden" name="forex" value="$form->{forex}">
  340. </tr>
  341. |;
  342. $vclabel = ucfirst $form->{vc};
  343. $vclabel = $locale->text($vclabel);
  344. $terms = qq|
  345. <tr>
  346. <th align="right" nowrap>| . $locale->text('Terms') . qq|</th>
  347. <td nowrap><input name="terms" size="3" maxlength="3" value="$form->{terms}"> |
  348. . $locale->text('days')
  349. . qq|</td>
  350. </tr>
  351. |;
  352. if ( $form->{business} ) {
  353. $business = qq|
  354. <tr>
  355. <th align="right" nowrap>| . $locale->text('Business') . qq|</th>
  356. <td colspan="3">$form->{business}
  357. &nbsp;&nbsp;&nbsp;|;
  358. $business .= qq|
  359. <b>| . $locale->text('Trade Discount') . qq|</b>
  360. | . $form->format_amount( \%myconfig, $form->{tradediscount} * 100 ) . qq| %|
  361. if $form->{vc} eq 'customer';
  362. $business .= qq|</td>
  363. </tr>
  364. |;
  365. }
  366. if ( $form->{type} !~ /_quotation$/ ) {
  367. $ordnumber = qq|
  368. <tr>
  369. <th width="70%" align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
  370. <td><input name="ordnumber" size="20" value="$form->{ordnumber}"></td>
  371. <input type="hidden" name="quonumber" value="$form->{quonumber}">
  372. </tr>
  373. <tr>
  374. <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
  375. <td><input name="transdate" size="11" title="$myconfig{dateformat}" value="$form->{transdate}"></td>
  376. </tr>
  377. <tr>
  378. <th align="right" nowrap="true">| . $locale->text('Required by') . qq|</th>
  379. <td><input name="reqdate" size="11" title="$myconfig{dateformat}" value="$form->{reqdate}"></td>
  380. </tr>
  381. <tr>
  382. <th align="right" nowrap>| . $locale->text('PO Number') . qq|</th>
  383. <td><input name="ponumber" size="20" value="$form->{ponumber}"></td>
  384. </tr>
  385. |;
  386. $n = ( $form->{creditremaining} < 0 ) ? "0" : "1";
  387. $creditremaining = qq|
  388. <tr>
  389. <td></td>
  390. <td colspan="3">
  391. <table>
  392. <tr>
  393. <th align="right" nowrap>| . $locale->text('Credit Limit') . qq|</th>
  394. <td>|
  395. . $form->format_amount( \%myconfig, $form->{creditlimit}, 0, "0" )
  396. . qq|</td>
  397. <td width="10"></td>
  398. <th align="right" nowrap>| . $locale->text('Remaining') . qq|</th>
  399. <td class="plus$n" nowrap>|
  400. . $form->format_amount( \%myconfig, $form->{creditremaining}, 0, "0" )
  401. . qq|</td>
  402. </tr>
  403. </table>
  404. </td>
  405. </tr>
  406. |;
  407. }
  408. else {
  409. $reqlabel =
  410. ( $form->{type} eq 'sales_quotation' )
  411. ? $locale->text('Valid until')
  412. : $locale->text('Required by');
  413. if ( $form->{type} eq 'sales_quotation' ) {
  414. $ordnumber = qq|
  415. <tr>
  416. <th width="70%" align="right" nowrap>|
  417. . $locale->text('Quotation Number')
  418. . qq|</th>
  419. <td><input name="quonumber" size="20" value="$form->{quonumber}"></td>
  420. <input type="hidden" name="ordnumber" value="$form->{ordnumber}">
  421. </tr>
  422. |;
  423. }
  424. else {
  425. $ordnumber = qq|
  426. <tr>
  427. <th width="70%" align="right" nowrap>| . $locale->text('RFQ Number') . qq|</th>
  428. <td><input name="quonumber" size="20" value="$form->{quonumber}"></td>
  429. <input type="hidden" name="ordnumber" value="$form->{ordnumber}">
  430. </tr>
  431. |;
  432. $terms = "";
  433. }
  434. $ordnumber .= qq|
  435. <tr>
  436. <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>