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