/doc/plugins/teximg/

l='shortcut icon' href='/favicon.ico'/>
summaryrefslogtreecommitdiff
path: root/bin/am.pl
blob: 0cb0355c336752c4b12d31d56303a1dbc20ad57b (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. 1;
  41. # end of main
  42. sub add { &{"add_$form->{type}"} }
  43. sub edit { &{"edit_$form->{type}"} }
  44. sub save { &{"save_$form->{type}"} }
  45. sub delete { &{"delete_$form->{type}"} }
  46. sub save_as_new {
  47. delete $form->{id};
  48. &save;
  49. }
  50. sub add_account {
  51. $form->{title} = "Add";
  52. $form->{charttype} = "A";
  53. $form->{callback} =
  54. "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  55. unless $form->{callback};
  56. &account_header;
  57. &form_footer;
  58. }
  59. sub edit_account {
  60. $form->{title} = "Edit";
  61. $form->{accno} =~ s/\\'/'/g;
  62. $form->{accno} =~ s/\\\\/\\/g;
  63. AM->get_account( \%myconfig, \%$form );
  64. foreach my $item ( split( /:/, $form->{link} ) ) {
  65. $form->{$item} = "checked";
  66. }
  67. &account_header;
  68. &form_footer;
  69. }
  70. sub account_header {
  71. $form->{title} = $locale->text("$form->{title} Account");
  72. $checked{ $form->{charttype} } = "checked";
  73. $checked{contra} = "checked" if $form->{contra};
  74. $checked{"$form->{category}_"} = "checked";
  75. for (qw(accno description)) { $form->{$_} = $form->quote( $form->{$_} ) }
  76. # this is for our parser only!
  77. # type=submit $locale->text('Add Account')
  78. # type=submit $locale->text('Edit Account')
  79. $form->header;
  80. print qq|
  81. <body>
  82. <form method=post action=$form->{script}>
  83. <input type=hidden name=id value=$form->{id}>
  84. <input type=hidden name=type value=account>
  85. <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>
  86. <input type=hidden name=income_accno_id value=$form->{income_accno_id}>
  87. <input type=hidden name=expense_accno_id value=$form->{expense_accno_id}>
  88. <input type=hidden name=fxgain_accno_id values=$form->{fxgain_accno_id}>
  89. <input type=hidden name=fxloss_accno_id values=$form->{fxloss_accno_id}>
  90. <table border=0 width=100%>
  91. <tr>
  92. <th class=listtop>$form->{title}</th>
  93. </tr>
  94. <tr height="5"></tr>
  95. <tr valign=top>
  96. <td>
  97. <table>
  98. <tr>
  99. <th align="right">| . $locale->text('Account Number') . qq|</th>
  100. <td><input name=accno size=20 value="$form->{accno}"></td>
  101. </tr>
  102. <tr>
  103. <th align="right">| . $locale->text('Description') . qq|</th>
  104. <td><input name=description size=40 value="$form->{description}"></td>
  105. </tr>
  106. <tr>
  107. <th align="right">| . $locale->text('Account Type') . qq|</th>
  108. <td>
  109. <table>
  110. <tr valign=top>
  111. <td><input name=category type=radio class=radio value=A $checked{A_}>&nbsp;|
  112. . $locale->text('Asset')
  113. . qq|\n<br>
  114. <input name=category type=radio class=radio value=L $checked{L_}>&nbsp;|
  115. . $locale->text('Liability')
  116. . qq|\n<br>
  117. <input name=category type=radio class=radio value=Q $checked{Q_}>&nbsp;|
  118. . $locale->text('Equity')
  119. . qq|\n<br>
  120. <input name=category type=radio class=radio value=I $checked{I_}>&nbsp;|
  121. . $locale->text('Income')
  122. . qq|\n<br>
  123. <input name=category type=radio class=radio value=E $checked{E_}>&nbsp;|
  124. . $locale->text('Expense')
  125. . qq|</td>
  126. <td>
  127. <input name=contra class=checkbox type=checkbox value=1 $checked{contra}>&nbsp;|
  128. . $locale->text('Contra') . qq|
  129. </td>
  130. <td>
  131. <input name=charttype type=radio class=radio value="H" $checked{H}>&nbsp;|
  132. . $locale->text('Heading') . qq|<br>
  133. <input name=charttype type=radio class=radio value="A" $checked{A}>&nbsp;|
  134. . $locale->text('Account')
  135. . qq|</td>
  136. </tr>
  137. </table>
  138. </td>
  139. </tr>
  140. |;
  141. if ( $form->{charttype} eq "A" ) {
  142. print qq|
  143. <tr>
  144. <td colspan=2>
  145. <table>
  146. <tr>
  147. <th align=left>|
  148. . $locale->text('Is this a summary account to record')
  149. . qq|</th>
  150. <td>
  151. <input name=AR class=checkbox type=checkbox value=AR $form->{AR}>&nbsp;|
  152. . $locale->text('AR')
  153. . qq|&nbsp;<input name=AP class=checkbox type=checkbox value=AP $form->{AP}>&nbsp;|
  154. . $locale->text('AP')
  155. . qq|&nbsp;<input name=IC class=checkbox type=checkbox value=IC $form->{IC}>&nbsp;|
  156. . $locale->text('Inventory')
  157. . qq|</td>
  158. </tr>
  159. </table>
  160. </td>
  161. </tr>
  162. <tr>
  163. <th colspan=2>| . $locale->text('Include in drop-down menus') . qq|</th>
  164. </tr>
  165. <tr valign=top>
  166. <td colspan=2>
  167. <table width=100%>
  168. <tr>
  169. <th align=left>| . $locale->text('Receivables') . qq|</th>
  170. <th align=left>| . $locale->text('Payables') . qq|</th>
  171. <th align=left>| . $locale->text('Tracking Items') . qq|</th>
  172. <th align=left>| . $locale->text('Non-tracking Items') . qq|</th>
  173. </tr>
  174. <tr>
  175. <td>
  176. <input name=AR_amount class=checkbox type=checkbox value=AR_amount $form->{AR_amount}>&nbsp;|
  177. . $locale->text('Income')
  178. . qq|\n<br>
  179. <input name=AR_paid class=checkbox type=checkbox value=AR_paid $form->{AR_paid}>&nbsp;|
  180. . $locale->text('Payment')
  181. . qq|\n<br>
  182. <input name=AR_tax class=checkbox type=checkbox value=AR_tax $form->{AR_tax}>&nbsp;|
  183. . $locale->text('Tax') . qq|
  184. </td>
  185. <td>
  186. <input name=AP_amount class=checkbox type=checkbox value=AP_amount $form->{AP_amount}>&nbsp;|
  187. . $locale->text('Expense/Asset')
  188. . qq|\n<br>
  189. <input name=AP_paid class=checkbox type=checkbox value=AP_paid $form->{AP_paid}>&nbsp;|
  190. . $locale->text('Payment')
  191. . qq|\n<br>
  192. <input name=AP_tax class=checkbox type=checkbox value=AP_tax $form->{AP_tax}>&nbsp;|
  193. . $locale->text('Tax') . qq|
  194. </td>
  195. <td>
  196. <input name=IC_sale class=checkbox type=checkbox value=IC_sale $form->{IC_sale}>&nbsp;|
  197. . $locale->text('Income')
  198. . qq|\n<br>
  199. <input name=IC_cogs class=checkbox type=checkbox value=IC_cogs $form->{IC_cogs}>&nbsp;|
  200. . $locale->text('COGS')
  201. . qq|\n<br>
  202. <input name=IC_taxpart class=checkbox type=checkbox value=IC_taxpart $form->{IC_taxpart}>&nbsp;|
  203. . $locale->text('Tax') . qq|
  204. </td>
  205. <td>
  206. <input name=IC_income class=checkbox type=checkbox value=IC_income $form->{IC_income}>&nbsp;|
  207. . $locale->text('Income')
  208. . qq|\n<br>
  209. <input name=IC_expense class=checkbox type=checkbox value=IC_expense $form->{IC_expense}>&nbsp;|
  210. . $locale->text('Expense')
  211. . qq|\n<br>
  212. <input name=IC_taxservice class=checkbox type=checkbox value=IC_taxservice $form->{IC_taxservice}>&nbsp;|
  213. . $locale->text('Tax') . qq|
  214. </td>
  215. </tr>
  216. </table>
  217. </td>
  218. </tr>
  219. <tr>
  220. </tr>
  221. |;
  222. }
  223. print qq|
  224. <tr>
  225. <th align="right">| . $locale->text('GIFI') . qq|</th>
  226. <td><input name=gifi_accno size=9 value="$form->{gifi_accno}"></td>
  227. </tr>
  228. </table>
  229. </td>
  230. </tr>
  231. <tr>
  232. <td><hr size=3 noshade></td>
  233. </tr>
  234. </table>
  235. |;
  236. }
  237. sub form_footer {
  238. $form->hide_form(qw(callback path login sessionid));
  239. # type=submit $locale->text('Save')
  240. # type=submit $locale->text('Save as new')
  241. # type=submit $locale->text('Delete')
  242. %button = ();
  243. if ( $form->{id} ) {
  244. $button{'save'} =
  245. { ndx => 3, key => 'S', value => $locale->text('Save') };
  246. $button{'save_as_new'} =
  247. { ndx => 7, key => 'N', value => $locale->text('Save as new') };
  248. if ( $form->{orphaned} ) {
  249. $button{'delete'} =
  250. { ndx => 16, key => 'D', value => $locale->text('Delete') };
  251. }
  252. }
  253. else {
  254. $button{'save'} =
  255. { ndx => 3, key => 'S', value => $locale->text('Save') };
  256. }
  257. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  258. $form->print_button( \%button, $_ );
  259. }
  260. if ( $form->{lynx} ) {
  261. require "bin/menu.pl";
  262. &menubar;
  263. }
  264. print qq|
  265. </form>
  266. </body>
  267. </html>
  268. |;
  269. }
  270. sub save_account {
  271. $form->isblank( "accno", $locale->text('Account Number missing!') );
  272. $form->isblank( "category", $locale->text('Account Type missing!') );
  273. # check for conflicting accounts
  274. if ( $form->{AR} || $form->{AP} || $form->{IC} ) {
  275. $a = "";
  276. for (qw(AR AP IC)) { $a .= $form->{$_} }
  277. $form->error(
  278. $locale->text(
  279. 'Cannot set account for more than one of AR, AP or IC')
  280. ) if length $a > 2;
  281. for (
  282. 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)
  283. )
  284. {
  285. $form->error(
  286. "$form->{AR}$form->{AP}$form->{IC} "
  287. . $locale->text(
  288. 'account cannot be set to any other type of account')
  289. ) if $form->{$_};
  290. }
  291. }
  292. foreach $item ( "AR", "AP" ) {
  293. $i = 0;
  294. for ( "${item}_amount", "${item}_paid", "${item}_tax" ) {
  295. $i++ if $form->{$_};
  296. }
  297. $form->error(
  298. $locale->text( 'Cannot set multiple options for [_1]', $item ) )
  299. if $i > 1;
  300. }
  301. if ( AM->save_account( \%myconfig, \%$form ) ) {
  302. $form->redirect( $locale->text('Account saved!') );
  303. }
  304. else {
  305. $form->error( $locale->text('Cannot save account!') );
  306. }
  307. }
  308. sub list_account {
  309. CA->all_accounts( \%myconfig, \%$form );
  310. $form->{title} = $locale->text('Chart of Accounts');
  311. # construct callback
  312. $callback =
  313. "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  314. @column_index = qw(accno gifi_accno description debit credit link);
  315. $column_header{accno} =
  316. qq|<th class=listtop>| . $locale->text('Account') . qq|</a></th>|;
  317. $column_header{gifi_accno} =
  318. qq|<th class=listtop>| . $locale->text('GIFI') . qq|</a></th>|;
  319. $column_header{description} =
  320. qq|<th class=listtop>| . $locale->text('Description') . qq|</a></th>|;
  321. $column_header{debit} =
  322. qq|<th class=listtop>| . $locale->text('Debit') . qq|</a></th>|;
  323. $column_header{credit} =
  324. qq|<th class=listtop>| . $locale->text('Credit') . qq|</a></th>|;
  325. $column_header{link} =
  326. qq|<th class=listtop>| . $locale->text('Link') . qq|</a></th>|;
  327. $form->header;
  328. $colspan = $#column_index + 1;
  329. print qq|
  330. <body>
  331. <table width=100%>
  332. <tr>
  333. <th class=listtop colspan=$colspan>$form->{title}</th>
  334. </tr>
  335. <tr height="5"></tr>
  336. <tr class="listheading">
  337. |;
  338. for (@column_index) { print "$column_header{$_}\n" }
  339. print qq|
  340. </tr>
  341. |;
  342. # escape callback
  343. $callback = $form->escape($callback);
  344. foreach $ca ( @{ $form->{CA} } ) {
  345. $ca->{debit} = "&nbsp;";
  346. $ca->{credit} = "&nbsp;";
  347. if ( $ca->{amount} > 0 ) {
  348. $ca->{credit} =
  349. $form->format_amount( \%myconfig, $ca->{amount}, 2, "&nbsp;" );
  350. }
  351. if ( $ca->{amount} < 0 ) {
  352. $ca->{debit} =
  353. $form->format_amount( \%myconfig, -$ca->{amount}, 2, "&nbsp;" );
  354. }
  355. $ca->{link} =~ s/:/<br>/og;
  356. $gifi_accno = $form->escape( $ca->{gifi_accno} );
  357. if ( $ca->{charttype} eq "H" ) {
  358. print qq|<tr class="listheading">|;
  359. $column_data{accno} =
  360. qq|<th><a class="listheading" href="$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{accno}</a></th>|;
  361. $column_data{gifi_accno} =
  362. qq|<th class="listheading"><a href="$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{gifi_accno}</a>&nbsp;</th>|;
  363. $column_data{description} =
  364. qq|<th class="listheading">$ca->{description}&nbsp;</th>|;
  365. $column_data{debit} = qq|<th>&nbsp;</th>|;
  366. $column_data{credit} = qq| <th>&nbsp;</th>|;
  367. $column_data{link} = qq|<th>&nbsp;</th>|;
  368. }
  369. else {
  370. $i++;
  371. $i %= 2;
  372. print qq|
  373. <tr valign=top class="listrow$i">|;
  374. $column_data{accno} =
  375. qq|<td><a href="$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{accno}</a></td>|;
  376. $column_data{gifi_accno} =
  377. qq|<td><a href="$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{gifi_accno}</a>&nbsp;</td>|;
  378. $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
  379. $column_data{debit} = qq|<td align="right">$ca->{debit}</td>|;
  380. $column_data{credit} = qq|<td align="right">$ca->{credit}</td>|;
  381. $column_data{link} = qq|<td>$ca->{link}&nbsp;</td>|;
  382. }
  383. for (@column_index) { print "$column_data{$_}\n" }
  384. print "</tr>\n";
  385. }
  386. print qq|
  387. <tr><td colspan="$colspan"><hr size="3" noshade /></td></tr>
  388. </table>
  389. </body>
  390. </html>
  391. |;
  392. }
  393. sub delete_account {
  394. $form->{title} = $locale->text('Delete Account');
  395. foreach $id (
  396. qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
  397. )
  398. {
  399. if ( $form->{id} == $form->{$id} ) {
  400. $form->error( $locale->text('Cannot delete default account!') );
  401. }
  402. }
  403. if ( AM->delete_account( \%myconfig, \%$form ) ) {
  404. $form->redirect( $locale->text('Account deleted!') );
  405. }
  406. else {
  407. $form->error( $locale->text('Cannot delete account!') );
  408. }
  409. }
  410. sub list_gifi {
  411. @{ $form->{fields} } = qw(accno description);
  412. $form->{table} = "gifi";
  413. AM->gifi_accounts( \%myconfig, \%$form );
  414. $form->{title} = $locale->text('GIFI');
  415. # construct callback
  416. $callback =
  417. "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  418. @column_index = qw(accno description);
  419. $column_header{accno} =
  420. qq|<th class="listheading">| . $locale->text('GIFI') . qq|</a></th>|;
  421. $column_header{description} =
  422. qq|<th class="listheading">|
  423. . $locale->text('Description')
  424. . qq|</a></th>|;
  425. $form->header;
  426. $colspan = $#column_index + 1;
  427. print qq|
  428. <body>
  429. <table width=100%>
  430. <tr>
  431. <th class=listtop colspan=$colspan>$form->{title}</th>
  432. </tr>
  433. <tr height="5"></tr>
  434. <tr class="listheading">
  435. |;
  436. for (@column_index) { print "$column_header{$_}\n" }
  437. print qq|
  438. </tr>
  439. |;
  440. # escape callback
  441. $callback = $form->escape($callback);
  442. foreach $ca ( @{ $form->{ALL} } ) {
  443. $i++;
  444. $i %= 2;
  445. print qq|
  446. <tr valign=top class=listrow$i>|;
  447. $accno = $form->escape( $ca->{accno} );
  448. $column_data{accno} =
  449. qq|<td><a href=$form->{script}?action=edit_gifi&coa=1&accno=$accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ca->{accno}</td>|;
  450. $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
  451. for (@column_index) { print "$column_data{$_}\n" }
  452. print "</tr>\n";
  453. }
  454. print qq|
  455. <tr>
  456. <td colspan=$colspan><hr size=3 noshade></td>
  457. </tr>
  458. </table>
  459. </body>
  460. </html>
  461. |;
  462. }
  463. sub add_gifi {
  464. $form->{title} = "Add";
  465. # construct callback
  466. $form->{callback} =
  467. "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  468. $form->{coa} = 1;
  469. &gifi_header;
  470. &gifi_footer;
  471. }
  472. sub edit_gifi {
  473. $form->{title} = "Edit";
  474. AM->get_gifi( \%myconfig, \%$form );
  475. $form->error( $locale->text('Account does not exist!') )
  476. unless $form->{accno};
  477. &gifi_header;
  478. &gifi_footer;
  479. }
  480. sub gifi_header {
  481. $form->{title} = $locale->text("$form->{title} GIFI");
  482. # $locale->text('Add GIFI')
  483. # $locale->text('Edit GIFI')
  484. for (qw(accno description)) { $form->{$_} = $form->quote( $form->{$_} ) }
  485. $form->header;
  486. print qq|
  487. <body>
  488. <form method=post action=$form->{script}>
  489. <input type=hidden name=id value="$form->{accno}">
  490. <input type=hidden name=type value=gifi>
  491. <table width=100%>
  492. <tr>
  493. <th class=listtop>$form->{title}</th>
  494. </tr>
  495. <tr height="5"></tr>
  496. <tr>
  497. <td>
  498. <table>
  499. <tr>
  500. <th align="right">| . $locale->text('GIFI') . qq|</th>
  501. <td><input name=accno size=20 value="$form->{accno}"></td>
  502. </tr>
  503. <tr>
  504. <th align="right">| . $locale->text('Description') . qq|</th>
  505. <td><input name=description size=60 value="$form->{description}"></td>
  506. </tr>
  507. </table>
  508. </td>
  509. </tr>
  510. <tr>
  511. <td colspan=2><hr size=3 noshade></td>
  512. </tr>
  513. </table>
  514. |;
  515. }
  516. sub gifi_footer {
  517. $form->hide_form(qw(callback path login sessionid));
  518. # type=submit $locale->text('Save')
  519. # type=submit $locale->text('Copy to COA')
  520. # type=submit $locale->text('Delete')
  521. %button = ();
  522. $button{'save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
  523. if ( $form->{accno} ) {
  524. if ( $form->{orphaned} ) {
  525. $button{'delete'} =
  526. { ndx => 16, key => 'D', value => $locale->text('Delete') };
  527. }
  528. }
  529. if ( $form->{coa} ) {
  530. $button{'copy_to_coa'} =
  531. { ndx => 7, key => 'C', value => $locale->text('Copy to COA') };
  532. }
  533. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  534. $form->print_button( \%button, $_ );
  535. }
  536. if ( $form->{lynx} ) {
  537. require "bin/menu.pl";
  538. &menubar;
  539. }
  540. print qq|
  541. </form>
  542. </body>
  543. </html>
  544. |;
  545. }
  546. sub save_gifi {
  547. $form->isblank( "accno", $locale->text('GIFI missing!') );
  548. AM->save_gifi( \%myconfig, \%$form );
  549. $form->redirect( $locale->text('GIFI saved!') );
  550. }
  551. sub copy_to_coa {
  552. $form->isblank( "accno", $locale->text('GIFI missing!') );
  553. AM->save_gifi( \%myconfig, \%$form );
  554. delete $form->{id};
  555. $form->{gifi_accno} = $form->{accno};
  556. $form->{title} = "Add";
  557. $form->{charttype} = "A";
  558. &account_header;
  559. &form_footer;
  560. }
  561. sub delete_gifi {
  562. AM->delete_gifi( \%myconfig, \%$form );
  563. $form->redirect( $locale->text('GIFI deleted!') );
  564. }
  565. sub add_department {
  566. $form->{title} = "Add";
  567. $form->{role} = "P";
  568. $form->{callback} =
  569. "$form->{script}?action=add_department&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  570. unless $form->{callback};
  571. &department_header;
  572. &form_footer;
  573. }
  574. sub edit_department {
  575. $form->{title} = "Edit";
  576. AM->get_department( \%myconfig, \%$form );
  577. &department_header;
  578. &form_footer;
  579. }
  580. sub list_department {
  581. AM->departments( \%myconfig, \%$form );
  582. $href =
  583. "$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  584. $form->sort_order();
  585. $form->{callback} =
  586. "$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  587. $callback = $form->escape( $form->{callback} );
  588. $form->{title} = $locale->text('Departments');
  589. @column_index = qw(description cost profit);
  590. $column_header{description} =
  591. qq|<th width=90%><a class="listheading" href=$href>|
  592. . $locale->text('Description')
  593. . qq|</a></th>|;
  594. $column_header{cost} =
  595. qq|<th class="listheading" nowrap>|
  596. . $locale->text('Cost Center')
  597. . qq|</th>|;
  598. $column_header{profit} =
  599. qq|<th class="listheading" nowrap>|
  600. . $locale->text('Profit Center')
  601. . qq|</th>|;
  602. $form->header;
  603. print qq|
  604. <body>
  605. <table width=100%>
  606. <tr>
  607. <th class=listtop>$form->{title}</th>
  608. </tr>
  609. <tr height="5"></tr>
  610. <tr>
  611. <td>
  612. <table width=100%>
  613. <tr class="listheading">
  614. |;
  615. for (@column_index) { print "$column_header{$_}\n" }
  616. print qq|
  617. </tr>
  618. |;
  619. foreach $ref ( @{ $form->{ALL} } ) {
  620. $i++;
  621. $i %= 2;
  622. print qq|
  623. <tr valign=top class=listrow$i>
  624. |;
  625. $costcenter = ( $ref->{role} eq "C" ) ? "*" : "&nbsp;";
  626. $profitcenter = ( $ref->{role} eq "P" ) ? "*" : "&nbsp;";
  627. $column_data{description} =
  628. qq|<td><a href=$form->{script}?action=edit_department&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
  629. $column_data{cost} = qq|<td align=center>$costcenter</td>|;
  630. $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
  631. for (@column_index) { print "$column_data{$_}\n" }
  632. print qq|
  633. </tr>
  634. |;
  635. }
  636. print qq|
  637. </table>
  638. </td>
  639. </tr>
  640. <tr>
  641. <td><hr size=3 noshade></td>
  642. </tr>
  643. </table>
  644. <br>
  645. <form method=post action=$form->{script}>
  646. |;
  647. $form->{type} = "department";
  648. $form->hide_form(qw(type callback path login sessionid));
  649. print qq|
  650. <button class="submit" type="submit" name="action" value="add_department">|
  651. . $locale->text('Add Department')
  652. . qq|"</button>|;
  653. if ( $form->{lynx} ) {
  654. require "bin/menu.pl";
  655. &menubar;
  656. }
  657. print qq|
  658. </form>
  659. </body>
  660. </html>
  661. |;
  662. }
  663. sub department_header {
  664. $form->{title} = $locale->text("$form->{title} Department");
  665. # $locale->text('Add Department')
  666. # $locale->text('Edit Department')
  667. $form->{description} = $form->quote( $form->{description} );
  668. if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) {
  669. $description =
  670. qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
  671. }
  672. else {
  673. $description =
  674. qq|<input name=description size=60 value="$form->{description}">|;
  675. }
  676. $costcenter = "checked" if $form->{role} eq "C";
  677. $profitcenter = "checked" if $form->{role} eq "P";
  678. $form->header;
  679. print qq|
  680. <body>
  681. <form method=post action=$form->{script}>
  682. <input type=hidden name=id value=$form->{id}>
  683. <input type=hidden name=type value=department>
  684. <table width=100%>
  685. <tr>
  686. <th class=listtop colspan=2>$form->{title}</th>
  687. </tr>
  688. <tr height="5"></tr>
  689. <tr>
  690. <th align="right">| . $locale->text('Description') . qq|</th>
  691. <td>$description</td>
  692. </tr>
  693. <tr>
  694. <td></td>
  695. <td><input type=radio style=radio name=role value="C" $costcenter> |
  696. . $locale->text('Cost Center') . qq|
  697. <input type=radio style=radio name=role value="P" $profitcenter> |
  698. . $locale->text('Profit Center') . qq|
  699. </td>
  700. <tr>
  701. <td colspan=2><hr size=3 noshade></td>
  702. </tr>
  703. </table>
  704. |;
  705. }
  706. sub save_department {
  707. $form->isblank( "description", $locale->text('Description missing!') );
  708. AM->save_department( \%myconfig, \%$form );
  709. $form->redirect( $locale->text('Department saved!') );
  710. }
  711. sub delete_department {
  712. AM->delete_department( \%myconfig, \%$form );
  713. $form->redirect( $locale->text('Department deleted!') );
  714. }
  715. sub add_business {
  716. $form->{title} = "Add";
  717. $form->{callback} =
  718. "$form->{script}?action=add_business&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  719. unless $form->{callback};
  720. &business_header;
  721. &form_footer;
  722. }
  723. sub edit_business {
  724. $form->{title} = "Edit";
  725. AM->get_business( \%myconfig, \%$form );
  726. &business_header;
  727. $form->{orphaned} = 1;
  728. &form_footer;
  729. }
  730. sub list_business {
  731. AM->business( \%myconfig, \%$form );
  732. $href =
  733. "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  734. $form->sort_order();
  735. $form->{callback} =
  736. "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
  737. $callback = $form->escape( $form->{callback} );
  738. $form->{title} = $locale->text('Type of Business');
  739. @column_index = qw(description discount);
  740. $column_header{description} =
  741. qq|<th width=90%><a class="listheading" href=$href>|
  742. . $locale->text('Description')
  743. . qq|</a></th>|;
  744. $column_header{discount} =
  745. qq|<th class="listheading">| . $locale->text('Discount') . qq| %</th>|;
  746. $form->header;
  747. print qq|
  748. <body>
  749. <table width=100%>
  750. <tr>
  751. <th class=listtop>$form->{title}</th>
  752. </tr>
  753. <tr height="5"></tr>
  754. <tr>
  755. <td>
  756. <table width=100%>
  757. <tr class="listheading">
  758. |;
  759. for (@column_index) { print "$column_header{$_}\n" }
  760. print qq|
  761. </tr>
  762. |;
  763. foreach $ref ( @{ $form->{ALL} } ) {
  764. $i++;
  765. $i %= 2;
  766. print qq|
  767. <tr valign=top class=listrow$i>
  768. |;
  769. $discount =
  770. $form->format_amount( \%myconfig, $ref->{discount} * 100, 2,
  771. "&nbsp" );
  772. $column_data{description} =
  773. qq|<td><a href=$form->{script}?action=edit_business&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
  774. $column_data{discount} = qq|<td align="right">$discount</td>|;
  775. for (@column_index) { print "$column_data{$_}\n" }
  776. print qq|
  777. </tr>
  778. |;
  779. }
  780. print qq|
  781. </table>
  782. </td>
  783. </tr>
  784. <tr>
  785. <td><hr size=3 noshade></td>
  786. </tr>
  787. </table>
  788. <br>
  789. <form method=post action=$form->{script}>
  790. |;
  791. $form->{type} = "business";
  792. $form->hide_form(qw(type callback path login sessionid));
  793. print qq|
  794. <button class="submit" type="submit" name="action" value="add_business">|
  795. . $locale->text('Add Business')
  796. . qq|</button>|;
  797. if ( $form->{lynx} ) {
  798. require "bin/menu.pl";
  799. &menubar;
  800. }
  801. print qq|
  802. </form>
  803. </body>
  804. </html>
  805. |;
  806. }
  807. sub business_header {
  808. $form->{title} = $locale->text("$form->{title} Business");
  809. # $locale->text('Add Business')
  810. # $locale->text('Edit Business')
  811. $form->{description} = $form->quote( $form->{description} );
  812. $form->{discount} =