summaryrefslogtreecommitdiff
path: root/bin/ct.pl
blob: 8244738b7c81e997d7959366378e2a236ba1734a (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. $href =
  823. "$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}";
  824. $form->sort_order();
  825. $callback =
  826. "$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}";
  827. $form->{l_fxsellprice} = $form->{l_curr};
  828. @columns = $form->sort_columns( partnumber, description, qty, unit,
  829. sellprice, fxsellprice, curr, discount,
  830. deliverydate, projectnumber, serialnumber
  831. );
  832. if ( $form->{history} eq 'summary' ) {
  833. @columns =
  834. $form->sort_columns( partnumber, description, qty, unit, sellprice,
  835. curr );
  836. }
  837. foreach $item (@columns) {
  838. if ( $form->{"l_$item"} eq "Y" ) {
  839. push @column_index, $item;
  840. # add column to href and callback
  841. $callback .= "&l_$item=Y";
  842. $href .= "&l_$item=Y";
  843. }
  844. }
  845. if ( $form->{history} eq 'detail' ) {
  846. $option = $locale->text('Detail');
  847. }
  848. if ( $form->{history} eq 'summary' ) {
  849. $option .= $locale->text('Summary');
  850. }
  851. if ( $form->{name} ) {
  852. $callback .= "&name=" . $form->escape( $form->{name}, 1 );
  853. $href .= "&name=" . $form->escape( $form->{name} );
  854. $option .= "\n<br>" . $locale->text('Name') . " : $form->{name}";
  855. }
  856. if ( $form->{contact} ) {
  857. $callback .= "&contact=" . $form->escape( $form->{contact}, 1 );
  858. $href .= "&contact=" . $form->escape( $form->{contact} );
  859. $option .= "\n<br>" . $locale->text('Contact') . " : $form->{contact}";
  860. }
  861. if ( $form->{"$form->{db}number"} ) {
  862. $callback .=
  863. qq|&$form->{db}number=|
  864. . $form->escape( $form->{"$form->{db}number"}, 1 );
  865. $href .=
  866. "&$form->{db}number=" . $form->escape( $form->{"$form->{db}number"} );
  867. $option .= "\n<br>"
  868. . $locale->text('Number')
  869. . qq| : $form->{"$form->{db}number"}|;
  870. }
  871. if ( $form->{email} ) {
  872. $callback .= "&email=" . $form->escape( $form->{email}, 1 );
  873. $href .= "&email=" . $form->escape( $form->{email} );
  874. $option .= "\n<br>" . $locale->text('E-mail') . " : $form->{email}";
  875. }
  876. if ( $form->{transdatefrom} ) {
  877. $callback .= "&transdatefrom=$form->{transdatefrom}";
  878. $href .= "&transdatefrom=$form->{transdatefrom}";
  879. $option .= "\n<br>" if ($option);
  880. $option .=
  881. $locale->text('From') . "&nbsp;"
  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. $option .= " ";
  889. }
  890. else {
  891. $option .= "\n<br>" if ($option);
  892. }
  893. $option .=
  894. $locale->text('To') . "&nbsp;"
  895. . $locale->date( \%myconfig, $form->{transdateto}, 1 );
  896. }
  897. if ( $form->{open} ) {
  898. $callback .= "&open=$form->{open}";
  899. $href .= "&open=$form->{open}";
  900. $option .= "\n<br>" if ($option);
  901. $option .= $locale->text('Open');
  902. }
  903. if ( $form->{closed} ) {
  904. $callback .= "&closed=$form->{closed}";
  905. $href .= "&closed=$form->{closed}";
  906. $option .= "\n<br>" if ($option);
  907. $option .= $locale->text('Closed');
  908. }
  909. $form->{callback} = "$callback&sort=$form->{sort}";
  910. $callback = $form->escape( $form->{callback} );
  911. $column_header{partnumber} =
  912. qq|<th><a class=listheading href=$href&sort=partnumber>|
  913. . $locale->text('Part Number')
  914. . qq|</a></th>|;
  915. $column_header{description} =
  916. qq|<th><a class=listheading href=$href&sort=description>|
  917. . $locale->text('Description')
  918. . qq|</a></th>|;
  919. if ( $form->{history} eq 'summary' ) {
  920. $column_header{sellprice} =
  921. qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
  922. }
  923. else {
  924. $column_header{sellprice} =
  925. qq|<th class=listheading>| . $locale->text('Sell Price') . qq|</th>|;
  926. }
  927. $column_header{fxsellprice} = qq|<th>&nbsp;</th>|;
  928. $column_header{curr} =
  929. qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
  930. $column_header{discount} =
  931. qq|<th class=listheading>| . $locale->text('Discount') . qq|</th>|;
  932. $column_header{qty} =
  933. qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
  934. $column_header{unit} =
  935. qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
  936. $column_header{deliverydate} =
  937. qq|<th><a class=listheading href=$href&sort=deliverydate>|
  938. . $locale->text('Delivery Date')
  939. . qq|</a></th>|;
  940. $column_header{projectnumber} =
  941. qq|<th><a class=listheading href=$href&sort=projectnumber>|
  942. . $locale->text('Project Number')
  943. . qq|</a></th>|;
  944. $column_header{serialnumber} =
  945. qq|<th><a class=listheading href=$href&sort=serialnumber>|
  946. . $locale->text('Serial Number')
  947. . qq|</a></th>|;
  948. # $locale->text('Customer History')
  949. # $locale->text('Vendor History')
  950. $label = ucfirst $form->{db};
  951. $form->{title} = $locale->text( $label . " History" );
  952. $colspan = $#column_index + 1;
  953. $form->header;
  954. print qq|
  955. <body>
  956. <table width=100%>
  957. <tr>
  958. <th class=listtop>$form->{title}</th>
  959. </tr>
  960. <tr height="5"></tr>
  961. <tr>
  962. <td>$option</td>
  963. </tr>
  964. <tr>
  965. <td>
  966. <table width=100%>
  967. <tr class=listheading>
  968. |;
  969. for (@column_index) { print "$column_header{$_}\n" }
  970. print qq|
  971. </tr>
  972. |;
  973. $module = 'oe';
  974. if ( $form->{db} eq 'customer' ) {
  975. $invlabel = $locale->text('Sales Invoice');
  976. $ordlabel = $locale->text('Sales Order');
  977. $quolabel = $locale->text('Quotation');
  978. $ordertype = 'sales_order';
  979. $quotationtype = 'sales_quotation';
  980. if ( $form->{type} eq 'invoice' ) {
  981. $module = 'is';
  982. }
  983. }
  984. else {
  985. $invlabel = $locale->text('Vendor Invoice');
  986. $ordlabel = $locale->text('Purchase Order');
  987. $quolabel = $locale->text('RFQ');
  988. $ordertype = 'purchase_order';
  989. $quotationtype = 'request_quotation';
  990. if ( $form->{type} eq 'invoice' ) {
  991. $module = 'ir';
  992. }
  993. }
  994. $ml = ( $form->{db} eq 'vendor' ) ? -1 : 1;
  995. foreach $ref ( @{ $form->{CT} } ) {
  996. if ( $ref->{id} ne $sameid ) {
  997. # print the header
  998. print qq|
  999. <tr class=listheading>
  1000. <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>
  1001. </tr>
  1002. |;
  1003. }
  1004. if ( $form->{type} ne 'invoice' ) {
  1005. $ref->{fxsellprice} = $ref->{sellprice};
  1006. $ref->{sellprice} *= $ref->{exchangerate};
  1007. }
  1008. if ( $form->{history} eq 'detail' and $ref->{invid} ne $sameinvid ) {
  1009. # print inv, ord, quo number
  1010. $i++;
  1011. $i %= 2;
  1012. print qq|
  1013. <tr class=listrow$i>
  1014. |;
  1015. if ( $form->{type} eq 'invoice' ) {
  1016. print
  1017. 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>|;
  1018. }
  1019. if ( $form->{type} eq 'order' ) {
  1020. print
  1021. 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>|;
  1022. }
  1023. if ( $form->{type} eq 'quotation' ) {
  1024. print
  1025. 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>|;
  1026. }
  1027. print qq|
  1028. </tr>
  1029. |;
  1030. }
  1031. for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
  1032. if ( $form->{l_curr} ) {
  1033. $column_data{fxsellprice} =
  1034. qq|<td align=right>|
  1035. . $form->format_amount( \%myconfig, $ref->{fxsellprice}, 2 )
  1036. . "</td>";
  1037. }
  1038. $column_data{sellprice} =
  1039. qq|<td align=right>|
  1040. . $form->format_amount( \%myconfig, $ref->{sellprice}, 2 ) . "</td>";
  1041. $column_data{qty} =
  1042. qq|<td align=right>|
  1043. . $form->format_amount( \%myconfig, $ref->{qty} * $ml ) . "</td>";
  1044. $column_data{discount} = qq|<td align=right>|
  1045. . $form->format_amount( \%myconfig, $ref->{discount} * 100,
  1046. "", "&nbsp;" )
  1047. . "</td>";
  1048. $column_data{partnumber} =
  1049. 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>|;
  1050. $i++;
  1051. $i %= 2;
  1052. print qq|
  1053. <tr class=listrow$i>
  1054. |;
  1055. for (@column_index) { print "$column_data{$_}\n" }
  1056. print qq|
  1057. </tr>
  1058. |;
  1059. $sameid = $ref->{id};
  1060. $sameinvid = $ref->{invid};
  1061. }
  1062. print qq|
  1063. </table>
  1064. </td>
  1065. </tr>
  1066. <tr>
  1067. <td><hr size=3 noshade></td>
  1068. </tr>
  1069. </table>
  1070. |;
  1071. if ( $form->{lynx} ) {
  1072. require "bin/menu.pl";
  1073. &menubar;
  1074. }
  1075. print qq|
  1076. </form>
  1077. </body>
  1078. </html>
  1079. |;
  1080. }
  1081. sub edit {
  1082. # $locale->text('Edit Customer')
  1083. # $locale->text('Edit Vendor')
  1084. CT->create_links( \%myconfig, \%$form );
  1085. for ( keys %$form ) { $form->{$_} = $form->quote( $form->{$_} ) }
  1086. $form->{title} = "Edit";
  1087. # format discount
  1088. $form->{discount} *= 100;
  1089. &form_header;
  1090. &form_footer;
  1091. }
  1092. sub form_header {
  1093. $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
  1094. $form->{creditlimit} =
  1095. $form->format_amount( \%myconfig, $form->{creditlimit}, 0 );
  1096. $form->{discount} =
  1097. $form->format_amount( \%myconfig, $form->{discount}, "" );
  1098. $form->{terms} = $form->format_amount( \%myconfig, $form->{terms}, "" );
  1099. if ( $form->{currencies} ) {
  1100. # currencies
  1101. $form->{selectcurrency} = {
  1102. name => 'curr',
  1103. options => [],
  1104. default_values => $form->{curr},
  1105. };
  1106. push @{$form->{selectcurrency}{options}}, {
  1107. text => $_,
  1108. value => $_,
  1109. } foreach split /:/, $form->{currencies};
  1110. }
  1111. $form->{taxable} = [];
  1112. foreach my $item ( split / /, $form->{taxaccounts} ) {
  1113. my $temp_tax = {
  1114. name => "tax_$item",
  1115. value => 1,
  1116. type => 'checkbox',
  1117. label => $form->{tax}{$item}{description}
  1118. };
  1119. $temp_tax->{checked} = 'checked' if $form->{tax}{$item}{taxable};
  1120. push @{$form->{taxable}}, $temp_tax;
  1121. }
  1122. if (ref $form->{all_business} eq 'ARRAY') {
  1123. $form->{selectbusiness} = {
  1124. name => 'business',
  1125. options => [{text => '', value => ''}],
  1126. };
  1127. push @{$form->{selectbusiness}{options}}, {
  1128. text => $_->{description},
  1129. value => "$_->{description}--$_->{id}",
  1130. } foreach @{$form->{all_business}};
  1131. $form->{selectbusiness}{default_values} =
  1132. "$form->{business}--$form->{business_id}";
  1133. }
  1134. if (ref $form->{all_pricegroup} eq 'ARRAY' && $form->{db} eq 'customer') {
  1135. $form->{selectpricegroup} = {
  1136. name => 'pricegroup',
  1137. options => [{text => '', value => ''}],
  1138. };
  1139. push @{$form->{selectpricegroup}{options}}, {
  1140. name => $_->{pricegroup},
  1141. value => "$_->{pricegroup}--$_->{id}",
  1142. } foreach @{$form->{all_pricegroup}};
  1143. $form->{selectpricegroup}{default_values} =
  1144. "$form->{pricegroup}--$form->{pricegroup_id}";
  1145. }
  1146. if ( @{ $form->{all_language} } ) {
  1147. $form->{selectlanguage} = {
  1148. name => 'language',
  1149. options => [{text => '', value => ''}],
  1150. };
  1151. push @{$form->{selectlanguage}{options}}, {
  1152. text => $_->{description},
  1153. value => "$_->{description}--$_->{code}",
  1154. } foreach @{$form->{all_language}};
  1155. $form->{selectlangauge}{default_values} =
  1156. "$form->{language}--$form->{language_code}";
  1157. }
  1158. $form->{selectemployee} = {
  1159. name => 'employee',
  1160. options => [{text => '', value => ''}],
  1161. default_values => "$form->{employee}--$form->{employee_id}",
  1162. };
  1163. push @{$form->{selectemployee}{options}}, {
  1164. text => $_->{name},
  1165. value => "$_->{name}--$_->{id}",
  1166. } foreach @{$form->{all_employee}};
  1167. if (ref $form->{all_employee} eq 'ARRAY') {
  1168. if ( $myconfig{role} eq 'user' && $form->{id} ) {
  1169. $hiddens{employee} = "$form->{employee}--$form->{employee_id}";
  1170. }
  1171. }
  1172. # $locale->text('Customer Number')
  1173. # $locale->text('Vendor Number')
  1174. $label = ucfirst $form->{db};
  1175. $form->{label} = $label;
  1176. $form->{title} = $locale->text("$form->{title} $label");
  1177. }
  1178. sub form_footer {
  1179. # type=submit $locale->text('Save')
  1180. # type=submit $locale->text('Save as new')
  1181. # type=submit $locale->text('AR Transaction')
  1182. # type=submit $locale->text('Sales Invoice')
  1183. # type=submit $locale->text('Sales Order')
  1184. # type=submit $locale->text('Quotation')
  1185. # type=submit $locale->text('AP Transaction')
  1186. # type=submit $locale->text('Vendor Invoice')
  1187. # type=submit $locale->text('Purchase Order')
  1188. # type=submit $locale->text('RFQ')
  1189. # type=submit $locale->text('Pricelist')
  1190. # type=submit $locale->text('Delete')
  1191. # type=submit $locale->text('POS')
  1192. my %hiddens;
  1193. my @buttons;
  1194. %button = (
  1195. 'save' => { ndx => 1, key => 'S', value => $locale->text('Save') },
  1196. 'save_as_new' =>
  1197. { ndx => 2, key => 'N', value => $locale->text('Save as new') },
  1198. 'ar_transaction' =>
  1199. { ndx => 7, key => 'A', value => $locale->text('AR Transaction') },
  1200. 'ap_transaction' =>
  1201. { ndx => 8, key => 'A', value => $locale->text('AP Transaction') },
  1202. 'sales_invoice' =>
  1203. { ndx => 9, key => 'I', value => $locale->text('Sales Invoice') },
  1204. 'pos' => { ndx => 10, key => 'C', value => $locale->text('POS') },
  1205. 'sales_order' =>
  1206. { ndx => 11, key => 'O', value => $locale->text('Sales Order') },
  1207. 'quotation' =>
  1208. { ndx => 12, key => 'Q', value => $locale->text('Quotation') },
  1209. 'vendor_invoice' =>
  1210. { ndx => 13, key => 'I', value => $locale->text('Vendor Invoice') },
  1211. 'purchase_order' =>
  1212. { ndx => 14, key => 'O', value => $locale->text('Purchase Order') },
  1213. 'rfq' => { ndx => 15, key => 'Q', value => $locale->text('RFQ') },
  1214. 'pricelist' =>
  1215. { ndx => 16, key => 'P', value => $locale->text('Pricelist') },
  1216. 'delete' => { ndx => 17, key => 'D', value => $locale->text('Delete') },
  1217. );
  1218. my %blist = ();
  1219. if ( $form->{db} eq 'customer' ) {
  1220. if ( $myconfig{acs} !~ /AR--Customers--Add Customer/ ) {
  1221. $blist{'save'} = 1;
  1222. if ( $form->{id} ) {
  1223. $blist{'save_as_new'} = 1;
  1224. if ( $form->{status} eq 'orphaned' ) {
  1225. $blist{'delete'} = 1;
  1226. }
  1227. }
  1228. }
  1229. if ( $myconfig{acs} !~ /AR--AR/ ) {
  1230. if ( $myconfig{acs} !~ /AR--Add Transaction/ ) {
  1231. $blist{'ar_transaction'} = 1;
  1232. }
  1233. if ( $myconfig{acs} !~ /AR--Sales Invoice/ ) {
  1234. $blist{'sales_invoice'} = 1;
  1235. }
  1236. }
  1237. if ( $myconfig{acs} !~ /POS--POS/ ) {
  1238. if ( $myconfig{acs} !~ /POS--Sale/ ) {
  1239. $blist{'pos'} = 1;
  1240. }
  1241. }
  1242. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1243. if ( $myconfig{acs} !~ /Order Entry--Sales Order/ ) {
  1244. $blist{'sales_order'} = 1;
  1245. }
  1246. }
  1247. if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
  1248. if ( $myconfig{acs} !~ /Quotations--Quotation/ ) {
  1249. $blist{'quotation'} = 1;
  1250. }
  1251. }
  1252. }
  1253. if ( $form->{db} eq 'vendor' ) {
  1254. if ( $myconfig{acs} !~ /AP--Vendors--Add Vendor/ ) {
  1255. $blist{'save'} = 1;
  1256. if ( $form->{id} ) {
  1257. $blist{'save_as_new'} = 1;
  1258. if ( $form->{status} eq 'orphaned' ) {
  1259. $blist{'delete'} = 1;
  1260. }
  1261. }
  1262. }
  1263. if ( $myconfig{acs} !~ /AP--AP/ ) {
  1264. if ( $myconfig{acs} !~ /AP--Add Transaction/ ) {
  1265. $blist{'ap_transaction'} = 1;
  1266. }
  1267. if ( $myconfig{acs} !~ /AP--Vendor Invoice/ ) {
  1268. $blist{'vendor_invoice'} = 1;
  1269. }
  1270. }
  1271. if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
  1272. if ( $myconfig{acs} !~ /Order Entry--Purchase Order/ ) {
  1273. $blist{'purchase_order'} = 1;
  1274. }
  1275. }
  1276. if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
  1277. if ( $myconfig{acs} !~ /Quotations--RFQ/ ) {
  1278. $blist{'rfq'} = 1;
  1279. }
  1280. }
  1281. }
  1282. if ( $myconfig{acs} !~ /Goods & Services--Goods & Services/ ) {
  1283. $myconfig{acs} =~
  1284. s/(Goods & Services--)Add (Service|Assembly).*;/$1--Add Part/g;
  1285. if ( $myconfig{acs} !~ /Goods & Services--Add Part/ ) {
  1286. $blist{'pricelist'} = 1;
  1287. }
  1288. }
  1289. $hiddens{$_} = $form->{$_} foreach
  1290. qw(id taxaccounts path login sessionid callback db);
  1291. for ( keys %button ) { delete $button{$_} if !$blist{$_} }
  1292. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  1293. push @buttons, {
  1294. name => 'action',
  1295. value => $_,
  1296. accesskey => $button{$_}{key},
  1297. title => "$button{$name}{value} [Alt-$button{$_}{key}]",
  1298. text => $button{$_}{value},
  1299. };
  1300. }
  1301. ##SC: Temporary removal
  1302. ## if ( $form->{lynx} ) {
  1303. ## require "bin/menu.pl";
  1304. ## &menubar;
  1305. ## }
  1306. $form->{dbnumber} = "$form->{db}number";
  1307. my $template = LedgerSMB::Template->new_UI(
  1308. user => \%myconfig,
  1309. locale => $locale,
  1310. template => 'ct-form',
  1311. );
  1312. $template->render({
  1313. form => $form,
  1314. user => \%myconfig,
  1315. hiddens => \%hiddens,
  1316. buttons => \@buttons,
  1317. options => \@options,
  1318. });
  1319. }
  1320. sub pricelist {
  1321. $form->isblank( "name", $locale->text('Name missing!') );
  1322. $form->{display_form} ||= "display_pricelist";
  1323. CT->pricelist( \%myconfig, \%$form );
  1324. foreach $ref ( @{ $form->{"all_partspricelist"} } ) {
  1325. $i++;
  1326. for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
  1327. }
  1328. $form->{rowcount} = $i;
  1329. # currencies
  1330. @curr = split /:/, $form->{currencies};
  1331. for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
  1332. if ( @{ $form->{all_partsgroup} } ) {
  1333. $form->{selectpartsgroup} = "";
  1334. foreach $ref ( @{ $form->{all_partsgroup} } ) {
  1335. $form->{selectpartsgroup} .= qq|$ref->{partsgroup}--$ref->{id}\n|;
  1336. }
  1337. }
  1338. for (qw(currencies all_partsgroup all_partspricelist)) {
  1339. delete $form->{$_};
  1340. }
  1341. foreach $i ( 1 .. $form->{rowcount} ) {
  1342. if ( $form->{db} eq 'customer' ) {
  1343. $form->{"pricebreak_$i"} =
  1344. $form->format_amount( \%myconfig, $form->{"pricebreak_$i"} );
  1345. $form->{"sellprice_$i"} =
  1346. $form->format_amount( \%myconfig, $form->{"sellprice_$i"}, 2 );
  1347. }
  1348. if ( $form->{db} eq 'vendor' ) {
  1349. $form->{"leadtime_$i"} =
  1350. $form->format_amount( \%myconfig, $form->{"leadtime_$i"} );
  1351. $form->{"lastcost_$i"} =
  1352. $form->format_amount( \%myconfig, $form->{"lastcost_$i"}, 2 );
  1353. }
  1354. }
  1355. $form->{rowcount}++;
  1356. &{"$form->{db}_pricelist"};
  1357. }
  1358. sub customer_pricelist {
  1359. @flds =
  1360. qw(runningnumber id partnumber description sellprice unit partsgroup pricebreak curr validfrom validto);
  1361. $form->{rowcount}--;
  1362. # remove empty rows
  1363. if ( $form->{rowcount} ) {
  1364. foreach $i ( 1 .. $form->{rowcount} ) {
  1365. for (qw(pricebreak sellprice)) {
  1366. $form->{"${_}_$i"} =
  1367. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  1368. }
  1369. ( $a, $b ) = split /\./, $form->{"pricebreak_$i"};
  1370. $a = length $a;
  1371. $b = length $b;
  1372. $whole = ( $whole > $a ) ? $whole : $a;
  1373. $dec = ( $dec > $b ) ? $dec : $b;
  1374. }
  1375. $pad1 = '0' x $whole;
  1376. $pad2 = '0' x $dec;
  1377. foreach $i ( 1 .. $form->{rowcount} ) {
  1378. ( $a, $b ) = split /\./, $form->{"pricebreak_$i"};
  1379. $a = substr( "$pad1$a", -$whole );
  1380. $b = substr( "$b$pad2", 0, $dec );
  1381. $ndx{qq|$form->{"partnumber_$i"}_$form->{"id_$i"}_$a$b|} = $i;
  1382. }
  1383. $i = 1;
  1384. for ( sort keys %ndx ) { $form->{"runningnumber_$ndx{$_}"} = $i++ }
  1385. foreach $i ( 1 .. $form->{rowcount} ) {
  1386. if ( $form->{"partnumber_$i"} && $form->{"sellprice_$i"} ) {
  1387. if ( $form->{"id_$i"} eq $sameid ) {
  1388. $j = $i + 1;
  1389. next
  1390. if ( $form->{"id_$j"} eq $sameid
  1391. && !$form->{"pricebreak_$i"} );
  1392. }
  1393. push @a, {};
  1394. $j = $#a;
  1395. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1396. $count++;
  1397. }
  1398. $sameid = $form->{"id_$i"};
  1399. }
  1400. $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
  1401. $form->{rowcount} = $count;
  1402. }
  1403. $form->{rowcount}++;
  1404. if ( $form->{display_form} ) {
  1405. &{"$form->{display_form}"};
  1406. }
  1407. }
  1408. sub vendor_pricelist {
  1409. @flds =
  1410. qw(runningnumber id sku partnumber description lastcost unit partsgroup curr leadtime);
  1411. $form->{rowcount}--;
  1412. # remove empty rows
  1413. if ( $form->{rowcount} ) {
  1414. foreach $i ( 1 .. $form->{rowcount} ) {
  1415. for (qw(leadtime lastcost)) {
  1416. $form->{"${_}_$i"} =
  1417. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  1418. }
  1419. $var =
  1420. ( $form->{"partnumber_$i"} )
  1421. ? $form->{"sku_$i"}
  1422. : qq|_$form->{"sku_$i"}|;
  1423. $ndx{$var} = $i;
  1424. }
  1425. $i = 1;
  1426. for ( sort keys %ndx ) { $form->{"runningnumber_$ndx{$_}"} = $i++ }
  1427. foreach $i ( 1 .. $form->{rowcount} ) {
  1428. if ( $form->{"sku_$i"} ) {
  1429. push @a, {};
  1430. $j = $#a;
  1431. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1432. $count++;
  1433. }
  1434. }
  1435. $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
  1436. $form->{rowcount} = $count;
  1437. }
  1438. $form->{rowcount}++;
  1439. if ( $form->{display_form} ) {
  1440. &{"$form->{display_form}"};
  1441. }
  1442. }
  1443. sub display_pricelist {
  1444. my %hiddens;
  1445. &pricelist_header(\%hiddens);
  1446. delete $form->{action};
  1447. $form->hide_form;
  1448. $hiddens{$_} = $form->{$_} foreach sort keys %$form;
  1449. &pricelist_footer(\%hiddens);
  1450. }
  1451. sub pricelist_header {
  1452. $form->{title} = $form->{name};
  1453. $form->header;
  1454. print qq|
  1455. <body>
  1456. <form method=post action="$form->{script}">
  1457. <table width=100%>
  1458. <tr>
  1459. <th class=listtop>$form->{title}</th>
  1460. </tr>
  1461. <tr height="5"></tr>
  1462. |;
  1463. if ( $form->{db} eq 'customer' ) {
  1464. @column_index = qw(partnumber description);
  1465. push @column_index, "partsgroup" if $form->{selectpartsgroup};
  1466. push @column_index, qw(pricebreak sellprice curr validfrom validto);
  1467. $column_header{pricebreak} =
  1468. qq|<th class=listheading nowrap>|
  1469. . $locale->text('Break')
  1470. . qq|</th>|;
  1471. $column_header{sellprice} =
  1472. qq|<th class=listheading nowrap>|
  1473. . $locale->text('Sell Price')
  1474. . qq|</th>|;
  1475. $column_header{validfrom} =
  1476. qq|<th class=listheading nowrap>| . $locale->text('From') . qq|</th>|;
  1477. $column_header{validto} =
  1478. qq|<th class=listheading nowrap>| . $locale->text('To') . qq|</th>|;
  1479. }
  1480. if ( $form->{db} eq 'vendor' ) {
  1481. @column_index = qw(sku partnumber description);
  1482. push @column_index, "partsgroup" if $form->{selectpartsgroup};
  1483. push @column_index, qw(lastcost curr leadtime);
  1484. $column_header{sku} =
  1485. qq|<th class=listheading nowrap>| . $locale->text('SKU') . qq|</th>|;
  1486. $column_header{leadtime} =
  1487. qq|<th class=listheading nowrap>|
  1488. . $locale->text('Leadtime')
  1489. . qq|</th>|;
  1490. $column_header{lastcost} =
  1491. qq|<th class=listheading nowrap>| . $locale->text('Cost') . qq|</th>|;
  1492. }
  1493. $column_header{partnumber} =
  1494. qq|<th class=listheading nowrap>| . $locale->text('Number') . qq|</th>|;
  1495. $column_header{description} =
  1496. qq|<th class=listheading nowrap width=80%>|
  1497. . $locale->text('Description')
  1498. . qq|</th>|;
  1499. $column_header{partsgroup} =
  1500. qq|<th class=listheading nowrap>| . $locale->text('Group') . qq|</th>|;
  1501. $column_header{curr} =
  1502. qq|<th class=listheading nowrap>| . $locale->text('Curr') . qq|</th>|;
  1503. print qq|
  1504. <tr>
  1505. <td>
  1506. <table width=100%>
  1507. <tr class=listheading>
  1508. |;
  1509. for (@column_index) { print "\n$column_header{$_}" }
  1510. print qq|
  1511. </tr>
  1512. |;
  1513. $sameid = "";
  1514. foreach $i ( 1 .. $form->{rowcount} ) {
  1515. $selectcurrency = $form->{selectcurrency};
  1516. $selectcurrency =~
  1517. s/option>\Q$form->{"curr_$i"}\E/option selected>$form->{"curr_$i"}/;
  1518. if ( $form->{selectpartsgroup} ) {
  1519. if ( $i < $form->{rowcount} ) {
  1520. ($partsgroup) = split /--/, $form->{"partsgroup_$i"};
  1521. $column_data{partsgroup} = qq|<td>$partsgroup</td>
  1522. <input type=hidden name="partsgroup_$i" value="|
  1523. . $form->quote( $form->{"partsgroup_$i"} ) . qq|">|;
  1524. }
  1525. }
  1526. if ( $i < $form->{rowcount} ) {
  1527. if ( $form->{"id_$i"} eq $sameid ) {
  1528. for (qw(partnumber description partsgroup)) {
  1529. $column_data{$_} = qq|<td>&nbsp;</td>
  1530. <input type=hidden name="${_}_$i" value="|
  1531. . $form->quote( $form->{"${_}_$i"} ) . qq|">|;
  1532. }
  1533. }
  1534. else {
  1535. $column_data{sku} =
  1536. qq|<td><input name="sku_$i" value="$form->{"sku_$i"}"></td>|;
  1537. $column_data{partnumber} =
  1538. qq|<td><input name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
  1539. $column_data{description} =
  1540. qq|<td>$form->{"description_$i"}&nbsp;</td>
  1541. <input type=hidden name="description_$i" value="|
  1542. . $form->quote( $form->{"description_$i"} ) . qq|">|;
  1543. }
  1544. $column_data{partnumber} .= qq|
  1545. <input type=hidden name="id_$i" value="$form->{"id_$i"}">|;
  1546. }
  1547. else {
  1548. if ( $form->{db} eq 'customer' ) {
  1549. $column_data{partnumber} =
  1550. qq|<td><input name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
  1551. }
  1552. else {
  1553. $column_data{partnumber} = qq|<td>&nbsp;</td>|;
  1554. }
  1555. $column_data{partnumber} .= qq|
  1556. <input type=hidden name="id_$i" value="$form->{"id_$i"}">|;
  1557. $column_data{sku} =
  1558. qq|<td><input name="sku_$i" value="$form->{"sku_$i"}"></td>|;
  1559. $column_data{description} =
  1560. qq|<td><input name="description_$i" value="$form->{"description_$i"}"></td>|;
  1561. if ( $form->{selectpartsgroup} ) {
  1562. $selectpartsgroup = "<option>";
  1563. foreach $line ( split /\n/, $form->{selectpartsgroup} ) {
  1564. $selectpartsgroup .=
  1565. qq|\n<option value="|
  1566. . $form->quote($line) . qq|">|
  1567. . ( split /--/, $line )[0];
  1568. }
  1569. $column_data{partsgroup} =
  1570. qq|<td><select name="partsgroup_$i">$selectpartsgroup</select></td>|;
  1571. }
  1572. }
  1573. if ( $form->{db} eq 'customer' ) {
  1574. $column_data{pricebreak} =
  1575. qq|<td align=right><input name="pricebreak_$i" size=5 value=|
  1576. . $form->format_amount( \%myconfig, $form->{"pricebreak_$i"} )
  1577. . qq|></td>|;
  1578. $column_data{sellprice} =
  1579. qq|<td align=right><input name="sellprice_$i" size=10 value=|
  1580. . $form->format_amount( \%myconfig, $form->{"sellprice_$i"}, 2 )
  1581. . qq|></td>|;
  1582. $column_data{validfrom} =
  1583. qq|<td><input name="validfrom_$i" size=11 value=$form->{"validfrom_$i"}></td>|;
  1584. $column_data{validto} =
  1585. qq|<td><input name="validto_$i" size=11 value=$form->{"validto_$i"}></td>|;
  1586. }
  1587. if ( $form->{db} eq 'vendor' ) {
  1588. $column_data{leadtime} =
  1589. qq|<td align=right><input name="leadtime_$i" size=5 value=|
  1590. . $form->format_amount( \%myconfig, $form->{"leadtime_$i"} )
  1591. . qq|></td>|;
  1592. $column_data{lastcost} =
  1593. qq|<td align=right><input name="lastcost_$i" size=10 value=|
  1594. . $form->format_amount( \%myconfig, $form->{"lastcost_$i"}, 2 )
  1595. . qq|></td>|;
  1596. }
  1597. $column_data{curr} =
  1598. qq|<td><select name="curr_$i">$selectcurrency</select></td>|;
  1599. print qq|<tr valign=top>|;
  1600. for (@column_index) { print "\n$column_data{$_}" }
  1601. print qq|</tr>|;
  1602. $sameid = $form->{"id_$i"};
  1603. }
  1604. print qq|
  1605. </table>
  1606. </td>
  1607. </tr>
  1608. <tr>
  1609. <td><hr size=3 noshade></td>
  1610. </tr>
  1611. </table>
  1612. |;
  1613. # delete variables
  1614. foreach $i ( 1 .. $form->{rowcount} ) {
  1615. for ( @column_index, "id" ) { delete $form->{"${_}_$i"} }
  1616. }
  1617. for (qw(title titlebar script none)) { delete $form->{$_} }
  1618. }
  1619. sub pricelist_footer {
  1620. # type=submit $locale->text('Update')
  1621. # type=submit $locale->text('Save Pricelist')
  1622. %button = (
  1623. 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  1624. 'save_pricelist' =>
  1625. { ndx => 3, key => 'S', value => $locale->text('Save Pricelist') },
  1626. );
  1627. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  1628. $form->print_button( \%button, $_ );
  1629. }
  1630. print qq|
  1631. </form>
  1632. </body>
  1633. </html>
  1634. |;
  1635. }
  1636. sub update {
  1637. $i = $form->{rowcount};
  1638. $additem = 0;
  1639. if ( $form->{db} eq 'customer' ) {
  1640. $additem = 1
  1641. if !(( $form->{"partnumber_$i"} eq "" )
  1642. && ( $form->{"description_$i"} eq "" )
  1643. && ( $form->{"partsgroup_$i"} eq "" ) );
  1644. }
  1645. if ( $form->{db} eq 'vendor' ) {
  1646. if (
  1647. !(
  1648. ( $form->{"sku_$i"} eq "" )
  1649. && ( $form->{"description_$i"} eq "" )
  1650. && ( $form->{"partsgroup_$i"} eq "" )
  1651. )
  1652. )
  1653. {
  1654. $additem = 1;
  1655. $form->{"partnumber_$i"} = $form->{"sku_$i"};
  1656. }
  1657. }
  1658. if ($additem) {
  1659. CT->retrieve_item( \%myconfig, \%$form );
  1660. $rows = scalar @{ $form->{item_list} };
  1661. if ( $rows > 0 ) {
  1662. if ( $rows > 1 ) {
  1663. &select_item;
  1664. exit;
  1665. } else {
  1666. $sellprice = $form->{"sellprice_$i"};
  1667. $pricebreak = $form->{"pricebreak_$i"};
  1668. $lastcost = $form->{"lastcost_$i"};
  1669. for (qw(partnumber description)) {
  1670. $form->{item_list}[0]{$_} =
  1671. $form->quote( $form->{item_list}[0]{$_} );
  1672. }
  1673. for ( keys %{ $form->{item_list}[0] } ) {
  1674. $form->{"${_}_$i"} = $form->{item_list}[0]{$_};
  1675. }
  1676. if ( $form->{db} eq 'customer' ) {
  1677. if ($sellprice) {
  1678. $form->{"sellprice_$i"} = $sellprice;
  1679. }
  1680. $form->{"sellprice_$i"} =
  1681. $form->format_amount( \%myconfig, $form->{"sellprice_$i"},
  1682. 2 );
  1683. $form->{"pricebreak_$i"} = $pricebreak;
  1684. }
  1685. else {
  1686. foreach $j ( 1 .. $form->{rowcount} - 1 ) {
  1687. if ( $form->{"sku_$j"} eq $form->{"partnumber_$i"} ) {
  1688. $form->error(
  1689. $locale->text('Item already on pricelist!') );
  1690. }
  1691. }
  1692. if ($lastcost) {
  1693. $form->{"lastcost_$i"} = $lastcost;
  1694. }
  1695. $form->{"lastcost_$i"} =
  1696. $form->format_amount( \%myconfig, $form->{"lastcost_$i"},
  1697. 2 );
  1698. $form->{"sku_$i"} = $form->{"partnumber_$i"};
  1699. # delete $form->{"partnumber_$i"};
  1700. }
  1701. $form->{rowcount}++;
  1702. }
  1703. }
  1704. else {
  1705. $form->error( $locale->text('Item not on file!') );
  1706. }
  1707. }
  1708. &{"$form->{db}_pricelist"};
  1709. }
  1710. sub select_item {
  1711. my %hiddens;
  1712. my @column_index =
  1713. qw(ndx partnumber description partsgroup unit sellprice lastcost);
  1714. my %column_data;
  1715. $column_data{ndx} = ' ';
  1716. $column_data{partnumber} = locale->text('Number');
  1717. $column_data{description} = $locale->text('Description');
  1718. $column_data{partsgroup} = $locale->text('Group');
  1719. $column_data{unit} = $locale->text('Unit');
  1720. $column_data{sellprice} = $locale->text('Sell Price');
  1721. $column_data{lastcost} = $locale->text('Cost');
  1722. $form->{title} = $locale->text('Select items');
  1723. my $i = 0;
  1724. my @rows;
  1725. foreach $ref ( @{ $form->{item_list} } ) {
  1726. $i++;
  1727. my %column_data;
  1728. for (qw(partnumber description unit)) {
  1729. $ref->{$_} = $form->quote( $ref->{$_} );
  1730. }
  1731. $column_data{ndx} = {input => {
  1732. name => "ndx_$i",
  1733. type => 'checkbox',
  1734. value => $i,
  1735. }};
  1736. $column_data{$_} = $ref->{$_} foreach
  1737. qw(partnumber description partsgroup unit);
  1738. $column_data{sellprice} =
  1739. $form->format_amount( \%myconfig, $ref->{sellprice}, 2, ' ' );
  1740. $column_data{lastcost} =
  1741. $form->format_amount( \%myconfig, $ref->{lastcost}, 2, ' ' );
  1742. $j++;
  1743. $j %= 2;
  1744. $column_data{i} = $j;
  1745. push @rows, \%column_data;
  1746. $hiddens{"new_${_}_$i"} = $ref->{$_} foreach
  1747. qw(partnumber description partsgroup partsgroup_id sellprice lastcost unit id);
  1748. }
  1749. # delete action variable
  1750. for (qw(nextsub item_list)) { delete $form->{$_} }
  1751. $form->{action} = "item_selected";
  1752. $hiddens{$_} = $form->{$_} foreach sort keys %$form;
  1753. $hiddens{nextsub} = 'item_selected';
  1754. $hiddens{lastndx} = $i;
  1755. my @buttons = ({
  1756. name => 'action',
  1757. value => 'item_selected',
  1758. text => $locale->text('Continue'),
  1759. });
  1760. my $template = LedgerSMB::Template->new_UI(
  1761. user => \%myconfig,
  1762. locale => $locale,
  1763. template => 'form-dynatable',
  1764. );
  1765. $template->render({
  1766. form => $form,
  1767. user => \%myconfig,
  1768. hiddens => \%hiddens,
  1769. buttons => \@buttons,
  1770. options => \@options,
  1771. rows => \@rows,
  1772. columns => \@column_index,
  1773. heading => \%column_header,
  1774. });
  1775. }
  1776. sub item_selected {
  1777. # add rows
  1778. $i = $form->{rowcount};
  1779. %id = ();
  1780. for $i ( 1 .. $form->{rowcount} - 1 ) {
  1781. $id{ $form->{"id_$i"} } = 1;
  1782. }
  1783. for $j ( 1 .. $form->{lastndx} ) {
  1784. if ( $form->{"ndx_$j"} ) {
  1785. if ( $id{ $form->{"new_id_$j"} } ) {
  1786. next if $form->{db} eq 'vendor';
  1787. }
  1788. for (qw(id partnumber description unit sellprice lastcost)) {
  1789. $form->{"${_}_$i"} = $form->{"new_${_}_$j"};
  1790. }
  1791. $form->{"partsgroup_$i"} =
  1792. qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|;
  1793. $form->{"sku_$i"} = $form->{"new_partnumber_$j"};
  1794. $i++;
  1795. }
  1796. }
  1797. $form->{rowcount} = $i;
  1798. # delete all the new_ variables
  1799. for $i ( 1 .. $form->{lastndx} ) {
  1800. for (
  1801. qw(id partnumber description unit sellprice lastcost partsgroup partsgroup_id)
  1802. )
  1803. {
  1804. delete $form->{"new_${_}_$i"};
  1805. }
  1806. delete $form->{"ndx_$i"};
  1807. }
  1808. for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
  1809. &{"$form->{db}_pricelist"};
  1810. }
  1811. sub save_pricelist {
  1812. &{"CT::save_$form->{db}"}( "", \%myconfig, \%$form );
  1813. $callback = $form->{callback};
  1814. $form->{callback} = "$form->{script}?action=edit";
  1815. for (qw(db id login path sessionid)) {
  1816. $form->{callback} .= "&$_=$form->{$_}";
  1817. }
  1818. $form->{callback} .= "&callback=" . $form->escape( $callback, 1 );
  1819. if ( CT->save_pricelist( \%myconfig, \%$form ) ) {
  1820. $form->redirect;
  1821. }
  1822. else {
  1823. $form->error( $locale->text('Could not save pricelist!') );
  1824. }
  1825. }
  1826. sub add_transaction {
  1827. $form->isblank( "name", $locale->text("Name missing!") );
  1828. &{"CT::save_$form->{db}"}( "", \%myconfig, \%$form );
  1829. $form->{callback} = $form->escape( $form->{callback}, 1 );
  1830. $name = $form->escape( $form->{name}, 1 );
  1831. $form->{callback} =
  1832. "$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}";
  1833. $form->redirect;
  1834. }
  1835. sub ap_transaction {
  1836. $form->{script} = "ap.pl";
  1837. $form->{type} = "ap_transaction";
  1838. &add_transaction;
  1839. }
  1840. sub ar_transaction {
  1841. $form->{script} = "ar.pl";
  1842. $form->{type} = "ar_transaction";
  1843. &add_transaction;
  1844. }
  1845. sub sales_invoice {
  1846. $form->{script} = "is.pl";
  1847. $form->{type} = "invoice";
  1848. &add_transaction;
  1849. }
  1850. sub pos {
  1851. $form->{script} = "ps.pl";
  1852. $form->{type} = "pos_invoice";
  1853. &add_transaction;
  1854. }
  1855. sub vendor_invoice {
  1856. $form->{script} = "ir.pl";
  1857. $form->{type} = "invoice";
  1858. &add_transaction;
  1859. }
  1860. sub rfq {
  1861. $form->{script} = "oe.pl";
  1862. $form->{type} = "request_quotation";
  1863. &add_transaction;
  1864. }
  1865. sub quotation {
  1866. $form->{script} = "oe.pl";
  1867. $form->{type} = "sales_quotation";
  1868. &add_transaction;
  1869. }
  1870. sub sales_order {
  1871. $form->{script} = "oe.pl";
  1872. $form->{type} = "sales_order";
  1873. &add_transaction;
  1874. }
  1875. sub purchase_order {
  1876. $form->{script} = "oe.pl";
  1877. $form->{type} = "purchase_order";
  1878. &add_transaction;
  1879. }
  1880. sub save_as_new {
  1881. delete $form->{id};
  1882. &save;
  1883. }
  1884. sub save {
  1885. # $locale->text('Customer saved!')
  1886. # $locale->text('Vendor saved!')
  1887. $msg = ucfirst $form->{db};
  1888. $msg .= " saved!";
  1889. $form->isblank( "name", $locale->text("Name missing!") );
  1890. &{"CT::save_$form->{db}"}( "", \%myconfig, \%$form );
  1891. $form->redirect( $locale->text($msg) );
  1892. }
  1893. sub delete {
  1894. # $locale->text('Customer deleted!')
  1895. # $locale->text('Cannot delete customer!')
  1896. # $locale->text('Vendor deleted!')
  1897. # $locale->text('Cannot delete vendor!')
  1898. CT->delete( \%myconfig, \%$form );
  1899. $msg = ucfirst $form->{db};
  1900. $msg .= " deleted!";
  1901. $form->redirect( $locale->text($msg) );
  1902. }
  1903. sub continue { &{ $form->{nextsub} } }
  1904. sub add_customer { &add }
  1905. sub add_vendor { &add }