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