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