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