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