summaryrefslogtreecommitdiff
path: root/bin/ct.pl
blob: c7299b92c4b1c50582d00142d4ed1c95f3ec3567 (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. # Contributors: Reed White <alta@alta-research.com>
  22. #
  23. #
  24. #
  25. # This program is free software; you can redistribute it and/or modify
  26. # it under the terms of the GNU General Public License as published by
  27. # the Free Software Foundation; either version 2 of the License, or
  28. # (at your option) any later version.
  29. #
  30. # This program is distributed in the hope that it will be useful,
  31. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. # GNU General Public License for more details.
  34. # You should have received a copy of the GNU General Public License
  35. # along with this program; if not, write to the Free Software
  36. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  37. #======================================================================
  38. #
  39. # customer/vendor module
  40. #
  41. #======================================================================
  42. use LedgerSMB::CT;
  43. 1;
  44. # end of main
  45. sub add {
  46. $form->{title} = "Add";
  47. # $locale->text('Add Customer')
  48. # $locale->text('Add Vendor')
  49. $form->{callback} =
  50. "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  51. unless $form->{callback};
  52. CT->create_links( \%myconfig, \%$form );
  53. &form_header;
  54. &form_footer;
  55. }
  56. sub history {
  57. # $locale->text('Customer History')
  58. # $locale->text('Vendor History')
  59. $history = 1;
  60. $label = ucfirst $form->{db};
  61. $label .= " History";
  62. if ( $form->{db} eq 'customer' ) {
  63. $invlabel = $locale->text('Sales Invoices');
  64. $ordlabel = $locale->text('Sales Orders');
  65. $quolabel = $locale->text('Quotations');
  66. }
  67. else {
  68. $invlabel = $locale->text('Vendor Invoices');
  69. $ordlabel = $locale->text('Purchase Orders');
  70. $quolabel = $locale->text('Request for Quotations');
  71. }
  72. $form->{title} = $locale->text($label);
  73. $form->{nextsub} = "list_history";
  74. $transactions = qq|
  75. <tr>
  76. <td></td>
  77. <td>
  78. <table>
  79. <tr>
  80. <td>
  81. <table>
  82. <tr>
  83. <td><input name=type type=radio class=radio value=invoice checked> $invlabel</td>
  84. </tr>
  85. <tr>
  86. <td><input name=type type=radio class=radio value=order> $ordlabel</td>
  87. </tr>
  88. <tr>
  89. <td><input name="type" type=radio class=radio value=quotation> $quolabel</td>
  90. </tr>
  91. </table>
  92. </td>
  93. <td>
  94. <table>
  95. <tr>
  96. <th>| . $locale->text('From') . qq|</th>
  97. <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
  98. <th>| . $locale->text('To') . qq|</th>
  99. <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
  100. </tr>
  101. <tr>
  102. <td></td>
  103. <td colspan=3>
  104. <input name="open" type=checkbox class=checkbox value=Y checked>&nbsp;|
  105. . $locale->text('Open') . qq|
  106. <input name="closed" type=checkbox class=checkbox value=Y checked>&nbsp;|
  107. . $locale->text('Closed') . qq|
  108. </td>
  109. </tr>
  110. </table>
  111. </td>
  112. </tr>
  113. </table>
  114. </td>
  115. </tr>
  116. |;
  117. $include = qq|
  118. <tr>
  119. <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
  120. <td>
  121. <table>
  122. <tr>
  123. <td><input name=history type=radio class=radio value=summary checked> |
  124. . $locale->text('Summary')
  125. . qq|</td>
  126. <td><input name=history type=radio class=radio value=detail> |
  127. . $locale->text('Detail') . qq|
  128. </td>
  129. </tr>
  130. <tr>
  131. <td>
  132. <input name="l_partnumber" type=checkbox class=checkbox value=Y checked>&nbsp;|
  133. . $locale->text('Part Number') . qq|
  134. </td>
  135. <td>
  136. <input name="l_description" type=checkbox class=checkbox value=Y checked>&nbsp;|
  137. . $locale->text('Description') . qq|
  138. </td>
  139. <td>
  140. <input name="l_sellprice" type=checkbox class=checkbox value=Y checked>&nbsp;|
  141. . $locale->text('Sell Price') . qq|
  142. </td>
  143. <td>
  144. <input name="l_curr" type=checkbox class=checkbox value=Y>&nbsp;|
  145. . $locale->text('Currency') . qq|
  146. </td>
  147. </tr>
  148. <tr>
  149. <td>
  150. <input name="l_qty" type=checkbox class=checkbox value=Y>&nbsp;|
  151. . $locale->text('Qty') . qq|
  152. </td>
  153. <td>
  154. <input name="l_unit" type=checkbox class=checkbox value=Y>&nbsp;|
  155. . $locale->text('Unit') . qq|
  156. </td>
  157. <td>
  158. <input name="l_discount" type=checkbox class=checkbox value=Y>&nbsp;|
  159. . $locale->text('Discount') . qq|
  160. </td>
  161. <tr>
  162. </tr>
  163. <td>
  164. <input name="l_deliverydate" type=checkbox class=checkbox value=Y>&nbsp;|
  165. . $locale->text('Delivery Date') . qq|
  166. </td>
  167. <td>
  168. <input name="l_projectnumber" type=checkbox class=checkbox value=Y>&nbsp;|
  169. . $locale->text('Project Number') . qq|
  170. </td>
  171. <td>
  172. <input name="l_serialnumber" type=checkbox class=checkbox value=Y>&nbsp;|
  173. . $locale->text('Serial Number') . qq|
  174. </td>
  175. </tr>
  176. </table>
  177. </td>
  178. </tr>
  179. |;
  180. &search_name;
  181. if ( $form->{lynx} ) {
  182. require "bin/menu.pl";
  183. &menubar;
  184. }
  185. print qq|
  186. </body>
  187. </html>
  188. |;
  189. }
  190. sub transactions {
  191. if ( $form->{db} eq 'customer' ) {
  192. $translabel = $locale->text('AR Transactions');
  193. $invlabel = $locale->text('Sales Invoices');
  194. $ordlabel = $locale->text('Sales Orders');
  195. $quolabel = $locale->text('Quotations');
  196. }
  197. else {
  198. $translabel = $locale->text('AP Transactions');
  199. $invlabel = $locale->text('Vendor Invoices');
  200. $ordlabel = $locale->text('Purchase Orders');
  201. $quolabel = $locale->text('Request for Quotations');
  202. }
  203. $transactions = qq|
  204. <tr>
  205. <td></td>
  206. <td>
  207. <table>
  208. <tr>
  209. <td>
  210. <table>
  211. <tr>
  212. <td><input name="l_transnumber" type=checkbox class=checkbox value=Y> $translabel</td>
  213. </tr>
  214. <tr>
  215. <td><input name="l_invnumber" type=checkbox class=checkbox value=Y> $invlabel</td>
  216. </tr>
  217. <tr>
  218. <td><input name="l_ordnumber" type=checkbox class=checkbox value=Y> $ordlabel</td>
  219. </tr>
  220. <tr>
  221. <td><input name="l_quonumber" type=checkbox class=checkbox value=Y> $quolabel</td>
  222. </tr>
  223. </table>
  224. </td>
  225. <td>
  226. <table>
  227. <tr>
  228. <th>| . $locale->text('From') . qq|</th>
  229. <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
  230. <th>| . $locale->text('To') . qq|</th>
  231. <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
  232. </tr>
  233. <tr>
  234. <td></td>
  235. <td colspan=3>
  236. <input name="open" type=checkbox class=checkbox value=Y checked>&nbsp;|
  237. . $locale->text('Open') . qq|
  238. <input name="closed" type=checkbox class=checkbox value=Y checked>&nbsp;|
  239. . $locale->text('Closed') . qq|
  240. </td>
  241. </tr>
  242. <tr>
  243. <td></td>
  244. <td colspan=3>
  245. <input name="l_amount" type=checkbox class=checkbox value=Y checked>&nbsp;|
  246. . $locale->text('Amount') . qq|
  247. <input name="l_tax" type=checkbox class=checkbox value=Y checked>&nbsp;|
  248. . $locale->text('Tax') . qq|
  249. <input name="l_total" type=checkbox class=checkbox value=Y checked>&nbsp;|
  250. . $locale->text('Total') . qq|
  251. <input name="l_subtotal" type=checkbox class=checkbox value=Y>&nbsp;|
  252. . $locale->text('Subtotal') . qq|
  253. </td>
  254. </tr>
  255. </table>
  256. </td>
  257. </tr>
  258. </table>
  259. </td>
  260. </tr>
  261. |;
  262. }
  263. sub include_in_report {
  264. $label = ucfirst $form->{db};
  265. @a = ();
  266. push @a, qq|<input name="l_ndx" type=checkbox class=checkbox value=Y> |
  267. . $locale->text('No.');
  268. push @a, qq|<input name="l_id" type=checkbox class=checkbox value=Y> |
  269. . $locale->text('ID');
  270. push @a,
  271. qq|<input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |
  272. . $locale->text( $label . ' Number' );
  273. push @a,
  274. qq|<input name="l_name" type=checkbox class=checkbox value=Y $form->{l_name}> |
  275. . $locale->text('Company Name');
  276. push @a,
  277. qq|<input name="l_contact" type=checkbox class=checkbox value=Y $form->{l_contact}> |
  278. . $locale->text('Contact');
  279. push @a,
  280. qq|<input name="l_email" type=checkbox class=checkbox value=Y $form->{l_email}> |
  281. . $locale->text('E-mail');
  282. push @a, qq|<input name="l_address" type=checkbox class=checkbox value=Y> |
  283. . $locale->text('Address');
  284. push @a, qq|<input name="l_city" type=checkbox class=checkbox value=Y> |
  285. . $locale->text('City');
  286. push @a, qq|<input name="l_state" type=checkbox class=checkbox value=Y> |
  287. . $locale->text('State/Province');
  288. push @a, qq|<input name="l_zipcode" type=checkbox class=checkbox value=Y> |
  289. . $locale->text('Zip/Postal Code');
  290. push @a, qq|<input name="l_country" type=checkbox class=checkbox value=Y> |
  291. . $locale->text('Country');
  292. push @a,
  293. qq|<input name="l_phone" type=checkbox class=checkbox value=Y $form->{l_phone}> |
  294. . $locale->text('Phone');
  295. push @a, qq|<input name="l_fax" type=checkbox class=checkbox value=Y> |
  296. . $locale->text('Fax');
  297. push @a, qq|<input name="l_cc" type=checkbox class=checkbox value=Y> |
  298. . $locale->text('Cc');
  299. if ( $myconfig{role} =~ /(admin|manager)/ ) {
  300. push @a, qq|<input name="l_bcc" type=checkbox class=checkbox value=Y> |
  301. . $locale->text('Bcc');
  302. }
  303. push @a, qq|<input name="l_notes" type=checkbox class=checkbox value=Y> |
  304. . $locale->text('Notes');
  305. push @a, qq|<input name="l_discount" type=checkbox class=checkbox value=Y> |
  306. . $locale->text('Discount');
  307. push @a,
  308. qq|<input name="l_taxaccount" type=checkbox class=checkbox value=Y> |
  309. . $locale->text('Tax Account');
  310. push @a,
  311. qq|<input name="l_taxnumber" type=checkbox class=checkbox value=Y> |
  312. . $locale->text('Tax Number');
  313. if ( $form->{db} eq 'customer' ) {
  314. push @a,
  315. qq|<input name="l_employee" type=checkbox class=checkbox value=Y> |
  316. . $locale->text('Salesperson');
  317. push @a,
  318. qq|<input name="l_manager" type=checkbox class=checkbox value=Y> |
  319. . $locale->text('Manager');
  320. push @a,
  321. qq|<input name="l_pricegroup" type=checkbox class=checkbox value=Y> |
  322. . $locale->text('Pricegroup');
  323. }
  324. else {
  325. push @a,
  326. qq|<input name="l_employee" type=checkbox class=checkbox value=Y> |
  327. . $locale->text('Employee');
  328. push @a,
  329. qq|<input name="l_manager" type=checkbox class=checkbox value=Y> |
  330. . $locale->text('Manager');
  331. push @a,
  332. qq|<input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |
  333. . $locale->text('GIFI');
  334. }
  335. push @a, qq|<input name="l_sic_code" type=checkbox class=checkbox value=Y> |
  336. . $locale->text('SIC');
  337. push @a, qq|<input name="l_iban" type=checkbox class=checkbox value=Y> |
  338. . $locale->text('IBAN');
  339. push @a, qq|<input name="l_bic" type=checkbox class=checkbox value=Y> |
  340. . $locale->text('BIC');
  341. push @a, qq|<input name="l_business" type=checkbox class=checkbox value=Y> |
  342. . $locale->text('Type of Business');
  343. push @a, qq|<input name="l_terms" type=checkbox class=checkbox value=Y> |
  344. . $locale->text('Terms');
  345. push @a, qq|<input name="l_language" type=checkbox class=checkbox value=Y> |
  346. . $locale->text('Language');
  347. push @a,
  348. qq|<input name="l_startdate" type=checkbox class=checkbox value=Y> |
  349. . $locale->text('Startdate');
  350. push @a, qq|<input name="l_enddate" type=checkbox class=checkbox value=Y> |
  351. . $locale->text('Enddate');
  352. $include = qq|
  353. <tr>
  354. <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
  355. <td>
  356. <table>
  357. |;
  358. while (@a) {
  359. $include .= qq|<tr>\n|;
  360. for ( 1 .. 5 ) {
  361. $include .= qq|<td nowrap>| . shift @a;
  362. $include .= qq|</td>\n|;
  363. }
  364. $include .= qq|</tr>\n|;
  365. }
  366. $include .= qq|
  367. </table>
  368. </td>
  369. </tr>
  370. |;
  371. }
  372. sub search {
  373. # $locale->text('Customers')
  374. # $locale->text('Vendors')
  375. $form->{title} = $locale->text('Search') unless $form->{title};
  376. for (qw(name contact phone email)) { $form->{"l_$_"} = 'checked' }
  377. $form->{nextsub} = "list_names";
  378. $orphan = qq|
  379. <tr>
  380. <td></td>
  381. <td><input name=status class=radio type=radio value=all checked>&nbsp;|
  382. . $locale->text('All') . qq|
  383. <input name=status class=radio type=radio value=active>&nbsp;|
  384. . $locale->text('Active') . qq|
  385. <input name=status class=radio type=radio value=inactive>&nbsp;|
  386. . $locale->text('Inactive') . qq|
  387. <input name=status class=radio type=radio value=orphaned>&nbsp;|
  388. . $locale->text('Orphaned')
  389. . qq|</td>
  390. </tr>
  391. |;
  392. &transactions;
  393. &include_in_report;
  394. &search_name;
  395. if ( $form->{lynx} ) {
  396. require "bin/menu.pl";
  397. &menubar;
  398. }
  399. print qq|
  400. </body>
  401. </html>
  402. |;
  403. }
  404. sub search_name {
  405. $label = ucfirst $form->{db};
  406. if ( $form->{db} eq 'customer' ) {
  407. $employee = qq|
  408. <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
  409. <td><input name=employee size=32></td>
  410. |;
  411. }
  412. if ( $form->{db} eq 'vendor' ) {
  413. $employee = qq|
  414. <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
  415. <td><input name=employee size=32></td>
  416. |;
  417. }
  418. $form->header;
  419. print qq|
  420. <body>
  421. <form method=post action=$form->{script}>
  422. <input type=hidden name=db value="$form->{db}">
  423. <table width=100%>
  424. <tr>
  425. <th class=listtop>$form->{title}</th>
  426. </tr>
  427. <tr height="5"></tr>
  428. <tr valign=top>
  429. <td>
  430. <table>
  431. <tr valign=top>
  432. <td>
  433. <table>
  434. <tr>
  435. <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
  436. <td><input name=name size=32></td>
  437. </tr>
  438. <tr>
  439. <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
  440. <td><input name=contact size=32></td>
  441. </tr>
  442. <tr>
  443. <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
  444. <td><input name=email size=32></td>
  445. </tr>
  446. <tr>
  447. <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
  448. <td><input name=phone size=20></td>
  449. </tr>
  450. <tr>
  451. $employee
  452. </tr>
  453. <tr>
  454. <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
  455. <td colspan=3><textarea name=notes rows=3 cols=32></textarea></td>
  456. </tr>
  457. </table>
  458. </td>
  459. <td>
  460. <table>
  461. <tr>
  462. <th align=right nowrap>| . $locale->text( $label . ' Number' ) . qq|</th>
  463. <td><input name=$form->{db}number size=32></td>
  464. </tr>
  465. <tr>
  466. <th align=right nowrap>| . $locale->text('Address') . qq|</th>
  467. <td><input name=address size=32></td>
  468. </tr>
  469. <tr>
  470. <th align=right nowrap>| . $locale->text('City') . qq|</th>
  471. <td><input name=city size=32></td>
  472. </tr>
  473. <tr>
  474. <th align=right nowrap>| . $locale->text('State/Province') . qq|</th>
  475. <td><input name=state size=32></td>
  476. </tr>
  477. <tr>
  478. <th align=right nowrap>| . $locale->text('Zip/Postal Code') . qq|</th>
  479. <td><input name=zipcode size=10></td>
  480. </tr>
  481. <tr>
  482. <th align=right nowrap>| . $locale->text('Country') . qq|</th>
  483. <td><input name=country size=32></td>
  484. </tr>
  485. <tr>
  486. <th align=right nowrap>| . $locale->text('Startdate') . qq|</th>
  487. <td>|
  488. . $locale->text('From')
  489. . qq| <input name=startdatefrom size=11 title="$myconfig{dateformat}"> |
  490. . $locale->text('To')
  491. . qq| <input name=startdateto size=11 title="$myconfig{dateformat}"></td>
  492. </tr>
  493. </table>
  494. </td>
  495. </tr>
  496. </table>
  497. </td>
  498. </tr>
  499. <tr>
  500. <td>
  501. <table>
  502. $orphan
  503. $transactions
  504. $include
  505. </table>
  506. </td>
  507. </tr>
  508. <tr>
  509. <td><hr size=3 noshade></td>
  510. </tr>
  511. </table>
  512. <input type="hidden" name="nextsub" value="$form->{nextsub}">
  513. <input type="hidden" name="path" value="$form->{path}">
  514. <input type="hidden" name="login" value="$form->{login}">
  515. <input type="hidden" name="sessionid" value="$form->{sessionid}">
  516. <br>
  517. <button type="submit" class="submit" name="action" value="continue">|
  518. . $locale->text('Continue')
  519. . qq|</button>
  520. </form>
  521. |;
  522. }
  523. sub list_names {
  524. CT->search( \%myconfig, \%$form );
  525. $href =
  526. "$form->{script}?action=list_names&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&l_subtotal=$form->{l_subtotal}";
  527. $form->sort_order();
  528. $callback =
  529. "$form->{script}?action=list_names&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&l_subtotal=$form->{l_subtotal}";
  530. @columns = $form->sort_columns( id, name, "$form->{db}number", address,
  531. city, state, zipcode, country,
  532. contact, phone, fax, email,
  533. cc, bcc, employee, manager,
  534. notes, discount, terms, taxaccount,
  535. taxnumber, gifi_accno, sic_code, business,
  536. pricegroup, language, iban, bic,
  537. startdate, enddate, invnumber, invamount,
  538. invtax, invtotal, ordnumber, ordamount,
  539. ordtax, ordtotal, quonumber, quoamount,
  540. quotax, quototal
  541. );
  542. unshift @columns, "ndx";
  543. $form->{l_invnumber} = "Y" if $form->{l_transnumber};
  544. foreach $item (qw(inv ord quo)) {
  545. if ( $form->{"l_${item}number"} ) {
  546. for (qw(amount tax total)) {
  547. $form->{"l_$item$_"} = $form->{"l_$_"};
  548. }
  549. $removeemployee = 1;
  550. $openclosed = 1;
  551. }
  552. }
  553. $form->{open} = $form->{closed} = "" if !$openclosed;
  554. foreach $item (@columns) {
  555. if ( $form->{"l_$item"} eq "Y" ) {
  556. push @column_index, $item;
  557. # add column to href and callback
  558. $callback .= "&l_$item=Y";
  559. $href .= "&l_$item=Y";
  560. }
  561. }
  562. foreach $item (qw(amount tax total transnumber)) {
  563. if ( $form->{"l_$item"} eq "Y" ) {
  564. $callback .= "&l_$item=Y";
  565. $href .= "&l_$item=Y";
  566. }
  567. }
  568. if ( $form->{status} eq 'all' ) {
  569. $option = $locale->text('All');
  570. }
  571. if ( $form->{status} eq 'orphaned' ) {
  572. $option = $locale->text('Orphaned');
  573. }
  574. if ( $form->{status} eq 'active' ) {
  575. $option = $locale->text('Active');
  576. }
  577. if ( $form->{status} eq 'inactive' ) {
  578. $option = $locale->text('Inactive');
  579. }
  580. if ( $form->{name} ) {
  581. $callback .= "&name=" . $form->escape( $form->{name}, 1 );
  582. $href .= "&name=" . $form->escape( $form->{name} );
  583. $option .= "\n<br>" . $locale->text('Name') . " : $form->{name}";
  584. }
  585. if ( $form->{address} ) {
  586. $callback .= "&address=" . $form->escape( $form->{address}, 1 );
  587. $href .= "&address=" . $form->escape( $form->{address} );
  588. $option .= "\n<br>" . $locale->text('Address') . " : $form->{address}";
  589. }
  590. if ( $form->{city} ) {
  591. $callback .= "&city=" . $form->escape( $form->{city}, 1 );
  592. $href .= "&city=" . $form->escape( $form->{city} );
  593. $option .= "\n<br>" . $locale->text('City') . " : $form->{city}";
  594. }
  595. if ( $form->{state} ) {
  596. $callback .= "&state=" . $form->escape( $form->{state}, 1 );
  597. $href .= "&state=" . $form->escape( $form->{state} );
  598. $option .= "\n<br>" . $locale->text('State') . " : $form->{state}";
  599. }
  600. if ( $form->{zipcode} ) {
  601. $callback .= "&zipcode=" . $form->escape( $form->{zipcode}, 1 );
  602. $href .= "&zipcode=" . $form->escape( $form->{zipcode} );
  603. $option .=
  604. "\n<br>" . $locale->text('Zip/Postal Code') . " : $form->{zipcode}";
  605. }
  606. if ( $form->{country} ) {
  607. $callback .= "&country=" . $form->escape( $form->{country}, 1 );
  608. $href .= "&country=" . $form->escape( $form->{country} );
  609. $option .= "\n<br>" . $locale->text('Country') . " : $form->{country}";
  610. }
  611. if ( $form->{contact} ) {
  612. $callback .= "&contact=" . $form->escape( $form->{contact}, 1 );
  613. $href .= "&contact=" . $form->escape( $form->{contact} );
  614. $option .= "\n<br>" . $locale->text('Contact') . " : $form->{contact}";
  615. }
  616. if ( $form->{employee} ) {
  617. $callback .= "&employee=" . $form->escape( $form->{employee}, 1 );
  618. $href .= "&employee=" . $form->escape( $form->{employee} );
  619. $option .= "\n<br>";
  620. if ( $form->{db} eq 'customer' ) {
  621. $option .= $locale->text('Salesperson');
  622. }
  623. if ( $form->{db} eq 'vendor' ) {
  624. $option .= $locale->text('Employee');
  625. }
  626. $option .= " : $form->{employee}";
  627. }
  628. $fromdate = "";
  629. $todate = "";
  630. if ( $form->{startdatefrom} ) {
  631. $callback .= "&startdatefrom=$form->{startdatefrom}";
  632. $href .= "&startdatefrom=$form->{startdatefrom}";
  633. $fromdate = $locale->date( \%myconfig, $form->{startdatefrom}, 1 );
  634. }
  635. if ( $form->{startdateto} ) {
  636. $callback .= "&startdateto=$form->{startdateto}";
  637. $href .= "&startdateto=$form->{startdateto}";
  638. $todate = $locale->date( \%myconfig, $form->{startdateto}, 1 );
  639. }
  640. if ( $fromdate || $todate ) {
  641. $option .=
  642. "\n<br>" . $locale->text('Startdate') . " $fromdate - $todate";
  643. }
  644. if ( $form->{notes} ) {
  645. $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
  646. $href .= "&notes=" . $form->escape( $form->{notes} );
  647. $option .= "\n<br>" . $locale->text('Notes') . " : $form->{notes}";
  648. }
  649. if ( $form->{"$form->{db}number"} ) {
  650. $callback .=
  651. qq|&$form->{db}number=|
  652. . $form->escape( $form->{"$form->{db}number"}, 1 );
  653. $href .=
  654. "&$form->{db}number=" . $form->escape( $form->{"$form->{db}number"} );
  655. $option .= "\n<br>"
  656. . $locale->text('Number')
  657. . qq| : $form->{"$form->{db}number"}|;
  658. }
  659. if ( $form->{phone} ) {
  660. $callback .= "&phone=" . $form->escape( $form->{phone}, 1 );
  661. $href .= "&phone=" . $form->escape( $form->{phone} );
  662. $option .= "\n<br>" . $locale->text('Phone') . " : $form->{phone}";
  663. }
  664. if ( $form->{email} ) {
  665. $callback .= "&email=" . $form->escape( $form->{email}, 1 );
  666. $href .= "&email=" . $form->escape( $form->{email} );
  667. $option .= "\n<br>" . $locale->text('E-mail') . " : $form->{email}";
  668. }
  669. if ( $form->{transdatefrom} ) {
  670. $callback .= "&transdatefrom=$form->{transdatefrom}";
  671. $href .= "&transdatefrom=$form->{transdatefrom}";
  672. $option .= "\n<br>" if ($option);
  673. $option .=
  674. $locale->text('From') . "&nbsp;"
  675. . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
  676. }
  677. if ( $form->{transdateto} ) {
  678. $callback .= "&transdateto=$form->{transdateto}";
  679. $href .= "&transdateto=$form->{transdateto}";
  680. if ( $form->{transdatefrom} ) {
  681. $option .= " ";
  682. }
  683. else {
  684. $option .= "\n<br>" if ($option);
  685. }
  686. $option .=
  687. $locale->text('To') . "&nbsp;"
  688. . $locale->date( \%myconfig, $form->{transdateto}, 1 );
  689. }
  690. if ( $form->{open} ) {
  691. $callback .= "&open=$form->{open}";
  692. $href .= "&open=$form->{open}";
  693. $option .= "\n<br>" if ($option);
  694. $option .= $locale->text('Open');
  695. }
  696. if ( $form->{closed} ) {
  697. $callback .= "&closed=$form->{closed}";
  698. $href .= "&closed=$form->{closed}";
  699. $option .= "\n<br>" if ($option);
  700. $option .= $locale->text('Closed');
  701. }
  702. $form->{callback} = "$callback&sort=$form->{sort}";
  703. $callback = $form->escape( $form->{callback} );
  704. $column_header{ndx} = qq|<th class=listheading>&nbsp;</th>|;
  705. $column_header{id} =
  706. qq|<th class=listheading>| . $locale->text('ID') . qq|</th>|;
  707. $column_header{"$form->{db}number"} =
  708. qq|<th><a class=listheading href=$href&sort=$form->{db}number>|
  709. . $locale->text('Number')
  710. . qq|</a></th>|;
  711. $column_header{name} =
  712. qq|<th><a class=listheading href=$href&sort=name>|
  713. . $locale->text('Name')
  714. . qq|</a></th>|;
  715. $column_header{address} =
  716. qq|<th class=listheading>| . $locale->text('Address') . qq|</th>|;
  717. $column_header{city} =
  718. qq|<th><a class=listheading href=$href&sort=city>|
  719. . $locale->text('City')
  720. . qq|</a></th>|;
  721. $column_header{state} =
  722. qq|<th><a class=listheading href=$href&sort=state>|
  723. . $locale->text('State/Province')
  724. . qq|</a></th>|;
  725. $column_header{zipcode} =
  726. qq|<th><a class=listheading href=$href&sort=zipcode>|
  727. . $locale->text('Zip/Postal Code')
  728. . qq|</a></th>|;
  729. $column_header{country} =
  730. qq|<th><a class=listheading href=$href&sort=country>|
  731. . $locale->text('Country')
  732. . qq|</a></th>|;
  733. $column_header{contact} =
  734. qq|<th><a class=listheading href=$href&sort=contact>|
  735. . $locale->text('Contact')
  736. . qq|</a></th>|;
  737. $column_header{phone} =
  738. qq|<th><a class=listheading href=$href&sort=phone>|
  739. . $locale->text('Phone')
  740. . qq|</a></th>|;
  741. $column_header{fax} =
  742. qq|<th><a class=listheading href=$href&sort=fax>|
  743. . $locale->text('Fax')
  744. . qq|</a></th>|;
  745. $column_header{email} =
  746. qq|<th><a class=listheading href=$href&sort=email>|
  747. . $locale->text('E-mail')
  748. . qq|</a></th>|;
  749. $column_header{cc} =
  750. qq|<th><a class=listheading href=$href&sort=cc>|
  751. . $locale->text('Cc')
  752. . qq|</a></th>|;
  753. $column_header{bcc} =
  754. qq|<th><a class=listheading href=$href&sort=cc>|
  755. . $locale->text('Bcc')
  756. . qq|</a></th>|;
  757. $column_header{notes} =
  758. qq|<th><a class=listheading href=$href&sort=notes>|
  759. . $locale->text('Notes')
  760. . qq|</a></th>|;
  761. $column_header{discount} = qq|<th class=listheading>%</th>|;
  762. $column_header{terms} =
  763. qq|<th class=listheading>| . $locale->text('Terms') . qq|</th>|;
  764. $column_header{taxnumber} =
  765. qq|<th><a class=listheading href=$href&sort=taxnumber>|
  766. . $locale->text('Tax Number')
  767. . qq|</a></th>|;
  768. $column_header{taxaccount} =
  769. qq|<th class=listheading>| . $locale->text('Tax Account') . qq|</th>|;
  770. $column_header{gifi_accno} =
  771. qq|<th><a class=listheading href=$href&sort=gifi_accno>|
  772. . $locale->text('GIFI')
  773. . qq|</a></th>|;
  774. $column_header{sic_code} =
  775. qq|<th><a class=listheading href=$href&sort=sic_code>|
  776. . $locale->text('SIC')
  777. . qq|</a></th>|;
  778. $column_header{business} =
  779. qq|<th><a class=listheading href=$href&sort=business>|
  780. . $locale->text('Type of Business')
  781. . qq|</a></th>|;
  782. $column_header{iban} =
  783. qq|<th class=listheading>| . $locale->text('IBAN') . qq|</th>|;
  784. $column_header{bic} =
  785. qq|<th class=listheading>| . $locale->text('BIC') . qq|</th>|;
  786. $column_header{startdate} =
  787. qq|<th><a class=listheading href=$href&sort=startdate>|
  788. . $locale->text('Startdate')
  789. . qq|</a></th>|;
  790. $column_header{enddate} =
  791. qq|<th><a class=listheading href=$href&sort=enddate>|
  792. . $locale->text('Enddate')
  793. . qq|</a></th>|;
  794. $column_header{invnumber} =
  795. qq|<th><a class=listheading href=$href&sort=invnumber>|
  796. . $locale->text('Invoice')
  797. . qq|</a></th>|;
  798. $column_header{ordnumber} =
  799. qq|<th><a class=listheading href=$href&sort=ordnumber>|
  800. . $locale->text('Order')
  801. . qq|</a></th>|;
  802. $column_header{quonumber} =
  803. qq|<th><a class=listheading href=$href&sort=quonumber>|
  804. . $locale->text('Quotation')
  805. . qq|</a></th>|;
  806. if ( $form->{db} eq 'customer' ) {
  807. $column_header{employee} =
  808. qq|<th><a class=listheading href=$href&sort=employee>|
  809. . $locale->text('Salesperson')
  810. . qq|</a></th>|;
  811. }
  812. else {
  813. $column_header{employee} =
  814. qq|<th><a class=listheading href=$href&sort=employee>|
  815. . $locale->text('Employee')
  816. . qq|</a></th>|;
  817. }
  818. $column_header{manager} =
  819. qq|<th><a class=listheading href=$href&sort=manager>|
  820. . $locale->text('Manager')
  821. . qq|</a></th>|;
  822. $column_header{pricegroup} =
  823. qq|<th><a class=listheading href=$href&sort=pricegroup>|
  824. . $locale->text('Pricegroup')
  825. . qq|</a></th>|;
  826. $column_header{language} =
  827. qq|<th><a class=listheading href=$href&sort=language>|
  828. . $locale->text('Language')
  829. . qq|</a></th>|;
  830. $amount = $locale->text('Amount');
  831. $tax = $locale->text('Tax');
  832. $total = $locale->text('Total');
  833. $column_header{invamount} = qq|<th class=listheading>$amount</th>|;
  834. $column_header{ordamount} = qq|<th class=listheading>$amount</th>|;
  835. $column_header{quoamount} = qq|<th class=listheading>$amount</th>|;
  836. $column_header{invtax} = qq|<th class=listheading>$tax</th>|;
  837. $column_header{ordtax} = qq|<th class=listheading>$tax</th>|;
  838. $column_header{quotax} = qq|<th class=listheading>$tax</th>|;
  839. $column_header{invtotal} = qq|<th class=listheading>$total</th>|;
  840. $column_header{ordtotal} = qq|<th class=listheading>$total</th>|;
  841. $column_header{quototal} = qq|<th class=listheading>$total</th>|;
  842. if ( $form->{status} ) {
  843. $label = ucfirst $form->{db} . "s";
  844. $form->{title} = $locale->text($label);
  845. }
  846. else {
  847. $label = ucfirst $form->{db};
  848. $form->{title} = $locale->text( $label . " Transactions" );
  849. }
  850. $form->header;
  851. print qq|
  852. <body>
  853. <table width=100%>
  854. <tr>
  855. <th class=listtop>$form->{title}</th>
  856. </tr>
  857. <tr height="5"></tr>
  858. <tr>
  859. <td>$option</td>
  860. </tr>
  861. <tr>
  862. <td>
  863. <table width=100%>
  864. <tr class=listheading>
  865. |;
  866. for (@column_index) { print "$column_header{$_}\n" }
  867. print qq|
  868. </tr>
  869. |;
  870. $ordertype =
  871. ( $form->{db} eq 'customer' ) ? 'sales_order' : 'purchase_order';
  872. $quotationtype =
  873. ( $form->{db} eq 'customer' ) ? 'sales_quotation' : 'request_quotation';
  874. $subtotal = 0;
  875. $i = 0;
  876. foreach $ref ( @{ $form->{CT} } ) {
  877. if ( $ref->{ $form->{sort} } ne $sameitem && $form->{l_subtotal} ) {
  878. # print subtotal
  879. if ($subtotal) {
  880. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  881. &list_subtotal;
  882. }
  883. }
  884. if ( $ref->{id} eq $sameid ) {
  885. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  886. }
  887. else {
  888. $i++;
  889. $ref->{notes} =~ s/\r?\n/<br>/g;
  890. for (@column_index) {
  891. $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
  892. }
  893. $column_data{ndx} = "<td align=right>$i</td>";
  894. if ( $ref->{ $form->{sort} } eq $sameitem ) {
  895. $column_data{ $form->{sort} } = "<td>&nbsp;</td>";
  896. }
  897. $column_data{address} =
  898. "<td>$ref->{address1} $ref->{address2}&nbsp;</td>";
  899. $column_data{name} =
  900. "<td><a href=$form->{script}?action=edit&id=$ref->{id}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&callback=$callback>$ref->{name}&nbsp;</td>";
  901. $email = "";
  902. if ( $form->{sort} =~ /(email|cc)/ ) {
  903. if ( $ref->{ $form->{sort} } ne $sameitem ) {
  904. $email = 1;
  905. }
  906. }
  907. else {
  908. $email = 1;
  909. }
  910. if ($email) {
  911. foreach $item (qw(email cc bcc)) {
  912. if ( $ref->{$item} ) {
  913. $email = $ref->{$item};
  914. $email =~ s/</\&lt;/;
  915. $email =~ s/>/\&gt;/;
  916. $column_data{$item} =
  917. qq|<td><a href="mailto:$ref->{$item}">$email</a></td>|;
  918. }
  919. }
  920. }
  921. }
  922. if ( $ref->{formtype} eq 'invoice' ) {
  923. $column_data{invnumber} =
  924. "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}&nbsp;</td>";
  925. $column_data{invamount} =
  926. "<td align=right>"
  927. . $form->format_amount( \%myconfig, $ref->{netamount}, 2,
  928. "&nbsp;" )
  929. . "</td>";
  930. $column_data{invtax} = "<td align=right>"
  931. . $form->format_amount( \%myconfig,
  932. $ref->{amount} - $ref->{netamount},
  933. 2, "&nbsp;" )
  934. . "</td>";
  935. $column_data{invtotal} =
  936. "<td align=right>"
  937. . $form->format_amount( \%myconfig, $ref->{amount}, 2, "&nbsp;" )
  938. . "</td>";
  939. $invamountsubtotal += $ref->{netamount};
  940. $invtaxsubtotal += ( $ref->{amount} - $ref->{netamount} );
  941. $invtotalsubtotal += $ref->{amount};
  942. $subtotal = 1;
  943. }
  944. if ( $ref->{formtype} eq 'order' ) {
  945. $column_data{ordnumber} =
  946. "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{ordnumber}&nbsp;</td>";
  947. $column_data{ordamount} =
  948. "<td align=right>"
  949. . $form->format_amount( \%myconfig, $ref->{netamount}, 2,
  950. "&nbsp;" )
  951. . "</td>";
  952. $column_data{ordtax} = "<td align=right>"
  953. . $form->format_amount( \%myconfig,
  954. $ref->{amount} - $ref->{netamount},
  955. 2, "&nbsp;" )
  956. . "</td>";
  957. $column_data{ordtotal} =
  958. "<td align=right>"
  959. . $form->format_amount( \%myconfig, $ref->{amount}, 2, "&nbsp;" )
  960. . "</td>";
  961. $ordamountsubtotal += $ref->{netamount};
  962. $ordtaxsubtotal += ( $ref->{amount} - $ref->{netamount} );
  963. $ordtotalsubtotal += $ref->{amount};
  964. $subtotal = 1;
  965. }
  966. if ( $ref->{formtype} eq 'quotation' ) {
  967. $column_data{quonumber} =
  968. "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{quonumber}&nbsp;</td>";
  969. $column_data{quoamount} =
  970. "<td align=right>"
  971. . $form->format_amount( \%myconfig, $ref->{netamount}, 2,
  972. "&nbsp;" )
  973. . "</td>";
  974. $column_data{quotax} = "<td align=right>"
  975. . $form->format_amount( \%myconfig,
  976. $ref->{amount} - $ref->{netamount},
  977. 2, "&nbsp;" )
  978. . "</td>";
  979. $column_data{quototal} =
  980. "<td align=right>"
  981. . $form->format_amount( \%myconfig, $ref->{amount}, 2, "&nbsp;" )
  982. . "</td>";
  983. $quoamountsubtotal += $ref->{netamount};
  984. $quotaxsubtotal += ( $ref->{amount} - $ref->{netamount} );
  985. $quototalsubtotal += $ref->{amount};
  986. $subtotal = 1;
  987. }
  988. if ( $sameid ne "$ref->{id}" ) {
  989. if ( $form->{l_discount} ) {
  990. $column_data{discount} = "<td align=right>"
  991. . $form->format_amount( \%myconfig, $ref->{discount} * 100,
  992. "", "&nbsp;" )
  993. . "</td>";
  994. }
  995. if ( $form->{l_terms} ) {
  996. $column_data{terms} = "<td align=right>"
  997. . $form->format_amount( \%myconfig, $ref->{terms}, "",
  998. "&nbsp;" )
  999. . "</td>";
  1000. }
  1001. }
  1002. $j++;
  1003. $j %= 2;
  1004. print "
  1005. <tr class=listrow$j>
  1006. ";
  1007. for (@column_index) { print "$column_data{$_}\n" }
  1008. print qq|
  1009. </tr>
  1010. |;
  1011. $sameitem = "$ref->{$form->{sort}}";
  1012. $sameid = $ref->{id};
  1013. }
  1014. if ( $form->{l_subtotal} && $subtotal ) {
  1015. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1016. &list_subtotal;
  1017. }
  1018. $i = 1;
  1019. if ( $myconfig{acs} !~ /AR--AR/ ) {
  1020. if ( $form->{db} eq 'customer' ) {
  1021. $button{'AR--Customers--Add Customer'}{code} =
  1022. qq|<button class="submit" type="submit" name="action" value="add_customer">|
  1023. . $locale->text('Add Customer')
  1024. . qq|</button> |;
  1025. $button{'AR--Customers--Add Customer'}{order} = $i++;
  1026. }
  1027. }
  1028. if ( $myconfig{acs} !~ /AP--AP/ ) {
  1029. if ( $form->{db} eq 'vendor' ) {
  1030. $button{'AP--Vendors--Add Vendor'}{code} =
  1031. qq|<button class="submit" type="submit" name="action" value="add_vendor">|
  1032. . $locale->text('Add Vendor')
  1033. . qq|</button> |;
  1034. $button{'AP--Vendors--Add Vendor'}{order} = $i++;
  1035. }
  1036. }
  1037. foreach $item ( split /;/, $myconfig{acs} ) {
  1038. delete $button{$item};
  1039. }
  1040. print qq|
  1041. </table>
  1042. </td>
  1043. </tr>
  1044. <tr>
  1045. <td><hr size=3 noshade></td>
  1046. </tr>
  1047. </table>
  1048. <br>
  1049. <form method=post action=$form->{script}>
  1050. |;
  1051. $form->hide_form(qw(callback db path login sessionid));
  1052. if ( $form->{status} ) {
  1053. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  1054. print $item->{code};
  1055. }
  1056. }
  1057. if ( $form->{lynx} ) {
  1058. require "bin/menu.pl";
  1059. &menubar;
  1060. }
  1061. print qq|
  1062. </form>
  1063. </body>
  1064. </html>
  1065. |;
  1066. }
  1067. sub list_subtotal {
  1068. $column_data{invamount} =
  1069. "<td align=right>"
  1070. . $form->format_amount( \%myconfig, $invamountsubtotal, 2, "&nbsp;" )
  1071. . "</td>";
  1072. $column_data{invtax} =
  1073. "<td align=right>"
  1074. . $form->format_amount( \%myconfig, $invtaxsubtotal, 2, "&nbsp;" )
  1075. . "</td>";
  1076. $column_data{invtotal} =
  1077. "<td align=right>"
  1078. . $form->format_amount( \%myconfig, $invtotalsubtotal, 2, "&nbsp;" )
  1079. . "</td>";
  1080. $invamountsubtotal = 0;
  1081. $invtaxsubtotal = 0;
  1082. $invtotalsubtotal = 0;
  1083. $column_data{ordamount} =
  1084. "<td align=right>"
  1085. . $form->format_amount( \%myconfig, $ordamountsubtotal, 2, "&nbsp;" )
  1086. . "</td>";
  1087. $column_data{ordtax} =
  1088. "<td align=right>"
  1089. . $form->format_amount( \%myconfig, $ordtaxsubtotal, 2, "&nbsp;" )
  1090. . "</td>";
  1091. $column_data{ordtotal} =
  1092. "<td align=right>"
  1093. . $form->format_amount( \%myconfig, $ordtotalsubtotal, 2, "&nbsp;" )
  1094. . "</td>";
  1095. $ordamountsubtotal = 0;
  1096. $ordtaxsubtotal = 0;
  1097. $ordtotalsubtotal = 0;
  1098. $column_data{quoamount} =
  1099. "<td align=right>"
  1100. . $form->format_amount( \%myconfig, $quoamountsubtotal, 2, "&nbsp;" )
  1101. . "</td>";
  1102. $column_data{quotax} =
  1103. "<td align=right>"
  1104. . $form->format_amount( \%myconfig, $quotaxsubtotal, 2, "&nbsp;" )
  1105. . "</td>";
  1106. $column_data{quototal} =
  1107. "<td align=right>"
  1108. . $form->format_amount( \%myconfig, $quototalsubtotal, 2, "&nbsp;" )
  1109. . "</td>";
  1110. $quoamountsubtotal = 0;
  1111. $quotaxsubtotal = 0;
  1112. $quototalsubtotal = 0;
  1113. print "
  1114. <tr class=listsubtotal>
  1115. ";
  1116. for (@column_index) { print "$column_data{$_}\n" }
  1117. print qq|
  1118. </tr>
  1119. |;
  1120. }
  1121. sub list_history {
  1122. CT->get_history( \%myconfig, \%$form );
  1123. $href =
  1124. "$form->{script}?action=list_history&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&history=$form->{history}";
  1125. $form->sort_order();
  1126. $callback =
  1127. "$form->{script}?action=list_history&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&history=$form->{history}";
  1128. $form->{l_fxsellprice} = $form->{l_curr};
  1129. @columns = $form->sort_columns( partnumber, description, qty, unit,
  1130. sellprice, fxsellprice, curr, discount,
  1131. deliverydate, projectnumber, serialnumber
  1132. );
  1133. if ( $form->{history} eq 'summary' ) {
  1134. @columns =
  1135. $form->sort_columns( partnumber, description, qty, unit, sellprice,
  1136. curr );
  1137. }
  1138. foreach $item (@columns) {
  1139. if ( $form->{"l_$item"} eq "Y" ) {
  1140. push @column_index, $item;
  1141. # add column to href and callback
  1142. $callback .= "&l_$item=Y";
  1143. $href .= "&l_$item=Y";
  1144. }
  1145. }
  1146. if ( $form->{history} eq 'detail' ) {
  1147. $option = $locale->text('Detail');
  1148. }
  1149. if ( $form->{history} eq 'summary' ) {
  1150. $option .= $locale->text('Summary');
  1151. }
  1152. if ( $form->{name} ) {
  1153. $callback .= "&name=" . $form->escape( $form->{name}, 1 );
  1154. $href .= "&name=" . $form->escape( $form->{name} );
  1155. $option .= "\n<br>" . $locale->text('Name') . " : $form->{name}";
  1156. }
  1157. if ( $form->{contact} ) {
  1158. $callback .= "&contact=" . $form->escape( $form->{contact}, 1 );
  1159. $href .= "&contact=" . $form->escape( $form->{contact} );
  1160. $option .= "\n<br>" . $locale->text('Contact') . " : $form->{contact}";
  1161. }
  1162. if ( $form->{"$form->{db}number"} ) {
  1163. $callback .=
  1164. qq|&$form->{db}number=|
  1165. . $form->escape( $form->{"$form->{db}number"}, 1 );
  1166. $href .=
  1167. "&$form->{db}number=" . $form->escape( $form->{"$form->{db}number"} );
  1168. $option .= "\n<br>"
  1169. . $locale->text('Number')
  1170. . qq| : $form->{"$form->{db}number"}|;
  1171. }
  1172. if ( $form->{email} ) {
  1173. $callback .= "&email=" . $form->escape( $form->{email}, 1 );
  1174. $href .= "&email=" . $form->escape( $form->{email} );
  1175. $option .= "\n<br>" . $locale->text('E-mail') . " : $form->{email}";
  1176. }
  1177. if ( $form->{transdatefrom} ) {
  1178. $callback .= "&transdatefrom=$form->{transdatefrom}";
  1179. $href .= "&transdatefrom=$form->{transdatefrom}";
  1180. $option .= "\n<br>" if ($option);
  1181. $option .=
  1182. $locale->text('From') . "&nbsp;"
  1183. . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
  1184. }
  1185. if ( $form->{transdateto} ) {
  1186. $callback .= "&transdateto=$form->{transdateto}";
  1187. $href .= "&transdateto=$form->{transdateto}";
  1188. if ( $form->{transdatefrom} ) {
  1189. $option .= " ";
  1190. }
  1191. else {
  1192. $option .= "\n<br>" if ($option);
  1193. }
  1194. $option .=
  1195. $locale->text('To') . "&nbsp;"
  1196. . $locale->date( \%myconfig, $form->{transdateto}, 1 );
  1197. }
  1198. if ( $form->{open} ) {
  1199. $callback .= "&open=$form->{open}";
  1200. $href .= "&open=$form->{open}";
  1201. $option .= "\n<br>" if ($option);
  1202. $option .= $locale->text('Open');
  1203. }
  1204. if ( $form->{closed} ) {
  1205. $callback .= "&closed=$form->{closed}";
  1206. $href .= "&closed=$form->{closed}";
  1207. $option .= "\n<br>" if ($option);
  1208. $option .= $locale->text('Closed');
  1209. }
  1210. $form->{callback} = "$callback&sort=$form->{sort}";
  1211. $callback = $form->escape( $form->{callback} );
  1212. $column_header{partnumber} =
  1213. qq|<th><a class=listheading href=$href&sort=partnumber>|
  1214. . $locale->text('Part Number')
  1215. . qq|</a></th>|;
  1216. $column_header{description} =
  1217. qq|<th><a class=listheading href=$href&sort=description>|
  1218. . $locale->text('Description')
  1219. . qq|</a></th>|;
  1220. if ( $form->{history} eq 'summary' ) {
  1221. $column_header{sellprice} =
  1222. qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
  1223. }
  1224. else {
  1225. $column_header{sellprice} =
  1226. qq|<th class=listheading>| . $locale->text('Sell Price') . qq|</th>|;
  1227. }
  1228. $column_header{fxsellprice} = qq|<th>&nbsp;</th>|;
  1229. $column_header{curr} =
  1230. qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
  1231. $column_header{discount} =
  1232. qq|<th class=listheading>| . $locale->text('Discount') . qq|</th>|;
  1233. $column_header{qty} =
  1234. qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
  1235. $column_header{unit} =
  1236. qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
  1237. $column_header{deliverydate} =
  1238. qq|<th><a class=listheading href=$href&sort=deliverydate>|
  1239. . $locale->text('Delivery Date')
  1240. . qq|</a></th>|;
  1241. $column_header{projectnumber} =
  1242. qq|<th><a class=listheading href=$href&sort=projectnumber>|
  1243. . $locale->text('Project Number')
  1244. . qq|</a></th>|;
  1245. $column_header{serialnumber} =
  1246. qq|<th><a class=listheading href=$href&sort=serialnumber>|
  1247. . $locale->text('Serial Number')
  1248. . qq|</a></th>|;
  1249. # $locale->text('Customer History')
  1250. # $locale->text('Vendor History')
  1251. $label = ucfirst $form->{db};
  1252. $form->{title} = $locale->text( $label . " History" );
  1253. $colspan = $#column_index + 1;
  1254. $form->header;
  1255. print qq|
  1256. <body>
  1257. <table width=100%>
  1258. <tr>
  1259. <th class=listtop>$form->{title}</th>
  1260. </tr>
  1261. <tr height="5"></tr>
  1262. <tr>
  1263. <td>$option</td>
  1264. </tr>
  1265. <tr>
  1266. <td>
  1267. <table width=100%>
  1268. <tr class=listheading>
  1269. |;
  1270. for (@column_index) { print "$column_header{$_}\n" }
  1271. print qq|
  1272. </tr>
  1273. |;
  1274. $module = 'oe';
  1275. if ( $form->{db} eq 'customer' ) {
  1276. $invlabel = $locale->text('Sales Invoice');
  1277. $ordlabel = $locale->text('Sales Order');
  1278. $quolabel = $locale->text('Quotation');
  1279. $ordertype = 'sales_order';
  1280. $quotationtype = 'sales_quotation';
  1281. if ( $form->{type} eq 'invoice' ) {
  1282. $module = 'is';
  1283. }
  1284. }
  1285. else {
  1286. $invlabel = $locale->text('Vendor Invoice');
  1287. $ordlabel = $locale->text('Purchase Order');
  1288. $quolabel = $locale->text('RFQ');
  1289. $ordertype = 'purchase_order';
  1290. $quotationtype = 'request_quotation';
  1291. if ( $form->{type} eq 'invoice' ) {
  1292. $module = 'ir';
  1293. }
  1294. }
  1295. $ml = ( $form->{db} eq 'vendor' ) ? -1 : 1;
  1296. foreach $ref ( @{ $form->{CT} } ) {
  1297. if ( $ref->{id} ne $sameid ) {
  1298. # print the header
  1299. print qq|
  1300. <tr class=listheading>
  1301. <th colspan=$colspan><a class=listheading href=$form->{script}?action=edit&id=$ref->{ctid}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{name} $ref->{address}</a></th>
  1302. </tr>
  1303. |;
  1304. }
  1305. if ( $form->{type} ne 'invoice' ) {
  1306. $ref->{fxsellprice} = $ref->{sellprice};
  1307. $ref->{sellprice} *= $ref->{exchangerate};
  1308. }
  1309. if ( $form->{history} eq 'detail' and $ref->{invid} ne $sameinvid ) {
  1310. # print inv, ord, quo number
  1311. $i++;
  1312. $i %= 2;
  1313. print qq|
  1314. <tr class=listrow$i>
  1315. |;
  1316. if ( $form->{type} eq 'invoice' ) {
  1317. print
  1318. qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$invlabel $ref->{invnumber} / $ref->{employee}</a></th>|;
  1319. }
  1320. if ( $form->{type} eq 'order' ) {
  1321. print
  1322. qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ordlabel $ref->{ordnumber} / $ref->{employee}</a></th>|;
  1323. }
  1324. if ( $form->{type} eq 'quotation' ) {
  1325. print
  1326. qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$quolabel $ref->{quonumber} / $ref->{employee}</a></th>|;
  1327. }
  1328. print qq|
  1329. </tr>
  1330. |;
  1331. }
  1332. for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
  1333. if ( $form->{l_curr} ) {
  1334. $column_data{fxsellprice} =
  1335. qq|<td align=right>|
  1336. . $form->format_amount( \%myconfig, $ref->{fxsellprice}, 2 )
  1337. . "</td>";
  1338. }
  1339. $column_data{sellprice} =
  1340. qq|<td align=right>|
  1341. . $form->format_amount( \%myconfig, $ref->{sellprice}, 2 ) . "</td>";
  1342. $column_data{qty} =
  1343. qq|<td align=right>|
  1344. . $form->format_amount( \%myconfig, $ref->{qty} * $ml ) . "</td>";
  1345. $column_data{discount} = qq|<td align=right>|
  1346. . $form->format_amount( \%myconfig, $ref->{discount} * 100,
  1347. "", "&nbsp;" )
  1348. . "</td>";
  1349. $column_data{partnumber} =
  1350. qq|<td><a href=ic.pl?action=edit&id=$ref->{pid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}</td>|;
  1351. $i++;
  1352. $i %= 2;
  1353. print qq|
  1354. <tr class=listrow$i>
  1355. |;
  1356. for (@column_index) { print "$column_data{$_}\n" }
  1357. print qq|
  1358. </tr>
  1359. |;
  1360. $sameid = $ref->{id};
  1361. $sameinvid = $ref->{invid};
  1362. }
  1363. print qq|
  1364. </table>
  1365. </td>
  1366. </tr>
  1367. <tr>
  1368. <td><hr size=3 noshade></td>
  1369. </tr>
  1370. </table>
  1371. |;
  1372. if ( $form->{lynx} ) {
  1373. require "bin/menu.pl";
  1374. &menubar;
  1375. }
  1376. print qq|
  1377. </form>
  1378. </body>
  1379. </html>
  1380. |;
  1381. }
  1382. sub edit {
  1383. # $locale->text('Edit Customer')
  1384. # $locale->text('Edit Vendor')
  1385. CT->create_links( \%myconfig, \%$form );
  1386. for ( keys %$form ) { $form->{$_} = $form->quote( $form->{$_} ) }
  1387. $form->{title} = "Edit";
  1388. # format discount
  1389. $form->{discount} *= 100;
  1390. &form_header;
  1391. &form_footer;
  1392. }
  1393. sub form_header {
  1394. $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
  1395. $form->{creditlimit} =
  1396. $form->format_amount( \%myconfig, $form->{creditlimit}, 0 );
  1397. $form->{discount} =
  1398. $form->format_amount( \%myconfig, $form->{discount}, "" );
  1399. $form->{terms} = $form->format_amount( \%myconfig, $form->{terms}, "" );
  1400. if ( $myconfig{role} =~ /(admin|manager)/ ) {
  1401. $bcc = qq|
  1402. <tr>
  1403. <th align=right nowrap>| . $locale->text('Bcc') . qq|</th>
  1404. <td><input name=bcc size=35 value="$form->{bcc}"></td>
  1405. </tr>
  1406. |;
  1407. }
  1408. if ( $form->{currencies} ) {
  1409. # currencies
  1410. for ( split /:/, $form->{currencies} ) {
  1411. $form->{selectcurrency} .= "<option>$_\n";
  1412. }
  1413. $form->{selectcurrency} =~ s/option>($form->{curr})/option selected>$1/;
  1414. $currency = qq|
  1415. <th>| . $locale->text('Currency') . qq|</th>
  1416. <td><select name=curr>$form->{selectcurrency}</select></td>
  1417. |;
  1418. }
  1419. foreach $item ( split / /, $form->{taxaccounts} ) {
  1420. if ( $form->{tax}{$item}{taxable} ) {
  1421. $taxable .=
  1422. qq| <input name="tax_$item" value=1 class=checkbox type=checkbox checked>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
  1423. }
  1424. else {
  1425. $taxable .=
  1426. qq| <input name="tax_$item" value=1 class=checkbox type=checkbox>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
  1427. }
  1428. }
  1429. if ($taxable) {
  1430. $tax = qq|
  1431. <tr>
  1432. <th align=right>| . $locale->text('Taxable') . qq|</th>
  1433. <td colspan=5>
  1434. <table>
  1435. <tr>
  1436. <td>$taxable</td>
  1437. <td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
  1438. <th align=left>| . $locale->text('Tax Included') . qq|</th>
  1439. </tr>
  1440. </table>
  1441. </td>
  1442. </tr>
  1443. |;
  1444. }
  1445. $typeofbusiness = qq|
  1446. <th></th>
  1447. <td></td>
  1448. |;
  1449. if ( @{ $form->{all_business} } ) {
  1450. $form->{selectbusiness} = qq|<option>\n|;
  1451. for ( @{ $form->{all_business} } ) {
  1452. $form->{selectbusiness} .=
  1453. qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
  1454. }
  1455. $form->{selectbusiness} =~
  1456. s/(<option value="\Q$form->{business}--$form->{business_id}\E")>/$1 selected>/;
  1457. $typeofbusiness = qq|
  1458. <th align=right>| . $locale->text('Type of Business') . qq|</th>
  1459. <td><select name=business>$form->{selectbusiness}</select></td>
  1460. |;
  1461. }
  1462. $pricegroup = qq|
  1463. <th></th>
  1464. <td></td>
  1465. |;
  1466. if ( @{ $form->{all_pricegroup} } && $form->{db} eq 'customer' ) {
  1467. $form->{selectpricegroup} = qq|<option>\n|;
  1468. for ( @{ $form->{all_pricegroup} } ) {
  1469. $form->{selectpricegroup} .=
  1470. qq|<option value="$_->{pricegroup}--$_->{id}">$_->{pricegroup}\n|;
  1471. }
  1472. $form->{selectpricegroup} =~
  1473. s/(<option value="\Q$form->{pricegroup}--$form->{pricegroup_id}\E")/$1 selected/;
  1474. $pricegroup = qq|
  1475. <th align=right>| . $locale->text('Pricegroup') . qq|</th>
  1476. <td><select name=pricegroup>$form->{selectpricegroup}</select></td>
  1477. |;
  1478. }
  1479. $lang = qq|
  1480. <th></th>
  1481. <td></td>
  1482. |;
  1483. if ( @{ $form->{all_language} } ) {
  1484. $form->{selectlanguage} = qq|<option>\n|;
  1485. for ( @{ $form->{all_language} } ) {
  1486. $form->{selectlanguage} .=
  1487. qq|<option value="$_->{description}--$_->{code}">$_->{description}\n|;
  1488. }
  1489. $form->{selectlanguage} =~
  1490. s/(<option value="\Q$form->{language}--$form->{language_code}\E")/$1 selected/;
  1491. $lang = qq|
  1492. <th align=right>| . $locale->text('Language') . qq|</th>
  1493. <td><select name=language>$form->{selectlanguage}</select></td>
  1494. |;
  1495. }
  1496. $employeelabel = $locale->text('Salesperson');
  1497. $form->{selectemployee} = qq|<option>\n|;
  1498. for ( @{ $form->{all_employee} } ) {
  1499. $form->{selectemployee} .=
  1500. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  1501. }
  1502. $form->{selectemployee} =~
  1503. s/(<option value="\Q$form->{employee}--$form->{employee_id}\E")/$1 selected/;
  1504. if ( $form->{db} eq 'vendor' ) {
  1505. $gifi = qq|
  1506. <th align=right>| . $locale->text('Sub-contract GIFI') . qq|</th>
  1507. <td><input name=gifi_accno size=9 value="$form->{gifi_accno}"></td>
  1508. |;
  1509. $employeelabel = $locale->text('Employee');
  1510. }
  1511. if ( @{ $form->{all_employee} } ) {
  1512. $employee = qq|
  1513. <th align=right>$employeelabel</th>|;
  1514. if ( $myconfig{role} ne 'user' || !$form->{id} ) {
  1515. $employee .= qq|
  1516. <td><select name=employee>$form->{selectemployee}</select></td>
  1517. |;
  1518. }
  1519. else {
  1520. $employee .= qq|
  1521. <td>$form->{employee}</td>
  1522. <input type=hidden name=employee value="$form->{employee}--$form->{employee_id}">|;
  1523. }
  1524. }
  1525. # $locale->text('Customer Number')
  1526. # $locale->text('Vendor Number')
  1527. $label = ucfirst $form->{db};
  1528. $form->{title} = $locale->text("$form->{title} $label");
  1529. $form->header;
  1530. print qq|
  1531. <body>
  1532. <form method=post action=$form->{script}>
  1533. <table width=100%>
  1534. <tr>
  1535. <th class=listtop>$form->{title}</th>
  1536. </tr>
  1537. <tr height="5"></tr>
  1538. <tr>
  1539. <td>
  1540. <table width=100%>
  1541. <tr valign=top>
  1542. <td width=50%>
  1543. <table width=100%>
  1544. <tr class=listheading>
  1545. <th class=listheading colspan=2 width=50%>|
  1546. . $locale->text('Billing Address')
  1547. . qq|</th>
  1548. <tr>
  1549. <th align=right nowrap>| . $locale->text( $label . ' Number' ) . qq|</th>
  1550. <td><input name="$form->{db}number" size=35 maxlength=32 value="$form->{"$form->{db}number"}"></td>
  1551. </tr>
  1552. <tr>
  1553. <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
  1554. <td><input name=name size=35 maxlength=64 value="$form->{name}"></td>
  1555. </tr>
  1556. <tr>
  1557. <th align=right nowrap>| . $locale->text('Address') . qq|</th>
  1558. <td><input name=address1 size=35 maxlength=32 value="$form->{address1}"></td>
  1559. </tr>
  1560. <tr>
  1561. <th></th>
  1562. <td><input name=address2 size=35 maxlength=32 value="$form->{address2}"></td>
  1563. </tr>
  1564. <tr>
  1565. <th align=right nowrap>| . $locale->text('City') . qq|</th>
  1566. <td><input name=city size=35 maxlength=32 value="$form->{city}"></td>
  1567. </tr>
  1568. <tr>
  1569. <th align=right nowrap>| . $locale->text('State/Province') . qq|</th>
  1570. <td><input name=state size=35 maxlength=32 value="$form->{state}"></td>
  1571. </tr>
  1572. <tr>
  1573. <th align=right nowrap>| . $locale->text('Zip/Postal Code') . qq|</th>
  1574. <td><input name=zipcode size=10 maxlength=10 value="$form->{zipcode}"></td>
  1575. </tr>
  1576. <tr>
  1577. <th align=right nowrap>| . $locale->text('Country') . qq|</th>
  1578. <td><input name=country size=35 maxlength=32 value="$form->{country}"></td>
  1579. </tr>
  1580. <tr>
  1581. <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
  1582. <td><input name=contact size=35 maxlength=64 value="$form->{contact}"></td>
  1583. </tr>
  1584. <tr>
  1585. <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
  1586. <td><input name=phone size=20 maxlength=20 value="$form->{phone}"></td>
  1587. </tr>
  1588. <tr>
  1589. <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
  1590. <td><input name=fax size=20 maxlength=20 value="$form->{fax}"></td>
  1591. </tr>
  1592. <tr>
  1593. <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
  1594. <td><input name=email size=35 value="$form->{email}"></td>
  1595. </tr>
  1596. <tr>
  1597. <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
  1598. <td><input name=cc size=35 value="$form->{cc}"></td>
  1599. </tr>
  1600. $bcc
  1601. </table>
  1602. </td>
  1603. <td width=50%>
  1604. <table width=100%>
  1605. <tr>
  1606. <th class=listheading colspan=2>|
  1607. . $locale->text('Shipping Address')
  1608. . qq|</th>
  1609. </tr>
  1610. <tr>
  1611. <td><input name=none size=35 value="| . ( "=" x 35 ) . qq|"></td>
  1612. </tr>
  1613. <tr>
  1614. <td><input name=shiptoname size=35 maxlength=64 value="$form->{shiptoname}"></td>
  1615. </tr>
  1616. <tr>
  1617. <td><input name=shiptoaddress1 size=35 maxlength=32 value="$form->{shiptoaddress1}"></td>
  1618. </tr>
  1619. <tr>
  1620. <td><input name=shiptoaddress2 size=35 maxlength=32 value="$form->{shiptoaddress2}"></td>
  1621. </tr>
  1622. <tr>
  1623. <td><input name=shiptocity size=35 maxlength=32 value="$form->{shiptocity}"></td>
  1624. </tr>
  1625. <tr>
  1626. <td><input name=shiptostate size=35 maxlength=32 value="$form->{shiptostate}"></td>
  1627. </tr>
  1628. <tr>
  1629. <td><input name=shiptozipcode size=10 maxlength=10 value="$form->{shiptozipcode}"></td>
  1630. </tr>
  1631. <tr>
  1632. <td><input name=shiptocountry size=35 maxlength=32 value="$form->{shiptocountry}"></td>
  1633. </tr>
  1634. <tr>
  1635. <td><input name=shiptocontact size=35 maxlength=64 value="$form->{shiptocontact}"></td>
  1636. </tr>
  1637. <tr>
  1638. <td><input name=shiptophone size=20 maxlength=20 value="$form->{shiptophone}"></td>
  1639. </tr>
  1640. <tr>
  1641. <td><input name=shiptofax size=20 maxlength=20 value="$form->{shiptofax}"></td>
  1642. </tr>
  1643. <tr>
  1644. <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
  1645. </tr>
  1646. </table>
  1647. </td>
  1648. </tr>
  1649. </table>
  1650. </td>
  1651. </tr>
  1652. <tr>
  1653. <td>
  1654. <table>
  1655. $tax
  1656. <tr>
  1657. <th align=right>| . $locale->text('Startdate') . qq|</th>
  1658. <td><input name=startdate size=11 title="$myconfig{dateformat}" value="$form->{startdate}"></td>
  1659. <th align=right>| . $locale->text('Enddate') . qq|</th>
  1660. <td><input name=enddate size=11 title="$myconfig{dateformat}" value="$form->{enddate}"></td>
  1661. </tr>
  1662. <tr>
  1663. <th align=right>| . $locale->text('Credit Limit') . qq|</th>
  1664. <td><input name=creditlimit size=9 value="$form->{creditlimit}"></td>
  1665. <th align=right>| . $locale->text('Terms') . qq|</th>
  1666. <td><input name=terms size=2 value="$form->{terms}"> <b>|
  1667. . $locale->text('days')
  1668. . qq|</b></td>
  1669. <th align=right>| . $locale->text('Discount') . qq|</th>
  1670. <td><input name=discount size=4 value="$form->{discount}">
  1671. <b>%</b></td>
  1672. </tr>
  1673. <tr>
  1674. <th align=right>| . $locale->text('Tax Number / SSN') . qq|</th>
  1675. <td><input name=taxnumber size=20 value="$form->{taxnumber}"></td>
  1676. $gifi
  1677. <th align=right>| . $locale->text('SIC') . qq|</th>
  1678. <td><input name=sic_code size=6 maxlength=6 value="$form->{sic_code}"></td>
  1679. </tr>
  1680. <tr>
  1681. $typeofbusiness
  1682. <th align=right>| . $locale->text('BIC') . qq|</th>
  1683. <td><input name=bic size=11 maxlength=11 value="$form->{bic}"></td>
  1684. <th align=right>| . $locale->text('IBAN') . qq|</th>
  1685. <td><input name=iban size=24 maxlength=34 value="$form->{iban}"></td>
  1686. </tr>
  1687. <tr>
  1688. $pricegroup
  1689. $lang
  1690. $currency
  1691. </tr>
  1692. <tr valign=top>
  1693. $employee
  1694. <td colspan=4>
  1695. <table>
  1696. <tr valign=top>
  1697. <th align=left nowrap>| . $locale->text('Notes') . qq|</th>
  1698. <td><textarea name=notes rows=3 cols=40 wrap=soft>$form->{notes}</textarea></td>
  1699. </tr>
  1700. </table>
  1701. </td>
  1702. </tr>
  1703. </table>
  1704. </td>
  1705. </tr>
  1706. <tr>
  1707. <td><hr size=3 noshade></td>
  1708. </tr>
  1709. </table>
  1710. |;
  1711. }
  1712. sub form_footer {
  1713. # type=submit $locale->text('Save')
  1714. # type=submit $locale->text('Save as new')
  1715. # type=submit $locale->text('AR Transaction')
  1716. # type=submit $locale->text('Sales Invoice')
  1717. # type=submit $locale->text('Sales Order')
  1718. # type=submit $locale->text('Quotation')
  1719. # type=submit $locale->text('AP Transaction')
  1720. # type=submit $locale->text('Vendor Invoice')
  1721. # type=submit $locale->text('Purchase Order')
  1722. # type=submit $locale->text('RFQ')
  1723. # type=submit $locale->text('Pricelist')
  1724. # type=submit $locale->text('Delete')
  1725. # type=submit $locale->text('POS')
  1726. %button = (
  1727. 'save' => { ndx => 1, key => 'S', value => $locale->text('Save') },
  1728. 'save_as_new' =>
  1729. { ndx => 2, key => 'N', value => $locale->text('Save as new') },
  1730. 'ar_transaction' =>
  1731. { ndx => 7, key => 'A', value => $locale->text('AR Transaction') },
  1732. 'ap_transaction' =>
  1733. { ndx => 8, key => 'A', value => $locale->text('AP Transaction') },
  1734. 'sales_invoice' =>
  1735. { ndx => 9, key => 'I', value => $locale->text('Sales Invoice') },
  1736. 'pos' => { ndx => 10, key => 'C', value => $locale->text('POS') },
  1737. 'sales_order' =>
  1738. { ndx => 11, key => 'O', value => $locale->text('Sales Order') },
  1739. 'quotation' =>
  1740. { ndx => 12, key => 'Q', value => $locale->text('Quotation') },
  1741. 'vendor_invoice' =>
  1742. { ndx => 13, key => 'I', value => $locale->text('Vendor Invoice') },
  1743. 'purchase_order' =>
  1744. { ndx => 14, key => 'O', value => $locale->text('Purchase Order') },
  1745. 'rfq' => { ndx => 15, key => 'Q', value => $locale->text('RFQ') },
  1746. 'pricelist' =>
  1747. { ndx => 16, key => 'P', value => $locale->text('Pricelist') },
  1748. 'delete' => { ndx => 17, key => 'D', value => $locale->text('Delete') },
  1749. );
  1750. %a = ();
  1751. if ( $form->{db} eq 'customer' ) {
  1752. if ( $myconfig{acs} !~ /AR--Customers--Add Customer/ ) {
  1753. $a{'save'} = 1;
  1754. if ( $form->{id} ) {
  1755. $a{'save_as_new'} = 1;
  1756. if ( $form->{status} eq 'orphaned' ) {
  1757. $a{'delete'} = 1;
  1758. }
  1759. }
  1760. }
  1761. if ( $myconfig{acs} !~ /AR--AR/ ) {
  1762. if ( $myconfig{acs} !~ /AR--Add Transaction/ ) {
  1763. $a{'ar_transaction'} = 1;
  1764. }
  1765. if ( $myconfig{acs} !~ /AR--Sales Invoice/ ) {
  1766. $a{'sales_invoice'} = 1;
  1767. }
  1768. }
  1769. if ( $myconfig{acs} !~ /POS--POS/ ) {
  1770. if ( $myconfig{acs} !~ /POS--Sale/ ) {
  1771. $a{'pos'} = 1;
  1772. }
  1773. }
  1774. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1775. if ( $myconfig{acs} !~ /Order Entry--Sales Order/ ) {
  1776. $a{'sales_order'} = 1;
  1777. }
  1778. }
  1779. if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
  1780. if ( $myconfig{acs} !~ /Quotations--Quotation/ ) {
  1781. $a{'quotation'} = 1;
  1782. }
  1783. }
  1784. }
  1785. if ( $form->{db} eq 'vendor' ) {
  1786. if ( $myconfig{acs} !~ /AP--Vendors--Add Vendor/ ) {
  1787. $a{'save'} = 1;
  1788. if ( $form->{id} ) {
  1789. $a{'save_as_new'} = 1;
  1790. if ( $form->{status} eq 'orphaned' ) {
  1791. $a{'delete'} = 1;
  1792. }
  1793. }
  1794. }
  1795. if ( $myconfig{acs} !~ /AP--AP/ ) {
  1796. if ( $myconfig{acs} !~ /AP--Add Transaction/ ) {
  1797. $a{'ap_transaction'} = 1;
  1798. }
  1799. if ( $myconfig{acs} !~ /AP--Vendor Invoice/ ) {
  1800. $a{'vendor_invoice'} = 1;
  1801. }
  1802. }
  1803. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1804. if ( $myconfig{acs} !~ /Order Entry--Purchase Order/ ) {
  1805. $a{'purchase_order'} = 1;
  1806. }
  1807. }
  1808. if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
  1809. if ( $myconfig{acs} !~ /Quotations--RFQ/ ) {
  1810. $a{'rfq'} = 1;
  1811. }
  1812. }
  1813. }
  1814. if ( $myconfig{acs} !~ /Goods & Services--Goods & Services/ ) {
  1815. $myconfig{acs} =~
  1816. s/(Goods & Services--)Add (Service|Assembly).*;/$1--Add Part/g;
  1817. if ( $myconfig{acs} !~ /Goods & Services--Add Part/ ) {
  1818. $a{'pricelist'} = 1;
  1819. }
  1820. }
  1821. $form->hide_form(qw(id taxaccounts path login sessionid callback db));
  1822. for ( keys %button ) { delete $button{$_} if !$a{$_} }
  1823. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  1824. $form->print_button( \%button, $_ );
  1825. }
  1826. if ( $form->{lynx} ) {
  1827. require "bin/menu.pl";
  1828. &menubar;
  1829. }
  1830. print qq|
  1831. </form>
  1832. </body>
  1833. </html>
  1834. |;
  1835. }
  1836. sub pricelist {
  1837. $form->isblank( "name", $locale->text('Name missing!') );
  1838. $form->{display_form} ||= "display_pricelist";
  1839. CT->pricelist( \%myconfig, \%$form );
  1840. foreach $ref ( @{ $form->{"all_partspricelist"} } ) {
  1841. $i++;
  1842. for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
  1843. }
  1844. $form->{rowcount} = $i;
  1845. # currencies
  1846. @curr = split /:/, $form->{currencies};
  1847. for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
  1848. if ( @{ $form->{all_partsgroup} } ) {
  1849. $form->{selectpartsgroup} = "";
  1850. foreach $ref ( @{ $form->{all_partsgroup} } ) {
  1851. $form->{selectpartsgroup} .= qq|$ref->{partsgroup}--$ref->{id}\n|;
  1852. }
  1853. }
  1854. for (qw(currencies all_partsgroup all_partspricelist)) {
  1855. delete $form->{$_};
  1856. }
  1857. foreach $i ( 1 .. $form->{rowcount} ) {
  1858. if ( $form->{db} eq 'customer' ) {
  1859. $form->{"pricebreak_$i"} =
  1860. $form->format_amount( \%myconfig, $form->{"pricebreak_$i"} );
  1861. $form->{"sellprice_$i"} =
  1862. $form->format_amount( \%myconfig, $form->{"sellprice_$i"}, 2 );
  1863. }
  1864. if ( $form->{db} eq 'vendor' ) {
  1865. $form->{"leadtime_$i"} =
  1866. $form->format_amount( \%myconfig, $form->{"leadtime_$i"} );
  1867. $form->{"lastcost_$i"} =
  1868. $form->format_amount( \%myconfig, $form->{"lastcost_$i"}, 2 );
  1869. }
  1870. }
  1871. $form->{rowcount}++;
  1872. &{"$form->{db}_pricelist"};
  1873. }
  1874. sub customer_pricelist {
  1875. @flds =
  1876. qw(runningnumber id partnumber description sellprice unit partsgroup pricebreak curr validfrom validto);
  1877. $form->{rowcount}--;
  1878. # remove empty rows
  1879. if ( $form->{rowcount} ) {
  1880. foreach $i ( 1 .. $form->{rowcount} ) {
  1881. for (qw(pricebreak sellprice)) {
  1882. $form->{"${_}_$i"} =
  1883. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  1884. }
  1885. ( $a, $b ) = split /\./, $form->{"pricebreak_$i"};
  1886. $a = length $a;
  1887. $b = length $b;
  1888. $whole = ( $whole > $a ) ? $whole : $a;
  1889. $dec = ( $dec > $b ) ? $dec : $b;
  1890. }
  1891. $pad1 = '0' x $whole;
  1892. $pad2 = '0' x $dec;
  1893. foreach $i ( 1 .. $form->{rowcount} ) {
  1894. ( $a, $b ) = split /\./, $form->{"pricebreak_$i"};
  1895. $a = substr( "$pad1$a", -$whole );
  1896. $b = substr( "$b$pad2", 0, $dec );
  1897. $ndx{qq|$form->{"partnumber_$i"}_$form->{"id_$i"}_$a$b|} = $i;
  1898. }
  1899. $i = 1;
  1900. for ( sort keys %ndx ) { $form->{"runningnumber_$ndx{$_}"} = $i++ }
  1901. foreach $i ( 1 .. $form->{rowcount} ) {
  1902. if ( $form->{"partnumber_$i"} && $form->{"sellprice_$i"} ) {
  1903. if ( $form->{"id_$i"} eq $sameid ) {
  1904. $j = $i + 1;
  1905. next
  1906. if ( $form->{"id_$j"} eq $sameid
  1907. && !$form->{"pricebreak_$i"} );
  1908. }
  1909. push @a, {};
  1910. $j = $#a;
  1911. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1912. $count++;
  1913. }
  1914. $sameid = $form->{"id_$i"};
  1915. }
  1916. $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
  1917. $form->{rowcount} = $count;
  1918. }
  1919. $form->{rowcount}++;
  1920. if ( $form->{display_form} ) {
  1921. &{"$form->{display_form}"};
  1922. }
  1923. }
  1924. sub vendor_pricelist {
  1925. @flds =
  1926. qw(runningnumber id sku partnumber description lastcost unit partsgroup curr leadtime);
  1927. $form->{rowcount}--;
  1928. # remove empty rows
  1929. if ( $form->{rowcount} ) {
  1930. foreach $i ( 1 .. $form->{rowcount} ) {
  1931. for (qw(leadtime lastcost)) {
  1932. $form->{"${_}_$i"} =
  1933. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  1934. }
  1935. $var =
  1936. ( $form->{"partnumber_$i"} )
  1937. ? $form->{"sku_$i"}
  1938. : qq|_$form->{"sku_$i"}|;
  1939. $ndx{$var} = $i;
  1940. }
  1941. $i = 1;
  1942. for ( sort keys %ndx ) { $form->{"runningnumber_$ndx{$_}"} = $i++ }
  1943. foreach $i ( 1 .. $form->{rowcount} ) {
  1944. if ( $form->{"sku_$i"} ) {
  1945. push @a, {};
  1946. $j = $#a;
  1947. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1948. $count++;
  1949. }
  1950. }
  1951. $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
  1952. $form->{rowcount} = $count;
  1953. }
  1954. $form->{rowcount}++;
  1955. if ( $form->{display_form} ) {
  1956. &{"$form->{display_form}"};
  1957. }
  1958. }
  1959. sub display_pricelist {
  1960. &pricelist_header;
  1961. delete $form->{action};
  1962. $form->hide_form;
  1963. &pricelist_footer;
  1964. }
  1965. sub pricelist_header {
  1966. $form->{title} = $form->{name};
  1967. $form->header;
  1968. print qq|
  1969. <body>
  1970. <form method=post action="$form->{script}">
  1971. <table width=100%>
  1972. <tr>
  1973. <th class=listtop>$form->{title}</th>
  1974. </tr>
  1975. <tr height="5"></tr>
  1976. |;
  1977. if ( $form->{db} eq 'customer' ) {
  1978. @column_index = qw(partnumber description);
  1979. push @column_index, "partsgroup" if $form->{selectpartsgroup};
  1980. push @column_index, qw(pricebreak sellprice curr validfrom validto);
  1981. $column_header{pricebreak} =
  1982. qq|<th class=listheading nowrap>|
  1983. . $locale->text('Break')
  1984. . qq|</th>|;
  1985. $column_header{sellprice} =
  1986. qq|<th class=listheading nowrap>|
  1987. . $locale->text('Sell Price')
  1988. . qq|</th>|;
  1989. $column_header{validfrom} =
  1990. qq|<th class=listheading nowrap>| . $locale->text('From') . qq|</th>|;
  1991. $column_header{validto} =
  1992. qq|<th class=listheading nowrap>| . $locale->text('To') . qq|</th>|;
  1993. }
  1994. if ( $form->{db} eq 'vendor' ) {
  1995. @column_index = qw(sku partnumber description);
  1996. push @column_index, "partsgroup" if $form->{selectpartsgroup};
  1997. push @column_index, qw(lastcost curr leadtime);
  1998. $column_header{sku} =
  1999. qq|<th class=listheading nowrap>| . $locale->text('SKU') . qq|</th>|;
  2000. $column_header{leadtime} =
  2001. qq|<th class=listheading nowrap>|
  2002. . $locale->text('Leadtime')
  2003. . qq|</th>|;
  2004. $column_header{lastcost} =
  2005. qq|<th class=listheading nowrap>| . $locale->text('Cost') . qq|</th>|;
  2006. }
  2007. $column_header{partnumber} =
  2008. qq|<th class=listheading nowrap>| . $locale->text('Number') . qq|</th>|;
  2009. $column_header{description} =
  2010. qq|<th class=listheading nowrap width=80%>|
  2011. . $locale->text('Description')
  2012. . qq|</th>|;
  2013. $column_header{partsgroup} =
  2014. qq|<th class=listheading nowrap>| . $locale->text('Group') . qq|</th>|;
  2015. $column_header{curr} =
  2016. qq|<th class=listheading nowrap>| . $locale->text('Curr') . qq|</th>|;
  2017. print qq|
  2018. <tr>
  2019. <td>
  2020. <table width=100%>
  2021. <tr class=listheading>
  2022. |;
  2023. for (@column_index) { print "\n$column_header{$_}" }
  2024. print qq|
  2025. </tr>
  2026. |;
  2027. $sameid = "";
  2028. foreach $i ( 1 .. $form->{rowcount} ) {
  2029. $selectcurrency = $form->{selectcurrency};
  2030. $selectcurrency =~
  2031. s/option>\Q$form->{"curr_$i"}\E/option selected>$form->{"curr_$i"}/;
  2032. if ( $form->{selectpartsgroup} ) {
  2033. if ( $i < $form->{rowcount} ) {
  2034. ($partsgroup) = split /--/, $form->{"partsgroup_$i"};
  2035. $column_data{partsgroup} = qq|<td>$partsgroup</td>
  2036. <input type=hidden name="partsgroup_$i" value="|
  2037. . $form->quote( $form->{"partsgroup_$i"} ) . qq|">|;
  2038. }
  2039. }
  2040. if ( $i < $form->{rowcount} ) {
  2041. if ( $form->{"id_$i"} eq $sameid ) {
  2042. for (qw(partnumber description partsgroup)) {
  2043. $column_data{$_} = qq|<td>&nbsp;</td>
  2044. <input type=hidden name="${_}_$i" value="|
  2045. . $form->quote( $form->{"${_}_$i"} ) . qq|">|;
  2046. }
  2047. }
  2048. else {
  2049. $column_data{sku} =
  2050. qq|<td><input name="sku_$i" value="$form->{"sku_$i"}"></td>|;
  2051. $column_data{partnumber} =
  2052. qq|<td><input name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
  2053. $column_data{description} =
  2054. qq|<td>$form->{"description_$i"}&nbsp;</td>
  2055. <input type=hidden name="description_$i" value="|
  2056. . $form->quote( $form->{"description_$i"} ) . qq|">|;
  2057. }
  2058. $column_data{partnumber} .= qq|
  2059. <input type=hidden name="id_$i" value="$form->{"id_$i"}">|;
  2060. }
  2061. else {
  2062. if ( $form->{db} eq 'customer' ) {
  2063. $column_data{partnumber} =
  2064. qq|<td><input name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
  2065. }
  2066. else {
  2067. $column_data{partnumber} = qq|<td>&nbsp;</td>|;
  2068. }
  2069. $column_data{partnumber} .= qq|
  2070. <input type=hidden name="id_$i" value="$form->{"id_$i"}">|;
  2071. $column_data{sku} =
  2072. qq|<td><input name="sku_$i" value="$form->{"sku_$i"}"></td>|;
  2073. $column_data{description} =
  2074. qq|<td><input name="description_$i" value="$form->{"description_$i"}"></td>|;
  2075. if ( $form->{selectpartsgroup} ) {
  2076. $selectpartsgroup = "<option>";
  2077. foreach $line ( split /\n/, $form->{selectpartsgroup} ) {
  2078. $selectpartsgroup .=
  2079. qq|\n<option value="|
  2080. . $form->quote($line) . qq|">|
  2081. . ( split /--/, $line )[0];
  2082. }
  2083. $column_data{partsgroup} =
  2084. qq|<td><select name="partsgroup_$i">$selectpartsgroup</select></td>|;
  2085. }
  2086. }
  2087. if ( $form->{db} eq 'customer' ) {
  2088. $column_data{pricebreak} =
  2089. qq|<td align=right><input name="pricebreak_$i" size=5 value="|
  2090. . $form->format_amount( \%myconfig, $form->{"pricebreak_$i"} )
  2091. . qq|"></td>|;
  2092. $column_data{sellprice} =
  2093. qq|<td align=right><input name="sellprice_$i" size=10 value="|
  2094. . $form->format_amount( \%myconfig, $form->{"sellprice_$i"}, 2 )
  2095. . qq|"></td>|;
  2096. $column_data{validfrom} =
  2097. qq|<td><input name="validfrom_$i" size=11 value="$form->{"validfrom_$i"}"></td>|;
  2098. $column_data{validto} =
  2099. qq|<td><input name="validto_$i" size=11 value="$form->{"validto_$i"}"></td>|;
  2100. }
  2101. if ( $form->{db} eq 'vendor' ) {
  2102. $column_data{leadtime} =
  2103. qq|<td align=right><input name="leadtime_$i" size=5 value="|
  2104. . $form->format_amount( \%myconfig, $form->{"leadtime_$i"} )
  2105. . qq|"></td>|;
  2106. $column_data{lastcost} =
  2107. qq|<td align=right><input name="lastcost_$i" size=10 value="|
  2108. . $form->format_amount( \%myconfig, $form->{"lastcost_$i"}, 2 )
  2109. . qq|"></td>|;
  2110. }
  2111. $column_data{curr} =
  2112. qq|<td><select name="curr_$i">$selectcurrency</select></td>|;
  2113. print qq|<tr valign=top>|;
  2114. for (@column_index) { print "\n$column_data{$_}" }
  2115. print qq|</tr>|;
  2116. $sameid = $form->{"id_$i"};
  2117. }
  2118. print qq|
  2119. </table>
  2120. </td>
  2121. </tr>
  2122. <tr>
  2123. <td><hr size=3 noshade></td>
  2124. </tr>
  2125. </table>
  2126. |;
  2127. # delete variables
  2128. foreach $i ( 1 .. $form->{rowcount} ) {
  2129. for ( @column_index, "id" ) { delete $form->{"${_}_$i"} }
  2130. }
  2131. for (qw(title titlebar script none)) { delete $form->{$_} }
  2132. }
  2133. sub pricelist_footer {
  2134. # type=submit $locale->text('Update')
  2135. # type=submit $locale->text('Save Pricelist')
  2136. %button = (
  2137. 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  2138. 'save_pricelist' =>
  2139. { ndx => 3, key => 'S', value => $locale->text('Save Pricelist') },
  2140. );
  2141. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  2142. $form->print_button( \%button, $_ );
  2143. }
  2144. print qq|
  2145. </form>
  2146. </body>
  2147. </html>
  2148. |;
  2149. }
  2150. sub update {
  2151. $i = $form->{rowcount};
  2152. $additem = 0;
  2153. if ( $form->{db} eq 'customer' ) {
  2154. $additem = 1
  2155. if !(( $form->{"partnumber_$i"} eq "" )
  2156. && ( $form->{"description_$i"} eq "" )
  2157. && ( $form->{"partsgroup_$i"} eq "" ) );
  2158. }
  2159. if ( $form->{db} eq 'vendor' ) {
  2160. if (
  2161. !(
  2162. ( $form->{"sku_$i"} eq "" )
  2163. && ( $form->{"description_$i"} eq "" )
  2164. && ( $form->{"partsgroup_$i"} eq "" )
  2165. )
  2166. )
  2167. {
  2168. $additem = 1;
  2169. $form->{"partnumber_$i"} = $form->{"sku_$i"};
  2170. }
  2171. }
  2172. if ($additem) {
  2173. CT->retrieve_item( \%myconfig, \%$form );
  2174. $rows = scalar @{ $form->{item_list} };
  2175. if ( $rows > 0 ) {
  2176. if ( $rows > 1 ) {
  2177. &select_item;
  2178. exit;
  2179. }
  2180. else {
  2181. $sellprice = $form->{"sellprice_$i"};
  2182. $pricebreak = $form->{"pricebreak_$i"};
  2183. $lastcost = $form->{"lastcost_$i"};
  2184. for (qw(partnumber description)) {
  2185. $form->{item_list}[0]{$_} =
  2186. $form->quote( $form->{item_list}[0]{$_} );
  2187. }
  2188. for ( keys %{ $form->{item_list}[0] } ) {
  2189. $form->{"${_}_$i"} = $form->{item_list}[0]{$_};
  2190. }
  2191. if ( $form->{db} eq 'customer' ) {
  2192. if ($sellprice) {
  2193. $form->{"sellprice_$i"} = $sellprice;
  2194. }
  2195. $form->{"sellprice_$i"} =
  2196. $form->format_amount( \%myconfig, $form->{"sellprice_$i"},
  2197. 2 );
  2198. $form->{"pricebreak_$i"} = $pricebreak;
  2199. }
  2200. else {
  2201. foreach $j ( 1 .. $form->{rowcount} - 1 ) {
  2202. if ( $form->{"sku_$j"} eq $form->{"partnumber_$i"} ) {
  2203. $form->error(
  2204. $locale->text('Item already on pricelist!') );
  2205. }
  2206. }
  2207. if ($lastcost) {
  2208. $form->{"lastcost_$i"} = $lastcost;
  2209. }
  2210. $form->{"lastcost_$i"} =
  2211. $form->format_amount( \%myconfig, $form->{"lastcost_$i"},
  2212. 2 );
  2213. $form->{"sku_$i"} = $form->{"partnumber_$i"};
  2214. # delete $form->{"partnumber_$i"};
  2215. }
  2216. $form->{rowcount}++;
  2217. }
  2218. }
  2219. else {
  2220. $form->error( $locale->text('Item not on file!') );
  2221. }
  2222. }
  2223. &{"$form->{db}_pricelist"};
  2224. }
  2225. sub select_item {
  2226. @column_index =
  2227. qw(ndx partnumber description partsgroup unit sellprice lastcost);
  2228. $column_data{ndx} = qq|<th>&nbsp;</th>|;
  2229. $column_data{partnumber} =
  2230. qq|<th class=listheading>| . $locale->text('Number') . qq|</th>|;
  2231. $column_data{description} =
  2232. qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
  2233. $column_data{partsgroup} =
  2234. qq|<th class=listheading>| . $locale->text('Group') . qq|</th>|;
  2235. $column_data{unit} =
  2236. qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
  2237. $column_data{sellprice} =
  2238. qq|<th class=listheading>| . $locale->text('Sell Price') . qq|</th>|;
  2239. $column_data{lastcost} =
  2240. qq|<th class=listheading>| . $locale->text('Cost') . qq|</th>|;
  2241. $form->header;
  2242. $title = $locale->text('Select items');
  2243. print qq|
  2244. <body>
  2245. <form method=post action="$form->{script}">
  2246. <table width=100%>
  2247. <tr>
  2248. <th class=listtop>$title</th>
  2249. </tr>
  2250. <tr height="5"></tr>
  2251. <tr>
  2252. <td>$option</td>
  2253. </tr>
  2254. <tr>
  2255. <td>
  2256. <table width=100%>
  2257. <tr class=listheading>|;
  2258. for (@column_index) { print "\n$column_data{$_}" }
  2259. print qq|
  2260. </tr>
  2261. |;
  2262. my $i = 0;
  2263. foreach $ref ( @{ $form->{item_list} } ) {
  2264. $i++;
  2265. for (qw(partnumber description unit)) {
  2266. $ref->{$_} = $form->quote( $ref->{$_} );
  2267. }
  2268. $column_data{ndx} =
  2269. qq|<td><input name="ndx_$i" class=checkbox type=checkbox value=$i></td>|;
  2270. for (qw(partnumber description partsgroup unit)) {
  2271. $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>|;
  2272. }
  2273. $column_data{sellprice} =
  2274. qq|<td align=right>|
  2275. . $form->format_amount( \%myconfig, $ref->{sellprice}, 2, "&nbsp;" )
  2276. . qq|</td>|;
  2277. $column_data{lastcost} =
  2278. qq|<td align=right>|
  2279. . $form->format_amount( \%myconfig, $ref->{lastcost}, 2, "&nbsp;" )
  2280. . qq|</td>|;
  2281. $j++;
  2282. $j %= 2;
  2283. print qq|
  2284. <tr class=listrow$j>|;
  2285. for (@column_index) { print "\n$column_data{$_}" }
  2286. print qq|
  2287. </tr>
  2288. |;
  2289. for (
  2290. qw(partnumber description partsgroup partsgroup_id sellprice lastcost unit id)
  2291. )
  2292. {
  2293. print
  2294. qq|<input type=hidden name="new_${_}_$i" value="$ref->{$_}">\n|;
  2295. }
  2296. }
  2297. print qq|
  2298. </table>
  2299. </td>
  2300. </tr>
  2301. <tr>
  2302. <td><hr size=3 noshade></td>
  2303. </tr>
  2304. </table>
  2305. <input name="lastndx" type="hidden" value="$i">
  2306. |;
  2307. # delete action variable
  2308. for (qw(nextsub item_list)) { delete $form->{$_} }
  2309. $form->{action} = "item_selected";
  2310. $form->hide_form;
  2311. print qq|
  2312. <input type="hidden" name="nextsub" value="item_selected">
  2313. <br>
  2314. <button class="submit" type="submit" name="action" value="continue">|
  2315. . $locale->text('Continue')
  2316. . qq|</button>
  2317. </form>
  2318. </body>
  2319. </html>
  2320. |;
  2321. }
  2322. sub item_selected {
  2323. # add rows
  2324. $i = $form->{rowcount};
  2325. %id = ();
  2326. for $i ( 1 .. $form->{rowcount} - 1 ) {
  2327. $id{ $form->{"id_$i"} } = 1;
  2328. }
  2329. for $j ( 1 .. $form->{lastndx} ) {
  2330. if ( $form->{"ndx_$j"} ) {
  2331. if ( $id{ $form->{"new_id_$j"} } ) {
  2332. next if $form->{db} eq 'vendor';
  2333. }
  2334. for (qw(id partnumber description unit sellprice lastcost)) {
  2335. $form->{"${_}_$i"} = $form->{"new_${_}_$j"};
  2336. }
  2337. $form->{"partsgroup_$i"} =
  2338. qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|;
  2339. $form->{"sku_$i"} = $form->{"new_partnumber_$j"};
  2340. $i++;
  2341. }
  2342. }
  2343. $form->{rowcount} = $i;
  2344. # delete all the new_ variables
  2345. for $i ( 1 .. $form->{lastndx} ) {
  2346. for (
  2347. qw(id partnumber description unit sellprice lastcost partsgroup partsgroup_id)
  2348. )
  2349. {
  2350. delete $form->{"new_${_}_$i"};
  2351. }
  2352. delete $form->{"ndx_$i"};
  2353. }
  2354. for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
  2355. &{"$form->{db}_pricelist"};
  2356. }
  2357. sub save_pricelist {
  2358. &{"CT::save_$form->{db}"}( "", \%myconfig, \%$form );
  2359. $callback = $form->{callback};
  2360. $form->{callback} = "$form->{script}?action=edit";
  2361. for (qw(db id login path sessionid)) {
  2362. $form->{callback} .= "&$_=$form->{$_}";
  2363. }
  2364. $form->{callback} .= "&callback=" . $form->escape( $callback, 1 );
  2365. if ( CT->save_pricelist( \%myconfig, \%$form ) ) {
  2366. $form->redirect;
  2367. }
  2368. else {
  2369. $form->error( $locale->text('Could not save pricelist!') );
  2370. }
  2371. }
  2372. sub add_transaction {
  2373. $form->isblank( "name", $locale->text("Name missing!") );
  2374. &{"CT::save_$form->{db}"}( "", \%myconfig, \%$form );
  2375. $form->{callback} = $form->escape( $form->{callback}, 1 );
  2376. $name = $form->escape( $form->{name}, 1 );
  2377. $form->{callback} =
  2378. "$form->{script}?login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}";
  2379. $form->redirect;
  2380. }
  2381. sub ap_transaction {
  2382. $form->{script} = "ap.pl";
  2383. $form->{type} = "ap_transaction";
  2384. &add_transaction;
  2385. }
  2386. sub ar_transaction {
  2387. $form->{script} = "ar.pl";
  2388. $form->{type} = "ar_transaction";
  2389. &add_transaction;
  2390. }
  2391. sub sales_invoice {
  2392. $form->{script} = "is.pl";
  2393. $form->{type} = "invoice";
  2394. &add_transaction;
  2395. }
  2396. sub pos {
  2397. $form->{script} = "ps.pl";
  2398. $form->{type} = "pos_invoice";
  2399. &add_transaction;
  2400. }
  2401. sub vendor_invoice {
  2402. $form->{script} = "ir.pl";
  2403. $form->{type} = "invoice";
  2404. &add_transaction;
  2405. }
  2406. sub rfq {
  2407. $form->{script} = "oe.pl";
  2408. $form->{type} = "request_quotation";
  2409. &add_transaction;
  2410. }
  2411. sub quotation {
  2412. $form->{script} = "oe.pl";
  2413. $form->{type} = "sales_quotation";
  2414. &add_transaction;
  2415. }
  2416. sub sales_order {
  2417. $form->{script} = "oe.pl";
  2418. $form->{type} = "sales_order";
  2419. &add_transaction;
  2420. }
  2421. sub purchase_order {
  2422. $form->{script} = "oe.pl";
  2423. $form->{type} = "purchase_order";
  2424. &add_transaction;
  2425. }
  2426. sub save_as_new {
  2427. delete $form->{id};
  2428. &save;
  2429. }
  2430. sub save {
  2431. # $locale->text('Customer saved!')
  2432. # $locale->text('Vendor saved!')
  2433. $msg = ucfirst $form->{db};
  2434. $msg .= " saved!";
  2435. $form->isblank( "name", $locale->text("Name missing!") );
  2436. &{"CT::save_$form->{db}"}( "", \%myconfig, \%$form );
  2437. $form->redirect( $locale->text($msg) );
  2438. }
  2439. sub delete {
  2440. # $locale->text('Customer deleted!')
  2441. # $locale->text('Cannot delete customer!')
  2442. # $locale->text('Vendor deleted!')
  2443. # $locale->text('Cannot delete vendor!')
  2444. CT->delete( \%myconfig, \%$form );
  2445. $msg = ucfirst $form->{db};
  2446. $msg .= " deleted!";
  2447. $form->redirect( $locale->text($msg) );
  2448. }
  2449. sub continue { &{ $form->{nextsub} } }
  2450. sub add_customer { &add }
  2451. sub add_vendor { &add }