1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   7 #=====================================================================
 
   8 # SQL-Ledger Accounting
 
  11 #  Author: Dieter Simader
 
  12 #   Email: dsimader@sql-ledger.org
 
  13 #     Web: http://www.sql-ledger.org
 
  16 # This program is free software; you can redistribute it and/or modify
 
  17 # it under the terms of the GNU General Public License as published by
 
  18 # the Free Software Foundation; either version 2 of the License, or
 
  19 # (at your option) any later version.
 
  21 # This program is distributed in the hope that it will be useful,
 
  22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  24 # GNU General Public License for more details.
 
  25 # You should have received a copy of the GNU General Public License
 
  26 # along with this program; if not, write to the Free Software
 
  27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  28 #======================================================================
 
  32 #======================================================================
 
  36 use List::Util qw(first);
 
  40 require "bin/mozilla/common.pl";
 
  46 sub assert_bp_access {
 
  47   my $form     = $main::form;
 
  50     'invoice'           => 'invoice_edit',
 
  51     'sales_order'       => 'sales_order_edit',
 
  52     'sales_quotation'   => 'sales_quotation_edit',
 
  53     'purchase_order'    => 'purchase_order_edit',
 
  54     'request_quotation' => 'request_quotation_edit',
 
  59   if ($form->{type} && $access_map{$form->{type}}) {
 
  60     $main::auth->assert($access_map{$form->{type}});
 
  63     $main::auth->assert('DOES_NOT_EXIST');
 
  68   $main::lxdebug->enter_sub();
 
  70   my $form     = $main::form;
 
  71   my %myconfig = %main::myconfig;
 
  72   my $locale   = $main::locale;
 
  74   my ($name, $account, $onload);
 
  78   # $locale->text('Sales Invoices')
 
  79   # $locale->text('Sales Orders')
 
  80   # $locale->text('Purchase Orders')
 
  81   # $locale->text('Quotations')
 
  82   # $locale->text('RFQs')
 
  83   # $locale->text('Checks')
 
  84   # $locale->text('Receipts')
 
  86   # setup customer/vendor selection
 
  87   BP->get_vc(\%myconfig, \%$form);
 
  89   if (@{ $form->{"all_$form->{vc}"} || [] }) {
 
  90     map { $name .= "<option>$_->{name}--$_->{id}\n" }
 
  91       @{ $form->{"all_$form->{vc}"} };
 
  92     $name = qq|<select name=$form->{vc}><option>\n$name</select>|;
 
  94     $name = qq|<input name=$form->{vc} size=35>|;
 
  97   # $locale->text('Customer')
 
  98   # $locale->text('Vendor')
 
 102          { title => 'Sales Invoices', name => 'Customer', l_invnumber => 'Y' },
 
 104          { title => 'Sales Orders', name => 'Customer', l_ordnumber => 'Y' },
 
 106          { title => 'Purchase Orders', name => 'Vendor', l_ordnumber => 'Y' },
 
 108          { title => 'Quotations', name => 'Customer', l_quonumber => 'Y' },
 
 110          { title => 'RFQs', name => 'Vendor', l_quonumber => 'Y' },
 
 111        check   => { title => 'Checks',   name => 'Vendor' },
 
 112        receipt => { title => 'Receipts', name => 'Customer' });
 
 114   $label{invoice}{invnumber} = qq|
 
 116           <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
 117           <td colspan=3><input name=invnumber size=20></td>
 
 120   $label{invoice}{ordnumber} = qq|
 
 122           <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 
 123           <td colspan=3><input name=ordnumber size=20></td>
 
 126   $label{sales_quotation}{quonumber} = qq|
 
 128           <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
 
 129           <td colspan=3><input name=quonumber size=20></td>
 
 133   $label{check}{chknumber} = qq|
 
 135           <th align=right nowrap>| . $locale->text('Reference') . qq|</th>
 
 136           <td colspan=3><input name=chknumber size=20></td>
 
 140   $label{sales_order}{ordnumber}       = $label{invoice}{ordnumber};
 
 141   $label{purchase_order}{ordnumber}    = $label{invoice}{ordnumber};
 
 142   $label{request_quotation}{quonumber} = $label{sales_quotation}{quonumber};
 
 143   $label{receipt}{rctnumber}           = $label{check}{chknumber};
 
 145   # do one call to text
 
 147       $locale->text('Print') . " "
 
 148     . $locale->text($label{ $form->{type} }{title});
 
 150   if ($form->{type} =~ /(check|receipt)/) {
 
 151     if (BP->payment_accounts(\%myconfig, \%$form)) {
 
 154           <th align=right>| . $locale->text('Account') . qq|</th>
 
 157       if ($form->{accounts}) {
 
 159           <td colspan=3><select name=account>
 
 161         foreach my $ref (@{ $form->{accounts} }) {
 
 163           <option>$ref->{accno}--$ref->{description}
 
 172           <td colspan=3><input name=account></td>
 
 184   # use JavaScript Calendar or not
 
 185   $form->{jsscript} = 1;
 
 187   my ($button1, $button2);
 
 188   if ($form->{jsscript}) {
 
 190     # with JavaScript Calendar
 
 192        <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
 193        <input type=button name=transdatefrom id="trigger1" value=|
 
 194       . $locale->text('button') . qq|></td>
 
 197        <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
 198        <input type=button name=transdateto name=transdateto id="trigger2" value=|
 
 199       . $locale->text('button') . qq|></td>
 
 204       Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
 
 205                           "transdateto", "BL", "trigger2");
 
 208     # without JavaScript Calendar
 
 210                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
 
 212                               <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
 
 214   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
 216   $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
 217   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
 219 <body onLoad="$onload">
 
 221 <form method=post action=bp.pl>
 
 223 <input type=hidden name=vc value=$form->{vc}>
 
 224 <input type=hidden name=type value=$form->{type}>
 
 225 <input type=hidden name=title value="$form->{title}">
 
 228   <tr><th class=listtop>$form->{title}</th></tr>
 
 234           <th align=right>Kunde</th>
 
 235           <td colspan=3>$name</td>
 
 238         $label{$form->{type}}{invnumber}
 
 239         $label{$form->{type}}{ordnumber}
 
 240         $label{$form->{type}}{quonumber}
 
 241         $label{$form->{type}}{chknumber}
 
 242         $label{$form->{type}}{rctnumber}
 
 244           <th align=right nowrap>| . $locale->text('From') . qq|</th>
 
 246           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 249         <input type=hidden name=sort value=transdate>
 
 254     <td><hr size=3 noshade></td>
 
 258 <input type=hidden name=nextsub value=list_spool>
 
 261 <input class=submit type=submit name=action value="|
 
 262     . $locale->text('Continue') . qq|">
 
 273   $main::lxdebug->leave_sub();
 
 277   $main::lxdebug->enter_sub();
 
 279   my $form     = $main::form;
 
 280   my $locale   = $main::locale;
 
 286   for my $i (1 .. $form->{rowcount}) {
 
 287     if ($form->{"checked_$i"}) {
 
 293   $form->error('Nothing selected!') unless $selected;
 
 295   $form->{title} = $locale->text('Confirm!');
 
 302 <form method=post action=bp.pl>
 
 305   map { delete $form->{$_} } qw(action header);
 
 307   foreach my $key (keys %$form) {
 
 308     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
 
 309     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
 313 <h2 class=confirm>$form->{title}</h2>
 
 317           'Are you sure you want to remove the marked entries from the queue?')
 
 320 <input name=action class=submit type=submit value="|
 
 321     . $locale->text('Yes') . qq|">
 
 328   $main::lxdebug->leave_sub();
 
 332   $main::lxdebug->enter_sub();
 
 334   my $form     = $main::form;
 
 335   my %myconfig = %main::myconfig;
 
 336   my $locale   = $main::locale;
 
 340   $form->info($locale->text('Removing marked entries from queue ...'));
 
 341   $form->{callback} .= "&header=1" if $form->{callback};
 
 343   $form->redirect($locale->text('Removed spoolfiles!'))
 
 344     if (BP->delete_spool(\%myconfig, \%$form));
 
 345   $form->error($locale->text('Cannot remove files!'));
 
 347   $main::lxdebug->leave_sub();
 
 351   $main::lxdebug->enter_sub();
 
 353   my $form     = $main::form;
 
 354   my %myconfig = %main::myconfig;
 
 355   my $locale   = $main::locale;
 
 359   $form->get_lists(printers => 'ALL_PRINTERS');
 
 360   # use the command stored in the databse or fall back to $myconfig{printer}
 
 361   my $selected_printer =  first { $_ } map ({ $_ ->{printer_command} }
 
 362                                          grep { $_->{id} eq $form->{printer} }
 
 363                                            @{ $form->{ALL_PRINTERS} }),
 
 366   if ($form->{callback}) {
 
 367     map { $form->{callback} .= "&checked_$_=1" if $form->{"checked_$_"} }
 
 368       (1 .. $form->{rowcount});
 
 369     $form->{callback} .= "&header=1";
 
 372   for my $i (1 .. $form->{rowcount}) {
 
 373     if ($form->{"checked_$i"}) {
 
 374       $form->info($locale->text('Printing ... '));
 
 376       if (BP->print_spool(\%myconfig, \%$form, "| $selected_printer")) {
 
 377         print $locale->text('done');
 
 378         $form->redirect($locale->text('Marked entries printed!'));
 
 384   $form->error('Nothing selected!');
 
 386   $main::lxdebug->leave_sub();
 
 390   $main::lxdebug->enter_sub();
 
 392   my $form     = $main::form;
 
 393   my %myconfig = %main::myconfig;
 
 394   my $locale   = $main::locale;
 
 398   $form->{ $form->{vc} } = $form->unescape($form->{ $form->{vc} });
 
 399   ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
 
 400     split(/--/, $form->{ $form->{vc} });
 
 402   BP->get_spoolfiles(\%myconfig, \%$form);
 
 404   my $title = $form->escape($form->{title});
 
 405   my $href  = "bp.pl?action=list_spool&vc=$form->{vc}&type=$form->{type}&title=$title";
 
 407   $title = $form->escape($form->{title}, 1);
 
 409     "bp.pl?action=list_spool&vc=$form->{vc}&type=$form->{type}&title=$title";
 
 412   if ($form->{ $form->{vc} }) {
 
 413     $callback .= "&$form->{vc}=" . $form->escape($form->{ $form->{vc} }, 1);
 
 414     $href .= "&$form->{vc}=" . $form->escape($form->{ $form->{vc} });
 
 416       ($form->{vc} eq 'customer')
 
 417       ? $locale->text('Customer')
 
 418       : $locale->text('Vendor');
 
 419     $option .= " : $form->{$form->{vc}}";
 
 421   if ($form->{account}) {
 
 422     $callback .= "&account=" . $form->escape($form->{account}, 1);
 
 423     $href .= "&account=" . $form->escape($form->{account});
 
 424     $option .= "\n<br>" if ($option);
 
 425     $option .= $locale->text('Account') . " : $form->{account}";
 
 427   if ($form->{invnumber}) {
 
 428     $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1);
 
 429     $href .= "&invnumber=" . $form->escape($form->{invnumber});
 
 430     $option .= "\n<br>" if ($option);
 
 431     $option .= $locale->text('Invoice Number') . " : $form->{invnumber}";
 
 433   if ($form->{ordnumber}) {
 
 434     $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1);
 
 435     $href .= "&ordnumber=" . $form->escape($form->{ordnumber});
 
 436     $option .= "\n<br>" if ($option);
 
 437     $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
 
 439   if ($form->{quonumber}) {
 
 440     $callback .= "&quonumber=" . $form->escape($form->{quonumber}, 1);
 
 441     $href .= "&quonumber=" . $form->escape($form->{quonumber});
 
 442     $option .= "\n<br>" if ($option);
 
 443     $option .= $locale->text('Quotation Number') . " : $form->{quonumber}";
 
 446   if ($form->{transdatefrom}) {
 
 447     $callback .= "&transdatefrom=$form->{transdatefrom}";
 
 448     $href     .= "&transdatefrom=$form->{transdatefrom}";
 
 449     $option   .= "\n<br>" if ($option);
 
 451         $locale->text('From') . " "
 
 452       . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
 
 454   if ($form->{transdateto}) {
 
 455     $callback .= "&transdateto=$form->{transdateto}";
 
 456     $href     .= "&transdateto=$form->{transdateto}";
 
 457     $option   .= "\n<br>" if ($option);
 
 459         $locale->text('To') . " "
 
 460       . $locale->date(\%myconfig, $form->{transdateto}, 1);
 
 463   my $name = ucfirst $form->{vc};
 
 465   my @columns = qw(transdate);
 
 466   if ($form->{type} =~ /_order$/) {
 
 467     push @columns, "ordnumber";
 
 469   if ($form->{type} =~ /_quotation$/) {
 
 470     push @columns, "quonumber";
 
 473   push @columns, qw(name spoolfile);
 
 474   my @column_index = $form->sort_columns(@columns);
 
 475   unshift @column_index, "checked";
 
 480   $column_header{checked}   = "<th class=listheading> </th>";
 
 481   $column_header{transdate} =
 
 482       "<th><a class=listheading href=$href&sort=transdate>"
 
 483     . $locale->text('Date')
 
 485   $column_header{invnumber} =
 
 486       "<th><a class=listheading href=$href&sort=invnumber>"
 
 487     . $locale->text('Invoice')
 
 489   $column_header{ordnumber} =
 
 490       "<th><a class=listheading href=$href&sort=ordnumber>"
 
 491     . $locale->text('Order')
 
 493   $column_header{quonumber} =
 
 494       "<th><a class=listheading href=$href&sort=quonumber>"
 
 495     . $locale->text('Quotation')
 
 497   $column_header{name} =
 
 498       "<th><a class=listheading href=$href&sort=name>"
 
 499     . $locale->text($name)
 
 501   $column_header{spoolfile} =
 
 502     "<th class=listheading>" . $locale->text('Spoolfile') . "</th>";
 
 509 <form method=post action=bp.pl>
 
 513     <th class=listtop>$form->{title}</th>
 
 522         <tr class=listheading>
 
 525   map { print "\n$column_header{$_}" } @column_index;
 
 531   # add sort and escape callback, this one we use for the add sub
 
 532   $form->{callback} = $callback .= "&sort=$form->{sort}";
 
 534   # escape callback for href
 
 535   $callback = $form->escape($callback);
 
 540   my $spool = $::lx_office_conf{paths}->{spool};
 
 542   foreach my $ref (@{ $form->{SPOOL} }) {
 
 546     $form->{"checked_$i"} = "checked" if $form->{"checked_$i"};
 
 548     if ($ref->{invoice}) {
 
 549       $ref->{module} = ($ref->{module} eq 'ar') ? "is" : "ir";
 
 551     my $module = "$ref->{module}.pl";
 
 553     $column_data{transdate} = "<td>$ref->{transdate} </td>";
 
 555     if ($spoolfile eq $ref->{spoolfile}) {
 
 556       $column_data{checked} = qq|<td></td>|;
 
 558       $column_data{checked} =
 
 559         qq|<td><input name=checked_$i type=checkbox style=checkbox $form->{"checked_$i"} $form->{"checked_$i"}></td>|;
 
 562     $column_data{invnumber} =
 
 563       "<td><a href=$module?action=edit&id=$ref->{id}&type=$form->{type}&callback=$callback>$ref->{invnumber}</a></td>";
 
 564     $column_data{ordnumber} =
 
 565       "<td><a href=$module?action=edit&id=$ref->{id}&type=$form->{type}&callback=$callback>$ref->{ordnumber}</a></td>";
 
 566     $column_data{quonumber} =
 
 567       "<td><a href=$module?action=edit&id=$ref->{id}&type=$form->{type}&callback=$callback>$ref->{quonumber}</a></td>";
 
 568     $column_data{name}      = "<td>$ref->{name}</td>";
 
 569     $column_data{spoolfile} =
 
 570       qq|<td><a href=$spool/$ref->{spoolfile}>$ref->{spoolfile}</a></td>
 
 571 <input type=hidden name="spoolfile_$i" value=$ref->{spoolfile}>
 
 574     $spoolfile = $ref->{spoolfile};
 
 582     map { print "\n$column_data{$_}" } @column_index;
 
 591 <input type=hidden name=rowcount value=$i>
 
 597     <td><hr size=3 noshade></td>
 
 603 <input name=callback type=hidden value="$form->{callback}">
 
 605 <input type=hidden name=title value="$form->{title}">
 
 606 <input type=hidden name=vc value="$form->{vc}">
 
 607 <input type=hidden name=type value="$form->{type}">
 
 608 <input type=hidden name=sort value="$form->{sort}">
 
 610 <input type=hidden name=account value="$form->{account}">
 
 613 #  if ($myconfig{printer}) {
 
 615 <input type=hidden name=transdateto value=$form->{transdateto}>
 
 616 <input type=hidden name=transdatefrom value=$form->{transdatefrom}>
 
 617 <input type=hidden name=invnumber value=$form->{invnumber}>
 
 618 <input type=hidden name=ordnumber value=$form->{ordnumber}>
 
 619 <input type=hidden name=quonumber value=$form->{quonumber}>
 
 620 <input type=hidden name=customer value=$form->{customer}>
 
 621 <input type=hidden name=vendor value=$form->{vendor}>
 
 622 <input class=submit type=submit name=action value="|
 
 623       . $locale->text('Select all') . qq|">
 
 624 <input class=submit type=submit name=action value="|
 
 625       . $locale->text('Remove') . qq|">
 
 626 <input class=submit type=submit name=action value="|
 
 627       . $locale->text('Print') . qq|">
 
 630 $form->get_lists(printers=>"ALL_PRINTERS");
 
 631 print qq|<select name="printer">|;
 
 632 print map(qq|<option value="$_->{id}">| . H($_->{printer_description}) . qq|</option>|, @{ $form->{ALL_PRINTERS} });
 
 644   $main::lxdebug->leave_sub();
 
 648   $main::lxdebug->enter_sub();
 
 650   my $form     = $main::form;
 
 654   map { $form->{"checked_$_"} = 1 } (1 .. $form->{rowcount});
 
 657   $main::lxdebug->leave_sub();
 
 660 sub continue { call_sub($main::form->{"nextsub"}); }