summaryrefslogtreecommitdiff
path: root/bin/am.pl
blob: 12b36db9b4ef8a3a66ccf89e7ec82e54d61bd2af (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. # http://www.ledgersmb.org/
  5. #
  6. #
  7. # Copyright (C) 2006
  8. # This work contains copyrighted information from a number of sources all used
  9. # with permission.
  10. #
  11. # This file contains source code included with or based on SQL-Ledger which
  12. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  13. # under the GNU General Public License version 2 or, at your option, any later
  14. # version. For a full list including contact information of contributors,
  15. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  16. #
  17. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  18. # Copyright (c) 2001
  19. #
  20. # Author: DWS Systems Inc.
  21. # Web: http://www.sql-ledger.org
  22. #
  23. # Contributors:
  24. #
  25. #======================================================================
  26. #
  27. # This file has NOT undergone whitespace cleanup.
  28. #
  29. #======================================================================
  30. #
  31. # administration
  32. #
  33. #======================================================================
  34. use LedgerSMB::AM;
  35. use LedgerSMB::CA;
  36. use LedgerSMB::Form;
  37. use LedgerSMB::User;
  38. use LedgerSMB::RP;
  39. use LedgerSMB::GL;
  40. use LedgerSMB::Template;
  41. 1;
  42. # end of main
  43. sub add { &{"add_$form->{type}"} }
  44. sub edit { &{"edit_$form->{type}"} }
  45. sub save { &{"save_$form->{type}"} }
  46. sub delete { &{"delete_$form->{type}"} }
  47. sub save_as_new {
  48. delete $form->{id};
  49. &save;
  50. }
  51. sub add_account {
  52. $form->{title} = "Add";
  53. $form->{charttype} = "A";
  54. $form->{callback} =
  55. "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  56. unless $form->{callback};
  57. &account_header;
  58. &form_footer;
  59. }
  60. sub edit_account {
  61. $form->{title} = "Edit";
  62. $form->{accno} =~ s/\\'/'/g;
  63. $form->{accno} =~ s/\\\\/\\/g;
  64. AM->get_account( \%myconfig, \%$form );
  65. foreach my $item ( split( /:/, $form->{link} ) ) {
  66. $form->{$item} = "checked";
  67. }
  68. &account_header;
  69. &form_footer;
  70. }
  71. sub account_header {
  72. $form->{title} = $locale->text("$form->{title} Account");
  73. $checked{ $form->{charttype} } = "checked";
  74. $checked{contra} = "checked" if $form->{contra};
  75. $checked{"$form->{category}_"} = "checked";
  76. for (qw(accno description)) { $form->{$_} = $form->quote( $form->{$_} ) }
  77. # this is for our parser only!
  78. # type=submit $locale->text('Add Account')
  79. # type=submit $locale->text('Edit Account')
  80. $form->header;
  81. print qq|
  82. <body>
  83. <form method=post action=$form->{script}>
  84. <input type=hidden name=id value=$form->{id}>
  85. <input type=hidden name=type value=account>
  86. <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>
  87. <input type=hidden name=income_accno_id value=$form->{income_accno_id}>
  88. <input type=hidden name=expense_accno_id value=$form->{expense_accno_id}>
  89. <input type=hidden name=fxgain_accno_id values=$form->{fxgain_accno_id}>
  90. <input type=hidden name=fxloss_accno_id values=$form->{fxloss_accno_id}>
  91. <table border=0 width=100%>
  92. <tr>
  93. <th class=listtop>$form->{title}</th>
  94. </tr>
  95. <tr height="5"></tr>
  96. <tr valign=top>
  97. <td>
  98. <table>
  99. <tr>
  100. <th align="right">| . $locale->text('Account Number') . qq|</th>
  101. <td><input name=accno size=20 value="$form->{accno}"></td>
  102. </tr>
  103. <tr>
  104. <th align="right">| . $locale->text('Description') . qq|</th>
  105. <td><input name=description size=40 value="$form->{description}"></td>
  106. </tr>
  107. <tr>
  108. <th align="right">| . $locale->text('Account Type') . qq|</th>
  109. <td>
  110. <table>
  111. <tr valign=top>
  112. <td><input name=category type=radio class=radio value=A $checked{A_}>&nbsp;|
  113. . $locale->text('Asset')
  114. . qq|\n<br>
  115. <input name=category type=radio class=radio value=L $checked{L_}>&nbsp;|
  116. . $locale->text('Liability')
  117. . qq|\n<br>
  118. <input name=category type=radio class=radio value=Q $checked{Q_}>&nbsp;|
  119. . $locale->text('Equity')
  120. . qq|\n<br>
  121. <input name=category type=radio class=radio value=I $checked{I_}>&nbsp;|
  122. . $locale->text('Income')
  123. . qq|\n<br>
  124. <input name=category type=radio class=radio value=E $checked{E_}>&nbsp;|
  125. . $locale->text('Expense')
  126. . qq|</td>
  127. <td>
  128. <input name=contra class=checkbox type=checkbox value=1 $checked{contra}>&nbsp;|
  129. . $locale->text('Contra') . qq|
  130. </td>
  131. <td>
  132. <input name=charttype type=radio class=radio value="H" $checked{H}>&nbsp;|
  133. . $locale->text('Heading') . qq|<br>
  134. <input name=charttype type=radio class=radio value="A" $checked{A}>&nbsp;|
  135. . $locale->text('Account')
  136. . qq|</td>
  137. </tr>
  138. </table>
  139. </td>
  140. </tr>
  141. |;
  142. if ( $form->{charttype} eq "A" ) {
  143. print qq|
  144. <tr>
  145. <td colspan=2>
  146. <table>
  147. <tr>
  148. <th align=left>|
  149. . $locale->text('Is this a summary account to record')
  150. . qq|</th>
  151. <td>
  152. <input name=AR class=checkbox type=checkbox value=AR $form->{AR}>&nbsp;|
  153. . $locale->text('AR')
  154. . qq|&nbsp;<input name=AP class=checkbox type=checkbox value=AP $form->{AP}>&nbsp;|
  155. . $locale->text('AP')
  156. . qq|&nbsp;<input name=IC class=checkbox type=checkbox value=IC $form->{IC}>&nbsp;|
  157. . $locale->text('Inventory')
  158. . qq|</td>
  159. </tr>
  160. </table>
  161. </td>
  162. </tr>
  163. <tr>
  164. <th colspan=2>| . $locale->text('Include in drop-down menus') . qq|</th>
  165. </tr>
  166. <tr valign=top>
  167. <td colspan=2>
  168. <table width=100%>
  169. <tr>
  170. <th align=left>| . $locale->text('Receivables') . qq|</th>
  171. <th align=left>| . $locale->text('Payables') . qq|</th>
  172. <th align=left>| . $locale->text('Tracking Items') . qq|</th>
  173. <th align=left>| . $locale->text('Non-tracking Items') . qq|</th>
  174. </tr>
  175. <tr>
  176. <td>
  177. <input name=AR_amount class=checkbox type=checkbox value=AR_amount $form->{AR_amount}>&nbsp;|
  178. . $locale->text('Income')
  179. . qq|\n<br>
  180. <input name=AR_paid class=checkbox type=checkbox value=AR_paid $form->{AR_paid}>&nbsp;|
  181. . $locale->text('Payment')
  182. . qq|\n<br>
  183. <input name=AR_tax class=checkbox type=checkbox value=AR_tax $form->{AR_tax}>&nbsp;|
  184. . $locale->text('Tax') . qq|
  185. </td>
  186. <td>
  187. <input name=AP_amount class=checkbox type=checkbox value=AP_amount $form->{AP_amount}>&nbsp;|
  188. . $locale->text('Expense/Asset')
  189. . qq|\n<br>
  190. <input name=AP_paid class=checkbox type=checkbox value=AP_paid $form->{AP_paid}>&nbsp;|
  191. . $locale->text('Payment')
  192. . qq|\n<br>
  193. <input name=AP_tax class=checkbox type=checkbox value=AP_tax $form->{AP_tax}>&nbsp;|
  194. . $locale->text('Tax') . qq|
  195. </td>
  196. <td>
  197. <input name=IC_sale class=checkbox type=checkbox value=IC_sale $form->{IC_sale}>&nbsp;|
  198. . $locale->text('Income')
  199. . qq|\n<br>
  200. <input name=IC_cogs class=checkbox type=checkbox value=IC_cogs $form->{IC_cogs}>&nbsp;|
  201. . $locale->text('COGS')
  202. . qq|\n<br>
  203. <input name=IC_taxpart class=checkbox type=checkbox value=IC_taxpart $form->{IC_taxpart}>&nbsp;|
  204. . $locale->text('Tax') . qq|
  205. </td>
  206. <td>
  207. <input name=IC_income class=checkbox type=checkbox value=IC_income $form->{IC_income}>&nbsp;|
  208. . $locale->text('Income')
  209. . qq|\n<br>
  210. <input name=IC_expense class=checkbox type=checkbox value=IC_expense $form->{IC_expense}>&nbsp;|
  211. . $locale->text('Expense')
  212. . qq|\n<br>
  213. <input name=IC_taxservice class=checkbox type=checkbox value=IC_taxservice $form->{IC_taxservice}>&nbsp;|
  214. . $locale->text('Tax') . qq|
  215. </td>
  216. </tr>
  217. </table>
  218. </td>
  219. </tr>
  220. <tr>
  221. </tr>
  222. |;
  223. }
  224. print qq|
  225. <tr>
  226. <th align="right">| . $locale->text('GIFI') . qq|</th>
  227. <td><input name=gifi_accno size=9 value="$form->{gifi_accno}"></td>
  228. </tr>
  229. </table>
  230. </td>
  231. </tr>
  232. <tr>
  233. <td><hr size=3 noshade></td>
  234. </tr>
  235. </table>
  236. |;
  237. }
  238. sub form_footer {
  239. $form->hide_form(qw(callback path login sessionid));
  240. # type=submit $locale->text('Save')
  241. # type=submit $locale->text('Save as new')
  242. # type=submit $locale->text('Delete')
  243. %button = ();
  244. if ( $form->{id} ) {
  245. $button{'save'} =
  246. { ndx => 3, key => 'S', value => $locale->text('Save') };
  247. $button{'save_as_new'} =
  248. { ndx => 7, key => 'N', value => $locale->text('Save as new') };
  249. if ( $form->{orphaned} ) {
  250. $button{'delete'} =
  251. { ndx => 16, key => 'D', value => $locale->text('Delete') };
  252. }
  253. }
  254. else {
  255. $button{'save'} =
  256. { ndx => 3, key => 'S', value => $locale->text('Save') };
  257. }
  258. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  259. $form->print_button( \%button, $_ );
  260. }
  261. if ( $form->{lynx} ) {
  262. require "bin/menu.pl";
  263. &menubar;
  264. }
  265. print qq|
  266. </form>
  267. </body>
  268. </html>
  269. |;
  270. }
  271. sub save_account {
  272. $form->isblank( "accno", $locale->text('Account Number missing!') );
  273. $form->isblank( "category", $locale->text('Account Type missing!') );
  274. # check for conflicting accounts
  275. if ( $form->{AR} || $form->{AP} || $form->{IC} ) {
  276. $a = "";
  277. for (qw(AR AP IC)) { $a .= $form->{$_} }
  278. $form->error(
  279. $locale->text(
  280. 'Cannot set account for more than one of AR, AP or IC')
  281. ) if length $a > 2;
  282. for (
  283. qw(AR_amount AR_tax AR_paid AP_amount AP_tax AP_paid IC_taxpart IC_taxservice IC_sale IC_cogs IC_income IC_expense)
  284. )
  285. {
  286. $form->error(
  287. "$form->{AR}$form->{AP}$form->{IC} "
  288. . $locale->text(
  289. 'account cannot be set to any other type of account')
  290. ) if $form->{$_};
  291. }
  292. }
  293. foreach $item ( "AR", "AP" ) {
  294. $i = 0;
  295. for ( "${item}_amount", "${item}_paid", "${item}_tax" ) {
  296. $i++ if $form->{$_};
  297. }
  298. $form->error(
  299. $locale->text( 'Cannot set multiple options for [_1]', $item ) )
  300. if $i > 1;
  301. }
  302. if ( AM->save_account( \%myconfig, \%$form ) ) {
  303. $form->redirect( $locale->text('Account saved!') );
  304. }
  305. else {
  306. $form->error( $locale->text('Cannot save account!') );
  307. }
  308. }
  309. sub list_account {
  310. CA->all_accounts( \%myconfig, \%$form );
  311. $form->{title} = $locale->text('Chart of Accounts');
  312. # construct callback
  313. $callback =
  314. "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  315. $form->{callback} = $callback;
  316. @column_index = qw(accno gifi_accno description debit credit link);
  317. $column_header{accno} = $locale->text('Account');
  318. $column_header{gifi_accno} = $locale->text('GIFI');
  319. $column_header{description} = $locale->text('Description');
  320. $column_header{debit} = $locale->text('Debit');
  321. $column_header{credit} = $locale->text('Credit');
  322. $column_header{link} = $locale->text('Link');
  323. # escape callback
  324. $callback = $form->escape($callback);
  325. my @rows;
  326. foreach my $ca ( @{ $form->{CA} } ) {
  327. my %column_data;
  328. $ca->{debit} = " ";
  329. $ca->{credit} = " ";
  330. if ( $ca->{amount} > 0 ) {
  331. $ca->{credit} =
  332. $form->format_amount( \%myconfig, $ca->{amount}, 2, " " );
  333. }
  334. if ( $ca->{amount} < 0 ) {
  335. $ca->{debit} =
  336. $form->format_amount( \%myconfig, -$ca->{amount}, 2, " " );
  337. }
  338. #$ca->{link} =~ s/:/<br>/og;
  339. $gifi_accno = $form->escape( $ca->{gifi_accno} );
  340. if ( $ca->{charttype} eq "H" ) {
  341. $column_data{heading} = 'H';
  342. $column_data{accno} = {
  343. text => $ca->{accno},
  344. href => "$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback"};
  345. $column_data{gifi_accno} = {
  346. text => $ca->{gifi_accno},
  347. href => "$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback"};
  348. $column_data{description} = $ca->{description};
  349. $column_data{debit} = " ";
  350. $column_data{credit} = " ";
  351. $column_data{link} = " ";
  352. }
  353. else {
  354. $i++;
  355. $i %= 2;
  356. $column_data{i} = $i;
  357. $column_data{accno} = {
  358. text => $ca->{accno},
  359. href => "$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback"};
  360. $column_data{gifi_accno} = {
  361. text => $ca->{gifi_accno},
  362. href => "$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback"};
  363. $column_data{description} = $ca->{description};
  364. $column_data{debit} = $ca->{debit};
  365. $column_data{credit} = $ca->{credit};
  366. $column_data{link} = $ca->{link};
  367. }
  368. push @rows, \%column_data;
  369. }
  370. my @buttons;
  371. push @buttons, {
  372. name => 'action',
  373. value => 'csv_list_account',
  374. text => $locale->text('CSV Report'),
  375. type => 'submit',
  376. class => 'submit',
  377. };
  378. my $template = LedgerSMB::Template->new(
  379. user => \%myconfig,
  380. locale => $locale,
  381. path => 'UI',
  382. template => 'am-list-accounts',
  383. format => ($form->{action} =~ /^csv/)? 'CSV': 'HTML');
  384. $template->render({
  385. form => \%$form,
  386. buttons => \@buttons,
  387. columns => \@column_index,
  388. heading => \%column_header,
  389. rows => \@rows,
  390. });
  391. }
  392. sub csv_list_account { &list_account }
  393. sub delete_account {
  394. $form->{title} = $locale->text('Delete Account');
  395. foreach $id (
  396. qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
  397. )
  398. {
  399. if ( $form->{id} == $form->{$id} ) {
  400. $form->error( $locale->text('Cannot delete default account!') );
  401. }
  402. }
  403. if ( AM->delete_account( \%myconfig, \%$form ) ) {
  404. $form->redirect( $locale->text('Account deleted!') );
  405. }
  406. else {
  407. $form->error( $locale->text('Cannot delete account!') );
  408. }
  409. }
  410. sub list_gifi {
  411. @{ $form->{fields} } = qw(accno description);
  412. $form->{table} = "gifi";
  413. AM->gifi_accounts( \%myconfig, \%$form );
  414. $form->{title} = $locale->text('GIFI');
  415. # construct callback
  416. my $callback =
  417. "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  418. $form->{callback} = $callback;
  419. my @column_index = qw(accno description);
  420. my %column_header;
  421. my @rows;
  422. $column_header{accno} = $locale->text('GIFI');
  423. $column_header{description} = $locale->text('Description');
  424. my $i = 0;
  425. foreach $ca ( @{ $form->{ALL} } ) {
  426. my %column_data;
  427. $i++;
  428. $i %= 2;
  429. $column_data{i} = $i;
  430. $accno = $form->escape( $ca->{accno} );
  431. $column_data{accno} = {text => $ca->{accno}, href =>
  432. qq|$form->{script}?action=edit_gifi&coa=1&accno=$accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback|};
  433. $column_data{description} = $ca->{description};
  434. push @rows, \%column_data;
  435. }
  436. my @buttons;
  437. push @buttons, {
  438. name => 'action',
  439. value => 'csv_list_gifi',
  440. text => $locale->text('CSV Report'),
  441. type => 'submit',
  442. class => 'submit',
  443. };
  444. my $template = LedgerSMB::Template->new(
  445. user => \%myconfig,
  446. locale => $locale,
  447. path => 'UI',
  448. template => 'am-list-accounts',
  449. format => ($form->{action} =~ /^csv/)? 'CSV': 'HTML');
  450. $template->render({
  451. form => \%$form,
  452. buttons => \@buttons,
  453. columns => \@column_index,
  454. heading => \%column_header,
  455. rows => \@rows,
  456. });
  457. }
  458. sub csv_list_gifi { &list_gifi }
  459. sub add_gifi {
  460. $form->{title} = "Add";
  461. # construct callback
  462. $form->{callback} =
  463. "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  464. $form->{coa} = 1;
  465. &gifi_header;
  466. &gifi_footer;
  467. }
  468. sub edit_gifi {
  469. $form->{title} = "Edit";
  470. AM->get_gifi( \%myconfig, \%$form );
  471. $form->error( $locale->text('Account does not exist!') )
  472. unless $form->{accno};
  473. &gifi_header;
  474. &gifi_footer;
  475. }
  476. sub gifi_header {
  477. $form->{title} = $locale->text("$form->{title} GIFI");
  478. # $locale->text('Add GIFI')
  479. # $locale->text('Edit GIFI')
  480. for (qw(accno description)) { $form->{$_} = $form->quote( $form->{$_} ) }
  481. $form->header;
  482. print qq|
  483. <body>
  484. <form method=post action=$form->{script}>
  485. <input type=hidden name=id value="$form->{accno}">
  486. <input type=hidden name=type value=gifi>
  487. <table width=100%>
  488. <tr>
  489. <th class=listtop>$form->{title}</th>
  490. </tr>
  491. <tr height="5"></tr>
  492. <tr>
  493. <td>
  494. <table>
  495. <tr>
  496. <th align="right">| . $locale->text('GIFI') . qq|</th>
  497. <td><input name=accno size=20 value="$form->{accno}"></td>
  498. </tr>
  499. <tr>
  500. <th align="right">| . $locale->text('Description') . qq|</th>
  501. <td><input name=description size=60 value="$form->{description}"></td>
  502. </tr>
  503. </table>
  504. </td>
  505. </tr>
  506. <tr>
  507. <td colspan=2><hr size=3 noshade></td>
  508. </tr>
  509. </table>
  510. |;
  511. }
  512. sub gifi_footer {
  513. $form->hide_form(qw(callback path login sessionid));
  514. # type=submit $locale->text('Save')
  515. # type=submit $locale->text('Copy to COA')
  516. # type=submit $locale->text('Delete')
  517. %button = ();
  518. $button{'save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
  519. if ( $form->{accno} ) {
  520. if ( $form->{orphaned} ) {
  521. $button{'delete'} =
  522. { ndx => 16, key => 'D', value => $locale->text('Delete') };
  523. }
  524. }
  525. if ( $form->{coa} ) {
  526. $button{'copy_to_coa'} =
  527. { ndx => 7, key => 'C', value => $locale->text('Copy to COA') };
  528. }
  529. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  530. $form->print_button( \%button, $_ );
  531. }
  532. if ( $form->{lynx} ) {
  533. require "bin/menu.pl";
  534. &menubar;
  535. }
  536. print qq|
  537. </form>
  538. </body>
  539. </html>
  540. |;
  541. }
  542. sub save_gifi {
  543. $form->isblank( "accno", $locale->text('GIFI missing!') );
  544. AM->save_gifi( \%myconfig, \%$form );
  545. $form->redirect( $locale->text('GIFI saved!') );
  546. }
  547. sub copy_to_coa {
  548. $form->isblank( "accno", $locale->text('GIFI missing!') );
  549. AM->save_gifi( \%myconfig, \%$form );
  550. delete $form->{id};
  551. $form->{gifi_accno} = $form->{accno};
  552. $form->{title} = "Add";
  553. $form->{charttype} = "A";
  554. &account_header;
  555. &form_footer;
  556. }
  557. sub delete_gifi {
  558. AM->delete_gifi( \%myconfig, \%$form );
  559. $form->redirect( $locale->text('GIFI deleted!') );
  560. }
  561. sub add_department {
  562. $form->{title} = "Add";
  563. $form->{role} = "P";
  564. $form->{callback} =
  565. "$form->{script}?action=add_department&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  566. unless $form->{callback};
  567. &department_header;
  568. &form_footer;
  569. }
  570. sub edit_department {
  571. $form->{title} = "Edit";
  572. AM->get_department( \%myconfig, \%$form );
  573. &department_header;
  574. &form_footer;
  575. }
  576. sub list_department {
  577. AM->departments( \%myconfig, \%$form );
  578. $href =
  579. "$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  580. $form->sort_order();
  581. $form->{callback} =
  582. "$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  583. $callback = $form->escape( $form->{callback} );
  584. $form->{title} = $locale->text('Departments');
  585. @column_index = qw(description cost profit);
  586. $column_header{description} =
  587. qq|<th width=90%><a class="listheading" href=$href>|
  588. . $locale->text('Description')
  589. . qq|</a></th>|;
  590. $column_header{cost} =
  591. qq|<th class="listheading" nowrap>|
  592. . $locale->text('Cost Center')
  593. . qq|</th>|;
  594. $column_header{profit} =
  595. qq|<th class="listheading" nowrap>|
  596. . $locale->text('Profit Center')
  597. . qq|</th>|;
  598. $form->header;
  599. print qq|
  600. <body>
  601. <table width=100%>
  602. <tr>
  603. <th class=listtop>$form->{title}</th>
  604. </tr>
  605. <tr height="5"></tr>
  606. <tr>
  607. <td>
  608. <table width=100%>
  609. <tr class="listheading">
  610. |;
  611. for (@column_index) { print "$column_header{$_}\n" }
  612. print qq|
  613. </tr>
  614. |;
  615. foreach $ref ( @{ $form->{ALL} } ) {
  616. $i++;
  617. $i %= 2;
  618. print qq|
  619. <tr valign=top class=listrow$i>
  620. |;
  621. $costcenter = ( $ref->{role} eq "C" ) ? "*" : "&nbsp;";
  622. $profitcenter = ( $ref->{role} eq "P" ) ? "*" : "&nbsp;";
  623. $column_data{description} =
  624. qq|<td><a href=$form->{script}?action=edit_department&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
  625. $column_data{cost} = qq|<td align=center>$costcenter</td>|;
  626. $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
  627. for (@column_index) { print "$column_data{$_}\n" }
  628. print qq|
  629. </tr>
  630. |;
  631. }
  632. print qq|
  633. </table>
  634. </td>
  635. </tr>
  636. <tr>
  637. <td><hr size=3 noshade></td>
  638. </tr>
  639. </table>
  640. <br>
  641. <form method=post action=$form->{script}>
  642. |;
  643. $form->{type} = "department";
  644. $form->hide_form(qw(type callback path login sessionid));
  645. print qq|
  646. <button class="submit" type="submit" name="action" value="add_department">|
  647. . $locale->text('Add Department')
  648. . qq|"</button>|;
  649. if ( $form->{lynx} ) {
  650. require "bin/menu.pl";
  651. &menubar;
  652. }
  653. print qq|
  654. </form>
  655. </body>
  656. </html>
  657. |;
  658. }
  659. sub department_header {
  660. $form->{title} = $locale->text("$form->{title} Department");
  661. # $locale->text('Add Department')
  662. # $locale->text('Edit Department')
  663. $form->{description} = $form->quote( $form->{description} );
  664. if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) {
  665. $description =
  666. qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
  667. }
  668. else {
  669. $description =
  670. qq|<input name=description size=60 value="$form->{description}">|;
  671. }
  672. $costcenter = "checked" if $form->{role} eq "C";
  673. $profitcenter = "checked" if $form->{role} eq "P";
  674. $form->header;
  675. print qq|
  676. <body>
  677. <form method=post action=$form->{script}>
  678. <input type=hidden name=id value=$form->{id}>
  679. <input type=hidden name=type value=department>
  680. <table width=100%>
  681. <tr>
  682. <th class=listtop colspan=2>$form->{title}</th>
  683. </tr>
  684. <tr height="5"></tr>
  685. <tr>
  686. <th align="right">| . $locale->text('Description') . qq|</th>
  687. <td>$description</td>
  688. </tr>
  689. <tr>
  690. <td></td>
  691. <td><input type=radio style=radio name=role value="C" $costcenter> |
  692. . $locale->text('Cost Center') . qq|
  693. <input type=radio style=radio name=role value="P" $profitcenter> |
  694. . $locale->text('Profit Center') . qq|
  695. </td>
  696. <tr>
  697. <td colspan=2><hr size=3 noshade></td>
  698. </tr>
  699. </table>
  700. |;
  701. }
  702. sub save_department {
  703. $form->isblank( "description", $locale->text('Description missing!') );
  704. AM->save_department( \%myconfig, \%$form );
  705. $form->redirect( $locale->text('Department saved!') );
  706. }
  707. sub delete_department {
  708. AM->delete_department( \%myconfig, \%$form );
  709. $form->redirect( $locale->text('Department deleted!') );
  710. }
  711. sub add_business {
  712. $form->{title} = "Add";
  713. $form->{callback} =
  714. "$form->{script}?action=add_business&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  715. unless $form->{callback};
  716. &business_header;
  717. &form_footer;
  718. }
  719. sub edit_business {
  720. $form->{title} = "Edit";
  721. AM->get_business( \%myconfig, \%$form );
  722. &business_header;
  723. $form->{orphaned} = 1;
  724. &form_footer;
  725. }
  726. sub list_business {
  727. AM->business( \%myconfig, \%$form );
  728. $href =
  729. "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  730. $form->sort_order();
  731. $form->{callback} =
  732. "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  733. $callback = $form->escape( $form->{callback} );
  734. $form->{title} = $locale->text('Type of Business');
  735. @column_index = qw(description discount);
  736. $column_header{description} =
  737. qq|<th width=90%><a class="listheading" href=$href>|
  738. . $locale->text('Description')
  739. . qq|</a></th>|;
  740. $column_header{discount} =
  741. qq|<th class="listheading">| . $locale->text('Discount') . qq| %</th>|;
  742. $form->header;
  743. print qq|
  744. <body>
  745. <table width=100%>
  746. <tr>
  747. <th class=listtop>$form->{title}</th>
  748. </tr>
  749. <tr height="5"></tr>
  750. <tr>
  751. <td>
  752. <table width=100%>
  753. <tr class="listheading">
  754. |;
  755. for (@column_index) { print "$column_header{$_}\n" }
  756. print qq|
  757. </tr>
  758. |;
  759. foreach $ref ( @{ $form->{ALL} } ) {
  760. $i++;
  761. $i %= 2;
  762. print qq|
  763. <tr valign=top class=listrow$i>
  764. |;
  765. $discount =
  766. $form->format_amount( \%myconfig, $ref->{discount} * 100, 2,
  767. "&nbsp" );
  768. $column_data{description} =
  769. qq|<td><a href=$form->{script}?action=edit_business&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
  770. $column_data{discount} = qq|<td align="right">$discount</td>|;
  771. for (@column_index) { print "$column_data{$_}\n" }
  772. print qq|
  773. </tr>
  774. |;
  775. }
  776. print qq|
  777. </table>
  778. </td>
  779. </tr>
  780. <tr>
  781. <td><hr size=3 noshade></td>
  782. </tr>
  783. </table>
  784. <br>
  785. <form method=post action=$form->{script}>
  786. |;
  787. $form->{type} = "business";
  788. $form->hide_form(qw(type callback path login sessionid));
  789. print qq|
  790. <button class="submit" type="submit" name="action" value="add_business">|
  791. . $locale->text('Add Business')
  792. . qq|</button>|;
  793. if ( $form->{lynx} ) {
  794. require "bin/menu.pl";
  795. &menubar;
  796. }
  797. print qq|
  798. </form>
  799. </body>
  800. </html>
  801. |;
  802. }
  803. sub business_header {
  804. $form->{title} = $locale->text("$form->{title} Business");
  805. # $locale->text('Add Business')
  806. # $locale->text('Edit Business')
  807. $form->{description} = $form->quote( $form->{description} );
  808. $form->{discount} =
  809. $form->format_amount( \%myconfig, $form->{discount} * 100 );
  810. $form->header;
  811. print qq|
  812. <body>
  813. <form method=post action=$form->{script}>
  814. <input type=hidden name=id value=$form->{id}>
  815. <input type=hidden name=type value=business>
  816. <table width=100%>
  817. <tr>
  818. <th class=listtop>$form->{title}</th>
  819. </tr>
  820. <tr height="5"></tr>
  821. <tr>
  822. <td>
  823. <table>
  824. <tr>
  825. <th align="right">| . $locale->text('Type of Business') . qq|</th>
  826. <td><input name=description size=30 value="$form->{description}"></td>
  827. <tr>
  828. <tr>
  829. <th align="right">| . $locale->text('Discount') . qq| %</th>
  830. <td><input name=discount size=5 value=$form->{discount}></td>
  831. </tr>
  832. </table>
  833. </td>
  834. </tr>
  835. <tr>
  836. <td><hr size=3 noshade></td>
  837. </tr>
  838. </table>
  839. |;
  840. }
  841. sub save_business {
  842. $form->isblank( "description", $locale->text('Description missing!') );
  843. AM->save_business( \%myconfig, \%$form );
  844. $form->redirect( $locale->text('Business saved!') );
  845. }
  846. sub delete_business {
  847. AM->delete_business( \%myconfig, \%$form );
  848. $form->redirect( $locale->text('Business deleted!') );
  849. }
  850. sub add_sic {
  851. $form->{title} = "Add";
  852. $form->{callback} =
  853. "$form->{script}?action=add_sic&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  854. unless $form->{callback};
  855. &sic_header;
  856. &form_footer;
  857. }
  858. sub edit_sic {
  859. $form->{title} = "Edit";
  860. $form->{code} =~ s/\\'/'/g;
  861. $form->{code} =~ s/\\\\/\\/g;
  862. AM->get_sic( \%myconfig, \%$form );
  863. $form->{id} = $form->{code};
  864. &sic_header;
  865. $form->{orphaned} = 1;
  866. &form_footer;
  867. }
  868. sub list_sic {
  869. AM->sic( \%myconfig, \%$form );
  870. $href =
  871. "$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  872. $form->sort_order();
  873. $form->{callback} =
  874. "$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  875. $callback = $form->escape( $form->{callback} );
  876. $form->{title} = $locale->text('Standard Industrial Codes');
  877. @column_index = $form->sort_columns(qw(code description));
  878. $column_header{code} =
  879. qq|<th><a class="listheading" href=$href&sort=code>|
  880. . $locale->text('Code')
  881. . qq|</a></th>|;
  882. $column_header{description} =
  883. qq|<th><a class="listheading" href=$href&sort=description>|
  884. . $locale->text('Description')
  885. . qq|</a></th>|;
  886. $form->header;
  887. print qq|
  888. <body>
  889. <table width=100%>
  890. <tr>
  891. <th class=listtop>$form->{title}</th>
  892. </tr>
  893. <tr height="5"></tr>
  894. <tr>
  895. <td>
  896. <table width=100%>
  897. <tr class="listheading">
  898. |;
  899. for (@column_index) { print "$column_header{$_}\n" }
  900. print qq|
  901. </tr>
  902. |;
  903. foreach $ref ( @{ $form->{ALL} } ) {
  904. $i++;
  905. $i %= 2;
  906. if ( $ref->{sictype} eq 'H' ) {
  907. print qq|
  908. <tr valign=top class="listheading">
  909. |;
  910. $column_data{code} =
  911. qq|<th><a href=$form->{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</th>|;
  912. $column_data{description} = qq|<th>$ref->{description}</th>|;
  913. }
  914. else {
  915. print qq|
  916. <tr valign=top class=listrow$i>
  917. |;
  918. $column_data{code} =
  919. qq|<td><a href=$form->{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</td>|;
  920. $column_data{description} = qq|<td>$ref->{description}</td>|;
  921. }
  922. for (@column_index) { print "$column_data{$_}\n" }
  923. print qq|
  924. </tr>
  925. |;
  926. }
  927. print qq|
  928. </table>
  929. </td>
  930. </tr>
  931. <tr>
  932. <td><hr size=3 noshade></td>
  933. </tr>
  934. </table>
  935. <br>
  936. <form method=post action=$form->{script}>
  937. |;
  938. $form->{type} = "sic";
  939. $form->hide_form(qw(type callback path login sessionid));
  940. print qq|
  941. <button class="submit" type="submit" name="action" value="add_sic">|
  942. . $locale->text('Add SIC')
  943. . qq|</button>|;
  944. if ( $form->{lynx} ) {
  945. require "bin/menu.pl";
  946. &menubar;
  947. }
  948. print qq|
  949. </form>
  950. </body>
  951. </html>
  952. |;
  953. }
  954. sub sic_header {
  955. $form->{title} = $locale->text("$form->{title} SIC");
  956. # $locale->text('Add SIC')
  957. # $locale->text('Edit SIC')
  958. for (qw(code description)) { $form->{$_} = $form->quote( $form->{$_} ) }
  959. $checked = ( $form->{sictype} eq 'H' ) ? "checked" : "";
  960. $form->header;
  961. print qq|
  962. <body>
  963. <form method=post action=$form->{script}>
  964. <input type=hidden name=type value=sic>
  965. <input type=hidden name=id value="$form->{code}">
  966. <table width=100%>
  967. <tr>
  968. <th class=listtop colspan=2>$form->{title}</th>
  969. </tr>
  970. <tr height="5"></tr>
  971. <tr>
  972. <th align="right">| . $locale->text('Code') . qq|</th>
  973. <td><input name=code size=10 value="$form->{code}"></td>
  974. <tr>
  975. <tr>
  976. <td></td>
  977. <th align=left><input name=sictype class=checkbox type=checkbox value="H" $checked> |
  978. . $locale->text('Heading')
  979. . qq|</th>
  980. <tr>
  981. <tr>
  982. <th align="right">| . $locale->text('Description') . qq|</th>
  983. <td><input name=description size=60 value="$form->{description}"></td>
  984. </tr>
  985. <td colspan=2><hr size=3 noshade></td>
  986. </tr>
  987. </table>
  988. |;
  989. }
  990. sub save_sic {
  991. $form->isblank( "code", $locale->text('Code missing!') );
  992. $form->isblank( "description", $locale->text('Description missing!') );
  993. AM->save_sic( \%myconfig, \%$form );
  994. $form->redirect( $locale->text('SIC saved!') );
  995. }
  996. sub delete_sic {
  997. AM->delete_sic( \%myconfig, \%$form );
  998. $form->redirect( $locale->text('SIC deleted!') );
  999. }
  1000. sub add_language {
  1001. $form->{title} = "Add";
  1002. $form->{callback} =
  1003. "$form->{script}?action=add_language&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  1004. unless $form->{callback};
  1005. &language_header;
  1006. &form_footer;
  1007. }
  1008. sub edit_language {
  1009. $form->{title} = "Edit";
  1010. $form->{code} =~ s/\\'/'/g;
  1011. $form->{code} =~ s/\\\\/\\/g;
  1012. AM->get_language( \%myconfig, \%$form );
  1013. $form->{id} = $form->{code};
  1014. &language_header;
  1015. $form->{orphaned} = 1;
  1016. &form_footer;
  1017. }
  1018. sub list_language {
  1019. AM->language( \%myconfig, \%$form );
  1020. $href =
  1021. "$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1022. $form->sort_order();
  1023. $form->{callback} =
  1024. "$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1025. $callback = $form->escape( $form->{callback} );
  1026. $form->{title} = $locale->text('Languages');
  1027. @column_index = $form->sort_columns(qw(code description));
  1028. $column_header{code} =
  1029. qq|<th><a class="listheading" href=$href&sort=code>|
  1030. . $locale->text('Code')
  1031. . qq|</a></th>|;
  1032. $column_header{description} =
  1033. qq|<th><a class="listheading" href=$href&sort=description>|
  1034. . $locale->text('Description')
  1035. . qq|</a></th>|;
  1036. $form->header;
  1037. print qq|
  1038. <body>
  1039. <table width=100%>
  1040. <tr>
  1041. <th class=listtop>$form->{title}</th>
  1042. </tr>
  1043. <tr height="5"></tr>
  1044. <tr>
  1045. <td>
  1046. <table width=100%>
  1047. <tr class="listheading">
  1048. |;
  1049. for (@column_index) { print "$column_header{$_}\n" }
  1050. print qq|
  1051. </tr>
  1052. |;
  1053. foreach $ref ( @{ $form->{ALL} } ) {
  1054. $i++;
  1055. $i %= 2;
  1056. print qq|
  1057. <tr valign=top class=listrow$i>
  1058. |;
  1059. $column_data{code} =
  1060. qq|<td><a href=$form->{script}?action=edit_language&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</td>|;
  1061. $column_data{description} = qq|<td>$ref->{description}</td>|;
  1062. for (@column_index) { print "$column_data{$_}\n" }
  1063. print qq|
  1064. </tr>
  1065. |;
  1066. }
  1067. print qq|
  1068. </table>
  1069. </td>
  1070. </tr>
  1071. <tr>
  1072. <td><hr size=3 noshade></td>
  1073. </tr>
  1074. </table>
  1075. <br>
  1076. <form method=post action=$form->{script}>
  1077. |;
  1078. $form->{type} = "language";
  1079. $form->hide_form(qw(type callback path login sessionid));
  1080. print qq|
  1081. <button class="submit" type="submit" name="action" value="add_language">|
  1082. . $locale->text('Add Language')
  1083. . qq|</button>|;
  1084. if ( $form->{lynx} ) {
  1085. require "bin/menu.pl";
  1086. &menubar;
  1087. }
  1088. print qq|
  1089. </form>
  1090. </body>
  1091. </html>
  1092. |;
  1093. }
  1094. sub language_header {
  1095. $form->{title} = $locale->text("$form->{title} Language");
  1096. # $locale->text('Add Language')
  1097. # $locale->text('Edit Language')
  1098. for (qw(code description)) { $form->{$_} = $form->quote( $form->{$_} ) }
  1099. $form->header;
  1100. print qq|
  1101. <body>
  1102. <form method=post action=$form->{script}>
  1103. <input type=hidden name=type value=language>
  1104. <input type=hidden name=id value="$form->{code}">
  1105. <table width=100%>
  1106. <tr>
  1107. <th class=listtop colspan=2>$form->{title}</th>
  1108. </tr>
  1109. <tr height="5"></tr>
  1110. <tr>
  1111. <th align="right">| . $locale->text('Code') . qq|</th>
  1112. <td><input name=code size=10 value="$form->{code}"></td>
  1113. <tr>
  1114. <tr>
  1115. <th align="right">| . $locale->text('Description') . qq|</th>
  1116. <td><input name=description size=60 value="$form->{description}"></td>
  1117. </tr>
  1118. <td colspan=2><hr size=3 noshade></td>
  1119. </tr>
  1120. </table>
  1121. |;
  1122. }
  1123. sub save_language {
  1124. $form->isblank( "code", $locale->text('Code missing!') );
  1125. $form->isblank( "description", $locale->text('Description missing!') );
  1126. $form->{code} =~ s/(\.\.|\*)//g;
  1127. AM->save_language( \%myconfig, \%$form );
  1128. if ( !-d "$myconfig{templates}/$form->{code}" ) {
  1129. umask(002);
  1130. if ( mkdir "$myconfig{templates}/$form->{code}", oct("771") ) {
  1131. umask(007);
  1132. opendir TEMPLATEDIR, "$myconfig{templates}"
  1133. or $form->error("$myconfig{templates} : $!");
  1134. @templates = grep !/^(\.|\.\.)/, readdir TEMPLATEDIR;
  1135. closedir TEMPLATEDIR;
  1136. foreach $file (@templates) {
  1137. if ( -f "$myconfig{templates}/$file" ) {
  1138. open( TEMP, '<', "$myconfig{templates}/$file" )
  1139. or $form->error("$myconfig{templates}/$file : $!");
  1140. open( NEW, '>', "$myconfig{templates}/$form->{code}/$file" )
  1141. or $form->error(
  1142. "$myconfig{templates}/$form->{code}/$file : $!");
  1143. while ( $line = <TEMP> ) {
  1144. print NEW $line;
  1145. }
  1146. close(TEMP);
  1147. close(NEW);
  1148. }
  1149. }
  1150. }
  1151. else {
  1152. $form->error("${templates}/$form->{code} : $!");
  1153. }
  1154. }
  1155. $form->redirect( $locale->text('Language saved!') );
  1156. }
  1157. sub delete_language {
  1158. $form->{title} = $locale->text('Confirm!');
  1159. $form->header;
  1160. print qq|
  1161. <body>
  1162. <form method=post action=$form->{script}>
  1163. |;
  1164. for (qw(action nextsub)) { delete $form->{$_} }
  1165. $form->hide_form;
  1166. print qq|
  1167. <h2 class=confirm>$form->{title}</h2>
  1168. <h4>|
  1169. . $locale->text(
  1170. 'Deleting a language will also delete the templates for the language [_1]',
  1171. $form->{invnumber}
  1172. )
  1173. . qq|</h4>
  1174. <input type=hidden name=action value=continue>
  1175. <input type=hidden name=nextsub value=yes_delete_language>
  1176. <button name="action" class="submit" type="submit" value="continue">|
  1177. . $locale->text('Continue')
  1178. . qq|</button>
  1179. </form>
  1180. </body>
  1181. </html>
  1182. |;
  1183. }
  1184. sub yes_delete_language {
  1185. AM->delete_language( \%myconfig, \%$form );
  1186. # delete templates
  1187. $dir = "$myconfig{templates}/$form->{code}";
  1188. if ( -d $dir ) {
  1189. unlink <$dir/*>;
  1190. rmdir "$myconfig{templates}/$form->{code}";
  1191. }
  1192. $form->redirect( $locale->text('Language deleted!') );
  1193. }
  1194. sub display_stylesheet {
  1195. $form->{file} = "css/$myconfig{stylesheet}";
  1196. &display_form;
  1197. }
  1198. sub list_templates {
  1199. AM->language( \%myconfig, \%$form );
  1200. if ( !@{ $form->{ALL} } ) {
  1201. &display_form;
  1202. exit;
  1203. }
  1204. unshift @{ $form->{ALL} },
  1205. { code => '.', description => $locale->text('Default Template') };
  1206. $href =
  1207. "$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1208. $form->sort_order();
  1209. $form->{callback} =
  1210. "$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1211. $callback = $form->escape( $form->{callback} );
  1212. chomp $myconfig{templates};
  1213. $form->{file} =~ s/$myconfig{templates}//;
  1214. $form->{file} =~ s/\///;
  1215. $form->{title} = $form->{file};
  1216. @column_index = $form->sort_columns(qw(code description));
  1217. $column_header{code} =
  1218. qq|<th><a class="listheading" href=$href&sort=code>|
  1219. . $locale->text('Code')
  1220. . qq|</a></th>|;
  1221. $column_header{description} =
  1222. qq|<th><a class="listheading" href=$href&sort=description>|
  1223. . $locale->text('Description')
  1224. . qq|</a></th>|;
  1225. $form->header;
  1226. print qq|
  1227. <body>
  1228. <table width=100%>
  1229. <tr>
  1230. <th class=listtop>$form->{title}</th>
  1231. </tr>
  1232. <tr height="5"></tr>
  1233. <tr>
  1234. <td>
  1235. <table width=100%>
  1236. <tr class="listheading">
  1237. |;
  1238. for (@column_index) { print "$column_header{$_}\n" }
  1239. print qq|
  1240. </tr>
  1241. |;
  1242. foreach $ref ( @{ $form->{ALL} } ) {
  1243. $i++;
  1244. $i %= 2;
  1245. print qq|
  1246. <tr valign=top class=listrow$i>
  1247. |;
  1248. $column_data{code} =
  1249. qq|<td><a href=$form->{script}?action=display_form&file=$myconfig{templates}/$ref->{code}/$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&code=$ref->{code}&callback=$callback>$ref->{code}</td>|;
  1250. $column_data{description} = qq|<td>$ref->{description}</td>|;
  1251. for (@column_index) { print "$column_data{$_}\n" }
  1252. print qq|
  1253. </tr>
  1254. |;
  1255. }
  1256. print qq|
  1257. </table>
  1258. </td>
  1259. </tr>
  1260. <tr>
  1261. <td><hr size=3 noshade></td>
  1262. </tr>
  1263. </table>
  1264. <br>
  1265. <form method=post action=$form->{script}>
  1266. <input name=callback type=hidden value="$form->{callback}">
  1267. <input type=hidden name=type value=language>
  1268. <input type=hidden name=path value=$form->{path}>
  1269. <input type=hidden name=login value=$form->{login}>
  1270. <input type=hidden name=sessionid value=$form->{sessionid}>
  1271. |;
  1272. if ( $form->{lynx} ) {
  1273. require "bin/menu.pl";
  1274. &menubar;
  1275. }
  1276. print qq|
  1277. </form>
  1278. </body>
  1279. </html>
  1280. |;
  1281. }
  1282. sub display_form {
  1283. AM->load_template( \%myconfig, \%$form );
  1284. $form->{title} = $form->{file};
  1285. $form->{body} =~
  1286. s/<%include (.*?)%>/<a href=$form->{script}\?action=display_form&file=$myconfig{templates}\/$form->{code}\/$1&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}>$1<\/a>/g;
  1287. # if it is anything but html
  1288. if ( $form->{file} !~ /\.html$/ ) {
  1289. $form->{body} = "<pre>\n$form->{body}\n</pre>";
  1290. }
  1291. $form->header;
  1292. print qq|
  1293. <body>
  1294. $form->{body}
  1295. <form method=post action=$form->{script}>
  1296. |;
  1297. $form->{type} = "template";
  1298. $form->hide_form(qw(file type path login sessionid));
  1299. print qq|
  1300. <button name="action" type="submit" class="submit" value="edit">|
  1301. . $locale->text('Edit')
  1302. . qq|</button>|;
  1303. if ( $form->{lynx} ) {
  1304. require "bin/menu.pl";
  1305. &menubar;
  1306. }
  1307. print qq|
  1308. </form>
  1309. </body>
  1310. </html>
  1311. |;
  1312. }
  1313. sub edit_template {
  1314. AM->load_template( \%myconfig, \%$form );
  1315. $form->{title} = $locale->text('Edit Template');
  1316. # convert &nbsp to &amp;nbsp;
  1317. $form->{body} =~ s/&nbsp;/&amp;nbsp;/gi;
  1318. $form->header;
  1319. print qq|
  1320. <body>
  1321. <form method=post action=$form->{script}>
  1322. <input name=file type=hidden value=$form->{file}>
  1323. <input name=type type=hidden value=template>
  1324. <input type=hidden name=path value=$form->{path}>
  1325. <input type=hidden name=login value=$form->{login}>
  1326. <input type=hidden name=sessionid value=$form->{sessionid}>
  1327. <input name=callback type=hidden value="$form->{script}?action=display_form&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}">
  1328. <textarea name=body rows=25 cols=70>
  1329. $form->{body}
  1330. </textarea>
  1331. <br>
  1332. <button type="submit" class="submit" name="action" value="save">|
  1333. . $locale->text('Save')
  1334. . qq|</button>|;
  1335. if ( $form->{lynx} ) {
  1336. require "bin/menu.pl";
  1337. &menubar;
  1338. }
  1339. print q|
  1340. </form>
  1341. </body>
  1342. </html>
  1343. |;
  1344. }
  1345. sub save_template {
  1346. AM->save_template( \%myconfig, \%$form );
  1347. $form->redirect( $locale->text('Template saved!') );
  1348. }
  1349. sub defaults {
  1350. # get defaults for account numbers and last numbers
  1351. AM->get_all_defaults( \%$form );
  1352. foreach $key ( keys %{ $form->{accno} } ) {
  1353. foreach $accno ( sort keys %{ $form->{accno}{$key} } ) {
  1354. $form->{account}{$key} .=
  1355. "<option>$accno--$form->{accno}{$key}{$accno}{description}\n";
  1356. $form->{accno}{ $form->{accno}{$key}{$accno}{id} } = $accno;
  1357. }
  1358. }
  1359. for (qw(IC IC_inventory IC_income IC_expense FX_gain FX_loss)) {
  1360. $form->{account}{$_} =~
  1361. s/>$form->{accno}{$form->{defaults}{$_}}/ selected>$form->{accno}{$form->{defaults}{$_}}/;
  1362. }
  1363. for (qw(accno defaults)) { delete $form->{$_} }
  1364. $form->{title} = $locale->text('System Defaults');
  1365. $form->header;
  1366. print qq|
  1367. <body>
  1368. <form method=post action=$form->{script}>
  1369. <input type=hidden name=type value=defaults>
  1370. <table width=100%>
  1371. <tr><th class=listtop>$form->{title}</th></tr>
  1372. <tr>
  1373. <td>
  1374. <table>
  1375. <tr>
  1376. <th align="right">| . $locale->text('Business Number') . qq|</th>
  1377. <td><input name=businessnumber size=25 value="$form->{businessnumber}"></td>
  1378. </tr>
  1379. <tr>
  1380. <th align="right">| . $locale->text('Weight Unit') . qq|</th>
  1381. <td><input name=weightunit size=5 value="$form->{weightunit}"></td>
  1382. </tr>
  1383. </table>
  1384. </td>
  1385. </tr>
  1386. <tr>
  1387. <th class="listheading">|
  1388. . $locale->text('Last Numbers & Default Accounts')
  1389. . qq|</th>
  1390. </tr>
  1391. <tr>
  1392. <td>
  1393. <table>
  1394. <tr>
  1395. <th align="right" nowrap>| . $locale->text('Inventory') . qq|</th>
  1396. <td><select name=IC>$form->{account}{IC}</select></td>
  1397. </tr>
  1398. <tr>
  1399. <th align="right" nowrap>| . $locale->text('Income') . qq|</th>
  1400. <td><select name=IC_income>$form->{account}{IC_income}</select></td>
  1401. </tr>
  1402. <tr>
  1403. <th align="right" nowrap>| . $locale->text('Expense') . qq|</th>
  1404. <td><select name=IC_expense>$form->{account}{IC_expense}</select></td>
  1405. </tr>
  1406. <tr>
  1407. <th align="right" nowrap>|
  1408. . $locale->text('Foreign Exchange Gain')
  1409. . qq|</th>
  1410. <td><select name=FX_gain>$form->{account}{FX_gain}</select></td>
  1411. </tr>
  1412. <tr>
  1413. <th align="right" nowrap>|
  1414. . $locale->text('Foreign Exchange Loss')
  1415. . qq|</th>
  1416. <td><select name=FX_loss>$form->{account}{FX_loss}</select></td>
  1417. </tr>
  1418. </table>
  1419. </td>
  1420. </tr>
  1421. <tr>
  1422. <th align=left>|
  1423. . $locale->text(
  1424. 'Enter up to 3 letters separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies'
  1425. )
  1426. . qq|</th>
  1427. </tr>
  1428. <tr>
  1429. <td>
  1430. <input name=curr size=40 value="$form->{curr}">
  1431. </td>
  1432. </tr>
  1433. <tr>
  1434. <td>
  1435. <table>
  1436. <tr>
  1437. <th align="right" nowrap>| . $locale->text('GL Reference Number') . qq|</th>
  1438. <td><input name=glnumber size=40 value="$form->{glnumber}"></td>
  1439. </tr>
  1440. <tr>
  1441. <th align="right" nowrap>|
  1442. . $locale->text('Sales Invoice/AR Transaction Number')
  1443. . qq|</th>
  1444. <td><input name=sinumber size=40 value="$form->{sinumber}"></td>
  1445. </tr>
  1446. <tr>
  1447. <th align="right" nowrap>| . $locale->text('Sales Order Number') . qq|</th>
  1448. <td><input name=sonumber size=40 value="$form->{sonumber}"></td>
  1449. </tr>
  1450. <tr>
  1451. <th align="right" nowrap>|
  1452. . $locale->text('Vendor Invoice/AP Transaction Number')
  1453. . qq|</th>
  1454. <td><input name=vinumber size=40 value="$form->{vinumber}"></td>
  1455. </tr>
  1456. <tr>
  1457. <th align="right" nowrap>|
  1458. . $locale->text('Purchase Order Number')
  1459. . qq|</th>
  1460. <td><input name=ponumber size=40 value="$form->{ponumber}"></td>
  1461. </tr>
  1462. <tr>
  1463. <th align="right" nowrap>|
  1464. . $locale->text('Sales Quotation Number')
  1465. . qq|</th>
  1466. <td><input name=sqnumber size=40 value="$form->{sqnumber}"></td>
  1467. </tr>
  1468. <tr>
  1469. <th align="right" nowrap>| . $locale->text('RFQ Number') . qq|</th>
  1470. <td><input name=rfqnumber size=40 value="$form->{rfqnumber}"></td>
  1471. </tr>
  1472. <tr>
  1473. <th align="right" nowrap>| . $locale->text('Part Number') . qq|</th>
  1474. <td><input name=partnumber size=40 value="$form->{partnumber}"></td>
  1475. </tr>
  1476. <tr>
  1477. <th align="right" nowrap>| . $locale->text('Job/Project Number') . qq|</th>
  1478. <td><input name=projectnumber size=40 value="$form->{projectnumber}"></td>
  1479. </tr>
  1480. <tr>
  1481. <th align="right" nowrap>| . $locale->text('Employee Number') . qq|</th>
  1482. <td><input name=employeenumber size=40 value="$form->{employeenumber}"></td>
  1483. </tr>
  1484. <tr>
  1485. <th align="right" nowrap>| . $locale->text('Customer Number') . qq|</th>
  1486. <td><input name=customernumber size=40 value="$form->{customernumber}"></td>
  1487. </tr>
  1488. <tr>
  1489. <th align="right" nowrap>| . $locale->text('Vendor Number') . qq|</th>
  1490. <td><input name=vendornumber size=40 value="$form->{vendornumber}"></td>
  1491. </tr>
  1492. </table>
  1493. </td>
  1494. </tr>
  1495. <tr>
  1496. <td><hr size=3 noshade></td>
  1497. </tr>
  1498. </table>
  1499. |;
  1500. $form->hide_form(qw(path login sessionid));
  1501. print qq|
  1502. <button type="submit" class="submit" name="action" value="save">|
  1503. . $locale->text('Save')
  1504. . qq|</button>|;
  1505. if ( $form->{lynx} ) {
  1506. require "bin/menu.pl";
  1507. &menubar;
  1508. }
  1509. print qq|
  1510. </form>
  1511. </body>
  1512. </html>
  1513. |;
  1514. }
  1515. sub taxes {
  1516. # get tax account numbers
  1517. AM->taxes( \%myconfig, \%$form );
  1518. $i = 0;
  1519. foreach $ref ( @{ $form->{taxrates} } ) {
  1520. $i++;
  1521. $form->{"taxrate_$i"} =
  1522. $form->format_amount( \%myconfig, $ref->{rate} );
  1523. $form->{"taxdescription_$i"} = $ref->{description};
  1524. for (qw(taxnumber validto pass taxmodulename)) {
  1525. $form->{"${_}_$i"} = $ref->{$_};
  1526. }
  1527. $form->{taxaccounts} .= "$ref->{id}_$i ";
  1528. }
  1529. chop $form->{taxaccounts};
  1530. &display_taxes;
  1531. }
  1532. sub display_taxes {
  1533. $form->{title} = $locale->text('Taxes');
  1534. $form->header;
  1535. print qq|
  1536. <body>
  1537. <form method=post action=$form->{script}>
  1538. <input type=hidden name=type value=taxes>
  1539. <table width=100%>
  1540. <tr><th class=listtop>$form->{title}</th></tr>
  1541. <tr>
  1542. <td>
  1543. <table>
  1544. <tr>
  1545. <th></th>
  1546. <th>| . $locale->text('Rate') . qq| (%)</th>
  1547. <th>| . $locale->text('Number') . qq|</th>
  1548. <th>| . $locale->text('Valid To') . qq|</th>
  1549. <th>| . $locale->text('Ordering') . qq|</th>
  1550. <th>| . $locale->text('Tax Rules') . qq|</th>
  1551. </tr>
  1552. |;
  1553. for ( split( / /, $form->{taxaccounts} ) ) {
  1554. ( $null, $i ) = split /_/, $_;
  1555. $form->{"taxrate_$i"} =
  1556. $form->format_amount( \%myconfig, $form->{"taxrate_$i"} );
  1557. $form->hide_form("taxdescription_$i");
  1558. print qq|
  1559. <tr>
  1560. <th align="right">|;
  1561. if ( $form->{"taxdescription_$i"} eq $sametax ) {
  1562. print "";
  1563. }
  1564. else {
  1565. print qq|$form->{"taxdescription_$i"}|;
  1566. }
  1567. print qq|</th>
  1568. <td><input name="taxrate_$i" size=6 value=$form->{"taxrate_$i"}></td>
  1569. <td><input name="taxnumber_$i" value="$form->{"taxnumber_$i"}"></td>
  1570. <td><input class="date" name="validto_$i" size=11 value="$form->{"validto_$i"}" title="$myconfig{dateformat}"></td>
  1571. <td><input name="pass_$i" size=6 value="$form->{"pass_$i"}"></td>
  1572. <td><select name="taxmodule_id_$i" size=1>|;
  1573. foreach my $taxmodule ( sort keys %$form ) {
  1574. next if ( $taxmodule !~ /^taxmodule_/ );
  1575. next if ( $taxmodule =~ /^taxmodule_id_/ );
  1576. my $modulenum = $taxmodule;
  1577. $modulenum =~ s/^taxmodule_//;
  1578. print '<option label="'
  1579. . $form->{$taxmodule}
  1580. . '" value="'
  1581. . $modulenum . '"';
  1582. print " SELECTED "
  1583. if $form->{$taxmodule} eq $form->{"taxmodulename_$i"};
  1584. print ">" . $form->{$taxmodule} . "</option>\n";
  1585. }
  1586. print qq|</select></td>
  1587. </tr> |;
  1588. $sametax = $form->{"taxdescription_$i"};
  1589. }
  1590. print qq|
  1591. </table>
  1592. </td>
  1593. </tr>
  1594. <tr>
  1595. <td><hr size=3 noshade></td>
  1596. </tr>
  1597. </table>
  1598. |;
  1599. $form->hide_form(qw(taxaccounts path login sessionid));
  1600. foreach my $taxmodule ( sort keys %$form ) {
  1601. next if ( $taxmodule !~ /^taxmodule_/ );
  1602. next if ( $taxmodule =~ /^taxmodule_id_/ );
  1603. $form->hide_form("$taxmodule");
  1604. }
  1605. print qq|
  1606. <button type="submit" class="submit" name="action" value="update">|
  1607. . $locale->text('Update')
  1608. . qq|</button>
  1609. <button type="submit" class="submit" name="action" value="save_taxes">|
  1610. . $locale->text('Save')
  1611. . qq|</button>|;
  1612. if ( $form->{lynx} ) {
  1613. require "bin/menu.pl";
  1614. &menubar;
  1615. }
  1616. print qq|
  1617. </form>
  1618. </body>
  1619. </html>
  1620. |;
  1621. }
  1622. sub update {
  1623. @a = split / /, $form->{taxaccounts};
  1624. $ndx = $#a + 1;
  1625. foreach $item (@a) {
  1626. ( $accno, $i ) = split /_/, $item;
  1627. push @t, $accno;
  1628. $form->{"taxmodulename_$i"} =
  1629. $form->{ "taxmodule_" . $form->{"taxmodule_id_$i"} };
  1630. if ( $form->{"validto_$i"} ) {
  1631. $j = $i + 1;
  1632. if ( $form->{"taxdescription_$i"} ne $form->{"taxdescription_$j"} )
  1633. {
  1634. #insert line
  1635. for ( $j = $ndx + 1 ; $j > $i ; $j-- ) {
  1636. $k = $j - 1;
  1637. for (qw(taxrate taxdescription taxnumber validto)) {
  1638. $form->{"${_}_$j"} = $form->{"${_}_$k"};
  1639. }
  1640. }
  1641. $ndx++;
  1642. $k = $i + 1;
  1643. for (qw(taxdescription taxnumber)) {
  1644. $form->{"${_}_$k"} = $form->{"${_}_$i"};
  1645. }
  1646. for (qw(taxrate validto)) { $form->{"${_}_$k"} = "" }
  1647. push @t, $accno;
  1648. }
  1649. }
  1650. else {
  1651. # remove line
  1652. $j = $i + 1;
  1653. if ( $form->{"taxdescription_$i"} eq $form->{"taxdescription_$j"} )
  1654. {
  1655. for ( $j = $i + 1 ; $j <= $ndx ; $j++ ) {
  1656. $k = $j + 1;
  1657. for (qw(taxrate taxdescription taxnumber validto)) {
  1658. $form->{"${_}_$j"} = $form->{"${_}_$k"};
  1659. }
  1660. }
  1661. $ndx--;
  1662. splice @t, $i - 1, 1;
  1663. }
  1664. }
  1665. }
  1666. $i = 1;
  1667. $form->{taxaccounts} = "";
  1668. for (@t) {
  1669. $form->{taxaccounts} .= "${_}_$i ";
  1670. $i++;
  1671. }
  1672. chop $form->{taxaccounts};
  1673. &display_taxes;
  1674. }
  1675. sub config {
  1676. foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd))
  1677. {
  1678. $dateformat .=
  1679. ( $item eq $myconfig{dateformat} )
  1680. ? "<option selected>$item\n"
  1681. : "<option>$item\n";
  1682. }
  1683. my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00);
  1684. push @formats, '1 000.00';
  1685. foreach $item (@formats) {
  1686. $numberformat .=
  1687. ( $item eq $myconfig{numberformat} )
  1688. ? "<option selected>$item\n"
  1689. : "<option>$item\n";
  1690. }
  1691. for (qw(name company address signature)) {
  1692. $myconfig{$_} = $form->quote( $myconfig{$_} );
  1693. }
  1694. for (qw(address signature)) { $myconfig{$_} =~ s/\\n/\n/g }
  1695. %countrycodes = LedgerSMB::User->country_codes;
  1696. $countrycodes = '';
  1697. my $selectedcode =
  1698. ( $myconfig{countrycode} ) ? $myconfig{countrycode} : 'en';
  1699. foreach $key ( sort { $countrycodes{$a} cmp $countrycodes{$b} }
  1700. keys %countrycodes )
  1701. {
  1702. $countrycodes .=
  1703. ( $selectedcode eq $key )
  1704. ? "<option selected value=$key>$countrycodes{$key}\n"
  1705. : "<option value=$key>$countrycodes{$key}\n";
  1706. }
  1707. opendir CSS, "css/.";
  1708. @all = grep /.*\.css$/, readdir CSS;
  1709. closedir CSS;
  1710. foreach $item (@all) {
  1711. if ( $item eq $myconfig{stylesheet} ) {
  1712. $selectstylesheet .= qq|<option selected>$item\n|;
  1713. }
  1714. else {
  1715. $selectstylesheet .= qq|<option>$item\n|;
  1716. }
  1717. }
  1718. $selectstylesheet .= "<option>\n";
  1719. if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) {
  1720. $selectprinter = "<option>\n";
  1721. foreach $item ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  1722. if ( $myconfig{printer} eq $item ) {
  1723. $selectprinter .= qq|<option value="$item" selected>$item\n|;
  1724. }
  1725. else {
  1726. $selectprinter .= qq|<option value="$item">$item\n|;
  1727. }
  1728. }
  1729. $printer = qq|
  1730. <tr>
  1731. <th align="right">| . $locale->text('Printer') . qq|</th>
  1732. <td><select name=printer>$selectprinter</select></td>
  1733. </tr>
  1734. |;
  1735. }
  1736. $form->{title} =
  1737. $locale->text( 'Edit Preferences for [_1]', $form->{login} );
  1738. $form->header;
  1739. print qq|
  1740. <body>
  1741. <form method=post action=$form->{script}>
  1742. <input type=hidden name=old_password value="$myconfig{password}">
  1743. <input type=hidden name=type value=preferences>
  1744. <input type=hidden name=role value="$myconfig{role}">
  1745. <table width=100%>
  1746. <tr><th class=listtop>$form->{title}</th></tr>
  1747. <tr>
  1748. <td>
  1749. <table width=100%>
  1750. <tr valign=top>
  1751. <td>
  1752. <table>
  1753. <tr>
  1754. <th align="right">| . $locale->text('Name') . qq|</th>
  1755. <td><input name=name size=20 value="$myconfig{name}"></td>
  1756. </tr>
  1757. <tr>
  1758. <th align="right">| . $locale->text('E-mail') . qq|</th>
  1759. <td><input name=email size=35 value="$myconfig{email}"></td>
  1760. </tr>
  1761. <tr valign=top>
  1762. <th align="right">| . $locale->text('Signature') . qq|</th>
  1763. <td><textarea name=signature rows=3 cols=35>$myconfig{signature}</textarea></td>
  1764. </tr>
  1765. <tr>
  1766. <th align="right">| . $locale->text('Phone') . qq|</th>
  1767. <td><input name=tel size=14 value="$myconfig{tel}"></td>
  1768. </tr>
  1769. <tr>
  1770. <th align="right">| . $locale->text('Fax') . qq|</th>
  1771. <td><input name=fax size=14 value="$myconfig{fax}"></td>
  1772. </tr>
  1773. <tr>
  1774. <th align="right">| . $locale->text('Company') . qq|</th>
  1775. <td><input name=company size=35 value="$myconfig{company}"></td>
  1776. </tr>
  1777. <tr valign=top>
  1778. <th align="right">| . $locale->text('Address') . qq|</th>
  1779. <td><textarea name=address rows=4 cols=35>$myconfig{address}</textarea></td>
  1780. </tr>
  1781. </table>
  1782. </td>
  1783. <td>
  1784. <table>
  1785. <tr>
  1786. <th align="right">| . $locale->text('Password') . qq|</th>
  1787. <td><input type=password name=new_password size=10 value="$myconfig{password}"></td>
  1788. </tr>
  1789. <tr>
  1790. <th align="right">| . $locale->text('Confirm') . qq|</th>
  1791. <td><input type=password name=confirm_password size=10></td>
  1792. </tr>
  1793. <tr>
  1794. <th align="right">| . $locale->text('Date Format') . qq|</th>
  1795. <td><select name=dateformat>$dateformat</select></td>
  1796. </tr>
  1797. <tr>
  1798. <th align="right">| . $locale->text('Number Format') . qq|</th>
  1799. <td><select name=numberformat>$numberformat</select></td>
  1800. </tr>
  1801. <tr>
  1802. <th align="right">| . $locale->text('Dropdown Limit') . qq|</th>
  1803. <td><input name=vclimit size=10 value="$myconfig{vclimit}"></td>
  1804. </tr>
  1805. <tr>
  1806. <th align="right">| . $locale->text('Menu Width') . qq|</th>
  1807. <td><input name=menuwidth size=10 value="$myconfig{menuwidth}"></td>
  1808. </tr>
  1809. <tr>
  1810. <th align="right">| . $locale->text('Language') . qq|</th>
  1811. <td><select name=countrycode>$countrycodes</select></td>
  1812. </tr>
  1813. <tr>
  1814. <th align="right">| . $locale->text('Session Timeout') . qq|</th>
  1815. <td><input name=timeout size=10 value="$myconfig{timeout}"></td>
  1816. </tr>
  1817. <tr>
  1818. <th align="right">| . $locale->text('Stylesheet') . qq|</th>
  1819. <td><select name=usestylesheet>$selectstylesheet</select></td>
  1820. </tr>
  1821. $printer
  1822. </table>
  1823. </td>
  1824. </tr>
  1825. </table>
  1826. </td>
  1827. <tr>
  1828. <td><hr size=3 noshade></td>
  1829. </tr>
  1830. </table>
  1831. |;
  1832. $form->hide_form(qw(path login sessionid));
  1833. print qq|
  1834. <button type="submit" class="submit" name="action" value="save">|
  1835. . $locale->text('Save')
  1836. . qq|</button>|;
  1837. if ( $form->{lynx} ) {
  1838. require "bin/menu.pl";
  1839. &menubar;
  1840. }
  1841. print qq|
  1842. </form>
  1843. </body>
  1844. </html>
  1845. |;
  1846. }
  1847. sub save_defaults {
  1848. if ( AM->save_defaults( \%myconfig, \%$form ) ) {
  1849. $form->redirect( $locale->text('Defaults saved!') );
  1850. }
  1851. else {
  1852. $form->error( $locale->text('Cannot save defaults!') );
  1853. }
  1854. }
  1855. sub save_taxes {
  1856. if ( AM->save_taxes( \%myconfig, \%$form ) ) {
  1857. $form->redirect( $locale->text('Taxes saved!') );
  1858. }
  1859. else {
  1860. $form->error( $locale->text('Cannot save taxes!') );
  1861. }
  1862. }
  1863. sub save_preferences {
  1864. $form->{stylesheet} = $form->{usestylesheet};
  1865. if ( $form->{new_password} ne $form->{old_password} ) {
  1866. $form->error( $locale->text('Password does not match!') )
  1867. if $form->{new_password} ne $form->{confirm_password};
  1868. }
  1869. if ( AM->save_preferences( \%myconfig, \%$form ) ) {
  1870. $form->info( $locale->text('Preferences saved!') );
  1871. }
  1872. else {
  1873. $form->error( $locale->text('Cannot save preferences!') );
  1874. }
  1875. }
  1876. sub backup {
  1877. if ( $form->{media} eq 'email' ) {
  1878. $form->error(
  1879. $locale->text( 'No email address for [_1]', $myconfig{name} ) )
  1880. unless ( $myconfig{email} );
  1881. }
  1882. $SIG{INT} = 'IGNORE';
  1883. AM->backup(
  1884. \%myconfig, \%$form,
  1885. ${LedgerSMB::Sysconfig::userspath},
  1886. ${LedgerSMB::Sysconfig::gzip}
  1887. );
  1888. if ( $form->{media} eq 'email' ) {
  1889. $form->redirect(
  1890. $locale->text( 'Backup sent to [_1]', $myconfig{email} ) );
  1891. }
  1892. }
  1893. sub audit_control {
  1894. $form->{title} = $locale->text('Audit Control');
  1895. AM->closedto( \%myconfig, \%$form );
  1896. if ( $form->{revtrans} ) {
  1897. $checked{revtransY} = "checked";
  1898. }
  1899. else {
  1900. $checked{revtransN} = "checked";
  1901. }
  1902. if ( $form->{audittrail} ) {
  1903. $checked{audittrailY} = "checked";
  1904. }
  1905. else {
  1906. $checked{audittrailN} = "checked";
  1907. }
  1908. $form->header;
  1909. print qq|
  1910. <body>
  1911. <form method=post action=$form->{script}>
  1912. <input type=hidden name=path value=$form->{path}>
  1913. <input type=hidden name=login value=$form->{login}>
  1914. <input type=hidden name=sessionid value=$form->{sessionid}>
  1915. <table width=100%>
  1916. <tr><th class=listtop>$form->{title}</th></tr>
  1917. <tr height="5"></tr>
  1918. <tr>
  1919. <td>
  1920. <table>
  1921. <tr>
  1922. <th align="right">|
  1923. . $locale->text('Enforce transaction reversal for all dates')
  1924. . qq|</th>
  1925. <td><input name=revtrans class=radio type=radio value="1" $checked{revtransY}> |
  1926. . $locale->text('Yes')
  1927. . qq| <input name=revtrans class=radio type=radio value="0" $checked{revtransN}> |
  1928. . $locale->text('No')
  1929. . qq|</td>
  1930. </tr>
  1931. <tr>
  1932. <th align="right">| . $locale->text('Close Books up to') . qq|</th>
  1933. <td><input class="date" name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
  1934. </tr>
  1935. <tr>
  1936. <th align="right">| . $locale->text('Activate Audit trail') . qq|</th>
  1937. <td><input name=audittrail class=radio type=radio value="1" $checked{audittrailY}> |
  1938. . $locale->text('Yes')
  1939. . qq| <input name=audittrail class=radio type=radio value="0" $checked{audittrailN}> |
  1940. . $locale->text('No')
  1941. . qq|</td>
  1942. </tr><!-- SC: Disabling audit trail deletion
  1943. <tr>
  1944. <th align="right">| . $locale->text('Remove Audit trail up to') . qq|</th>
  1945. <td><input class="date" name=removeaudittrail size=11 title="$myconfig{dateformat}"></td>
  1946. </tr> -->
  1947. </table>
  1948. </td>
  1949. </tr>
  1950. </table>
  1951. <hr size=3 noshade>
  1952. <br>
  1953. <input type=hidden name=nextsub value=doclose>
  1954. <input type=hidden name=action value=continue>
  1955. <button type="submit" class="submit" name="action" value="continue">|
  1956. . $locale->text('Continue')
  1957. . qq|</button>
  1958. </form>
  1959. </body>
  1960. </html>
  1961. |;
  1962. }
  1963. sub doclose {
  1964. AM->closebooks( \%myconfig, \%$form );
  1965. if ( $form->{revtrans} ) {
  1966. $msg = $locale->text('Transaction reversal enforced for all dates');
  1967. }
  1968. else {
  1969. if ( $form->{closedto} ) {
  1970. $msg =
  1971. $locale->text('Transaction reversal enforced up to') . " "
  1972. . $locale->date( \%myconfig, $form->{closedto}, 1 );
  1973. }
  1974. else {
  1975. $msg = $locale->text('Books are open');
  1976. }
  1977. }
  1978. $msg .= "<p>";
  1979. if ( $form->{audittrail} ) {
  1980. $msg .= $locale->text('Audit trail enabled');
  1981. }
  1982. else {
  1983. $msg .= $locale->text('Audit trail disabled');
  1984. }
  1985. ##SC: Disabling audit trail deletion
  1986. ## $msg .= "<p>";
  1987. ## if ( $form->{removeaudittrail} ) {
  1988. ## $msg .=
  1989. ## $locale->text('Audit trail removed up to') . " "
  1990. ## . $locale->date( \%myconfig, $form->{removeaudittrail}, 1 );
  1991. ## }
  1992. $form->redirect($msg);
  1993. }
  1994. sub add_warehouse {
  1995. $form->{title} = "Add";
  1996. $form->{callback} =
  1997. "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  1998. unless $form->{callback};
  1999. &warehouse_header;
  2000. &form_footer;
  2001. }
  2002. sub edit_warehouse {
  2003. $form->{title} = "Edit";
  2004. AM->get_warehouse( \%myconfig, \%$form );
  2005. &warehouse_header;
  2006. &form_footer;
  2007. }
  2008. sub list_warehouse {
  2009. AM->warehouses( \%myconfig, \%$form );
  2010. $href =
  2011. "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  2012. $form->sort_order();
  2013. $form->{callback} =
  2014. "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  2015. $callback = $form->escape( $form->{callback} );
  2016. $form->{title} = $locale->text('Warehouses');
  2017. @column_index = qw(description);
  2018. $column_header{description} =
  2019. qq|<th width=100%><a class="listheading" href=$href>|
  2020. . $locale->text('Description')
  2021. . qq|</a></th>|;
  2022. $form->header;
  2023. print qq|
  2024. <body>
  2025. <table width=100%>
  2026. <tr>
  2027. <th class=listtop>$form->{title}</th>
  2028. </tr>
  2029. <tr height="5"></tr>
  2030. <tr>
  2031. <td>
  2032. <table width=100%>
  2033. <tr class="listheading">
  2034. |;
  2035. for (@column_index) { print "$column_header{$_}\n" }
  2036. print qq|
  2037. </tr>
  2038. |;
  2039. foreach $ref ( @{ $form->{ALL} } ) {
  2040. $i++;
  2041. $i %= 2;
  2042. print qq|
  2043. <tr valign=top class=listrow$i>
  2044. |;
  2045. $column_data{description} =
  2046. qq|<td><a href=$form->{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
  2047. for (@column_index) { print "$column_data{$_}\n" }
  2048. print qq|
  2049. </tr>
  2050. |;
  2051. }
  2052. print qq|
  2053. </table>
  2054. </td>
  2055. </tr>
  2056. <tr>
  2057. <td><hr size=3 noshade></td>
  2058. </tr>
  2059. </table>
  2060. <br>
  2061. <form method=post action=$form->{script}>
  2062. |;
  2063. $form->{type} = "warehouse";
  2064. $form->hide_form(qw(type callback path login sessionid));
  2065. print qq|
  2066. <button class="submit" type="submit" name="action" value="add_warehouse">|
  2067. . $locale->text('Add Warehouse')
  2068. . qq|</button>|;
  2069. if ( $form->{lynx} ) {
  2070. require "bin/menu.pl";
  2071. &menubar;
  2072. }
  2073. print qq|
  2074. </form>
  2075. </body>
  2076. </html>
  2077. |;
  2078. }
  2079. sub warehouse_header {
  2080. $form->{title} = $locale->text("$form->{title} Warehouse");
  2081. # $locale->text('Add Warehouse')
  2082. # $locale->text('Edit Warehouse')
  2083. $form->{description} = $form->quote( $form->{description} );
  2084. if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) {
  2085. $description =
  2086. qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
  2087. }
  2088. else {
  2089. $description =
  2090. qq|<input name=description size=60 value="$form->{description}">|;
  2091. }
  2092. $form->header;
  2093. print qq|
  2094. <body>
  2095. <form method=post action=$form->{script}>
  2096. <input type=hidden name=id value=$form->{id}>
  2097. <input type=hidden name=type value=warehouse>
  2098. <table width=100%>
  2099. <tr>
  2100. <th class=listtop colspan=2>$form->{title}</th>
  2101. </tr>
  2102. <tr height="5"></tr>
  2103. <tr>
  2104. <th align="right">| . $locale->text('Description') . qq|</th>
  2105. <td>$description</td>
  2106. </tr>
  2107. <tr>
  2108. <td colspan=2><hr size=3 noshade></td>
  2109. </tr>
  2110. </table>
  2111. |;
  2112. }
  2113. sub save_warehouse {
  2114. $form->isblank( "description", $locale->text('Description missing!') );
  2115. AM->save_warehouse( \%myconfig, \%$form );
  2116. $form->redirect( $locale->text('Warehouse saved!') );
  2117. }
  2118. sub delete_warehouse {
  2119. AM->delete_warehouse( \%myconfig, \%$form );
  2120. $form->redirect( $locale->text('Warehouse deleted!') );
  2121. }
  2122. sub yearend {
  2123. AM->earningsaccounts( \%myconfig, \%$form );
  2124. $chart = "";
  2125. for ( @{ $form->{chart} } ) {
  2126. $chart .= "<option>$_->{accno}--$_->{description}";
  2127. }
  2128. $form->{title} = $locale->text('Yearend');
  2129. $form->header;
  2130. print qq|
  2131. <body>
  2132. <form method=post action=$form->{script}>
  2133. <input type=hidden name=decimalplaces value=2>
  2134. <input type=hidden name=l_accno value=Y>
  2135. <table width=100%>
  2136. <tr>
  2137. <th class=listtop>$form->{title}</th>
  2138. </tr>
  2139. <tr height="5"></tr>
  2140. <tr>
  2141. <td>
  2142. <table>
  2143. <tr>
  2144. <th align="right">| . $locale->text('Yearend') . qq|</th>
  2145. <td><input class="date" name=todate size=11 title="$myconfig{dateformat}" value=$todate></td>
  2146. </tr>
  2147. <tr>
  2148. <th align="right">| . $locale->text('Reference') . qq|</th>
  2149. <td><input name=reference size=20 value="|
  2150. . $locale->text('Yearend')
  2151. . qq|"></td>
  2152. </tr>
  2153. <tr>
  2154. <th align="right">| . $locale->text('Description') . qq|</th>
  2155. <td><textarea name=description rows=3 cols=50 wrap=soft></textarea></td>
  2156. </tr>
  2157. <tr>
  2158. <th align="right">| . $locale->text('Retained Earnings') . qq|</th>
  2159. <td><select name=accno>$chart</select></td>
  2160. </tr>
  2161. <tr>
  2162. <th align="right">| . $locale->text('Method') . qq|</th>
  2163. <td><input name=method class=radio type=radio value=accrual checked>&nbsp;|
  2164. . $locale->text('Accrual')
  2165. . qq|&nbsp;<input name=method class=radio type=radio value=cash>&nbsp;|
  2166. . $locale->text('Cash')
  2167. . qq|</td>
  2168. </tr>
  2169. </table>
  2170. </td>
  2171. </tr>
  2172. </table>
  2173. <hr size=3 noshade>
  2174. <input type=hidden name=nextsub value=generate_yearend>
  2175. |;
  2176. $form->hide_form(qw(path login sessionid));
  2177. print qq|
  2178. <button class="submit" type="submit" name="action" value="continue">|
  2179. . $locale->text('Continue')
  2180. . qq|</button>|;
  2181. }
  2182. sub generate_yearend {
  2183. $form->isblank( "todate", $locale->text('Yearend date missing!') );
  2184. RP->yearend_statement( \%myconfig, \%$form );
  2185. $form->{transdate} = $form->{todate};
  2186. $earnings = 0;
  2187. $form->{rowcount} = 1;
  2188. foreach $key ( keys %{ $form->{I} } ) {
  2189. if ( $form->{I}{$key}{charttype} eq "A" ) {
  2190. $form->{"debit_$form->{rowcount}"} = $form->{I}{$key}{this};
  2191. $earnings += $form->{I}{$key}{this};
  2192. $form->{"accno_$form->{rowcount}"} = $key;
  2193. $form->{rowcount}++;
  2194. $ok = 1;
  2195. }
  2196. }
  2197. foreach $key ( keys %{ $form->{E} } ) {
  2198. if ( $form->{E}{$key}{charttype} eq "A" ) {
  2199. $form->{"credit_$form->{rowcount}"} = $form->{E}{$key}{this} * -1;
  2200. $earnings += $form->{E}{$key}{this};
  2201. $form->{"accno_$form->{rowcount}"} = $key;
  2202. $form->{rowcount}++;
  2203. $ok = 1;
  2204. }
  2205. }
  2206. if ( $earnings > 0 ) {
  2207. $form->{"credit_$form->{rowcount}"} = $earnings;
  2208. $form->{"accno_$form->{rowcount}"} = $form->{accno};
  2209. }
  2210. else {
  2211. $form->{"debit_$form->{rowcount}"} = $earnings * -1;
  2212. $form->{"accno_$form->{rowcount}"} = $form->{accno};
  2213. }
  2214. if ($ok) {
  2215. if ( AM->post_yearend( \%myconfig, \%$form ) ) {
  2216. $form->redirect( $locale->text('Yearend posted!') );
  2217. }
  2218. else {
  2219. $form->error( $locale->text('Yearend posting failed!') );
  2220. }
  2221. }
  2222. else {
  2223. $form->error('Nothing to do!');
  2224. }
  2225. }
  2226. sub company_logo {
  2227. $myconfig{address} =~ s/\\n/<br>/g;
  2228. $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
  2229. $form->{stylesheet} = $myconfig{stylesheet};
  2230. $form->{title} = $locale->text('About');
  2231. # create the logo screen
  2232. $form->header;
  2233. print qq|
  2234. <body>
  2235. <pre>
  2236. </pre>
  2237. <center>
  2238. <a href="http://www.ledgersmb.org/" target="_blank"><img src="images/ledgersmb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
  2239. <h1 class="login">| . $locale->text('Version') . qq| $form->{version}</h1>
  2240. <p>
  2241. |.$locale->text('Company').qq| :
  2242. <p>
  2243. <b>
  2244. $myconfig{company}
  2245. <br>$myconfig{address}
  2246. </b>
  2247. <p>
  2248. <table border=0>
  2249. <tr>
  2250. <th align="right">| . $locale->text('User') . qq|</th>
  2251. <td>$myconfig{name}</td>
  2252. </tr>
  2253. <tr>
  2254. <th align="right">| . $locale->text('Dataset') . qq|</th>
  2255. <td>$myconfig{dbname}</td>
  2256. </tr>
  2257. <tr>
  2258. <th align="right">| . $locale->text('Database Host') . qq|</th>
  2259. <td>$myconfig{dbhost}</td>
  2260. </tr>
  2261. </table>
  2262. </center>
  2263. </body>
  2264. </html>
  2265. |;
  2266. }
  2267. sub recurring_transactions {
  2268. # $locale->text('Day')
  2269. # $locale->text('Days')
  2270. # $locale->text('Month')
  2271. # $locale->text('Months')
  2272. # $locale->text('Week')
  2273. # $locale->text('Weeks')
  2274. # $locale->text('Year')
  2275. # $locale->text('Years')
  2276. $form->{stylesheet} = $myconfig{stylesheet};
  2277. $form->{title} = $locale->text('Recurring Transactions');
  2278. $column_header{id} = "";
  2279. AM->recurring_transactions( \%myconfig, \%$form );
  2280. $href = "$form->{script}?action=recurring_transactions";
  2281. for (qw(direction oldsort path login sessionid)) {
  2282. $href .= qq|&$_=$form->{$_}|;
  2283. }
  2284. $form->sort_order();
  2285. # create the logo screen
  2286. $form->header;
  2287. @column_index = qw(ndx reference description);
  2288. push @column_index,
  2289. qw(nextdate enddate id amount curr repeat howmany recurringemail recurringprint);
  2290. $column_header{reference} =
  2291. qq|<th><a class="listheading" href="$href&sort=reference">|
  2292. . $locale->text('Reference')
  2293. . q|</a></th>|;
  2294. $column_header{ndx} = q|<th class="listheading">&nbsp;</th>|;
  2295. $column_header{id} =
  2296. q|<th class="listheading">| . $locale->text('ID') . q|</th>|;
  2297. $column_header{description} =
  2298. q|<th class="listheading">| . $locale->text('Description') . q|</th>|;
  2299. $column_header{nextdate} =
  2300. qq|<th><a class="listheading" href="$href&sort=nextdate">|
  2301. . $locale->text('Next')
  2302. . q|</a></th>|;
  2303. $column_header{enddate} =
  2304. qq|<th><a class="listheading" href="$href&sort=enddate">|
  2305. . $locale->text('Ends')
  2306. . q|</a></th>|;
  2307. $column_header{amount} =
  2308. q|<th class="listheading">| . $locale->text('Amount') . q|</th>|;
  2309. $column_header{curr} = q|<th class="listheading">&nbsp;</th>|;
  2310. $column_header{repeat} =
  2311. q|<th class="listheading">| . $locale->text('Every') . q|</th>|;
  2312. $column_header{howmany} =
  2313. q|<th class="listheading">| . $locale->text('Times') . q|</th>|;
  2314. $column_header{recurringemail} =
  2315. q|<th class="listheading">| . $locale->text('E-mail') . q|</th>|;
  2316. $column_header{recurringprint} =
  2317. q|<th class="listheading">| . $locale->text('Print') . q|</th>|;
  2318. print qq|
  2319. <body>
  2320. <form method=post action=$form->{script}>
  2321. <table width=100%>
  2322. <tr>
  2323. <th class=listtop>$form->{title}</th>
  2324. </tr>
  2325. <tr height="5"></tr>
  2326. <tr>
  2327. <td>
  2328. <table width=100%>
  2329. <tr class="listheading">
  2330. |;
  2331. for (@column_index) { print "\n$column_header{$_}" }
  2332. print qq|
  2333. </tr>
  2334. |;
  2335. $i = 1;
  2336. $colspan = $#column_index + 1;
  2337. %tr = (
  2338. ar => $locale->text('AR'),
  2339. ap => $locale->text('AP'),
  2340. gl => $locale->text('GL'),
  2341. so => $locale->text('Sales Orders'),
  2342. po => $locale->text('Purchase Orders'),
  2343. );
  2344. %f = &formnames;
  2345. foreach $transaction ( sort keys %{ $form->{transactions} } ) {
  2346. my $transaction_count = scalar( @{ $form->{transactions}{$transaction} } );
  2347. print qq|
  2348. <tr>
  2349. <th class="listheading" colspan=$colspan>$tr{$transaction} ($transaction_count)</th>
  2350. </tr>
  2351. |;
  2352. foreach $ref ( @{ $form->{transactions}{$transaction} } ) {
  2353. for (@column_index) {
  2354. $column_data{$_} = "<td nowrap>$ref->{$_}</td>";
  2355. }
  2356. if ( $ref->{repeat} > 1 ) {
  2357. $unit = $locale->text( ucfirst $ref->{unit} );
  2358. $repeat = "$ref->{repeat} $unit";
  2359. }
  2360. else {
  2361. chop $ref->{unit};
  2362. $unit = $locale->text( ucfirst $ref->{unit} );
  2363. $repeat = $unit;
  2364. }
  2365. $column_data{ndx} = qq|<td></td>|;
  2366. if ( !$ref->{expired} ) {
  2367. if ( $ref->{overdue} <= 0 ) {
  2368. $k++;
  2369. $column_data{ndx} =
  2370. qq|<td nowrap><input name="ndx_$k" class=checkbox type=checkbox value=$ref->{id} checked></td>|;
  2371. }
  2372. }
  2373. $reference =
  2374. ( $ref->{reference} )
  2375. ? $ref->{reference}
  2376. : $locale->text('Next Number');
  2377. $column_data{reference} =
  2378. qq|<td nowrap><a href=$form->{script}?action=edit_recurring&id=$ref->{id}&vc=$ref->{vc}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&module=$ref->{module}&invoice=$ref->{invoice}&transaction=$ref->{transaction}&recurringnextdate=$ref->{nextdate}>$reference</a></td>|;
  2379. $module = "$ref->{module}.pl";
  2380. $type = "";
  2381. if ( $ref->{module} eq 'ar' ) {
  2382. $module = "is.pl" if $ref->{invoice};
  2383. $ref->{amount} /= $ref->{exchangerate};
  2384. }
  2385. if ( $ref->{module} eq 'ap' ) {
  2386. $module = "ir.pl" if $ref->{invoice};
  2387. $ref->{amount} /= $ref->{exchangerate};
  2388. }
  2389. if ( $ref->{module} eq 'oe' ) {
  2390. $type =
  2391. ( $ref->{vc} eq 'customer' )
  2392. ? "sales_order"
  2393. : "purchase_order";
  2394. }
  2395. $column_data{id} =
  2396. qq|<td><a href="$module?action=edit&id=$ref->{id}&vc=$ref->{vc}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$type&readonly=1">$ref->{id}</a></td>|;
  2397. $column_data{repeat} = qq|<td align="right" nowrap>$repeat</td>|;
  2398. $column_data{howmany} =
  2399. qq|<td align="right" nowrap>|
  2400. . $form->format_amount( \%myconfig, $ref->{howmany} ) . "</td>";
  2401. $column_data{amount} =
  2402. qq|<td align="right" nowrap>|
  2403. . $form->format_amount( \%myconfig, $ref->{amount}, 2 ) . "</td>";
  2404. $column_data{recurringemail} = "<td nowrap>";
  2405. @f = split /:/, $ref->{recurringemail};
  2406. for ( 0 .. $#f ) {
  2407. $column_data{recurringemail} .= "$f{$f[$_]}<br>";
  2408. }
  2409. $column_data{recurringemail} .= "</td>";
  2410. $column_data{recurringprint} = "<td nowrap>";
  2411. @f = split /:/, $ref->{recurringprint};
  2412. for ( 0 .. $#f ) {
  2413. $column_data{recurringprint} .= "$f{$f[$_]}<br>";
  2414. }
  2415. $column_data{recurringprint} .= "</td>";
  2416. $j++;
  2417. $j %= 2;
  2418. print qq|
  2419. <tr class=listrow$j>
  2420. |;
  2421. for (@column_index) { print "\n$column_data{$_}" }
  2422. print qq|
  2423. </tr>
  2424. |;
  2425. }
  2426. }
  2427. print qq|
  2428. </tr>
  2429. </table>
  2430. </td>
  2431. </tr>
  2432. <tr>
  2433. <td><hr size=3 noshade></td>
  2434. </tr>
  2435. </table>
  2436. <input name=lastndx type=hidden value=$k>
  2437. |;
  2438. $form->hide_form(qw(path login sessionid));
  2439. print qq|
  2440. <button class="submit" type="submit" name="action" value="process_transactions">|
  2441. . $locale->text('Process Transactions')
  2442. . qq|</button>|
  2443. if $k;
  2444. if ( $form->{lynx} ) {
  2445. require "bin/menu.pl";
  2446. &menubar;
  2447. }
  2448. print qq|
  2449. </form>
  2450. </body>
  2451. </html>
  2452. |;
  2453. }
  2454. sub edit_recurring {
  2455. %links = (
  2456. ar => 'create_links',
  2457. ap => 'create_links',
  2458. gl => 'create_links',
  2459. is => 'invoice_links',
  2460. ir => 'invoice_links',
  2461. oe => 'order_links',
  2462. );
  2463. %prepare = (
  2464. is => 'prepare_invoice',
  2465. ir => 'prepare_invoice',
  2466. oe => 'prepare_order',
  2467. );
  2468. $form->{callback} =
  2469. "$form->{script}?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  2470. $form->{type} = "transaction";
  2471. if ( $form->{module} eq 'ar' ) {
  2472. if ( $form->{invoice} ) {
  2473. $form->{type} = "invoice";
  2474. $form->{module} = "is";
  2475. }
  2476. }
  2477. if ( $form->{module} eq 'ap' ) {
  2478. if ( $form->{invoice} ) {
  2479. $form->{type} = "invoice";
  2480. $form->{module} = "ir";
  2481. }
  2482. }
  2483. if ( $form->{module} eq 'oe' ) {
  2484. %tr = (
  2485. so => sales_order,
  2486. po => purchase_order,
  2487. );
  2488. $form->{type} = $tr{ $form->{transaction} };
  2489. }
  2490. $form->{script} = "$form->{module}.pl";
  2491. do "bin/$form->{script}";
  2492. &{ $links{ $form->{module} } };
  2493. # return if transaction doesn't exist
  2494. $form->redirect unless $form->{recurring};
  2495. if ( $prepare{ $form->{module} } ) {
  2496. &{ $prepare{ $form->{module} } };
  2497. }
  2498. $form->{selectformat} = qq|<option value="html">html\n|;
  2499. if ( ${LedgerSMB::Sysconfig::latex} ) {
  2500. $form->{selectformat} .= qq|
  2501. <option value="postscript">| . $locale->text('Postscript') . qq|
  2502. <option value="pdf">| . $locale->text('PDF');
  2503. }
  2504. &schedule;
  2505. }
  2506. sub process_transactions {
  2507. # save variables
  2508. my $pt = new Form;
  2509. for ( keys %$form ) { $pt->{$_} = $form->{$_} }
  2510. my $defaultprinter;
  2511. while ( my ( $key, $value ) = each %{LedgerSMB::Sysconfig::printer} ) {
  2512. if ( $value =~ /lpr/ ) {
  2513. $defaultprinter = $key;
  2514. last;
  2515. }
  2516. }
  2517. $myconfig{vclimit} = 0;
  2518. %f = &formnames;
  2519. for ( my $i = 1 ; $i <= $pt->{lastndx} ; $i++ ) {
  2520. if ( $pt->{"ndx_$i"} ) {
  2521. $id = $pt->{"ndx_$i"};
  2522. # process transaction
  2523. AM->recurring_details( \%myconfig, \%$pt, $id );
  2524. $header = $form->{header};
  2525. # reset $form
  2526. for ( keys %$form ) { delete $form->{$_}; }
  2527. for (qw(login path sessionid stylesheet timeout)) {
  2528. $form->{$_} = $pt->{$_};
  2529. }
  2530. $form->{id} = $id;
  2531. $form->{header} = $header;
  2532. $form->db_init(\%myconfig);
  2533. # post, print, email
  2534. if ( $pt->{arid} || $pt->{apid} || $pt->{oeid} ) {
  2535. if ( $pt->{arid} || $pt->{apid} ) {
  2536. if ( $pt->{arid} ) {
  2537. $form->{script} =
  2538. ( $pt->{invoice} ) ? "is.pl" : "ar.pl";
  2539. $form->{ARAP} = "AR";
  2540. $form->{module} = "ar";
  2541. $invfld = "sinumber";
  2542. }
  2543. else {
  2544. $form->{script} =
  2545. ( $pt->{invoice} ) ? "ir.pl" : "ap.pl";
  2546. $form->{ARAP} = "AP";
  2547. $form->{module} = "ap";
  2548. $invfld = "vinumber";
  2549. }
  2550. do "bin/$form->{script}";
  2551. if ( $pt->{invoice} ) {
  2552. &invoice_links;
  2553. &prepare_invoice;
  2554. for ( keys %$form ) {
  2555. $form->{$_} = $form->unquote( $form->{$_} );
  2556. }
  2557. }
  2558. else {
  2559. &create_links;
  2560. $form->{type} = "transaction";
  2561. for ( 1 .. $form->{rowcount} - 1 ) {
  2562. $form->{"amount_$_"} =
  2563. $form->format_amount( \%myconfig,
  2564. $form->{"amount_$_"}, 2 );
  2565. }
  2566. for ( 1 .. $form->{paidaccounts} ) {
  2567. $form->{"paid_$_"} =
  2568. $form->format_amount( \%myconfig,
  2569. $form->{"paid_$_"}, 2 );
  2570. }
  2571. }
  2572. delete $form->{"$form->{ARAP}_links"};
  2573. for (qw(acc_trans invoice_details)) { delete $form->{$_} }
  2574. for (
  2575. qw(department employee language month partsgroup project years)
  2576. )
  2577. {
  2578. delete $form->{"all_$_"};
  2579. }
  2580. $form->{invnumber} = $pt->{reference};
  2581. $form->{transdate} = $pt->{nextdate};
  2582. # tax accounts
  2583. $form->all_taxaccounts( \%myconfig, undef,
  2584. $form->{transdate} );
  2585. # calculate duedate
  2586. $form->{duedate} =
  2587. $form->add_date( \%myconfig, $form->{transdate},
  2588. $pt->{overdue}, "days" );
  2589. if ( $pt->{payment} ) {
  2590. # calculate date paid
  2591. for ( $j = 1 ; $j <= $form->{paidaccounts} ; $j++ ) {
  2592. $form->{"datepaid_$j"} =
  2593. $form->add_date( \%myconfig, $form->{transdate},
  2594. $pt->{paid}, "days" );
  2595. ( $form->{"$form->{ARAP}_paid_$j"} ) = split /--/,
  2596. $form->{"$form->{ARAP}_paid_$j"};
  2597. delete $form->{"cleared_$j"};
  2598. }
  2599. $form->{paidaccounts}++;
  2600. }
  2601. else {
  2602. $form->{paidaccounts} = -1;
  2603. }
  2604. for (qw(id recurring intnotes printed emailed queued)) {
  2605. delete $form->{$_};
  2606. }
  2607. ( $form->{ $form->{ARAP} } ) = split /--/,
  2608. $form->{ $form->{ARAP} };
  2609. $form->{invnumber} =
  2610. $form->update_defaults( \%myconfig, "$invfld" )
  2611. unless $form->{invnumber};
  2612. $form->{reference} = $form->{invnumber};
  2613. for (qw(invnumber reference)) {
  2614. $form->{$_} = $form->unquote( $form->{$_} );
  2615. }
  2616. if ( $pt->{invoice} ) {
  2617. if ( $pt->{arid} ) {
  2618. $form->info(
  2619. "\n"
  2620. . $locale->text(
  2621. 'Posting Sales Invoice [_1]',
  2622. $form->{invnumber}
  2623. )
  2624. );
  2625. $ok = IS->post_invoice( \%myconfig, \%$form );
  2626. }
  2627. else {
  2628. $form->info(
  2629. "\n"
  2630. . $locale->text(
  2631. 'Posting Vendor Invoice [_1]',
  2632. $form->{invnumber}
  2633. )
  2634. );
  2635. $ok = IR->post_invoice( \%myconfig, \%$form );
  2636. }
  2637. }
  2638. else {
  2639. if ( $pt->{arid} ) {
  2640. $form->info(
  2641. "\n"
  2642. . $locale->text(
  2643. 'Posting Transaction [_1]',
  2644. $form->{invnumber}
  2645. )
  2646. );
  2647. }
  2648. else {
  2649. $form->info(
  2650. "\n"
  2651. . $locale->text(
  2652. 'Posting Transaction [_1]',
  2653. $form->{invnumber}
  2654. )
  2655. );
  2656. }
  2657. $ok = AA->post_transaction( \%myconfig, \%$form );
  2658. }
  2659. $form->info( " ..... " . $locale->text('done') );
  2660. # print form
  2661. if ( ${LedgerSMB::Sysconfig::latex} && $ok ) {
  2662. $ok = &print_recurring( \%$pt, $defaultprinter );
  2663. }
  2664. &email_recurring( \%$pt ) if $ok;
  2665. }
  2666. else {
  2667. # order
  2668. $form->{script} = "oe.pl";
  2669. $form->{module} = "oe";
  2670. $ordnumber = "ordnumber";
  2671. if ( $pt->{customer_id} ) {
  2672. $form->{vc} = "customer";
  2673. $form->{type} = "sales_order";
  2674. $ordfld = "sonumber";
  2675. $flabel = $locale->text('Sales Order');
  2676. }
  2677. else {
  2678. $form->{vc} = "vendor";
  2679. $form->{type} = "purchase_order";
  2680. $ordfld = "ponumber";
  2681. $flabel = $locale->text('Purchase Order');
  2682. }
  2683. require "bin/$form->{script}";
  2684. &order_links;
  2685. &prepare_order;
  2686. for ( keys %$form ) {
  2687. $form->{$_} = $form->unquote( $form->{$_} );
  2688. }
  2689. $form->{$ordnumber} = $pt->{reference};
  2690. $form->{transdate} = $pt->{nextdate};
  2691. # calculate reqdate
  2692. $form->{reqdate} =
  2693. $form->add_date( \%myconfig, $form->{transdate},
  2694. $pt->{req}, "days" )
  2695. if $form->{reqdate};
  2696. for (qw(id recurring intnotes printed emailed queued)) {
  2697. delete $form->{$_};
  2698. }
  2699. for ( 1 .. $form->{rowcount} ) {
  2700. delete $form->{"orderitems_id_$_"};
  2701. }
  2702. $form->{$ordnumber} =
  2703. $form->update_defaults( \%myconfig, "$ordfld" )
  2704. unless $form->{$ordnumber};
  2705. $form->{reference} = $form->{$ordnumber};
  2706. for ( "$ordnumber", "reference" ) {
  2707. $form->{$_} = $form->unquote( $form->{$_} );
  2708. }
  2709. $form->{closed} = 0;
  2710. $form->info(
  2711. "\n"
  2712. . $locale->text(
  2713. 'Saving [_1] [_2]',
  2714. $flabel, $form->{$ordnumber}
  2715. )
  2716. );
  2717. if ( $ok = OE->save( \%myconfig, \%$form ) ) {
  2718. $form->info( " ..... " . $locale->text('done') );
  2719. }
  2720. else {
  2721. $form->info( " ..... " . $locale->text('failed') );
  2722. }
  2723. # print form
  2724. if ( ${LedgerSMB::Sysconfig::latex} && $ok ) {
  2725. &print_recurring( \%$pt, $defaultprinter );
  2726. }
  2727. &email_recurring( \%$pt );
  2728. }
  2729. }
  2730. else {
  2731. # GL transaction
  2732. GL->transaction( \%myconfig, \%$form );
  2733. $form->{reference} = $pt->{reference};
  2734. $form->{transdate} = $pt->{nextdate};
  2735. $j = 1;
  2736. foreach $ref ( @{ $form->{GL} } ) {
  2737. $form->{"accno_$j"} = "$ref->{accno}--$ref->{description}";
  2738. $form->{"projectnumber_$j"} =
  2739. "$ref->{projectnumber}--$ref->{project_id}"
  2740. if $ref->{project_id};
  2741. $form->{"fx_transaction_$j"} = $ref->{fx_transaction};
  2742. if ( $ref->{amount} < 0 ) {
  2743. $form->{"debit_$j"} = $ref->{amount} * -1;
  2744. }
  2745. else {
  2746. $form->{"credit_$j"} = $ref->{amount};
  2747. }
  2748. $j++;
  2749. }
  2750. $form->{rowcount} = $j;
  2751. for (qw(id recurring)) { delete $form->{$_} }
  2752. $form->info(
  2753. "\n"
  2754. . $locale->text(
  2755. 'Posting GL Transaction [_1]',
  2756. $form->{reference}
  2757. )
  2758. );
  2759. $ok = GL->post_transaction( \%myconfig, \%$form );
  2760. $form->info( " ..... " . $locale->text('done') );
  2761. }
  2762. AM->update_recurring( \%myconfig, \%$pt, $id ) if $ok;
  2763. }
  2764. }
  2765. $form->{callback} =
  2766. "am.pl?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&header=$form->{header}";
  2767. $form->redirect;
  2768. }
  2769. sub print_recurring {
  2770. my ( $pt, $defaultprinter ) = @_;
  2771. use List::Util qw(first);
  2772. my %f = &formnames;
  2773. my $ok = 1;
  2774. if ( $pt->{recurringprint} ) {
  2775. @f = split /:/, $pt->{recurringprint};
  2776. for ( $j = 0 ; $j <= $#f ; $j += 3 ) {
  2777. $media = $f[ $j + 2 ];
  2778. $media ||= $myconfig->{printer}
  2779. if ${LedgerSMB::Sysconfig::printer}{ $myconfig->{printer} };
  2780. $media ||= $defaultprinter;
  2781. $form->info( "\n"
  2782. . $locale->text('Printing') . " "
  2783. . $locale->text( $f{ $f[$j] } )
  2784. . " $form->{reference}" );
  2785. @a = (
  2786. "perl", "$form->{script}",
  2787. "action=reprint&module=$form->{module}&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&id=$form->{id}&formname=$f[$j]&format=$f[$j+1]&media=$media&vc=$form->{vc}&ARAP=$form->{ARAP}"
  2788. );
  2789. $form->error( $locale->text('Invalid redirect') )
  2790. unless first { $_ eq $form->{script} }
  2791. @{LedgerSMB::Sysconfig::scripts};
  2792. $ok = !( system(@a) );
  2793. if ($ok) {
  2794. $form->info( " ..... " . $locale->text('done') );
  2795. }
  2796. else {
  2797. $form->info( " ..... " . $locale->text('failed') );
  2798. last;
  2799. }
  2800. }
  2801. }
  2802. $ok;
  2803. }
  2804. sub email_recurring {
  2805. my ($pt) = @_;
  2806. use List::Util qw(first);
  2807. my %f = &formnames;
  2808. my $ok = 1;
  2809. if ( $pt->{recurringemail} ) {
  2810. @f = split /:/, $pt->{recurringemail};
  2811. for ( $j = 0 ; $j <= $#f ; $j += 2 ) {
  2812. $form->info( "\n"
  2813. . $locale->text('Sending') . " "
  2814. . $locale->text( $f{ $f[$j] } )
  2815. . " $form->{reference}" );
  2816. # no email, bail out
  2817. if ( !$form->{email} ) {
  2818. $form->info(
  2819. " ..... " . $locale->text('E-mail address missing!') );
  2820. last;
  2821. }
  2822. $message = $form->escape( $pt->{message}, 1 );
  2823. @a = (
  2824. "perl", "$form->{script}",
  2825. "action=reprint&module=$form->{module}&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&id=$form->{id}&formname=$f[$j]&format=$f[$j+1]&media=email&vc=$form->{vc}&ARAP=$form->{ARAP}&message=$message"
  2826. );
  2827. $form->error( $locale->text('Invalid redirect') )
  2828. unless first { $_ eq $form->{script} }
  2829. @{LedgerSMB::Sysconfig::scripts};
  2830. $ok = !( system(@a) );
  2831. if ($ok) {
  2832. $form->info( " ..... " . $locale->text('done') );
  2833. }
  2834. else {
  2835. $form->info( " ..... " . $locale->text('failed') );
  2836. last;
  2837. }
  2838. }
  2839. }
  2840. $ok;
  2841. }
  2842. sub formnames {
  2843. # $locale->text('Transaction')
  2844. # $locale->text('Invoice')
  2845. # $locale->text('Credit Invoice')
  2846. # $locale->text('Debit Invoice')
  2847. # $locale->text('Packing List')
  2848. # $locale->text('Pick List')
  2849. # $locale->text('Sales Order')
  2850. # $locale->text('Work Order')
  2851. # $locale->text('Purchase Order')
  2852. # $locale->text('Bin List')
  2853. my %f = (
  2854. transaction => 'Transaction',
  2855. invoice => 'Invoice',
  2856. credit_invoice => 'Credit Invoice',
  2857. debit_invoice => 'Debit Invoice',
  2858. packing_list => 'Packing List',
  2859. pick_list => 'Pick List',
  2860. sales_order => 'Sales Order',
  2861. work_order => 'Work Order',
  2862. purchase_order => 'Purchase Order',
  2863. bin_list => 'Bin List',
  2864. );
  2865. %f;
  2866. }
  2867. sub continue { &{ $form->{nextsub} } }