summaryrefslogtreecommitdiff
path: root/bin/am.pl
blob: 9627cea52282b77e9efdc3bdc64322a7190ee514 (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. foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd))
  1442. {
  1443. $dateformat .=
  1444. ( $item eq $myconfig{dateformat} )
  1445. ? "<option selected>$item\n"
  1446. : "<option>$item\n";
  1447. }
  1448. my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00);
  1449. push @formats, '1 000.00';
  1450. foreach $item (@formats) {
  1451. $numberformat .=
  1452. ( $item eq $myconfig{numberformat} )
  1453. ? "<option selected>$item\n"
  1454. : "<option>$item\n";
  1455. }
  1456. for (qw(name company address signature)) {
  1457. $myconfig{$_} = $form->quote( $myconfig{$_} );
  1458. }
  1459. for (qw(address signature)) { $myconfig{$_} =~ s/\\n/\n/g }
  1460. %countrycodes = LedgerSMB::User->country_codes;
  1461. $countrycodes = '';
  1462. my $selectedcode =
  1463. ( $myconfig{countrycode} ) ? $myconfig{countrycode} : 'en';
  1464. foreach $key ( sort { $countrycodes{$a} cmp $countrycodes{$b} }
  1465. keys %countrycodes )
  1466. {
  1467. $countrycodes .=
  1468. ( $selectedcode eq $key )
  1469. ? "<option selected value=$key>$countrycodes{$key}\n"
  1470. : "<option value=$key>$countrycodes{$key}\n";
  1471. }
  1472. opendir CSS, "css/.";
  1473. @all = grep /.*\.css$/, readdir CSS;
  1474. closedir CSS;
  1475. foreach $item (@all) {
  1476. if ( $item eq $myconfig{stylesheet} ) {
  1477. $selectstylesheet .= qq|<option selected>$item\n|;
  1478. }
  1479. else {
  1480. $selectstylesheet .= qq|<option>$item\n|;
  1481. }
  1482. }
  1483. $selectstylesheet .= "<option>\n";
  1484. if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) {
  1485. $selectprinter = "<option>\n";
  1486. foreach $item ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  1487. if ( $myconfig{printer} eq $item ) {
  1488. $selectprinter .= qq|<option value="$item" selected>$item\n|;
  1489. }
  1490. else {
  1491. $selectprinter .= qq|<option value="$item">$item\n|;
  1492. }
  1493. }
  1494. $printer = qq|
  1495. <tr>
  1496. <th align="right">| . $locale->text('Printer') . qq|</th>
  1497. <td><select name=printer>$selectprinter</select></td>
  1498. </tr>
  1499. |;
  1500. }
  1501. $form->{title} =
  1502. $locale->text( 'Edit Preferences for [_1]', $form->{login} );
  1503. $form->header;
  1504. print qq|
  1505. <body>
  1506. <form method=post action=$form->{script}>
  1507. <input type=hidden name=old_password value="$myconfig{password}">
  1508. <input type=hidden name=type value=preferences>
  1509. <input type=hidden name=role value="$myconfig{role}">
  1510. <table width=100%>
  1511. <tr><th class=listtop>$form->{title}</th></tr>
  1512. <tr>
  1513. <td>
  1514. <table width=100%>
  1515. <tr valign=top>
  1516. <td>
  1517. <table>
  1518. <tr>
  1519. <th align="right">| . $locale->text('Name') . qq|</th>
  1520. <td><input name=name size=20 value="$myconfig{name}"></td>
  1521. </tr>
  1522. <tr>
  1523. <th align="right">| . $locale->text('E-mail') . qq|</th>
  1524. <td><input name=email size=35 value="$myconfig{email}"></td>
  1525. </tr>
  1526. <tr valign=top>
  1527. <th align="right">| . $locale->text('Signature') . qq|</th>
  1528. <td><textarea name=signature rows=3 cols=35>$myconfig{signature}</textarea></td>
  1529. </tr>
  1530. <tr>
  1531. <th align="right">| . $locale->text('Phone') . qq|</th>
  1532. <td><input name=tel size=14 value="$myconfig{tel}"></td>
  1533. </tr>
  1534. <tr>
  1535. <th align="right">| . $locale->text('Fax') . qq|</th>
  1536. <td><input name=fax size=14 value="$myconfig{fax}"></td>
  1537. </tr>
  1538. <tr>
  1539. <th align="right">| . $locale->text('Company') . qq|</th>
  1540. <td><input name=company size=35 value="$myconfig{company}"></td>
  1541. </tr>
  1542. <tr valign=top>
  1543. <th align="right">| . $locale->text('Address') . qq|</th>
  1544. <td><textarea name=address rows=4 cols=35>$myconfig{address}</textarea></td>
  1545. </tr>
  1546. </table>
  1547. </td>
  1548. <td>
  1549. <table>
  1550. <tr>
  1551. <th align="right">| . $locale->text('Password') . qq|</th>
  1552. <td><input type=password name=new_password size=10 value="$myconfig{password}"></td>
  1553. </tr>
  1554. <tr>
  1555. <th align="right">| . $locale->text('Confirm') . qq|</th>
  1556. <td><input type=password name=confirm_password size=10></td>
  1557. </tr>
  1558. <tr>
  1559. <th align="right">| . $locale->text('Date Format') . qq|</th>
  1560. <td><select name=dateformat>$dateformat</select></td>
  1561. </tr>
  1562. <tr>
  1563. <th align="right">| . $locale->text('Number Format') . qq|</th>
  1564. <td><select name=numberformat>$numberformat</select></td>
  1565. </tr>
  1566. <tr>
  1567. <th align="right">| . $locale->text('Dropdown Limit') . qq|</th>
  1568. <td><input name=vclimit size=10 value="$myconfig{vclimit}"></td>
  1569. </tr>
  1570. <tr>
  1571. <th align="right">| . $locale->text('Menu Width') . qq|</th>
  1572. <td><input name=menuwidth size=10 value="$myconfig{menuwidth}"></td>
  1573. </tr>
  1574. <tr>
  1575. <th align="right">| . $locale->text('Language') . qq|</th>
  1576. <td><select name=countrycode>$countrycodes</select></td>
  1577. </tr>
  1578. <tr>
  1579. <th align="right">| . $locale->text('Session Timeout') . qq|</th>
  1580. <td><input name=timeout size=10 value="$myconfig{timeout}"></td>
  1581. </tr>
  1582. <tr>
  1583. <th align="right">| . $locale->text('Stylesheet') . qq|</th>
  1584. <td><select name=usestylesheet>$selectstylesheet</select></td>
  1585. </tr>
  1586. $printer
  1587. </table>
  1588. </td>
  1589. </tr>
  1590. </table>
  1591. </td>
  1592. <tr>
  1593. <td><hr size=3 noshade></td>
  1594. </tr>
  1595. </table>
  1596. |;
  1597. $form->hide_form(qw(path login sessionid));
  1598. print qq|
  1599. <button type="submit" class="submit" name="action" value="save">|
  1600. . $locale->text('Save')
  1601. . qq|</button>|;
  1602. if ( $form->{lynx} ) {
  1603. require "bin/menu.pl";
  1604. &menubar;
  1605. }
  1606. print qq|
  1607. </form>
  1608. </body>
  1609. </html>
  1610. |;
  1611. }
  1612. sub save_defaults {
  1613. if ( AM->save_defaults( \%myconfig, \%$form ) ) {
  1614. $form->redirect( $locale->text('Defaults saved!') );
  1615. }
  1616. else {
  1617. $form->error( $locale->text('Cannot save defaults!') );
  1618. }
  1619. }
  1620. sub save_taxes {
  1621. if ( AM->save_taxes( \%myconfig, \%$form ) ) {
  1622. $form->redirect( $locale->text('Taxes saved!') );
  1623. }
  1624. else {
  1625. $form->error( $locale->text('Cannot save taxes!') );
  1626. }
  1627. }
  1628. sub save_preferences {
  1629. $form->{stylesheet} = $form->{usestylesheet};
  1630. if ( $form->{new_password} ne $form->{old_password} ) {
  1631. $form->error( $locale->text('Password does not match!') )
  1632. if $form->{new_password} ne $form->{confirm_password};
  1633. }
  1634. if ( AM->save_preferences( \%myconfig, \%$form ) ) {
  1635. $form->info( $locale->text('Preferences saved!') );
  1636. }
  1637. else {
  1638. $form->error( $locale->text('Cannot save preferences!') );
  1639. }
  1640. }
  1641. sub backup {
  1642. if ( $form->{media} eq 'email' ) {
  1643. $form->error(
  1644. $locale->text( 'No email address for [_1]', $myconfig{name} ) )
  1645. unless ( $myconfig{email} );
  1646. }
  1647. $SIG{INT} = 'IGNORE';
  1648. AM->backup(
  1649. \%myconfig, \%$form,
  1650. ${LedgerSMB::Sysconfig::userspath},
  1651. ${LedgerSMB::Sysconfig::gzip}
  1652. );
  1653. if ( $form->{media} eq 'email' ) {
  1654. $form->redirect(
  1655. $locale->text( 'Backup sent to [_1]', $myconfig{email} ) );
  1656. }
  1657. }
  1658. sub audit_control {
  1659. $form->{title} = $locale->text('Audit Control');
  1660. AM->closedto( \%myconfig, \%$form );
  1661. if ( $form->{revtrans} ) {
  1662. $checked{revtransY} = "checked";
  1663. }
  1664. else {
  1665. $checked{revtransN} = "checked";
  1666. }
  1667. if ( $form->{audittrail} ) {
  1668. $checked{audittrailY} = "checked";
  1669. }
  1670. else {
  1671. $checked{audittrailN} = "checked";
  1672. }
  1673. $form->header;
  1674. print qq|
  1675. <body>
  1676. <form method=post action=$form->{script}>
  1677. <input type=hidden name=path value=$form->{path}>
  1678. <input type=hidden name=login value=$form->{login}>
  1679. <input type=hidden name=sessionid value=$form->{sessionid}>
  1680. <table width=100%>
  1681. <tr><th class=listtop>$form->{title}</th></tr>
  1682. <tr height="5"></tr>
  1683. <tr>
  1684. <td>
  1685. <table>
  1686. <tr>
  1687. <th align="right">|
  1688. . $locale->text('Enforce transaction reversal for all dates')
  1689. . qq|</th>
  1690. <td><input name=revtrans class=radio type=radio value="1" $checked{revtransY}> |
  1691. . $locale->text('Yes')
  1692. . qq| <input name=revtrans class=radio type=radio value="0" $checked{revtransN}> |
  1693. . $locale->text('No')
  1694. . qq|</td>
  1695. </tr>
  1696. <tr>
  1697. <th align="right">| . $locale->text('Close Books up to') . qq|</th>
  1698. <td><input class="date" name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
  1699. </tr>
  1700. <tr>
  1701. <th align="right">| . $locale->text('Activate Audit trail') . qq|</th>
  1702. <td><input name=audittrail class=radio type=radio value="1" $checked{audittrailY}> |
  1703. . $locale->text('Yes')
  1704. . qq| <input name=audittrail class=radio type=radio value="0" $checked{audittrailN}> |
  1705. . $locale->text('No')
  1706. . qq|</td>
  1707. </tr><!-- SC: Disabling audit trail deletion
  1708. <tr>
  1709. <th align="right">| . $locale->text('Remove Audit trail up to') . qq|</th>
  1710. <td><input class="date" name=removeaudittrail size=11 title="$myconfig{dateformat}"></td>
  1711. </tr> -->
  1712. </table>
  1713. </td>
  1714. </tr>
  1715. </table>
  1716. <hr size=3 noshade>
  1717. <br>
  1718. <input type=hidden name=nextsub value=doclose>
  1719. <input type=hidden name=action value=continue>
  1720. <button type="submit" class="submit" name="action" value="continue">|
  1721. . $locale->text('Continue')
  1722. . qq|</button>
  1723. </form>
  1724. </body>
  1725. </html>
  1726. |;
  1727. }
  1728. sub doclose {
  1729. AM->closebooks( \%myconfig, \%$form );
  1730. if ( $form->{revtrans} ) {
  1731. $msg = $locale->text('Transaction reversal enforced for all dates');
  1732. }
  1733. else {
  1734. if ( $form->{closedto} ) {
  1735. $msg =
  1736. $locale->text('Transaction reversal enforced up to') . " "
  1737. . $locale->date( \%myconfig, $form->{closedto}, 1 );
  1738. }
  1739. else {
  1740. $msg = $locale->text('Books are open');
  1741. }
  1742. }
  1743. $msg .= "<p>";
  1744. if ( $form->{audittrail} ) {
  1745. $msg .= $locale->text('Audit trail enabled');
  1746. }
  1747. else {
  1748. $msg .= $locale->text('Audit trail disabled');
  1749. }
  1750. ##SC: Disabling audit trail deletion
  1751. ## $msg .= "<p>";
  1752. ## if ( $form->{removeaudittrail} ) {
  1753. ## $msg .=
  1754. ## $locale->text('Audit trail removed up to') . " "
  1755. ## . $locale->date( \%myconfig, $form->{removeaudittrail}, 1 );
  1756. ## }
  1757. $form->redirect($msg);
  1758. }
  1759. sub add_warehouse {
  1760. $form->{title} = "Add";
  1761. $form->{callback} =
  1762. "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  1763. unless $form->{callback};
  1764. &warehouse_header;
  1765. &form_footer;
  1766. }
  1767. sub edit_warehouse {
  1768. $form->{title} = "Edit";
  1769. AM->get_warehouse( \%myconfig, \%$form );
  1770. &warehouse_header;
  1771. &form_footer;
  1772. }
  1773. sub list_warehouse {
  1774. AM->warehouses( \%myconfig, \%$form );
  1775. $href =
  1776. "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1777. $form->sort_order();
  1778. $form->{callback} =
  1779. "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  1780. $callback = $form->escape( $form->{callback} );
  1781. $form->{title} = $locale->text('Warehouses');
  1782. @column_index = qw(description);
  1783. $column_header{description} =
  1784. qq|<th width=100%><a class="listheading" href=$href>|
  1785. . $locale->text('Description')
  1786. . qq|</a></th>|;
  1787. $form->header;
  1788. print qq|
  1789. <body>
  1790. <table width=100%>
  1791. <tr>
  1792. <th class=listtop>$form->{title}</th>
  1793. </tr>
  1794. <tr height="5"></tr>
  1795. <tr>
  1796. <td>
  1797. <table width=100%>
  1798. <tr class="listheading">
  1799. |;
  1800. for (@column_index) { print "$column_header{$_}\n" }
  1801. print qq|
  1802. </tr>
  1803. |;
  1804. foreach $ref ( @{ $form->{ALL} } ) {
  1805. $i++;
  1806. $i %= 2;
  1807. print qq|
  1808. <tr valign=top class=listrow$i>
  1809. |;
  1810. $column_data{description} =
  1811. 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>|;
  1812. for (@column_index) { print "$column_data{$_}\n" }
  1813. print qq|
  1814. </tr>
  1815. |;
  1816. }
  1817. print qq|
  1818. </table>
  1819. </td>
  1820. </tr>
  1821. <tr>
  1822. <td><hr size=3 noshade></td>
  1823. </tr>
  1824. </table>
  1825. <br>
  1826. <form method=post action=$form->{script}>
  1827. |;
  1828. $form->{type} = "warehouse";
  1829. $form->hide_form(qw(type callback path login sessionid));
  1830. print qq|
  1831. <button class="submit" type="submit" name="action" value="add_warehouse">|
  1832. . $locale->text('Add Warehouse')
  1833. . qq|</button>|;
  1834. if ( $form->{lynx} ) {
  1835. require "bin/menu.pl";
  1836. &menubar;
  1837. }
  1838. print qq|
  1839. </form>
  1840. </body>
  1841. </html>
  1842. |;
  1843. }
  1844. sub warehouse_header {
  1845. $form->{title} = $locale->text("$form->{title} Warehouse");
  1846. # $locale->text('Add Warehouse')
  1847. # $locale->text('Edit Warehouse')
  1848. $form->{description} = $form->quote( $form->{description} );
  1849. if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) {
  1850. $description =
  1851. qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
  1852. }
  1853. else {
  1854. $description =
  1855. qq|<input name=description size=60 value="$form->{description}">|;
  1856. }
  1857. $form->header;
  1858. print qq|
  1859. <body>
  1860. <form method=post action=$form->{script}>
  1861. <input type=hidden name=id value=$form->{id}>
  1862. <input type=hidden name=type value=warehouse>
  1863. <table width=100%>
  1864. <tr>
  1865. <th class=listtop colspan=2>$form->{title}</th>
  1866. </tr>
  1867. <tr height="5"></tr>
  1868. <tr>
  1869. <th align="right">| . $locale->text('Description') . qq|</th>
  1870. <td>$description</td>
  1871. </tr>
  1872. <tr>
  1873. <td colspan=2><hr size=3 noshade></td>
  1874. </tr>
  1875. </table>
  1876. |;
  1877. }
  1878. sub save_warehouse {
  1879. $form->isblank( "description", $locale->text('Description missing!') );
  1880. AM->save_warehouse( \%myconfig, \%$form );
  1881. $form->redirect( $locale->text('Warehouse saved!') );
  1882. }
  1883. sub delete_warehouse {
  1884. AM->delete_warehouse( \%myconfig, \%$form );
  1885. $form->redirect( $locale->text('Warehouse deleted!') );
  1886. }
  1887. sub yearend {
  1888. AM->earningsaccounts( \%myconfig, \%$form );
  1889. $chart = "";
  1890. for ( @{ $form->{chart} } ) {
  1891. $chart .= "<option>$_->{accno}--$_->{description}";
  1892. }
  1893. $form->{title} = $locale->text('Yearend');
  1894. $form->header;
  1895. print qq|
  1896. <body>
  1897. <form method=post action=$form->{script}>
  1898. <input type=hidden name=decimalplaces value=2>
  1899. <input type=hidden name=l_accno value=Y>
  1900. <table width=100%>
  1901. <tr>
  1902. <th class=listtop>$form->{title}</th>
  1903. </tr>
  1904. <tr height="5"></tr>
  1905. <tr>
  1906. <td>
  1907. <table>
  1908. <tr>
  1909. <th align="right">| . $locale->text('Yearend') . qq|</th>
  1910. <td><input class="date" name=todate size=11 title="$myconfig{dateformat}" value=$todate></td>
  1911. </tr>
  1912. <tr>
  1913. <th align="right">| . $locale->text('Reference') . qq|</th>
  1914. <td><input name=reference size=20 value="|
  1915. . $locale->text('Yearend')
  1916. . qq|"></td>
  1917. </tr>
  1918. <tr>
  1919. <th align="right">| . $locale->text('Description') . qq|</th>
  1920. <td><textarea name=description rows=3 cols=50 wrap=soft></textarea></td>
  1921. </tr>
  1922. <tr>
  1923. <th align="right">| . $locale->text('Retained Earnings') . qq|</th>
  1924. <td><select name=accno>$chart</select></td>
  1925. </tr>
  1926. <tr>
  1927. <th align="right">| . $locale->text('Method') . qq|</th>
  1928. <td><input name=method class=radio type=radio value=accrual checked>&nbsp;|
  1929. . $locale->text('Accrual')
  1930. . qq|&nbsp;<input name=method class=radio type=radio value=cash>&nbsp;|
  1931. . $locale->text('Cash')
  1932. . qq|</td>
  1933. </tr>
  1934. </table>
  1935. </td>
  1936. </tr>
  1937. </table>
  1938. <hr size=3 noshade>
  1939. <input type=hidden name=nextsub value=generate_yearend>
  1940. |;
  1941. $form->hide_form(qw(path login sessionid));
  1942. print qq|
  1943. <button class="submit" type="submit" name="action" value="continue">|
  1944. . $locale->text('Continue')
  1945. . qq|</button>|;
  1946. }
  1947. sub generate_yearend {
  1948. $form->isblank( "todate", $locale->text('Yearend date missing!') );
  1949. RP->yearend_statement( \%myconfig, \%$form );
  1950. $form->{transdate} = $form->{todate};
  1951. $earnings = 0;
  1952. $form->{rowcount} = 1;
  1953. foreach $key ( keys %{ $form->{I} } ) {
  1954. if ( $form->{I}{$key}{charttype} eq "A" ) {
  1955. $form->{"debit_$form->{rowcount}"} = $form->{I}{$key}{this};
  1956. $earnings += $form->{I}{$key}{this};
  1957. $form->{"accno_$form->{rowcount}"} = $key;
  1958. $form->{rowcount}++;
  1959. $ok = 1;
  1960. }
  1961. }
  1962. foreach $key ( keys %{ $form->{E} } ) {
  1963. if ( $form->{E}{$key}{charttype} eq "A" ) {
  1964. $form->{"credit_$form->{rowcount}"} = $form->{E}{$key}{this} * -1;
  1965. $earnings += $form->{E}{$key}{this};
  1966. $form->{"accno_$form->{rowcount}"} = $key;
  1967. $form->{rowcount}++;
  1968. $ok = 1;
  1969. }
  1970. }
  1971. if ( $earnings > 0 ) {
  1972. $form->{"credit_$form->{rowcount}"} = $earnings;
  1973. $form->{"accno_$form->{rowcount}"} = $form->{accno};
  1974. }
  1975. else {
  1976. $form->{"debit_$form->{rowcount}"} = $earnings * -1;
  1977. $form->{"accno_$form->{rowcount}"} = $form->{accno};
  1978. }
  1979. if ($ok) {
  1980. if ( AM->post_yearend( \%myconfig, \%$form ) ) {
  1981. $form->redirect( $locale->text('Yearend posted!') );
  1982. }
  1983. else {
  1984. $form->error( $locale->text('Yearend posting failed!') );
  1985. }
  1986. }
  1987. else {
  1988. $form->error('Nothing to do!');
  1989. }
  1990. }
  1991. sub company_logo {
  1992. $myconfig{address} =~ s/\\n/<br>/g;
  1993. $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
  1994. $form->{stylesheet} = $myconfig{stylesheet};
  1995. $form->{title} = $locale->text('About');
  1996. # create the logo screen
  1997. $form->header;
  1998. print qq|
  1999. <body>
  2000. <pre>
  2001. </pre>
  2002. <center>
  2003. <a href="http://www.ledgersmb.org/" target="_blank"><img src="images/ledgersmb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
  2004. <h1 class="login">| . $locale->text('Version') . qq| $form->{version}</h1>
  2005. <p>
  2006. |.$locale->text('Company').qq| :
  2007. <p>
  2008. <b>
  2009. $myconfig{company}
  2010. <br>$myconfig{address}
  2011. </b>
  2012. <p>
  2013. <table border=0>
  2014. <tr>
  2015. <th align="right">| . $locale->text('User') . qq|</th>
  2016. <td>$myconfig{name}</td>
  2017. </tr>
  2018. <tr>
  2019. <th align="right">| . $locale->text('Dataset') . qq|</th>
  2020. <td>$myconfig{dbname}</td>
  2021. </tr>
  2022. <tr>
  2023. <th align="right">| . $locale->text('Database Host') . qq|</th>
  2024. <td>$myconfig{dbhost}</td>
  2025. </tr>
  2026. </table>
  2027. </center>
  2028. </body>
  2029. </html>
  2030. |;
  2031. }
  2032. sub recurring_transactions {
  2033. # $locale->text('Day')
  2034. # $locale->text('Days')
  2035. # $locale->text('Month')
  2036. # $locale->text('Months')
  2037. # $locale->text('Week')
  2038. # $locale->text('Weeks')
  2039. # $locale->text('Year')
  2040. # $locale->text('Years')
  2041. $form->{stylesheet} = $myconfig{stylesheet};
  2042. $form->{title} = $locale->text('Recurring Transactions');
  2043. $column_header{id} = "";
  2044. AM->recurring_transactions( \%myconfig, \%$form );
  2045. $href = "$form->{script}?action=recurring_transactions";
  2046. for (qw(direction oldsort path login sessionid)) {
  2047. $href .= qq|&$_=$form->{$_}|;
  2048. }
  2049. $form->sort_order();
  2050. # create the logo screen
  2051. $form->header;
  2052. @column_index = qw(ndx reference description);
  2053. push @column_index,
  2054. qw(nextdate enddate id amount curr repeat howmany recurringemail recurringprint);
  2055. $column_header{reference} =
  2056. qq|<th><a class="listheading" href="$href&sort=reference">|
  2057. . $locale->text('Reference')
  2058. . q|</a></th>|;
  2059. $column_header{ndx} = q|<th class="listheading">&nbsp;</th>|;
  2060. $column_header{id} =
  2061. q|<th class="listheading">| . $locale->text('ID') . q|</th>|;
  2062. $column_header{description} =
  2063. q|<th class="listheading">| . $locale->text('Description') . q|</th>|;
  2064. $column_header{nextdate} =
  2065. qq|<th><a class="listheading" href="$href&sort=nextdate">|
  2066. . $locale->text('Next')
  2067. . q|</a></th>|;
  2068. $column_header{enddate} =
  2069. qq|<th><a class="listheading" href="$href&sort=enddate">|
  2070. . $locale->text('Ends')
  2071. . q|</a></th>|;
  2072. $column_header{amount} =
  2073. q|<th class="listheading">| . $locale->text('Amount') . q|</th>|;
  2074. $column_header{curr} = q|<th class="listheading">&nbsp;</th>|;
  2075. $column_header{repeat} =
  2076. q|<th class="listheading">| . $locale->text('Every') . q|</th>|;
  2077. $column_header{howmany} =
  2078. q|<th class="listheading">| . $locale->text('Times') . q|</th>|;
  2079. $column_header{recurringemail} =
  2080. q|<th class="listheading">| . $locale->text('E-mail') . q|</th>|;
  2081. $column_header{recurringprint} =
  2082. q|<th class="listheading">| . $locale->text('Print') . q|</th>|;
  2083. print qq|
  2084. <body>
  2085. <form method=post action=$form->{script}>
  2086. <table width=100%>
  2087. <tr>
  2088. <th class=listtop>$form->{title}</th>
  2089. </tr>
  2090. <tr height="5"></tr>
  2091. <tr>
  2092. <td>
  2093. <table width=100%>
  2094. <tr class="listheading">
  2095. |;
  2096. for (@column_index) { print "\n$column_header{$_}" }
  2097. print qq|
  2098. </tr>
  2099. |;
  2100. $i = 1;
  2101. $colspan = $#column_index + 1;
  2102. %tr = (
  2103. ar => $locale->text('AR'),
  2104. ap => $locale->text('AP'),
  2105. gl => $locale->text('GL'),
  2106. so => $locale->text('Sales Orders'),
  2107. po => $locale->text('Purchase Orders'),
  2108. );
  2109. %f = &formnames;
  2110. foreach $transaction ( sort keys %{ $form->{transactions} } ) {
  2111. my $transaction_count = scalar( @{ $form->{transactions}{$transaction} } );
  2112. print qq|
  2113. <tr>
  2114. <th class="listheading" colspan=$colspan>$tr{$transaction} ($transaction_count)</th>
  2115. </tr>
  2116. |;
  2117. foreach $ref ( @{ $form->{transactions}{$transaction} } ) {
  2118. for (@column_index) {
  2119. $column_data{$_} = "<td nowrap>$ref->{$_}</td>";
  2120. }
  2121. if ( $ref->{repeat} > 1 ) {
  2122. $unit = $locale->text( ucfirst $ref->{unit} );
  2123. $repeat = "$ref->{repeat} $unit";
  2124. }
  2125. else {
  2126. chop $ref->{unit};
  2127. $unit = $locale->text( ucfirst $ref->{unit} );
  2128. $repeat = $unit;
  2129. }
  2130. $column_data{ndx} = qq|<td></td>|;
  2131. if ( !$ref->{expired} ) {
  2132. if ( $ref->{overdue} <= 0 ) {
  2133. $k++;
  2134. $column_data{ndx} =
  2135. qq|<td nowrap><input name="ndx_$k" class=checkbox type=checkbox value=$ref->{id} checked></td>|;
  2136. }
  2137. }
  2138. $reference =
  2139. ( $ref->{reference} )
  2140. ? $ref->{reference}
  2141. : $locale->text('Next Number');
  2142. $column_data{reference} =
  2143. 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>|;
  2144. $module = "$ref->{module}.pl";
  2145. $type = "";
  2146. if ( $ref->{module} eq 'ar' ) {
  2147. $module = "is.pl" if $ref->{invoice};
  2148. $ref->{amount} /= $ref->{exchangerate};
  2149. }
  2150. if ( $ref->{module} eq 'ap' ) {
  2151. $module = "ir.pl" if $ref->{invoice};
  2152. $ref->{amount} /= $ref->{exchangerate};
  2153. }
  2154. if ( $ref->{module} eq 'oe' ) {
  2155. $type =
  2156. ( $ref->{vc} eq 'customer' )
  2157. ? "sales_order"
  2158. : "purchase_order";
  2159. }
  2160. $column_data{id} =
  2161. 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>|;
  2162. $column_data{repeat} = qq|<td align="right" nowrap>$repeat</td>|;
  2163. $column_data{howmany} =
  2164. qq|<td align="right" nowrap>|
  2165. . $form->format_amount( \%myconfig, $ref->{howmany} ) . "</td>";
  2166. $column_data{amount} =
  2167. qq|<td align="right" nowrap>|
  2168. . $form->format_amount( \%myconfig, $ref->{amount}, 2 ) . "</td>";
  2169. $column_data{recurringemail} = "<td nowrap>";
  2170. @f = split /:/, $ref->{recurringemail};
  2171. for ( 0 .. $#f ) {
  2172. $column_data{recurringemail} .= "$f{$f[$_]}<br>";
  2173. }
  2174. $column_data{recurringemail} .= "</td>";
  2175. $column_data{recurringprint} = "<td nowrap>";
  2176. @f = split /:/, $ref->{recurringprint};
  2177. for ( 0 .. $#f ) {
  2178. $column_data{recurringprint} .= "$f{$f[$_]}<br>";
  2179. }
  2180. $column_data{recurringprint} .= "</td>";
  2181. $j++;
  2182. $j %= 2;
  2183. print qq|
  2184. <tr class=listrow$j>
  2185. |;
  2186. for (@column_index) { print "\n$column_data{$_}" }
  2187. print qq|
  2188. </tr>
  2189. |;
  2190. }
  2191. }
  2192. print qq|
  2193. </tr>
  2194. </table>
  2195. </td>
  2196. </tr>
  2197. <tr>
  2198. <td><hr size=3 noshade></td>
  2199. </tr>
  2200. </table>
  2201. <input name=lastndx type=hidden value=$k>
  2202. |;
  2203. $form->hide_form(qw(path login sessionid));
  2204. print qq|
  2205. <button class="submit" type="submit" name="action" value="process_transactions">|
  2206. . $locale->text('Process Transactions')
  2207. . qq|</button>|
  2208. if $k;
  2209. if ( $form->{lynx} ) {
  2210. require "bin/menu.pl";
  2211. &menubar;
  2212. }
  2213. print qq|
  2214. </form>
  2215. </body>
  2216. </html>
  2217. |;
  2218. }
  2219. sub edit_recurring {
  2220. %links = (
  2221. ar => 'create_links',
  2222. ap => 'create_links',
  2223. gl => 'create_links',
  2224. is => 'invoice_links',
  2225. ir => 'invoice_links',
  2226. oe => 'order_links',
  2227. );
  2228. %prepare = (
  2229. is => 'prepare_invoice',
  2230. ir => 'prepare_invoice',
  2231. oe => 'prepare_order',
  2232. );
  2233. $form->{callback} =
  2234. "$form->{script}?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  2235. $form->{type} = "transaction";
  2236. if ( $form->{module} eq 'ar' ) {
  2237. if ( $form->{invoice} ) {
  2238. $form->{type} = "invoice";
  2239. $form->{module} = "is";
  2240. }
  2241. }
  2242. if ( $form->{module} eq 'ap' ) {
  2243. if ( $form->{invoice} ) {
  2244. $form->{type} = "invoice";
  2245. $form->{module} = "ir";
  2246. }
  2247. }
  2248. if ( $form->{module} eq 'oe' ) {
  2249. %tr = (
  2250. so => sales_order,
  2251. po => purchase_order,
  2252. );
  2253. $form->{type} = $tr{ $form->{transaction} };
  2254. }
  2255. $form->{script} = "$form->{module}.pl";
  2256. do "bin/$form->{script}";
  2257. &{ $links{ $form->{module} } };
  2258. # return if transaction doesn't exist
  2259. $form->redirect unless $form->{recurring};
  2260. if ( $prepare{ $form->{module} } ) {
  2261. &{ $prepare{ $form->{module} } };
  2262. }
  2263. $form->{selectformat} = qq|<option value="html">html\n|;
  2264. if ( ${LedgerSMB::Sysconfig::latex} ) {
  2265. $form->{selectformat} .= qq|
  2266. <option value="postscript">| . $locale->text('Postscript') . qq|
  2267. <option value="pdf">| . $locale->text('PDF');
  2268. }
  2269. &schedule;
  2270. }
  2271. sub process_transactions {
  2272. # save variables
  2273. my $pt = new Form;
  2274. for ( keys %$form ) { $pt->{$_} = $form->{$_} }
  2275. my $defaultprinter;
  2276. while ( my ( $key, $value ) = each %{LedgerSMB::Sysconfig::printer} ) {
  2277. if ( $value =~ /lpr/ ) {
  2278. $defaultprinter = $key;
  2279. last;
  2280. }
  2281. }
  2282. $myconfig{vclimit} = 0;
  2283. %f = &formnames;
  2284. for ( my $i = 1 ; $i <= $pt->{lastndx} ; $i++ ) {
  2285. if ( $pt->{"ndx_$i"} ) {
  2286. $id = $pt->{"ndx_$i"};
  2287. # process transaction
  2288. AM->recurring_details( \%myconfig, \%$pt, $id );
  2289. $header = $form->{header};
  2290. # reset $form
  2291. for ( keys %$form ) { delete $form->{$_}; }
  2292. for (qw(login path sessionid stylesheet timeout)) {
  2293. $form->{$_} = $pt->{$_};
  2294. }
  2295. $form->{id} = $id;
  2296. $form->{header} = $header;
  2297. $form->db_init(\%myconfig);
  2298. # post, print, email
  2299. if ( $pt->{arid} || $pt->{apid} || $pt->{oeid} ) {
  2300. if ( $pt->{arid} || $pt->{apid} ) {
  2301. if ( $pt->{arid} ) {
  2302. $form->{script} =
  2303. ( $pt->{invoice} ) ? "is.pl" : "ar.pl";
  2304. $form->{ARAP} = "AR";
  2305. $form->{module} = "ar";
  2306. $invfld = "sinumber";
  2307. }
  2308. else {
  2309. $form->{script} =
  2310. ( $pt->{invoice} ) ? "ir.pl" : "ap.pl";
  2311. $form->{ARAP} = "AP";
  2312. $form->{module} = "ap";
  2313. $invfld = "vinumber";
  2314. }
  2315. do "bin/$form->{script}";
  2316. if ( $pt->{invoice} ) {
  2317. &invoice_links;
  2318. &prepare_invoice;
  2319. for ( keys %$form ) {
  2320. $form->{$_} = $form->unquote( $form->{$_} );
  2321. }
  2322. }
  2323. else {
  2324. &create_links;
  2325. $form->{type} = "transaction";
  2326. for ( 1 .. $form->{rowcount} - 1 ) {
  2327. $form->{"amount_$_"} =
  2328. $form->format_amount( \%myconfig,
  2329. $form->{"amount_$_"}, 2 );
  2330. }
  2331. for ( 1 .. $form->{paidaccounts} ) {
  2332. $form->{"paid_$_"} =
  2333. $form->format_amount( \%myconfig,
  2334. $form->{"paid_$_"}, 2 );
  2335. }
  2336. }
  2337. delete $form->{"$form->{ARAP}_links"};
  2338. for (qw(acc_trans invoice_details)) { delete $form->{$_} }
  2339. for (
  2340. qw(department employee language month partsgroup project years)
  2341. )
  2342. {
  2343. delete $form->{"all_$_"};
  2344. }
  2345. $form->{invnumber} = $pt->{reference};
  2346. $form->{transdate} = $pt->{nextdate};
  2347. # tax accounts
  2348. $form->all_taxaccounts( \%myconfig, undef,
  2349. $form->{transdate} );
  2350. # calculate duedate
  2351. $form->{duedate} =
  2352. $form->add_date( \%myconfig, $form->{transdate},
  2353. $pt->{overdue}, "days" );
  2354. if ( $pt->{payment} ) {
  2355. # calculate date paid
  2356. for ( $j = 1 ; $j <= $form->{paidaccounts} ; $j++ ) {
  2357. $form->{"datepaid_$j"} =
  2358. $form->add_date( \%myconfig, $form->{transdate},
  2359. $pt->{paid}, "days" );
  2360. ( $form->{"$form->{ARAP}_paid_$j"} ) = split /--/,
  2361. $form->{"$form->{ARAP}_paid_$j"};
  2362. delete $form->{"cleared_$j"};
  2363. }
  2364. $form->{paidaccounts}++;
  2365. }
  2366. else {
  2367. $form->{paidaccounts} = -1;
  2368. }
  2369. for (qw(id recurring intnotes printed emailed queued)) {
  2370. delete $form->{$_};
  2371. }
  2372. ( $form->{ $form->{ARAP} } ) = split /--/,
  2373. $form->{ $form->{ARAP} };
  2374. $form->{invnumber} =
  2375. $form->update_defaults( \%myconfig, "$invfld" )
  2376. unless $form->{invnumber};
  2377. $form->{reference} = $form->{invnumber};
  2378. for (qw(invnumber reference)) {
  2379. $form->{$_} = $form->unquote( $form->{$_} );
  2380. }
  2381. if ( $pt->{invoice} ) {
  2382. if ( $pt->{arid} ) {
  2383. $form->info(
  2384. "\n"
  2385. . $locale->text(
  2386. 'Posting Sales Invoice [_1]',
  2387. $form->{invnumber}
  2388. )
  2389. );
  2390. $ok = IS->post_invoice( \%myconfig, \%$form );
  2391. }
  2392. else {
  2393. $form->info(
  2394. "\n"
  2395. . $locale->text(
  2396. 'Posting Vendor Invoice [_1]',
  2397. $form->{invnumber}
  2398. )
  2399. );
  2400. $ok = IR->post_invoice( \%myconfig, \%$form );
  2401. }
  2402. }
  2403. else {
  2404. if ( $pt->{arid} ) {
  2405. $form->info(
  2406. "\n"
  2407. . $locale->text(
  2408. 'Posting Transaction [_1]',
  2409. $form->{invnumber}
  2410. )
  2411. );
  2412. }
  2413. else {
  2414. $form->info(
  2415. "\n"
  2416. . $locale->text(
  2417. 'Posting Transaction [_1]',
  2418. $form->{invnumber}
  2419. )
  2420. );
  2421. }
  2422. $ok = AA->post_transaction( \%myconfig, \%$form );
  2423. }
  2424. $form->info( " ..... " . $locale->text('done') );
  2425. # print form
  2426. if ( ${LedgerSMB::Sysconfig::latex} && $ok ) {
  2427. $ok = &print_recurring( \%$pt, $defaultprinter );
  2428. }
  2429. &email_recurring( \%$pt ) if $ok;
  2430. }
  2431. else {
  2432. # order
  2433. $form->{script} = "oe.pl";
  2434. $form->{module} = "oe";
  2435. $ordnumber = "ordnumber";
  2436. if ( $pt->{customer_id} ) {
  2437. $form->{vc} = "customer";
  2438. $form->{type} = "sales_order";
  2439. $ordfld = "sonumber";
  2440. $flabel = $locale->text('Sales Order');
  2441. }
  2442. else {
  2443. $form->{vc} = "vendor";
  2444. $form->{type} = "purchase_order";
  2445. $ordfld = "ponumber";
  2446. $flabel = $locale->text('Purchase Order');
  2447. }
  2448. require "bin/$form->{script}";
  2449. &order_links;
  2450. &prepare_order;
  2451. for ( keys %$form ) {
  2452. $form->{$_} = $form->unquote( $form->{$_} );
  2453. }
  2454. $form->{$ordnumber} = $pt->{reference};
  2455. $form->{transdate} = $pt->{nextdate};
  2456. # calculate reqdate
  2457. $form->{reqdate} =
  2458. $form->add_date( \%myconfig, $form->{transdate},
  2459. $pt->{req}, "days" )
  2460. if $form->{reqdate};
  2461. for (qw(id recurring intnotes printed emailed queued)) {
  2462. delete $form->{$_};
  2463. }
  2464. for ( 1 .. $form->{rowcount} ) {
  2465. delete $form->{"orderitems_id_$_"};
  2466. }
  2467. $form->{$ordnumber} =
  2468. $form->update_defaults( \%myconfig, "$ordfld" )
  2469. unless $form->{$ordnumber};
  2470. $form->{reference} = $form->{$ordnumber};
  2471. for ( "$ordnumber", "reference" ) {
  2472. $form->{$_} = $form->unquote( $form->{$_} );
  2473. }
  2474. $form->{closed} = 0;
  2475. $form->info(
  2476. "\n"
  2477. . $locale->text(
  2478. 'Saving [_1] [_2]',
  2479. $flabel, $form->{$ordnumber}
  2480. )
  2481. );
  2482. if ( $ok = OE->save( \%myconfig, \%$form ) ) {
  2483. $form->info( " ..... " . $locale->text('done') );
  2484. }
  2485. else {
  2486. $form->info( " ..... " . $locale->text('failed') );
  2487. }
  2488. # print form
  2489. if ( ${LedgerSMB::Sysconfig::latex} && $ok ) {
  2490. &print_recurring( \%$pt, $defaultprinter );
  2491. }
  2492. &email_recurring( \%$pt );
  2493. }
  2494. }
  2495. else {
  2496. # GL transaction
  2497. GL->transaction( \%myconfig, \%$form );
  2498. $form->{reference} = $pt->{reference};
  2499. $form->{transdate} = $pt->{nextdate};
  2500. $j = 1;
  2501. foreach $ref ( @{ $form->{GL} } ) {
  2502. $form->{"accno_$j"} = "$ref->{accno}--$ref->{description}";
  2503. $form->{"projectnumber_$j"} =
  2504. "$ref->{projectnumber}--$ref->{project_id}"
  2505. if $ref->{project_id};
  2506. $form->{"fx_transaction_$j"} = $ref->{fx_transaction};
  2507. if ( $ref->{amount} < 0 ) {
  2508. $form->{"debit_$j"} = $ref->{amount} * -1;
  2509. }
  2510. else {
  2511. $form->{"credit_$j"} = $ref->{amount};
  2512. }
  2513. $j++;
  2514. }
  2515. $form->{rowcount} = $j;
  2516. for (qw(id recurring)) { delete $form->{$_} }
  2517. $form->info(
  2518. "\n"
  2519. . $locale->text(
  2520. 'Posting GL Transaction [_1]',
  2521. $form->{reference}
  2522. )
  2523. );
  2524. $ok = GL->post_transaction( \%myconfig, \%$form );
  2525. $form->info( " ..... " . $locale->text('done') );
  2526. }
  2527. AM->update_recurring( \%myconfig, \%$pt, $id ) if $ok;
  2528. }
  2529. }
  2530. $form->{callback} =
  2531. "am.pl?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&header=$form->{header}";
  2532. $form->redirect;
  2533. }
  2534. sub print_recurring {
  2535. my ( $pt, $defaultprinter ) = @_;
  2536. use List::Util qw(first);
  2537. my %f = &formnames;
  2538. my $ok = 1;
  2539. if ( $pt->{recurringprint} ) {
  2540. @f = split /:/, $pt->{recurringprint};
  2541. for ( $j = 0 ; $j <= $#f ; $j += 3 ) {
  2542. $media = $f[ $j + 2 ];
  2543. $media ||= $myconfig->{printer}
  2544. if ${LedgerSMB::Sysconfig::printer}{ $myconfig->{printer} };
  2545. $media ||= $defaultprinter;
  2546. $form->info( "\n"
  2547. . $locale->text('Printing') . " "
  2548. . $locale->text( $f{ $f[$j] } )
  2549. . " $form->{reference}" );
  2550. @a = (
  2551. "perl", "$form->{script}",
  2552. "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}"
  2553. );
  2554. $form->error( $locale->text('Invalid redirect') )
  2555. unless first { $_ eq $form->{script} }
  2556. @{LedgerSMB::Sysconfig::scripts};
  2557. $ok = !( system(@a) );
  2558. if ($ok) {
  2559. $form->info( " ..... " . $locale->text('done') );
  2560. }
  2561. else {
  2562. $form->info( " ..... " . $locale->text('failed') );
  2563. last;
  2564. }
  2565. }
  2566. }
  2567. $ok;
  2568. }
  2569. sub email_recurring {
  2570. my ($pt) = @_;
  2571. use List::Util qw(first);
  2572. my %f = &formnames;
  2573. my $ok = 1;
  2574. if ( $pt->{recurringemail} ) {
  2575. @f = split /:/, $pt->{recurringemail};
  2576. for ( $j = 0 ; $j <= $#f ; $j += 2 ) {
  2577. $form->info( "\n"
  2578. . $locale->text('Sending') . " "
  2579. . $locale->text( $f{ $f[$j] } )
  2580. . " $form->{reference}" );
  2581. # no email, bail out
  2582. if ( !$form->{email} ) {
  2583. $form->info(
  2584. " ..... " . $locale->text('E-mail address missing!') );
  2585. last;
  2586. }
  2587. $message = $form->escape( $pt->{message}, 1 );
  2588. @a = (
  2589. "perl", "$form->{script}",
  2590. "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"
  2591. );
  2592. $form->error( $locale->text('Invalid redirect') )
  2593. unless first { $_ eq $form->{script} }
  2594. @{LedgerSMB::Sysconfig::scripts};
  2595. $ok = !( system(@a) );
  2596. if ($ok) {
  2597. $form->info( " ..... " . $locale->text('done') );
  2598. }
  2599. else {
  2600. $form->info( " ..... " . $locale->text('failed') );
  2601. last;
  2602. }
  2603. }
  2604. }
  2605. $ok;
  2606. }
  2607. sub formnames {
  2608. # $locale->text('Transaction')
  2609. # $locale->text('Invoice')
  2610. # $locale->text('Credit Invoice')
  2611. # $locale->text('Debit Invoice')
  2612. # $locale->text('Packing List')
  2613. # $locale->text('Pick List')
  2614. # $locale->text('Sales Order')
  2615. # $locale->text('Work Order')
  2616. # $locale->text('Purchase Order')
  2617. # $locale->text('Bin List')
  2618. my %f = (
  2619. transaction => 'Transaction',
  2620. invoice => 'Invoice',
  2621. credit_invoice => 'Credit Invoice',
  2622. debit_invoice => 'Debit Invoice',
  2623. packing_list => 'Packing List',
  2624. pick_list => 'Pick List',
  2625. sales_order => 'Sales Order',
  2626. work_order => 'Work Order',
  2627. purchase_order => 'Purchase Order',
  2628. bin_list => 'Bin List',
  2629. );
  2630. %f;
  2631. }
  2632. sub continue { &{ $form->{nextsub} } }