summaryrefslogtreecommitdiff
path: root/bin/bp.pl
blob: 7f9be0ea9437c409e3bd7c530332b642fb254a7a (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. # Batch printing
  37. #
  38. #======================================================================
  39. use LedgerSMB::BP;
  40. 1;
  41. # end of main
  42. sub search {
  43. # $locale->text('Sales Invoices')
  44. # $locale->text('Packing Lists')
  45. # $locale->text('Pick Lists')
  46. # $locale->text('Sales Orders')
  47. # $locale->text('Work Orders')
  48. # $locale->text('Purchase Orders')
  49. # $locale->text('Bin Lists')
  50. # $locale->text('Quotations')
  51. # $locale->text('RFQs')
  52. # $locale->text('Time Cards')
  53. # setup customer/vendor selection
  54. BP->get_vc(\%myconfig, \%$form);
  55. if (@{ $form->{"all_$form->{vc}"} }) {
  56. $name = "<option>\n";
  57. for (@{ $form->{"all_$form->{vc}"} }) { $name .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  58. $name = qq|<select name=$form->{vc}>$name</select>|;
  59. } else {
  60. $name = qq|<input name=$form->{vc} size=35>|;
  61. }
  62. # $locale->text('Customer')
  63. # $locale->text('Vendor')
  64. # $locale->text('Employee')
  65. %label = ( invoice => { title => 'Sales Invoices', name => 'Customer' },
  66. packing_list => { title => 'Packing Lists', name => 'Customer' },
  67. pick_list => { title => 'Pick Lists', name => 'Customer' },
  68. sales_order => { title => 'Sales Orders', name => 'Customer' },
  69. work_order => { title => 'Work Orders', name => 'Customer' },
  70. purchase_order => { title => 'Purchase Orders', name => 'Vendor' },
  71. bin_list => { title => 'Bin Lists', name => 'Vendor' },
  72. sales_quotation => { title => 'Quotations', name => 'Customer' },
  73. request_quotation => { title => 'RFQs', name => 'Vendor' },
  74. timecard => { title => 'Time Cards', name => 'Employee' },
  75. check => {title => 'Check', name => 'Vendor'},
  76. );
  77. $label{invoice}{invnumber} = qq|
  78. <tr>
  79. <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
  80. <td colspan=3><input name=invnumber size=20></td>
  81. </tr>
  82. |;
  83. $label{invoice}{ordnumber} = qq|
  84. <tr>
  85. <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
  86. <td colspan=3><input name=ordnumber size=20></td>
  87. </tr>
  88. |;
  89. $label{sales_quotation}{quonumber} = qq|
  90. <tr>
  91. <th align=right nowrap>|.$locale->text('Quotation Number').qq|</th>
  92. <td colspan=3><input name=quonumber size=20></td>
  93. </tr>
  94. |;
  95. $label{packing_list}{invnumber} = $label{invoice}{invnumber};
  96. $label{packing_list}{ordnumber} = $label{invoice}{ordnumber};
  97. $label{pick_list}{invnumber} = $label{invoice}{invnumber};
  98. $label{pick_list}{ordnumber} = $label{invoice}{ordnumber};
  99. $label{sales_order}{ordnumber} = $label{invoice}{ordnumber};
  100. $label{work_order}{ordnumber} = $label{invoice}{ordnumber};
  101. $label{purchase_order}{ordnumber} = $label{invoice}{ordnumber};
  102. $label{bin_list}{ordnumber} = $label{invoice}{ordnumber};
  103. $label{request_quotation}{quonumber} = $label{sales_quotation}{quonumber};
  104. # do one call to text
  105. $form->{title} = $locale->text('Print')." ".$locale->text($label{$form->{type}}{title});
  106. # accounting years
  107. if (@{ $form->{all_years} }) {
  108. # accounting years
  109. $form->{selectaccountingyear} = "<option>\n";
  110. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  111. $form->{selectaccountingmonth} = "<option>\n";
  112. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
  113. $selectfrom = qq|
  114. <tr>
  115. <th align=right>|.$locale->text('Period').qq|</th>
  116. <td colspan=3>
  117. <select name=month>$form->{selectaccountingmonth}</select>
  118. <select name=year>$form->{selectaccountingyear}</select>
  119. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  120. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  121. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  122. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  123. </td>
  124. </tr>
  125. |;
  126. }
  127. $form->header;
  128. print qq|
  129. <body>
  130. <form method=post action=$form->{script}>
  131. |;
  132. $form->hide_form(qw(vc type title));
  133. print qq|
  134. <table width=100%>
  135. <tr><th class=listtop>$form->{title}</th></tr>
  136. <tr height="5"></tr>
  137. <tr>
  138. <td>
  139. <table>
  140. <tr>
  141. <th align=right>|.$locale->text($label{$form->{type}}{name}).qq|</th>
  142. <td colspan=3>$name</td>
  143. </tr>
  144. $account
  145. $label{$form->{type}}{invnumber}
  146. $label{$form->{type}}{ordnumber}
  147. $label{$form->{type}}{quonumber}
  148. <tr>
  149. <th align=right nowrap>|.$locale->text('From').qq|</th>
  150. <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
  151. <th align=right>|.$locale->text('To').qq|</th>
  152. <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
  153. </tr>
  154. $selectfrom
  155. </table>
  156. </td>
  157. </tr>
  158. <tr>
  159. <td><hr size=3 noshade></td>
  160. </tr>
  161. </table>
  162. <input type=hidden name=sort value=transdate>
  163. <input type=hidden name=nextsub value=list_spool>
  164. <br>
  165. <button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  166. |;
  167. $form->hide_form(qw(path login sessionid));
  168. print qq|
  169. </form>
  170. </body>
  171. </html>
  172. |;
  173. }
  174. sub remove {
  175. $selected = 0;
  176. for $i (1 .. $form->{rowcount}) {
  177. if ($form->{"checked_$i"}) {
  178. $selected = 1;
  179. last;
  180. }
  181. }
  182. $form->error($locale->text('Nothing selected!')) unless $selected;
  183. $form->{title} = $locale->text('Confirm!');
  184. $form->header;
  185. print qq|
  186. <body>
  187. <form method=post action=$form->{script}>
  188. |;
  189. for (qw(action header)) { delete $form->{$_} }
  190. foreach $key (keys %$form) {
  191. print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
  192. }
  193. print qq|
  194. <h2 class=confirm>$form->{title}</h2>
  195. <h4>|.$locale->text('Are you sure you want to remove the marked entries from the queue?').qq|</h4>
  196. <button name="action" class="submit" type="submit" value="yes">|.$locale->text('Yes').qq|</button>
  197. </form>
  198. </body>
  199. </html>
  200. |;
  201. }
  202. sub yes {
  203. $form->info($locale->text('Removing marked entries from queue ...'));
  204. $form->{callback} .= "&header=1" if $form->{callback};
  205. if (BP->delete_spool(\%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool})) {
  206. $form->redirect($locale->text('Removed spoolfiles!'));
  207. } else {
  208. $form->error($locale->text('Cannot remove files!'));
  209. }
  210. }
  211. sub print {
  212. if ($form->{callback}) {
  213. for (1 .. $form->{rowcount}) { $form->{callback} .= "&checked_$_=1" if $form->{"checked_$_"} }
  214. $form->{callback} .= "&header=1";
  215. }
  216. for $i (1 .. $form->{rowcount}) {
  217. if ($form->{"checked_$i"}) {
  218. $form->{OUT} = ${LedgerSMB::Sysconfig::printer}{$form->{media}};
  219. $form->{printmode} = '|-';
  220. $form->info($locale->text('Printing')." ...");
  221. if (BP->print_spool(\%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool})) {
  222. print $locale->text('done');
  223. $form->redirect($locale->text('Marked entries printed!'));
  224. }
  225. exit;
  226. }
  227. }
  228. $form->error('Nothing selected!');
  229. }
  230. sub list_spool {
  231. $form->{$form->{vc}} = $form->unescape($form->{$form->{vc}});
  232. ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}});
  233. BP->get_spoolfiles(\%myconfig, \%$form);
  234. $title = $form->escape($form->{title});
  235. $href = "$form->{script}?action=list_spool&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&vc=$form->{vc}&type=$form->{type}&title=$title";
  236. $form->sort_order();
  237. $title = $form->escape($form->{title},1);
  238. $callback = "$form->{script}?action=list_spool&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&vc=$form->{vc}&type=$form->{type}&title=$title";
  239. if ($form->{$form->{vc}}) {
  240. $callback .= "&$form->{vc}=".$form->escape($form->{$form->{vc}},1);
  241. $href .= "&$form->{vc}=".$form->escape($form->{$form->{vc}});
  242. $option = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor');
  243. $option .= " : $form->{$form->{vc}}";
  244. }
  245. if ($form->{account}) {
  246. $callback .= "&account=".$form->escape($form->{account},1);
  247. $href .= "&account=".$form->escape($form->{account});
  248. $option .= "\n<br>" if ($option);
  249. $option .= $locale->text('Account')." : $form->{account}";
  250. }
  251. if ($form->{invnumber}) {
  252. $callback .= "&invnumber=".$form->escape($form->{invnumber},1);
  253. $href .= "&invnumber=".$form->escape($form->{invnumber});
  254. $option .= "\n<br>" if ($option);
  255. $option .= $locale->text('Invoice Number')." : $form->{invnumber}";
  256. }
  257. if ($form->{ordnumber}) {
  258. $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1);
  259. $href .= "&ordnumber=".$form->escape($form->{ordnumber});
  260. $option .= "\n<br>" if ($option);
  261. $option .= $locale->text('Order Number')." : $form->{ordnumber}";
  262. }
  263. if ($form->{quonumber}) {
  264. $callback .= "&quonumber=".$form->escape($form->{quonumber},1);
  265. $href .= "&quonumber=".$form->escape($form->{quonumber});
  266. $option .= "\n<br>" if ($option);
  267. $option .= $locale->text('Quotation Number')." : $form->{quonumber}";
  268. }
  269. if ($form->{transdatefrom}) {
  270. $callback .= "&transdatefrom=$form->{transdatefrom}";
  271. $href .= "&transdatefrom=$form->{transdatefrom}";
  272. $option .= "\n<br>" if ($option);
  273. $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
  274. }
  275. if ($form->{transdateto}) {
  276. $callback .= "&transdateto=$form->{transdateto}";
  277. $href .= "&transdateto=$form->{transdateto}";
  278. $option .= "\n<br>" if ($option);
  279. $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 1);
  280. }
  281. $name = ucfirst $form->{vc};
  282. @columns = qw(transdate);
  283. if ($form->{type} =~ /(invoice)/) {
  284. push @columns, "invnumber";
  285. }
  286. if ($form->{type} =~ /(packing|pick)_list/) {
  287. push @columns, "invnumber";
  288. }
  289. if ($form->{type} =~ /_(order|list)$/) {
  290. push @columns, "ordnumber";
  291. }
  292. if ($form->{type} =~ /_quotation$/) {
  293. push @columns, "quonumber";
  294. }
  295. if ($form->{type} eq 'timecard') {
  296. push @columns, "id";
  297. }
  298. push @columns, (name, spoolfile);
  299. @column_index = $form->sort_columns(@columns);
  300. unshift @column_index, "checked";
  301. $column_header{checked} = "<th class=listheading>&nbsp;</th>";
  302. $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
  303. $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>";
  304. $column_header{ordnumber} = "<th><a class=listheading href=$href&sort=ordnumber>".$locale->text('Order')."</a></th>";
  305. $column_header{quonumber} = "<th><a class=listheading href=$href&sort=quonumber>".$locale->text('Quotation')."</a></th>";
  306. $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text($name)."</a></th>";
  307. $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>";
  308. $column_header{spoolfile} = "<th class=listheading>".$locale->text('Spoolfile')."</th>";
  309. $form->header;
  310. print qq|
  311. <body>
  312. <form method=post action=$form->{script}>
  313. <table width=100%>
  314. <tr>
  315. <th class=listtop>$form->{title}</th>
  316. </tr>
  317. <tr height="5"></tr>
  318. <tr>
  319. <td>$option</td>
  320. </tr>
  321. <tr>
  322. <td>
  323. <table width=100%>
  324. <tr class=listheading>
  325. |;
  326. for (@column_index) { print "\n$column_header{$_}" }
  327. print qq|
  328. </tr>
  329. |;
  330. # add sort and escape callback, this one we use for the add sub
  331. $form->{callback} = $callback .= "&sort=$form->{sort}";
  332. # escape callback for href
  333. $callback = $form->escape($callback);
  334. $i = 0;
  335. foreach $ref (@{ $form->{SPOOL} }) {
  336. $i++;
  337. $form->{"checked_$i"} = "checked" if $form->{"checked_$i"};
  338. # this is for audittrail
  339. $form->{module} = $ref->{module};
  340. if ($ref->{invoice}) {
  341. $ref->{module} = ($ref->{module} eq 'ar') ? "is" : "ir";
  342. }
  343. $module = "$ref->{module}.pl";
  344. $column_data{transdate} = "<td>$ref->{transdate}&nbsp;</td>";
  345. if (${LedgerSMB::Sysconfig::spool} eq $ref->{spoolfile}) {
  346. $column_data{checked} = qq|<td></td>|;
  347. } else {
  348. $column_data{checked} = qq|<td><input name=checked_$i type=checkbox class=checkbox $form->{"checked_$i"} $form->{"checked_$i"}></td>|;
  349. }
  350. for (qw(id invnumber ordnumber quonumber)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| }
  351. if ($ref->{module} eq 'oe') {
  352. $column_data{invnumber} = qq|<td>&nbsp</td>|;
  353. $column_data{ordnumber} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{ordnumber}</a></td>
  354. <input type=hidden name="reference_$i" value="$ref->{ordnumber}">|;
  355. $column_data{quonumber} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{quonumber}</a></td>
  356. <input type=hidden name="reference_$i" value="$ref->{quonumber}">|;
  357. } elsif ($ref->{module} eq 'jc') {
  358. $column_data{id} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{id}</a></td>
  359. <input type=hidden name="reference_$i" value="$ref->{id}">|;
  360. } else {
  361. $column_data{invnumber} = qq|<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&callback=$callback>$ref->{invnumber}</a></td>
  362. <input type=hidden name="reference_$i" value="$ref->{invnumber}">|;
  363. }
  364. $column_data{name} = "<td>$ref->{name}</td>";
  365. $column_data{spoolfile} = qq|<td><a href=${LedgerSMB::Sysconfig::spool}/$ref->{spoolfile}>$ref->{spoolfile}</a></td>
  366. |;
  367. ${LedgerSMB::Sysconfig::spool} = $ref->{spoolfile};
  368. $j++; $j %= 2;
  369. print "
  370. <tr class=listrow$j>
  371. ";
  372. for (@column_index) { print "\n$column_data{$_}" }
  373. print qq|
  374. <input type=hidden name="id_$i" value=$ref->{id}>
  375. <input type=hidden name="spoolfile_$i" value=$ref->{spoolfile}>
  376. </tr>
  377. |;
  378. }
  379. print qq|
  380. <input type=hidden name=rowcount value=$i>
  381. </table>
  382. </td>
  383. </tr>
  384. <tr>
  385. <td><hr size=3 noshade></td>
  386. </tr>
  387. </table>
  388. <br>
  389. |;
  390. $form->hide_form(qw(callback title vc type sort module account path login sessionid));
  391. if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
  392. foreach $key (sort keys %{LedgerSMB::Sysconfig::printer}) {
  393. print qq|
  394. <input name=media type=radio class=radio value="$key" |;
  395. print qq|checked| if $key eq $myconfig{printer};
  396. print qq|>$key|;
  397. }
  398. print qq|<p>\n|;
  399. # type=submit $locale->text('Select all')
  400. # type=submit $locale->text('Print')
  401. # type=submit $locale->text('Remove')
  402. %button = ('select_all' => { ndx => 2, key => 'A', value => $locale->text('Select all') },
  403. 'print' => { ndx => 3, key => 'P', value => $locale->text('Print') },
  404. 'remove' => { ndx => 4, key => 'R', value => $locale->text('Remove') },
  405. );
  406. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  407. }
  408. if ($form->{lynx}) {
  409. require "bin/menu.pl";
  410. &menubar;
  411. }
  412. print qq|
  413. </form>
  414. </body>
  415. </html>
  416. |;
  417. }
  418. sub select_all {
  419. for (1 .. $form->{rowcount}) { $form->{"checked_$_"} = 1 }
  420. &list_spool;
  421. }
  422. sub continue { &{ $form->{nextsub} } };