summaryrefslogtreecommitdiff
path: root/bin/ct.pl
blob: 3b664096a196e3f5b76aabfb72e96980b2f8f87b (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. my %hiddens;
  307. my @buttons;
  308. my @options;
  309. CT->search( \%myconfig, \%$form );
  310. my $href =
  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. $form->sort_order();
  313. my $callback =
  314. "$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}";
  315. my @columns = $form->sort_columns( id, name, "$form->{db}number", address,
  316. city, state, zipcode, country,
  317. contact, phone, fax, email,
  318. cc, bcc, employee, manager,
  319. notes, discount, terms, taxaccount,
  320. taxnumber, gifi_accno, sic_code, business,
  321. pricegroup, language, iban, bic,
  322. startdate, enddate, invnumber, invamount,
  323. invtax, invtotal, ordnumber, ordamount,
  324. ordtax, ordtotal, quonumber, quoamount,
  325. quotax, quototal
  326. );
  327. unshift @columns, "ndx";
  328. $form->{l_invnumber} = "Y" if $form->{l_transnumber};
  329. foreach my $item (qw(inv ord quo)) {
  330. if ( $form->{"l_${item}number"} ) {
  331. for (qw(amount tax total)) {
  332. $form->{"l_$item$_"} = $form->{"l_$_"};
  333. }
  334. $removeemployee = 1;
  335. $openclosed = 1;
  336. }
  337. }
  338. $form->{open} = $form->{closed} = "" if !$openclosed;
  339. my @column_index;
  340. foreach my $item (@columns) {
  341. if ( $form->{"l_$item"} eq "Y" ) {
  342. push @column_index, $item;
  343. # add column to href and callback
  344. $callback .= "&l_$item=Y";
  345. $href .= "&l_$item=Y";
  346. }
  347. }
  348. foreach my $item (qw(amount tax total transnumber)) {
  349. if ( $form->{"l_$item"} eq "Y" ) {
  350. $callback .= "&l_$item=Y";
  351. $href .= "&l_$item=Y";
  352. }
  353. }
  354. if ( $form->{status} eq 'all' ) {
  355. push @options, $locale->text('All');
  356. } elsif ( $form->{status} eq 'orphaned' ) {
  357. push @options, $locale->text('Orphaned');
  358. } elsif ( $form->{status} eq 'active' ) {
  359. push @options, $locale->text('Active');
  360. } elsif ( $form->{status} eq 'inactive' ) {
  361. push @options, $locale->text('Inactive');
  362. }
  363. if ( $form->{name} ) {
  364. $callback .= "&name=" . $form->escape( $form->{name}, 1 );
  365. $href .= "&name=" . $form->escape( $form->{name} );
  366. push @options, $locale->text('Name: [_1]', $form->{name});
  367. }
  368. if ( $form->{address} ) {
  369. $callback .= "&address=" . $form->escape( $form->{address}, 1 );
  370. $href .= "&address=" . $form->escape( $form->{address} );
  371. push @options, $locale->text('Address: [_1]', $form->{address});
  372. }
  373. if ( $form->{city} ) {
  374. $callback .= "&city=" . $form->escape( $form->{city}, 1 );
  375. $href .= "&city=" . $form->escape( $form->{city} );
  376. push @options, $locale->text('City: [_1]', $form->{city});
  377. }
  378. if ( $form->{state} ) {
  379. $callback .= "&state=" . $form->escape( $form->{state}, 1 );
  380. $href .= "&state=" . $form->escape( $form->{state} );
  381. push @options, $locale->text('State: [_1]', $form->{state});
  382. }
  383. if ( $form->{zipcode} ) {
  384. $callback .= "&zipcode=" . $form->escape( $form->{zipcode}, 1 );
  385. $href .= "&zipcode=" . $form->escape( $form->{zipcode} );
  386. push @options, $locale->text('Zip/Postal Code: [_1]', $form->{zipcode});
  387. }
  388. if ( $form->{country} ) {
  389. $callback .= "&country=" . $form->escape( $form->{country}, 1 );
  390. $href .= "&country=" . $form->escape( $form->{country} );
  391. push @options, $locale->text('Country: [_1]', $form->{country});
  392. }
  393. if ( $form->{contact} ) {
  394. $callback .= "&contact=" . $form->escape( $form->{contact}, 1 );
  395. $href .= "&contact=" . $form->escape( $form->{contact} );
  396. push @options, $locale->text('Contact: [_1]', $form->{contact});
  397. }
  398. if ( $form->{employee} ) {
  399. $callback .= "&employee=" . $form->escape( $form->{employee}, 1 );
  400. $href .= "&employee=" . $form->escape( $form->{employee} );
  401. if ( $form->{db} eq 'customer' ) {
  402. push @options, $locale->text('Salesperson: [_1]', $form->{employee});
  403. } elsif ( $form->{db} eq 'vendor' ) {
  404. push @options, $locale->text('Employee: [_1]', $form->{employee});
  405. }
  406. }
  407. my $fromdate = "";
  408. my $todate = "";
  409. if ( $form->{startdatefrom} ) {
  410. $callback .= "&startdatefrom=$form->{startdatefrom}";
  411. $href .= "&startdatefrom=$form->{startdatefrom}";
  412. $fromdate = $locale->date( \%myconfig, $form->{startdatefrom}, 1 );
  413. }
  414. if ( $form->{startdateto} ) {
  415. $callback .= "&startdateto=$form->{startdateto}";
  416. $href .= "&startdateto=$form->{startdateto}";
  417. $todate = $locale->date( \%myconfig, $form->{startdateto}, 1 );
  418. }
  419. if ( $fromdate || $todate ) {
  420. push @options,
  421. $locale->text('Startdate [_1] - [_2]', $fromdate, $todate);
  422. }
  423. if ( $form->{notes} ) {
  424. $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
  425. $href .= "&notes=" . $form->escape( $form->{notes} );
  426. push @options, $locale->text('Notes: [_1]', $form->{notes});
  427. }
  428. if ( $form->{"$form->{db}number"} ) {
  429. $callback .=
  430. qq|&$form->{db}number=|
  431. . $form->escape( $form->{"$form->{db}number"}, 1 );
  432. $href .=
  433. "&$form->{db}number=" . $form->escape( $form->{"$form->{db}number"} );
  434. push @options,
  435. $locale->text('Number: [_1]', $form->{"$form->{db}number"});
  436. }
  437. if ( $form->{phone} ) {
  438. $callback .= "&phone=" . $form->escape( $form->{phone}, 1 );
  439. $href .= "&phone=" . $form->escape( $form->{phone} );
  440. push @options, $locale->text('Phone: [_1]', $form->{phone});
  441. }
  442. if ( $form->{email} ) {
  443. $callback .= "&email=" . $form->escape( $form->{email}, 1 );
  444. $href .= "&email=" . $form->escape( $form->{email} );
  445. push @options, $locale->text('E-mail: [_1]', $form->{email});
  446. }
  447. if ( $form->{transdatefrom} ) {
  448. $callback .= "&transdatefrom=$form->{transdatefrom}";
  449. $href .= "&transdatefrom=$form->{transdatefrom}";
  450. push @options, $locale->text('From [_1]',
  451. $locale->date( \%myconfig, $form->{transdatefrom}, 1 ));
  452. }
  453. if ( $form->{transdateto} ) {
  454. $callback .= "&transdateto=$form->{transdateto}";
  455. $href .= "&transdateto=$form->{transdateto}";
  456. if ( $form->{transdatefrom} ) {
  457. pop @options;
  458. push @options, $locale->text('From [_1] To [_2]',
  459. $locale->date( \%myconfig, $form->{transdatefrom}, 1 ),
  460. $locale->date( \%myconfig, $form->{transdateto}, 1 ));
  461. } else {
  462. push @options, $locale->text('To [_1]',
  463. $locale->date( \%myconfig, $form->{transdateto}, 1 ));
  464. }
  465. }
  466. if ( $form->{open} ) {
  467. $callback .= "&open=$form->{open}";
  468. $href .= "&open=$form->{open}";
  469. push @options, $locale->text('Open');
  470. }
  471. if ( $form->{closed} ) {
  472. $callback .= "&closed=$form->{closed}";
  473. $href .= "&closed=$form->{closed}";
  474. push @options, $locale->text('Closed');
  475. }
  476. $form->{callback} = "$callback&sort=$form->{sort}";
  477. $callback = $form->escape( $form->{callback} );
  478. my %column_header;
  479. $column_header{ndx} = ' ';
  480. $column_header{id} = $locale->text('ID');
  481. $column_header{"$form->{db}number"} = {
  482. href => "$href&sort=$form->{db}number",
  483. text => $locale->text('Number')
  484. };
  485. $column_header{name} = {
  486. href => "$href&sort=name",
  487. text => $locale->text('Name')
  488. };
  489. $column_header{address} = $locale->text('Address');
  490. $column_header{city} = {
  491. href => "$href&sort=city",
  492. text => $locale->text('City')
  493. };
  494. $column_header{state} = {
  495. href => "$href&sort=state",
  496. text => $locale->text('State/Province')
  497. };
  498. $column_header{zipcode} = {
  499. href => "$href&sort=zipcode",
  500. text => $locale->text('Zip/Postal Code')
  501. };
  502. $column_header{country} = {
  503. href => "$href&sort=country",
  504. text => $locale->text('Country')
  505. };
  506. $column_header{contact} = {
  507. href => "$href&sort=contact",
  508. text => $locale->text('Contact'),
  509. };
  510. $column_header{phone} = {
  511. href => "$href&sort=phone",
  512. text => $locale->text('Phone')
  513. };
  514. $column_header{fax} = {
  515. href => "$href&sort=fax",
  516. text => $locale->text('Fax')
  517. };
  518. $column_header{email} = {
  519. href => "$href&sort=email",
  520. text => $locale->text('E-mail')
  521. };
  522. $column_header{cc} = {
  523. href => "$href&sort=cc",
  524. text => $locale->text('Cc')
  525. };
  526. $column_header{bcc} = {
  527. href => "$href&sort=cc",
  528. text => $locale->text('Bcc')
  529. };
  530. $column_header{notes} = {
  531. href => "$href&sort=notes",
  532. text => $locale->text('Notes')
  533. };
  534. $column_header{discount} = '%';
  535. $column_header{terms} = $locale->text('Terms');
  536. $column_header{taxnumber} = {
  537. href => "$href&sort=taxnumber",
  538. text => $locale->text('Tax Number')
  539. };
  540. $column_header{taxaccount} = $locale->text('Tax Account');
  541. $column_header{gifi_accno} = {
  542. href => "$href&sort=gifi_accno",
  543. text => $locale->text('GIFI')
  544. };
  545. $column_header{sic_code} = {
  546. href => "$href&sort=sic_code",
  547. text => $locale->text('SIC')
  548. };
  549. $column_header{business} = {
  550. href => "$href&sort=business",
  551. text => $locale->text('Type of Business')
  552. };
  553. $column_header{iban} = $locale->text('IBAN');
  554. $column_header{bic} = $locale->text('BIC');
  555. $column_header{startdate} = {
  556. href => "$href&sort=startdate",
  557. text => $locale->text('Startdate')
  558. };
  559. $column_header{enddate} = {
  560. href => "$href&sort=enddate",
  561. text => $locale->text('Enddate')
  562. };
  563. $column_header{invnumber} = {
  564. href => "$href&sort=invnumber",
  565. text => $locale->text('Invoice')
  566. };
  567. $column_header{ordnumber} = {
  568. href => "$href&sort=ordnumber",
  569. text => $locale->text('Order')
  570. };
  571. $column_header{quonumber} = {
  572. href => "$href&sort=quonumber",
  573. text => $locale->text('Quotation')
  574. };
  575. if ( $form->{db} eq 'customer' ) {
  576. $column_header{employee} = {
  577. href => "$href&sort=employee",
  578. text => $locale->text('Salesperson')
  579. };
  580. } else {
  581. $column_header{employee} = {
  582. href => "$href&sort=employee",
  583. text => $locale->text('Employee')
  584. };
  585. }
  586. $column_header{manager} = {
  587. href => "$href&sort=manager",
  588. text => $locale->text('Manager')
  589. };
  590. $column_header{pricegroup} = {
  591. href => "$href&sort=pricegroup",
  592. text => $locale->text('Pricegroup')
  593. };
  594. $column_header{language} = {
  595. href => "$href&sort=language",
  596. text => $locale->text('Language')
  597. };
  598. $amount = $locale->text('Amount');
  599. $tax = $locale->text('Tax');
  600. $total = $locale->text('Total');
  601. $column_header{invamount} = $amount;
  602. $column_header{ordamount} = $amount;
  603. $column_header{quoamount} = $amount;
  604. $column_header{invtax} = $tax;
  605. $column_header{ordtax} = $tax;
  606. $column_header{quotax} = $tax;
  607. $column_header{invtotal} = $total;
  608. $column_header{ordtotal} = $total;
  609. $column_header{quototal} = $total;
  610. if ( $form->{status} ) {
  611. $label = ucfirst $form->{db} . "s";
  612. $form->{title} = $locale->text($label);
  613. } else {
  614. $label = ucfirst $form->{db};
  615. $form->{title} = $locale->text( $label . " Transactions" );
  616. }
  617. my $ordertype =
  618. ( $form->{db} eq 'customer' ) ? 'sales_order' : 'purchase_order';
  619. my $quotationtype =
  620. ( $form->{db} eq 'customer' ) ? 'sales_quotation' : 'request_quotation';
  621. $subtotal = 0;
  622. my $i = 0;
  623. my @rows;
  624. foreach my $ref ( @{ $form->{CT} } ) {
  625. if ( $ref->{ $form->{sort} } ne $sameitem && $form->{l_subtotal} ) {
  626. # append subtotal
  627. if ($subtotal) {
  628. push @rows, &list_subtotal;
  629. }
  630. }
  631. my %column_data;
  632. if ( $ref->{id} eq $sameid ) {
  633. for (@column_index) { $column_data{$_} = ' ' }
  634. } else {
  635. $i++;
  636. $ref->{notes} =~ s/\r?\n/<br>/g;
  637. for (@column_index) {
  638. $column_data{$_} = $ref->{$_};
  639. }
  640. $column_data{ndx} = $i;
  641. if ( $ref->{ $form->{sort} } eq $sameitem ) {
  642. $column_data{ $form->{sort} } = ' ';
  643. }
  644. $column_data{address} =
  645. "$ref->{address1} $ref->{address2}";
  646. $column_data{name} = {
  647. text => $ref->{name},
  648. 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",
  649. };
  650. $email = "";
  651. if ( $form->{sort} =~ /(email|cc)/ ) {
  652. if ( $ref->{ $form->{sort} } ne $sameitem ) {
  653. $email = 1;
  654. }
  655. } else {
  656. $email = 1;
  657. }
  658. if ($email) {
  659. foreach $item (qw(email cc bcc)) {
  660. if ( $ref->{$item} ) {
  661. $email = $ref->{$item};
  662. $column_data{$item} = {
  663. href => "mailto:$ref->{$item}",
  664. text => $email,
  665. };
  666. }
  667. }
  668. }
  669. }
  670. if ( $ref->{formtype} eq 'invoice' ) {
  671. $column_data{invnumber} = {
  672. href => "$ref->{module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback",
  673. text => $ref->{invnumber},
  674. };
  675. $column_data{invamount} =
  676. $form->format_amount( \%myconfig, $ref->{netamount}, 2, ' ' );
  677. $column_data{invtax} = $form->format_amount( \%myconfig,
  678. $ref->{amount} - $ref->{netamount}, 2, ' ' );
  679. $column_data{invtotal} =
  680. $form->format_amount( \%myconfig, $ref->{amount}, 2, ' ' );
  681. $invamountsubtotal += $ref->{netamount};
  682. $invtaxsubtotal += ( $ref->{amount} - $ref->{netamount} );
  683. $invtotalsubtotal += $ref->{amount};
  684. $subtotal = 1;
  685. } elsif ( $ref->{formtype} eq 'order' ) {
  686. $column_data{ordnumber} = {
  687. href => "$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback",
  688. text => $ref->{ordnumber},
  689. };
  690. $column_data{ordamount} =
  691. $form->format_amount( \%myconfig, $ref->{netamount}, 2, ' ' );
  692. $column_data{ordtax} = $form->format_amount( \%myconfig,
  693. $ref->{amount} - $ref->{netamount}, 2, ' ' );
  694. $column_data{ordtotal} =
  695. $form->format_amount( \%myconfig, $ref->{amount}, 2, ' ' );
  696. $ordamountsubtotal += $ref->{netamount};
  697. $ordtaxsubtotal += ( $ref->{amount} - $ref->{netamount} );
  698. $ordtotalsubtotal += $ref->{amount};
  699. $subtotal = 1;
  700. } elsif ( $ref->{formtype} eq 'quotation' ) {
  701. $column_data{quonumber} = {
  702. href => "$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback",
  703. text => $ref->{quonumber},
  704. };
  705. $column_data{quoamount} =
  706. $form->format_amount( \%myconfig, $ref->{netamount}, 2, ' ' );
  707. $column_data{quotax} = $form->format_amount( \%myconfig,
  708. $ref->{amount} - $ref->{netamount}, 2, ' ' );
  709. $column_data{quototal} =
  710. $form->format_amount( \%myconfig, $ref->{amount}, 2, ' ' );
  711. $quoamountsubtotal += $ref->{netamount};
  712. $quotaxsubtotal += ( $ref->{amount} - $ref->{netamount} );
  713. $quototalsubtotal += $ref->{amount};
  714. $subtotal = 1;
  715. }
  716. if ( $sameid ne "$ref->{id}" ) {
  717. if ( $form->{l_discount} ) {
  718. $column_data{discount} =
  719. $form->format_amount( \%myconfig, $ref->{discount} * 100,
  720. "", ' ' );
  721. }
  722. if ( $form->{l_terms} ) {
  723. $column_data{terms} =
  724. $form->format_amount( \%myconfig, $ref->{terms}, "", ' ' );
  725. }
  726. }
  727. $j++;
  728. $j %= 2;
  729. $column_data{i} = $j;
  730. $sameitem = $ref->{$form->{sort}};
  731. $sameid = $ref->{id};
  732. push @rows, \%column_data;
  733. }
  734. if ( $form->{l_subtotal} && $subtotal ) {
  735. push @rows, &list_subtotal;
  736. }
  737. $i = 1;
  738. if ( $myconfig{acs} !~ /AR--AR/ ) {
  739. if ( $form->{db} eq 'customer' ) {
  740. $button{'AR--Customers--Add Customer'}{code} = {
  741. name => 'action',
  742. value => 'add_customer',
  743. text => $locale->text('Add Customer'),
  744. };
  745. $button{'AR--Customers--Add Customer'}{order} = $i++;
  746. }
  747. }
  748. if ( $myconfig{acs} !~ /AP--AP/ ) {
  749. if ( $form->{db} eq 'vendor' ) {
  750. $button{'AP--Vendors--Add Vendor'}{code} = {
  751. name => 'action',
  752. value => 'add_vendor',
  753. text => $locale->text('Add Vendor'),
  754. };
  755. $button{'AP--Vendors--Add Vendor'}{order} = $i++;
  756. }
  757. }
  758. foreach $item ( split /;/, $myconfig{acs} ) {
  759. delete $button{$item};
  760. }
  761. $hiddens{$_} = $form->{$_} foreach qw(callback db path login sessionid);
  762. if ( $form->{status} ) {
  763. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  764. push @buttons, $item->{code};
  765. }
  766. }
  767. ##SC: Temporary removal
  768. ## if ( $form->{lynx} ) {
  769. ## require "bin/menu.pl";
  770. ## &menubar;
  771. ## }
  772. my $template = LedgerSMB::Template->new_UI(
  773. user => \%myconfig,
  774. locale => $locale,
  775. template => 'form-dynatable',
  776. );
  777. $template->render({
  778. form => $form,
  779. user => \%myconfig,
  780. hiddens => \%hiddens,
  781. buttons => \@buttons,
  782. options => \@options,
  783. rows => \@rows,
  784. columns => \@column_index,
  785. heading => \%column_header,
  786. });
  787. }
  788. sub list_subtotal {
  789. my %column_data;
  790. $column_data{invamount} =
  791. $form->format_amount( \%myconfig, $invamountsubtotal, 2, ' ' );
  792. $column_data{invtax} =
  793. $form->format_amount( \%myconfig, $invtaxsubtotal, 2, ' ' );
  794. $column_data{invtotal} =
  795. $form->format_amount( \%myconfig, $invtotalsubtotal, 2, ' ' );
  796. $invamountsubtotal = 0;
  797. $invtaxsubtotal = 0;
  798. $invtotalsubtotal = 0;
  799. $column_data{ordamount} =
  800. $form->format_amount( \%myconfig, $ordamountsubtotal, 2, ' ' );
  801. $column_data{ordtax} =
  802. $form->format_amount( \%myconfig, $ordtaxsubtotal, 2, ' ' );
  803. $column_data{ordtotal} =
  804. $form->format_amount( \%myconfig, $ordtotalsubtotal, 2, ' ' );
  805. $ordamountsubtotal = 0;
  806. $ordtaxsubtotal = 0;
  807. $ordtotalsubtotal = 0;
  808. $column_data{quoamount} =
  809. $form->format_amount( \%myconfig, $quoamountsubtotal, 2, ' ' );
  810. $column_data{quotax} =
  811. $form->format_amount( \%myconfig, $quotaxsubtotal, 2, ' ' );
  812. $column_data{quototal} =
  813. $form->format_amount( \%myconfig, $quototalsubtotal, 2, ' ' );
  814. $quoamountsubtotal = 0;
  815. $quotaxsubtotal = 0;
  816. $quototalsubtotal = 0;
  817. $column_data{class} = 'subtotal';
  818. \%column_data;
  819. }
  820. sub list_history {
  821. CT->get_history( \%myconfig, \%$form );
  822. my %hiddens;
  823. my @buttons;
  824. my $href =
  825. "$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}";
  826. $form->sort_order();
  827. my $callback =
  828. "$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}";
  829. $form->{l_fxsellprice} = $form->{l_curr};
  830. my @columns = $form->sort_columns( partnumber, description, qty, unit,
  831. sellprice, fxsellprice, curr, discount,
  832. deliverydate, projectnumber, serialnumber
  833. );
  834. if ( $form->{history} eq 'summary' ) {
  835. @columns =
  836. $form->sort_columns( partnumber, description, qty, unit, sellprice,
  837. curr );
  838. }
  839. my @column_index;
  840. foreach $item (@columns) {
  841. if ( $form->{"l_$item"} eq "Y" ) {
  842. push @column_index, $item;
  843. # add column to href and callback
  844. $callback .= "&l_$item=Y";
  845. $href .= "&l_$item=Y";
  846. }
  847. }
  848. my @options;
  849. if ( $form->{history} eq 'detail' ) {
  850. push @options, $locale->text('Detail');
  851. } elsif ( $form->{history} eq 'summary' ) {
  852. push @options, $locale->text('Summary');
  853. }
  854. if ( $form->{name} ) {
  855. $callback .= "&name=" . $form->escape( $form->{name}, 1 );
  856. $href .= "&name=" . $form->escape( $form->{name} );
  857. push @options, $locale->text('Name: [_1]', $form->{name});
  858. }
  859. if ( $form->{contact} ) {
  860. $callback .= "&contact=" . $form->escape( $form->{contact}, 1 );
  861. $href .= "&contact=" . $form->escape( $form->{contact} );
  862. push @options, $locale->text('Contact: [_1]', $form->{contact});
  863. }
  864. if ( $form->{"$form->{db}number"} ) {
  865. $callback .=
  866. qq|&$form->{db}number=|
  867. . $form->escape( $form->{"$form->{db}number"}, 1 );
  868. $href .=
  869. "&$form->{db}number=" . $form->escape( $form->{"$form->{db}number"} );
  870. push @options, $locale->text('Number: [_1]',
  871. $form->{"$form->{db}number"});
  872. }
  873. if ( $form->{email} ) {
  874. $callback .= "&email=" . $form->escape( $form->{email}, 1 );
  875. $href .= "&email=" . $form->escape( $form->{email} );
  876. push @options, $locale->text('E-mail: [_1]', $form->{email});
  877. }
  878. if ( $form->{transdatefrom} ) {
  879. $callback .= "&transdatefrom=$form->{transdatefrom}";
  880. $href .= "&transdatefrom=$form->{transdatefrom}";
  881. push @options, $locale->text('From [_1]',
  882. $locale->date( \%myconfig, $form->{transdatefrom}, 1 ));
  883. }
  884. if ( $form->{transdateto} ) {
  885. $callback .= "&transdateto=$form->{transdateto}";
  886. $href .= "&transdateto=$form->{transdateto}";
  887. if ( $form->{transdatefrom} ) {
  888. pop @options;
  889. push @options, $locale->text('From [_1] To [_2]',
  890. $locale->date( \%myconfig, $form->{transdatefrom}, 1 ),
  891. $locale->date( \%myconfig, $form->{transdateto}, 1 ));
  892. } else {
  893. push @options, $locale->text('To [_1]',
  894. $locale->date( \%myconfig, $form->{transdateto}, 1 ));
  895. }
  896. }
  897. if ( $form->{open} ) {
  898. $callback .= "&open=$form->{open}";
  899. $href .= "&open=$form->{open}";
  900. push @options, $locale->text('Open');
  901. }
  902. if ( $form->{closed} ) {
  903. $callback .= "&closed=$form->{closed}";
  904. $href .= "&closed=$form->{closed}";
  905. push @options, $locale->text('Closed');
  906. }
  907. $form->{callback} = "$callback&sort=$form->{sort}";
  908. $callback = $form->escape( $form->{callback} );
  909. my %column_header;
  910. $column_header{partnumber} = {
  911. href => "$href&sort=partnumber",
  912. text => $locale->text('Part Number')
  913. };
  914. $column_header{description} = {
  915. href => "$href&sort=description",
  916. text => $locale->text('Description')
  917. };
  918. if ( $form->{history} eq 'summary' ) {
  919. $column_header{sellprice} = $locale->text('Total');
  920. } else {
  921. $column_header{sellprice} = $locale->text('Sell Price');
  922. }
  923. $column_header{fxsellprice} = ' ';
  924. $column_header{curr} = $locale->text('Curr');
  925. $column_header{discount} = $locale->text('Discount');
  926. $column_header{qty} = $locale->text('Qty');
  927. $column_header{unit} = $locale->text('Unit');
  928. $column_header{deliverydate} = {
  929. href => "$href&sort=deliverydate",
  930. text => $locale->text('Delivery Date')
  931. };
  932. $column_header{projectnumber} = {
  933. href => "$href&sort=projectnumber",
  934. text => $locale->text('Project Number')
  935. };
  936. $column_header{serialnumber} = {
  937. href => "$href&sort=serialnumber",
  938. text => $locale->text('Serial Number')
  939. };
  940. # $locale->text('Customer History')
  941. # $locale->text('Vendor History')
  942. $label = ucfirst $form->{db};
  943. $form->{title} = $locale->text( $label . " History" );
  944. $module = 'oe';
  945. if ( $form->{db} eq 'customer' ) {
  946. $invlabel = $locale->text('Sales Invoice');
  947. $ordlabel = $locale->text('Sales Order');
  948. $quolabel = $locale->text('Quotation');
  949. $ordertype = 'sales_order';
  950. $quotationtype = 'sales_quotation';
  951. if ( $form->{type} eq 'invoice' ) {
  952. $module = 'is';
  953. }
  954. } else {
  955. $invlabel = $locale->text('Vendor Invoice');
  956. $ordlabel = $locale->text('Purchase Order');
  957. $quolabel = $locale->text('RFQ');
  958. $ordertype = 'purchase_order';
  959. $quotationtype = 'request_quotation';
  960. if ( $form->{type} eq 'invoice' ) {
  961. $module = 'ir';
  962. }
  963. }
  964. $ml = ( $form->{db} eq 'vendor' ) ? -1 : 1;
  965. my @rows;
  966. foreach my $ref ( @{ $form->{CT} } ) {
  967. if ( $ref->{id} ne $sameid ) {
  968. # print the header
  969. push @rows, {
  970. class => 'divider',
  971. text => "$ref->{name} $ref->{address}"
  972. href => "$form->{script}?action=edit&id=$ref->{ctid}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback",
  973. };
  974. }
  975. if ( $form->{type} ne 'invoice' ) {
  976. $ref->{fxsellprice} = $ref->{sellprice};
  977. $ref->{sellprice} *= $ref->{exchangerate};
  978. }
  979. if ( $form->{history} eq 'detail' and $ref->{invid} ne $sameinvid ) {
  980. # print inv, ord, quo number
  981. $i++;
  982. $i %= 2;
  983. if ( $form->{type} eq 'invoice' ) {
  984. push @rows, {
  985. class => 'divider',
  986. href => "${module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback",
  987. text => "$invlabel $ref->{invnumber} / $ref->{employee}";
  988. };
  989. } elsif ( $form->{type} eq 'order' ) {
  990. push @rows, {
  991. class => 'divider',
  992. href => "${module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback",
  993. text => "$ordlabel $ref->{ordnumber} / $ref->{employee}"
  994. };
  995. } elsif ( $form->{type} eq 'quotation' ) {
  996. push @rows, {
  997. class => 'divider',
  998. href => "${module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback",
  999. text => "$quolabel $ref->{quonumber} / $ref->{employee}"
  1000. };
  1001. }
  1002. }
  1003. my %column_data;
  1004. for (@column_index) { $column_data{$_} = $ref->{$_} }
  1005. if ( $form->{l_curr} ) {
  1006. $column_data{fxsellprice} =
  1007. $form->format_amount( \%myconfig, $ref->{fxsellprice}, 2 );
  1008. }
  1009. $column_data{sellprice} =
  1010. $form->format_amount( \%myconfig, $ref->{sellprice}, 2 );
  1011. $column_data{qty} =
  1012. $form->format_amount( \%myconfig, $ref->{qty} * $ml );
  1013. $column_data{discount} =
  1014. $form->format_amount( \%myconfig, $ref->{discount} * 100, "", ' ' );
  1015. $column_data{partnumber} = {
  1016. href => "ic.pl?action=edit&id=$ref->{pid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback"
  1017. text => $ref->{partnumber}
  1018. };
  1019. $i++;
  1020. $i %= 2;
  1021. $column_data{i} = $i;
  1022. push @rows, \%column_data;
  1023. $sameid = $ref->{id};
  1024. $sameinvid = $ref->{invid};
  1025. }
  1026. ##SC: Temporary removal
  1027. ## if ( $form->{lynx} ) {
  1028. ## require "bin/menu.pl";
  1029. ## &menubar;
  1030. ## }
  1031. my $template = LedgerSMB::Template->new_UI(
  1032. user => \%myconfig,
  1033. locale => $locale,
  1034. template => 'form-dynatable',
  1035. );
  1036. $template->render({
  1037. form => $form,
  1038. options => \@options,
  1039. rows => \@rows,
  1040. columns => \@column_index,
  1041. heading => \%column_header,
  1042. });
  1043. }
  1044. sub edit {
  1045. # $locale->text('Edit Customer')
  1046. # $locale->text('Edit Vendor')
  1047. CT->create_links( \%myconfig, \%$form );
  1048. for ( keys %$form ) { $form->{$_} = $form->quote( $form->{$_} ) }
  1049. $form->{title} = "Edit";
  1050. # format discount
  1051. $form->{discount} *= 100;
  1052. &form_header;
  1053. &form_footer;
  1054. }
  1055. sub form_header {
  1056. $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
  1057. $form->{creditlimit} =
  1058. $form->format_amount( \%myconfig, $form->{creditlimit}, 0 );
  1059. $form->{discount} =
  1060. $form->format_amount( \%myconfig, $form->{discount}, "" );
  1061. $form->{terms} = $form->format_amount( \%myconfig, $form->{terms}, "" );
  1062. if ( $form->{currencies} ) {
  1063. # currencies
  1064. $form->{selectcurrency} = {
  1065. name => 'curr',
  1066. options => [],
  1067. default_values => $form->{curr},
  1068. };
  1069. push @{$form->{selectcurrency}{options}}, {
  1070. text => $_,
  1071. value => $_,
  1072. } foreach split /:/, $form->{currencies};
  1073. }
  1074. $form->{taxable} = [];
  1075. foreach my $item ( split / /, $form->{taxaccounts} ) {
  1076. my $temp_tax = {
  1077. name => "tax_$item",
  1078. value => 1,
  1079. type => 'checkbox',
  1080. label => $form->{tax}{$item}{description}
  1081. };
  1082. $temp_tax->{checked} = 'checked' if $form->{tax}{$item}{taxable};
  1083. push @{$form->{taxable}}, $temp_tax;
  1084. }
  1085. if (ref $form->{all_business} eq 'ARRAY') {
  1086. $form->{selectbusiness} = {
  1087. name => 'business',
  1088. options => [{text => '', value => ''}],
  1089. };
  1090. push @{$form->{selectbusiness}{options}}, {
  1091. text => $_->{description},
  1092. value => "$_->{description}--$_->{id}",
  1093. } foreach @{$form->{all_business}};
  1094. $form->{selectbusiness}{default_values} =
  1095. "$form->{business}--$form->{business_id}";
  1096. }
  1097. if (ref $form->{all_pricegroup} eq 'ARRAY' && $form->{db} eq 'customer') {
  1098. $form->{selectpricegroup} = {
  1099. name => 'pricegroup',
  1100. options => [{text => '', value => ''}],
  1101. };
  1102. push @{$form->{selectpricegroup}{options}}, {
  1103. name => $_->{pricegroup},
  1104. value => "$_->{pricegroup}--$_->{id}",
  1105. } foreach @{$form->{all_pricegroup}};
  1106. $form->{selectpricegroup}{default_values} =
  1107. "$form->{pricegroup}--$form->{pricegroup_id}";
  1108. }
  1109. if ( @{ $form->{all_language} } ) {
  1110. $form->{selectlanguage} = {
  1111. name => 'language',
  1112. options => [{text => '', value => ''}],
  1113. };
  1114. push @{$form->{selectlanguage}{options}}, {
  1115. text => $_->{description},
  1116. value => "$_->{description}--$_->{code}",
  1117. } foreach @{$form->{all_language}};
  1118. $form->{selectlangauge}{default_values} =
  1119. "$form->{language}--$form->{language_code}";
  1120. }
  1121. $form->{selectemployee} = {
  1122. name => 'employee',
  1123. options => [{text => '', value => ''}],
  1124. default_values => "$form->{employee}--$form->{employee_id}",
  1125. };
  1126. push @{$form->{selectemployee}{options}}, {
  1127. text => $_->{name},
  1128. value => "$_->{name}--$_->{id}",
  1129. } foreach @{$form->{all_employee}};
  1130. if (ref $form->{all_employee} eq 'ARRAY') {
  1131. if ( $myconfig{role} eq 'user' && $form->{id} ) {
  1132. $hiddens{employee} = "$form->{employee}--$form->{employee_id}";
  1133. }
  1134. }
  1135. # $locale->text('Customer Number')
  1136. # $locale->text('Vendor Number')
  1137. $label = ucfirst $form->{db};
  1138. $form->{label} = $label;
  1139. $form->{title} = $locale->text("$form->{title} $label");
  1140. }
  1141. sub form_footer {
  1142. # type=submit $locale->text('Save')
  1143. # type=submit $locale->text('Save as new')
  1144. # type=submit $locale->text('AR Transaction')
  1145. # type=submit $locale->text('Sales Invoice')
  1146. # type=submit $locale->text('Sales Order')
  1147. # type=submit $locale->text('Quotation')
  1148. # type=submit $locale->text('AP Transaction')
  1149. # type=submit $locale->text('Vendor Invoice')
  1150. # type=submit $locale->text('Purchase Order')
  1151. # type=submit $locale->text('RFQ')
  1152. # type=submit $locale->text('Pricelist')
  1153. # type=submit $locale->text('Delete')
  1154. # type=submit $locale->text('POS')
  1155. my %hiddens;
  1156. my @buttons;
  1157. %button = (
  1158. 'save' => { ndx => 1, key => 'S', value => $locale->text('Save') },
  1159. 'save_as_new' =>
  1160. { ndx => 2, key => 'N', value => $locale->text('Save as new') },
  1161. 'ar_transaction' =>
  1162. { ndx => 7, key => 'A', value => $locale->text('AR Transaction') },
  1163. 'ap_transaction' =>
  1164. { ndx => 8, key => 'A', value => $locale->text('AP Transaction') },
  1165. 'sales_invoice' =>
  1166. { ndx => 9, key => 'I', value => $locale->text('Sales Invoice') },
  1167. 'pos' => { ndx => 10, key => 'C', value => $locale->text('POS') },
  1168. 'sales_order' =>
  1169. { ndx => 11, key => 'O', value => $locale->text('Sales Order') },
  1170. 'quotation' =>
  1171. { ndx => 12, key => 'Q', value => $locale->text('Quotation') },
  1172. 'vendor_invoice' =>
  1173. { ndx => 13, key => 'I', value => $locale->text('Vendor Invoice') },
  1174. 'purchase_order' =>
  1175. { ndx => 14, key => 'O', value => $locale->text('Purchase Order') },
  1176. 'rfq' => { ndx => 15, key => 'Q', value => $locale->text('RFQ') },
  1177. 'pricelist' =>
  1178. { ndx => 16, key => 'P', value => $locale->text('Pricelist') },
  1179. 'delete' => { ndx => 17, key => 'D', value => $locale->text('Delete') },
  1180. );
  1181. my %blist = ();
  1182. if ( $form->{db} eq 'customer' ) {
  1183. if ( $myconfig{acs} !~ /AR--Customers--Add Customer/ ) {
  1184. $blist{'save'} = 1;
  1185. if ( $form->{id} ) {
  1186. $blist{'save_as_new'} = 1;
  1187. if ( $form->{status} eq 'orphaned' ) {
  1188. $blist{'delete'} = 1;
  1189. }
  1190. }
  1191. }
  1192. if ( $myconfig{acs} !~ /AR--AR/ ) {
  1193. if ( $myconfig{acs} !~ /AR--Add Transaction/ ) {
  1194. $blist{'ar_transaction'} = 1;
  1195. }
  1196. if ( $myconfig{acs} !~ /AR--Sales Invoice/ ) {
  1197. $blist{'sales_invoice'} = 1;
  1198. }
  1199. }
  1200. if ( $myconfig{acs} !~ /POS--POS/ ) {
  1201. if ( $myconfig{acs} !~ /POS--Sale/ ) {
  1202. $blist{'pos'} = 1;
  1203. }
  1204. }
  1205. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1206. if ( $myconfig{acs} !~ /Order Entry--Sales Order/ ) {
  1207. $blist{'sales_order'} = 1;
  1208. }
  1209. }
  1210. if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
  1211. if ( $myconfig{acs} !~ /Quotations--Quotation/ ) {
  1212. $blist{'quotation'} = 1;
  1213. }
  1214. }
  1215. }
  1216. if ( $form->{db} eq 'vendor' ) {
  1217. if ( $myconfig{acs} !~ /AP--Vendors--Add Vendor/ ) {
  1218. $blist{'save'} = 1;
  1219. if ( $form->{id} ) {
  1220. $blist{'save_as_new'} = 1;
  1221. if ( $form->{status} eq 'orphaned' ) {
  1222. $blist{'delete'} = 1;
  1223. }
  1224. }
  1225. }
  1226. if ( $myconfig{acs} !~ /AP--AP/ ) {
  1227. if ( $myconfig{acs} !~ /AP--Add Transaction/ ) {
  1228. $blist{'ap_transaction'} = 1;
  1229. }
  1230. if ( $myconfig{acs} !~ /AP--Vendor Invoice/ ) {
  1231. $blist{'vendor_invoice'} = 1;
  1232. }
  1233. }
  1234. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1235. if ( $myconfig{acs} !~ /Order Entry--Purchase Order/ ) {
  1236. $blist{'purchase_order'} = 1;
  1237. }
  1238. }
  1239. if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
  1240. if ( $myconfig{acs} !~ /Quotations--RFQ/ ) {
  1241. $blist{'rfq'} = 1;
  1242. }
  1243. }
  1244. }
  1245. if ( $myconfig{acs} !~ /Goods & Services--Goods & Services/ ) {
  1246. $myconfig{acs} =~
  1247. s/(Goods & Services--)Add (Service|Assembly).*;/$1--Add Part/g;
  1248. if ( $myconfig{acs} !~ /Goods & Services--Add Part/ ) {
  1249. $blist{'pricelist'} = 1;
  1250. }
  1251. }
  1252. $hiddens{$_} = $form->{$_} foreach
  1253. qw(id taxaccounts path login sessionid callback db);
  1254. for ( keys %button ) { delete $button{$_} if !$blist{$_} }
  1255. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  1256. push @buttons, {
  1257. name => 'action',
  1258. value => $_,
  1259. accesskey => $button{$_}{key},
  1260. title => "$button{$name}{value} [Alt-$button{$_}{key}]",
  1261. text => $button{$_}{value},
  1262. };
  1263. }
  1264. ##SC: Temporary removal
  1265. ## if ( $form->{lynx} ) {
  1266. ## require "bin/menu.pl";
  1267. ## &menubar;
  1268. ## }
  1269. $form->{dbnumber} = "$form->{db}number";
  1270. my $template = LedgerSMB::Template->new_UI(
  1271. user => \%myconfig,
  1272. locale => $locale,
  1273. template => 'ct-form',
  1274. );
  1275. $template->render({
  1276. form => $form,
  1277. user => \%myconfig,
  1278. hiddens => \%hiddens,
  1279. buttons => \@buttons,
  1280. options => \@options,
  1281. });
  1282. }
  1283. sub pricelist {
  1284. $form->isblank( "name", $locale->text('Name missing!') );
  1285. $form->{display_form} ||= "display_pricelist";
  1286. CT->pricelist( \%myconfig, \%$form );
  1287. foreach $ref ( @{ $form->{"all_partspricelist"} } ) {
  1288. $i++;
  1289. for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
  1290. }
  1291. $form->{rowcount} = $i;
  1292. # currencies
  1293. @curr = split /:/, $form->{currencies};
  1294. $form->{selectcurrency} = [];
  1295. for (@curr) {push @{$form->{selectcurrency}}, {text => $_, value => $_}}
  1296. if (ref $form->{all_partsgroup} eq 'ARRAY') {
  1297. $form->{selectpartsgroup} = "";
  1298. foreach $ref ( @{ $form->{all_partsgroup} } ) {
  1299. $form->{selectpartsgroup} .= qq|$ref->{partsgroup}--$ref->{id}\n|;
  1300. }
  1301. }
  1302. for (qw(currencies all_partsgroup all_partspricelist)) {
  1303. delete $form->{$_};
  1304. }
  1305. foreach $i ( 1 .. $form->{rowcount} ) {
  1306. if ( $form->{db} eq 'customer' ) {
  1307. $form->{"pricebreak_$i"} =
  1308. $form->format_amount( \%myconfig, $form->{"pricebreak_$i"} );
  1309. $form->{"sellprice_$i"} =
  1310. $form->format_amount( \%myconfig, $form->{"sellprice_$i"}, 2 );
  1311. }
  1312. if ( $form->{db} eq 'vendor' ) {
  1313. $form->{"leadtime_$i"} =
  1314. $form->format_amount( \%myconfig, $form->{"leadtime_$i"} );
  1315. $form->{"lastcost_$i"} =
  1316. $form->format_amount( \%myconfig, $form->{"lastcost_$i"}, 2 );
  1317. }
  1318. }
  1319. $form->{rowcount}++;
  1320. &{"$form->{db}_pricelist"};
  1321. }
  1322. sub customer_pricelist {
  1323. my @flds =
  1324. qw(runningnumber id partnumber description sellprice unit partsgroup pricebreak curr validfrom validto);
  1325. $form->{rowcount}--;
  1326. # remove empty rows
  1327. if ( $form->{rowcount} ) {
  1328. foreach $i ( 1 .. $form->{rowcount} ) {
  1329. for (qw(pricebreak sellprice)) {
  1330. $form->{"${_}_$i"} =
  1331. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  1332. }
  1333. ( $a, $b ) = split /\./, $form->{"pricebreak_$i"};
  1334. $a = length $a;
  1335. $b = length $b;
  1336. $whole = ( $whole > $a ) ? $whole : $a;
  1337. $dec = ( $dec > $b ) ? $dec : $b;
  1338. }
  1339. $pad1 = '0' x $whole;
  1340. $pad2 = '0' x $dec;
  1341. foreach $i ( 1 .. $form->{rowcount} ) {
  1342. ( $a, $b ) = split /\./, $form->{"pricebreak_$i"};
  1343. $a = substr( "$pad1$a", -$whole );
  1344. $b = substr( "$b$pad2", 0, $dec );
  1345. $ndx{qq|$form->{"partnumber_$i"}_$form->{"id_$i"}_$a$b|} = $i;
  1346. }
  1347. $i = 1;
  1348. for ( sort keys %ndx ) { $form->{"runningnumber_$ndx{$_}"} = $i++ }
  1349. foreach $i ( 1 .. $form->{rowcount} ) {
  1350. if ( $form->{"partnumber_$i"} && $form->{"sellprice_$i"} ) {
  1351. if ( $form->{"id_$i"} eq $sameid ) {
  1352. $j = $i + 1;
  1353. next
  1354. if ( $form->{"id_$j"} eq $sameid
  1355. && !$form->{"pricebreak_$i"} );
  1356. }
  1357. push @a, {};
  1358. $j = $#a;
  1359. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1360. $count++;
  1361. }
  1362. $sameid = $form->{"id_$i"};
  1363. }
  1364. $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
  1365. $form->{rowcount} = $count;
  1366. }
  1367. $form->{rowcount}++;
  1368. if ( $form->{display_form} ) {
  1369. &{"$form->{display_form}"};
  1370. }
  1371. }
  1372. sub vendor_pricelist {
  1373. my @flds =
  1374. qw(runningnumber id sku partnumber description lastcost unit partsgroup curr leadtime);
  1375. $form->{rowcount}--;
  1376. # remove empty rows
  1377. if ( $form->{rowcount} ) {
  1378. foreach $i ( 1 .. $form->{rowcount} ) {
  1379. for (qw(leadtime lastcost)) {
  1380. $form->{"${_}_$i"} =
  1381. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  1382. }
  1383. $var =
  1384. ( $form->{"partnumber_$i"} )
  1385. ? $form->{"sku_$i"}
  1386. : qq|_$form->{"sku_$i"}|;
  1387. $ndx{$var} = $i;
  1388. }
  1389. $i = 1;
  1390. for ( sort keys %ndx ) { $form->{"runningnumber_$ndx{$_}"} = $i++ }
  1391. foreach $i ( 1 .. $form->{rowcount} ) {
  1392. if ( $form->{"sku_$i"} ) {
  1393. push @a, {};
  1394. $j = $#a;
  1395. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1396. $count++;
  1397. }
  1398. }
  1399. $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
  1400. $form->{rowcount} = $count;
  1401. }
  1402. $form->{rowcount}++;
  1403. if ( $form->{display_form} ) {
  1404. &{"$form->{display_form}"};
  1405. }
  1406. }
  1407. sub display_pricelist {
  1408. my %hiddens;
  1409. my $buttons = &pricelist_footer;
  1410. delete $form->{action};
  1411. $hiddens{$_} = $form->{$_} foreach sort keys %$form;
  1412. &pricelist_header(\%hiddens, $buttons);
  1413. }
  1414. sub pricelist_header {
  1415. my $hiddens = shift;
  1416. my $buttons = shift;
  1417. $form->{title} = $form->{name};
  1418. my @column_index;
  1419. my %column_header;
  1420. if ( $form->{db} eq 'customer' ) {
  1421. @column_index = qw(partnumber description);
  1422. push @column_index, "partsgroup" if $form->{selectpartsgroup};
  1423. push @column_index, qw(pricebreak sellprice curr validfrom validto);
  1424. $column_header{pricebreak} = $locale->text('Break');
  1425. $column_header{sellprice} = $locale->text('Sell Price');
  1426. $column_header{validfrom} = $locale->text('From');
  1427. $column_header{validto} = $locale->text('To');
  1428. }
  1429. if ( $form->{db} eq 'vendor' ) {
  1430. @column_index = qw(sku partnumber description);
  1431. push @column_index, "partsgroup" if $form->{selectpartsgroup};
  1432. push @column_index, qw(lastcost curr leadtime);
  1433. $column_header{sku} = $locale->text('SKU');
  1434. $column_header{leadtime} = $locale->text('Leadtime');
  1435. $column_header{lastcost} = $locale->text('Cost');
  1436. }
  1437. $column_header{partnumber} = $locale->text('Number');
  1438. $column_header{description} = $locale->text('Description'); #80% width
  1439. $column_header{partsgroup} = $locale->text('Group');
  1440. $column_header{curr} = $locale->text('Curr');
  1441. $sameid = "";
  1442. my @rows;
  1443. foreach my $i ( 1 .. $form->{rowcount} ) {
  1444. my %column_data;
  1445. if ( $form->{selectpartsgroup} ) {
  1446. if ( $i < $form->{rowcount} ) {
  1447. ($partsgroup) = split /--/, $form->{"partsgroup_$i"};
  1448. $hiddens->{"partsgroup_$i"} = $form->{"partsgroup_$i"};
  1449. $column_data{partsgroup} = $partsgroup;
  1450. }
  1451. }
  1452. if ( $i < $form->{rowcount} ) {
  1453. if ( $form->{"id_$i"} eq $sameid ) {
  1454. for (qw(partnumber description partsgroup)) {
  1455. $hiddens->{"${_}_$i"} = $form->{"${_}_$i"};
  1456. $column_data{$_} = ' ';
  1457. }
  1458. } else {
  1459. $column_data{sku} = {input => {
  1460. name => "sku_$i",
  1461. value => $form->{"sku_$i"}
  1462. }};
  1463. $column_data{partnumber} = {input => {
  1464. name => "partnumber_$i",
  1465. value => $form->{"partnumber_$i"}
  1466. }};
  1467. $column_data{description} =$form->{"description_$i"};
  1468. $hiddens->{"description_$i"} = $form->{"description_$i"};
  1469. }
  1470. $hiddens->{"id_$i"} = $form->{"id_$i"};
  1471. } else {
  1472. if ( $form->{db} eq 'customer' ) {
  1473. $column_data{partnumber} = {input => {
  1474. name => "partnumber_$i",
  1475. value => $form->{"partnumber_$i"}
  1476. }};
  1477. } else {
  1478. $column_data{partnumber} = ' ';
  1479. }
  1480. $hiddens->{"id_$i"} = $form->{"id_$i"};
  1481. $column_data{sku} = {input => {
  1482. name => "sku_$i",
  1483. value => $form->{"sku_$i"}
  1484. }};
  1485. $column_data{partnumber} = {input => {
  1486. name => "partnumber_$i",
  1487. value => $form->{"partnumber_$i"}
  1488. }};
  1489. if ( $form->{selectpartsgroup} ) {
  1490. @selectpartsgroup = ({text => '', value => ''});
  1491. foreach $line ( split /\n/, $form->{selectpartsgroup} ) {
  1492. push @selectpartsgroup, {
  1493. text => (split /--/, $line)[0],
  1494. value => $line,
  1495. };
  1496. }
  1497. $column_data{partsgroup} = {'select' => {
  1498. name => "partnumber_$i",
  1499. options => \@selectpartsgroup,
  1500. }};
  1501. }
  1502. }
  1503. if ( $form->{db} eq 'customer' ) {
  1504. $column_data{pricebreak} = {input => {
  1505. name => "pricebreak_$i",
  1506. size => 5,
  1507. value => $form->format_amount(\%myconfig, $form->{"pricebreak_$i"})
  1508. }};
  1509. $column_data{sellprice} = {input => {
  1510. name => "sellprice_$i",
  1511. size => 10,
  1512. value => $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, 2)
  1513. }};
  1514. $column_data{validfrom} = {input => {
  1515. name => "validfrom_$i",
  1516. size => 11,
  1517. value => $form->{"validfrom_$i"},
  1518. }};
  1519. $column_data{validto} = {input => {
  1520. name => "validto_$i",
  1521. size => 11,
  1522. value => $form->{"validto_$i"},
  1523. }};
  1524. }
  1525. if ( $form->{db} eq 'vendor' ) {
  1526. $column_data{leadtime} = {input => {
  1527. name => "leadtime_$i",
  1528. size => 5,
  1529. value => $form->format_amount(\%myconfig, $form->{"leadtime_$i"})
  1530. }};
  1531. $column_data{lastcost} = {input => {
  1532. name => "lastcost_$i",
  1533. size => 10,
  1534. value => $form->format_amount( \%myconfig, $form->{"lastcost_$i"}, 2 )
  1535. }};
  1536. }
  1537. $column_data{curr} = {'select' => {
  1538. name => "curr_$i",
  1539. options => $form->{selectcurrency},
  1540. default_values => $form->{"curr_$i"},
  1541. }};
  1542. $sameid = $form->{"id_$i"};
  1543. push @rows, \%column_data;
  1544. }
  1545. # delete variables
  1546. foreach $i ( 1 .. $form->{rowcount} ) {
  1547. for ( @column_index, "id" ) { delete $form->{"${_}_$i"} }
  1548. }
  1549. for (qw(title titlebar script none)) { delete $form->{$_} }
  1550. my $template = LedgerSMB::Template->new_UI(
  1551. user => \%myconfig,
  1552. locale => $locale,
  1553. template => 'form-dynatable',
  1554. );
  1555. $template->render({
  1556. form => $form,
  1557. user => \%myconfig,
  1558. hiddens => $hiddens,
  1559. buttons => $buttons,
  1560. options => \@options,
  1561. rows => \@rows,
  1562. columns => \@column_index,
  1563. heading => \%column_header,
  1564. });
  1565. }
  1566. sub pricelist_footer {
  1567. # type=submit $locale->text('Update')
  1568. # type=submit $locale->text('Save Pricelist')
  1569. %button = (
  1570. 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  1571. 'save_pricelist' =>
  1572. { ndx => 3, key => 'S', value => $locale->text('Save Pricelist') },
  1573. );
  1574. my @buttons;
  1575. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  1576. push @buttons, {
  1577. name => 'action',
  1578. value => $_,
  1579. accesskey => $button{$_}{key},
  1580. title => "$button{$name}{value} [Alt-$button{$_}{key}]",
  1581. text => $button{$_}{value},
  1582. };
  1583. }
  1584. \@buttons;
  1585. }
  1586. sub update {
  1587. $i = $form->{rowcount};
  1588. $additem = 0;
  1589. if ( $form->{db} eq 'customer' ) {
  1590. $additem = 1
  1591. if !(( $form->{"partnumber_$i"} eq "" )
  1592. && ( $form->{"description_$i"} eq "" )
  1593. && ( $form->{"partsgroup_$i"} eq "" ) );
  1594. }
  1595. if ( $form->{db} eq 'vendor' ) {
  1596. if (
  1597. !(
  1598. ( $form->{"sku_$i"} eq "" )
  1599. && ( $form->{"description_$i"} eq "" )
  1600. && ( $form->{"partsgroup_$i"} eq "" )
  1601. )
  1602. )
  1603. {
  1604. $additem = 1;
  1605. $form->{"partnumber_$i"} = $form->{"sku_$i"};
  1606. }
  1607. }
  1608. if ($additem) {
  1609. CT->retrieve_item( \%myconfig, \%$form );
  1610. $rows = scalar @{ $form->{item_list} };
  1611. if ( $rows > 0 ) {
  1612. if ( $rows > 1 ) {
  1613. &select_item;
  1614. exit;
  1615. } else {
  1616. $sellprice = $form->{"sellprice_$i"};
  1617. $pricebreak = $form->{"pricebreak_$i"};
  1618. $lastcost = $form->{"lastcost_$i"};
  1619. for (qw(partnumber description)) {
  1620. $form->{item_list}[0]{$_} =
  1621. $form->quote( $form->{item_list}[0]{$_} );
  1622. }
  1623. for ( keys %{ $form->{item_list}[0] } ) {
  1624. $form->{"${_}_$i"} = $form->{item_list}[0]{$_};
  1625. }
  1626. if ( $form->{db} eq 'customer' ) {
  1627. if ($sellprice) {
  1628. $form->{"sellprice_$i"} = $sellprice;
  1629. }
  1630. $form->{"sellprice_$i"} =
  1631. $form->format_amount( \%myconfig, $form->{"sellprice_$i"},
  1632. 2 );
  1633. $form->{"pricebreak_$i"} = $pricebreak;
  1634. } else {
  1635. foreach $j ( 1 .. $form->{rowcount} - 1 ) {
  1636. if ( $form->{"sku_$j"} eq $form->{"partnumber_$i"} ) {
  1637. $form->error(
  1638. $locale->text('Item already on pricelist!') );
  1639. }
  1640. }
  1641. if ($lastcost) {
  1642. $form->{"lastcost_$i"} = $lastcost;
  1643. }
  1644. $form->{"lastcost_$i"} =
  1645. $form->format_amount( \%myconfig, $form->{"lastcost_$i"},
  1646. 2 );
  1647. $form->{"sku_$i"} = $form->{"partnumber_$i"};
  1648. # delete $form->{"partnumber_$i"};
  1649. }
  1650. $form->{rowcount}++;
  1651. }
  1652. } else {
  1653. $form->error( $locale->text('Item not on file!') );
  1654. }
  1655. }
  1656. &{"$form->{db}_pricelist"};
  1657. }
  1658. sub select_item {
  1659. my %hiddens;
  1660. my @column_index =
  1661. qw(ndx partnumber description partsgroup unit sellprice lastcost);
  1662. my %column_data;
  1663. $column_data{ndx} = ' ';
  1664. $column_data{partnumber} = locale->text('Number');
  1665. $column_data{description} = $locale->text('Description');
  1666. $column_data{partsgroup} = $locale->text('Group');
  1667. $column_data{unit} = $locale->text('Unit');
  1668. $column_data{sellprice} = $locale->text('Sell Price');
  1669. $column_data{lastcost} = $locale->text('Cost');
  1670. $form->{title} = $locale->text('Select items');
  1671. my $i = 0;
  1672. my @rows;
  1673. foreach $ref ( @{ $form->{item_list} } ) {
  1674. $i++;
  1675. my %column_data;
  1676. for (qw(partnumber description unit)) {
  1677. $ref->{$_} = $form->quote( $ref->{$_} );
  1678. }
  1679. $column_data{ndx} = {input => {
  1680. name => "ndx_$i",
  1681. type => 'checkbox',
  1682. value => $i,
  1683. }};
  1684. $column_data{$_} = $ref->{$_} foreach
  1685. qw(partnumber description partsgroup unit);
  1686. $column_data{sellprice} =
  1687. $form->format_amount( \%myconfig, $ref->{sellprice}, 2, ' ' );
  1688. $column_data{lastcost} =
  1689. $form->format_amount( \%myconfig, $ref->{lastcost}, 2, ' ' );
  1690. $j++;
  1691. $j %= 2;
  1692. $column_data{i} = $j;
  1693. push @rows, \%column_data;
  1694. $hiddens{"new_${_}_$i"} = $ref->{$_} foreach
  1695. qw(partnumber description partsgroup partsgroup_id sellprice lastcost unit id);
  1696. }
  1697. # delete action variable
  1698. for (qw(nextsub item_list)) { delete $form->{$_} }
  1699. $form->{action} = "item_selected";
  1700. $hiddens{$_} = $form->{$_} foreach sort keys %$form;
  1701. $hiddens{nextsub} = 'item_selected';
  1702. $hiddens{lastndx} = $i;
  1703. my @buttons = ({
  1704. name => 'action',
  1705. value => 'item_selected',
  1706. text => $locale->text('Continue'),
  1707. });
  1708. my $template = LedgerSMB::Template->new_UI(
  1709. user => \%myconfig,
  1710. locale => $locale,
  1711. template => 'form-dynatable',
  1712. );
  1713. $template->render({
  1714. form => $form,
  1715. user => \%myconfig,
  1716. hiddens => \%hiddens,
  1717. buttons => \@buttons,
  1718. options => \@options,
  1719. rows => \@rows,
  1720. columns => \@column_index,
  1721. heading => \%column_header,
  1722. });
  1723. }
  1724. sub item_selected {
  1725. # add rows
  1726. $i = $form->{rowcount};
  1727. %id = ();
  1728. for $i ( 1 .. $form->{rowcount} - 1 ) {
  1729. $id{ $form->{"id_$i"} } = 1;
  1730. }
  1731. for $j ( 1 .. $form->{lastndx} ) {
  1732. if ( $form->{"ndx_$j"} ) {
  1733. if ( $id{ $form->{"new_id_$j"} } ) {
  1734. next if $form->{db} eq 'vendor';
  1735. }
  1736. for (qw(id partnumber description unit sellprice lastcost)) {
  1737. $form->{"${_}_$i"} = $form->{"new_${_}_$j"};
  1738. }
  1739. $form->{"partsgroup_$i"} =
  1740. qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|;
  1741. $form->{"sku_$i"} = $form->{"new_partnumber_$j"};
  1742. $i++;
  1743. }
  1744. }
  1745. $form->{rowcount} = $i;
  1746. # delete all the new_ variables
  1747. for $i ( 1 .. $form->{lastndx} ) {
  1748. for (
  1749. qw(id partnumber description unit sellprice lastcost partsgroup partsgroup_id)
  1750. )
  1751. {
  1752. delete $form->{"new_${_}_$i"};
  1753. }
  1754. delete $form->{"ndx_$i"};
  1755. }
  1756. for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
  1757. &{"$form->{db}_pricelist"};
  1758. }
  1759. sub save_pricelist {
  1760. &{"CT::save_$form->{db}"}( "", \%myconfig, \%$form );
  1761. $callback = $form->{callback};
  1762. $form->{callback} = "$form->{script}?action=edit";
  1763. for (qw(db id login path sessionid)) {
  1764. $form->{callback} .= "&$_=$form->{$_}";
  1765. }
  1766. $form->{callback} .= "&callback=" . $form->escape( $callback, 1 );
  1767. if ( CT->save_pricelist( \%myconfig, \%$form ) ) {
  1768. $form->redirect;
  1769. }
  1770. else {
  1771. $form->error( $locale->text('Could not save pricelist!') );
  1772. }
  1773. }
  1774. sub add_transaction {
  1775. $form->isblank( "name", $locale->text("Name missing!") );
  1776. &{"CT::save_$form->{db}"}( "", \%myconfig, \%$form );
  1777. $form->{callback} = $form->escape( $form->{callback}, 1 );
  1778. $name = $form->escape( $form->{name}, 1 );
  1779. $form->{callback} =
  1780. "$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}";
  1781. $form->redirect;
  1782. }
  1783. sub ap_transaction {
  1784. $form->{script} = "ap.pl";
  1785. $form->{type} = "ap_transaction";
  1786. &add_transaction;
  1787. }
  1788. sub ar_transaction {
  1789. $form->{script} = "ar.pl";
  1790. $form->{type} = "ar_transaction";
  1791. &add_transaction;
  1792. }
  1793. sub sales_invoice {
  1794. $form->{script} = "is.pl";
  1795. $form->{type} = "invoice";
  1796. &add_transaction;
  1797. }
  1798. sub pos {
  1799. $form->{script} = "ps.pl";
  1800. $form->{type} = "pos_invoice";
  1801. &add_transaction;
  1802. }
  1803. sub vendor_invoice {
  1804. $form->{script} = "ir.pl";
  1805. $form->{type} = "invoice";
  1806. &add_transaction;
  1807. }
  1808. sub rfq {
  1809. $form->{script} = "oe.pl";
  1810. $form->{type} = "request_quotation";
  1811. &add_transaction;
  1812. }
  1813. sub quotation {
  1814. $form->{script} = "oe.pl";
  1815. $form->{type} = "sales_quotation";
  1816. &add_transaction;
  1817. }
  1818. sub sales_order {
  1819. $form->{script} = "oe.pl";
  1820. $form->{type} = "sales_order";
  1821. &add_transaction;
  1822. }
  1823. sub purchase_order {
  1824. $form->{script} = "oe.pl";
  1825. $form->{type} = "purchase_order";
  1826. &add_transaction;
  1827. }
  1828. sub save_as_new {
  1829. delete $form->{id};
  1830. &save;
  1831. }
  1832. sub save {
  1833. # $locale->text('Customer saved!')
  1834. # $locale->text('Vendor saved!')
  1835. $msg = ucfirst $form->{db};
  1836. $msg .= " saved!";
  1837. $form->isblank( "name", $locale->text("Name missing!") );
  1838. &{"CT::save_$form->{db}"}( "", \%myconfig, \%$form );
  1839. $form->redirect( $locale->text($msg) );
  1840. }
  1841. sub delete {
  1842. # $locale->text('Customer deleted!')
  1843. # $locale->text('Cannot delete customer!')
  1844. # $locale->text('Vendor deleted!')
  1845. # $locale->text('Cannot delete vendor!')
  1846. CT->delete( \%myconfig, \%$form );
  1847. $msg = ucfirst $form->{db};
  1848. $msg .= " deleted!";
  1849. $form->redirect( $locale->text($msg) );
  1850. }
  1851. sub continue { &{ $form->{nextsub} } }
  1852. sub add_customer { &add }
  1853. sub add_vendor { &add }