summaryrefslogtreecommitdiff
path: root/bin/arapprn.pl
blob: 845d829ab2f5640ffe39f11ee3b7e711e43b1822 (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. my $template = LedgerSMB::Template->new(
  235. user => \%myconfig, template => $form->{'formname'},
  236. format => uc $form->{'format'} );
  237. try {
  238. $template->render($form);
  239. $template->output($form->{'media'});
  240. }
  241. catch Error::Simple with {
  242. my $E = shift;
  243. $form->error( $E->stacktrace );
  244. };
  245. if ( $form->{previousform} ) {
  246. $previousform = $form->unescape( $form->{previousform} );
  247. for ( keys %$form ) { delete $form->{$_} }
  248. foreach $item ( split /&/, $previousform ) {
  249. ( $key, $value ) = split /=/, $item, 2;
  250. $value =~ s/%26/&/g;
  251. $form->{$key} = $value;
  252. }
  253. for (qw(exchangerate creditlimit creditremaining)) {
  254. $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} );
  255. }
  256. for ( 1 .. $form->{rowcount} ) {
  257. $form->{"amount_$_"} =
  258. $form->parse_amount( \%myconfig, $form->{"amount_$_"} );
  259. }
  260. for ( split / /, $form->{taxaccounts} ) {
  261. $form->{"tax_$_"} =
  262. $form->parse_amount( \%myconfig, $form->{"tax_$_"} );
  263. }
  264. for $i ( 1 .. $form->{paidaccounts} ) {
  265. for (qw(paid exchangerate)) {
  266. $form->{"${_}_$i"} =
  267. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  268. }
  269. }
  270. for (qw(printed audittrail)) { $form->{$_} = $status{$_} }
  271. &{"$display_form"};
  272. }
  273. }
  274. sub print_receipt {
  275. my ( $old_form, $i ) = @_;
  276. &print_check( $old_form, $i );
  277. }
  278. sub print_transaction {
  279. my ($old_form) = @_;
  280. $display_form =
  281. ( $form->{display_form} ) ? $form->{display_form} : "display_form";
  282. &{"$form->{vc}_details"};
  283. @a = qw(name address1 address2 city state zipcode country);
  284. $form->{invtotal} = 0;
  285. foreach $i ( 1 .. $form->{rowcount} - 1 ) {
  286. ( $form->{tempaccno}, $form->{tempaccount} ) = split /--/,
  287. $form->{"$form->{ARAP}_amount_$i"};
  288. ( $form->{tempprojectnumber} ) = split /--/,
  289. $form->{"projectnumber_$i"};
  290. $form->{tempdescription} = $form->{"description_$i"};
  291. $form->format_string(
  292. qw(tempaccno tempaccount tempprojectnumber tempdescription));
  293. push( @{ $form->{accno} }, $form->{tempaccno} );
  294. push( @{ $form->{account} }, $form->{tempaccount} );
  295. push( @{ $form->{description} }, $form->{tempdescription} );
  296. push( @{ $form->{projectnumber} }, $form->{tempprojectnumber} );
  297. push( @{ $form->{amount} }, $form->{"amount_$i"} );
  298. $form->{subtotal} +=
  299. $form->parse_amount( \%myconfig, $form->{"amount_$i"} );
  300. }
  301. foreach $accno ( split / /, $form->{taxaccounts} ) {
  302. if ( $form->{"tax_$accno"} ) {
  303. $form->format_string("${accno}_description");
  304. $tax += $form->parse_amount( \%myconfig, $form->{"tax_$accno"} );
  305. $form->{"${accno}_tax"} = $form->{"tax_$accno"};
  306. push( @{ $form->{tax} }, $form->{"tax_$accno"} );
  307. push(
  308. @{ $form->{taxdescription} },
  309. $form->{"${accno}_description"}
  310. );
  311. $form->{"${accno}_taxrate"} =
  312. $form->format_amount( $myconfig, $form->{"${accno}_rate"} * 100 );
  313. push( @{ $form->{taxrate} }, $form->{"${accno}_taxrate"} );
  314. push( @{ $form->{taxnumber} }, $form->{"${accno}_taxnumber"} );
  315. }
  316. }
  317. $tax = 0 if $form->{taxincluded};
  318. push @a, $form->{ARAP};
  319. $form->format_string(@a);
  320. $form->{paid} = 0;
  321. for $i ( 1 .. $form->{paidaccounts} - 1 ) {
  322. if ( $form->{"paid_$i"} ) {
  323. @a = ();
  324. $form->{paid} +=
  325. $form->parse_amount( \%myconfig, $form->{"paid_$i"} );
  326. if ( exists $form->{longformat} ) {
  327. $form->{"datepaid_$i"} =
  328. $locale->date( \%myconfig, $form->{"datepaid_$i"},
  329. $form->{longformat} );
  330. }
  331. push @a, "$form->{ARAP}_paid_$i", "source_$i", "memo_$i";
  332. $form->format_string(@a);
  333. ( $accno, $account ) = split /--/, $form->{"$form->{ARAP}_paid_$i"};
  334. push( @{ $form->{payment} }, $form->{"paid_$i"} );
  335. push( @{ $form->{paymentdate} }, $form->{"datepaid_$i"} );
  336. push( @{ $form->{paymentaccount} }, $account );
  337. push( @{ $form->{paymentsource} }, $form->{"source_$i"} );
  338. push( @{ $form->{paymentmemo} }, $form->{"memo_$i"} );
  339. }
  340. }
  341. $form->{invtotal} = $form->{subtotal} + $tax;
  342. $form->{total} = $form->{invtotal} - $form->{paid};
  343. use LedgerSMB::CP;
  344. $c =
  345. CP->new( ( $form->{language_code} )
  346. ? $form->{language_code}
  347. : $myconfig{countrycode} );
  348. $c->init;
  349. ( $whole, $form->{decimal} ) = split /\./, $form->{invtotal};
  350. $form->{decimal} .= "00";
  351. $form->{decimal} = substr( $form->{decimal}, 0, 2 );
  352. $form->{text_decimal} = $c->num2text( $form->{decimal} * 1 );
  353. $form->{text_amount} = $c->num2text($whole);
  354. $form->{integer_amount} = $form->format_amount( $myconfig, $whole );
  355. for (qw(invtotal subtotal paid total)) {
  356. $form->{$_} = $form->format_amount( \%myconfig, $form->{$_}, 2 );
  357. }
  358. ( $form->{employee} ) = split /--/, $form->{employee};
  359. if ( exists $form->{longformat} ) {
  360. for (qw(duedate transdate)) {
  361. $form->{$_} =
  362. $locale->date( \%myconfig, $form->{$_}, $form->{longformat} );
  363. }
  364. }
  365. $form->{notes} =~ s/^\s+//g;
  366. @a = ( "invnumber", "transdate", "duedate", "notes" );
  367. for (qw(company address tel fax businessnumber)) {
  368. $form->{$_} = $myconfig{$_};
  369. }
  370. $form->{address} =~ s/\\n/\n/g;
  371. push @a,
  372. qw(company address tel fax businessnumber text_amount text_decimal);
  373. $form->format_string(@a);
  374. $form->{invdate} = $form->{transdate};
  375. $form->{templates} = "$myconfig{templates}";
  376. $form->{IN} =
  377. ( $form->{formname} eq 'transaction' )
  378. ? lc $form->{ARAP} . "_$form->{formname}.html"
  379. : "$form->{formname}.html";
  380. if ( $form->{format} =~ /(postscript|pdf)/ ) {
  381. $form->{IN} =~ s/html$/tex/;
  382. }
  383. if ( $form->{media} eq 'queue' ) {
  384. %queued = split / /, $form->{queued};
  385. if ( $filename = $queued{ $form->{formname} } ) {
  386. $form->{queued} =~ s/$form->{formname} $filename//;
  387. unlink "${LedgerSMB::Sysconfig::spool}/$filename";
  388. $filename =~ s/\..*$//g;
  389. }
  390. else {
  391. $filename = time;
  392. $filename .= $$;
  393. }
  394. $filename .= ( $form->{format} eq 'postscript' ) ? '.ps' : '.pdf';
  395. $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
  396. $form->{printmode} = '>';
  397. $form->{queued} .= " $form->{formname} $filename";
  398. $form->{queued} =~ s/^ //;
  399. # save status
  400. $form->update_status( \%myconfig );
  401. $old_form->{queued} = $form->{queued};
  402. %audittrail = (
  403. tablename => ($order) ? 'oe' : lc $ARAP,
  404. reference => $form->{"${inv}number"},
  405. formname => $form->{formname},
  406. action => 'queued',
  407. id => $form->{id}
  408. );
  409. $old_form->{audittrail} .=
  410. $form->audittrail( "", \%myconfig, \%audittrail );
  411. }
  412. if ( $form->{media} !~ /(queue|screen)/ ) {
  413. $form->{OUT} = ${LedgerSMB::Sysconfig::printer}{ $form->{media} };
  414. $form->{printmode} = '|-';
  415. if ( $form->{printed} !~ /$form->{formname}/ ) {
  416. $form->{printed} .= " $form->{formname}";
  417. $form->{printed} =~ s/^ //;
  418. $form->update_status( \%myconfig );
  419. }
  420. $old_form->{printed} = $form->{printed} if %$old_form;
  421. %audittrail = (
  422. tablename => lc $form->{ARAP},
  423. reference => $form->{"invnumber"},
  424. formname => $form->{formname},
  425. action => 'printed',
  426. id => $form->{id}
  427. );
  428. $old_form->{audittrail} .=
  429. $form->audittrail( "", \%myconfig, \%audittrail )
  430. if %$old_form;
  431. }
  432. $form->{fileid} = $form->{invnumber};
  433. $form->{fileid} =~ s/(\s|\W)+//g;
  434. my $template = LedgerSMB::Template->new(
  435. user => \%myconfig, template => $form->{'formname'},
  436. format => uc $form->{format} );
  437. try {
  438. $template->render($form);
  439. $template->output($form->{media});
  440. }
  441. catch Error::Simple with {
  442. my $E = shift;
  443. $form->error( $E->stacktrace );
  444. };
  445. if (%$old_form) {
  446. $old_form->{invnumber} = $form->{invnumber};
  447. $old_form->{invtotal} = $form->{invtotal};
  448. for ( keys %$form ) { delete $form->{$_} }
  449. for ( keys %$old_form ) { $form->{$_} = $old_form->{$_} }
  450. if ( !$form->{printandpost} ) {
  451. for (qw(exchangerate creditlimit creditremaining)) {
  452. $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} );
  453. }
  454. for ( 1 .. $form->{rowcount} ) {
  455. $form->{"amount_$_"} =
  456. $form->parse_amount( \%myconfig, $form->{"amount_$_"} );
  457. }
  458. for ( split / /, $form->{taxaccounts} ) {
  459. $form->{"tax_$_"} =
  460. $form->parse_amount( \%myconfig, $form->{"tax_$_"} );
  461. }
  462. for $i ( 1 .. $form->{paidaccounts} ) {
  463. for (qw(paid exchangerate)) {
  464. $form->{"${_}_$i"} =
  465. $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
  466. }
  467. }
  468. }
  469. &{"$display_form"};
  470. }
  471. }
  472. sub vendor_details { IR->vendor_details( \%myconfig, \%$form ) }
  473. sub customer_details { IS->customer_details( \%myconfig, \%$form ) }
  474. sub select_payment {
  475. @column_index =
  476. ( "ndx", "datepaid", "source", "memo", "paid", "$form->{ARAP}_paid" );
  477. # list payments with radio button on a form
  478. $form->header;
  479. $title = $locale->text('Select payment');
  480. $column_data{ndx} = qq|<th width=1%>&nbsp;</th>|;
  481. $column_data{datepaid} = qq|<th>| . $locale->text('Date') . qq|</th>|;
  482. $column_data{source} = qq|<th>| . $locale->text('Source') . qq|</th>|;
  483. $column_data{memo} = qq|<th>| . $locale->text('Memo') . qq|</th>|;
  484. $column_data{paid} = qq|<th>| . $locale->text('Amount') . qq|</th>|;
  485. $column_data{"$form->{ARAP}_paid"} =
  486. qq|<th>| . $locale->text('Account') . qq|</th>|;
  487. print qq|
  488. <body>
  489. <form method=post action=$form->{script}>
  490. <table width=100%>
  491. <tr>
  492. <th class=listtop>$title</th>
  493. </tr>
  494. <tr space=5></tr>
  495. <tr>
  496. <td>
  497. <table width=100%>
  498. <tr class=listheading>|;
  499. for (@column_index) { print "\n$column_data{$_}" }
  500. print qq|
  501. </tr>
  502. |;
  503. $checked = "checked";
  504. foreach $i ( 1 .. $form->{paidaccounts} - 1 ) {
  505. for (@column_index) {
  506. $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>|;
  507. }
  508. $paid = $form->{"paid_$i"};
  509. $ok = 1;
  510. $column_data{ndx} =
  511. qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
  512. $column_data{paid} = qq|<td align=right>$paid</td>|;
  513. $checked = "";
  514. $j++;
  515. $j %= 2;
  516. print qq|
  517. <tr class=listrow$j>|;
  518. for (@column_index) { print "\n$column_data{$_}" }
  519. print qq|
  520. </tr>
  521. |;
  522. }
  523. print qq|
  524. </table>
  525. </td>
  526. </tr>
  527. <tr>
  528. <td><hr size=3 noshade></td>
  529. </tr>
  530. </table>
  531. |;
  532. for (qw(action nextsub)) { delete $form->{$_} }
  533. $form->hide_form;
  534. print qq|
  535. <br>
  536. <input type=hidden name=nextsub value=payment_selected>
  537. |;
  538. if ($ok) {
  539. print qq|
  540. <button class="submit" type="submit" name="action" value="continue">|
  541. . $locale->text('Continue')
  542. . qq|</button>|;
  543. }
  544. print qq|
  545. </form>
  546. </body>
  547. </html>
  548. |;
  549. }
  550. sub payment_selected {
  551. &{"print_$form->{formname}"}( $form->{oldform}, $form->{ndx} );
  552. }
  553. sub print_options {
  554. if ( $form->{selectlanguage} ) {
  555. $form->{"selectlanguage"} =
  556. $form->unescape( $form->{"selectlanguage"} );
  557. $form->{"selectlanguage"} =~ s/ selected//;
  558. $form->{"selectlanguage"} =~
  559. s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
  560. $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
  561. <input type=hidden name=selectlanguage value="|
  562. . $form->escape( $form->{selectlanguage}, 1 ) . qq|">|;
  563. }
  564. $form->{selectformname} = $form->unescape( $form->{selectformname} );
  565. $form->{selectformname} =~ s/ selected//;
  566. $form->{selectformname} =~
  567. s/(<option value="\Q$form->{formname}\E")/$1 selected/;
  568. $type = qq|<select name=formname>$form->{selectformname}</select>
  569. <input type=hidden name=selectformname value="|
  570. . $form->escape( $form->{selectformname}, 1 ) . qq|">|;
  571. $media = qq|<select name=media>
  572. <option value="screen">| . $locale->text('Screen');
  573. $form->{selectformat} = qq|<option value="html">html\n|;
  574. if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) {
  575. for ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  576. $media .= qq|
  577. <option value="$_">$_|;
  578. }
  579. }
  580. if ( ${LedgerSMB::Sysconfig::latex} ) {
  581. $form->{selectformat} .= qq|
  582. <option value="postscript">| . $locale->text('Postscript') . qq|
  583. <option value="pdf">| . $locale->text('PDF');
  584. $media .= qq|<option value="queue">| . $locale->text('Queue');
  585. }
  586. $format = qq|<select name=format>$form->{selectformat}</select>|;
  587. $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
  588. $format .= qq|
  589. <input type=hidden name=selectformat value="|
  590. . $form->escape( $form->{selectformat}, 1 ) . qq|">|;
  591. $media .= qq|</select>|;
  592. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  593. print qq|
  594. <table width=100%>
  595. <tr>
  596. <td>$type</td>
  597. <td>$lang</td>
  598. <td>$format</td>
  599. <td>$media</td>
  600. <td align=right width=90%>
  601. |;
  602. if ( $form->{printed} =~ /$form->{formname}/ ) {
  603. print $locale->text('Printed') . qq|<br>|;
  604. }
  605. if ( $form->{recurring} ) {
  606. print $locale->text('Scheduled');
  607. }
  608. print qq|
  609. </td>
  610. </tr>
  611. </table>
  612. |;
  613. }
  614. sub print_and_post {
  615. $form->error( $locale->text('Select postscript or PDF!') )
  616. if $form->{format} !~ /(postscript|pdf)/;
  617. $form->error( $locale->text('Select a Printer!') )
  618. if $form->{media} eq 'screen';
  619. $form->{printandpost} = 1;
  620. $form->{display_form} = "post";
  621. &print;
  622. }