summaryrefslogtreecommitdiff
path: root/bin/arapprn.pl
blob: ceae64beaf423038e9a2d3fd1415f571b4e40657 (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # http://www.ledgersmb.org/
  4. #
  5. # Copyright (C) 2006
  6. # This work contains copyrighted information from a number of sources all used
  7. # with permission.
  8. #
  9. # This file contains source code included with or based on SQL-Ledger which
  10. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  11. # under the GNU General Public License version 2 or, at your option, any later
  12. # version. For a full list including contact information of contributors,
  13. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  14. #
  15. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  16. # Copyright (c) 2003
  17. #
  18. # Author: DWS Systems Inc.
  19. # Web: http://www.sql-ledger.org
  20. #
  21. #
  22. # This program is free software; you can redistribute it and/or modify
  23. # it under the terms of the GNU General Public License as published by
  24. # the Free Software Foundation; either version 2 of the License, or
  25. # (at your option) any later version.
  26. #
  27. # This program is distributed in the hope that it will be useful,
  28. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. # GNU General Public License for more details.
  31. # You should have received a copy of the GNU General Public License
  32. # along with this program; if not, write to the Free Software
  33. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  34. #======================================================================
  35. #
  36. # This file has not undergone any whitespace cleanup.
  37. #
  38. # printing routines for ar, ap
  39. #
  40. use Error qw(:try);
  41. use LedgerSMB::Template;
  42. # any custom scripts for this one
  43. if ( -f "bin/custom/arapprn.pl" ) {
  44. eval { require "bin/custom/arapprn.pl"; };
  45. }
  46. if ( -f "bin/custom/$form->{login}_arapprn.pl" ) {
  47. eval { require "bin/custom/$form->{login}_arapprn.pl"; };
  48. }
  49. 1;
  50. # end of main
  51. sub print {
  52. if ( $form->{media} !~ /screen/ ) {
  53. $form->error( $locale->text('Select postscript or PDF!') )
  54. if $form->{format} !~ /(postscript|pdf)/;
  55. $old_form = new Form;
  56. for ( keys %$form ) { $old_form->{$_} = $form->{$_} }
  57. }
  58. if ( $form->{formname} =~ /(check|receipt)/ ) {
  59. if ( $form->{media} eq 'screen' ) {
  60. $form->error( $locale->text('Select postscript or PDF!') )
  61. if $form->{format} !~ /(postscript|pdf)/;
  62. }
  63. }
  64. if ( !$form->{invnumber} ) {
  65. $invfld = 'sinumber';
  66. $invfld = 'vinumber' if $form->{ARAP} eq 'AP';
  67. $form->{invnumber} = $form->update_defaults( \%myconfig, $invfld );
  68. if ( $form->{media} eq 'screen' ) {
  69. if ( $form->{media} eq 'screen' ) {
  70. &update;
  71. exit;
  72. }
  73. }
  74. }
  75. if ( $form->{formname} =~ /(check|receipt)/ ) {
  76. if ( $form->{media} ne 'screen' ) {
  77. for (qw(action header)) { delete $form->{$_} }
  78. $form->{invtotal} = $form->{oldinvtotal};
  79. foreach $key ( keys %$form ) {
  80. $form->{$key} =~ s/&/%26/g;
  81. $form->{previousform} .= qq|$key=$form->{$key}&|;
  82. }
  83. chop $form->{previousform};
  84. $form->{previousform} = $form->escape( $form->{previousform}, 1 );
  85. }
  86. if ( $form->{paidaccounts} > 1 ) {
  87. if ( $form->{"paid_$form->{paidaccounts}"} ) {
  88. &update;
  89. exit;
  90. }
  91. elsif ( $form->{paidaccounts} > 2 ) {
  92. # select payment
  93. &select_payment;
  94. exit;
  95. }
  96. }
  97. else {
  98. $form->error( $locale->text('Nothing to print!') );
  99. }
  100. }
  101. if ( $filename = $queued{ $form->{formname} } ) {
  102. $form->{queued} =~ s/$form->{formname} $filename//;
  103. unlink "${LedgerSMB::Sysconfig::spool}/$filename";
  104. $filename =~ s/\..*$//g;
  105. }
  106. else {
  107. $filename = time;
  108. $filename .= $$;
  109. }
  110. $filename .= ( $form->{format} eq 'postscript' ) ? '.ps' : '.pdf';
  111. if ( $form->{media} ne 'screen' ) {
  112. $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
  113. $form{printmode} = '>';
  114. }
  115. $form->{queued} .= " $form->{formname} $filename";
  116. $form->{queued} =~ s/^ //;
  117. $printform = new Form;
  118. for ( keys %$form ) {
  119. $printform->{$_} = $form->{$_};
  120. }
  121. if ( $form->{printandpost} ) {
  122. &post;
  123. }
  124. else {
  125. &{"print_$form->{formname}"}( $old_form, 1 );
  126. }
  127. }
  128. sub print_check {
  129. my ( $old_form, $i ) = @_;
  130. $display_form =
  131. ( $form->{display_form} ) ? $form->{display_form} : "display_form";
  132. if ( $form->{"paid_$i"} ) {
  133. @a = ();
  134. if ( exists $form->{longformat} ) {
  135. $form->{"datepaid_$i"} =
  136. $locale->date( \%myconfig, $form->{"datepaid_$i"},
  137. $form->{longformat} );
  138. }
  139. push @a, "source_$i", "memo_$i";
  140. $form->format_string(@a);
  141. }
  142. $form->{amount} = $form->{"paid_$i"};
  143. if ( ( $form->{formname} eq 'check' && $form->{vc} eq 'customer' )
  144. || ( $form->{formname} eq 'receipt' && $form->{vc} eq 'vendor' ) )
  145. {
  146. $form->{amount} =~ s/-//g;
  147. }
  148. for (qw(datepaid source memo)) { $form->{$_} = $form->{"${_}_$i"} }
  149. &{"$form->{vc}_details"};
  150. @a = qw(name address1 address2 city state zipcode country);
  151. foreach $item (qw(invnumber ordnumber)) {
  152. $temp{$item} = $form->{$item};
  153. delete $form->{$item};
  154. push( @{ $form->{$item} }, $temp{$item} );
  155. }
  156. push( @{ $form->{invdate} }, $form->{transdate} );
  157. push(
  158. @{ $form->{due} },
  159. $form->format_amount( \%myconfig, $form->{oldinvtotal}, 2 )
  160. );
  161. push( @{ $form->{paid} }, $form->{"paid_$i"} );
  162. use LedgerSMB::CP;
  163. $c =
  164. CP->new( ( $form->{language_code} )
  165. ? $form->{language_code}
  166. : $myconfig{countrycode} );
  167. $c->init;
  168. ( $whole, $form->{decimal} ) = split /\./,
  169. $form->parse_amount( \%myconfig, $form->{amount} );
  170. $form->{decimal} .= "00";
  171. $form->{decimal} = substr( $form->{decimal}, 0, 2 );
  172. $form->{text_decimal} = $c->num2text( $form->{decimal} * 1 );
  173. $form->{text_amount} = $c->num2text($whole);
  174. $form->{integer_amount} = $form->format_amount( $myconfig, $whole );
  175. ( $form->{employee} ) = split /--/, $form->{employee};
  176. $form->{notes} =~ s/^\s+//g;
  177. push @a, "notes";
  178. for (qw(company address tel fax businessnumber)) {
  179. $form->{$_} = $myconfig{$_};
  180. }
  181. $form->{address} =~ s/\\n/\n/g;
  182. push @a,
  183. qw(company address tel fax businessnumber text_amount text_decimal);
  184. $form->format_string(@a);
  185. $form->{templates} = "$myconfig{templates}";
  186. $form->{IN} =
  187. ( $form->{formname} eq 'transaction' )
  188. ? lc $form->{ARAP} . "_$form->{formname}.html"
  189. : "$form->{formname}.html";
  190. if ( $form->{format} =~ /(postscript|pdf)/ ) {
  191. $form->{IN} =~ s/html$/tex/;
  192. }
  193. if ( $form->{media} eq 'queue' ) {
  194. # save status
  195. $form->update_status( \%myconfig );
  196. $form->{queued} = $form->{queued};
  197. %audittrail = (
  198. tablename => ($order) ? 'oe' : lc $ARAP,
  199. reference => $form->{"${inv}number"},
  200. formname => $form->{formname},
  201. action => 'queued',
  202. id => $form->{id}
  203. );
  204. $form->{audittrail} .=
  205. $form->audittrail( "", \%myconfig, \%audittrail );
  206. $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
  207. $form->{printmode} = '>';
  208. $form->{queued} .= " $form->{formname} $filename";
  209. $form->{queued} =~ s/^ //;
  210. }
  211. if ( $form->{media} !~ /(screen|queue)/ ) {
  212. %queued = split / /, $form->{queued};
  213. $form->{OUT} = "| ${LedgerSMB::Sysconfig::printer}{$form->{media}}";
  214. $form->{printmode} = '|-';
  215. if ( $form->{printed} !~ /$form->{formname}/ ) {
  216. $form->{printed} .= " $form->{formname}";
  217. $form->{printed} =~ s/^ //;
  218. $form->update_status( \%myconfig );
  219. }
  220. %audittrail = (
  221. tablename => lc $form->{ARAP},
  222. reference => $form->{invnumber},
  223. formname => $form->{formname},
  224. action => 'printed',
  225. id => $form->{id}
  226. );
  227. %status = ();
  228. for (qw(printed audittrail)) { $status{$_} = $form->{$_} }
  229. $status{audittrail} .=
  230. $form->audittrail( "", \%myconfig, \%audittrail );
  231. }
  232. $form->{fileid} = $invnumber;
  233. $form->{fileid} =~ s/(\s|\W)+//g;
  234. if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
  235. {
  236. my $template =
  237. LedgerSMB::Template->new( \%myconfig, $form->{'formname'}, 'HTML' );
  238. try {
  239. $template->render($form);
  240. $form->header;
  241. print $template->{'output'};
  242. exit;
  243. }
  244. catch Error::Simple with {
  245. my $E = shift;
  246. $form->error( $E->stacktrace );
  247. };
  248. }
  249. $form->parse_template( \%myconfig );
  250. if ( $form->{previousform} ) {
  251. $previousform = $form->unescape( $form->{previousform} );
  252. for ( keys %$form ) { delete $form->{$_} }
  253. foreach $item ( split /&/, $previousform ) {
  254. ( $key, $value ) = split /=/, $item, 2;
  255. $value =~ s/%26/&/g;
  256. $form->{$key} = $value;
  257. }
  258. for (qw(exchangerate creditlimit creditremaining)) {
  259. $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} );
  260. }
  261. for ( 1 .. $form->{rowcount} ) {
  262. $form->{"amount_$_"} =
  263. $form->parse_amount( \%myconfig, $form->{"amount_$_"} );
  264. }
  265. for ( split / /, $form->{taxaccounts} ) {
  266. $form->{"tax_$_"} =
  267. $form->parse_amount( \%myconfig, $form->{"tax_$_"} );
  268. }
  269. for $i ( 1 .. $form->{paidaccounts} ) {
  270. for (qw(paid exchangerate)) {
  271. $form->{"${_}_$i"} =
  272. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  273. }
  274. }
  275. for (qw(printed audittrail)) { $form->{$_} = $status{$_} }
  276. &{"$display_form"};
  277. }
  278. }
  279. sub print_receipt {
  280. my ( $old_form, $i ) = @_;
  281. &print_check( $old_form, $i );
  282. }
  283. sub print_transaction {
  284. my ($old_form) = @_;
  285. $display_form =
  286. ( $form->{display_form} ) ? $form->{display_form} : "display_form";
  287. &{"$form->{vc}_details"};
  288. @a = qw(name address1 address2 city state zipcode country);
  289. $form->{invtotal} = 0;
  290. foreach $i ( 1 .. $form->{rowcount} - 1 ) {
  291. ( $form->{tempaccno}, $form->{tempaccount} ) = split /--/,
  292. $form->{"$form->{ARAP}_amount_$i"};
  293. ( $form->{tempprojectnumber} ) = split /--/,
  294. $form->{"projectnumber_$i"};
  295. $form->{tempdescription} = $form->{"description_$i"};
  296. $form->format_string(
  297. qw(tempaccno tempaccount tempprojectnumber tempdescription));
  298. push( @{ $form->{accno} }, $form->{tempaccno} );
  299. push( @{ $form->{account} }, $form->{tempaccount} );
  300. push( @{ $form->{description} }, $form->{tempdescription} );
  301. push( @{ $form->{projectnumber} }, $form->{tempprojectnumber} );
  302. push( @{ $form->{amount} }, $form->{"amount_$i"} );
  303. $form->{subtotal} +=
  304. $form->parse_amount( \%myconfig, $form->{"amount_$i"} );
  305. }
  306. foreach $accno ( split / /, $form->{taxaccounts} ) {
  307. if ( $form->{"tax_$accno"} ) {
  308. $form->format_string("${accno}_description");
  309. $tax += $form->parse_amount( \%myconfig, $form->{"tax_$accno"} );
  310. $form->{"${accno}_tax"} = $form->{"tax_$accno"};
  311. push( @{ $form->{tax} }, $form->{"tax_$accno"} );
  312. push(
  313. @{ $form->{taxdescription} },
  314. $form->{"${accno}_description"}
  315. );
  316. $form->{"${accno}_taxrate"} =
  317. $form->format_amount( $myconfig, $form->{"${accno}_rate"} * 100 );
  318. push( @{ $form->{taxrate} }, $form->{"${accno}_taxrate"} );
  319. push( @{ $form->{taxnumber} }, $form->{"${accno}_taxnumber"} );
  320. }
  321. }
  322. $tax = 0 if $form->{taxincluded};
  323. push @a, $form->{ARAP};
  324. $form->format_string(@a);
  325. $form->{paid} = 0;
  326. for $i ( 1 .. $form->{paidaccounts} - 1 ) {
  327. if ( $form->{"paid_$i"} ) {
  328. @a = ();
  329. $form->{paid} +=
  330. $form->parse_amount( \%myconfig, $form->{"paid_$i"} );
  331. if ( exists $form->{longformat} ) {
  332. $form->{"datepaid_$i"} =
  333. $locale->date( \%myconfig, $form->{"datepaid_$i"},
  334. $form->{longformat} );
  335. }
  336. push @a, "$form->{ARAP}_paid_$i", "source_$i", "memo_$i";
  337. $form->format_string(@a);
  338. ( $accno, $account ) = split /--/, $form->{"$form->{ARAP}_paid_$i"};
  339. push( @{ $form->{payment} }, $form->{"paid_$i"} );
  340. push( @{ $form->{paymentdate} }, $form->{"datepaid_$i"} );
  341. push( @{ $form->{paymentaccount} }, $account );
  342. push( @{ $form->{paymentsource} }, $form->{"source_$i"} );
  343. push( @{ $form->{paymentmemo} }, $form->{"memo_$i"} );
  344. }
  345. }
  346. $form->{invtotal} = $form->{subtotal} + $tax;
  347. $form->{total} = $form->{invtotal} - $form->{paid};
  348. use LedgerSMB::CP;
  349. $c =
  350. CP->new( ( $form->{language_code} )
  351. ? $form->{language_code}
  352. : $myconfig{countrycode} );
  353. $c->init;
  354. ( $whole, $form->{decimal} ) = split /\./, $form->{invtotal};
  355. $form->{decimal} .= "00";
  356. $form->{decimal} = substr( $form->{decimal}, 0, 2 );
  357. $form->{text_decimal} = $c->num2text( $form->{decimal} * 1 );
  358. $form->{text_amount} = $c->num2text($whole);
  359. $form->{integer_amount} = $form->format_amount( $myconfig, $whole );
  360. for (qw(invtotal subtotal paid total)) {
  361. $form->{$_} = $form->format_amount( \%myconfig, $form->{$_}, 2 );
  362. }
  363. ( $form->{employee} ) = split /--/, $form->{employee};
  364. if ( exists $form->{longformat} ) {
  365. for (qw(duedate transdate)) {
  366. $form->{$_} =
  367. $locale->date( \%myconfig, $form->{$_}, $form->{longformat} );
  368. }
  369. }
  370. $form->{notes} =~ s/^\s+//g;
  371. @a = ( "invnumber", "transdate", "duedate", "notes" );
  372. for (qw(company address tel fax businessnumber)) {
  373. $form->{$_} = $myconfig{$_};
  374. }
  375. $form->{address} =~ s/\\n/\n/g;
  376. push @a,
  377. qw(company address tel fax businessnumber text_amount text_decimal);
  378. $form->format_string(@a);
  379. $form->{invdate} = $form->{transdate};
  380. $form->{templates} = "$myconfig{templates}";
  381. $form->{IN} =
  382. ( $form->{formname} eq 'transaction' )
  383. ? lc $form->{ARAP} . "_$form->{formname}.html"
  384. : "$form->{formname}.html";
  385. if ( $form->{format} =~ /(postscript|pdf)/ ) {
  386. $form->{IN} =~ s/html$/tex/;
  387. }
  388. if ( $form->{media} eq 'queue' ) {
  389. %queued = split / /, $form->{queued};
  390. if ( $filename = $queued{ $form->{formname} } ) {
  391. $form->{queued} =~ s/$form->{formname} $filename//;
  392. unlink "${LedgerSMB::Sysconfig::spool}/$filename";
  393. $filename =~ s/\..*$//g;
  394. }
  395. else {
  396. $filename = time;
  397. $filename .= $$;
  398. }
  399. $filename .= ( $form->{format} eq 'postscript' ) ? '.ps' : '.pdf';
  400. $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
  401. $form->{printmode} = '>';
  402. $form->{queued} .= " $form->{formname} $filename";
  403. $form->{queued} =~ s/^ //;
  404. # save status
  405. $form->update_status( \%myconfig );
  406. $old_form->{queued} = $form->{queued};
  407. %audittrail = (
  408. tablename => ($order) ? 'oe' : lc $ARAP,
  409. reference => $form->{"${inv}number"},
  410. formname => $form->{formname},
  411. action => 'queued',
  412. id => $form->{id}
  413. );
  414. $old_form->{audittrail} .=
  415. $form->audittrail( "", \%myconfig, \%audittrail );
  416. }
  417. if ( $form->{media} !~ /(queue|screen)/ ) {
  418. $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
  419. $form->{printmode} = '|-';
  420. if ( $form->{printed} !~ /$form->{formname}/ ) {
  421. $form->{printed} .= " $form->{formname}";
  422. $form->{printed} =~ s/^ //;
  423. $form->update_status( \%myconfig );
  424. }
  425. $old_form->{printed} = $form->{printed} if %$old_form;
  426. %audittrail = (
  427. tablename => lc $form->{ARAP},
  428. reference => $form->{"invnumber"},
  429. formname => $form->{formname},
  430. action => 'printed',
  431. id => $form->{id}
  432. );
  433. $old_form->{audittrail} .=
  434. $form->audittrail( "", \%myconfig, \%audittrail )
  435. if %$old_form;
  436. }
  437. $form->{fileid} = $form->{invnumber};
  438. $form->{fileid} =~ s/(\s|\W)+//g;
  439. if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
  440. {
  441. my $template =
  442. LedgerSMB::Template->new( \%myconfig, $form->{'formname'}, 'HTML' );
  443. try {
  444. $template->render($form);
  445. $form->header;
  446. print $template->{'output'};
  447. exit;
  448. }
  449. catch Error::Simple with {
  450. my $E = shift;
  451. $form->error( $E->stacktrace );
  452. };
  453. }
  454. $form->parse_template( \%myconfig );
  455. if (%$old_form) {
  456. $old_form->{invnumber} = $form->{invnumber};
  457. $old_form->{invtotal} = $form->{invtotal};
  458. for ( keys %$form ) { delete $form->{$_} }
  459. for ( keys %$old_form ) { $form->{$_} = $old_form->{$_} }
  460. if ( !$form->{printandpost} ) {
  461. for (qw(exchangerate creditlimit creditremaining)) {
  462. $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} );
  463. }
  464. for ( 1 .. $form->{rowcount} ) {
  465. $form->{"amount_$_"} =
  466. $form->parse_amount( \%myconfig, $form->{"amount_$_"} );
  467. }
  468. for ( split / /, $form->{taxaccounts} ) {
  469. $form->{"tax_$_"} =
  470. $form->parse_amount( \%myconfig, $form->{"tax_$_"} );
  471. }
  472. for $i ( 1 .. $form->{paidaccounts} ) {
  473. for (qw(paid exchangerate)) {
  474. $form->{"${_}_$i"} =
  475. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  476. }
  477. }
  478. }
  479. &{"$display_form"};
  480. }
  481. }
  482. sub vendor_details { IR->vendor_details( \%myconfig, \%$form ) }
  483. sub customer_details { IS->customer_details( \%myconfig, \%$form ) }
  484. sub select_payment {
  485. @column_index =
  486. ( "ndx", "datepaid", "source", "memo", "paid", "$form->{ARAP}_paid" );
  487. # list payments with radio button on a form
  488. $form->header;
  489. $title = $locale->text('Select payment');
  490. $column_data{ndx} = qq|<th width=1%>&nbsp;</th>|;
  491. $column_data{datepaid} = qq|<th>| . $locale->text('Date') . qq|</th>|;
  492. $column_data{source} = qq|<th>| . $locale->text('Source') . qq|</th>|;
  493. $column_data{memo} = qq|<th>| . $locale->text('Memo') . qq|</th>|;
  494. $column_data{paid} = qq|<th>| . $locale->text('Amount') . qq|</th>|;
  495. $column_data{"$form->{ARAP}_paid"} =
  496. qq|<th>| . $locale->text('Account') . qq|</th>|;
  497. print qq|
  498. <body>
  499. <form method=post action=$form->{script}>
  500. <table width=100%>
  501. <tr>
  502. <th class=listtop>$title</th>
  503. </tr>
  504. <tr space=5></tr>
  505. <tr>
  506. <td>
  507. <table width=100%>
  508. <tr class=listheading>|;
  509. for (@column_index) { print "\n$column_data{$_}" }
  510. print qq|
  511. </tr>
  512. |;
  513. $checked = "checked";
  514. foreach $i ( 1 .. $form->{paidaccounts} - 1 ) {
  515. for (@column_index) {
  516. $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>|;
  517. }
  518. $paid = $form->{"paid_$i"};
  519. $ok = 1;
  520. $column_data{ndx} =
  521. qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
  522. $column_data{paid} = qq|<td align=right>$paid</td>|;
  523. $checked = "";
  524. $j++;
  525. $j %= 2;
  526. print qq|
  527. <tr class=listrow$j>|;
  528. for (@column_index) { print "\n$column_data{$_}" }
  529. print qq|
  530. </tr>
  531. |;
  532. }
  533. print qq|
  534. </table>
  535. </td>
  536. </tr>
  537. <tr>
  538. <td><hr size=3 noshade></td>
  539. </tr>
  540. </table>
  541. |;
  542. for (qw(action nextsub)) { delete $form->{$_} }
  543. $form->hide_form;
  544. print qq|
  545. <br>
  546. <input type=hidden name=nextsub value=payment_selected>
  547. |;
  548. if ($ok) {
  549. print qq|
  550. <button class="submit" type="submit" name="action" value="continue">|
  551. . $locale->text('Continue')
  552. . qq|</button>|;
  553. }
  554. print qq|
  555. </form>
  556. </body>
  557. </html>
  558. |;
  559. }
  560. sub payment_selected {
  561. &{"print_$form->{formname}"}( $form->{oldform}, $form->{ndx} );
  562. }
  563. sub print_options {
  564. if ( $form->{selectlanguage} ) {
  565. $form->{"selectlanguage"} =
  566. $form->unescape( $form->{"selectlanguage"} );
  567. $form->{"selectlanguage"} =~ s/ selected//;
  568. $form->{"selectlanguage"} =~
  569. s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
  570. $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
  571. <input type=hidden name=selectlanguage value="|
  572. . $form->escape( $form->{selectlanguage}, 1 ) . qq|">|;
  573. }
  574. $form->{selectformname} = $form->unescape( $form->{selectformname} );
  575. $form->{selectformname} =~ s/ selected//;
  576. $form->{selectformname} =~
  577. s/(<option value="\Q$form->{formname}\E")/$1 selected/;
  578. $type = qq|<select name=formname>$form->{selectformname}</select>
  579. <input type=hidden name=selectformname value="|
  580. . $form->escape( $form->{selectformname}, 1 ) . qq|">|;
  581. $media = qq|<select name=media>
  582. <option value="screen">| . $locale->text('Screen');
  583. $form->{selectformat} = qq|<option value="html">html\n|;
  584. if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) {
  585. for ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  586. $media .= qq|
  587. <option value="$_">$_|;
  588. }
  589. }
  590. if ( ${LedgerSMB::Sysconfig::latex} ) {
  591. $form->{selectformat} .= qq|
  592. <option value="postscript">| . $locale->text('Postscript') . qq|
  593. <option value="pdf">| . $locale->text('PDF');
  594. $media .= qq|<option value="queue">| . $locale->text('Queue');
  595. }
  596. $format = qq|<select name=format>$form->{selectformat}</select>|;
  597. $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
  598. $format .= qq|
  599. <input type=hidden name=selectformat value="|
  600. . $form->escape( $form->{selectformat}, 1 ) . qq|">|;
  601. $media .= qq|</select>|;
  602. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  603. print qq|
  604. <table width=100%>
  605. <tr>
  606. <td>$type</td>
  607. <td>$lang</td>
  608. <td>$format</td>
  609. <td>$media</td>
  610. <td align=right width=90%>
  611. |;
  612. if ( $form->{printed} =~ /$form->{formname}/ ) {
  613. print $locale->text('Printed') . qq|<br>|;
  614. }
  615. if ( $form->{recurring} ) {
  616. print $locale->text('Scheduled');
  617. }
  618. print qq|
  619. </td>
  620. </tr>
  621. </table>
  622. |;
  623. }
  624. sub print_and_post {
  625. $form->error( $locale->text('Select postscript or PDF!') )
  626. if $form->{format} !~ /(postscript|pdf)/;
  627. $form->error( $locale->text('Select a Printer!') )
  628. if $form->{media} eq 'screen';
  629. $form->{printandpost} = 1;
  630. $form->{display_form} = "post";
  631. &print;
  632. }