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