summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/arapprn.pl1379
-rwxr-xr-xbin/bp.pl1093
-rwxr-xr-xbin/cp.pl3
-rwxr-xr-xbin/io.pl3409
-rwxr-xr-xbin/jc.pl3856
-rwxr-xr-xbin/pos.pl2165
-rwxr-xr-xbin/rp.pl5090
7 files changed, 8506 insertions, 8489 deletions
diff --git a/bin/arapprn.pl b/bin/arapprn.pl
index 18fd884f..5eb138d9 100755
--- a/bin/arapprn.pl
+++ b/bin/arapprn.pl
@@ -1,686 +1,693 @@
-#=====================================================================
-# LedgerSMB Small Medium Business Accounting
-# http://www.ledgersmb.org/
-#
-
-# Copyright (C) 2006
-# This work contains copyrighted information from a number of sources all used
-# with permission.
-#
-# This file contains source code included with or based on SQL-Ledger which
-# is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
-# under the GNU General Public License version 2 or, at your option, any later
-# version. For a full list including contact information of contributors,
-# maintainers, and copyright holders, see the CONTRIBUTORS file.
-#
-# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
-# Copyright (c) 2003
-#
-# Author: DWS Systems Inc.
-# Web: http://www.sql-ledger.org
-#
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#======================================================================
-#
-# This file has not undergone any whitespace cleanup.
-#
-# printing routines for ar, ap
-#
-
-# any custom scripts for this one
-if (-f "bin/custom/arapprn.pl") {
- eval { require "bin/custom/arapprn.pl"; };
-}
-if (-f "bin/custom/$form->{login}_arapprn.pl") {
- eval { require "bin/custom/$form->{login}_arapprn.pl"; };
-}
-
-
-1;
-# end of main
-
-
-sub print {
-
- if ($form->{media} !~ /screen/) {
- $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
- $old_form = new Form;
- for (keys %$form) { $old_form->{$_} = $form->{$_} }
- }
-
- if ($form->{formname} =~ /(check|receipt)/) {
- if ($form->{media} eq 'screen') {
- $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
- }
- }
-
- if (! $form->{invnumber}) {
- $invfld = 'sinumber';
- $invfld = 'vinumber' if $form->{ARAP} eq 'AP';
- $form->{invnumber} = $form->update_defaults(\%myconfig, $invfld);
- if ($form->{media} eq 'screen') {
- if ($form->{media} eq 'screen') {
- &update;
- exit;
- }
- }
- }
-
- if ($form->{formname} =~ /(check|receipt)/) {
- if ($form->{media} ne 'screen') {
- for (qw(action header)) { delete $form->{$_} }
- $form->{invtotal} = $form->{oldinvtotal};
-
- foreach $key (keys %$form) {
- $form->{$key} =~ s/&/%26/g;
- $form->{previousform} .= qq|$key=$form->{$key}&|;
- }
- chop $form->{previousform};
- $form->{previousform} = $form->escape($form->{previousform}, 1);
- }
-
- if ($form->{paidaccounts} > 1) {
- if ($form->{"paid_$form->{paidaccounts}"}) {
- &update;
- exit;
- } elsif ($form->{paidaccounts} > 2) {
- # select payment
- &select_payment;
- exit;
- }
- } else {
- $form->error($locale->text('Nothing to print!'));
- }
-
- }
- if ($filename = $queued{$form->{formname}}) {
- $form->{queued} =~ s/$form->{formname} $filename//;
- unlink "${LedgerSMB::Sysconfig::spool}/$filename";
- $filename =~ s/\..*$//g;
- } else {
- $filename = time;
- $filename .= $$;
- }
-
- $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
- $form->{OUT} = ">${LedgerSMB::Sysconfig::spool}/$filename" if
- $form->{media} ne 'screen';
-
- $form->{queued} .= " $form->{formname} $filename";
- $form->{queued} =~ s/^ //;
- $printform = new Form;
- for (keys %$form){
- $printform->{$_} = $form->{$_};
- }
-
-
- if ($form->{printandpost}){
- &post;
- } else {
- &{ "print_$form->{formname}" }($old_form, 1);
- }
-
-
-}
-
-
-sub print_check {
- my ($old_form, $i) = @_;
-
- $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
-
- if ($form->{"paid_$i"}) {
- @a = ();
-
- if (exists $form->{longformat}) {
- $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
- }
-
- push @a, "source_$i", "memo_$i";
- $form->format_string(@a);
- }
-
- $form->{amount} = $form->{"paid_$i"};
-
- if (($form->{formname} eq 'check' && $form->{vc} eq 'customer') ||
- ($form->{formname} eq 'receipt' && $form->{vc} eq 'vendor')) {
- $form->{amount} =~ s/-//g;
- }
-
- for (qw(datepaid source memo)) { $form->{$_} = $form->{"${_}_$i"} }
-
- &{ "$form->{vc}_details" };
- @a = qw(name address1 address2 city state zipcode country);
-
- foreach $item (qw(invnumber ordnumber)) {
- $temp{$item} = $form->{$item};
- delete $form->{$item};
- push(@{ $form->{$item} }, $temp{$item});
- }
- push(@{ $form->{invdate} }, $form->{transdate});
- push(@{ $form->{due} }, $form->format_amount(\%myconfig, $form->{oldinvtotal}, 2));
- push(@{ $form->{paid} }, $form->{"paid_$i"});
-
- use LedgerSMB::CP;
- $c = CP->new(($form->{language_code}) ? $form->{language_code} : $myconfig{countrycode});
- $c->init;
- ($whole, $form->{decimal}) = split /\./, $form->parse_amount(\%myconfig, $form->{amount});
-
- $form->{decimal} .= "00";
- $form->{decimal} = substr($form->{decimal}, 0, 2);
- $form->{text_decimal} = $c->num2text($form->{decimal} * 1);
- $form->{text_amount} = $c->num2text($whole);
- $form->{integer_amount} = $form->format_amount($myconfig, $whole);
-
- ($form->{employee}) = split /--/, $form->{employee};
-
- $form->{notes} =~ s/^\s+//g;
- push @a, "notes";
-
- for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
- $form->{address} =~ s/\\n/\n/g;
-
- push @a, qw(company address tel fax businessnumber text_amount text_decimal);
-
- $form->format_string(@a);
-
- $form->{templates} = "$myconfig{templates}";
- $form->{IN} = ($form->{formname} eq 'transaction') ? lc $form->{ARAP} . "_$form->{formname}.html" : "$form->{formname}.html";
-
- if ($form->{format} =~ /(postscript|pdf)/) {
- $form->{IN} =~ s/html$/tex/;
- }
- if ($form->{media} eq 'queue') {
-
- # save status
- $form->update_status(\%myconfig);
-
- $form->{queued} = $form->{queued};
-
- %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
- reference => $form->{"${inv}number"},
- formname => $form->{formname},
- action => 'queued',
- id => $form->{id} );
-
- $form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
- $form->{OUT} = ">${LedgerSMB::Sysconfig::spool}/$filename";
-
- $form->{queued} .= " $form->{formname} $filename";
- $form->{queued} =~ s/^ //;
- }
-
- if ($form->{media} !~ /(screen|queue)/) {
-
- %queued = split / /, $form->{queued};
-
-
- $form->{OUT} = "| ${LedgerSMB::Sysconfig::printer}{$form->{media}}";
-
- if ($form->{printed} !~ /$form->{formname}/) {
-
- $form->{printed} .= " $form->{formname}";
- $form->{printed} =~ s/^ //;
-
- $form->update_status(\%myconfig);
- }
-
- %audittrail = ( tablename => lc $form->{ARAP},
- reference => $form->{invnumber},
- formname => $form->{formname},
- action => 'printed',
- id => $form->{id} );
-
- %status = ();
- for (qw(printed audittrail)) { $status{$_} = $form->{$_} }
-
- $status{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
-
- }
-
- $form->{fileid} = $invnumber;
- $form->{fileid} =~ s/(\s|\W)+//g;
-
- $form->parse_template(\%myconfig);
-
- if ($form->{previousform}) {
-
- $previousform = $form->unescape($form->{previousform});
-
- for (keys %$form) { delete $form->{$_} }
-
- foreach $item (split /&/, $previousform) {
- ($key, $value) = split /=/, $item, 2;
- $value =~ s/%26/&/g;
- $form->{$key} = $value;
- }
-
- for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-
- for (1 .. $form->{rowcount}) { $form->{"amount_$_"} = $form->parse_amount(\%myconfig, $form->{"amount_$_"}) }
- for (split / /, $form->{taxaccounts}) { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) }
-
- for $i (1 .. $form->{paidaccounts}) {
- for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
- }
-
- for (qw(printed audittrail)) { $form->{$_} = $status{$_} }
-
- &{ "$display_form" };
-
- }
-
-}
-
-
-sub print_receipt {
- my ($old_form, $i) = @_;
-
- &print_check($old_form, $i);
-
-}
-
-
-sub print_transaction {
- my ($old_form) = @_;
-
- $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
-
-
- &{ "$form->{vc}_details" };
- @a = qw(name address1 address2 city state zipcode country);
-
-
- $form->{invtotal} = 0;
- foreach $i (1 .. $form->{rowcount} - 1) {
- ($form->{tempaccno}, $form->{tempaccount}) = split /--/, $form->{"$form->{ARAP}_amount_$i"};
- ($form->{tempprojectnumber}) = split /--/, $form->{"projectnumber_$i"};
- $form->{tempdescription} = $form->{"description_$i"};
-
- $form->format_string(qw(tempaccno tempaccount tempprojectnumber tempdescription));
-
- push(@{ $form->{accno} }, $form->{tempaccno});
- push(@{ $form->{account} }, $form->{tempaccount});
- push(@{ $form->{description} }, $form->{tempdescription});
- push(@{ $form->{projectnumber} }, $form->{tempprojectnumber});
-
- push(@{ $form->{amount} }, $form->{"amount_$i"});
-
- $form->{subtotal} += $form->parse_amount(\%myconfig, $form->{"amount_$i"});
-
- }
-
- foreach $accno (split / /, $form->{taxaccounts}) {
- if ($form->{"tax_$accno"}) {
- $form->format_string("${accno}_description");
-
- $tax += $form->parse_amount(\%myconfig, $form->{"tax_$accno"});
-
- $form->{"${accno}_tax"} = $form->{"tax_$accno"};
- push(@{ $form->{tax} }, $form->{"tax_$accno"});
-
- push(@{ $form->{taxdescription} }, $form->{"${accno}_description"});
-
- $form->{"${accno}_taxrate"} = $form->format_amount($myconfig, $form->{"${accno}_rate"} * 100);
- push(@{ $form->{taxrate} }, $form->{"${accno}_taxrate"});
-
- push(@{ $form->{taxnumber} }, $form->{"${accno}_taxnumber"});
- }
- }
-
- $tax = 0 if $form->{taxincluded};
-
- push @a, $form->{ARAP};
- $form->format_string(@a);
-
- $form->{paid} = 0;
- for $i (1 .. $form->{paidaccounts} - 1) {
-
- if ($form->{"paid_$i"}) {
- @a = ();
- $form->{paid} += $form->parse_amount(\%myconfig, $form->{"paid_$i"});
-
- if (exists $form->{longformat}) {
- $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
- }
-
- push @a, "$form->{ARAP}_paid_$i", "source_$i", "memo_$i";
- $form->format_string(@a);
-
- ($accno, $account) = split /--/, $form->{"$form->{ARAP}_paid_$i"};
-
- push(@{ $form->{payment} }, $form->{"paid_$i"});
- push(@{ $form->{paymentdate} }, $form->{"datepaid_$i"});
- push(@{ $form->{paymentaccount} }, $account);
- push(@{ $form->{paymentsource} }, $form->{"source_$i"});
- push(@{ $form->{paymentmemo} }, $form->{"memo_$i"});
- }
-
- }
-
- $form->{invtotal} = $form->{subtotal} + $tax;
- $form->{total} = $form->{invtotal} - $form->{paid};
-
- use LedgerSMB::CP;
- $c = CP->new(($form->{language_code}) ? $form->{language_code} : $myconfig{countrycode});
- $c->init;
- ($whole, $form->{decimal}) = split /\./, $form->{invtotal};
-
- $form->{decimal} .= "00";
- $form->{decimal} = substr($form->{decimal}, 0, 2);
- $form->{text_decimal} = $c->num2text($form->{decimal} * 1);
- $form->{text_amount} = $c->num2text($whole);
- $form->{integer_amount} = $form->format_amount($myconfig, $whole);
-
- for (qw(invtotal subtotal paid total)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
-
- ($form->{employee}) = split /--/, $form->{employee};
-
- if (exists $form->{longformat}) {
- for (qw(duedate transdate)) { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) }
- }
-
- $form->{notes} =~ s/^\s+//g;
-
- @a = ("invnumber", "transdate", "duedate", "notes");
-
- for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
- $form->{address} =~ s/\\n/\n/g;
-
- push @a, qw(company address tel fax businessnumber text_amount text_decimal);
-
- $form->format_string(@a);
-
- $form->{invdate} = $form->{transdate};
-
- $form->{templates} = "$myconfig{templates}";
- $form->{IN} = ($form->{formname} eq 'transaction') ? lc $form->{ARAP} . "_$form->{formname}.html" : "$form->{formname}.html";
-
- if ($form->{format} =~ /(postscript|pdf)/) {
- $form->{IN} =~ s/html$/tex/;
- }
- if ($form->{media} eq 'queue') {
- %queued = split / /, $form->{queued};
-
- if ($filename = $queued{$form->{formname}}) {
- $form->{queued} =~ s/$form->{formname} $filename//;
- unlink "${LedgerSMB::Sysconfig::spool}/$filename";
- $filename =~ s/\..*$//g;
- } else {
- $filename = time;
- $filename .= $$;
- }
-
- $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
- $form->{OUT} = ">${LedgerSMB::Sysconfig::spool}/$filename";
-
- $form->{queued} .= " $form->{formname} $filename";
- $form->{queued} =~ s/^ //;
-
- # save status
- $form->update_status(\%myconfig);
-
- $old_form->{queued} = $form->{queued};
-
- %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
- reference => $form->{"${inv}number"},
- formname => $form->{formname},
- action => 'queued',
- id => $form->{id} );
-
- $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
- }
-
- if ($form->{media} !~ /(queue|screen)/) {
- $form->{OUT} = "| ${LedgerSMB::Sysconfig::printer}{$form->{media}}";
-
- if ($form->{printed} !~ /$form->{formname}/) {
-
- $form->{printed} .= " $form->{formname}";
- $form->{printed} =~ s/^ //;
-
- $form->update_status(\%myconfig);
- }
-
- $old_form->{printed} = $form->{printed} if %$old_form;
-
- %audittrail = ( tablename => lc $form->{ARAP},
- reference => $form->{"invnumber"},
- formname => $form->{formname},
- action => 'printed',
- id => $form->{id} );
-
- $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if %$old_form;
-
- }
-
- $form->{fileid} = $form->{invnumber};
- $form->{fileid} =~ s/(\s|\W)+//g;
-
- $form->parse_template(\%myconfig);
-
- if (%$old_form) {
- $old_form->{invnumber} = $form->{invnumber};
- $old_form->{invtotal} = $form->{invtotal};
-
- for (keys %$form) { delete $form->{$_} }
- for (keys %$old_form) { $form->{$_} = $old_form->{$_} }
-
- if (! $form->{printandpost}) {
- for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-
- for (1 .. $form->{rowcount}) { $form->{"amount_$_"} = $form->parse_amount(\%myconfig, $form->{"amount_$_"}) }
- for (split / /, $form->{taxaccounts}) { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) }
-
- for $i (1 .. $form->{paidaccounts}) {
- for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
- }
- }
-
- &{ "$display_form" };
-
- }
-
-}
-
-
-sub vendor_details { IR->vendor_details(\%myconfig, \%$form) };
-sub customer_details { IS->customer_details(\%myconfig, \%$form) };
-
-
-sub select_payment {
-
- @column_index = ("ndx", "datepaid", "source", "memo", "paid", "$form->{ARAP}_paid");
-
- # list payments with radio button on a form
- $form->header;
-
- $title = $locale->text('Select payment');
-
- $column_data{ndx} = qq|<th width=1%>&nbsp;</th>|;
- $column_data{datepaid} = qq|<th>|.$locale->text('Date').qq|</th>|;
- $column_data{source} = qq|<th>|.$locale->text('Source').qq|</th>|;
- $column_data{memo} = qq|<th>|.$locale->text('Memo').qq|</th>|;
- $column_data{paid} = qq|<th>|.$locale->text('Amount').qq|</th>|;
- $column_data{"$form->{ARAP}_paid"} = qq|<th>|.$locale->text('Account').qq|</th>|;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-
-<table width=100%>
- <tr>
- <th class=listtop>$title</th>
- </tr>
- <tr space=5></tr>
- <tr>
- <td>
- <table width=100%>
- <tr class=listheading>|;
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
- </tr>
-|;
-
- $checked = "checked";
- foreach $i (1 .. $form->{paidaccounts} - 1) {
-
- for (@column_index) { $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>| }
-
- $paid = $form->{"paid_$i"};
- $ok = 1;
-
- $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
- $column_data{paid} = qq|<td align=right>$paid</td>|;
-
- $checked = "";
-
- $j++; $j %= 2;
- print qq|
- <tr class=listrow$j>|;
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
- </tr>
-|;
-
- }
-
- print qq|
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-|;
-
- for (qw(action nextsub)) { delete $form->{$_} }
-
- $form->hide_form;
-
- print qq|
-
-<br>
-<input type=hidden name=nextsub value=payment_selected>
-|;
-
- if ($ok) {
- print qq|
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>|;
- }
-
- print qq|
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-sub payment_selected {
-
- &{ "print_$form->{formname}" }($form->{oldform}, $form->{ndx});
-
-}
-
-
-sub print_options {
-
- if ($form->{selectlanguage}) {
- $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
- $form->{"selectlanguage"} =~ s/ selected//;
- $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
- $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
- <input type=hidden name=selectlanguage value="|.
- $form->escape($form->{selectlanguage},1).qq|">|;
- }
-
- $form->{selectformname} = $form->unescape($form->{selectformname});
- $form->{selectformname} =~ s/ selected//;
- $form->{selectformname} =~ s/(<option value="\Q$form->{formname}\E")/$1 selected/;
-
- $type = qq|<select name=formname>$form->{selectformname}</select>
- <input type=hidden name=selectformname value="|.$form->escape($form->{selectformname},1).qq|">|;
-
- $media = qq|<select name=media>
- <option value="screen">|.$locale->text('Screen');
-
- $form->{selectformat} = qq|<option value="html">html\n|;
-
- if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
- for (sort keys %{LedgerSMB::Sysconfig::printer}) { $media .= qq|
- <option value="$_">$_| }
- }
-
- if (${LedgerSMB::Sysconfig::latex}) {
- $form->{selectformat} .= qq|
- <option value="postscript">|.$locale->text('Postscript').qq|
- <option value="pdf">|.$locale->text('PDF');
- $media .= qq|<option value="queue">|.$locale->text('Queue');
- }
-
- $format = qq|<select name=format>$form->{selectformat}</select>|;
- $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
- $format .= qq|
- <input type=hidden name=selectformat value="|.$form->escape($form->{selectformat},1).qq|">|;
- $media .= qq|</select>|;
- $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
-
- print qq|
- <table width=100%>
- <tr>
- <td>$type</td>
- <td>$lang</td>
- <td>$format</td>
- <td>$media</td>
- <td align=right width=90%>
- |;
-
- if ($form->{printed} =~ /$form->{formname}/) {
- print $locale->text('Printed').qq|<br>|;
- }
-
- if ($form->{recurring}) {
- print $locale->text('Scheduled');
- }
-
- print qq|
- </td>
- </tr>
- </table>
-|;
-
-}
-
-
-sub print_and_post {
-
- $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
- $form->error($locale->text('Select a Printer!')) if $form->{media} eq 'screen';
-
- $form->{printandpost} = 1;
- $form->{display_form} = "post";
- &print;
-
-}
-
-
+#=====================================================================
+# LedgerSMB Small Medium Business Accounting
+# http://www.ledgersmb.org/
+#
+
+# Copyright (C) 2006
+# This work contains copyrighted information from a number of sources all used
+# with permission.
+#
+# This file contains source code included with or based on SQL-Ledger which
+# is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
+# under the GNU General Public License version 2 or, at your option, any later
+# version. For a full list including contact information of contributors,
+# maintainers, and copyright holders, see the CONTRIBUTORS file.
+#
+# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
+# Copyright (c) 2003
+#
+# Author: DWS Systems Inc.
+# Web: http://www.sql-ledger.org
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#======================================================================
+#
+# This file has not undergone any whitespace cleanup.
+#
+# printing routines for ar, ap
+#
+
+# any custom scripts for this one
+if (-f "bin/custom/arapprn.pl") {
+ eval { require "bin/custom/arapprn.pl"; };
+}
+if (-f "bin/custom/$form->{login}_arapprn.pl") {
+ eval { require "bin/custom/$form->{login}_arapprn.pl"; };
+}
+
+
+1;
+# end of main
+
+
+sub print {
+
+ if ($form->{media} !~ /screen/) {
+ $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
+ $old_form = new Form;
+ for (keys %$form) { $old_form->{$_} = $form->{$_} }
+ }
+
+ if ($form->{formname} =~ /(check|receipt)/) {
+ if ($form->{media} eq 'screen') {
+ $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
+ }
+ }
+
+ if (! $form->{invnumber}) {
+ $invfld = 'sinumber';
+ $invfld = 'vinumber' if $form->{ARAP} eq 'AP';
+ $form->{invnumber} = $form->update_defaults(\%myconfig, $invfld);
+ if ($form->{media} eq 'screen') {
+ if ($form->{media} eq 'screen') {
+ &update;
+ exit;
+ }
+ }
+ }
+
+ if ($form->{formname} =~ /(check|receipt)/) {
+ if ($form->{media} ne 'screen') {
+ for (qw(action header)) { delete $form->{$_} }
+ $form->{invtotal} = $form->{oldinvtotal};
+
+ foreach $key (keys %$form) {
+ $form->{$key} =~ s/&/%26/g;
+ $form->{previousform} .= qq|$key=$form->{$key}&|;
+ }
+ chop $form->{previousform};
+ $form->{previousform} = $form->escape($form->{previousform}, 1);
+ }
+
+ if ($form->{paidaccounts} > 1) {
+ if ($form->{"paid_$form->{paidaccounts}"}) {
+ &update;
+ exit;
+ } elsif ($form->{paidaccounts} > 2) {
+ # select payment
+ &select_payment;
+ exit;
+ }
+ } else {
+ $form->error($locale->text('Nothing to print!'));
+ }
+
+ }
+ if ($filename = $queued{$form->{formname}}) {
+ $form->{queued} =~ s/$form->{formname} $filename//;
+ unlink "${LedgerSMB::Sysconfig::spool}/$filename";
+ $filename =~ s/\..*$//g;
+ } else {
+ $filename = time;
+ $filename .= $$;
+ }
+
+ $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
+
+ if ($form->{media} ne 'screen'){
+ $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
+ $form{printmode} = '>';
+ }
+
+ $form->{queued} .= " $form->{formname} $filename";
+ $form->{queued} =~ s/^ //;
+ $printform = new Form;
+ for (keys %$form){
+ $printform->{$_} = $form->{$_};
+ }
+
+
+ if ($form->{printandpost}){
+ &post;
+ } else {
+ &{ "print_$form->{formname}" }($old_form, 1);
+ }
+
+
+}
+
+
+sub print_check {
+ my ($old_form, $i) = @_;
+
+ $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
+
+ if ($form->{"paid_$i"}) {
+ @a = ();
+
+ if (exists $form->{longformat}) {
+ $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
+ }
+
+ push @a, "source_$i", "memo_$i";
+ $form->format_string(@a);
+ }
+
+ $form->{amount} = $form->{"paid_$i"};
+
+ if (($form->{formname} eq 'check' && $form->{vc} eq 'customer') ||
+ ($form->{formname} eq 'receipt' && $form->{vc} eq 'vendor')) {
+ $form->{amount} =~ s/-//g;
+ }
+
+ for (qw(datepaid source memo)) { $form->{$_} = $form->{"${_}_$i"} }
+
+ &{ "$form->{vc}_details" };
+ @a = qw(name address1 address2 city state zipcode country);
+
+ foreach $item (qw(invnumber ordnumber)) {
+ $temp{$item} = $form->{$item};
+ delete $form->{$item};
+ push(@{ $form->{$item} }, $temp{$item});
+ }
+ push(@{ $form->{invdate} }, $form->{transdate});
+ push(@{ $form->{due} }, $form->format_amount(\%myconfig, $form->{oldinvtotal}, 2));
+ push(@{ $form->{paid} }, $form->{"paid_$i"});
+
+ use LedgerSMB::CP;
+ $c = CP->new(($form->{language_code}) ? $form->{language_code} : $myconfig{countrycode});
+ $c->init;
+ ($whole, $form->{decimal}) = split /\./, $form->parse_amount(\%myconfig, $form->{amount});
+
+ $form->{decimal} .= "00";
+ $form->{decimal} = substr($form->{decimal}, 0, 2);
+ $form->{text_decimal} = $c->num2text($form->{decimal} * 1);
+ $form->{text_amount} = $c->num2text($whole);
+ $form->{integer_amount} = $form->format_amount($myconfig, $whole);
+
+ ($form->{employee}) = split /--/, $form->{employee};
+
+ $form->{notes} =~ s/^\s+//g;
+ push @a, "notes";
+
+ for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
+ $form->{address} =~ s/\\n/\n/g;
+
+ push @a, qw(company address tel fax businessnumber text_amount text_decimal);
+
+ $form->format_string(@a);
+
+ $form->{templates} = "$myconfig{templates}";
+ $form->{IN} = ($form->{formname} eq 'transaction') ? lc $form->{ARAP} . "_$form->{formname}.html" : "$form->{formname}.html";
+
+ if ($form->{format} =~ /(postscript|pdf)/) {
+ $form->{IN} =~ s/html$/tex/;
+ }
+ if ($form->{media} eq 'queue') {
+
+ # save status
+ $form->update_status(\%myconfig);
+
+ $form->{queued} = $form->{queued};
+
+ %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
+ reference => $form->{"${inv}number"},
+ formname => $form->{formname},
+ action => 'queued',
+ id => $form->{id} );
+
+ $form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
+ $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
+ $form->{printmode} = '>';
+
+ $form->{queued} .= " $form->{formname} $filename";
+ $form->{queued} =~ s/^ //;
+ }
+
+ if ($form->{media} !~ /(screen|queue)/) {
+
+ %queued = split / /, $form->{queued};
+
+
+ $form->{OUT} = "| ${LedgerSMB::Sysconfig::printer}{$form->{media}}";
+ $form->{printmode} = '|-';
+
+ if ($form->{printed} !~ /$form->{formname}/) {
+
+ $form->{printed} .= " $form->{formname}";
+ $form->{printed} =~ s/^ //;
+
+ $form->update_status(\%myconfig);
+ }
+
+ %audittrail = ( tablename => lc $form->{ARAP},
+ reference => $form->{invnumber},
+ formname => $form->{formname},
+ action => 'printed',
+ id => $form->{id} );
+
+ %status = ();
+ for (qw(printed audittrail)) { $status{$_} = $form->{$_} }
+
+ $status{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
+
+ }
+
+ $form->{fileid} = $invnumber;
+ $form->{fileid} =~ s/(\s|\W)+//g;
+
+ $form->parse_template(\%myconfig);
+
+ if ($form->{previousform}) {
+
+ $previousform = $form->unescape($form->{previousform});
+
+ for (keys %$form) { delete $form->{$_} }
+
+ foreach $item (split /&/, $previousform) {
+ ($key, $value) = split /=/, $item, 2;
+ $value =~ s/%26/&/g;
+ $form->{$key} = $value;
+ }
+
+ for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+
+ for (1 .. $form->{rowcount}) { $form->{"amount_$_"} = $form->parse_amount(\%myconfig, $form->{"amount_$_"}) }
+ for (split / /, $form->{taxaccounts}) { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) }
+
+ for $i (1 .. $form->{paidaccounts}) {
+ for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
+ }
+
+ for (qw(printed audittrail)) { $form->{$_} = $status{$_} }
+
+ &{ "$display_form" };
+
+ }
+
+}
+
+
+sub print_receipt {
+ my ($old_form, $i) = @_;
+
+ &print_check($old_form, $i);
+
+}
+
+
+sub print_transaction {
+ my ($old_form) = @_;
+
+ $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
+
+
+ &{ "$form->{vc}_details" };
+ @a = qw(name address1 address2 city state zipcode country);
+
+
+ $form->{invtotal} = 0;
+ foreach $i (1 .. $form->{rowcount} - 1) {
+ ($form->{tempaccno}, $form->{tempaccount}) = split /--/, $form->{"$form->{ARAP}_amount_$i"};
+ ($form->{tempprojectnumber}) = split /--/, $form->{"projectnumber_$i"};
+ $form->{tempdescription} = $form->{"description_$i"};
+
+ $form->format_string(qw(tempaccno tempaccount tempprojectnumber tempdescription));
+
+ push(@{ $form->{accno} }, $form->{tempaccno});
+ push(@{ $form->{account} }, $form->{tempaccount});
+ push(@{ $form->{description} }, $form->{tempdescription});
+ push(@{ $form->{projectnumber} }, $form->{tempprojectnumber});
+
+ push(@{ $form->{amount} }, $form->{"amount_$i"});
+
+ $form->{subtotal} += $form->parse_amount(\%myconfig, $form->{"amount_$i"});
+
+ }
+
+ foreach $accno (split / /, $form->{taxaccounts}) {
+ if ($form->{"tax_$accno"}) {
+ $form->format_string("${accno}_description");
+
+ $tax += $form->parse_amount(\%myconfig, $form->{"tax_$accno"});
+
+ $form->{"${accno}_tax"} = $form->{"tax_$accno"};
+ push(@{ $form->{tax} }, $form->{"tax_$accno"});
+
+ push(@{ $form->{taxdescription} }, $form->{"${accno}_description"});
+
+ $form->{"${accno}_taxrate"} = $form->format_amount($myconfig, $form->{"${accno}_rate"} * 100);
+ push(@{ $form->{taxrate} }, $form->{"${accno}_taxrate"});
+
+ push(@{ $form->{taxnumber} }, $form->{"${accno}_taxnumber"});
+ }
+ }
+
+ $tax = 0 if $form->{taxincluded};
+
+ push @a, $form->{ARAP};
+ $form->format_string(@a);
+
+ $form->{paid} = 0;
+ for $i (1 .. $form->{paidaccounts} - 1) {
+
+ if ($form->{"paid_$i"}) {
+ @a = ();
+ $form->{paid} += $form->parse_amount(\%myconfig, $form->{"paid_$i"});
+
+ if (exists $form->{longformat}) {
+ $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
+ }
+
+ push @a, "$form->{ARAP}_paid_$i", "source_$i", "memo_$i";
+ $form->format_string(@a);
+
+ ($accno, $account) = split /--/, $form->{"$form->{ARAP}_paid_$i"};
+
+ push(@{ $form->{payment} }, $form->{"paid_$i"});
+ push(@{ $form->{paymentdate} }, $form->{"datepaid_$i"});
+ push(@{ $form->{paymentaccount} }, $account);
+ push(@{ $form->{paymentsource} }, $form->{"source_$i"});
+ push(@{ $form->{paymentmemo} }, $form->{"memo_$i"});
+ }
+
+ }
+
+ $form->{invtotal} = $form->{subtotal} + $tax;
+ $form->{total} = $form->{invtotal} - $form->{paid};
+
+ use LedgerSMB::CP;
+ $c = CP->new(($form->{language_code}) ? $form->{language_code} : $myconfig{countrycode});
+ $c->init;
+ ($whole, $form->{decimal}) = split /\./, $form->{invtotal};
+
+ $form->{decimal} .= "00";
+ $form->{decimal} = substr($form->{decimal}, 0, 2);
+ $form->{text_decimal} = $c->num2text($form->{decimal} * 1);
+ $form->{text_amount} = $c->num2text($whole);
+ $form->{integer_amount} = $form->format_amount($myconfig, $whole);
+
+ for (qw(invtotal subtotal paid total)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
+
+ ($form->{employee}) = split /--/, $form->{employee};
+
+ if (exists $form->{longformat}) {
+ for (qw(duedate transdate)) { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) }
+ }
+
+ $form->{notes} =~ s/^\s+//g;
+
+ @a = ("invnumber", "transdate", "duedate", "notes");
+
+ for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
+ $form->{address} =~ s/\\n/\n/g;
+
+ push @a, qw(company address tel fax businessnumber text_amount text_decimal);
+
+ $form->format_string(@a);
+
+ $form->{invdate} = $form->{transdate};
+
+ $form->{templates} = "$myconfig{templates}";
+ $form->{IN} = ($form->{formname} eq 'transaction') ? lc $form->{ARAP} . "_$form->{formname}.html" : "$form->{formname}.html";
+
+ if ($form->{format} =~ /(postscript|pdf)/) {
+ $form->{IN} =~ s/html$/tex/;
+ }
+ if ($form->{media} eq 'queue') {
+ %queued = split / /, $form->{queued};
+
+ if ($filename = $queued{$form->{formname}}) {
+ $form->{queued} =~ s/$form->{formname} $filename//;
+ unlink "${LedgerSMB::Sysconfig::spool}/$filename";
+ $filename =~ s/\..*$//g;
+ } else {
+ $filename = time;
+ $filename .= $$;
+ }
+
+ $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
+ $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
+ $form->{printmode} = '>';
+
+ $form->{queued} .= " $form->{formname} $filename";
+ $form->{queued} =~ s/^ //;
+
+ # save status
+ $form->update_status(\%myconfig);
+
+ $old_form->{queued} = $form->{queued};
+
+ %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
+ reference => $form->{"${inv}number"},
+ formname => $form->{formname},
+ action => 'queued',
+ id => $form->{id} );
+
+ $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
+ }
+
+ if ($form->{media} !~ /(queue|screen)/) {
+ $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
+ $form->{printmode} = '|-';
+
+ if ($form->{printed} !~ /$form->{formname}/) {
+
+ $form->{printed} .= " $form->{formname}";
+ $form->{printed} =~ s/^ //;
+
+ $form->update_status(\%myconfig);
+ }
+
+ $old_form->{printed} = $form->{printed} if %$old_form;
+
+ %audittrail = ( tablename => lc $form->{ARAP},
+ reference => $form->{"invnumber"},
+ formname => $form->{formname},
+ action => 'printed',
+ id => $form->{id} );
+
+ $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if %$old_form;
+
+ }
+
+ $form->{fileid} = $form->{invnumber};
+ $form->{fileid} =~ s/(\s|\W)+//g;
+
+ $form->parse_template(\%myconfig);
+
+ if (%$old_form) {
+ $old_form->{invnumber} = $form->{invnumber};
+ $old_form->{invtotal} = $form->{invtotal};
+
+ for (keys %$form) { delete $form->{$_} }
+ for (keys %$old_form) { $form->{$_} = $old_form->{$_} }
+
+ if (! $form->{printandpost}) {
+ for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+
+ for (1 .. $form->{rowcount}) { $form->{"amount_$_"} = $form->parse_amount(\%myconfig, $form->{"amount_$_"}) }
+ for (split / /, $form->{taxaccounts}) { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) }
+
+ for $i (1 .. $form->{paidaccounts}) {
+ for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
+ }
+ }
+
+ &{ "$display_form" };
+
+ }
+
+}
+
+
+sub vendor_details { IR->vendor_details(\%myconfig, \%$form) };
+sub customer_details { IS->customer_details(\%myconfig, \%$form) };
+
+
+sub select_payment {
+
+ @column_index = ("ndx", "datepaid", "source", "memo", "paid", "$form->{ARAP}_paid");
+
+ # list payments with radio button on a form
+ $form->header;
+
+ $title = $locale->text('Select payment');
+
+ $column_data{ndx} = qq|<th width=1%>&nbsp;</th>|;
+ $column_data{datepaid} = qq|<th>|.$locale->text('Date').qq|</th>|;
+ $column_data{source} = qq|<th>|.$locale->text('Source').qq|</th>|;
+ $column_data{memo} = qq|<th>|.$locale->text('Memo').qq|</th>|;
+ $column_data{paid} = qq|<th>|.$locale->text('Amount').qq|</th>|;
+ $column_data{"$form->{ARAP}_paid"} = qq|<th>|.$locale->text('Account').qq|</th>|;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$title</th>
+ </tr>
+ <tr space=5></tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr class=listheading>|;
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+ </tr>
+|;
+
+ $checked = "checked";
+ foreach $i (1 .. $form->{paidaccounts} - 1) {
+
+ for (@column_index) { $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>| }
+
+ $paid = $form->{"paid_$i"};
+ $ok = 1;
+
+ $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
+ $column_data{paid} = qq|<td align=right>$paid</td>|;
+
+ $checked = "";
+
+ $j++; $j %= 2;
+ print qq|
+ <tr class=listrow$j>|;
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+ </tr>
+|;
+
+ }
+
+ print qq|
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+|;
+
+ for (qw(action nextsub)) { delete $form->{$_} }
+
+ $form->hide_form;
+
+ print qq|
+
+<br>
+<input type=hidden name=nextsub value=payment_selected>
+|;
+
+ if ($ok) {
+ print qq|
+<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>|;
+ }
+
+ print qq|
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+sub payment_selected {
+
+ &{ "print_$form->{formname}" }($form->{oldform}, $form->{ndx});
+
+}
+
+
+sub print_options {
+
+ if ($form->{selectlanguage}) {
+ $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
+ $form->{"selectlanguage"} =~ s/ selected//;
+ $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
+ $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
+ <input type=hidden name=selectlanguage value="|.
+ $form->escape($form->{selectlanguage},1).qq|">|;
+ }
+
+ $form->{selectformname} = $form->unescape($form->{selectformname});
+ $form->{selectformname} =~ s/ selected//;
+ $form->{selectformname} =~ s/(<option value="\Q$form->{formname}\E")/$1 selected/;
+
+ $type = qq|<select name=formname>$form->{selectformname}</select>
+ <input type=hidden name=selectformname value="|.$form->escape($form->{selectformname},1).qq|">|;
+
+ $media = qq|<select name=media>
+ <option value="screen">|.$locale->text('Screen');
+
+ $form->{selectformat} = qq|<option value="html">html\n|;
+
+ if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
+ for (sort keys %{LedgerSMB::Sysconfig::printer}) { $media .= qq|
+ <option value="$_">$_| }
+ }
+
+ if (${LedgerSMB::Sysconfig::latex}) {
+ $form->{selectformat} .= qq|
+ <option value="postscript">|.$locale->text('Postscript').qq|
+ <option value="pdf">|.$locale->text('PDF');
+ $media .= qq|<option value="queue">|.$locale->text('Queue');
+ }
+
+ $format = qq|<select name=format>$form->{selectformat}</select>|;
+ $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
+ $format .= qq|
+ <input type=hidden name=selectformat value="|.$form->escape($form->{selectformat},1).qq|">|;
+ $media .= qq|</select>|;
+ $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
+
+ print qq|
+ <table width=100%>
+ <tr>
+ <td>$type</td>
+ <td>$lang</td>
+ <td>$format</td>
+ <td>$media</td>
+ <td align=right width=90%>
+ |;
+
+ if ($form->{printed} =~ /$form->{formname}/) {
+ print $locale->text('Printed').qq|<br>|;
+ }
+
+ if ($form->{recurring}) {
+ print $locale->text('Scheduled');
+ }
+
+ print qq|
+ </td>
+ </tr>
+ </table>
+|;
+
+}
+
+
+sub print_and_post {
+
+ $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
+ $form->error($locale->text('Select a Printer!')) if $form->{media} eq 'screen';
+
+ $form->{printandpost} = 1;
+ $form->{display_form} = "post";
+ &print;
+
+}
+
+
diff --git a/bin/bp.pl b/bin/bp.pl
index 0d770bda..16fb2996 100755
--- a/bin/bp.pl
+++ b/bin/bp.pl
@@ -1,546 +1,547 @@
-#=====================================================================
-# LedgerSMB Small Medium Business Accounting
-# http://www.ledgersmb.org/
-#
-
-# Copyright (C) 2006
-# This work contains copyrighted information from a number of sources all used
-# with permission.
-#
-# This file contains source code included with or based on SQL-Ledger which
-# is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
-# under the GNU General Public License version 2 or, at your option, any later
-# version. For a full list including contact information of contributors,
-# maintainers, and copyright holders, see the CONTRIBUTORS file.
-#
-# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
-# Copyright (c) 2003
-#
-# Author: DWS Systems Inc.
-# Web: http://www.sql-ledger.org
-#
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#======================================================================
-#
-# Batch printing
-#
-#======================================================================
-
-
-use LedgerSMB::BP;
-
-1;
-# end of main
-
-
-sub search {
-
-# $locale->text('Sales Invoices')
-# $locale->text('Packing Lists')
-# $locale->text('Pick Lists')
-# $locale->text('Sales Orders')
-# $locale->text('Work Orders')
-# $locale->text('Purchase Orders')
-# $locale->text('Bin Lists')
-# $locale->text('Quotations')
-# $locale->text('RFQs')
-# $locale->text('Time Cards')
-
- # setup customer/vendor selection
- BP->get_vc(\%myconfig, \%$form);
-
- if (@{ $form->{"all_$form->{vc}"} }) {
- $name = "<option>\n";
- for (@{ $form->{"all_$form->{vc}"} }) { $name .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- $name = qq|<select name=$form->{vc}>$name</select>|;
- } else {
- $name = qq|<input name=$form->{vc} size=35>|;
- }
-
-# $locale->text('Customer')
-# $locale->text('Vendor')
-# $locale->text('Employee')
-
- %label = ( invoice => { title => 'Sales Invoices', name => 'Customer' },
- packing_list => { title => 'Packing Lists', name => 'Customer' },
- pick_list => { title => 'Pick Lists', name => 'Customer' },
- sales_order => { title => 'Sales Orders', name => 'Customer' },
- work_order => { title => 'Work Orders', name => 'Customer' },
- purchase_order => { title => 'Purchase Orders', name => 'Vendor' },
- bin_list => { title => 'Bin Lists', name => 'Vendor' },
- sales_quotation => { title => 'Quotations', name => 'Customer' },
- request_quotation => { title => 'RFQs', name => 'Vendor' },
- timecard => { title => 'Time Cards', name => 'Employee' },
- check => {title => 'Check', name => 'Vendor'},
- );
-
- $label{invoice}{invnumber} = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
- <td colspan=3><input name=invnumber size=20></td>
- </tr>
-|;
- $label{invoice}{ordnumber} = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
- <td colspan=3><input name=ordnumber size=20></td>
- </tr>
-|;
- $label{sales_quotation}{quonumber} = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Quotation Number').qq|</th>
- <td colspan=3><input name=quonumber size=20></td>
- </tr>
-|;
-
- $label{packing_list}{invnumber} = $label{invoice}{invnumber};
- $label{packing_list}{ordnumber} = $label{invoice}{ordnumber};
- $label{pick_list}{invnumber} = $label{invoice}{invnumber};
- $label{pick_list}{ordnumber} = $label{invoice}{ordnumber};
- $label{sales_order}{ordnumber} = $label{invoice}{ordnumber};
- $label{work_order}{ordnumber} = $label{invoice}{ordnumber};
- $label{purchase_order}{ordnumber} = $label{invoice}{ordnumber};
- $label{bin_list}{ordnumber} = $label{invoice}{ordnumber};
- $label{request_quotation}{quonumber} = $label{sales_quotation}{quonumber};
-
- # do one call to text
- $form->{title} = $locale->text('Print')." ".$locale->text($label{$form->{type}}{title});
-
- # accounting years
- if (@{ $form->{all_years} }) {
- # accounting years
- $form->{selectaccountingyear} = "<option>\n";
- for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
- $form->{selectaccountingmonth} = "<option>\n";
- for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
-
- $selectfrom = qq|
- <tr>
- <th align=right>|.$locale->text('Period').qq|</th>
- <td colspan=3>
- <select name=month>$form->{selectaccountingmonth}</select>
- <select name=year>$form->{selectaccountingyear}</select>
- <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
- <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
- <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
- <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
- </td>
- </tr>
-|;
- }
-
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-|;
-
- $form->hide_form(qw(vc type title));
-
- print qq|
-<table width=100%>
- <tr><th class=listtop>$form->{title}</th></tr>
- <tr height="5"></tr>
- <tr>
- <td>
- <table>
- <tr>
- <th align=right>|.$locale->text($label{$form->{type}}{name}).qq|</th>
- <td colspan=3>$name</td>
- </tr>
- $account
- $label{$form->{type}}{invnumber}
- $label{$form->{type}}{ordnumber}
- $label{$form->{type}}{quonumber}
- <tr>
- <th align=right nowrap>|.$locale->text('From').qq|</th>
- <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
- <th align=right>|.$locale->text('To').qq|</th>
- <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
- </tr>
- $selectfrom
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<input type=hidden name=sort value=transdate>
-<input type=hidden name=nextsub value=list_spool>
-
-<br>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
-|;
-
- $form->hide_form(qw(path login sessionid));
-
- print qq|
-
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
-
-sub remove {
-
- $selected = 0;
-
- for $i (1 .. $form->{rowcount}) {
- if ($form->{"checked_$i"}) {
- $selected = 1;
- last;
- }
- }
-
- $form->error($locale->text('Nothing selected!')) unless $selected;
-
- $form->{title} = $locale->text('Confirm!');
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-|;
-
- for (qw(action header)) { delete $form->{$_} }
-
- foreach $key (keys %$form) {
- print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
- }
-
- print qq|
-<h2 class=confirm>$form->{title}</h2>
-
-<h4>|.$locale->text('Are you sure you want to remove the marked entries from the queue?').qq|</h4>
-
-<button name="action" class="submit" type="submit" value="yes">|.$locale->text('Yes').qq|</button>
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
-
-sub yes {
-
- $form->info($locale->text('Removing marked entries from queue ...'));
- $form->{callback} .= "&header=1" if $form->{callback};
-
- if (BP->delete_spool(\%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool})) {
- $form->redirect($locale->text('Removed spoolfiles!'));
- } else {
- $form->error($locale->text('Cannot remove files!'));
- }
-
-}
-
-
-sub print {
-
- if ($form->{callback}) {
- for (1 .. $form->{rowcount}) { $form->{callback} .= "&checked_$_=1" if $form->{"checked_$_"} }
- $form->{callback} .= "&header=1";
- }
-
- for $i (1 .. $form->{rowcount}) {
- if ($form->{"checked_$i"}) {
- $form->{OUT} = "| ${LedgerSMB::Sysconfig::printer}{$form->{media}}";
- $form->info($locale->text('Printing')." ...");
-
- if (BP->print_spool(\%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool})) {
- print $locale->text('done');
- $form->redirect($locale->text('Marked entries printed!'));
- }
- exit;
- }
- }
-
- $form->error('Nothing selected!');
-
-}
-
-
-sub list_spool {
-
- $form->{$form->{vc}} = $form->unescape($form->{$form->{vc}});
- ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}});
-
- BP->get_spoolfiles(\%myconfig, \%$form);
-
- $title = $form->escape($form->{title});
- $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";
-
- $form->sort_order();
-
- $title = $form->escape($form->{title},1);
- $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";
-
- if ($form->{$form->{vc}}) {
- $callback .= "&$form->{vc}=".$form->escape($form->{$form->{vc}},1);
- $href .= "&$form->{vc}=".$form->escape($form->{$form->{vc}});
- $option = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor');
- $option .= " : $form->{$form->{vc}}";
- }
- if ($form->{account}) {
- $callback .= "&account=".$form->escape($form->{account},1);
- $href .= "&account=".$form->escape($form->{account});
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Account')." : $form->{account}";
- }
- if ($form->{invnumber}) {
- $callback .= "&invnumber=".$form->escape($form->{invnumber},1);
- $href .= "&invnumber=".$form->escape($form->{invnumber});
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Invoice Number')." : $form->{invnumber}";
- }
- if ($form->{ordnumber}) {
- $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1);
- $href .= "&ordnumber=".$form->escape($form->{ordnumber});
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Order Number')." : $form->{ordnumber}";
- }
- if ($form->{quonumber}) {
- $callback .= "&quonumber=".$form->escape($form->{quonumber},1);
- $href .= "&quonumber=".$form->escape($form->{quonumber});
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Quotation Number')." : $form->{quonumber}";
- }
-
- if ($form->{transdatefrom}) {
- $callback .= "&transdatefrom=$form->{transdatefrom}";
- $href .= "&transdatefrom=$form->{transdatefrom}";
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
- }
- if ($form->{transdateto}) {
- $callback .= "&transdateto=$form->{transdateto}";
- $href .= "&transdateto=$form->{transdateto}";
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 1);
- }
-
- $name = ucfirst $form->{vc};
-
- @columns = qw(transdate);
- if ($form->{type} =~ /(invoice)/) {
- push @columns, "invnumber";
- }
- if ($form->{type} =~ /(packing|pick)_list/) {
- push @columns, "invnumber";
- }
- if ($form->{type} =~ /_(order|list)$/) {
- push @columns, "ordnumber";
- }
- if ($form->{type} =~ /_quotation$/) {
- push @columns, "quonumber";
- }
- if ($form->{type} eq 'timecard') {
- push @columns, "id";
- }
-
-
- push @columns, (name, spoolfile);
- @column_index = $form->sort_columns(@columns);
- unshift @column_index, "checked";
-
- $column_header{checked} = "<th class=listheading>&nbsp;</th>";
- $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
- $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>";
- $column_header{ordnumber} = "<th><a class=listheading href=$href&sort=ordnumber>".$locale->text('Order')."</a></th>";
- $column_header{quonumber} = "<th><a class=listheading href=$href&sort=quonumber>".$locale->text('Quotation')."</a></th>";
- $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text($name)."</a></th>";
- $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>";
- $column_header{spoolfile} = "<th class=listheading>".$locale->text('Spoolfile')."</th>";
-
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>$option</td>
- </tr>
- <tr>
- <td>
- <table width=100%>
- <tr class=listheading>
-|;
-
- for (@column_index) { print "\n$column_header{$_}" }
-
- print qq|
- </tr>
-|;
-
-
- # add sort and escape callback, this one we use for the add sub
- $form->{callback} = $callback .= "&sort=$form->{sort}";
-
- # escape callback for href
- $callback = $form->escape($callback);
-
- $i = 0;
-
- foreach $ref (@{ $form->{SPOOL} }) {
-
- $i++;
-
- $form->{"checked_$i"} = "checked" if $form->{"checked_$i"};
-
- # this is for audittrail
- $form->{module} = $ref->{module};
-
- if ($ref->{invoice}) {
- $ref->{module} = ($ref->{module} eq 'ar') ? "is" : "ir";
- }
- $module = "$ref->{module}.pl";
-
- $column_data{transdate} = "<td>$ref->{transdate}&nbsp;</td>";
-
- if (${LedgerSMB::Sysconfig::spool} eq $ref->{spoolfile}) {
- $column_data{checked} = qq|<td></td>|;
- } else {
- $column_data{checked} = qq|<td><input name=checked_$i type=checkbox class=checkbox $form->{"checked_$i"} $form->{"checked_$i"}></td>|;
- }
-
- for (qw(id invnumber ordnumber quonumber)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| }
-
- if ($ref->{module} eq 'oe') {
- $column_data{invnumber} = qq|<td>&nbsp</td>|;
- $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>
- <input type=hidden name="reference_$i" value="$ref->{ordnumber}">|;
-
- $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>
- <input type=hidden name="reference_$i" value="$ref->{quonumber}">|;
-
- } elsif ($ref->{module} eq 'jc') {
- $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>
- <input type=hidden name="reference_$i" value="$ref->{id}">|;
- } else {
- $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>
- <input type=hidden name="reference_$i" value="$ref->{invnumber}">|;
- }
-
-
- $column_data{name} = "<td>$ref->{name}</td>";
- $column_data{spoolfile} = qq|<td><a href=${LedgerSMB::Sysconfig::spool}/$ref->{spoolfile}>$ref->{spoolfile}</a></td>
-
-|;
-
- ${LedgerSMB::Sysconfig::spool} = $ref->{spoolfile};
-
- $j++; $j %= 2;
- print "
- <tr class=listrow$j>
-";
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
-<input type=hidden name="id_$i" value=$ref->{id}>
-<input type=hidden name="spoolfile_$i" value=$ref->{spoolfile}>
-
- </tr>
-|;
-
- }
-
- print qq|
-<input type=hidden name=rowcount value=$i>
-
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<br>
-|;
-
- $form->hide_form(qw(callback title vc type sort module account path login sessionid));
-
- if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
- foreach $key (sort keys %{LedgerSMB::Sysconfig::printer}) {
- print qq|
-<input name=media type=radio class=radio value="$key" |;
- print qq|checked| if $key eq $myconfig{printer};
- print qq|>$key|;
- }
-
- print qq|<p>\n|;
-
-# type=submit $locale->text('Select all')
-# type=submit $locale->text('Print')
-# type=submit $locale->text('Remove')
-
- %button = ('select_all' => { ndx => 2, key => 'A', value => $locale->text('Select all') },
- 'print' => { ndx => 3, key => 'P', value => $locale->text('Print') },
- 'remove' => { ndx => 4, key => 'R', value => $locale->text('Remove') },
- );
-
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
-
- }
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
-sub select_all {
-
- for (1 .. $form->{rowcount}) { $form->{"checked_$_"} = 1 }
- &list_spool;
-
-}
-
-
-sub continue { &{ $form->{nextsub} } };
-
+#=====================================================================
+# LedgerSMB Small Medium Business Accounting
+# http://www.ledgersmb.org/
+#
+
+# Copyright (C) 2006
+# This work contains copyrighted information from a number of sources all used
+# with permission.
+#
+# This file contains source code included with or based on SQL-Ledger which
+# is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
+# under the GNU General Public License version 2 or, at your option, any later
+# version. For a full list including contact information of contributors,
+# maintainers, and copyright holders, see the CONTRIBUTORS file.
+#
+# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
+# Copyright (c) 2003
+#
+# Author: DWS Systems Inc.
+# Web: http://www.sql-ledger.org
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#======================================================================
+#
+# Batch printing
+#
+#======================================================================
+
+
+use LedgerSMB::BP;
+
+1;
+# end of main
+
+
+sub search {
+
+# $locale->text('Sales Invoices')
+# $locale->text('Packing Lists')
+# $locale->text('Pick Lists')
+# $locale->text('Sales Orders')
+# $locale->text('Work Orders')
+# $locale->text('Purchase Orders')
+# $locale->text('Bin Lists')
+# $locale->text('Quotations')
+# $locale->text('RFQs')
+# $locale->text('Time Cards')
+
+ # setup customer/vendor selection
+ BP->get_vc(\%myconfig, \%$form);
+
+ if (@{ $form->{"all_$form->{vc}"} }) {
+ $name = "<option>\n";
+ for (@{ $form->{"all_$form->{vc}"} }) { $name .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
+ $name = qq|<select name=$form->{vc}>$name</select>|;
+ } else {
+ $name = qq|<input name=$form->{vc} size=35>|;
+ }
+
+# $locale->text('Customer')
+# $locale->text('Vendor')
+# $locale->text('Employee')
+
+ %label = ( invoice => { title => 'Sales Invoices', name => 'Customer' },
+ packing_list => { title => 'Packing Lists', name => 'Customer' },
+ pick_list => { title => 'Pick Lists', name => 'Customer' },
+ sales_order => { title => 'Sales Orders', name => 'Customer' },
+ work_order => { title => 'Work Orders', name => 'Customer' },
+ purchase_order => { title => 'Purchase Orders', name => 'Vendor' },
+ bin_list => { title => 'Bin Lists', name => 'Vendor' },
+ sales_quotation => { title => 'Quotations', name => 'Customer' },
+ request_quotation => { title => 'RFQs', name => 'Vendor' },
+ timecard => { title => 'Time Cards', name => 'Employee' },
+ check => {title => 'Check', name => 'Vendor'},
+ );
+
+ $label{invoice}{invnumber} = qq|
+ <tr>
+ <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
+ <td colspan=3><input name=invnumber size=20></td>
+ </tr>
+|;
+ $label{invoice}{ordnumber} = qq|
+ <tr>
+ <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
+ <td colspan=3><input name=ordnumber size=20></td>
+ </tr>
+|;
+ $label{sales_quotation}{quonumber} = qq|
+ <tr>
+ <th align=right nowrap>|.$locale->text('Quotation Number').qq|</th>
+ <td colspan=3><input name=quonumber size=20></td>
+ </tr>
+|;
+
+ $label{packing_list}{invnumber} = $label{invoice}{invnumber};
+ $label{packing_list}{ordnumber} = $label{invoice}{ordnumber};
+ $label{pick_list}{invnumber} = $label{invoice}{invnumber};
+ $label{pick_list}{ordnumber} = $label{invoice}{ordnumber};
+ $label{sales_order}{ordnumber} = $label{invoice}{ordnumber};
+ $label{work_order}{ordnumber} = $label{invoice}{ordnumber};
+ $label{purchase_order}{ordnumber} = $label{invoice}{ordnumber};
+ $label{bin_list}{ordnumber} = $label{invoice}{ordnumber};
+ $label{request_quotation}{quonumber} = $label{sales_quotation}{quonumber};
+
+ # do one call to text
+ $form->{title} = $locale->text('Print')." ".$locale->text($label{$form->{type}}{title});
+
+ # accounting years
+ if (@{ $form->{all_years} }) {
+ # accounting years
+ $form->{selectaccountingyear} = "<option>\n";
+ for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
+ $form->{selectaccountingmonth} = "<option>\n";
+ for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
+
+ $selectfrom = qq|
+ <tr>
+ <th align=right>|.$locale->text('Period').qq|</th>
+ <td colspan=3>
+ <select name=month>$form->{selectaccountingmonth}</select>
+ <select name=year>$form->{selectaccountingyear}</select>
+ <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
+ <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
+ <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
+ <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
+ </td>
+ </tr>
+|;
+ }
+
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+|;
+
+ $form->hide_form(qw(vc type title));
+
+ print qq|
+<table width=100%>
+ <tr><th class=listtop>$form->{title}</th></tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>
+ <table>
+ <tr>
+ <th align=right>|.$locale->text($label{$form->{type}}{name}).qq|</th>
+ <td colspan=3>$name</td>
+ </tr>
+ $account
+ $label{$form->{type}}{invnumber}
+ $label{$form->{type}}{ordnumber}
+ $label{$form->{type}}{quonumber}
+ <tr>
+ <th align=right nowrap>|.$locale->text('From').qq|</th>
+ <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
+ <th align=right>|.$locale->text('To').qq|</th>
+ <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
+ </tr>
+ $selectfrom
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+<input type=hidden name=sort value=transdate>
+<input type=hidden name=nextsub value=list_spool>
+
+<br>
+<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+|;
+
+ $form->hide_form(qw(path login sessionid));
+
+ print qq|
+
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
+
+sub remove {
+
+ $selected = 0;
+
+ for $i (1 .. $form->{rowcount}) {
+ if ($form->{"checked_$i"}) {
+ $selected = 1;
+ last;
+ }
+ }
+
+ $form->error($locale->text('Nothing selected!')) unless $selected;
+
+ $form->{title} = $locale->text('Confirm!');
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+|;
+
+ for (qw(action header)) { delete $form->{$_} }
+
+ foreach $key (keys %$form) {
+ print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
+ }
+
+ print qq|
+<h2 class=confirm>$form->{title}</h2>
+
+<h4>|.$locale->text('Are you sure you want to remove the marked entries from the queue?').qq|</h4>
+
+<button name="action" class="submit" type="submit" value="yes">|.$locale->text('Yes').qq|</button>
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
+
+sub yes {
+
+ $form->info($locale->text('Removing marked entries from queue ...'));
+ $form->{callback} .= "&header=1" if $form->{callback};
+
+ if (BP->delete_spool(\%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool})) {
+ $form->redirect($locale->text('Removed spoolfiles!'));
+ } else {
+ $form->error($locale->text('Cannot remove files!'));
+ }
+
+}
+
+
+sub print {
+
+ if ($form->{callback}) {
+ for (1 .. $form->{rowcount}) { $form->{callback} .= "&checked_$_=1" if $form->{"checked_$_"} }
+ $form->{callback} .= "&header=1";
+ }
+
+ for $i (1 .. $form->{rowcount}) {
+ if ($form->{"checked_$i"}) {
+ $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
+ $form->{printmode} = '|-';
+ $form->info($locale->text('Printing')." ...");
+
+ if (BP->print_spool(\%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool})) {
+ print $locale->text('done');
+ $form->redirect($locale->text('Marked entries printed!'));
+ }
+ exit;
+ }
+ }
+
+ $form->error('Nothing selected!');
+
+}
+
+
+sub list_spool {
+
+ $form->{$form->{vc}} = $form->unescape($form->{$form->{vc}});
+ ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}});
+
+ BP->get_spoolfiles(\%myconfig, \%$form);
+
+ $title = $form->escape($form->{title});
+ $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";
+
+ $form->sort_order();
+
+ $title = $form->escape($form->{title},1);
+ $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";
+
+ if ($form->{$form->{vc}}) {
+ $callback .= "&$form->{vc}=".$form->escape($form->{$form->{vc}},1);
+ $href .= "&$form->{vc}=".$form->escape($form->{$form->{vc}});
+ $option = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor');
+ $option .= " : $form->{$form->{vc}}";
+ }
+ if ($form->{account}) {
+ $callback .= "&account=".$form->escape($form->{account},1);
+ $href .= "&account=".$form->escape($form->{account});
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Account')." : $form->{account}";
+ }
+ if ($form->{invnumber}) {
+ $callback .= "&invnumber=".$form->escape($form->{invnumber},1);
+ $href .= "&invnumber=".$form->escape($form->{invnumber});
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Invoice Number')." : $form->{invnumber}";
+ }
+ if ($form->{ordnumber}) {
+ $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1);
+ $href .= "&ordnumber=".$form->escape($form->{ordnumber});
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Order Number')." : $form->{ordnumber}";
+ }
+ if ($form->{quonumber}) {
+ $callback .= "&quonumber=".$form->escape($form->{quonumber},1);
+ $href .= "&quonumber=".$form->escape($form->{quonumber});
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Quotation Number')." : $form->{quonumber}";
+ }
+
+ if ($form->{transdatefrom}) {
+ $callback .= "&transdatefrom=$form->{transdatefrom}";
+ $href .= "&transdatefrom=$form->{transdatefrom}";
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
+ }
+ if ($form->{transdateto}) {
+ $callback .= "&transdateto=$form->{transdateto}";
+ $href .= "&transdateto=$form->{transdateto}";
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 1);
+ }
+
+ $name = ucfirst $form->{vc};
+
+ @columns = qw(transdate);
+ if ($form->{type} =~ /(invoice)/) {
+ push @columns, "invnumber";
+ }
+ if ($form->{type} =~ /(packing|pick)_list/) {
+ push @columns, "invnumber";
+ }
+ if ($form->{type} =~ /_(order|list)$/) {
+ push @columns, "ordnumber";
+ }
+ if ($form->{type} =~ /_quotation$/) {
+ push @columns, "quonumber";
+ }
+ if ($form->{type} eq 'timecard') {
+ push @columns, "id";
+ }
+
+
+ push @columns, (name, spoolfile);
+ @column_index = $form->sort_columns(@columns);
+ unshift @column_index, "checked";
+
+ $column_header{checked} = "<th class=listheading>&nbsp;</th>";
+ $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
+ $column_header{invnumber} = "<th><a class=listheading href=$href&sort=invnumber>".$locale->text('Invoice')."</a></th>";
+ $column_header{ordnumber} = "<th><a class=listheading href=$href&sort=ordnumber>".$locale->text('Order')."</a></th>";
+ $column_header{quonumber} = "<th><a class=listheading href=$href&sort=quonumber>".$locale->text('Quotation')."</a></th>";
+ $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text($name)."</a></th>";
+ $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>";
+ $column_header{spoolfile} = "<th class=listheading>".$locale->text('Spoolfile')."</th>";
+
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>$option</td>
+ </tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr class=listheading>
+|;
+
+ for (@column_index) { print "\n$column_header{$_}" }
+
+ print qq|
+ </tr>
+|;
+
+
+ # add sort and escape callback, this one we use for the add sub
+ $form->{callback} = $callback .= "&sort=$form->{sort}";
+
+ # escape callback for href
+ $callback = $form->escape($callback);
+
+ $i = 0;
+
+ foreach $ref (@{ $form->{SPOOL} }) {
+
+ $i++;
+
+ $form->{"checked_$i"} = "checked" if $form->{"checked_$i"};
+
+ # this is for audittrail
+ $form->{module} = $ref->{module};
+
+ if ($ref->{invoice}) {
+ $ref->{module} = ($ref->{module} eq 'ar') ? "is" : "ir";
+ }
+ $module = "$ref->{module}.pl";
+
+ $column_data{transdate} = "<td>$ref->{transdate}&nbsp;</td>";
+
+ if (${LedgerSMB::Sysconfig::spool} eq $ref->{spoolfile}) {
+ $column_data{checked} = qq|<td></td>|;
+ } else {
+ $column_data{checked} = qq|<td><input name=checked_$i type=checkbox class=checkbox $form->{"checked_$i"} $form->{"checked_$i"}></td>|;
+ }
+
+ for (qw(id invnumber ordnumber quonumber)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| }
+
+ if ($ref->{module} eq 'oe') {
+ $column_data{invnumber} = qq|<td>&nbsp</td>|;
+ $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>
+ <input type=hidden name="reference_$i" value="$ref->{ordnumber}">|;
+
+ $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>
+ <input type=hidden name="reference_$i" value="$ref->{quonumber}">|;
+
+ } elsif ($ref->{module} eq 'jc') {
+ $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>
+ <input type=hidden name="reference_$i" value="$ref->{id}">|;
+ } else {
+ $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>
+ <input type=hidden name="reference_$i" value="$ref->{invnumber}">|;
+ }
+
+
+ $column_data{name} = "<td>$ref->{name}</td>";
+ $column_data{spoolfile} = qq|<td><a href=${LedgerSMB::Sysconfig::spool}/$ref->{spoolfile}>$ref->{spoolfile}</a></td>
+
+|;
+
+ ${LedgerSMB::Sysconfig::spool} = $ref->{spoolfile};
+
+ $j++; $j %= 2;
+ print "
+ <tr class=listrow$j>
+";
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+<input type=hidden name="id_$i" value=$ref->{id}>
+<input type=hidden name="spoolfile_$i" value=$ref->{spoolfile}>
+
+ </tr>
+|;
+
+ }
+
+ print qq|
+<input type=hidden name=rowcount value=$i>
+
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+<br>
+|;
+
+ $form->hide_form(qw(callback title vc type sort module account path login sessionid));
+
+ if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
+ foreach $key (sort keys %{LedgerSMB::Sysconfig::printer}) {
+ print qq|
+<input name=media type=radio class=radio value="$key" |;
+ print qq|checked| if $key eq $myconfig{printer};
+ print qq|>$key|;
+ }
+
+ print qq|<p>\n|;
+
+# type=submit $locale->text('Select all')
+# type=submit $locale->text('Print')
+# type=submit $locale->text('Remove')
+
+ %button = ('select_all' => { ndx => 2, key => 'A', value => $locale->text('Select all') },
+ 'print' => { ndx => 3, key => 'P', value => $locale->text('Print') },
+ 'remove' => { ndx => 4, key => 'R', value => $locale->text('Remove') },
+ );
+
+ for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
+
+ }
+
+ if ($form->{lynx}) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
+sub select_all {
+
+ for (1 .. $form->{rowcount}) { $form->{"checked_$_"} = 1 }
+ &list_spool;
+
+}
+
+
+sub continue { &{ $form->{nextsub} } };
+
diff --git a/bin/cp.pl b/bin/cp.pl
index 0facb738..95a19254 100755
--- a/bin/cp.pl
+++ b/bin/cp.pl
@@ -1273,7 +1273,8 @@ sub print_form {
$form->{IN} = "$form->{formname}.tex";
if ($form->{media} ne 'screen') {
- $form->{OUT} = "| ${LedgerSMB::Sysconfig::printer}{$form->{media}}";
+ $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
+ $form->{printmode} = '|-';
}
$form->parse_template(\%myconfig, ${LedgerSMB::Sysconfig::userspath});
diff --git a/bin/io.pl b/bin/io.pl
index ec824540..67db96ac 100755
--- a/bin/io.pl
+++ b/bin/io.pl
@@ -1,1703 +1,1706 @@
-######################################################################
-# LedgerSMB Small Medium Business Accounting
-# http://www.ledgersmb.org/
-#
-
-# Copyright (C) 2006
-# This work contains copyrighted information from a number of sources all used
-# with permission.
-#
-# This file contains source code included with or based on SQL-Ledger which
-# is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
-# under the GNU General Public License version 2 or, at your option, any later
-# version. For a full list including contact information of contributors,
-# maintainers, and copyright holders, see the CONTRIBUTORS file.
-#
-# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
-# Copyright (c) 2002
-#
-# Author: DWS Systems Inc.
-# Web: http://www.sql-ledger.org
-#
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#######################################################################
-#
-# common routines used in is, ir, oe
-#
-#######################################################################
-
-use LedgerSMB::Tax;
-use LedgerSMB::Sysconfig;
-
-# any custom scripts for this one
-if (-f "bin/custom/io.pl") {
- eval { require "bin/custom/io.pl"; };
-}
-if (-f "bin/custom/$form->{login}_io.pl") {
- eval { require "bin/custom/$form->{login}_io.pl"; };
-}
-
-
-1;
-# end of main
-
-
-# this is for our long dates
-# $locale->text('January')
-# $locale->text('February')
-# $locale->text('March')
-# $locale->text('April')
-# $locale->text('May ')
-# $locale->text('June')
-# $locale->text('July')
-# $locale->text('August')
-# $locale->text('September')
-# $locale->text('October')
-# $locale->text('November')
-# $locale->text('December')
-
-# this is for our short month
-# $locale->text('Jan')
-# $locale->text('Feb')
-# $locale->text('Mar')
-# $locale->text('Apr')
-# $locale->text('May')
-# $locale->text('Jun')
-# $locale->text('Jul')
-# $locale->text('Aug')
-# $locale->text('Sep')
-# $locale->text('Oct')
-# $locale->text('Nov')
-# $locale->text('Dec')
-
-
-sub display_row {
- my $numrows = shift;
-
- @column_index = qw(runningnumber partnumber description qty);
-
- if ($form->{type} eq "sales_order") {
- push @column_index, "ship";
- $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Ship').qq|</th>|;
- }
- if ($form->{type} eq "purchase_order") {
- push @column_index, "ship";
- $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Recd').qq|</th>|;
- }
-
- for (qw(projectnumber partsgroup)) {
- $form->{"select$_"} = $form->unescape($form->{"select$_"}) if $form->{"select$_"};
- }
-
- if ($form->{language_code} ne $form->{oldlanguage_code}) {
- # rebuild partsgroup
- $l{language_code} = $form->{language_code};
- $l{searchitems} = 'nolabor' if $form->{vc} eq 'customer';
-
- $form->get_partsgroup(\%myconfig, \%l);
- if (@ { $form->{all_partsgroup} }) {
- $form->{selectpartsgroup} = "<option>\n";
- foreach $ref (@ { $form->{all_partsgroup} }) {
- if ($ref->{translation}) {
- $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{translation}\n|;
- } else {
- $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|;
- }
- }
- }
- $form->{oldlanguage_code} = $form->{language_code};
- }
-
-
- push @column_index, @{LedgerSMB::Sysconfig::io_lineitem_columns};
-
- my $colspan = $#column_index + 1;
-
- $form->{invsubtotal} = 0;
- for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
-
- $column_data{runningnumber} = qq|<th class=listheading nowrap>|.$locale->text('Item').qq|</th>|;
- $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
- $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|;
- $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
- $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
- $column_data{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Price').qq|</th>|;
- $column_data{discount} = qq|<th class=listheading>%</th>|;
- $column_data{linetotal} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;
- $column_data{bin} = qq|<th class=listheading nowrap>|.$locale->text('Bin').qq|</th>|;
- $column_data{onhand} = qq|<th class=listheading nowrap>|.$locale->text('OH').qq|</th>|;
-
- print qq|
- <tr>
- <td>
- <table width=100%>
- <tr class=listheading>|;
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
- </tr>
-|;
-
-
- $deliverydate = $locale->text('Delivery Date');
- $serialnumber = $locale->text('Serial No.');
- $projectnumber = $locale->text('Project');
- $group = $locale->text('Group');
- $sku = $locale->text('SKU');
-
- $delvar = 'deliverydate';
-
- if ($form->{type} =~ /_(order|quotation)$/) {
- $reqdate = $locale->text('Required by');
- $delvar = 'reqdate';
- }
-
- $exchangerate = $form->parse_amount(\%myconfig, $form->{exchangerate});
- $exchangerate = ($exchangerate) ? $exchangerate : 1;
-
- $spc = substr($myconfig{numberformat},-3,1);
- for $i (1 .. $numrows) {
- if ($spc eq '.') {
- ($null, $dec) = split /\./, $form->{"sellprice_$i"};
- } else {
- ($null, $dec) = split /,/, $form->{"sellprice_$i"};
- }
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
-
- # undo formatting
- for (qw(qty oldqty ship discount sellprice)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- if ($form->{"qty_$i"} != $form->{"oldqty_$i"}) {
- # check pricematrix
- @a = split / /, $form->{"pricematrix_$i"};
- if (scalar @a > 2) {
- foreach $item (@a) {
- ($q, $p) = split /:/, $item;
- if (($p * 1) && ($form->{"qty_$i"} >= ($q * 1))) {
- ($dec) = ($p =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
- $form->{"sellprice_$i"} = $form->round_amount($p / $exchangerate, $decimalplaces);
- }
- }
- }
- }
-
- $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces);
- $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
- $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
-
-
- if (($rows = $form->numtextrows($form->{"description_$i"}, 46, 6)) > 1) {
- $form->{"description_$i"} = $form->quote($form->{"description_$i"});
- $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=46 wrap=soft>$form->{"description_$i"}</textarea></td>|;
- } else {
- $form->{"description_$i"} = $form->quote($form->{"description_$i"});
- $column_data{description} = qq|<td><input name="description_$i" size=48 value="$form->{"description_$i"}"></td>|;
- }
-
- for (qw(partnumber sku unit)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
-
- $skunumber = qq|
- <p><b>$sku</b> $form->{"sku_$i"}| if ($form->{vc} eq 'vendor' && $form->{"sku_$i"});
-
-
- if ($form->{selectpartsgroup}) {
- if ($i < $numrows) {
- $partsgroup = qq|
- <b>$group</b>
- <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">|;
- ($form->{"partsgroup_$i"}) = split /--/, $form->{"partsgroup_$i"};
- $partsgroup .= $form->{"partsgroup_$i"};
- $partsgroup = "" unless $form->{"partsgroup_$i"};
- }
- }
-
- $delivery = qq|
- <td colspan=2 nowrap>
- <b>${$delvar}</b>
- <input name="${delvar}_$i" size=11 title="$myconfig{dateformat}" value="$form->{"${delvar}_$i"}"></td>
-|;
-
- $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=3 value=$i></td>|;
- $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}" accesskey="$i" title="[Alt-$i]">$skunumber</td>|;
- $column_data{qty} = qq|<td align=right><input name="qty_$i" title="$form->{"onhand_$i"}" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|;
- $column_data{ship} = qq|<td align=right><input name="ship_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"ship_$i"}).qq|></td>|;
- $column_data{unit} = qq|<td><input name="unit_$i" size=5 value="$form->{"unit_$i"}"></td>|;
- $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;
- $column_data{discount} = qq|<td align=right><input name="discount_$i" size=3 value=|.$form->format_amount(\%myconfig, $form->{"discount_$i"}).qq|></td>|;
- $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|;
- $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
- $column_data{onhand} = qq|<td>$form->{"onhand_$i"}</td>|;
-
- print qq|
- <tr valign=top>|;
-
- for (@column_index) {
- print "\n$column_data{$_}";
- }
-
- print qq|
- </tr>
-<input type=hidden name="oldqty_$i" value="$form->{"qty_$i"}">
-|;
-
- for (qw(orderitems_id id bin weight listprice lastcost taxaccounts pricematrix sku onhand assembly inventory_accno_id income_accno_id expense_accno_id)) {
- $form->hide_form("${_}_$i");
- }
-
- $form->{selectprojectnumber} =~ s/ selected//;
- $form->{selectprojectnumber} =~ s/(<option value="\Q$form->{"projectnumber_$i"}\E")/$1 selected/;
-
- $project = qq|
- <b>$projectnumber</b>
- <select name="projectnumber_$i">$form->{selectprojectnumber}</select>
-| if $form->{selectprojectnumber};
-
-
- if (($rows = $form->numtextrows($form->{"notes_$i"}, 46, 6)) > 1) {
- $form->{"notes_$i"} = $form->quote($form->{"notes_$i"});
- $notes = qq|<td><textarea name="notes_$i" rows=$rows cols=46 wrap=soft>$form->{"notes_$i"}</textarea></td>|;
- } else {
- $form->{"notes_$i"} = $form->quote($form->{"notes_$i"});
- $notes = qq|<td><input name="notes_$i" size=48 value="$form->{"notes_$i"}"></td>|;
- }
-
- $serial = qq|
- <td colspan=6 nowrap><b>$serialnumber</b> <input name="serialnumber_$i" value="$form->{"serialnumber_$i"}"></td>| if $form->{type} !~ /_quotation/;
-
- if ($i == $numrows) {
- $partsgroup = "";
- if ($form->{selectpartsgroup}) {
- $partsgroup = qq|
- <b>$group</b>
- <select name="partsgroup_$i">$form->{selectpartsgroup}</select>
-|;
- }
-
- $serial = "";
- $project = "";
- $delivery = "";
- $notes = "";
- }
-
-
- # print second and third row
- print qq|
- <tr valign=top>
- $delivery
- $notes
- $serial
- </tr>
- <tr valign=top>
- <td colspan=$colspan>
- $project
- $partsgroup
- </td>
- </tr>
- <tr>
- <td colspan=$colspan><hr size=1 noshade></td>
- </tr>
-|;
-
- $skunumber = "";
-
- for (split / /, $form->{"taxaccounts_$i"}) {
- $form->{"${_}_base"} += $linetotal;
- }
-
- $form->{invsubtotal} += $linetotal;
- }
-
- print qq|
- </table>
- </td>
- </tr>
-|;
-
- $form->hide_form(qw(audittrail));
-
- print qq|
-
-<input type=hidden name=oldcurrency value=$form->{currency}>
-
-<input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|">
-<input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">
-
-|;
-
-}
-
-
-sub select_item {
-
- if ($form->{vc} eq "vendor") {
- @column_index = qw(ndx partnumber sku description partsgroup onhand sellprice);
- } else {
- @column_index = qw(ndx partnumber description partsgroup onhand sellprice);
- }
-
- $column_data{ndx} = qq|<th>&nbsp;</th>|;
- $column_data{partnumber} = qq|<th class=listheading>|.$locale->text('Number').qq|</th>|;
- $column_data{sku} = qq|<th class=listheading>|.$locale->text('SKU').qq|</th>|;
- $column_data{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
- $column_data{partsgroup} = qq|<th class=listheading>|.$locale->text('Group').qq|</th>|;
- $column_data{sellprice} = qq|<th class=listheading>|.$locale->text('Price').qq|</th>|;
- $column_data{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
-
- $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
-
- # list items with radio button on a form
- $form->header;
-
- $title = $locale->text('Select items');
-
- print qq|
-<body>
-
-<form method=post action="$form->{script}">
-
-<table width=100%>
- <tr>
- <th class=listtop>$title</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>$option</td>
- </tr>
- <tr>
- <td>
- <table width=100%>
- <tr class=listheading>|;
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
- </tr>
-|;
-
- my $i = 0;
- foreach $ref (@{ $form->{item_list} }) {
- $i++;
-
- for (qw(sku partnumber description unit notes partsgroup)) {
- $ref->{$_} = $form->quote($ref->{$_});
- }
-
- $column_data{ndx} = qq|<td><input name="ndx_$i" class=checkbox type=checkbox value=$i></td>|;
-
- for (qw(partnumber sku description partsgroup)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
-
- $column_data{sellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{sellprice} / $exchangerate, 2, "&nbsp;").qq|</td>|;
- $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;").qq|</td>|;
-
- $j++; $j %= 2;
- print qq|
- <tr class=listrow$j>|;
-
- for (@column_index) {
- print "\n$column_data{$_}";
- }
-
- print qq|
- </tr>
-|;
-
- for (qw(partnumber sku description partsgroup partsgroup_id bin weight sellprice listprice lastcost onhand unit assembly taxaccounts inventory_accno_id income_accno_id expense_accno_id pricematrix id notes)) {
- print qq|<input type=hidden name="new_${_}_$i" value="$ref->{$_}">\n|;
- }
- }
-
- print qq|
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<input name=lastndx type=hidden value=$i>
-
-|;
-
- # delete variables
- for (qw(nextsub item_list)) { delete $form->{$_} }
-
- $form->{action} = "item_selected";
-
- $form->hide_form;
-
- print qq|
-<input type="hidden" name="nextsub" value="item_selected">
-
-<br>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
-
-sub item_selected {
-
- $i = $form->{rowcount} - 1;
- $i = $form->{assembly_rows} - 1 if ($form->{item} eq 'assembly');
- $qty = ($form->{"qty_$form->{rowcount}"}) ? $form->{"qty_$form->{rowcount}"} : 1;
-
- for $j (1 .. $form->{lastndx}) {
-
- if ($form->{"ndx_$j"}) {
-
- $i++;
-
- $form->{"qty_$i"} = $qty;
- $form->{"discount_$i"} = $form->{discount} * 100;
- $form->{"reqdate_$i"} = $form->{reqdate} if $form->{type} !~ /_quotation/;
-
- for (qw(id partnumber sku description sellprice listprice lastcost bin unit weight assembly taxaccounts pricematrix onhand notes inventory_accno_id income_accno_id expense_accno_id)) {
- $form->{"${_}_$i"} = $form->{"new_${_}_$j"};
- }
-
- $form->{"partsgroup_$i"} = qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|;
-
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces1 = ($dec > 2) ? $dec : 2;
-
- ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces2 = ($dec > 2) ? $dec : 2;
-
- # if there is an exchange rate adjust sellprice
- if (($form->{exchangerate} * 1)) {
- for (qw(sellprice listprice lastcost)) { $form->{"${_}_$i"} /= $form->{exchangerate} }
- # don't format list and cost
- $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"}, $decimalplaces1);
- }
-
- # this is for the assembly
- if ($form->{item} eq 'assembly') {
- $form->{"adj_$i"} = 1;
-
- for (qw(sellprice listprice weight)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-
- $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
- $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
- }
-
- $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
- for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
- if (!$form->{taxincluded}) {
- my @taxlist= Tax::init_taxes($form, $form->{"taxaccounts_$i"});
- $amount += Tax::calculate_taxes(\@taxlist, $form, $amount, 0);
- }
-
- $form->{creditremaining} -= $amount;
-
- $form->{"runningnumber_$i"} = $i;
-
- # format amounts
- if ($form->{item} ne 'assembly') {
- for (qw(sellprice listprice)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces1) }
- $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces2);
- }
- $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"});
-
- }
- }
-
- $form->{rowcount} = $i;
- $form->{assembly_rows} = $i if ($form->{item} eq 'assembly');
-
- $form->{focus} = "description_$i";
-
- # delete all the new_ variables
- for $i (1 .. $form->{lastndx}) {
- for (qw(id partnumber sku description sellprice listprice lastcost bin unit weight assembly taxaccounts pricematrix onhand notes inventory_accno_id income_accno_id expense_accno_id)) {
- delete $form->{"new_${_}_$i"};
- }
- }
-
- for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
-
- &display_form;
-
-}
-
-
-sub new_item {
-
- if ($form->{language_code} && $form->{"description_$form->{rowcount}"}) {
- $form->error($locale->text('Translation not on file!'));
- }
-
- # change callback
- $form->{old_callback} = $form->escape($form->{callback},1);
- $form->{callback} = $form->escape("$form->{script}?action=display_form",1);
-
- # delete action
- delete $form->{action};
-
- # save all other form variables in a previousform variable
- if (!$form->{previousform}) {
- foreach $key (keys %$form) {
- # escape ampersands
- $form->{$key} =~ s/&/%26/g;
- $form->{previousform} .= qq|$key=$form->{$key}&|;
- }
- chop $form->{previousform};
- $form->{previousform} = $form->escape($form->{previousform}, 1);
- }
-
- $i = $form->{rowcount};
- for (qw(partnumber description)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
-
- $form->header;
-
- print qq|
-<body>
-
-<h4 class=error>|.$locale->text('Item not on file!').qq|</h4>|;
-
- if ($myconfig{acs} !~ /(Goods \& Services--Add Part|Goods \& Services--Add Service)/) {
-
- print qq|
-<h4>|.$locale->text('What type of item is this?').qq|</h4>
-
-<form method=post action=ic.pl>
-
-<p>
-
- <input class=radio type=radio name=item value=part checked>&nbsp;|.$locale->text('Part')
-.qq|<br>
- <input class=radio type=radio name=item value=service>&nbsp;|.$locale->text('Service')
-
-.qq|
-<input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
-<input type=hidden name=description value="$form->{"description_$i"}">
-<input type=hidden name=nextsub value=add>
-<input type=hidden name=action value=add>
-|;
-
- $form->hide_form(qw(previousform rowcount path login sessionid));
-
- print qq|
-<p>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
-</form>
-|;
- }
-
- print qq|
-</body>
-</html>
-|;
-
-}
-
-
-
-sub display_form {
-
- # if we have a display_form
- if ($form->{display_form}) {
- &{ "$form->{display_form}" };
- exit;
- }
-
- &form_header;
-
- $numrows = ++$form->{rowcount};
- $subroutine = "display_row";
-
- if ($form->{item} eq 'part') {
- # create makemodel rows
- &makemodel_row(++$form->{makemodel_rows});
-
- &vendor_row(++$form->{vendor_rows});
-
- $numrows = ++$form->{customer_rows};
- $subroutine = "customer_row";
- }
- if ($form->{item} eq 'assembly') {
- # create makemodel rows
- &makemodel_row(++$form->{makemodel_rows});
-
- $numrows = ++$form->{customer_rows};
- $subroutine = "customer_row";
- }
- if ($form->{item} eq 'service') {
- &vendor_row(++$form->{vendor_rows});
-
- $numrows = ++$form->{customer_rows};
- $subroutine = "customer_row";
- }
- if ($form->{item} eq 'labor') {
- $numrows = 0;
- }
-
- # create rows
- &{ $subroutine }($numrows) if $numrows;
-
- &form_footer;
-
-}
-
-
-
-sub check_form {
-
- my @a = ();
- my $count = 0;
- my $i;
- my $j;
- my @flds = qw(id runningnumber partnumber description partsgroup qty ship unit sellprice discount oldqty orderitems_id bin weight listprice lastcost taxaccounts pricematrix sku onhand assembly inventory_accno_id income_accno_id expense_accno_id notes reqdate deliverydate serialnumber projectnumber);
-
- # remove any makes or model rows
- if ($form->{item} eq 'part') {
- for (qw(listprice sellprice lastcost avgcost weight rop markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-
- &calc_markup;
-
- @flds = qw(make model);
- $count = 0;
- @a = ();
- for $i (1 .. $form->{makemodel_rows}) {
- if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
- push @a, {};
- $j = $#a;
-
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
- }
- }
-
- $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
- $form->{makemodel_rows} = $count;
-
- &check_vendor;
- &check_customer;
-
- }
-
- if ($form->{item} eq 'service') {
-
- for (qw(sellprice listprice lastcost avgcost markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-
- &calc_markup;
- &check_vendor;
- &check_customer;
-
- }
-
- if ($form->{item} eq 'assembly') {
-
- if (!$form->{project_id}) {
- $form->{sellprice} = 0;
- $form->{listprice} = 0;
- $form->{lastcost} = 0;
- $form->{weight} = 0;
- }
-
- for (qw(rop stock markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-
- @flds = qw(id qty unit bom adj partnumber description sellprice listprice lastcost weight assembly runningnumber partsgroup);
- $count = 0;
- @a = ();
-
- for $i (1 .. ($form->{assembly_rows} - 1)) {
- if ($form->{"qty_$i"}) {
- push @a, {};
- my $j = $#a;
-
- $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
-
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
-
- if (! $form->{project_id}) {
- for (qw(sellprice listprice weight lastcost)) { $form->{$_} += ($form->{"${_}_$i"} * $form->{"qty_$i"}) }
- }
-
- $count++;
- }
- }
-
- if ($form->{markup} && $form->{markup} != $form->{oldmarkup}) {
- $form->{sellprice} = 0;
- &calc_markup;
- }
-
- for (qw(sellprice lastcost listprice)) { $form->{$_} = $form->round_amount($form->{$_}, 2) }
-
- $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
- $form->{assembly_rows} = $count;
-
- $count = 0;
- @flds = qw(make model);
- @a = ();
-
- for $i (1 .. ($form->{makemodel_rows})) {
- if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
- push @a, {};
- my $j = $#a;
-
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
- }
- }
-
- $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
- $form->{makemodel_rows} = $count;
-
- &check_customer;
-
- }
-
- if ($form->{type}) {
-
- # this section applies to invoices and orders
- # remove any empty numbers
-
- $count = 0;
- @a = ();
- if ($form->{rowcount}) {
- for $i (1 .. $form->{rowcount} - 1) {
- if ($form->{"partnumber_$i"}) {
- push @a, {};
- my $j = $#a;
-
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
- }
- }
-
- $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
- $form->{rowcount} = $count;
-
- $form->{creditremaining} -= &invoicetotal;
-
- }
- }
-
- &display_form;
-
-}
-
-
-sub calc_markup {
-
- if ($form->{markup}) {
- if ($form->{markup} != $form->{oldmarkup}) {
- if ($form->{lastcost}) {
- $form->{sellprice} = $form->{lastcost} * (1 + $form->{markup}/100);
- $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
- } else {
- $form->{lastcost} = $form->{sellprice} / (1 + $form->{markup}/100);
- $form->{lastcost} = $form->round_amount($form->{lastcost}, 2);
- }
- }
- } else {
- if ($form->{lastcost}) {
- $form->{markup} = $form->round_amount(((1 - $form->{sellprice} / $form->{lastcost}) * 100), 1);
- }
- $form->{markup} = "" if $form->{markup} == 0;
- }
-
-}
-
-
-sub invoicetotal {
-
- $form->{oldinvtotal} = 0;
- # add all parts and deduct paid
- for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
-
- my ($amount, $sellprice, $discount, $qty);
-
- for $i (1 .. $form->{rowcount}) {
- $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
- $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
- $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
-
- $amount = $sellprice * (1 - $discount / 100) * $qty;
- for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
- $form->{oldinvtotal} += $amount;
- }
-
- if (!$form->{taxincluded}) {
- my @taxlist= Tax::init_taxes($form, $form->{taxaccounts});
- $form->{oldinvtotal} += Tax::calculate_taxes(\@taxlist, $form,
- $amount, 0);
- }
-
- $form->{oldtotalpaid} = 0;
- for $i (1 .. $form->{paidaccounts}) {
- $form->{oldtotalpaid} += $form->{"paid_$i"};
- }
-
- # return total
- ($form->{oldinvtotal} - $form->{oldtotalpaid});
-
-}
-
-
-sub validate_items {
-
- # check if items are valid
- if ($form->{rowcount} == 1) {
- &update;
- exit;
- }
-
- for $i (1 .. $form->{rowcount} - 1) {
- $form->isblank("partnumber_$i", $locale->text('Number missing in Row [_1]', $i));
- }
-
-}
-
-
-
-sub purchase_order {
-
- $form->{title} = $locale->text('Add Purchase Order');
- $form->{vc} = 'vendor';
- $form->{type} = 'purchase_order';
- $buysell = 'sell';
-
- &create_form;
-
-}
-
-
-sub sales_order {
-
- $form->{title} = $locale->text('Add Sales Order');
- $form->{vc} = 'customer';
- $form->{type} = 'sales_order';
- $buysell = 'buy';
-
- &create_form;
-
-}
-
-
-sub rfq {
-
- $form->{title} = $locale->text('Add Request for Quotation');
- $form->{vc} = 'vendor';
- $form->{type} = 'request_quotation';
- $buysell = 'sell';
-
- &create_form;
-
-}
-
-
-sub quotation {
-
- $form->{title} = $locale->text('Add Quotation');
- $form->{vc} = 'customer';
- $form->{type} = 'sales_quotation';
- $buysell = 'buy';
-
- &create_form;
-
-}
-
-
-sub create_form {
-
- for (qw(id printed emailed queued)) { delete $form->{$_} }
-
- $form->{script} = 'oe.pl';
-
- $form->{shipto} = 1;
-
- $form->{rowcount}-- if $form->{rowcount};
- $form->{rowcount} = 0 if ! $form->{"$form->{vc}_id"};
-
- do "bin/$form->{script}";
-
- for ("$form->{vc}", "currency") { $form->{"select$_"} = "" }
-
- for (qw(currency employee department intnotes notes language_code taxincluded)) { $temp{$_} = $form->{$_} }
-
- &order_links;
-
- for (keys %temp) { $form->{$_} = $temp{$_} if $temp{$_} }
-
- $form->{exchangerate} = "";
- $form->{forex} = "";
- if ($form->{currency} ne $form->{defaultcurrency}) {
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell)));
- }
-
- &prepare_order;
-
- &display_form;
-
-}
-
-
-
-sub e_mail {
-
- $bcc = qq|<input type=hidden name=bcc value="$form->{bcc}">|;
- if ($myconfig{role} =~ /(admin|manager)/) {
- $bcc = qq|
- <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
- <td><input name=bcc size=30 value="$form->{bcc}"></td>
-|;
- }
-
- if ($form->{formname} =~ /(pick|packing|bin)_list/) {
- $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
- }
-
- $name = $form->{$form->{vc}};
- $name =~ s/--.*//g;
- $title = $locale->text('E-mail')." $name";
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action="$form->{script}">
-
-<table width=100%>
- <tr class=listtop>
- <th class=listtop>$title</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>
- <table width=100%>
- <tr>
- <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
- <td><input name=email size=30 value="$form->{email}"></td>
- <th align=right nowrap>|.$locale->text('Cc').qq|</th>
- <td><input name=cc size=30 value="$form->{cc}"></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Subject').qq|</th>
- <td><input name=subject size=30 value="$form->{subject}"></td>
- $bcc
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td>
- <table width=100%>
- <tr>
- <th align=left nowrap>|.$locale->text('Message').qq|</th>
- </tr>
- <tr>
- <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td>
-|;
-
- $form->{oldmedia} = $form->{media};
- $form->{media} = "email";
- $form->{format} = "pdf";
-
- &print_options;
-
- for (qw(email cc bcc subject message formname sendmode format language_code action nextsub)) { delete $form->{$_} }
-
- $form->hide_form;
-
- print qq|
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<input type="hidden" name="nextsub" value="send_email">
-
-<br>
-<button name="action" class="submit" type="submit" value="continue">|.$locale->text('Continue').qq|</button>
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
-sub send_email {
-
- $old_form = new Form;
-
- for (keys %$form) { $old_form->{$_} = $form->{$_} }
- $old_form->{media} = $old_form->{oldmedia};
-
- &print_form($old_form);
-
-}
-
-
-
-sub print_options {
-
- $form->{sendmode} = "attachment";
- $form->{copies} = 1 unless $form->{copies};
-
- $form->{SM}{$form->{sendmode}} = "selected";
-
- if ($form->{selectlanguage}) {
- $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
- $form->{"selectlanguage"} =~ s/ selected//;
- $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
-
- $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
- <input type=hidden name=oldlanguage_code value=$form->{oldlanguage_code}>
- <input type=hidden name=selectlanguage value="|.$form->escape($form->{selectlanguage},1).qq|">|;
- }
-
- $form->{selectformname} = $form->unescape($form->{selectformname});
- $form->{selectformname} =~ s/ selected//;
- $form->{selectformname} =~ s/(<option value="\Q$form->{formname}\E")/$1 selected/;
-
- $type = qq|<select name=formname>$form->{selectformname}</select>
- <input type=hidden name=selectformname value="|.$form->escape($form->{selectformname},1).qq|">|;
-
-
- if ($form->{media} eq 'email') {
- $media = qq|<select name=sendmode>
- <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq|
- <option value=inline $form->{SM}{inline}>|.$locale->text('In-line').qq|</select>|;
- } else {
- $media = qq|<select name=media>
- <option value="screen">|.$locale->text('Screen');
-
- if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
- for (sort keys %{LedgerSMB::Sysconfig::printer}) { $media .= qq|
- <option value="$_">$_| }
- }
- if (${LedgerSMB::Sysconfig::latex}) {
- $media .= qq|
- <option value="queue">|.$locale->text('Queue');
- }
- $media .= qq|</select>|;
-
- # set option selected
- $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
-
- }
-
-
- $form->{selectformat} = qq|<option value="html">html\n|;
-# <option value="txt">|.$locale->text('Text');
-
- if (${LedgerSMB::Sysconfig::latex}) {
- $form->{selectformat} .= qq|
- <option value="postscript">|.$locale->text('Postscript').qq|
- <option value="pdf">|.$locale->text('PDF');
- }
-
- $format = qq|<select name=format>$form->{selectformat}</select>|;
- $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
- $format .= qq|
- <input type=hidden name=selectformat value="|.$form->escape($form->{selectformat},1).qq|">|;
-
- print qq|
-<table width=100%>
- <tr>
- <td>$type</td>
- <td>$lang</td>
- <td>$format</td>
- <td>$media</td>
-|;
-
- if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} && $form->{media} ne 'email') {
- print qq|
- <td nowrap>|.$locale->text('Copies').qq|
- <input name=copies size=2 value=$form->{copies}></td>
-|;
- }
-
-# $locale->text('Printed')
-# $locale->text('E-mailed')
-# $locale->text('Queued')
-# $locale->text('Scheduled')
-
- %status = ( printed => 'Printed',
- emailed => 'E-mailed',
- queued => 'Queued',
- recurring => 'Scheduled' );
-
- print qq|<td align=right width=90%>|;
-
- for (qw(printed emailed queued recurring)) {
- if ($form->{$_} =~ /$form->{formname}/) {
- print $locale->text($status{$_}).qq|<br>|;
- }
- }
-
- print qq|
- </td>
- </tr>
-|;
-
- $form->{groupprojectnumber} = "checked" if $form->{groupprojectnumber};
- $form->{grouppartsgroup} = "checked" if $form->{grouppartsgroup};
-
- for (qw(runningnumber partnumber description bin)) { $sortby{$_} = "checked" if $form->{sortby} eq $_ }
-
- print qq|
- <tr>
- <td colspan=3>|.$locale->text('Group by').qq| ->
- <input name=groupprojectnumber type=checkbox class=checkbox $form->{groupprojectnumber}>
- |.$locale->text('Project').qq|
- <input name=grouppartsgroup type=checkbox class=checkbox $form->{grouppartsgroup}>
- |.$locale->text('Group').qq|
- </td>
-
- <td colspan=3>|.$locale->text('Sort by').qq| ->
- <input name=sortby type=radio class=radio value=runningnumber $sortby{runningnumber}>
- |.$locale->text('Item').qq|
- <input name=sortby type=radio class=radio value=partnumber $sortby{partnumber}>
- |.$locale->text('Number').qq|
- <input name=sortby type=radio class=radio value=description $sortby{description}>
- |.$locale->text('Description').qq|
- <input name=sortby type=radio class=radio value=bin $sortby{bin}>
- |.$locale->text('Bin').qq|
- </td>
-
- </tr>
-</table>
-|;
-
-}
-
-
-
-sub print {
-
- # if this goes to the printer pass through
- if ($form->{media} !~ /(screen|email)/) {
- $form->error($locale->text('Select txt, postscript or PDF!')) if ($form->{format} !~ /(txt|postscript|pdf)/);
-
- $old_form = new Form;
- for (keys %$form) { $old_form->{$_} = $form->{$_} }
-
- }
-
- &print_form($old_form);
-
-}
-
-
-sub print_form {
- my ($old_form) = @_;
-
- $inv = "inv";
- $due = "due";
-
- $numberfld = "sinumber";
-
- $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
-
- if ($form->{formname} eq "invoice") {
- $form->{label} = $locale->text('Invoice');
- }
- if ($form->{formname} eq 'sales_order') {
- $inv = "ord";
- $due = "req";
- $form->{label} = $locale->text('Sales Order');
- $numberfld = "sonumber";
- $order = 1;
- }
- if ($form->{formname} eq 'work_order') {
- $inv = "ord";
- $due = "req";
- $form->{label} = $locale->text('Work Order');
- $numberfld = "sonumber";
- $order = 1;
- }
- if ($form->{formname} eq 'packing_list') {
- # we use the same packing list as from an invoice
- $form->{label} = $locale->text('Packing List');
-
- if ($form->{type} ne 'invoice') {
- $inv = "ord";
- $due = "req";
- $numberfld = "sonumber";
- $order = 1;
-
- $filled = 0;
- for ($i = 1; $i < $form->{rowcount}; $i++) {
- if ($form->{"ship_$i"}) {
- $filled = 1;
- last;
- }
- }
- if (!$filled) {
- for (1 .. $form->{rowcount}) { $form->{"ship_$_"} = $form->{"qty_$_"} }
- }
- }
- }
- if ($form->{formname} eq 'pick_list') {
- $form->{label} = $locale->text('Pick List');
- if ($form->{type} ne 'invoice') {
- $inv = "ord";
- $due = "req";
- $order = 1;
- $numberfld = "sonumber";
- }
- }
- if ($form->{formname} eq 'purchase_order') {
- $inv = "ord";
- $due = "req";
- $form->{label} = $locale->text('Purchase Order');
- $numberfld = "ponumber";
- $order = 1;
- }
- if ($form->{formname} eq 'bin_list') {
- $inv = "ord";
- $due = "req";
- $form->{label} = $locale->text('Bin List');
- $numberfld = "ponumber";
- $order = 1;
- }
- if ($form->{formname} eq 'sales_quotation') {
- $inv = "quo";
- $due = "req";
- $form->{label} = $locale->text('Quotation');
- $numberfld = "sqnumber";
- $order = 1;
- }
- if ($form->{formname} eq 'request_quotation') {
- $inv = "quo";
- $due = "req";
- $form->{label} = $locale->text('Quotation');
- $numberfld = "rfqnumber";
- $order = 1;
- }
-
- &validate_items;
-
- $form->{"${inv}date"} = $form->{transdate};
-
- $form->isblank("email", $locale->text('E-mail address missing!')) if ($form->{media} eq 'email');
- $form->isblank("${inv}date", $locale->text($form->{label} .' Date missing!'));
-
- # get next number
- if (! $form->{"${inv}number"}) {
- $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
- if ($form->{media} eq 'screen') {
- &update;
- exit;
- }
- }
-
-
-# $locale->text('Invoice Number missing!')
-# $locale->text('Invoice Date missing!')
-# $locale->text('Packing List Number missing!')
-# $locale->text('Packing List Date missing!')
-# $locale->text('Order Number missing!')
-# $locale->text('Order Date missing!')
-# $locale->text('Quotation Number missing!')
-# $locale->text('Quotation Date missing!')
-
- &{ "$form->{vc}_details" };
-
- @a = ();
- foreach $i (1 .. $form->{rowcount}) {
- push @a, ("partnumber_$i", "description_$i", "projectnumber_$i", "partsgroup_$i", "serialnumber_$i", "bin_$i", "unit_$i", "notes_$i");
- }
- for (split / /, $form->{taxaccounts}) { push @a, "${_}_description" }
-
- $ARAP = ($form->{vc} eq 'customer') ? "AR" : "AP";
- push @a, $ARAP;
-
- # format payment dates
- for $i (1 .. $form->{paidaccounts} - 1) {
- if (exists $form->{longformat}) {
- $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
- }
-
- push @a, "${ARAP}_paid_$i", "source_$i", "memo_$i";
- }
-
- $form->format_string(@a);
-
- ($form->{employee}) = split /--/, $form->{employee};
- ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
-
- # this is a label for the subtotals
- $form->{groupsubtotaldescription} = $locale->text('Subtotal') if not exists $form->{groupsubtotaldescription};
- delete $form->{groupsubtotaldescription} if $form->{deletegroupsubtotal};
-
- $duedate = $form->{"${due}date"};
-
- # create the form variables
- if ($order) {
- OE->order_details(\%myconfig, \%$form);
- } else {
- IS->invoice_details(\%myconfig, \%$form);
- }
-
- if (exists $form->{longformat}) {
- $form->{"${due}date"} = $duedate;
- for ("${inv}date", "${due}date", "shippingdate", "transdate") { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) }
- }
-
- @a = qw(name address1 address2 city state zipcode country contact phone fax email);
-
- $shipto = 1;
- # if there is no shipto fill it in from billto
- foreach $item (@a) {
- if ($form->{"shipto$item"}) {
- $shipto = 0;
- last;
- }
- }
-
- if ($shipto) {
- if ($form->{formname} eq 'purchase_order' || $form->{formname} eq 'request_quotation') {
- $form->{shiptoname} = $myconfig{company};
- $form->{shiptoaddress1} = $myconfig{address};
- $form->{shiptoaddress1} =~ s/\\n/\n/g;
- } else {
- if ($form->{formname} !~ /bin_list/) {
- for (@a) { $form->{"shipto$_"} = $form->{$_} }
- }
- }
- }
-
- # some of the stuff could have umlauts so we translate them
- push @a, qw(contact shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptoemail shippingpoint shipvia notes intnotes employee warehouse);
-
- push @a, ("${inv}number", "${inv}date", "${due}date");
-
- for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
- $form->{address} =~ s/\\n/\n/g;
-
- for (qw(name email)) { $form->{"user$_"} = $myconfig{$_} }
-
- push @a, qw(company address tel fax businessnumber username useremail);
-
- for (qw(notes intnotes)) { $form->{$_} =~ s/^\s+//g }
-
- # before we format replace <%var%>
- for (qw(notes intnotes message)) { $form->{$_} =~ s/<%(.*?)%>/$form->{$1}/g }
-
- $form->format_string(@a);
-
-
- $form->{templates} = "$myconfig{templates}";
- $form->{IN} = "$form->{formname}.$form->{format}";
-
- if ($form->{format} =~ /(postscript|pdf)/) {
- $form->{IN} =~ s/$&$/tex/;
- }
-
-
- $form->{pre} = "<body bgcolor=#ffffff>\n<pre>" if $form->{format} eq 'txt';
-
- if ($form->{media} !~ /(screen|queue|email)/) {
- $form->{OUT} = "| ${LedgerSMB::SysConfig::printer}{$form->{media}}";
-
- $form->{OUT} =~ s/<%(fax)%>/<%$form->{vc}$1%>/;
- $form->{OUT} =~ s/<%(.*?)%>/$form->{$1}/g;
-
- if ($form->{printed} !~ /$form->{formname}/) {
-
- $form->{printed} .= " $form->{formname}";
- $form->{printed} =~ s/^ //;
-
- $form->update_status(\%myconfig);
- }
-
- $old_form->{printed} = $form->{printed} if defined %$old_form;
-
- %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
- reference => $form->{"${inv}number"},
- formname => $form->{formname},
- action => 'printed',
- id => $form->{id} );
-
- $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if defined %$old_form;
-
- }
-
-
- if ($form->{media} eq 'email') {
- $form->{subject} = qq|$form->{label} $form->{"${inv}number"}| unless $form->{subject};
-
- $form->{plainpaper} = 1;
- $form->{OUT} = "${LedgerSMB::Sysconfig::sendmail}";
-
- if ($form->{emailed} !~ /$form->{formname}/) {
- $form->{emailed} .= " $form->{formname}";
- $form->{emailed} =~ s/^ //;
-
- # save status
- $form->update_status(\%myconfig);
- }
-
- $now = scalar localtime;
- $cc = $locale->text('Cc: [_1]', $form->{cc}).qq|\n| if $form->{cc};
- $bcc = $locale->text('Bcc: [_1]', $form->{bcc}).qq|\n| if $form->{bcc};
-
- if (defined %$old_form) {
- $old_form->{intnotes} = qq|$old_form->{intnotes}\n\n| if $old_form->{intnotes};
- $old_form->{intnotes} .= qq|[email]\n|
- .$locale->text('Date: [_1]', $now).qq|\n|
- .$locale->text('To: [_1]', $form->{email}).qq|\n${cc}${bcc}|
- .$locale->text('Subject: [_1]', $form->{subject}).qq|\n|;
-
- $old_form->{intnotes} .= qq|\n|.$locale->text('Message').qq|: |;
- $old_form->{intnotes} .= ($form->{message}) ? $form->{message} : $locale->text('sent');
-
- $old_form->{message} = $form->{message};
- $old_form->{emailed} = $form->{emailed};
-
- $old_form->{format} = "postscript" if $myconfig{printer};
- $old_form->{media} = $myconfig{printer};
-
- $old_form->save_intnotes(\%myconfig, ($order) ? 'oe' : lc $ARAP);
- }
-
- %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
- reference => $form->{"${inv}number"},
- formname => $form->{formname},
- action => 'emailed',
- id => $form->{id} );
-
- $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if defined %$old_form;
- }
-
-
- if ($form->{media} eq 'queue') {
- %queued = split / /, $form->{queued};
-
- if ($filename = $queued{$form->{formname}}) {
- $form->{queued} =~ s/$form->{formname} $filename//;
- unlink "${LedgerSMB::Sysconfig::spool}/$filename";
- $filename =~ s/\..*$//g;
- } else {
- $filename = time;
- $filename .= $$;
- }
-
- $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
- $form->{OUT} = ">${LedgerSMB::Sysconfig::spool}/$filename";
-
- $form->{queued} .= " $form->{formname} $filename";
- $form->{queued} =~ s/^ //;
-
- # save status
- $form->update_status(\%myconfig);
-
- $old_form->{queued} = $form->{queued};
-
- %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
- reference => $form->{"${inv}number"},
- formname => $form->{formname},
- action => 'queued',
- id => $form->{id} );
-
- $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
-
- }
-
-
- $form->format_string("email", "cc", "bcc");
-
- $form->{fileid} = $form->{"${inv}number"};
- $form->{fileid} =~ s/(\s|\W)+//g;
-
- $form->parse_template(\%myconfig, ${LedgerSMB::Sysconfig::userspath});
-
- # if we got back here restore the previous form
- if (defined %$old_form) {
-
- $old_form->{"${inv}number"} = $form->{"${inv}number"};
-
- # restore and display form
- for (keys %$old_form) { $form->{$_} = $old_form->{$_} }
- delete $form->{pre};
-
- $form->{rowcount}--;
-
- for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-
- for $i (1 .. $form->{paidaccounts}) {
- for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
- }
-
- &{ "$display_form" };
-
- }
-
-}
-
-
-sub customer_details {
-
- IS->customer_details(\%myconfig, \%$form);
-
-}
-
-
-sub vendor_details {
-
- IR->vendor_details(\%myconfig, \%$form);
-
-}
-
-
-sub ship_to {
-
- $title = $form->{title};
- $form->{title} = $locale->text('Ship to');
-
- for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
- for (1 .. $form->{paidaccounts}) { $form->{"paid_$_"} = $form->parse_amount(\%myconfig, $form->{"paid_$_"}) }
-
- # get details for name
- &{ "$form->{vc}_details" };
-
- $number = ($form->{vc} eq 'customer') ? $locale->text('Customer Number') : $locale->text('Vendor Number');
-
- $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
-
- $form->{rowcount}--;
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-
-<table width=100%>
- <tr>
- <td>
- <table>
- <tr class=listheading>
- <th class=listheading colspan=2 width=50%>|.$locale->text('Billing Address').qq|</th>
- <th class=listheading width=50%>|.$locale->text('Shipping Address').qq|</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <th align=right nowrap>$number</th>
- <td>$form->{"$form->{vc}number"}</td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Company Name').qq|</th>
- <td>$form->{name}</td>
- <td><input name=shiptoname size=35 maxlength=64 value="$form->{shiptoname}"></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Address').qq|</th>
- <td>$form->{address1}</td>
- <td><input name=shiptoaddress1 size=35 maxlength=32 value="$form->{shiptoaddress1}"></td>
- </tr>
- <tr>
- <th></th>
- <td>$form->{address2}</td>
- <td><input name=shiptoaddress2 size=35 maxlength=32 value="$form->{shiptoaddress2}"></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('City').qq|</th>
- <td>$form->{city}</td>
- <td><input name=shiptocity size=35 maxlength=32 value="$form->{shiptocity}"></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
- <td>$form->{state}</td>
- <td><input name=shiptostate size=35 maxlength=32 value="$form->{shiptostate}"></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
- <td>$form->{zipcode}</td>
- <td><input name=shiptozipcode size=10 maxlength=10 value="$form->{shiptozipcode}"></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Country').qq|</th>
- <td>$form->{country}</td>
- <td><input name=shiptocountry size=35 maxlength=32 value="$form->{shiptocountry}"></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Contact').qq|</th>
- <td>$form->{contact}</td>
- <td><input name=shiptocontact size=35 maxlength=64 value="$form->{shiptocontact}"></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Phone').qq|</th>
- <td>$form->{"$form->{vc}phone"}</td>
- <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Fax').qq|</th>
- <td>$form->{"$form->{vc}fax"}</td>
- <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
- <td>$form->{email}</td>
- <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
- </tr>
- </table>
- </td>
- </tr>
-</table>
-
-<input type=hidden name=nextsub value=$nextsub>
-|;
-
- # delete shipto
- for (qw(action nextsub)) { delete $form->{$_} }
- for (qw(name address1 address2 city state zipcode country contact phone fax email)) { delete $form->{"shipto$_"} }
- $form->{title} = $title;
-
- $form->hide_form;
-
- print qq|
-
-<hr size=3 noshade>
-
-<br>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
+######################################################################
+# LedgerSMB Small Medium Business Accounting
+# http://www.ledgersmb.org/
+#
+
+# Copyright (C) 2006
+# This work contains copyrighted information from a number of sources all used
+# with permission.
+#
+# This file contains source code included with or based on SQL-Ledger which
+# is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
+# under the GNU General Public License version 2 or, at your option, any later
+# version. For a full list including contact information of contributors,
+# maintainers, and copyright holders, see the CONTRIBUTORS file.
+#
+# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
+# Copyright (c) 2002
+#
+# Author: DWS Systems Inc.
+# Web: http://www.sql-ledger.org
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#######################################################################
+#
+# common routines used in is, ir, oe
+#
+#######################################################################
+
+use LedgerSMB::Tax;
+use LedgerSMB::Sysconfig;
+
+# any custom scripts for this one
+if (-f "bin/custom/io.pl") {
+ eval { require "bin/custom/io.pl"; };
+}
+if (-f "bin/custom/$form->{login}_io.pl") {
+ eval { require "bin/custom/$form->{login}_io.pl"; };
+}
+
+
+1;
+# end of main
+
+
+# this is for our long dates
+# $locale->text('January')
+# $locale->text('February')
+# $locale->text('March')
+# $locale->text('April')
+# $locale->text('May ')
+# $locale->text('June')
+# $locale->text('July')
+# $locale->text('August')
+# $locale->text('September')
+# $locale->text('October')
+# $locale->text('November')
+# $locale->text('December')
+
+# this is for our short month
+# $locale->text('Jan')
+# $locale->text('Feb')
+# $locale->text('Mar')
+# $locale->text('Apr')
+# $locale->text('May')
+# $locale->text('Jun')
+# $locale->text('Jul')
+# $locale->text('Aug')
+# $locale->text('Sep')
+# $locale->text('Oct')
+# $locale->text('Nov')
+# $locale->text('Dec')
+
+
+sub display_row {
+ my $numrows = shift;
+
+ @column_index = qw(runningnumber partnumber description qty);
+
+ if ($form->{type} eq "sales_order") {
+ push @column_index, "ship";
+ $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Ship').qq|</th>|;
+ }
+ if ($form->{type} eq "purchase_order") {
+ push @column_index, "ship";
+ $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Recd').qq|</th>|;
+ }
+
+ for (qw(projectnumber partsgroup)) {
+ $form->{"select$_"} = $form->unescape($form->{"select$_"}) if $form->{"select$_"};
+ }
+
+ if ($form->{language_code} ne $form->{oldlanguage_code}) {
+ # rebuild partsgroup
+ $l{language_code} = $form->{language_code};
+ $l{searchitems} = 'nolabor' if $form->{vc} eq 'customer';
+
+ $form->get_partsgroup(\%myconfig, \%l);
+ if (@ { $form->{all_partsgroup} }) {
+ $form->{selectpartsgroup} = "<option>\n";
+ foreach $ref (@ { $form->{all_partsgroup} }) {
+ if ($ref->{translation}) {
+ $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{translation}\n|;
+ } else {
+ $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|;
+ }
+ }
+ }
+ $form->{oldlanguage_code} = $form->{language_code};
+ }
+
+
+ push @column_index, @{LedgerSMB::Sysconfig::io_lineitem_columns};
+
+ my $colspan = $#column_index + 1;
+
+ $form->{invsubtotal} = 0;
+ for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
+
+ $column_data{runningnumber} = qq|<th class=listheading nowrap>|.$locale->text('Item').qq|</th>|;
+ $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
+ $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|;
+ $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
+ $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
+ $column_data{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Price').qq|</th>|;
+ $column_data{discount} = qq|<th class=listheading>%</th>|;
+ $column_data{linetotal} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;
+ $column_data{bin} = qq|<th class=listheading nowrap>|.$locale->text('Bin').qq|</th>|;
+ $column_data{onhand} = qq|<th class=listheading nowrap>|.$locale->text('OH').qq|</th>|;
+
+ print qq|
+ <tr>
+ <td>
+ <table width=100%>
+ <tr class=listheading>|;
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+ </tr>
+|;
+
+
+ $deliverydate = $locale->text('Delivery Date');
+ $serialnumber = $locale->text('Serial No.');
+ $projectnumber = $locale->text('Project');
+ $group = $locale->text('Group');
+ $sku = $locale->text('SKU');
+
+ $delvar = 'deliverydate';
+
+ if ($form->{type} =~ /_(order|quotation)$/) {
+ $reqdate = $locale->text('Required by');
+ $delvar = 'reqdate';
+ }
+
+ $exchangerate = $form->parse_amount(\%myconfig, $form->{exchangerate});
+ $exchangerate = ($exchangerate) ? $exchangerate : 1;
+
+ $spc = substr($myconfig{numberformat},-3,1);
+ for $i (1 .. $numrows) {
+ if ($spc eq '.') {
+ ($null, $dec) = split /\./, $form->{"sellprice_$i"};
+ } else {
+ ($null, $dec) = split /,/, $form->{"sellprice_$i"};
+ }
+ $dec = length $dec;
+ $decimalplaces = ($dec > 2) ? $dec : 2;
+
+ # undo formatting
+ for (qw(qty oldqty ship discount sellprice)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
+
+ if ($form->{"qty_$i"} != $form->{"oldqty_$i"}) {
+ # check pricematrix
+ @a = split / /, $form->{"pricematrix_$i"};
+ if (scalar @a > 2) {
+ foreach $item (@a) {
+ ($q, $p) = split /:/, $item;
+ if (($p * 1) && ($form->{"qty_$i"} >= ($q * 1))) {
+ ($dec) = ($p =~ /\.(\d+)/);
+ $dec = length $dec;
+ $decimalplaces = ($dec > 2) ? $dec : 2;
+ $form->{"sellprice_$i"} = $form->round_amount($p / $exchangerate, $decimalplaces);
+ }
+ }
+ }
+ }
+
+ $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces);
+ $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
+ $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
+
+
+ if (($rows = $form->numtextrows($form->{"description_$i"}, 46, 6)) > 1) {
+ $form->{"description_$i"} = $form->quote($form->{"description_$i"});
+ $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=46 wrap=soft>$form->{"description_$i"}</textarea></td>|;
+ } else {
+ $form->{"description_$i"} = $form->quote($form->{"description_$i"});
+ $column_data{description} = qq|<td><input name="description_$i" size=48 value="$form->{"description_$i"}"></td>|;
+ }
+
+ for (qw(partnumber sku unit)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
+
+ $skunumber = qq|
+ <p><b>$sku</b> $form->{"sku_$i"}| if ($form->{vc} eq 'vendor' && $form->{"sku_$i"});
+
+
+ if ($form->{selectpartsgroup}) {
+ if ($i < $numrows) {
+ $partsgroup = qq|
+ <b>$group</b>
+ <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">|;
+ ($form->{"partsgroup_$i"}) = split /--/, $form->{"partsgroup_$i"};
+ $partsgroup .= $form->{"partsgroup_$i"};
+ $partsgroup = "" unless $form->{"partsgroup_$i"};
+ }
+ }
+
+ $delivery = qq|
+ <td colspan=2 nowrap>
+ <b>${$delvar}</b>
+ <input name="${delvar}_$i" size=11 title="$myconfig{dateformat}" value="$form->{"${delvar}_$i"}"></td>
+|;
+
+ $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=3 value=$i></td>|;
+ $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}" accesskey="$i" title="[Alt-$i]">$skunumber</td>|;
+ $column_data{qty} = qq|<td align=right><input name="qty_$i" title="$form->{"onhand_$i"}" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|;
+ $column_data{ship} = qq|<td align=right><input name="ship_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"ship_$i"}).qq|></td>|;
+ $column_data{unit} = qq|<td><input name="unit_$i" size=5 value="$form->{"unit_$i"}"></td>|;
+ $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;
+ $column_data{discount} = qq|<td align=right><input name="discount_$i" size=3 value=|.$form->format_amount(\%myconfig, $form->{"discount_$i"}).qq|></td>|;
+ $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|;
+ $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
+ $column_data{onhand} = qq|<td>$form->{"onhand_$i"}</td>|;
+
+ print qq|
+ <tr valign=top>|;
+
+ for (@column_index) {
+ print "\n$column_data{$_}";
+ }
+
+ print qq|
+ </tr>
+<input type=hidden name="oldqty_$i" value="$form->{"qty_$i"}">
+|;
+
+ for (qw(orderitems_id id bin weight listprice lastcost taxaccounts pricematrix sku onhand assembly inventory_accno_id income_accno_id expense_accno_id)) {
+ $form->hide_form("${_}_$i");
+ }
+
+ $form->{selectprojectnumber} =~ s/ selected//;
+ $form->{selectprojectnumber} =~ s/(<option value="\Q$form->{"projectnumber_$i"}\E")/$1 selected/;
+
+ $project = qq|
+ <b>$projectnumber</b>
+ <select name="projectnumber_$i">$form->{selectprojectnumber}</select>
+| if $form->{selectprojectnumber};
+
+
+ if (($rows = $form->numtextrows($form->{"notes_$i"}, 46, 6)) > 1) {
+ $form->{"notes_$i"} = $form->quote($form->{"notes_$i"});
+ $notes = qq|<td><textarea name="notes_$i" rows=$rows cols=46 wrap=soft>$form->{"notes_$i"}</textarea></td>|;
+ } else {
+ $form->{"notes_$i"} = $form->quote($form->{"notes_$i"});
+ $notes = qq|<td><input name="notes_$i" size=48 value="$form->{"notes_$i"}"></td>|;
+ }
+
+ $serial = qq|
+ <td colspan=6 nowrap><b>$serialnumber</b> <input name="serialnumber_$i" value="$form->{"serialnumber_$i"}"></td>| if $form->{type} !~ /_quotation/;
+
+ if ($i == $numrows) {
+ $partsgroup = "";
+ if ($form->{selectpartsgroup}) {
+ $partsgroup = qq|
+ <b>$group</b>
+ <select name="partsgroup_$i">$form->{selectpartsgroup}</select>
+|;
+ }
+
+ $serial = "";
+ $project = "";
+ $delivery = "";
+ $notes = "";
+ }
+
+
+ # print second and third row
+ print qq|
+ <tr valign=top>
+ $delivery
+ $notes
+ $serial
+ </tr>
+ <tr valign=top>
+ <td colspan=$colspan>
+ $project
+ $partsgroup
+ </td>
+ </tr>
+ <tr>
+ <td colspan=$colspan><hr size=1 noshade></td>
+ </tr>
+|;
+
+ $skunumber = "";
+
+ for (split / /, $form->{"taxaccounts_$i"}) {
+ $form->{"${_}_base"} += $linetotal;
+ }
+
+ $form->{invsubtotal} += $linetotal;
+ }
+
+ print qq|
+ </table>
+ </td>
+ </tr>
+|;
+
+ $form->hide_form(qw(audittrail));
+
+ print qq|
+
+<input type=hidden name=oldcurrency value=$form->{currency}>
+
+<input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|">
+<input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">
+
+|;
+
+}
+
+
+sub select_item {
+
+ if ($form->{vc} eq "vendor") {
+ @column_index = qw(ndx partnumber sku description partsgroup onhand sellprice);
+ } else {
+ @column_index = qw(ndx partnumber description partsgroup onhand sellprice);
+ }
+
+ $column_data{ndx} = qq|<th>&nbsp;</th>|;
+ $column_data{partnumber} = qq|<th class=listheading>|.$locale->text('Number').qq|</th>|;
+ $column_data{sku} = qq|<th class=listheading>|.$locale->text('SKU').qq|</th>|;
+ $column_data{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
+ $column_data{partsgroup} = qq|<th class=listheading>|.$locale->text('Group').qq|</th>|;
+ $column_data{sellprice} = qq|<th class=listheading>|.$locale->text('Price').qq|</th>|;
+ $column_data{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
+
+ $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
+
+ # list items with radio button on a form
+ $form->header;
+
+ $title = $locale->text('Select items');
+
+ print qq|
+<body>
+
+<form method=post action="$form->{script}">
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$title</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>$option</td>
+ </tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr class=listheading>|;
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+ </tr>
+|;
+
+ my $i = 0;
+ foreach $ref (@{ $form->{item_list} }) {
+ $i++;
+
+ for (qw(sku partnumber description unit notes partsgroup)) {
+ $ref->{$_} = $form->quote($ref->{$_});
+ }
+
+ $column_data{ndx} = qq|<td><input name="ndx_$i" class=checkbox type=checkbox value=$i></td>|;
+
+ for (qw(partnumber sku description partsgroup)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
+
+ $column_data{sellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{sellprice} / $exchangerate, 2, "&nbsp;").qq|</td>|;
+ $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;").qq|</td>|;
+
+ $j++; $j %= 2;
+ print qq|
+ <tr class=listrow$j>|;
+
+ for (@column_index) {
+ print "\n$column_data{$_}";
+ }
+
+ print qq|
+ </tr>
+|;
+
+ for (qw(partnumber sku description partsgroup partsgroup_id bin weight sellprice listprice lastcost onhand unit assembly taxaccounts inventory_accno_id income_accno_id expense_accno_id pricematrix id notes)) {
+ print qq|<input type=hidden name="new_${_}_$i" value="$ref->{$_}">\n|;
+ }
+ }
+
+ print qq|
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+<input name=lastndx type=hidden value=$i>
+
+|;
+
+ # delete variables
+ for (qw(nextsub item_list)) { delete $form->{$_} }
+
+ $form->{action} = "item_selected";
+
+ $form->hide_form;
+
+ print qq|
+<input type="hidden" name="nextsub" value="item_selected">
+
+<br>
+<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
+
+sub item_selected {
+
+ $i = $form->{rowcount} - 1;
+ $i = $form->{assembly_rows} - 1 if ($form->{item} eq 'assembly');
+ $qty = ($form->{"qty_$form->{rowcount}"}) ? $form->{"qty_$form->{rowcount}"} : 1;
+
+ for $j (1 .. $form->{lastndx}) {
+
+ if ($form->{"ndx_$j"}) {
+
+ $i++;
+
+ $form->{"qty_$i"} = $qty;
+ $form->{"discount_$i"} = $form->{discount} * 100;
+ $form->{"reqdate_$i"} = $form->{reqdate} if $form->{type} !~ /_quotation/;
+
+ for (qw(id partnumber sku description sellprice listprice lastcost bin unit weight assembly taxaccounts pricematrix onhand notes inventory_accno_id income_accno_id expense_accno_id)) {
+ $form->{"${_}_$i"} = $form->{"new_${_}_$j"};
+ }
+
+ $form->{"partsgroup_$i"} = qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|;
+
+ ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
+ $dec = length $dec;
+ $decimalplaces1 = ($dec > 2) ? $dec : 2;
+
+ ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/);
+ $dec = length $dec;
+ $decimalplaces2 = ($dec > 2) ? $dec : 2;
+
+ # if there is an exchange rate adjust sellprice
+ if (($form->{exchangerate} * 1)) {
+ for (qw(sellprice listprice lastcost)) { $form->{"${_}_$i"} /= $form->{exchangerate} }
+ # don't format list and cost
+ $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"}, $decimalplaces1);
+ }
+
+ # this is for the assembly
+ if ($form->{item} eq 'assembly') {
+ $form->{"adj_$i"} = 1;
+
+ for (qw(sellprice listprice weight)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+
+ $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
+ $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
+ }
+
+ $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
+ for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
+ if (!$form->{taxincluded}) {
+ my @taxlist= Tax::init_taxes($form, $form->{"taxaccounts_$i"});
+ $amount += Tax::calculate_taxes(\@taxlist, $form, $amount, 0);
+ }
+
+ $form->{creditremaining} -= $amount;
+
+ $form->{"runningnumber_$i"} = $i;
+
+ # format amounts
+ if ($form->{item} ne 'assembly') {
+ for (qw(sellprice listprice)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces1) }
+ $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces2);
+ }
+ $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"});
+
+ }
+ }
+
+ $form->{rowcount} = $i;
+ $form->{assembly_rows} = $i if ($form->{item} eq 'assembly');
+
+ $form->{focus} = "description_$i";
+
+ # delete all the new_ variables
+ for $i (1 .. $form->{lastndx}) {
+ for (qw(id partnumber sku description sellprice listprice lastcost bin unit weight assembly taxaccounts pricematrix onhand notes inventory_accno_id income_accno_id expense_accno_id)) {
+ delete $form->{"new_${_}_$i"};
+ }
+ }
+
+ for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
+
+ &display_form;
+
+}
+
+
+sub new_item {
+
+ if ($form->{language_code} && $form->{"description_$form->{rowcount}"}) {
+ $form->error($locale->text('Translation not on file!'));
+ }
+
+ # change callback
+ $form->{old_callback} = $form->escape($form->{callback},1);
+ $form->{callback} = $form->escape("$form->{script}?action=display_form",1);
+
+ # delete action
+ delete $form->{action};
+
+ # save all other form variables in a previousform variable
+ if (!$form->{previousform}) {
+ foreach $key (keys %$form) {
+ # escape ampersands
+ $form->{$key} =~ s/&/%26/g;
+ $form->{previousform} .= qq|$key=$form->{$key}&|;
+ }
+ chop $form->{previousform};
+ $form->{previousform} = $form->escape($form->{previousform}, 1);
+ }
+
+ $i = $form->{rowcount};
+ for (qw(partnumber description)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
+
+ $form->header;
+
+ print qq|
+<body>
+
+<h4 class=error>|.$locale->text('Item not on file!').qq|</h4>|;
+
+ if ($myconfig{acs} !~ /(Goods \& Services--Add Part|Goods \& Services--Add Service)/) {
+
+ print qq|
+<h4>|.$locale->text('What type of item is this?').qq|</h4>
+
+<form method=post action=ic.pl>
+
+<p>
+
+ <input class=radio type=radio name=item value=part checked>&nbsp;|.$locale->text('Part')
+.qq|<br>
+ <input class=radio type=radio name=item value=service>&nbsp;|.$locale->text('Service')
+
+.qq|
+<input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
+<input type=hidden name=description value="$form->{"description_$i"}">
+<input type=hidden name=nextsub value=add>
+<input type=hidden name=action value=add>
+|;
+
+ $form->hide_form(qw(previousform rowcount path login sessionid));
+
+ print qq|
+<p>
+<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+</form>
+|;
+ }
+
+ print qq|
+</body>
+</html>
+|;
+
+}
+
+
+
+sub display_form {
+
+ # if we have a display_form
+ if ($form->{display_form}) {
+ &{ "$form->{display_form}" };
+ exit;
+ }
+
+ &form_header;
+
+ $numrows = ++$form->{rowcount};
+ $subroutine = "display_row";
+
+ if ($form->{item} eq 'part') {
+ # create makemodel rows
+ &makemodel_row(++$form->{makemodel_rows});
+
+ &vendor_row(++$form->{vendor_rows});
+
+ $numrows = ++$form->{customer_rows};
+ $subroutine = "customer_row";
+ }
+ if ($form->{item} eq 'assembly') {
+ # create makemodel rows
+ &makemodel_row(++$form->{makemodel_rows});
+
+ $numrows = ++$form->{customer_rows};
+ $subroutine = "customer_row";
+ }
+ if ($form->{item} eq 'service') {
+ &vendor_row(++$form->{vendor_rows});
+
+ $numrows = ++$form->{customer_rows};
+ $subroutine = "customer_row";
+ }
+ if ($form->{item} eq 'labor') {
+ $numrows = 0;
+ }
+
+ # create rows
+ &{ $subroutine }($numrows) if $numrows;
+
+ &form_footer;
+
+}
+
+
+
+sub check_form {
+
+ my @a = ();
+ my $count = 0;
+ my $i;
+ my $j;
+ my @flds = qw(id runningnumber partnumber description partsgroup qty ship unit sellprice discount oldqty orderitems_id bin weight listprice lastcost taxaccounts pricematrix sku onhand assembly inventory_accno_id income_accno_id expense_accno_id notes reqdate deliverydate serialnumber projectnumber);
+
+ # remove any makes or model rows
+ if ($form->{item} eq 'part') {
+ for (qw(listprice sellprice lastcost avgcost weight rop markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+
+ &calc_markup;
+
+ @flds = qw(make model);
+ $count = 0;
+ @a = ();
+ for $i (1 .. $form->{makemodel_rows}) {
+ if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
+ push @a, {};
+ $j = $#a;
+
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
+ }
+
+ $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
+ $form->{makemodel_rows} = $count;
+
+ &check_vendor;
+ &check_customer;
+
+ }
+
+ if ($form->{item} eq 'service') {
+
+ for (qw(sellprice listprice lastcost avgcost markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+
+ &calc_markup;
+ &check_vendor;
+ &check_customer;
+
+ }
+
+ if ($form->{item} eq 'assembly') {
+
+ if (!$form->{project_id}) {
+ $form->{sellprice} = 0;
+ $form->{listprice} = 0;
+ $form->{lastcost} = 0;
+ $form->{weight} = 0;
+ }
+
+ for (qw(rop stock markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+
+ @flds = qw(id qty unit bom adj partnumber description sellprice listprice lastcost weight assembly runningnumber partsgroup);
+ $count = 0;
+ @a = ();
+
+ for $i (1 .. ($form->{assembly_rows} - 1)) {
+ if ($form->{"qty_$i"}) {
+ push @a, {};
+ my $j = $#a;
+
+ $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
+
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+
+ if (! $form->{project_id}) {
+ for (qw(sellprice listprice weight lastcost)) { $form->{$_} += ($form->{"${_}_$i"} * $form->{"qty_$i"}) }
+ }
+
+ $count++;
+ }
+ }
+
+ if ($form->{markup} && $form->{markup} != $form->{oldmarkup}) {
+ $form->{sellprice} = 0;
+ &calc_markup;
+ }
+
+ for (qw(sellprice lastcost listprice)) { $form->{$_} = $form->round_amount($form->{$_}, 2) }
+
+ $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
+ $form->{assembly_rows} = $count;
+
+ $count = 0;
+ @flds = qw(make model);
+ @a = ();
+
+ for $i (1 .. ($form->{makemodel_rows})) {
+ if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
+ push @a, {};
+ my $j = $#a;
+
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
+ }
+
+ $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
+ $form->{makemodel_rows} = $count;
+
+ &check_customer;
+
+ }
+
+ if ($form->{type}) {
+
+ # this section applies to invoices and orders
+ # remove any empty numbers
+
+ $count = 0;
+ @a = ();
+ if ($form->{rowcount}) {
+ for $i (1 .. $form->{rowcount} - 1) {
+ if ($form->{"partnumber_$i"}) {
+ push @a, {};
+ my $j = $#a;
+
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
+ }
+
+ $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
+ $form->{rowcount} = $count;
+
+ $form->{creditremaining} -= &invoicetotal;
+
+ }
+ }
+
+ &display_form;
+
+}
+
+
+sub calc_markup {
+
+ if ($form->{markup}) {
+ if ($form->{markup} != $form->{oldmarkup}) {
+ if ($form->{lastcost}) {
+ $form->{sellprice} = $form->{lastcost} * (1 + $form->{markup}/100);
+ $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
+ } else {
+ $form->{lastcost} = $form->{sellprice} / (1 + $form->{markup}/100);
+ $form->{lastcost} = $form->round_amount($form->{lastcost}, 2);
+ }
+ }
+ } else {
+ if ($form->{lastcost}) {
+ $form->{markup} = $form->round_amount(((1 - $form->{sellprice} / $form->{lastcost}) * 100), 1);
+ }
+ $form->{markup} = "" if $form->{markup} == 0;
+ }
+
+}
+
+
+sub invoicetotal {
+
+ $form->{oldinvtotal} = 0;
+ # add all parts and deduct paid
+ for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
+
+ my ($amount, $sellprice, $discount, $qty);
+
+ for $i (1 .. $form->{rowcount}) {
+ $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
+ $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
+ $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
+
+ $amount = $sellprice * (1 - $discount / 100) * $qty;
+ for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
+ $form->{oldinvtotal} += $amount;
+ }
+
+ if (!$form->{taxincluded}) {
+ my @taxlist= Tax::init_taxes($form, $form->{taxaccounts});
+ $form->{oldinvtotal} += Tax::calculate_taxes(\@taxlist, $form,
+ $amount, 0);
+ }
+
+ $form->{oldtotalpaid} = 0;
+ for $i (1 .. $form->{paidaccounts}) {
+ $form->{oldtotalpaid} += $form->{"paid_$i"};
+ }
+
+ # return total
+ ($form->{oldinvtotal} - $form->{oldtotalpaid});
+
+}
+
+
+sub validate_items {
+
+ # check if items are valid
+ if ($form->{rowcount} == 1) {
+ &update;
+ exit;
+ }
+
+ for $i (1 .. $form->{rowcount} - 1) {
+ $form->isblank("partnumber_$i", $locale->text('Number missing in Row [_1]', $i));
+ }
+
+}
+
+
+
+sub purchase_order {
+
+ $form->{title} = $locale->text('Add Purchase Order');
+ $form->{vc} = 'vendor';
+ $form->{type} = 'purchase_order';
+ $buysell = 'sell';
+
+ &create_form;
+
+}
+
+
+sub sales_order {
+
+ $form->{title} = $locale->text('Add Sales Order');
+ $form->{vc} = 'customer';
+ $form->{type} = 'sales_order';
+ $buysell = 'buy';
+
+ &create_form;
+
+}
+
+
+sub rfq {
+
+ $form->{title} = $locale->text('Add Request for Quotation');
+ $form->{vc} = 'vendor';
+ $form->{type} = 'request_quotation';
+ $buysell = 'sell';
+
+ &create_form;
+
+}
+
+
+sub quotation {
+
+ $form->{title} = $locale->text('Add Quotation');
+ $form->{vc} = 'customer';
+ $form->{type} = 'sales_quotation';
+ $buysell = 'buy';
+
+ &create_form;
+
+}
+
+
+sub create_form {
+
+ for (qw(id printed emailed queued)) { delete $form->{$_} }
+
+ $form->{script} = 'oe.pl';
+
+ $form->{shipto} = 1;
+
+ $form->{rowcount}-- if $form->{rowcount};
+ $form->{rowcount} = 0 if ! $form->{"$form->{vc}_id"};
+
+ do "bin/$form->{script}";
+
+ for ("$form->{vc}", "currency") { $form->{"select$_"} = "" }
+
+ for (qw(currency employee department intnotes notes language_code taxincluded)) { $temp{$_} = $form->{$_} }
+
+ &order_links;
+
+ for (keys %temp) { $form->{$_} = $temp{$_} if $temp{$_} }
+
+ $form->{exchangerate} = "";
+ $form->{forex} = "";
+ if ($form->{currency} ne $form->{defaultcurrency}) {
+ $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell)));
+ }
+
+ &prepare_order;
+
+ &display_form;
+
+}
+
+
+
+sub e_mail {
+
+ $bcc = qq|<input type=hidden name=bcc value="$form->{bcc}">|;
+ if ($myconfig{role} =~ /(admin|manager)/) {
+ $bcc = qq|
+ <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
+ <td><input name=bcc size=30 value="$form->{bcc}"></td>
+|;
+ }
+
+ if ($form->{formname} =~ /(pick|packing|bin)_list/) {
+ $form->{email} = $form->{shiptoemail} if $form->{shiptoemail};
+ }
+
+ $name = $form->{$form->{vc}};
+ $name =~ s/--.*//g;
+ $title = $locale->text('E-mail')." $name";
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action="$form->{script}">
+
+<table width=100%>
+ <tr class=listtop>
+ <th class=listtop>$title</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr>
+ <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
+ <td><input name=email size=30 value="$form->{email}"></td>
+ <th align=right nowrap>|.$locale->text('Cc').qq|</th>
+ <td><input name=cc size=30 value="$form->{cc}"></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Subject').qq|</th>
+ <td><input name=subject size=30 value="$form->{subject}"></td>
+ $bcc
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr>
+ <th align=left nowrap>|.$locale->text('Message').qq|</th>
+ </tr>
+ <tr>
+ <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+|;
+
+ $form->{oldmedia} = $form->{media};
+ $form->{media} = "email";
+ $form->{format} = "pdf";
+
+ &print_options;
+
+ for (qw(email cc bcc subject message formname sendmode format language_code action nextsub)) { delete $form->{$_} }
+
+ $form->hide_form;
+
+ print qq|
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+<input type="hidden" name="nextsub" value="send_email">
+
+<br>
+<button name="action" class="submit" type="submit" value="continue">|.$locale->text('Continue').qq|</button>
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
+sub send_email {
+
+ $old_form = new Form;
+
+ for (keys %$form) { $old_form->{$_} = $form->{$_} }
+ $old_form->{media} = $old_form->{oldmedia};
+
+ &print_form($old_form);
+
+}
+
+
+
+sub print_options {
+
+ $form->{sendmode} = "attachment";
+ $form->{copies} = 1 unless $form->{copies};
+
+ $form->{SM}{$form->{sendmode}} = "selected";
+
+ if ($form->{selectlanguage}) {
+ $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
+ $form->{"selectlanguage"} =~ s/ selected//;
+ $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
+
+ $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
+ <input type=hidden name=oldlanguage_code value=$form->{oldlanguage_code}>
+ <input type=hidden name=selectlanguage value="|.$form->escape($form->{selectlanguage},1).qq|">|;
+ }
+
+ $form->{selectformname} = $form->unescape($form->{selectformname});
+ $form->{selectformname} =~ s/ selected//;
+ $form->{selectformname} =~ s/(<option value="\Q$form->{formname}\E")/$1 selected/;
+
+ $type = qq|<select name=formname>$form->{selectformname}</select>
+ <input type=hidden name=selectformname value="|.$form->escape($form->{selectformname},1).qq|">|;
+
+
+ if ($form->{media} eq 'email') {
+ $media = qq|<select name=sendmode>
+ <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq|
+ <option value=inline $form->{SM}{inline}>|.$locale->text('In-line').qq|</select>|;
+ } else {
+ $media = qq|<select name=media>
+ <option value="screen">|.$locale->text('Screen');
+
+ if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
+ for (sort keys %{LedgerSMB::Sysconfig::printer}) { $media .= qq|
+ <option value="$_">$_| }
+ }
+ if (${LedgerSMB::Sysconfig::latex}) {
+ $media .= qq|
+ <option value="queue">|.$locale->text('Queue');
+ }
+ $media .= qq|</select>|;
+
+ # set option selected
+ $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
+
+ }
+
+
+ $form->{selectformat} = qq|<option value="html">html\n|;
+# <option value="txt">|.$locale->text('Text');
+
+ if (${LedgerSMB::Sysconfig::latex}) {
+ $form->{selectformat} .= qq|
+ <option value="postscript">|.$locale->text('Postscript').qq|
+ <option value="pdf">|.$locale->text('PDF');
+ }
+
+ $format = qq|<select name=format>$form->{selectformat}</select>|;
+ $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
+ $format .= qq|
+ <input type=hidden name=selectformat value="|.$form->escape($form->{selectformat},1).qq|">|;
+
+ print qq|
+<table width=100%>
+ <tr>
+ <td>$type</td>
+ <td>$lang</td>
+ <td>$format</td>
+ <td>$media</td>
+|;
+
+ if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} && $form->{media} ne 'email') {
+ print qq|
+ <td nowrap>|.$locale->text('Copies').qq|
+ <input name=copies size=2 value=$form->{copies}></td>
+|;
+ }
+
+# $locale->text('Printed')
+# $locale->text('E-mailed')
+# $locale->text('Queued')
+# $locale->text('Scheduled')
+
+ %status = ( printed => 'Printed',
+ emailed => 'E-mailed',
+ queued => 'Queued',
+ recurring => 'Scheduled' );
+
+ print qq|<td align=right width=90%>|;
+
+ for (qw(printed emailed queued recurring)) {
+ if ($form->{$_} =~ /$form->{formname}/) {
+ print $locale->text($status{$_}).qq|<br>|;
+ }
+ }
+
+ print qq|
+ </td>
+ </tr>
+|;
+
+ $form->{groupprojectnumber} = "checked" if $form->{groupprojectnumber};
+ $form->{grouppartsgroup} = "checked" if $form->{grouppartsgroup};
+
+ for (qw(runningnumber partnumber description bin)) { $sortby{$_} = "checked" if $form->{sortby} eq $_ }
+
+ print qq|
+ <tr>
+ <td colspan=3>|.$locale->text('Group by').qq| ->
+ <input name=groupprojectnumber type=checkbox class=checkbox $form->{groupprojectnumber}>
+ |.$locale->text('Project').qq|
+ <input name=grouppartsgroup type=checkbox class=checkbox $form->{grouppartsgroup}>
+ |.$locale->text('Group').qq|
+ </td>
+
+ <td colspan=3>|.$locale->text('Sort by').qq| ->
+ <input name=sortby type=radio class=radio value=runningnumber $sortby{runningnumber}>
+ |.$locale->text('Item').qq|
+ <input name=sortby type=radio class=radio value=partnumber $sortby{partnumber}>
+ |.$locale->text('Number').qq|
+ <input name=sortby type=radio class=radio value=description $sortby{description}>
+ |.$locale->text('Description').qq|
+ <input name=sortby type=radio class=radio value=bin $sortby{bin}>
+ |.$locale->text('Bin').qq|
+ </td>
+
+ </tr>
+</table>
+|;
+
+}
+
+
+
+sub print {
+
+ # if this goes to the printer pass through
+ if ($form->{media} !~ /(screen|email)/) {
+ $form->error($locale->text('Select txt, postscript or PDF!')) if ($form->{format} !~ /(txt|postscript|pdf)/);
+
+ $old_form = new Form;
+ for (keys %$form) { $old_form->{$_} = $form->{$_} }
+
+ }
+
+ &print_form($old_form);
+
+}
+
+
+sub print_form {
+ my ($old_form) = @_;
+
+ $inv = "inv";
+ $due = "due";
+
+ $numberfld = "sinumber";
+
+ $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
+
+ if ($form->{formname} eq "invoice") {
+ $form->{label} = $locale->text('Invoice');
+ }
+ if ($form->{formname} eq 'sales_order') {
+ $inv = "ord";
+ $due = "req";
+ $form->{label} = $locale->text('Sales Order');
+ $numberfld = "sonumber";
+ $order = 1;
+ }
+ if ($form->{formname} eq 'work_order') {
+ $inv = "ord";
+ $due = "req";
+ $form->{label} = $locale->text('Work Order');
+ $numberfld = "sonumber";
+ $order = 1;
+ }
+ if ($form->{formname} eq 'packing_list') {
+ # we use the same packing list as from an invoice
+ $form->{label} = $locale->text('Packing List');
+
+ if ($form->{type} ne 'invoice') {
+ $inv = "ord";
+ $due = "req";
+ $numberfld = "sonumber";
+ $order = 1;
+
+ $filled = 0;
+ for ($i = 1; $i < $form->{rowcount}; $i++) {
+ if ($form->{"ship_$i"}) {
+ $filled = 1;
+ last;
+ }
+ }
+ if (!$filled) {
+ for (1 .. $form->{rowcount}) { $form->{"ship_$_"} = $form->{"qty_$_"} }
+ }
+ }
+ }
+ if ($form->{formname} eq 'pick_list') {
+ $form->{label} = $locale->text('Pick List');
+ if ($form->{type} ne 'invoice') {
+ $inv = "ord";
+ $due = "req";
+ $order = 1;
+ $numberfld = "sonumber";
+ }
+ }
+ if ($form->{formname} eq 'purchase_order') {
+ $inv = "ord";
+ $due = "req";
+ $form->{label} = $locale->text('Purchase Order');
+ $numberfld = "ponumber";
+ $order = 1;
+ }
+ if ($form->{formname} eq 'bin_list') {
+ $inv = "ord";
+ $due = "req";
+ $form->{label} = $locale->text('Bin List');
+ $numberfld = "ponumber";
+ $order = 1;
+ }
+ if ($form->{formname} eq 'sales_quotation') {
+ $inv = "quo";
+ $due = "req";
+ $form->{label} = $locale->text('Quotation');
+ $numberfld = "sqnumber";
+ $order = 1;
+ }
+ if ($form->{formname} eq 'request_quotation') {
+ $inv = "quo";
+ $due = "req";
+ $form->{label} = $locale->text('Quotation');
+ $numberfld = "rfqnumber";
+ $order = 1;
+ }
+
+ &validate_items;
+
+ $form->{"${inv}date"} = $form->{transdate};
+
+ $form->isblank("email", $locale->text('E-mail address missing!')) if ($form->{media} eq 'email');
+ $form->isblank("${inv}date", $locale->text($form->{label} .' Date missing!'));
+
+ # get next number
+ if (! $form->{"${inv}number"}) {
+ $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
+ if ($form->{media} eq 'screen') {
+ &update;
+ exit;
+ }
+ }
+
+
+# $locale->text('Invoice Number missing!')
+# $locale->text('Invoice Date missing!')
+# $locale->text('Packing List Number missing!')
+# $locale->text('Packing List Date missing!')
+# $locale->text('Order Number missing!')
+# $locale->text('Order Date missing!')
+# $locale->text('Quotation Number missing!')
+# $locale->text('Quotation Date missing!')
+
+ &{ "$form->{vc}_details" };
+
+ @a = ();
+ foreach $i (1 .. $form->{rowcount}) {
+ push @a, ("partnumber_$i", "description_$i", "projectnumber_$i", "partsgroup_$i", "serialnumber_$i", "bin_$i", "unit_$i", "notes_$i");
+ }
+ for (split / /, $form->{taxaccounts}) { push @a, "${_}_description" }
+
+ $ARAP = ($form->{vc} eq 'customer') ? "AR" : "AP";
+ push @a, $ARAP;
+
+ # format payment dates
+ for $i (1 .. $form->{paidaccounts} - 1) {
+ if (exists $form->{longformat}) {
+ $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
+ }
+
+ push @a, "${ARAP}_paid_$i", "source_$i", "memo_$i";
+ }
+
+ $form->format_string(@a);
+
+ ($form->{employee}) = split /--/, $form->{employee};
+ ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
+
+ # this is a label for the subtotals
+ $form->{groupsubtotaldescription} = $locale->text('Subtotal') if not exists $form->{groupsubtotaldescription};
+ delete $form->{groupsubtotaldescription} if $form->{deletegroupsubtotal};
+
+ $duedate = $form->{"${due}date"};
+
+ # create the form variables
+ if ($order) {
+ OE->order_details(\%myconfig, \%$form);
+ } else {
+ IS->invoice_details(\%myconfig, \%$form);
+ }
+
+ if (exists $form->{longformat}) {
+ $form->{"${due}date"} = $duedate;
+ for ("${inv}date", "${due}date", "shippingdate", "transdate") { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) }
+ }
+
+ @a = qw(name address1 address2 city state zipcode country contact phone fax email);
+
+ $shipto = 1;
+ # if there is no shipto fill it in from billto
+ foreach $item (@a) {
+ if ($form->{"shipto$item"}) {
+ $shipto = 0;
+ last;
+ }
+ }
+
+ if ($shipto) {
+ if ($form->{formname} eq 'purchase_order' || $form->{formname} eq 'request_quotation') {
+ $form->{shiptoname} = $myconfig{company};
+ $form->{shiptoaddress1} = $myconfig{address};
+ $form->{shiptoaddress1} =~ s/\\n/\n/g;
+ } else {
+ if ($form->{formname} !~ /bin_list/) {
+ for (@a) { $form->{"shipto$_"} = $form->{$_} }
+ }
+ }
+ }
+
+ # some of the stuff could have umlauts so we translate them
+ push @a, qw(contact shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptoemail shippingpoint shipvia notes intnotes employee warehouse);
+
+ push @a, ("${inv}number", "${inv}date", "${due}date");
+
+ for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
+ $form->{address} =~ s/\\n/\n/g;
+
+ for (qw(name email)) { $form->{"user$_"} = $myconfig{$_} }
+
+ push @a, qw(company address tel fax businessnumber username useremail);
+
+ for (qw(notes intnotes)) { $form->{$_} =~ s/^\s+//g }
+
+ # before we format replace <%var%>
+ for (qw(notes intnotes message)) { $form->{$_} =~ s/<%(.*?)%>/$form->{$1}/g }
+
+ $form->format_string(@a);
+
+
+ $form->{templates} = "$myconfig{templates}";
+ $form->{IN} = "$form->{formname}.$form->{format}";
+
+ if ($form->{format} =~ /(postscript|pdf)/) {
+ $form->{IN} =~ s/$&$/tex/;
+ }
+
+
+ $form->{pre} = "<body bgcolor=#ffffff>\n<pre>" if $form->{format} eq 'txt';
+
+ if ($form->{media} !~ /(screen|queue|email)/) {
+ $form->{OUT} = "${LedgerSMB::SysConfig::printer}{$form->{media}}";
+ $form->{printmode} = '|-';
+
+ $form->{OUT} =~ s/<%(fax)%>/<%$form->{vc}$1%>/;
+ $form->{OUT} =~ s/<%(.*?)%>/$form->{$1}/g;
+
+ if ($form->{printed} !~ /$form->{formname}/) {
+
+ $form->{printed} .= " $form->{formname}";
+ $form->{printed} =~ s/^ //;
+
+ $form->update_status(\%myconfig);
+ }
+
+ $old_form->{printed} = $form->{printed} if defined %$old_form;
+
+ %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
+ reference => $form->{"${inv}number"},
+ formname => $form->{formname},
+ action => 'printed',
+ id => $form->{id} );
+
+ $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if defined %$old_form;
+
+ }
+
+
+ if ($form->{media} eq 'email') {
+ $form->{subject} = qq|$form->{label} $form->{"${inv}number"}| unless $form->{subject};
+
+ $form->{plainpaper} = 1;
+ $form->{OUT} = "${LedgerSMB::Sysconfig::sendmail}";
+ $form->{printmode} = '|-';
+
+ if ($form->{emailed} !~ /$form->{formname}/) {
+ $form->{emailed} .= " $form->{formname}";
+ $form->{emailed} =~ s/^ //;
+
+ # save status
+ $form->update_status(\%myconfig);
+ }
+
+ $now = scalar localtime;
+ $cc = $locale->text('Cc: [_1]', $form->{cc}).qq|\n| if $form->{cc};
+ $bcc = $locale->text('Bcc: [_1]', $form->{bcc}).qq|\n| if $form->{bcc};
+
+ if (defined %$old_form) {
+ $old_form->{intnotes} = qq|$old_form->{intnotes}\n\n| if $old_form->{intnotes};
+ $old_form->{intnotes} .= qq|[email]\n|
+ .$locale->text('Date: [_1]', $now).qq|\n|
+ .$locale->text('To: [_1]', $form->{email}).qq|\n${cc}${bcc}|
+ .$locale->text('Subject: [_1]', $form->{subject}).qq|\n|;
+
+ $old_form->{intnotes} .= qq|\n|.$locale->text('Message').qq|: |;
+ $old_form->{intnotes} .= ($form->{message}) ? $form->{message} : $locale->text('sent');
+
+ $old_form->{message} = $form->{message};
+ $old_form->{emailed} = $form->{emailed};
+
+ $old_form->{format} = "postscript" if $myconfig{printer};
+ $old_form->{media} = $myconfig{printer};
+
+ $old_form->save_intnotes(\%myconfig, ($order) ? 'oe' : lc $ARAP);
+ }
+
+ %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
+ reference => $form->{"${inv}number"},
+ formname => $form->{formname},
+ action => 'emailed',
+ id => $form->{id} );
+
+ $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail) if defined %$old_form;
+ }
+
+
+ if ($form->{media} eq 'queue') {
+ %queued = split / /, $form->{queued};
+
+ if ($filename = $queued{$form->{formname}}) {
+ $form->{queued} =~ s/$form->{formname} $filename//;
+ unlink "${LedgerSMB::Sysconfig::spool}/$filename";
+ $filename =~ s/\..*$//g;
+ } else {
+ $filename = time;
+ $filename .= $$;
+ }
+
+ $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
+ $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
+ $form->{printmode} = '>';
+
+ $form->{queued} .= " $form->{formname} $filename";
+ $form->{queued} =~ s/^ //;
+
+ # save status
+ $form->update_status(\%myconfig);
+
+ $old_form->{queued} = $form->{queued};
+
+ %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
+ reference => $form->{"${inv}number"},
+ formname => $form->{formname},
+ action => 'queued',
+ id => $form->{id} );
+
+ $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
+
+ }
+
+
+ $form->format_string("email", "cc", "bcc");
+
+ $form->{fileid} = $form->{"${inv}number"};
+ $form->{fileid} =~ s/(\s|\W)+//g;
+
+ $form->parse_template(\%myconfig, ${LedgerSMB::Sysconfig::userspath});
+
+ # if we got back here restore the previous form
+ if (defined %$old_form) {
+
+ $old_form->{"${inv}number"} = $form->{"${inv}number"};
+
+ # restore and display form
+ for (keys %$old_form) { $form->{$_} = $old_form->{$_} }
+ delete $form->{pre};
+
+ $form->{rowcount}--;
+
+ for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+
+ for $i (1 .. $form->{paidaccounts}) {
+ for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
+ }
+
+ &{ "$display_form" };
+
+ }
+
+}
+
+
+sub customer_details {
+
+ IS->customer_details(\%myconfig, \%$form);
+
+}
+
+
+sub vendor_details {
+
+ IR->vendor_details(\%myconfig, \%$form);
+
+}
+
+
+sub ship_to {
+
+ $title = $form->{title};
+ $form->{title} = $locale->text('Ship to');
+
+ for (qw(exchangerate creditlimit creditremaining)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+ for (1 .. $form->{paidaccounts}) { $form->{"paid_$_"} = $form->parse_amount(\%myconfig, $form->{"paid_$_"}) }
+
+ # get details for name
+ &{ "$form->{vc}_details" };
+
+ $number = ($form->{vc} eq 'customer') ? $locale->text('Customer Number') : $locale->text('Vendor Number');
+
+ $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
+
+ $form->{rowcount}--;
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+
+<table width=100%>
+ <tr>
+ <td>
+ <table>
+ <tr class=listheading>
+ <th class=listheading colspan=2 width=50%>|.$locale->text('Billing Address').qq|</th>
+ <th class=listheading width=50%>|.$locale->text('Shipping Address').qq|</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <th align=right nowrap>$number</th>
+ <td>$form->{"$form->{vc}number"}</td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Company Name').qq|</th>
+ <td>$form->{name}</td>
+ <td><input name=shiptoname size=35 maxlength=64 value="$form->{shiptoname}"></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Address').qq|</th>
+ <td>$form->{address1}</td>
+ <td><input name=shiptoaddress1 size=35 maxlength=32 value="$form->{shiptoaddress1}"></td>
+ </tr>
+ <tr>
+ <th></th>
+ <td>$form->{address2}</td>
+ <td><input name=shiptoaddress2 size=35 maxlength=32 value="$form->{shiptoaddress2}"></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('City').qq|</th>
+ <td>$form->{city}</td>
+ <td><input name=shiptocity size=35 maxlength=32 value="$form->{shiptocity}"></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
+ <td>$form->{state}</td>
+ <td><input name=shiptostate size=35 maxlength=32 value="$form->{shiptostate}"></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
+ <td>$form->{zipcode}</td>
+ <td><input name=shiptozipcode size=10 maxlength=10 value="$form->{shiptozipcode}"></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Country').qq|</th>
+ <td>$form->{country}</td>
+ <td><input name=shiptocountry size=35 maxlength=32 value="$form->{shiptocountry}"></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Contact').qq|</th>
+ <td>$form->{contact}</td>
+ <td><input name=shiptocontact size=35 maxlength=64 value="$form->{shiptocontact}"></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Phone').qq|</th>
+ <td>$form->{"$form->{vc}phone"}</td>
+ <td><input name=shiptophone size=20 value="$form->{shiptophone}"></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Fax').qq|</th>
+ <td>$form->{"$form->{vc}fax"}</td>
+ <td><input name=shiptofax size=20 value="$form->{shiptofax}"></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
+ <td>$form->{email}</td>
+ <td><input name=shiptoemail size=35 value="$form->{shiptoemail}"></td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</table>
+
+<input type=hidden name=nextsub value=$nextsub>
+|;
+
+ # delete shipto
+ for (qw(action nextsub)) { delete $form->{$_} }
+ for (qw(name address1 address2 city state zipcode country contact phone fax email)) { delete $form->{"shipto$_"} }
+ $form->{title} = $title;
+
+ $form->hide_form;
+
+ print qq|
+
+<hr size=3 noshade>
+
+<br>
+<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
diff --git a/bin/jc.pl b/bin/jc.pl
index 97ccf3db..48271981 100755
--- a/bin/jc.pl
+++ b/bin/jc.pl
@@ -1,1927 +1,1929 @@
-#=====================================================================
-# LedgerSMB Small Medium Business Accounting
-# http://www.ledgersmb.org/
-#
-
-# Copyright (C) 2006
-# This work contains copyrighted information from a number of sources all used
-# with permission.
-#
-# This file contains source code included with or based on SQL-Ledger which
-# is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
-# under the GNU General Public License version 2 or, at your option, any later
-# version. For a full list including contact information of contributors,
-# maintainers, and copyright holders, see the CONTRIBUTORS file.
-#
-# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
-# Copyright (c) 2005
-#
-# Author: DWS Systems Inc.
-# Web: http://www.sql-ledger.org
-#
-#
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#======================================================================
-#
-# Job Costing module
-#
-#======================================================================
-
-use LedgerSMB::JC;
-
-1;
-# end of main
-
-
-
-sub add {
-
- if ($form->{type} eq 'timecard') {
- $form->{title} = $locale->text('Add Time Card');
- }
- if ($form->{type} eq 'storescard') {
- $form->{title} = $locale->text('Add Stores Card');
- }
-
- $form->{callback} = "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&project=$form->{project}" unless $form->{callback};
-
- &{ "prepare_$form->{type}" };
-
- $form->{orphaned} = 1;
- &display_form;
-
-}
-
-
-sub edit {
-
- if ($form->{type} eq 'timecard') {
- $form->{title} = $locale->text('Edit Time Card');
- }
- if ($form->{type} eq 'storescard') {
- $form->{title} = $locale->text('Add Stores Card');
- }
-
- &{ "prepare_$form->{type}" };
-
- &display_form;
-
-}
-
-
-sub jcitems_links {
-
- if (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} = "<option>\n";
- foreach $ref (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} .= qq|<option value="$ref->{projectnumber}--$ref->{id}">$ref->{projectnumber}\n|;
- if ($form->{projectnumber} eq "$ref->{projectnumber}--$ref->{id}") {
- $form->{projectdescription} = $ref->{description};
- }
- }
- } else {
- if ($form->{project} eq 'job') {
- $form->error($locale->text('No open Jobs!'));
- } else {
- $form->error($locale->text('No open Projects!'));
- }
- }
-
- if (@{ $form->{all_parts} }) {
- $form->{selectpartnumber} = "<option>\n";
- foreach $ref (@{ $form->{all_parts} }) {
- $form->{selectpartnumber} .= qq|<option value="$ref->{partnumber}--$ref->{id}">$ref->{partnumber}\n|;
- if ($form->{partnumber} eq "$ref->{partnumber}--$ref->{id}") {
- if ($form->{partnumber} ne $form->{oldpartnumber}) {
- for (qw(description unit sellprice pricematrix)) { $form->{$_} = $ref->{$_} }
- }
- }
- }
- } else {
- if ($form->{type} eq 'timecard') {
- if ($form->{project} eq 'job') {
- $form->error($locale->text('No Labor codes on file!'));
- } else {
- $form->error($locale->text('No Services on file!'));
- }
- } else {
- $form->error($locale->text('No Parts on file!'));
- }
- }
-
- # employees
- if (@{ $form->{all_employee} }) {
- $form->{selectemployee} = "<option>\n";
- for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- } else {
- $form->error($locale->text('No Employees on file!'));
- }
-
-}
-
-
-sub search {
-
- # accounting years
- $form->all_years(\%myconfig);
-
- if (@{ $form->{all_years} }) {
- $form->{selectaccountingyear} = "<option>\n";
- for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
-
- $form->{selectaccountingmonth} = "<option>\n";
- for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
-
- $selectfrom = qq|
- <tr>
- <th align=right>|.$locale->text('Period').qq|</th>
- <td colspan=3>
- <select name=month>$form->{selectaccountingmonth}</select>
- <select name=year>$form->{selectaccountingyear}</select>
- <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
- <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
- <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
- <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
- </td>
- </tr>
-|;
- }
-
- $fromto = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Startdate').qq|</th>
- <td>|.$locale->text('From').qq| <input name=startdatefrom size=11 title="$myconfig{dateformat}">
- |.$locale->text('To').qq| <input name=startdateto size=11 title="$myconfig{dateformat}"></td>
- </tr>
- $selectfrom
-|;
-
-
- if ($form->{type} eq 'timecard') {
- $form->{title} = $locale->text('Time Cards');
- JC->jcitems_links(\%myconfig, \%$form);
- }
- if ($form->{type} eq 'storescard') {
- $form->{title} = $locale->text('Stores Cards');
- JC->jcitems_links(\%myconfig, \%$form);
- }
-
- if (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} = "<option>\n";
- for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
- }
-
- if (@{ $form->{all_parts} }) {
- $form->{selectpartnumber} = "<option>\n";
- foreach $ref (@{ $form->{all_parts} }) {
- $form->{selectpartnumber} .= qq|<option value="$ref->{partnumber}--$ref->{id}">$ref->{partnumber}\n|;
- }
- }
-
- if ($form->{project} eq 'job') {
- $joblabel = $locale->text('Job Number');
- $laborlabel = $locale->text('Labor Code');
- } elsif ($form->{project} eq 'project') {
- $joblabel = $locale->text('Project Number');
- $laborlabel = $locale->text('Service Code');
- } else {
- $joblabel = $locale->text('Project/Job Number');
- $laborlabel = $locale->text('Service/Labor Code');
- }
-
- if ($form->{selectprojectnumber}) {
- $jobnumber = qq|
- <tr>
- <th align=right nowrap>$joblabel</th>
- <td colspan=3><select name=projectnumber>$form->{selectprojectnumber}</select></td>
- </tr>
-|;
- }
-
-
- if ($form->{type} eq 'timecard') {
- # employees
- if (@{ $form->{all_employee} }) {
- $form->{selectemployee} = "<option>\n";
- for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- } else {
- $form->error($locale->text('No Employees on file!'));
- }
-
- if ($form->{selectpartnumber}) {
- $partnumber = qq|
- <tr>
- <th align=right nowrap>$laborlabel</th>
- <td colspan=3><select name=partnumber>$form->{selectpartnumber}</select></td>
- </tr>
-|;
- }
-
- $employee = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Employee').qq|</th>
- <td colspan=3><select name=employee>$form->{selectemployee}</select></td>
- </tr>
-|;
-
- $l_time = qq|<td nowrap><input name=l_time class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Time').qq|</td>|;
-
- }
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr valign=top>
- <td>
- <table>
- $jobnumber
- $partnumber
- $employee
- $fromto
-
- <tr>
- <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
- <td>
- <table>
- <tr>
- <td nowrap><input name=open class=checkbox type=checkbox value=Y checked> |.$locale->text('Open').qq|</td>
- <td nowrap><input name=closed class=checkbox type=checkbox value=Y> |.$locale->text('Closed').qq|</td>
- </tr>
- <tr>
- $l_time
- <td nowrap><input name=l_allocated class=checkbox type=checkbox value=Y> |.$locale->text('Allocated').qq|</td>
- </tr>
- <tr>
- <td><input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|</td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<input type=hidden name=nextsub value="list_$form->{type}">
-<input type=hidden name=sort value="transdate">
-|;
-
- $form->hide_form(qw(db path login sessionid project type));
-
- print qq|
-<br>
-<button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
-</form>
-|;
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
-
-</body>
-</html>
-|;
-
-}
-
-
-sub display_form {
-
- &{ "$form->{type}_header" };
- &{ "$form->{type}_footer" };
-
-}
-
-
-sub form_header {
-
- &{ "$form->{type}_header" };
-
-}
-
-
-sub form_footer {
-
- &{ "form->{type}_footer" };
-
-}
-
-
-sub prepare_timecard {
-
- $form->{formname} = "timecard";
- $form->{format} = "postscript" if $myconfig{printer};
- $form->{media} = $myconfig{printer};
-
- JC->get_jcitems(\%myconfig, \%$form);
-
- $form->{selectformname} = qq|<option value="timecard">|.$locale->text('Time Card');
-
- foreach $item (qw(in out)) {
- ($form->{"${item}hour"}, $form->{"${item}min"}, $form->{"${item}sec"}) = split /:/, $form->{"checked$item"};
- for (qw(hour min sec)) {
- if (($form->{"$item$_"} *= 1) > 0) {
- $form->{"$item$_"} = substr(qq|0$form->{"$item$_"}|,-2);
- } else {
- $form->{"$item$_"} ||= "";
- }
- }
- }
-
- $form->{checkedin} = $form->{inhour} * 3600 + $form->{inmin} * 60 + $form->{insec};
- $form->{checkedout} = $form->{outhour} * 3600 + $form->{outmin} * 60 + $form->{outsec};
-
- if ($form->{checkedin} > $form->{checkedout}) {
- $form->{checkedout} = 86400 - ($form->{checkedin} - $form->{checkedout});
- $form->{checkedin} = 0;
- }
-
- $form->{clocked} = ($form->{checkedout} - $form->{checkedin}) / 3600;
- if ($form->{clocked}) {
- $form->{oldnoncharge} = $form->{clocked} - $form->{qty};
- }
- $form->{oldqty} = $form->{qty};
-
- $form->{noncharge} = $form->format_amount(\%myconfig, $form->{clocked} - $form->{qty}, 4) if $form->{checkedin} != $form->{checkedout};
- $form->{clocked} = $form->format_amount(\%myconfig, $form->{clocked}, 4);
-
- $form->{amount} = $form->{sellprice} * $form->{qty};
- for (qw(sellprice amount)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
- $form->{qty} = $form->format_amount(\%myconfig, $form->{qty}, 4);
- $form->{allocated} = $form->format_amount(\%myconfig, $form->{allocated});
-
- $form->{employee} .= "--$form->{employee_id}";
- $form->{projectnumber} .= "--$form->{project_id}";
- $form->{partnumber} .= "--$form->{parts_id}";
- $form->{oldpartnumber} = $form->{partnumber};
-
- if (@{ $form->{all_language} }) {
- $form->{selectlanguage} = "<option>\n";
- for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
- }
-
- &jcitems_links;
-
- $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
-
- $form->{readonly} = 1 if $myconfig{acs} =~ /Production--Add Time Card/;
-
- if ($form->{income_accno_id}) {
- $form->{locked} = 1 if $form->{production} == $form->{completed};
- }
-
-}
-
-
-sub timecard_header {
-
- # set option selected
- for (qw(employee projectnumber partnumber)) {
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
- }
-
- $rows = $form->numtextrows($form->{description}, 50, 8);
-
- for (qw(transdate checkedin checkedout partnumber)) { $form->{"old$_"} = $form->{$_} }
- for (qw(partnumber description)) { $form->{$_} = $form->quote($form->{$_}) }
-
- if ($rows > 1) {
- $description = qq|<textarea name=description rows=$rows cols=46 wrap=soft>$form->{description}</textarea>|;
- } else {
- $description = qq|<input name=description size=48 value="$form->{description}">|;
- }
-
- if ($form->{project} eq 'job') {
-
- $projectlabel = $locale->text('Job Number');
- $laborlabel = $locale->text('Labor Code');
- $rate = qq|<input type=hidden name=sellprice value=$form->{sellprice}>|;
-
- } else {
-
- if ($form->{project} eq 'project') {
- $projectlabel = $locale->text('Project Number');
- $laborlabel = $locale->text('Service Code');
- } else {
- $projectlabel = $locale->text('Project/Job Number');
- $laborlabel = $locale->text('Service/Labor Code');
- }
-
- if ($myconfig{role} ne 'user') {
- $rate = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Chargeout Rate').qq|</th>
- <td><input name=sellprice value=$form->{sellprice}></td>
- <th align=right nowrap>|.$locale->text('Total').qq|</th>
- <td>$form->{amount}</td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Allocated').qq|</th>
- <td><input name=allocated value=$form->{allocated}></td>
- </tr>
-|;
- } else {
- $rate = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Chargeout Rate').qq|</th>
- <td>$form->{sellprice}</td>
- <th align=right nowrap>|.$locale->text('Total').qq|</th>
- <td>$form->{amount}</td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Allocated').qq|</th>
- <td>$form->{allocated}</td>
- </tr>
- <input type=hidden name=sellprice value=$form->{sellprice}>
- <input type=hidden name=allocated value=$form->{allocated}>
-|;
- }
- }
-
- if ($myconfig{role} eq 'user') {
- $charge = qq|<input type=hidden name=qty value=$form->{qty}>$form->{qty}|;
- } else {
- $charge = qq|<input name=qty value=$form->{qty}>|;
- }
-
- if (($rows = $form->numtextrows($form->{notes}, 40, 6)) < 2) {
- $rows = 2;
- }
-
- $notes = qq|<tr>
- <th align=right>|.$locale->text('Notes').qq|</th>
- <td colspan=3><textarea name="notes" rows=$rows cols=46 wrap=soft>$form->{notes}</textarea>
- </td>
- </tr>
-|;
-
-##################
- ($null, $form->{oldproject_id}) = split /--/, $form->{projectnumber};
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action="$form->{script}">
-|;
-
- $form->hide_form(qw(id type media format printed queued title closedto locked oldtransdate oldcheckedin oldcheckedout oldpartnumber project oldqty oldnoncharge pricematrix oldproject_id));
-
- print qq|
-<table width=100%>
- <tr class=listtop>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>
- <table>
- <tr>
- <td>
- <table>
- <tr>
- <th align=right nowrap>|.$locale->text('Employee').qq|</th>
- <td><select name=employee>$form->{selectemployee}</select></td>
- </tr>
- <tr>
- <th align=right nowrap>$projectlabel</th>
- <td><select name=projectnumber>$form->{selectprojectnumber}</select>
- </td>
- <td></td>
- <td>$form->{projectdescription}</td>
- <input type=hidden name=projectdescription value="|.$form->quote($form->{projectdescription}).qq|">
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Date worked').qq|</th>
- <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
- </tr>
- <tr>
- <th align=right nowrap>$laborlabel</th>
- <td><select name=partnumber>$form->{selectpartnumber}</select></td>
- </tr>
- <tr valign=top>
- <th align=right nowrap>|.$locale->text('Description').qq|</th>
- <td colspan=3>$description</td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Time In').qq|</th>
- <td>
- <table>
- <tr>
- <td><input name=inhour title="hh" size=3 maxlength=2 value=$form->{inhour}></td>
- <td><input name=inmin title="mm" size=3 maxlength=2 value=$form->{inmin}></td>
- <td><input name=insec title="ss" size=3 maxlength=2 value=$form->{insec}></td>
- </tr>
- </table>
- </td>
- <th align=right nowrap>|.$locale->text('Time Out').qq|</th>
- <td>
- <table>
- <tr>
- <td><input name=outhour title="hh" size=3 maxlength=2 value=$form->{outhour}></td>
- <td><input name=outmin title="mm" size=3 maxlength=2 value=$form->{outmin}></td>
- <td><input name=outsec title="ss" size=3 maxlength=2 value=$form->{outsec}></td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Clocked').qq|</th>
- <td>$form->{clocked}</td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Non-chargeable').qq|</th>
- <td><input name=noncharge value=$form->{noncharge}></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Chargeable').qq|</th>
- <td>$charge</td>
- </tr>
- $rate
- $notes
- </table>
- </td>
- </tr>
-
-|;
-
-}
-
-
-sub timecard_footer {
-
- print qq|
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
- <tr>
- <td>
-|;
-
- &print_options;
-
- print qq|
- </td>
- </tr>
-</table>
-<br>
-|;
-
- $transdate = $form->datetonum(\%myconfig, $form->{transdate});
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
-
- if (! $form->{readonly}) {
-
-# type=submit $locale->text('Update')
-# type=submit $locale->text('Print')
-# type=submit $locale->text('Save')
-# type=submit $locale->text('Print and Save')
-# type=submit $locale->text('Save as new')
-# type=submit $locale->text('Print and Save as new')
-# type=submit $locale->text('Delete')
-
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
- 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
- 'print_and_save' => { ndx => 6, key => 'R', value => $locale->text('Print and Save') },
- 'save_as_new' => { ndx => 7, key => 'N', value => $locale->text('Save as new') },
- 'print_and_save_as_new' => { ndx => 8, key => 'W', value => $locale->text('Print and Save as new') },
-
- 'delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') },
- );
-
- %a = ();
-
- if ($form->{id}) {
-
- if (!$form->{locked}) {
- for ('update', 'print', 'save', 'save_as_new') { $a{$_} = 1 }
-
- if (${LedgerSMB::Sysconfig::latex}) {
- for ('print_and_save', 'print_and_save_as_new') { $a{$_} = 1 }
- }
-
- if ($form->{orphaned}) {
- $a{'delete'} = 1;
- }
-
- }
-
- } else {
-
- if ($transdate > $closedto) {
-
- for ('update', 'print', 'save') { $a{$_} = 1 }
-
- if (${LedgerSMB::Sysconfig::latex}) {
- $a{'print_and_save'} = 1;
- }
-
- }
- }
- }
-
- for (keys %button) { delete $button{$_} if ! $a{$_} }
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- $form->hide_form(qw(callback path login sessionid));
-
- print qq|
-
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
-sub prepare_storescard {
-
- $form->{formname} = "storescard";
- $form->{format} = "postscript" if $myconfig{printer};
- $form->{media} = $myconfig{printer};
-
- JC->get_jcitems(\%myconfig, \%$form);
-
- $form->{selectformname} = qq|<option value="storescard">|.$locale->text('Stores Card');
-
- $form->{amount} = $form->{sellprice} * $form->{qty};
- for (qw(sellprice amount)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
- $form->{qty} = $form->format_amount(\%myconfig, $form->{qty}, 4);
-
- $form->{employee} .= "--$form->{employee_id}";
- $form->{projectnumber} .= "--$form->{project_id}";
- $form->{partnumber} .= "--$form->{parts_id}";
- $form->{oldpartnumber} = $form->{partnumber};
-
- if (@{ $form->{all_language} }) {
- $form->{selectlanguage} = "<option>\n";
- for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
- }
-
- &jcitems_links;
-
- $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
-
- $form->{readonly} = 1 if $myconfig{acs} =~ /Production--Add Time Card/;
-
- if ($form->{income_accno_id}) {
- $form->{locked} = 1 if $form->{production} == $form->{completed};
- }
-
-}
-
-
-sub storescard_header {
-
- # set option selected
- for (qw(employee projectnumber partnumber)) {
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
- }
-
- $rows = $form->numtextrows($form->{description}, 50, 8);
-
- for (qw(transdate partnumber)) { $form->{"old$_"} = $form->{$_} }
- for (qw(partnumber description)) { $form->{$_} = $form->quote($form->{$_}) }
-
- if ($rows > 1) {
- $description = qq|<textarea name=description rows=$rows cols=46 wrap=soft>$form->{description}</textarea>|;
- } else {
- $description = qq|<input name=description size=48 value="$form->{description}">|;
- }
-
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action="$form->{script}">
-|;
-
- $form->hide_form(qw(id type media format printed queued title closedto locked oldtransdate oldpartnumber project));
-
- print qq|
-<table width=100%>
- <tr class=listtop>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>
- <table>
- <tr>
- <td>
- <table>
- <tr>
- <th align=right nowrap>|.$locale->text('Job Number').qq|</th>
- <td><select name=projectnumber>$form->{selectprojectnumber}</select>
- </td>
- <td>$form->{projectdescription}</td>
- <input type=hidden name=projectdescription value="|.$form->quote($form->{projectdescription}).qq|">
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Date').qq|</th>
- <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Part Number').qq|</th>
- <td><select name=partnumber>$form->{selectpartnumber}</td>
- </tr>
- <tr valign=top>
- <th align=right nowrap>|.$locale->text('Description').qq|</th>
- <td>$description</td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Qty').qq|</th>
- <td><input name=qty size=6 value=$form->{qty}>
- <b>|.$locale->text('Cost').qq|</b>
- <input name=sellprice size=10 value=$form->{sellprice}></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Total').qq|</th>
- <td>$form->{amount}</td>
- </tr>
- </table>
- </td>
- </tr>
-
-|;
-
-}
-
-
-sub storescard_footer {
-
- print qq|
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
- <tr>
- <td>
-|;
-
- &print_options;
-
- print qq|
- </td>
- </tr>
-</table>
-<br>
-|;
-
- $transdate = $form->datetonum(\%myconfig, $form->{transdate});
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
-
-# type=submit $locale->text('Update')
-# type=submit $locale->text('Print')
-# type=submit $locale->text('Save')
-# type=submit $locale->text('Print and Save')
-# type=submit $locale->text('Save as new')
-# type=submit $locale->text('Print and Save as new')
-# type=submit $locale->text('Delete')
-
-
- if (! $form->{readonly}) {
-
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
- 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
- 'print_and_save' => { ndx => 6, key => 'R', value => $locale->text('Print and Save') },
- 'save_as_new' => { ndx => 7, key => 'N', value => $locale->text('Save as new') },
- 'print_and_save_as_new' => { ndx => 8, key => 'W', value => $locale->text('Print and Save as new') },
- 'delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') },
- );
-
- %a = ();
-
- if ($form->{id}) {
-
- if (!$form->{locked}) {
- for ('update', 'print', 'save', 'save_as_new') { $a{$_} = 1 }
- if (${LedgerSMB::Sysconfig::latex}) {
- for ('print_and_save', 'print_and_save_as_new') { $a{$_} = 1 }
- }
- if ($form->{orphaned}) {
- $a{'delete'} = 1;
- }
- }
-
- } else {
-
- if ($transdate > $closedto) {
- for ('update', 'print', 'save') { $a{$_} = 1 }
-
- if (${LedgerSMB::Sysconfig::latex}) {
- $a{'print_and_save'} = 1;
- }
- }
- }
-
- for (keys %button) { delete $button{$_} if ! $a{$_} }
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
-
- }
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- $form->hide_form(qw(callback path login sessionid));
-
- print qq|
-
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
-
-sub update {
-
- ($null, $form->{project_id}) = split /--/, $form->{projectnumber};
-
- # check labor/part
- JC->jcitems_links(\%myconfig, \%$form);
-
- &jcitems_links;
-
- $checkmatrix = 1 if $form->{oldproject_id} != $form->{project_id};
-
- if ($form->{type} eq 'timecard') {
-
- # time clocked
- %hour = ( in => 0, out => 0 );
- for $t (qw(in out)) {
- if ($form->{"${t}sec"} > 60) {
- $form->{"${t}sec"} -= 60;
- $form->{"${t}min"}++;
- }
- if ($form->{"${t}min"} > 60) {
- $form->{"${t}min"} -= 60;
- $form->{"${t}hour"}++;
- }
- $hour{$t} = $form->{"${t}hour"};
- }
-
- $form->{checkedin} = $hour{in} * 3600 + $form->{inmin} * 60 + $form->{insec};
- $form->{checkedout} = $hour{out} * 3600 + $form->{outmin} * 60 + $form->{outsec};
-
- if ($form->{checkedin} > $form->{checkedout}) {
- $form->{checkedout} = 86400 - ($form->{checkedin} - $form->{checkedout});
- $form->{checkedin} = 0;
- }
-
- $form->{clocked} = ($form->{checkedout} - $form->{checkedin}) / 3600;
-
- for (qw(sellprice qty noncharge allocated)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-
- $checkmatrix = 1 if $form->{oldqty} != $form->{qty};
-
- if (($form->{oldcheckedin} != $form->{checkedin}) || ($form->{oldcheckedout} != $form->{checkedout})) {
- $checkmatrix = 1;
- $form->{oldqty} = $form->{qty} = $form->{clocked} - $form->{noncharge};
- $form->{oldnoncharge} = $form->{noncharge};
- }
-
- if (($form->{qty} != $form->{oldqty}) && $form->{clocked}) {
- $form->{oldnoncharge} = $form->{noncharge} = $form->{clocked} - $form->{qty};
- $checkmatrix = 1;
- }
-
- if (($form->{oldnoncharge} != $form->{noncharge}) && $form->{clocked}) {
- $form->{oldqty} = $form->{qty} = $form->{clocked} - $form->{noncharge};
- $checkmatrix = 1;
- }
-
- if ($checkmatrix) {
- @a = split / /, $form->{pricematrix};
- if (scalar @a > 2) {
- for (@a) {
- ($q, $p) = split /:/, $_;
- if (($p * 1) && ($form->{qty} >= ($q * 1))) {
- $form->{sellprice} = $p;
- }
- }
- }
- }
-
- $form->{amount} = $form->{sellprice} * $form->{qty};
-
- $form->{clocked} = $form->format_amount(\%myconfig, $form->{clocked}, 4);
- for (qw(sellprice amount)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
- for (qw(qty noncharge)) {
- $form->{"old$_"} = $form->{$_};
- $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 4);
- }
-
- } else {
-
- for (qw(sellprice qty allocated)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-
- if ($form->{oldqty} != $form->{qty}) {
- @a = split / /, $form->{pricematrix};
- if (scalar @a > 2) {
- for (@a) {
- ($q, $p) = split /:/, $_;
- if (($p * 1) && ($form->{qty} >= ($q * 1))) {
- $form->{sellprice} = $p;
- }
- }
- }
- }
-
- $form->{amount} = $form->{sellprice} * $form->{qty};
- for (qw(sellprice amount)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
-
- }
-
- $form->{allocated} = $form->format_amount(\%myconfig, $form->{allocated});
-
- &display_form;
-
-}
-
-
-sub save {
-
- $form->isblank("transdate", $locale->text('Date missing!'));
-
- if ($form->{project} eq 'project') {
- $form->isblank("projectnumber", $locale->text('Project Number missing!'));
- $form->isblank("partnumber", $locale->text('Service Code missing!'));
- } else {
- $form->isblank("projectnumber", $locale->text('Job Number missing!'));
- $form->isblank("partnumber", $locale->text('Labor Code missing!'));
- }
-
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
- $transdate = $form->datetonum(\%myconfig, $form->{transdate});
-
- $msg = ($form->{type} eq 'timecard') ? $locale->text('Cannot save time card for a closed period!') : $locale->text('Cannot save stores card for a closed period!');
- $form->error($msg) if ($transdate <= $closedto);
-
- if (! $form->{resave}) {
- if ($form->{id}) {
- &resave;
- exit;
- }
- }
-
-
- $rc = JC->save(\%myconfig, \%$form);
-
- if ($form->{type} eq 'timecard') {
- $form->error($locale->text('Cannot change time card for a completed job!')) if ($rc == -1);
- $form->error($locale->text('Cannot add time card for a completed job!')) if ($rc == -2);
-
- if ($rc) {
- $form->redirect($locale->text('Time Card saved!'));
- } else {
- $form->error($locale->text('Cannot save time card!'));
- }
-
- } else {
- $form->error($locale->text('Cannot change stores card for a completed job!')) if ($rc == -1);
- $form->error($locale->text('Cannot add stores card for a completed job!')) if ($rc == -2);
-
- if ($rc) {
- $form->redirect($locale->text('Stores Card saved!'));
- } else {
- $form->error($locale->text('Cannot save stores card!'));
- }
- }
-
-}
-
-
-sub save_as_new {
-
- delete $form->{id};
- &save;
-
-}
-
-
-sub print_and_save_as_new {
-
- delete $form->{id};
- &print_and_save;
-
-}
-
-
-sub resave {
-
- if ($form->{print_and_save}) {
- $form->{nextsub} = "print_and_save";
- $msg = $locale->text('You are printing and saving an existing transaction!');
- } else {
- $form->{nextsub} = "save";
- $msg = $locale->text('You are saving an existing transaction!');
- }
-
- $form->{resave} = 1;
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-
-|;
-
- delete $form->{action};
-
- $form->hide_form;
-
- print qq|
-<h2 class=confirm>|.$locale->text('Warning!').qq|</h2>
-
-<h4>$msg</h4>
-
-<button name="action" class="submit" type="submit" value="continue">|.$locale->text('Continue').qq|</button>
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
-sub print_and_save {
-
- $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
- $form->error($locale->text('Select a Printer!')) if $form->{media} eq 'screen';
-
- if (! $form->{resave}) {
- if ($form->{id}) {
- $form->{print_and_save} = 1;
- &resave;
- exit;
- }
- }
-
- $old_form = new Form;
- $form->{display_form} = "save";
- for (keys %$form) { $old_form->{$_} = $form->{$_} }
-
- &{ "print_$form->{formname}" }($old_form);
-
-}
-
-
-sub delete_timecard {
-
- $form->header;
-
- $employee = $form->{employee};
- $employee =~ s/--.*//g;
- $projectnumber = $form->{projectnumber};
- $projectnumber =~ s/--.*//g;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-|;
-
- delete $form->{action};
-
- $form->hide_form;
-
- print qq|
-<h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
-
-<h4>|.$locale->text('Are you sure you want to delete time card for').qq|
-<p>$form->{transdate}
-<br>$employee
-<br>$projectnumber
-</h4>
-
-<p>
-<button name="action" class="submit" type="submit" value="yes">|.$locale->text('Yes').qq|</button>
-</form>
-|;
-
-}
-
-
-sub delete { &{ "delete_$form->{type}" } };
-sub yes { &{ "yes_delete_$form->{type}" } };
-
-
-sub yes_delete_timecard {
-
- if (JC->delete_timecard(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Time Card deleted!'));
- } else {
- $form->error($locale->text('Cannot delete time card!'));
- }
-
-}
-
-
-sub list_timecard {
-
- $form->{type} = "timecard";
-
- JC->jcitems(\%myconfig, \%$form);
-
- $form->{title} = $locale->text('Time Cards');
-
- @a = qw(type direction oldsort path login sessionid project l_subtotal open closed l_time l_allocated);
- $href = "$form->{script}?action=list_timecard";
- for (@a) { $href .= "&$_=$form->{$_}" }
-
- $href .= "&title=".$form->escape($form->{title});
-
- $form->sort_order();
-
- $callback = "$form->{script}?action=list_timecard";
- for (@a) { $callback .= "&$_=$form->{$_}" }
-
- $callback .= "&title=".$form->escape($form->{title},1);
-
- @column_index = (qw(transdate projectnumber projectdescription id partnumber description));
-
- push @column_index, (qw(allocated)) if $form->{l_allocated};
- push @column_index, (qw(1 2 3 4 5 6 7));
-
- @column_index = $form->sort_columns(@column_index);
-
- if ($form->{project} eq 'job') {
- $joblabel = $locale->text('Job Number');
- $laborlabel = $locale->text('Labor Code');
- $desclabel = $locale->text('Job Name');
- } elsif ($form->{project} eq 'project') {
- $joblabel = $locale->text('Project Number');
- $laborlabel = $locale->text('Service Code');
- $desclabel = $locale->text('Project Name');
- } else {
- $joblabel = $locale->text('Project/Job Number');
- $laborlabel = $locale->text('Service/Labor Code');
- $desclabel = $locale->text('Project/Job Name');
- }
-
- if ($form->{projectnumber}) {
- $callback .= "&projectnumber=".$form->escape($form->{projectnumber},1);
- $href .= "&projectnumber=".$form->escape($form->{projectnumber});
- ($var) = split /--/, $form->{projectnumber};
- $option .= "\n<br>" if ($option);
- $option .= "$joblabel : $var";
- @column_index = grep !/projectnumber/, @column_index;
- }
- if ($form->{partnumber}) {
- $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
- $href .= "&partnumber=".$form->escape($form->{partnumber});
- ($var) = split /--/, $form->{partnumber};
- $option .= "\n<br>" if ($option);
- $option .= "$laborlabel : $var";
- @column_index = grep !/partnumber/, @column_index;
- }
- if ($form->{employee}) {
- $callback .= "&employee=".$form->escape($form->{employee},1);
- $href .= "&employee=".$form->escape($form->{employee});
- }
-
- if ($form->{startdatefrom}) {
- $callback .= "&startdatefrom=$form->{startdatefrom}";
- $href .= "&startdatefrom=$form->{startdatefrom}";
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{startdatefrom}, 1);
- }
- if ($form->{startdateto}) {
- $callback .= "&startdateto=$form->{startdateto}";
- $href .= "&startdateto=$form->{startdateto}";
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{startdateto}, 1);
- }
- if ($form->{open}) {
- $callback .= "&open=$form->{open}";
- $href .= "&open=$form->{open}";
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Open');
- }
- if ($form->{closed}) {
- $callback .= "&closed=$form->{closed}";
- $href .= "&closed=$form->{closed}";
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Closed');
- }
-
- %weekday = ( 1 => $locale->text('Sunday'),
- 2 => $locale->text('Monday'),
- 3 => $locale->text('Tuesday'),
- 4 => $locale->text('Wednesday'),
- 5 => $locale->text('Thursday'),
- 6 => $locale->text('Friday'),
- 7 => $locale->text('Saturday'),
- );
-
- for (keys %weekday) { $column_header{$_} = "<th class=listheading width=25>".substr($weekday{$_},0,3)."</th>" }
-
- $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>";
- $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
- $column_header{description} = "<th><a class=listheading href=$href&sort=description>" . $locale->text('Description') . "</th>";
- $column_header{projectnumber} = "<th><a class=listheading href=$href&sort=projectnumber>$joblabel</a></th>";
- $column_header{partnumber} = "<th><a class=listheading href=$href&sort=partnumber>$laborlabel</a></th>";
- $column_header{projectdescription} = "<th><a class=listheading href=$href&sort=projectdescription>$desclabel</a></th>";
- $column_header{allocated} = "<th class=listheading></th>";
-
-
- $form->header;
-
- if (@{ $form->{transactions} }) {
- $sameitem = $form->{transactions}->[0]->{$form->{sort}};
- $sameemployeenumber = $form->{transactions}->[0]->{employeenumber};
- $employee = $form->{transactions}->[0]->{employee};
- $sameweek = $form->{transactions}->[0]->{workweek};
- }
-
- print qq|
-<body>
-
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>$option</td>
- </tr>
- <tr>
- <td>
- <table width=100%>
- <tr>
- <th colspan=2 align=left>
- $employee
- </th>
- <th align=left>
- $sameemployeenumber
- </th>
- <tr class=listheading>
-|;
-
- for (@column_index) { print "\n$column_header{$_}" }
-
- print qq|
- </tr>
-|;
-
- # add sort and escape callback, this one we use for the add sub
- $form->{callback} = $callback .= "&sort=$form->{sort}";
-
- # escape callback for href
- $callback = $form->escape($callback);
-
- # flip direction
- $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
- $href =~ s/&direction=(\w+)&/&direction=$direction&/;
-
- %total = ();
-
- foreach $ref (@{ $form->{transactions} }) {
-
- if ($sameemployeenumber ne $ref->{employeenumber}) {
- $sameemployeenumber = $ref->{employeenumber};
- $sameweek = $ref->{workweek};
-
- if ($form->{l_subtotal}) {
- print qq|
- <tr class=listsubtotal>
-|;
-
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $weektotal = 0;
- for (keys %weekday) {
- $column_data{$_} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotal{$_}, "", "&nbsp;")."</th>";
- $weektotal += $subtotal{$_};
- $subtotal{$_} = 0;
- }
-
- $column_data{$form->{sort}} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $weektotal, "", "&nbsp;")."</th>";
-
- for (@column_index) { print "\n$column_data{$_}" }
- }
-
- # print total
- print qq|
- <tr class=listtotal>
-|;
-
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $total = 0;
- for (keys %weekday) {
- $column_data{$_} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $total{$_}, "", "&nbsp;")."</th>";
- $total += $total{$_};
- $total{$_} = 0;
- }
-
- $column_data{$form->{sort}} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $total, "", "&nbsp;")."</th>";
-
- for (@column_index) { print "\n$column_data{$_}" }
-
-
- print qq|
- <tr height=30 valign=bottom>
- <th colspan=2 align=left>
- $ref->{employee}
- </th>
- <th align=left>
- $ref->{employeenumber}
- </th>
- <tr class=listheading>
-|;
-
- for (@column_index) { print "\n$column_header{$_}" }
-
- print qq|
- </tr>
-|;
-
- }
-
- if ($form->{l_subtotal}) {
- if ($ref->{workweek} != $sameweek) {
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
- $weektotal = 0;
- for (keys %weekday) {
- $column_data{$_} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotal{$_}, "", "&nbsp;")."</th>";
- $weektotal += $subtotal{$_};
- $subtotal{$_} = 0
- }
- $column_data{$form->{sort}} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $weektotal, "", "&nbsp;")."</th>";
- $sameweek = $ref->{workweek};
-
- print qq|
- <tr class=listsubtotal>
-|;
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
- </tr>
-|;
- }
- }
-
- for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
- for (keys %weekday) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $column_data{allocated} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{allocated}, "", "&nbsp;")."</td>";
- $column_data{$ref->{weekday}} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{qty}, "", "&nbsp;");
-
- if ($form->{l_time}) {
- $column_data{$ref->{weekday}} .= "<br>$ref->{checkedin}<br>$ref->{checkedout}";
- }
- $column_data{$ref->{weekday}} .= "</td>";
-
- $column_data{id} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&project=$form->{project}&callback=$callback>$ref->{id}</a></td>";
-
- $subtotal{$ref->{weekday}} += $ref->{qty};
- $total{$ref->{weekday}} += $ref->{qty};
-
- $j++; $j %= 2;
- print qq|
- <tr class=listrow$j>
-|;
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
- </tr>
-|;
- }
-
- # print last subtotal
- if ($form->{l_subtotal}) {
- print qq|
- <tr class=listsubtotal>
-|;
-
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $weektotal = 0;
- for (keys %weekday) {
- $column_data{$_} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotal{$_}, "", "&nbsp;")."</th>";
- $weektotal += $subtotal{$_};
- }
-
- $column_data{$form->{sort}} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $weektotal, "", "&nbsp;")."</th>";
-
- for (@column_index) { print "\n$column_data{$_}" }
- }
-
- # print last total
- print qq|
- <tr class=listtotal>
-|;
-
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $total = 0;
- for (keys %weekday) {
- $column_data{$_} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $total{$_}, "", "&nbsp;")."</th>";
- $total += $total{$_};
- $total{$_} = 0;
- }
-
- $column_data{$form->{sort}} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $total, "", "&nbsp;")."</th>";
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- if ($form->{project} eq 'job') {
- if ($myconfig{acs} !~ /Production--Production/) {
- $i = 1;
- $button{'Production--Add Time Card'}{code} = qq|<button class="submit" type="submit" name="action" value="add_time_card">|.$locale->text('Add Time Card').qq|</button> |;
- $button{'Production--Add Time Card'}{order} = $i++;
- }
- } elsif ($form->{project} eq 'project') {
- if ($myconfig{acs} !~ /Projects--Projects/) {
- $i = 1;
- $button{'Projects--Add Time Card'}{code} = qq|<button class="submit" type="submit" name="action" value="add_time_card">|.$locale->text('Add Time Card').qq|</button> |;
- $button{'Projects--Add Time Card'}{order} = $i++;
- }
- } else {
- if ($myconfig{acs} !~ /Time Cards--Time Cards/) {
- $i = 1;
- $button{'Time Cards--Add Time Card'}{code} = qq|<button class="submit" type="submit" name="action" value="add_time_card">|.$locale->text('Add Time Card').qq|</button> |;
- $button{'Time Cards--Add Time Card'}{order} = $i++;
- }
- }
-
- for (split /;/, $myconfig{acs}) { delete $button{$_} }
-
- print qq|
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<br>
-<form method=post action=$form->{script}>
-|;
-
- $form->hide_form(qw(callback path login sessionid project));
-
- foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
- print $item->{code};
- }
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
-sub list_storescard {
-
- $form->{type} = "storescard";
-
- JC->jcitems(\%myconfig, \%$form);
-
- $form->{title} = $locale->text('Stores Cards');
-
- $href = "$form->{script}?action=list_storescard";
- for (qw(type direction oldsort path login sessionid project)) { $href .= "&$_=$form->{$_}" }
-
- $href .= "&title=".$form->escape($form->{title});
-
- $form->sort_order();
-
- $callback = "$form->{script}?action=list_storescard";
- for (qw(type direction oldsort path login sessionid project)) { $callback .= "&$_=$form->{$_}" }
-
- $callback .= "&title=".$form->escape($form->{title},1);
-
- @column_index = $form->sort_columns(qw(transdate projectnumber projectdescription id partnumber description qty amount));
-
-
- if ($form->{projectnumber}) {
- $callback .= "&projectnumber=".$form->escape($form->{projectnumber},1);
- $href .= "&projectnumber=".$form->escape($form->{projectnumber});
- ($var) = split /--/, $form->{projectnumber};
- $option .= "\n<br>" if ($option);
- $option .= "$joblabel : $var";
- @column_index = grep !/projectnumber/, @column_index;
- }
- if ($form->{partnumber}) {
- $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
- $href .= "&partnumber=".$form->escape($form->{partnumber});
- ($var) = split /--/, $form->{partnumber};
- $option .= "\n<br>" if ($option);
- $option .= "$laborlabel : $var";
- @column_index = grep !/partnumber/, @column_index;
- }
- if ($form->{startdatefrom}) {
- $callback .= "&startdatefrom=$form->{startdatefrom}";
- $href .= "&startdatefrom=$form->{startdatefrom}";
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{startdatefrom}, 1);
- }
- if ($form->{startdateto}) {
- $callback .= "&startdateto=$form->{startdateto}";
- $href .= "&startdateto=$form->{startdateto}";
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{startdateto}, 1);
- }
-
- $column_header{id} = "<th><a class=listheading href=$href&sort=id>" . $locale->text('ID') . "</a></th>";
- $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
- $column_header{projectnumber} = "<th><a class=listheading href=$href&sort=projectnumber>" . $locale->text('Job Number') . "</a></th>";
- $column_header{projectdescription} = "<th><a class=listheading href=$href&sort=projectdescription>" . $locale->text('Job Description') . "</a></th>";
- $column_header{partnumber} = "<th><a class=listheading href=$href&sort=partnumber>" . $locale->text('Part Number') . "</a></th>";
- $column_header{description} = "<th><a class=listheading href=$href&sort=description>" . $locale->text('Description') . "</a></th>";
- $column_header{qty} = "<th class=listheading>" . $locale->text('Qty') . "</th>";
- $column_header{amount} = "<th class=listheading>" . $locale->text('Amount') . "</th>";
-
-
- $form->header;
-
- if (@{ $form->{transactions} }) {
- $sameitem = $form->{transactions}->[0]->{$form->{sort}};
- }
-
- print qq|
-<body>
-
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>$option</td>
- </tr>
- <tr>
- <td>
- <table width=100%>
- <tr class=listheading>
-|;
-
- for (@column_index) { print "\n$column_header{$_}" }
-
- print qq|
- </tr>
-|;
-
- # add sort and escape callback, this one we use for the add sub
- $form->{callback} = $callback .= "&sort=$form->{sort}";
-
- # escape callback for href
- $callback = $form->escape($callback);
-
- # flip direction
- $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
- $href =~ s/&direction=(\w+)&/&direction=$direction&/;
-
- $total = 0;
- foreach $ref (@{ $form->{transactions} }) {
-
- for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
- $column_data{qty} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{qty}, "", "&nbsp;")."</td>";
- $column_data{amount} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{qty} * $ref->{sellprice}, 2)."</td>";
-
- $column_data{id} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&project=$form->{project}&callback=$callback>$ref->{id}</a></td>";
-
- $total += ($ref->{qty} * $ref->{sellprice});
-
- $j++; $j %= 2;
- print qq|
- <tr class=listrow$j>
-|;
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
- </tr>
-|;
- }
-
- # print total
- print qq|
- <tr class=listtotal>
-|;
-
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
- $column_data{amount} = qq|<th align=right>|.$form->format_amount(\%myconfig, $total, 2)."</th";
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- if ($form->{project} eq 'job') {
- if ($myconfig{acs} !~ /Production--Production/) {
- $i = 1;
- $button{'Production--Add Stores Card'}{code} = qq|<button class="submit" type="submit" name="action" value="add_stores_card">|.$locale->text('Add Stores Card').qq|</button> |;
- $button{'Production--Add Stores Card'}{order} = $i++;
- }
- }
-
- for (split /;/, $myconfig{acs}) { delete $button{$_} }
-
- print qq|
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<br>
-<form method=post action=$form->{script}>
-|;
-
- $form->hide_form(qw(callback path login sessionid project));
-
- foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
- print $item->{code};
- }
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
-
-sub continue { &{ $form->{nextsub} } };
-
-sub add_time_card {
-
- $form->{type} = "timecard";
- &add;
-
-}
-
-
-sub add_stores_card {
-
- $form->{type} = "storescard";
- &add;
-
-}
-
-
-sub print_options {
-
- if ($form->{selectlanguage}) {
- $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
- $form->{"selectlanguage"} =~ s/ selected//;
- $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
- $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
- <input type=hidden name=selectlanguage value="|.
- $form->escape($form->{selectlanguage},1).qq|">|;
- }
-
- $form->{selectformname} = $form->unescape($form->{selectformname});
- $form->{selectformname} =~ s/ selected//;
- $form->{selectformname} =~ s/(<option value="\Q$form->{formname}\E")/$1 selected/;
-
- $type = qq|<select name=formname>$form->{selectformname}</select>
- <input type=hidden name=selectformname value="|.$form->escape($form->{selectformname},1).qq|">|;
-
- $media = qq|<select name=media>
- <option value="screen">|.$locale->text('Screen');
-
- $form->{selectformat} = qq|<option value="html">html\n|;
-
- if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
- for (sort keys %{LedgerSMB::Sysconfig::printer}) { $media .= qq|
- <option value="$_">$_| }
- }
-
- if (${LedgerSMB::Sysconfig::latex}) {
- $media .= qq|
- <option value="queue">|.$locale->text('Queue');
-
- $form->{selectformat} .= qq|
- <option value="postscript">|.$locale->text('Postscript').qq|
- <option value="pdf">|.$locale->text('PDF');
- }
-
- $format = qq|<select name=format>$form->{selectformat}</select>|;
- $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
- $format .= qq|
- <input type=hidden name=selectformat value="|.$form->escape($form->{selectformat},1).qq|">|;
- $media .= qq|</select>|;
- $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
-
- print qq|
- <table width=100%>
- <tr>
- <td>$type</td>
- <td>$lang</td>
- <td>$format</td>
- <td>$media</td>
- <td align=right width=90%>
- |;
-
- if ($form->{printed} =~ /$form->{formname}/) {
- print $locale->text('Printed').qq|<br>|;
- }
-
- if ($form->{queued} =~ /$form->{formname}/) {
- print $locale->text('Queued');
- }
-
- print qq|
- </td>
- </tr>
- </table>
-|;
-
-}
-
-
-sub print {
-
- if ($form->{media} !~ /screen/) {
- $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
- $old_form = new Form;
- for (keys %$form) { $old_form->{$_} = $form->{$_} }
- }
-
- &{ "print_$form->{formname}" }($old_form);
-
-}
-
-
-sub print_timecard {
- my ($old_form) = @_;
-
- $display_form = ($form->{display_form}) ? $form->{display_form} : "update";
-
- $form->{description} =~ s/^\s+//g;
-
- for (qw(partnumber projectnumber)) { $form->{$_} =~ s/--.*// }
-
- @a = qw(hour min sec);
- foreach $item (qw(in out)) {
- for (@a) { $form->{"$item$_"} = substr(qq|00$form->{"$item$_"}|, -2) }
- $form->{"checked$item"} = qq|$form->{"${item}hour"}:$form->{"${item}min"}:$form->{"${item}sec"}|;
- }
-
- @a = ();
- for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
- $form->{address} =~ s/\\n/\n/g;
-
- push @a, qw(partnumber description projectnumber projectdescription);
- push @a, qw(company address tel fax businessnumber username useremail);
-
- $form->format_string(@a);
-
- $form->{total} = $form->format_amount(\%myconfig, $form->parse_amount(\%myconfig, $form->{qty}) * $form->parse_amount(\%myconfig, $form->{sellprice}), 2);
-
-
- ($form->{employee}, $form->{employee_id}) = split /--/, $form->{employee};
-
- $form->{templates} = "$myconfig{templates}";
- $form->{IN} = "$form->{formname}.html";
-
- if ($form->{format} =~ /(postscript|pdf)/) {
- $form->{IN} =~ s/html$/tex/;
- }
-
- if ($form->{media} !~ /(screen|queue)/) {
- $form->{OUT} = "| ${LedgerSMB::Sysconfig::printer}{$form->{media}}";
-
- if ($form->{printed} !~ /$form->{formname}/) {
- $form->{printed} .= " $form->{formname}";
- $form->{printed} =~ s/^ //;
-
- $form->update_status(\%myconfig);
- }
-
- %audittrail = ( tablename => jcitems,
- reference => $form->{id},
- formname => $form->{formname},
- action => 'printed',
- id => $form->{id} );
-
- %status = ();
- for (qw(printed queued audittrail)) { $status{$_} = $form->{$_} }
-
- $status{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
-
- }
-
- if ($form->{media} eq 'queue') {
- %queued = split / /, $form->{queued};
-
- if ($filename = $queued{$form->{formname}}) {
- $form->{queued} =~ s/$form->{formname} $filename//;
- unlink "${LedgerSMB::Sysconfig::spool}/$filename";
- $filename =~ s/\..*$//g;
- } else {
- $filename = time;
- $filename .= $$;
- }
-
- $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
- $form->{OUT} = ">${LedgerSMB::Sysconfig::spool}/$filename";
-
- $form->{queued} = "$form->{formname} $filename";
- $form->update_status(\%myconfig);
-
- %audittrail = ( tablename => jcitems,
- reference => $form->{id},
- formname => $form->{formname},
- action => 'queued',
- id => $form->{id} );
-
- %status = ();
- for (qw(printed queued audittrail)) { $status{$_} = $form->{$_} }
-
- $status{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
- }
-
- $form->parse_template(\%myconfig, ${LedgerSMB::Sysconfig::userspath});
-
- if (defined %$old_form) {
-
- for (keys %$old_form) { $form->{$_} = $old_form->{$_} }
- for (qw(printed queued audittrail)) { $form->{$_} = $status{$_} }
-
- &{ "$display_form" };
-
- }
-
-}
-
-
+#=====================================================================
+# LedgerSMB Small Medium Business Accounting
+# http://www.ledgersmb.org/
+#
+
+# Copyright (C) 2006
+# This work contains copyrighted information from a number of sources all used
+# with permission.
+#
+# This file contains source code included with or based on SQL-Ledger which
+# is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
+# under the GNU General Public License version 2 or, at your option, any later
+# version. For a full list including contact information of contributors,
+# maintainers, and copyright holders, see the CONTRIBUTORS file.
+#
+# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
+# Copyright (c) 2005
+#
+# Author: DWS Systems Inc.
+# Web: http://www.sql-ledger.org
+#
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#======================================================================
+#
+# Job Costing module
+#
+#======================================================================
+
+use LedgerSMB::JC;
+
+1;
+# end of main
+
+
+
+sub add {
+
+ if ($form->{type} eq 'timecard') {
+ $form->{title} = $locale->text('Add Time Card');
+ }
+ if ($form->{type} eq 'storescard') {
+ $form->{title} = $locale->text('Add Stores Card');
+ }
+
+ $form->{callback} = "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&project=$form->{project}" unless $form->{callback};
+
+ &{ "prepare_$form->{type}" };
+
+ $form->{orphaned} = 1;
+ &display_form;
+
+}
+
+
+sub edit {
+
+ if ($form->{type} eq 'timecard') {
+ $form->{title} = $locale->text('Edit Time Card');
+ }
+ if ($form->{type} eq 'storescard') {
+ $form->{title} = $locale->text('Add Stores Card');
+ }
+
+ &{ "prepare_$form->{type}" };
+
+ &display_form;
+
+}
+
+
+sub jcitems_links {
+
+ if (@{ $form->{all_project} }) {
+ $form->{selectprojectnumber} = "<option>\n";
+ foreach $ref (@{ $form->{all_project} }) {
+ $form->{selectprojectnumber} .= qq|<option value="$ref->{projectnumber}--$ref->{id}">$ref->{projectnumber}\n|;
+ if ($form->{projectnumber} eq "$ref->{projectnumber}--$ref->{id}") {
+ $form->{projectdescription} = $ref->{description};
+ }
+ }
+ } else {
+ if ($form->{project} eq 'job') {
+ $form->error($locale->text('No open Jobs!'));
+ } else {
+ $form->error($locale->text('No open Projects!'));
+ }
+ }
+
+ if (@{ $form->{all_parts} }) {
+ $form->{selectpartnumber} = "<option>\n";
+ foreach $ref (@{ $form->{all_parts} }) {
+ $form->{selectpartnumber} .= qq|<option value="$ref->{partnumber}--$ref->{id}">$ref->{partnumber}\n|;
+ if ($form->{partnumber} eq "$ref->{partnumber}--$ref->{id}") {
+ if ($form->{partnumber} ne $form->{oldpartnumber}) {
+ for (qw(description unit sellprice pricematrix)) { $form->{$_} = $ref->{$_} }
+ }
+ }
+ }
+ } else {
+ if ($form->{type} eq 'timecard') {
+ if ($form->{project} eq 'job') {
+ $form->error($locale->text('No Labor codes on file!'));
+ } else {
+ $form->error($locale->text('No Services on file!'));
+ }
+ } else {
+ $form->error($locale->text('No Parts on file!'));
+ }
+ }
+
+ # employees
+ if (@{ $form->{all_employee} }) {
+ $form->{selectemployee} = "<option>\n";
+ for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
+ } else {
+ $form->error($locale->text('No Employees on file!'));
+ }
+
+}
+
+
+sub search {
+
+ # accounting years
+ $form->all_years(\%myconfig);
+
+ if (@{ $form->{all_years} }) {
+ $form->{selectaccountingyear} = "<option>\n";
+ for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
+
+ $form->{selectaccountingmonth} = "<option>\n";
+ for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
+
+ $selectfrom = qq|
+ <tr>
+ <th align=right>|.$locale->text('Period').qq|</th>
+ <td colspan=3>
+ <select name=month>$form->{selectaccountingmonth}</select>
+ <select name=year>$form->{selectaccountingyear}</select>
+ <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
+ <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
+ <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
+ <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
+ </td>
+ </tr>
+|;
+ }
+
+ $fromto = qq|
+ <tr>
+ <th align=right nowrap>|.$locale->text('Startdate').qq|</th>
+ <td>|.$locale->text('From').qq| <input name=startdatefrom size=11 title="$myconfig{dateformat}">
+ |.$locale->text('To').qq| <input name=startdateto size=11 title="$myconfig{dateformat}"></td>
+ </tr>
+ $selectfrom
+|;
+
+
+ if ($form->{type} eq 'timecard') {
+ $form->{title} = $locale->text('Time Cards');
+ JC->jcitems_links(\%myconfig, \%$form);
+ }
+ if ($form->{type} eq 'storescard') {
+ $form->{title} = $locale->text('Stores Cards');
+ JC->jcitems_links(\%myconfig, \%$form);
+ }
+
+ if (@{ $form->{all_project} }) {
+ $form->{selectprojectnumber} = "<option>\n";
+ for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
+ }
+
+ if (@{ $form->{all_parts} }) {
+ $form->{selectpartnumber} = "<option>\n";
+ foreach $ref (@{ $form->{all_parts} }) {
+ $form->{selectpartnumber} .= qq|<option value="$ref->{partnumber}--$ref->{id}">$ref->{partnumber}\n|;
+ }
+ }
+
+ if ($form->{project} eq 'job') {
+ $joblabel = $locale->text('Job Number');
+ $laborlabel = $locale->text('Labor Code');
+ } elsif ($form->{project} eq 'project') {
+ $joblabel = $locale->text('Project Number');
+ $laborlabel = $locale->text('Service Code');
+ } else {
+ $joblabel = $locale->text('Project/Job Number');
+ $laborlabel = $locale->text('Service/Labor Code');
+ }
+
+ if ($form->{selectprojectnumber}) {
+ $jobnumber = qq|
+ <tr>
+ <th align=right nowrap>$joblabel</th>
+ <td colspan=3><select name=projectnumber>$form->{selectprojectnumber}</select></td>
+ </tr>
+|;
+ }
+
+
+ if ($form->{type} eq 'timecard') {
+ # employees
+ if (@{ $form->{all_employee} }) {
+ $form->{selectemployee} = "<option>\n";
+ for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
+ } else {
+ $form->error($locale->text('No Employees on file!'));
+ }
+
+ if ($form->{selectpartnumber}) {
+ $partnumber = qq|
+ <tr>
+ <th align=right nowrap>$laborlabel</th>
+ <td colspan=3><select name=partnumber>$form->{selectpartnumber}</select></td>
+ </tr>
+|;
+ }
+
+ $employee = qq|
+ <tr>
+ <th align=right nowrap>|.$locale->text('Employee').qq|</th>
+ <td colspan=3><select name=employee>$form->{selectemployee}</select></td>
+ </tr>
+|;
+
+ $l_time = qq|<td nowrap><input name=l_time class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Time').qq|</td>|;
+
+ }
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr valign=top>
+ <td>
+ <table>
+ $jobnumber
+ $partnumber
+ $employee
+ $fromto
+
+ <tr>
+ <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
+ <td>
+ <table>
+ <tr>
+ <td nowrap><input name=open class=checkbox type=checkbox value=Y checked> |.$locale->text('Open').qq|</td>
+ <td nowrap><input name=closed class=checkbox type=checkbox value=Y> |.$locale->text('Closed').qq|</td>
+ </tr>
+ <tr>
+ $l_time
+ <td nowrap><input name=l_allocated class=checkbox type=checkbox value=Y> |.$locale->text('Allocated').qq|</td>
+ </tr>
+ <tr>
+ <td><input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+<input type=hidden name=nextsub value="list_$form->{type}">
+<input type=hidden name=sort value="transdate">
+|;
+
+ $form->hide_form(qw(db path login sessionid project type));
+
+ print qq|
+<br>
+<button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+</form>
+|;
+
+ if ($form->{lynx}) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
+
+</body>
+</html>
+|;
+
+}
+
+
+sub display_form {
+
+ &{ "$form->{type}_header" };
+ &{ "$form->{type}_footer" };
+
+}
+
+
+sub form_header {
+
+ &{ "$form->{type}_header" };
+
+}
+
+
+sub form_footer {
+
+ &{ "form->{type}_footer" };
+
+}
+
+
+sub prepare_timecard {
+
+ $form->{formname} = "timecard";
+ $form->{format} = "postscript" if $myconfig{printer};
+ $form->{media} = $myconfig{printer};
+
+ JC->get_jcitems(\%myconfig, \%$form);
+
+ $form->{selectformname} = qq|<option value="timecard">|.$locale->text('Time Card');
+
+ foreach $item (qw(in out)) {
+ ($form->{"${item}hour"}, $form->{"${item}min"}, $form->{"${item}sec"}) = split /:/, $form->{"checked$item"};
+ for (qw(hour min sec)) {
+ if (($form->{"$item$_"} *= 1) > 0) {
+ $form->{"$item$_"} = substr(qq|0$form->{"$item$_"}|,-2);
+ } else {
+ $form->{"$item$_"} ||= "";
+ }
+ }
+ }
+
+ $form->{checkedin} = $form->{inhour} * 3600 + $form->{inmin} * 60 + $form->{insec};
+ $form->{checkedout} = $form->{outhour} * 3600 + $form->{outmin} * 60 + $form->{outsec};
+
+ if ($form->{checkedin} > $form->{checkedout}) {
+ $form->{checkedout} = 86400 - ($form->{checkedin} - $form->{checkedout});
+ $form->{checkedin} = 0;
+ }
+
+ $form->{clocked} = ($form->{checkedout} - $form->{checkedin}) / 3600;
+ if ($form->{clocked}) {
+ $form->{oldnoncharge} = $form->{clocked} - $form->{qty};
+ }
+ $form->{oldqty} = $form->{qty};
+
+ $form->{noncharge} = $form->format_amount(\%myconfig, $form->{clocked} - $form->{qty}, 4) if $form->{checkedin} != $form->{checkedout};
+ $form->{clocked} = $form->format_amount(\%myconfig, $form->{clocked}, 4);
+
+ $form->{amount} = $form->{sellprice} * $form->{qty};
+ for (qw(sellprice amount)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
+ $form->{qty} = $form->format_amount(\%myconfig, $form->{qty}, 4);
+ $form->{allocated} = $form->format_amount(\%myconfig, $form->{allocated});
+
+ $form->{employee} .= "--$form->{employee_id}";
+ $form->{projectnumber} .= "--$form->{project_id}";
+ $form->{partnumber} .= "--$form->{parts_id}";
+ $form->{oldpartnumber} = $form->{partnumber};
+
+ if (@{ $form->{all_language} }) {
+ $form->{selectlanguage} = "<option>\n";
+ for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
+ }
+
+ &jcitems_links;
+
+ $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
+
+ $form->{readonly} = 1 if $myconfig{acs} =~ /Production--Add Time Card/;
+
+ if ($form->{income_accno_id}) {
+ $form->{locked} = 1 if $form->{production} == $form->{completed};
+ }
+
+}
+
+
+sub timecard_header {
+
+ # set option selected
+ for (qw(employee projectnumber partnumber)) {
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
+ }
+
+ $rows = $form->numtextrows($form->{description}, 50, 8);
+
+ for (qw(transdate checkedin checkedout partnumber)) { $form->{"old$_"} = $form->{$_} }
+ for (qw(partnumber description)) { $form->{$_} = $form->quote($form->{$_}) }
+
+ if ($rows > 1) {
+ $description = qq|<textarea name=description rows=$rows cols=46 wrap=soft>$form->{description}</textarea>|;
+ } else {
+ $description = qq|<input name=description size=48 value="$form->{description}">|;
+ }
+
+ if ($form->{project} eq 'job') {
+
+ $projectlabel = $locale->text('Job Number');
+ $laborlabel = $locale->text('Labor Code');
+ $rate = qq|<input type=hidden name=sellprice value=$form->{sellprice}>|;
+
+ } else {
+
+ if ($form->{project} eq 'project') {
+ $projectlabel = $locale->text('Project Number');
+ $laborlabel = $locale->text('Service Code');
+ } else {
+ $projectlabel = $locale->text('Project/Job Number');
+ $laborlabel = $locale->text('Service/Labor Code');
+ }
+
+ if ($myconfig{role} ne 'user') {
+ $rate = qq|
+ <tr>
+ <th align=right nowrap>|.$locale->text('Chargeout Rate').qq|</th>
+ <td><input name=sellprice value=$form->{sellprice}></td>
+ <th align=right nowrap>|.$locale->text('Total').qq|</th>
+ <td>$form->{amount}</td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Allocated').qq|</th>
+ <td><input name=allocated value=$form->{allocated}></td>
+ </tr>
+|;
+ } else {
+ $rate = qq|
+ <tr>
+ <th align=right nowrap>|.$locale->text('Chargeout Rate').qq|</th>
+ <td>$form->{sellprice}</td>
+ <th align=right nowrap>|.$locale->text('Total').qq|</th>
+ <td>$form->{amount}</td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Allocated').qq|</th>
+ <td>$form->{allocated}</td>
+ </tr>
+ <input type=hidden name=sellprice value=$form->{sellprice}>
+ <input type=hidden name=allocated value=$form->{allocated}>
+|;
+ }
+ }
+
+ if ($myconfig{role} eq 'user') {
+ $charge = qq|<input type=hidden name=qty value=$form->{qty}>$form->{qty}|;
+ } else {
+ $charge = qq|<input name=qty value=$form->{qty}>|;
+ }
+
+ if (($rows = $form->numtextrows($form->{notes}, 40, 6)) < 2) {
+ $rows = 2;
+ }
+
+ $notes = qq|<tr>
+ <th align=right>|.$locale->text('Notes').qq|</th>
+ <td colspan=3><textarea name="notes" rows=$rows cols=46 wrap=soft>$form->{notes}</textarea>
+ </td>
+ </tr>
+|;
+
+##################
+ ($null, $form->{oldproject_id}) = split /--/, $form->{projectnumber};
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action="$form->{script}">
+|;
+
+ $form->hide_form(qw(id type media format printed queued title closedto locked oldtransdate oldcheckedin oldcheckedout oldpartnumber project oldqty oldnoncharge pricematrix oldproject_id));
+
+ print qq|
+<table width=100%>
+ <tr class=listtop>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>
+ <table>
+ <tr>
+ <td>
+ <table>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Employee').qq|</th>
+ <td><select name=employee>$form->{selectemployee}</select></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>$projectlabel</th>
+ <td><select name=projectnumber>$form->{selectprojectnumber}</select>
+ </td>
+ <td></td>
+ <td>$form->{projectdescription}</td>
+ <input type=hidden name=projectdescription value="|.$form->quote($form->{projectdescription}).qq|">
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Date worked').qq|</th>
+ <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>$laborlabel</th>
+ <td><select name=partnumber>$form->{selectpartnumber}</select></td>
+ </tr>
+ <tr valign=top>
+ <th align=right nowrap>|.$locale->text('Description').qq|</th>
+ <td colspan=3>$description</td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Time In').qq|</th>
+ <td>
+ <table>
+ <tr>
+ <td><input name=inhour title="hh" size=3 maxlength=2 value=$form->{inhour}></td>
+ <td><input name=inmin title="mm" size=3 maxlength=2 value=$form->{inmin}></td>
+ <td><input name=insec title="ss" size=3 maxlength=2 value=$form->{insec}></td>
+ </tr>
+ </table>
+ </td>
+ <th align=right nowrap>|.$locale->text('Time Out').qq|</th>
+ <td>
+ <table>
+ <tr>
+ <td><input name=outhour title="hh" size=3 maxlength=2 value=$form->{outhour}></td>
+ <td><input name=outmin title="mm" size=3 maxlength=2 value=$form->{outmin}></td>
+ <td><input name=outsec title="ss" size=3 maxlength=2 value=$form->{outsec}></td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Clocked').qq|</th>
+ <td>$form->{clocked}</td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Non-chargeable').qq|</th>
+ <td><input name=noncharge value=$form->{noncharge}></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Chargeable').qq|</th>
+ <td>$charge</td>
+ </tr>
+ $rate
+ $notes
+ </table>
+ </td>
+ </tr>
+
+|;
+
+}
+
+
+sub timecard_footer {
+
+ print qq|
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+ <tr>
+ <td>
+|;
+
+ &print_options;
+
+ print qq|
+ </td>
+ </tr>
+</table>
+<br>
+|;
+
+ $transdate = $form->datetonum(\%myconfig, $form->{transdate});
+ $closedto = $form->datetonum(\%myconfig, $form->{closedto});
+
+ if (! $form->{readonly}) {
+
+# type=submit $locale->text('Update')
+# type=submit $locale->text('Print')
+# type=submit $locale->text('Save')
+# type=submit $locale->text('Print and Save')
+# type=submit $locale->text('Save as new')
+# type=submit $locale->text('Print and Save as new')
+# type=submit $locale->text('Delete')
+
+ %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
+ 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
+ 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
+ 'print_and_save' => { ndx => 6, key => 'R', value => $locale->text('Print and Save') },
+ 'save_as_new' => { ndx => 7, key => 'N', value => $locale->text('Save as new') },
+ 'print_and_save_as_new' => { ndx => 8, key => 'W', value => $locale->text('Print and Save as new') },
+
+ 'delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') },
+ );
+
+ %a = ();
+
+ if ($form->{id}) {
+
+ if (!$form->{locked}) {
+ for ('update', 'print', 'save', 'save_as_new') { $a{$_} = 1 }
+
+ if (${LedgerSMB::Sysconfig::latex}) {
+ for ('print_and_save', 'print_and_save_as_new') { $a{$_} = 1 }
+ }
+
+ if ($form->{orphaned}) {
+ $a{'delete'} = 1;
+ }
+
+ }
+
+ } else {
+
+ if ($transdate > $closedto) {
+
+ for ('update', 'print', 'save') { $a{$_} = 1 }
+
+ if (${LedgerSMB::Sysconfig::latex}) {
+ $a{'print_and_save'} = 1;
+ }
+
+ }
+ }
+ }
+
+ for (keys %button) { delete $button{$_} if ! $a{$_} }
+ for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
+
+ if ($form->{lynx}) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ $form->hide_form(qw(callback path login sessionid));
+
+ print qq|
+
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
+sub prepare_storescard {
+
+ $form->{formname} = "storescard";
+ $form->{format} = "postscript" if $myconfig{printer};
+ $form->{media} = $myconfig{printer};
+
+ JC->get_jcitems(\%myconfig, \%$form);
+
+ $form->{selectformname} = qq|<option value="storescard">|.$locale->text('Stores Card');
+
+ $form->{amount} = $form->{sellprice} * $form->{qty};
+ for (qw(sellprice amount)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
+ $form->{qty} = $form->format_amount(\%myconfig, $form->{qty}, 4);
+
+ $form->{employee} .= "--$form->{employee_id}";
+ $form->{projectnumber} .= "--$form->{project_id}";
+ $form->{partnumber} .= "--$form->{parts_id}";
+ $form->{oldpartnumber} = $form->{partnumber};
+
+ if (@{ $form->{all_language} }) {
+ $form->{selectlanguage} = "<option>\n";
+ for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
+ }
+
+ &jcitems_links;
+
+ $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
+
+ $form->{readonly} = 1 if $myconfig{acs} =~ /Production--Add Time Card/;
+
+ if ($form->{income_accno_id}) {
+ $form->{locked} = 1 if $form->{production} == $form->{completed};
+ }
+
+}
+
+
+sub storescard_header {
+
+ # set option selected
+ for (qw(employee projectnumber partnumber)) {
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
+ }
+
+ $rows = $form->numtextrows($form->{description}, 50, 8);
+
+ for (qw(transdate partnumber)) { $form->{"old$_"} = $form->{$_} }
+ for (qw(partnumber description)) { $form->{$_} = $form->quote($form->{$_}) }
+
+ if ($rows > 1) {
+ $description = qq|<textarea name=description rows=$rows cols=46 wrap=soft>$form->{description}</textarea>|;
+ } else {
+ $description = qq|<input name=description size=48 value="$form->{description}">|;
+ }
+
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action="$form->{script}">
+|;
+
+ $form->hide_form(qw(id type media format printed queued title closedto locked oldtransdate oldpartnumber project));
+
+ print qq|
+<table width=100%>
+ <tr class=listtop>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>
+ <table>
+ <tr>
+ <td>
+ <table>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Job Number').qq|</th>
+ <td><select name=projectnumber>$form->{selectprojectnumber}</select>
+ </td>
+ <td>$form->{projectdescription}</td>
+ <input type=hidden name=projectdescription value="|.$form->quote($form->{projectdescription}).qq|">
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Date').qq|</th>
+ <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Part Number').qq|</th>
+ <td><select name=partnumber>$form->{selectpartnumber}</td>
+ </tr>
+ <tr valign=top>
+ <th align=right nowrap>|.$locale->text('Description').qq|</th>
+ <td>$description</td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Qty').qq|</th>
+ <td><input name=qty size=6 value=$form->{qty}>
+ <b>|.$locale->text('Cost').qq|</b>
+ <input name=sellprice size=10 value=$form->{sellprice}></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Total').qq|</th>
+ <td>$form->{amount}</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+
+|;
+
+}
+
+
+sub storescard_footer {
+
+ print qq|
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+ <tr>
+ <td>
+|;
+
+ &print_options;
+
+ print qq|
+ </td>
+ </tr>
+</table>
+<br>
+|;
+
+ $transdate = $form->datetonum(\%myconfig, $form->{transdate});
+ $closedto = $form->datetonum(\%myconfig, $form->{closedto});
+
+# type=submit $locale->text('Update')
+# type=submit $locale->text('Print')
+# type=submit $locale->text('Save')
+# type=submit $locale->text('Print and Save')
+# type=submit $locale->text('Save as new')
+# type=submit $locale->text('Print and Save as new')
+# type=submit $locale->text('Delete')
+
+
+ if (! $form->{readonly}) {
+
+ %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
+ 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
+ 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
+ 'print_and_save' => { ndx => 6, key => 'R', value => $locale->text('Print and Save') },
+ 'save_as_new' => { ndx => 7, key => 'N', value => $locale->text('Save as new') },
+ 'print_and_save_as_new' => { ndx => 8, key => 'W', value => $locale->text('Print and Save as new') },
+ 'delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') },
+ );
+
+ %a = ();
+
+ if ($form->{id}) {
+
+ if (!$form->{locked}) {
+ for ('update', 'print', 'save', 'save_as_new') { $a{$_} = 1 }
+ if (${LedgerSMB::Sysconfig::latex}) {
+ for ('print_and_save', 'print_and_save_as_new') { $a{$_} = 1 }
+ }
+ if ($form->{orphaned}) {
+ $a{'delete'} = 1;
+ }
+ }
+
+ } else {
+
+ if ($transdate > $closedto) {
+ for ('update', 'print', 'save') { $a{$_} = 1 }
+
+ if (${LedgerSMB::Sysconfig::latex}) {
+ $a{'print_and_save'} = 1;
+ }
+ }
+ }
+
+ for (keys %button) { delete $button{$_} if ! $a{$_} }
+ for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
+
+ }
+
+ if ($form->{lynx}) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ $form->hide_form(qw(callback path login sessionid));
+
+ print qq|
+
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
+
+sub update {
+
+ ($null, $form->{project_id}) = split /--/, $form->{projectnumber};
+
+ # check labor/part
+ JC->jcitems_links(\%myconfig, \%$form);
+
+ &jcitems_links;
+
+ $checkmatrix = 1 if $form->{oldproject_id} != $form->{project_id};
+
+ if ($form->{type} eq 'timecard') {
+
+ # time clocked
+ %hour = ( in => 0, out => 0 );
+ for $t (qw(in out)) {
+ if ($form->{"${t}sec"} > 60) {
+ $form->{"${t}sec"} -= 60;
+ $form->{"${t}min"}++;
+ }
+ if ($form->{"${t}min"} > 60) {
+ $form->{"${t}min"} -= 60;
+ $form->{"${t}hour"}++;
+ }
+ $hour{$t} = $form->{"${t}hour"};
+ }
+
+ $form->{checkedin} = $hour{in} * 3600 + $form->{inmin} * 60 + $form->{insec};
+ $form->{checkedout} = $hour{out} * 3600 + $form->{outmin} * 60 + $form->{outsec};
+
+ if ($form->{checkedin} > $form->{checkedout}) {
+ $form->{checkedout} = 86400 - ($form->{checkedin} - $form->{checkedout});
+ $form->{checkedin} = 0;
+ }
+
+ $form->{clocked} = ($form->{checkedout} - $form->{checkedin}) / 3600;
+
+ for (qw(sellprice qty noncharge allocated)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+
+ $checkmatrix = 1 if $form->{oldqty} != $form->{qty};
+
+ if (($form->{oldcheckedin} != $form->{checkedin}) || ($form->{oldcheckedout} != $form->{checkedout})) {
+ $checkmatrix = 1;
+ $form->{oldqty} = $form->{qty} = $form->{clocked} - $form->{noncharge};
+ $form->{oldnoncharge} = $form->{noncharge};
+ }
+
+ if (($form->{qty} != $form->{oldqty}) && $form->{clocked}) {
+ $form->{oldnoncharge} = $form->{noncharge} = $form->{clocked} - $form->{qty};
+ $checkmatrix = 1;
+ }
+
+ if (($form->{oldnoncharge} != $form->{noncharge}) && $form->{clocked}) {
+ $form->{oldqty} = $form->{qty} = $form->{clocked} - $form->{noncharge};
+ $checkmatrix = 1;
+ }
+
+ if ($checkmatrix) {
+ @a = split / /, $form->{pricematrix};
+ if (scalar @a > 2) {
+ for (@a) {
+ ($q, $p) = split /:/, $_;
+ if (($p * 1) && ($form->{qty} >= ($q * 1))) {
+ $form->{sellprice} = $p;
+ }
+ }
+ }
+ }
+
+ $form->{amount} = $form->{sellprice} * $form->{qty};
+
+ $form->{clocked} = $form->format_amount(\%myconfig, $form->{clocked}, 4);
+ for (qw(sellprice amount)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
+ for (qw(qty noncharge)) {
+ $form->{"old$_"} = $form->{$_};
+ $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 4);
+ }
+
+ } else {
+
+ for (qw(sellprice qty allocated)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+
+ if ($form->{oldqty} != $form->{qty}) {
+ @a = split / /, $form->{pricematrix};
+ if (scalar @a > 2) {
+ for (@a) {
+ ($q, $p) = split /:/, $_;
+ if (($p * 1) && ($form->{qty} >= ($q * 1))) {
+ $form->{sellprice} = $p;
+ }
+ }
+ }
+ }
+
+ $form->{amount} = $form->{sellprice} * $form->{qty};
+ for (qw(sellprice amount)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
+
+ }
+
+ $form->{allocated} = $form->format_amount(\%myconfig, $form->{allocated});
+
+ &display_form;
+
+}
+
+
+sub save {
+
+ $form->isblank("transdate", $locale->text('Date missing!'));
+
+ if ($form->{project} eq 'project') {
+ $form->isblank("projectnumber", $locale->text('Project Number missing!'));
+ $form->isblank("partnumber", $locale->text('Service Code missing!'));
+ } else {
+ $form->isblank("projectnumber", $locale->text('Job Number missing!'));
+ $form->isblank("partnumber", $locale->text('Labor Code missing!'));
+ }
+
+ $closedto = $form->datetonum(\%myconfig, $form->{closedto});
+ $transdate = $form->datetonum(\%myconfig, $form->{transdate});
+
+ $msg = ($form->{type} eq 'timecard') ? $locale->text('Cannot save time card for a closed period!') : $locale->text('Cannot save stores card for a closed period!');
+ $form->error($msg) if ($transdate <= $closedto);
+
+ if (! $form->{resave}) {
+ if ($form->{id}) {
+ &resave;
+ exit;
+ }
+ }
+
+
+ $rc = JC->save(\%myconfig, \%$form);
+
+ if ($form->{type} eq 'timecard') {
+ $form->error($locale->text('Cannot change time card for a completed job!')) if ($rc == -1);
+ $form->error($locale->text('Cannot add time card for a completed job!')) if ($rc == -2);
+
+ if ($rc) {
+ $form->redirect($locale->text('Time Card saved!'));
+ } else {
+ $form->error($locale->text('Cannot save time card!'));
+ }
+
+ } else {
+ $form->error($locale->text('Cannot change stores card for a completed job!')) if ($rc == -1);
+ $form->error($locale->text('Cannot add stores card for a completed job!')) if ($rc == -2);
+
+ if ($rc) {
+ $form->redirect($locale->text('Stores Card saved!'));
+ } else {
+ $form->error($locale->text('Cannot save stores card!'));
+ }
+ }
+
+}
+
+
+sub save_as_new {
+
+ delete $form->{id};
+ &save;
+
+}
+
+
+sub print_and_save_as_new {
+
+ delete $form->{id};
+ &print_and_save;
+
+}
+
+
+sub resave {
+
+ if ($form->{print_and_save}) {
+ $form->{nextsub} = "print_and_save";
+ $msg = $locale->text('You are printing and saving an existing transaction!');
+ } else {
+ $form->{nextsub} = "save";
+ $msg = $locale->text('You are saving an existing transaction!');
+ }
+
+ $form->{resave} = 1;
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+
+|;
+
+ delete $form->{action};
+
+ $form->hide_form;
+
+ print qq|
+<h2 class=confirm>|.$locale->text('Warning!').qq|</h2>
+
+<h4>$msg</h4>
+
+<button name="action" class="submit" type="submit" value="continue">|.$locale->text('Continue').qq|</button>
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
+sub print_and_save {
+
+ $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
+ $form->error($locale->text('Select a Printer!')) if $form->{media} eq 'screen';
+
+ if (! $form->{resave}) {
+ if ($form->{id}) {
+ $form->{print_and_save} = 1;
+ &resave;
+ exit;
+ }
+ }
+
+ $old_form = new Form;
+ $form->{display_form} = "save";
+ for (keys %$form) { $old_form->{$_} = $form->{$_} }
+
+ &{ "print_$form->{formname}" }($old_form);
+
+}
+
+
+sub delete_timecard {
+
+ $form->header;
+
+ $employee = $form->{employee};
+ $employee =~ s/--.*//g;
+ $projectnumber = $form->{projectnumber};
+ $projectnumber =~ s/--.*//g;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+|;
+
+ delete $form->{action};
+
+ $form->hide_form;
+
+ print qq|
+<h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
+
+<h4>|.$locale->text('Are you sure you want to delete time card for').qq|
+<p>$form->{transdate}
+<br>$employee
+<br>$projectnumber
+</h4>
+
+<p>
+<button name="action" class="submit" type="submit" value="yes">|.$locale->text('Yes').qq|</button>
+</form>
+|;
+
+}
+
+
+sub delete { &{ "delete_$form->{type}" } };
+sub yes { &{ "yes_delete_$form->{type}" } };
+
+
+sub yes_delete_timecard {
+
+ if (JC->delete_timecard(\%myconfig, \%$form)) {
+ $form->redirect($locale->text('Time Card deleted!'));
+ } else {
+ $form->error($locale->text('Cannot delete time card!'));
+ }
+
+}
+
+
+sub list_timecard {
+
+ $form->{type} = "timecard";
+
+ JC->jcitems(\%myconfig, \%$form);
+
+ $form->{title} = $locale->text('Time Cards');
+
+ @a = qw(type direction oldsort path login sessionid project l_subtotal open closed l_time l_allocated);
+ $href = "$form->{script}?action=list_timecard";
+ for (@a) { $href .= "&$_=$form->{$_}" }
+
+ $href .= "&title=".$form->escape($form->{title});
+
+ $form->sort_order();
+
+ $callback = "$form->{script}?action=list_timecard";
+ for (@a) { $callback .= "&$_=$form->{$_}" }
+
+ $callback .= "&title=".$form->escape($form->{title},1);
+
+ @column_index = (qw(transdate projectnumber projectdescription id partnumber description));
+
+ push @column_index, (qw(allocated)) if $form->{l_allocated};
+ push @column_index, (qw(1 2 3 4 5 6 7));
+
+ @column_index = $form->sort_columns(@column_index);
+
+ if ($form->{project} eq 'job') {
+ $joblabel = $locale->text('Job Number');
+ $laborlabel = $locale->text('Labor Code');
+ $desclabel = $locale->text('Job Name');
+ } elsif ($form->{project} eq 'project') {
+ $joblabel = $locale->text('Project Number');
+ $laborlabel = $locale->text('Service Code');
+ $desclabel = $locale->text('Project Name');
+ } else {
+ $joblabel = $locale->text('Project/Job Number');
+ $laborlabel = $locale->text('Service/Labor Code');
+ $desclabel = $locale->text('Project/Job Name');
+ }
+
+ if ($form->{projectnumber}) {
+ $callback .= "&projectnumber=".$form->escape($form->{projectnumber},1);
+ $href .= "&projectnumber=".$form->escape($form->{projectnumber});
+ ($var) = split /--/, $form->{projectnumber};
+ $option .= "\n<br>" if ($option);
+ $option .= "$joblabel : $var";
+ @column_index = grep !/projectnumber/, @column_index;
+ }
+ if ($form->{partnumber}) {
+ $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
+ $href .= "&partnumber=".$form->escape($form->{partnumber});
+ ($var) = split /--/, $form->{partnumber};
+ $option .= "\n<br>" if ($option);
+ $option .= "$laborlabel : $var";
+ @column_index = grep !/partnumber/, @column_index;
+ }
+ if ($form->{employee}) {
+ $callback .= "&employee=".$form->escape($form->{employee},1);
+ $href .= "&employee=".$form->escape($form->{employee});
+ }
+
+ if ($form->{startdatefrom}) {
+ $callback .= "&startdatefrom=$form->{startdatefrom}";
+ $href .= "&startdatefrom=$form->{startdatefrom}";
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{startdatefrom}, 1);
+ }
+ if ($form->{startdateto}) {
+ $callback .= "&startdateto=$form->{startdateto}";
+ $href .= "&startdateto=$form->{startdateto}";
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{startdateto}, 1);
+ }
+ if ($form->{open}) {
+ $callback .= "&open=$form->{open}";
+ $href .= "&open=$form->{open}";
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Open');
+ }
+ if ($form->{closed}) {
+ $callback .= "&closed=$form->{closed}";
+ $href .= "&closed=$form->{closed}";
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Closed');
+ }
+
+ %weekday = ( 1 => $locale->text('Sunday'),
+ 2 => $locale->text('Monday'),
+ 3 => $locale->text('Tuesday'),
+ 4 => $locale->text('Wednesday'),
+ 5 => $locale->text('Thursday'),
+ 6 => $locale->text('Friday'),
+ 7 => $locale->text('Saturday'),
+ );
+
+ for (keys %weekday) { $column_header{$_} = "<th class=listheading width=25>".substr($weekday{$_},0,3)."</th>" }
+
+ $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>";
+ $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
+ $column_header{description} = "<th><a class=listheading href=$href&sort=description>" . $locale->text('Description') . "</th>";
+ $column_header{projectnumber} = "<th><a class=listheading href=$href&sort=projectnumber>$joblabel</a></th>";
+ $column_header{partnumber} = "<th><a class=listheading href=$href&sort=partnumber>$laborlabel</a></th>";
+ $column_header{projectdescription} = "<th><a class=listheading href=$href&sort=projectdescription>$desclabel</a></th>";
+ $column_header{allocated} = "<th class=listheading></th>";
+
+
+ $form->header;
+
+ if (@{ $form->{transactions} }) {
+ $sameitem = $form->{transactions}->[0]->{$form->{sort}};
+ $sameemployeenumber = $form->{transactions}->[0]->{employeenumber};
+ $employee = $form->{transactions}->[0]->{employee};
+ $sameweek = $form->{transactions}->[0]->{workweek};
+ }
+
+ print qq|
+<body>
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>$option</td>
+ </tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr>
+ <th colspan=2 align=left>
+ $employee
+ </th>
+ <th align=left>
+ $sameemployeenumber
+ </th>
+ <tr class=listheading>
+|;
+
+ for (@column_index) { print "\n$column_header{$_}" }
+
+ print qq|
+ </tr>
+|;
+
+ # add sort and escape callback, this one we use for the add sub
+ $form->{callback} = $callback .= "&sort=$form->{sort}";
+
+ # escape callback for href
+ $callback = $form->escape($callback);
+
+ # flip direction
+ $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
+ $href =~ s/&direction=(\w+)&/&direction=$direction&/;
+
+ %total = ();
+
+ foreach $ref (@{ $form->{transactions} }) {
+
+ if ($sameemployeenumber ne $ref->{employeenumber}) {
+ $sameemployeenumber = $ref->{employeenumber};
+ $sameweek = $ref->{workweek};
+
+ if ($form->{l_subtotal}) {
+ print qq|
+ <tr class=listsubtotal>
+|;
+
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $weektotal = 0;
+ for (keys %weekday) {
+ $column_data{$_} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotal{$_}, "", "&nbsp;")."</th>";
+ $weektotal += $subtotal{$_};
+ $subtotal{$_} = 0;
+ }
+
+ $column_data{$form->{sort}} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $weektotal, "", "&nbsp;")."</th>";
+
+ for (@column_index) { print "\n$column_data{$_}" }
+ }
+
+ # print total
+ print qq|
+ <tr class=listtotal>
+|;
+
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $total = 0;
+ for (keys %weekday) {
+ $column_data{$_} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $total{$_}, "", "&nbsp;")."</th>";
+ $total += $total{$_};
+ $total{$_} = 0;
+ }
+
+ $column_data{$form->{sort}} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $total, "", "&nbsp;")."</th>";
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+
+ print qq|
+ <tr height=30 valign=bottom>
+ <th colspan=2 align=left>
+ $ref->{employee}
+ </th>
+ <th align=left>
+ $ref->{employeenumber}
+ </th>
+ <tr class=listheading>
+|;
+
+ for (@column_index) { print "\n$column_header{$_}" }
+
+ print qq|
+ </tr>
+|;
+
+ }
+
+ if ($form->{l_subtotal}) {
+ if ($ref->{workweek} != $sameweek) {
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+ $weektotal = 0;
+ for (keys %weekday) {
+ $column_data{$_} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotal{$_}, "", "&nbsp;")."</th>";
+ $weektotal += $subtotal{$_};
+ $subtotal{$_} = 0
+ }
+ $column_data{$form->{sort}} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $weektotal, "", "&nbsp;")."</th>";
+ $sameweek = $ref->{workweek};
+
+ print qq|
+ <tr class=listsubtotal>
+|;
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+ </tr>
+|;
+ }
+ }
+
+ for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
+ for (keys %weekday) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{allocated} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{allocated}, "", "&nbsp;")."</td>";
+ $column_data{$ref->{weekday}} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{qty}, "", "&nbsp;");
+
+ if ($form->{l_time}) {
+ $column_data{$ref->{weekday}} .= "<br>$ref->{checkedin}<br>$ref->{checkedout}";
+ }
+ $column_data{$ref->{weekday}} .= "</td>";
+
+ $column_data{id} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&project=$form->{project}&callback=$callback>$ref->{id}</a></td>";
+
+ $subtotal{$ref->{weekday}} += $ref->{qty};
+ $total{$ref->{weekday}} += $ref->{qty};
+
+ $j++; $j %= 2;
+ print qq|
+ <tr class=listrow$j>
+|;
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+ </tr>
+|;
+ }
+
+ # print last subtotal
+ if ($form->{l_subtotal}) {
+ print qq|
+ <tr class=listsubtotal>
+|;
+
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $weektotal = 0;
+ for (keys %weekday) {
+ $column_data{$_} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotal{$_}, "", "&nbsp;")."</th>";
+ $weektotal += $subtotal{$_};
+ }
+
+ $column_data{$form->{sort}} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $weektotal, "", "&nbsp;")."</th>";
+
+ for (@column_index) { print "\n$column_data{$_}" }
+ }
+
+ # print last total
+ print qq|
+ <tr class=listtotal>
+|;
+
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $total = 0;
+ for (keys %weekday) {
+ $column_data{$_} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $total{$_}, "", "&nbsp;")."</th>";
+ $total += $total{$_};
+ $total{$_} = 0;
+ }
+
+ $column_data{$form->{sort}} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $total, "", "&nbsp;")."</th>";
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ if ($form->{project} eq 'job') {
+ if ($myconfig{acs} !~ /Production--Production/) {
+ $i = 1;
+ $button{'Production--Add Time Card'}{code} = qq|<button class="submit" type="submit" name="action" value="add_time_card">|.$locale->text('Add Time Card').qq|</button> |;
+ $button{'Production--Add Time Card'}{order} = $i++;
+ }
+ } elsif ($form->{project} eq 'project') {
+ if ($myconfig{acs} !~ /Projects--Projects/) {
+ $i = 1;
+ $button{'Projects--Add Time Card'}{code} = qq|<button class="submit" type="submit" name="action" value="add_time_card">|.$locale->text('Add Time Card').qq|</button> |;
+ $button{'Projects--Add Time Card'}{order} = $i++;
+ }
+ } else {
+ if ($myconfig{acs} !~ /Time Cards--Time Cards/) {
+ $i = 1;
+ $button{'Time Cards--Add Time Card'}{code} = qq|<button class="submit" type="submit" name="action" value="add_time_card">|.$locale->text('Add Time Card').qq|</button> |;
+ $button{'Time Cards--Add Time Card'}{order} = $i++;
+ }
+ }
+
+ for (split /;/, $myconfig{acs}) { delete $button{$_} }
+
+ print qq|
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+<br>
+<form method=post action=$form->{script}>
+|;
+
+ $form->hide_form(qw(callback path login sessionid project));
+
+ foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
+ print $item->{code};
+ }
+
+ if ($form->{lynx}) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
+sub list_storescard {
+
+ $form->{type} = "storescard";
+
+ JC->jcitems(\%myconfig, \%$form);
+
+ $form->{title} = $locale->text('Stores Cards');
+
+ $href = "$form->{script}?action=list_storescard";
+ for (qw(type direction oldsort path login sessionid project)) { $href .= "&$_=$form->{$_}" }
+
+ $href .= "&title=".$form->escape($form->{title});
+
+ $form->sort_order();
+
+ $callback = "$form->{script}?action=list_storescard";
+ for (qw(type direction oldsort path login sessionid project)) { $callback .= "&$_=$form->{$_}" }
+
+ $callback .= "&title=".$form->escape($form->{title},1);
+
+ @column_index = $form->sort_columns(qw(transdate projectnumber projectdescription id partnumber description qty amount));
+
+
+ if ($form->{projectnumber}) {
+ $callback .= "&projectnumber=".$form->escape($form->{projectnumber},1);
+ $href .= "&projectnumber=".$form->escape($form->{projectnumber});
+ ($var) = split /--/, $form->{projectnumber};
+ $option .= "\n<br>" if ($option);
+ $option .= "$joblabel : $var";
+ @column_index = grep !/projectnumber/, @column_index;
+ }
+ if ($form->{partnumber}) {
+ $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
+ $href .= "&partnumber=".$form->escape($form->{partnumber});
+ ($var) = split /--/, $form->{partnumber};
+ $option .= "\n<br>" if ($option);
+ $option .= "$laborlabel : $var";
+ @column_index = grep !/partnumber/, @column_index;
+ }
+ if ($form->{startdatefrom}) {
+ $callback .= "&startdatefrom=$form->{startdatefrom}";
+ $href .= "&startdatefrom=$form->{startdatefrom}";
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{startdatefrom}, 1);
+ }
+ if ($form->{startdateto}) {
+ $callback .= "&startdateto=$form->{startdateto}";
+ $href .= "&startdateto=$form->{startdateto}";
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{startdateto}, 1);
+ }
+
+ $column_header{id} = "<th><a class=listheading href=$href&sort=id>" . $locale->text('ID') . "</a></th>";
+ $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
+ $column_header{projectnumber} = "<th><a class=listheading href=$href&sort=projectnumber>" . $locale->text('Job Number') . "</a></th>";
+ $column_header{projectdescription} = "<th><a class=listheading href=$href&sort=projectdescription>" . $locale->text('Job Description') . "</a></th>";
+ $column_header{partnumber} = "<th><a class=listheading href=$href&sort=partnumber>" . $locale->text('Part Number') . "</a></th>";
+ $column_header{description} = "<th><a class=listheading href=$href&sort=description>" . $locale->text('Description') . "</a></th>";
+ $column_header{qty} = "<th class=listheading>" . $locale->text('Qty') . "</th>";
+ $column_header{amount} = "<th class=listheading>" . $locale->text('Amount') . "</th>";
+
+
+ $form->header;
+
+ if (@{ $form->{transactions} }) {
+ $sameitem = $form->{transactions}->[0]->{$form->{sort}};
+ }
+
+ print qq|
+<body>
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>$option</td>
+ </tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr class=listheading>
+|;
+
+ for (@column_index) { print "\n$column_header{$_}" }
+
+ print qq|
+ </tr>
+|;
+
+ # add sort and escape callback, this one we use for the add sub
+ $form->{callback} = $callback .= "&sort=$form->{sort}";
+
+ # escape callback for href
+ $callback = $form->escape($callback);
+
+ # flip direction
+ $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
+ $href =~ s/&direction=(\w+)&/&direction=$direction&/;
+
+ $total = 0;
+ foreach $ref (@{ $form->{transactions} }) {
+
+ for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
+ $column_data{qty} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{qty}, "", "&nbsp;")."</td>";
+ $column_data{amount} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{qty} * $ref->{sellprice}, 2)."</td>";
+
+ $column_data{id} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&project=$form->{project}&callback=$callback>$ref->{id}</a></td>";
+
+ $total += ($ref->{qty} * $ref->{sellprice});
+
+ $j++; $j %= 2;
+ print qq|
+ <tr class=listrow$j>
+|;
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+ </tr>
+|;
+ }
+
+ # print total
+ print qq|
+ <tr class=listtotal>
+|;
+
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+ $column_data{amount} = qq|<th align=right>|.$form->format_amount(\%myconfig, $total, 2)."</th";
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ if ($form->{project} eq 'job') {
+ if ($myconfig{acs} !~ /Production--Production/) {
+ $i = 1;
+ $button{'Production--Add Stores Card'}{code} = qq|<button class="submit" type="submit" name="action" value="add_stores_card">|.$locale->text('Add Stores Card').qq|</button> |;
+ $button{'Production--Add Stores Card'}{order} = $i++;
+ }
+ }
+
+ for (split /;/, $myconfig{acs}) { delete $button{$_} }
+
+ print qq|
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+<br>
+<form method=post action=$form->{script}>
+|;
+
+ $form->hide_form(qw(callback path login sessionid project));
+
+ foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
+ print $item->{code};
+ }
+
+ if ($form->{lynx}) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
+
+sub continue { &{ $form->{nextsub} } };
+
+sub add_time_card {
+
+ $form->{type} = "timecard";
+ &add;
+
+}
+
+
+sub add_stores_card {
+
+ $form->{type} = "storescard";
+ &add;
+
+}
+
+
+sub print_options {
+
+ if ($form->{selectlanguage}) {
+ $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
+ $form->{"selectlanguage"} =~ s/ selected//;
+ $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
+ $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
+ <input type=hidden name=selectlanguage value="|.
+ $form->escape($form->{selectlanguage},1).qq|">|;
+ }
+
+ $form->{selectformname} = $form->unescape($form->{selectformname});
+ $form->{selectformname} =~ s/ selected//;
+ $form->{selectformname} =~ s/(<option value="\Q$form->{formname}\E")/$1 selected/;
+
+ $type = qq|<select name=formname>$form->{selectformname}</select>
+ <input type=hidden name=selectformname value="|.$form->escape($form->{selectformname},1).qq|">|;
+
+ $media = qq|<select name=media>
+ <option value="screen">|.$locale->text('Screen');
+
+ $form->{selectformat} = qq|<option value="html">html\n|;
+
+ if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
+ for (sort keys %{LedgerSMB::Sysconfig::printer}) { $media .= qq|
+ <option value="$_">$_| }
+ }
+
+ if (${LedgerSMB::Sysconfig::latex}) {
+ $media .= qq|
+ <option value="queue">|.$locale->text('Queue');
+
+ $form->{selectformat} .= qq|
+ <option value="postscript">|.$locale->text('Postscript').qq|
+ <option value="pdf">|.$locale->text('PDF');
+ }
+
+ $format = qq|<select name=format>$form->{selectformat}</select>|;
+ $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
+ $format .= qq|
+ <input type=hidden name=selectformat value="|.$form->escape($form->{selectformat},1).qq|">|;
+ $media .= qq|</select>|;
+ $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
+
+ print qq|
+ <table width=100%>
+ <tr>
+ <td>$type</td>
+ <td>$lang</td>
+ <td>$format</td>
+ <td>$media</td>
+ <td align=right width=90%>
+ |;
+
+ if ($form->{printed} =~ /$form->{formname}/) {
+ print $locale->text('Printed').qq|<br>|;
+ }
+
+ if ($form->{queued} =~ /$form->{formname}/) {
+ print $locale->text('Queued');
+ }
+
+ print qq|
+ </td>
+ </tr>
+ </table>
+|;
+
+}
+
+
+sub print {
+
+ if ($form->{media} !~ /screen/) {
+ $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
+ $old_form = new Form;
+ for (keys %$form) { $old_form->{$_} = $form->{$_} }
+ }
+
+ &{ "print_$form->{formname}" }($old_form);
+
+}
+
+
+sub print_timecard {
+ my ($old_form) = @_;
+
+ $display_form = ($form->{display_form}) ? $form->{display_form} : "update";
+
+ $form->{description} =~ s/^\s+//g;
+
+ for (qw(partnumber projectnumber)) { $form->{$_} =~ s/--.*// }
+
+ @a = qw(hour min sec);
+ foreach $item (qw(in out)) {
+ for (@a) { $form->{"$item$_"} = substr(qq|00$form->{"$item$_"}|, -2) }
+ $form->{"checked$item"} = qq|$form->{"${item}hour"}:$form->{"${item}min"}:$form->{"${item}sec"}|;
+ }
+
+ @a = ();
+ for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_} }
+ $form->{address} =~ s/\\n/\n/g;
+
+ push @a, qw(partnumber description projectnumber projectdescription);
+ push @a, qw(company address tel fax businessnumber username useremail);
+
+ $form->format_string(@a);
+
+ $form->{total} = $form->format_amount(\%myconfig, $form->parse_amount(\%myconfig, $form->{qty}) * $form->parse_amount(\%myconfig, $form->{sellprice}), 2);
+
+
+ ($form->{employee}, $form->{employee_id}) = split /--/, $form->{employee};
+
+ $form->{templates} = "$myconfig{templates}";
+ $form->{IN} = "$form->{formname}.html";
+
+ if ($form->{format} =~ /(postscript|pdf)/) {
+ $form->{IN} =~ s/html$/tex/;
+ }
+
+ if ($form->{media} !~ /(screen|queue)/) {
+ $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
+ $form->{printmode} = '|-';
+
+ if ($form->{printed} !~ /$form->{formname}/) {
+ $form->{printed} .= " $form->{formname}";
+ $form->{printed} =~ s/^ //;
+
+ $form->update_status(\%myconfig);
+ }
+
+ %audittrail = ( tablename => jcitems,
+ reference => $form->{id},
+ formname => $form->{formname},
+ action => 'printed',
+ id => $form->{id} );
+
+ %status = ();
+ for (qw(printed queued audittrail)) { $status{$_} = $form->{$_} }
+
+ $status{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
+
+ }
+
+ if ($form->{media} eq 'queue') {
+ %queued = split / /, $form->{queued};
+
+ if ($filename = $queued{$form->{formname}}) {
+ $form->{queued} =~ s/$form->{formname} $filename//;
+ unlink "${LedgerSMB::Sysconfig::spool}/$filename";
+ $filename =~ s/\..*$//g;
+ } else {
+ $filename = time;
+ $filename .= $$;
+ }
+
+ $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
+ $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
+ $form->{printmode} = '>';
+
+ $form->{queued} = "$form->{formname} $filename";
+ $form->update_status(\%myconfig);
+
+ %audittrail = ( tablename => jcitems,
+ reference => $form->{id},
+ formname => $form->{formname},
+ action => 'queued',
+ id => $form->{id} );
+
+ %status = ();
+ for (qw(printed queued audittrail)) { $status{$_} = $form->{$_} }
+
+ $status{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
+ }
+
+ $form->parse_template(\%myconfig, ${LedgerSMB::Sysconfig::userspath});
+
+ if (defined %$old_form) {
+
+ for (keys %$old_form) { $form->{$_} = $old_form->{$_} }
+ for (qw(printed queued audittrail)) { $form->{$_} = $status{$_} }
+
+ &{ "$display_form" };
+
+ }
+
+}
+
+
diff --git a/bin/pos.pl b/bin/pos.pl
index 31087cca..9f414d1d 100755
--- a/bin/pos.pl
+++ b/bin/pos.pl
@@ -1,1082 +1,1083 @@
-#=====================================================================
-# LedgerSMB Small Medium Business Accounting
-# http://www.ledgersmb.org/
-#
-
-# Copyright (C) 2006
-# This work contains copyrighted information from a number of sources all used
-# with permission.
-#
-# This file contains source code included with or based on SQL-Ledger which
-# is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
-# under the GNU General Public License version 2 or, at your option, any later
-# version. For a full list including contact information of contributors,
-# maintainers, and copyright holders, see the CONTRIBUTORS file.
-#
-# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
-# Copyright (c) 2003
-#
-# Author: DWS Systems Inc.
-# Web: http://www.sql-ledger.org
-#
-# Contributors: Steve Doerr <sdoerr907@everestkc.net>
-#
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#=====================================================================
-#
-# POS
-#
-#=====================================================================
-
-use LedgerSMB::Tax;
-
-1;
-# end
-
-sub check_alert {
- my $rc = $form->{'rowcount'};
- if (!$form->{"partnumber_$rc"}){
- --$rc; # Ensures that alert shows up when item is selected from a list;
- }
- for (1 .. $rc){
- $form->{'check_id'} = ($form->{'check_id'} || $form->{"check_id_$_"});
- }
-}
-
-sub send_to_pd{
- socket(SOCK, 2, 1, getprotobynumber($pos_config{'pd_proto'}));
- connect(SOCK, $pos_config{'pd_dest'});
- my $rn = $numrows - 1;
- my $ds_string = sprintf (
- '%s%s @ $%-7.2f%s%s%s',
- $pd_control{'new_line'},
- $form->{"qty_$rn"},
- $form->{"sellprice_$rn"},
- $pd_control{'new_line'},
- "Subtotal: \$".sprintf('%-7.2f', $form->{'invtotal'})
- );
- print SOCK $ds_string;
- close SOCK;
-}
-
-sub on_update{
- &send_to_pd;
- &check_alert;
-}
-
-sub open_drawer{
- open (PRINTER, "|-", ${LedgerSMB::Sysconfig::printer}{Printer});
- print PRINTER $pos_config{'rp_cash_open'};
- close PRINTER;
- sleep 1;
-}
-
-sub open {
- &open_drawer;
- &update;
-}
-
-sub add {
- $form->{nextsub} = 'add';
-
- $form->{title} = $locale->text('Add POS Invoice');
-
- $form->{callback} = "$form->{script}?action=$form->{nextsub}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- &invoice_links;
-
- $form->{type} = "pos_invoice";
- $form->{format} = "txt";
- $form->{media} = ($myconfig{printer}) ? $myconfig{printer} : "screen";
- $form->{rowcount} = 0;
-
- $form->{readonly} = ($myconfig{acs} =~ /POS--Sale/) ? 1 : 0;
-
- $ENV{REMOTE_ADDR} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/;
- $form->{till} = $4;
-
- $form->{partsgroup} = "";
- for (@{ $form->{all_partsgroup} }) { $form->{partsgroup} .= "$_->{partsgroup}--$_->{translation}\n"; }
-
- $form->{dontdisplayend} = 1;
-
- &display_form;
-
- $form->{dontdisplayrows} = 1;
- $form->{dontdisplayend} = 0;
- &openinvoices;
-}
-
-
-sub openinvoices {
- undef %column_data;
- undef %column_heading;
-
- $ENV{REMOTE_ADDR} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/;
- $form->{till} = $4;
-
- $form->{sort} = 'transdate';
-
- for (qw(open l_invnumber l_transdate l_name l_amount l_curr l_till l_subtotal)) { $form->{$_} = 'Y'; }
-
- if ($myconfig{role} ne 'user') {
- $form->{l_employee} = 'Y';
- }
-
- $form->{title} = $locale->text('Open');
- transactions;
-
-}
-
-
-sub edit {
-
- $form->{title} = $locale->text('Edit POS Invoice');
-
- $form->{callback} = "$form->{script}?action=$form->{nextsub}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- &invoice_links;
- &prepare_invoice;
-
- $form->{type} = "pos_invoice";
- $form->{format} = "txt";
- $form->{media} = ($myconfig{printer}) ? $myconfig{printer} : "screen";
-
- $form->{readonly} = ($myconfig{acs} =~ /POS--Sale/) ? 1 : 0;
-
- $form->{partsgroup} = "";
- for (@{ $form->{all_partsgroup} }) { $form->{partsgroup} .= "$_->{partsgroup}--$_->{translation}\n"; }
-
- &display_form;
-
-}
-
-
-sub form_header {
-
-
- if (!$form->{'check_id'}){
- &check_alert;
- }
-
- # set option selected
- for (qw(AR currency)) {
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
- }
-
- for (qw(customer department employee)) {
- $form->{"select$_"} = $form->unescape($form->{"select$_"});
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
- }
-
- $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
-
- $exchangerate = qq|<tr>|;
- $exchangerate .= qq|
- <th align=right nowrap>|.$locale->text('Currency').qq|</th>
- <td><select name=currency>$form->{selectcurrency}</select></td> | if $form->{defaultcurrency};
- $exchangerate .= qq|
- <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
- <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
-|;
-
- if ($form->{defaultcurrency} && $form->{currency} ne $form->{defaultcurrency}) {
- if ($form->{forex}) {
- $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
- } else {
- $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
- }
- }
- $exchangerate .= qq|
-<input type=hidden name=forex value=$form->{forex}>
-</tr>
-|;
-
- if ($form->{selectcustomer}) {
- $customer = qq|<select name=customer>$form->{selectcustomer}</select>
- <input type=hidden name="selectcustomer" value="|.
- $form->escape($form->{selectcustomer},1).qq|">|;
- } else {
- $customer = qq|<input name=customer value="$form->{customer}" size=35>|;
- }
-
- $department = qq|
- <tr>
- <th align="right" nowrap>|.$locale->text('Department').qq|</th>
- <td colspan=3><select name=department>$form->{selectdepartment}</select>
- <input type=hidden name=selectdepartment value="|.
- $form->escape($form->{selectdepartment},1).qq|">
- </td>
- </tr>
-| if $form->{selectdepartment};
-
- $employee = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Salesperson').qq|</th>
- <td colspan=3><select name=employee>$form->{selectemployee}</select></td>
- <input type=hidden name=selectemployee value="|.
- $form->escape($form->{selectemployee},1).qq|">
- </tr>
-| if $form->{selectemployee};
-
- if ($form->{change} != $form->{oldchange}) {
- $form->{creditremaining} -= $form->{oldchange};
- }
- $n = ($form->{creditremaining} < 0) ? "0" : "1";
-
- if ($form->{business}) {
- $business = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Business').qq|</th>
- <td>$form->{business}</td>
- <td width=10></td>
- <th align=right nowrap>|.$locale->text('Trade Discount').qq|</th>
- <td>|.$form->format_amount(\%myconfig, $form->{tradediscount} * 100).qq| %</td>
- </tr>
-|;
- }
-
- if ($form->{selectlanguage}) {
- if ($form->{language_code} ne $form->{oldlanguage_code}) {
- # rebuild partsgroup
- $form->get_partsgroup(\%myconfig, { language_code => $form->{language_code}, searchitems => 'nolabor'});
- $form->{partsgroup} = "";
- for (@{ $form->{all_partsgroup} }) { $form->{partsgroup} .= "$_->{partsgroup}--$_->{translation}\n"; }
- $form->{oldlanguage_code} = $form->{language_code};
- }
-
-
- $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
- $form->{"selectlanguage"} =~ s/ selected//;
- $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
- $lang = qq|
- <tr>
- <th align=right>|.$locale->text('Language').qq|</th>
- <td colspan=3><select name=language_code>$form->{selectlanguage}</select></td>
- </tr>
- <input type=hidden name=oldlanguage_code value=$form->{oldlanguage_code}>
- <input type=hidden name=selectlanguage value="|.
- $form->escape($form->{selectlanguage},1).qq|">|;
- }
-
- $i = $form->{rowcount} + 1;
- $focus = "partnumber_$i";
-
- $form->header();
-
- print qq|
-<body onLoad="document.forms[0].${focus}.focus()" />
-
-<form method=post action="$form->{script}">
-|;
-
- $form->hide_form(qw(id till type format printed title discount creditlimit creditremaining tradediscount business closedto locked oldtransdate customer_id oldcustomer check_id));
-
- print qq|
-<input type=hidden name=vc value="customer">
-
-<table width=100%>
- <tr class=listtop>
- <th class=listtop>$form->{title}</font></th>
- </tr>|;
- if ($form->{'check_id'}){
- print qq|
- <tr class=listtop>
- <th class=listtop style="background-color: red">|.$locale->text('Check ID').qq|
- </th>
- </tr>|;
- }
- print qq|
- <tr height="5"></tr>
- <tr>
- <td>
- <table width=100%>
- <tr valign=top>
- <td>
- <table>
- <tr>
- <th align=right nowrap>|.$locale->text('Customer').qq|</th>
- <td colspan=3>$customer</td>
- </tr>
- <tr>
- <td></td>
- <td colspan=3>
- <table>
- <tr>
- <th align=right nowrap>|.$locale->text('Credit Limit').qq|</th>
- <td>$form->{creditlimit}</td>
- <td width=10></td>
- <th align=right nowrap>|.$locale->text('Remaining').qq|</th>
- <td class="plus$n">|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</font></td>
- </tr>
- $business
- </table>
- </td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Record in').qq|</th>
- <td colspan=3><select name=AR>$form->{selectAR}</select></td>
- <input type=hidden name=selectAR value="$form->{selectAR}">
- </tr>
- $department
- </table>
- </td>
- <td>
- <table>
- $employee
- $exchangerate
- $lang
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td>
- </td>
- </tr>
-|;
-
- $form->hide_form(qw(taxaccounts duedate invnumber transdate selectcurrency defaultcurrency));
-
- for (split / /, $form->{taxaccounts}) {
- $form->hide_form("${_}_rate", "${_}_description", "${_}_taxnumber");
- }
-
-}
-
-
-
-sub form_footer {
-
- $form->{invtotal} = $form->{invsubtotal};
-
- $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
-
- $taxincluded = "";
- if ($form->{taxaccounts}) {
- $taxincluded = qq|
- <tr height="5"></tr>
- <tr>
- <td align=right>
- <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td><th align=left>|.$locale->text('Tax Included').qq|</th>
- </tr>
-|;
- }
-
- if (!$form->{taxincluded}) {
-
- my @taxes = Tax::init_taxes($form, $form->{taxaccounts});
- $form->{invtotal} += Tax::calculate_taxes(\@taxes, $form,
- $form->{invsubtotal}, 0);
-
- foreach my $item (@taxes) {
- my $taccno = $item->account;
-
- $form->{"${taccno}_total"} = $form->format_amount(\%myconfig,
- $item->value, 2, 0);
-
- $tax .= qq|
- <tr>
- <th align=right>$form->{"${taccno}_description"}</th>
- <td align=right>$form->{"${taccno}_total"}</td>
- </tr>
- | if $item->value;
- }
-
- $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
-
- $subtotal = qq|
- <tr>
- <th align=right>|.$locale->text('Subtotal').qq|</th>
- <td align=right>$form->{invsubtotal}</td>
- </tr>
-|;
- }
-
- @column_index = qw(paid memo source cctrack AR_paid);
-
- $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
- $column_data{source} = "<th>".$locale->text('Source')."</th>";
- $column_data{memo} = "<th>".$locale->text('Memo')."</th>";
- $column_data{cctrack} = "<th>".$locale->text('Credit Card Track')."</th>";
- $column_data{AR_paid} = "<th>&nbsp;</th>";
-
- print qq|
- <tr>
- <td>
- <table width=100%>
- <tr valign=top>
- <td>
- <table>
- <tr>
-|;
-
- for (@column_index) { print "$column_data{$_}\n"; }
-
- print qq|
- </tr>
-|;
-
- $totalpaid = 0;
-
- $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
-
- my $memoselect = qq|<SELECT name="MEMONAME">|;
- for (sort keys %pos_sources){
- $memoselect .= qq|<option value="$_">$pos_sources{$_}</option>|;
- }
- $memoselect .= qq|</SELECT>|;
-
-
- for $i (1 .. $form->{paidaccounts}) {
-
- $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
- $form->{"selectAR_paid_$i"} =~ s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
-
- # format amounts
- $totalpaid += $form->{"paid_$i"};
- $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
- $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
-
- if ($form->{"paid__$i"}){
- $column_data{paid} = qq|<td><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
- } else {
- $column_data{paid} = qq|<td><input accesskey='n' name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
- }
-
- $column_data{source} = qq|<td><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|;
- $column_data{memo} = qq|<td>$memoselect</td>|;
- $column_data{memo} =~ s/MEMONAME/memo_$i/;
- if (!$form->{"memo_$i"}){
- $form->{"memo_$i"} = $pos_source_default;
- }
- my $memval = $form->{"memo_$i"};
- $column_data{memo} =~ s/(option value="$memval")/$1 SELECTED/;
-
- $column_data{cctrack} = qq|<td><input type="text" name="cctrack_$i"
- value="|.$form->{"cctrack_$i"}.qq|" size="3"></td>|;
-
- if ($pos_config{"coa_prefix"}){
- if (!$form->{"AR_paid_$i"}){
- $form->{"AR_paid_$i"} =
- $pos_config{"coa_prefix"}.'.'.$pos_config{"till"};
- }
- $column_data{AR_paid} = qq|<input type=hidden name="AR_paid_$i"
- value='$form->{"AR_paid_$i"}'>|;
- } else {
- $column_data{AR_paid} = qq|<td><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
- }
- print qq|
- <tr>
-|;
- for (@column_index) { print "$column_data{$_}\n"; }
-
- print qq|
- </tr>
-|;
-
- $form->hide_form("cleared_$i", "exchangerate_$i", "forex_$i");
-
- }
-
- $form->{change} = 0;
- if ($totalpaid > $form->{invtotal}) {
- $form->{change} = $totalpaid - $form->{invtotal};
- }
- $form->{oldchange} = $form->{change};
- $form->{change} = $form->format_amount(\%myconfig, $form->{change}, 2, 0);
- $form->{totalpaid} = $form->format_amount(\%myconfig, $totalpaid, 2);
-
- $form->{oldinvtotal} = $form->{invtotal};
- $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
-
- print qq|
- <tr>
- <th align=right>|.$locale->text('Change').qq|</th>
- <th>$form->{change}</th>
- </tr>
- </table>
- </td>
- <td align=right>
- <table>
- $subtotal
- $tax
- <tr>
- <th align=right>|.$locale->text('Total').qq|</th>
- <td align=right>$form->{invtotal}</td>
- </tr>
- $taxincluded
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
-
-<input type=hidden name=oldtotalpaid value=$totalpaid>
-<input type=hidden name=datepaid value=$form->{transdate}>
-
-<tr>
- <td>
-|;
-
- $form->hide_form(qw(paidaccounts selectAR_paid oldinvtotal change oldchange invtotal));
-
- &print_options;
-
- print qq|
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-|;
-
- $transdate = $form->datetonum(\%myconfig, $form->{transdate});
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
-
-# type=submit $locale->text('Update')
-# type=submit $locale->text('Print')
-# type=submit $locale->text('Post')
-# type=submit $locale->text('Print and Post')
-# type=submit $locale->text('Delete')
-
- if (! $form->{readonly}) {
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
- 'post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
- 'print_and_post' => { ndx => 4, key => 'R', value => $locale->text('Print and Post') },
- 'delete' => { ndx => 5, key => 'D', value => $locale->text('Delete') },
- );
-
- if ($transdate > $closedto) {
-
- if (! $form->{id}) {
- delete $button{'delete'};
- }
-
- delete $button{'print_and_post'} unless ${LedgerSMB::Sysconfig::latex};
- } else {
- for ('print', 'post', 'print_and_post', 'delete') { delete $button{$_} }
- }
-
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
-
- print qq|<p>
- <input type=text size=1 value="B" accesskey="B" title="[Alt-B]">\n|;
-
- if ($form->{partsgroup}) {
- $form->{partsgroup} =~ s/\r//g;
- $form->{partsgroup} = $form->quote($form->{partsgroup});
-
- $spc = ($form->{path} =~ /lynx/) ? "." : " ";
- print qq|
-<input type=hidden name=nextsub value=lookup_partsgroup>
-<input type=hidden name=partsgroup value="$form->{partsgroup}">|;
-
- foreach $item (split /\n/, $form->{partsgroup}) {
- ($partsgroup, $translation) = split /--/, $item;
- $item = ($translation) ? $translation : $partsgroup;
- print qq| <button class="submit" type="submit" name="action" value="$spc$item">$spc$item</button>\n| if $item;
- }
- }
- }
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- $form->hide_form(qw(rowcount callback path login sessionid));
-
- print qq|</form>|;
-
- if (!$form->{dontdisplayend}){
- print qq|
-</body>
-</html>
-|;
- }
-}
-
-
-sub post {
-
- $form->{media} = 'Printer';
- $form->isblank("customer", $locale->text('Customer missing!'));
-
- # if oldcustomer ne customer redo form
- $customer = $form->{customer};
- $customer =~ s/--.*//g;
- $customer .= "--$form->{customer_id}";
- if ($customer ne $form->{oldcustomer}) {
- &update;
- exit;
- }
-
- &validate_items;
- &print;
-
- $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
-
- $paid = 0;
- for (1 .. $form->{paidaccounts}) { $paid += $form->parse_amount(\%myconfig, $form->{"paid_$_"}); }
- delete $form->{datepaid} unless $paid;
-
- $total = $form->parse_amount(\%myconfig, $form->{invtotal});
-
- # deduct change from first payment
- #$form->{"paid_1"} = $form->{invtotal} if $paid > $total;
- $form->{paid} = $paid;
- if ($paid > $total){
- ++$form->{paidaccounts};
- my $pa = $form->{paidaccounts};
- $form->{"paid_$pa"} = $total - $paid;
- $form->{"source_$pa"} = 'cash';
- $form->{"exchangerate_$pa"} = 0;
- $form->{"AR_paid_$pa"} = $form->{AR_paid_1}
- }
-
- ($form->{AR}) = split /--/, $form->{AR};
-
- if (IS->post_invoice(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Posted!'));
- } else {
- $form->error($locale->text('Cannot post transaction!'));
- }
-
-}
-
-
-sub display_row {
- my $numrows = shift;
-
- @column_index = qw(partnumber description partsgroup qty unit sellprice discount linetotal);
-
- $form->{invsubtotal} = 0;
-
- for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0; }
-
- $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
- $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|;
- $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
- $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
- $column_data{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Price').qq|</th>|;
- $column_data{linetotal} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;
- $column_data{discount} = qq|<th class=listheading nowrap>%</th>|;
-
- print qq|
- <tr>
- <td>
- <table width=100%>
- <tr class=listheading>|;
-
- for (@column_index) { print "\n$column_data{$_}"; };
-
- print qq|
- </tr>
-|;
-
- $exchangerate = $form->parse_amount(\%myconfig, $form->{exchangerate});
- $exchangerate = ($exchangerate) ? $exchangerate : 1;
-
- for $i (1 .. $numrows) {
- # undo formatting
- for (qw(qty discount sellprice)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}); }
-
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
-
- if (($form->{"qty_$i"} != $form->{"oldqty_$i"}) || ($form->{currency} ne $form->{oldcurrency})) {
- # check for a pricematrix
- @a = split / /, $form->{"pricematrix_$i"};
- if (scalar @a) {
- foreach $item (@a) {
- ($q, $p) = split /:/, $item;
- if (($p * 1) && ($form->{"qty_$i"} >= ($q * 1))) {
- ($dec) = ($p =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
- $form->{"sellprice_$i"} = $form->round_amount($p / $exchangerate, $decimalplaces);
- }
- }
- }
- }
-
- if ($i < $numrows) {
- $column_data{discount} = qq|<td align=right><input name="discount_$i" size=3 value=|.$form->format_amount(\%myconfig, $form->{"discount_$i"}).qq|></td>|;
- } else {
- $column_data{discount} = qq|<td></td>|;
- }
-
- $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces);
- $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
- $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
-
- for (qw(partnumber sku description partsgroup unit)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}); }
-
- $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=20 value="$form->{"partnumber_$i"}" accesskey="$i" title="[Alt-$i]"></td>|;
-
- if (($rows = $form->numtextrows($form->{"description_$i"}, 40, 6)) > 1) {
- $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=46 wrap=soft>$form->{"description_$i"}</textarea></td>|;
- } else {
- $column_data{description} = qq|<td><input name="description_$i" size=48 value="$form->{"description_$i"}"></td>|;
- }
-
- $column_data{qty} = qq|<td align=right><input name="qty_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|;
- $column_data{unit} = qq|<td>$form->{"unit_$i"}</td>|;
- $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;
- $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|;
-
- print qq|
- <tr valign=top>|;
-
- for (@column_index) { print "\n$column_data{$_}"; }
-
- print qq|
- </tr>
-|;
-
- $form->{"oldqty_$i"} = $form->{"qty_$i"};
-
- for (qw(id listprice lastcost taxaccounts pricematrix oldqty sku partsgroup unit inventory_accno_id income_accno_id expense_accno_id)) { $form->hide_form("${_}_$i") }
-
- for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $linetotal; }
-
- $form->{invsubtotal} += $linetotal;
- }
-
- print qq|
- </table>
- </td>
- </tr>
-
-<input type=hidden name=oldcurrency value=$form->{currency}>
-
-|;
-
-}
-
-
-sub print {
- if (!$form->{invnumber}){
- $form->{invnumber} = $form->update_defaults(\%myconfig, 'sinumber');
- }
- $rc = $form->{'rowcount'};
- $pc = $form->{'paidaccounts'};
- if ($form->{"partnumber_$rc"} || $form->{"description_$rc"} ||
- $form->{"paid_$pc"}){
- &update;
- exit;
- }
- for $i (1 .. $rc - 1){
- if ($form->{"qty_$i"} != $form->{"oldqty_$i"}){
- &update;
- exit;
- }
- }
-
- if (!$form->{invnumber}) {
- $form->{invnumber} = $form->update_defaults(\%myconfig, "sinumber");
- if ($form->{media} eq 'screen') {
- &update;
- exit;
- }
- }
-
- $old_form = new Form;
- for (keys %$form) { $old_form->{$_} = $form->{$_}; }
-
- for (qw(employee department)) { $form->{$_} =~ s/--.*//g; }
- $form->{invdate} = $form->{transdate};
- my @lt = localtime();
- $form->{dateprinted} = $lt[2].":".$lt[1].":".$lt[0];
-
- &print_form($old_form);
-
-}
-
-
-sub print_form {
- my $old_form = shift;
- &open_drawer;
-
- # if oldcustomer ne customer redo form
- $customer = $form->{customer};
- $customer =~ s/--.*//g;
- $customer .= "--$form->{customer_id}";
- if ($customer ne $form->{oldcustomer}) {
- &update;
- exit;
- }
-
- &validate_items;
-
- &{ "$form->{vc}_details" };
-
- @a = ();
- for (1 .. $form->{rowcount}) { push @a, ("partnumber_$_", "description_$_"); }
- for (split / /, $form->{taxaccounts}) { push @a, "${_}_description"; }
- $form->format_string(@a);
-
- # format payment dates
- for (1 .. $form->{paidaccounts}) { $form->{"datepaid_$_"} = $locale->date(\%myconfig, $form->{"datepaid_$_"}); }
-
- IS->invoice_details(\%myconfig, \%$form);
-
- if ($form->parse_amount(\%myconfig, $form->{total}) <= 0) {
- $form->{total} = 0;
- } else {
- $form->{change} = 0;
- }
-
- for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_}; }
- $form->{username} = $myconfig{name};
-
- $form->{address} =~ s/\\n/\n/g;
- push @a, qw(company address tel fax businessnumber username);
- $form->format_string(@a);
-
- $form->{templates} = "$myconfig{templates}";
- $form->{IN} = "$form->{type}.$form->{format}";
-
- if ($form->{format} =~ /(postscript|pdf)/) {
- $form->{IN} =~ s/$&$/tex/;
- }
-
- if ($form->{media} ne 'screen') {
- $form->{OUT} = "| ${LedgerSMB::Sysconfig::printer}{$form->{media}}";
- }
-
- $form->{discount} = $form->format_amount(\%myconfig, $form->{discount} * 100);
-
- $form->{rowcount}--;
- $form->{pre} = "<body bgcolor=#ffffff>\n<pre>";
- delete $form->{stylesheet};
- $form->{cd_open} = $pos_config{rp_cash_drawer_open};
-
- $form->parse_template(\%myconfig, ${LedgerSMB::Sysconfig::userspath});
-
- if ($form->{printed} !~ /$form->{formname}/) {
- $form->{printed} .= " $form->{formname}";
- $form->{printed} =~ s/^ //;
-
- $form->update_status(\%myconfig);
- }
- $old_form->{printed} = $form->{printed};
-
- # if we got back here restore the previous form
- if ($form->{media} ne 'screen') {
- # restore and display form
- for (keys %$old_form) { $form->{$_} = $old_form->{$_}; }
- $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
-
- for $i (1 .. $form->{paidaccounts}) {
- for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}); }
- }
-
- delete $form->{pre};
-
- if (! $form->{printandpost}) {
- $form->{rowcount}--;
- #&display_form;
- }
- }
-
-}
-
-
-sub print_and_post {
-
- $form->error($locale->text('Select a Printer!')) if ($form->{media} eq 'screen');
- $form->{printandpost} = 1;
- &print;
- &post;
-
-}
-
-sub lookup_partsgroup {
-
- $form->{action} =~ s/\r//;
- $form->{action} = substr($form->{action}, 1);
-
- if ($form->{language_code}) {
- # get english
- foreach $item (split /\n/, $form->{partsgroup}) {
- if ($item =~ /$form->{action}/) {
- ($partsgroup, $translation) = split /--/, $item;
- $form->{action} = $partsgroup;
- last;
- }
- }
- }
-
- $form->{"partsgroup_$form->{rowcount}"} = $form->{action};
-
- &update;
-
-}
-
-
-
-sub print_options {
-
- $form->{PD}{$form->{type}} = "checked";
-
- print qq|
-<input type=hidden name=format value=$form->{format}>
-<input type=hidden name=formname value=$form->{type}>
-
-<table width=100%>
- <tr>
-|;
-
-
- $media = qq|
- <td><input class=radio type=radio name=media value="screen"></td>
- <td>|.$locale->text('Screen').qq|</td>|;
-
- if (%{LedgerSMB::Sysconfig::printer}) {
- for (keys %{LedgerSMB::Sysconfig::printer}) {
- $media .= qq|
- <td><input class=radio type=radio name=media value="$_"></td>
- <td nowrap>$_</td>
-|;
- }
- }
-
- $media =~ s/(value="\Q$form->{media}\E")/$1 checked/;
-
- print qq|
- $media
-
- <td width=99%>&nbsp;</td>|;
-
- if ($form->{printed} =~ /$form->{type}/) {
- print qq|
- <th>\||.$locale->text('Printed').qq|\|</th>|;
- }
-
- print qq|
- </tr>
-</table>
-|;
-
-}
-
-
-sub receipts {
-
- $form->{title} = $locale->text('Receipts');
-
- $form->{db} = 'ar';
- RP->paymentaccounts(\%myconfig, \%$form);
-
- $paymentaccounts = "";
- for (@{ $form->{PR} } ) { $paymentaccounts .= "$_->{accno} "; }
-
- if (@{ $form->{all_years} }) {
- # accounting years
- $form->{selectaccountingyear} = "<option>\n";
- for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n|; }
- $form->{selectaccountingmonth} = "<option>\n";
- for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n|; }
-
- $selectfrom = qq|
- <tr>
- <th align=right>|.$locale->text('Period').qq|</th>
- <td colspan=3>
- <select name=month>$form->{selectaccountingmonth}</select>
- <select name=year>$form->{selectaccountingyear}</select>
- <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
- <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
- <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
- <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
- </td>
- </tr>
-|;
- }
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-
-<input type=hidden name=title value="$form->{title}">
-<input type=hidden name=paymentaccounts value="$paymentaccounts">
-
-<input type=hidden name=till value=1>
-<input type=hidden name=subtotal value=1>
-
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>
- <table>
-
- <input type=hidden name=nextsub value=list_payments>
-
- <tr>
- <th align=right>|.$locale->text('From').qq|</th>
- <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
- <th align=right>|.$locale->text('To').qq|</th>
- <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
- </tr>
- $selectfrom
- <input type=hidden name=sort value=transdate>
- <input type=hidden name=db value=$form->{db}>
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<br>
-<input type="hidden" name="path" value="$form->{path}">
-<input type="hidden" name="login" value="$form->{login}">
-<input type="hidden" name="sessionid" value="$form->{sessionid}">
-
-<button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
-|;
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
-
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
+#=====================================================================
+# LedgerSMB Small Medium Business Accounting
+# http://www.ledgersmb.org/
+#
+
+# Copyright (C) 2006
+# This work contains copyrighted information from a number of sources all used
+# with permission.
+#
+# This file contains source code included with or based on SQL-Ledger which
+# is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
+# under the GNU General Public License version 2 or, at your option, any later
+# version. For a full list including contact information of contributors,
+# maintainers, and copyright holders, see the CONTRIBUTORS file.
+#
+# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
+# Copyright (c) 2003
+#
+# Author: DWS Systems Inc.
+# Web: http://www.sql-ledger.org
+#
+# Contributors: Steve Doerr <sdoerr907@everestkc.net>
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#=====================================================================
+#
+# POS
+#
+#=====================================================================
+
+use LedgerSMB::Tax;
+
+1;
+# end
+
+sub check_alert {
+ my $rc = $form->{'rowcount'};
+ if (!$form->{"partnumber_$rc"}){
+ --$rc; # Ensures that alert shows up when item is selected from a list;
+ }
+ for (1 .. $rc){
+ $form->{'check_id'} = ($form->{'check_id'} || $form->{"check_id_$_"});
+ }
+}
+
+sub send_to_pd{
+ socket(SOCK, 2, 1, getprotobynumber($pos_config{'pd_proto'}));
+ connect(SOCK, $pos_config{'pd_dest'});
+ my $rn = $numrows - 1;
+ my $ds_string = sprintf (
+ '%s%s @ $%-7.2f%s%s%s',
+ $pd_control{'new_line'},
+ $form->{"qty_$rn"},
+ $form->{"sellprice_$rn"},
+ $pd_control{'new_line'},
+ "Subtotal: \$".sprintf('%-7.2f', $form->{'invtotal'})
+ );
+ print SOCK $ds_string;
+ close SOCK;
+}
+
+sub on_update{
+ &send_to_pd;
+ &check_alert;
+}
+
+sub open_drawer{
+ open (PRINTER, "|-", ${LedgerSMB::Sysconfig::printer}{Printer});
+ print PRINTER $pos_config{'rp_cash_open'};
+ close PRINTER;
+ sleep 1;
+}
+
+sub open {
+ &open_drawer;
+ &update;
+}
+
+sub add {
+ $form->{nextsub} = 'add';
+
+ $form->{title} = $locale->text('Add POS Invoice');
+
+ $form->{callback} = "$form->{script}?action=$form->{nextsub}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+
+ &invoice_links;
+
+ $form->{type} = "pos_invoice";
+ $form->{format} = "txt";
+ $form->{media} = ($myconfig{printer}) ? $myconfig{printer} : "screen";
+ $form->{rowcount} = 0;
+
+ $form->{readonly} = ($myconfig{acs} =~ /POS--Sale/) ? 1 : 0;
+
+ $ENV{REMOTE_ADDR} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/;
+ $form->{till} = $4;
+
+ $form->{partsgroup} = "";
+ for (@{ $form->{all_partsgroup} }) { $form->{partsgroup} .= "$_->{partsgroup}--$_->{translation}\n"; }
+
+ $form->{dontdisplayend} = 1;
+
+ &display_form;
+
+ $form->{dontdisplayrows} = 1;
+ $form->{dontdisplayend} = 0;
+ &openinvoices;
+}
+
+
+sub openinvoices {
+ undef %column_data;
+ undef %column_heading;
+
+ $ENV{REMOTE_ADDR} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/;
+ $form->{till} = $4;
+
+ $form->{sort} = 'transdate';
+
+ for (qw(open l_invnumber l_transdate l_name l_amount l_curr l_till l_subtotal)) { $form->{$_} = 'Y'; }
+
+ if ($myconfig{role} ne 'user') {
+ $form->{l_employee} = 'Y';
+ }
+
+ $form->{title} = $locale->text('Open');
+ transactions;
+
+}
+
+
+sub edit {
+
+ $form->{title} = $locale->text('Edit POS Invoice');
+
+ $form->{callback} = "$form->{script}?action=$form->{nextsub}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+
+ &invoice_links;
+ &prepare_invoice;
+
+ $form->{type} = "pos_invoice";
+ $form->{format} = "txt";
+ $form->{media} = ($myconfig{printer}) ? $myconfig{printer} : "screen";
+
+ $form->{readonly} = ($myconfig{acs} =~ /POS--Sale/) ? 1 : 0;
+
+ $form->{partsgroup} = "";
+ for (@{ $form->{all_partsgroup} }) { $form->{partsgroup} .= "$_->{partsgroup}--$_->{translation}\n"; }
+
+ &display_form;
+
+}
+
+
+sub form_header {
+
+
+ if (!$form->{'check_id'}){
+ &check_alert;
+ }
+
+ # set option selected
+ for (qw(AR currency)) {
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
+ }
+
+ for (qw(customer department employee)) {
+ $form->{"select$_"} = $form->unescape($form->{"select$_"});
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
+ }
+
+ $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
+
+ $exchangerate = qq|<tr>|;
+ $exchangerate .= qq|
+ <th align=right nowrap>|.$locale->text('Currency').qq|</th>
+ <td><select name=currency>$form->{selectcurrency}</select></td> | if $form->{defaultcurrency};
+ $exchangerate .= qq|
+ <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
+ <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
+|;
+
+ if ($form->{defaultcurrency} && $form->{currency} ne $form->{defaultcurrency}) {
+ if ($form->{forex}) {
+ $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
+ } else {
+ $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
+ }
+ }
+ $exchangerate .= qq|
+<input type=hidden name=forex value=$form->{forex}>
+</tr>
+|;
+
+ if ($form->{selectcustomer}) {
+ $customer = qq|<select name=customer>$form->{selectcustomer}</select>
+ <input type=hidden name="selectcustomer" value="|.
+ $form->escape($form->{selectcustomer},1).qq|">|;
+ } else {
+ $customer = qq|<input name=customer value="$form->{customer}" size=35>|;
+ }
+
+ $department = qq|
+ <tr>
+ <th align="right" nowrap>|.$locale->text('Department').qq|</th>
+ <td colspan=3><select name=department>$form->{selectdepartment}</select>
+ <input type=hidden name=selectdepartment value="|.
+ $form->escape($form->{selectdepartment},1).qq|">
+ </td>
+ </tr>
+| if $form->{selectdepartment};
+
+ $employee = qq|
+ <tr>
+ <th align=right nowrap>|.$locale->text('Salesperson').qq|</th>
+ <td colspan=3><select name=employee>$form->{selectemployee}</select></td>
+ <input type=hidden name=selectemployee value="|.
+ $form->escape($form->{selectemployee},1).qq|">
+ </tr>
+| if $form->{selectemployee};
+
+ if ($form->{change} != $form->{oldchange}) {
+ $form->{creditremaining} -= $form->{oldchange};
+ }
+ $n = ($form->{creditremaining} < 0) ? "0" : "1";
+
+ if ($form->{business}) {
+ $business = qq|
+ <tr>
+ <th align=right nowrap>|.$locale->text('Business').qq|</th>
+ <td>$form->{business}</td>
+ <td width=10></td>
+ <th align=right nowrap>|.$locale->text('Trade Discount').qq|</th>
+ <td>|.$form->format_amount(\%myconfig, $form->{tradediscount} * 100).qq| %</td>
+ </tr>
+|;
+ }
+
+ if ($form->{selectlanguage}) {
+ if ($form->{language_code} ne $form->{oldlanguage_code}) {
+ # rebuild partsgroup
+ $form->get_partsgroup(\%myconfig, { language_code => $form->{language_code}, searchitems => 'nolabor'});
+ $form->{partsgroup} = "";
+ for (@{ $form->{all_partsgroup} }) { $form->{partsgroup} .= "$_->{partsgroup}--$_->{translation}\n"; }
+ $form->{oldlanguage_code} = $form->{language_code};
+ }
+
+
+ $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
+ $form->{"selectlanguage"} =~ s/ selected//;
+ $form->{"selectlanguage"} =~ s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
+ $lang = qq|
+ <tr>
+ <th align=right>|.$locale->text('Language').qq|</th>
+ <td colspan=3><select name=language_code>$form->{selectlanguage}</select></td>
+ </tr>
+ <input type=hidden name=oldlanguage_code value=$form->{oldlanguage_code}>
+ <input type=hidden name=selectlanguage value="|.
+ $form->escape($form->{selectlanguage},1).qq|">|;
+ }
+
+ $i = $form->{rowcount} + 1;
+ $focus = "partnumber_$i";
+
+ $form->header();
+
+ print qq|
+<body onLoad="document.forms[0].${focus}.focus()" />
+
+<form method=post action="$form->{script}">
+|;
+
+ $form->hide_form(qw(id till type format printed title discount creditlimit creditremaining tradediscount business closedto locked oldtransdate customer_id oldcustomer check_id));
+
+ print qq|
+<input type=hidden name=vc value="customer">
+
+<table width=100%>
+ <tr class=listtop>
+ <th class=listtop>$form->{title}</font></th>
+ </tr>|;
+ if ($form->{'check_id'}){
+ print qq|
+ <tr class=listtop>
+ <th class=listtop style="background-color: red">|.$locale->text('Check ID').qq|
+ </th>
+ </tr>|;
+ }
+ print qq|
+ <tr height="5"></tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr valign=top>
+ <td>
+ <table>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Customer').qq|</th>
+ <td colspan=3>$customer</td>
+ </tr>
+ <tr>
+ <td></td>
+ <td colspan=3>
+ <table>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Credit Limit').qq|</th>
+ <td>$form->{creditlimit}</td>
+ <td width=10></td>
+ <th align=right nowrap>|.$locale->text('Remaining').qq|</th>
+ <td class="plus$n">|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</font></td>
+ </tr>
+ $business
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Record in').qq|</th>
+ <td colspan=3><select name=AR>$form->{selectAR}</select></td>
+ <input type=hidden name=selectAR value="$form->{selectAR}">
+ </tr>
+ $department
+ </table>
+ </td>
+ <td>
+ <table>
+ $employee
+ $exchangerate
+ $lang
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ </td>
+ </tr>
+|;
+
+ $form->hide_form(qw(taxaccounts duedate invnumber transdate selectcurrency defaultcurrency));
+
+ for (split / /, $form->{taxaccounts}) {
+ $form->hide_form("${_}_rate", "${_}_description", "${_}_taxnumber");
+ }
+
+}
+
+
+
+sub form_footer {
+
+ $form->{invtotal} = $form->{invsubtotal};
+
+ $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
+
+ $taxincluded = "";
+ if ($form->{taxaccounts}) {
+ $taxincluded = qq|
+ <tr height="5"></tr>
+ <tr>
+ <td align=right>
+ <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td><th align=left>|.$locale->text('Tax Included').qq|</th>
+ </tr>
+|;
+ }
+
+ if (!$form->{taxincluded}) {
+
+ my @taxes = Tax::init_taxes($form, $form->{taxaccounts});
+ $form->{invtotal} += Tax::calculate_taxes(\@taxes, $form,
+ $form->{invsubtotal}, 0);
+
+ foreach my $item (@taxes) {
+ my $taccno = $item->account;
+
+ $form->{"${taccno}_total"} = $form->format_amount(\%myconfig,
+ $item->value, 2, 0);
+
+ $tax .= qq|
+ <tr>
+ <th align=right>$form->{"${taccno}_description"}</th>
+ <td align=right>$form->{"${taccno}_total"}</td>
+ </tr>
+ | if $item->value;
+ }
+
+ $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
+
+ $subtotal = qq|
+ <tr>
+ <th align=right>|.$locale->text('Subtotal').qq|</th>
+ <td align=right>$form->{invsubtotal}</td>
+ </tr>
+|;
+ }
+
+ @column_index = qw(paid memo source cctrack AR_paid);
+
+ $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
+ $column_data{source} = "<th>".$locale->text('Source')."</th>";
+ $column_data{memo} = "<th>".$locale->text('Memo')."</th>";
+ $column_data{cctrack} = "<th>".$locale->text('Credit Card Track')."</th>";
+ $column_data{AR_paid} = "<th>&nbsp;</th>";
+
+ print qq|
+ <tr>
+ <td>
+ <table width=100%>
+ <tr valign=top>
+ <td>
+ <table>
+ <tr>
+|;
+
+ for (@column_index) { print "$column_data{$_}\n"; }
+
+ print qq|
+ </tr>
+|;
+
+ $totalpaid = 0;
+
+ $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
+
+ my $memoselect = qq|<SELECT name="MEMONAME">|;
+ for (sort keys %pos_sources){
+ $memoselect .= qq|<option value="$_">$pos_sources{$_}</option>|;
+ }
+ $memoselect .= qq|</SELECT>|;
+
+
+ for $i (1 .. $form->{paidaccounts}) {
+
+ $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
+ $form->{"selectAR_paid_$i"} =~ s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
+
+ # format amounts
+ $totalpaid += $form->{"paid_$i"};
+ $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
+ $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
+
+ if ($form->{"paid__$i"}){
+ $column_data{paid} = qq|<td><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
+ } else {
+ $column_data{paid} = qq|<td><input accesskey='n' name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
+ }
+
+ $column_data{source} = qq|<td><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|;
+ $column_data{memo} = qq|<td>$memoselect</td>|;
+ $column_data{memo} =~ s/MEMONAME/memo_$i/;
+ if (!$form->{"memo_$i"}){
+ $form->{"memo_$i"} = $pos_source_default;
+ }
+ my $memval = $form->{"memo_$i"};
+ $column_data{memo} =~ s/(option value="$memval")/$1 SELECTED/;
+
+ $column_data{cctrack} = qq|<td><input type="text" name="cctrack_$i"
+ value="|.$form->{"cctrack_$i"}.qq|" size="3"></td>|;
+
+ if ($pos_config{"coa_prefix"}){
+ if (!$form->{"AR_paid_$i"}){
+ $form->{"AR_paid_$i"} =
+ $pos_config{"coa_prefix"}.'.'.$pos_config{"till"};
+ }
+ $column_data{AR_paid} = qq|<input type=hidden name="AR_paid_$i"
+ value='$form->{"AR_paid_$i"}'>|;
+ } else {
+ $column_data{AR_paid} = qq|<td><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
+ }
+ print qq|
+ <tr>
+|;
+ for (@column_index) { print "$column_data{$_}\n"; }
+
+ print qq|
+ </tr>
+|;
+
+ $form->hide_form("cleared_$i", "exchangerate_$i", "forex_$i");
+
+ }
+
+ $form->{change} = 0;
+ if ($totalpaid > $form->{invtotal}) {
+ $form->{change} = $totalpaid - $form->{invtotal};
+ }
+ $form->{oldchange} = $form->{change};
+ $form->{change} = $form->format_amount(\%myconfig, $form->{change}, 2, 0);
+ $form->{totalpaid} = $form->format_amount(\%myconfig, $totalpaid, 2);
+
+ $form->{oldinvtotal} = $form->{invtotal};
+ $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
+
+ print qq|
+ <tr>
+ <th align=right>|.$locale->text('Change').qq|</th>
+ <th>$form->{change}</th>
+ </tr>
+ </table>
+ </td>
+ <td align=right>
+ <table>
+ $subtotal
+ $tax
+ <tr>
+ <th align=right>|.$locale->text('Total').qq|</th>
+ <td align=right>$form->{invtotal}</td>
+ </tr>
+ $taxincluded
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+
+<input type=hidden name=oldtotalpaid value=$totalpaid>
+<input type=hidden name=datepaid value=$form->{transdate}>
+
+<tr>
+ <td>
+|;
+
+ $form->hide_form(qw(paidaccounts selectAR_paid oldinvtotal change oldchange invtotal));
+
+ &print_options;
+
+ print qq|
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+|;
+
+ $transdate = $form->datetonum(\%myconfig, $form->{transdate});
+ $closedto = $form->datetonum(\%myconfig, $form->{closedto});
+
+# type=submit $locale->text('Update')
+# type=submit $locale->text('Print')
+# type=submit $locale->text('Post')
+# type=submit $locale->text('Print and Post')
+# type=submit $locale->text('Delete')
+
+ if (! $form->{readonly}) {
+ %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
+ 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
+ 'post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
+ 'print_and_post' => { ndx => 4, key => 'R', value => $locale->text('Print and Post') },
+ 'delete' => { ndx => 5, key => 'D', value => $locale->text('Delete') },
+ );
+
+ if ($transdate > $closedto) {
+
+ if (! $form->{id}) {
+ delete $button{'delete'};
+ }
+
+ delete $button{'print_and_post'} unless ${LedgerSMB::Sysconfig::latex};
+ } else {
+ for ('print', 'post', 'print_and_post', 'delete') { delete $button{$_} }
+ }
+
+ for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
+
+ print qq|<p>
+ <input type=text size=1 value="B" accesskey="B" title="[Alt-B]">\n|;
+
+ if ($form->{partsgroup}) {
+ $form->{partsgroup} =~ s/\r//g;
+ $form->{partsgroup} = $form->quote($form->{partsgroup});
+
+ $spc = ($form->{path} =~ /lynx/) ? "." : " ";
+ print qq|
+<input type=hidden name=nextsub value=lookup_partsgroup>
+<input type=hidden name=partsgroup value="$form->{partsgroup}">|;
+
+ foreach $item (split /\n/, $form->{partsgroup}) {
+ ($partsgroup, $translation) = split /--/, $item;
+ $item = ($translation) ? $translation : $partsgroup;
+ print qq| <button class="submit" type="submit" name="action" value="$spc$item">$spc$item</button>\n| if $item;
+ }
+ }
+ }
+
+ if ($form->{lynx}) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ $form->hide_form(qw(rowcount callback path login sessionid));
+
+ print qq|</form>|;
+
+ if (!$form->{dontdisplayend}){
+ print qq|
+</body>
+</html>
+|;
+ }
+}
+
+
+sub post {
+
+ $form->{media} = 'Printer';
+ $form->isblank("customer", $locale->text('Customer missing!'));
+
+ # if oldcustomer ne customer redo form
+ $customer = $form->{customer};
+ $customer =~ s/--.*//g;
+ $customer .= "--$form->{customer_id}";
+ if ($customer ne $form->{oldcustomer}) {
+ &update;
+ exit;
+ }
+
+ &validate_items;
+ &print;
+
+ $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
+
+ $paid = 0;
+ for (1 .. $form->{paidaccounts}) { $paid += $form->parse_amount(\%myconfig, $form->{"paid_$_"}); }
+ delete $form->{datepaid} unless $paid;
+
+ $total = $form->parse_amount(\%myconfig, $form->{invtotal});
+
+ # deduct change from first payment
+ #$form->{"paid_1"} = $form->{invtotal} if $paid > $total;
+ $form->{paid} = $paid;
+ if ($paid > $total){
+ ++$form->{paidaccounts};
+ my $pa = $form->{paidaccounts};
+ $form->{"paid_$pa"} = $total - $paid;
+ $form->{"source_$pa"} = 'cash';
+ $form->{"exchangerate_$pa"} = 0;
+ $form->{"AR_paid_$pa"} = $form->{AR_paid_1}
+ }
+
+ ($form->{AR}) = split /--/, $form->{AR};
+
+ if (IS->post_invoice(\%myconfig, \%$form)) {
+ $form->redirect($locale->text('Posted!'));
+ } else {
+ $form->error($locale->text('Cannot post transaction!'));
+ }
+
+}
+
+
+sub display_row {
+ my $numrows = shift;
+
+ @column_index = qw(partnumber description partsgroup qty unit sellprice discount linetotal);
+
+ $form->{invsubtotal} = 0;
+
+ for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0; }
+
+ $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
+ $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|;
+ $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
+ $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
+ $column_data{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Price').qq|</th>|;
+ $column_data{linetotal} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;
+ $column_data{discount} = qq|<th class=listheading nowrap>%</th>|;
+
+ print qq|
+ <tr>
+ <td>
+ <table width=100%>
+ <tr class=listheading>|;
+
+ for (@column_index) { print "\n$column_data{$_}"; };
+
+ print qq|
+ </tr>
+|;
+
+ $exchangerate = $form->parse_amount(\%myconfig, $form->{exchangerate});
+ $exchangerate = ($exchangerate) ? $exchangerate : 1;
+
+ for $i (1 .. $numrows) {
+ # undo formatting
+ for (qw(qty discount sellprice)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}); }
+
+ ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
+ $dec = length $dec;
+ $decimalplaces = ($dec > 2) ? $dec : 2;
+
+ if (($form->{"qty_$i"} != $form->{"oldqty_$i"}) || ($form->{currency} ne $form->{oldcurrency})) {
+ # check for a pricematrix
+ @a = split / /, $form->{"pricematrix_$i"};
+ if (scalar @a) {
+ foreach $item (@a) {
+ ($q, $p) = split /:/, $item;
+ if (($p * 1) && ($form->{"qty_$i"} >= ($q * 1))) {
+ ($dec) = ($p =~ /\.(\d+)/);
+ $dec = length $dec;
+ $decimalplaces = ($dec > 2) ? $dec : 2;
+ $form->{"sellprice_$i"} = $form->round_amount($p / $exchangerate, $decimalplaces);
+ }
+ }
+ }
+ }
+
+ if ($i < $numrows) {
+ $column_data{discount} = qq|<td align=right><input name="discount_$i" size=3 value=|.$form->format_amount(\%myconfig, $form->{"discount_$i"}).qq|></td>|;
+ } else {
+ $column_data{discount} = qq|<td></td>|;
+ }
+
+ $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces);
+ $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
+ $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
+
+ for (qw(partnumber sku description partsgroup unit)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}); }
+
+ $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=20 value="$form->{"partnumber_$i"}" accesskey="$i" title="[Alt-$i]"></td>|;
+
+ if (($rows = $form->numtextrows($form->{"description_$i"}, 40, 6)) > 1) {
+ $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=46 wrap=soft>$form->{"description_$i"}</textarea></td>|;
+ } else {
+ $column_data{description} = qq|<td><input name="description_$i" size=48 value="$form->{"description_$i"}"></td>|;
+ }
+
+ $column_data{qty} = qq|<td align=right><input name="qty_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|;
+ $column_data{unit} = qq|<td>$form->{"unit_$i"}</td>|;
+ $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;
+ $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|;
+
+ print qq|
+ <tr valign=top>|;
+
+ for (@column_index) { print "\n$column_data{$_}"; }
+
+ print qq|
+ </tr>
+|;
+
+ $form->{"oldqty_$i"} = $form->{"qty_$i"};
+
+ for (qw(id listprice lastcost taxaccounts pricematrix oldqty sku partsgroup unit inventory_accno_id income_accno_id expense_accno_id)) { $form->hide_form("${_}_$i") }
+
+ for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $linetotal; }
+
+ $form->{invsubtotal} += $linetotal;
+ }
+
+ print qq|
+ </table>
+ </td>
+ </tr>
+
+<input type=hidden name=oldcurrency value=$form->{currency}>
+
+|;
+
+}
+
+
+sub print {
+ if (!$form->{invnumber}){
+ $form->{invnumber} = $form->update_defaults(\%myconfig, 'sinumber');
+ }
+ $rc = $form->{'rowcount'};
+ $pc = $form->{'paidaccounts'};
+ if ($form->{"partnumber_$rc"} || $form->{"description_$rc"} ||
+ $form->{"paid_$pc"}){
+ &update;
+ exit;
+ }
+ for $i (1 .. $rc - 1){
+ if ($form->{"qty_$i"} != $form->{"oldqty_$i"}){
+ &update;
+ exit;
+ }
+ }
+
+ if (!$form->{invnumber}) {
+ $form->{invnumber} = $form->update_defaults(\%myconfig, "sinumber");
+ if ($form->{media} eq 'screen') {
+ &update;
+ exit;
+ }
+ }
+
+ $old_form = new Form;
+ for (keys %$form) { $old_form->{$_} = $form->{$_}; }
+
+ for (qw(employee department)) { $form->{$_} =~ s/--.*//g; }
+ $form->{invdate} = $form->{transdate};
+ my @lt = localtime();
+ $form->{dateprinted} = $lt[2].":".$lt[1].":".$lt[0];
+
+ &print_form($old_form);
+
+}
+
+
+sub print_form {
+ my $old_form = shift;
+ &open_drawer;
+
+ # if oldcustomer ne customer redo form
+ $customer = $form->{customer};
+ $customer =~ s/--.*//g;
+ $customer .= "--$form->{customer_id}";
+ if ($customer ne $form->{oldcustomer}) {
+ &update;
+ exit;
+ }
+
+ &validate_items;
+
+ &{ "$form->{vc}_details" };
+
+ @a = ();
+ for (1 .. $form->{rowcount}) { push @a, ("partnumber_$_", "description_$_"); }
+ for (split / /, $form->{taxaccounts}) { push @a, "${_}_description"; }
+ $form->format_string(@a);
+
+ # format payment dates
+ for (1 .. $form->{paidaccounts}) { $form->{"datepaid_$_"} = $locale->date(\%myconfig, $form->{"datepaid_$_"}); }
+
+ IS->invoice_details(\%myconfig, \%$form);
+
+ if ($form->parse_amount(\%myconfig, $form->{total}) <= 0) {
+ $form->{total} = 0;
+ } else {
+ $form->{change} = 0;
+ }
+
+ for (qw(company address tel fax businessnumber)) { $form->{$_} = $myconfig{$_}; }
+ $form->{username} = $myconfig{name};
+
+ $form->{address} =~ s/\\n/\n/g;
+ push @a, qw(company address tel fax businessnumber username);
+ $form->format_string(@a);
+
+ $form->{templates} = "$myconfig{templates}";
+ $form->{IN} = "$form->{type}.$form->{format}";
+
+ if ($form->{format} =~ /(postscript|pdf)/) {
+ $form->{IN} =~ s/$&$/tex/;
+ }
+
+ if ($form->{media} ne 'screen') {
+ $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
+ $form->{printmode} = '|-';
+ }
+
+ $form->{discount} = $form->format_amount(\%myconfig, $form->{discount} * 100);
+
+ $form->{rowcount}--;
+ $form->{pre} = "<body bgcolor=#ffffff>\n<pre>";
+ delete $form->{stylesheet};
+ $form->{cd_open} = $pos_config{rp_cash_drawer_open};
+
+ $form->parse_template(\%myconfig, ${LedgerSMB::Sysconfig::userspath});
+
+ if ($form->{printed} !~ /$form->{formname}/) {
+ $form->{printed} .= " $form->{formname}";
+ $form->{printed} =~ s/^ //;
+
+ $form->update_status(\%myconfig);
+ }
+ $old_form->{printed} = $form->{printed};
+
+ # if we got back here restore the previous form
+ if ($form->{media} ne 'screen') {
+ # restore and display form
+ for (keys %$old_form) { $form->{$_} = $old_form->{$_}; }
+ $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
+
+ for $i (1 .. $form->{paidaccounts}) {
+ for (qw(paid exchangerate)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}); }
+ }
+
+ delete $form->{pre};
+
+ if (! $form->{printandpost}) {
+ $form->{rowcount}--;
+ #&display_form;
+ }
+ }
+
+}
+
+
+sub print_and_post {
+
+ $form->error($locale->text('Select a Printer!')) if ($form->{media} eq 'screen');
+ $form->{printandpost} = 1;
+ &print;
+ &post;
+
+}
+
+sub lookup_partsgroup {
+
+ $form->{action} =~ s/\r//;
+ $form->{action} = substr($form->{action}, 1);
+
+ if ($form->{language_code}) {
+ # get english
+ foreach $item (split /\n/, $form->{partsgroup}) {
+ if ($item =~ /$form->{action}/) {
+ ($partsgroup, $translation) = split /--/, $item;
+ $form->{action} = $partsgroup;
+ last;
+ }
+ }
+ }
+
+ $form->{"partsgroup_$form->{rowcount}"} = $form->{action};
+
+ &update;
+
+}
+
+
+
+sub print_options {
+
+ $form->{PD}{$form->{type}} = "checked";
+
+ print qq|
+<input type=hidden name=format value=$form->{format}>
+<input type=hidden name=formname value=$form->{type}>
+
+<table width=100%>
+ <tr>
+|;
+
+
+ $media = qq|
+ <td><input class=radio type=radio name=media value="screen"></td>
+ <td>|.$locale->text('Screen').qq|</td>|;
+
+ if (%{LedgerSMB::Sysconfig::printer}) {
+ for (keys %{LedgerSMB::Sysconfig::printer}) {
+ $media .= qq|
+ <td><input class=radio type=radio name=media value="$_"></td>
+ <td nowrap>$_</td>
+|;
+ }
+ }
+
+ $media =~ s/(value="\Q$form->{media}\E")/$1 checked/;
+
+ print qq|
+ $media
+
+ <td width=99%>&nbsp;</td>|;
+
+ if ($form->{printed} =~ /$form->{type}/) {
+ print qq|
+ <th>\||.$locale->text('Printed').qq|\|</th>|;
+ }
+
+ print qq|
+ </tr>
+</table>
+|;
+
+}
+
+
+sub receipts {
+
+ $form->{title} = $locale->text('Receipts');
+
+ $form->{db} = 'ar';
+ RP->paymentaccounts(\%myconfig, \%$form);
+
+ $paymentaccounts = "";
+ for (@{ $form->{PR} } ) { $paymentaccounts .= "$_->{accno} "; }
+
+ if (@{ $form->{all_years} }) {
+ # accounting years
+ $form->{selectaccountingyear} = "<option>\n";
+ for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n|; }
+ $form->{selectaccountingmonth} = "<option>\n";
+ for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n|; }
+
+ $selectfrom = qq|
+ <tr>
+ <th align=right>|.$locale->text('Period').qq|</th>
+ <td colspan=3>
+ <select name=month>$form->{selectaccountingmonth}</select>
+ <select name=year>$form->{selectaccountingyear}</select>
+ <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
+ <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
+ <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
+ <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
+ </td>
+ </tr>
+|;
+ }
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+
+<input type=hidden name=title value="$form->{title}">
+<input type=hidden name=paymentaccounts value="$paymentaccounts">
+
+<input type=hidden name=till value=1>
+<input type=hidden name=subtotal value=1>
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>
+ <table>
+
+ <input type=hidden name=nextsub value=list_payments>
+
+ <tr>
+ <th align=right>|.$locale->text('From').qq|</th>
+ <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
+ <th align=right>|.$locale->text('To').qq|</th>
+ <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
+ </tr>
+ $selectfrom
+ <input type=hidden name=sort value=transdate>
+ <input type=hidden name=db value=$form->{db}>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+<br>
+<input type="hidden" name="path" value="$form->{path}">
+<input type="hidden" name="login" value="$form->{login}">
+<input type="hidden" name="sessionid" value="$form->{sessionid}">
+
+<button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+|;
+
+ if ($form->{lynx}) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
+
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
diff --git a/bin/rp.pl b/bin/rp.pl
index 29c49869..bea42005 100755
--- a/bin/rp.pl
+++ b/bin/rp.pl
@@ -1,2544 +1,2546 @@
-#=====================================================================
-# LedgerSMB Small Medium Business Accounting
-# http://www.ledgersmb.org/
-#
-
-# Copyright (C) 2006
-# This work contains copyrighted information from a number of sources all used
-# with permission.
-#
-# This file contains source code included with or based on SQL-Ledger which
-# is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
-# under the GNU General Public License version 2 or, at your option, any later
-# version. For a full list including contact information of contributors,
-# maintainers, and copyright holders, see the CONTRIBUTORS file.
-#
-# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
-# Copyright (c) 2001
-#
-# Author: DWS Systems Inc.
-# Web: http://www.sql-ledger.org
-#
-# Contributors: Antonio Gallardo <agssa@ibw.com.ni>
-# Benjamin Lee <benjaminlee@consultant.com>
-#
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#======================================================================
-#
-# module for preparing Income Statement and Balance Sheet
-#
-#======================================================================
-
-
-require "bin/arap.pl";
-
-use LedgerSMB::PE;
-use LedgerSMB::RP;
-
-1;
-# end of main
-
-# this is for our long dates
-# $locale->text('January')
-# $locale->text('February')
-# $locale->text('March')
-# $locale->text('April')
-# $locale->text('May ')
-# $locale->text('June')
-# $locale->text('July')
-# $locale->text('August')
-# $locale->text('September')
-# $locale->text('October')
-# $locale->text('November')
-# $locale->text('December')
-
-# this is for our short month
-# $locale->text('Jan')
-# $locale->text('Feb')
-# $locale->text('Mar')
-# $locale->text('Apr')
-# $locale->text('May')
-# $locale->text('Jun')
-# $locale->text('Jul')
-# $locale->text('Aug')
-# $locale->text('Sep')
-# $locale->text('Oct')
-# $locale->text('Nov')
-# $locale->text('Dec')
-
-# $locale->text('Balance Sheet')
-# $locale->text('Income Statement')
-# $locale->text('Trial Balance')
-# $locale->text('AR Aging')
-# $locale->text('AP Aging')
-# $locale->text('Tax collected')
-# $locale->text('Tax paid')
-# $locale->text('Receipts')
-# $locale->text('Payments')
-# $locale->text('Project Transactions')
-# $locale->text('Non-taxable Sales')
-# $locale->text('Non-taxable Purchases')
-
-
-sub report {
-
- %report = ( balance_sheet => { title => 'Balance Sheet' },
- income_statement => { title => 'Income Statement' },
- trial_balance => { title => 'Trial Balance' },
- ar_aging => { title => 'AR Aging', vc => 'customer' },
- ap_aging => { title => 'AP Aging', vc => 'vendor' },
- tax_collected => { title => 'Tax collected', vc => 'customer' },
- tax_paid => { title => 'Tax paid' },
- nontaxable_sales => { title => 'Non-taxable Sales', vc => 'customer' },
- nontaxable_purchases => { title => 'Non-taxable Purchases' },
- receipts => { title => 'Receipts', vc => 'customer' },
- payments => { title => 'Payments' },
- projects => { title => 'Project Transactions' },
- inv_activity => { title => 'Inventory Activity'},
- );
-
- $form->{title} = $locale->text($report{$form->{report}}->{title});
-
- $gifi = qq|
-<tr>
- <th align=right>|.$locale->text('Accounts').qq|</th>
- <td><input name=accounttype class=radio type=radio value=standard checked> |.$locale->text('Standard').qq|
-
- <input name=accounttype class=radio type=radio value=gifi> |.$locale->text('GIFI').qq|
- </td>
-</tr>
-|;
-
-
- # get departments
- $form->all_departments(\%myconfig, undef, $report{$form->{report}}->{vc});
- if (@{ $form->{all_department} }) {
- $form->{selectdepartment} = "<option>\n";
-
- for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
- }
-
- $department = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Department').qq|</th>
- <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
- </tr>
-| if $form->{selectdepartment};
-
- if (@{ $form->{all_years} }) {
- # accounting years
- $form->{selectaccountingyear} = "<option>\n";
- for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
-
- $form->{selectaccountingmonth} = "<option>\n";
- for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
-
- $selectfrom = qq|
- <tr>
- <th align=right>|.$locale->text('Period').qq|</th>
- <td colspan=3>
- <select name=month>$form->{selectaccountingmonth}</select>
- <select name=year>$form->{selectaccountingyear}</select>
- <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
- <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
- <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
- <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
- </td>
- </tr>
-|;
-
- $selectto = qq|
- <tr>
- <th align=right></th>
- <td>
- <select name=month>$form->{selectaccountingmonth}</select>
- <select name=year>$form->{selectaccountingyear}</select>
- </td>
- </tr>
-|;
- }
-
-
- $summary = qq|
- <tr>
- <th></th>
- <td><input name=summary type=radio class=radio value=1 checked> |.$locale->text('Summary').qq|
- <input name=summary type=radio class=radio value=0> |.$locale->text('Detail').qq|
- </td>
- </tr>
-|;
-
- # get projects
- $form->all_projects(\%myconfig);
- if (@{ $form->{all_project} }) {
- $form->{selectproject} = "<option>\n";
- for (@{ $form->{all_project} }) { $form->{selectproject} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
-
- $project = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Project').qq|</th>
- <td colspan=3><select name=projectnumber>$form->{selectproject}</select></td>
- </tr>|;
-
- }
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-
-<input type=hidden name=title value="$form->{title}">
-
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>
- <table>
- $department
-|;
-
- if ($form->{report} eq "projects") {
- print qq|
- $project
- <input type=hidden name=nextsub value=generate_projects>
- <tr>
- <th align=right>|.$locale->text('From').qq|</th>
- <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
- <th align=right>|.$locale->text('To').qq|</th>
- <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
- </tr>
- $selectfrom
- </table>
- </td>
- </tr>
- <tr>
- <td>
- <table>
- <tr>
- <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
- <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
- <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|</td>
- </tr>
-|;
- }
-
- if ($form->{report} eq "inv_activity"){
- $gifi = '';
- print qq|
- <input type=hidden name=nextsub value=generate_inv_activity>
- <tr>
- <th align=right>|.$locale->text('From').qq|</th>
- <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
- <th align=right>|.$locale->text('To').qq|</th>
- <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
- </tr>
- <tr>
- <th align=right>|.$locale->text('Period').qq|</th>
- <td colspan=3>
- <select name=frommonth>$form->{selectaccountingmonth}</select>
- <select name=fromyear>$form->{selectaccountingyear}</select>
- <input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq|
- <input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq|
- <input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq|
- <input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq|
- </td>
- </tr>
- </table>
- <table>
- <tr>
- <th>|.$locale->text("Part Number").qq|</th>
- <td><input name=partnumber></td>
- <th>|.$locale->text('Description').qq|</th>
- <td><input type=text name=description></td>
- </tr>|;
- }
- if ($form->{report} eq "income_statement") {
- print qq|
- $project
- <input type=hidden name=nextsub value=generate_income_statement>
- <tr>
- <th align=right>|.$locale->text('From').qq|</th>
- <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
- <th align=right>|.$locale->text('To').qq|</th>
- <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
- </tr>
-|;
-
- if ($selectfrom) {
- print qq|
- <tr>
- <th align=right>|.$locale->text('Period').qq|</th>
- <td colspan=3>
- <select name=frommonth>$form->{selectaccountingmonth}</select>
- <select name=fromyear>$form->{selectaccountingyear}</select>
- <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
- <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
- <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
- <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
- </td>
- </tr>
-|;
- }
-
- print qq|
-
- <tr>
- <th align=right>|.$locale->text('Compare to').qq|</th>
- </tr>
- <tr>
- <th align=right>|.$locale->text('From').qq|</th>
- <td><input name=comparefromdate size=11 title="$myconfig{dateformat}"></td>
- <th align=right>|.$locale->text('To').qq|</th>
- <td><input name=comparetodate size=11 title="$myconfig{dateformat}"></td>
- </tr>
-|;
-
- if ($selectto) {
- print qq|
- <tr>
- <th align=right>|.$locale->text('Period').qq|</th>
- <td>
- <select name=comparemonth>$form->{selectaccountingmonth}</select>
- <select name=compareyear>$form->{selectaccountingyear}</select>
- </td>
- </tr>
-|;
- }
-
- print qq|
- <tr>
- <th align=right>|.$locale->text('Decimalplaces').qq|</th>
- <td><input name=decimalplaces size=3 value=2></td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td>
- <table>
- <tr>
- <th align=right>|.$locale->text('Method').qq|</th>
- <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
- &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
- </tr>
-
- <tr>
- <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
- <td colspan=3><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
- <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
- <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Account Number').qq|</td>
- </tr>
-|;
- }
-
-
- if ($form->{report} eq "balance_sheet") {
- print qq|
- <input type=hidden name=nextsub value=generate_balance_sheet>
- <tr>
- <th align=right>|.$locale->text('as at').qq|</th>
- <td><input name=asofdate size=11 title="$myconfig{dateformat}" value=$form->{asofdate}></td>
-|;
-
- if ($selectfrom) {
- print qq|
- <td>
- <select name=asofmonth>$form->{selectaccountingmonth}</select>
- <select name=asofyear>$form->{selectaccountingyear}</select>
- </td>
-|;
- }
-
- print qq|
- </tr>
-
- <th align=right nowrap>|.$locale->text('Compare to').qq|</th>
- <td><input name=compareasofdate size=11 title="$myconfig{dateformat}"></td>
- <td>
-|;
-
- if ($selectto) {
- print qq|
- <select name=compareasofmonth>$form->{selectaccountingmonth}</select>
- <select name=compareasofyear>$form->{selectaccountingyear}</select>
- </td>
-|;
- }
-
- print qq|
- </tr>
- <tr>
- <th align=right>|.$locale->text('Decimalplaces').qq|</th>
- <td><input name=decimalplaces size=3 value=2></td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td>
- <table>
- <tr>
- <th align=right>|.$locale->text('Method').qq|</th>
- <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
- &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
- </tr>
-
- <tr>
- <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
- <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
- <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
- <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Account Number').qq|</td>
- </tr>
-|;
- }
-
-
- if ($form->{report} eq "trial_balance") {
- print qq|
- <input type=hidden name=nextsub value=generate_trial_balance>
- <tr>
- <th align=right>|.$locale->text('From').qq|</th>
- <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
- <th align=right>|.$locale->text('To').qq|</th>
- <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
- </tr>
- $selectfrom
- </table>
- </td>
- </tr>
- <tr>
- <td>
- <table>
- <tr>
- <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
- <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
- <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
- <input name=all_accounts class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('All Accounts').qq|</td>
- </tr>
-|;
- }
-
-
- if ($form->{report} =~ /^tax_/) {
- $gifi = "";
-
- $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
-
- RP->get_taxaccounts(\%myconfig, \%$form);
-
- print qq|
- <input type=hidden name=nextsub value=generate_tax_report>
- <tr>
- <th align=right>|.$locale->text('From').qq|</th>
- <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
- <th align=right>|.$locale->text('To').qq|</th>
- <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
- </tr>
- $selectfrom
- $summary
- <tr>
- <th align=right>|.$locale->text('Report for').qq|</th>
- <td colspan=3>
-|;
-
- $checked = "checked";
- foreach $ref (@{ $form->{taxaccounts} }) {
-
- print qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked>&nbsp;$ref->{description}
-
- <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
- <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
-
- $checked = "";
-
- }
-
- print qq|
- <input type=hidden name=db value=$form->{db}>
- <input type=hidden name=sort value=transdate>
-
- </td>
- </tr>
-|;
-
-
- if (@{ $form->{gifi_taxaccounts} }) {
- print qq|
- <tr>
- <th align=right>|.$locale->text('GIFI').qq|</th>
- <td colspan=3>
-|;
-
- foreach $ref (@{ $form->{gifi_taxaccounts} }) {
-
- print qq|<input name=accno class=radio type=radio value="gifi_$ref->{accno}">&nbsp;$ref->{description}
-
- <input name="gifi_$ref->{accno}_description" type=hidden value="$ref->{description}">
- <input name="gifi_$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
-
- }
-
- print qq|
- </td>
- </tr>
-|;
- }
-
-
-print qq|
- <tr>
- <th align=right>|.$locale->text('Method').qq|</th>
- <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
- &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td>
- <table>
- <tr>
- <th align=right>|.$locale->text('Include in Report').qq|</th>
- <td>
- <table>
- <tr>
- <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
- <td>|.$locale->text('ID').qq|</td>
- <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
- <td>|.$locale->text('Invoice').qq|</td>
- <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
- <td>|.$locale->text('Date').qq|</td>
- </tr>
- <tr>
- <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
-|;
-
- if ($form->{db} eq 'ar') {
- print qq|<td>|.$locale->text('Customer').qq|</td>|;
- }
- if ($form->{db} eq 'ap') {
- print qq|<td>|.$locale->text('Vendor').qq|</td>|;
- }
-
- print qq|
- <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
- <td>|.$locale->text('Description').qq|</td>
- <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
- <td>|.$locale->text('Amount').qq|</td>
-
- <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
- <td>|.$locale->text('Tax').qq|</td>
-
- <td><input name="l_total" class=checkbox type=checkbox value=Y checked></td>
- <td>|.$locale->text('Total').qq|</td>
- </tr>
- <tr>
- </tr>
- <tr>
- <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
- <td>|.$locale->text('Subtotal').qq|</td>
- </tr>
- </table>
- </td>
- </tr>
-|;
-
- }
-
-
- if ($form->{report} =~ /^nontaxable_/) {
- $gifi = "";
-
- $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
-
- print qq|
- <input type=hidden name=nextsub value=generate_tax_report>
-
- <input type=hidden name=db value=$form->{db}>
- <input type=hidden name=sort value=transdate>
- <input type=hidden name=report value=$form->{report}>
-
- <tr>
- <th align=right>|.$locale->text('From').qq|</th>
- <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
- <th align=right>|.$locale->text('To').qq|</th>
- <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
- </tr>
- $selectfrom
- $summary
- <tr>
- <th align=right>|.$locale->text('Method').qq|</th>
- <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
- &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
- </tr>
- <tr>
- <th align=right>|.$locale->text('Include in Report').qq|</th>
- <td colspan=3>
- <table>
- <tr>
- <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
- <td>|.$locale->text('ID').qq|</td>
- <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
- <td>|.$locale->text('Invoice').qq|</td>
- <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
- <td>|.$locale->text('Date').qq|</td>
- </tr>
- <tr>
- <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
-|;
-
- if ($form->{db} eq 'ar') {
- print qq|<td>|.$locale->text('Customer').qq|</td>|;
- }
- if ($form->{db} eq 'ap') {
- print qq|<td>|.$locale->text('Vendor').qq|</td>|;
- }
-
- print qq|
- <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
- <td>|.$locale->text('Description').qq|</td>
- <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
- <td>|.$locale->text('Amount').qq|</td>
- </tr>
- <tr>
- <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
- <td>|.$locale->text('Subtotal').qq|</td>
- </tr>
- </table>
- </td>
- </tr>
-|;
-
- }
-
-
- if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
- $gifi = "";
-
- if ($form->{report} eq 'ar_aging') {
- $label = $locale->text('Customer');
- $form->{vc} = 'customer';
- } else {
- $label = $locale->text('Vendor');
- $form->{vc} = 'vendor';
- }
-
- $nextsub = "generate_$form->{report}";
-
- # setup vc selection
- $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
-
- for (@{ $form->{"all_$form->{vc}"} }) { $vc .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
-
- $vc = ($vc) ? qq|<select name=$form->{vc}><option>\n$vc</select>| : qq|<input name=$form->{vc} size=35>|;
-
- $postscript = "postscript" if $myconfig{printer};
-
- print qq|
- <tr>
- <th align=right>|.$locale->text($label).qq|</th>
- <td>$vc</td>
- </tr>
- <tr>
- <th align=right>|.$locale->text('To').qq|</th>
- <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
- </tr>
- $selectto
- <input type=hidden name=type value=statement>
- <input type=hidden name=format value=$postscript>
- <input type=hidden name=media value="$myconfig{printer}">
-
- <input type=hidden name=nextsub value=$nextsub>
- <input type=hidden name=action value=$nextsub>
- $summary
- <tr>
- <table>
- <tr>
- <th>|.$locale->text('Include in Report').qq|</th>
-
- <td>
- <table>
- <tr>
- <td nowrap><input name=overdue type=radio class=radio value=0 checked> |.$locale->text('Aged').qq|</td>
- <td nowrap><input name=overdue type=radio class=radio value=1> |.$locale->text('Overdue').qq|</td>
- </tr>
- <tr>
- <td nowrap width=70><input name=c0 type=checkbox class=checkbox value=1 checked> |.$locale->text('Current').qq|</td>
- <td nowrap width=70><input name=c30 type=checkbox class=checkbox value=1 checked> 30</td>
- <td nowrap width=70><input name=c60 type=checkbox class=checkbox value=1 checked> 60</td>
- <td nowrap width=70><input name=c90 type=checkbox class=checkbox value=1 checked> 90</td>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </tr>
-
-|;
- }
-
-# above action can be removed if there is more than one input field
-
-
- if ($form->{report} =~ /(receipts|payments)$/) {
- $gifi = "";
-
- $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
-
- RP->paymentaccounts(\%myconfig, \%$form);
-
- $selection = "<option>\n";
- foreach $ref (@{ $form->{PR} }) {
- $paymentaccounts .= "$ref->{accno} ";
- $selection .= "<option>$ref->{accno}--$ref->{description}\n";
- }
-
- chop $paymentaccounts;
-
- print qq|
- <input type=hidden name=nextsub value=list_payments>
- <tr>
- <th align=right nowrap>|.$locale->text('Account').qq|</th>
- <td colspan=3><select name=account>$selection</select>
- <input type=hidden name=paymentaccounts value="$paymentaccounts">
- </td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Description').qq|</th>
- <td colspan=3><input name=description size=35></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Source').qq|</th>
- <td colspan=3><input name=source></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Memo').qq|</th>
- <td colspan=3><input name=memo size=30></td>
- </tr>
- <tr>
- <th align=right>|.$locale->text('From').qq|</th>
- <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
- <th align=right>|.$locale->text('To').qq|</th>
- <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
- </tr>
- $selectfrom
- <tr>
- <td align=right><input type=checkbox class=checkbox name=fx_transaction value=1 checked></td>
- <td colspan=3>|.$locale->text('Include Exchange Rate Difference').qq|</td>
- </tr>
- <tr>
- <td align=right><input name=l_subtotal class=checkbox type=checkbox value=Y></td>
- <td align=left colspan=3>|.$locale->text('Subtotal').qq|</th>
- </tr>
-
- <input type=hidden name=db value=$form->{db}>
- <input type=hidden name=sort value=transdate>
-|;
-
- }
-
-
- print qq|
-
-$gifi
-
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<br>
-<input type="hidden" name="path" value="$form->{path}">
-<input type="hidden" name="login" value="$form->{login}">
-<input type="hidden" name="sessionid" value="$form->{sessionid}">
-
-<button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
-
-</form>
-|;
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
-
-</body>
-</html>
-|;
-
-}
-
-
-sub continue { &{$form->{nextsub}} };
-
-sub generate_inv_activity {
- $form->header;
-
- RP->inventory_activity(\%myconfig, \%$form);
-
- $title = $form->escape($form->{title});
-
-# if ($form->{department}) {
-# ($department) = split /--/, $form->{department};
-# $options = $locale->text('Department')." : $department<br>";
-# $department = $form->escape($form->{department});
-# }
-## if ($form->{projectnumber}) {
-# ($projectnumber) = split /--/, $form->{projectnumber};
-# $options .= $locale->text('Project Number')." : $projectnumber<br>";
-# $projectnumber = $form->escape($form->{projectnumber});
-# }
-
- # if there are any dates
- if ($form->{fromdate} || $form->{todate}) {
- if ($form->{fromdate}) {
- $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
- }
- if ($form->{todate}) {
- $todate = $locale->date(\%myconfig, $form->{todate}, 1);
- }
-
- $form->{period} = "$fromdate - $todate";
- } else {
- $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
-
- }
- $options .= $form->{period};
-
- @column_index = qw(partnumber description sold revenue received expense);
-
- $href = qq|rp.pl?path=$form->{path}&action=continue&accounttype=$form->{accounttype}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}|;
-
- $column_header{partnumber} = qq|
- <th class=listheading><a class=listheading href="$href&sort_col=partnumber">|
- .$locale->text('Part Number').qq|</a></th>|;
- $column_header{description} = qq|
- <th class=listheading><a class=listheading href="$href&sort_col=description">|
- .$locale->text('Description').qq|</a></th>|;
- $column_header{sold} = qq|
- <th class=listheading><a class=listheading href="$href&sort_col=sold">|
- .$locale->text('Sold').qq|</a></th>|;
- $column_header{revenue} = qq|
- <th class=listheading><a class=listheading href="$href&sort_col=revenue">|
- .$locale->text('Revenue').qq|</a></th>|;
- $column_header{received} = qq|
- <th class=listheading><a class=listheading href="$href&sort_col=received">|
- .$locale->text('Received').qq|</a></th>|;
- $column_header{expense} = qq|
- <th class=listheading><a class=listheading href="$href&sort_col=expense">|
- .$locale->text('Expense').qq|</a></th>|;
-
-
-
- print qq|
-<body>
-
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>$options</td>
- </tr>
- <tr>
- <td>
- <table width=100%>
- <tr>|;
-
- map { print "$column_header{$_}\n" } @column_index;
-
- print qq|
- </tr>
-|;
-
-
-
- if ($form->{sort_col} eq 'qty' || $form->{sort_col} eq 'revenue'){
- $form->{sort_type} = 'numeric';
- }
- $i = 0;
- $cols = "l_transdate=Y&l_name=Y&l_invnumber=Y&summary=1";
- $dates= "transdatefrom=$form->{fromdate}&transdateto=$form->{todate}&year=$form->{fromyear}&month=$form->{frommonth}&interval=$form->{interval}";
- $base="path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- $form->{callback} = "rp.pl?action=continue&$base";
- $form->{callback} = $form->escape($form->{callback});
- $callback = "callback=$form->{callback}";
- # sort the whole thing by account numbers and display
- foreach $ref (@{ $form->{TB} }) {
- $description = $form->escape($ref->{description});
- $i = $i % 2;
-
- $pnumhref="ic.pl?action=edit&id=$ref->{id}&$base&callback=$form->{callback}";
- $soldhref="ar.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&$callback";
- $rechref="ap.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&callback=$form->{callback}";
-
- $ml = ($ref->{category} =~ /(A|E)/) ? -1 : 1;
-
- $debit = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
- $credit = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
- $begbalance = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, "&nbsp;");
- $endbalance = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2, "&nbsp;");
-
- $ref->{partnumber} = qq|<a href="$pnumhref">$ref->{partnumber}</a>|;
- $ref->{sold} = qq|<a href="$soldhref">$ref->{sold}</a>|;
- $ref->{received} = qq|<a href="$rechref">$ref->{received}<a/>|;
- map { $column_data{$_} = "<td>&nbsp;</td>" }
- @column_index;
-
-
-
- print qq|
- <tr class=listrow$i>
- |;
- map { print "<td>$ref->{$_}</td>\n" } @column_index;
-
- print qq|
- </tr>
-|;
- ++$i;
- }
-
-
- print qq|
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-</body>
-</html>
-|;
-
-}
-
-
-sub generate_income_statement {
-
- $form->{padding} = "&nbsp;&nbsp;";
- $form->{bold} = "<b>";
- $form->{endbold} = "</b>";
- $form->{br} = "<br>";
-
- RP->income_statement(\%myconfig, \%$form);
-
- ($form->{department}) = split /--/, $form->{department};
- ($form->{projectnumber}) = split /--/, $form->{projectnumber};
-
- $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
- $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
-
- # if there are any dates construct a where
- if ($form->{fromdate} || $form->{todate}) {
-
- unless ($form->{todate}) {
- $form->{todate} = $form->current_date(\%myconfig);
- }
-
- $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
- $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
-
- $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
- $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
-
- $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
- $form->{period} = $locale->text('for Period').qq|<br>\n$longfromdate |.$locale->text('To').qq| $longtodate|;
- }
-
- if ($form->{comparefromdate} || $form->{comparetodate}) {
- $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
- $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
-
- $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
- $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
-
- $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
- $form->{period} .= "<br>\n$longcomparefromdate ".$locale->text('To').qq| $longcomparetodate|;
- }
-
- # setup variables for the form
- @a = qw(company address businessnumber);
- for (@a) { $form->{$_} = $myconfig{$_} }
- $form->{address} =~ s/\\n/<br>/g;
-
- $form->{templates} = $myconfig{templates};
-
- $form->{IN} = "income_statement.html";
-
- $form->parse_template;
-
-}
-
-
-sub generate_balance_sheet {
-
- $form->{padding} = "&nbsp;&nbsp;";
- $form->{bold} = "<b>";
- $form->{endbold} = "</b>";
- $form->{br} = "<br>";
-
- RP->balance_sheet(\%myconfig, \%$form);
-
- $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
- $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
-
- ($form->{department}) = split /--/, $form->{department};
-
- # define Current Earnings account
- $padding = ($form->{l_heading}) ? $form->{padding} : "";
- push(@{$form->{equity_account}}, $padding.$locale->text('Current Earnings'));
-
- $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
- $form->{last_period} = $locale->date(\%myconfig, $form->{compareasofdate}, 0);
-
- $form->{IN} = "balance_sheet.html";
-
- # setup company variables for the form
- for (qw(company address businessnumber nativecurr)) { $form->{$_} = $myconfig{$_} }
- $form->{address} =~ s/\\n/<br>/g;
-
- $form->{templates} = $myconfig{templates};
-
- $form->parse_template;
-
-}
-
-
-sub generate_projects {
-
- $form->{nextsub} = "generate_projects";
- $form->{title} = $locale->text('Project Transactions');
-
- RP->trial_balance(\%myconfig, \%$form);
-
- &list_accounts;
-
-}
-
-
-# Antonio Gallardo
-#
-# D.S. Feb 16, 2001
-# included links to display transactions for period entered
-# added headers and subtotals
-#
-sub generate_trial_balance {
-
- # get for each account initial balance, debits and credits
- RP->trial_balance(\%myconfig, \%$form);
-
- $form->{nextsub} = "generate_trial_balance";
- $form->{title} = $locale->text('Trial Balance');
-
- $form->{callback} = "$form->{script}?action=generate_trial_balance";
- for (qw(login path sessionid nextsub fromdate todate month year interval l_heading l_subtotal all_accounts accounttype title)) { $form->{callback} .= "&$_=$form->{$_}" }
- $form->{callback} = $form->escape($form->{callback});
-
- &list_accounts;
-
-}
-
-
-sub list_accounts {
-
- $title = $form->escape($form->{title});
-
- if ($form->{department}) {
- ($department) = split /--/, $form->{department};
- $options = $locale->text('Department')." : $department<br>";
- $department = $form->escape($form->{department});
- }
- if ($form->{projectnumber}) {
- ($projectnumber) = split /--/, $form->{projectnumber};
- $options .= $locale->text('Project Number')." : $projectnumber<br>";
- $projectnumber = $form->escape($form->{projectnumber});
- }
-
- # if there are any dates
- if ($form->{fromdate} || $form->{todate}) {
-
- if ($form->{fromdate}) {
- $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
- }
- if ($form->{todate}) {
- $todate = $locale->date(\%myconfig, $form->{todate}, 1);
- }
-
- $form->{period} = "$fromdate - $todate";
- } else {
- $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
-
- }
- $options .= $form->{period};
-
- @column_index = qw(accno description begbalance debit credit endbalance);
-
- $column_header{accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</th>|;
- $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
- $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</th>|;
- $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</th>|;
- $column_header{begbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
- $column_header{endbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
-
-
- if ($form->{accounttype} eq 'gifi') {
- $column_header{accno} = qq|<th class=listheading>|.$locale->text('GIFI').qq|</th>|;
- }
-
-
- $form->header;
-
- print qq|
-<body>
-
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>$options</td>
- </tr>
- <tr>
- <td>
- <table width=100%>
- <tr>|;
-
- for (@column_index) { print "$column_header{$_}\n" }
-
- print qq|
- </tr>
-|;
-
-
-
- # sort the whole thing by account numbers and display
- foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} }) {
-
- $description = $form->escape($ref->{description});
-
- $href = qq|ca.pl?path=$form->{path}&action=list_transactions&accounttype=$form->{accounttype}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&sort=transdate&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}&prevreport=$form->{callback}|;
-
- if ($form->{accounttype} eq 'gifi') {
- $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description";
- $na = $locale->text('N/A');
- if (!$ref->{accno}) {
- for (qw(accno description)) { $ref->{$_} = $na }
- }
- } else {
- $href .= "&accno=$ref->{accno}&description=$description";
- }
-
- $ml = ($ref->{category} =~ /(A|E)/) ? -1 : 1;
- $ml *= -1 if $ref->{contra};
-
- $debit = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
- $credit = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
- $begbalance = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, "&nbsp;");
- $endbalance = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2, "&nbsp;");
-
-
- if ($ref->{charttype} eq "H" && $subtotal && $form->{l_subtotal}) {
-
- if ($subtotal) {
-
- for (qw(accno begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
-
- $subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, "&nbsp;");
- $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, "&nbsp;");
- $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
- $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
-
- $column_data{description} = "<th class=listsubtotal>$subtotaldescription</th>";
- $column_data{begbalance} = "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
- $column_data{endbalance} = "<th align=right class=listsubtotal>$subtotalendbalance</th>";
- $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</th>";
- $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</th>";
-
- print qq|
- <tr class=listsubtotal>
-|;
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
- </tr>
-|;
- }
- }
-
- if ($ref->{charttype} eq "H") {
- $subtotal = 1;
- $subtotaldescription = $ref->{description};
- $subtotaldebit = $ref->{debit};
- $subtotalcredit = $ref->{credit};
- $subtotalbegbalance = 0;
- $subtotalendbalance = 0;
-
- if ($form->{l_heading}) {
- if (! $form->{all_accounts}) {
- if (($subtotaldebit + $subtotalcredit) == 0) {
- $subtotal = 0;
- next;
- }
- }
- } else {
- $subtotal = 0;
- if ($form->{all_accounts} || ($form->{l_subtotal} && (($subtotaldebit + $subtotalcredit) != 0))) {
- $subtotal = 1;
- }
- next;
- }
-
- for (qw(accno debit credit begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
- $column_data{description} = "<th class=listheading>$ref->{description}</th>";
- }
-
- if ($ref->{charttype} eq "A") {
- $column_data{accno} = "<td><a href=$href>$ref->{accno}</a></td>";
- $column_data{description} = "<td>$ref->{description}</td>";
- $column_data{debit} = "<td align=right>$debit</td>";
- $column_data{credit} = "<td align=right>$credit</td>";
- $column_data{begbalance} = "<td align=right>$begbalance</td>";
- $column_data{endbalance} = "<td align=right>$endbalance</td>";
-
- $totaldebit += $ref->{debit};
- $totalcredit += $ref->{credit};
-
- $cml = ($ref->{contra}) ? -1 : 1;
-
- $subtotalbegbalance += $ref->{balance} * $ml * $cml;
- $subtotalendbalance += ($ref->{balance} + $ref->{amount}) * $ml * $cml;
-
- }
-
-
- if ($ref->{charttype} eq "H") {
- print qq|
- <tr class=listheading>
-|;
- }
- if ($ref->{charttype} eq "A") {
- $i++; $i %= 2;
- print qq|
- <tr class=listrow$i>
-|;
- }
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
- </tr>
-|;
- }
-
-
- # print last subtotal
- if ($subtotal && $form->{l_subtotal}) {
- for (qw(accno begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
- $subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, "&nbsp;");
- $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, "&nbsp;");
- $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
- $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
- $column_data{description} = "<th class=listsubtotal>$subtotaldescription</th>";
- $column_data{begbalance} = "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
- $column_data{endbalance} = "<th align=right class=listsubtotal>$subtotalendbalance</th>";
- $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</th>";
- $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</th>";
-
- print qq|
- <tr class=listsubtotal>
-|;
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
- </tr>
-|;
- }
-
- $totaldebit = $form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;");
- $totalcredit = $form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;");
-
- for (qw(accno description begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
-
- $column_data{debit} = qq|<th align=right class=listtotal>$totaldebit</th>|;
- $column_data{credit} = qq|<th align=right class=listtotal>$totalcredit</th>|;
-
- print qq|
- <tr class=listtotal>
-|;
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-</body>
-</html>
-|;
-
-}
-
-
-sub generate_ar_aging {
-
- # split customer
- ($form->{customer}) = split(/--/, $form->{customer});
- $customer = $form->escape($form->{customer},1);
- $title = $form->escape($form->{title},1);
- $media = $form->escape($form->{media},1);
-
- $form->{ct} = "customer";
- $form->{arap} = "ar";
-
- RP->aging(\%myconfig, \%$form);
-
- $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ar_aging&login=$form->{login}&sessionid=$form->{sessionid}&todate=$form->{todate}&customer=$customer&title=$title&type=$form->{type}&format=$form->{format}&media=$media&summary=$form->{summary}|;
-
- &aging;
-
-}
-
-
-sub generate_ap_aging {
-
- # split vendor
- ($form->{vendor}) = split(/--/, $form->{vendor});
- $vendor = $form->escape($form->{vendor},1);
- $title = $form->escape($form->{title},1);
- $media = $form->escape($form->{media},1);
-
- $form->{ct} = "vendor";
- $form->{arap} = "ap";
-
- RP->aging(\%myconfig, \%$form);
-
- $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ap_aging&login=$form->{login}&sessionid=$form->{sessionid}&todate=$form->{todate}&vendor=$vendor&title=$title&type=$form->{type}&format=$form->{format}&media=$media&summary=$form->{summary}|;
-
- &aging;
-
-}
-
-
-sub aging {
-
- $form->header;
-
- $column_header{statement} = qq|<th class=listheading width=1%>&nbsp;</th>|;
- $column_header{ct} = qq|<th class=listheading width=60%>|.$locale->text(ucfirst $form->{ct}).qq|</th>|;
- $column_header{language} = qq|<th class=listheading>|.$locale->text('Language').qq|</th>|;
- $column_header{invnumber} = qq|<th class=listheading>|.$locale->text('Invoice').qq|</th>|;
- $column_header{ordnumber} = qq|<th class=listheading>|.$locale->text('Order').qq|</th>|;
- $column_header{transdate} = qq|<th class=listheading nowrap>|.$locale->text('Date').qq|</th>|;
- $column_header{duedate} = qq|<th class=listheading nowrap>|.$locale->text('Due Date').qq|</th>|;
- $column_header{c0} = qq|<th class=listheading width=10% nowrap>|.$locale->text('Current').qq|</th>|;
- $column_header{c30} = qq|<th class=listheading width=10% nowrap>30</th>|;
- $column_header{c60} = qq|<th class=listheading width=10% nowrap>60</th>|;
- $column_header{c90} = qq|<th class=listheading width=10% nowrap>90</th>|;
- $column_header{total} = qq|<th class=listheading width=10% nowrap>|.$locale->text('Total').qq|</th>|;
-
- @column_index = qw(statement ct);
-
- if (@{ $form->{all_language} } && $form->{arap} eq 'ar') {
- push @column_index, "language";
- $form->{selectlanguage} = qq|<option>\n|;
-
- for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
- }
-
- @c = ();
- for (qw(c0 c30 c60 c90)) {
- if ($form->{$_}) {
- push @c, $_;
- $form->{callback} .= "&$_=$form->{$_}";
- }
- }
-
- if (!$form->{summary}) {
- push @column_index, qw(invnumber ordnumber transdate duedate);
- }
- push @column_index, @c;
- push @column_index, "total";
-
- $option = $locale->text('Aged');
- if ($form->{overdue}) {
- $option= $locale->text('Aged Overdue');
- $form->{callback} .= "&overdue=$form->{overdue}";
- }
-
- if ($form->{department}) {
- $option .= "\n<br>" if $option;
- ($department) = split /--/, $form->{department};
- $option .= $locale->text('Department')." : $department";
- $department = $form->escape($form->{department},1);
- $form->{callback} .= "&department=$department";
- }
-
- if ($form->{arap} eq 'ar') {
- if ($form->{customer}) {
- $option .= "\n<br>" if $option;
- $option .= $form->{customer};
- }
- }
- if ($form->{arap} eq 'ap') {
- shift @column_index;
- if ($form->{vendor}) {
- $option .= "\n<br>" if $option;
- $option .= $form->{vendor};
- }
- }
-
- $todate = $locale->date(\%myconfig, $form->{todate}, 1);
- $option .= "\n<br>" if $option;
- $option .= $locale->text('for Period')." ".$locale->text('To')." $todate";
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>$option</td>
- </tr>
- <tr>
- <td>
- <table width=100%>
-|;
-
- $ctid = 0;
- $i = 0;
- $k = 0;
- $l = $#{ $form->{AG} };
-
- foreach $ref (@{ $form->{AG} }) {
-
- if ($curr ne $ref->{curr}) {
- $ctid = 0;
- for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
- if ($curr) {
- $c0total = $form->format_amount(\%myconfig, $c0total, 2, "&nbsp");
- $c30total = $form->format_amount(\%myconfig, $c30total, 2, "&nbsp");
- $c60total = $form->format_amount(\%myconfig, $c60total, 2, "&nbsp");
- $c90total = $form->format_amount(\%myconfig, $c90total, 2, "&nbsp");
- $total = $form->format_amount(\%myconfig, $total, 2, "&nbsp");
-
- for (qw(ct statement language)) { $column_data{$_} = qq|<td>&nbsp;</td>| }
- $column_data{c0} = qq|<th align=right>$c0total</th>|;
- $column_data{c30} = qq|<th align=right>$c30total</th>|;
- $column_data{c60} = qq|<th align=right>$c60total</th>|;
- $column_data{c90} = qq|<th align=right>$c90total</th>|;
- $column_data{total} = qq|<th align=right>$total</th>|;
-
- print qq|
- <tr class=listtotal>
-|;
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
- </tr>
-|;
-
- $c0subtotal = 0;
- $c30subtotal = 0;
- $c60subtotal = 0;
- $c90subtotal = 0;
- $subtotal = 0;
-
- $c0total = 0;
- $c30total = 0;
- $c60total = 0;
- $c90total = 0;
- $total = 0;
-
- }
-
- $curr = $ref->{curr};
- print qq|
- <tr>
- <td></td>
- <th>$curr</th>
- </tr>
-
- <tr class=listheading>
-|;
-
- for (@column_index) { print "$column_header{$_}\n" }
-
- print qq|
- </tr>
-|;
- }
-
- $k++;
-
- if ($ctid != $ref->{ctid}) {
-
- $i++;
-
- $column_data{ct} = qq|<td>$ref->{name}</td>|;
-
- if ($form->{selectlanguage}) {
- $form->{"selectlanguage_$i"} = $form->{selectlanguage};
- $form->{"selectlanguage_$i"} =~ s/(<option value="\Q$ref->{language_code}\E")/$1 selected/;
- $column_data{language} = qq|<td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td>|;
- }
-
- $column_data{statement} = qq|<td><input name="statement_$i" type=checkbox class=checkbox value=1 $ref->{checked}>
- <input type=hidden name="$form->{ct}_id_$i" value=$ref->{ctid}>
- <input type=hidden name="curr_$i" value=$ref->{curr}>
- </td>|;
-
- }
-
- $ctid = $ref->{ctid};
-
- for (qw(c0 c30 c60 c90)) { $ref->{$_} = $form->round_amount($ref->{$_} / $ref->{exchangerate}, 2) }
-
- $c0subtotal += $ref->{c0};
- $c30subtotal += $ref->{c30};
- $c60subtotal += $ref->{c60};
- $c90subtotal += $ref->{c90};
-
- $c0total += $ref->{c0};
- $c30total += $ref->{c30};
- $c60total += $ref->{c60};
- $c90total += $ref->{c90};
-
- $ref->{total} = ($ref->{c0} + $ref->{c30} + $ref->{c60} + $ref->{c90});
- $subtotal += $ref->{total};
- $total += $ref->{total};
-
- $ref->{c0} = $form->format_amount(\%myconfig, $ref->{c0}, 2, "&nbsp;");
- $ref->{c30} = $form->format_amount(\%myconfig, $ref->{c30}, 2, "&nbsp;");
- $ref->{c60} = $form->format_amount(\%myconfig, $ref->{c60}, 2, "&nbsp;");
- $ref->{c90} = $form->format_amount(\%myconfig, $ref->{c90}, 2, "&nbsp;");
- $ref->{total} = $form->format_amount(\%myconfig, $ref->{total}, 2, "&nbsp;");
-
- $href = qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=|.$form->escape($form->{callback});
-
- $column_data{invnumber} = qq|<td><a href=$href>$ref->{invnumber}</a></td>|;
- for (qw(ordnumber transdate duedate)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| }
- for (qw(c0 c30 c60 c90 total)) { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
-
- if (!$form->{summary}) {
-
- $j++; $j %= 2;
- print qq|
- <tr class=listrow$j>
-|;
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
- </tr>
-|;
-
- for (qw(ct statement language)) { $column_data{$_} = qq|<td>&nbsp;</td>| }
-
- }
-
- # print subtotal
- $nextid = ($k <= $l) ? $form->{AG}->[$k]->{ctid} : 0;
- if ($ctid != $nextid) {
-
- $c0subtotal = $form->format_amount(\%myconfig, $c0subtotal, 2, "&nbsp");
- $c30subtotal = $form->format_amount(\%myconfig, $c30subtotal, 2, "&nbsp");
- $c60subtotal = $form->format_amount(\%myconfig, $c60subtotal, 2, "&nbsp");
- $c90subtotal = $form->format_amount(\%myconfig, $c90subtotal, 2, "&nbsp");
- $subtotal = $form->format_amount(\%myconfig, $subtotal, 2, "&nbsp");
-
- if ($form->{summary}) {
- $column_data{c0} = qq|<td align=right>$c0subtotal</th>|;
- $column_data{c30} = qq|<td align=right>$c30subtotal</th>|;
- $column_data{c60} = qq|<td align=right>$c60subtotal</th>|;
- $column_data{c90} = qq|<td align=right>$c90subtotal</th>|;
- $column_data{total} = qq|<td align=right>$subtotal</th>|;
-
- $j++; $j %= 2;
- print qq|
- <tr class=listrow$j>
-|;
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
- </tr>
-|;
-
- } else {
-
- for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
-
- $column_data{c0} = qq|<th class=listsubtotal align=right>$c0subtotal</th>|;
- $column_data{c30} = qq|<th class=listsubtotal align=right>$c30subtotal</th>|;
- $column_data{c60} = qq|<th class=listsubtotal align=right>$c60subtotal</th>|;
- $column_data{c90} = qq|<th class=listsubtotal align=right>$c90subtotal</th>|;
- $column_data{total} = qq|<th class=listsubtotal align=right>$subtotal</th>|;
-
- # print subtotals
- print qq|
- <tr class=listsubtotal>
-|;
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
- </tr>
-|;
-
- }
-
- $c0subtotal = 0;
- $c30subtotal = 0;
- $c60subtotal = 0;
- $c90subtotal = 0;
- $subtotal = 0;
-
- }
- }
-
- print qq|
- </tr>
- <tr class=listtotal>
-|;
-
- for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
-
- $c0total = $form->format_amount(\%myconfig, $c0total, 2, "&nbsp;");
- $c30total = $form->format_amount(\%myconfig, $c30total, 2, "&nbsp;");
- $c60total = $form->format_amount(\%myconfig, $c60total, 2, "&nbsp;");
- $c90total = $form->format_amount(\%myconfig, $c90total, 2, "&nbsp;");
- $total = $form->format_amount(\%myconfig, $total, 2, "&nbsp;");
-
- $column_data{c0} = qq|<th align=right class=listtotal>$c0total</th>|;
- $column_data{c30} = qq|<th align=right class=listtotal>$c30total</th>|;
- $column_data{c60} = qq|<th align=right class=listtotal>$c60total</th>|;
- $column_data{c90} = qq|<th align=right class=listtotal>$c90total</th>|;
- $column_data{total} = qq|<th align=right class=listtotal>$total</th>|;
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
- </tr>
- <input type=hidden name=rowcount value=$i>
- </table>
- </td>
- </tr>
-
- <tr>
- <td>
-|;
-
- &print_options if ($form->{arap} eq 'ar');
-
- print qq|
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-|;
-
- if ($form->{arap} eq 'ar') {
-
- $form->hide_form(qw(todate title summary overdue c0 c30 c60 c90 callback arap ct department path login sessionid));
-
- print qq|
-<input type=hidden name=$form->{ct} value="$form->{$form->{ct}}">
-|;
-
-# type=submit $locale->text('Select all')
-# type=submit $locale->text('Print')
-# type=submit $locale->text('E-mail')
-
- %button = ('select_all' => { ndx => 1, key => 'A', value => $locale->text('Select all') },
- 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
- 'e_mail' => { ndx => 5, key => 'E', value => $locale->text('E-mail') },
- );
-
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
-
- }
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
-sub select_all {
-
- RP->aging(\%myconfig, \%$form);
-
- for (@{ $form->{AG} }) { $_->{checked} = "checked" }
-
- &aging;
-
-}
-
-
-sub print_options {
-
- $form->{sendmode} = "attachment";
- $form->{copies} = 1 unless $form->{copies};
-
- $form->{PD}{$form->{type}} = "selected";
- $form->{DF}{$form->{format}} = "selected";
- $form->{SM}{$form->{sendmode}} = "selected";
-
- $format = qq|
- <option value=html $form->{PD}{format}>html|;
-
- $type = qq|
- <option value=statement $form->{PD}{statement}>|.$locale->text('Statement');
-
-
- if ($form->{media} eq 'email') {
- $media = qq|
- <td><select name=sendmode>
- <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq|
- <option value=inline $form->{SM}{inline}>|.$locale->text('In-line');
- } else {
- $media = qq|
- <td><select name=media>
- <option value=screen>|.$locale->text('Screen');
- if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
- for (sort keys %{LedgerSMB::Sysconfig::printer}) { $media .= qq|
- <option value="$_">$_| }
- }
- }
-
- $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
- $media .= qq|</select></td>|;
-
- if (${LedgerSMB::Sysconfig::latex}) {
- $format .= qq|
- <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq|
- <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF');
- }
-
- print qq|
-<table>
- <tr>
- <td><select name=type>$type</select></td>
- <td><select name=format>$format</select></td>
- $media
-|;
-
- if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} && $form->{media} ne 'email') {
- print qq|
- <td>|.$locale->text('Copies').qq|
- <input name=copies size=2 value=$form->{copies}></td>
-|;
- }
-
- print qq|
- </tr>
-</table>
-|;
-
-}
-
-
-sub e_mail {
-
- # get name and email addresses
- for $i (1 .. $form->{rowcount}) {
- if ($form->{"statement_$i"}) {
- $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
- $form->{"statement_1"} = 1;
- $form->{"language_code_1"} = $form->{"language_code_$i"};
- $form->{"curr_1"} = $form->{"curr_$i"};
- RP->get_customer(\%myconfig, \%$form);
- $selected = 1;
- last;
- }
- }
-
- $form->error($locale->text('Nothing selected!')) unless $selected;
-
- if ($myconfig{role} =~ /(admin|manager)/) {
- $bcc = qq|
- <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
- <td><input name=bcc size=30 value="$form->{bcc}"></td>
-|;
- }
-
- $title = $locale->text('E-mail Statement to [_1]', $form->{$form->{ct}});
-
- $form->{media} = "email";
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-
-<table width=100%>
- <tr class=listtop>
- <th>$title</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>
- <table width=100%>
- <tr>
- <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
- <td><input name=email size=30 value="$form->{email}"></td>
- <th align=right nowrap>|.$locale->text('Cc').qq|</th>
- <td><input name=cc size=30 value="$form->{cc}"></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Subject').qq|</th>
- <td><input name=subject size=30 value="$form->{subject}"></td>
- $bcc
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td>
- <table width=100%>
- <tr>
- <th align=left nowrap>|.$locale->text('Message').qq|</th>
- </tr>
- <tr>
- <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td>
-|;
-
- &print_options;
-
- for (qw(email cc bcc subject message type sendmode format action nextsub)) { delete $form->{$_} }
-
- $form->hide_form;
-
- print qq|
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<input type="hidden" name="nextsub" value="send_email">
-
-<br>
-<button name="action" class="submit" type="submit" value="continue">|.$locale->text('Continue').qq|</button>
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
-sub send_email {
-
- $form->{OUT} = "${LedgerSMB::Sysconfig::sendmail}";
-
- $form->{subject} = $locale->text('Statement - [_1]', $form->{todate}) unless $form->{subject};
- $form->isblank("email", $locale->text('E-mail address missing!'));
-
- RP->aging(\%myconfig, \%$form);
-
- &print_form;
-
- $form->redirect($locale->text('Statement sent to [_1]', $form->{$form->{ct}}));
-
-}
-
-
-
-sub print {
-
- if ($form->{media} !~ /(screen|email)/) {
- $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/);
- }
-
- for $i (1 .. $form->{rowcount}) {
- if ($form->{"statement_$i"}) {
- $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
- $language_code = $form->{"language_code_$i"};
- $curr = $form->{"curr_$i"};
- $selected = 1;
- last;
- }
- }
-
- $form->error($locale->text('Nothing selected!')) unless $selected;
-
-
- if ($form->{media} !~ /(screen|email)/) {
- $form->{OUT} = "| ${LedgerSMB::Sysconfig::printer}{$form->{media}}";
- $form->{"$form->{ct}_id"} = "";
- $SIG{INT} = 'IGNORE';
- } else {
- $form->{"statement_1"} = 1;
- $form->{"language_code_1"} = $language_code;
- $form->{"curr_1"} = $curr;
- }
-
- RP->aging(\%myconfig, \%$form);
-
- &print_form;
-
- $form->redirect($locale->text('Statements sent to printer!')) if ($form->{media} !~ /(screen|email)/);
-
-}
-
-
-sub print_form {
-
- $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
-
- $form->{templates} = "$myconfig{templates}";
-
- # setup variables for the form
- @a = qw(company address businessnumber tel fax);
- for (@a) { $form->{$_} = $myconfig{$_} }
- $form->{address} =~ s/\\n/\n/g;
-
- $form->format_string(@a);
-
- $form->{IN} = "$form->{type}.html";
-
- if ($form->{format} eq 'postscript') {
- $form->{IN} =~ s/html$/tex/;
- }
- if ($form->{format} eq 'pdf') {
- $form->{IN} =~ s/html$/tex/;
- }
-
- @a = qw(name address1 address2 city state zipcode country contact);
- push @a, "$form->{ct}phone", "$form->{ct}fax", "$form->{ct}taxnumber";
- push @a, 'email' if ! $form->{media} eq 'email';
-
- $i = 0;
- while (@{ $form->{AG} }) {
-
- $ref = shift @{ $form->{AG} };
-
- if ($ctid != $ref->{ctid}) {
-
- $ctid = $ref->{ctid};
- $i++;
-
- if ($form->{"statement_$i"}) {
-
- for (@a) { $form->{$_} = $ref->{$_} }
- $form->format_string(@a);
-
- $form->{$form->{ct}} = $form->{name};
- $form->{"$form->{ct}_id"} = $ref->{ctid};
- $form->{language_code} = $form->{"language_code_$i"};
- $form->{currency} = $form->{"curr_$i"};
-
- for (qw(invnumber ordnumber ponumber notes invdate duedate)) { $form->{$_} = () }
- $form->{total} = 0;
- foreach $item (qw(c0 c30 c60 c90)) {
- $form->{$item} = ();
- $form->{"${item}total"} = 0;
- }
-
- &statement_details($ref) if $ref->{curr} eq $form->{currency};
-
- while ($ref) {
-
- if (scalar (@{ $form->{AG} }) > 0) {
- # one or more left to go
- if ($ctid == $form->{AG}->[0]->{ctid}) {
- $ref = shift @{ $form->{AG} };
- &statement_details($ref) if $ref->{curr} eq $form->{currency};
- # any more?
- $ref = scalar (@{ $form->{AG} });
- } else {
- $ref = 0;
- }
- } else {
- # set initial ref to 0
- $ref = 0;
- }
-
- }
-
- for ("c0", "c30", "c60", "c90", "") { $form->{"${_}total"} = $form->format_amount(\%myconfig, $form->{"${_}total"}, 2) }
-
- $form->parse_template(\%myconfig, ${LedgerSMB::Sysconfig::userspath});
-
- }
- }
- }
-
-}
-
-
-sub statement_details {
- my ($ref) = @_;
-
- $ref->{invdate} = $ref->{transdate};
- my @a = qw(invnumber ordnumber ponumber notes invdate duedate);
- for (@a) { $form->{"${_}_1"} = $ref->{$_} }
- $form->format_string(qw(invnumber_1 ordnumber_1 ponumber_1 notes_1));
- for (@a) { push @{ $form->{$_} }, $form->{"${_}_1"} }
-
- foreach $item (qw(c0 c30 c60 c90)) {
- eval { $ref->{$item} = $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2) };
- $form->{"${item}total"} += $ref->{$item};
- $form->{total} += $ref->{$item};
- push @{ $form->{$item} }, $form->format_amount(\%myconfig, $ref->{$item}, 2);
- }
-
-}
-
-
-sub generate_tax_report {
-
- RP->tax_report(\%myconfig, \%$form);
-
- $descvar = "$form->{accno}_description";
- $description = $form->escape($form->{$descvar});
- $ratevar = "$form->{accno}_rate";
- $taxrate = $form->{"$form->{accno}_rate"};
-
- if ($form->{accno} =~ /^gifi_/) {
- $descvar = "gifi_$form->{accno}_description";
- $description = $form->escape($form->{$descvar});
- $ratevar = "gifi_$form->{accno}_rate";
- $taxrate = $form->{"gifi_$form->{accno}_rate"};
- }
-
- $department = $form->escape($form->{department});
-
- # construct href
- $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
-
- # construct callback
- $description = $form->escape($form->{$descvar},1);
- $department = $form->escape($form->{department},1);
-
- $form->sort_order();
-
- $callback = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
-
- $form->{title} = $locale->text('GIFI')." - " if ($form->{accno} =~ /^gifi_/);
-
- $title = $form->escape($form->{title});
- $href .= "&title=$title";
- $title = $form->escape($form->{title},1);
- $callback .= "&title=$title";
-
- $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
-
- @columns = $form->sort_columns(qw(id transdate invnumber name description netamount tax total));
-
- $form->{"l_description"} = "" if $form->{summary};
-
- foreach $item (@columns) {
- if ($form->{"l_$item"} eq "Y") {
- push @column_index, $item;
-
- # add column to href and callback
- $callback .= "&l_$item=Y";
- $href .= "&l_$item=Y";
- }
- }
-
-
- if ($form->{l_subtotal} eq 'Y') {
- $callback .= "&l_subtotal=Y";
- $href .= "&l_subtotal=Y";
- }
-
-
- if ($form->{department}) {
- ($department) = split /--/, $form->{department};
- $option = $locale->text('Department')." : $department";
- }
-
- # if there are any dates
- if ($form->{fromdate} || $form->{todate}) {
- if ($form->{fromdate}) {
- $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
- }
- if ($form->{todate}) {
- $todate = $locale->date(\%myconfig, $form->{todate}, 1);
- }
-
- $form->{period} = "$fromdate - $todate";
- } else {
- $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
- }
-
-
- if ($form->{db} eq 'ar') {
- $name = $locale->text('Customer');
- $invoice = 'is.pl';
- $arap = 'ar.pl';
- }
- if ($form->{db} eq 'ap') {
- $name = $locale->text('Vendor');
- $invoice = 'ir.pl';
- $arap = 'ap.pl';
- }
-
- $option .= "<br>" if $option;
- $option .= "$form->{period}";
-
-
- $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>|.$locale->text('ID').qq|</th>|;
- $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice').qq|</th>|;
- $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</th>|;
- $column_header{netamount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
- $column_header{tax} = qq|<th class=listheading>|.$locale->text('Tax').qq|</th>|;
- $column_header{total} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;
-
- $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
-
- $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</th>|;
-
-
- $form->header;
-
- print qq|
-<body>
-
-<table width=100%>
- <tr>
- <th class=listtop colspan=$colspan>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>$option</td>
- </tr>
- <tr>
- <td>
- <table width=100%>
- <tr class=listheading>
-|;
-
- for (@column_index) { print "$column_header{$_}\n" }
-
- print qq|
- </tr>
-|;
-
- # add sort and escape callback
- $callback = $form->escape($callback . "&sort=$form->{sort}");
-
- if (@{ $form->{TR} }) {
- $sameitem = $form->{TR}->[0]->{$form->{sort}};
- }
-
- foreach $ref (@{ $form->{TR} }) {
-
- $module = ($ref->{invoice}) ? $invoice : $arap;
- $module = 'ps.pl' if $ref->{till};
-
- if ($form->{l_subtotal} eq 'Y') {
- if ($sameitem ne $ref->{$form->{sort}}) {
- &tax_subtotal;
- $sameitem = $ref->{$form->{sort}};
- }
- }
-
- $totalnetamount += $ref->{netamount};
- $totaltax += $ref->{tax};
- $ref->{total} = $ref->{netamount} + $ref->{tax};
-
- $subtotalnetamount += $ref->{netamount};
- $subtotaltax += $ref->{tax};
-
- for (qw(netamount tax total)) { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;"); }
-
- $column_data{id} = qq|<td>$ref->{id}</td>|;
- $column_data{invnumber} = qq|<td><a href=$module?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}</a></td>|;
-
- for (qw(id transdate name partnumber description)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| }
-
- for (qw(netamount tax total)) { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
-
- $i++; $i %= 2;
- print qq|
- <tr class=listrow$i>
-|;
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
- </tr>
-|;
-
- }
-
- if ($form->{l_subtotal} eq 'Y') {
- &tax_subtotal;
- }
-
-
- for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
-
- print qq|
- </tr>
- <tr class=listtotal>
-|;
-
- $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, "&nbsp;");
- $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;");
- $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, "&nbsp;");
-
- $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
- $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
- $column_data{total} = qq|<th class=listtotal align=right>$total</th>|;
-
- for (@column_index) { print "$column_data{$_}\n" }
-
-
- print qq|
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-</body>
-</html>
-|;
-
-}
-
-
-sub tax_subtotal {
-
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $subtotal = $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax, 2, "&nbsp;");
- $subtotalnetamount = $form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;");
- $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, "&nbsp;");
-
- $column_data{netamount} = "<th class=listsubtotal align=right>$subtotalnetamount</th>";
- $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
- $column_data{total} = "<th class=listsubtotal align=right>$subtotal</th>";
-
- $subtotalnetamount = 0;
- $subtotaltax = 0;
-
- print qq|
- <tr class=listsubtotal>
-|;
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
- </tr>
-|;
-
-}
-
-
-
-sub list_payments {
-
-
- if ($form->{account}) {
- ($form->{paymentaccounts}) = split /--/, $form->{account};
- }
- if ($form->{department}) {
- ($department, $form->{department_id}) = split /--/, $form->{department};
- $option = $locale->text('Department')." : $department";
- }
-
- RP->payments(\%myconfig, \%$form);
-
- @columns = $form->sort_columns(qw(transdate name paid source memo));
-
- if ($form->{till}) {
- @columns = $form->sort_columns(qw(transdate name paid curr source till));
- if ($myconfig{role} ne 'user') {
- @columns = $form->sort_columns(qw(transdate name paid curr source till employee));
- }
- }
-
- # construct href
- $title = $form->escape($form->{title});
- $form->{paymentaccounts} =~ s/ /%20/g;
-
- $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&sort=$form->{sort}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_subtotal}&prepayment=$form->{prepayment}&paymentaccounts=$form->{paymentaccounts}&title=".$form->escape($form->{title});
-
- $form->sort_order();
-
- $form->{callback} = "$form->{script}?path=$form->{path}&direction=$form->{direction}&sort=$form->{sort}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_subtotal}&prepayment=$form->{prepayment}&paymentaccounts=$form->{paymentaccounts}&title=".$form->escape($form->{title},1);
-
- if ($form->{account}) {
- $callback .= "&account=".$form->escape($form->{account},1);
- $href .= "&account=".$form->escape($form->{account});
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Account')." : $form->{account}";
- }
- if ($form->{department}) {
- $callback .= "&department=".$form->escape($form->{department},1);
- $href .= "&department=".$form->escape($form->{department});
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Department')." : $form->{department}";
- }
- if ($form->{description}) {
- $callback .= "&description=".$form->escape($form->{description},1);
- $href .= "&description=".$form->escape($form->{description});
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Description')." : $form->{description}";
- }
- if ($form->{source}) {
- $callback .= "&source=".$form->escape($form->{source},1);
- $href .= "&source=".$form->escape($form->{source});
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Source')." : $form->{source}";
- }
- if ($form->{memo}) {
- $callback .= "&memo=".$form->escape($form->{memo},1);
- $href .= "&memo=".$form->escape($form->{memo});
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Memo')." : $form->{memo}";
- }
- if ($form->{fromdate}) {
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{fromdate}, 1);
- }
- if ($form->{todate}) {
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{todate}, 1);
- }
-
- $callback = $form->escape($form->{callback});
-
- $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text('Description')."</a></th>";
- $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
- $column_header{paid} = "<th class=listheading>".$locale->text('Amount')."</a></th>";
- $column_header{curr} = "<th class=listheading>".$locale->text('Curr')."</a></th>";
- $column_header{source} = "<th><a class=listheading href=$href&sort=source>".$locale->text('Source')."</a></th>";
- $column_header{memo} = "<th><a class=listheading href=$href&sort=memo>".$locale->text('Memo')."</a></th>";
-
- $column_header{employee} = "<th><a class=listheading href=$href&sort=employee>".$locale->text('Salesperson')."</a></th>";
- $column_header{till} = "<th><a class=listheading href=$href&sort=till>".$locale->text('Till')."</a></th>";
-
- @column_index = @columns;
- $colspan = $#column_index + 1;
-
- $form->header;
-
- print qq|
-<body>
-
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>$option</td>
- </tr>
- <tr>
- <td>
- <table width=100%>
- <tr class=listheading>
-|;
-
- for (@column_index) { print "\n$column_header{$_}" }
-
- print qq|
- </tr>
-|;
-
-
- foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
-
- next unless @{ $form->{$ref->{id}} };
-
- print qq|
- <tr>
- <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
- </tr>
-|;
-
- if (@{ $form->{$ref->{id}} }) {
- $sameitem = $form->{$ref->{id}}[0]->{$form->{sort}};
- }
-
- foreach $payment (@{ $form->{$ref->{id}} }) {
-
- if ($form->{l_subtotal}) {
- if ($payment->{$form->{sort}} ne $sameitem) {
- # print subtotal
- &payment_subtotal;
- }
- }
-
- next if ($form->{till} && ! $payment->{till});
-
- $column_data{name} = "<td>$payment->{name}&nbsp;</td>";
- $column_data{transdate} = "<td>$payment->{transdate}&nbsp;</td>";
- $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $payment->{paid}, 2, "&nbsp;")."</td>";
- $column_data{curr} = "<td>$payment->{curr}</td>";
- $column_data{source} = "<td>$payment->{source}&nbsp;</td>";
- $column_data{memo} = "<td>$payment->{memo}&nbsp;</td>";
- $column_data{employee} = "<td>$payment->{employee}&nbsp;</td>";
- $column_data{till} = "<td>$payment->{till}&nbsp;</td>";
-
- $subtotalpaid += $payment->{paid};
- $accounttotalpaid += $payment->{paid};
- $totalpaid += $payment->{paid};
-
- $i++; $i %= 2;
- print qq|
- <tr class=listrow$i>
-|;
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
- </tr>
-|;
-
- $sameitem = $payment->{$form->{sort}};
-
- }
-
- &payment_subtotal if $form->{l_subtotal};
-
- # print account totals
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $accounttotalpaid, 2, "&nbsp;")."</th>";
-
- print qq|
- <tr class=listtotal>
-|;
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
- </tr>
-|;
-
- $accounttotalpaid = 0;
-
- }
-
-
- # print total
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;")."</th>";
-
- print qq|
- <tr class=listtotal>
-|;
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
- </tr>
-
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-|;
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
-
-</body>
-</html>
-|;
-
-}
-
-
-sub payment_subtotal {
-
- if ($subtotalpaid != 0) {
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, "&nbsp;")."</th>";
-
- print qq|
- <tr class=listsubtotal>
-|;
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
- </tr>
-|;
- }
-
- $subtotalpaid = 0;
-
-}
-
-
+#=====================================================================
+# LedgerSMB Small Medium Business Accounting
+# http://www.ledgersmb.org/
+#
+
+# Copyright (C) 2006
+# This work contains copyrighted information from a number of sources all used
+# with permission.
+#
+# This file contains source code included with or based on SQL-Ledger which
+# is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
+# under the GNU General Public License version 2 or, at your option, any later
+# version. For a full list including contact information of contributors,
+# maintainers, and copyright holders, see the CONTRIBUTORS file.
+#
+# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
+# Copyright (c) 2001
+#
+# Author: DWS Systems Inc.
+# Web: http://www.sql-ledger.org
+#
+# Contributors: Antonio Gallardo <agssa@ibw.com.ni>
+# Benjamin Lee <benjaminlee@consultant.com>
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#======================================================================
+#
+# module for preparing Income Statement and Balance Sheet
+#
+#======================================================================
+
+
+require "bin/arap.pl";
+
+use LedgerSMB::PE;
+use LedgerSMB::RP;
+
+1;
+# end of main
+
+# this is for our long dates
+# $locale->text('January')
+# $locale->text('February')
+# $locale->text('March')
+# $locale->text('April')
+# $locale->text('May ')
+# $locale->text('June')
+# $locale->text('July')
+# $locale->text('August')
+# $locale->text('September')
+# $locale->text('October')
+# $locale->text('November')
+# $locale->text('December')
+
+# this is for our short month
+# $locale->text('Jan')
+# $locale->text('Feb')
+# $locale->text('Mar')
+# $locale->text('Apr')
+# $locale->text('May')
+# $locale->text('Jun')
+# $locale->text('Jul')
+# $locale->text('Aug')
+# $locale->text('Sep')
+# $locale->text('Oct')
+# $locale->text('Nov')
+# $locale->text('Dec')
+
+# $locale->text('Balance Sheet')
+# $locale->text('Income Statement')
+# $locale->text('Trial Balance')
+# $locale->text('AR Aging')
+# $locale->text('AP Aging')
+# $locale->text('Tax collected')
+# $locale->text('Tax paid')
+# $locale->text('Receipts')
+# $locale->text('Payments')
+# $locale->text('Project Transactions')
+# $locale->text('Non-taxable Sales')
+# $locale->text('Non-taxable Purchases')
+
+
+sub report {
+
+ %report = ( balance_sheet => { title => 'Balance Sheet' },
+ income_statement => { title => 'Income Statement' },
+ trial_balance => { title => 'Trial Balance' },
+ ar_aging => { title => 'AR Aging', vc => 'customer' },
+ ap_aging => { title => 'AP Aging', vc => 'vendor' },
+ tax_collected => { title => 'Tax collected', vc => 'customer' },
+ tax_paid => { title => 'Tax paid' },
+ nontaxable_sales => { title => 'Non-taxable Sales', vc => 'customer' },
+ nontaxable_purchases => { title => 'Non-taxable Purchases' },
+ receipts => { title => 'Receipts', vc => 'customer' },
+ payments => { title => 'Payments' },
+ projects => { title => 'Project Transactions' },
+ inv_activity => { title => 'Inventory Activity'},
+ );
+
+ $form->{title} = $locale->text($report{$form->{report}}->{title});
+
+ $gifi = qq|
+<tr>
+ <th align=right>|.$locale->text('Accounts').qq|</th>
+ <td><input name=accounttype class=radio type=radio value=standard checked> |.$locale->text('Standard').qq|
+
+ <input name=accounttype class=radio type=radio value=gifi> |.$locale->text('GIFI').qq|
+ </td>
+</tr>
+|;
+
+
+ # get departments
+ $form->all_departments(\%myconfig, undef, $report{$form->{report}}->{vc});
+ if (@{ $form->{all_department} }) {
+ $form->{selectdepartment} = "<option>\n";
+
+ for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
+ }
+
+ $department = qq|
+ <tr>
+ <th align=right nowrap>|.$locale->text('Department').qq|</th>
+ <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
+ </tr>
+| if $form->{selectdepartment};
+
+ if (@{ $form->{all_years} }) {
+ # accounting years
+ $form->{selectaccountingyear} = "<option>\n";
+ for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
+
+ $form->{selectaccountingmonth} = "<option>\n";
+ for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
+
+ $selectfrom = qq|
+ <tr>
+ <th align=right>|.$locale->text('Period').qq|</th>
+ <td colspan=3>
+ <select name=month>$form->{selectaccountingmonth}</select>
+ <select name=year>$form->{selectaccountingyear}</select>
+ <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
+ <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
+ <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
+ <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
+ </td>
+ </tr>
+|;
+
+ $selectto = qq|
+ <tr>
+ <th align=right></th>
+ <td>
+ <select name=month>$form->{selectaccountingmonth}</select>
+ <select name=year>$form->{selectaccountingyear}</select>
+ </td>
+ </tr>
+|;
+ }
+
+
+ $summary = qq|
+ <tr>
+ <th></th>
+ <td><input name=summary type=radio class=radio value=1 checked> |.$locale->text('Summary').qq|
+ <input name=summary type=radio class=radio value=0> |.$locale->text('Detail').qq|
+ </td>
+ </tr>
+|;
+
+ # get projects
+ $form->all_projects(\%myconfig);
+ if (@{ $form->{all_project} }) {
+ $form->{selectproject} = "<option>\n";
+ for (@{ $form->{all_project} }) { $form->{selectproject} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
+
+ $project = qq|
+ <tr>
+ <th align=right nowrap>|.$locale->text('Project').qq|</th>
+ <td colspan=3><select name=projectnumber>$form->{selectproject}</select></td>
+ </tr>|;
+
+ }
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+
+<input type=hidden name=title value="$form->{title}">
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>
+ <table>
+ $department
+|;
+
+ if ($form->{report} eq "projects") {
+ print qq|
+ $project
+ <input type=hidden name=nextsub value=generate_projects>
+ <tr>
+ <th align=right>|.$locale->text('From').qq|</th>
+ <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
+ <th align=right>|.$locale->text('To').qq|</th>
+ <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
+ </tr>
+ $selectfrom
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <table>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
+ <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
+ <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|</td>
+ </tr>
+|;
+ }
+
+ if ($form->{report} eq "inv_activity"){
+ $gifi = '';
+ print qq|
+ <input type=hidden name=nextsub value=generate_inv_activity>
+ <tr>
+ <th align=right>|.$locale->text('From').qq|</th>
+ <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
+ <th align=right>|.$locale->text('To').qq|</th>
+ <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
+ </tr>
+ <tr>
+ <th align=right>|.$locale->text('Period').qq|</th>
+ <td colspan=3>
+ <select name=frommonth>$form->{selectaccountingmonth}</select>
+ <select name=fromyear>$form->{selectaccountingyear}</select>
+ <input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq|
+ <input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq|
+ <input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq|
+ <input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq|
+ </td>
+ </tr>
+ </table>
+ <table>
+ <tr>
+ <th>|.$locale->text("Part Number").qq|</th>
+ <td><input name=partnumber></td>
+ <th>|.$locale->text('Description').qq|</th>
+ <td><input type=text name=description></td>
+ </tr>|;
+ }
+ if ($form->{report} eq "income_statement") {
+ print qq|
+ $project
+ <input type=hidden name=nextsub value=generate_income_statement>
+ <tr>
+ <th align=right>|.$locale->text('From').qq|</th>
+ <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
+ <th align=right>|.$locale->text('To').qq|</th>
+ <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
+ </tr>
+|;
+
+ if ($selectfrom) {
+ print qq|
+ <tr>
+ <th align=right>|.$locale->text('Period').qq|</th>
+ <td colspan=3>
+ <select name=frommonth>$form->{selectaccountingmonth}</select>
+ <select name=fromyear>$form->{selectaccountingyear}</select>
+ <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
+ <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
+ <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
+ <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
+ </td>
+ </tr>
+|;
+ }
+
+ print qq|
+
+ <tr>
+ <th align=right>|.$locale->text('Compare to').qq|</th>
+ </tr>
+ <tr>
+ <th align=right>|.$locale->text('From').qq|</th>
+ <td><input name=comparefromdate size=11 title="$myconfig{dateformat}"></td>
+ <th align=right>|.$locale->text('To').qq|</th>
+ <td><input name=comparetodate size=11 title="$myconfig{dateformat}"></td>
+ </tr>
+|;
+
+ if ($selectto) {
+ print qq|
+ <tr>
+ <th align=right>|.$locale->text('Period').qq|</th>
+ <td>
+ <select name=comparemonth>$form->{selectaccountingmonth}</select>
+ <select name=compareyear>$form->{selectaccountingyear}</select>
+ </td>
+ </tr>
+|;
+ }
+
+ print qq|
+ <tr>
+ <th align=right>|.$locale->text('Decimalplaces').qq|</th>
+ <td><input name=decimalplaces size=3 value=2></td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <table>
+ <tr>
+ <th align=right>|.$locale->text('Method').qq|</th>
+ <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
+ &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
+ </tr>
+
+ <tr>
+ <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
+ <td colspan=3><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
+ <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
+ <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Account Number').qq|</td>
+ </tr>
+|;
+ }
+
+
+ if ($form->{report} eq "balance_sheet") {
+ print qq|
+ <input type=hidden name=nextsub value=generate_balance_sheet>
+ <tr>
+ <th align=right>|.$locale->text('as at').qq|</th>
+ <td><input name=asofdate size=11 title="$myconfig{dateformat}" value=$form->{asofdate}></td>
+|;
+
+ if ($selectfrom) {
+ print qq|
+ <td>
+ <select name=asofmonth>$form->{selectaccountingmonth}</select>
+ <select name=asofyear>$form->{selectaccountingyear}</select>
+ </td>
+|;
+ }
+
+ print qq|
+ </tr>
+
+ <th align=right nowrap>|.$locale->text('Compare to').qq|</th>
+ <td><input name=compareasofdate size=11 title="$myconfig{dateformat}"></td>
+ <td>
+|;
+
+ if ($selectto) {
+ print qq|
+ <select name=compareasofmonth>$form->{selectaccountingmonth}</select>
+ <select name=compareasofyear>$form->{selectaccountingyear}</select>
+ </td>
+|;
+ }
+
+ print qq|
+ </tr>
+ <tr>
+ <th align=right>|.$locale->text('Decimalplaces').qq|</th>
+ <td><input name=decimalplaces size=3 value=2></td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <table>
+ <tr>
+ <th align=right>|.$locale->text('Method').qq|</th>
+ <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
+ &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
+ </tr>
+
+ <tr>
+ <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
+ <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
+ <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
+ <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Account Number').qq|</td>
+ </tr>
+|;
+ }
+
+
+ if ($form->{report} eq "trial_balance") {
+ print qq|
+ <input type=hidden name=nextsub value=generate_trial_balance>
+ <tr>
+ <th align=right>|.$locale->text('From').qq|</th>
+ <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
+ <th align=right>|.$locale->text('To').qq|</th>
+ <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
+ </tr>
+ $selectfrom
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <table>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
+ <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Heading').qq|
+ <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
+ <input name=all_accounts class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('All Accounts').qq|</td>
+ </tr>
+|;
+ }
+
+
+ if ($form->{report} =~ /^tax_/) {
+ $gifi = "";
+
+ $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
+
+ RP->get_taxaccounts(\%myconfig, \%$form);
+
+ print qq|
+ <input type=hidden name=nextsub value=generate_tax_report>
+ <tr>
+ <th align=right>|.$locale->text('From').qq|</th>
+ <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
+ <th align=right>|.$locale->text('To').qq|</th>
+ <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
+ </tr>
+ $selectfrom
+ $summary
+ <tr>
+ <th align=right>|.$locale->text('Report for').qq|</th>
+ <td colspan=3>
+|;
+
+ $checked = "checked";
+ foreach $ref (@{ $form->{taxaccounts} }) {
+
+ print qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked>&nbsp;$ref->{description}
+
+ <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
+ <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
+
+ $checked = "";
+
+ }
+
+ print qq|
+ <input type=hidden name=db value=$form->{db}>
+ <input type=hidden name=sort value=transdate>
+
+ </td>
+ </tr>
+|;
+
+
+ if (@{ $form->{gifi_taxaccounts} }) {
+ print qq|
+ <tr>
+ <th align=right>|.$locale->text('GIFI').qq|</th>
+ <td colspan=3>
+|;
+
+ foreach $ref (@{ $form->{gifi_taxaccounts} }) {
+
+ print qq|<input name=accno class=radio type=radio value="gifi_$ref->{accno}">&nbsp;$ref->{description}
+
+ <input name="gifi_$ref->{accno}_description" type=hidden value="$ref->{description}">
+ <input name="gifi_$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
+
+ }
+
+ print qq|
+ </td>
+ </tr>
+|;
+ }
+
+
+print qq|
+ <tr>
+ <th align=right>|.$locale->text('Method').qq|</th>
+ <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
+ &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <table>
+ <tr>
+ <th align=right>|.$locale->text('Include in Report').qq|</th>
+ <td>
+ <table>
+ <tr>
+ <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
+ <td>|.$locale->text('ID').qq|</td>
+ <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
+ <td>|.$locale->text('Invoice').qq|</td>
+ <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
+ <td>|.$locale->text('Date').qq|</td>
+ </tr>
+ <tr>
+ <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
+|;
+
+ if ($form->{db} eq 'ar') {
+ print qq|<td>|.$locale->text('Customer').qq|</td>|;
+ }
+ if ($form->{db} eq 'ap') {
+ print qq|<td>|.$locale->text('Vendor').qq|</td>|;
+ }
+
+ print qq|
+ <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
+ <td>|.$locale->text('Description').qq|</td>
+ <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
+ <td>|.$locale->text('Amount').qq|</td>
+
+ <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
+ <td>|.$locale->text('Tax').qq|</td>
+
+ <td><input name="l_total" class=checkbox type=checkbox value=Y checked></td>
+ <td>|.$locale->text('Total').qq|</td>
+ </tr>
+ <tr>
+ </tr>
+ <tr>
+ <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
+ <td>|.$locale->text('Subtotal').qq|</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+|;
+
+ }
+
+
+ if ($form->{report} =~ /^nontaxable_/) {
+ $gifi = "";
+
+ $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
+
+ print qq|
+ <input type=hidden name=nextsub value=generate_tax_report>
+
+ <input type=hidden name=db value=$form->{db}>
+ <input type=hidden name=sort value=transdate>
+ <input type=hidden name=report value=$form->{report}>
+
+ <tr>
+ <th align=right>|.$locale->text('From').qq|</th>
+ <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
+ <th align=right>|.$locale->text('To').qq|</th>
+ <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
+ </tr>
+ $selectfrom
+ $summary
+ <tr>
+ <th align=right>|.$locale->text('Method').qq|</th>
+ <td colspan=3><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
+ &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
+ </tr>
+ <tr>
+ <th align=right>|.$locale->text('Include in Report').qq|</th>
+ <td colspan=3>
+ <table>
+ <tr>
+ <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
+ <td>|.$locale->text('ID').qq|</td>
+ <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
+ <td>|.$locale->text('Invoice').qq|</td>
+ <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
+ <td>|.$locale->text('Date').qq|</td>
+ </tr>
+ <tr>
+ <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
+|;
+
+ if ($form->{db} eq 'ar') {
+ print qq|<td>|.$locale->text('Customer').qq|</td>|;
+ }
+ if ($form->{db} eq 'ap') {
+ print qq|<td>|.$locale->text('Vendor').qq|</td>|;
+ }
+
+ print qq|
+ <td><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
+ <td>|.$locale->text('Description').qq|</td>
+ <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
+ <td>|.$locale->text('Amount').qq|</td>
+ </tr>
+ <tr>
+ <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
+ <td>|.$locale->text('Subtotal').qq|</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+|;
+
+ }
+
+
+ if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
+ $gifi = "";
+
+ if ($form->{report} eq 'ar_aging') {
+ $label = $locale->text('Customer');
+ $form->{vc} = 'customer';
+ } else {
+ $label = $locale->text('Vendor');
+ $form->{vc} = 'vendor';
+ }
+
+ $nextsub = "generate_$form->{report}";
+
+ # setup vc selection
+ $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
+
+ for (@{ $form->{"all_$form->{vc}"} }) { $vc .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
+
+ $vc = ($vc) ? qq|<select name=$form->{vc}><option>\n$vc</select>| : qq|<input name=$form->{vc} size=35>|;
+
+ $postscript = "postscript" if $myconfig{printer};
+
+ print qq|
+ <tr>
+ <th align=right>|.$locale->text($label).qq|</th>
+ <td>$vc</td>
+ </tr>
+ <tr>
+ <th align=right>|.$locale->text('To').qq|</th>
+ <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
+ </tr>
+ $selectto
+ <input type=hidden name=type value=statement>
+ <input type=hidden name=format value=$postscript>
+ <input type=hidden name=media value="$myconfig{printer}">
+
+ <input type=hidden name=nextsub value=$nextsub>
+ <input type=hidden name=action value=$nextsub>
+ $summary
+ <tr>
+ <table>
+ <tr>
+ <th>|.$locale->text('Include in Report').qq|</th>
+
+ <td>
+ <table>
+ <tr>
+ <td nowrap><input name=overdue type=radio class=radio value=0 checked> |.$locale->text('Aged').qq|</td>
+ <td nowrap><input name=overdue type=radio class=radio value=1> |.$locale->text('Overdue').qq|</td>
+ </tr>
+ <tr>
+ <td nowrap width=70><input name=c0 type=checkbox class=checkbox value=1 checked> |.$locale->text('Current').qq|</td>
+ <td nowrap width=70><input name=c30 type=checkbox class=checkbox value=1 checked> 30</td>
+ <td nowrap width=70><input name=c60 type=checkbox class=checkbox value=1 checked> 60</td>
+ <td nowrap width=70><input name=c90 type=checkbox class=checkbox value=1 checked> 90</td>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </tr>
+
+|;
+ }
+
+# above action can be removed if there is more than one input field
+
+
+ if ($form->{report} =~ /(receipts|payments)$/) {
+ $gifi = "";
+
+ $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
+
+ RP->paymentaccounts(\%myconfig, \%$form);
+
+ $selection = "<option>\n";
+ foreach $ref (@{ $form->{PR} }) {
+ $paymentaccounts .= "$ref->{accno} ";
+ $selection .= "<option>$ref->{accno}--$ref->{description}\n";
+ }
+
+ chop $paymentaccounts;
+
+ print qq|
+ <input type=hidden name=nextsub value=list_payments>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Account').qq|</th>
+ <td colspan=3><select name=account>$selection</select>
+ <input type=hidden name=paymentaccounts value="$paymentaccounts">
+ </td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Description').qq|</th>
+ <td colspan=3><input name=description size=35></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Source').qq|</th>
+ <td colspan=3><input name=source></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Memo').qq|</th>
+ <td colspan=3><input name=memo size=30></td>
+ </tr>
+ <tr>
+ <th align=right>|.$locale->text('From').qq|</th>
+ <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
+ <th align=right>|.$locale->text('To').qq|</th>
+ <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
+ </tr>
+ $selectfrom
+ <tr>
+ <td align=right><input type=checkbox class=checkbox name=fx_transaction value=1 checked></td>
+ <td colspan=3>|.$locale->text('Include Exchange Rate Difference').qq|</td>
+ </tr>
+ <tr>
+ <td align=right><input name=l_subtotal class=checkbox type=checkbox value=Y></td>
+ <td align=left colspan=3>|.$locale->text('Subtotal').qq|</th>
+ </tr>
+
+ <input type=hidden name=db value=$form->{db}>
+ <input type=hidden name=sort value=transdate>
+|;
+
+ }
+
+
+ print qq|
+
+$gifi
+
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+<br>
+<input type="hidden" name="path" value="$form->{path}">
+<input type="hidden" name="login" value="$form->{login}">
+<input type="hidden" name="sessionid" value="$form->{sessionid}">
+
+<button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+
+</form>
+|;
+
+ if ($form->{lynx}) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
+
+</body>
+</html>
+|;
+
+}
+
+
+sub continue { &{$form->{nextsub}} };
+
+sub generate_inv_activity {
+ $form->header;
+
+ RP->inventory_activity(\%myconfig, \%$form);
+
+ $title = $form->escape($form->{title});
+
+# if ($form->{department}) {
+# ($department) = split /--/, $form->{department};
+# $options = $locale->text('Department')." : $department<br>";
+# $department = $form->escape($form->{department});
+# }
+## if ($form->{projectnumber}) {
+# ($projectnumber) = split /--/, $form->{projectnumber};
+# $options .= $locale->text('Project Number')." : $projectnumber<br>";
+# $projectnumber = $form->escape($form->{projectnumber});
+# }
+
+ # if there are any dates
+ if ($form->{fromdate} || $form->{todate}) {
+ if ($form->{fromdate}) {
+ $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
+ }
+ if ($form->{todate}) {
+ $todate = $locale->date(\%myconfig, $form->{todate}, 1);
+ }
+
+ $form->{period} = "$fromdate - $todate";
+ } else {
+ $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
+
+ }
+ $options .= $form->{period};
+
+ @column_index = qw(partnumber description sold revenue received expense);
+
+ $href = qq|rp.pl?path=$form->{path}&action=continue&accounttype=$form->{accounttype}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}|;
+
+ $column_header{partnumber} = qq|
+ <th class=listheading><a class=listheading href="$href&sort_col=partnumber">|
+ .$locale->text('Part Number').qq|</a></th>|;
+ $column_header{description} = qq|
+ <th class=listheading><a class=listheading href="$href&sort_col=description">|
+ .$locale->text('Description').qq|</a></th>|;
+ $column_header{sold} = qq|
+ <th class=listheading><a class=listheading href="$href&sort_col=sold">|
+ .$locale->text('Sold').qq|</a></th>|;
+ $column_header{revenue} = qq|
+ <th class=listheading><a class=listheading href="$href&sort_col=revenue">|
+ .$locale->text('Revenue').qq|</a></th>|;
+ $column_header{received} = qq|
+ <th class=listheading><a class=listheading href="$href&sort_col=received">|
+ .$locale->text('Received').qq|</a></th>|;
+ $column_header{expense} = qq|
+ <th class=listheading><a class=listheading href="$href&sort_col=expense">|
+ .$locale->text('Expense').qq|</a></th>|;
+
+
+
+ print qq|
+<body>
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>$options</td>
+ </tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr>|;
+
+ map { print "$column_header{$_}\n" } @column_index;
+
+ print qq|
+ </tr>
+|;
+
+
+
+ if ($form->{sort_col} eq 'qty' || $form->{sort_col} eq 'revenue'){
+ $form->{sort_type} = 'numeric';
+ }
+ $i = 0;
+ $cols = "l_transdate=Y&l_name=Y&l_invnumber=Y&summary=1";
+ $dates= "transdatefrom=$form->{fromdate}&transdateto=$form->{todate}&year=$form->{fromyear}&month=$form->{frommonth}&interval=$form->{interval}";
+ $base="path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+
+ $form->{callback} = "rp.pl?action=continue&$base";
+ $form->{callback} = $form->escape($form->{callback});
+ $callback = "callback=$form->{callback}";
+ # sort the whole thing by account numbers and display
+ foreach $ref (@{ $form->{TB} }) {
+ $description = $form->escape($ref->{description});
+ $i = $i % 2;
+
+ $pnumhref="ic.pl?action=edit&id=$ref->{id}&$base&callback=$form->{callback}";
+ $soldhref="ar.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&$callback";
+ $rechref="ap.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&callback=$form->{callback}";
+
+ $ml = ($ref->{category} =~ /(A|E)/) ? -1 : 1;
+
+ $debit = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
+ $credit = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
+ $begbalance = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, "&nbsp;");
+ $endbalance = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2, "&nbsp;");
+
+ $ref->{partnumber} = qq|<a href="$pnumhref">$ref->{partnumber}</a>|;
+ $ref->{sold} = qq|<a href="$soldhref">$ref->{sold}</a>|;
+ $ref->{received} = qq|<a href="$rechref">$ref->{received}<a/>|;
+ map { $column_data{$_} = "<td>&nbsp;</td>" }
+ @column_index;
+
+
+
+ print qq|
+ <tr class=listrow$i>
+ |;
+ map { print "<td>$ref->{$_}</td>\n" } @column_index;
+
+ print qq|
+ </tr>
+|;
+ ++$i;
+ }
+
+
+ print qq|
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+</body>
+</html>
+|;
+
+}
+
+
+sub generate_income_statement {
+
+ $form->{padding} = "&nbsp;&nbsp;";
+ $form->{bold} = "<b>";
+ $form->{endbold} = "</b>";
+ $form->{br} = "<br>";
+
+ RP->income_statement(\%myconfig, \%$form);
+
+ ($form->{department}) = split /--/, $form->{department};
+ ($form->{projectnumber}) = split /--/, $form->{projectnumber};
+
+ $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
+ $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
+
+ # if there are any dates construct a where
+ if ($form->{fromdate} || $form->{todate}) {
+
+ unless ($form->{todate}) {
+ $form->{todate} = $form->current_date(\%myconfig);
+ }
+
+ $longtodate = $locale->date(\%myconfig, $form->{todate}, 1);
+ $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
+
+ $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
+ $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
+
+ $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
+ $form->{period} = $locale->text('for Period').qq|<br>\n$longfromdate |.$locale->text('To').qq| $longtodate|;
+ }
+
+ if ($form->{comparefromdate} || $form->{comparetodate}) {
+ $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
+ $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
+
+ $longcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 1);
+ $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
+
+ $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
+ $form->{period} .= "<br>\n$longcomparefromdate ".$locale->text('To').qq| $longcomparetodate|;
+ }
+
+ # setup variables for the form
+ @a = qw(company address businessnumber);
+ for (@a) { $form->{$_} = $myconfig{$_} }
+ $form->{address} =~ s/\\n/<br>/g;
+
+ $form->{templates} = $myconfig{templates};
+
+ $form->{IN} = "income_statement.html";
+
+ $form->parse_template;
+
+}
+
+
+sub generate_balance_sheet {
+
+ $form->{padding} = "&nbsp;&nbsp;";
+ $form->{bold} = "<b>";
+ $form->{endbold} = "</b>";
+ $form->{br} = "<br>";
+
+ RP->balance_sheet(\%myconfig, \%$form);
+
+ $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
+ $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
+
+ ($form->{department}) = split /--/, $form->{department};
+
+ # define Current Earnings account
+ $padding = ($form->{l_heading}) ? $form->{padding} : "";
+ push(@{$form->{equity_account}}, $padding.$locale->text('Current Earnings'));
+
+ $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
+ $form->{last_period} = $locale->date(\%myconfig, $form->{compareasofdate}, 0);
+
+ $form->{IN} = "balance_sheet.html";
+
+ # setup company variables for the form
+ for (qw(company address businessnumber nativecurr)) { $form->{$_} = $myconfig{$_} }
+ $form->{address} =~ s/\\n/<br>/g;
+
+ $form->{templates} = $myconfig{templates};
+
+ $form->parse_template;
+
+}
+
+
+sub generate_projects {
+
+ $form->{nextsub} = "generate_projects";
+ $form->{title} = $locale->text('Project Transactions');
+
+ RP->trial_balance(\%myconfig, \%$form);
+
+ &list_accounts;
+
+}
+
+
+# Antonio Gallardo
+#
+# D.S. Feb 16, 2001
+# included links to display transactions for period entered
+# added headers and subtotals
+#
+sub generate_trial_balance {
+
+ # get for each account initial balance, debits and credits
+ RP->trial_balance(\%myconfig, \%$form);
+
+ $form->{nextsub} = "generate_trial_balance";
+ $form->{title} = $locale->text('Trial Balance');
+
+ $form->{callback} = "$form->{script}?action=generate_trial_balance";
+ for (qw(login path sessionid nextsub fromdate todate month year interval l_heading l_subtotal all_accounts accounttype title)) { $form->{callback} .= "&$_=$form->{$_}" }
+ $form->{callback} = $form->escape($form->{callback});
+
+ &list_accounts;
+
+}
+
+
+sub list_accounts {
+
+ $title = $form->escape($form->{title});
+
+ if ($form->{department}) {
+ ($department) = split /--/, $form->{department};
+ $options = $locale->text('Department')." : $department<br>";
+ $department = $form->escape($form->{department});
+ }
+ if ($form->{projectnumber}) {
+ ($projectnumber) = split /--/, $form->{projectnumber};
+ $options .= $locale->text('Project Number')." : $projectnumber<br>";
+ $projectnumber = $form->escape($form->{projectnumber});
+ }
+
+ # if there are any dates
+ if ($form->{fromdate} || $form->{todate}) {
+
+ if ($form->{fromdate}) {
+ $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
+ }
+ if ($form->{todate}) {
+ $todate = $locale->date(\%myconfig, $form->{todate}, 1);
+ }
+
+ $form->{period} = "$fromdate - $todate";
+ } else {
+ $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
+
+ }
+ $options .= $form->{period};
+
+ @column_index = qw(accno description begbalance debit credit endbalance);
+
+ $column_header{accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</th>|;
+ $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
+ $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</th>|;
+ $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</th>|;
+ $column_header{begbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
+ $column_header{endbalance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
+
+
+ if ($form->{accounttype} eq 'gifi') {
+ $column_header{accno} = qq|<th class=listheading>|.$locale->text('GIFI').qq|</th>|;
+ }
+
+
+ $form->header;
+
+ print qq|
+<body>
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>$options</td>
+ </tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr>|;
+
+ for (@column_index) { print "$column_header{$_}\n" }
+
+ print qq|
+ </tr>
+|;
+
+
+
+ # sort the whole thing by account numbers and display
+ foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} }) {
+
+ $description = $form->escape($ref->{description});
+
+ $href = qq|ca.pl?path=$form->{path}&action=list_transactions&accounttype=$form->{accounttype}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&sort=transdate&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}&prevreport=$form->{callback}|;
+
+ if ($form->{accounttype} eq 'gifi') {
+ $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description";
+ $na = $locale->text('N/A');
+ if (!$ref->{accno}) {
+ for (qw(accno description)) { $ref->{$_} = $na }
+ }
+ } else {
+ $href .= "&accno=$ref->{accno}&description=$description";
+ }
+
+ $ml = ($ref->{category} =~ /(A|E)/) ? -1 : 1;
+ $ml *= -1 if $ref->{contra};
+
+ $debit = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
+ $credit = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
+ $begbalance = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, "&nbsp;");
+ $endbalance = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2, "&nbsp;");
+
+
+ if ($ref->{charttype} eq "H" && $subtotal && $form->{l_subtotal}) {
+
+ if ($subtotal) {
+
+ for (qw(accno begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
+
+ $subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, "&nbsp;");
+ $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, "&nbsp;");
+ $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
+ $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
+
+ $column_data{description} = "<th class=listsubtotal>$subtotaldescription</th>";
+ $column_data{begbalance} = "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
+ $column_data{endbalance} = "<th align=right class=listsubtotal>$subtotalendbalance</th>";
+ $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</th>";
+ $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</th>";
+
+ print qq|
+ <tr class=listsubtotal>
+|;
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
+ </tr>
+|;
+ }
+ }
+
+ if ($ref->{charttype} eq "H") {
+ $subtotal = 1;
+ $subtotaldescription = $ref->{description};
+ $subtotaldebit = $ref->{debit};
+ $subtotalcredit = $ref->{credit};
+ $subtotalbegbalance = 0;
+ $subtotalendbalance = 0;
+
+ if ($form->{l_heading}) {
+ if (! $form->{all_accounts}) {
+ if (($subtotaldebit + $subtotalcredit) == 0) {
+ $subtotal = 0;
+ next;
+ }
+ }
+ } else {
+ $subtotal = 0;
+ if ($form->{all_accounts} || ($form->{l_subtotal} && (($subtotaldebit + $subtotalcredit) != 0))) {
+ $subtotal = 1;
+ }
+ next;
+ }
+
+ for (qw(accno debit credit begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
+ $column_data{description} = "<th class=listheading>$ref->{description}</th>";
+ }
+
+ if ($ref->{charttype} eq "A") {
+ $column_data{accno} = "<td><a href=$href>$ref->{accno}</a></td>";
+ $column_data{description} = "<td>$ref->{description}</td>";
+ $column_data{debit} = "<td align=right>$debit</td>";
+ $column_data{credit} = "<td align=right>$credit</td>";
+ $column_data{begbalance} = "<td align=right>$begbalance</td>";
+ $column_data{endbalance} = "<td align=right>$endbalance</td>";
+
+ $totaldebit += $ref->{debit};
+ $totalcredit += $ref->{credit};
+
+ $cml = ($ref->{contra}) ? -1 : 1;
+
+ $subtotalbegbalance += $ref->{balance} * $ml * $cml;
+ $subtotalendbalance += ($ref->{balance} + $ref->{amount}) * $ml * $cml;
+
+ }
+
+
+ if ($ref->{charttype} eq "H") {
+ print qq|
+ <tr class=listheading>
+|;
+ }
+ if ($ref->{charttype} eq "A") {
+ $i++; $i %= 2;
+ print qq|
+ <tr class=listrow$i>
+|;
+ }
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
+ </tr>
+|;
+ }
+
+
+ # print last subtotal
+ if ($subtotal && $form->{l_subtotal}) {
+ for (qw(accno begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
+ $subtotalbegbalance = $form->format_amount(\%myconfig, $subtotalbegbalance, 2, "&nbsp;");
+ $subtotalendbalance = $form->format_amount(\%myconfig, $subtotalendbalance, 2, "&nbsp;");
+ $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
+ $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
+ $column_data{description} = "<th class=listsubtotal>$subtotaldescription</th>";
+ $column_data{begbalance} = "<th align=right class=listsubtotal>$subtotalbegbalance</th>";
+ $column_data{endbalance} = "<th align=right class=listsubtotal>$subtotalendbalance</th>";
+ $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</th>";
+ $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</th>";
+
+ print qq|
+ <tr class=listsubtotal>
+|;
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
+ </tr>
+|;
+ }
+
+ $totaldebit = $form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;");
+ $totalcredit = $form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;");
+
+ for (qw(accno description begbalance endbalance)) { $column_data{$_} = "<th>&nbsp;</th>" }
+
+ $column_data{debit} = qq|<th align=right class=listtotal>$totaldebit</th>|;
+ $column_data{credit} = qq|<th align=right class=listtotal>$totalcredit</th>|;
+
+ print qq|
+ <tr class=listtotal>
+|;
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+</body>
+</html>
+|;
+
+}
+
+
+sub generate_ar_aging {
+
+ # split customer
+ ($form->{customer}) = split(/--/, $form->{customer});
+ $customer = $form->escape($form->{customer},1);
+ $title = $form->escape($form->{title},1);
+ $media = $form->escape($form->{media},1);
+
+ $form->{ct} = "customer";
+ $form->{arap} = "ar";
+
+ RP->aging(\%myconfig, \%$form);
+
+ $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ar_aging&login=$form->{login}&sessionid=$form->{sessionid}&todate=$form->{todate}&customer=$customer&title=$title&type=$form->{type}&format=$form->{format}&media=$media&summary=$form->{summary}|;
+
+ &aging;
+
+}
+
+
+sub generate_ap_aging {
+
+ # split vendor
+ ($form->{vendor}) = split(/--/, $form->{vendor});
+ $vendor = $form->escape($form->{vendor},1);
+ $title = $form->escape($form->{title},1);
+ $media = $form->escape($form->{media},1);
+
+ $form->{ct} = "vendor";
+ $form->{arap} = "ap";
+
+ RP->aging(\%myconfig, \%$form);
+
+ $form->{callback} = qq|$form->{script}?path=$form->{path}&action=generate_ap_aging&login=$form->{login}&sessionid=$form->{sessionid}&todate=$form->{todate}&vendor=$vendor&title=$title&type=$form->{type}&format=$form->{format}&media=$media&summary=$form->{summary}|;
+
+ &aging;
+
+}
+
+
+sub aging {
+
+ $form->header;
+
+ $column_header{statement} = qq|<th class=listheading width=1%>&nbsp;</th>|;
+ $column_header{ct} = qq|<th class=listheading width=60%>|.$locale->text(ucfirst $form->{ct}).qq|</th>|;
+ $column_header{language} = qq|<th class=listheading>|.$locale->text('Language').qq|</th>|;
+ $column_header{invnumber} = qq|<th class=listheading>|.$locale->text('Invoice').qq|</th>|;
+ $column_header{ordnumber} = qq|<th class=listheading>|.$locale->text('Order').qq|</th>|;
+ $column_header{transdate} = qq|<th class=listheading nowrap>|.$locale->text('Date').qq|</th>|;
+ $column_header{duedate} = qq|<th class=listheading nowrap>|.$locale->text('Due Date').qq|</th>|;
+ $column_header{c0} = qq|<th class=listheading width=10% nowrap>|.$locale->text('Current').qq|</th>|;
+ $column_header{c30} = qq|<th class=listheading width=10% nowrap>30</th>|;
+ $column_header{c60} = qq|<th class=listheading width=10% nowrap>60</th>|;
+ $column_header{c90} = qq|<th class=listheading width=10% nowrap>90</th>|;
+ $column_header{total} = qq|<th class=listheading width=10% nowrap>|.$locale->text('Total').qq|</th>|;
+
+ @column_index = qw(statement ct);
+
+ if (@{ $form->{all_language} } && $form->{arap} eq 'ar') {
+ push @column_index, "language";
+ $form->{selectlanguage} = qq|<option>\n|;
+
+ for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
+ }
+
+ @c = ();
+ for (qw(c0 c30 c60 c90)) {
+ if ($form->{$_}) {
+ push @c, $_;
+ $form->{callback} .= "&$_=$form->{$_}";
+ }
+ }
+
+ if (!$form->{summary}) {
+ push @column_index, qw(invnumber ordnumber transdate duedate);
+ }
+ push @column_index, @c;
+ push @column_index, "total";
+
+ $option = $locale->text('Aged');
+ if ($form->{overdue}) {
+ $option= $locale->text('Aged Overdue');
+ $form->{callback} .= "&overdue=$form->{overdue}";
+ }
+
+ if ($form->{department}) {
+ $option .= "\n<br>" if $option;
+ ($department) = split /--/, $form->{department};
+ $option .= $locale->text('Department')." : $department";
+ $department = $form->escape($form->{department},1);
+ $form->{callback} .= "&department=$department";
+ }
+
+ if ($form->{arap} eq 'ar') {
+ if ($form->{customer}) {
+ $option .= "\n<br>" if $option;
+ $option .= $form->{customer};
+ }
+ }
+ if ($form->{arap} eq 'ap') {
+ shift @column_index;
+ if ($form->{vendor}) {
+ $option .= "\n<br>" if $option;
+ $option .= $form->{vendor};
+ }
+ }
+
+ $todate = $locale->date(\%myconfig, $form->{todate}, 1);
+ $option .= "\n<br>" if $option;
+ $option .= $locale->text('for Period')." ".$locale->text('To')." $todate";
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>$option</td>
+ </tr>
+ <tr>
+ <td>
+ <table width=100%>
+|;
+
+ $ctid = 0;
+ $i = 0;
+ $k = 0;
+ $l = $#{ $form->{AG} };
+
+ foreach $ref (@{ $form->{AG} }) {
+
+ if ($curr ne $ref->{curr}) {
+ $ctid = 0;
+ for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
+ if ($curr) {
+ $c0total = $form->format_amount(\%myconfig, $c0total, 2, "&nbsp");
+ $c30total = $form->format_amount(\%myconfig, $c30total, 2, "&nbsp");
+ $c60total = $form->format_amount(\%myconfig, $c60total, 2, "&nbsp");
+ $c90total = $form->format_amount(\%myconfig, $c90total, 2, "&nbsp");
+ $total = $form->format_amount(\%myconfig, $total, 2, "&nbsp");
+
+ for (qw(ct statement language)) { $column_data{$_} = qq|<td>&nbsp;</td>| }
+ $column_data{c0} = qq|<th align=right>$c0total</th>|;
+ $column_data{c30} = qq|<th align=right>$c30total</th>|;
+ $column_data{c60} = qq|<th align=right>$c60total</th>|;
+ $column_data{c90} = qq|<th align=right>$c90total</th>|;
+ $column_data{total} = qq|<th align=right>$total</th>|;
+
+ print qq|
+ <tr class=listtotal>
+|;
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
+ </tr>
+|;
+
+ $c0subtotal = 0;
+ $c30subtotal = 0;
+ $c60subtotal = 0;
+ $c90subtotal = 0;
+ $subtotal = 0;
+
+ $c0total = 0;
+ $c30total = 0;
+ $c60total = 0;
+ $c90total = 0;
+ $total = 0;
+
+ }
+
+ $curr = $ref->{curr};
+ print qq|
+ <tr>
+ <td></td>
+ <th>$curr</th>
+ </tr>
+
+ <tr class=listheading>
+|;
+
+ for (@column_index) { print "$column_header{$_}\n" }
+
+ print qq|
+ </tr>
+|;
+ }
+
+ $k++;
+
+ if ($ctid != $ref->{ctid}) {
+
+ $i++;
+
+ $column_data{ct} = qq|<td>$ref->{name}</td>|;
+
+ if ($form->{selectlanguage}) {
+ $form->{"selectlanguage_$i"} = $form->{selectlanguage};
+ $form->{"selectlanguage_$i"} =~ s/(<option value="\Q$ref->{language_code}\E")/$1 selected/;
+ $column_data{language} = qq|<td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td>|;
+ }
+
+ $column_data{statement} = qq|<td><input name="statement_$i" type=checkbox class=checkbox value=1 $ref->{checked}>
+ <input type=hidden name="$form->{ct}_id_$i" value=$ref->{ctid}>
+ <input type=hidden name="curr_$i" value=$ref->{curr}>
+ </td>|;
+
+ }
+
+ $ctid = $ref->{ctid};
+
+ for (qw(c0 c30 c60 c90)) { $ref->{$_} = $form->round_amount($ref->{$_} / $ref->{exchangerate}, 2) }
+
+ $c0subtotal += $ref->{c0};
+ $c30subtotal += $ref->{c30};
+ $c60subtotal += $ref->{c60};
+ $c90subtotal += $ref->{c90};
+
+ $c0total += $ref->{c0};
+ $c30total += $ref->{c30};
+ $c60total += $ref->{c60};
+ $c90total += $ref->{c90};
+
+ $ref->{total} = ($ref->{c0} + $ref->{c30} + $ref->{c60} + $ref->{c90});
+ $subtotal += $ref->{total};
+ $total += $ref->{total};
+
+ $ref->{c0} = $form->format_amount(\%myconfig, $ref->{c0}, 2, "&nbsp;");
+ $ref->{c30} = $form->format_amount(\%myconfig, $ref->{c30}, 2, "&nbsp;");
+ $ref->{c60} = $form->format_amount(\%myconfig, $ref->{c60}, 2, "&nbsp;");
+ $ref->{c90} = $form->format_amount(\%myconfig, $ref->{c90}, 2, "&nbsp;");
+ $ref->{total} = $form->format_amount(\%myconfig, $ref->{total}, 2, "&nbsp;");
+
+ $href = qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=|.$form->escape($form->{callback});
+
+ $column_data{invnumber} = qq|<td><a href=$href>$ref->{invnumber}</a></td>|;
+ for (qw(ordnumber transdate duedate)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| }
+ for (qw(c0 c30 c60 c90 total)) { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
+
+ if (!$form->{summary}) {
+
+ $j++; $j %= 2;
+ print qq|
+ <tr class=listrow$j>
+|;
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
+ </tr>
+|;
+
+ for (qw(ct statement language)) { $column_data{$_} = qq|<td>&nbsp;</td>| }
+
+ }
+
+ # print subtotal
+ $nextid = ($k <= $l) ? $form->{AG}->[$k]->{ctid} : 0;
+ if ($ctid != $nextid) {
+
+ $c0subtotal = $form->format_amount(\%myconfig, $c0subtotal, 2, "&nbsp");
+ $c30subtotal = $form->format_amount(\%myconfig, $c30subtotal, 2, "&nbsp");
+ $c60subtotal = $form->format_amount(\%myconfig, $c60subtotal, 2, "&nbsp");
+ $c90subtotal = $form->format_amount(\%myconfig, $c90subtotal, 2, "&nbsp");
+ $subtotal = $form->format_amount(\%myconfig, $subtotal, 2, "&nbsp");
+
+ if ($form->{summary}) {
+ $column_data{c0} = qq|<td align=right>$c0subtotal</th>|;
+ $column_data{c30} = qq|<td align=right>$c30subtotal</th>|;
+ $column_data{c60} = qq|<td align=right>$c60subtotal</th>|;
+ $column_data{c90} = qq|<td align=right>$c90subtotal</th>|;
+ $column_data{total} = qq|<td align=right>$subtotal</th>|;
+
+ $j++; $j %= 2;
+ print qq|
+ <tr class=listrow$j>
+|;
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
+ </tr>
+|;
+
+ } else {
+
+ for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
+
+ $column_data{c0} = qq|<th class=listsubtotal align=right>$c0subtotal</th>|;
+ $column_data{c30} = qq|<th class=listsubtotal align=right>$c30subtotal</th>|;
+ $column_data{c60} = qq|<th class=listsubtotal align=right>$c60subtotal</th>|;
+ $column_data{c90} = qq|<th class=listsubtotal align=right>$c90subtotal</th>|;
+ $column_data{total} = qq|<th class=listsubtotal align=right>$subtotal</th>|;
+
+ # print subtotals
+ print qq|
+ <tr class=listsubtotal>
+|;
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
+ </tr>
+|;
+
+ }
+
+ $c0subtotal = 0;
+ $c30subtotal = 0;
+ $c60subtotal = 0;
+ $c90subtotal = 0;
+ $subtotal = 0;
+
+ }
+ }
+
+ print qq|
+ </tr>
+ <tr class=listtotal>
+|;
+
+ for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
+
+ $c0total = $form->format_amount(\%myconfig, $c0total, 2, "&nbsp;");
+ $c30total = $form->format_amount(\%myconfig, $c30total, 2, "&nbsp;");
+ $c60total = $form->format_amount(\%myconfig, $c60total, 2, "&nbsp;");
+ $c90total = $form->format_amount(\%myconfig, $c90total, 2, "&nbsp;");
+ $total = $form->format_amount(\%myconfig, $total, 2, "&nbsp;");
+
+ $column_data{c0} = qq|<th align=right class=listtotal>$c0total</th>|;
+ $column_data{c30} = qq|<th align=right class=listtotal>$c30total</th>|;
+ $column_data{c60} = qq|<th align=right class=listtotal>$c60total</th>|;
+ $column_data{c90} = qq|<th align=right class=listtotal>$c90total</th>|;
+ $column_data{total} = qq|<th align=right class=listtotal>$total</th>|;
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
+ </tr>
+ <input type=hidden name=rowcount value=$i>
+ </table>
+ </td>
+ </tr>
+
+ <tr>
+ <td>
+|;
+
+ &print_options if ($form->{arap} eq 'ar');
+
+ print qq|
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+|;
+
+ if ($form->{arap} eq 'ar') {
+
+ $form->hide_form(qw(todate title summary overdue c0 c30 c60 c90 callback arap ct department path login sessionid));
+
+ print qq|
+<input type=hidden name=$form->{ct} value="$form->{$form->{ct}}">
+|;
+
+# type=submit $locale->text('Select all')
+# type=submit $locale->text('Print')
+# type=submit $locale->text('E-mail')
+
+ %button = ('select_all' => { ndx => 1, key => 'A', value => $locale->text('Select all') },
+ 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
+ 'e_mail' => { ndx => 5, key => 'E', value => $locale->text('E-mail') },
+ );
+
+ for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
+
+ }
+
+ if ($form->{lynx}) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
+sub select_all {
+
+ RP->aging(\%myconfig, \%$form);
+
+ for (@{ $form->{AG} }) { $_->{checked} = "checked" }
+
+ &aging;
+
+}
+
+
+sub print_options {
+
+ $form->{sendmode} = "attachment";
+ $form->{copies} = 1 unless $form->{copies};
+
+ $form->{PD}{$form->{type}} = "selected";
+ $form->{DF}{$form->{format}} = "selected";
+ $form->{SM}{$form->{sendmode}} = "selected";
+
+ $format = qq|
+ <option value=html $form->{PD}{format}>html|;
+
+ $type = qq|
+ <option value=statement $form->{PD}{statement}>|.$locale->text('Statement');
+
+
+ if ($form->{media} eq 'email') {
+ $media = qq|
+ <td><select name=sendmode>
+ <option value=attachment $form->{SM}{attachment}>|.$locale->text('Attachment').qq|
+ <option value=inline $form->{SM}{inline}>|.$locale->text('In-line');
+ } else {
+ $media = qq|
+ <td><select name=media>
+ <option value=screen>|.$locale->text('Screen');
+ if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
+ for (sort keys %{LedgerSMB::Sysconfig::printer}) { $media .= qq|
+ <option value="$_">$_| }
+ }
+ }
+
+ $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
+ $media .= qq|</select></td>|;
+
+ if (${LedgerSMB::Sysconfig::latex}) {
+ $format .= qq|
+ <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq|
+ <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF');
+ }
+
+ print qq|
+<table>
+ <tr>
+ <td><select name=type>$type</select></td>
+ <td><select name=format>$format</select></td>
+ $media
+|;
+
+ if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} && $form->{media} ne 'email') {
+ print qq|
+ <td>|.$locale->text('Copies').qq|
+ <input name=copies size=2 value=$form->{copies}></td>
+|;
+ }
+
+ print qq|
+ </tr>
+</table>
+|;
+
+}
+
+
+sub e_mail {
+
+ # get name and email addresses
+ for $i (1 .. $form->{rowcount}) {
+ if ($form->{"statement_$i"}) {
+ $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
+ $form->{"statement_1"} = 1;
+ $form->{"language_code_1"} = $form->{"language_code_$i"};
+ $form->{"curr_1"} = $form->{"curr_$i"};
+ RP->get_customer(\%myconfig, \%$form);
+ $selected = 1;
+ last;
+ }
+ }
+
+ $form->error($locale->text('Nothing selected!')) unless $selected;
+
+ if ($myconfig{role} =~ /(admin|manager)/) {
+ $bcc = qq|
+ <th align=right nowrap=true>|.$locale->text('Bcc').qq|</th>
+ <td><input name=bcc size=30 value="$form->{bcc}"></td>
+|;
+ }
+
+ $title = $locale->text('E-mail Statement to [_1]', $form->{$form->{ct}});
+
+ $form->{media} = "email";
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+
+<table width=100%>
+ <tr class=listtop>
+ <th>$title</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr>
+ <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
+ <td><input name=email size=30 value="$form->{email}"></td>
+ <th align=right nowrap>|.$locale->text('Cc').qq|</th>
+ <td><input name=cc size=30 value="$form->{cc}"></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>|.$locale->text('Subject').qq|</th>
+ <td><input name=subject size=30 value="$form->{subject}"></td>
+ $bcc
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr>
+ <th align=left nowrap>|.$locale->text('Message').qq|</th>
+ </tr>
+ <tr>
+ <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+|;
+
+ &print_options;
+
+ for (qw(email cc bcc subject message type sendmode format action nextsub)) { delete $form->{$_} }
+
+ $form->hide_form;
+
+ print qq|
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+<input type="hidden" name="nextsub" value="send_email">
+
+<br>
+<button name="action" class="submit" type="submit" value="continue">|.$locale->text('Continue').qq|</button>
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+
+sub send_email {
+
+ $form->{OUT} = "${LedgerSMB::Sysconfig::sendmail}";
+ $form->{printmode} = '|-';
+
+ $form->{subject} = $locale->text('Statement - [_1]', $form->{todate}) unless $form->{subject};
+ $form->isblank("email", $locale->text('E-mail address missing!'));
+
+ RP->aging(\%myconfig, \%$form);
+
+ &print_form;
+
+ $form->redirect($locale->text('Statement sent to [_1]', $form->{$form->{ct}}));
+
+}
+
+
+
+sub print {
+
+ if ($form->{media} !~ /(screen|email)/) {
+ $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/);
+ }
+
+ for $i (1 .. $form->{rowcount}) {
+ if ($form->{"statement_$i"}) {
+ $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
+ $language_code = $form->{"language_code_$i"};
+ $curr = $form->{"curr_$i"};
+ $selected = 1;
+ last;
+ }
+ }
+
+ $form->error($locale->text('Nothing selected!')) unless $selected;
+
+
+ if ($form->{media} !~ /(screen|email)/) {
+ $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
+ $form->{printmode} = '|-';
+ $form->{"$form->{ct}_id"} = "";
+ $SIG{INT} = 'IGNORE';
+ } else {
+ $form->{"statement_1"} = 1;
+ $form->{"language_code_1"} = $language_code;
+ $form->{"curr_1"} = $curr;
+ }
+
+ RP->aging(\%myconfig, \%$form);
+
+ &print_form;
+
+ $form->redirect($locale->text('Statements sent to printer!')) if ($form->{media} !~ /(screen|email)/);
+
+}
+
+
+sub print_form {
+
+ $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
+
+ $form->{templates} = "$myconfig{templates}";
+
+ # setup variables for the form
+ @a = qw(company address businessnumber tel fax);
+ for (@a) { $form->{$_} = $myconfig{$_} }
+ $form->{address} =~ s/\\n/\n/g;
+
+ $form->format_string(@a);
+
+ $form->{IN} = "$form->{type}.html";
+
+ if ($form->{format} eq 'postscript') {
+ $form->{IN} =~ s/html$/tex/;
+ }
+ if ($form->{format} eq 'pdf') {
+ $form->{IN} =~ s/html$/tex/;
+ }
+
+ @a = qw(name address1 address2 city state zipcode country contact);
+ push @a, "$form->{ct}phone", "$form->{ct}fax", "$form->{ct}taxnumber";
+ push @a, 'email' if ! $form->{media} eq 'email';
+
+ $i = 0;
+ while (@{ $form->{AG} }) {
+
+ $ref = shift @{ $form->{AG} };
+
+ if ($ctid != $ref->{ctid}) {
+
+ $ctid = $ref->{ctid};
+ $i++;
+
+ if ($form->{"statement_$i"}) {
+
+ for (@a) { $form->{$_} = $ref->{$_} }
+ $form->format_string(@a);
+
+ $form->{$form->{ct}} = $form->{name};
+ $form->{"$form->{ct}_id"} = $ref->{ctid};
+ $form->{language_code} = $form->{"language_code_$i"};
+ $form->{currency} = $form->{"curr_$i"};
+
+ for (qw(invnumber ordnumber ponumber notes invdate duedate)) { $form->{$_} = () }
+ $form->{total} = 0;
+ foreach $item (qw(c0 c30 c60 c90)) {
+ $form->{$item} = ();
+ $form->{"${item}total"} = 0;
+ }
+
+ &statement_details($ref) if $ref->{curr} eq $form->{currency};
+
+ while ($ref) {
+
+ if (scalar (@{ $form->{AG} }) > 0) {
+ # one or more left to go
+ if ($ctid == $form->{AG}->[0]->{ctid}) {
+ $ref = shift @{ $form->{AG} };
+ &statement_details($ref) if $ref->{curr} eq $form->{currency};
+ # any more?
+ $ref = scalar (@{ $form->{AG} });
+ } else {
+ $ref = 0;
+ }
+ } else {
+ # set initial ref to 0
+ $ref = 0;
+ }
+
+ }
+
+ for ("c0", "c30", "c60", "c90", "") { $form->{"${_}total"} = $form->format_amount(\%myconfig, $form->{"${_}total"}, 2) }
+
+ $form->parse_template(\%myconfig, ${LedgerSMB::Sysconfig::userspath});
+
+ }
+ }
+ }
+
+}
+
+
+sub statement_details {
+ my ($ref) = @_;
+
+ $ref->{invdate} = $ref->{transdate};
+ my @a = qw(invnumber ordnumber ponumber notes invdate duedate);
+ for (@a) { $form->{"${_}_1"} = $ref->{$_} }
+ $form->format_string(qw(invnumber_1 ordnumber_1 ponumber_1 notes_1));
+ for (@a) { push @{ $form->{$_} }, $form->{"${_}_1"} }
+
+ foreach $item (qw(c0 c30 c60 c90)) {
+ eval { $ref->{$item} = $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2) };
+ $form->{"${item}total"} += $ref->{$item};
+ $form->{total} += $ref->{$item};
+ push @{ $form->{$item} }, $form->format_amount(\%myconfig, $ref->{$item}, 2);
+ }
+
+}
+
+
+sub generate_tax_report {
+
+ RP->tax_report(\%myconfig, \%$form);
+
+ $descvar = "$form->{accno}_description";
+ $description = $form->escape($form->{$descvar});
+ $ratevar = "$form->{accno}_rate";
+ $taxrate = $form->{"$form->{accno}_rate"};
+
+ if ($form->{accno} =~ /^gifi_/) {
+ $descvar = "gifi_$form->{accno}_description";
+ $description = $form->escape($form->{$descvar});
+ $ratevar = "gifi_$form->{accno}_rate";
+ $taxrate = $form->{"gifi_$form->{accno}_rate"};
+ }
+
+ $department = $form->escape($form->{department});
+
+ # construct href
+ $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
+
+ # construct callback
+ $description = $form->escape($form->{$descvar},1);
+ $department = $form->escape($form->{department},1);
+
+ $form->sort_order();
+
+ $callback = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
+
+ $form->{title} = $locale->text('GIFI')." - " if ($form->{accno} =~ /^gifi_/);
+
+ $title = $form->escape($form->{title});
+ $href .= "&title=$title";
+ $title = $form->escape($form->{title},1);
+ $callback .= "&title=$title";
+
+ $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
+
+ @columns = $form->sort_columns(qw(id transdate invnumber name description netamount tax total));
+
+ $form->{"l_description"} = "" if $form->{summary};
+
+ foreach $item (@columns) {
+ if ($form->{"l_$item"} eq "Y") {
+ push @column_index, $item;
+
+ # add column to href and callback
+ $callback .= "&l_$item=Y";
+ $href .= "&l_$item=Y";
+ }
+ }
+
+
+ if ($form->{l_subtotal} eq 'Y') {
+ $callback .= "&l_subtotal=Y";
+ $href .= "&l_subtotal=Y";
+ }
+
+
+ if ($form->{department}) {
+ ($department) = split /--/, $form->{department};
+ $option = $locale->text('Department')." : $department";
+ }
+
+ # if there are any dates
+ if ($form->{fromdate} || $form->{todate}) {
+ if ($form->{fromdate}) {
+ $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
+ }
+ if ($form->{todate}) {
+ $todate = $locale->date(\%myconfig, $form->{todate}, 1);
+ }
+
+ $form->{period} = "$fromdate - $todate";
+ } else {
+ $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
+ }
+
+
+ if ($form->{db} eq 'ar') {
+ $name = $locale->text('Customer');
+ $invoice = 'is.pl';
+ $arap = 'ar.pl';
+ }
+ if ($form->{db} eq 'ap') {
+ $name = $locale->text('Vendor');
+ $invoice = 'ir.pl';
+ $arap = 'ap.pl';
+ }
+
+ $option .= "<br>" if $option;
+ $option .= "$form->{period}";
+
+
+ $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>|.$locale->text('ID').qq|</th>|;
+ $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice').qq|</th>|;
+ $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</th>|;
+ $column_header{netamount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
+ $column_header{tax} = qq|<th class=listheading>|.$locale->text('Tax').qq|</th>|;
+ $column_header{total} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;
+
+ $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
+
+ $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</th>|;
+
+
+ $form->header;
+
+ print qq|
+<body>
+
+<table width=100%>
+ <tr>
+ <th class=listtop colspan=$colspan>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>$option</td>
+ </tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr class=listheading>
+|;
+
+ for (@column_index) { print "$column_header{$_}\n" }
+
+ print qq|
+ </tr>
+|;
+
+ # add sort and escape callback
+ $callback = $form->escape($callback . "&sort=$form->{sort}");
+
+ if (@{ $form->{TR} }) {
+ $sameitem = $form->{TR}->[0]->{$form->{sort}};
+ }
+
+ foreach $ref (@{ $form->{TR} }) {
+
+ $module = ($ref->{invoice}) ? $invoice : $arap;
+ $module = 'ps.pl' if $ref->{till};
+
+ if ($form->{l_subtotal} eq 'Y') {
+ if ($sameitem ne $ref->{$form->{sort}}) {
+ &tax_subtotal;
+ $sameitem = $ref->{$form->{sort}};
+ }
+ }
+
+ $totalnetamount += $ref->{netamount};
+ $totaltax += $ref->{tax};
+ $ref->{total} = $ref->{netamount} + $ref->{tax};
+
+ $subtotalnetamount += $ref->{netamount};
+ $subtotaltax += $ref->{tax};
+
+ for (qw(netamount tax total)) { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;"); }
+
+ $column_data{id} = qq|<td>$ref->{id}</td>|;
+ $column_data{invnumber} = qq|<td><a href=$module?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}</a></td>|;
+
+ for (qw(id transdate name partnumber description)) { $column_data{$_} = qq|<td>$ref->{$_}</td>| }
+
+ for (qw(netamount tax total)) { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
+
+ $i++; $i %= 2;
+ print qq|
+ <tr class=listrow$i>
+|;
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
+ </tr>
+|;
+
+ }
+
+ if ($form->{l_subtotal} eq 'Y') {
+ &tax_subtotal;
+ }
+
+
+ for (@column_index) { $column_data{$_} = qq|<th>&nbsp;</th>| }
+
+ print qq|
+ </tr>
+ <tr class=listtotal>
+|;
+
+ $total = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, "&nbsp;");
+ $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;");
+ $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, "&nbsp;");
+
+ $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
+ $column_data{tax} = qq|<th class=listtotal align=right>$totaltax</th>|;
+ $column_data{total} = qq|<th class=listtotal align=right>$total</th>|;
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+
+ print qq|
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+</body>
+</html>
+|;
+
+}
+
+
+sub tax_subtotal {
+
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $subtotal = $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax, 2, "&nbsp;");
+ $subtotalnetamount = $form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;");
+ $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, "&nbsp;");
+
+ $column_data{netamount} = "<th class=listsubtotal align=right>$subtotalnetamount</th>";
+ $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
+ $column_data{total} = "<th class=listsubtotal align=right>$subtotal</th>";
+
+ $subtotalnetamount = 0;
+ $subtotaltax = 0;
+
+ print qq|
+ <tr class=listsubtotal>
+|;
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+ </tr>
+|;
+
+}
+
+
+
+sub list_payments {
+
+
+ if ($form->{account}) {
+ ($form->{paymentaccounts}) = split /--/, $form->{account};
+ }
+ if ($form->{department}) {
+ ($department, $form->{department_id}) = split /--/, $form->{department};
+ $option = $locale->text('Department')." : $department";
+ }
+
+ RP->payments(\%myconfig, \%$form);
+
+ @columns = $form->sort_columns(qw(transdate name paid source memo));
+
+ if ($form->{till}) {
+ @columns = $form->sort_columns(qw(transdate name paid curr source till));
+ if ($myconfig{role} ne 'user') {
+ @columns = $form->sort_columns(qw(transdate name paid curr source till employee));
+ }
+ }
+
+ # construct href
+ $title = $form->escape($form->{title});
+ $form->{paymentaccounts} =~ s/ /%20/g;
+
+ $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&sort=$form->{sort}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_subtotal}&prepayment=$form->{prepayment}&paymentaccounts=$form->{paymentaccounts}&title=".$form->escape($form->{title});
+
+ $form->sort_order();
+
+ $form->{callback} = "$form->{script}?path=$form->{path}&direction=$form->{direction}&sort=$form->{sort}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_subtotal}&prepayment=$form->{prepayment}&paymentaccounts=$form->{paymentaccounts}&title=".$form->escape($form->{title},1);
+
+ if ($form->{account}) {
+ $callback .= "&account=".$form->escape($form->{account},1);
+ $href .= "&account=".$form->escape($form->{account});
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Account')." : $form->{account}";
+ }
+ if ($form->{department}) {
+ $callback .= "&department=".$form->escape($form->{department},1);
+ $href .= "&department=".$form->escape($form->{department});
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Department')." : $form->{department}";
+ }
+ if ($form->{description}) {
+ $callback .= "&description=".$form->escape($form->{description},1);
+ $href .= "&description=".$form->escape($form->{description});
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Description')." : $form->{description}";
+ }
+ if ($form->{source}) {
+ $callback .= "&source=".$form->escape($form->{source},1);
+ $href .= "&source=".$form->escape($form->{source});
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Source')." : $form->{source}";
+ }
+ if ($form->{memo}) {
+ $callback .= "&memo=".$form->escape($form->{memo},1);
+ $href .= "&memo=".$form->escape($form->{memo});
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Memo')." : $form->{memo}";
+ }
+ if ($form->{fromdate}) {
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{fromdate}, 1);
+ }
+ if ($form->{todate}) {
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{todate}, 1);
+ }
+
+ $callback = $form->escape($form->{callback});
+
+ $column_header{name} = "<th><a class=listheading href=$href&sort=name>".$locale->text('Description')."</a></th>";
+ $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
+ $column_header{paid} = "<th class=listheading>".$locale->text('Amount')."</a></th>";
+ $column_header{curr} = "<th class=listheading>".$locale->text('Curr')."</a></th>";
+ $column_header{source} = "<th><a class=listheading href=$href&sort=source>".$locale->text('Source')."</a></th>";
+ $column_header{memo} = "<th><a class=listheading href=$href&sort=memo>".$locale->text('Memo')."</a></th>";
+
+ $column_header{employee} = "<th><a class=listheading href=$href&sort=employee>".$locale->text('Salesperson')."</a></th>";
+ $column_header{till} = "<th><a class=listheading href=$href&sort=till>".$locale->text('Till')."</a></th>";
+
+ @column_index = @columns;
+ $colspan = $#column_index + 1;
+
+ $form->header;
+
+ print qq|
+<body>
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>$option</td>
+ </tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr class=listheading>
+|;
+
+ for (@column_index) { print "\n$column_header{$_}" }
+
+ print qq|
+ </tr>
+|;
+
+
+ foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
+
+ next unless @{ $form->{$ref->{id}} };
+
+ print qq|
+ <tr>
+ <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
+ </tr>
+|;
+
+ if (@{ $form->{$ref->{id}} }) {
+ $sameitem = $form->{$ref->{id}}[0]->{$form->{sort}};
+ }
+
+ foreach $payment (@{ $form->{$ref->{id}} }) {
+
+ if ($form->{l_subtotal}) {
+ if ($payment->{$form->{sort}} ne $sameitem) {
+ # print subtotal
+ &payment_subtotal;
+ }
+ }
+
+ next if ($form->{till} && ! $payment->{till});
+
+ $column_data{name} = "<td>$payment->{name}&nbsp;</td>";
+ $column_data{transdate} = "<td>$payment->{transdate}&nbsp;</td>";
+ $column_data{paid} = "<td align=right>".$form->format_amount(\%myconfig, $payment->{paid}, 2, "&nbsp;")."</td>";
+ $column_data{curr} = "<td>$payment->{curr}</td>";
+ $column_data{source} = "<td>$payment->{source}&nbsp;</td>";
+ $column_data{memo} = "<td>$payment->{memo}&nbsp;</td>";
+ $column_data{employee} = "<td>$payment->{employee}&nbsp;</td>";
+ $column_data{till} = "<td>$payment->{till}&nbsp;</td>";
+
+ $subtotalpaid += $payment->{paid};
+ $accounttotalpaid += $payment->{paid};
+ $totalpaid += $payment->{paid};
+
+ $i++; $i %= 2;
+ print qq|
+ <tr class=listrow$i>
+|;
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+ </tr>
+|;
+
+ $sameitem = $payment->{$form->{sort}};
+
+ }
+
+ &payment_subtotal if $form->{l_subtotal};
+
+ # print account totals
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $accounttotalpaid, 2, "&nbsp;")."</th>";
+
+ print qq|
+ <tr class=listtotal>
+|;
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+ </tr>
+|;
+
+ $accounttotalpaid = 0;
+
+ }
+
+
+ # print total
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;")."</th>";
+
+ print qq|
+ <tr class=listtotal>
+|;
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+ </tr>
+
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+|;
+
+ if ($form->{lynx}) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
+
+</body>
+</html>
+|;
+
+}
+
+
+sub payment_subtotal {
+
+ if ($subtotalpaid != 0) {
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, "&nbsp;")."</th>";
+
+ print qq|
+ <tr class=listsubtotal>
+|;
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+ </tr>
+|;
+ }
+
+ $subtotalpaid = 0;
+
+}
+
+