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