summaryrefslogtreecommitdiff
path: root/bin/am.pl
blob: 88cae508cd03609e230d2fe107b283324d212998 (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. $form->{stylesheet} = $myconfig{stylesheet};
  1917. $form->{title} = $locale->text('Recurring Transactions');
  1918. $column_header{id} = "";
  1919. AM->recurring_transactions( \%myconfig, \%$form );
  1920. $href = "$form->{script}?action=recurring_transactions";
  1921. for (qw(direction oldsort path login sessionid)) {
  1922. $href .= qq|&$_=$form->{$_}|;
  1923. }
  1924. $form->sort_order();
  1925. # create the logo screen
  1926. $form->header;
  1927. @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. qq|<th><a class="listheading" href="$href&sort=reference">|
  1932. . $locale->text('Reference')
  1933. . q|</a></th>|;
  1934. $column_header{ndx} = q|<th class="listheading">&nbsp;</th>|;
  1935. $column_header{id} =
  1936. q|<th class="listheading">| . $locale->text('ID') . q|</th>|;
  1937. $column_header{description} =
  1938. q|<th class="listheading">| . $locale->text('Description') . q|</th>|;
  1939. $column_header{nextdate} =
  1940. qq|<th><a class="listheading" href="$href&sort=nextdate">|
  1941. . $locale->text('Next')
  1942. . q|</a></th>|;
  1943. $column_header{enddate} =
  1944. qq|<th><a class="listheading" href="$href&sort=enddate">|
  1945. . $locale->text('Ends')
  1946. . q|</a></th>|;
  1947. $column_header{amount} =
  1948. q|<th class="listheading">| . $locale->text('Amount') . q|</th>|;
  1949. $column_header{curr} = q|<th class="listheading">&nbsp;</th>|;
  1950. $column_header{repeat} =
  1951. q|<th class="listheading">| . $locale->text('Every') . q|</th>|;
  1952. $column_header{howmany} =
  1953. q|<th class="listheading">| . $locale->text('Times') . q|</th>|;
  1954. $column_header{recurringemail} =
  1955. q|<th class="listheading">| . $locale->text('E-mail') . q|</th>|;
  1956. $column_header{recurringprint} =
  1957. q|<th class="listheading">| . $locale->text('Print') . q|</th>|;
  1958. print qq|
  1959. <body>
  1960. <form method=post action=$form->{script}>
  1961. <table width=100%>
  1962. <tr>
  1963. <th class=listtop>$form->{title}</th>
  1964. </tr>
  1965. <tr height="5"></tr>
  1966. <tr>
  1967. <td>
  1968. <table width=100%>
  1969. <tr class="listheading">
  1970. |;
  1971. for (@column_index) { print "\n$column_header{$_}" }
  1972. print qq|
  1973. </tr>
  1974. |;
  1975. $i = 1;
  1976. $colspan = $#column_index + 1;
  1977. %tr = (
  1978. ar => $locale->text('AR'),
  1979. ap => $locale->text('AP'),
  1980. gl => $locale->text('GL'),
  1981. so => $locale->text('Sales Orders'),
  1982. po => $locale->text('Purchase Orders'),
  1983. );
  1984. %f = &formnames;
  1985. foreach $transaction ( sort keys %{ $form->{transactions} } ) {
  1986. my $transaction_count = scalar( @{ $form->{transactions}{$transaction} } );
  1987. print qq|
  1988. <tr>
  1989. <th class="listheading" colspan=$colspan>$tr{$transaction} ($transaction_count)</th>
  1990. </tr>
  1991. |;
  1992. foreach $ref ( @{ $form->{transactions}{$transaction} } ) {
  1993. for (@column_index) {
  1994. $column_data{$_} = "<td nowrap>$ref->{$_}</td>";
  1995. }
  1996. if ( $ref->{repeat} > 1 ) {
  1997. $unit = $locale->text( ucfirst $ref->{unit} );
  1998. $repeat = "$ref->{repeat} $unit";
  1999. }
  2000. else {
  2001. chop $ref->{unit};
  2002. $unit = $locale->text( ucfirst $ref->{unit} );
  2003. $repeat = $unit;
  2004. }
  2005. $column_data{ndx} = qq|<td></td>|;
  2006. if ( !$ref->{expired} ) {
  2007. if ( $ref->{overdue} <= 0 ) {
  2008. $k++;
  2009. $column_data{ndx} =
  2010. qq|<td nowrap><input name="ndx_$k" class=checkbox type=checkbox value=$ref->{id} checked></td>|;
  2011. }
  2012. }
  2013. $reference =
  2014. ( $ref->{reference} )
  2015. ? $ref->{reference}
  2016. : $locale->text('Next Number');
  2017. $column_data{reference} =
  2018. 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>|;
  2019. $module = "$ref->{module}.pl";
  2020. $type = "";
  2021. if ( $ref->{module} eq 'ar' ) {
  2022. $module = "is.pl" if $ref->{invoice};
  2023. $ref->{amount} /= $ref->{exchangerate};
  2024. }
  2025. if ( $ref->{module} eq 'ap' ) {
  2026. $module = "ir.pl" if $ref->{invoice};
  2027. $ref->{amount} /= $ref->{exchangerate};
  2028. }
  2029. if ( $ref->{module} eq 'oe' ) {
  2030. $type =
  2031. ( $ref->{vc} eq 'customer' )
  2032. ? "sales_order"
  2033. : "purchase_order";
  2034. }
  2035. $column_data{id} =
  2036. 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>|;
  2037. $column_data{repeat} = qq|<td align="right" nowrap>$repeat</td>|;
  2038. $column_data{howmany} =
  2039. qq|<td align="right" nowrap>|
  2040. . $form->format_amount( \%myconfig, $ref->{howmany} ) . "</td>";
  2041. $column_data{amount} =
  2042. qq|<td align="right" nowrap>|
  2043. . $form->format_amount( \%myconfig, $ref->{amount}, 2 ) . "</td>";
  2044. $column_data{recurringemail} = "<td nowrap>";
  2045. @f = split /:/, $ref->{recurringemail};
  2046. for ( 0 .. $#f ) {
  2047. $column_data{recurringemail} .= "$f{$f[$_]}<br>";
  2048. }
  2049. $column_data{recurringemail} .= "</td>";
  2050. $column_data{recurringprint} = "<td nowrap>";
  2051. @f = split /:/, $ref->{recurringprint};
  2052. for ( 0 .. $#f ) {
  2053. $column_data{recurringprint} .= "$f{$f[$_]}<br>";
  2054. }
  2055. $column_data{recurringprint} .= "</td>";
  2056. $j++;
  2057. $j %= 2;
  2058. print qq|
  2059. <tr class=listrow$j>
  2060. |;
  2061. for (@column_index) { print "\n$column_data{$_}" }
  2062. print qq|
  2063. </tr>
  2064. |;
  2065. }
  2066. }
  2067. print qq|
  2068. </tr>
  2069. </table>
  2070. </td>
  2071. </tr>
  2072. <tr>
  2073. <td><hr size=3 noshade></td>
  2074. </tr>
  2075. </table>
  2076. <input name=lastndx type=hidden value=$k>
  2077. |;
  2078. $form->hide_form(qw(path login sessionid));
  2079. print qq|
  2080. <button class="submit" type="submit" name="action" value="process_transactions">|
  2081. . $locale->text('Process Transactions')
  2082. . qq|</button>|
  2083. if $k;
  2084. if ( $form->{lynx} ) {
  2085. require "bin/menu.pl";
  2086. &menubar;
  2087. }
  2088. print qq|
  2089. </form>
  2090. </body>
  2091. </html>
  2092. |;
  2093. }
  2094. sub edit_recurring {
  2095. %links = (
  2096. ar => 'create_links',
  2097. ap => 'create_links',
  2098. gl => 'create_links',
  2099. is => 'invoice_links',
  2100. ir => 'invoice_links',
  2101. oe => 'order_links',
  2102. );
  2103. %prepare = (
  2104. is => 'prepare_invoice',
  2105. ir => 'prepare_invoice',
  2106. oe => 'prepare_order',
  2107. );
  2108. $form->{callback} =
  2109. "$form->{script}?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  2110. $form->{type} = "transaction";
  2111. if ( $form->{module} eq 'ar' ) {
  2112. if ( $form->{invoice} ) {
  2113. $form->{type} = "invoice";
  2114. $form->{module} = "is";
  2115. }
  2116. }
  2117. if ( $form->{module} eq 'ap' ) {
  2118. if ( $form->{invoice} ) {
  2119. $form->{type} = "invoice";
  2120. $form->{module} = "ir";
  2121. }
  2122. }
  2123. if ( $form->{module} eq 'oe' ) {
  2124. %tr = (
  2125. so => sales_order,
  2126. po => purchase_order,
  2127. );
  2128. $form->{type} = $tr{ $form->{transaction} };
  2129. }
  2130. $form->{script} = "$form->{module}.pl";
  2131. do "bin/$form->{script}";
  2132. &{ $links{ $form->{module} } };
  2133. # return if transaction doesn't exist
  2134. $form->redirect unless $form->{recurring};
  2135. if ( $prepare{ $form->{module} } ) {
  2136. &{ $prepare{ $form->{module} } };
  2137. }
  2138. $form->{selectformat} = qq|<option value="html">html\n|;
  2139. if ( ${LedgerSMB::Sysconfig::latex} ) {
  2140. $form->{selectformat} .= qq|
  2141. <option value="postscript">| . $locale->text('Postscript') . qq|
  2142. <option value="pdf">| . $locale->text('PDF');
  2143. }
  2144. &schedule;
  2145. }
  2146. sub process_transactions {
  2147. # save variables
  2148. my $pt = new Form;
  2149. for ( keys %$form ) { $pt->{$_} = $form->{$_} }
  2150. my $defaultprinter;
  2151. while ( my ( $key, $value ) = each %{LedgerSMB::Sysconfig::printer} ) {
  2152. if ( $value =~ /lpr/ ) {
  2153. $defaultprinter = $key;
  2154. last;
  2155. }
  2156. }
  2157. $myconfig{vclimit} = 0;
  2158. %f = &formnames;
  2159. for ( my $i = 1 ; $i <= $pt->{lastndx} ; $i++ ) {
  2160. if ( $pt->{"ndx_$i"} ) {
  2161. $id = $pt->{"ndx_$i"};
  2162. # process transaction
  2163. AM->recurring_details( \%myconfig, \%$pt, $id );
  2164. $header = $form->{header};
  2165. # reset $form
  2166. for ( keys %$form ) { delete $form->{$_}; }
  2167. for (qw(login path sessionid stylesheet timeout)) {
  2168. $form->{$_} = $pt->{$_};
  2169. }
  2170. $form->{id} = $id;
  2171. $form->{header} = $header;
  2172. $form->db_init(\%myconfig);
  2173. # post, print, email
  2174. if ( $pt->{arid} || $pt->{apid} || $pt->{oeid} ) {
  2175. if ( $pt->{arid} || $pt->{apid} ) {
  2176. if ( $pt->{arid} ) {
  2177. $form->{script} =
  2178. ( $pt->{invoice} ) ? "is.pl" : "ar.pl";
  2179. $form->{ARAP} = "AR";
  2180. $form->{module} = "ar";
  2181. $invfld = "sinumber";
  2182. }
  2183. else {
  2184. $form->{script} =
  2185. ( $pt->{invoice} ) ? "ir.pl" : "ap.pl";
  2186. $form->{ARAP} = "AP";
  2187. $form->{module} = "ap";
  2188. $invfld = "vinumber";
  2189. }
  2190. do "bin/$form->{script}";
  2191. if ( $pt->{invoice} ) {
  2192. &invoice_links;
  2193. &prepare_invoice;
  2194. for ( keys %$form ) {
  2195. $form->{$_} = $form->unquote( $form->{$_} );
  2196. }
  2197. }
  2198. else {
  2199. &create_links;
  2200. $form->{type} = "transaction";
  2201. for ( 1 .. $form->{rowcount} - 1 ) {
  2202. $form->{"amount_$_"} =
  2203. $form->format_amount( \%myconfig,
  2204. $form->{"amount_$_"}, 2 );
  2205. }
  2206. for ( 1 .. $form->{paidaccounts} ) {
  2207. $form->{"paid_$_"} =
  2208. $form->format_amount( \%myconfig,
  2209. $form->{"paid_$_"}, 2 );
  2210. }
  2211. }
  2212. delete $form->{"$form->{ARAP}_links"};
  2213. for (qw(acc_trans invoice_details)) { delete $form->{$_} }
  2214. for (
  2215. qw(department employee language month partsgroup project years)
  2216. )
  2217. {
  2218. delete $form->{"all_$_"};
  2219. }
  2220. $form->{invnumber} = $pt->{reference};
  2221. $form->{transdate} = $pt->{nextdate};
  2222. # tax accounts
  2223. $form->all_taxaccounts( \%myconfig, undef,
  2224. $form->{transdate} );
  2225. # calculate duedate
  2226. $form->{duedate} =
  2227. $form->add_date( \%myconfig, $form->{transdate},
  2228. $pt->{overdue}, "days" );
  2229. if ( $pt->{payment} ) {
  2230. # calculate date paid
  2231. for ( $j = 1 ; $j <= $form->{paidaccounts} ; $j++ ) {
  2232. $form->{"datepaid_$j"} =
  2233. $form->add_date( \%myconfig, $form->{transdate},
  2234. $pt->{paid}, "days" );
  2235. ( $form->{"$form->{ARAP}_paid_$j"} ) = split /--/,
  2236. $form->{"$form->{ARAP}_paid_$j"};
  2237. delete $form->{"cleared_$j"};
  2238. }
  2239. $form->{paidaccounts}++;
  2240. }
  2241. else {
  2242. $form->{paidaccounts} = -1;
  2243. }
  2244. for (qw(id recurring intnotes printed emailed queued)) {
  2245. delete $form->{$_};
  2246. }
  2247. ( $form->{ $form->{ARAP} } ) = split /--/,
  2248. $form->{ $form->{ARAP} };
  2249. $form->{invnumber} =
  2250. $form->update_defaults( \%myconfig, "$invfld" )
  2251. unless $form->{invnumber};
  2252. $form->{reference} = $form->{invnumber};
  2253. for (qw(invnumber reference)) {
  2254. $form->{$_} = $form->unquote( $form->{$_} );
  2255. }
  2256. if ( $pt->{invoice} ) {
  2257. if ( $pt->{arid} ) {
  2258. $form->info(
  2259. "\n"
  2260. . $locale->text(
  2261. 'Posting Sales Invoice [_1]',
  2262. $form->{invnumber}
  2263. )
  2264. );
  2265. $ok = IS->post_invoice( \%myconfig, \%$form );
  2266. }
  2267. else {
  2268. $form->info(
  2269. "\n"
  2270. . $locale->text(
  2271. 'Posting Vendor Invoice [_1]',
  2272. $form->{invnumber}
  2273. )
  2274. );
  2275. $ok = IR->post_invoice( \%myconfig, \%$form );
  2276. }
  2277. }
  2278. else {
  2279. if ( $pt->{arid} ) {
  2280. $form->info(
  2281. "\n"
  2282. . $locale->text(
  2283. 'Posting Transaction [_1]',
  2284. $form->{invnumber}
  2285. )
  2286. );
  2287. }
  2288. else {
  2289. $form->info(
  2290. "\n"
  2291. . $locale->text(
  2292. 'Posting Transaction [_1]',
  2293. $form->{invnumber}
  2294. )
  2295. );
  2296. }
  2297. $ok = AA->post_transaction( \%myconfig, \%$form );
  2298. }
  2299. $form->info( " ..... " . $locale->text('done') );
  2300. # print form
  2301. if ( ${LedgerSMB::Sysconfig::latex} && $ok ) {
  2302. $ok = &print_recurring( \%$pt, $defaultprinter );
  2303. }
  2304. &email_recurring( \%$pt ) if $ok;
  2305. }
  2306. else {
  2307. # order
  2308. $form->{script} = "oe.pl";
  2309. $form->{module} = "oe";
  2310. $ordnumber = "ordnumber";
  2311. if ( $pt->{customer_id} ) {
  2312. $form->{vc} = "customer";
  2313. $form->{type} = "sales_order";
  2314. $ordfld = "sonumber";
  2315. $flabel = $locale->text('Sales Order');
  2316. }
  2317. else {
  2318. $form->{vc} = "vendor";
  2319. $form->{type} = "purchase_order";
  2320. $ordfld = "ponumber";
  2321. $flabel = $locale->text('Purchase Order');
  2322. }
  2323. require "bin/$form->{script}";
  2324. &order_links;
  2325. &prepare_order;
  2326. for ( keys %$form ) {
  2327. $form->{$_} = $form->unquote( $form->{$_} );
  2328. }
  2329. $form->{$ordnumber} = $pt->{reference};
  2330. $form->{transdate} = $pt->{nextdate};
  2331. # calculate reqdate
  2332. $form->{reqdate} =
  2333. $form->add_date( \%myconfig, $form->{transdate},
  2334. $pt->{req}, "days" )
  2335. if $form->{reqdate};
  2336. for (qw(id recurring intnotes printed emailed queued)) {
  2337. delete $form->{$_};
  2338. }
  2339. for ( 1 .. $form->{rowcount} ) {
  2340. delete $form->{"orderitems_id_$_"};
  2341. }
  2342. $form->{$ordnumber} =
  2343. $form->update_defaults( \%myconfig, "$ordfld" )
  2344. unless $form->{$ordnumber};
  2345. $form->{reference} = $form->{$ordnumber};
  2346. for ( "$ordnumber", "reference" ) {
  2347. $form->{$_} = $form->unquote( $form->{$_} );
  2348. }
  2349. $form->{closed} = 0;
  2350. $form->info(
  2351. "\n"
  2352. . $locale->text(
  2353. 'Saving [_1] [_2]',
  2354. $flabel, $form->{$ordnumber}
  2355. )
  2356. );
  2357. if ( $ok = OE->save( \%myconfig, \%$form ) ) {
  2358. $form->info( " ..... " . $locale->text('done') );
  2359. }
  2360. else {
  2361. $form->info( " ..... " . $locale->text('failed') );
  2362. }
  2363. # print form
  2364. if ( ${LedgerSMB::Sysconfig::latex} && $ok ) {
  2365. &print_recurring( \%$pt, $defaultprinter );
  2366. }
  2367. &email_recurring( \%$pt );
  2368. }
  2369. }
  2370. else {
  2371. # GL transaction
  2372. GL->transaction( \%myconfig, \%$form );
  2373. $form->{reference} = $pt->{reference};
  2374. $form->{transdate} = $pt->{nextdate};
  2375. $j = 1;
  2376. foreach $ref ( @{ $form->{GL} } ) {
  2377. $form->{"accno_$j"} = "$ref->{accno}--$ref->{description}";
  2378. $form->{"projectnumber_$j"} =
  2379. "$ref->{projectnumber}--$ref->{project_id}"
  2380. if $ref->{project_id};
  2381. $form->{"fx_transaction_$j"} = $ref->{fx_transaction};
  2382. if ( $ref->{amount} < 0 ) {
  2383. $form->{"debit_$j"} = $ref->{amount} * -1;
  2384. }
  2385. else {
  2386. $form->{"credit_$j"} = $ref->{amount};
  2387. }
  2388. $j++;
  2389. }
  2390. $form->{rowcount} = $j;
  2391. for (qw(id recurring)) { delete $form->{$_} }
  2392. $form->info(
  2393. "\n"
  2394. . $locale->text(
  2395. 'Posting GL Transaction [_1]',
  2396. $form->{reference}
  2397. )
  2398. );
  2399. $ok = GL->post_transaction( \%myconfig, \%$form );
  2400. $form->info( " ..... " . $locale->text('done') );
  2401. }
  2402. AM->update_recurring( \%myconfig, \%$pt, $id ) if $ok;
  2403. }
  2404. }
  2405. $form->{callback} =
  2406. "am.pl?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&header=$form->{header}";
  2407. $form->redirect;
  2408. }
  2409. sub print_recurring {
  2410. my ( $pt, $defaultprinter ) = @_;
  2411. use List::Util qw(first);
  2412. my %f = &formnames;
  2413. my $ok = 1;
  2414. if ( $pt->{recurringprint} ) {
  2415. @f = split /:/, $pt->{recurringprint};
  2416. for ( $j = 0 ; $j <= $#f ; $j += 3 ) {
  2417. $media = $f[ $j + 2 ];
  2418. $media ||= $myconfig->{printer}
  2419. if ${LedgerSMB::Sysconfig::printer}{ $myconfig->{printer} };
  2420. $media ||= $defaultprinter;
  2421. $form->info( "\n"
  2422. . $locale->text('Printing') . " "
  2423. . $locale->text( $f{ $f[$j] } )
  2424. . " $form->{reference}" );
  2425. @a = (
  2426. "perl", "$form->{script}",
  2427. "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}"
  2428. );
  2429. $form->error( $locale->text('Invalid redirect') )
  2430. unless first { $_ eq $form->{script} }
  2431. @{LedgerSMB::Sysconfig::scripts};
  2432. $ok = !( system(@a) );
  2433. if ($ok) {
  2434. $form->info( " ..... " . $locale->text('done') );
  2435. }
  2436. else {
  2437. $form->info( " ..... " . $locale->text('failed') );
  2438. last;
  2439. }
  2440. }
  2441. }
  2442. $ok;
  2443. }
  2444. sub email_recurring {
  2445. my ($pt) = @_;
  2446. use List::Util qw(first);
  2447. my %f = &formnames;
  2448. my $ok = 1;
  2449. if ( $pt->{recurringemail} ) {
  2450. @f = split /:/, $pt->{recurringemail};
  2451. for ( $j = 0 ; $j <= $#f ; $j += 2 ) {
  2452. $form->info( "\n"
  2453. . $locale->text('Sending') . " "
  2454. . $locale->text( $f{ $f[$j] } )
  2455. . " $form->{reference}" );
  2456. # no email, bail out
  2457. if ( !$form->{email} ) {
  2458. $form->info(
  2459. " ..... " . $locale->text('E-mail address missing!') );
  2460. last;
  2461. }
  2462. $message = $form->escape( $pt->{message}, 1 );
  2463. @a = (
  2464. "perl", "$form->{script}",
  2465. "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"
  2466. );
  2467. $form->error( $locale->text('Invalid redirect') )
  2468. unless first { $_ eq $form->{script} }
  2469. @{LedgerSMB::Sysconfig::scripts};
  2470. $ok = !( system(@a) );
  2471. if ($ok) {
  2472. $form->info( " ..... " . $locale->text('done') );
  2473. }
  2474. else {
  2475. $form->info( " ..... " . $locale->text('failed') );
  2476. last;
  2477. }
  2478. }
  2479. }
  2480. $ok;
  2481. }
  2482. sub formnames {
  2483. # $locale->text('Transaction')
  2484. # $locale->text('Invoice')
  2485. # $locale->text('Credit Invoice')
  2486. # $locale->text('Debit Invoice')
  2487. # $locale->text('Packing List')
  2488. # $locale->text('Pick List')
  2489. # $locale->text('Sales Order')
  2490. # $locale->text('Work Order')
  2491. # $locale->text('Purchase Order')
  2492. # $locale->text('Bin List')
  2493. my %f = (
  2494. transaction => 'Transaction',
  2495. invoice => 'Invoice',
  2496. credit_invoice => 'Credit Invoice',
  2497. debit_invoice => 'Debit Invoice',
  2498. packing_list => 'Packing List',
  2499. pick_list => 'Pick List',
  2500. sales_order => 'Sales Order',
  2501. work_order => 'Work Order',
  2502. purchase_order => 'Purchase Order',
  2503. bin_list => 'Bin List',
  2504. );
  2505. %f;
  2506. }
  2507. sub continue { &{ $form->{nextsub} } }