summaryrefslogtreecommitdiff
path: root/bin/am.pl
blob: 120207a065bfff422367c1232e8f14e3164e2eaa (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. my $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. my $callback = $form->escape( $form->{callback} );
  584. $form->{title} = $locale->text('Departments');
  585. my @column_index = qw(description cost profit);
  586. my %column_header;
  587. $column_header{description} = { text => $locale->text('Description'),
  588. href => $href};
  589. $column_header{cost} = $locale->text('Cost Center');
  590. $column_header{profit} = $locale->text('Profit Center');
  591. my @rows;
  592. my $i = 0;
  593. foreach my $ref ( @{ $form->{ALL} } ) {
  594. my %column_data;
  595. $i++;
  596. $i %= 2;
  597. $column_data{i} = $i;
  598. $column_data{cost} = ( $ref->{role} eq "C" ) ? "*" : " ";
  599. $column_data{profit} = ( $ref->{role} eq "P" ) ? "*" : " ";
  600. $column_data{description} = { text => $ref->{description},
  601. href => qq|$form->{script}?action=edit_department&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback|,};
  602. push @rows, \%column_data;
  603. }
  604. $form->{type} = "department";
  605. my @hiddens = qw(type callback path login sessionid);
  606. ## SC: removing this for now
  607. #if ( $form->{lynx} ) {
  608. # require "bin/menu.pl";
  609. # &menubar;
  610. #}
  611. my @buttons;
  612. push @buttons, {
  613. name => 'action',
  614. value => 'add_department',
  615. text => $locale->text('Add Department'),
  616. type => 'submit',
  617. class => 'submit',
  618. };
  619. my $template = LedgerSMB::Template->new_UI(
  620. user => \%myconfig,
  621. locale => $locale,
  622. template => 'am-list-departments');
  623. $template->render({
  624. form => $form,
  625. buttons => \@buttons,
  626. columns => \@column_index,
  627. heading => \%column_header,
  628. rows => \@rows,
  629. hiddens => \@hiddens,
  630. });
  631. }
  632. sub department_header {
  633. $form->{title} = $locale->text("$form->{title} Department");
  634. # $locale->text('Add Department')
  635. # $locale->text('Edit Department')
  636. $form->{description} = $form->quote( $form->{description} );
  637. if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) {
  638. $description =
  639. qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
  640. }
  641. else {
  642. $description =
  643. qq|<input name=description size=60 value="$form->{description}">|;
  644. }
  645. $costcenter = "checked" if $form->{role} eq "C";
  646. $profitcenter = "checked" if $form->{role} eq "P";
  647. $form->header;
  648. print qq|
  649. <body>
  650. <form method=post action=$form->{script}>
  651. <input type=hidden name=id value=$form->{id}>
  652. <input type=hidden name=type value=department>
  653. <table width=100%>
  654. <tr>
  655. <th class=listtop colspan=2>$form->{title}</th>
  656. </tr>
  657. <tr height="5"></tr>
  658. <tr>
  659. <th align="right">| . $locale->text('Description') . qq|</th>
  660. <td>$description</td>
  661. </tr>
  662. <tr>
  663. <td></td>
  664. <td><input type=radio style=radio name=role value="C" $costcenter> |
  665. . $locale->text('Cost Center') . qq|
  666. <input type=radio style=radio name=role value="P" $profitcenter> |
  667. . $locale->text('Profit Center') . qq|
  668. </td>
  669. <tr>
  670. <td colspan=2><hr size=3 noshade></td>
  671. </tr>
  672. </table>
  673. |;
  674. }
  675. sub save_department {
  676. $form->isblank( "description", $locale->text('Description missing!') );
  677. AM->save_department( \%myconfig, \%$form );
  678. $form->redirect( $locale->text('Department saved!') );
  679. }
  680. sub delete_department {
  681. AM->delete_department( \%myconfig, \%$form );
  682. $form->redirect( $locale->text('Department deleted!') );
  683. }
  684. sub add_business {
  685. $form->{title} = "Add";
  686. $form->{callback} =
  687. "$form->{script}?action=add_business&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  688. unless $form->{callback};
  689. &business_header;
  690. &form_footer;
  691. }
  692. sub edit_business {
  693. $form->{title} = "Edit";
  694. AM->get_business( \%myconfig, \%$form );
  695. &business_header;
  696. $form->{orphaned} = 1;
  697. &form_footer;
  698. }
  699. sub list_business {
  700. AM->business( \%myconfig, \%$form );
  701. my $href =
  702. "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  703. $form->sort_order();
  704. $form->{callback} =
  705. "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  706. my $callback = $form->escape( $form->{callback} );
  707. $form->{title} = $locale->text('Type of Business');
  708. my @column_index = qw(description discount);
  709. my %column_header;
  710. $column_header{description} = { text => $locale->text('Description'),
  711. href => $href };
  712. $column_header{discount} = $locale->text('Discount %');
  713. my @rows;
  714. $i = 0;
  715. foreach my $ref ( @{ $form->{ALL} } ) {
  716. my %column_data;
  717. $i++;
  718. $i %= 2;
  719. $column_data{i} = $i;
  720. $column_data{discount} =
  721. $form->format_amount( \%myconfig, $ref->{discount} * 100, 2, " " );
  722. $column_data{description} = { text => $ref->{description}, href =>
  723. qq|$form->{script}?action=edit_business&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback|};
  724. push @rows, \%column_data;
  725. }
  726. $form->{type} = "business";
  727. my @hiddens = qw(type callback path login sessionid);
  728. ## SC: Temporary removal
  729. ## if ( $form->{lynx} ) {
  730. ## require "bin/menu.pl";
  731. ## &menubar;
  732. ## }
  733. my @buttons;
  734. push @buttons, {
  735. name => 'action',
  736. value => 'add_business',
  737. text => $locale->text('Add Business'),
  738. type => 'submit',
  739. class => 'submit',
  740. };
  741. my $template = LedgerSMB::Template->new_UI(
  742. user => \%myconfig,
  743. locale => $locale,
  744. template => 'am-list-departments');
  745. $template->render({
  746. form => $form,
  747. buttons => \@buttons,
  748. columns => \@column_index,
  749. heading => \%column_header,
  750. rows => \@rows,
  751. hiddens => \@hiddens,
  752. });
  753. }
  754. sub business_header {
  755. $form->{title} = $locale->text("$form->{title} Business");
  756. # $locale->text('Add Business')
  757. # $locale->text('Edit Business')
  758. $form->{description} = $form->quote( $form->{description} );
  759. $form->{discount} =
  760. $form->format_amount( \%myconfig, $form->{discount} * 100 );
  761. $form->header;
  762. print qq|
  763. <body>
  764. <form method=post action=$form->{script}>
  765. <input type=hidden name=id value=$form->{id}>
  766. <input type=hidden name=type value=business>
  767. <table width=100%>
  768. <tr>
  769. <th class=listtop>$form->{title}</th>
  770. </tr>
  771. <tr height="5"></tr>
  772. <tr>
  773. <td>
  774. <table>
  775. <tr>
  776. <th align="right">| . $locale->text('Type of Business') . qq|</th>
  777. <td><input name=description size=30 value="$form->{description}"></td>
  778. <tr>
  779. <tr>
  780. <th align="right">| . $locale->text('Discount') . qq| %</th>
  781. <td><input name=discount size=5 value=$form->{discount}></td>
  782. </tr>
  783. </table>
  784. </td>
  785. </tr>
  786. <tr>
  787. <td><hr size=3 noshade></td>
  788. </tr>
  789. </table>
  790. |;
  791. }
  792. sub save_business {
  793. $form->isblank( "description", $locale->text('Description missing!') );
  794. AM->save_business( \%myconfig, \%$form );
  795. $form->redirect( $locale->text('Business saved!') );
  796. }
  797. sub delete_business {
  798. AM->delete_business( \%myconfig, \%$form );
  799. $form->redirect( $locale->text('Business deleted!') );
  800. }
  801. sub add_sic {
  802. $form->{title} = "Add";
  803. $form->{callback} =
  804. "$form->{script}?action=add_sic&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  805. unless $form->{callback};
  806. &sic_header;
  807. &form_footer;
  808. }
  809. sub edit_sic {
  810. $form->{title} = "Edit";
  811. $form->{code} =~ s/\\'/'/g;
  812. $form->{code} =~ s/\\\\/\\/g;
  813. AM->get_sic( \%myconfig, \%$form );
  814. $form->{id} = $form->{code};
  815. &sic_header;
  816. $form->{orphaned} = 1;
  817. &form_footer;
  818. }
  819. sub list_sic {
  820. AM->sic( \%myconfig, \%$form );
  821. $href =
  822. "$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  823. $form->sort_order();
  824. $form->{callback} =
  825. "$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  826. $callback = $form->escape( $form->{callback} );
  827. $form->{title} = $locale->text('Standard Industrial Codes');
  828. @column_index = $form->sort_columns(qw(code description));
  829. $column_header{code} =
  830. qq|<th><a class="listheading" href=$href&sort=code>|
  831. . $locale->text('Code')
  832. . qq|</a></th>|;
  833. $column_header{description} =
  834. qq|<th><a class="listheading" href=$href&sort=description>|
  835. . $locale->text('Description')
  836. . qq|</a></th>|;
  837. $form->header;
  838. print qq|
  839. <body>
  840. <table width=100%>
  841. <tr>
  842. <th class=listtop>$form->{title}</th>
  843. </tr>
  844. <tr height="5"></tr>
  845. <tr>
  846. <td>
  847. <table width=100%>
  848. <tr class="listheading">
  849. |;
  850. for (@column_index) { print "$column_header{$_}\n" }
  851. print qq|
  852. </tr>
  853. |;
  854. foreach $ref ( @{ $form->{ALL} } ) {
  855. $i++;
  856. $i %= 2;
  857. if ( $ref->{sictype} eq 'H' ) {
  858. print qq|
  859. <tr valign=top class="listheading">
  860. |;
  861. $column_data{code} =
  862. 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>|;
  863. $column_data{description} = qq|<th>$ref->{description}</th>|;
  864. }
  865. else {
  866. print qq|
  867. <tr valign=top class=listrow$i>
  868. |;
  869. $column_data{code} =
  870. 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>|;
  871. $column_data{description} = qq|<td>$ref->{description}</td>|;
  872. }
  873. for (@column_index) { print "$column_data{$_}\n" }
  874. print qq|
  875. </tr>
  876. |;
  877. }
  878. print qq|
  879. </table>
  880. </td>
  881. </tr>
  882. <tr>
  883. <td><hr size=3 noshade></td>
  884. </tr>
  885. </table>
  886. <br>
  887. <form method=post action=$form->{script}>
  888. |;
  889. $form->{type} = "sic";
  890. $form->hide_form(qw(type callback path login sessionid));
  891. print qq|
  892. <button class="submit" type="submit" name="action" value="add_sic">|
  893. . $locale->text('Add SIC')
  894. . qq|</button>|;
  895. if ( $form->{lynx} ) {
  896. require "bin/menu.pl";
  897. &menubar;
  898. }
  899. print qq|
  900. </form>
  901. </body>
  902. </html>
  903. |;
  904. }
  905. sub sic_header {
  906. $form->{title} = $locale->text("$form->{title} SIC");
  907. # $locale->text('Add SIC')
  908. # $locale->text('Edit SIC')
  909. for (qw(code description)) { $form->{$_} = $form->quote( $form->{$_} ) }
  910. $checked = ( $form->{sictype} eq 'H' ) ? "checked" : "";
  911. $form->header;
  912. print qq|
  913. <body>
  914. <form method=post action=$form->{script}>
  915. <input type=hidden name=type value=sic>
  916. <input type=hidden name=id value="$form->{code}">
  917. <table width=100%>
  918. <tr>
  919. <th class=listtop colspan=2>$form->{title}</th>
  920. </tr>
  921. <tr height="5"></tr>
  922. <tr>
  923. <th align="right">| . $locale->text('Code') . qq|</th>
  924. <td><input name=code size=10 value="$form->{code}"></td>
  925. <tr>
  926. <tr>
  927. <td></td>
  928. <th align=left><input name=sictype class=checkbox type=checkbox value="H" $checked> |
  929. . $locale->text('Heading')
  930. . qq|</th>
  931. <tr>
  932. <tr>
  933. <th align="right">| . $locale->text('Description') . qq|</th>
  934. <td><input name=description size=60 value="$form->{description}"></td>
  935. </tr>
  936. <td colspan=2><hr size=3 noshade></td>
  937. </tr>
  938. </table>
  939. |;
  940. }
  941. sub save_sic {
  942. $form->isblank( "code", $locale->text('Code missing!') );
  943. $form->isblank( "description", $locale->text('Description missing!') );
  944. AM->save_sic( \%myconfig, \%$form );
  945. $form->redirect( $locale->text('SIC saved!') );
  946. }
  947. sub delete_sic {
  948. AM->delete_sic( \%myconfig, \%$form );
  949. $form->redirect( $locale->text('SIC deleted!') );
  950. }
  951. sub add_language {
  952. $form->{title} = "Add";
  953. $form->{callback} =
  954. "$form->{script}?action=add_language&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  955. unless $form->{callback};
  956. &language_header;
  957. &form_footer;
  958. }
  959. sub edit_language {
  960. $form->{title} = "Edit";
  961. $form->{code} =~ s/\\'/'/g;
  962. $form->{code} =~ s/\\\\/\\/g;
  963. AM->get_language( \%myconfig, \%$form );
  964. $form->{id} = $form->{code};
  965. &language_header;
  966. $form->{orphaned} = 1;
  967. &form_footer;
  968. }
  969. sub list_language {
  970. AM->language( \%myconfig, \%$form );
  971. $href =
  972. "$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  973. $form->sort_order();
  974. $form->{callback} =
  975. "$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  976. my $callback = $form->escape( $form->{callback} );
  977. $form->{title} = $locale->text('Languages');
  978. my @column_index = $form->sort_columns(qw(code description));
  979. my %column_header;
  980. $column_header{code} = { text => $locale->text('Code'),
  981. href => "$href&sort=code" };
  982. $column_header{description} = { text => $locale->text('Description'),
  983. href => "$href&sort=description" };
  984. my @rows;
  985. my $i = 0;
  986. foreach my $ref ( @{ $form->{ALL} } ) {
  987. my %column_data;
  988. $i++;
  989. $i %= 2;
  990. $column_data{i} = $i;
  991. $column_data{code} = {text => $ref->{code}, href =>
  992. qq|$form->{script}?action=edit_language&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback|};
  993. $column_data{description} = $ref->{description};
  994. push @rows, \%column_data;
  995. }
  996. $form->{type} = "language";
  997. my @hiddens = qw(type callback path login sessionid);
  998. ## SC: Temporary removal
  999. ## if ( $form->{lynx} ) {
  1000. ## require "bin/menu.pl";
  1001. ## &menubar;
  1002. ## }
  1003. my @buttons;
  1004. push @buttons, {
  1005. name => 'action',
  1006. value => 'add_language',
  1007. text => $locale->text('Add Lanugage'),
  1008. type => 'submit',
  1009. class => 'submit',
  1010. };
  1011. # SC: I'm not concerned about the wider description as code is 6 chars max
  1012. my $template = LedgerSMB::Template->new_UI(
  1013. user => \%myconfig,
  1014. locale => $locale,
  1015. template => 'am-list-departments');
  1016. $template->render({
  1017. form => $form,
  1018. buttons => \@buttons,
  1019. columns => \@column_index,
  1020. heading => \%column_header,
  1021. rows => \@rows,
  1022. hiddens => \@hiddens,
  1023. });
  1024. }
  1025. sub language_header {
  1026. $form->{title} = $locale->text("$form->{title} Language");
  1027. # $locale->text('Add Language')
  1028. # $locale->text('Edit Language')
  1029. for (qw(code description)) { $form->{$_} = $form->quote( $form->{$_} ) }
  1030. $form->header;
  1031. print qq|
  1032. <body>
  1033. <form method=post action=$form->{script}>
  1034. <input type=hidden name=type value=language>
  1035. <input type=hidden name=id value="$form->{code}">
  1036. <table width=100%>
  1037. <tr>
  1038. <th class=listtop colspan=2>$form->{title}</th>
  1039. </tr>
  1040. <tr height="5"></tr>
  1041. <tr>
  1042. <th align="right">| . $locale->text('Code') . qq|</th>
  1043. <td><input name=code size=10 value="$form->{code}"></td>
  1044. <tr>
  1045. <tr>
  1046. <th align="right">| . $locale->text('Description') . qq|</th>
  1047. <td><input name=description size=60 value="$form->{description}"></td>
  1048. </tr>
  1049. <td colspan=2><hr size=3 noshade></td>
  1050. </tr>
  1051. </table>
  1052. |;
  1053. }
  1054. sub save_language {
  1055. $form->isblank( "code", $locale->text('Code missing!') );
  1056. $form->isblank( "description", $locale->text('Description missing!') );
  1057. $form->{code} =~ s/(\.\.|\*)//g;
  1058. AM->save_language( \%myconfig, \%$form );
  1059. if ( !-d "$myconfig{templates}/$form->{code}" ) {
  1060. umask(002);
  1061. if ( mkdir "$myconfig{templates}/$form->{code}", oct("771") ) {
  1062. umask(007);
  1063. opendir TEMPLATEDIR, "$myconfig{templates}"
  1064. or $form->error("$myconfig{templates} : $!");
  1065. @templates = grep !/^(\.|\.\.)/, readdir TEMPLATEDIR;
  1066. closedir TEMPLATEDIR;
  1067. foreach $file (@templates) {
  1068. if ( -f "$myconfig{templates}/$file" ) {
  1069. open( TEMP, '<', "$myconfig{templates}/$file" )
  1070. or $form->error("$myconfig{templates}/$file : $!");
  1071. open( NEW, '>', "$myconfig{templates}/$form->{code}/$file" )
  1072. or $form->error(
  1073. "$myconfig{templates}/$form->{code}/$file : $!");
  1074. while ( $line = <TEMP> ) {
  1075. print NEW $line;
  1076. }
  1077. close(TEMP);
  1078. close(NEW);
  1079. }
  1080. }
  1081. }
  1082. else {
  1083. $form->error("${templates}/$form->{code} : $!");
  1084. }
  1085. }
  1086. $form->redirect( $locale->text('Language saved!') );
  1087. }
  1088. sub delete_language {
  1089. $form->{title} = $locale->text('Confirm!');
  1090. $form->header;
  1091. print qq|
  1092. <body>
  1093. <form method=post action=$form->{script}>
  1094. |;
  1095. for (qw(action nextsub)) { delete $form->{$_} }
  1096. $form->hide_form;
  1097. print qq|
  1098. <h2 class=confirm>$form->{title}</h2>
  1099. <h4>|
  1100. . $locale->text(
  1101. 'Deleting a language will also delete the templates for the language [_1]',
  1102. $form->{invnumber}
  1103. )
  1104. . qq|</h4>
  1105. <input type=hidden name=action value=continue>
  1106. <input type=hidden name=nextsub value=yes_delete_language>
  1107. <button name="action" class="submit" type="submit" value="continue">|
  1108. . $locale->text('Continue')
  1109. . qq|</button>
  1110. </form>
  1111. </body>
  1112. </html>
  1113. |;
  1114. }
  1115. sub yes_delete_language {
  1116. AM->delete_language( \%myconfig, \%$form );
  1117. # delete templates
  1118. $dir = "$myconfig{templates}/$form->{code}";
  1119. if ( -d $dir ) {
  1120. unlink <$dir/*>;
  1121. rmdir "$myconfig{templates}/$form->{code}";
  1122. }
  1123. $form->redirect( $locale->text('Language deleted!') );
  1124. }
  1125. sub display_stylesheet {
  1126. $form->{file} = "css/$myconfig{stylesheet}";
  1127. &display_form;
  1128. }
  1129. sub list_templates {
  1130. AM->language( \%myconfig, \%$form );
  1131. if ( !@{ $form->{ALL} } ) {
  1132. &display_form;
  1133. exit;
  1134. }
  1135. unshift @{ $form->{ALL} },
  1136. { code => '.', description => $locale->text('Default Template') };
  1137. my $href =
  1138. "$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1139. $form->sort_order();
  1140. $form->{callback} =
  1141. "$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1142. my $callback = $form->escape( $form->{callback} );
  1143. chomp $myconfig{templates};
  1144. $form->{file} =~ s/$myconfig{templates}//;
  1145. $form->{file} =~ s/\///;
  1146. $form->{title} = "$form->{format}: $form->{template}";
  1147. my @column_index = $form->sort_columns(qw(code description));
  1148. $column_header{code} = { text => $locale->text('Code'),
  1149. href => "$href&sort=code" };
  1150. $column_header{description} = { text => $locale->text('Description'),
  1151. href => "$href&sort=description" };
  1152. my @rows;
  1153. my $i = 0;
  1154. foreach my $ref ( @{ $form->{ALL} } ) {
  1155. my %column_data;
  1156. $i++;
  1157. $i %= 2;
  1158. $column_data{i} = $i;
  1159. $column_data{code} = { text => $ref->{code}, href =>
  1160. qq|$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|};
  1161. $column_data{description} = $ref->{description};
  1162. push @rows, \%column_data;
  1163. }
  1164. $form->{type} = 'language';
  1165. my @hiddens = qw(sessionid login path calllback type);
  1166. ## SC: Temporary removal
  1167. ## if ( $form->{lynx} ) {
  1168. ## require "bin/menu.pl";
  1169. ## &menubar;
  1170. ## }
  1171. # SC: I'm not concerned about the wider description as code is 6 chars max
  1172. my $template = LedgerSMB::Template->new_UI(
  1173. user => \%myconfig,
  1174. locale => $locale,
  1175. template => 'am-list-departments');
  1176. $template->render({
  1177. form => $form,
  1178. columns => \@column_index,
  1179. heading => \%column_header,
  1180. rows => \@rows,
  1181. hiddens => \@hiddens,
  1182. });
  1183. }
  1184. sub display_form {
  1185. AM->load_template( \%myconfig, \%$form );
  1186. $form->{title} = $form->{file};
  1187. $form->{body} =~
  1188. 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;
  1189. # if it is anything but html
  1190. if ( $form->{file} !~ /\.html$/ ) {
  1191. $form->{body} = "<pre>\n$form->{body}\n</pre>";
  1192. }
  1193. $form->header;
  1194. print qq|
  1195. <body>
  1196. $form->{body}
  1197. <form method=post action=$form->{script}>
  1198. |;
  1199. $form->{type} = "template";
  1200. $form->hide_form(qw(file type path login sessionid));
  1201. print qq|
  1202. <button name="action" type="submit" class="submit" value="edit">|
  1203. . $locale->text('Edit')
  1204. . qq|</button>|;
  1205. if ( $form->{lynx} ) {
  1206. require "bin/menu.pl";
  1207. &menubar;
  1208. }
  1209. print qq|
  1210. </form>
  1211. </body>
  1212. </html>
  1213. |;
  1214. }
  1215. sub edit_template {
  1216. AM->load_template( \%myconfig, \%$form );
  1217. $form->{title} = $locale->text('Edit Template');
  1218. # convert &nbsp to &amp;nbsp;
  1219. $form->{body} =~ s/&nbsp;/&amp;nbsp;/gi;
  1220. $form->header;
  1221. print qq|
  1222. <body>
  1223. <form method=post action=$form->{script}>
  1224. <input name=file type=hidden value=$form->{file}>
  1225. <input name=type type=hidden value=template>
  1226. <input type=hidden name=path value=$form->{path}>
  1227. <input type=hidden name=login value=$form->{login}>
  1228. <input type=hidden name=sessionid value=$form->{sessionid}>
  1229. <input name=callback type=hidden value="$form->{script}?action=display_form&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}">
  1230. <textarea name=body rows=25 cols=70>
  1231. $form->{body}
  1232. </textarea>
  1233. <br>
  1234. <button type="submit" class="submit" name="action" value="save">|
  1235. . $locale->text('Save')
  1236. . qq|</button>|;
  1237. if ( $form->{lynx} ) {
  1238. require "bin/menu.pl";
  1239. &menubar;
  1240. }
  1241. print q|
  1242. </form>
  1243. </body>
  1244. </html>
  1245. |;
  1246. }
  1247. sub save_template {
  1248. AM->save_template( \%myconfig, \%$form );
  1249. $form->redirect( $locale->text('Template saved!') );
  1250. }
  1251. sub defaults {
  1252. # get defaults for account numbers and last numbers
  1253. AM->get_all_defaults( \%$form );
  1254. foreach $key ( keys %{ $form->{accno} } ) {
  1255. foreach $accno ( sort keys %{ $form->{accno}{$key} } ) {
  1256. $form->{account}{$key} .=
  1257. "<option>$accno--$form->{accno}{$key}{$accno}{description}\n";
  1258. $form->{accno}{ $form->{accno}{$key}{$accno}{id} } = $accno;
  1259. }
  1260. }
  1261. for (qw(IC IC_inventory IC_income IC_expense FX_gain FX_loss)) {
  1262. $form->{account}{$_} =~
  1263. s/>$form->{accno}{$form->{defaults}{$_}}/ selected>$form->{accno}{$form->{defaults}{$_}}/;
  1264. }
  1265. for (qw(accno defaults)) { delete $form->{$_} }
  1266. $form->{title} = $locale->text('System Defaults');
  1267. $form->header;
  1268. print qq|
  1269. <body>
  1270. <form method=post action=$form->{script}>
  1271. <input type=hidden name=type value=defaults>
  1272. <table width=100%>
  1273. <tr><th class=listtop>$form->{title}</th></tr>
  1274. <tr>
  1275. <td>
  1276. <table>
  1277. <tr>
  1278. <th align="right">| . $locale->text('Business Number') . qq|</th>
  1279. <td><input name=businessnumber size=25 value="$form->{businessnumber}"></td>
  1280. </tr>
  1281. <tr>
  1282. <th align="right">| . $locale->text('Weight Unit') . qq|</th>
  1283. <td><input name=weightunit size=5 value="$form->{weightunit}"></td>
  1284. </tr>
  1285. </table>
  1286. </td>
  1287. </tr>
  1288. <tr>
  1289. <th class="listheading">|
  1290. . $locale->text('Last Numbers & Default Accounts')
  1291. . qq|</th>
  1292. </tr>
  1293. <tr>
  1294. <td>
  1295. <table>
  1296. <tr>
  1297. <th align="right" nowrap>| . $locale->text('Inventory') . qq|</th>
  1298. <td><select name=IC>$form->{account}{IC}</select></td>
  1299. </tr>
  1300. <tr>
  1301. <th align="right" nowrap>| . $locale->text('Income') . qq|</th>
  1302. <td><select name=IC_income>$form->{account}{IC_income}</select></td>
  1303. </tr>
  1304. <tr>
  1305. <th align="right" nowrap>| . $locale->text('Expense') . qq|</th>
  1306. <td><select name=IC_expense>$form->{account}{IC_expense}</select></td>
  1307. </tr>
  1308. <tr>
  1309. <th align="right" nowrap>|
  1310. . $locale->text('Foreign Exchange Gain')
  1311. . qq|</th>
  1312. <td><select name=FX_gain>$form->{account}{FX_gain}</select></td>
  1313. </tr>
  1314. <tr>
  1315. <th align="right" nowrap>|
  1316. . $locale->text('Foreign Exchange Loss')
  1317. . qq|</th>
  1318. <td><select name=FX_loss>$form->{account}{FX_loss}</select></td>
  1319. </tr>
  1320. </table>
  1321. </td>
  1322. </tr>
  1323. <tr>
  1324. <th align=left>|
  1325. . $locale->text(
  1326. 'Enter up to 3 letters separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies'
  1327. )
  1328. . qq|</th>
  1329. </tr>
  1330. <tr>
  1331. <td>
  1332. <input name=curr size=40 value="$form->{curr}">
  1333. </td>
  1334. </tr>
  1335. <tr>
  1336. <td>
  1337. <table>
  1338. <tr>
  1339. <th align="right" nowrap>| . $locale->text('GL Reference Number') . qq|</th>
  1340. <td><input name=glnumber size=40 value="$form->{glnumber}"></td>
  1341. </tr>
  1342. <tr>
  1343. <th align="right" nowrap>|
  1344. . $locale->text('Sales Invoice/AR Transaction Number')
  1345. . qq|</th>
  1346. <td><input name=sinumber size=40 value="$form->{sinumber}"></td>
  1347. </tr>
  1348. <tr>
  1349. <th align="right" nowrap>| . $locale->text('Sales Order Number') . qq|</th>
  1350. <td><input name=sonumber size=40 value="$form->{sonumber}"></td>
  1351. </tr>
  1352. <tr>
  1353. <th align="right" nowrap>|
  1354. . $locale->text('Vendor Invoice/AP Transaction Number')
  1355. . qq|</th>
  1356. <td><input name=vinumber size=40 value="$form->{vinumber}"></td>
  1357. </tr>
  1358. <tr>
  1359. <th align="right" nowrap>|
  1360. . $locale->text('Purchase Order Number')
  1361. . qq|</th>
  1362. <td><input name=ponumber size=40 value="$form->{ponumber}"></td>
  1363. </tr>
  1364. <tr>
  1365. <th align="right" nowrap>|
  1366. . $locale->text('Sales Quotation Number')
  1367. . qq|</th>
  1368. <td><input name=sqnumber size=40 value="$form->{sqnumber}"></td>
  1369. </tr>
  1370. <tr>
  1371. <th align="right" nowrap>| . $locale->text('RFQ Number') . qq|</th>
  1372. <td><input name=rfqnumber size=40 value="$form->{rfqnumber}"></td>
  1373. </tr>
  1374. <tr>
  1375. <th align="right" nowrap>| . $locale->text('Part Number') . qq|</th>
  1376. <td><input name=partnumber size=40 value="$form->{partnumber}"></td>
  1377. </tr>
  1378. <tr>
  1379. <th align="right" nowrap>| . $locale->text('Job/Project Number') . qq|</th>
  1380. <td><input name=projectnumber size=40 value="$form->{projectnumber}"></td>
  1381. </tr>
  1382. <tr>
  1383. <th align="right" nowrap>| . $locale->text('Employee Number') . qq|</th>
  1384. <td><input name=employeenumber size=40 value="$form->{employeenumber}"></td>
  1385. </tr>
  1386. <tr>
  1387. <th align="right" nowrap>| . $locale->text('Customer Number') . qq|</th>
  1388. <td><input name=customernumber size=40 value="$form->{customernumber}"></td>
  1389. </tr>
  1390. <tr>
  1391. <th align="right" nowrap>| . $locale->text('Vendor Number') . qq|</th>
  1392. <td><input name=vendornumber size=40 value="$form->{vendornumber}"></td>
  1393. </tr>
  1394. </table>
  1395. </td>
  1396. </tr>
  1397. <tr>
  1398. <td><hr size=3 noshade></td>
  1399. </tr>
  1400. </table>
  1401. |;
  1402. $form->hide_form(qw(path login sessionid));
  1403. print qq|
  1404. <button type="submit" class="submit" name="action" value="save">|
  1405. . $locale->text('Save')
  1406. . qq|</button>|;
  1407. if ( $form->{lynx} ) {
  1408. require "bin/menu.pl";
  1409. &menubar;
  1410. }
  1411. print qq|
  1412. </form>
  1413. </body>
  1414. </html>
  1415. |;
  1416. }
  1417. sub taxes {
  1418. # get tax account numbers
  1419. AM->taxes( \%myconfig, \%$form );
  1420. $i = 0;
  1421. foreach $ref ( @{ $form->{taxrates} } ) {
  1422. $i++;
  1423. $form->{"taxrate_$i"} =
  1424. $form->format_amount( \%myconfig, $ref->{rate} );
  1425. $form->{"taxdescription_$i"} = $ref->{description};
  1426. for (qw(taxnumber validto pass taxmodulename)) {
  1427. $form->{"${_}_$i"} = $ref->{$_};
  1428. }
  1429. $form->{taxaccounts} .= "$ref->{id}_$i ";
  1430. }
  1431. chop $form->{taxaccounts};
  1432. &display_taxes;
  1433. }
  1434. sub display_taxes {
  1435. $form->{title} = $locale->text('Taxes');
  1436. $form->header;
  1437. print qq|
  1438. <body>
  1439. <form method=post action=$form->{script}>
  1440. <input type=hidden name=type value=taxes>
  1441. <table width=100%>
  1442. <tr><th class=listtop>$form->{title}</th></tr>
  1443. <tr>
  1444. <td>
  1445. <table>
  1446. <tr>
  1447. <th></th>
  1448. <th>| . $locale->text('Rate') . qq| (%)</th>
  1449. <th>| . $locale->text('Number') . qq|</th>
  1450. <th>| . $locale->text('Valid To') . qq|</th>
  1451. <th>| . $locale->text('Ordering') . qq|</th>
  1452. <th>| . $locale->text('Tax Rules') . qq|</th>
  1453. </tr>
  1454. |;
  1455. for ( split( / /, $form->{taxaccounts} ) ) {
  1456. ( $null, $i ) = split /_/, $_;
  1457. $form->{"taxrate_$i"} =
  1458. $form->format_amount( \%myconfig, $form->{"taxrate_$i"} );
  1459. $form->hide_form("taxdescription_$i");
  1460. print qq|
  1461. <tr>
  1462. <th align="right">|;
  1463. if ( $form->{"taxdescription_$i"} eq $sametax ) {
  1464. print "";
  1465. }
  1466. else {
  1467. print qq|$form->{"taxdescription_$i"}|;
  1468. }
  1469. print qq|</th>
  1470. <td><input name="taxrate_$i" size=6 value=$form->{"taxrate_$i"}></td>
  1471. <td><input name="taxnumber_$i" value="$form->{"taxnumber_$i"}"></td>
  1472. <td><input class="date" name="validto_$i" size=11 value="$form->{"validto_$i"}" title="$myconfig{dateformat}"></td>
  1473. <td><input name="pass_$i" size=6 value="$form->{"pass_$i"}"></td>
  1474. <td><select name="taxmodule_id_$i" size=1>|;
  1475. foreach my $taxmodule ( sort keys %$form ) {
  1476. next if ( $taxmodule !~ /^taxmodule_/ );
  1477. next if ( $taxmodule =~ /^taxmodule_id_/ );
  1478. my $modulenum = $taxmodule;
  1479. $modulenum =~ s/^taxmodule_//;
  1480. print '<option label="'
  1481. . $form->{$taxmodule}
  1482. . '" value="'
  1483. . $modulenum . '"';
  1484. print " SELECTED "
  1485. if $form->{$taxmodule} eq $form->{"taxmodulename_$i"};
  1486. print ">" . $form->{$taxmodule} . "</option>\n";
  1487. }
  1488. print qq|</select></td>
  1489. </tr> |;
  1490. $sametax = $form->{"taxdescription_$i"};
  1491. }
  1492. print qq|
  1493. </table>
  1494. </td>
  1495. </tr>
  1496. <tr>
  1497. <td><hr size=3 noshade></td>
  1498. </tr>
  1499. </table>
  1500. |;
  1501. $form->hide_form(qw(taxaccounts path login sessionid));
  1502. foreach my $taxmodule ( sort keys %$form ) {
  1503. next if ( $taxmodule !~ /^taxmodule_/ );
  1504. next if ( $taxmodule =~ /^taxmodule_id_/ );
  1505. $form->hide_form("$taxmodule");
  1506. }
  1507. print qq|
  1508. <button type="submit" class="submit" name="action" value="update">|
  1509. . $locale->text('Update')
  1510. . qq|</button>
  1511. <button type="submit" class="submit" name="action" value="save_taxes">|
  1512. . $locale->text('Save')
  1513. . qq|</button>|;
  1514. if ( $form->{lynx} ) {
  1515. require "bin/menu.pl";
  1516. &menubar;
  1517. }
  1518. print qq|
  1519. </form>
  1520. </body>
  1521. </html>
  1522. |;
  1523. }
  1524. sub update {
  1525. @a = split / /, $form->{taxaccounts};
  1526. $ndx = $#a + 1;
  1527. foreach $item (@a) {
  1528. ( $accno, $i ) = split /_/, $item;
  1529. push @t, $accno;
  1530. $form->{"taxmodulename_$i"} =
  1531. $form->{ "taxmodule_" . $form->{"taxmodule_id_$i"} };
  1532. if ( $form->{"validto_$i"} ) {
  1533. $j = $i + 1;
  1534. if ( $form->{"taxdescription_$i"} ne $form->{"taxdescription_$j"} )
  1535. {
  1536. #insert line
  1537. for ( $j = $ndx + 1 ; $j > $i ; $j-- ) {
  1538. $k = $j - 1;
  1539. for (qw(taxrate taxdescription taxnumber validto)) {
  1540. $form->{"${_}_$j"} = $form->{"${_}_$k"};
  1541. }
  1542. }
  1543. $ndx++;
  1544. $k = $i + 1;
  1545. for (qw(taxdescription taxnumber)) {
  1546. $form->{"${_}_$k"} = $form->{"${_}_$i"};
  1547. }
  1548. for (qw(taxrate validto)) { $form->{"${_}_$k"} = "" }
  1549. push @t, $accno;
  1550. }
  1551. }
  1552. else {
  1553. # remove line
  1554. $j = $i + 1;
  1555. if ( $form->{"taxdescription_$i"} eq $form->{"taxdescription_$j"} )
  1556. {
  1557. for ( $j = $i + 1 ; $j <= $ndx ; $j++ ) {
  1558. $k = $j + 1;
  1559. for (qw(taxrate taxdescription taxnumber validto)) {
  1560. $form->{"${_}_$j"} = $form->{"${_}_$k"};
  1561. }
  1562. }
  1563. $ndx--;
  1564. splice @t, $i - 1, 1;
  1565. }
  1566. }
  1567. }
  1568. $i = 1;
  1569. $form->{taxaccounts} = "";
  1570. for (@t) {
  1571. $form->{taxaccounts} .= "${_}_$i ";
  1572. $i++;
  1573. }
  1574. chop $form->{taxaccounts};
  1575. &display_taxes;
  1576. }
  1577. sub config {
  1578. foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd))
  1579. {
  1580. $dateformat .=
  1581. ( $item eq $myconfig{dateformat} )
  1582. ? "<option selected>$item\n"
  1583. : "<option>$item\n";
  1584. }
  1585. my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00);
  1586. push @formats, '1 000.00';
  1587. foreach $item (@formats) {
  1588. $numberformat .=
  1589. ( $item eq $myconfig{numberformat} )
  1590. ? "<option selected>$item\n"
  1591. : "<option>$item\n";
  1592. }
  1593. for (qw(name company address signature)) {
  1594. $myconfig{$_} = $form->quote( $myconfig{$_} );
  1595. }
  1596. for (qw(address signature)) { $myconfig{$_} =~ s/\\n/\n/g }
  1597. %countrycodes = LedgerSMB::User->country_codes;
  1598. $countrycodes = '';
  1599. my $selectedcode =
  1600. ( $myconfig{countrycode} ) ? $myconfig{countrycode} : 'en';
  1601. foreach $key ( sort { $countrycodes{$a} cmp $countrycodes{$b} }
  1602. keys %countrycodes )
  1603. {
  1604. $countrycodes .=
  1605. ( $selectedcode eq $key )
  1606. ? "<option selected value=$key>$countrycodes{$key}\n"
  1607. : "<option value=$key>$countrycodes{$key}\n";
  1608. }
  1609. opendir CSS, "css/.";
  1610. @all = grep /.*\.css$/, readdir CSS;
  1611. closedir CSS;
  1612. foreach $item (@all) {
  1613. if ( $item eq $myconfig{stylesheet} ) {
  1614. $selectstylesheet .= qq|<option selected>$item\n|;
  1615. }
  1616. else {
  1617. $selectstylesheet .= qq|<option>$item\n|;
  1618. }
  1619. }
  1620. $selectstylesheet .= "<option>\n";
  1621. if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) {
  1622. $selectprinter = "<option>\n";
  1623. foreach $item ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  1624. if ( $myconfig{printer} eq $item ) {
  1625. $selectprinter .= qq|<option value="$item" selected>$item\n|;
  1626. }
  1627. else {
  1628. $selectprinter .= qq|<option value="$item">$item\n|;
  1629. }
  1630. }
  1631. $printer = qq|
  1632. <tr>
  1633. <th align="right">| . $locale->text('Printer') . qq|</th>
  1634. <td><select name=printer>$selectprinter</select></td>
  1635. </tr>
  1636. |;
  1637. }
  1638. $form->{title} =
  1639. $locale->text( 'Edit Preferences for [_1]', $form->{login} );
  1640. $form->header;
  1641. print qq|
  1642. <body>
  1643. <form method=post action=$form->{script}>
  1644. <input type=hidden name=old_password value="$myconfig{password}">
  1645. <input type=hidden name=type value=preferences>
  1646. <input type=hidden name=role value="$myconfig{role}">
  1647. <table width=100%>
  1648. <tr><th class=listtop>$form->{title}</th></tr>
  1649. <tr>
  1650. <td>
  1651. <table width=100%>
  1652. <tr valign=top>
  1653. <td>
  1654. <table>
  1655. <tr>
  1656. <th align="right">| . $locale->text('Name') . qq|</th>
  1657. <td><input name=name size=20 value="$myconfig{name}"></td>
  1658. </tr>
  1659. <tr>
  1660. <th align="right">| . $locale->text('E-mail') . qq|</th>
  1661. <td><input name=email size=35 value="$myconfig{email}"></td>
  1662. </tr>
  1663. <tr valign=top>
  1664. <th align="right">| . $locale->text('Signature') . qq|</th>
  1665. <td><textarea name=signature rows=3 cols=35>$myconfig{signature}</textarea></td>
  1666. </tr>
  1667. <tr>
  1668. <th align="right">| . $locale->text('Phone') . qq|</th>
  1669. <td><input name=tel size=14 value="$myconfig{tel}"></td>
  1670. </tr>
  1671. <tr>
  1672. <th align="right">| . $locale->text('Fax') . qq|</th>
  1673. <td><input name=fax size=14 value="$myconfig{fax}"></td>
  1674. </tr>
  1675. <tr>
  1676. <th align="right">| . $locale->text('Company') . qq|</th>
  1677. <td><input name=company size=35 value="$myconfig{company}"></td>
  1678. </tr>
  1679. <tr valign=top>
  1680. <th align="right">| . $locale->text('Address') . qq|</th>
  1681. <td><textarea name=address rows=4 cols=35>$myconfig{address}</textarea></td>
  1682. </tr>
  1683. </table>
  1684. </td>
  1685. <td>
  1686. <table>
  1687. <tr>
  1688. <th align="right">| . $locale->text('Password') . qq|</th>
  1689. <td><input type=password name=new_password size=10 value="$myconfig{password}"></td>
  1690. </tr>
  1691. <tr>
  1692. <th align="right">| . $locale->text('Confirm') . qq|</th>
  1693. <td><input type=password name=confirm_password size=10></td>
  1694. </tr>
  1695. <tr>
  1696. <th align="right">| . $locale->text('Date Format') . qq|</th>
  1697. <td><select name=dateformat>$dateformat</select></td>
  1698. </tr>
  1699. <tr>
  1700. <th align="right">| . $locale->text('Number Format') . qq|</th>
  1701. <td><select name=numberformat>$numberformat</select></td>
  1702. </tr>
  1703. <tr>
  1704. <th align="right">| . $locale->text('Dropdown Limit') . qq|</th>
  1705. <td><input name=vclimit size=10 value="$myconfig{vclimit}"></td>
  1706. </tr>
  1707. <tr>
  1708. <th align="right">| . $locale->text('Menu Width') . qq|</th>
  1709. <td><input name=menuwidth size=10 value="$myconfig{menuwidth}"></td>
  1710. </tr>
  1711. <tr>
  1712. <th align="right">| . $locale->text('Language') . qq|</th>
  1713. <td><select name=countrycode>$countrycodes</select></td>
  1714. </tr>
  1715. <tr>
  1716. <th align="right">| . $locale->text('Session Timeout') . qq|</th>
  1717. <td><input name=timeout size=10 value="$myconfig{timeout}"></td>
  1718. </tr>
  1719. <tr>
  1720. <th align="right">| . $locale->text('Stylesheet') . qq|</th>
  1721. <td><select name=usestylesheet>$selectstylesheet</select></td>
  1722. </tr>
  1723. $printer
  1724. </table>
  1725. </td>
  1726. </tr>
  1727. </table>
  1728. </td>
  1729. <tr>
  1730. <td><hr size=3 noshade></td>
  1731. </tr>
  1732. </table>
  1733. |;
  1734. $form->hide_form(qw(path login sessionid));
  1735. print qq|
  1736. <button type="submit" class="submit" name="action" value="save">|
  1737. . $locale->text('Save')
  1738. . qq|</button>|;
  1739. if ( $form->{lynx} ) {
  1740. require "bin/menu.pl";
  1741. &menubar;
  1742. }
  1743. print qq|
  1744. </form>
  1745. </body>
  1746. </html>
  1747. |;
  1748. }
  1749. sub save_defaults {
  1750. if ( AM->save_defaults( \%myconfig, \%$form ) ) {
  1751. $form->redirect( $locale->text('Defaults saved!') );
  1752. }
  1753. else {
  1754. $form->error( $locale->text('Cannot save defaults!') );
  1755. }
  1756. }
  1757. sub save_taxes {
  1758. if ( AM->save_taxes( \%myconfig, \%$form ) ) {
  1759. $form->redirect( $locale->text('Taxes saved!') );
  1760. }
  1761. else {
  1762. $form->error( $locale->text('Cannot save taxes!') );
  1763. }
  1764. }
  1765. sub save_preferences {
  1766. $form->{stylesheet} = $form->{usestylesheet};
  1767. if ( $form->{new_password} ne $form->{old_password} ) {
  1768. $form->error( $locale->text('Password does not match!') )
  1769. if $form->{new_password} ne $form->{confirm_password};
  1770. }
  1771. if ( AM->save_preferences( \%myconfig, \%$form ) ) {
  1772. $form->info( $locale->text('Preferences saved!') );
  1773. }
  1774. else {
  1775. $form->error( $locale->text('Cannot save preferences!') );
  1776. }
  1777. }
  1778. sub backup {
  1779. if ( $form->{media} eq 'email' ) {
  1780. $form->error(
  1781. $locale->text( 'No email address for [_1]', $myconfig{name} ) )
  1782. unless ( $myconfig{email} );
  1783. }
  1784. $SIG{INT} = 'IGNORE';
  1785. AM->backup(
  1786. \%myconfig, \%$form,
  1787. ${LedgerSMB::Sysconfig::userspath},
  1788. ${LedgerSMB::Sysconfig::gzip}
  1789. );
  1790. if ( $form->{media} eq 'email' ) {
  1791. $form->redirect(
  1792. $locale->text( 'Backup sent to [_1]', $myconfig{email} ) );
  1793. }
  1794. }
  1795. sub audit_control {
  1796. $form->{title} = $locale->text('Audit Control');
  1797. AM->closedto( \%myconfig, \%$form );
  1798. if ( $form->{revtrans} ) {
  1799. $checked{revtransY} = "checked";
  1800. }
  1801. else {
  1802. $checked{revtransN} = "checked";
  1803. }
  1804. if ( $form->{audittrail} ) {
  1805. $checked{audittrailY} = "checked";
  1806. }
  1807. else {
  1808. $checked{audittrailN} = "checked";
  1809. }
  1810. $form->header;
  1811. print qq|
  1812. <body>
  1813. <form method=post action=$form->{script}>
  1814. <input type=hidden name=path value=$form->{path}>
  1815. <input type=hidden name=login value=$form->{login}>
  1816. <input type=hidden name=sessionid value=$form->{sessionid}>
  1817. <table width=100%>
  1818. <tr><th class=listtop>$form->{title}</th></tr>
  1819. <tr height="5"></tr>
  1820. <tr>
  1821. <td>
  1822. <table>
  1823. <tr>
  1824. <th align="right">|
  1825. . $locale->text('Enforce transaction reversal for all dates')
  1826. . qq|</th>
  1827. <td><input name=revtrans class=radio type=radio value="1" $checked{revtransY}> |
  1828. . $locale->text('Yes')
  1829. . qq| <input name=revtrans class=radio type=radio value="0" $checked{revtransN}> |
  1830. . $locale->text('No')
  1831. . qq|</td>
  1832. </tr>
  1833. <tr>
  1834. <th align="right">| . $locale->text('Close Books up to') . qq|</th>
  1835. <td><input class="date" name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
  1836. </tr>
  1837. <tr>
  1838. <th align="right">| . $locale->text('Activate Audit trail') . qq|</th>
  1839. <td><input name=audittrail class=radio type=radio value="1" $checked{audittrailY}> |
  1840. . $locale->text('Yes')
  1841. . qq| <input name=audittrail class=radio type=radio value="0" $checked{audittrailN}> |
  1842. . $locale->text('No')
  1843. . qq|</td>
  1844. </tr><!-- SC: Disabling audit trail deletion
  1845. <tr>
  1846. <th align="right">| . $locale->text('Remove Audit trail up to') . qq|</th>
  1847. <td><input class="date" name=removeaudittrail size=11 title="$myconfig{dateformat}"></td>
  1848. </tr> -->
  1849. </table>
  1850. </td>
  1851. </tr>
  1852. </table>
  1853. <hr size=3 noshade>
  1854. <br>
  1855. <input type=hidden name=nextsub value=doclose>
  1856. <input type=hidden name=action value=continue>
  1857. <button type="submit" class="submit" name="action" value="continue">|
  1858. . $locale->text('Continue')
  1859. . qq|</button>
  1860. </form>
  1861. </body>
  1862. </html>
  1863. |;
  1864. }
  1865. sub doclose {
  1866. AM->closebooks( \%myconfig, \%$form );
  1867. if ( $form->{revtrans} ) {
  1868. $msg = $locale->text('Transaction reversal enforced for all dates');
  1869. }
  1870. else {
  1871. if ( $form->{closedto} ) {
  1872. $msg =
  1873. $locale->text('Transaction reversal enforced up to') . " "
  1874. . $locale->date( \%myconfig, $form->{closedto}, 1 );
  1875. }
  1876. else {
  1877. $msg = $locale->text('Books are open');
  1878. }
  1879. }
  1880. $msg .= "<p>";
  1881. if ( $form->{audittrail} ) {
  1882. $msg .= $locale->text('Audit trail enabled');
  1883. }
  1884. else {
  1885. $msg .= $locale->text('Audit trail disabled');
  1886. }
  1887. ##SC: Disabling audit trail deletion
  1888. ## $msg .= "<p>";
  1889. ## if ( $form->{removeaudittrail} ) {
  1890. ## $msg .=
  1891. ## $locale->text('Audit trail removed up to') . " "
  1892. ## . $locale->date( \%myconfig, $form->{removeaudittrail}, 1 );
  1893. ## }
  1894. $form->redirect($msg);
  1895. }
  1896. sub add_warehouse {
  1897. $form->{title} = "Add";
  1898. $form->{callback} =
  1899. "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  1900. unless $form->{callback};
  1901. &warehouse_header;
  1902. &form_footer;
  1903. }
  1904. sub edit_warehouse {
  1905. $form->{title} = "Edit";
  1906. AM->get_warehouse( \%myconfig, \%$form );
  1907. &warehouse_header;
  1908. &form_footer;
  1909. }
  1910. sub list_warehouse {
  1911. AM->warehouses( \%myconfig, \%$form );
  1912. $href =
  1913. "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1914. $form->sort_order();
  1915. $form->{callback} =
  1916. "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1917. $callback = $form->escape( $form->{callback} );
  1918. $form->{title} = $locale->text('Warehouses');
  1919. @column_index = qw(description);
  1920. $column_header{description} =
  1921. qq|<th width=100%><a class="listheading" href=$href>|
  1922. . $locale->text('Description')
  1923. . qq|</a></th>|;
  1924. $form->header;
  1925. print qq|
  1926. <body>
  1927. <table width=100%>
  1928. <tr>
  1929. <th class=listtop>$form->{title}</th>
  1930. </tr>
  1931. <tr height="5"></tr>
  1932. <tr>
  1933. <td>
  1934. <table width=100%>
  1935. <tr class="listheading">
  1936. |;
  1937. for (@column_index) { print "$column_header{$_}\n" }
  1938. print qq|
  1939. </tr>
  1940. |;
  1941. foreach $ref ( @{ $form->{ALL} } ) {
  1942. $i++;
  1943. $i %= 2;
  1944. print qq|
  1945. <tr valign=top class=listrow$i>
  1946. |;
  1947. $column_data{description} =
  1948. 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>|;
  1949. for (@column_index) { print "$column_data{$_}\n" }
  1950. print qq|
  1951. </tr>
  1952. |;
  1953. }
  1954. print qq|
  1955. </table>
  1956. </td>
  1957. </tr>
  1958. <tr>
  1959. <td><hr size=3 noshade></td>
  1960. </tr>
  1961. </table>
  1962. <br>
  1963. <form method=post action=$form->{script}>
  1964. |;
  1965. $form->{type} = "warehouse";
  1966. $form->hide_form(qw(type callback path login sessionid));
  1967. print qq|
  1968. <button class="submit" type="submit" name="action" value="add_warehouse">|
  1969. . $locale->text('Add Warehouse')
  1970. . qq|</button>|;
  1971. if ( $form->{lynx} ) {
  1972. require "bin/menu.pl";
  1973. &menubar;
  1974. }
  1975. print qq|
  1976. </form>
  1977. </body>
  1978. </html>
  1979. |;
  1980. }
  1981. sub warehouse_header {
  1982. $form->{title} = $locale->text("$form->{title} Warehouse");
  1983. # $locale->text('Add Warehouse')
  1984. # $locale->text('Edit Warehouse')
  1985. $form->{description} = $form->quote( $form->{description} );
  1986. if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) {
  1987. $description =
  1988. qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
  1989. }
  1990. else {
  1991. $description =
  1992. qq|<input name=description size=60 value="$form->{description}">|;
  1993. }
  1994. $form->header;
  1995. print qq|
  1996. <body>
  1997. <form method=post action=$form->{script}>
  1998. <input type=hidden name=id value=$form->{id}>
  1999. <input type=hidden name=type value=warehouse>
  2000. <table width=100%>
  2001. <tr>
  2002. <th class=listtop colspan=2>$form->{title}</th>
  2003. </tr>
  2004. <tr height="5"></tr>
  2005. <tr>
  2006. <th align="right">| . $locale->text('Description') . qq|</th>
  2007. <td>$description</td>
  2008. </tr>
  2009. <tr>
  2010. <td colspan=2><hr size=3 noshade></td>
  2011. </tr>
  2012. </table>
  2013. |;
  2014. }
  2015. sub save_warehouse {
  2016. $form->isblank( "description", $locale->text('Description missing!') );
  2017. AM->save_warehouse( \%myconfig, \%$form );
  2018. $form->redirect( $locale->text('Warehouse saved!') );
  2019. }
  2020. sub delete_warehouse {
  2021. AM->delete_warehouse( \%myconfig, \%$form );
  2022. $form->redirect( $locale->text('Warehouse deleted!') );
  2023. }
  2024. sub yearend {
  2025. AM->earningsaccounts( \%myconfig, \%$form );
  2026. $chart = "";
  2027. for ( @{ $form->{chart} } ) {
  2028. $chart .= "<option>$_->{accno}--$_->{description}";
  2029. }
  2030. $form->{title} = $locale->text('Yearend');
  2031. $form->header;
  2032. print qq|
  2033. <body>
  2034. <form method=post action=$form->{script}>
  2035. <input type=hidden name=decimalplaces value=2>
  2036. <input type=hidden name=l_accno value=Y>
  2037. <table width=100%>
  2038. <tr>
  2039. <th class=listtop>$form->{title}</th>
  2040. </tr>
  2041. <tr height="5"></tr>
  2042. <tr>
  2043. <td>
  2044. <table>
  2045. <tr>
  2046. <th align="right">| . $locale->text('Yearend') . qq|</th>
  2047. <td><input class="date" name=todate size=11 title="$myconfig{dateformat}" value=$todate></td>
  2048. </tr>
  2049. <tr>
  2050. <th align="right">| . $locale->text('Reference') . qq|</th>
  2051. <td><input name=reference size=20 value="|
  2052. . $locale->text('Yearend')
  2053. . qq|"></td>
  2054. </tr>
  2055. <tr>
  2056. <th align="right">| . $locale->text('Description') . qq|</th>
  2057. <td><textarea name=description rows=3 cols=50 wrap=soft></textarea></td>
  2058. </tr>
  2059. <tr>
  2060. <th align="right">| . $locale->text('Retained Earnings') . qq|</th>
  2061. <td><select name=accno>$chart</select></td>
  2062. </tr>
  2063. <tr>
  2064. <th align="right">| . $locale->text('Method') . qq|</th>
  2065. <td><input name=method class=radio type=radio value=accrual checked>&nbsp;|
  2066. . $locale->text('Accrual')
  2067. . qq|&nbsp;<input name=method class=radio type=radio value=cash>&nbsp;|
  2068. . $locale->text('Cash')
  2069. . qq|</td>
  2070. </tr>
  2071. </table>
  2072. </td>
  2073. </tr>
  2074. </table>
  2075. <hr size=3 noshade>
  2076. <input type=hidden name=nextsub value=generate_yearend>
  2077. |;
  2078. $form->hide_form(qw(path login sessionid));
  2079. print qq|
  2080. <button class="submit" type="submit" name="action" value="continue">|
  2081. . $locale->text('Continue')
  2082. . qq|</button>|;
  2083. }
  2084. sub generate_yearend {
  2085. $form->isblank( "todate", $locale->text('Yearend date missing!') );
  2086. RP->yearend_statement( \%myconfig, \%$form );
  2087. $form->{transdate} = $form->{todate};
  2088. $earnings = 0;
  2089. $form->{rowcount} = 1;
  2090. foreach $key ( keys %{ $form->{I} } ) {
  2091. if ( $form->{I}{$key}{charttype} eq "A" ) {
  2092. $form->{"debit_$form->{rowcount}"} = $form->{I}{$key}{this};
  2093. $earnings += $form->{I}{$key}{this};
  2094. $form->{"accno_$form->{rowcount}"} = $key;
  2095. $form->{rowcount}++;
  2096. $ok = 1;
  2097. }
  2098. }
  2099. foreach $key ( keys %{ $form->{E} } ) {
  2100. if ( $form->{E}{$key}{charttype} eq "A" ) {
  2101. $form->{"credit_$form->{rowcount}"} = $form->{E}{$key}{this} * -1;
  2102. $earnings += $form->{E}{$key}{this};
  2103. $form->{"accno_$form->{rowcount}"} = $key;
  2104. $form->{rowcount}++;
  2105. $ok = 1;
  2106. }
  2107. }
  2108. if ( $earnings > 0 ) {
  2109. $form->{"credit_$form->{rowcount}"} = $earnings;
  2110. $form->{"accno_$form->{rowcount}"} = $form->{accno};
  2111. }
  2112. else {
  2113. $form->{"debit_$form->{rowcount}"} = $earnings * -1;
  2114. $form->{"accno_$form->{rowcount}"} = $form->{accno};
  2115. }
  2116. if ($ok) {
  2117. if ( AM->post_yearend( \%myconfig, \%$form ) ) {
  2118. $form->redirect( $locale->text('Yearend posted!') );
  2119. }
  2120. else {
  2121. $form->error( $locale->text('Yearend posting failed!') );
  2122. }
  2123. }
  2124. else {
  2125. $form->error('Nothing to do!');
  2126. }
  2127. }
  2128. sub company_logo {
  2129. $myconfig{address} =~ s/\\n/<br>/g;
  2130. $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
  2131. $form->{stylesheet} = $myconfig{stylesheet};
  2132. $form->{title} = $locale->text('About');
  2133. # create the logo screen
  2134. $form->header;
  2135. print qq|
  2136. <body>
  2137. <pre>
  2138. </pre>
  2139. <center>
  2140. <a href="http://www.ledgersmb.org/" target="_blank"><img src="images/ledgersmb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
  2141. <h1 class="login">| . $locale->text('Version') . qq| $form->{version}</h1>
  2142. <p>
  2143. |.$locale->text('Company').qq| :
  2144. <p>
  2145. <b>
  2146. $myconfig{company}
  2147. <br>$myconfig{address}
  2148. </b>
  2149. <p>
  2150. <table border=0>
  2151. <tr>
  2152. <th align="right">| . $locale->text('User') . qq|</th>
  2153. <td>$myconfig{name}</td>
  2154. </tr>
  2155. <tr>
  2156. <th align="right">| . $locale->text('Dataset') . qq|</th>
  2157. <td>$myconfig{dbname}</td>
  2158. </tr>
  2159. <tr>
  2160. <th align="right">| . $locale->text('Database Host') . qq|</th>
  2161. <td>$myconfig{dbhost}</td>
  2162. </tr>
  2163. </table>
  2164. </center>
  2165. </body>
  2166. </html>
  2167. |;
  2168. }
  2169. sub recurring_transactions {
  2170. # $locale->text('Day')
  2171. # $locale->text('Days')
  2172. # $locale->text('Month')
  2173. # $locale->text('Months')
  2174. # $locale->text('Week')
  2175. # $locale->text('Weeks')
  2176. # $locale->text('Year')
  2177. # $locale->text('Years')
  2178. $form->{stylesheet} = $myconfig{stylesheet};
  2179. $form->{title} = $locale->text('Recurring Transactions');
  2180. $column_header{id} = "";
  2181. AM->recurring_transactions( \%myconfig, \%$form );
  2182. $href = "$form->{script}?action=recurring_transactions";
  2183. for (qw(direction oldsort path login sessionid)) {
  2184. $href .= qq|&$_=$form->{$_}|;
  2185. }
  2186. $form->sort_order();
  2187. # create the logo screen
  2188. $form->header;
  2189. @column_index = qw(ndx reference description);
  2190. push @column_index,
  2191. qw(nextdate enddate id amount curr repeat howmany recurringemail recurringprint);
  2192. $column_header{reference} =
  2193. qq|<th><a class="listheading" href="$href&sort=reference">|
  2194. . $locale->text('Reference')
  2195. . q|</a></th>|;
  2196. $column_header{ndx} = q|<th class="listheading">&nbsp;</th>|;
  2197. $column_header{id} =
  2198. q|<th class="listheading">| . $locale->text('ID') . q|</th>|;
  2199. $column_header{description} =
  2200. q|<th class="listheading">| . $locale->text('Description') . q|</th>|;
  2201. $column_header{nextdate} =
  2202. qq|<th><a class="listheading" href="$href&sort=nextdate">|
  2203. . $locale->text('Next')
  2204. . q|</a></th>|;
  2205. $column_header{enddate} =
  2206. qq|<th><a class="listheading" href="$href&sort=enddate">|
  2207. . $locale->text('Ends')
  2208. . q|</a></th>|;
  2209. $column_header{amount} =
  2210. q|<th class="listheading">| . $locale->text('Amount') . q|</th>|;
  2211. $column_header{curr} = q|<th class="listheading">&nbsp;</th>|;
  2212. $column_header{repeat} =
  2213. q|<th class="listheading">| . $locale->text('Every') . q|</th>|;
  2214. $column_header{howmany} =
  2215. q|<th class="listheading">| . $locale->text('Times') . q|</th>|;
  2216. $column_header{recurringemail} =
  2217. q|<th class="listheading">| . $locale->text('E-mail') . q|</th>|;
  2218. $column_header{recurringprint} =
  2219. q|<th class="listheading">| . $locale->text('Print') . q|</th>|;
  2220. print qq|
  2221. <body>
  2222. <form method=post action=$form->{script}>
  2223. <table width=100%>
  2224. <tr>
  2225. <th class=listtop>$form->{title}</th>
  2226. </tr>
  2227. <tr height="5"></tr>
  2228. <tr>
  2229. <td>
  2230. <table width=100%>
  2231. <tr class="listheading">
  2232. |;
  2233. for (@column_index) { print "\n$column_header{$_}" }
  2234. print qq|
  2235. </tr>
  2236. |;
  2237. $i = 1;
  2238. $colspan = $#column_index + 1;
  2239. %tr = (
  2240. ar => $locale->text('AR'),
  2241. ap => $locale->text('AP'),
  2242. gl => $locale->text('GL'),
  2243. so => $locale->text('Sales Orders'),
  2244. po => $locale->text('Purchase Orders'),
  2245. );
  2246. %f = &formnames;
  2247. foreach $transaction ( sort keys %{ $form->{transactions} } ) {
  2248. my $transaction_count = scalar( @{ $form->{transactions}{$transaction} } );
  2249. print qq|
  2250. <tr>
  2251. <th class="listheading" colspan=$colspan>$tr{$transaction} ($transaction_count)</th>
  2252. </tr>
  2253. |;
  2254. foreach $ref ( @{ $form->{transactions}{$transaction} } ) {
  2255. for (@column_index) {
  2256. $column_data{$_} = "<td nowrap>$ref->{$_}</td>";
  2257. }
  2258. if ( $ref->{repeat} > 1 ) {
  2259. $unit = $locale->text( ucfirst $ref->{unit} );
  2260. $repeat = "$ref->{repeat} $unit";
  2261. }
  2262. else {
  2263. chop $ref->{unit};
  2264. $unit = $locale->text( ucfirst $ref->{unit} );
  2265. $repeat = $unit;
  2266. }
  2267. $column_data{ndx} = qq|<td></td>|;
  2268. if ( !$ref->{expired} ) {
  2269. if ( $ref->{overdue} <= 0 ) {
  2270. $k++;
  2271. $column_data{ndx} =
  2272. qq|<td nowrap><input name="ndx_$k" class=checkbox type=checkbox value=$ref->{id} checked></td>|;
  2273. }
  2274. }
  2275. $reference =
  2276. ( $ref->{reference} )
  2277. ? $ref->{reference}
  2278. : $locale->text('Next Number');
  2279. $column_data{reference} =
  2280. 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>|;
  2281. $module = "$ref->{module}.pl";
  2282. $type = "";
  2283. if ( $ref->{module} eq 'ar' ) {
  2284. $module = "is.pl" if $ref->{invoice};
  2285. $ref->{amount} /= $ref->{exchangerate};
  2286. }
  2287. if ( $ref->{module} eq 'ap' ) {
  2288. $module = "ir.pl" if $ref->{invoice};
  2289. $ref->{amount} /= $ref->{exchangerate};
  2290. }
  2291. if ( $ref->{module} eq 'oe' ) {
  2292. $type =
  2293. ( $ref->{vc} eq 'customer' )
  2294. ? "sales_order"
  2295. : "purchase_order";
  2296. }
  2297. $column_data{id} =
  2298. 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>|;
  2299. $column_data{repeat} = qq|<td align="right" nowrap>$repeat</td>|;
  2300. $column_data{howmany} =
  2301. qq|<td align="right" nowrap>|
  2302. . $form->format_amount( \%myconfig, $ref->{howmany} ) . "</td>";
  2303. $column_data{amount} =
  2304. qq|<td align="right" nowrap>|
  2305. . $form->format_amount( \%myconfig, $ref->{amount}, 2 ) . "</td>";
  2306. $column_data{recurringemail} = "<td nowrap>";
  2307. @f = split /:/, $ref->{recurringemail};
  2308. for ( 0 .. $#f ) {
  2309. $column_data{recurringemail} .= "$f{$f[$_]}<br>";
  2310. }
  2311. $column_data{recurringemail} .= "</td>";
  2312. $column_data{recurringprint} = "<td nowrap>";
  2313. @f = split /:/, $ref->{recurringprint};
  2314. for ( 0 .. $#f ) {
  2315. $column_data{recurringprint} .= "$f{$f[$_]}<br>";
  2316. }
  2317. $column_data{recurringprint} .= "</td>";
  2318. $j++;
  2319. $j %= 2;
  2320. print qq|
  2321. <tr class=listrow$j>
  2322. |;
  2323. for (@column_index) { print "\n$column_data{$_}" }
  2324. print qq|
  2325. </tr>
  2326. |;
  2327. }
  2328. }
  2329. print qq|
  2330. </tr>
  2331. </table>
  2332. </td>
  2333. </tr>
  2334. <tr>
  2335. <td><hr size=3 noshade></td>
  2336. </tr>
  2337. </table>
  2338. <input name=lastndx type=hidden value=$k>
  2339. |;
  2340. $form->hide_form(qw(path login sessionid));
  2341. print qq|
  2342. <button class="submit" type="submit" name="action" value="process_transactions">|
  2343. . $locale->text('Process Transactions')
  2344. . qq|</button>|
  2345. if $k;
  2346. if ( $form->{lynx} ) {
  2347. require "bin/menu.pl";
  2348. &menubar;
  2349. }
  2350. print qq|
  2351. </form>
  2352. </body>
  2353. </html>
  2354. |;
  2355. }
  2356. sub edit_recurring {
  2357. %links = (
  2358. ar => 'create_links',
  2359. ap => 'create_links',
  2360. gl => 'create_links',
  2361. is => 'invoice_links',
  2362. ir => 'invoice_links',
  2363. oe => 'order_links',
  2364. );
  2365. %prepare = (
  2366. is => 'prepare_invoice',
  2367. ir => 'prepare_invoice',
  2368. oe => 'prepare_order',
  2369. );
  2370. $form->{callback} =
  2371. "$form->{script}?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  2372. $form->{type} = "transaction";
  2373. if ( $form->{module} eq 'ar' ) {
  2374. if ( $form->{invoice} ) {
  2375. $form->{type} = "invoice";
  2376. $form->{module} = "is";
  2377. }
  2378. }
  2379. if ( $form->{module} eq 'ap' ) {
  2380. if ( $form->{invoice} ) {
  2381. $form->{type} = "invoice";
  2382. $form->{module} = "ir";
  2383. }
  2384. }
  2385. if ( $form->{module} eq 'oe' ) {
  2386. %tr = (
  2387. so => sales_order,
  2388. po => purchase_order,
  2389. );
  2390. $form->{type} = $tr{ $form->{transaction} };
  2391. }
  2392. $form->{script} = "$form->{module}.pl";
  2393. do "bin/$form->{script}";
  2394. &{ $links{ $form->{module} } };
  2395. # return if transaction doesn't exist
  2396. $form->redirect unless $form->{recurring};
  2397. if ( $prepare{ $form->{module} } ) {
  2398. &{ $prepare{ $form->{module} } };
  2399. }
  2400. $form->{selectformat} = qq|<option value="html">html\n|;
  2401. if ( ${LedgerSMB::Sysconfig::latex} ) {
  2402. $form->{selectformat} .= qq|
  2403. <option value="postscript">| . $locale->text('Postscript') . qq|
  2404. <option value="pdf">| . $locale->text('PDF');
  2405. }
  2406. &schedule;
  2407. }
  2408. sub process_transactions {
  2409. # save variables
  2410. my $pt = new Form;
  2411. for ( keys %$form ) { $pt->{$_} = $form->{$_} }
  2412. my $defaultprinter;
  2413. while ( my ( $key, $value ) = each %{LedgerSMB::Sysconfig::printer} ) {
  2414. if ( $value =~ /lpr/ ) {
  2415. $defaultprinter = $key;
  2416. last;
  2417. }
  2418. }
  2419. $myconfig{vclimit} = 0;
  2420. %f = &formnames;
  2421. for ( my $i = 1 ; $i <= $pt->{lastndx} ; $i++ ) {
  2422. if ( $pt->{"ndx_$i"} ) {
  2423. $id = $pt->{"ndx_$i"};
  2424. # process transaction
  2425. AM->recurring_details( \%myconfig, \%$pt, $id );
  2426. $header = $form->{header};
  2427. # reset $form
  2428. for ( keys %$form ) { delete $form->{$_}; }
  2429. for (qw(login path sessionid stylesheet timeout)) {
  2430. $form->{$_} = $pt->{$_};
  2431. }
  2432. $form->{id} = $id;
  2433. $form->{header} = $header;
  2434. $form->db_init(\%myconfig);
  2435. # post, print, email
  2436. if ( $pt->{arid} || $pt->{apid} || $pt->{oeid} ) {
  2437. if ( $pt->{arid} || $pt->{apid} ) {
  2438. if ( $pt->{arid} ) {
  2439. $form->{script} =
  2440. ( $pt->{invoice} ) ? "is.pl" : "ar.pl";
  2441. $form->{ARAP} = "AR";
  2442. $form->{module} = "ar";
  2443. $invfld = "sinumber";
  2444. }
  2445. else {
  2446. $form->{script} =
  2447. ( $pt->{invoice} ) ? "ir.pl" : "ap.pl";
  2448. $form->{ARAP} = "AP";
  2449. $form->{module} = "ap";
  2450. $invfld = "vinumber";
  2451. }
  2452. do "bin/$form->{script}";
  2453. if ( $pt->{invoice} ) {
  2454. &invoice_links;
  2455. &prepare_invoice;
  2456. for ( keys %$form ) {
  2457. $form->{$_} = $form->unquote( $form->{$_} );
  2458. }
  2459. }
  2460. else {
  2461. &create_links;
  2462. $form->{type} = "transaction";
  2463. for ( 1 .. $form->{rowcount} - 1 ) {
  2464. $form->{"amount_$_"} =
  2465. $form->format_amount( \%myconfig,
  2466. $form->{"amount_$_"}, 2 );
  2467. }
  2468. for ( 1 .. $form->{paidaccounts} ) {
  2469. $form->{"paid_$_"} =
  2470. $form->format_amount( \%myconfig,
  2471. $form->{"paid_$_"}, 2 );
  2472. }
  2473. }
  2474. delete $form->{"$form->{ARAP}_links"};
  2475. for (qw(acc_trans invoice_details)) { delete $form->{$_} }
  2476. for (
  2477. qw(department employee language month partsgroup project years)
  2478. )
  2479. {
  2480. delete $form->{"all_$_"};
  2481. }
  2482. $form->{invnumber} = $pt->{reference};
  2483. $form->{transdate} = $pt->{nextdate};
  2484. # tax accounts
  2485. $form->all_taxaccounts( \%myconfig, undef,
  2486. $form->{transdate} );
  2487. # calculate duedate
  2488. $form->{duedate} =
  2489. $form->add_date( \%myconfig, $form->{transdate},
  2490. $pt->{overdue}, "days" );
  2491. if ( $pt->{payment} ) {
  2492. # calculate date paid
  2493. for ( $j = 1 ; $j <= $form->{paidaccounts} ; $j++ ) {
  2494. $form->{"datepaid_$j"} =
  2495. $form->add_date( \%myconfig, $form->{transdate},
  2496. $pt->{paid}, "days" );
  2497. ( $form->{"$form->{ARAP}_paid_$j"} ) = split /--/,
  2498. $form->{"$form->{ARAP}_paid_$j"};
  2499. delete $form->{"cleared_$j"};
  2500. }
  2501. $form->{paidaccounts}++;
  2502. }
  2503. else {
  2504. $form->{paidaccounts} = -1;
  2505. }
  2506. for (qw(id recurring intnotes printed emailed queued)) {
  2507. delete $form->{$_};
  2508. }
  2509. ( $form->{ $form->{ARAP} } ) = split /--/,
  2510. $form->{ $form->{ARAP} };
  2511. $form->{invnumber} =
  2512. $form->update_defaults( \%myconfig, "$invfld" )
  2513. unless $form->{invnumber};
  2514. $form->{reference} = $form->{invnumber};
  2515. for (qw(invnumber reference)) {
  2516. $form->{$_} = $form->unquote( $form->{$_} );
  2517. }
  2518. if ( $pt->{invoice} ) {
  2519. if ( $pt->{arid} ) {
  2520. $form->info(
  2521. "\n"
  2522. . $locale->text(
  2523. 'Posting Sales Invoice [_1]',
  2524. $form->{invnumber}
  2525. )
  2526. );
  2527. $ok = IS->post_invoice( \%myconfig, \%$form );
  2528. }
  2529. else {
  2530. $form->info(
  2531. "\n"
  2532. . $locale->text(
  2533. 'Posting Vendor Invoice [_1]',
  2534. $form->{invnumber}
  2535. )
  2536. );
  2537. $ok = IR->post_invoice( \%myconfig, \%$form );
  2538. }
  2539. }
  2540. else {
  2541. if ( $pt->{arid} ) {
  2542. $form->info(
  2543. "\n"
  2544. . $locale->text(
  2545. 'Posting Transaction [_1]',
  2546. $form->{invnumber}
  2547. )
  2548. );
  2549. }
  2550. else {
  2551. $form->info(
  2552. "\n"
  2553. . $locale->text(
  2554. 'Posting Transaction [_1]',
  2555. $form->{invnumber}
  2556. )
  2557. );
  2558. }
  2559. $ok = AA->post_transaction( \%myconfig, \%$form );
  2560. }
  2561. $form->info( " ..... " . $locale->text('done') );
  2562. # print form
  2563. if ( ${LedgerSMB::Sysconfig::latex} && $ok ) {
  2564. $ok = &print_recurring( \%$pt, $defaultprinter );
  2565. }
  2566. &email_recurring( \%$pt ) if $ok;
  2567. }
  2568. else {
  2569. # order
  2570. $form->{script} = "oe.pl";
  2571. $form->{module} = "oe";
  2572. $ordnumber = "ordnumber";
  2573. if ( $pt->{customer_id} ) {
  2574. $form->{vc} = "customer";
  2575. $form->{type} = "sales_order";
  2576. $ordfld = "sonumber";
  2577. $flabel = $locale->text('Sales Order');
  2578. }
  2579. else {
  2580. $form->{vc} = "vendor";
  2581. $form->{type} = "purchase_order";
  2582. $ordfld = "ponumber";
  2583. $flabel = $locale->text('Purchase Order');
  2584. }
  2585. require "bin/$form->{script}";
  2586. &order_links;
  2587. &prepare_order;
  2588. for ( keys %$form ) {
  2589. $form->{$_} = $form->unquote( $form->{$_} );
  2590. }
  2591. $form->{$ordnumber} = $pt->{reference};
  2592. $form->{transdate} = $pt->{nextdate};
  2593. # calculate reqdate
  2594. $form->{reqdate} =
  2595. $form->add_date( \%myconfig, $form->{transdate},
  2596. $pt->{req}, "days" )
  2597. if $form->{reqdate};
  2598. for (qw(id recurring intnotes printed emailed queued)) {
  2599. delete $form->{$_};
  2600. }
  2601. for ( 1 .. $form->{rowcount} ) {
  2602. delete $form->{"orderitems_id_$_"};
  2603. }
  2604. $form->{$ordnumber} =
  2605. $form->update_defaults( \%myconfig, "$ordfld" )
  2606. unless $form->{$ordnumber};
  2607. $form->{reference} = $form->{$ordnumber};
  2608. for ( "$ordnumber", "reference" ) {
  2609. $form->{$_} = $form->unquote( $form->{$_} );
  2610. }
  2611. $form->{closed} = 0;
  2612. $form->info(
  2613. "\n"
  2614. . $locale->text(
  2615. 'Saving [_1] [_2]',
  2616. $flabel, $form->{$ordnumber}
  2617. )
  2618. );
  2619. if ( $ok = OE->save( \%myconfig, \%$form ) ) {
  2620. $form->info( " ..... " . $locale->text('done') );
  2621. }
  2622. else {
  2623. $form->info( " ..... " . $locale->text('failed') );
  2624. }
  2625. # print form
  2626. if ( ${LedgerSMB::Sysconfig::latex} && $ok ) {
  2627. &print_recurring( \%$pt, $defaultprinter );
  2628. }
  2629. &email_recurring( \%$pt );
  2630. }
  2631. }
  2632. else {
  2633. # GL transaction
  2634. GL->transaction( \%myconfig, \%$form );
  2635. $form->{reference} = $pt->{reference};
  2636. $form->{transdate} = $pt->{nextdate};
  2637. $j = 1;
  2638. foreach $ref ( @{ $form->{GL} } ) {
  2639. $form->{"accno_$j"} = "$ref->{accno}--$ref->{description}";
  2640. $form->{"projectnumber_$j"} =
  2641. "$ref->{projectnumber}--$ref->{project_id}"
  2642. if $ref->{project_id};
  2643. $form->{"fx_transaction_$j"} = $ref->{fx_transaction};
  2644. if ( $ref->{amount} < 0 ) {
  2645. $form->{"debit_$j"} = $ref->{amount} * -1;
  2646. }
  2647. else {
  2648. $form->{"credit_$j"} = $ref->{amount};
  2649. }
  2650. $j++;
  2651. }
  2652. $form->{rowcount} = $j;
  2653. for (qw(id recurring)) { delete $form->{$_} }
  2654. $form->info(
  2655. "\n"
  2656. . $locale->text(
  2657. 'Posting GL Transaction [_1]',
  2658. $form->{reference}
  2659. )
  2660. );
  2661. $ok = GL->post_transaction( \%myconfig, \%$form );
  2662. $form->info( " ..... " . $locale->text('done') );
  2663. }
  2664. AM->update_recurring( \%myconfig, \%$pt, $id ) if $ok;
  2665. }
  2666. }
  2667. $form->{callback} =
  2668. "am.pl?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&header=$form->{header}";
  2669. $form->redirect;
  2670. }
  2671. sub print_recurring {
  2672. my ( $pt, $defaultprinter ) = @_;
  2673. use List::Util qw(first);
  2674. my %f = &formnames;
  2675. my $ok = 1;
  2676. if ( $pt->{recurringprint} ) {
  2677. @f = split /:/, $pt->{recurringprint};
  2678. for ( $j = 0 ; $j <= $#f ; $j += 3 ) {
  2679. $media = $f[ $j + 2 ];
  2680. $media ||= $myconfig->{printer}
  2681. if ${LedgerSMB::Sysconfig::printer}{ $myconfig->{printer} };
  2682. $media ||= $defaultprinter;
  2683. $form->info( "\n"
  2684. . $locale->text('Printing') . " "
  2685. . $locale->text( $f{ $f[$j] } )
  2686. . " $form->{reference}" );
  2687. @a = (
  2688. "perl", "$form->{script}",
  2689. "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}"
  2690. );
  2691. $form->error( $locale->text('Invalid redirect') )
  2692. unless first { $_ eq $form->{script} }
  2693. @{LedgerSMB::Sysconfig::scripts};
  2694. $ok = !( system(@a) );
  2695. if ($ok) {
  2696. $form->info( " ..... " . $locale->text('done') );
  2697. }
  2698. else {
  2699. $form->info( " ..... " . $locale->text('failed') );
  2700. last;
  2701. }
  2702. }
  2703. }
  2704. $ok;
  2705. }
  2706. sub email_recurring {
  2707. my ($pt) = @_;
  2708. use List::Util qw(first);
  2709. my %f = &formnames;
  2710. my $ok = 1;
  2711. if ( $pt->{recurringemail} ) {
  2712. @f = split /:/, $pt->{recurringemail};
  2713. for ( $j = 0 ; $j <= $#f ; $j += 2 ) {
  2714. $form->info( "\n"
  2715. . $locale->text('Sending') . " "
  2716. . $locale->text( $f{ $f[$j] } )
  2717. . " $form->{reference}" );
  2718. # no email, bail out
  2719. if ( !$form->{email} ) {
  2720. $form->info(
  2721. " ..... " . $locale->text('E-mail address missing!') );
  2722. last;
  2723. }
  2724. $message = $form->escape( $pt->{message}, 1 );
  2725. @a = (
  2726. "perl", "$form->{script}",
  2727. "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"
  2728. );
  2729. $form->error( $locale->text('Invalid redirect') )
  2730. unless first { $_ eq $form->{script} }
  2731. @{LedgerSMB::Sysconfig::scripts};
  2732. $ok = !( system(@a) );
  2733. if ($ok) {
  2734. $form->info( " ..... " . $locale->text('done') );
  2735. }
  2736. else {
  2737. $form->info( " ..... " . $locale->text('failed') );
  2738. last;
  2739. }
  2740. }
  2741. }
  2742. $ok;
  2743. }
  2744. sub formnames {
  2745. # $locale->text('Transaction')
  2746. # $locale->text('Invoice')
  2747. # $locale->text('Credit Invoice')
  2748. # $locale->text('Debit Invoice')
  2749. # $locale->text('Packing List')
  2750. # $locale->text('Pick List')
  2751. # $locale->text('Sales Order')
  2752. # $locale->text('Work Order')
  2753. # $locale->text('Purchase Order')
  2754. # $locale->text('Bin List')
  2755. my %f = (
  2756. transaction => 'Transaction',
  2757. invoice => 'Invoice',
  2758. credit_invoice => 'Credit Invoice',
  2759. debit_invoice => 'Debit Invoice',
  2760. packing_list => 'Packing List',
  2761. pick_list => 'Pick List',
  2762. sales_order => 'Sales Order',
  2763. work_order => 'Work Order',
  2764. purchase_order => 'Purchase Order',
  2765. bin_list => 'Bin List',
  2766. );
  2767. %f;
  2768. }
  2769. sub continue { &{ $form->{nextsub} } }