summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xLedgerSMB.pm734
-rw-r--r--LedgerSMB/AA.pm1580
-rw-r--r--LedgerSMB/AM.pm1975
-rw-r--r--LedgerSMB/BP.pm516
-rw-r--r--LedgerSMB/CA.pm596
-rw-r--r--LedgerSMB/CP.pm935
-rw-r--r--LedgerSMB/CT.pm1417
-rw-r--r--LedgerSMB/Contact.pm1
-rw-r--r--LedgerSMB/CreditCard.pm3
-rw-r--r--LedgerSMB/CreditCard/Config.pm4
-rw-r--r--LedgerSMB/CreditCard/TrustCommerce.pm96
-rw-r--r--LedgerSMB/CreditCard/TrustCommerce/Config.pm9
-rw-r--r--LedgerSMB/DBObject.pm294
-rw-r--r--LedgerSMB/Employee.pm23
-rw-r--r--LedgerSMB/Form.pm4382
-rw-r--r--LedgerSMB/GL.pm728
-rw-r--r--LedgerSMB/HR.pm316
-rw-r--r--LedgerSMB/IC.pm2660
-rw-r--r--LedgerSMB/IR.pm1984
-rw-r--r--LedgerSMB/IS.pm3324
-rw-r--r--LedgerSMB/Inifile.pm95
-rw-r--r--LedgerSMB/JC.pm827
-rw-r--r--LedgerSMB/Locale.pm197
-rw-r--r--LedgerSMB/Location.pm27
-rw-r--r--LedgerSMB/Log.pm50
-rw-r--r--LedgerSMB/Mailer.pm152
-rw-r--r--LedgerSMB/Menu.pm136
-rw-r--r--LedgerSMB/Num2text.pm1904
-rw-r--r--LedgerSMB/OE.pm4291
-rw-r--r--LedgerSMB/OP.pm136
-rw-r--r--LedgerSMB/PE.pm2119
-rw-r--r--LedgerSMB/PriceMatrix.pm254
-rw-r--r--LedgerSMB/RC.pm589
-rw-r--r--LedgerSMB/RESTXML/Document/Base.pm52
-rw-r--r--LedgerSMB/RESTXML/Document/Customer.pm27
-rw-r--r--LedgerSMB/RESTXML/Document/Customer_Search.pm91
-rw-r--r--LedgerSMB/RESTXML/Document/Part.pm27
-rw-r--r--LedgerSMB/RESTXML/Document/Part_Search.pm89
-rw-r--r--LedgerSMB/RESTXML/Document/SalesOrder.pm11
-rw-r--r--LedgerSMB/RESTXML/Document/Session.pm15
-rw-r--r--LedgerSMB/RESTXML/Handler.pm207
-rw-r--r--LedgerSMB/RP.pm2930
-rw-r--r--LedgerSMB/Report.pm2
-rw-r--r--LedgerSMB/Session.pm14
-rwxr-xr-xLedgerSMB/Session/DB.pm375
-rw-r--r--LedgerSMB/Setting.pm202
-rw-r--r--LedgerSMB/Sysconfig.pm89
-rw-r--r--LedgerSMB/Tax.pm109
-rwxr-xr-xLedgerSMB/Taxes/Simple.pm48
-rwxr-xr-xLedgerSMB/Template.pm112
-rwxr-xr-xLedgerSMB/Template/HTML.pm37
-rw-r--r--LedgerSMB/User.pm1356
-rwxr-xr-xLedgerSMB/locales.pl537
-rwxr-xr-xSL2LS.pl52
-rwxr-xr-xadmin.pl47
-rw-r--r--bin/aa.pl3779
-rw-r--r--bin/admin.pl1398
-rw-r--r--bin/am.pl3861
-rw-r--r--bin/ap.pl9
-rw-r--r--bin/ar.pl9
-rw-r--r--bin/arap.pl1160
-rw-r--r--bin/arapprn.pl1535
-rw-r--r--bin/bp.pl1164
-rw-r--r--bin/ca.pl638
-rw-r--r--bin/cp.pl3088
-rw-r--r--bin/ct.pl3613
-rw-r--r--bin/gl.pl1661
-rw-r--r--bin/hr.pl1520
-rw-r--r--bin/ic.pl4861
-rw-r--r--bin/io.pl3695
-rw-r--r--bin/ir.pl1438
-rw-r--r--bin/is.pl1499
-rw-r--r--bin/jc.pl4179
-rw-r--r--bin/login.pl256
-rw-r--r--bin/menu.pl373
-rw-r--r--bin/oe.pl4616
-rw-r--r--bin/pe.pl3151
-rw-r--r--bin/pos.pl2341
-rw-r--r--bin/ps.pl21
-rw-r--r--bin/pw.pl41
-rw-r--r--bin/rc.pl985
-rw-r--r--bin/rp.pl5488
-rw-r--r--common.pl69
-rw-r--r--custom.pl2
-rw-r--r--dists/win32/shebang-activeperl.pl20
-rw-r--r--dists/win32/shebang-vanilla.pl20
-rw-r--r--dists/win32/wix/uuidgen.pl10
-rw-r--r--doc/samples/lsmb02-cli-example.pl89
-rw-r--r--drivers/pd3000.pl40
-rwxr-xr-ximport_members.pl334
-rwxr-xr-xlogin.pl23
-rwxr-xr-xlsmb.pl60
-rwxr-xr-xmenu.pl169
-rwxr-xr-xnet-setup.pl1082
-rw-r--r--pos.conf.pl65
-rwxr-xr-xrest.pl6
-rw-r--r--utils/cli/ledgersmb_cli.pl134
-rw-r--r--utils/notify_short/config.pl8
-rw-r--r--utils/notify_short/listener.pl46
-rwxr-xr-xutils/pos/directnet.pl17
100 files changed, 51765 insertions, 45591 deletions
diff --git a/LedgerSMB.pm b/LedgerSMB.pm
index 51f10115..5727edbe 100755
--- a/LedgerSMB.pm
+++ b/LedgerSMB.pm
@@ -1,3 +1,4 @@
+
=head1 NAME
LedgerSMB The Base class for many LedgerSMB objects, including DBObject.
@@ -96,460 +97,465 @@ non-numbers.
=cut
use CGI;
-use Math::BigFloat lib=>'GMP';
+use Math::BigFloat lib => 'GMP';
use LedgerSMB::Sysconfig;
use Data::Dumper;
use strict;
package LedgerSMB;
-
sub new {
- my $type = shift @_;
- my $argstr = shift @_;
+ my $type = shift @_;
+ my $argstr = shift @_;
- my $self = {};
- $self->{version} = "1.3.0 Alpha 0 Pre";
- $self->{dbversion} = "1.2.0";
- bless $self, $type;
-
- my $query = ($argstr) ? new CGI($argstr) : new CGI;
- my $params = $query->Vars;
+ my $self = {};
+ $self->{version} = "1.3.0 Alpha 0 Pre";
+ $self->{dbversion} = "1.2.0";
+ bless $self, $type;
- $self->merge($params);
+ my $query = ($argstr) ? new CGI($argstr) : new CGI;
+ my $params = $query->Vars;
- $self->{action} =~ s/\W/_/g;
- $self->{action} = lc $self->{action};
+ $self->merge($params);
+ $self->{action} =~ s/\W/_/g;
+ $self->{action} = lc $self->{action};
- if ($self->{path} eq "bin/lynx"){
- $self->{menubar} = 1;
- #menubar will be deprecated, replaced with below
- $self->{lynx} = 1;
- $self->{path} = "bin/lynx";
- } else {
- $self->{path} = "bin/mozilla";
+ if ( $self->{path} eq "bin/lynx" ) {
+ $self->{menubar} = 1;
- }
+ #menubar will be deprecated, replaced with below
+ $self->{lynx} = 1;
+ $self->{path} = "bin/lynx";
+ }
+ else {
+ $self->{path} = "bin/mozilla";
- if (($self->{script} =~ m#(..|\\|/)#)){
- $self->error("Access Denied");
- }
-
+ }
- $self;
+ if ( ( $self->{script} =~ m#(..|\\|/)# ) ) {
+ $self->error("Access Denied");
+ }
-}
+ $self;
+}
sub debug {
- my $self = shift @_;
- my %args = @_;
- my $file = $args{file};
- my $d = Data::Dumper->new([@_]);
- $d->Sortkeys(1);
-
- if ($file) {
- open(FH, '>', "$file") or die $!;
- print FH $d->Dump();
- close(FH);
- } else {
- print "\n";
- print $d->Dump();
- }
-
-}
+ my $self = shift @_;
+ my %args = @_;
+ my $file = $args{file};
+ my $d = Data::Dumper->new( [@_] );
+ $d->Sortkeys(1);
+
+ if ($file) {
+ open( FH, '>', "$file" ) or die $!;
+ print FH $d->Dump();
+ close(FH);
+ }
+ else {
+ print "\n";
+ print $d->Dump();
+ }
+}
sub escape {
- my ($self) = @_;
- my %args = @_;
- my $str = $args{string};
+ my ($self) = @_;
+ my %args = @_;
+ my $str = $args{string};
- my $regex = qr/([^a-zA-Z0-9_.-])/;
- $str =~ s/$regex/sprintf("%%%02x", ord($1))/ge;
- $str;
+ my $regex = qr/([^a-zA-Z0-9_.-])/;
+ $str =~ s/$regex/sprintf("%%%02x", ord($1))/ge;
+ $str;
}
-
sub is_blank {
- my $self = shift @_;
- my %args = @_;
- my $name = $args{name};
- my $rc;
- if ($self->{$name} =~ /^\s*$/){
- $rc = 1;
- } else {
- $rc = 0;
- }
- $rc;
+ my $self = shift @_;
+ my %args = @_;
+ my $name = $args{name};
+ my $rc;
+ if ( $self->{$name} =~ /^\s*$/ ) {
+ $rc = 1;
+ }
+ else {
+ $rc = 0;
+ }
+ $rc;
}
sub is_run_mode {
- my $self = shift @_;
- my $mode = lc shift @_;
- my $rc = 0;
- if ($mode eq 'cgi' && $ENV{GATEWAY_INTERFACE}){
- $rc = 1;
- }
- elsif ($mode eq 'cli' && ! ($ENV{GATEWAY_INTERFACE} || $ENV{MOD_PERL})){
- $rc = 1;
- } elsif ($mode eq 'mod_perl' && $ENV{MOD_PERL}){
- $rc = 1;
- }
- $rc;
+ my $self = shift @_;
+ my $mode = lc shift @_;
+ my $rc = 0;
+ if ( $mode eq 'cgi' && $ENV{GATEWAY_INTERFACE} ) {
+ $rc = 1;
+ }
+ elsif ( $mode eq 'cli' && !( $ENV{GATEWAY_INTERFACE} || $ENV{MOD_PERL} ) ) {
+ $rc = 1;
+ }
+ elsif ( $mode eq 'mod_perl' && $ENV{MOD_PERL} ) {
+ $rc = 1;
+ }
+ $rc;
}
sub num_text_rows {
- my $self = shift @_;
- my %args = @_;
- my $string = $args{string};
- my $cols = $args{cols};
- my $maxrows = $args{max};
-
- my $rows = 0;
-
- for (split /\n/, $string) {
- my $line = $_;
- while (length($line) > $cols){
- my $fragment = substr($line, 0, $cols + 1);
- my $fragment = s/^(.*)\S*$/$1/;
- $line = s/$fragment//;
- if ($line eq $fragment){ # No word breaks!
- $line = "";
- }
- ++$rows;
- }
- ++$rows;
- }
-
- if (! defined $maxrows){
- $maxrows = $rows;
- }
-
- return ($rows > $maxrows) ? $maxrows : $rows;
+ my $self = shift @_;
+ my %args = @_;
+ my $string = $args{string};
+ my $cols = $args{cols};
+ my $maxrows = $args{max};
+
+ my $rows = 0;
+
+ for ( split /\n/, $string ) {
+ my $line = $_;
+ while ( length($line) > $cols ) {
+ my $fragment = substr( $line, 0, $cols + 1 );
+ my $fragment = s/^(.*)\S*$/$1/;
+ $line = s/$fragment//;
+ if ( $line eq $fragment ) { # No word breaks!
+ $line = "";
+ }
+ ++$rows;
+ }
+ ++$rows;
+ }
+
+ if ( !defined $maxrows ) {
+ $maxrows = $rows;
+ }
+
+ return ( $rows > $maxrows ) ? $maxrows : $rows;
}
-
sub redirect {
- my $self = shift @_;
- my %args = @_;
- my $msg = $args{msg};
+ my $self = shift @_;
+ my %args = @_;
+ my $msg = $args{msg};
- if ($self->{callback} || !$msg) {
+ if ( $self->{callback} || !$msg ) {
- main::redirect();
- } else {
+ main::redirect();
+ }
+ else {
- $self->info($msg);
- }
+ $self->info($msg);
+ }
}
# TODO: Either we should have an amount class with formats and such attached
# Or maybe we should move this into the user class...
sub format_amount {
- # Based on SQL-Ledger's Form::format_amount
- my $self = shift @_;
- my %args = @_;
- my $myconfig = $args{user};
- my $amount = $args{amount};
- my $places = $args{precision};
- my $dash = $args{neg_format};
-
- my $negative ;
- if ($amount){
- $amount = $self->parse_amount($myconfig, $amount);
- $negative = ($amount < 0);
- $amount =~ s/-//;
- }
-
- if ($places =~ /\d+/) {
- #$places = 4 if $places == 2;
- $amount = $self->round_amount($amount, $places);
- }
-
- # is the amount negative
-
- # Parse $myconfig->{numberformat}
-
-
-
- my ($ts, $ds) = ($1, $2);
-
- if ($amount) {
-
- if ($myconfig->{numberformat}) {
-
- my ($whole, $dec) = split /\./, "$amount";
- $amount = join '', reverse split //, $whole;
-
- if ($places) {
- $dec .= "0" x $places;
- $dec = substr($dec, 0, $places);
- }
-
- if ($myconfig->{numberformat} eq '1,000.00') {
- $amount =~ s/\d{3,}?/$&,/g;
- $amount =~ s/,$//;
- $amount = join '', reverse split //, $amount;
- $amount .= "\.$dec" if ($dec ne "");
- }
-
- if ($myconfig->{numberformat} eq '1 000.00') {
- $amount =~ s/\d{3,}?/$& /g;
- $amount =~ s/\s$//;
- $amount = join '', reverse split //, $amount;
- $amount .= "\.$dec" if ($dec ne "");
- }
-
- if ($myconfig->{numberformat} eq "1'000.00") {
- $amount =~ s/\d{3,}?/$&'/g;
- $amount =~ s/'$//;
- $amount = join '', reverse split //, $amount;
- $amount .= "\.$dec" if ($dec ne "");
- }
-
- if ($myconfig->{numberformat} eq '1.000,00') {
- $amount =~ s/\d{3,}?/$&./g;
- $amount =~ s/\.$//;
- $amount = join '', reverse split //, $amount;
- $amount .= ",$dec" if ($dec ne "");
- }
-
- if ($myconfig->{numberformat} eq '1000,00') {
- $amount = "$whole";
- $amount .= ",$dec" if ($dec ne "");
- }
-
- if ($myconfig->{numberformat} eq '1000.00') {
- $amount = "$whole";
- $amount .= ".$dec" if ($dec ne "");
- }
-
- if ($dash =~ /-/) {
- $amount = ($negative) ? "($amount)" : "$amount";
- } elsif ($dash =~ /DRCR/) {
- $amount = ($negative) ? "$amount DR" : "$amount CR";
- } else {
- $amount = ($negative) ? "-$amount" : "$amount";
- }
- }
-
- } else {
-
- if ($dash eq "0" && $places) {
-
- if ($myconfig->{numberformat} eq '1.000,00') {
- $amount = "0".","."0" x $places;
- } else {
- $amount = "0"."."."0" x $places;
- }
-
- } else {
- $amount = ($dash ne "") ? "$dash" : "";
- }
- }
-
- $amount;
+
+ # Based on SQL-Ledger's Form::format_amount
+ my $self = shift @_;
+ my %args = @_;
+ my $myconfig = $args{user};
+ my $amount = $args{amount};
+ my $places = $args{precision};
+ my $dash = $args{neg_format};
+
+ my $negative;
+ if ($amount) {
+ $amount = $self->parse_amount( $myconfig, $amount );
+ $negative = ( $amount < 0 );
+ $amount =~ s/-//;
+ }
+
+ if ( $places =~ /\d+/ ) {
+
+ #$places = 4 if $places == 2;
+ $amount = $self->round_amount( $amount, $places );
+ }
+
+ # is the amount negative
+
+ # Parse $myconfig->{numberformat}
+
+ my ( $ts, $ds ) = ( $1, $2 );
+
+ if ($amount) {
+
+ if ( $myconfig->{numberformat} ) {
+
+ my ( $whole, $dec ) = split /\./, "$amount";
+ $amount = join '', reverse split //, $whole;
+
+ if ($places) {
+ $dec .= "0" x $places;
+ $dec = substr( $dec, 0, $places );
+ }
+
+ if ( $myconfig->{numberformat} eq '1,000.00' ) {
+ $amount =~ s/\d{3,}?/$&,/g;
+ $amount =~ s/,$//;
+ $amount = join '', reverse split //, $amount;
+ $amount .= "\.$dec" if ( $dec ne "" );
+ }
+
+ if ( $myconfig->{numberformat} eq '1 000.00' ) {
+ $amount =~ s/\d{3,}?/$& /g;
+ $amount =~ s/\s$//;
+ $amount = join '', reverse split //, $amount;
+ $amount .= "\.$dec" if ( $dec ne "" );
+ }
+
+ if ( $myconfig->{numberformat} eq "1'000.00" ) {
+ $amount =~ s/\d{3,}?/$&'/g;
+ $amount =~ s/'$//;
+ $amount = join '', reverse split //, $amount;
+ $amount .= "\.$dec" if ( $dec ne "" );
+ }
+
+ if ( $myconfig->{numberformat} eq '1.000,00' ) {
+ $amount =~ s/\d{3,}?/$&./g;
+ $amount =~ s/\.$//;
+ $amount = join '', reverse split //, $amount;
+ $amount .= ",$dec" if ( $dec ne "" );
+ }
+
+ if ( $myconfig->{numberformat} eq '1000,00' ) {
+ $amount = "$whole";
+ $amount .= ",$dec" if ( $dec ne "" );
+ }
+
+ if ( $myconfig->{numberformat} eq '1000.00' ) {
+ $amount = "$whole";
+ $amount .= ".$dec" if ( $dec ne "" );
+ }
+
+ if ( $dash =~ /-/ ) {
+ $amount = ($negative) ? "($amount)" : "$amount";
+ }
+ elsif ( $dash =~ /DRCR/ ) {
+ $amount = ($negative) ? "$amount DR" : "$amount CR";
+ }
+ else {
+ $amount = ($negative) ? "-$amount" : "$amount";
+ }
+ }
+
+ }
+ else {
+
+ if ( $dash eq "0" && $places ) {
+
+ if ( $myconfig->{numberformat} eq '1.000,00' ) {
+ $amount = "0" . "," . "0" x $places;
+ }
+ else {
+ $amount = "0" . "." . "0" x $places;
+ }
+
+ }
+ else {
+ $amount = ( $dash ne "" ) ? "$dash" : "";
+ }
+ }
+
+ $amount;
}
# This should probably go to the User object too.
sub parse_amount {
- my $self = shift @_;
- my %args = @_;
- my $myconfig = $args{user};
- my $amount = $args{amount};
-
- if ($amount eq '' or $amount == undef){
- return 0;
- }
-
- if (UNIVERSAL::isa($amount, 'Math::BigFloat')){ # Amount may not be an object
- return $amount;
- }
- my $numberformat = $myconfig->{numberformat};
-
-
- if (($numberformat eq '1.000,00') ||
- ($numberformat eq '1000,00')) {
-
- $amount =~ s/\.//g;
- $amount =~ s/,/./;
- }
- if ($numberformat eq '1 000.00'){
- $amount =~ s/\s//g;
- }
-
- if ($numberformat eq "1'000.00") {
- $amount =~ s/'//g;
- }
-
-
- $amount =~ s/,//g;
- if ($amount =~ s/\((\d*\.?\d*)\)/$1/){
- $amount = $1 * -1;
- }
- if ($amount =~ s/(\d*\.?\d*)\s?DR/$1/){
- $amount = $1 * -1;
- }
- $amount =~ s/\s?CR//;
- $amount = new Math::BigFloat($amount);
- return ($amount * 1);
+ my $self = shift @_;
+ my %args = @_;
+ my $myconfig = $args{user};
+ my $amount = $args{amount};
+
+ if ( $amount eq '' or $amount == undef ) {
+ return 0;
+ }
+
+ if ( UNIVERSAL::isa( $amount, 'Math::BigFloat' ) )
+ { # Amount may not be an object
+ return $amount;
+ }
+ my $numberformat = $myconfig->{numberformat};
+
+ if ( ( $numberformat eq '1.000,00' )
+ || ( $numberformat eq '1000,00' ) )
+ {
+
+ $amount =~ s/\.//g;
+ $amount =~ s/,/./;
+ }
+ if ( $numberformat eq '1 000.00' ) {
+ $amount =~ s/\s//g;
+ }
+
+ if ( $numberformat eq "1'000.00" ) {
+ $amount =~ s/'//g;
+ }
+
+ $amount =~ s/,//g;
+ if ( $amount =~ s/\((\d*\.?\d*)\)/$1/ ) {
+ $amount = $1 * -1;
+ }
+ if ( $amount =~ s/(\d*\.?\d*)\s?DR/$1/ ) {
+ $amount = $1 * -1;
+ }
+ $amount =~ s/\s?CR//;
+ $amount = new Math::BigFloat($amount);
+ return ( $amount * 1 );
}
-
sub round_amount {
- my ($self, $amount, $places) = @_;
+ my ( $self, $amount, $places ) = @_;
- # These rounding rules follow from the previous implementation.
- # They should be changed to allow different rules for different accounts.
- Math::BigFloat->round_mode('+inf') if $amount >= 0;
- Math::BigFloat->round_mode('-inf') if $amount < 0;
+ # These rounding rules follow from the previous implementation.
+ # They should be changed to allow different rules for different accounts.
+ Math::BigFloat->round_mode('+inf') if $amount >= 0;
+ Math::BigFloat->round_mode('-inf') if $amount < 0;
- $amount = Math::BigFloat->new($amount)->ffround(-$places) if $places >= 0;
- $amount = Math::BigFloat->new($amount)->ffround(-($places-1)) if $places < 0;
+ $amount = Math::BigFloat->new($amount)->ffround( -$places ) if $places >= 0;
+ $amount = Math::BigFloat->new($amount)->ffround( -( $places - 1 ) )
+ if $places < 0;
- return $amount;
+ return $amount;
}
sub call_procedure {
- my $self = shift @_;
- my %args = @_;
- my $procname = $args{procname};
- my @args = @{$args{args}};
- my $argstr = "";
- my @results;
- for (1 .. scalar @args){
- $argstr .= "?, ";
- }
- $argstr =~ s/\, $//;
- my $query = "SELECT * FROM $procname()";
- $query =~ s/\(\)/($argstr)/;
- my $sth = $self->{dbh}->prepare($query);
- $sth->execute(@args);
- while (my $ref = $sth->fetchrow_hashref('NAME_lc')){
- push @results, $ref;
- }
- @results;
+ my $self = shift @_;
+ my %args = @_;
+ my $procname = $args{procname};
+ my @args = @{ $args{args} };
+ my $argstr = "";
+ my @results;
+ for ( 1 .. scalar @args ) {
+ $argstr .= "?, ";
+ }
+ $argstr =~ s/\, $//;
+ my $query = "SELECT * FROM $procname()";
+ $query =~ s/\(\)/($argstr)/;
+ my $sth = $self->{dbh}->prepare($query);
+ $sth->execute(@args);
+ while ( my $ref = $sth->fetchrow_hashref('NAME_lc') ) {
+ push @results, $ref;
+ }
+ @results;
}
# This should probably be moved to User too...
sub date_to_number {
- #based on SQL-Ledger's Form::datetonum
- my $self = shift @_;
- my %args = @_;
- my $myconfig = $args{user};
- my $date = $args{date};
- my ($yy, $mm, $dd);
- if ($date && $date =~ /\D/) {
+ #based on SQL-Ledger's Form::datetonum
+ my $self = shift @_;
+ my %args = @_;
+ my $myconfig = $args{user};
+ my $date = $args{date};
- if ($myconfig->{dateformat} =~ /^yy/) {
- ($yy, $mm, $dd) = split /\D/, $date;
- }
+ my ( $yy, $mm, $dd );
+ if ( $date && $date =~ /\D/ ) {
- if ($myconfig->{dateformat} =~ /^mm/) {
- ($mm, $dd, $yy) = split /\D/, $date;
- }
+ if ( $myconfig->{dateformat} =~ /^yy/ ) {
+ ( $yy, $mm, $dd ) = split /\D/, $date;
+ }
- if ($myconfig->{dateformat} =~ /^dd/) {
- ($dd, $mm, $yy) = split /\D/, $date;
- }
+ if ( $myconfig->{dateformat} =~ /^mm/ ) {
+ ( $mm, $dd, $yy ) = split /\D/, $date;
+ }
- $dd *= 1;
- $mm *= 1;
- $yy += 2000 if length $yy == 2;
+ if ( $myconfig->{dateformat} =~ /^dd/ ) {
+ ( $dd, $mm, $yy ) = split /\D/, $date;
+ }
- $dd = substr("0$dd", -2);
- $mm = substr("0$mm", -2);
+ $dd *= 1;
+ $mm *= 1;
+ $yy += 2000 if length $yy == 2;
- $date = "$yy$mm$dd";
- }
+ $dd = substr( "0$dd", -2 );
+ $mm = substr( "0$mm", -2 );
- $date;
-}
+ $date = "$yy$mm$dd";
+ }
+ $date;
+}
# Database routines used throughout
sub db_init {
- my $self = shift @_;
- my %args = @_;
- my $myconfig = $args{user};
+ my $self = shift @_;
+ my %args = @_;
+ my $myconfig = $args{user};
- my $dbh = DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser},
- $myconfig->{dbpasswd}, {AutoCommit => 0}) or $self->dberror;
+ my $dbh = DBI->connect(
+ $myconfig->{dbconnect}, $myconfig->{dbuser},
+ $myconfig->{dbpasswd}, { AutoCommit => 0 }
+ ) or $self->dberror;
- $dbh->{pg_server_prepare} = 0;
+ $dbh->{pg_server_prepare} = 0;
- if ($myconfig->{dboptions}) {
- $dbh->do($myconfig->{dboptions});
- }
+ if ( $myconfig->{dboptions} ) {
+ $dbh->do( $myconfig->{dboptions} );
+ }
- my $query =
- "SELECT t.extends,
+ my $query = "SELECT t.extends,
coalesce (t.table_name, 'custom_' || extends)
|| ':' || f.field_name as field_def
FROM custom_table_catalog t
JOIN custom_field_catalog f USING (table_id)";
- my $sth = $self->{dbh}->prepare($query);
- $sth->execute;
- my $ref;
- while ($ref = $sth->fetchrow_hashref('NAME_lc')){
- push @{$self->{custom_db_fields}{$ref->{extends}}},
- $ref->{field_def};
- }
+ my $sth = $self->{dbh}->prepare($query);
+ $sth->execute;
+ my $ref;
+ while ( $ref = $sth->fetchrow_hashref('NAME_lc') ) {
+ push @{ $self->{custom_db_fields}{ $ref->{extends} } },
+ $ref->{field_def};
+ }
}
sub redo_rows {
- my $self = shift @_;
- my %args = @_;
- my @flds = @{$args{fields}};
- my $count = $args{count};
- my $index = ($args{index}) ? $args{index} : 'runningnumber';
-
- my @rows;
- my $i; # incriment counter use only
- for $i (1 .. $count){
- my $temphash = {_inc => $i};
- for my $fld (@flds){
- $temphash->{$fld} = $self->{"$fld"."_$i"}
- }
- push @rows, $temphash;
- }
- $i = 1;
- for my $row (sort {$a->{index} <=> $b->{index}} @rows){
- for my $fld (@flds){
- $self->{"$fld"."_$i"} = $row->{$fld};
- }
- ++$i;
- }
+ my $self = shift @_;
+ my %args = @_;
+ my @flds = @{ $args{fields} };
+ my $count = $args{count};
+ my $index = ( $args{index} ) ? $args{index} : 'runningnumber';
+
+ my @rows;
+ my $i; # incriment counter use only
+ for $i ( 1 .. $count ) {
+ my $temphash = { _inc => $i };
+ for my $fld (@flds) {
+ $temphash->{$fld} = $self->{ "$fld" . "_$i" };
+ }
+ push @rows, $temphash;
+ }
+ $i = 1;
+ for my $row ( sort { $a->{index} <=> $b->{index} } @rows ) {
+ for my $fld (@flds) {
+ $self->{ "$fld" . "_$i" } = $row->{$fld};
+ }
+ ++$i;
+ }
}
-
sub merge {
- my ($self, $src) = @_;
- for my $arg ($self, $src){
- shift;
- }
- my %args = @_;
- my @keys = @{$args{keys}};
- my $index = $args{index};
- if (! scalar @keys){
- @keys = keys %{$src};
- }
- for my $arg (keys %$src){
- my $dst_arg;
- if ($index){
- $dst_arg = $arg . "_$index";
- } else {
- $dst_arg = $arg;
- }
- $self->{$dst_arg} = $src->{$arg};
- }
+ my ( $self, $src ) = @_;
+ for my $arg ( $self, $src ) {
+ shift;
+ }
+ my %args = @_;
+ my @keys = @{ $args{keys} };
+ my $index = $args{index};
+ if ( !scalar @keys ) {
+ @keys = keys %{$src};
+ }
+ for my $arg ( keys %$src ) {
+ my $dst_arg;
+ if ($index) {
+ $dst_arg = $arg . "_$index";
+ }
+ else {
+ $dst_arg = $arg;
+ }
+ $self->{$dst_arg} = $src->{$arg};
+ }
}
1;
diff --git a/LedgerSMB/AA.pm b/LedgerSMB/AA.pm
index 77c97b0a..e6d7b573 100644
--- a/LedgerSMB/AA.pm
+++ b/LedgerSMB/AA.pm
@@ -1,5 +1,5 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
# Copyright (C) 2006
@@ -20,7 +20,7 @@
#
# Contributors:
#
-#
+#
# See COPYRIGHT file for copyright information
#======================================================================
#
@@ -38,237 +38,258 @@ use LedgerSMB::Sysconfig;
sub post_transaction {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my $query;
- my $sth;
-
- my $null;
- ($null, $form->{department_id}) = split(/--/, $form->{department});
- $form->{department_id} *= 1;
-
- my $ml = 1;
- my $table = 'ar';
- my $buysell = 'buy';
- my $ARAP = 'AR';
- my $invnumber = "sinumber";
- my $keepcleared;
-
- if ($form->{vc} eq 'vendor') {
- $table = 'ap';
- $buysell = 'sell';
- $ARAP = 'AP';
- $ml = -1;
- $invnumber = "vinumber";
- }
-
- if ($form->{currency} eq $form->{defaultcurrency}) {
- $form->{exchangerate} = 1;
- } else {
- $exchangerate = $form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, $buysell);
-
- $form->{exchangerate} = ($exchangerate) ? $exchangerate : $form->parse_amount($myconfig, $form->{exchangerate});
- }
-
- my @taxaccounts = split / /, $form->{taxaccounts};
- my $tax = 0;
- my $fxtax = 0;
- my $amount;
- my $diff;
-
- my %tax = ();
- my $accno;
-
- # add taxes
- foreach $accno (@taxaccounts) {
- $fxtax += $tax{fxamount}{$accno} = $form->parse_amount($myconfig, $form->{"tax_$accno"});
- $tax += $tax{fxamount}{$accno};
-
- push @{ $form->{acc_trans}{taxes} }, {
- accno => $accno,
- amount => $tax{fxamount}{$accno},
- project_id => undef,
- fx_transaction => 0 };
-
- $amount = $tax{fxamount}{$accno} * $form->{exchangerate};
- $tax{amount}{$accno} = $form->round_amount($amount - $diff, 2);
- $diff = $tax{amount}{$accno} - ($amount - $diff);
- $amount = $tax{amount}{$accno} - $tax{fxamount}{$accno};
- $tax += $amount;
-
- if ($form->{currency} ne $form->{defaultcurrency}) {
- push @{ $form->{acc_trans}{taxes} }, {
- accno => $accno,
- amount => $amount,
- project_id => undef,
- fx_transaction => 1 };
- }
-
- }
-
- my %amount = ();
- my $fxinvamount = 0;
- for (1 .. $form->{rowcount}) {
- $fxinvamount += $amount{fxamount}{$_} = $form->parse_amount($myconfig, $form->{"amount_$_"})
- }
-
- $form->{taxincluded} *= 1;
-
- my $i;
- my $project_id;
- my $cleared = 0;
-
- $diff = 0;
- # deduct tax from amounts if tax included
- for $i (1 .. $form->{rowcount}) {
-
- if ($amount{fxamount}{$i}) {
-
- if ($form->{taxincluded}) {
- $amount = ($fxinvamount) ? $fxtax * $amount{fxamount}{$i} / $fxinvamount : 0;
- $amount{fxamount}{$i} -= $amount;
- }
-
- # multiply by exchangerate
- $amount = $amount{fxamount}{$i} * $form->{exchangerate};
- $amount{amount}{$i} = $form->round_amount($amount - $diff, 2);
- $diff = $amount{amount}{$i} - ($amount - $diff);
-
- ($null, $project_id) = split /--/, $form->{"projectnumber_$i"};
- $project_id ||= undef;
- ($accno) = split /--/, $form->{"${ARAP}_amount_$i"};
-
- if ($keepcleared) {
- $cleared = ($form->{"cleared_$i"}) ? 1 : 0;
- }
-
- push @{ $form->{acc_trans}{lineitems} }, {
- accno => $accno,
- amount => $amount{fxamount}{$i},
- project_id => $project_id,
- description => $form->{"description_$i"},
- cleared => $cleared,
- fx_transaction => 0 };
-
- if ($form->{currency} ne $form->{defaultcurrency}) {
- $amount = $amount{amount}{$i} - $amount{fxamount}{$i};
- push @{ $form->{acc_trans}{lineitems} }, {
- accno => $accno,
- amount => $amount,
- project_id => $project_id,
- description => $form->{"description_$i"},
- cleared => $cleared,
- fx_transaction => 1 };
- }
- }
- }
-
-
- my $invnetamount = 0;
- for (@{ $form->{acc_trans}{lineitems} }) { $invnetamount += $_->{amount} }
- my $invamount = $invnetamount + $tax;
-
- # adjust paidaccounts if there is no date in the last row
- $form->{paidaccounts}--
- unless ($form->{"datepaid_$form->{paidaccounts}"});
-
- if ($form->{vc} ne "customer"){
- $form->{vc} = "vendor";
- }
-
- my $paid = 0;
- my $fxamount;
-
- $diff = 0;
- # add payments
- for $i (1 .. $form->{paidaccounts}) {
- $fxamount = $form->parse_amount($myconfig, $form->{"paid_$i"});
-
- if ($fxamount) {
- $paid += $fxamount;
-
- $paidamount = $fxamount * $form->{exchangerate};
-
- $amount = $form->round_amount($paidamount - $diff, 2);
- $diff = $amount - ($paidamount - $diff);
-
- $form->{datepaid} = $form->{"datepaid_$i"};
-
- $paid{fxamount}{$i} = $fxamount;
- $paid{amount}{$i} = $amount;
- }
- }
-
- $fxinvamount += $fxtax unless $form->{taxincluded};
- $fxinvamount = $form->round_amount($fxinvamount, 2);
- $invamount = $form->round_amount($invamount, 2);
- $paid = $form->round_amount($paid, 2);
-
- $paid = ($fxinvamount == $paid)
- ? $invamount
- : $form->round_amount($paid * $form->{exchangerate}, 2);
-
-
- $query = q|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my $query;
+ my $sth;
+
+ my $null;
+ ( $null, $form->{department_id} ) = split( /--/, $form->{department} );
+ $form->{department_id} *= 1;
+
+ my $ml = 1;
+ my $table = 'ar';
+ my $buysell = 'buy';
+ my $ARAP = 'AR';
+ my $invnumber = "sinumber";
+ my $keepcleared;
+
+ if ( $form->{vc} eq 'vendor' ) {
+ $table = 'ap';
+ $buysell = 'sell';
+ $ARAP = 'AP';
+ $ml = -1;
+ $invnumber = "vinumber";
+ }
+
+ if ( $form->{currency} eq $form->{defaultcurrency} ) {
+ $form->{exchangerate} = 1;
+ }
+ else {
+ $exchangerate =
+ $form->check_exchangerate( $myconfig, $form->{currency},
+ $form->{transdate}, $buysell );
+
+ $form->{exchangerate} =
+ ($exchangerate)
+ ? $exchangerate
+ : $form->parse_amount( $myconfig, $form->{exchangerate} );
+ }
+
+ my @taxaccounts = split / /, $form->{taxaccounts};
+ my $tax = 0;
+ my $fxtax = 0;
+ my $amount;
+ my $diff;
+
+ my %tax = ();
+ my $accno;
+
+ # add taxes
+ foreach $accno (@taxaccounts) {
+ $fxtax += $tax{fxamount}{$accno} =
+ $form->parse_amount( $myconfig, $form->{"tax_$accno"} );
+ $tax += $tax{fxamount}{$accno};
+
+ push @{ $form->{acc_trans}{taxes} },
+ {
+ accno => $accno,
+ amount => $tax{fxamount}{$accno},
+ project_id => undef,
+ fx_transaction => 0
+ };
+
+ $amount = $tax{fxamount}{$accno} * $form->{exchangerate};
+ $tax{amount}{$accno} = $form->round_amount( $amount - $diff, 2 );
+ $diff = $tax{amount}{$accno} - ( $amount - $diff );
+ $amount = $tax{amount}{$accno} - $tax{fxamount}{$accno};
+ $tax += $amount;
+
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ push @{ $form->{acc_trans}{taxes} },
+ {
+ accno => $accno,
+ amount => $amount,
+ project_id => undef,
+ fx_transaction => 1
+ };
+ }
+
+ }
+
+ my %amount = ();
+ my $fxinvamount = 0;
+ for ( 1 .. $form->{rowcount} ) {
+ $fxinvamount += $amount{fxamount}{$_} =
+ $form->parse_amount( $myconfig, $form->{"amount_$_"} );
+ }
+
+ $form->{taxincluded} *= 1;
+
+ my $i;
+ my $project_id;
+ my $cleared = 0;
+
+ $diff = 0;
+
+ # deduct tax from amounts if tax included
+ for $i ( 1 .. $form->{rowcount} ) {
+
+ if ( $amount{fxamount}{$i} ) {
+
+ if ( $form->{taxincluded} ) {
+ $amount =
+ ($fxinvamount)
+ ? $fxtax * $amount{fxamount}{$i} / $fxinvamount
+ : 0;
+ $amount{fxamount}{$i} -= $amount;
+ }
+
+ # multiply by exchangerate
+ $amount = $amount{fxamount}{$i} * $form->{exchangerate};
+ $amount{amount}{$i} = $form->round_amount( $amount - $diff, 2 );
+ $diff = $amount{amount}{$i} - ( $amount - $diff );
+
+ ( $null, $project_id ) = split /--/, $form->{"projectnumber_$i"};
+ $project_id ||= undef;
+ ($accno) = split /--/, $form->{"${ARAP}_amount_$i"};
+
+ if ($keepcleared) {
+ $cleared = ( $form->{"cleared_$i"} ) ? 1 : 0;
+ }
+
+ push @{ $form->{acc_trans}{lineitems} },
+ {
+ accno => $accno,
+ amount => $amount{fxamount}{$i},
+ project_id => $project_id,
+ description => $form->{"description_$i"},
+ cleared => $cleared,
+ fx_transaction => 0
+ };
+
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ $amount = $amount{amount}{$i} - $amount{fxamount}{$i};
+ push @{ $form->{acc_trans}{lineitems} },
+ {
+ accno => $accno,
+ amount => $amount,
+ project_id => $project_id,
+ description => $form->{"description_$i"},
+ cleared => $cleared,
+ fx_transaction => 1
+ };
+ }
+ }
+ }
+
+ my $invnetamount = 0;
+ for ( @{ $form->{acc_trans}{lineitems} } ) { $invnetamount += $_->{amount} }
+ my $invamount = $invnetamount + $tax;
+
+ # adjust paidaccounts if there is no date in the last row
+ $form->{paidaccounts}--
+ unless ( $form->{"datepaid_$form->{paidaccounts}"} );
+
+ if ( $form->{vc} ne "customer" ) {
+ $form->{vc} = "vendor";
+ }
+
+ my $paid = 0;
+ my $fxamount;
+
+ $diff = 0;
+
+ # add payments
+ for $i ( 1 .. $form->{paidaccounts} ) {
+ $fxamount = $form->parse_amount( $myconfig, $form->{"paid_$i"} );
+
+ if ($fxamount) {
+ $paid += $fxamount;
+
+ $paidamount = $fxamount * $form->{exchangerate};
+
+ $amount = $form->round_amount( $paidamount - $diff, 2 );
+ $diff = $amount - ( $paidamount - $diff );
+
+ $form->{datepaid} = $form->{"datepaid_$i"};
+
+ $paid{fxamount}{$i} = $fxamount;
+ $paid{amount}{$i} = $amount;
+ }
+ }
+
+ $fxinvamount += $fxtax unless $form->{taxincluded};
+ $fxinvamount = $form->round_amount( $fxinvamount, 2 );
+ $invamount = $form->round_amount( $invamount, 2 );
+ $paid = $form->round_amount( $paid, 2 );
+
+ $paid =
+ ( $fxinvamount == $paid )
+ ? $invamount
+ : $form->round_amount( $paid * $form->{exchangerate}, 2 );
+
+ $query = q|
SELECT (SELECT value FROM defaults
WHERE setting_key = 'fxgain_accno_id'),
(SELECT value FROM defaults
WHERE setting_key = 'fxloss_accno_id')|;
- my ($fxgain_accno_id, $fxloss_accno_id) = $dbh->selectrow_array($query);
+ my ( $fxgain_accno_id, $fxloss_accno_id ) = $dbh->selectrow_array($query);
- ($null, $form->{employee_id}) = split /--/, $form->{employee};
- unless ($form->{employee_id}) {
- ($form->{employee}, $form->{employee_id}) =
- $form->get_employee($dbh);
- }
+ ( $null, $form->{employee_id} ) = split /--/, $form->{employee};
+ unless ( $form->{employee_id} ) {
+ ( $form->{employee}, $form->{employee_id} ) = $form->get_employee($dbh);
+ }
- # check if id really exists
- if ($form->{id}) {
- my $id = $dbh->quote($form->{id});
- $keepcleared = 1;
- $query = qq|
+ # check if id really exists
+ if ( $form->{id} ) {
+ my $id = $dbh->quote( $form->{id} );
+ $keepcleared = 1;
+ $query = qq|
SELECT id
FROM $table
WHERE id = $id|;
- if ($dbh->selectrow_array($query)) {
- # delete detail records
- $query = qq|
+ if ( $dbh->selectrow_array($query) ) {
+
+ # delete detail records
+ $query = qq|
DELETE FROM acc_trans
WHERE trans_id = $id|;
- $dbh->do($query) || $form->dberror($query);
- }
- } else {
+ $dbh->do($query) || $form->dberror($query);
+ }
+ }
+ else {
- my $uid = localtime;
- $uid .= "$$";
+ my $uid = localtime;
+ $uid .= "$$";
- $query = qq|
+ $query = qq|
INSERT INTO $table (invnumber)
VALUES ('$uid')|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT id FROM $table
WHERE invnumber = '$uid'|;
- ($form->{id}) = $dbh->selectrow_array($query);
- }
-
+ ( $form->{id} ) = $dbh->selectrow_array($query);
+ }
- # record last payment date in ar/ap table
- $form->{datepaid} = $form->{transdate} unless $form->{datepaid};
- my $datepaid = ($paid) ? qq|'$form->{datepaid}'| : 'NOW';
+ # record last payment date in ar/ap table
+ $form->{datepaid} = $form->{transdate} unless $form->{datepaid};
+ my $datepaid = ($paid) ? qq|'$form->{datepaid}'| : 'NOW';
- $form->{invnumber} = $form->update_defaults($myconfig, $invnumber) unless $form->{invnumber};
+ $form->{invnumber} = $form->update_defaults( $myconfig, $invnumber )
+ unless $form->{invnumber};
- $query = qq|
+ $query = qq|
UPDATE $table
SET invnumber = ?,
ordnumber = ?,
@@ -288,38 +309,42 @@ sub post_transaction {
WHERE id = ?
|;
- my @queryargs = ($form->{invnumber}, $form->{ordnumber},
- $form->{transdate}, $form->{"$form->{vc}_id"},
- $form->{taxincluded}, $invamount, $form->{duedate}, $paid,
- $datepaid, $invnetamout, $form->{currency}, $form->{notes},
- $form->{department_id}, $form->{employee_id},
- $form->{ponumber}, $form->{id});
-
- $dbh->prepare($query)->execute(@queryargs) || $form->dberror($query);
-
- @queries = $form->run_custom_queries($table, 'INSERT');
- # update exchangerate
- my $buy = $form->{exchangerate};
- my $sell = 0;
- if ($form->{vc} eq 'vendor') {
- $buy = 0;
- $sell = $form->{exchangerate};
- }
-
- if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) {
- $form->update_exchangerate(
- $dbh, $form->{currency}, $form->{transdate},
- $buy, $sell);
- }
-
- my $ref;
-
- # add individual transactions
- foreach $ref (@{ $form->{acc_trans}{lineitems} }) {
-
- # insert detail records in acc_trans
- if ($ref->{amount}) {
- $query = qq|
+ my @queryargs = (
+ $form->{invnumber}, $form->{ordnumber},
+ $form->{transdate}, $form->{"$form->{vc}_id"},
+ $form->{taxincluded}, $invamount,
+ $form->{duedate}, $paid,
+ $datepaid, $invnetamout,
+ $form->{currency}, $form->{notes},
+ $form->{department_id}, $form->{employee_id},
+ $form->{ponumber}, $form->{id}
+ );
+
+ $dbh->prepare($query)->execute(@queryargs) || $form->dberror($query);
+
+ @queries = $form->run_custom_queries( $table, 'INSERT' );
+
+ # update exchangerate
+ my $buy = $form->{exchangerate};
+ my $sell = 0;
+ if ( $form->{vc} eq 'vendor' ) {
+ $buy = 0;
+ $sell = $form->{exchangerate};
+ }
+
+ if ( ( $form->{currency} ne $form->{defaultcurrency} ) && !$exchangerate ) {
+ $form->update_exchangerate( $dbh, $form->{currency}, $form->{transdate},
+ $buy, $sell );
+ }
+
+ my $ref;
+
+ # add individual transactions
+ foreach $ref ( @{ $form->{acc_trans}{lineitems} } ) {
+
+ # insert detail records in acc_trans
+ if ( $ref->{amount} ) {
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate, project_id, memo,
@@ -328,19 +353,21 @@ sub post_transaction {
WHERE accno = ?),
?, ?, ?, ?, ?, ?)|;
- @queryargs = ($form->{id}, $ref->{accno},
- $ref->{amount} * $ml, $form->{transdate},
- $ref->{project_id}, $ref->{description},
- $ref->{fx_transaction}, $ref->{cleared});
- $dbh->prepare($query)->execute(@queryargs)
- || $form->dberror($query);
- }
- }
-
- # save taxes
- foreach $ref (@{ $form->{acc_trans}{taxes} }) {
- if ($ref->{amount}) {
- $query = qq|
+ @queryargs = (
+ $form->{id}, $ref->{accno},
+ $ref->{amount} * $ml, $form->{transdate},
+ $ref->{project_id}, $ref->{description},
+ $ref->{fx_transaction}, $ref->{cleared}
+ );
+ $dbh->prepare($query)->execute(@queryargs)
+ || $form->dberror($query);
+ }
+ }
+
+ # save taxes
+ foreach $ref ( @{ $form->{acc_trans}{taxes} } ) {
+ if ( $ref->{amount} ) {
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate, fx_transaction)
@@ -348,78 +375,78 @@ sub post_transaction {
WHERE accno = ?),
?, ?, ?)|;
- @queryargs = ($form->{id}, $ref->{accno},
- $ref->{amount} * $ml, $form->{transdate},
- $ref->{fx_transaction});
- $dbh->prepare($query)->execute(@queryargs)
- || $form->dberror($query);
- }
- }
-
+ @queryargs = (
+ $form->{id}, $ref->{accno}, $ref->{amount} * $ml,
+ $form->{transdate}, $ref->{fx_transaction}
+ );
+ $dbh->prepare($query)->execute(@queryargs)
+ || $form->dberror($query);
+ }
+ }
- my $arap;
+ my $arap;
- # record ar/ap
- if (($arap = $invamount)) {
- ($accno) = split /--/, $form->{$ARAP};
+ # record ar/ap
+ if ( ( $arap = $invamount ) ) {
+ ($accno) = split /--/, $form->{$ARAP};
- $query = qq|
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount, transdate)
VALUES (?, (SELECT id FROM chart
WHERE accno = '?'),
?, ?)|;
- @queryargs = ($form->{id}, $accno, $invamount * -1 * $ml,
- $form->{transdate});
+ @queryargs =
+ ( $form->{id}, $accno, $invamount * -1 * $ml, $form->{transdate} );
- $dbh->prepare($query)->execute(@queryargs)
- || $form->dberror($query);
- }
+ $dbh->prepare($query)->execute(@queryargs)
+ || $form->dberror($query);
+ }
- # if there is no amount force ar/ap
- if ($fxinvamount == 0) {
- $arap = 1;
- }
+ # if there is no amount force ar/ap
+ if ( $fxinvamount == 0 ) {
+ $arap = 1;
+ }
+ my $exchangerate;
- my $exchangerate;
+ # add paid transactions
+ for $i ( 1 .. $form->{paidaccounts} ) {
- # add paid transactions
- for $i (1 .. $form->{paidaccounts}) {
+ if ( $paid{fxamount}{$i} ) {
- if ($paid{fxamount}{$i}) {
+ ($accno) = split( /--/, $form->{"${ARAP}_paid_$i"} );
+ $form->{"datepaid_$i"} = $form->{transdate}
+ unless ( $form->{"datepaid_$i"} );
- ($accno) = split(/--/, $form->{"${ARAP}_paid_$i"});
- $form->{"datepaid_$i"} = $form->{transdate} unless ($form->{"datepaid_$i"});
+ $exchangerate = 0;
- $exchangerate = 0;
+ if ( $form->{currency} eq $form->{defaultcurrency} ) {
+ $form->{"exchangerate_$i"} = 1;
+ }
+ else {
+ $exchangerate =
+ $form->check_exchangerate( $myconfig, $form->{currency},
+ $form->{"datepaid_$i"}, $buysell );
- if ($form->{currency} eq $form->{defaultcurrency}) {
- $form->{"exchangerate_$i"} = 1;
- } else {
- $exchangerate = $form->check_exchangerate(
- $myconfig, $form->{currency},
- $form->{"datepaid_$i"}, $buysell);
+ $form->{"exchangerate_$i"} =
+ ($exchangerate)
+ ? $exchangerate
+ : $form->parse_amount( $myconfig,
+ $form->{"exchangerate_$i"} );
+ }
- $form->{"exchangerate_$i"} = ($exchangerate)
- ? $exchangerate
- : $form->parse_amount(
- $myconfig,
- $form->{"exchangerate_$i"});
- }
+ # if there is no amount
+ if ( $fxinvamount == 0 ) {
+ $form->{exchangerate} = $form->{"exchangerate_$i"};
+ }
- # if there is no amount
- if ($fxinvamount == 0) {
- $form->{exchangerate} =
- $form->{"exchangerate_$i"};
- }
+ # ar/ap amount
+ if ($arap) {
+ ($accno) = split /--/, $form->{$ARAP};
- # ar/ap amount
- if ($arap) {
- ($accno) = split /--/, $form->{$ARAP};
-
- # add ar/ap
- $query = qq|
+ # add ar/ap
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id,
amount,transdate)
@@ -427,25 +454,26 @@ sub post_transaction {
WHERE accno = ?),
?, ?)|;
- @queryargs = ($form->{id},
- $paid{amount}{$i} * $ml,
- $form->{"datepaid_$i"});
- $dbh->prepare($query)->execute(@queryargs)
- || $form->dberror($query);
- }
-
- $arap = $paid{amount}{$i};
+ @queryargs = (
+ $form->{id},
+ $paid{amount}{$i} * $ml,
+ $form->{"datepaid_$i"}
+ );
+ $dbh->prepare($query)->execute(@queryargs)
+ || $form->dberror($query);
+ }
+ $arap = $paid{amount}{$i};
- # add payment
- if ($paid{fxamount}{$i}) {
+ # add payment
+ if ( $paid{fxamount}{$i} ) {
- ($accno) = split /--/, $form->{"${ARAP}_paid_$i"};
+ ($accno) = split /--/, $form->{"${ARAP}_paid_$i"};
- my $cleared = ($form->{"cleared_$i"}) ? 1 : 0;
+ my $cleared = ( $form->{"cleared_$i"} ) ? 1 : 0;
- $amount = $paid{fxamount}{$i};
- $query = qq|
+ $amount = $paid{fxamount}{$i};
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate, source, memo,
@@ -454,32 +482,34 @@ sub post_transaction {
WHERE accno = ?),
? * -1 * $ml, ?, ?, ?, ?)|;
- @queryargs = ($form->{id}, $accno,
- $amount * -1 * $ml,
- $form->{"datepaid_$i"},
- $form->{"source_$i"},
- $form->{"memo_$i"},
- $cleared);
- $dbh->prepare($query)->execute(@queryargs)
- || $form->dberror($query);
-
- if ($form->{currency}
- ne $form->{defaultcurrency}) {
-
- # exchangerate gain/loss
- $amount = ($form->round_amount(
- $paid{fxamount}{$i}
- * $form->{exchangerate},2) -
- $form->round_amount(
- $paid{fxamount}{$i}
- * $form->{"exchangerate_$i"},
- 2)) * -1;
-
- if ($amount) {
-
- my $accno_id = (($amount * $ml) > 0) ? $fxgain_accno_id : $fxloss_accno_id;
-
- $query = qq|
+ @queryargs = (
+ $form->{id}, $accno,
+ $amount * -1 * $ml, $form->{"datepaid_$i"},
+ $form->{"source_$i"}, $form->{"memo_$i"},
+ $cleared
+ );
+ $dbh->prepare($query)->execute(@queryargs)
+ || $form->dberror($query);
+
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+
+ # exchangerate gain/loss
+ $amount = (
+ $form->round_amount(
+ $paid{fxamount}{$i} * $form->{exchangerate}, 2 ) -
+ $form->round_amount(
+ $paid{fxamount}{$i} * $form->{"exchangerate_$i"}, 2
+ )
+ ) * -1;
+
+ if ($amount) {
+
+ my $accno_id =
+ ( ( $amount * $ml ) > 0 )
+ ? $fxgain_accno_id
+ : $fxloss_accno_id;
+
+ $query = qq|
INSERT INTO acc_trans
(trans_id,
chart_id,
@@ -491,21 +521,20 @@ sub post_transaction {
?,
?, '1', ?)|;
- @queryargs = ($form->{id},
- $accno_id,
- $amount * $ml,
- $form->{"datepaid_$i"},
- $cleared);
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs)
- ||
- $form->dberror($query);
- }
-
- # exchangerate difference
- $amount = $paid{amount}{$i} - $paid{fxamount}{$i} + $amount;
-
- $query = qq|
+ @queryargs = (
+ $form->{id}, $accno_id,
+ $amount * $ml,
+ $form->{"datepaid_$i"}, $cleared
+ );
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs)
+ || $form->dberror($query);
+ }
+
+ # exchangerate difference
+ $amount = $paid{amount}{$i} - $paid{fxamount}{$i} + $amount;
+
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id,
amount,
@@ -518,171 +547,175 @@ sub post_transaction {
= ?),
?, ?, '1', ?, ?)|;
- @queryargs = ($form->{id}, $accno,
- $amount * -1 * $ml,
- $form->{"datepaid_$i"},
- $cleared, $form->{"source_$i"});
- $sth = $dbh->prepare($query) ;
- $sth->execute(@queryargs)
- || $form->dberror($query);
+ @queryargs = (
+ $form->{id}, $accno,
+ $amount * -1 * $ml,
+ $form->{"datepaid_$i"},
+ $cleared, $form->{"source_$i"}
+ );
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs)
+ || $form->dberror($query);
- }
+ }
- # update exchangerate record
- $buy = $form->{"exchangerate_$i"};
- $sell = 0;
+ # update exchangerate record
+ $buy = $form->{"exchangerate_$i"};
+ $sell = 0;
- if ($form->{vc} eq 'vendor') {
- $buy = 0;
- $sell = $form->{"exchangerate_$i"};
- }
+ if ( $form->{vc} eq 'vendor' ) {
+ $buy = 0;
+ $sell = $form->{"exchangerate_$i"};
+ }
- if (($form->{currency} ne
- $form->{defaultcurrency}) && !$exchangerate) {
+ if ( ( $form->{currency} ne $form->{defaultcurrency} )
+ && !$exchangerate )
+ {
- $form->update_exchangerate(
- $dbh, $form->{currency},
- $form->{"datepaid_$i"}, $buy,
- $sell);
- }
- }
- }
- }
+ $form->update_exchangerate( $dbh, $form->{currency},
+ $form->{"datepaid_$i"},
+ $buy, $sell );
+ }
+ }
+ }
+ }
- # save printed and queued
- $form->save_status($dbh);
+ # save printed and queued
+ $form->save_status($dbh);
- my %audittrail = ( tablename => $table,
- reference => $form->{invnumber},
- formname => 'transaction',
- action => 'posted',
- id => $form->{id} );
+ my %audittrail = (
+ tablename => $table,
+ reference => $form->{invnumber},
+ formname => 'transaction',
+ action => 'posted',
+ id => $form->{id}
+ );
- $form->audittrail($dbh, "", \%audittrail);
+ $form->audittrail( $dbh, "", \%audittrail );
- $form->save_recurring($dbh, $myconfig);
+ $form->save_recurring( $dbh, $myconfig );
- my $rc = $dbh->commit;
+ my $rc = $dbh->commit;
- $rc;
+ $rc;
}
-
sub delete_transaction {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database, turn AutoCommit off
- my $dbh = $form->{dbh};
+ # connect to database, turn AutoCommit off
+ my $dbh = $form->{dbh};
- my $table = ($form->{vc} eq 'customer') ? 'ar' : 'ap';
+ my $table = ( $form->{vc} eq 'customer' ) ? 'ar' : 'ap';
- my %audittrail = ( tablename => $table,
- reference => $form->{invnumber},
- formname => 'transaction',
- action => 'deleted',
- id => $form->{id} );
+ my %audittrail = (
+ tablename => $table,
+ reference => $form->{invnumber},
+ formname => 'transaction',
+ action => 'deleted',
+ id => $form->{id}
+ );
- $form->audittrail($dbh, "", \%audittrail);
+ $form->audittrail( $dbh, "", \%audittrail );
- my $query = qq|DELETE FROM $table WHERE id = $form->{id}|;
- $dbh->do($query) || $form->dberror($query);
+ my $query = qq|DELETE FROM $table WHERE id = $form->{id}|;
+ $dbh->do($query) || $form->dberror($query);
- $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
- $dbh->prepare($query)->execute($form->{id}) || $form->dberror($query);
+ $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
+ $dbh->prepare($query)->execute( $form->{id} ) || $form->dberror($query);
- # get spool files
- $query = qq|SELECT spoolfile
+ # get spool files
+ $query = qq|SELECT spoolfile
FROM status
WHERE trans_id = ?
AND spoolfile IS NOT NULL|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- my $spoolfile;
- my @spoolfiles = ();
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- while (($spoolfile) = $sth->fetchrow_array) {
- push @spoolfiles, $spoolfile;
- }
-
- $sth->finish;
+ my $spoolfile;
+ my @spoolfiles = ();
- $query = qq|DELETE FROM status WHERE trans_id = ?|;
- $dbh->prepare($query)->execute($form->{id}) || $form->dberror($query);
+ while ( ($spoolfile) = $sth->fetchrow_array ) {
+ push @spoolfiles, $spoolfile;
+ }
- # commit
- my $rc = $dbh->commit;
+ $sth->finish;
- if ($rc) {
- foreach $spoolfile (@spoolfiles) {
- unlink "${LedgerSMB::Sysconfig::spool}/$spoolfile" if $spoolfile;
- }
- }
+ $query = qq|DELETE FROM status WHERE trans_id = ?|;
+ $dbh->prepare($query)->execute( $form->{id} ) || $form->dberror($query);
- $rc;
-}
+ # commit
+ my $rc = $dbh->commit;
+ if ($rc) {
+ foreach $spoolfile (@spoolfiles) {
+ unlink "${LedgerSMB::Sysconfig::spool}/$spoolfile" if $spoolfile;
+ }
+ }
+ $rc;
+}
sub transactions {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
- my $null;
- my $var;
- my $paid = "a.paid";
- my $ml = 1;
- my $ARAP = 'AR';
- my $table = 'ar';
- my $buysell = 'buy';
- my $acc_trans_join;
- my $acc_trans_flds;
-
- if ($form->{vc} eq 'vendor') {
- $ml = -1;
- $ARAP = 'AP';
- $table = 'ap';
- $buysell = 'sell';
- }
-
- ($form->{transdatefrom}, $form->{transdateto}) = $form->from_to($form->{year}, $form->{month}, $form->{interval}) if $form->{year} && $form->{month};
-
- my @paidargs = ();
- if ($form->{outstanding}) {
- $paid = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+ my $null;
+ my $var;
+ my $paid = "a.paid";
+ my $ml = 1;
+ my $ARAP = 'AR';
+ my $table = 'ar';
+ my $buysell = 'buy';
+ my $acc_trans_join;
+ my $acc_trans_flds;
+
+ if ( $form->{vc} eq 'vendor' ) {
+ $ml = -1;
+ $ARAP = 'AP';
+ $table = 'ap';
+ $buysell = 'sell';
+ }
+
+ ( $form->{transdatefrom}, $form->{transdateto} ) =
+ $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
+ if $form->{year} && $form->{month};
+
+ my @paidargs = ();
+ if ( $form->{outstanding} ) {
+ $paid = qq|
SELECT SUM(ac.amount) * -1 * $ml
FROM acc_trans ac
JOIN chart c ON (c.id = ac.chart_id)
WHERE ac.trans_id = a.id
AND (c.link LIKE '%${ARAP}_paid%'
OR c.link = '')|;
- if ($form->{transdateto}){
- $paid .= qq|
+ if ( $form->{transdateto} ) {
+ $paid .= qq|
AND ac.transdate <= ?|;
- push @paidargs, $form->{transdateto};
- }
- $form->{summary} = 1;
- }
-
+ push @paidargs, $form->{transdateto};
+ }
+ $form->{summary} = 1;
+ }
- if (!$form->{summary}) {
- $acc_trans_flds = qq|
+ if ( !$form->{summary} ) {
+ $acc_trans_flds = qq|
, c.accno, ac.source,
pr.projectnumber, ac.memo AS description,
ac.amount AS linetotal,
i.description AS linedescription|;
- $acc_trans_join = qq|
+ $acc_trans_join = qq|
JOIN acc_trans ac ON (a.id = ac.trans_id)
JOIN chart c ON (c.id = ac.chart_id)
LEFT JOIN project pr ON (pr.id = ac.project_id)
LEFT JOIN invoice i ON (i.id = ac.invoice_id)|;
- }
+ }
- my $query = qq|
+ my $query = qq|
SELECT a.id, a.invnumber, a.ordnumber, a.transdate,
a.duedate, a.netamount, a.amount, ($paid) AS paid,
a.invoice, a.datepaid, a.terms, a.notes,
@@ -701,129 +734,130 @@ sub transactions {
LEFT JOIN department d ON (a.department_id = d.id)
$acc_trans_join|;
- my %ordinal = ( id => 1,
- invnumber => 2,
- ordnumber => 3,
- transdate => 4,
- duedate => 5,
- datepaid => 10,
- shipvia => 13,
- shippingpoint => 14,
- employee => 15,
- name => 16,
- manager => 19,
- curr => 20,
- department => 22,
- ponumber => 23,
- accno => 24,
- source => 25,
- project => 26,
- description => 27);
-
-
- my @a = (transdate, invnumber, name);
- push @a, "employee" if $form->{l_employee};
- push @a, "manager" if $form->{l_manager};
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
- my $where = "1 = 1";
- if ($form->{"$form->{vc}_id"}) {
- $where .= qq| AND a.$form->{vc}_id = $form->{"$form->{vc}_id"}|;
- } else {
- if ($form->{$form->{vc}}) {
- $var = $dbh->quote(
- $form->like(lc $form->{$form->{vc}}));
- $where .= " AND lower(vc.name) LIKE $var";
- }
- }
-
- for (qw(department employee)) {
- if ($form->{$_}) {
- ($null, $var) = split /--/, $form->{$_};
- $var = $dbh->quote($var);
- $where .= " AND a.${_}_id = $var";
- }
- }
-
- for (qw(invnumber ordnumber)) {
- if ($form->{$_}) {
- $var = $dbh->quote($form->like(lc $form->{$_}));
- $where .= " AND lower(a.$_) LIKE $var";
- $form->{open} = $form->{closed} = 0;
- }
- }
- if ($form->{partsid}){
- my $partsid = $dbh->quote($form->{partsid});
- $where .= " AND a.id IN (select trans_id FROM invoice
+ my %ordinal = (
+ id => 1,
+ invnumber => 2,
+ ordnumber => 3,
+ transdate => 4,
+ duedate => 5,
+ datepaid => 10,
+ shipvia => 13,
+ shippingpoint => 14,
+ employee => 15,
+ name => 16,
+ manager => 19,
+ curr => 20,
+ department => 22,
+ ponumber => 23,
+ accno => 24,
+ source => 25,
+ project => 26,
+ description => 27
+ );
+
+ my @a = ( transdate, invnumber, name );
+ push @a, "employee" if $form->{l_employee};
+ push @a, "manager" if $form->{l_manager};
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ my $where = "1 = 1";
+ if ( $form->{"$form->{vc}_id"} ) {
+ $where .= qq| AND a.$form->{vc}_id = $form->{"$form->{vc}_id"}|;
+ }
+ else {
+ if ( $form->{ $form->{vc} } ) {
+ $var = $dbh->quote( $form->like( lc $form->{ $form->{vc} } ) );
+ $where .= " AND lower(vc.name) LIKE $var";
+ }
+ }
+
+ for (qw(department employee)) {
+ if ( $form->{$_} ) {
+ ( $null, $var ) = split /--/, $form->{$_};
+ $var = $dbh->quote($var);
+ $where .= " AND a.${_}_id = $var";
+ }
+ }
+
+ for (qw(invnumber ordnumber)) {
+ if ( $form->{$_} ) {
+ $var = $dbh->quote( $form->like( lc $form->{$_} ) );
+ $where .= " AND lower(a.$_) LIKE $var";
+ $form->{open} = $form->{closed} = 0;
+ }
+ }
+ if ( $form->{partsid} ) {
+ my $partsid = $dbh->quote( $form->{partsid} );
+ $where .= " AND a.id IN (select trans_id FROM invoice
WHERE parts_id = $partsid)";
- }
-
- for (qw(ponumber shipvia notes)) {
- if ($form->{$_}) {
- $var = $dbh->quote($form->like(lc $form->{$_}));
- $where .= " AND lower(a.$_) LIKE $var";
- }
- }
-
- if ($form->{description}) {
- if ($acc_trans_flds) {
- $var = $dbh->quote(
- $form->like(lc $form->{description})
- );
- $where .= " AND lower(ac.memo) LIKE $var
+ }
+
+ for (qw(ponumber shipvia notes)) {
+ if ( $form->{$_} ) {
+ $var = $dbh->quote( $form->like( lc $form->{$_} ) );
+ $where .= " AND lower(a.$_) LIKE $var";
+ }
+ }
+
+ if ( $form->{description} ) {
+ if ($acc_trans_flds) {
+ $var = $dbh->quote( $form->like( lc $form->{description} ) );
+ $where .= " AND lower(ac.memo) LIKE $var
OR lower(i.description) LIKE $var";
- } else {
- $where .= " AND a.id = 0";
- }
- }
-
- if ($form->{source}) {
- if ($acc_trans_flds) {
- $var = $dbh->quote($form->like(lc $form->{source}));
- $where .= " AND lower(ac.source) LIKE $var";
- } else {
- $where .= " AND a.id = 0";
- }
- }
-
- my $transdatefrom = $dbh->quote($form->{transdatefrom});
- $where .= " AND a.transdate >= $transdatefrom"
- if $form->{transdatefrom};
-
- my $transdateto = $dbh->quote($form->{transdateto});
- $where .= " AND a.transdate <= $transdateto" if $form->{transdateto};
-
- if ($form->{open} || $form->{closed}) {
- unless ($form->{open} && $form->{closed}) {
- $where .= " AND a.amount != a.paid" if ($form->{open});
- $where .= " AND a.amount = a.paid" if ($form->{closed});
- }
- }
-
- if ($form->{till} ne "") {
- $where .= " AND a.invoice = '1'
+ }
+ else {
+ $where .= " AND a.id = 0";
+ }
+ }
+
+ if ( $form->{source} ) {
+ if ($acc_trans_flds) {
+ $var = $dbh->quote( $form->like( lc $form->{source} ) );
+ $where .= " AND lower(ac.source) LIKE $var";
+ }
+ else {
+ $where .= " AND a.id = 0";
+ }
+ }
+
+ my $transdatefrom = $dbh->quote( $form->{transdatefrom} );
+ $where .= " AND a.transdate >= $transdatefrom"
+ if $form->{transdatefrom};
+
+ my $transdateto = $dbh->quote( $form->{transdateto} );
+ $where .= " AND a.transdate <= $transdateto" if $form->{transdateto};
+
+ if ( $form->{open} || $form->{closed} ) {
+ unless ( $form->{open} && $form->{closed} ) {
+ $where .= " AND a.amount != a.paid" if ( $form->{open} );
+ $where .= " AND a.amount = a.paid" if ( $form->{closed} );
+ }
+ }
+
+ if ( $form->{till} ne "" ) {
+ $where .= " AND a.invoice = '1'
AND a.till = $form->{till}";
- if ($myconfig->{role} eq 'user') {
- my $login = $dbh->quote($form->{login});
- $where .= " AND e.login = $login";
- }
- }
+ if ( $myconfig->{role} eq 'user' ) {
+ my $login = $dbh->quote( $form->{login} );
+ $where .= " AND e.login = $login";
+ }
+ }
- if ($form->{$ARAP}) {
- my ($accno) = split /--/, $form->{$ARAP};
- $accno = $dbh->quote($accno);
- $where .= qq|
+ if ( $form->{$ARAP} ) {
+ my ($accno) = split /--/, $form->{$ARAP};
+ $accno = $dbh->quote($accno);
+ $where .= qq|
AND a.id IN (SELECT ac.trans_id
FROM acc_trans ac
JOIN chart c ON (c.id = ac.chart_id)
WHERE a.id = ac.trans_id
AND c.accno = $accno)|;
- }
+ }
- if ($form->{description}) {
- $var = $dbh->quote($form->like(lc $form->{description}));
- $where .= qq|
+ if ( $form->{description} ) {
+ $var = $dbh->quote( $form->like( lc $form->{description} ) );
+ $where .= qq|
AND (a.id IN (SELECT DISTINCT trans_id
FROM acc_trans
WHERE lower(memo) LIKE '$var')
@@ -832,79 +866,83 @@ sub transactions {
FROM invoice
WHERE lower(description)
LIKE '$var'))|;
- }
+ }
- $query .= "WHERE $where
+ $query .= "WHERE $where
ORDER BY $sortorder";
- my $sth = $dbh->prepare($query);
- $sth->execute(@paidargs) || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute(@paidargs) || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{exchangerate} = 1 unless $ref->{exchangerate};
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{exchangerate} = 1 unless $ref->{exchangerate};
- if ($ref->{linetotal} <= 0) {
- $ref->{debit} = $ref->{linetotal} * -1;
- $ref->{credit} = 0;
- } else {
- $ref->{debit} = 0;
- $ref->{credit} = $ref->{linetotal};
- }
+ if ( $ref->{linetotal} <= 0 ) {
+ $ref->{debit} = $ref->{linetotal} * -1;
+ $ref->{credit} = 0;
+ }
+ else {
+ $ref->{debit} = 0;
+ $ref->{credit} = $ref->{linetotal};
+ }
- if ($ref->{invoice}) {
- $ref->{description} ||= $ref->{linedescription};
- }
+ if ( $ref->{invoice} ) {
+ $ref->{description} ||= $ref->{linedescription};
+ }
- if ($form->{outstanding}) {
- next if $form->round_amount($ref->{amount}, 2)
- == $form->round_amount($ref->{paid}, 2);
- }
+ if ( $form->{outstanding} ) {
+ next
+ if $form->round_amount( $ref->{amount}, 2 ) ==
+ $form->round_amount( $ref->{paid}, 2 );
+ }
- push @{ $form->{transactions} }, $ref;
- }
+ push @{ $form->{transactions} }, $ref;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
# this is used in IS, IR to retrieve the name
sub get_name {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # sanitize $form->{vc}
- if ($form->{vc} ne 'customer'){
- $form->{vc} = 'vendor';
- } else {
- $form->{vc} = 'customer';
- }
- # connect to database
- my $dbh = $form->{dbh};
+ # sanitize $form->{vc}
+ if ( $form->{vc} ne 'customer' ) {
+ $form->{vc} = 'vendor';
+ }
+ else {
+ $form->{vc} = 'customer';
+ }
- my $dateformat = $myconfig->{dateformat};
+ # connect to database
+ my $dbh = $form->{dbh};
- if ($myconfig->{dateformat} !~ /^y/) {
- my @a = split /\W/, $form->{transdate};
- $dateformat .= "yy" if (length $a[2] > 2);
- }
+ my $dateformat = $myconfig->{dateformat};
- if ($form->{transdate} !~ /\W/) {
- $dateformat = 'yyyymmdd';
- }
+ if ( $myconfig->{dateformat} !~ /^y/ ) {
+ my @a = split /\W/, $form->{transdate};
+ $dateformat .= "yy" if ( length $a[2] > 2 );
+ }
- my $duedate;
+ if ( $form->{transdate} !~ /\W/ ) {
+ $dateformat = 'yyyymmdd';
+ }
- $dateformat = $dbh->quote($dateformat);
- my $tdate = $dbh->quote($form->{transdate});
- $duedate = ($form->{transdate})
- ? "to_date($tdate, $dateformat)
- + c.terms"
- : "current_date + c.terms";
+ my $duedate;
- $form->{"$form->{vc}_id"} *= 1;
- # get customer/vendor
- my $query = qq|
+ $dateformat = $dbh->quote($dateformat);
+ my $tdate = $dbh->quote( $form->{transdate} );
+ $duedate = ( $form->{transdate} )
+ ? "to_date($tdate, $dateformat)
+ + c.terms"
+ : "current_date + c.terms";
+
+ $form->{"$form->{vc}_id"} *= 1;
+
+ # get customer/vendor
+ my $query = qq|
SELECT c.name AS $form->{vc}, c.discount, c.creditlimit,
c.terms, c.email, c.cc, c.bcc, c.taxincluded,
c.address1, c.address2, c.city, c.state,
@@ -919,65 +957,67 @@ sub get_name {
LEFT JOIN employees e ON (e.id = c.employee_id)
WHERE c.id = ?|;
- @queryargs = ($form->{"$form->{vc}_id"});
- my $sth = $dbh->prepare($query);
+ @queryargs = ( $form->{"$form->{vc}_id"} );
+ my $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $form->dberror($query);
+ $sth->execute(@queryargs) || $form->dberror($query);
- $ref = $sth->fetchrow_hashref(NAME_lc);
+ $ref = $sth->fetchrow_hashref(NAME_lc);
- if ($form->{id}) {
- for (qw(currency employee employee_id intnotes)) {
- delete $ref->{$_};
- }
- }
+ if ( $form->{id} ) {
+ for (qw(currency employee employee_id intnotes)) {
+ delete $ref->{$_};
+ }
+ }
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
- my $buysell = ($form->{vc} eq 'customer') ? "buy" : "sell";
+ my $buysell = ( $form->{vc} eq 'customer' ) ? "buy" : "sell";
- # if no currency use defaultcurrency
- $form->{currency} =
- ($form->{currency})
- ? $form->{currency}
- : $form->{defaultcurrency};
- $form->{exchangerate} = 0
- if $form->{currency} eq $form->{defaultcurrency};
+ # if no currency use defaultcurrency
+ $form->{currency} =
+ ( $form->{currency} )
+ ? $form->{currency}
+ : $form->{defaultcurrency};
+ $form->{exchangerate} = 0
+ if $form->{currency} eq $form->{defaultcurrency};
- if ($form->{transdate} && ($form->{currency}
- ne $form->{defaultcurrency})) {
- $form->{exchangerate} = $form->get_exchangerate(
- $dbh, $form->{currency}, $form->{transdate}, $buysell);
- }
+ if ( $form->{transdate}
+ && ( $form->{currency} ne $form->{defaultcurrency} ) )
+ {
+ $form->{exchangerate} =
+ $form->get_exchangerate( $dbh, $form->{currency}, $form->{transdate},
+ $buysell );
+ }
- $form->{forex} = $form->{exchangerate};
+ $form->{forex} = $form->{exchangerate};
- # if no employee, default to login
- ($form->{employee}, $form->{employee_id}) = $form->get_employee($dbh)
- unless $form->{employee_id};
+ # if no employee, default to login
+ ( $form->{employee}, $form->{employee_id} ) = $form->get_employee($dbh)
+ unless $form->{employee_id};
- my $arap = ($form->{vc} eq 'customer') ? 'ar' : 'ap';
- my $ARAP = uc $arap;
+ my $arap = ( $form->{vc} eq 'customer' ) ? 'ar' : 'ap';
+ my $ARAP = uc $arap;
- $form->{creditremaining} = $form->{creditlimit};
- $query = qq|
+ $form->{creditremaining} = $form->{creditlimit};
+ $query = qq|
SELECT SUM(amount - paid)
FROM $arap
WHERE $form->{vc}_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{"$form->{vc}_id"})
- || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{"$form->{vc}_id"} )
+ || $form->dberror($query);
- ($form->{creditremaining}) -= $sth->fetchrow_array;
+ ( $form->{creditremaining} ) -= $sth->fetchrow_array;
- $sth->finish;
- if ($form->{vc} ne "customer"){
- $form->{vc} = 'vendor';
- }
+ $sth->finish;
+ if ( $form->{vc} ne "customer" ) {
+ $form->{vc} = 'vendor';
+ }
- $query = qq|
+ $query = qq|
SELECT o.amount, (SELECT e.$buysell FROM exchangerate e
WHERE e.curr = o.curr
AND e.transdate = o.transdate)
@@ -985,66 +1025,66 @@ sub get_name {
WHERE o.$form->{vc}_id = ?
AND o.quotation = '0' AND o.closed = '0'|;
- $sth = $dbh->prepare($query);
- $sth->execute ($form->{"$form->{vc}_id"}) || $form->dberror($query);
-
- while (my ($amount, $exch) = $sth->fetchrow_array) {
- $exch = 1 unless $exch;
- $form->{creditremaining} -= $amount * $exch;
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{"$form->{vc}_id"} ) || $form->dberror($query);
- $sth->finish;
+ while ( my ( $amount, $exch ) = $sth->fetchrow_array ) {
+ $exch = 1 unless $exch;
+ $form->{creditremaining} -= $amount * $exch;
+ }
+ $sth->finish;
- # get shipto if we did not converted an order or invoice
- if (!$form->{shipto}) {
+ # get shipto if we did not converted an order or invoice
+ if ( !$form->{shipto} ) {
- for (
- qw(shiptoname shiptoaddress1 shiptoaddress2
- shiptocity shiptostate shiptozipcode
- shiptocountry shiptocontact shiptophone
- shiptofax shiptoemail)
- ) {
- delete $form->{$_}
- }
+ for (
+ qw(shiptoname shiptoaddress1 shiptoaddress2
+ shiptocity shiptostate shiptozipcode
+ shiptocountry shiptocontact shiptophone
+ shiptofax shiptoemail)
+ )
+ {
+ delete $form->{$_};
+ }
- ## needs fixing (SELECT *)
- $query = qq|
+ ## needs fixing (SELECT *)
+ $query = qq|
SELECT *
FROM shipto
WHERE trans_id = $form->{"$form->{vc}_id"}|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
- }
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
+ }
- # get taxes
- $query = qq|
+ # get taxes
+ $query = qq|
SELECT c.accno
FROM chart c
JOIN $form->{vc}tax ct ON (ct.chart_id = c.id)
WHERE ct.$form->{vc}_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute( $form->{"$form->{vc}_id"}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{"$form->{vc}_id"} ) || $form->dberror($query);
- my %tax;
+ my %tax;
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $tax{$ref->{accno}} = 1;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $tax{ $ref->{accno} } = 1;
+ }
- $sth->finish;
- $transdate = $dbh->quote($form->{transdate});
- my $where = qq|AND (t.validto >= $transdate OR t.validto IS NULL)|
- if $form->{transdate};
+ $sth->finish;
+ $transdate = $dbh->quote( $form->{transdate} );
+ my $where = qq|AND (t.validto >= $transdate OR t.validto IS NULL)|
+ if $form->{transdate};
- # get tax rates and description
- $query = qq|
+ # get tax rates and description
+ $query = qq|
SELECT c.accno, c.description, t.rate, t.taxnumber
FROM chart c
JOIN tax t ON (c.id = t.chart_id)
@@ -1052,33 +1092,32 @@ sub get_name {
$where
ORDER BY accno, validto|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- $form->{taxaccounts} = "";
- my %a = ();
+ $form->{taxaccounts} = "";
+ my %a = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
- if ($tax{$ref->{accno}}) {
- if (not exists $a{$ref->{accno}}) {
- for (qw(rate description taxnumber)) {
- $form->{"$ref->{accno}_$_"} =
- $ref->{$_};
- }
- $form->{taxaccounts} .= "$ref->{accno} ";
- $a{$ref->{accno}} = 1;
- }
- }
- }
+ if ( $tax{ $ref->{accno} } ) {
+ if ( not exists $a{ $ref->{accno} } ) {
+ for (qw(rate description taxnumber)) {
+ $form->{"$ref->{accno}_$_"} = $ref->{$_};
+ }
+ $form->{taxaccounts} .= "$ref->{accno} ";
+ $a{ $ref->{accno} } = 1;
+ }
+ }
+ }
- $sth->finish;
- chop $form->{taxaccounts};
+ $sth->finish;
+ chop $form->{taxaccounts};
- # setup last accounts used for this customer/vendor
- if (!$form->{id} && $form->{type} !~ /_(order|quotation)/) {
+ # setup last accounts used for this customer/vendor
+ if ( !$form->{id} && $form->{type} !~ /_(order|quotation)/ ) {
- $query = qq|
+ $query = qq|
SELECT c.accno, c.description, c.link, c.category,
ac.project_id, p.projectnumber,
a.department_id, d.description AS department
@@ -1094,41 +1133,38 @@ sub get_name {
?)
|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{"$form->{vc}_id"},
- $form->{"$form->{vc}_id"}) || $form->dberror($query);
-
- my $i = 0;
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $form->{department} = $ref->{department};
- $form->{department_id} = $ref->{department_id};
-
- if ($ref->{link} =~ /_amount/) {
- $i++;
- $form->{"$form->{ARAP}_amount_$i"} =
- "$ref->{accno}--$ref->{description}"
- if $ref->{accno};
- $form->{"projectnumber_$i"} =
- "$ref->{projectnumber}--" .
- "$ref->{project_id}"
- if $ref->{project_id};
- }
-
- if ($ref->{link} eq $form->{ARAP}) {
- $form->{$form->{ARAP}} =
- $form->{"$form->{ARAP}_1"} =
- "$ref->{accno}--".
- "$ref->{description}"
- if $ref->{accno};
- }
- }
-
- $sth->finish;
- $form->{rowcount} = $i if ($i && !$form->{type});
- }
-
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{"$form->{vc}_id"}, $form->{"$form->{vc}_id"} )
+ || $form->dberror($query);
+
+ my $i = 0;
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $form->{department} = $ref->{department};
+ $form->{department_id} = $ref->{department_id};
+
+ if ( $ref->{link} =~ /_amount/ ) {
+ $i++;
+ $form->{"$form->{ARAP}_amount_$i"} =
+ "$ref->{accno}--$ref->{description}"
+ if $ref->{accno};
+ $form->{"projectnumber_$i"} =
+ "$ref->{projectnumber}--" . "$ref->{project_id}"
+ if $ref->{project_id};
+ }
+
+ if ( $ref->{link} eq $form->{ARAP} ) {
+ $form->{ $form->{ARAP} } = $form->{"$form->{ARAP}_1"} =
+ "$ref->{accno}--" . "$ref->{description}"
+ if $ref->{accno};
+ }
+ }
+
+ $sth->finish;
+ $form->{rowcount} = $i if ( $i && !$form->{type} );
+ }
+
+ $dbh->commit;
}
1;
diff --git a/LedgerSMB/AM.pm b/LedgerSMB/AM.pm
index 66795305..1219c50c 100644
--- a/LedgerSMB/AM.pm
+++ b/LedgerSMB/AM.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -40,25 +40,25 @@ use LedgerSMB::Sysconfig;
sub get_account {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
+ my $dbh = $form->{dbh};
- my $query = qq|
+ my $query = qq|
SELECT accno, description, charttype, gifi_accno,
category, link, contra
FROM chart
WHERE id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- my $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
- # get default accounts
- $query = qq|
+ # get default accounts
+ $query = qq|
SELECT (SELECT value FROM defaults
WHERE setting_key = 'inventory_accno_id')
AS inventory_accno_id,
@@ -75,77 +75,71 @@ sub get_account {
WHERE setting_key = 'fxloss_accno_id')
AS fxloss_accno_id|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
- # check if we have any transactions
- $query = qq|
+ # check if we have any transactions
+ $query = qq|
SELECT trans_id
FROM acc_trans
WHERE chart_id = ?
LIMIT 1|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id});
- ($form->{orphaned}) = $sth->fetchrow_array();
- $form->{orphaned} = !$form->{orphaned};
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} );
+ ( $form->{orphaned} ) = $sth->fetchrow_array();
+ $form->{orphaned} = !$form->{orphaned};
- $dbh->commit;
+ $dbh->commit;
}
-
sub save_account {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database, turn off AutoCommit
- my $dbh = $form->{dbh};
-
- $form->{link} = "";
- foreach my $item ($form->{AR},
- $form->{AR_amount},
- $form->{AR_tax},
- $form->{AR_paid},
- $form->{AP},
- $form->{AP_amount},
- $form->{AP_tax},
- $form->{AP_paid},
- $form->{IC},
- $form->{IC_income},
- $form->{IC_sale},
- $form->{IC_expense},
- $form->{IC_cogs},
- $form->{IC_taxpart},
- $form->{IC_taxservice}) {
- $form->{link} .= "${item}:" if ($item);
- }
-
- chop $form->{link};
-
- # strip blanks from accno
- for (qw(accno gifi_accno)) { $form->{$_} =~ s/( |')//g }
-
- foreach my $item (qw(accno gifi_accno description)) {
- $form->{$item} =~ s/-(-+)/-/g;
- $form->{$item} =~ s/ ( )+/ /g;
- }
-
- my $query;
- my $sth;
-
- $form->{contra} *= 1;
-
- my @queryargs;
- @queryargs = ($form->{accno}, $form->{description},
- $form->{charttype}, $form->{gifi_accno},
- $form->{category}, $form->{"link"},
- $form->{contra});
- # if we have an id then replace the old record
- if ($form->{id}) {
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database, turn off AutoCommit
+ my $dbh = $form->{dbh};
+
+ $form->{link} = "";
+ foreach my $item (
+ $form->{AR}, $form->{AR_amount}, $form->{AR_tax},
+ $form->{AR_paid}, $form->{AP}, $form->{AP_amount},
+ $form->{AP_tax}, $form->{AP_paid}, $form->{IC},
+ $form->{IC_income}, $form->{IC_sale}, $form->{IC_expense},
+ $form->{IC_cogs}, $form->{IC_taxpart}, $form->{IC_taxservice}
+ )
+ {
+ $form->{link} .= "${item}:" if ($item);
+ }
+
+ chop $form->{link};
+
+ # strip blanks from accno
+ for (qw(accno gifi_accno)) { $form->{$_} =~ s/( |')//g }
+
+ foreach my $item (qw(accno gifi_accno description)) {
+ $form->{$item} =~ s/-(-+)/-/g;
+ $form->{$item} =~ s/ ( )+/ /g;
+ }
+
+ my $query;
+ my $sth;
+
+ $form->{contra} *= 1;
+
+ my @queryargs;
+ @queryargs = (
+ $form->{accno}, $form->{description}, $form->{charttype},
+ $form->{gifi_accno}, $form->{category}, $form->{"link"},
+ $form->{contra}
+ );
+
+ # if we have an id then replace the old record
+ if ( $form->{id} ) {
+ $query = qq|
UPDATE chart SET accno = ?,
description = ?,
charttype = ?,
@@ -154,102 +148,104 @@ sub save_account {
link = ?,
contra = ?
WHERE id = ?|;
- push @queryargs, $form->{id};
- } else {
- $query = qq|
+ push @queryargs, $form->{id};
+ }
+ else {
+ $query = qq|
INSERT INTO chart
(accno, description, charttype,
gifi_accno, category, link, contra)
VALUES (?, ?, ?, ?, ?, ?, ?)|;
- }
+ }
+
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $form->dberror($query);
+ $sth->finish;
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $form->dberror($query);
- $sth->finish;
+ $chart_id = $dbh->quote( $form->{id} );
- $chart_id = $dbh->quote($form->{id});
+ if ( !$form->{id} ) {
- if (! $form->{id}) {
- # get id from chart
- $query = qq|
+ # get id from chart
+ $query = qq|
SELECT id
FROM chart
WHERE accno = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{accno});
- ($chart_id) = $sth->fetchrow_array();
- $sth->finish;
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{accno} );
+ ($chart_id) = $sth->fetchrow_array();
+ $sth->finish;
+ }
- if ($form->{IC_taxpart} || $form->{IC_taxservice} || $form->{AR_tax} || $form->{AP_tax}) {
+ if ( $form->{IC_taxpart}
+ || $form->{IC_taxservice}
+ || $form->{AR_tax}
+ || $form->{AP_tax} )
+ {
- # add account if it doesn't exist in tax
- $query = qq|SELECT chart_id
+ # add account if it doesn't exist in tax
+ $query = qq|SELECT chart_id
FROM tax
WHERE chart_id = $chart_id|;
- my ($tax_id) = $dbh->selectrow_array($query);
+ my ($tax_id) = $dbh->selectrow_array($query);
- # add tax if it doesn't exist
- unless ($tax_id) {
- $query = qq|INSERT INTO tax (chart_id, rate)
+ # add tax if it doesn't exist
+ unless ($tax_id) {
+ $query = qq|INSERT INTO tax (chart_id, rate)
VALUES ($chart_id, 0)|;
- $dbh->do($query) || $form->dberror($query);
- }
+ $dbh->do($query) || $form->dberror($query);
+ }
- } else {
+ }
+ else {
- # remove tax
- if ($form->{id}) {
- $query = qq|DELETE FROM tax
+ # remove tax
+ if ( $form->{id} ) {
+ $query = qq|DELETE FROM tax
WHERE chart_id = $form->{id}|;
- $dbh->do($query) || $form->dberror($query);
- }
- }
+ $dbh->do($query) || $form->dberror($query);
+ }
+ }
- # commit
- my $rc = $dbh->commit;
+ # commit
+ my $rc = $dbh->commit;
- $rc;
+ $rc;
}
-
-
sub delete_account {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database, turn off AutoCommit
- my $dbh = $form->{dbh};
- my $sth;
- my $query = qq|
+ # connect to database, turn off AutoCommit
+ my $dbh = $form->{dbh};
+ my $sth;
+ my $query = qq|
SELECT count(*)
FROM acc_trans
WHERE chart_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id});
- my ($rowcount) = $sth->fetchrow_array();
-
- if ($rowcount) {
- $form->error(
- "Cannot delete accounts with associated transactions!"
- );
- }
-
-
- # delete chart of account record
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} );
+ my ($rowcount) = $sth->fetchrow_array();
+
+ if ($rowcount) {
+ $form->error( "Cannot delete accounts with associated transactions!" );
+ }
+
+ # delete chart of account record
+ $query = qq|
DELETE FROM chart
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- # set inventory_accno_id, income_accno_id, expense_accno_id to defaults
- $query = qq|
+ # set inventory_accno_id, income_accno_id, expense_accno_id to defaults
+ $query = qq|
UPDATE parts
SET inventory_accno_id = (SELECT value
FROM defaults
@@ -257,724 +253,711 @@ sub delete_account {
'inventory_accno_id')
WHERE inventory_accno_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- for (qw(income_accno_id expense_accno_id)){
- $query = qq|
+ for (qw(income_accno_id expense_accno_id)) {
+ $query = qq|
UPDATE parts
SET $_ = (SELECT value
FROM defaults
WHERE setting_key = '$_')
WHERE $_ = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- $sth->finish;
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ $sth->finish;
+ }
- foreach my $table (qw(partstax customertax vendortax tax)) {
- $query = qq|
+ foreach my $table (qw(partstax customertax vendortax tax)) {
+ $query = qq|
DELETE FROM $table
WHERE chart_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- $sth->finish;
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ $sth->finish;
+ }
- # commit and redirect
- my $rc = $dbh->commit;
+ # commit and redirect
+ my $rc = $dbh->commit;
- $rc;
+ $rc;
}
-
sub gifi_accounts {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my $query = qq|
+ my $query = qq|
SELECT accno, description
FROM gifi
ORDER BY accno|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{ALL} }, $ref;
- }
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{ALL} }, $ref;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
-
sub get_gifi {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
- my $sth;
+ # connect to database
+ my $dbh = $form->{dbh};
+ my $sth;
- my $query = qq|
+ my $query = qq|
SELECT accno, description
FROM gifi
WHERE accno = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{accno}) || $form->dberror($query);
- ($form->{accno}, $form->{description}) = $sth->fetchrow_array();
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{accno} ) || $form->dberror($query);
+ ( $form->{accno}, $form->{description} ) = $sth->fetchrow_array();
- $sth->finish;
+ $sth->finish;
- # check for transactions
- $query = qq|
+ # check for transactions
+ $query = qq|
SELECT count(*)
FROM acc_trans a
JOIN chart c ON (a.chart_id = c.id)
JOIN gifi g ON (c.gifi_accno = g.accno)
WHERE g.accno = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{accno}) || $form->dberror($query);
- ($numrows) = $sth->fetchrow_array;
- if (($numrows * 1) == 0){
- $form->{orphaned} = 1;
- } else {
- $form->{orphaned} = 0;
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{accno} ) || $form->dberror($query);
+ ($numrows) = $sth->fetchrow_array;
+ if ( ( $numrows * 1 ) == 0 ) {
+ $form->{orphaned} = 1;
+ }
+ else {
+ $form->{orphaned} = 0;
+ }
- $dbh->commit;
+ $dbh->commit;
}
-
sub save_gifi {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
- my $dbh = $form->{dbh};
+ $form->{accno} =~ s/( |')//g;
- $form->{accno} =~ s/( |')//g;
+ foreach my $item (qw(accno description)) {
+ $form->{$item} =~ s/-(-+)/-/g;
+ $form->{$item} =~ s/ ( )+/ /g;
+ }
- foreach my $item (qw(accno description)) {
- $form->{$item} =~ s/-(-+)/-/g;
- $form->{$item} =~ s/ ( )+/ /g;
- }
+ my @queryargs = ( $form->{accno}, $form->{description} );
- my @queryargs = ($form->{accno}, $form->{description});
- # id is the old account number!
- if ($form->{id}) {
- $query = qq|
+ # id is the old account number!
+ if ( $form->{id} ) {
+ $query = qq|
UPDATE gifi
SET accno = ?,
description = ?
WHERE accno = ?|;
- push @queryargs, $form->{id};
+ push @queryargs, $form->{id};
- } else {
- $query = qq|
+ }
+ else {
+ $query = qq|
INSERT INTO gifi (accno, description)
VALUES (?, ?)|;
- }
+ }
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $form->dberror;
- $sth->finish;
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $form->dberror;
+ $sth->finish;
+ $dbh->commit;
}
-
sub delete_gifi {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- # id is the old account number!
- $query = qq|
+ # id is the old account number!
+ $query = qq|
DELETE FROM gifi
WHERE accno = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- $sth->finish;
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ $sth->finish;
+ $dbh->commit;
}
-
sub warehouses {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- $form->sort_order();
- my $query = qq|
+ $form->sort_order();
+ my $query = qq|
SELECT id, description
FROM warehouse
ORDER BY description $form->{direction}|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{ALL} }, $ref;
- }
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{ALL} }, $ref;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub get_warehouse {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
- my $sth;
+ # connect to database
+ my $dbh = $form->{dbh};
+ my $sth;
- my $query = qq|
+ my $query = qq|
SELECT description
FROM warehouse
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- ($form->{description}) = $sth->fetchrow_array;
- $sth->finish;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ ( $form->{description} ) = $sth->fetchrow_array;
+ $sth->finish;
- # see if it is in use
- $query = qq|
+ # see if it is in use
+ $query = qq|
SELECT count(*)
FROM inventory
WHERE warehouse_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id});
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} );
- ($form->{orphaned}) = $sth->fetchrow_array;
- if (($form->{orphaned} * 1) == 0){
- $form->{orphaned} = 1;
- } else {
- $form->{orphaned} = 0;
- }
+ ( $form->{orphaned} ) = $sth->fetchrow_array;
+ if ( ( $form->{orphaned} * 1 ) == 0 ) {
+ $form->{orphaned} = 1;
+ }
+ else {
+ $form->{orphaned} = 0;
+ }
- $dbh->commit;
+ $dbh->commit;
}
-
sub save_warehouse {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
+ my ( $self, $myconfig, $form ) = @_;
- my $sth;
- my @queryargs = ($form->{description});
+ # connect to database
+ my $dbh = $form->{dbh};
- $form->{description} =~ s/-(-)+/-/g;
- $form->{description} =~ s/ ( )+/ /g;
+ my $sth;
+ my @queryargs = ( $form->{description} );
+ $form->{description} =~ s/-(-)+/-/g;
+ $form->{description} =~ s/ ( )+/ /g;
- if ($form->{id}) {
- $query = qq|
+ if ( $form->{id} ) {
+ $query = qq|
UPDATE warehouse
SET description = ?
WHERE id = ?|;
- push @queryargs, $form->{id};
- } else {
- $query = qq|
+ push @queryargs, $form->{id};
+ }
+ else {
+ $query = qq|
INSERT INTO warehouse (description)
VALUES (?)|;
- }
+ }
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $form->dberror($query);
- $sth->finish;
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $form->dberror($query);
+ $sth->finish;
+ $dbh->commit;
}
-
sub delete_warehouse {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- $query = qq|
+ $query = qq|
DELETE FROM warehouse
WHERE id = ?|;
- $dbh->prepare($query)->execute($form->{id}) || $form->dberror($query);
- $dbh->commit;
+ $dbh->prepare($query)->execute( $form->{id} ) || $form->dberror($query);
+ $dbh->commit;
}
-
-
sub departments {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- $form->sort_order();
- my $query = qq|SELECT id, description, role
+ $form->sort_order();
+ my $query = qq|SELECT id, description, role
FROM department
ORDER BY description $form->{direction}|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{ALL} }, $ref;
- }
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{ALL} }, $ref;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
-
sub get_department {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
- my $sth;
+ # connect to database
+ my $dbh = $form->{dbh};
+ my $sth;
- my $query = qq|
+ my $query = qq|
SELECT description, role
FROM department
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id});
- ($form->{description}, $form->{role}) = $sth->fetchrow_array;
- $sth->finish;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} );
+ ( $form->{description}, $form->{role} ) = $sth->fetchrow_array;
+ $sth->finish;
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
- # see if it is in use
- $query = qq|
+ # see if it is in use
+ $query = qq|
SELECT count(*)
FROM dpt_trans
WHERE department_id = ? |;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id});
- ($form->{orphaned}) = $sth->fetchrow_array;
- if (($form->{orphaned} * 1) == 0){
- $form->{orphaned} = 1;
- } else {
- $form->{orphaned} = 0;
- }
-
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} );
+ ( $form->{orphaned} ) = $sth->fetchrow_array;
+ if ( ( $form->{orphaned} * 1 ) == 0 ) {
+ $form->{orphaned} = 1;
+ }
+ else {
+ $form->{orphaned} = 0;
+ }
+
+ $dbh->commit;
}
-
sub save_department {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- $form->{description} =~ s/-(-)+/-/g;
- $form->{description} =~ s/ ( )+/ /g;
- my $sth;
- my @queryargs = ($form->{description}, $form->{role});
- if ($form->{id}) {
- $query = qq|
+ $form->{description} =~ s/-(-)+/-/g;
+ $form->{description} =~ s/ ( )+/ /g;
+ my $sth;
+ my @queryargs = ( $form->{description}, $form->{role} );
+ if ( $form->{id} ) {
+ $query = qq|
UPDATE department
SET description = ?,
role = ?
WHERE id = ?|;
- push @queryargs, $form->{id};
+ push @queryargs, $form->{id};
- } else {
- $query = qq|
+ }
+ else {
+ $query = qq|
INSERT INTO department (description, role)
VALUES (?, ?)|;
- }
+ }
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $form->dberror($query);
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $form->dberror($query);
+ $dbh->commit;
}
-
sub delete_department {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- $query = qq|
+ $query = qq|
DELETE FROM department
WHERE id = ?|;
- $dbh->prepare($query)->execute($form->{id});
- $dbh->commit;
+ $dbh->prepare($query)->execute( $form->{id} );
+ $dbh->commit;
}
-
sub business {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- $form->sort_order();
- my $query = qq|
+ $form->sort_order();
+ my $query = qq|
SELECT id, description, discount
FROM business
ORDER BY description $form->{direction}|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{ALL} }, $ref;
- }
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{ALL} }, $ref;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub get_business {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my $query = qq|
+ my $query = qq|
SELECT description, discount
FROM business
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id});
- ($form->{description}, $form->{discount}) = $sth->fetchrow_array();
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} );
+ ( $form->{description}, $form->{discount} ) = $sth->fetchrow_array();
+ $dbh->commit;
}
-
sub save_business {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- $form->{description} =~ s/-(-)+/-/g;
- $form->{description} =~ s/ ( )+/ /g;
- $form->{discount} /= 100;
+ $form->{description} =~ s/-(-)+/-/g;
+ $form->{description} =~ s/ ( )+/ /g;
+ $form->{discount} /= 100;
- my $sth;
- my @queryargs = ($form->{description}, $form->{discount});
+ my $sth;
+ my @queryargs = ( $form->{description}, $form->{discount} );
- if ($form->{id}) {
- $query = qq|
+ if ( $form->{id} ) {
+ $query = qq|
UPDATE business
SET description = ?,
discount = ?
WHERE id = ?|;
- push @queryargs, $form->{id};
+ push @queryargs, $form->{id};
- } else {
- $query = qq|INSERT INTO business (description, discount)
+ }
+ else {
+ $query = qq|INSERT INTO business (description, discount)
VALUES (?, ?)|;
- }
+ }
- $dbh->prepare($query)->execute(@queryargs) || $form->dberror($query);
- $dbh->commit;
+ $dbh->prepare($query)->execute(@queryargs) || $form->dberror($query);
+ $dbh->commit;
}
-
sub delete_business {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- $query = qq|
+ $query = qq|
DELETE FROM business
WHERE id = ?|;
- $dbh->prepare($query)->execute($form->{id}) || $form->dberror($query);
- $dbh->commit;
+ $dbh->prepare($query)->execute( $form->{id} ) || $form->dberror($query);
+ $dbh->commit;
}
-
sub sic {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- $form->{sort} = "code" unless $form->{sort};
- my @a = qw(code description);
+ $form->{sort} = "code" unless $form->{sort};
+ my @a = qw(code description);
- my %ordinal = ( code => 1,
- description => 3 );
+ my %ordinal = (
+ code => 1,
+ description => 3
+ );
- my $sortorder = $form->sort_order(\@a, \%ordinal);
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
- my $query = qq|SELECT code, sictype, description
+ my $query = qq|SELECT code, sictype, description
FROM sic
ORDER BY $sortorder|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{ALL} }, $ref;
- }
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{ALL} }, $ref;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub get_sic {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my $query = qq|
+ my $query = qq|
SELECT code, sictype, description
FROM sic
- WHERE code = |.$dbh->quote($form->{code});
+ WHERE code = | . $dbh->quote( $form->{code} );
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- my $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub save_sic {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
- # connect to database
- my $dbh = $form->{dbh};
+ foreach my $item (qw(code description)) {
+ $form->{$item} =~ s/-(-)+/-/g;
+ }
+ my $sth;
+ @queryargs = ( $form->{code}, $form->{sictype}, $form->{description} );
- foreach my $item (qw(code description)) {
- $form->{$item} =~ s/-(-)+/-/g;
- }
- my $sth;
- @queryargs = ($form->{code}, $form->{sictype}, $form->{description});
- # if there is an id
- if ($form->{id}) {
- $query = qq|
+ # if there is an id
+ if ( $form->{id} ) {
+ $query = qq|
UPDATE sic
SET code = ?,
sictype = ?,
description = ?
WHERE code = ?)|;
- push @queryargs, $form->{id};
+ push @queryargs, $form->{id};
- } else {
- $query = qq|
+ }
+ else {
+ $query = qq|
INSERT INTO sic (code, sictype, description)
VALUES (?, ?, ?)|;
- }
+ }
- $dbh->prepare($query)->execute(@queryargs) || $form->dberror($query);
- $dbh->commit;
+ $dbh->prepare($query)->execute(@queryargs) || $form->dberror($query);
+ $dbh->commit;
}
-
sub delete_sic {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- $query = qq|
+ $query = qq|
DELETE FROM sic
WHERE code = ?|;
- $dbh->prepare($query)->execute($form->{code});
- $dbh->commit;
+ $dbh->prepare($query)->execute( $form->{code} );
+ $dbh->commit;
}
-
sub language {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- $form->{sort} = "code" unless $form->{sort};
- my @a = qw(code description);
+ $form->{sort} = "code" unless $form->{sort};
+ my @a = qw(code description);
- my %ordinal = ( code => 1,
- description => 2 );
+ my %ordinal = (
+ code => 1,
+ description => 2
+ );
- my $sortorder = $form->sort_order(\@a, \%ordinal);
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
- my $query = qq|
+ my $query = qq|
SELECT code, description
FROM language
ORDER BY $sortorder|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{ALL} }, $ref;
- }
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{ALL} }, $ref;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub get_language {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- ## needs fixing (SELECT *...)
- my $query = qq|
+ ## needs fixing (SELECT *...)
+ my $query = qq|
SELECT *
FROM language
WHERE code = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{code}) || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{code} ) || $form->dberror($query);
- my $ref = $sth->fetchrow_hashref(NAME_lc);
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub save_language {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
- # connect to database
- my $dbh = $form->{dbh};
+ $form->{code} =~ s/ //g;
- $form->{code} =~ s/ //g;
+ foreach my $item (qw(code description)) {
+ $form->{$item} =~ s/-(-)+/-/g;
+ $form->{$item} =~ s/ ( )+/-/g;
+ }
+ my $sth;
+ my @queryargs = ( $form->{code}, $form->{description} );
- foreach my $item (qw(code description)) {
- $form->{$item} =~ s/-(-)+/-/g;
- $form->{$item} =~ s/ ( )+/-/g;
- }
- my $sth;
- my @queryargs = ($form->{code}, $form->{description});
- # if there is an id
- if ($form->{id}) {
- $query = qq|
+ # if there is an id
+ if ( $form->{id} ) {
+ $query = qq|
UPDATE language
SET code = ?,
description = ?
WHERE code = ?|;
- push @queryargs, $form->{id};
+ push @queryargs, $form->{id};
- } else {
- $query = qq|
+ }
+ else {
+ $query = qq|
INSERT INTO language (code, description)
VALUES (?, ?)|;
- }
+ }
- $dbh->prepare($query)->execute(@queryargs) || $form->dberror($query);
- $dbh->commit;
+ $dbh->prepare($query)->execute(@queryargs) || $form->dberror($query);
+ $dbh->commit;
}
-
sub delete_language {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- $query = qq|
+ $query = qq|
DELETE FROM language
- WHERE code = |.$dbh->quote($form->{code});
+ WHERE code = | . $dbh->quote( $form->{code} );
- $dbh->do($query) || $form->dberror($query);
- $dbh->{dbh};
+ $dbh->do($query) || $form->dberror($query);
+ $dbh->{dbh};
}
-
sub recurring_transactions {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
+ my $dbh = $form->{dbh};
- my $query = qq|SELECT value FROM defaults where setting_key = 'curr'|;
+ my $query = qq|SELECT value FROM defaults where setting_key = 'curr'|;
- my ($defaultcurrency) = $dbh->selectrow_array($query);
- $defaultcurrency = $dbh->quote($defaultcurrency =~ s/:.*//g);
+ my ($defaultcurrency) = $dbh->selectrow_array($query);
+ $defaultcurrency = $dbh->quote( $defaultcurrency =~ s/:.*//g );
- $form->{sort} ||= "nextdate";
- my @a = ($form->{sort});
- my $sortorder = $form->sort_order(\@a);
+ $form->{sort} ||= "nextdate";
+ my @a = ( $form->{sort} );
+ my $sortorder = $form->sort_order( \@a );
- $query = qq|
+ $query = qq|
SELECT 'ar' AS module, 'ar' AS transaction, a.invoice,
n.name AS description, a.amount,
s.*, se.formname AS recurringemail,
@@ -1069,77 +1052,90 @@ sub recurring_transactions {
ORDER BY $sortorder|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- my $id;
- my $transaction;
- my %e = ();
- my %p = ();
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ my $id;
+ my $transaction;
+ my %e = ();
+ my %p = ();
- $ref->{exchangerate} ||= 1;
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
- if ($ref->{id} != $id) {
+ $ref->{exchangerate} ||= 1;
- if (%e) {
- $form->{transactions}{$transaction}->[$i]->{recurringemail} = "";
- for (keys %e) {
- $form->{transactions}{$transaction}->[$i]->{recurringemail} .= "${_}:";
- }
- chop $form->{transactions}{$transaction}->[$i]->{recurringemail};
- }
+ if ( $ref->{id} != $id ) {
- if (%p) {
- $form->{transactions}{$transaction}->[$i]->{recurringprint} = "";
- for (keys %p) { $form->{transactions}{$transaction}->[$i]->{recurringprint} .= "${_}:" }
- chop $form->{transactions}{$transaction}->[$i]->{recurringprint};
- }
+ if (%e) {
+ $form->{transactions}{$transaction}->[$i]->{recurringemail} =
+ "";
+ for ( keys %e ) {
+ $form->{transactions}{$transaction}->[$i]
+ ->{recurringemail} .= "${_}:";
+ }
+ chop $form->{transactions}{$transaction}->[$i]
+ ->{recurringemail};
+ }
- %e = ();
- %p = ();
+ if (%p) {
+ $form->{transactions}{$transaction}->[$i]->{recurringprint} =
+ "";
+ for ( keys %p ) {
+ $form->{transactions}{$transaction}->[$i]
+ ->{recurringprint} .= "${_}:";
+ }
+ chop $form->{transactions}{$transaction}->[$i]
+ ->{recurringprint};
+ }
- push @{ $form->{transactions}{$ref->{transaction}} }, $ref;
+ %e = ();
+ %p = ();
- $id = $ref->{id};
- $i = $#{ $form->{transactions}{$ref->{transaction}} };
+ push @{ $form->{transactions}{ $ref->{transaction} } }, $ref;
- }
+ $id = $ref->{id};
+ $i = $#{ $form->{transactions}{ $ref->{transaction} } };
- $transaction = $ref->{transaction};
+ }
- $e{$ref->{recurringemail}} = 1 if $ref->{recurringemail};
- $p{$ref->{recurringprint}} = 1 if $ref->{recurringprint};
+ $transaction = $ref->{transaction};
- }
+ $e{ $ref->{recurringemail} } = 1 if $ref->{recurringemail};
+ $p{ $ref->{recurringprint} } = 1 if $ref->{recurringprint};
- $sth->finish;
+ }
- # this is for the last row
- if (%e) {
- $form->{transactions}{$transaction}->[$i]->{recurringemail} = "";
- for (keys %e) { $form->{transactions}{$transaction}->[$i]->{recurringemail} .= "${_}:" }
- chop $form->{transactions}{$transaction}->[$i]->{recurringemail};
- }
+ $sth->finish;
- if (%p) {
- $form->{transactions}{$transaction}->[$i]->{recurringprint} = "";
- for (keys %p) { $form->{transactions}{$transaction}->[$i]->{recurringprint} .= "${_}:" }
- chop $form->{transactions}{$transaction}->[$i]->{recurringprint};
- }
+ # this is for the last row
+ if (%e) {
+ $form->{transactions}{$transaction}->[$i]->{recurringemail} = "";
+ for ( keys %e ) {
+ $form->{transactions}{$transaction}->[$i]->{recurringemail} .=
+ "${_}:";
+ }
+ chop $form->{transactions}{$transaction}->[$i]->{recurringemail};
+ }
+ if (%p) {
+ $form->{transactions}{$transaction}->[$i]->{recurringprint} = "";
+ for ( keys %p ) {
+ $form->{transactions}{$transaction}->[$i]->{recurringprint} .=
+ "${_}:";
+ }
+ chop $form->{transactions}{$transaction}->[$i]->{recurringprint};
+ }
- $dbh->commit;
+ $dbh->commit;
}
sub recurring_details {
- my ($self, $myconfig, $form, $id) = @_;
+ my ( $self, $myconfig, $form, $id ) = @_;
- my $dbh = $form->{dbh};
- my $query = qq|
+ my $dbh = $form->{dbh};
+ my $query = qq|
SELECT s.*, ar.id AS arid, ar.invoice AS arinvoice,
ap.id AS apid, ap.invoice AS apinvoice,
ar.duedate - ar.transdate AS overdue,
@@ -1152,374 +1148,386 @@ sub recurring_details {
LEFT JOIN oe ON (oe.id = s.id)
WHERE s.id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($id) || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute($id) || $form->dberror($query);
- my $ref = $sth->fetchrow_hashref(NAME_lc);
- $form->{vc} = "customer" if $ref->{customer_id};
- $form->{vc} = "vendor" if $ref->{vendor_id};
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+ $form->{vc} = "customer" if $ref->{customer_id};
+ $form->{vc} = "vendor" if $ref->{vendor_id};
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
- $form->{invoice} = ($form->{arid} && $form->{arinvoice});
- $form->{invoice} = ($form->{apid} && $form->{apinvoice}) unless $form->{invoice};
+ $form->{invoice} = ( $form->{arid} && $form->{arinvoice} );
+ $form->{invoice} = ( $form->{apid} && $form->{apinvoice} )
+ unless $form->{invoice};
- $query = qq|
+ $query = qq|
SELECT *
FROM recurringemail
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($id) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute($id) || $form->dberror($query);
- $form->{recurringemail} = "";
+ $form->{recurringemail} = "";
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $form->{recurringemail} .= "$ref->{formname}:$ref->{format}:";
- $form->{message} = $ref->{message};
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $form->{recurringemail} .= "$ref->{formname}:$ref->{format}:";
+ $form->{message} = $ref->{message};
+ }
- $sth->finish;
+ $sth->finish;
- $query = qq|
+ $query = qq|
SELECT *
FROM recurringprint
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($id) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute($id) || $form->dberror($query);
- $form->{recurringprint} = "";
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $form->{recurringprint} .=
- "$ref->{formname}:$ref->{format}:$ref->{printer}:";
- }
+ $form->{recurringprint} = "";
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $form->{recurringprint} .=
+ "$ref->{formname}:$ref->{format}:$ref->{printer}:";
+ }
- $sth->finish;
+ $sth->finish;
- chop $form->{recurringemail};
- chop $form->{recurringprint};
+ chop $form->{recurringemail};
+ chop $form->{recurringprint};
- for (qw(arinvoice apinvoice)) { delete $form->{$_} }
+ for (qw(arinvoice apinvoice)) { delete $form->{$_} }
- $dbh->commit;
+ $dbh->commit;
}
-
sub update_recurring {
- my ($self, $myconfig, $form, $id) = @_;
+ my ( $self, $myconfig, $form, $id ) = @_;
- my $dbh = $form->{dbh};
+ my $dbh = $form->{dbh};
- $id = $dbh->quote($id);
- my $query = qq|
+ $id = $dbh->quote($id);
+ my $query = qq|
SELECT nextdate, repeat, unit
FROM recurring
WHERE id = $id|;
- my ($nextdate, $repeat, $unit) = $dbh->selectrow_array($query);
+ my ( $nextdate, $repeat, $unit ) = $dbh->selectrow_array($query);
+
+ $nextdate = $dbh->quote($nextdate);
+ my $interval = $dbh->quote("$repeat $unit");
- $nextdate = $dbh->quote($nextdate);
- my $interval = $dbh->quote("$repeat $unit");
- # check if it is the last date
- $query = qq|
+ # check if it is the last date
+ $query = qq|
SELECT (date $nextdate + interval $interval) > enddate
FROM recurring
WHERE id = $id|;
- my ($last_repeat) = $dbh->selectrow_array($query);
- if ($last_repeat) {
- $advance{$myconfig->{dbdriver}} = "NULL";
- }
+ my ($last_repeat) = $dbh->selectrow_array($query);
+ if ($last_repeat) {
+ $advance{ $myconfig->{dbdriver} } = "NULL";
+ }
- $query = qq|
+ $query = qq|
UPDATE recurring
SET nextdate = (date $nextdate + interval $interval)
WHERE id = $id|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $form->dberror($query);
- $dbh->commit;
+ $dbh->commit;
}
-
sub check_template_name {
- my ($self, $myconfig, $form) = @_;
-
- my @allowedsuff = qw(css tex txt html xml);
- if ($form->{file} =~ /^(.:)*?\/|\.\.\/|^\//){
- $form->error("Directory transversal not allowed.");
- }
- if ($form->{file} =~ /^${LedgerSMB::Sysconfig::userspath}\//){
- $form->error("Not allowed to access ${LedgerSMB::Sysconfig::userspath}/ with this method");
- }
- my $whitelisted = 0;
- for (@allowedsuff){
- if ($form->{file} =~ /$_$/){
- $whitelisted = 1;
- }
- }
- if (!$whitelisted){
- $form->error("Error: File is of type that is not allowed.");
- }
-
- if ($form->{file} !~ /^$myconfig->{templates}\//){
- $form->error("Not in a whitelisted directory: $form->{file}") unless $form->{file} =~ /^css\//;
- }
+ my ( $self, $myconfig, $form ) = @_;
+
+ my @allowedsuff = qw(css tex txt html xml);
+ if ( $form->{file} =~ /^(.:)*?\/|\.\.\/|^\// ) {
+ $form->error("Directory transversal not allowed.");
+ }
+ if ( $form->{file} =~ /^${LedgerSMB::Sysconfig::userspath}\// ) {
+ $form->error(
+"Not allowed to access ${LedgerSMB::Sysconfig::userspath}/ with this method"
+ );
+ }
+ my $whitelisted = 0;
+ for (@allowedsuff) {
+ if ( $form->{file} =~ /$_$/ ) {
+ $whitelisted = 1;
+ }
+ }
+ if ( !$whitelisted ) {
+ $form->error("Error: File is of type that is not allowed.");
+ }
+
+ if ( $form->{file} !~ /^$myconfig->{templates}\// ) {
+ $form->error("Not in a whitelisted directory: $form->{file}")
+ unless $form->{file} =~ /^css\//;
+ }
}
-
sub load_template {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- $self->check_template_name(\%$myconfig, \%$form);
- open(TEMPLATE, '<', "$form->{file}") or $form->error("$form->{file} : $!");
+ $self->check_template_name( \%$myconfig, \%$form );
+ open( TEMPLATE, '<', "$form->{file}" )
+ or $form->error("$form->{file} : $!");
- while (<TEMPLATE>) {
- $form->{body} .= $_;
- }
+ while (<TEMPLATE>) {
+ $form->{body} .= $_;
+ }
- close(TEMPLATE);
+ close(TEMPLATE);
}
-
sub save_template {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- $self->check_template_name(\%$myconfig, \%$form);
- open(TEMPLATE, '>', "$form->{file}") or $form->error("$form->{file} : $!");
+ $self->check_template_name( \%$myconfig, \%$form );
+ open( TEMPLATE, '>', "$form->{file}" )
+ or $form->error("$form->{file} : $!");
- # strip
- $form->{body} =~ s/\r//g;
- print TEMPLATE $form->{body};
+ # strip
+ $form->{body} =~ s/\r//g;
+ print TEMPLATE $form->{body};
- close(TEMPLATE);
+ close(TEMPLATE);
}
-
sub save_preferences {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- # get username, is same as requested?
- my @queryargs;
- my $query = qq|
+ # get username, is same as requested?
+ my @queryargs;
+ my $query = qq|
SELECT login
FROM employees
WHERE login = ?|;
- @queryargs = ($form->{login});
- my $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $form->dberror($query);
- my ($dbusername) = $sth->fetchrow_array;
- $sth->finish;
+ @queryargs = ( $form->{login} );
+ my $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $form->dberror($query);
+ my ($dbusername) = $sth->fetchrow_array;
+ $sth->finish;
- return 0 if ($dbusername ne $form->{login});
+ return 0 if ( $dbusername ne $form->{login} );
- # update name
- $query = qq|
+ # update name
+ $query = qq|
UPDATE employees
SET name = ?
WHERE login = ?|;
- @queryargs = ($form->{name}, $form->{login});
- $dbh->prepare($query)->execute(@queryargs) || $form->dberror($query);
+ @queryargs = ( $form->{name}, $form->{login} );
+ $dbh->prepare($query)->execute(@queryargs) || $form->dberror($query);
- # get default currency
- $query = qq|
+ # get default currency
+ $query = qq|
SELECT value, (SELECT value FROM defaults
WHERE setting_key = 'businessnumber')
FROM defaults
WHERE setting_key = 'curr'|;
- ($form->{currency}, $form->{businessnumber}) =
- $dbh->selectrow_array($query);
- $form->{currency} =~ s/:.*//;
+ ( $form->{currency}, $form->{businessnumber} ) =
+ $dbh->selectrow_array($query);
+ $form->{currency} =~ s/:.*//;
- $dbh->commit;
+ $dbh->commit;
- my $myconfig = LedgerSMB::User->new($form->{login});
+ my $myconfig = LedgerSMB::User->new( $form->{login} );
- map {$myconfig->{$_} = $form->{$_} if exists $form->{$_}}
- qw(name email dateformat signature numberformat vclimit tel fax
- company menuwidth countrycode address timeout stylesheet
- printer password);
-
- foreach my $item (keys %$form) {
- $myconfig->{$item} = $form->{$item};
- }
+ map { $myconfig->{$_} = $form->{$_} if exists $form->{$_} }
+ qw(name email dateformat signature numberformat vclimit tel fax
+ company menuwidth countrycode address timeout stylesheet
+ printer password);
- $myconfig->{password} = $form->{new_password} if ($form->{old_password} ne $form->{new_password});
+ foreach my $item ( keys %$form ) {
+ $myconfig->{$item} = $form->{$item};
+ }
- $myconfig->save_member();
+ $myconfig->{password} = $form->{new_password}
+ if ( $form->{old_password} ne $form->{new_password} );
- 1;
+ $myconfig->save_member();
-}
+ 1;
+}
sub save_defaults {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
+
+ for (qw(IC IC_income IC_expense FX_gain FX_loss)) {
+ ( $form->{$_} ) = split /--/, $form->{$_};
+ }
- for (qw(IC IC_income IC_expense FX_gain FX_loss)) { ($form->{$_}) = split /--/, $form->{$_} }
+ my @a;
+ $form->{curr} =~ s/ //g;
+ for ( split /:/, $form->{curr} ) { push( @a, uc pack "A3", $_ ) if $_ }
+ $form->{curr} = join ':', @a;
- my @a;
- $form->{curr} =~ s/ //g;
- for (split /:/, $form->{curr}) { push(@a, uc pack "A3", $_) if $_ }
- $form->{curr} = join ':', @a;
+ # connect to database
+ my $dbh = $form->{dbh};
- # connect to database
- my $dbh = $form->{dbh};
- # save defaults
- $sth_plain = $dbh->prepare("
- UPDATE defaults SET value = ? WHERE setting_key = ?");
- $sth_accno = $dbh->prepare(qq|
+ # save defaults
+ $sth_plain = $dbh->prepare( "
+ UPDATE defaults SET value = ? WHERE setting_key = ?" );
+ $sth_accno = $dbh->prepare(
+ qq|
UPDATE defaults
SET value = (SELECT id
FROM chart
WHERE accno = ?)
- WHERE setting_key = ?|);
- my %translation = (
- inventory_accno_id => 'IC',
- income_accno_id => 'IC_income',
- expense_accno_id => 'IC_expense',
- fxgain_accno_id => 'FX_gain',
- fxloss_accno_id => 'FX_loss'
- );
- for (
- qw(inventory_accno_id income_accno_id expense_accno_id
- fxgain_accno_id fxloss_accno_id glnumber sinumber vinumber
- sonumber ponumber sqnumber rfqnumber partnumber employeenumber
- customernumber vendornumber projectnumber yearend curr
- weightunit businessnumber)
- ){
- my $val = $form->{$_};
-
- if ($translation{$_}){
- $val = $form->{$translation{$_}};
- }
- if ($_ =~ /accno/){
- $sth_accno->execute($val, $_)
- || $form->dberror("Saving $_");
- } else {
- $sth_plain->execute($val, $_)
- || $form->dberror("Saving $_");
- }
-
- }
- my $rc = $dbh->commit;
-
- $rc;
+ WHERE setting_key = ?|
+ );
+ my %translation = (
+ inventory_accno_id => 'IC',
+ income_accno_id => 'IC_income',
+ expense_accno_id => 'IC_expense',
+ fxgain_accno_id => 'FX_gain',
+ fxloss_accno_id => 'FX_loss'
+ );
+ for (
+ qw(inventory_accno_id income_accno_id expense_accno_id
+ fxgain_accno_id fxloss_accno_id glnumber sinumber vinumber
+ sonumber ponumber sqnumber rfqnumber partnumber employeenumber
+ customernumber vendornumber projectnumber yearend curr
+ weightunit businessnumber)
+ )
+ {
+ my $val = $form->{$_};
+
+ if ( $translation{$_} ) {
+ $val = $form->{ $translation{$_} };
+ }
+ if ( $_ =~ /accno/ ) {
+ $sth_accno->execute( $val, $_ )
+ || $form->dberror("Saving $_");
+ }
+ else {
+ $sth_plain->execute( $val, $_ )
+ || $form->dberror("Saving $_");
+ }
+
+ }
+ my $rc = $dbh->commit;
+
+ $rc;
}
-
sub defaultaccounts {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- # get defaults from defaults table
- my $query = qq|
+ # get defaults from defaults table
+ my $query = qq|
SELECT setting_key, value FROM defaults
WHERE setting_key LIKE ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute('%accno_id') || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute('%accno_id') || $form->dberror($query);
- my $ref;
- while ($ref = $sth->fetchrow_hashref(NAME_lc)){
- $form->{$ref->{setting_key}} = $ref->{value};
- }
+ my $ref;
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $form->{ $ref->{setting_key} } = $ref->{value};
+ }
- $form->{defaults}{IC} = $form->{inventory_accno_id};
- $form->{defaults}{IC_income} = $form->{income_accno_id};
- $form->{defaults}{IC_sale} = $form->{income_accno_id};
- $form->{defaults}{IC_expense} = $form->{expense_accno_id};
- $form->{defaults}{IC_cogs} = $form->{expense_accno_id};
- $form->{defaults}{FX_gain} = $form->{fxgain_accno_id};
- $form->{defaults}{FX_loss} = $form->{fxloss_accno_id};
+ $form->{defaults}{IC} = $form->{inventory_accno_id};
+ $form->{defaults}{IC_income} = $form->{income_accno_id};
+ $form->{defaults}{IC_sale} = $form->{income_accno_id};
+ $form->{defaults}{IC_expense} = $form->{expense_accno_id};
+ $form->{defaults}{IC_cogs} = $form->{expense_accno_id};
+ $form->{defaults}{FX_gain} = $form->{fxgain_accno_id};
+ $form->{defaults}{FX_loss} = $form->{fxloss_accno_id};
- $sth->finish;
+ $sth->finish;
- $query = qq|
+ $query = qq|
SELECT id, accno, description, link
FROM chart
WHERE link LIKE '%IC%'
ORDER BY accno|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- my $nkey;
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- foreach my $key (split(/:/, $ref->{link})) {
- if ($key =~ /IC/) {
- $nkey = $key;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- if ($key =~ /cogs/) {
- $nkey = "IC_expense";
- }
+ my $nkey;
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ foreach my $key ( split( /:/, $ref->{link} ) ) {
+ if ( $key =~ /IC/ ) {
+ $nkey = $key;
- if ($key =~ /sale/) {
- $nkey = "IC_income";
- }
+ if ( $key =~ /cogs/ ) {
+ $nkey = "IC_expense";
+ }
- %{ $form->{accno}{$nkey}{$ref->{accno}} } = ( id => $ref->{id},
- description => $ref->{description} );
- }
- }
- }
+ if ( $key =~ /sale/ ) {
+ $nkey = "IC_income";
+ }
- $sth->finish;
+ %{ $form->{accno}{$nkey}{ $ref->{accno} } } = (
+ id => $ref->{id},
+ description => $ref->{description}
+ );
+ }
+ }
+ }
+ $sth->finish;
- $query = qq|
+ $query = qq|
SELECT id, accno, description
FROM chart
WHERE (category = 'I' OR category = 'E')
AND charttype = 'A'
ORDER BY accno|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- %{ $form->{accno}{FX_gain}{$ref->{accno}} } = ( id => $ref->{id},
- description => $ref->{description} );
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ %{ $form->{accno}{FX_gain}{ $ref->{accno} } } = (
+ id => $ref->{id},
+ description => $ref->{description}
+ );
- %{ $form->{accno}{FX_loss}{$ref->{accno}} } = ( id => $ref->{id},
- description => $ref->{description} );
- }
+ %{ $form->{accno}{FX_loss}{ $ref->{accno} } } = (
+ id => $ref->{id},
+ description => $ref->{description}
+ );
+ }
- $sth->finish;
+ $sth->finish;
- $dbh->commit;
+ $dbh->commit;
}
-
sub taxes {
- my ($self, $myconfig, $form) = @_;
- my $taxaccounts = '';
+ my ( $self, $myconfig, $form ) = @_;
+ my $taxaccounts = '';
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my $query = qq|
+ my $query = qq|
SELECT c.id, c.accno, c.description,
t.rate * 100 AS rate, t.taxnumber, t.validto,
t.pass, m.taxmodulename
@@ -1528,155 +1536,160 @@ sub taxes {
JOIN taxmodule m ON (t.taxmodule_id = m.taxmodule_id)
ORDER BY 3, 6|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{taxrates} }, $ref;
+ $taxaccounts .= " " . $ref{accno};
+ }
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{taxrates} }, $ref;
- $taxaccounts .= " " . $ref{accno};
- }
+ $sth->finish;
- $sth->finish;
-
- $query = qq|
+ $query = qq|
SELECT taxmodule_id, taxmodulename FROM taxmodule
ORDER BY 2|;
-
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $form->{"taxmodule_".$ref->{taxmodule_id}} =
- $ref->{taxmodulename};
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- $sth->finish;
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $form->{ "taxmodule_" . $ref->{taxmodule_id} } = $ref->{taxmodulename};
+ }
- $dbh->commit;
+ $sth->finish;
-}
+ $dbh->commit;
+}
sub save_taxes {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my $query = qq|DELETE FROM tax|;
- $dbh->do($query) || $form->dberror($query);
+ my $query = qq|DELETE FROM tax|;
+ $dbh->do($query) || $form->dberror($query);
-
- $query = qq|
+ $query = qq|
INSERT INTO tax (chart_id, rate, taxnumber, validto,
pass, taxmodule_id)
VALUES (?, ?, ?, ?, ?, ?)|;
- my $sth = $dbh->prepare($query);
- foreach my $item (split / /, $form->{taxaccounts}) {
- my ($chart_id, $i) = split /_/, $item;
- my $rate = $form->parse_amount(
- $myconfig, $form->{"taxrate_$i"}) / 100;
- my $validto = $form->{"validto_$i"};
- $validto = undef if not $validto;
- my @queryargs = ($chart_id, $rate, $form->{"taxnumber_$i"},
- $validto, $form->{"pass_$i"},
- $form->{"taxmodule_id_$i"});
+ my $sth = $dbh->prepare($query);
+ foreach my $item ( split / /, $form->{taxaccounts} ) {
+ my ( $chart_id, $i ) = split /_/, $item;
+ my $rate =
+ $form->parse_amount( $myconfig, $form->{"taxrate_$i"} ) / 100;
+ my $validto = $form->{"validto_$i"};
+ $validto = undef if not $validto;
+ my @queryargs = (
+ $chart_id, $rate, $form->{"taxnumber_$i"},
+ $validto, $form->{"pass_$i"}, $form->{"taxmodule_id_$i"}
+ );
- $sth->execute(@queryargs) || $form->dberror($query);
- }
+ $sth->execute(@queryargs) || $form->dberror($query);
+ }
- my $rc = $dbh->commit;
+ my $rc = $dbh->commit;
- $rc;
+ $rc;
}
-
sub backup {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $mail;
- my $err;
+ my $mail;
+ my $err;
- my @t = localtime(time);
- $t[4]++;
- $t[5] += 1900;
- $t[3] = substr("0$t[3]", -2);
- $t[4] = substr("0$t[4]", -2);
+ my @t = localtime(time);
+ $t[4]++;
+ $t[5] += 1900;
+ $t[3] = substr( "0$t[3]", -2 );
+ $t[4] = substr( "0$t[4]", -2 );
- my $boundary = time;
- my $tmpfile = "${LedgerSMB::Sysconfig::userspath}/$boundary.$myconfig->{dbname}-$form->{dbversion}-$t[5]$t[4]$t[3].sql";
- $tmpfile .= ".gz" if ${LedgerSMB::Sysconfig::gzip};
- $form->{OUT} = "$tmpfile";
+ my $boundary = time;
+ my $tmpfile =
+"${LedgerSMB::Sysconfig::userspath}/$boundary.$myconfig->{dbname}-$form->{dbversion}-$t[5]$t[4]$t[3].sql";
+ $tmpfile .= ".gz" if ${LedgerSMB::Sysconfig::gzip};
+ $form->{OUT} = "$tmpfile";
- open(OUT, '>', "$form->{OUT}") or $form->error("$form->{OUT} : $!");
+ open( OUT, '>', "$form->{OUT}" ) or $form->error("$form->{OUT} : $!");
- # get sequences, functions and triggers
+ # get sequences, functions and triggers
- my $today = scalar localtime;
+ my $today = scalar localtime;
- $myconfig->{dbhost} = 'localhost' unless $myconfig->{dbhost};
+ $myconfig->{dbhost} = 'localhost' unless $myconfig->{dbhost};
- $ENV{PGPASSWD} = $myconfig->{dbpasswd};
- # drop tables and sequences
+ $ENV{PGPASSWD} = $myconfig->{dbpasswd};
- # compress backup if gzip defined
- my $suffix = "";
+ # drop tables and sequences
- if ($form->{media} eq 'email') {
- if (${LedgerSMB::Sysconfig::gzip}){
- print OUT `pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} $myconfig->{dbname} | ${LedgerSMB::Sysconfig::gzip}`;
- } else {
- print OUT `pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} $myconfig->{dbname}`;
- }
- close OUT;
- use LedgerSMB::Mailer;
- $mail = new Mailer;
+ # compress backup if gzip defined
+ my $suffix = "";
- $mail->{to} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
- $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
- $mail->{subject} = "LedgerSMB Backup / $myconfig->{dbname}-$form->{dbversion}-$t[5]$t[4]$t[3].sql$suffix";
- @{ $mail->{attachments} } = ($tmpfile);
- $mail->{version} = $form->{version};
- $mail->{fileid} = "$boundary.";
- $mail->{format} = "plain";
- $mail->{format} = "octet-stream" if ${LedgerSMB::Sysconfig::gzip};
+ if ( $form->{media} eq 'email' ) {
+ if ( ${LedgerSMB::Sysconfig::gzip} ) {
+ print OUT
+`pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} $myconfig->{dbname} | ${LedgerSMB::Sysconfig::gzip}`;
+ }
+ else {
+ print OUT
+`pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} $myconfig->{dbname}`;
+ }
+ close OUT;
+ use LedgerSMB::Mailer;
+ $mail = new Mailer;
- $myconfig->{signature} =~ s/\\n/\n/g;
- $mail->{message} = "-- \n$myconfig->{signature}";
+ $mail->{to} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
+ $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
+ $mail->{subject} =
+"LedgerSMB Backup / $myconfig->{dbname}-$form->{dbversion}-$t[5]$t[4]$t[3].sql$suffix";
+ @{ $mail->{attachments} } = ($tmpfile);
+ $mail->{version} = $form->{version};
+ $mail->{fileid} = "$boundary.";
+ $mail->{format} = "plain";
+ $mail->{format} = "octet-stream" if ${LedgerSMB::Sysconfig::gzip};
- $err = $mail->send;
- }
+ $myconfig->{signature} =~ s/\\n/\n/g;
+ $mail->{message} = "-- \n$myconfig->{signature}";
- if ($form->{media} eq 'file') {
+ $err = $mail->send;
+ }
- open(IN, '<', "$tmpfile") or $form->error("$tmpfile : $!");
- open(OUT, ">-") or $form->error("STDOUT : $!");
+ if ( $form->{media} eq 'file' ) {
- print OUT qq|Content-Type: application/file;\n| .
- qq|Content-Disposition: attachment; filename="$myconfig->{dbname}-$form->{dbversion}-$t[5]$t[4]$t[3].sql$suffix"\n\n|;
- if (${LedgerSMB::Sysconfig::gzip}){
- print OUT `pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} $myconfig->{dbname} | ${LedgerSMB::Sysconfig::gzip}`;
- } else {
- print OUT `pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} $myconfig->{dbname}`;
- }
+ open( IN, '<', "$tmpfile" ) or $form->error("$tmpfile : $!");
+ open( OUT, ">-" ) or $form->error("STDOUT : $!");
- }
+ print OUT qq|Content-Type: application/file;\n|
+ . qq|Content-Disposition: attachment; filename="$myconfig->{dbname}-$form->{dbversion}-$t[5]$t[4]$t[3].sql$suffix"\n\n|;
+ if ( ${LedgerSMB::Sysconfig::gzip} ) {
+ print OUT
+`pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} $myconfig->{dbname} | ${LedgerSMB::Sysconfig::gzip}`;
+ }
+ else {
+ print OUT
+`pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} $myconfig->{dbname}`;
+ }
- unlink "$tmpfile";
+ }
-}
+ unlink "$tmpfile";
+}
sub closedto {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
+ my $dbh = $form->{dbh};
- my $query = qq|
+ my $query = qq|
SELECT (SELECT value FROM defaults
WHERE setting_key = 'closedto'),
(SELECT value FROM defaults
@@ -1684,108 +1697,104 @@ sub closedto {
(SELECT value FROM defaults
WHERE setting_key = 'audittrail')|;
- ($form->{closedto}, $form->{revtrans}, $form->{audittrail})
- = $dbh->selectrow_array($query);
+ ( $form->{closedto}, $form->{revtrans}, $form->{audittrail} ) =
+ $dbh->selectrow_array($query);
- $dbh->commit;
+ $dbh->commit;
}
-
sub closebooks {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
- my $query = qq|
+ my $dbh = $form->{dbh};
+ my $query = qq|
UPDATE defaults SET value = ?
WHERE setting_key = ?|;
- my $sth = $dbh->prepare($query);
- for (qw(revtrans closedto audittrail)){
-
- if ($form->{$_}){
- $val = 1;
- } else {
- $val = 0;
- }
- $sth->execute($val, $_);
- }
-
-
- if ($form->{removeaudittrail}) {
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ for (qw(revtrans closedto audittrail)) {
+
+ if ( $form->{$_} ) {
+ $val = 1;
+ }
+ else {
+ $val = 0;
+ }
+ $sth->execute( $val, $_ );
+ }
+
+ if ( $form->{removeaudittrail} ) {
+ $query = qq|
DELETE FROM audittrail
- WHERE transdate < | .
- $dbh->quote($form->{removeaudittrail});
+ WHERE transdate < | . $dbh->quote( $form->{removeaudittrail} );
- $dbh->do($query) || $form->dberror($query);
- }
+ $dbh->do($query) || $form->dberror($query);
+ }
- $dbh->commit;
+ $dbh->commit;
}
-
sub earningsaccounts {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my ($query, $sth, $ref);
+ my ( $query, $sth, $ref );
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- # get chart of accounts
- $query = qq|
+ # get chart of accounts
+ $query = qq|
SELECT accno,description
FROM chart
WHERE charttype = 'A'
AND category = 'Q'
ORDER BY accno|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
- $form->{chart} = "";
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+ $form->{chart} = "";
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{chart} }, $ref;
- }
-
- $sth->finish;
- $dbh->commit;
-}
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{chart} }, $ref;
+ }
+ $sth->finish;
+ $dbh->commit;
+}
sub post_yearend {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database, turn off AutoCommit
- my $dbh = $form->{dbh};
+ # connect to database, turn off AutoCommit
+ my $dbh = $form->{dbh};
- my $query;
- my @queryargs;
- my $uid = localtime;
- $uid .= "$$";
+ my $query;
+ my @queryargs;
+ my $uid = localtime;
+ $uid .= "$$";
- $query = qq|
+ $query = qq|
INSERT INTO gl (reference, employee_id)
VALUES (?, (SELECT id FROM employees
WHERE login = ?))|;
- $dbh->prepare($query)->execute($uid, $form->{login})
- || $form->dberror($query);
+ $dbh->prepare($query)->execute( $uid, $form->{login} )
+ || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT id
FROM gl
WHERE reference = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($uid);
- ($form->{id}) = $sth->fetchrow_array;
+ my $sth = $dbh->prepare($query);
+ $sth->execute($uid);
+ ( $form->{id} ) = $sth->fetchrow_array;
- $query = qq|
+ $query = qq|
UPDATE gl
SET reference = ?,
description = ?,
@@ -1794,13 +1803,15 @@ sub post_yearend {
department_id = 0
WHERE id = ?|;
- @queryargs = ($form->{reference}, $form->{description}, $form->{notes},
- $form->{transdate}, $form->{id});
- $dbh->prepare($query)->execute(@queryargs) || $form->dberror($query);
+ @queryargs = (
+ $form->{reference}, $form->{description}, $form->{notes},
+ $form->{transdate}, $form->{id}
+ );
+ $dbh->prepare($query)->execute(@queryargs) || $form->dberror($query);
- my $amount;
- my $accno;
- $query = qq|
+ my $amount;
+ my $accno;
+ $query = qq|
INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
source)
VALUES (?, (SELECT id
@@ -1808,67 +1819,69 @@ sub post_yearend {
WHERE accno = ?),
?, ?, ?)|;
+ # insert acc_trans transactions
+ for my $i ( 1 .. $form->{rowcount} ) {
- # insert acc_trans transactions
- for my $i (1 .. $form->{rowcount}) {
- # extract accno
- ($accno) = split(/--/, $form->{"accno_$i"});
- $amount = 0;
-
- if ($form->{"credit_$i"}) {
- $amount = $form->{"credit_$i"};
- }
+ # extract accno
+ ($accno) = split( /--/, $form->{"accno_$i"} );
+ $amount = 0;
- if ($form->{"debit_$i"}) {
- $amount = $form->{"debit_$i"} * -1;
- }
+ if ( $form->{"credit_$i"} ) {
+ $amount = $form->{"credit_$i"};
+ }
+ if ( $form->{"debit_$i"} ) {
+ $amount = $form->{"debit_$i"} * -1;
+ }
- # if there is an amount, add the record
- if ($amount) {
- my @args = ($form->{id}, $accno, $amount,
- $form->{transdate}, $form->{reference});
+ # if there is an amount, add the record
+ if ($amount) {
+ my @args = (
+ $form->{id}, $accno, $amount, $form->{transdate},
+ $form->{reference}
+ );
- $dbh->prepare($query)->execute(@args)
- || $form->dberror($query);
- }
- }
+ $dbh->prepare($query)->execute(@args)
+ || $form->dberror($query);
+ }
+ }
- $query = qq|
+ $query = qq|
INSERT INTO yearend (trans_id, transdate)
VALUES (?, ?)|;
- $dbh->prepare($query)->execute($form->{id}, $form->{transdate})
- || $form->dberror($query);
+ $dbh->prepare($query)->execute( $form->{id}, $form->{transdate} )
+ || $form->dberror($query);
- my %audittrail = (
- tablename => 'gl',
- reference => $form->{reference},
- formname => 'yearend',
- action => 'posted',
- id => $form->{id} );
+ my %audittrail = (
+ tablename => 'gl',
+ reference => $form->{reference},
+ formname => 'yearend',
+ action => 'posted',
+ id => $form->{id}
+ );
- $form->audittrail($dbh, "", \%audittrail);
+ $form->audittrail( $dbh, "", \%audittrail );
- # commit and redirect
- my $rc = $dbh->commit;
+ # commit and redirect
+ my $rc = $dbh->commit;
- $rc;
+ $rc;
}
-sub get_all_defaults{
- my ($self, $form) = @_;
- my $dbh = $form->{dbh};
- my $query = "select setting_key, value FROM defaults";
- $sth = $dbh->prepare($query);
- $sth->execute;
- while (($skey, $value) = $sth->fetchrow_array()){
- $form->{$skey} = $value;
- }
-
- $self->defaultaccounts(undef, $form);
- $dbh->commit;
+sub get_all_defaults {
+ my ( $self, $form ) = @_;
+ my $dbh = $form->{dbh};
+ my $query = "select setting_key, value FROM defaults";
+ $sth = $dbh->prepare($query);
+ $sth->execute;
+ while ( ( $skey, $value ) = $sth->fetchrow_array() ) {
+ $form->{$skey} = $value;
+ }
+
+ $self->defaultaccounts( undef, $form );
+ $dbh->commit;
}
1;
diff --git a/LedgerSMB/BP.pm b/LedgerSMB/BP.pm
index 6b9bf73d..f745f62d 100644
--- a/LedgerSMB/BP.pm
+++ b/LedgerSMB/BP.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
@@ -20,7 +20,7 @@
# Author: DWS Systems Inc.
# Web: http://www.sql-ledger.org
#
-# Contributors:
+# Contributors:
# This file has undergone whitespace cleanup.
#
@@ -33,38 +33,37 @@
package BP;
use LedgerSMB::Sysconfig;
-
-
sub get_vc {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my %arap = ( invoice => ['ar'],
- packing_list => ['oe', 'ar'],
- sales_order => ['oe'],
- work_order => ['oe'],
- pick_list => ['oe', 'ar'],
- purchase_order => ['oe'],
- bin_list => ['oe'],
- sales_quotation => ['oe'],
- request_quotation => ['oe'],
- timecard => ['jcitems'],
- check => ['ap'],
- );
-
- my $query = "";
- my $sth;
- my $n;
- my $count;
- my $item;
- my $sth;
-
- $item = $form->{dbh}->quote($item);
- foreach $item (@{ $arap{$form->{type}} }) {
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my %arap = (
+ invoice => ['ar'],
+ packing_list => [ 'oe', 'ar' ],
+ sales_order => ['oe'],
+ work_order => ['oe'],
+ pick_list => [ 'oe', 'ar' ],
+ purchase_order => ['oe'],
+ bin_list => ['oe'],
+ sales_quotation => ['oe'],
+ request_quotation => ['oe'],
+ timecard => ['jcitems'],
+ check => ['ap'],
+ );
+
+ my $query = "";
+ my $sth;
+ my $n;
+ my $count;
+ my $item;
+ my $sth;
+
+ $item = $form->{dbh}->quote($item);
+ foreach $item ( @{ $arap{ $form->{type} } } ) {
+ $query = qq|
SELECT count(*)
FROM (SELECT DISTINCT vc.id
FROM $form->{vc} vc, $item a, status s
@@ -73,21 +72,21 @@ sub get_vc {
AND s.formname = ?
AND s.spoolfile IS NOT NULL) AS total|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{type});
- ($n) = $sth->fetchrow_array;
- $count += $n;
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{type} );
+ ($n) = $sth->fetchrow_array;
+ $count += $n;
+ }
- # build selection list
- my $union = "";
- $query = "";
- my @queryargs = ();
+ # build selection list
+ my $union = "";
+ $query = "";
+ my @queryargs = ();
- if ($count < $myconfig->{vclimit}) {
+ if ( $count < $myconfig->{vclimit} ) {
- foreach $item (@{ $arap{$form->{type}} }) {
- $query .= qq|
+ foreach $item ( @{ $arap{ $form->{type} } } ) {
+ $query .= qq|
$union
SELECT DISTINCT vc.id, vc.name
FROM $item a
@@ -96,61 +95,63 @@ sub get_vc {
JOIN status s ON (s.trans_id = a.id)
WHERE s.formname = ?
AND s.spoolfile IS NOT NULL|;
- $union = "UNION";
- push @queryargs, $form->{type};
- }
+ $union = "UNION";
+ push @queryargs, $form->{type};
+ }
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{"all_$form->{vc}"} }, $ref;
- }
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{"all_$form->{vc}"} }, $ref;
+ }
- $sth->finish;
- }
- $dbh->{commit};
+ $sth->finish;
+ }
+ $dbh->{commit};
- $form->all_years($myconfig, $dbh);
+ $form->all_years( $myconfig, $dbh );
}
-
sub get_spoolfiles {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my $query;
- my $invnumber = "invnumber";
- my $item;
-
- my %arap = ( invoice => ['ar'],
- packing_list => ['oe', 'ar'],
- sales_order => ['oe'],
- work_order => ['oe'],
- pick_list => ['oe', 'ar'],
- purchase_order => ['oe'],
- bin_list => ['oe'],
- sales_quotation => ['oe'],
- request_quotation => ['oe'],
- timecard => ['jc'],
- check => ['ap'],
- );
-
- ($form->{transdatefrom}, $form->{transdateto}) = $form->from_to($form->{year}, $form->{month}, $form->{interval}) if $form->{year} && $form->{month};
-
- my @queryargs;
- if ($form->{type} eq 'timecard') {
- my $dateformat = $myconfig->{dateformat};
- $dateformat =~ s/yy/yyyy/;
- $dateformat =~ s/yyyyyy/yyyy/;
-
- $invnumber = 'id';
-
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my $query;
+ my $invnumber = "invnumber";
+ my $item;
+
+ my %arap = (
+ invoice => ['ar'],
+ packing_list => [ 'oe', 'ar' ],
+ sales_order => ['oe'],
+ work_order => ['oe'],
+ pick_list => [ 'oe', 'ar' ],
+ purchase_order => ['oe'],
+ bin_list => ['oe'],
+ sales_quotation => ['oe'],
+ request_quotation => ['oe'],
+ timecard => ['jc'],
+ check => ['ap'],
+ );
+
+ ( $form->{transdatefrom}, $form->{transdateto} ) =
+ $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
+ if $form->{year} && $form->{month};
+
+ my @queryargs;
+ if ( $form->{type} eq 'timecard' ) {
+ my $dateformat = $myconfig->{dateformat};
+ $dateformat =~ s/yy/yyyy/;
+ $dateformat =~ s/yyyyyy/yyyy/;
+
+ $invnumber = 'id';
+
+ $query = qq|
SELECT j.id, e.name, j.id AS invnumber,
to_char(j.checkedin, ?) AS transdate,
'' AS ordnumber, '' AS quonumber, '0' AS invoice,
@@ -160,42 +161,44 @@ sub get_spoolfiles {
JOIN status s ON (s.trans_id = j.id)
WHERE s.formname = ?
AND s.spoolfile IS NOT NULL|;
- @queryargs = ($dateformat, $form->{type});
-
- if ($form->{"$form->{vc}_id"}) {
- $query .= qq| AND j.$form->{vc}_id = ?|;
- push(@queryargs, $form->{"$form->{vc}_id"});
- } else {
-
- if ($form->{$form->{vc}}) {
- $item = $form->like(lc $form->{$form->{vc}});
- $query .= " AND lower(e.name) LIKE ?";
- push(@queryargs, $item);
- }
- }
-
- if ($form->{transdatefrom}){
- $query .= " AND j.checkedin >= ?";
- push (@queryargs, $form->{transdatefrom});
- }
- if ($form->{transdateto}){
- $query .= " AND j.checkedin <= ?";
- push (@queryargs, $form->{transdateto});
- }
- } else {
- @queryargs = ();
-
- foreach $item (@{ $arap{$form->{type}} }) {
-
- $invoice = "a.invoice";
- $invnumber = "invnumber";
-
- if ($item eq 'oe') {
- $invnumber = "ordnumber";
- $invoice = "'0'";
- }
-
- $query .= qq|
+ @queryargs = ( $dateformat, $form->{type} );
+
+ if ( $form->{"$form->{vc}_id"} ) {
+ $query .= qq| AND j.$form->{vc}_id = ?|;
+ push( @queryargs, $form->{"$form->{vc}_id"} );
+ }
+ else {
+
+ if ( $form->{ $form->{vc} } ) {
+ $item = $form->like( lc $form->{ $form->{vc} } );
+ $query .= " AND lower(e.name) LIKE ?";
+ push( @queryargs, $item );
+ }
+ }
+
+ if ( $form->{transdatefrom} ) {
+ $query .= " AND j.checkedin >= ?";
+ push( @queryargs, $form->{transdatefrom} );
+ }
+ if ( $form->{transdateto} ) {
+ $query .= " AND j.checkedin <= ?";
+ push( @queryargs, $form->{transdateto} );
+ }
+ }
+ else {
+ @queryargs = ();
+
+ foreach $item ( @{ $arap{ $form->{type} } } ) {
+
+ $invoice = "a.invoice";
+ $invnumber = "invnumber";
+
+ if ( $item eq 'oe' ) {
+ $invnumber = "ordnumber";
+ $invoice = "'0'";
+ }
+
+ $query .= qq|
$union
SELECT a.id, vc.name, a.$invnumber AS invnumber, a.transdate,
a.ordnumber, a.quonumber, $invoice AS invoice,
@@ -206,174 +209,175 @@ sub get_spoolfiles {
AND s.formname = ?
AND a.$form->{vc}_id = vc.id|;
- push (@queryargs, $form->{type});
- if ($form->{"$form->{vc}_id"}) {
- $query .= qq| AND a.$form->{vc}_id = $form->{"$form->{vc}_id"}|;
- } else {
-
- if ($form->{$form->{vc}} ne "") {
- $item = $form->like(
- lc $form->{$form->{vc}});
- $query .= " AND lower(vc.name) LIKE ?";
- push @queryargs, $item;
- }
- }
-
- if ($form->{invnumber} ne "") {
- $item = $form->like(lc $form->{invnumber});
- $query .= " AND lower(a.invnumber) LIKE ?";
- push @queryargs, $item;
- }
-
- if ($form->{ordnumber} ne "") {
- $item = $form->like(lc $form->{ordnumber});
- $query .= " AND lower(a.ordnumber) LIKE ?";
- push @queryargs, $item;
- }
-
- if ($form->{quonumber} ne "") {
- $item = $form->like(lc $form->{quonumber});
- $query .= " AND lower(a.quonumber) LIKE ?";
- push @queryargs, $item;
- }
-
- if ($form->{transdatefrom}){
- $query .= " AND a.transdate >= ?";
- push @queryargs, $form->{transdatefrom};
- }
- if ($form->{transdateto}){
- $query .= " AND a.transdate <= ?";
- push @queryargs, $form->{transdateto};
- }
- $union = "UNION";
-
- }
- }
-
- my %ordinal = ( 'name' => 2,
- 'invnumber' => 3,
- 'transdate' => 4,
- 'ordnumber' => 5,
- 'quonumber' => 6,);
-
- my @a = ();
- push @a, ("transdate", "$invnumber", "name");
- my $sortorder = $form->sort_order(\@a, \%ordinal);
- $query .= " ORDER by $sortorder";
-
- my $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{SPOOL} }, $ref;
- }
-
- $sth->finish;
- $dbh->commit;
+ push( @queryargs, $form->{type} );
+ if ( $form->{"$form->{vc}_id"} ) {
+ $query .= qq| AND a.$form->{vc}_id = $form->{"$form->{vc}_id"}|;
+ }
+ else {
+
+ if ( $form->{ $form->{vc} } ne "" ) {
+ $item = $form->like( lc $form->{ $form->{vc} } );
+ $query .= " AND lower(vc.name) LIKE ?";
+ push @queryargs, $item;
+ }
+ }
+
+ if ( $form->{invnumber} ne "" ) {
+ $item = $form->like( lc $form->{invnumber} );
+ $query .= " AND lower(a.invnumber) LIKE ?";
+ push @queryargs, $item;
+ }
+
+ if ( $form->{ordnumber} ne "" ) {
+ $item = $form->like( lc $form->{ordnumber} );
+ $query .= " AND lower(a.ordnumber) LIKE ?";
+ push @queryargs, $item;
+ }
+
+ if ( $form->{quonumber} ne "" ) {
+ $item = $form->like( lc $form->{quonumber} );
+ $query .= " AND lower(a.quonumber) LIKE ?";
+ push @queryargs, $item;
+ }
+
+ if ( $form->{transdatefrom} ) {
+ $query .= " AND a.transdate >= ?";
+ push @queryargs, $form->{transdatefrom};
+ }
+ if ( $form->{transdateto} ) {
+ $query .= " AND a.transdate <= ?";
+ push @queryargs, $form->{transdateto};
+ }
+ $union = "UNION";
+
+ }
+ }
+
+ my %ordinal = (
+ 'name' => 2,
+ 'invnumber' => 3,
+ 'transdate' => 4,
+ 'ordnumber' => 5,
+ 'quonumber' => 6,
+ );
+
+ my @a = ();
+ push @a, ( "transdate", "$invnumber", "name" );
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+ $query .= " ORDER by $sortorder";
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $form->dberror($query);
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{SPOOL} }, $ref;
+ }
+
+ $sth->finish;
+ $dbh->commit;
}
-
sub delete_spool {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database, turn AutoCommit off
- my $dbh = $form->{dbh};
+ # connect to database, turn AutoCommit off
+ my $dbh = $form->{dbh};
- my $query;
- my %audittrail;
+ my $query;
+ my %audittrail;
- $query = qq|
+ $query = qq|
UPDATE status
SET spoolfile = NULL
WHERE spoolfile = ?|;
- my $sth = $dbh->prepare($query) || $form->dberror($query);
+ my $sth = $dbh->prepare($query) || $form->dberror($query);
- foreach my $i (1 .. $form->{rowcount}) {
+ foreach my $i ( 1 .. $form->{rowcount} ) {
- if ($form->{"checked_$i"}) {
- $sth->execute($form->{"spoolfile_$i"}) || $form->dberror($query);
- $sth->finish;
+ if ( $form->{"checked_$i"} ) {
+ $sth->execute( $form->{"spoolfile_$i"} ) || $form->dberror($query);
+ $sth->finish;
- %audittrail = (
- tablename => $form->{module},
- reference => $form->{"reference_$i"},
- formname => $form->{type},
- action => 'dequeued',
- id => $form->{"id_$i"} );
+ %audittrail = (
+ tablename => $form->{module},
+ reference => $form->{"reference_$i"},
+ formname => $form->{type},
+ action => 'dequeued',
+ id => $form->{"id_$i"}
+ );
- $form->audittrail($dbh, "", \%audittrail);
- }
- }
+ $form->audittrail( $dbh, "", \%audittrail );
+ }
+ }
- # commit
- my $rc = $dbh->commit;
+ # commit
+ my $rc = $dbh->commit;
- if ($rc) {
- foreach my $i (1 .. $form->{rowcount}) {
- $_ = qq|${LedgerSMB::Sysconfig::spool}/$form->{"spoolfile_$i"}|;
- if ($form->{"checked_$i"}) {
- unlink;
- }
- }
- }
+ if ($rc) {
+ foreach my $i ( 1 .. $form->{rowcount} ) {
+ $_ = qq|${LedgerSMB::Sysconfig::spool}/$form->{"spoolfile_$i"}|;
+ if ( $form->{"checked_$i"} ) {
+ unlink;
+ }
+ }
+ }
- $rc;
+ $rc;
}
-
sub print_spool {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my %audittrail;
+ my %audittrail;
- my $query = qq|UPDATE status
+ my $query = qq|UPDATE status
SET printed = '1'
WHERE spoolfile = ?|;
- my $sth = $dbh->prepare($query) || $form->dberror($query);
-
- foreach my $i (1 .. $form->{rowcount}) {
+ my $sth = $dbh->prepare($query) || $form->dberror($query);
- if ($form->{"checked_$i"}) {
- open(OUT, '>', $form->{OUT}) or $form->error("$form->{OUT} : $!");
- binmode(OUT);
+ foreach my $i ( 1 .. $form->{rowcount} ) {
- $spoolfile = qq|$spool/$form->{"spoolfile_$i"}|;
+ if ( $form->{"checked_$i"} ) {
+ open( OUT, '>', $form->{OUT} ) or $form->error("$form->{OUT} : $!");
+ binmode(OUT);
- # send file to printer
- open(IN, '<', $spoolfile) or $form->error("$spoolfile : $!");
- binmode(IN);
+ $spoolfile = qq|$spool/$form->{"spoolfile_$i"}|;
- while (<IN>) {
- print OUT $_;
- }
+ # send file to printer
+ open( IN, '<', $spoolfile ) or $form->error("$spoolfile : $!");
+ binmode(IN);
- close(IN);
- close(OUT);
+ while (<IN>) {
+ print OUT $_;
+ }
- $sth->execute($form->{"spoolfile_$i"}) || $form->dberror($query);
- $sth->finish;
+ close(IN);
+ close(OUT);
- %audittrail = (
- tablename => $form->{module},
- reference => $form->{"reference_$i"},
- formname => $form->{type},
- action => 'printed',
- id => $form->{"id_$i"} );
+ $sth->execute( $form->{"spoolfile_$i"} ) || $form->dberror($query);
+ $sth->finish;
- $form->audittrail($dbh, "", \%audittrail);
+ %audittrail = (
+ tablename => $form->{module},
+ reference => $form->{"reference_$i"},
+ formname => $form->{type},
+ action => 'printed',
+ id => $form->{"id_$i"}
+ );
- $dbh->commit;
- }
- }
+ $form->audittrail( $dbh, "", \%audittrail );
+ $dbh->commit;
+ }
+ }
}
diff --git a/LedgerSMB/CA.pm b/LedgerSMB/CA.pm
index 2c4ff105..b182e6d0 100644
--- a/LedgerSMB/CA.pm
+++ b/LedgerSMB/CA.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
@@ -32,199 +32,202 @@
#
#======================================================================
-
package CA;
-
sub all_accounts {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $amount = ();
- # connect to database
- my $dbh = $form->{dbh};
+ my $amount = ();
- my $query = qq|
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my $query = qq|
SELECT accno, SUM(acc_trans.amount) AS amount
FROM chart, acc_trans
WHERE chart.id = acc_trans.chart_id
GROUP BY accno|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $amount{ $ref->{accno} } = $ref->{amount};
+ }
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $amount{$ref->{accno}} = $ref->{amount}
- }
-
- $sth->finish;
+ $sth->finish;
- $query = qq|
+ $query = qq|
SELECT accno, description
FROM gifi|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- my $gifi = ();
+ my $gifi = ();
- while (my ($accno, $description) = $sth->fetchrow_array) {
- $gifi{$accno} = $description;
- }
+ while ( my ( $accno, $description ) = $sth->fetchrow_array ) {
+ $gifi{$accno} = $description;
+ }
- $sth->finish;
+ $sth->finish;
- $query = qq|
+ $query = qq|
SELECT c.id, c.accno, c.description, c.charttype,
c.gifi_accno, c.category, c.link
FROM chart c
ORDER BY accno|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ca = $sth->fetchrow_hashref(NAME_lc)) {
- $ca->{amount} = $amount{$ca->{accno}};
- $ca->{gifi_description} = $gifi{$ca->{gifi_accno}};
+ while ( my $ca = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ca->{amount} = $amount{ $ca->{accno} };
+ $ca->{gifi_description} = $gifi{ $ca->{gifi_accno} };
- if ($ca->{amount} < 0) {
- $ca->{debit} = $ca->{amount} * -1;
- } else {
- $ca->{credit} = $ca->{amount};
- }
+ if ( $ca->{amount} < 0 ) {
+ $ca->{debit} = $ca->{amount} * -1;
+ }
+ else {
+ $ca->{credit} = $ca->{amount};
+ }
- push @{ $form->{CA} }, $ca;
- }
+ push @{ $form->{CA} }, $ca;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub all_transactions {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- # get chart_id
- my $query = qq|
+ # get chart_id
+ my $query = qq|
SELECT id
FROM chart
WHERE accno = ?|;
- my $accno = $form->{accno};
+ my $accno = $form->{accno};
- if ($form->{accounttype} eq 'gifi') {
- $query = qq|
+ if ( $form->{accounttype} eq 'gifi' ) {
+ $query = qq|
SELECT id
FROM chart
WHERE gifi_accno = ?|;
- $accno = $form->{gifi_accno};
- }
-
- my $sth = $dbh->prepare($query);
- $sth->execute($accno) || $form->dberror($query);
-
- my @id = ();
-
- while (my ($id) = $sth->fetchrow_array) {
- push @id, $id;
- }
-
- $sth->finish;
-
- my $fromdate_where;
- my $todate_where;
-
- ($form->{fromdate}, $form->{todate}) = $form->from_to($form->{year}, $form->{month}, $form->{interval}) if $form->{year} && $form->{month};
-
- my $fdate;
- if ($form->{fromdate}) {
- $fromdate_where = qq| AND ac.transdate >= ? |;
- $fdate = $form->{fromdate};
- }
- my $tdate;
- if ($form->{todate}) {
- $todate_where .= qq| AND ac.transdate <= ? |;
- $tdate = $form->{todate};
- }
-
-
- my $false = 'FALSE';
-
- # Oracle workaround, use ordinal positions
- my %ordinal = ( transdate => 4,
- reference => 2,
- description => 3 );
-
- my @a = qw(transdate reference description);
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
- my $null;
- my $department_id;
- my $dpt_where;
- my $dpt_join;
- my $union;
-
- ($null, $department_id) = split /--/, $form->{department};
-
- my $d_id;
- if ($department_id) {
- $dpt_join = qq| JOIN department t ON (t.id = a.department_id) |;
- $dpt_where = qq| AND t.id = ? |;
- $d_id = $department_id;
- }
-
-
- my $project;
- my $project_id;
- my $p_id;
- if ($form->{projectnumber}) {
- ($null, $project_id) = split /--/, $form->{projectnumber};
- $project = qq| AND ac.project_id = ? |;
- $p_id = $project_id;
- }
-
- @queryargs = ();
-
- if ($form->{accno} || $form->{gifi_accno}) {
- # get category for account
- $query = qq|
+ $accno = $form->{gifi_accno};
+ }
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute($accno) || $form->dberror($query);
+
+ my @id = ();
+
+ while ( my ($id) = $sth->fetchrow_array ) {
+ push @id, $id;
+ }
+
+ $sth->finish;
+
+ my $fromdate_where;
+ my $todate_where;
+
+ ( $form->{fromdate}, $form->{todate} ) =
+ $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
+ if $form->{year} && $form->{month};
+
+ my $fdate;
+ if ( $form->{fromdate} ) {
+ $fromdate_where = qq| AND ac.transdate >= ? |;
+ $fdate = $form->{fromdate};
+ }
+ my $tdate;
+ if ( $form->{todate} ) {
+ $todate_where .= qq| AND ac.transdate <= ? |;
+ $tdate = $form->{todate};
+ }
+
+ my $false = 'FALSE';
+
+ # Oracle workaround, use ordinal positions
+ my %ordinal = (
+ transdate => 4,
+ reference => 2,
+ description => 3
+ );
+
+ my @a = qw(transdate reference description);
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ my $null;
+ my $department_id;
+ my $dpt_where;
+ my $dpt_join;
+ my $union;
+
+ ( $null, $department_id ) = split /--/, $form->{department};
+
+ my $d_id;
+ if ($department_id) {
+ $dpt_join = qq| JOIN department t ON (t.id = a.department_id) |;
+ $dpt_where = qq| AND t.id = ? |;
+ $d_id = $department_id;
+ }
+
+ my $project;
+ my $project_id;
+ my $p_id;
+ if ( $form->{projectnumber} ) {
+ ( $null, $project_id ) = split /--/, $form->{projectnumber};
+ $project = qq| AND ac.project_id = ? |;
+ $p_id = $project_id;
+ }
+
+ @queryargs = ();
+
+ if ( $form->{accno} || $form->{gifi_accno} ) {
+
+ # get category for account
+ $query = qq|
SELECT description, category, link, contra
FROM chart
WHERE accno = ?|;
- $accno = $form->{accno};
- if ($form->{accounttype} eq 'gifi') {
- $query = qq|
+ $accno = $form->{accno};
+ if ( $form->{accounttype} eq 'gifi' ) {
+ $query = qq|
SELECT description, category, link, contra
FROM chart
WHERE gifi_accno = ?
AND charttype = 'A'|;
- $accno = $form->{gifi_accno};
- }
+ $accno = $form->{gifi_accno};
+ }
- $sth = $dbh->prepare($query);
- $sth->execute($accno);
- ($form->{description}, $form->{category}, $form->{link},
- $form->{contra})
- = $sth->fetchrow_array;
+ $sth = $dbh->prepare($query);
+ $sth->execute($accno);
+ (
+ $form->{description}, $form->{category},
+ $form->{link}, $form->{contra}
+ ) = $sth->fetchrow_array;
- if ($form->{fromdate}) {
+ if ( $form->{fromdate} ) {
- if ($department_id) {
+ if ($department_id) {
- # get beginning balance
- $query = "";
- $union = "";
+ # get beginning balance
+ $query = "";
+ $union = "";
- for (qw(ar ap gl)) {
+ for (qw(ar ap gl)) {
- if ($form->{accounttype} eq 'gifi') {
- $query = qq|
+ if ( $form->{accounttype} eq 'gifi' ) {
+ $query = qq|
$union
SELECT SUM(ac.amount)
FROM acc_trans ac
@@ -244,16 +247,15 @@ sub all_transactions {
= ?
$project |;
- push @queryargs,
- $form->{gifi_accno},
- $form->{fromdate},
- $form->{department_id};
- if ($p_id){
- push @queryargs, $p_id;
- }
- } else {
+ push @queryargs, $form->{gifi_accno}, $form->{fromdate},
+ $form->{department_id};
+ if ($p_id) {
+ push @queryargs, $p_id;
+ }
+ }
+ else {
- $query .= qq|
+ $query .= qq|
$union
SELECT SUM(ac.amount)
FROM acc_trans ac
@@ -270,21 +272,21 @@ sub all_transactions {
a.department_id
= ?
$project |;
- push @queryargs, $form->{accno},
- $form->{fromdate},
- $department_id;
- if ($p_id){
- push @queryargs, $p_id;
- }
- }
+ push @queryargs, $form->{accno}, $form->{fromdate},
+ $department_id;
+ if ($p_id) {
+ push @queryargs, $p_id;
+ }
+ }
- $union = qq| UNION ALL |;
- }
+ $union = qq| UNION ALL |;
+ }
- } else {
+ }
+ else {
- if ($form->{accounttype} eq 'gifi') {
- $query = qq|
+ if ( $form->{accounttype} eq 'gifi' ) {
+ $query = qq|
SELECT SUM(ac.amount)
FROM acc_trans ac
JOIN chart c ON
@@ -292,13 +294,13 @@ sub all_transactions {
WHERE c.gifi_accno = ?
AND ac.transdate < ?
$project |;
- @queryargs = ($form->{gifi_accno},
- $form->{fromdate});
- if ($p_id){
- push @query_ags, $p_id;
- }
- } else {
- $query = qq|
+ @queryargs = ( $form->{gifi_accno}, $form->{fromdate} );
+ if ($p_id) {
+ push @query_ags, $p_id;
+ }
+ }
+ else {
+ $query = qq|
SELECT SUM(ac.amount)
FROM acc_trans ac
JOIN chart c
@@ -306,29 +308,28 @@ sub all_transactions {
WHERE c.accno = ?
AND ac.transdate < ?
$project |;
- @queryargs = ($form->{accno},
- $form->{fromdate});
- if ($p_id){
- push @queryargs, $p_id;
- }
- }
- }
-
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs);
- ($form->{balance}) = $sth->fetchrow_array;
- $sth->finish;
- @queryargs = ();
- }
- }
-
- $query = "";
- $union = "";
-
- foreach my $id (@id) {
-
- # get all transactions
- $query .= qq|
+ @queryargs = ( $form->{accno}, $form->{fromdate} );
+ if ($p_id) {
+ push @queryargs, $p_id;
+ }
+ }
+ }
+
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs);
+ ( $form->{balance} ) = $sth->fetchrow_array;
+ $sth->finish;
+ @queryargs = ();
+ }
+ }
+
+ $query = "";
+ $union = "";
+
+ foreach my $id (@id) {
+
+ # get all transactions
+ $query .= qq|
$union
SELECT a.id, a.reference, a.description, ac.transdate,
$false AS invoice, ac.amount, 'gl' as module,
@@ -341,23 +342,23 @@ sub all_transactions {
$todate_where
$dpt_where
$project|;
- if ($d_id){
- push @queryargs, $d_id;
- }
- push @queryargs, $id;
- if ($fdate){
- push @queryargs, $fdate;
- }
- if ($tdate){
- push @queryargs, $tdate;
- }
- if ($d_id){
- push @queryargs, $d_id;
- }
- if ($p_id){
- push @queryargs, $p_id;
- }
- $query .= qq|
+ if ($d_id) {
+ push @queryargs, $d_id;
+ }
+ push @queryargs, $id;
+ if ($fdate) {
+ push @queryargs, $fdate;
+ }
+ if ($tdate) {
+ push @queryargs, $tdate;
+ }
+ if ($d_id) {
+ push @queryargs, $d_id;
+ }
+ if ($p_id) {
+ push @queryargs, $p_id;
+ }
+ $query .= qq|
UNION ALL
@@ -374,24 +375,24 @@ sub all_transactions {
$dpt_where
$project|;
- if ($d_id){
- push @queryargs, $d_id;
- }
- push @queryargs, $id;
- if ($fdate){
- push @queryargs, $fdate;
- }
- if ($tdate){
- push @queryargs, $tdate;
- }
- if ($d_id){
- push @queryargs, $d_id;
- }
- if ($p_id){
- push @queryargs, $p_id;
- }
-
- $query .= qq|
+ if ($d_id) {
+ push @queryargs, $d_id;
+ }
+ push @queryargs, $id;
+ if ($fdate) {
+ push @queryargs, $fdate;
+ }
+ if ($tdate) {
+ push @queryargs, $tdate;
+ }
+ if ($d_id) {
+ push @queryargs, $d_id;
+ }
+ if ($p_id) {
+ push @queryargs, $p_id;
+ }
+
+ $query .= qq|
UNION ALL
SELECT a.id, a.invnumber, v.name, ac.transdate,
@@ -407,112 +408,113 @@ sub all_transactions {
$dpt_where
$project |;
- if ($d_id){
- push @queryargs, $d_id;
- }
- push @queryargs, $id;
- if ($fdate){
- push @queryargs, $fdate;
- }
- if ($tdate){
- push @queryargs, $tdate;
- }
- if ($d_id){
- push @queryargs, $d_id;
- }
- if ($p_id){
- push @queryargs, $p_id;
- }
- $union = qq| UNION ALL |;
- }
-
- $query .= qq| ORDER BY $sortorder |;
-
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $form->dberror($query);
-
- $query = qq|SELECT c.id, c.accno
+ if ($d_id) {
+ push @queryargs, $d_id;
+ }
+ push @queryargs, $id;
+ if ($fdate) {
+ push @queryargs, $fdate;
+ }
+ if ($tdate) {
+ push @queryargs, $tdate;
+ }
+ if ($d_id) {
+ push @queryargs, $d_id;
+ }
+ if ($p_id) {
+ push @queryargs, $p_id;
+ }
+ $union = qq| UNION ALL |;
+ }
+
+ $query .= qq| ORDER BY $sortorder |;
+
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $form->dberror($query);
+
+ $query = qq|SELECT c.id, c.accno
FROM chart c
JOIN acc_trans ac ON (ac.chart_id = c.id)
WHERE ac.amount >= 0
AND (c.link = 'AR' OR c.link = 'AP')
AND ac.trans_id = ?|;
- my $dr = $dbh->prepare($query) || $form->dberror($query);
+ my $dr = $dbh->prepare($query) || $form->dberror($query);
- $query = qq|SELECT c.id, c.accno
+ $query = qq|SELECT c.id, c.accno
FROM chart c
JOIN acc_trans ac ON (ac.chart_id = c.id)
WHERE ac.amount < 0
AND (c.link = 'AR' OR c.link = 'AP')
AND ac.trans_id = ?|;
- my $cr = $dbh->prepare($query) || $form->dberror($query);
+ my $cr = $dbh->prepare($query) || $form->dberror($query);
- my $accno;
- my $chart_id;
- my %accno;
+ my $accno;
+ my $chart_id;
+ my %accno;
- while (my $ca = $sth->fetchrow_hashref(NAME_lc)) {
+ while ( my $ca = $sth->fetchrow_hashref(NAME_lc) ) {
- # gl
- if ($ca->{module} eq "gl") {
- $ca->{module} = "gl";
- }
+ # gl
+ if ( $ca->{module} eq "gl" ) {
+ $ca->{module} = "gl";
+ }
- # ap
- if ($ca->{module} eq "ap") {
- $ca->{module} = ($ca->{invoice}) ? 'ir' : 'ap';
- $ca->{module} = 'ps' if $ca->{till};
- }
+ # ap
+ if ( $ca->{module} eq "ap" ) {
+ $ca->{module} = ( $ca->{invoice} ) ? 'ir' : 'ap';
+ $ca->{module} = 'ps' if $ca->{till};
+ }
- # ar
- if ($ca->{module} eq "ar") {
- $ca->{module} = ($ca->{invoice}) ? 'is' : 'ar';
- $ca->{module} = 'ps' if $ca->{till};
- }
+ # ar
+ if ( $ca->{module} eq "ar" ) {
+ $ca->{module} = ( $ca->{invoice} ) ? 'is' : 'ar';
+ $ca->{module} = 'ps' if $ca->{till};
+ }
- if ($ca->{amount}) {
- %accno = ();
+ if ( $ca->{amount} ) {
+ %accno = ();
- if ($ca->{amount} < 0) {
- $ca->{debit} = $ca->{amount} * -1;
- $ca->{credit} = 0;
- $dr->execute($ca->{id});
- $ca->{accno} = ();
+ if ( $ca->{amount} < 0 ) {
+ $ca->{debit} = $ca->{amount} * -1;
+ $ca->{credit} = 0;
+ $dr->execute( $ca->{id} );
+ $ca->{accno} = ();
- while (($chart_id, $accno) = $dr->fetchrow_array) {
- $accno{$accno} = 1 if $chart_id ne $ca->{chart_id};
- }
+ while ( ( $chart_id, $accno ) = $dr->fetchrow_array ) {
+ $accno{$accno} = 1 if $chart_id ne $ca->{chart_id};
+ }
- $dr->finish;
+ $dr->finish;
- for (sort keys %accno) { push @{ $ca->{accno} }, "$_ " }
+ for ( sort keys %accno ) { push @{ $ca->{accno} }, "$_ " }
- } else {
+ }
+ else {
- $ca->{credit} = $ca->{amount};
- $ca->{debit} = 0;
+ $ca->{credit} = $ca->{amount};
+ $ca->{debit} = 0;
- $cr->execute($ca->{id});
- $ca->{accno} = ();
+ $cr->execute( $ca->{id} );
+ $ca->{accno} = ();
- while (($chart_id, $accno) = $cr->fetchrow_array) {
- $accno{$accno} = 1 if $chart_id ne $ca->{chart_id};
- }
+ while ( ( $chart_id, $accno ) = $cr->fetchrow_array ) {
+ $accno{$accno} = 1 if $chart_id ne $ca->{chart_id};
+ }
- $cr->finish;
+ $cr->finish;
- for (keys %accno) { push @{ $ca->{accno} }, "$_ " }
+ for ( keys %accno ) { push @{ $ca->{accno} }, "$_ " }
- }
+ }
- push @{ $form->{CA} }, $ca;
- }
- }
+ push @{ $form->{CA} }, $ca;
+ }
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
diff --git a/LedgerSMB/CP.pm b/LedgerSMB/CP.pm
index bfd18585..7c2d3b45 100644
--- a/LedgerSMB/CP.pm
+++ b/LedgerSMB/CP.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -37,353 +37,354 @@
package CP;
use LedgerSMB::Sysconfig;
-
-
sub new {
- my ($type, $countrycode) = @_;
+ my ( $type, $countrycode ) = @_;
- $self = {};
+ $self = {};
- use LedgerSMB::Num2text;
- use LedgerSMB::Locale;
- $self->{'locale'} = LedgerSMB::Locale->get_handle($countrycode);
+ use LedgerSMB::Num2text;
+ use LedgerSMB::Locale;
+ $self->{'locale'} = LedgerSMB::Locale->get_handle($countrycode);
- bless $self, $type;
+ bless $self, $type;
}
-
sub paymentaccounts {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
+ my $dbh = $form->{dbh};
- my $query = qq|SELECT accno, description, link
+ my $query = qq|SELECT accno, description, link
FROM chart
WHERE link LIKE ?
ORDER BY accno|;
- my $sth = $dbh->prepare($query);
- $sth->execute("%$form->{ARAP}%") || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute("%$form->{ARAP}%") || $form->dberror($query);
- $form->{PR}{$form->{ARAP}} = ();
- $form->{PR}{"$form->{ARAP}_paid"} = ();
+ $form->{PR}{ $form->{ARAP} } = ();
+ $form->{PR}{"$form->{ARAP}_paid"} = ();
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
- foreach my $item (split /:/, $ref->{link}) {
+ foreach my $item ( split /:/, $ref->{link} ) {
- if ($item eq $form->{ARAP}) {
- push @{ $form->{PR}{$form->{ARAP}} }, $ref;
- }
+ if ( $item eq $form->{ARAP} ) {
+ push @{ $form->{PR}{ $form->{ARAP} } }, $ref;
+ }
- if ($item eq "$form->{ARAP}_paid") {
- push @{ $form->{PR}{"$form->{ARAP}_paid"} }, $ref;
- }
- }
- }
+ if ( $item eq "$form->{ARAP}_paid" ) {
+ push @{ $form->{PR}{"$form->{ARAP}_paid"} }, $ref;
+ }
+ }
+ }
- $sth->finish;
+ $sth->finish;
- # get currencies and closedto
- $query = qq|
+ # get currencies and closedto
+ $query = qq|
SELECT value, (SELECT value FROM defaults
WHERE setting_key = 'closedto'),
current_date
FROM defaults
WHERE setting_key = 'curr'|;
- ($form->{currencies}, $form->{closedto}, $form->{datepaid}) = $dbh->selectrow_array($query);
+ ( $form->{currencies}, $form->{closedto}, $form->{datepaid} ) =
+ $dbh->selectrow_array($query);
- if ($form->{payment} eq 'payments') {
- # get language codes
- $query = qq|SELECT *
+ if ( $form->{payment} eq 'payments' ) {
+
+ # get language codes
+ $query = qq|SELECT *
FROM language
ORDER BY 2|;
- $sth = $dbh->prepare($query);
- $sth->execute || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
- $form->{all_language} = ();
+ $form->{all_language} = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_language} }, $ref;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_language} }, $ref;
+ }
- $sth->finish;
+ $sth->finish;
- $form->all_departments($myconfig, $dbh, $form->{vc});
- }
+ $form->all_departments( $myconfig, $dbh, $form->{vc} );
+ }
- $dbh->commit;
+ $dbh->commit;
}
-
sub get_openvc {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
+ my $dbh = $form->{dbh};
- my $arap = ($form->{vc} eq 'customer') ? 'ar' : 'ap';
- my $query = qq|SELECT count(*)
+ my $arap = ( $form->{vc} eq 'customer' ) ? 'ar' : 'ap';
+ my $query = qq|SELECT count(*)
FROM $form->{vc} ct, $arap a
WHERE a.$form->{vc}_id = ct.id
AND a.amount != a.paid|;
- my ($count) = $dbh->selectrow_array($query);
+ my ($count) = $dbh->selectrow_array($query);
- my $sth;
- my $ref;
- my $i = 0;
+ my $sth;
+ my $ref;
+ my $i = 0;
- my $where = qq|WHERE a.$form->{vc}_id = ct.id
+ my $where = qq|WHERE a.$form->{vc}_id = ct.id
AND a.amount != a.paid|;
- if ($form->{$form->{vc}}) {
- my $var = $dbh->quote($form->like(lc $form->{$form->{vc}}));
- $where .= " AND lower(name) LIKE $var";
- }
+ if ( $form->{ $form->{vc} } ) {
+ my $var = $dbh->quote( $form->like( lc $form->{ $form->{vc} } ) );
+ $where .= " AND lower(name) LIKE $var";
+ }
- # build selection list
- $query = qq|SELECT DISTINCT ct.*
+ # build selection list
+ $query = qq|SELECT DISTINCT ct.*
FROM $form->{vc} ct, $arap a
$where
ORDER BY name|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $i++;
- push @{ $form->{name_list} }, $ref;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $i++;
+ push @{ $form->{name_list} }, $ref;
+ }
- $sth->finish;
+ $sth->finish;
- $form->all_departments($myconfig, $dbh, $form->{vc});
+ $form->all_departments( $myconfig, $dbh, $form->{vc} );
- # get language codes
- $query = qq|SELECT *
+ # get language codes
+ $query = qq|SELECT *
FROM language
ORDER BY 2|;
- $sth = $dbh->prepare($query);
- $sth->execute || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
- $form->{all_language} = ();
+ $form->{all_language} = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_language} }, $ref;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_language} }, $ref;
+ }
- $sth->finish;
+ $sth->finish;
- # get currency for first name
- if (@{ $form->{name_list} }) {
+ # get currency for first name
+ if ( @{ $form->{name_list} } ) {
- # Chris T: I don't like this but it seems safe injection-wise
- # Leaving it so we can change it when we go to a new system
- $query = qq|SELECT curr
+ # Chris T: I don't like this but it seems safe injection-wise
+ # Leaving it so we can change it when we go to a new system
+ $query = qq|SELECT curr
FROM $form->{vc}
WHERE id = $form->{name_list}->[0]->{id}|;
- ($form->{currency}) = $dbh->selectrow_array($query);
- $form->{currency} ||= $form->{defaultcurrency};
- }
+ ( $form->{currency} ) = $dbh->selectrow_array($query);
+ $form->{currency} ||= $form->{defaultcurrency};
+ }
- $dbh->commit;
+ $dbh->commit;
- $i;
+ $i;
}
-
sub get_openinvoices {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $null;
- my $department_id;
+ my $null;
+ my $department_id;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- $vc_id = $dbh->quote($form->{"$form->{vc}_id"});
- my $where = qq|WHERE a.$form->{vc}_id = $vc_id
+ $vc_id = $dbh->quote( $form->{"$form->{vc}_id"} );
+ my $where = qq|WHERE a.$form->{vc}_id = $vc_id
AND a.amount != a.paid|;
- $curr = $dbh->quote($form->{currency});
- $where .= qq| AND a.curr = $curr| if $form->{currency};
+ $curr = $dbh->quote( $form->{currency} );
+ $where .= qq| AND a.curr = $curr| if $form->{currency};
- my $sortorder = "transdate, invnumber";
+ my $sortorder = "transdate, invnumber";
- my ($buysell);
+ my ($buysell);
- if ($form->{vc} eq 'customer') {
- $buysell = "buy";
- } else {
- $buysell = "sell";
- }
+ if ( $form->{vc} eq 'customer' ) {
+ $buysell = "buy";
+ }
+ else {
+ $buysell = "sell";
+ }
- if ($form->{payment} eq 'payments') {
+ if ( $form->{payment} eq 'payments' ) {
- $where = qq|WHERE a.amount != a.paid|;
- $where .= qq| AND a.curr = $curr| if $form->{currency};
+ $where = qq|WHERE a.amount != a.paid|;
+ $where .= qq| AND a.curr = $curr| if $form->{currency};
- if ($form->{duedatefrom}) {
- $where .= qq| AND a.duedate >=
- |.$dbh->quote($form->{duedatefrom});
- }
+ if ( $form->{duedatefrom} ) {
+ $where .= qq| AND a.duedate >=
+ | . $dbh->quote( $form->{duedatefrom} );
+ }
- if ($form->{duedateto}) {
- $where .= qq| AND a.duedate <= |.
- $dbh->quote($form->{duedateto});
- }
+ if ( $form->{duedateto} ) {
+ $where .=
+ qq| AND a.duedate <= | . $dbh->quote( $form->{duedateto} );
+ }
- $sortorder = "name, transdate";
- }
+ $sortorder = "name, transdate";
+ }
+ ( $null, $department_id ) = split /--/, $form->{department};
- ($null, $department_id) = split /--/, $form->{department};
+ if ($department_id) {
+ $where .= qq| AND a.department_id = $department_id|;
+ }
- if ($department_id) {
- $where .= qq| AND a.department_id = $department_id|;
- }
-
- my $query = qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid,
+ my $query = qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid,
a.curr, c.name, a.$form->{vc}_id, c.language_code
FROM $form->{arap} a
JOIN $form->{vc} c ON (c.id = a.$form->{vc}_id)
$where
ORDER BY $sortorder|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- $query = qq|SELECT s.spoolfile
+ $query = qq|SELECT s.spoolfile
FROM status s
WHERE s.formname = '$form->{formname}'
AND s.trans_id = ?|;
- my $vth = $dbh->prepare($query);
-
- my $spoolfile;
+ my $vth = $dbh->prepare($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ my $spoolfile;
- # if this is a foreign currency transaction get exchangerate
- $ref->{exchangerate} =
- $form->get_exchangerate($dbh,
- $ref->{curr},
- $ref->{transdate},
- $buysell)
- if ($form->{currency}
- ne $form->{defaultcurrency});
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
- $vth->execute($ref->{id});
- $ref->{queue} = "";
-
- while (($spoolfile) = $vth->fetchrow_array) {
- $ref->{queued} .= "$form->{formname} $spoolfile ";
- }
+ # if this is a foreign currency transaction get exchangerate
+ $ref->{exchangerate} =
+ $form->get_exchangerate( $dbh, $ref->{curr}, $ref->{transdate},
+ $buysell )
+ if ( $form->{currency} ne $form->{defaultcurrency} );
- $vth->finish;
- $ref->{queued} =~ s/ +$//g;
+ $vth->execute( $ref->{id} );
+ $ref->{queue} = "";
- push @{ $form->{PR} }, $ref;
- }
+ while ( ($spoolfile) = $vth->fetchrow_array ) {
+ $ref->{queued} .= "$form->{formname} $spoolfile ";
+ }
- $sth->finish;
- $dbh->commit;
+ $vth->finish;
+ $ref->{queued} =~ s/ +$//g;
-}
+ push @{ $form->{PR} }, $ref;
+ }
+ $sth->finish;
+ $dbh->commit;
+}
sub post_payment {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database, turn AutoCommit off
- my $dbh = $form->{dbh};
+ # connect to database, turn AutoCommit off
+ my $dbh = $form->{dbh};
- my $sth;
+ my $sth;
- my ($paymentaccno) = split /--/, $form->{account};
+ my ($paymentaccno) = split /--/, $form->{account};
- # if currency ne defaultcurrency update exchangerate
- if ($form->{currency} ne $form->{defaultcurrency}) {
+ # if currency ne defaultcurrency update exchangerate
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
- $form->{exchangerate} = $form->parse_amount($myconfig, $form->{exchangerate});
+ $form->{exchangerate} =
+ $form->parse_amount( $myconfig, $form->{exchangerate} );
- if ($form->{vc} eq 'customer') {
- $form->update_exchangerate($dbh, $form->{currency}, $form->{datepaid}, $form->{exchangerate}, 0);
- } else {
- $form->update_exchangerate($dbh, $form->{currency}, $form->{datepaid}, 0, $form->{exchangerate});
- }
+ if ( $form->{vc} eq 'customer' ) {
+ $form->update_exchangerate( $dbh, $form->{currency},
+ $form->{datepaid}, $form->{exchangerate}, 0 );
+ }
+ else {
+ $form->update_exchangerate( $dbh, $form->{currency},
+ $form->{datepaid}, 0, $form->{exchangerate} );
+ }
- } else {
- $form->{exchangerate} = 1;
- }
+ }
+ else {
+ $form->{exchangerate} = 1;
+ }
- my $query = qq|
+ my $query = qq|
SELECT (SELECT value FROM defaults
WHERE setting_key='fxgain_accno_id'),
(SELECT value FROM defaults
WHERE setting_key='fxloss_accno_id')|;
- my ($fxgain_accno_id, $fxloss_accno_id) = $dbh->selectrow_array($query);
+ my ( $fxgain_accno_id, $fxloss_accno_id ) = $dbh->selectrow_array($query);
- my ($buysell);
+ my ($buysell);
- if ($form->{vc} eq 'customer') {
- $buysell = "buy";
- } else {
- $buysell = "sell";
- }
+ if ( $form->{vc} eq 'customer' ) {
+ $buysell = "buy";
+ }
+ else {
+ $buysell = "sell";
+ }
- my $ml;
- my $where;
+ my $ml;
+ my $where;
- if ($form->{ARAP} eq 'AR') {
+ if ( $form->{ARAP} eq 'AR' ) {
- $ml = 1;
- $where = qq| (c.link = 'AR' OR c.link LIKE 'AR:%') |;
+ $ml = 1;
+ $where = qq| (c.link = 'AR' OR c.link LIKE 'AR:%') |;
- } else {
+ }
+ else {
- $ml = -1;
- $where = qq| (c.link = 'AP' OR c.link LIKE '%:AP' OR c.link LIKE '%:AP:%') |;
+ $ml = -1;
+ $where =
+ qq| (c.link = 'AP' OR c.link LIKE '%:AP' OR c.link LIKE '%:AP:%') |;
- }
+ }
- my $paymentamount = $form->parse_amount($myconfig, $form->{amount});
+ my $paymentamount = $form->parse_amount( $myconfig, $form->{amount} );
- # query to retrieve paid amount
- $query = qq|SELECT paid
+ # query to retrieve paid amount
+ $query = qq|SELECT paid
FROM $form->{arap}
WHERE id = ?
FOR UPDATE|;
- my $pth = $dbh->prepare($query) || $form->dberror($query);
+ my $pth = $dbh->prepare($query) || $form->dberror($query);
- my %audittrail;
+ my %audittrail;
- # go through line by line
- for my $i (1 .. $form->{rowcount}) {
+ # go through line by line
+ for my $i ( 1 .. $form->{rowcount} ) {
- $form->{"paid_$i"} = $form->parse_amount($myconfig, $form->{"paid_$i"});
- $form->{"due_$i"} = $form->parse_amount($myconfig, $form->{"due_$i"});
+ $form->{"paid_$i"} =
+ $form->parse_amount( $myconfig, $form->{"paid_$i"} );
+ $form->{"due_$i"} = $form->parse_amount( $myconfig, $form->{"due_$i"} );
- if ($form->{"checked_$i"} && $form->{"paid_$i"}) {
+ if ( $form->{"checked_$i"} && $form->{"paid_$i"} ) {
- $paymentamount -= $form->{"paid_$i"};
+ $paymentamount -= $form->{"paid_$i"};
- # get exchangerate for original
- $query = qq|
+ # get exchangerate for original
+ $query = qq|
SELECT $buysell
FROM exchangerate e
JOIN $form->{arap} a
@@ -391,42 +392,41 @@ sub post_payment {
WHERE e.curr = ?
AND a.id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{currency}, $form->{"id_$i"});
- my ($exchangerate) = $sth->fetchrow_array();
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{currency}, $form->{"id_$i"} );
+ my ($exchangerate) = $sth->fetchrow_array();
- $exchangerate = 1 unless $exchangerate;
+ $exchangerate = 1 unless $exchangerate;
- $query = qq|
+ $query = qq|
SELECT c.id
FROM chart c
JOIN acc_trans a ON (a.chart_id = c.id)
WHERE $where
AND a.trans_id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{"id_$i"});
- my ($id) = $sth->fetchrow_array;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{"id_$i"} );
+ my ($id) = $sth->fetchrow_array;
- $amount =
- $form->round_amount(
- $form->{"paid_$i"} * $exchangerate, 2);
+ $amount =
+ $form->round_amount( $form->{"paid_$i"} * $exchangerate, 2 );
- # add AR/AP
- $query = qq|
+ # add AR/AP
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, transdate,
amount)
VALUES (?, ?,
?,
?)|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{"id_$i"}, $id,
- $form->{date_paid}, $amount * $ml)
- || $form->dberror($query, __file__, __line__);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{"id_$i"}, $id, $form->{date_paid},
+ $amount * $ml )
+ || $form->dberror( $query, __file__, __line__ );
- # add payment
- $query = qq|
+ # add payment
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, transdate,
amount, source, memo)
@@ -434,24 +434,21 @@ sub post_payment {
FROM chart
WHERE accno = ?),
?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{"id_$i"}, $paymentaccno,
- $form->{datepaid},
- $form->{"paid_$i"} * $ml * -1,
- $form->{source}, $form->{memo})
- || $form->dberror(
- $query, 'CP.pm', 444);
-
- # add exchangerate difference if currency ne defaultcurrency
- $amount = $form->round_amount(
- $form->{"paid_$i"} *
- ($form->{exchangerate} - 1),
- 2);
-
- if ($amount) {
- # exchangerate difference
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{"id_$i"}, $paymentaccno, $form->{datepaid},
+ $form->{"paid_$i"} * $ml * -1,
+ $form->{source}, $form->{memo} )
+ || $form->dberror( $query, 'CP.pm', 444 );
+
+ # add exchangerate difference if currency ne defaultcurrency
+ $amount =
+ $form->round_amount(
+ $form->{"paid_$i"} * ( $form->{exchangerate} - 1 ), 2 );
+
+ if ($amount) {
+
+ # exchangerate difference
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id,
transdate, amount, cleared,
@@ -461,34 +458,29 @@ sub post_payment {
WHERE accno = ?),
?, ?, '0', '1',
?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{"id_$i"}, $paymentaccno,
- $form->{datepaid}, $amount * $ml * -1,
- $form->{source})
- || $form->dberror(
- $query, 'CP.pm', 470);
-
- # gain/loss
- $amount =
- ($form->round_amount(
- $form->{"paid_$i"} *
- $exchangerate,
- 2) -
- $form->round_amount(
- $form->{"paid_$i"} *
- $form->{exchangerate},
- 2))
- * $ml * -1;
-
- if ($amount) {
-
- my $accno_id =
- ($amount > 0)
- ? $fxgain_accno_id
- : $fxloss_accno_id;
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{"id_$i"}, $paymentaccno, $form->{datepaid},
+ $amount * $ml * -1, $form->{source}
+ ) || $form->dberror( $query, 'CP.pm', 470 );
+
+ # gain/loss
+ $amount = (
+ $form->round_amount(
+ $form->{"paid_$i"} * $exchangerate, 2
+ ) - $form->round_amount(
+ $form->{"paid_$i"} * $form->{exchangerate}, 2
+ )
+ ) * $ml * -1;
+
+ if ($amount) {
+
+ my $accno_id =
+ ( $amount > 0 )
+ ? $fxgain_accno_id
+ : $fxloss_accno_id;
+
+ $query = qq|
INSERT INTO acc_trans
(trans_id,
chart_id,
@@ -496,172 +488,176 @@ sub post_payment {
amount, cleared,
fx_transaction)
VALUES (?, ?, ?, ?, '0', '1')|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{"id_$i"}, $accno_id,
- $form->{datepaid}, $amount)
- || $form->dberror(
- $query,
- 'CP.pm',
- 506);
- }
- }
-
- $form->{"paid_$i"} =
- $form->round_amount(
- $form->{"paid_$i"} * $exchangerate, 2);
-
- $pth->execute($form->{"id_$i"}) || $form->dberror;
- ($amount) = $pth->fetchrow_array;
- $pth->finish;
-
- $amount += $form->{"paid_$i"};
-
- # update AR/AP transaction
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{"id_$i"}, $accno_id,
+ $form->{datepaid}, $amount
+ ) || $form->dberror( $query, 'CP.pm', 506 );
+ }
+ }
+
+ $form->{"paid_$i"} =
+ $form->round_amount( $form->{"paid_$i"} * $exchangerate, 2 );
+
+ $pth->execute( $form->{"id_$i"} ) || $form->dberror;
+ ($amount) = $pth->fetchrow_array;
+ $pth->finish;
+
+ $amount += $form->{"paid_$i"};
+
+ # update AR/AP transaction
+ $query = qq|
UPDATE $form->{arap}
SET paid = ?,
datepaid = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $amount, $form->{datepaid}, $form->{"id_$i"})
- || $form->dberror($query, 'CP.pm',
- 530);
-
- %audittrail = (
- tablename => $form->{arap},
- reference => $form->{source},
- formname => $form->{formname},
- action => 'posted',
- id => $form->{"id_$i"} );
+ $sth = $dbh->prepare($query);
+ $sth->execute( $amount, $form->{datepaid}, $form->{"id_$i"} )
+ || $form->dberror( $query, 'CP.pm', 530 );
- $form->audittrail($dbh, "", \%audittrail);
+ %audittrail = (
+ tablename => $form->{arap},
+ reference => $form->{source},
+ formname => $form->{formname},
+ action => 'posted',
+ id => $form->{"id_$i"}
+ );
- }
- }
+ $form->audittrail( $dbh, "", \%audittrail );
+ }
+ }
- # record a AR/AP with a payment
- if ($form->round_amount($paymentamount, 2)) {
- $form->{invnumber} = "";
- OP::overpayment("", $myconfig, $form, $dbh, $paymentamount, $ml, 1);
- }
+ # record a AR/AP with a payment
+ if ( $form->round_amount( $paymentamount, 2 ) ) {
+ $form->{invnumber} = "";
+ OP::overpayment( "", $myconfig, $form, $dbh, $paymentamount, $ml, 1 );
+ }
- my $rc = $dbh->commit;
+ my $rc = $dbh->commit;
- $rc;
+ $rc;
}
-
sub post_payments {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database, turn AutoCommit off
- my $dbh = $form->{dbh};
+ # connect to database, turn AutoCommit off
+ my $dbh = $form->{dbh};
- my $sth;
+ my $sth;
- my ($paymentaccno) = split /--/, $form->{account};
+ my ($paymentaccno) = split /--/, $form->{account};
- # if currency ne defaultcurrency update exchangerate
- if ($form->{currency} ne $form->{defaultcurrency}) {
- $form->{exchangerate} = $form->parse_amount($myconfig, $form->{exchangerate});
+ # if currency ne defaultcurrency update exchangerate
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ $form->{exchangerate} =
+ $form->parse_amount( $myconfig, $form->{exchangerate} );
- if ($form->{vc} eq 'customer') {
- $form->update_exchangerate($dbh, $form->{currency}, $form->{datepaid}, $form->{exchangerate}, 0);
- } else {
- $form->update_exchangerate($dbh, $form->{currency}, $form->{datepaid}, 0, $form->{exchangerate});
- }
+ if ( $form->{vc} eq 'customer' ) {
+ $form->update_exchangerate( $dbh, $form->{currency},
+ $form->{datepaid}, $form->{exchangerate}, 0 );
+ }
+ else {
+ $form->update_exchangerate( $dbh, $form->{currency},
+ $form->{datepaid}, 0, $form->{exchangerate} );
+ }
- } else {
- $form->{exchangerate} = 1;
- }
+ }
+ else {
+ $form->{exchangerate} = 1;
+ }
- my $query = qq|
+ my $query = qq|
SELECT (SELECT value FROM defaults
WHERE setting_key='fxgain_accno_id'),
(SELECT value FROM defaults
WHERE setting_key='fxloss_accno_id')|;
- my ($fxgain_accno_id, $fxloss_accno_id) = $dbh->selectrow_array($query);
+ my ( $fxgain_accno_id, $fxloss_accno_id ) = $dbh->selectrow_array($query);
- my ($buysell);
+ my ($buysell);
- if ($form->{vc} eq 'customer') {
- $buysell = "buy";
- } else {
- $buysell = "sell";
- }
+ if ( $form->{vc} eq 'customer' ) {
+ $buysell = "buy";
+ }
+ else {
+ $buysell = "sell";
+ }
- my $ml;
- my $where;
+ my $ml;
+ my $where;
- if ($form->{ARAP} eq 'AR') {
+ if ( $form->{ARAP} eq 'AR' ) {
- $ml = 1;
- $where = qq| (c.link = 'AR' OR c.link LIKE 'AR:%') |;
+ $ml = 1;
+ $where = qq| (c.link = 'AR' OR c.link LIKE 'AR:%') |;
- } else {
+ }
+ else {
- $ml = -1;
- $where = qq| (c.link = 'AP' OR c.link LIKE '%:AP' OR c.link LIKE '%:AP:%') |;
+ $ml = -1;
+ $where =
+ qq| (c.link = 'AP' OR c.link LIKE '%:AP' OR c.link LIKE '%:AP:%') |;
- }
+ }
- # get AR/AP account
- $query = qq|SELECT c.accno
+ # get AR/AP account
+ $query = qq|SELECT c.accno
FROM chart c
JOIN acc_trans ac ON (ac.chart_id = c.id)
WHERE trans_id = ?
AND $where|;
- my $ath = $dbh->prepare($query) || $form->dberror($query);
+ my $ath = $dbh->prepare($query) || $form->dberror($query);
- # query to retrieve paid amount
- $query = qq|SELECT paid
+ # query to retrieve paid amount
+ $query = qq|SELECT paid
FROM $form->{arap}
WHERE id = ?
FOR UPDATE|;
- my $pth = $dbh->prepare($query) || $form->dberror($query);
+ my $pth = $dbh->prepare($query) || $form->dberror($query);
+
+ my %audittrail;
- my %audittrail;
+ my $overpayment = 0;
+ my $accno_id;
- my $overpayment = 0;
- my $accno_id;
+ # go through line by line
+ for my $i ( 1 .. $form->{rowcount} ) {
- # go through line by line
- for my $i (1 .. $form->{rowcount}) {
+ $ath->execute( $form->{"id_$i"} );
+ ( $form->{ $form->{ARAP} } ) = $ath->fetchrow_array;
+ $ath->finish;
- $ath->execute($form->{"id_$i"});
- ($form->{$form->{ARAP}}) = $ath->fetchrow_array;
- $ath->finish;
+ $form->{"paid_$i"} =
+ $form->parse_amount( $myconfig, $form->{"paid_$i"} );
+ $form->{"due_$i"} = $form->parse_amount( $myconfig, $form->{"due_$i"} );
- $form->{"paid_$i"} = $form->parse_amount($myconfig, $form->{"paid_$i"});
- $form->{"due_$i"} = $form->parse_amount($myconfig, $form->{"due_$i"});
+ if ( $form->{"$form->{vc}_id_$i"} ne $sameid ) {
- if ($form->{"$form->{vc}_id_$i"} ne $sameid) {
- # record a AR/AP with a payment
- if ($overpayment > 0 && $form->{$form->{ARAP}}) {
- $form->{invnumber} = "";
- OP::overpayment("", $myconfig, $form, $dbh, $overpayment, $ml, 1);
- }
+ # record a AR/AP with a payment
+ if ( $overpayment > 0 && $form->{ $form->{ARAP} } ) {
+ $form->{invnumber} = "";
+ OP::overpayment( "", $myconfig, $form, $dbh, $overpayment, $ml,
+ 1 );
+ }
- $overpayment = 0;
- $form->{"$form->{vc}_id"} = $form->{"$form->{vc}_id_$i"};
- for (qw(source memo)) { $form->{$_} = $form->{"${_}_$i"} }
- }
+ $overpayment = 0;
+ $form->{"$form->{vc}_id"} = $form->{"$form->{vc}_id_$i"};
+ for (qw(source memo)) { $form->{$_} = $form->{"${_}_$i"} }
+ }
- if ($form->{"checked_$i"} && $form->{"paid_$i"}) {
+ if ( $form->{"checked_$i"} && $form->{"paid_$i"} ) {
- $overpayment += ($form->{"paid_$i"} - $form->{"due_$i"});
+ $overpayment += ( $form->{"paid_$i"} - $form->{"due_$i"} );
- # get exchangerate for original
- $query = qq|
+ # get exchangerate for original
+ $query = qq|
SELECT $buysell
FROM exchangerate e
JOIN $form->{arap} a
@@ -669,99 +665,97 @@ sub post_payments {
WHERE e.curr = ?
AND a.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{currency}, $form->{"id_$i"})
- || $form->dberror($query, 'CP.pm', 671);
- my ($exchangerate) = $sth->fetchrow_array;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{currency}, $form->{"id_$i"} )
+ || $form->dberror( $query, 'CP.pm', 671 );
+ my ($exchangerate) = $sth->fetchrow_array;
- $exchangerate ||= 1;
+ $exchangerate ||= 1;
- $query = qq|
+ $query = qq|
SELECT c.id
FROM chart c
JOIN acc_trans a ON (a.chart_id = c.id)
WHERE $where
AND a.trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{"id_$i"});
- ($id) = $sth->fetchrow_array();
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{"id_$i"} );
+ ($id) = $sth->fetchrow_array();
- $paid = ($form->{"paid_$i"} > $form->{"due_$i"}) ? $form->{"due_$i"} : $form->{"paid_$i"};
- $amount = $form->round_amount($paid * $exchangerate, 2);
+ $paid =
+ ( $form->{"paid_$i"} > $form->{"due_$i"} )
+ ? $form->{"due_$i"}
+ : $form->{"paid_$i"};
+ $amount = $form->round_amount( $paid * $exchangerate, 2 );
- # add AR/AP
- $query = qq|
+ # add AR/AP
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, transdate,
amount)
VALUES (?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{"id_$i"}, $id, $form->{datepaid},
- $amount * $ml)
- || $form->dberror($query, 'CP.pm',
- 701);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{"id_$i"}, $id, $form->{datepaid},
+ $amount * $ml )
+ || $form->dberror( $query, 'CP.pm', 701 );
- $query = qq|SELECT id
+ $query = qq|SELECT id
FROM chart
WHERE accno = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($paymentaccno);
- ($accno_id) = $sth->fetchrow_array;
+ $sth = $dbh->prepare($query);
+ $sth->execute($paymentaccno);
+ ($accno_id) = $sth->fetchrow_array;
- # add payment
- $query = qq|
+ # add payment
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, transdate,
amount, source, memo)
VALUES (?, ?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{"id_$i"}, $accno_id, $form->{datepaid},
- $paid * $ml * -1, $form->{source},
- $form->{memo})
- || $form->dberror($query, 'CP.pm',
- 723);
-
- # add exchangerate difference if currency ne defaultcurrency
- $amount =
- $form->round_amount(
- $paid * ($form->{exchangerate} - 1)
- * $ml * -1,
- 2);
-
- if ($amount) {
- # exchangerate difference
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{"id_$i"}, $accno_id, $form->{datepaid},
+ $paid * $ml * -1, $form->{source}, $form->{memo}
+ ) || $form->dberror( $query, 'CP.pm', 723 );
+
+ # add exchangerate difference if currency ne defaultcurrency
+ $amount =
+ $form->round_amount(
+ $paid * ( $form->{exchangerate} - 1 ) * $ml * -1, 2 );
+
+ if ($amount) {
+
+ # exchangerate difference
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id,
transdate,
amount, source)
VALUES (?, ?, ?, ?, ?)|;
-
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{"id_$i"}, $accno_id,
- $form->{datepaid}, $amount,
- $form->{source})
- || $form->dberror(
- $query, 'CP.pm', 748);
-
- # gain/loss
- $amount = ($form->round_amount($paid * $exchangerate,2) - $form->round_amount($paid * $form->{exchangerate},2)) * $ml * -1;
-
- if ($amount) {
- $accno_id =
- ($amount > 0)
- ? $fxgain_accno_id
- : $fxloss_accno_id;
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{"id_$i"}, $accno_id, $form->{datepaid},
+ $amount, $form->{source}
+ ) || $form->dberror( $query, 'CP.pm', 748 );
+
+ # gain/loss
+ $amount =
+ ( $form->round_amount( $paid * $exchangerate, 2 ) -
+ $form->round_amount( $paid * $form->{exchangerate}, 2 ) )
+ * $ml * -1;
+
+ if ($amount) {
+ $accno_id =
+ ( $amount > 0 )
+ ? $fxgain_accno_id
+ : $fxloss_accno_id;
+
+ $query = qq|
INSERT INTO acc_trans
(trans_id,
chart_id,
@@ -770,63 +764,60 @@ sub post_payments {
fx_transaction)
VALUES (?, ?, ?, ?, '1')|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{"id_$i"}, $accno_id,
- $form->{datepaid}, $amount)
- || $form->dberror(
- $query,
- 'CP.pm', 775);
- }
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{"id_$i"}, $accno_id,
+ $form->{datepaid}, $amount
+ ) || $form->dberror( $query, 'CP.pm', 775 );
+ }
+ }
- $paid = $form->round_amount($paid * $exchangerate, 2);
+ $paid = $form->round_amount( $paid * $exchangerate, 2 );
- $pth->execute($form->{"id_$i"}) || $form->dberror;
- ($amount) = $pth->fetchrow_array;
- $pth->finish;
+ $pth->execute( $form->{"id_$i"} ) || $form->dberror;
+ ($amount) = $pth->fetchrow_array;
+ $pth->finish;
- $amount += $paid;
+ $amount += $paid;
- # update AR/AP transaction
- $query = qq|
+ # update AR/AP transaction
+ $query = qq|
UPDATE $form->{arap}
SET paid = ?,
datepaid = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $amount, $form->{datepaid}, $form->{"id_$i"})
- || $form->dberror($query, 'CP.pm',
- 796);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $amount, $form->{datepaid}, $form->{"id_$i"} )
+ || $form->dberror( $query, 'CP.pm', 796 );
- %audittrail = ( tablename => $form->{arap},
- reference => $form->{source},
- formname => $form->{formname},
- action => 'posted',
- id => $form->{"id_$i"} );
+ %audittrail = (
+ tablename => $form->{arap},
+ reference => $form->{source},
+ formname => $form->{formname},
+ action => 'posted',
+ id => $form->{"id_$i"}
+ );
- $form->audittrail($dbh, "", \%audittrail);
+ $form->audittrail( $dbh, "", \%audittrail );
- }
+ }
- $sameid = $form->{"$form->{vc}_id_$i"};
+ $sameid = $form->{"$form->{vc}_id_$i"};
- }
+ }
- # record a AR/AP with a payment
- if ($overpayment > 0 && $form->{$form->{ARAP}}) {
- $form->{invnumber} = "";
- OP::overpayment("", $myconfig, $form, $dbh, $overpayment, $ml, 1);
- }
+ # record a AR/AP with a payment
+ if ( $overpayment > 0 && $form->{ $form->{ARAP} } ) {
+ $form->{invnumber} = "";
+ OP::overpayment( "", $myconfig, $form, $dbh, $overpayment, $ml, 1 );
+ }
- my $rc = $dbh->commit;
+ my $rc = $dbh->commit;
- $rc;
+ $rc;
}
-
1;
diff --git a/LedgerSMB/CT.pm b/LedgerSMB/CT.pm
index 5e70e302..7c1c3bf3 100644
--- a/LedgerSMB/CT.pm
+++ b/LedgerSMB/CT.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -34,20 +34,19 @@
package CT;
-
sub create_links {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
- my $query;
- my $sth;
- my $ref;
- my $arap = ($form->{db} eq 'customer') ? "ar" : "ap";
- my $ARAP = uc $arap;
+ my $dbh = $form->{dbh};
+ my $query;
+ my $sth;
+ my $ref;
+ my $arap = ( $form->{db} eq 'customer' ) ? "ar" : "ap";
+ my $ARAP = uc $arap;
- if ($form->{id}) {
- $query = qq|
+ if ( $form->{id} ) {
+ $query = qq|
SELECT ct.*, b.description AS business, s.*,
e.name AS employee,
g.pricegroup AS pricegroup,
@@ -60,15 +59,15 @@ sub create_links {
LEFT JOIN language l ON (l.code = ct.language_code)
WHERE ct.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
- # check if it is orphaned
- $query = qq|
+ # check if it is orphaned
+ $query = qq|
SELECT a.id
FROM $arap a
JOIN $form->{db} ct ON (a.$form->{db}_id = ct.id)
@@ -81,230 +80,232 @@ sub create_links {
JOIN $form->{db} ct ON (a.$form->{db}_id = ct.id)
WHERE ct.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}, $form->{id})
- || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $form->{id} )
+ || $form->dberror($query);
- unless ($sth->fetchrow_array) {
- $form->{status} = "orphaned";
- }
+ unless ( $sth->fetchrow_array ) {
+ $form->{status} = "orphaned";
+ }
- $sth->finish;
+ $sth->finish;
- # get taxes for customer/vendor
- $query = qq|
+ # get taxes for customer/vendor
+ $query = qq|
SELECT c.accno
FROM chart c
JOIN $form->{db}tax t ON (t.chart_id = c.id)
WHERE t.$form->{db}_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $form->{tax}{$ref->{accno}}{taxable} = 1;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $form->{tax}{ $ref->{accno} }{taxable} = 1;
+ }
- $sth->finish;
+ $sth->finish;
- } else {
+ }
+ else {
- ($form->{employee}, $form->{employee_id}) = $form->get_employee($dbh);
+ ( $form->{employee}, $form->{employee_id} ) = $form->get_employee($dbh);
- $query = qq|SELECT current_date|;
- ($form->{startdate}) = $dbh->selectrow_array($query);
+ $query = qq|SELECT current_date|;
+ ( $form->{startdate} ) = $dbh->selectrow_array($query);
- }
+ }
- # get tax labels
- $query = qq|
+ # get tax labels
+ $query = qq|
SELECT DISTINCT c.accno, c.description
FROM chart c
JOIN tax t ON (t.chart_id = c.id)
WHERE c.link LIKE ?
ORDER BY c.accno|;
- $sth = $dbh->prepare($query);
- $sth->execute("%${ARAP}_tax%") || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $form->{taxaccounts} .= "$ref->{accno} ";
- $form->{tax}{$ref->{accno}}{description} = $ref->{description};
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute("%${ARAP}_tax%") || $form->dberror($query);
- $sth->finish;
- chop $form->{taxaccounts};
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $form->{taxaccounts} .= "$ref->{accno} ";
+ $form->{tax}{ $ref->{accno} }{description} = $ref->{description};
+ }
+ $sth->finish;
+ chop $form->{taxaccounts};
- # get business types ## needs fixing, this is bad (SELECT * ...) with order by 2. Yuck
- $query = qq|
+# get business types ## needs fixing, this is bad (SELECT * ...) with order by 2. Yuck
+ $query = qq|
SELECT *
FROM business
ORDER BY 2|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_business} }, $ref;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_business} }, $ref;
+ }
- $sth->finish;
+ $sth->finish;
- # employees/salespersons
- $form->all_employees($myconfig, $dbh, undef,
- ($form->{vc} eq 'customer')
- ? 1
- : 0);
+ # employees/salespersons
+ $form->all_employees( $myconfig, $dbh, undef,
+ ( $form->{vc} eq 'customer' )
+ ? 1
+ : 0 );
- # get language ## needs fixing, this is bad (SELECT * ...) with order by 2. Yuck
- $query = qq|
+# get language ## needs fixing, this is bad (SELECT * ...) with order by 2. Yuck
+ $query = qq|
SELECT *
FROM language
ORDER BY 2|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_language} }, $ref;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_language} }, $ref;
+ }
- $sth->finish;
+ $sth->finish;
- # get pricegroups ## needs fixing, this is bad (SELECT * ...) with order by 2. Yuck
- $query = qq|
+# get pricegroups ## needs fixing, this is bad (SELECT * ...) with order by 2. Yuck
+ $query = qq|
SELECT *
FROM pricegroup
ORDER BY 2|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_pricegroup} }, $ref;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_pricegroup} }, $ref;
+ }
- $sth->finish;
+ $sth->finish;
- # get currencies
- $query = qq|
+ # get currencies
+ $query = qq|
SELECT value AS currencies
FROM defaults
WHERE setting_key = 'curr'|;
- ($form->{currencies}) = $dbh->selectrow_array($query);
+ ( $form->{currencies} ) = $dbh->selectrow_array($query);
- $dbh->commit;
+ $dbh->commit;
}
-
sub save_customer {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
- my $query;
- my $sth;
- my $null;
-
- # remove double spaces
- $form->{name} =~ s/ / /g;
- # remove double minus and minus at the end
- $form->{name} =~ s/--+/-/g;
- $form->{name} =~ s/-+$//;
-
- # assign value discount, terms, creditlimit
- $form->{discount} = $form->parse_amount($myconfig, $form->{discount});
- $form->{discount} /= 100;
- $form->{terms} *= 1;
- $form->{taxincluded} *= 1;
- $form->{creditlimit} = $form->parse_amount($myconfig, $form->{creditlimit});
- if (!$form->{creditlimit}){
- $form->{creditlimit} = 0;
- }
-
-
- if ($form->{id}) {
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+ my $query;
+ my $sth;
+ my $null;
+
+ # remove double spaces
+ $form->{name} =~ s/ / /g;
+
+ # remove double minus and minus at the end
+ $form->{name} =~ s/--+/-/g;
+ $form->{name} =~ s/-+$//;
+
+ # assign value discount, terms, creditlimit
+ $form->{discount} = $form->parse_amount( $myconfig, $form->{discount} );
+ $form->{discount} /= 100;
+ $form->{terms} *= 1;
+ $form->{taxincluded} *= 1;
+ $form->{creditlimit} =
+ $form->parse_amount( $myconfig, $form->{creditlimit} );
+ if ( !$form->{creditlimit} ) {
+ $form->{creditlimit} = 0;
+ }
+
+ if ( $form->{id} ) {
+ $query = qq|
DELETE FROM customertax
WHERE customer_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $query = qq|
+ $query = qq|
DELETE FROM shipto
WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT id
FROM customer
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- if (! $sth->fetchrow_array) {
- $query = qq|
+ if ( !$sth->fetchrow_array ) {
+ $query = qq|
INSERT INTO customer (id)
VALUES (?)|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ }
- # retrieve enddate
- if ($form->{type} && $form->{enddate}) {
- my $now;
- $query = qq|
+ # retrieve enddate
+ if ( $form->{type} && $form->{enddate} ) {
+ my $now;
+ $query = qq|
SELECT enddate, current_date AS now
FROM customer|;
- ($form->{enddate}, $now) =
- $dbh->selectrow_array($query);
- $form->{enddate} = $now if $form->{enddate} lt $now;
- }
+ ( $form->{enddate}, $now ) = $dbh->selectrow_array($query);
+ $form->{enddate} = $now if $form->{enddate} lt $now;
+ }
- } else {
- my $uid = localtime;
- $uid .= "$$";
+ }
+ else {
+ my $uid = localtime;
+ $uid .= "$$";
- $query = qq|INSERT INTO customer (name)
+ $query = qq|INSERT INTO customer (name)
VALUES ('$uid')|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $form->dberror($query);
- $query = qq|SELECT id
+ $query = qq|SELECT id
FROM customer
WHERE name = '$uid'|;
- ($form->{id}) = $dbh->selectrow_array($query);
+ ( $form->{id} ) = $dbh->selectrow_array($query);
- }
+ }
- my $employee_id;
- ($null, $employee_id) = split /--/, $form->{employee};
- $employee_id *= 1;
+ my $employee_id;
+ ( $null, $employee_id ) = split /--/, $form->{employee};
+ $employee_id *= 1;
- my $pricegroup_id;
- ($null, $pricegroup_id) = split /--/, $form->{pricegroup};
- $pricegroup_id *= 1;
+ my $pricegroup_id;
+ ( $null, $pricegroup_id ) = split /--/, $form->{pricegroup};
+ $pricegroup_id *= 1;
- my $business_id;
- ($null, $business_id) = split /--/, $form->{business};
- $business_id *= 1;
+ my $business_id;
+ ( $null, $business_id ) = split /--/, $form->{business};
+ $business_id *= 1;
- my $language_code;
- ($null, $language_code) = split /--/, $form->{language};
+ my $language_code;
+ ( $null, $language_code ) = split /--/, $form->{language};
- $form->{customernumber} = $form->update_defaults($myconfig, "customernumber", $dbh) if ! $form->{customernumber};
+ $form->{customernumber} =
+ $form->update_defaults( $myconfig, "customernumber", $dbh )
+ if !$form->{customernumber};
- $query = qq|
+ $query = qq|
UPDATE customer
SET customernumber = ?,
name = ?,
@@ -338,149 +339,151 @@ sub save_customer {
enddate = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- if (!$form->{startdate}){
- undef $form->{startdate};
- }
- if (!$form->{enddate}){
- undef $form->{enddate};
- }
- $sth->execute(
- $form->{customernumber}, $form->{name}, $form->{address1},
- $form->{address2}, $form->{city}, $form->{state},
- $form->{zipcode}, $form->{country}, $form->{contact},
- $form->{phone}, $form->{fax}, $form->{email}, $form->{cc},
- $form->{bcc}, $form->{notes}, $form->{discount},
- $form->{creditlimit}, $form->{terms}, $form->{taxincluded},
- $business_id, $form->{taxnumber}, $form->{sic_code},
- $form->{iban}, $form->{bic}, $employee_id, $pricegroup_id,
- $language_code,
- $form->{curr}, $form->{startdate}, $form->{enddate},
- $form->{id})
- || $form->dberror($query);
-
- # save taxes
- foreach $item (split / /, $form->{taxaccounts}) {
-
- if ($form->{"tax_$item"}) {
- $query = qq|
+ $sth = $dbh->prepare($query);
+ if ( !$form->{startdate} ) {
+ undef $form->{startdate};
+ }
+ if ( !$form->{enddate} ) {
+ undef $form->{enddate};
+ }
+ $sth->execute(
+ $form->{customernumber}, $form->{name}, $form->{address1},
+ $form->{address2}, $form->{city}, $form->{state},
+ $form->{zipcode}, $form->{country}, $form->{contact},
+ $form->{phone}, $form->{fax}, $form->{email},
+ $form->{cc}, $form->{bcc}, $form->{notes},
+ $form->{discount}, $form->{creditlimit}, $form->{terms},
+ $form->{taxincluded}, $business_id, $form->{taxnumber},
+ $form->{sic_code}, $form->{iban}, $form->{bic},
+ $employee_id, $pricegroup_id, $language_code,
+ $form->{curr}, $form->{startdate}, $form->{enddate},
+ $form->{id}
+ ) || $form->dberror($query);
+
+ # save taxes
+ foreach $item ( split / /, $form->{taxaccounts} ) {
+
+ if ( $form->{"tax_$item"} ) {
+ $query = qq|
INSERT INTO customertax (customer_id, chart_id)
VALUES (?, (SELECT id
FROM chart
WHERE accno = ?))|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}, $item)
- || $form->dberror($query);
- }
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $item )
+ || $form->dberror($query);
+ }
+ }
- # add shipto
- $form->add_shipto($dbh, $form->{id});
+ # add shipto
+ $form->add_shipto( $dbh, $form->{id} );
- $dbh->commit;
+ $dbh->commit;
}
-
sub save_vendor {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my $query;
- my $sth;
- my $null;
+ my $query;
+ my $sth;
+ my $null;
- # remove double spaces
- $form->{name} =~ s/ / /g;
- # remove double minus and minus at the end
- $form->{name} =~ s/--+/-/g;
- $form->{name} =~ s/-+$//;
+ # remove double spaces
+ $form->{name} =~ s/ / /g;
- $form->{discount} = $form->parse_amount($myconfig, $form->{discount});
- $form->{discount} /= 100;
- $form->{terms} *= 1;
- $form->{taxincluded} *= 1;
- $form->{creditlimit} =
- $form->parse_amount($myconfig, $form->{creditlimit});
+ # remove double minus and minus at the end
+ $form->{name} =~ s/--+/-/g;
+ $form->{name} =~ s/-+$//;
+ $form->{discount} = $form->parse_amount( $myconfig, $form->{discount} );
+ $form->{discount} /= 100;
+ $form->{terms} *= 1;
+ $form->{taxincluded} *= 1;
+ $form->{creditlimit} =
+ $form->parse_amount( $myconfig, $form->{creditlimit} );
- if ($form->{id}) {
- $query = qq|DELETE FROM vendortax
+ if ( $form->{id} ) {
+ $query = qq|DELETE FROM vendortax
WHERE vendor_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $query = qq|DELETE FROM shipto
+ $query = qq|DELETE FROM shipto
WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $query = qq|SELECT id
+ $query = qq|SELECT id
FROM vendor
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- if (! $sth->fetchrow_array) {
- $query = qq|INSERT INTO vendor (id)
+ if ( !$sth->fetchrow_array ) {
+ $query = qq|INSERT INTO vendor (id)
VALUES (?)|;
- $sth = $dbh->prepare($query) ;
- $sth->execute($form->{id}) || $form->dberror($query);
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ }
- # retrieve enddate
- if ($form->{type} && $form->{enddate}) {
- my $now;
- $query = qq|SELECT enddate, current_date AS now FROM vendor|;
- ($form->{enddate}, $now) = $dbh->selectrow_array($query);
- $form->{enddate} = $now if $form->{enddate} lt $now;
- }
+ # retrieve enddate
+ if ( $form->{type} && $form->{enddate} ) {
+ my $now;
+ $query = qq|SELECT enddate, current_date AS now FROM vendor|;
+ ( $form->{enddate}, $now ) = $dbh->selectrow_array($query);
+ $form->{enddate} = $now if $form->{enddate} lt $now;
+ }
- } else {
- my $uid = localtime;
- $uid .= "$$";
+ }
+ else {
+ my $uid = localtime;
+ $uid .= "$$";
- $query = qq|INSERT INTO vendor (name)
+ $query = qq|INSERT INTO vendor (name)
VALUES ('$uid')|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $form->dberror($query);
- $query = qq|SELECT id
+ $query = qq|SELECT id
FROM vendor
WHERE name = '$uid'|;
- ($form->{id}) = $dbh->selectrow_array($query);
+ ( $form->{id} ) = $dbh->selectrow_array($query);
- }
+ }
- my $employee_id;
- ($null, $employee_id) = split /--/, $form->{employee};
- $employee_id *= 1;
+ my $employee_id;
+ ( $null, $employee_id ) = split /--/, $form->{employee};
+ $employee_id *= 1;
- my $pricegroup_id;
- ($null, $pricegroup_id) = split /--/, $form->{pricegroup};
- $pricegroup_id *= 1;
+ my $pricegroup_id;
+ ( $null, $pricegroup_id ) = split /--/, $form->{pricegroup};
+ $pricegroup_id *= 1;
- my $business_id;
- ($null, $business_id) = split /--/, $form->{business};
- $business_id *= 1;
+ my $business_id;
+ ( $null, $business_id ) = split /--/, $form->{business};
+ $business_id *= 1;
- my $language_code;
- ($null, $language_code) = split /--/, $form->{language};
+ my $language_code;
+ ( $null, $language_code ) = split /--/, $form->{language};
- $form->{vendornumber} = $form->update_defaults($myconfig, "vendornumber", $dbh) if ! $form->{vendornumber};
-
- $form->{startdate} = undef unless $form->{startdate};
- $form->{enddate} = undef unless $form->{enddate};
+ $form->{vendornumber} =
+ $form->update_defaults( $myconfig, "vendornumber", $dbh )
+ if !$form->{vendornumber};
- $query = qq|
+ $form->{startdate} = undef unless $form->{startdate};
+ $form->{enddate} = undef unless $form->{enddate};
+
+ $query = qq|
UPDATE vendor
SET vendornumber = ?,
name = ?,
@@ -515,141 +518,138 @@ sub save_vendor {
enddate = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
-
- $sth->execute(
- $form->{vendornumber}, $form->{name}, $form->{address1},
- $form->{address2}, $form->{city}, $form->{state},
- $form->{zipcode}, $form->{country}, $form->{contact},
- $form->{phone}, $form->{fax}, $form->{email}, $form->{cc},
- $form->{bcc}, $form->{notes}, $form->{discount},
- $form->{creditlimit}, $form->{terms}, $form->{taxincluded},
- $form->{gifi_accno}, $business_id, $form->{taxnumber},
- $form->{sic_code}, $form->{iban}, $form->{bic}, $employee_id,
- $language_code, $pricegroup_id,
- $form->{curr}, $form->{startdate}, $form->{enddate},
- $form->{id})
- || $form->dberror($query);
- # save taxes
- foreach $item (split / /, $form->{taxaccounts}) {
- if ($form->{"tax_$item"}) {
- $query = qq|
+ $sth = $dbh->prepare($query);
+
+ $sth->execute(
+ $form->{vendornumber}, $form->{name}, $form->{address1},
+ $form->{address2}, $form->{city}, $form->{state},
+ $form->{zipcode}, $form->{country}, $form->{contact},
+ $form->{phone}, $form->{fax}, $form->{email},
+ $form->{cc}, $form->{bcc}, $form->{notes},
+ $form->{discount}, $form->{creditlimit}, $form->{terms},
+ $form->{taxincluded}, $form->{gifi_accno}, $business_id,
+ $form->{taxnumber}, $form->{sic_code}, $form->{iban},
+ $form->{bic}, $employee_id, $language_code,
+ $pricegroup_id, $form->{curr}, $form->{startdate},
+ $form->{enddate}, $form->{id}
+ ) || $form->dberror($query);
+
+ # save taxes
+ foreach $item ( split / /, $form->{taxaccounts} ) {
+ if ( $form->{"tax_$item"} ) {
+ $query = qq|
INSERT INTO vendortax (vendor_id, chart_id)
VALUES (?, (SELECT id
FROM chart
WHERE accno = ?))|;
-
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}, $item)
- || $form->dberror($query);
- }
- }
-
- # add shipto
- $form->add_shipto($dbh, $form->{id});
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $item )
+ || $form->dberror($query);
+ }
+ }
-}
+ # add shipto
+ $form->add_shipto( $dbh, $form->{id} );
+ $dbh->commit;
+}
sub delete {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- # delete customer/vendor
- my $query = qq|DELETE FROM $form->{db}
+ # delete customer/vendor
+ my $query = qq|DELETE FROM $form->{db}
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $dbh->commit;
+ $dbh->commit;
}
-
sub search {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my $where = "1 = 1";
- $form->{sort} = ($form->{sort}) ? $form->{sort} : "name";
- my @a = qw(name);
- my $sortorder = $form->sort_order(\@a);
+ my $where = "1 = 1";
+ $form->{sort} = ( $form->{sort} ) ? $form->{sort} : "name";
+ my @a = qw(name);
+ my $sortorder = $form->sort_order( \@a );
- my $var;
- my $item;
+ my $var;
+ my $item;
- @a = ("$form->{db}number");
- push @a, qw(name contact city state zipcode country notes phone email);
+ @a = ("$form->{db}number");
+ push @a, qw(name contact city state zipcode country notes phone email);
- if ($form->{employee}) {
- $var = $form->like(lc $form->{employee});
- $where .= " AND lower(e.name) LIKE '$var'";
- }
+ if ( $form->{employee} ) {
+ $var = $form->like( lc $form->{employee} );
+ $where .= " AND lower(e.name) LIKE '$var'";
+ }
- foreach $item (@a) {
+ foreach $item (@a) {
- if ($form->{$item} ne "") {
- $var = $form->like(lc $form->{$item});
- $where .= " AND lower(ct.$item) LIKE '$var'";
- }
- }
+ if ( $form->{$item} ne "" ) {
+ $var = $form->like( lc $form->{$item} );
+ $where .= " AND lower(ct.$item) LIKE '$var'";
+ }
+ }
- if ($form->{address} ne "") {
- $var = $dbh->quote($form->like(lc $form->{address}));
- $where .= " AND (lower(ct.address1) LIKE $var OR lower(ct.address2) LIKE '$var')";
- }
+ if ( $form->{address} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{address} ) );
+ $where .=
+" AND (lower(ct.address1) LIKE $var OR lower(ct.address2) LIKE '$var')";
+ }
- if ($form->{startdatefrom}) {
- $where .= " AND ct.startdate >= ".
- $dbh->quote($form->{startdatefrom});
- }
+ if ( $form->{startdatefrom} ) {
+ $where .=
+ " AND ct.startdate >= " . $dbh->quote( $form->{startdatefrom} );
+ }
- if ($form->{startdateto}) {
- $where .= " AND ct.startdate <= ".
- $dbh->quote($form->{startdateto});
- }
+ if ( $form->{startdateto} ) {
+ $where .= " AND ct.startdate <= " . $dbh->quote( $form->{startdateto} );
+ }
- if ($form->{status} eq 'active') {
- $where .= " AND ct.enddate IS NULL";
- }
+ if ( $form->{status} eq 'active' ) {
+ $where .= " AND ct.enddate IS NULL";
+ }
- if ($form->{status} eq 'inactive') {
- $where .= " AND ct.enddate <= current_date";
- }
+ if ( $form->{status} eq 'inactive' ) {
+ $where .= " AND ct.enddate <= current_date";
+ }
- if ($form->{status} eq 'orphaned') {
- $where .= qq|
+ if ( $form->{status} eq 'orphaned' ) {
+ $where .= qq|
AND ct.id NOT IN (SELECT o.$form->{db}_id
FROM oe o, $form->{db} vc
WHERE vc.id = o.$form->{db}_id)|;
- if ($form->{db} eq 'customer') {
- $where .= qq| AND ct.id NOT IN (SELECT a.customer_id
+ if ( $form->{db} eq 'customer' ) {
+ $where .= qq| AND ct.id NOT IN (SELECT a.customer_id
FROM ar a, customer vc
WHERE vc.id = a.customer_id)|;
- }
-
- if ($form->{db} eq 'vendor') {
- $where .= qq| AND ct.id NOT IN (SELECT a.vendor_id
+ }
+
+ if ( $form->{db} eq 'vendor' ) {
+ $where .= qq| AND ct.id NOT IN (SELECT a.vendor_id
FROM ap a, vendor vc
WHERE vc.id = a.vendor_id)|;
- }
-
- $form->{l_invnumber} = $form->{l_ordnumber} = $form->{l_quonumber} = "";
- }
+ }
+ $form->{l_invnumber} = $form->{l_ordnumber} = $form->{l_quonumber} = "";
+ }
- my $query = qq|
+ my $query = qq|
SELECT ct.*, b.description AS business,
e.name AS employee, g.pricegroup,
l.description AS language, m.name AS manager
@@ -661,46 +661,46 @@ sub search {
LEFT JOIN language l ON (l.code = ct.language_code)
WHERE $where|;
- # redo for invoices, orders and quotations
- if ($form->{l_transnumber}
- || $form->{l_invnumber}
- || $form->{l_ordnumber}
- || $form->{l_quonumber}) {
-
- my ($ar, $union, $module);
- $query = "";
- my $transwhere;
- my $openarap = "";
- my $openoe = "";
-
- if ($form->{open} || $form->{closed}) {
- unless ($form->{open} && $form->{closed}) {
- $openarap = " AND a.amount != a.paid"
- if $form->{open};
- $openarap = " AND a.amount = a.paid"
- if $form->{closed};
- $openoe = " AND o.closed = '0'"
- if $form->{open};
- $openoe = " AND o.closed = '1'"
- if $form->{closed};
- }
- }
-
- if ($form->{l_transnumber}) {
-
- $ar = ($form->{db} eq 'customer') ? 'ar' : 'ap';
- $module = $ar;
-
- $transwhere = "";
- $transwhere .= " AND a.transdate >= "
- .$dbh->quote($form->{transdatefrom})
- if $form->{transdatefrom};
- $transwhere .= " AND a.transdate <= ".
- $dbh->quote($form->{transdateto})
- if $form->{transdateto};
-
-
- $query = qq|
+ # redo for invoices, orders and quotations
+ if ( $form->{l_transnumber}
+ || $form->{l_invnumber}
+ || $form->{l_ordnumber}
+ || $form->{l_quonumber} )
+ {
+
+ my ( $ar, $union, $module );
+ $query = "";
+ my $transwhere;
+ my $openarap = "";
+ my $openoe = "";
+
+ if ( $form->{open} || $form->{closed} ) {
+ unless ( $form->{open} && $form->{closed} ) {
+ $openarap = " AND a.amount != a.paid"
+ if $form->{open};
+ $openarap = " AND a.amount = a.paid"
+ if $form->{closed};
+ $openoe = " AND o.closed = '0'"
+ if $form->{open};
+ $openoe = " AND o.closed = '1'"
+ if $form->{closed};
+ }
+ }
+
+ if ( $form->{l_transnumber} ) {
+
+ $ar = ( $form->{db} eq 'customer' ) ? 'ar' : 'ap';
+ $module = $ar;
+
+ $transwhere = "";
+ $transwhere .=
+ " AND a.transdate >= " . $dbh->quote( $form->{transdatefrom} )
+ if $form->{transdatefrom};
+ $transwhere .=
+ " AND a.transdate <= " . $dbh->quote( $form->{transdateto} )
+ if $form->{transdateto};
+
+ $query = qq|
SELECT ct.*, b.description AS business,
a.invnumber, a.ordnumber,
a.quonumber,
@@ -720,23 +720,23 @@ sub search {
$transwhere
$openarap |;
- $union = qq| UNION |;
+ $union = qq| UNION |;
- }
+ }
- if ($form->{l_invnumber}) {
- $ar = ($form->{db} eq 'customer') ? 'ar' : 'ap';
- $module = ($ar eq 'ar') ? 'is' : 'ir';
+ if ( $form->{l_invnumber} ) {
+ $ar = ( $form->{db} eq 'customer' ) ? 'ar' : 'ap';
+ $module = ( $ar eq 'ar' ) ? 'is' : 'ir';
- $transwhere = "";
- $transwhere .= " AND a.transdate >= ".
- $dbh->quote($form->{transdatefrom})
- if $form->{transdatefrom};
- $transwhere .= " AND a.transdate <= ".
- $dbh->quote($form->{transdateto})
- if $form->{transdateto};
+ $transwhere = "";
+ $transwhere .=
+ " AND a.transdate >= " . $dbh->quote( $form->{transdatefrom} )
+ if $form->{transdatefrom};
+ $transwhere .=
+ " AND a.transdate <= " . $dbh->quote( $form->{transdateto} )
+ if $form->{transdateto};
- $query .= qq|
+ $query .= qq|
$union
SELECT ct.*, b.description AS business,
a.invnumber, a.ordnumber, a.quonumber,
@@ -756,21 +756,21 @@ sub search {
$transwhere
$openarap |;
- $union = qq| UNION|;
+ $union = qq| UNION|;
- }
+ }
- if ($form->{l_ordnumber}) {
+ if ( $form->{l_ordnumber} ) {
- $transwhere = "";
- $transwhere .= " AND o.transdate >= ".
- $dbh->quote($form->{transdatefrom})
- if $form->{transdatefrom};
- $transwhere .= " AND o.transdate <= ".
- $dbh->quote($form->{transdateto})
- if $form->{transdateto};
+ $transwhere = "";
+ $transwhere .=
+ " AND o.transdate >= " . $dbh->quote( $form->{transdatefrom} )
+ if $form->{transdatefrom};
+ $transwhere .=
+ " AND o.transdate <= " . $dbh->quote( $form->{transdateto} )
+ if $form->{transdateto};
- $query .= qq|
+ $query .= qq|
$union
SELECT ct.*, b.description AS business,
' ' AS invnumber, o.ordnumber,
@@ -788,22 +788,21 @@ sub search {
$transwhere
$openoe |;
- $union = qq| UNION|;
-
- }
+ $union = qq| UNION|;
- if ($form->{l_quonumber}) {
+ }
- $transwhere = "";
- $transwhere .= " AND o.transdate >= ".
- $dbh->quote($form->{transdatefrom})
- if $form->{transdatefrom};
- $transwhere .= " AND o.transdate <= ".
- $dbh->quote($form->{transdateto})
- if $form->{transdateto};
+ if ( $form->{l_quonumber} ) {
+ $transwhere = "";
+ $transwhere .=
+ " AND o.transdate >= " . $dbh->quote( $form->{transdatefrom} )
+ if $form->{transdatefrom};
+ $transwhere .=
+ " AND o.transdate <= " . $dbh->quote( $form->{transdateto} )
+ if $form->{transdateto};
- $query .= qq|
+ $query .= qq|
$union
SELECT ct.*, b.description AS business,
' ' AS invnumber, o.ordnumber,
@@ -822,190 +821,195 @@ sub search {
$transwhere
$openoe |;
- }
+ }
- $sortorder .= ", invid";
- }
+ $sortorder .= ", invid";
+ }
- $query .= qq| ORDER BY $sortorder|;
+ $query .= qq| ORDER BY $sortorder|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- # accounts
- $query = qq|
+ # accounts
+ $query = qq|
SELECT c.accno
FROM chart c
JOIN $form->{db}tax t ON (t.chart_id = c.id)
WHERE t.$form->{db}_id = ?|;
- my $tth = $dbh->prepare($query);
+ my $tth = $dbh->prepare($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $tth->execute($ref->{id});
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $tth->execute( $ref->{id} );
- while (($item) = $tth->fetchrow_array) {
- $ref->{taxaccount} .= "$item ";
- }
+ while ( ($item) = $tth->fetchrow_array ) {
+ $ref->{taxaccount} .= "$item ";
+ }
- $tth->finish;
- chop $ref->{taxaccount};
+ $tth->finish;
+ chop $ref->{taxaccount};
- $ref->{address} = "";
+ $ref->{address} = "";
- for (qw(address1 address2 city state zipcode country)) {
- $ref->{address} .= "$ref->{$_} ";
- }
- push @{ $form->{CT} }, $ref;
- }
+ for (qw(address1 address2 city state zipcode country)) {
+ $ref->{address} .= "$ref->{$_} ";
+ }
+ push @{ $form->{CT} }, $ref;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub get_history {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my $query;
- my $where = "1 = 1";
- $form->{sort} = "partnumber" unless $form->{sort};
- my $sortorder = $form->{sort};
- my %ordinal = ();
- my $var;
- my $table;
-
- # setup ASC or DESC
- $form->sort_order();
-
- if ($form->{"$form->{db}number"} ne "") {
- $var = $dbh->($form->like(lc $form->{"$form->{db}number"}));
- $where .= " AND lower(ct.$form->{db}number) LIKE $var";
- }
-
- if ($form->{address} ne "") {
- $var = $dbh->quote($form->like(lc $form->{address}));
- $where .= " AND lower(ct.address1) LIKE $var";
- }
-
- for (qw(name contact email phone notes city state zipcode country)) {
-
- if ($form->{$_} ne "") {
- $var = $dbh->quote($form->like(lc $form->{$_}));
- $where .= " AND lower(ct.$_) LIKE $var";
- }
- }
-
- if ($form->{employee} ne "") {
- $var = $form->like(lc $form->{employee});
- $where .= " AND lower(e.name) LIKE '$var'";
- }
-
- $transwhere .= " AND a.transdate >= ".
- $dbh->quote($form->{transdatefrom})
- if $form->{transdatefrom};
- $transwhere .= " AND a.transdate <= ".
- $dbh->quote($form->{transdateto})
- if $form->{transdateto};
-
- if ($form->{open} || $form->{closed}) {
-
- unless ($form->{open} && $form->{closed}) {
-
- if ($form->{type} eq 'invoice') {
- $where .= " AND a.amount != a.paid"
- if $form->{open};
- $where .= " AND a.amount = a.paid"
- if $form->{closed};
- } else {
- $where .= " AND a.closed = '0'"
- if $form->{open};
- $where .= " AND a.closed = '1'"
- if $form->{closed};
- }
- }
- }
-
- my $invnumber = 'invnumber';
- my $deldate = 'deliverydate';
- my $buysell;
- my $sellprice = "sellprice";
-
- if ($form->{db} eq 'customer') {
- $buysell = "buy";
-
- if ($form->{type} eq 'invoice') {
- $where .= qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my $query;
+ my $where = "1 = 1";
+ $form->{sort} = "partnumber" unless $form->{sort};
+ my $sortorder = $form->{sort};
+ my %ordinal = ();
+ my $var;
+ my $table;
+
+ # setup ASC or DESC
+ $form->sort_order();
+
+ if ( $form->{"$form->{db}number"} ne "" ) {
+ $var = $dbh->( $form->like( lc $form->{"$form->{db}number"} ) );
+ $where .= " AND lower(ct.$form->{db}number) LIKE $var";
+ }
+
+ if ( $form->{address} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{address} ) );
+ $where .= " AND lower(ct.address1) LIKE $var";
+ }
+
+ for (qw(name contact email phone notes city state zipcode country)) {
+
+ if ( $form->{$_} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{$_} ) );
+ $where .= " AND lower(ct.$_) LIKE $var";
+ }
+ }
+
+ if ( $form->{employee} ne "" ) {
+ $var = $form->like( lc $form->{employee} );
+ $where .= " AND lower(e.name) LIKE '$var'";
+ }
+
+ $transwhere .=
+ " AND a.transdate >= " . $dbh->quote( $form->{transdatefrom} )
+ if $form->{transdatefrom};
+ $transwhere .= " AND a.transdate <= " . $dbh->quote( $form->{transdateto} )
+ if $form->{transdateto};
+
+ if ( $form->{open} || $form->{closed} ) {
+
+ unless ( $form->{open} && $form->{closed} ) {
+
+ if ( $form->{type} eq 'invoice' ) {
+ $where .= " AND a.amount != a.paid"
+ if $form->{open};
+ $where .= " AND a.amount = a.paid"
+ if $form->{closed};
+ }
+ else {
+ $where .= " AND a.closed = '0'"
+ if $form->{open};
+ $where .= " AND a.closed = '1'"
+ if $form->{closed};
+ }
+ }
+ }
+
+ my $invnumber = 'invnumber';
+ my $deldate = 'deliverydate';
+ my $buysell;
+ my $sellprice = "sellprice";
+
+ if ( $form->{db} eq 'customer' ) {
+ $buysell = "buy";
+
+ if ( $form->{type} eq 'invoice' ) {
+ $where .= qq|
AND a.invoice = '1' AND i.assemblyitem = '0'|;
- $table = 'ar';
- $sellprice = "fxsellprice";
- } else {
- $table = 'oe';
-
- if ($form->{type} eq 'order') {
- $invnumber = 'ordnumber';
- $where .= qq| AND a.quotation = '0'|;
- } else {
- $invnumber = 'quonumber';
- $where .= qq| AND a.quotation = '1'|;
- }
-
- $deldate = 'reqdate';
- }
- }
-
- if ($form->{db} eq 'vendor') {
-
- $buysell = "sell";
-
- if ($form->{type} eq 'invoice') {
-
- $where .= qq| AND a.invoice = '1' AND i.assemblyitem = '0'|;
- $table = 'ap';
- $sellprice = "fxsellprice";
-
- } else {
-
- $table = 'oe';
-
- if ($form->{type} eq 'order') {
- $invnumber = 'ordnumber';
- $where .= qq| AND a.quotation = '0'|;
- } else {
- $invnumber = 'quonumber';
- $where .= qq| AND a.quotation = '1'|;
- }
-
- $deldate = 'reqdate';
- }
- }
-
- my $invjoin = qq| JOIN invoice i ON (i.trans_id = a.id)|;
-
- if ($form->{type} eq 'order') {
- $invjoin = qq| JOIN orderitems i ON (i.trans_id = a.id)|;
- }
-
- if ($form->{type} eq 'quotation') {
- $invjoin = qq| JOIN orderitems i ON (i.trans_id = a.id)|;
- $where .= qq| AND a.quotation = '1'|;
- }
-
-
- %ordinal = ( partnumber => 9,
- description => 12,
- "$deldate" => 16,
- serialnumber => 17,
- projectnumber => 18 );
-
- $sortorder = "2 $form->{direction}, 1, 11, $ordinal{$sortorder} $form->{direction}";
-
- $query = qq|
+ $table = 'ar';
+ $sellprice = "fxsellprice";
+ }
+ else {
+ $table = 'oe';
+
+ if ( $form->{type} eq 'order' ) {
+ $invnumber = 'ordnumber';
+ $where .= qq| AND a.quotation = '0'|;
+ }
+ else {
+ $invnumber = 'quonumber';
+ $where .= qq| AND a.quotation = '1'|;
+ }
+
+ $deldate = 'reqdate';
+ }
+ }
+
+ if ( $form->{db} eq 'vendor' ) {
+
+ $buysell = "sell";
+
+ if ( $form->{type} eq 'invoice' ) {
+
+ $where .= qq| AND a.invoice = '1' AND i.assemblyitem = '0'|;
+ $table = 'ap';
+ $sellprice = "fxsellprice";
+
+ }
+ else {
+
+ $table = 'oe';
+
+ if ( $form->{type} eq 'order' ) {
+ $invnumber = 'ordnumber';
+ $where .= qq| AND a.quotation = '0'|;
+ }
+ else {
+ $invnumber = 'quonumber';
+ $where .= qq| AND a.quotation = '1'|;
+ }
+
+ $deldate = 'reqdate';
+ }
+ }
+
+ my $invjoin = qq| JOIN invoice i ON (i.trans_id = a.id)|;
+
+ if ( $form->{type} eq 'order' ) {
+ $invjoin = qq| JOIN orderitems i ON (i.trans_id = a.id)|;
+ }
+
+ if ( $form->{type} eq 'quotation' ) {
+ $invjoin = qq| JOIN orderitems i ON (i.trans_id = a.id)|;
+ $where .= qq| AND a.quotation = '1'|;
+ }
+
+ %ordinal = (
+ partnumber => 9,
+ description => 12,
+ "$deldate" => 16,
+ serialnumber => 17,
+ projectnumber => 18
+ );
+
+ $sortorder =
+ "2 $form->{direction}, 1, 11, $ordinal{$sortorder} $form->{direction}";
+
+ $query = qq|
SELECT ct.id AS ctid, ct.name, ct.address1,
ct.address2, ct.city, ct.state,
p.id AS pid, p.partnumber, a.id AS invid,
@@ -1026,34 +1030,35 @@ sub get_history {
WHERE $where
ORDER BY $sortorder|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{address} = "";
- $ref->{exchangerate} ||= 1;
- for (qw(address1 address2 city state zipcode country)) { $ref->{address} .= "$ref->{$_} " }
- $ref->{id} = $ref->{ctid};
- push @{ $form->{CT} }, $ref;
- }
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{address} = "";
+ $ref->{exchangerate} ||= 1;
+ for (qw(address1 address2 city state zipcode country)) {
+ $ref->{address} .= "$ref->{$_} ";
+ }
+ $ref->{id} = $ref->{ctid};
+ push @{ $form->{CT} }, $ref;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub pricelist {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my $query;
+ my $query;
- if ($form->{db} eq 'customer') {
- $query = qq|SELECT p.id, p.partnumber, p.description,
+ if ( $form->{db} eq 'customer' ) {
+ $query = qq|SELECT p.id, p.partnumber, p.description,
p.sellprice, pg.partsgroup, p.partsgroup_id,
m.pricebreak, m.sellprice,
m.validfrom, m.validto, m.curr
@@ -1062,10 +1067,10 @@ sub pricelist {
LEFT JOIN partsgroup pg ON (pg.id = p.partsgroup_id)
WHERE m.customer_id = ?
ORDER BY partnumber|;
- }
+ }
- if ($form->{db} eq 'vendor') {
- $query = qq|SELECT p.id, p.partnumber AS sku, p.description,
+ if ( $form->{db} eq 'vendor' ) {
+ $query = qq|SELECT p.id, p.partnumber AS sku, p.description,
pg.partsgroup, p.partsgroup_id,
m.partnumber, m.leadtime, m.lastcost, m.curr
FROM partsvendor m
@@ -1073,159 +1078,154 @@ sub pricelist {
LEFT JOIN partsgroup pg ON (pg.id = p.partsgroup_id)
WHERE m.vendor_id = ?
ORDER BY p.partnumber|;
- }
+ }
- my $sth;
- my $ref;
+ my $sth;
+ my $ref;
- if ($form->{id}) {
+ if ( $form->{id} ) {
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_partspricelist} }, $ref;
- }
-
- $sth->finish;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_partspricelist} }, $ref;
+ }
- $query = qq|SELECT value FROM defaults where setting_key = 'curr'|;
- ($form->{currencies}) = $dbh->selectrow_array($query);
+ $sth->finish;
+ }
- $query = qq|SELECT id, partsgroup
+ $query = qq|SELECT value FROM defaults where setting_key = 'curr'|;
+ ( $form->{currencies} ) = $dbh->selectrow_array($query);
+
+ $query = qq|SELECT id, partsgroup
FROM partsgroup
ORDER BY partsgroup|;
- $sth = $dbh->prepare($query);
- $sth->execute || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
- $form->{all_partsgroup} = ();
+ $form->{all_partsgroup} = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_partsgroup} }, $ref;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_partsgroup} }, $ref;
+ }
- $sth->finish;
+ $sth->finish;
- $dbh->commit;
+ $dbh->commit;
}
-
sub save_pricelist {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
+ my $dbh = $form->{dbh};
- my $query = qq|
+ my $query = qq|
DELETE FROM parts$form->{db}
WHERE $form->{db}_id = ?}|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- foreach $i (1 .. $form->{rowcount}) {
+ foreach $i ( 1 .. $form->{rowcount} ) {
- if ($form->{"id_$i"}) {
+ if ( $form->{"id_$i"} ) {
- if ($form->{db} eq 'customer') {
+ if ( $form->{db} eq 'customer' ) {
- for (qw(pricebreak sellprice)) {
- $form->{"${_}_$i"} =
- $form->parse_amount(
- $myconfig,
- $form->{"${_}_$i"});
- }
+ for (qw(pricebreak sellprice)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( $myconfig, $form->{"${_}_$i"} );
+ }
- $query = qq|
+ $query = qq|
INSERT INTO parts$form->{db}
(parts_id, customer_id,
pricebreak, sellprice,
validfrom, validto, curr)
VALUES (?, ?, ?, ?, ?, ?, ?)|;
- @queryargs = ($form->{"id_$i"}, $form->{id},
- $form->{"pricebreak_$i"},
- $form->{"sellprice_$i"},
- $form->{"validfrom_$i"},
- $form->{"validto_$i"},
- $form->{"curr_$i"});
- } else {
-
- for (qw(leadtime lastcost)) {
- $form->{"${_}_$i"} =
- $form->parse_amount(
- $myconfig,
- $form->{"${_}_$i"})
- }
-
- $query = qq|
+ @queryargs = (
+ $form->{"id_$i"}, $form->{id},
+ $form->{"pricebreak_$i"}, $form->{"sellprice_$i"},
+ $form->{"validfrom_$i"}, $form->{"validto_$i"},
+ $form->{"curr_$i"}
+ );
+ }
+ else {
+
+ for (qw(leadtime lastcost)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( $myconfig, $form->{"${_}_$i"} );
+ }
+
+ $query = qq|
INSERT INTO parts$form->{db}
(parts_id, vendor_id,
partnumber, lastcost,
leadtime, curr)
VALUES (?, ?, ?, ?, ?, ?)|;
- @queryargs = ($form->{"id_$i"}, $form->{id},
- $form->{"partnumber_$i"},
- $form->{"lastcost_$i"},
- $form->{"leadtime_$i"},
- $form->{"curr_$i"});
+ @queryargs = (
+ $form->{"id_$i"}, $form->{id},
+ $form->{"partnumber_$i"}, $form->{"lastcost_$i"},
+ $form->{"leadtime_$i"}, $form->{"curr_$i"}
+ );
- }
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $form->dberror($query);
- }
+ }
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $form->dberror($query);
+ }
- }
+ }
- $_ = $dbh->commit;
+ $_ = $dbh->commit;
}
-
-
sub retrieve_item {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my $i = $form->{rowcount};
- my $var;
- my $null;
+ my $i = $form->{rowcount};
+ my $var;
+ my $null;
- my $where = "WHERE p.obsolete = '0'";
+ my $where = "WHERE p.obsolete = '0'";
- if ($form->{db} eq 'vendor') {
- # parts, services, labor
- $where .= " AND p.assembly = '0'";
- }
+ if ( $form->{db} eq 'vendor' ) {
- if ($form->{db} eq 'customer') {
- # parts, assemblies, services
- $where .= " AND p.income_accno_id > 0";
- }
+ # parts, services, labor
+ $where .= " AND p.assembly = '0'";
+ }
- if ($form->{"partnumber_$i"} ne "") {
- $var = $dbh->quote($form->like(lc $form->{"partnumber_$i"}));
- $where .= " AND lower(p.partnumber) LIKE $var";
- }
+ if ( $form->{db} eq 'customer' ) {
- if ($form->{"description_$i"} ne "") {
- $var = $dbh->quote($form->like(lc $form->{"description_$i"}));
- $where .= " AND lower(p.description) LIKE $var";
- }
+ # parts, assemblies, services
+ $where .= " AND p.income_accno_id > 0";
+ }
- if ($form->{"partsgroup_$i"} ne "") {
- ($null, $var) = split /--/, $form->{"partsgroup_$i"};
- $var = $dbh->quote($var);
- $where .= qq| AND p.partsgroup_id = $var|;
- }
+ if ( $form->{"partnumber_$i"} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{"partnumber_$i"} ) );
+ $where .= " AND lower(p.partnumber) LIKE $var";
+ }
+ if ( $form->{"description_$i"} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{"description_$i"} ) );
+ $where .= " AND lower(p.description) LIKE $var";
+ }
- my $query = qq|
+ if ( $form->{"partsgroup_$i"} ne "" ) {
+ ( $null, $var ) = split /--/, $form->{"partsgroup_$i"};
+ $var = $dbh->quote($var);
+ $where .= qq| AND p.partsgroup_id = $var|;
+ }
+
+ my $query = qq|
SELECT p.id, p.partnumber, p.description, p.sellprice,
p.lastcost, p.unit, pg.partsgroup, p.partsgroup_id
FROM parts p
@@ -1233,19 +1233,18 @@ sub retrieve_item {
$where
ORDER BY partnumber|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
- my $ref;
- $form->{item_list} = ();
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+ my $ref;
+ $form->{item_list} = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{item_list} }, $ref;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{item_list} }, $ref;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
1;
diff --git a/LedgerSMB/Contact.pm b/LedgerSMB/Contact.pm
index d28cbc64..14f3ee6e 100644
--- a/LedgerSMB/Contact.pm
+++ b/LedgerSMB/Contact.pm
@@ -1,3 +1,4 @@
+
=head1 NAME
LedgerSMB::Contact - LedgerSMB class for managing Contacts
diff --git a/LedgerSMB/CreditCard.pm b/LedgerSMB/CreditCard.pm
index 8e2a4e1a..dd124163 100644
--- a/LedgerSMB/CreditCard.pm
+++ b/LedgerSMB/CreditCard.pm
@@ -1,5 +1,5 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
# Copyright (C) 2006
@@ -19,6 +19,7 @@ use LedgerSMB;
use LedgerSMB::DBObject;
our @ISA qw(LedgerSMB::DBObject);
+
# use LedgerSMB::CreditCard::Config; # moving elsewhere
## TODO: Add code for credit card number validation and the like
diff --git a/LedgerSMB/CreditCard/Config.pm b/LedgerSMB/CreditCard/Config.pm
index 199431c0..c8b30758 100644
--- a/LedgerSMB/CreditCard/Config.pm
+++ b/LedgerSMB/CreditCard/Config.pm
@@ -1,6 +1,6 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
# Copyright (C) 2006
@@ -18,6 +18,6 @@
package Config;
$gateway_module = "TrustCommerce";
-$debug = 0; # Debugging off by default
+$debug = 0; # Debugging off by default
1;
diff --git a/LedgerSMB/CreditCard/TrustCommerce.pm b/LedgerSMB/CreditCard/TrustCommerce.pm
index e0adb395..634af8f2 100644
--- a/LedgerSMB/CreditCard/TrustCommerce.pm
+++ b/LedgerSMB/CreditCard/TrustCommerce.pm
@@ -1,6 +1,6 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
# Copyright (C) 2006
@@ -23,63 +23,63 @@ use Net::TCLink;
$debug = $1;
sub sale {
- $form = shift @_;
- $params{action} = 'sale';
- $params{amount} = $form->{amount} * 100;
- $params{track1} = $form->{track1};
- $params{track2} = $form->{track2};
- &process;
+ $form = shift @_;
+ $params{action} = 'sale';
+ $params{amount} = $form->{amount} * 100;
+ $params{track1} = $form->{track1};
+ $params{track2} = $form->{track2};
+ &process;
}
sub process {
- for (keys %params){
- print "$_= ".$params{$_}."\n";
- }
- my %result = Net::TCLink::send(\%params);
- $form->{status} = $result{status};
- if ($result{status} eq 'decline'){
- $form->{declinetype} = $result{declinetype};
- $form->{declinemsg} = $declinemsg{$result{declinetype}};
- }
- $form->{ccauth} = $result{transID};
- # log transID and status
- print STDERR "Info: TCLink CC AUTH transID $result{transid} returned ".
- "status $result{status}:$result{declinetype}:$result{baddata}:".
- "$result{errortype}\n";
- if ($debug){
- print STDERR "Full Result:\n";
+ for ( keys %params ) {
+ print "$_= " . $params{$_} . "\n";
+ }
+ my %result = Net::TCLink::send( \%params );
+ $form->{status} = $result{status};
+ if ( $result{status} eq 'decline' ) {
+ $form->{declinetype} = $result{declinetype};
+ $form->{declinemsg} = $declinemsg{ $result{declinetype} };
+ }
+ $form->{ccauth} = $result{transID};
- for (keys %result){
- print STDERR "$_= ".$result{$_}."\n";
- }
- }
-
- %result;
+ # log transID and status
+ print STDERR "Info: TCLink CC AUTH transID $result{transid} returned "
+ . "status $result{status}:$result{declinetype}:$result{baddata}:"
+ . "$result{errortype}\n";
+ if ($debug) {
+ print STDERR "Full Result:\n";
+
+ for ( keys %result ) {
+ print STDERR "$_= " . $result{$_} . "\n";
+ }
+ }
+
+ %result;
}
sub credit {
- $form = shift @_;
- my %params = %baseparams;
- $params{transid} = $form->{transid};
- $params{amount} = $form->{amount};
- &process;
+ $form = shift @_;
+ my %params = %baseparams;
+ $params{transid} = $form->{transid};
+ $params{amount} = $form->{amount};
+ &process;
}
-
%declinemsg = (
- decline => 'Transaction declined by bank',
- avs => 'AVS failed: Address and/or Zip mismatch',
- cvv => 'CVV2 Failure: Check the CVV2 number and try again',
- call => 'Call customer service number on card to get authcode',
- expiredcard => 'This card has expired',
- carderror => 'This card number is invalid.',
- authexpired => 'The authorization expired. Can not postauth.',
- fraud => 'CrediGuard Fraud Score exceeded desired threshold',
- blacklist => 'CrediGuard Declined: blacklisted this transaction.',
- velocity => 'Crediguard declined: Too many transactions',
- dailylimit => 'Too many transactions in a day.',
- weeklylimit => 'Too many transactions in a week',
- monthlylimit => 'Too many transactions in a month'
+ decline => 'Transaction declined by bank',
+ avs => 'AVS failed: Address and/or Zip mismatch',
+ cvv => 'CVV2 Failure: Check the CVV2 number and try again',
+ call => 'Call customer service number on card to get authcode',
+ expiredcard => 'This card has expired',
+ carderror => 'This card number is invalid.',
+ authexpired => 'The authorization expired. Can not postauth.',
+ fraud => 'CrediGuard Fraud Score exceeded desired threshold',
+ blacklist => 'CrediGuard Declined: blacklisted this transaction.',
+ velocity => 'Crediguard declined: Too many transactions',
+ dailylimit => 'Too many transactions in a day.',
+ weeklylimit => 'Too many transactions in a week',
+ monthlylimit => 'Too many transactions in a month'
);
1;
diff --git a/LedgerSMB/CreditCard/TrustCommerce/Config.pm b/LedgerSMB/CreditCard/TrustCommerce/Config.pm
index bbe707be..86d026d8 100644
--- a/LedgerSMB/CreditCard/TrustCommerce/Config.pm
+++ b/LedgerSMB/CreditCard/TrustCommerce/Config.pm
@@ -1,5 +1,5 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
# Copyright (C) 2006
@@ -14,12 +14,11 @@
#
# TrustCommerce configuration Information goes Here
-
package TrustCommerce;
-
-%baseparams = ( custid => '000000',
- password => 'password',
+%baseparams = (
+ custid => '000000',
+ password => 'password',
);
$debug = 0;
diff --git a/LedgerSMB/DBObject.pm b/LedgerSMB/DBObject.pm
index 38e96adb..2b4b35da 100644
--- a/LedgerSMB/DBObject.pm
+++ b/LedgerSMB/DBObject.pm
@@ -1,3 +1,4 @@
+
=head1 NAME
LedgerSMB::DBObject - LedgerSMB class for building objects from db relations
@@ -41,161 +42,162 @@ use warnings;
our $AUTOLOAD;
sub AUTOLOAD {
- my ($self) = shift;
- my $type = Scalar::Util::blessed $self;
- $type =~ m/::(.*?)$/;
- $type = lc $1;
- print "Type: $type\n";
- $self->exec_method(procname => "$type" . "_" . $AUTOLOAD, args => \@_);
+ my ($self) = shift;
+ my $type = Scalar::Util::blessed $self;
+ $type =~ m/::(.*?)$/;
+ $type = lc $1;
+ print "Type: $type\n";
+ $self->exec_method( procname => "$type" . "_" . $AUTOLOAD, args => \@_ );
}
sub new {
- my $class = shift @_;
- my %args = @_;
- my $base = $args{base};
- my $self = bless {}, $class;
- if (! $base->isa('LedgerSMB')){
- $self->error("Constructor called without LedgerSMB object arg");
- }
-
- my $attr;
- $self->merge($base);
- $self;
+ my $class = shift @_;
+ my %args = @_;
+ my $base = $args{base};
+ my $self = bless {}, $class;
+ if ( !$base->isa('LedgerSMB') ) {
+ $self->error("Constructor called without LedgerSMB object arg");
+ }
+
+ my $attr;
+ $self->merge($base);
+ $self;
}
-
sub exec_method {
- my ($self) = shift @_;
- my %args = @_;
- my $funcname = $args{funcname};
- my @in_args = @{$args{args}};
- my @call_args;
-
- my $query =
- "SELECT proname, proargnames FROM pg_proc WHERE proname = ?";
- my $sth = $self->{dbh}->prepare($query);
- $sth->execute($funcname);
- my $ref;
-
- $ref = $sth->fetchrow_hashref('NAME_lc');
- my $args = $ref->{proargnames};
- $args =~ s/\{(.*)\}/$1/;
- my @proc_args = split /,/, $args;
-
- if (!$ref){ # no such function
- $self->error("No such function: ", $funcname);
- die;
- }
- my $m_name = $ref->{proname};
-
-
- if ($args){
- for my $arg (@proc_args){
- if ($arg =~ s/^in_//){
- push @call_args, $self->{$arg};
- }
- }
- }
- else {
- @call_args = @_;
- }
- $self->call_procedure(procname => $funcname, args => \@call_args);
+ my ($self) = shift @_;
+ my %args = @_;
+ my $funcname = $args{funcname};
+ my @in_args = @{ $args{args} };
+ my @call_args;
+
+ my $query = "SELECT proname, proargnames FROM pg_proc WHERE proname = ?";
+ my $sth = $self->{dbh}->prepare($query);
+ $sth->execute($funcname);
+ my $ref;
+
+ $ref = $sth->fetchrow_hashref('NAME_lc');
+ my $args = $ref->{proargnames};
+ $args =~ s/\{(.*)\}/$1/;
+ my @proc_args = split /,/, $args;
+
+ if ( !$ref ) { # no such function
+ $self->error( "No such function: ", $funcname );
+ die;
+ }
+ my $m_name = $ref->{proname};
+
+ if ($args) {
+ for my $arg (@proc_args) {
+ if ( $arg =~ s/^in_// ) {
+ push @call_args, $self->{$arg};
+ }
+ }
+ }
+ else {
+ @call_args = @_;
+ }
+ $self->call_procedure( procname => $funcname, args => \@call_args );
}
sub run_custom_queries {
- my ($self, $tablename, $query_type, $linenum) = @_;
- my $dbh = $self->{dbh};
- if ($query_type !~ /^(select|insert|update)$/i){
- # Commenting out this next bit until we figure out how the locale object
- # will operate. Chris
- #$self->error($locale->text(
- # "Passed incorrect query type to run_custom_queries."
- #));
- }
- my @rc;
- my %temphash;
- my @templist;
- my $did_insert;
- my @elements;
- my $query;
- my $ins_values;
- if ($linenum){
- $linenum = "_$linenum";
- }
-
- $query_type = uc($query_type);
- for (@{$self->{custom_db_fields}{$tablename}}){
- @elements = split (/:/, $_);
- push @{$temphash{$elements[0]}}, $elements[1];
- }
- for (keys %temphash){
- my @data;
- my $ins_values;
- $query = "$query_type ";
- if ($query_type eq 'UPDATE'){
- $query = "DELETE FROM $_ WHERE row_id = ?";
- my $sth = $dbh->prepare($query);
- $sth->execute->($self->{"id"."$linenum"})
- || $self->dberror($query);
- } elsif ($query_type eq 'INSERT'){
- $query .= " INTO $_ (";
- }
- my $first = 1;
- for (@{$temphash{$_}}){
- $query .= "$_";
- if ($query_type eq 'UPDATE'){
- $query .= '= ?';
- }
- $ins_values .= "?, ";
- $query .= ", ";
- $first = 0;
- if ($query_type eq 'UPDATE' or $query_type eq 'INSERT'){
- push @data, $self->{"$_$linenum"};
- }
- }
- if ($query_type ne 'INSERT'){
- $query =~ s/, $//;
- }
- if ($query_type eq 'SELECT'){
- $query .= " FROM $_";
- }
- if ($query_type eq 'SELECT' or $query_type eq 'UPDATE'){
- $query .= " WHERE row_id = ?";
- }
- if ($query_type eq 'INSERT'){
- $query .= " row_id) VALUES ($ins_values ?)";
- }
- if ($query_type eq 'SELECT'){
- push @rc, [ $query ];
- } else {
- unshift (@data, $query);
- push @rc, [ @data ];
- }
- }
- if ($query_type eq 'INSERT'){
- for (@rc){
- $query = shift (@{$_});
- my $sth = $dbh->prepare($query)
- || $self->db_error($query);
- $sth->execute(@{$_}, $self->{id})
- || $self->dberror($query);;
- $sth->finish;
- $did_insert = 1;
- }
- } elsif ($query_type eq 'UPDATE'){
- @rc = $self->run_custom_queries(
- $tablename, 'INSERT', $linenum);
- } elsif ($query_type eq 'SELECT'){
- for (@rc){
- $query = shift @{$_};
- my $sth = $self->{dbh}->prepare($query);
- $sth->execute($self->{id});
- my $ref = $sth->fetchrow_hashref('NAME_lc');
- $self->merge($ref, keys(%$ref));
- }
- }
- @rc;
+ my ( $self, $tablename, $query_type, $linenum ) = @_;
+ my $dbh = $self->{dbh};
+ if ( $query_type !~ /^(select|insert|update)$/i ) {
+
+ # Commenting out this next bit until we figure out how the locale object
+ # will operate. Chris
+ #$self->error($locale->text(
+ # "Passed incorrect query type to run_custom_queries."
+ #));
+ }
+ my @rc;
+ my %temphash;
+ my @templist;
+ my $did_insert;
+ my @elements;
+ my $query;
+ my $ins_values;
+
+ if ($linenum) {
+ $linenum = "_$linenum";
+ }
+
+ $query_type = uc($query_type);
+ for ( @{ $self->{custom_db_fields}{$tablename} } ) {
+ @elements = split( /:/, $_ );
+ push @{ $temphash{ $elements[0] } }, $elements[1];
+ }
+ for ( keys %temphash ) {
+ my @data;
+ my $ins_values;
+ $query = "$query_type ";
+ if ( $query_type eq 'UPDATE' ) {
+ $query = "DELETE FROM $_ WHERE row_id = ?";
+ my $sth = $dbh->prepare($query);
+ $sth->execute->( $self->{ "id" . "$linenum" } )
+ || $self->dberror($query);
+ }
+ elsif ( $query_type eq 'INSERT' ) {
+ $query .= " INTO $_ (";
+ }
+ my $first = 1;
+ for ( @{ $temphash{$_} } ) {
+ $query .= "$_";
+ if ( $query_type eq 'UPDATE' ) {
+ $query .= '= ?';
+ }
+ $ins_values .= "?, ";
+ $query .= ", ";
+ $first = 0;
+ if ( $query_type eq 'UPDATE' or $query_type eq 'INSERT' ) {
+ push @data, $self->{"$_$linenum"};
+ }
+ }
+ if ( $query_type ne 'INSERT' ) {
+ $query =~ s/, $//;
+ }
+ if ( $query_type eq 'SELECT' ) {
+ $query .= " FROM $_";
+ }
+ if ( $query_type eq 'SELECT' or $query_type eq 'UPDATE' ) {
+ $query .= " WHERE row_id = ?";
+ }
+ if ( $query_type eq 'INSERT' ) {
+ $query .= " row_id) VALUES ($ins_values ?)";
+ }
+ if ( $query_type eq 'SELECT' ) {
+ push @rc, [$query];
+ }
+ else {
+ unshift( @data, $query );
+ push @rc, [@data];
+ }
+ }
+ if ( $query_type eq 'INSERT' ) {
+ for (@rc) {
+ $query = shift( @{$_} );
+ my $sth = $dbh->prepare($query)
+ || $self->db_error($query);
+ $sth->execute( @{$_}, $self->{id} )
+ || $self->dberror($query);
+ $sth->finish;
+ $did_insert = 1;
+ }
+ }
+ elsif ( $query_type eq 'UPDATE' ) {
+ @rc = $self->run_custom_queries( $tablename, 'INSERT', $linenum );
+ }
+ elsif ( $query_type eq 'SELECT' ) {
+ for (@rc) {
+ $query = shift @{$_};
+ my $sth = $self->{dbh}->prepare($query);
+ $sth->execute( $self->{id} );
+ my $ref = $sth->fetchrow_hashref('NAME_lc');
+ $self->merge( $ref, keys(%$ref) );
+ }
+ }
+ @rc;
}
-
1;
diff --git a/LedgerSMB/Employee.pm b/LedgerSMB/Employee.pm
index 0512cf64..dd74be75 100644
--- a/LedgerSMB/Employee.pm
+++ b/LedgerSMB/Employee.pm
@@ -1,3 +1,4 @@
+
=head1 NAME
LedgerSMB::Employee - LedgerSMB class for managing Employees
@@ -34,25 +35,27 @@ use strict;
our $VERSION = '1.0.0';
sub save {
- my $self = shift;
- my $hashref = shift @{$self->exec_method(procname => "employee_save")};
- $self->merge($hashref, 'id');
+ my $self = shift;
+ my $hashref = shift @{ $self->exec_method( procname => "employee_save" ) };
+ $self->merge( $hashref, 'id' );
}
sub get {
- my $self = shift;
- my $hashref = shift @{$self->exec_method(procname => "employee_get")};
- $self->merge($hashref, keys %{$hashref});
+ my $self = shift;
+ my $hashref = shift @{ $self->exec_method( procname => "employee_get" ) };
+ $self->merge( $hashref, keys %{$hashref} );
}
sub list_managers {
- my $self = shift;
- $self->{manager_list} = $self->exec_method(procname => "employee_list_managers");
+ my $self = shift;
+ $self->{manager_list} =
+ $self->exec_method( procname => "employee_list_managers" );
}
sub search {
- my $self = shift;
- $self->{search_results} = $self->exec_method(procname => "employee_search");
+ my $self = shift;
+ $self->{search_results} =
+ $self->exec_method( procname => "employee_search" );
}
1;
diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm
index 9e6a403b..76f4877f 100644
--- a/LedgerSMB/Form.pm
+++ b/LedgerSMB/Form.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -33,284 +33,293 @@
#
#======================================================================
-use Math::BigFloat lib=>'GMP';
+use Math::BigFloat lib => 'GMP';
use LedgerSMB::Sysconfig;
package Form;
-
sub new {
- my $type = shift;
+ my $type = shift;
- my $argstr = shift;
+ my $argstr = shift;
- read(STDIN, $_, $ENV{CONTENT_LENGTH});
+ read( STDIN, $_, $ENV{CONTENT_LENGTH} );
- if ($argstr){
- $_ = $argstr;
- }
- elsif ($ENV{QUERY_STRING}) {
- $_ = $ENV{QUERY_STRING};
- }
+ if ($argstr) {
+ $_ = $argstr;
+ }
+ elsif ( $ENV{QUERY_STRING} ) {
+ $_ = $ENV{QUERY_STRING};
+ }
- elsif ($ARGV[0]) {
- $_ = $ARGV[0];
- }
-
- my $self = {};
- %$self = split /[&=]/;
- for (keys %$self) { $self->{$_} = unescape("", $self->{$_}) }
+ elsif ( $ARGV[0] ) {
+ $_ = $ARGV[0];
+ }
- if (substr($self->{action}, 0, 1) !~ /( |\.)/) {
- $self->{action} = lc $self->{action};
- $self->{action} =~ s/( |-|,|\#|\/|\.$)/_/g;
- $self->{nextsub} = lc $self->{nextsub};
- $self->{nextsub} =~ s/( |-|,|\#|\/|\.$)/_/g;
- }
+ my $self = {};
+ %$self = split /[&=]/;
+ for ( keys %$self ) { $self->{$_} = unescape( "", $self->{$_} ) }
- $self->{menubar} = 1 if $self->{path} =~ /lynx/i;
- #menubar will be deprecated, replaced with below
- $self->{lynx} = 1 if $self->{path} =~ /lynx/i;
+ if ( substr( $self->{action}, 0, 1 ) !~ /( |\.)/ ) {
+ $self->{action} = lc $self->{action};
+ $self->{action} =~ s/( |-|,|\#|\/|\.$)/_/g;
+ $self->{nextsub} = lc $self->{nextsub};
+ $self->{nextsub} =~ s/( |-|,|\#|\/|\.$)/_/g;
+ }
- $self->{version} = "1.3.0 Alpha 0 Pre";
- $self->{dbversion} = "1.2.0";
+ $self->{menubar} = 1 if $self->{path} =~ /lynx/i;
- bless $self, $type;
+ #menubar will be deprecated, replaced with below
+ $self->{lynx} = 1 if $self->{path} =~ /lynx/i;
- if ($self->{path} eq "bin/lynx"){
- $self->{menubar} = 1;
- #menubar will be deprecated, replaced with below
- $self->{lynx} = 1;
- $self->{path} = "bin/lynx";
- } else {
- $self->{path} = "bin/mozilla";
+ $self->{version} = "1.3.0 Alpha 0 Pre";
+ $self->{dbversion} = "1.2.0";
- }
+ bless $self, $type;
- if (($self->{script} =~ m#(\.\.|\\|/)#)){
- $self->error("Access Denied");
- }
-
+ if ( $self->{path} eq "bin/lynx" ) {
+ $self->{menubar} = 1;
- if (($self->{action} =~ /:/) || ($self->{nextsub} =~ /:/)){
- $self->error("Access Denied");
- }
- $self;
-}
+ #menubar will be deprecated, replaced with below
+ $self->{lynx} = 1;
+ $self->{path} = "bin/lynx";
+ }
+ else {
+ $self->{path} = "bin/mozilla";
+ }
-sub debug {
+ if ( ( $self->{script} =~ m#(\.\.|\\|/)# ) ) {
+ $self->error("Access Denied");
+ }
- my ($self, $file) = @_;
+ if ( ( $self->{action} =~ /:/ ) || ( $self->{nextsub} =~ /:/ ) ) {
+ $self->error("Access Denied");
+ }
+ $self;
+}
- if ($file) {
- open(FH, '>', "$file") or die $!;
- for (sort keys %$self) { print FH "$_ = $self->{$_}\n" }
- close(FH);
- } else {
- print "\n";
- for (sort keys %$self) { print "$_ = $self->{$_}\n" }
- }
+sub debug {
-}
+ my ( $self, $file ) = @_;
+ if ($file) {
+ open( FH, '>', "$file" ) or die $!;
+ for ( sort keys %$self ) { print FH "$_ = $self->{$_}\n" }
+ close(FH);
+ }
+ else {
+ print "\n";
+ for ( sort keys %$self ) { print "$_ = $self->{$_}\n" }
+ }
+
+}
sub escape {
- my ($self, $str, $beenthere) = @_;
+ my ( $self, $str, $beenthere ) = @_;
- # for Apache 2 we escape strings twice
- if (($ENV{SERVER_SIGNATURE} =~ /Apache\/2\.(\d+)\.(\d+)/) && !$beenthere) {
- $str = $self->escape($str, 1) if $1 == 0 && $2 < 44;
- }
+ # for Apache 2 we escape strings twice
+ if ( ( $ENV{SERVER_SIGNATURE} =~ /Apache\/2\.(\d+)\.(\d+)/ )
+ && !$beenthere )
+ {
+ $str = $self->escape( $str, 1 ) if $1 == 0 && $2 < 44;
+ }
- $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
- $str;
+ $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
+ $str;
}
-
sub unescape {
- my ($self, $str) = @_;
+ my ( $self, $str ) = @_;
- $str =~ tr/+/ /;
- $str =~ s/\\$//;
+ $str =~ tr/+/ /;
+ $str =~ s/\\$//;
- $str =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
- $str =~ s/\r?\n/\n/g;
+ $str =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
+ $str =~ s/\r?\n/\n/g;
- $str;
+ $str;
}
-
sub quote {
- my ($self, $str) = @_;
+ my ( $self, $str ) = @_;
- if ($str && ! ref($str)) {
- $str =~ s/"/&quot;/g;
- }
+ if ( $str && !ref($str) ) {
+ $str =~ s/"/&quot;/g;
+ }
- $str;
+ $str;
}
sub format_date {
- # takes an iso date in, and converts it to the date for printing
- my ($self, $date) = @_;
- my $datestring;
- if ($date =~ /^\d{4}\D/){ # is an ISO date
- $datestring = $self->{db_dateformat};
- my ($yyyy, $mm, $dd) = split(/\W/, $date);
- $datestring =~ s/y+/$yyyy/;
- $datestring =~ s/mm/$mm/;
- $datestring =~ s/dd/$dd/;
- } else { # return date
- $datestring = $date;
- }
- $datestring;
-}
+ # takes an iso date in, and converts it to the date for printing
+ my ( $self, $date ) = @_;
+ my $datestring;
+ if ( $date =~ /^\d{4}\D/ ) { # is an ISO date
+ $datestring = $self->{db_dateformat};
+ my ( $yyyy, $mm, $dd ) = split( /\W/, $date );
+ $datestring =~ s/y+/$yyyy/;
+ $datestring =~ s/mm/$mm/;
+ $datestring =~ s/dd/$dd/;
+ }
+ else { # return date
+ $datestring = $date;
+ }
+ $datestring;
+}
sub unquote {
- my ($self, $str) = @_;
+ my ( $self, $str ) = @_;
- if ($str && ! ref($str)) {
- $str =~ s/&quot;/"/g;
- }
+ if ( $str && !ref($str) ) {
+ $str =~ s/&quot;/"/g;
+ }
- $str;
+ $str;
}
-
sub hide_form {
- my $self = shift;
-
- if (@_) {
-
- for (@_) {
- print qq|<input type="hidden" name="$_" value="|.$self->quote($self->{$_}).qq|" />\n|
- }
-
- } else {
- delete $self->{header};
-
- for (sort keys %$self) {
- print qq|<input type="hidden" name="$_" value="|.$self->quote($self->{$_}).qq|" />\n|
- }
- }
+ my $self = shift;
+
+ if (@_) {
+
+ for (@_) {
+ print qq|<input type="hidden" name="$_" value="|
+ . $self->quote( $self->{$_} )
+ . qq|" />\n|;
+ }
+
+ }
+ else {
+ delete $self->{header};
+
+ for ( sort keys %$self ) {
+ print qq|<input type="hidden" name="$_" value="|
+ . $self->quote( $self->{$_} )
+ . qq|" />\n|;
+ }
+ }
}
-
sub error {
- my ($self, $msg) = @_;
+ my ( $self, $msg ) = @_;
- if ($ENV{GATEWAY_INTERFACE}) {
+ if ( $ENV{GATEWAY_INTERFACE} ) {
- $self->{msg} = $msg;
- $self->{format} = "html";
- $self->format_string('msg');
+ $self->{msg} = $msg;
+ $self->{format} = "html";
+ $self->format_string('msg');
- delete $self->{pre};
+ delete $self->{pre};
- if (!$self->{header}) {
- $self->header;
- }
+ if ( !$self->{header} ) {
+ $self->header;
+ }
- print qq|<body><h2 class="error">Error!</h2> <p><b>$self->{msg}</b></body>|;
+ print
+ qq|<body><h2 class="error">Error!</h2> <p><b>$self->{msg}</b></body>|;
- exit;
+ exit;
- } else {
+ }
+ else {
- if ($ENV{error_function}) {
- &{$ENV{error_function}}($msg);
- } else {
- die "Error: $msg\n";
- }
- }
+ if ( $ENV{error_function} ) {
+ &{ $ENV{error_function} }($msg);
+ }
+ else {
+ die "Error: $msg\n";
+ }
+ }
}
-
sub info {
- my ($self, $msg) = @_;
+ my ( $self, $msg ) = @_;
- if ($ENV{GATEWAY_INTERFACE}) {
- $msg =~ s/\n/<br>/g;
+ if ( $ENV{GATEWAY_INTERFACE} ) {
+ $msg =~ s/\n/<br>/g;
- delete $self->{pre};
+ delete $self->{pre};
- if (!$self->{header}) {
- $self->header;
- print qq| <body>|;
- $self->{header} = 1;
- }
+ if ( !$self->{header} ) {
+ $self->header;
+ print qq| <body>|;
+ $self->{header} = 1;
+ }
- print "<b>$msg</b>";
+ print "<b>$msg</b>";
- } else {
+ }
+ else {
- if ($ENV{info_function}) {
- &{ $ENV{info_function} }($msg);
- } else {
- print "$msg\n";
- }
- }
+ if ( $ENV{info_function} ) {
+ &{ $ENV{info_function} }($msg);
+ }
+ else {
+ print "$msg\n";
+ }
+ }
}
-
sub numtextrows {
- my ($self, $str, $cols, $maxrows) = @_;
+ my ( $self, $str, $cols, $maxrows ) = @_;
- my $rows = 0;
+ my $rows = 0;
- for (split /\n/, $str) {
- $rows += int (((length) - 2)/$cols) + 1
- }
+ for ( split /\n/, $str ) {
+ $rows += int( ( (length) - 2 ) / $cols ) + 1;
+ }
- $maxrows = $rows unless defined $maxrows;
+ $maxrows = $rows unless defined $maxrows;
- return ($rows > $maxrows) ? $maxrows : $rows;
+ return ( $rows > $maxrows ) ? $maxrows : $rows;
}
-
sub dberror {
- my ($self, $msg) = @_;
- $self->error("$msg\n".$DBI::errstr);
+ my ( $self, $msg ) = @_;
+ $self->error( "$msg\n" . $DBI::errstr );
}
-
sub isblank {
- my ($self, $name, $msg) = @_;
- $self->error($msg) if $self->{$name} =~ /^\s*$/;
+ my ( $self, $name, $msg ) = @_;
+ $self->error($msg) if $self->{$name} =~ /^\s*$/;
}
-
sub header {
- my ($self, $init, $headeradd) = @_;
+ my ( $self, $init, $headeradd ) = @_;
- return if $self->{header};
+ return if $self->{header};
- my ($stylesheet, $favicon, $charset);
+ my ( $stylesheet, $favicon, $charset );
- if ($ENV{GATEWAY_INTERFACE}) {
+ if ( $ENV{GATEWAY_INTERFACE} ) {
- if ($self->{stylesheet} && (-f "css/$self->{stylesheet}")) {
- $stylesheet = qq|<link rel="stylesheet" href="css/$self->{stylesheet}" type="text/css" title="LedgerSMB stylesheet" />\n|;
- }
+ if ( $self->{stylesheet} && ( -f "css/$self->{stylesheet}" ) ) {
+ $stylesheet =
+qq|<link rel="stylesheet" href="css/$self->{stylesheet}" type="text/css" title="LedgerSMB stylesheet" />\n|;
+ }
- if ($self->{charset}) {
- $charset = qq|<meta http-equiv="content-type" content="text/html; charset=$self->{charset}" />\n|;
- }
+ if ( $self->{charset} ) {
+ $charset =
+qq|<meta http-equiv="content-type" content="text/html; charset=$self->{charset}" />\n|;
+ }
- $self->{titlebar} = ($self->{title}) ? "$self->{title} - $self->{titlebar}" : $self->{titlebar};
+ $self->{titlebar} =
+ ( $self->{title} )
+ ? "$self->{title} - $self->{titlebar}"
+ : $self->{titlebar};
- print qq|Content-Type: text/html; charset=utf-8\n\n
+ print qq|Content-Type: text/html; charset=utf-8\n\n
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
@@ -326,1350 +335,1420 @@ sub header {
</head>
$self->{pre} \n|;
- }
+ }
- $self->{header} = 1;
+ $self->{header} = 1;
}
sub redirect {
- my ($self, $msg) = @_;
- use List::Util qw(first);
+ my ( $self, $msg ) = @_;
+ use List::Util qw(first);
- if ($self->{callback} || !$msg) {
+ if ( $self->{callback} || !$msg ) {
- main::redirect();
- } else {
+ main::redirect();
+ }
+ else {
- $self->info($msg);
- }
+ $self->info($msg);
+ }
}
-
sub sort_columns {
- my ($self, @columns) = @_;
+ my ( $self, @columns ) = @_;
- if ($self->{sort}) {
- if (@columns) {
- @columns = grep !/^$self->{sort}$/, @columns;
- splice @columns, 0, 0, $self->{sort};
- }
- }
+ if ( $self->{sort} ) {
+ if (@columns) {
+ @columns = grep !/^$self->{sort}$/, @columns;
+ splice @columns, 0, 0, $self->{sort};
+ }
+ }
- @columns;
+ @columns;
}
-
sub sort_order {
- my ($self, $columns, $ordinal) = @_;
+ my ( $self, $columns, $ordinal ) = @_;
- # setup direction
- if ($self->{direction}) {
+ # setup direction
+ if ( $self->{direction} ) {
- if ($self->{sort} eq $self->{oldsort}) {
+ if ( $self->{sort} eq $self->{oldsort} ) {
- if ($self->{direction} eq 'ASC') {
- $self->{direction} = "DESC";
- } else {
- $self->{direction} = "ASC";
- }
- }
+ if ( $self->{direction} eq 'ASC' ) {
+ $self->{direction} = "DESC";
+ }
+ else {
+ $self->{direction} = "ASC";
+ }
+ }
- } else {
+ }
+ else {
- $self->{direction} = "ASC";
- }
+ $self->{direction} = "ASC";
+ }
- $self->{oldsort} = $self->{sort};
+ $self->{oldsort} = $self->{sort};
- my @a = $self->sort_columns(@{$columns});
+ my @a = $self->sort_columns( @{$columns} );
- if (%$ordinal) {
- $a[0] = ($ordinal->{$a[$_]}) ? "$ordinal->{$a[0]} $self->{direction}" : "$a[0] $self->{direction}";
+ if (%$ordinal) {
+ $a[0] =
+ ( $ordinal->{ $a[$_] } )
+ ? "$ordinal->{$a[0]} $self->{direction}"
+ : "$a[0] $self->{direction}";
- for (1 .. $#a) {
- $a[$_] = $ordinal->{$a[$_]} if $ordinal->{$a[$_]}
- }
+ for ( 1 .. $#a ) {
+ $a[$_] = $ordinal->{ $a[$_] } if $ordinal->{ $a[$_] };
+ }
- } else {
- $a[0] .= " $self->{direction}";
- }
+ }
+ else {
+ $a[0] .= " $self->{direction}";
+ }
- $sortorder = join ',', @a;
- $sortorder;
+ $sortorder = join ',', @a;
+ $sortorder;
}
-
sub format_amount {
- my ($self, $myconfig, $amount, $places, $dash) = @_;
-
- my $negative ;
- if ($amount){
- $amount = $self->parse_amount($myconfig, $amount);
- $negative = ($amount < 0);
- $amount =~ s/-//;
- }
-
- if ($places =~ /\d+/) {
- #$places = 4 if $places == 2;
- $amount = $self->round_amount($amount, $places);
- }
-
- # is the amount negative
-
- # Parse $myconfig->{numberformat}
-
-
-
- my ($ts, $ds) = ($1, $2);
-
- if ($amount) {
-
- if ($myconfig->{numberformat}) {
-
- my ($whole, $dec) = split /\./, "$amount";
- $amount = join '', reverse split //, $whole;
-
- if ($places) {
- $dec .= "0" x $places;
- $dec = substr($dec, 0, $places);
- }
-
- if ($myconfig->{numberformat} eq '1,000.00') {
- $amount =~ s/\d{3,}?/$&,/g;
- $amount =~ s/,$//;
- $amount = join '', reverse split //, $amount;
- $amount .= "\.$dec" if ($dec ne "");
- }
-
- if ($myconfig->{numberformat} eq '1 000.00') {
- $amount =~ s/\d{3,}?/$& /g;
- $amount =~ s/\s$//;
- $amount = join '', reverse split //, $amount;
- $amount .= "\.$dec" if ($dec ne "");
- }
-
- if ($myconfig->{numberformat} eq "1'000.00") {
- $amount =~ s/\d{3,}?/$&'/g;
- $amount =~ s/'$//;
- $amount = join '', reverse split //, $amount;
- $amount .= "\.$dec" if ($dec ne "");
- }
-
- if ($myconfig->{numberformat} eq '1.000,00') {
- $amount =~ s/\d{3,}?/$&./g;
- $amount =~ s/\.$//;
- $amount = join '', reverse split //, $amount;
- $amount .= ",$dec" if ($dec ne "");
- }
-
- if ($myconfig->{numberformat} eq '1000,00') {
- $amount = "$whole";
- $amount .= ",$dec" if ($dec ne "");
- }
-
- if ($myconfig->{numberformat} eq '1000.00') {
- $amount = "$whole";
- $amount .= ".$dec" if ($dec ne "");
- }
-
- if ($dash =~ /-/) {
- $amount = ($negative) ? "($amount)" : "$amount";
- } elsif ($dash =~ /DRCR/) {
- $amount = ($negative) ? "$amount DR" : "$amount CR";
- } else {
- $amount = ($negative) ? "-$amount" : "$amount";
- }
- }
-
- } else {
-
- if ($dash eq "0" && $places) {
-
- if ($myconfig->{numberformat} eq '1.000,00') {
- $amount = "0".","."0" x $places;
- } else {
- $amount = "0"."."."0" x $places;
- }
-
- } else {
- $amount = ($dash ne "") ? "$dash" : "";
- }
- }
-
- $amount;
+ my ( $self, $myconfig, $amount, $places, $dash ) = @_;
+
+ my $negative;
+ if ($amount) {
+ $amount = $self->parse_amount( $myconfig, $amount );
+ $negative = ( $amount < 0 );
+ $amount =~ s/-//;
+ }
+
+ if ( $places =~ /\d+/ ) {
+
+ #$places = 4 if $places == 2;
+ $amount = $self->round_amount( $amount, $places );
+ }
+
+ # is the amount negative
+
+ # Parse $myconfig->{numberformat}
+
+ my ( $ts, $ds ) = ( $1, $2 );
+
+ if ($amount) {
+
+ if ( $myconfig->{numberformat} ) {
+
+ my ( $whole, $dec ) = split /\./, "$amount";
+ $amount = join '', reverse split //, $whole;
+
+ if ($places) {
+ $dec .= "0" x $places;
+ $dec = substr( $dec, 0, $places );
+ }
+
+ if ( $myconfig->{numberformat} eq '1,000.00' ) {
+ $amount =~ s/\d{3,}?/$&,/g;
+ $amount =~ s/,$//;
+ $amount = join '', reverse split //, $amount;
+ $amount .= "\.$dec" if ( $dec ne "" );
+ }
+
+ if ( $myconfig->{numberformat} eq '1 000.00' ) {
+ $amount =~ s/\d{3,}?/$& /g;
+ $amount =~ s/\s$//;
+ $amount = join '', reverse split //, $amount;
+ $amount .= "\.$dec" if ( $dec ne "" );
+ }
+
+ if ( $myconfig->{numberformat} eq "1'000.00" ) {
+ $amount =~ s/\d{3,}?/$&'/g;
+ $amount =~ s/'$//;
+ $amount = join '', reverse split //, $amount;
+ $amount .= "\.$dec" if ( $dec ne "" );
+ }
+
+ if ( $myconfig->{numberformat} eq '1.000,00' ) {
+ $amount =~ s/\d{3,}?/$&./g;
+ $amount =~ s/\.$//;
+ $amount = join '', reverse split //, $amount;
+ $amount .= ",$dec" if ( $dec ne "" );
+ }
+
+ if ( $myconfig->{numberformat} eq '1000,00' ) {
+ $amount = "$whole";
+ $amount .= ",$dec" if ( $dec ne "" );
+ }
+
+ if ( $myconfig->{numberformat} eq '1000.00' ) {
+ $amount = "$whole";
+ $amount .= ".$dec" if ( $dec ne "" );
+ }
+
+ if ( $dash =~ /-/ ) {
+ $amount = ($negative) ? "($amount)" : "$amount";
+ }
+ elsif ( $dash =~ /DRCR/ ) {
+ $amount = ($negative) ? "$amount DR" : "$amount CR";
+ }
+ else {
+ $amount = ($negative) ? "-$amount" : "$amount";
+ }
+ }
+
+ }
+ else {
+
+ if ( $dash eq "0" && $places ) {
+
+ if ( $myconfig->{numberformat} eq '1.000,00' ) {
+ $amount = "0" . "," . "0" x $places;
+ }
+ else {
+ $amount = "0" . "." . "0" x $places;
+ }
+
+ }
+ else {
+ $amount = ( $dash ne "" ) ? "$dash" : "";
+ }
+ }
+
+ $amount;
}
-
sub parse_amount {
- my ($self, $myconfig, $amount) = @_;
-
- if ($amount eq '' or $amount == undef){
- return 0;
- }
-
- if (UNIVERSAL::isa($amount, 'Math::BigFloat')){ # Amount may not be an object
- return $amount;
- }
- my $numberformat = $myconfig->{numberformat};
-
-
- if (($numberformat eq '1.000,00') ||
- ($numberformat eq '1000,00')) {
-
- $amount =~ s/\.//g;
- $amount =~ s/,/./;
- }
- if ($numberformat eq '1 000.00'){
- $amount =~ s/\s//g;
- }
-
- if ($numberformat eq "1'000.00") {
- $amount =~ s/'//g;
- }
-
-
- $amount =~ s/,//g;
- if ($amount =~ s/\((\d*\.?\d*)\)/$1/){
- $amount = $1 * -1;
- }
- if ($amount =~ s/(\d*\.?\d*)\s?DR/$1/){
- $amount = $1 * -1;
- }
- $amount =~ s/\s?CR//;
- $amount = new Math::BigFloat($amount);
- return ($amount * 1);
+ my ( $self, $myconfig, $amount ) = @_;
+
+ if ( $amount eq '' or $amount == undef ) {
+ return 0;
+ }
+
+ if ( UNIVERSAL::isa( $amount, 'Math::BigFloat' ) )
+ { # Amount may not be an object
+ return $amount;
+ }
+ my $numberformat = $myconfig->{numberformat};
+
+ if ( ( $numberformat eq '1.000,00' )
+ || ( $numberformat eq '1000,00' ) )
+ {
+
+ $amount =~ s/\.//g;
+ $amount =~ s/,/./;
+ }
+ if ( $numberformat eq '1 000.00' ) {
+ $amount =~ s/\s//g;
+ }
+
+ if ( $numberformat eq "1'000.00" ) {
+ $amount =~ s/'//g;
+ }
+
+ $amount =~ s/,//g;
+ if ( $amount =~ s/\((\d*\.?\d*)\)/$1/ ) {
+ $amount = $1 * -1;
+ }
+ if ( $amount =~ s/(\d*\.?\d*)\s?DR/$1/ ) {
+ $amount = $1 * -1;
+ }
+ $amount =~ s/\s?CR//;
+ $amount = new Math::BigFloat($amount);
+ return ( $amount * 1 );
}
-
sub round_amount {
- my ($self, $amount, $places) = @_;
+ my ( $self, $amount, $places ) = @_;
- # These rounding rules follow from the previous implementation.
- # They should be changed to allow different rules for different accounts.
- Math::BigFloat->round_mode('+inf') if $amount >= 0;
- Math::BigFloat->round_mode('-inf') if $amount < 0;
+ # These rounding rules follow from the previous implementation.
+ # They should be changed to allow different rules for different accounts.
+ Math::BigFloat->round_mode('+inf') if $amount >= 0;
+ Math::BigFloat->round_mode('-inf') if $amount < 0;
- $amount = Math::BigFloat->new($amount)->ffround(-$places) if $places >= 0;
- $amount = Math::BigFloat->new($amount)->ffround(-($places-1)) if $places < 0;
+ $amount = Math::BigFloat->new($amount)->ffround( -$places ) if $places >= 0;
+ $amount = Math::BigFloat->new($amount)->ffround( -( $places - 1 ) )
+ if $places < 0;
- return $amount;
+ return $amount;
}
sub callproc {
- my $procname = shift @_;
- my $argstr = "";
- my @results;
- for (1 .. $#_){
- $argstr .= "?, ";
- }
- $argstr =~ s/\, $//;
- $query = "SELECT * FROM $procname";
- $query =~ s/\(\)/$argstr/;
- my $sth = $self->{dbh}->prepare($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)){
- push @results, $ref;
- }
- @results;
+ my $procname = shift @_;
+ my $argstr = "";
+ my @results;
+ for ( 1 .. $#_ ) {
+ $argstr .= "?, ";
+ }
+ $argstr =~ s/\, $//;
+ $query = "SELECT * FROM $procname";
+ $query =~ s/\(\)/$argstr/;
+ my $sth = $self->{dbh}->prepare($query);
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @results, $ref;
+ }
+ @results;
}
sub get_my_emp_num {
- my ($self, $myconfig, $form) = @_;
- %myconfig = %{$myconfig};
- my $dbh = $form->{dbh};
- # we got a connection, check the version
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+ %myconfig = %{$myconfig};
+ my $dbh = $form->{dbh};
+
+ # we got a connection, check the version
+ my $query = qq|
SELECT employeenumber FROM employees
WHERE login = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{login}) || $form->dberror($query);
- $sth->execute;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{login} ) || $form->dberror($query);
+ $sth->execute;
- my ($id) = $sth->fetchrow_array;
- $sth->finish;
- $form->{'emp_num'} = $id;
+ my ($id) = $sth->fetchrow_array;
+ $sth->finish;
+ $form->{'emp_num'} = $id;
}
sub parse_template {
- my ($self, $myconfig) = @_;
-
- my ($chars_per_line, $lines_on_first_page, $lines_on_second_page) = (0, 0, 0);
- my ($current_page, $current_line) = (1, 1);
- print STDERR "Using deprecated Form::parse_template function\n";
- my $pagebreak = "";
- my $sum = 0;
-
- my $subdir = "";
- my $err = "";
-
- my %include = ();
- my $ok;
- $self->{images} = "${LedgerSMB::Sysconfig::images}/$self->{templates}";
-
- if ($self->{language_code}) {
- if ($self->{language_code} =~ /(\.\.|\/|\*)/){
- $self->error("Invalid Language Code");
- }
-
- if (-f "$self->{templates}/$self->{language_code}/$self->{IN}") {
- open(IN, '<', "$self->{templates}/$self->{language_code}/$self->{IN}") or $self->error("$self->{IN} : $!");
- } else {
- open(IN, '<', "$self->{templates}/$self->{IN}") or $self->error("$self->{IN} : $!");
- }
-
- } else {
- open(IN, '<', "$self->{templates}/$self->{IN}") or $self->error("$self->{IN} : $!");
- }
-
- @_ = <IN>;
- close(IN);
-
- $self->{copies} = 1 if (($self->{copies} *= 1) <= 0);
-
- # OUT is used for the media, screen, printer, email
- # for postscript we store a copy in a temporary file
- my $fileid = time;
- my $tmpfile = $self->{IN};
- $tmpfile =~ s/\./_$self->{fileid}./ if $self->{fileid};
- $self->{tmpfile} = "${LedgerSMB::Sysconfig::userspath}/${fileid}_${tmpfile}";
+ my ( $self, $myconfig ) = @_;
+
+ my ( $chars_per_line, $lines_on_first_page, $lines_on_second_page ) =
+ ( 0, 0, 0 );
+ my ( $current_page, $current_line ) = ( 1, 1 );
+ print STDERR "Using deprecated Form::parse_template function\n";
+ my $pagebreak = "";
+ my $sum = 0;
+
+ my $subdir = "";
+ my $err = "";
+
+ my %include = ();
+ my $ok;
+ $self->{images} = "${LedgerSMB::Sysconfig::images}/$self->{templates}";
+
+ if ( $self->{language_code} ) {
+ if ( $self->{language_code} =~ /(\.\.|\/|\*)/ ) {
+ $self->error("Invalid Language Code");
+ }
+
+ if ( -f "$self->{templates}/$self->{language_code}/$self->{IN}" ) {
+ open( IN, '<',
+ "$self->{templates}/$self->{language_code}/$self->{IN}" )
+ or $self->error("$self->{IN} : $!");
+ }
+ else {
+ open( IN, '<', "$self->{templates}/$self->{IN}" )
+ or $self->error("$self->{IN} : $!");
+ }
+
+ }
+ else {
+ open( IN, '<', "$self->{templates}/$self->{IN}" )
+ or $self->error("$self->{IN} : $!");
+ }
+
+ @_ = <IN>;
+ close(IN);
+
+ $self->{copies} = 1 if ( ( $self->{copies} *= 1 ) <= 0 );
+
+ # OUT is used for the media, screen, printer, email
+ # for postscript we store a copy in a temporary file
+ my $fileid = time;
+ my $tmpfile = $self->{IN};
+ $tmpfile =~ s/\./_$self->{fileid}./ if $self->{fileid};
+ $self->{tmpfile} =
+ "${LedgerSMB::Sysconfig::userspath}/${fileid}_${tmpfile}";
my %temphash;
- if ($self->{format} =~ /(postscript|pdf)/ || $self->{media} eq 'email') {
- $temphash{out} = $self->{OUT};
- $self->{OUT} = "$self->{tmpfile}";
+ if ( $self->{format} =~ /(postscript|pdf)/ || $self->{media} eq 'email' ) {
+ $temphash{out} = $self->{OUT};
+ $self->{OUT} = "$self->{tmpfile}";
$temphash{printmode} = $self->{printmode};
- $self->{printmode} = '>';
- }
-
- if ($self->{OUT}) {
- open(OUT, $self->{printmode}, "$self->{OUT}") or $self->error("$self->{OUT} : $!");
-
- } else {
- open(OUT, ">-") or $self->error("STDOUT : $!");
- $self->header;
- }
-
- # first we generate a tmpfile
- # read file and replace <?lsmb variable ?>
- while ($_ = shift) {
-
- $par = "";
- $var = $_;
-
- # detect pagebreak block and its parameters
- if (/<\?lsmb pagebreak ([0-9]+) ([0-9]+) ([0-9]+) \?>/) {
- $chars_per_line = $1;
- $lines_on_first_page = $2;
- $lines_on_second_page = $3;
-
- while ($_ = shift) {
- last if (/<\?lsmb end pagebreak \?>/);
- $pagebreak .= $_;
- }
- }
-
- if (/<\?lsmb foreach /) {
-
- # this one we need for the count
- chomp $var;
- $var =~ s/.*?<\?lsmb foreach (.+?) \?>/$1/;
- while ($_ = shift) {
- last if (/<\?lsmb end $var \?>/);
-
- # store line in $par
- $par .= $_;
- }
-
- # display contents of $self->{number}[] array
- for $i (0 .. $#{ $self->{$var} }) {
-
- if ($var =~ /^(part|service)$/) {
- next if $self->{$var}[$i] eq 'NULL';
- }
-
- # Try to detect whether a manual page break is necessary
- # but only if there was a <?lsmb pagebreak ... ?> block before
-
- if ($var eq 'number' || $var eq 'part' || $var eq 'service') {
-
- if ($chars_per_line && defined $self->{$var}) {
-
- my $line;
- my $lines = 0;
- my @d = qw(description);
- push @d, "itemnotes" if $self->{countitemnotes};
+ $self->{printmode} = '>';
+ }
+
+ if ( $self->{OUT} ) {
+ open( OUT, $self->{printmode}, "$self->{OUT}" )
+ or $self->error("$self->{OUT} : $!");
+
+ }
+ else {
+ open( OUT, ">-" ) or $self->error("STDOUT : $!");
+ $self->header;
+ }
+
+ # first we generate a tmpfile
+ # read file and replace <?lsmb variable ?>
+ while ( $_ = shift ) {
+
+ $par = "";
+ $var = $_;
+
+ # detect pagebreak block and its parameters
+ if (/<\?lsmb pagebreak ([0-9]+) ([0-9]+) ([0-9]+) \?>/) {
+ $chars_per_line = $1;
+ $lines_on_first_page = $2;
+ $lines_on_second_page = $3;
+
+ while ( $_ = shift ) {
+ last if (/<\?lsmb end pagebreak \?>/);
+ $pagebreak .= $_;
+ }
+ }
+
+ if (/<\?lsmb foreach /) {
+
+ # this one we need for the count
+ chomp $var;
+ $var =~ s/.*?<\?lsmb foreach (.+?) \?>/$1/;
+ while ( $_ = shift ) {
+ last if (/<\?lsmb end $var \?>/);
+
+ # store line in $par
+ $par .= $_;
+ }
+
+ # display contents of $self->{number}[] array
+ for $i ( 0 .. $#{ $self->{$var} } ) {
- foreach my $item (@d) {
+ if ( $var =~ /^(part|service)$/ ) {
+ next if $self->{$var}[$i] eq 'NULL';
+ }
- if ($self->{$item}[$i]) {
+ # Try to detect whether a manual page break is necessary
+ # but only if there was a <?lsmb pagebreak ... ?> block before
- foreach $line (split /\r?\n/, $self->{$item}[$i]) {
- $lines++;
- $lines += int(length($line) / $chars_per_line);
- }
- }
- }
+ if ( $var eq 'number' || $var eq 'part' || $var eq 'service' ) {
- my $lpp;
+ if ( $chars_per_line && defined $self->{$var} ) {
- if ($current_page == 1) {
- $lpp = $lines_on_first_page;
- } else {
- $lpp = $lines_on_second_page;
- }
+ my $line;
+ my $lines = 0;
+ my @d = qw(description);
+ push @d, "itemnotes" if $self->{countitemnotes};
+
+ foreach my $item (@d) {
+
+ if ( $self->{$item}[$i] ) {
+
+ foreach $line ( split /\r?\n/,
+ $self->{$item}[$i] )
+ {
+ $lines++;
+ $lines +=
+ int( length($line) / $chars_per_line );
+ }
+ }
+ }
- # Yes we need a manual page break
- if (($current_line + $lines) > $lpp) {
- my $pb = $pagebreak;
+ my $lpp;
- # replace the special variables <?lsmb sumcarriedforward ?>
- # and <?lsmb lastpage ?>
- my $psum = $self->format_amount($myconfig, $sum, 2);
- $pb =~ s/<\?lsmb sumcarriedforward \?>/$psum/g;
- $pb =~ s/<\?lsmb lastpage \?>/$current_page/g;
+ if ( $current_page == 1 ) {
+ $lpp = $lines_on_first_page;
+ }
+ else {
+ $lpp = $lines_on_second_page;
+ }
- # only "normal" variables are supported here
- # (no <?lsmb if, no <?lsmb foreach, no <?lsmb include)
- $pb =~ s/<\?lsmb (.+?) \?>/$self->{$1}/g;
+ # Yes we need a manual page break
+ if ( ( $current_line + $lines ) > $lpp ) {
+ my $pb = $pagebreak;
- # page break block is ready to rock
- print(OUT $pb);
- $current_page++;
- $current_line = 1;
- $lines = 0;
- }
+ # replace the special variables <?lsmb sumcarriedforward ?>
+ # and <?lsmb lastpage ?>
+ my $psum =
+ $self->format_amount( $myconfig, $sum, 2 );
+ $pb =~ s/<\?lsmb sumcarriedforward \?>/$psum/g;
+ $pb =~ s/<\?lsmb lastpage \?>/$current_page/g;
- $current_line += $lines;
- }
+ # only "normal" variables are supported here
+ # (no <?lsmb if, no <?lsmb foreach, no <?lsmb include)
+ $pb =~ s/<\?lsmb (.+?) \?>/$self->{$1}/g;
- $sum += $self->parse_amount($myconfig, $self->{linetotal}[$i]);
- }
+ # page break block is ready to rock
+ print( OUT $pb );
+ $current_page++;
+ $current_line = 1;
+ $lines = 0;
+ }
+
+ $current_line += $lines;
+ }
+
+ $sum +=
+ $self->parse_amount( $myconfig, $self->{linetotal}[$i] );
+ }
- # don't parse par, we need it for each line
- print OUT $self->format_line($par, $i);
- }
- next;
- }
+ # don't parse par, we need it for each line
+ print OUT $self->format_line( $par, $i );
+ }
+ next;
+ }
- # if not comes before if!
- if (/<\?lsmb if not /) {
+ # if not comes before if!
+ if (/<\?lsmb if not /) {
- # check if it is not set and display
- chop;
- s/.*?<\?lsmb if not (.+?) \?>/$1/;
+ # check if it is not set and display
+ chop;
+ s/.*?<\?lsmb if not (.+?) \?>/$1/;
- if (! $self->{$_}) {
+ if ( !$self->{$_} ) {
- while ($_ = shift) {
- last if (/<\?lsmb end /);
+ while ( $_ = shift ) {
+ last if (/<\?lsmb end /);
- # store line in $par
- $par .= $_;
- }
+ # store line in $par
+ $par .= $_;
+ }
- $_ = $par;
+ $_ = $par;
- } else {
+ }
+ else {
- while ($_ = shift) {
- last if (/<\?lsmb end /);
- }
+ while ( $_ = shift ) {
+ last if (/<\?lsmb end /);
+ }
- next;
- }
- }
+ next;
+ }
+ }
- if (/<\?lsmb if /) {
+ if (/<\?lsmb if /) {
- # check if it is set and display
- chop;
- s/.*?<\?lsmb if (.+?) \?>/$1/;
+ # check if it is set and display
+ chop;
+ s/.*?<\?lsmb if (.+?) \?>/$1/;
- if (/\s/) {
- @a = split;
- $ok = eval "$self->{$a[0]} $a[1] $a[2]";
- } else {
- $ok = $self->{$_};
- }
+ if (/\s/) {
+ @a = split;
+ $ok = eval "$self->{$a[0]} $a[1] $a[2]";
+ }
+ else {
+ $ok = $self->{$_};
+ }
- if ($ok) {
- while ($_ = shift) {
- last if (/<\?lsmb end /);
- # store line in $par
- $par .= $_;
- }
+ if ($ok) {
+ while ( $_ = shift ) {
+ last if (/<\?lsmb end /);
- $_ = $par;
+ # store line in $par
+ $par .= $_;
+ }
- } else {
+ $_ = $par;
- while ($_ = shift) {
- last if (/<\?lsmb end /);
- }
+ }
+ else {
- next;
- }
- }
+ while ( $_ = shift ) {
+ last if (/<\?lsmb end /);
+ }
- # check for <?lsmb include filename ?>
- if (/<\?lsmb include /) {
+ next;
+ }
+ }
- # get the filename
- chomp $var;
- $var =~ s/.*?<\?lsmb include (.+?) \?>/$1/;
+ # check for <?lsmb include filename ?>
+ if (/<\?lsmb include /) {
- # remove / .. for security reasons
- $var =~ s/(\/|\.\.)//g;
+ # get the filename
+ chomp $var;
+ $var =~ s/.*?<\?lsmb include (.+?) \?>/$1/;
- # assume loop after 10 includes of the same file
- next if ($include{$var} > 10);
+ # remove / .. for security reasons
+ $var =~ s/(\/|\.\.)//g;
- unless (open(INC, '<', "$self->{templates}/$self->{language_code}/$var")) {
- $err = $!;
- $self->cleanup;
- $self->error("$self->{templates}/$self->{language_code}/$var : $err");
- }
+ # assume loop after 10 includes of the same file
+ next if ( $include{$var} > 10 );
- unshift(@_, <INC>);
- close(INC);
+ unless (
+ open( INC, '<', "$self->{templates}/$self->{language_code}/$var"
+ )
+ )
+ {
+ $err = $!;
+ $self->cleanup;
+ $self->error(
+ "$self->{templates}/$self->{language_code}/$var : $err");
+ }
- $include{$var}++;
+ unshift( @_, <INC> );
+ close(INC);
- next;
- }
+ $include{$var}++;
- print OUT $self->format_line($_);
+ next;
+ }
- }
+ print OUT $self->format_line($_);
- close(OUT);
+ }
- delete $self->{countitemnotes};
+ close(OUT);
- # Convert the tex file to postscript
- if ($self->{format} =~ /(postscript|pdf)/) {
+ delete $self->{countitemnotes};
- use Cwd;
- $self->{cwd} = cwd();
- $self->{tmpdir} = "$self->{cwd}/${LedgerSMB::Sysconfig::userspath}";
- $self->{tmpdir} = "${LedgerSMB::Sysconfig::userspath}" if
- ${LedgerSMB::Sysconfig::userspath} =~ /^\//;
+ # Convert the tex file to postscript
+ if ( $self->{format} =~ /(postscript|pdf)/ ) {
- unless (chdir("${LedgerSMB::Sysconfig::userspath}")) {
- $err = $!;
- $self->cleanup;
- $self->error("chdir : $err");
- }
+ use Cwd;
+ $self->{cwd} = cwd();
+ $self->{tmpdir} = "$self->{cwd}/${LedgerSMB::Sysconfig::userspath}";
+ $self->{tmpdir} = "${LedgerSMB::Sysconfig::userspath}"
+ if ${LedgerSMB::Sysconfig::userspath} =~ /^\//;
- $self->{tmpfile} =~ s/${LedgerSMB::Sysconfig::userspath}\///g;
+ unless ( chdir("${LedgerSMB::Sysconfig::userspath}") ) {
+ $err = $!;
+ $self->cleanup;
+ $self->error("chdir : $err");
+ }
- $self->{errfile} = $self->{tmpfile};
- $self->{errfile} =~ s/tex$/err/;
+ $self->{tmpfile} =~ s/${LedgerSMB::Sysconfig::userspath}\///g;
- my $r = 1;
- if ($self->{format} eq 'postscript') {
+ $self->{errfile} = $self->{tmpfile};
+ $self->{errfile} =~ s/tex$/err/;
- system("latex --interaction=nonstopmode $self->{tmpfile} > $self->{errfile}");
+ my $r = 1;
+ if ( $self->{format} eq 'postscript' ) {
- while ($self->rerun_latex) {
- system("latex --interaction=nonstopmode $self->{tmpfile} > $self->{errfile}");
- last if ++$r > 4;
- }
+ system(
+"latex --interaction=nonstopmode $self->{tmpfile} > $self->{errfile}"
+ );
- $self->{tmpfile} =~ s/tex$/dvi/;
- $self->error($self->cleanup) if ! (-f $self->{tmpfile});
+ while ( $self->rerun_latex ) {
+ system(
+"latex --interaction=nonstopmode $self->{tmpfile} > $self->{errfile}"
+ );
+ last if ++$r > 4;
+ }
- system("dvips $self->{tmpfile} -o -q");
- $self->error($self->cleanup."dvips : $!") if ($?);
- $self->{tmpfile} =~ s/dvi$/ps/;
- }
+ $self->{tmpfile} =~ s/tex$/dvi/;
+ $self->error( $self->cleanup ) if !( -f $self->{tmpfile} );
- if ($self->{format} eq 'pdf') {
- system("pdflatex --interaction=nonstopmode $self->{tmpfile} > $self->{errfile}");
+ system("dvips $self->{tmpfile} -o -q");
+ $self->error( $self->cleanup . "dvips : $!" ) if ($?);
+ $self->{tmpfile} =~ s/dvi$/ps/;
+ }
- while ($self->rerun_latex) {
- system("pdflatex --interaction=nonstopmode $self->{tmpfile} > $self->{errfile}");
- last if ++$r > 4;
- }
+ if ( $self->{format} eq 'pdf' ) {
+ system(
+"pdflatex --interaction=nonstopmode $self->{tmpfile} > $self->{errfile}"
+ );
- $self->{tmpfile} =~ s/tex$/pdf/;
- $self->error($self->cleanup) if ! (-f $self->{tmpfile});
- }
- }
+ while ( $self->rerun_latex ) {
+ system(
+"pdflatex --interaction=nonstopmode $self->{tmpfile} > $self->{errfile}"
+ );
+ last if ++$r > 4;
+ }
+ $self->{tmpfile} =~ s/tex$/pdf/;
+ $self->error( $self->cleanup ) if !( -f $self->{tmpfile} );
+ }
+ }
- if ($self->{format} =~ /(postscript|pdf)/ || $self->{media} eq 'email') {
+ if ( $self->{format} =~ /(postscript|pdf)/ || $self->{media} eq 'email' ) {
- if ($self->{media} eq 'email') {
+ if ( $self->{media} eq 'email' ) {
- use LedgerSMB::Mailer;
+ use LedgerSMB::Mailer;
- my $mail = new Mailer;
+ my $mail = new Mailer;
- for (qw(cc bcc subject message version format charset)) {
- $mail->{$_} = $self->{$_}
- }
+ for (qw(cc bcc subject message version format charset)) {
+ $mail->{$_} = $self->{$_};
+ }
- $mail->{to} = qq|$self->{email}|;
- $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
- $mail->{notify} = $self->{notify};
- $mail->{fileid} = "$fileid.";
+ $mail->{to} = qq|$self->{email}|;
+ $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
+ $mail->{notify} = $self->{notify};
+ $mail->{fileid} = "$fileid.";
- # if we send html or plain text inline
- if (($self->{format} =~ /(html|txt)/) &&
- ($self->{sendmode} eq 'inline')) {
+ # if we send html or plain text inline
+ if ( ( $self->{format} =~ /(html|txt)/ )
+ && ( $self->{sendmode} eq 'inline' ) )
+ {
- my $br = "";
- $br = "<br>" if $self->{format} eq 'html';
+ my $br = "";
+ $br = "<br>" if $self->{format} eq 'html';
- $mail->{contenttype} = "text/$self->{format}";
+ $mail->{contenttype} = "text/$self->{format}";
- $mail->{message} =~ s/\r?\n/$br\n/g;
- $myconfig->{signature} =~ s/\\n/$br\n/g;
- $mail->{message} .= "$br\n-- $br\n$myconfig->{signature}\n$br" if $myconfig->{signature};
+ $mail->{message} =~ s/\r?\n/$br\n/g;
+ $myconfig->{signature} =~ s/\\n/$br\n/g;
+ $mail->{message} .= "$br\n-- $br\n$myconfig->{signature}\n$br"
+ if $myconfig->{signature};
- unless (open(IN, '<', $self->{tmpfile})) {
- $err = $!;
- $self->cleanup;
- $self->error("$self->{tmpfile} : $err");
- }
+ unless ( open( IN, '<', $self->{tmpfile} ) ) {
+ $err = $!;
+ $self->cleanup;
+ $self->error("$self->{tmpfile} : $err");
+ }
- while (<IN>) {
- $mail->{message} .= $_;
- }
+ while (<IN>) {
+ $mail->{message} .= $_;
+ }
- close(IN);
+ close(IN);
- } else {
+ }
+ else {
- @{ $mail->{attachments} } = ($self->{tmpfile});
+ @{ $mail->{attachments} } = ( $self->{tmpfile} );
- $myconfig->{signature} =~ s/\\n/\n/g;
- $mail->{message} .= "\n-- \n$myconfig->{signature}" if $myconfig->{signature};
+ $myconfig->{signature} =~ s/\\n/\n/g;
+ $mail->{message} .= "\n-- \n$myconfig->{signature}"
+ if $myconfig->{signature};
- }
+ }
- if ($err = $mail->send) {
- $self->cleanup;
- $self->error($err);
- }
+ if ( $err = $mail->send ) {
+ $self->cleanup;
+ $self->error($err);
+ }
- } else {
+ }
+ else {
- $self->{OUT} = $temphash{out};
+ $self->{OUT} = $temphash{out};
$self->{printmode} = $temphash{printmode};
- unless (open(IN, '<', $self->{tmpfile})) {
- $err = $!;
- $self->cleanup;
- $self->error("$self->{tmpfile} : $err");
- }
+ unless ( open( IN, '<', $self->{tmpfile} ) ) {
+ $err = $!;
+ $self->cleanup;
+ $self->error("$self->{tmpfile} : $err");
+ }
- binmode(IN);
+ binmode(IN);
- $self->{copies} = 1 if $self->{media} =~ /(screen|email|queue)/;
+ $self->{copies} = 1 if $self->{media} =~ /(screen|email|queue)/;
- chdir("$self->{cwd}");
+ chdir("$self->{cwd}");
- for my $i (1 .. $self->{copies}) {
- if ($self->{OUT}) {
+ for my $i ( 1 .. $self->{copies} ) {
+ if ( $self->{OUT} ) {
- unless (open(OUT, $self->{printmode}, $self->{OUT})) {
- $err = $!;
- $self->cleanup;
- $self->error("$self->{OUT} : $err");
- }
+ unless ( open( OUT, $self->{printmode}, $self->{OUT} ) ) {
+ $err = $!;
+ $self->cleanup;
+ $self->error("$self->{OUT} : $err");
+ }
- } else {
+ }
+ else {
- # launch application
- print qq|Content-Type: application/$self->{format}\n|.
- qq|Content-Disposition: attachment; filename="$self->{tmpfile}"\n\n|;
+ # launch application
+ print qq|Content-Type: application/$self->{format}\n|
+ . qq|Content-Disposition: attachment; filename="$self->{tmpfile}"\n\n|;
- unless (open(OUT, ">-")) {
- $err = $!;
- $self->cleanup;
- $self->error("STDOUT : $err");
- }
- }
+ unless ( open( OUT, ">-" ) ) {
+ $err = $!;
+ $self->cleanup;
+ $self->error("STDOUT : $err");
+ }
+ }
- binmode(OUT);
+ binmode(OUT);
- while (<IN>) {
- print OUT $_;
- }
+ while (<IN>) {
+ print OUT $_;
+ }
- close(OUT);
- seek IN, 0, 0;
- }
+ close(OUT);
+ seek IN, 0, 0;
+ }
- close(IN);
- }
+ close(IN);
+ }
- $self->cleanup;
- }
+ $self->cleanup;
+ }
}
-
sub format_line {
- my $self = shift;
+ my $self = shift;
- $_ = shift;
- my $i = shift;
+ $_ = shift;
+ my $i = shift;
- my $str;
- my $newstr;
- my $pos;
- my $l;
- my $lf;
- my $line;
- my $var = "";
- my %a;
- my $offset;
- my $pad;
- my $item;
+ my $str;
+ my $newstr;
+ my $pos;
+ my $l;
+ my $lf;
+ my $line;
+ my $var = "";
+ my %a;
+ my $offset;
+ my $pad;
+ my $item;
- while (/<\?lsmb (.+?) \?>/) {
+ while (/<\?lsmb (.+?) \?>/) {
- %a = ();
+ %a = ();
- foreach $item (split / /, $1) {
- my ($key, $value) = split /=/, $item;
+ foreach $item ( split / /, $1 ) {
+ my ( $key, $value ) = split /=/, $item;
- if ($value ne "") {
- $a{$key} = $value;
- } else {
- $var = $item;
- }
- }
+ if ( $value ne "" ) {
+ $a{$key} = $value;
+ }
+ else {
+ $var = $item;
+ }
+ }
- $str = (defined $i) ? $self->{$var}[$i] : $self->{$var};
- $newstr = $str;
+ $str = ( defined $i ) ? $self->{$var}[$i] : $self->{$var};
+ $newstr = $str;
- $self->{countitemnotes} = 1 if $var eq 'itemnotes';
+ $self->{countitemnotes} = 1 if $var eq 'itemnotes';
- $var = $1;
- if ($var =~ /^if\s+not\s+/) {
+ $var = $1;
+ if ( $var =~ /^if\s+not\s+/ ) {
- if ($str) {
+ if ($str) {
- $var =~ s/if\s+not\s+//;
- s/<\?lsmb if\s+not\s+$var \?>.*?(<\?lsmb end\s+$var \?>|$)//s;
+ $var =~ s/if\s+not\s+//;
+ s/<\?lsmb if\s+not\s+$var \?>.*?(<\?lsmb end\s+$var \?>|$)//s;
- } else {
- s/<\?lsmb $var \?>//;
- }
+ }
+ else {
+ s/<\?lsmb $var \?>//;
+ }
- next;
- }
+ next;
+ }
- if ($var =~ /^if\s+/) {
+ if ( $var =~ /^if\s+/ ) {
- if ($str) {
- s/<\?lsmb $var \?>//;
- } else {
- $var =~ s/if\s+//;
- s/<\?lsmb if\s+$var \?>.*?(<\?lsmb end\s+$var \?>|$)//s;
- }
+ if ($str) {
+ s/<\?lsmb $var \?>//;
+ }
+ else {
+ $var =~ s/if\s+//;
+ s/<\?lsmb if\s+$var \?>.*?(<\?lsmb end\s+$var \?>|$)//s;
+ }
- next;
- }
+ next;
+ }
- if ($var =~ /^end\s+/) {
- s/<\?lsmb $var \?>//;
- next;
- }
+ if ( $var =~ /^end\s+/ ) {
+ s/<\?lsmb $var \?>//;
+ next;
+ }
- if ($a{align} || $a{width} || $a{offset}) {
+ if ( $a{align} || $a{width} || $a{offset} ) {
- $newstr = "";
- $offset = 0;
- $lf = "";
+ $newstr = "";
+ $offset = 0;
+ $lf = "";
- foreach $str (split /\n/, $str) {
+ foreach $str ( split /\n/, $str ) {
- $line = $str;
- $l = length $str;
+ $line = $str;
+ $l = length $str;
- do {
+ do {
- if (($pos = length $str) > $a{width}) {
+ if ( ( $pos = length $str ) > $a{width} ) {
- if (($pos = rindex $str, " ", $a{width}) > 0) {
- $line = substr($str, 0, $pos);
- }
+ if ( ( $pos = rindex $str, " ", $a{width} ) > 0 ) {
+ $line = substr( $str, 0, $pos );
+ }
- $pos = length $str if $pos == -1;
- }
+ $pos = length $str if $pos == -1;
+ }
- $l = length $line;
+ $l = length $line;
- # pad left, right or center
- $l = ($a{width} - $l);
+ # pad left, right or center
+ $l = ( $a{width} - $l );
- $pad = " " x $l;
+ $pad = " " x $l;
- if ($a{align} =~ /right/i) {
- $line = " " x $offset . $pad . $line;
- }
+ if ( $a{align} =~ /right/i ) {
+ $line = " " x $offset . $pad . $line;
+ }
- if ($a{align} =~ /left/i) {
- $line = " " x $offset . $line . $pad;
- }
+ if ( $a{align} =~ /left/i ) {
+ $line = " " x $offset . $line . $pad;
+ }
- if ($a{align} =~ /center/i) {
- $pad = " " x ($l/2);
- $line = " " x $offset . $pad . $line;
- $pad = " " x ($l/2);
- $line .= $pad;
- }
+ if ( $a{align} =~ /center/i ) {
+ $pad = " " x ( $l / 2 );
+ $line = " " x $offset . $pad . $line;
+ $pad = " " x ( $l / 2 );
+ $line .= $pad;
+ }
- $newstr .= "$lf$line";
+ $newstr .= "$lf$line";
- $str = substr($str, $pos + 1);
- $line = $str;
- $lf = "\n";
+ $str = substr( $str, $pos + 1 );
+ $line = $str;
+ $lf = "\n";
- $offset = $a{offset};
+ $offset = $a{offset};
- } while ($str);
- }
- }
+ } while ($str);
+ }
+ }
- s/<\?lsmb (.+?) \?>/$newstr/;
+ s/<\?lsmb (.+?) \?>/$newstr/;
- }
+ }
- $_;
+ $_;
}
-
sub cleanup {
- my $self = shift;
+ my $self = shift;
- chdir("$self->{tmpdir}");
+ chdir("$self->{tmpdir}");
- my @err = ();
+ my @err = ();
- if (-f "$self->{errfile}") {
- open(FH, '<', "$self->{errfile}");
- @err = <FH>;
- close(FH);
- }
+ if ( -f "$self->{errfile}" ) {
+ open( FH, '<', "$self->{errfile}" );
+ @err = <FH>;
+ close(FH);
+ }
- if ($self->{tmpfile}) {
- # strip extension
- $self->{tmpfile} =~ s/\.\w+$//g;
- my $tmpfile = $self->{tmpfile};
- unlink(<$tmpfile.*>);
- }
+ if ( $self->{tmpfile} ) {
- chdir("$self->{cwd}");
+ # strip extension
+ $self->{tmpfile} =~ s/\.\w+$//g;
+ my $tmpfile = $self->{tmpfile};
+ unlink(<$tmpfile.*>);
+ }
- "@err";
-}
+ chdir("$self->{cwd}");
+ "@err";
+}
sub rerun_latex {
- my $self = shift;
+ my $self = shift;
- my $a = 0;
+ my $a = 0;
- if (-f "$self->{errfile}") {
- open(FH, '<', "$self->{errfile}");
- $a = grep /(longtable Warning:|Warning:.*?LastPage)/, <FH>;
- close(FH);
- }
+ if ( -f "$self->{errfile}" ) {
+ open( FH, '<', "$self->{errfile}" );
+ $a = grep /(longtable Warning:|Warning:.*?LastPage)/, <FH>;
+ close(FH);
+ }
- $a;
+ $a;
}
-
sub format_string {
- my ($self, @fields) = @_;
-
- my $format = $self->{format};
-
- if ($self->{format} =~ /(postscript|pdf)/) {
- $format = 'tex';
- }
-
- my %replace = (
- 'order' => {
- html => [ '<', '>', '\n', '\r' ],
- txt => [ '\n', '\r' ],
- tex => [ quotemeta('\\'), '&', '\n','\r',
- '\$', '%', '_', '#',
- quotemeta('^'), '{', '}', '<', '>', '£'
- ] },
- html => { '<' => '&lt;', '>' => '&gt;','\n' => '<br />',
- '\r' => '<br />' },
- txt => { '\n' => "\n", '\r' => "\r" },
- tex => {'&' => '\&', '$' => '\$', '%' => '\%', '_' => '\_',
- '#' => '\#', quotemeta('^') => '\^\\', '{' => '\{',
- '}' => '\}', '<' => '$<$', '>' => '$>$',
- '\n' => '\newline ', '\r' => '\newline ',
- '£' => '\pounds ', quotemeta('\\') => '/'}
- );
-
- my $key;
-
- foreach $key (@{ $replace{order}{$format} }) {
- for (@fields) { $self->{$_} =~ s/$key/$replace{$format}{$key}/g }
- }
+ my ( $self, @fields ) = @_;
+
+ my $format = $self->{format};
+
+ if ( $self->{format} =~ /(postscript|pdf)/ ) {
+ $format = 'tex';
+ }
+
+ my %replace = (
+ 'order' => {
+ html => [ '<', '>', '\n', '\r' ],
+ txt => [ '\n', '\r' ],
+ tex => [
+ quotemeta('\\'), '&', '\n', '\r',
+ '\$', '%', '_', '#',
+ quotemeta('^'), '{', '}', '<',
+ '>', '£'
+ ]
+ },
+ html => {
+ '<' => '&lt;',
+ '>' => '&gt;',
+ '\n' => '<br />',
+ '\r' => '<br />'
+ },
+ txt => { '\n' => "\n", '\r' => "\r" },
+ tex => {
+ '&' => '\&',
+ '$' => '\$',
+ '%' => '\%',
+ '_' => '\_',
+ '#' => '\#',
+ quotemeta('^') => '\^\\',
+ '{' => '\{',
+ '}' => '\}',
+ '<' => '$<$',
+ '>' => '$>$',
+ '\n' => '\newline ',
+ '\r' => '\newline ',
+ '£' => '\pounds ',
+ quotemeta('\\') => '/'
+ }
+ );
+
+ my $key;
+
+ foreach $key ( @{ $replace{order}{$format} } ) {
+ for (@fields) { $self->{$_} =~ s/$key/$replace{$format}{$key}/g }
+ }
}
-
sub datetonum {
- my ($self, $myconfig, $date, $picture) = @_;
+ my ( $self, $myconfig, $date, $picture ) = @_;
- if ($date && $date =~ /\D/) {
+ if ( $date && $date =~ /\D/ ) {
- if ($myconfig->{dateformat} =~ /^yy/) {
- ($yy, $mm, $dd) = split /\D/, $date;
- }
+ if ( $myconfig->{dateformat} =~ /^yy/ ) {
+ ( $yy, $mm, $dd ) = split /\D/, $date;
+ }
- if ($myconfig->{dateformat} =~ /^mm/) {
- ($mm, $dd, $yy) = split /\D/, $date;
- }
+ if ( $myconfig->{dateformat} =~ /^mm/ ) {
+ ( $mm, $dd, $yy ) = split /\D/, $date;
+ }
- if ($myconfig->{dateformat} =~ /^dd/) {
- ($dd, $mm, $yy) = split /\D/, $date;
- }
+ if ( $myconfig->{dateformat} =~ /^dd/ ) {
+ ( $dd, $mm, $yy ) = split /\D/, $date;
+ }
- $dd *= 1;
- $mm *= 1;
- $yy += 2000 if length $yy == 2;
+ $dd *= 1;
+ $mm *= 1;
+ $yy += 2000 if length $yy == 2;
- $dd = substr("0$dd", -2);
- $mm = substr("0$mm", -2);
+ $dd = substr( "0$dd", -2 );
+ $mm = substr( "0$mm", -2 );
- $date = "$yy$mm$dd";
- }
+ $date = "$yy$mm$dd";
+ }
- $date;
+ $date;
}
-
sub add_date {
- my ($self, $myconfig, $date, $repeat, $unit) = @_;
+ my ( $self, $myconfig, $date, $repeat, $unit ) = @_;
- use Time::Local;
+ use Time::Local;
- my $diff = 0;
- my $spc = $myconfig->{dateformat};
- $spc =~ s/\w//g;
- $spc = substr($spc, 0, 1);
+ my $diff = 0;
+ my $spc = $myconfig->{dateformat};
+ $spc =~ s/\w//g;
+ $spc = substr( $spc, 0, 1 );
- if ($date) {
+ if ($date) {
- if ($date =~ /\D/) {
+ if ( $date =~ /\D/ ) {
- if ($myconfig->{dateformat} =~ /^yy/) {
- ($yy, $mm, $dd) = split /\D/, $date;
- }
+ if ( $myconfig->{dateformat} =~ /^yy/ ) {
+ ( $yy, $mm, $dd ) = split /\D/, $date;
+ }
- if ($myconfig->{dateformat} =~ /^mm/) {
- ($mm, $dd, $yy) = split /\D/, $date;
- }
+ if ( $myconfig->{dateformat} =~ /^mm/ ) {
+ ( $mm, $dd, $yy ) = split /\D/, $date;
+ }
- if ($myconfig->{dateformat} =~ /^dd/) {
- ($dd, $mm, $yy) = split /\D/, $date;
- }
+ if ( $myconfig->{dateformat} =~ /^dd/ ) {
+ ( $dd, $mm, $yy ) = split /\D/, $date;
+ }
- } else {
- # ISO
- ($yy, $mm, $dd) =~ /(....)(..)(..)/;
- }
+ }
+ else {
- if ($unit eq 'days') {
- $diff = $repeat * 86400;
- }
+ # ISO
+ ( $yy, $mm, $dd ) =~ /(....)(..)(..)/;
+ }
- if ($unit eq 'weeks') {
- $diff = $repeat * 604800;
- }
+ if ( $unit eq 'days' ) {
+ $diff = $repeat * 86400;
+ }
- if ($unit eq 'months') {
- $diff = $mm + $repeat;
+ if ( $unit eq 'weeks' ) {
+ $diff = $repeat * 604800;
+ }
- my $whole = int($diff / 12);
- $yy += $whole;
+ if ( $unit eq 'months' ) {
+ $diff = $mm + $repeat;
- $mm = ($diff % 12) + 1;
- $diff = 0;
- }
+ my $whole = int( $diff / 12 );
+ $yy += $whole;
- if ($unit eq 'years') {
- $yy++;
- }
+ $mm = ( $diff % 12 ) + 1;
+ $diff = 0;
+ }
- $mm--;
+ if ( $unit eq 'years' ) {
+ $yy++;
+ }
- @t = localtime(timelocal(0,0,0,$dd,$mm,$yy) + $diff);
+ $mm--;
- $t[4]++;
- $mm = substr("0$t[4]",-2);
- $dd = substr("0$t[3]",-2);
- $yy = $t[5] + 1900;
+ @t = localtime( timelocal( 0, 0, 0, $dd, $mm, $yy ) + $diff );
- if ($date =~ /\D/) {
+ $t[4]++;
+ $mm = substr( "0$t[4]", -2 );
+ $dd = substr( "0$t[3]", -2 );
+ $yy = $t[5] + 1900;
- if ($myconfig->{dateformat} =~ /^yy/) {
- $date = "$yy$spc$mm$spc$dd";
- }
+ if ( $date =~ /\D/ ) {
- if ($myconfig->{dateformat} =~ /^mm/) {
- $date = "$mm$spc$dd$spc$yy";
- }
+ if ( $myconfig->{dateformat} =~ /^yy/ ) {
+ $date = "$yy$spc$mm$spc$dd";
+ }
- if ($myconfig->{dateformat} =~ /^dd/) {
- $date = "$dd$spc$mm$spc$yy";
- }
+ if ( $myconfig->{dateformat} =~ /^mm/ ) {
+ $date = "$mm$spc$dd$spc$yy";
+ }
- } else {
- $date = "$yy$mm$dd";
- }
- }
+ if ( $myconfig->{dateformat} =~ /^dd/ ) {
+ $date = "$dd$spc$mm$spc$yy";
+ }
- $date;
-}
+ }
+ else {
+ $date = "$yy$mm$dd";
+ }
+ }
+ $date;
+}
sub print_button {
- my ($self, $button, $name) = @_;
-
- print qq|<button class="submit" type="submit" name="action" value="$name" accesskey="$button->{$name}{key}" title="$button->{$name}{value} [Alt-$button->{$name}{key}]">$button->{$name}{value}</button>\n|;
-}
+ my ( $self, $button, $name ) = @_;
+ print
+qq|<button class="submit" type="submit" name="action" value="$name" accesskey="$button->{$name}{key}" title="$button->{$name}{value} [Alt-$button->{$name}{key}]">$button->{$name}{value}</button>\n|;
+}
# Database routines used throughout
sub db_init {
- my ($self, $myconfig) = @_;
- $self->{dbh} = $self->dbconnect_noauto($myconfig) || $self->dberror();
+ my ( $self, $myconfig ) = @_;
+ $self->{dbh} = $self->dbconnect_noauto($myconfig) || $self->dberror();
- my $query =
- "SELECT t.extends,
+ my $query = "SELECT t.extends,
coalesce (t.table_name, 'custom_' || extends)
|| ':' || f.field_name as field_def
FROM custom_table_catalog t
JOIN custom_field_catalog f USING (table_id)";
- my $sth = $self->{dbh}->prepare($query);
- $sth->execute;
- my $ref;
- while ($ref = $sth->fetchrow_hashref(NAME_lc)){
- push @{$self->{custom_db_fields}{$ref->{extends}}},
- $ref->{field_def};
- }
+ my $sth = $self->{dbh}->prepare($query);
+ $sth->execute;
+ my $ref;
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $self->{custom_db_fields}{ $ref->{extends} } },
+ $ref->{field_def};
+ }
}
sub run_custom_queries {
- my ($self, $tablename, $query_type, $linenum) = @_;
- my $dbh = $self->{dbh};
- if ($query_type !~ /^(select|insert|update)$/i){
- $self->error($locale->text(
- "Passed incorrect query type to run_custom_queries."
- ));
- }
- my @rc;
- my %temphash;
- my @templist;
- my @elements;
- my $query;
- my $ins_values;
- if ($linenum){
- $linenum = "_$linenum";
- }
-
- $query_type = uc($query_type);
- for (@{$self->{custom_db_fields}{$tablename}}){
- @elements = split (/:/, $_);
- push @{$temphash{$elements[0]}}, $elements[1];
- }
- for (keys %temphash){
- my @data;
- my $ins_values;
- $query = "$query_type ";
- if ($query_type eq 'UPDATE'){
- $query = "DELETE FROM $_ WHERE row_id = ?";
- my $sth = $dbh->prepare($query);
- $sth->execute->($self->{"id"."$linenum"})
- || $self->dberror($query);
- } elsif ($query_type eq 'INSERT'){
- $query .= " INTO $_ (";
- }
- my $first = 1;
- for (@{$temphash{$_}}){
- $query .= "$_";
- if ($query_type eq 'UPDATE'){
- $query .= '= ?';
- }
- $ins_values .= "?, ";
- $query .= ", ";
- $first = 0;
- if ($query_type eq 'UPDATE' or $query_type eq 'INSERT'){
- push @data, $self->{"$_$linenum"};
- }
- }
- if ($query_type ne 'INSERT'){
- $query =~ s/, $//;
- }
- if ($query_type eq 'SELECT'){
- $query .= " FROM $_";
- }
- if ($query_type eq 'SELECT' or $query_type eq 'UPDATE'){
- $query .= " WHERE row_id = ?";
- }
- if ($query_type eq 'INSERT'){
- $query .= " row_id) VALUES ($ins_values ?)";
- }
- if ($query_type eq 'SELECT'){
- push @rc, [ $query ];
- } else {
- unshift (@data, $query);
- push @rc, [ @data ];
- }
- }
- if ($query_type eq 'INSERT'){
- for (@rc){
- $query = shift (@{$_});
- $sth = $dbh->prepare($query)
- || $self->db_error($query);
- $sth->execute(@{$_}, $self->{id})
- || $self->dberror($query);;
- $sth->finish;
- $did_insert = 1;
- }
- } elsif ($query_type eq 'UPDATE'){
- @rc = $self->run_custom_queries(
- $tablename, 'INSERT', $linenum);
- } elsif ($query_type eq 'SELECT'){
- for (@rc){
- $query = shift @{$_};
- $sth = $self->{dbh}->prepare($query);
- $sth->execute($self->{id});
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %{$ref}){
- $self->{$_} = $ref->{$_};
- }
- }
- }
- @rc;
+ my ( $self, $tablename, $query_type, $linenum ) = @_;
+ my $dbh = $self->{dbh};
+ if ( $query_type !~ /^(select|insert|update)$/i ) {
+ $self->error(
+ $locale->text(
+ "Passed incorrect query type to run_custom_queries."
+ )
+ );
+ }
+ my @rc;
+ my %temphash;
+ my @templist;
+ my @elements;
+ my $query;
+ my $ins_values;
+ if ($linenum) {
+ $linenum = "_$linenum";
+ }
+
+ $query_type = uc($query_type);
+ for ( @{ $self->{custom_db_fields}{$tablename} } ) {
+ @elements = split( /:/, $_ );
+ push @{ $temphash{ $elements[0] } }, $elements[1];
+ }
+ for ( keys %temphash ) {
+ my @data;
+ my $ins_values;
+ $query = "$query_type ";
+ if ( $query_type eq 'UPDATE' ) {
+ $query = "DELETE FROM $_ WHERE row_id = ?";
+ my $sth = $dbh->prepare($query);
+ $sth->execute->( $self->{ "id" . "$linenum" } )
+ || $self->dberror($query);
+ }
+ elsif ( $query_type eq 'INSERT' ) {
+ $query .= " INTO $_ (";
+ }
+ my $first = 1;
+ for ( @{ $temphash{$_} } ) {
+ $query .= "$_";
+ if ( $query_type eq 'UPDATE' ) {
+ $query .= '= ?';
+ }
+ $ins_values .= "?, ";
+ $query .= ", ";
+ $first = 0;
+ if ( $query_type eq 'UPDATE' or $query_type eq 'INSERT' ) {
+ push @data, $self->{"$_$linenum"};
+ }
+ }
+ if ( $query_type ne 'INSERT' ) {
+ $query =~ s/, $//;
+ }
+ if ( $query_type eq 'SELECT' ) {
+ $query .= " FROM $_";
+ }
+ if ( $query_type eq 'SELECT' or $query_type eq 'UPDATE' ) {
+ $query .= " WHERE row_id = ?";
+ }
+ if ( $query_type eq 'INSERT' ) {
+ $query .= " row_id) VALUES ($ins_values ?)";
+ }
+ if ( $query_type eq 'SELECT' ) {
+ push @rc, [$query];
+ }
+ else {
+ unshift( @data, $query );
+ push @rc, [@data];
+ }
+ }
+ if ( $query_type eq 'INSERT' ) {
+ for (@rc) {
+ $query = shift( @{$_} );
+ $sth = $dbh->prepare($query)
+ || $self->db_error($query);
+ $sth->execute( @{$_}, $self->{id} )
+ || $self->dberror($query);
+ $sth->finish;
+ $did_insert = 1;
+ }
+ }
+ elsif ( $query_type eq 'UPDATE' ) {
+ @rc = $self->run_custom_queries( $tablename, 'INSERT', $linenum );
+ }
+ elsif ( $query_type eq 'SELECT' ) {
+ for (@rc) {
+ $query = shift @{$_};
+ $sth = $self->{dbh}->prepare($query);
+ $sth->execute( $self->{id} );
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %{$ref} ) {
+ $self->{$_} = $ref->{$_};
+ }
+ }
+ }
+ @rc;
}
-
sub dbconnect {
- my ($self, $myconfig) = @_;
+ my ( $self, $myconfig ) = @_;
- # connect to database
- my $dbh = DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}) or $self->dberror;
+ # connect to database
+ my $dbh = DBI->connect( $myconfig->{dbconnect},
+ $myconfig->{dbuser}, $myconfig->{dbpasswd} )
+ or $self->dberror;
- # set db options
- if ($myconfig->{dboptions}) {
- $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
- }
+ # set db options
+ if ( $myconfig->{dboptions} ) {
+ $dbh->do( $myconfig->{dboptions} )
+ || $self->dberror( $myconfig->{dboptions} );
+ }
- $dbh;
+ $dbh;
}
-
sub dbconnect_noauto {
- my ($self, $myconfig) = @_;
+ my ( $self, $myconfig ) = @_;
- # connect to database
- $dbh = DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, {AutoCommit => 0}) or $self->dberror;
+ # connect to database
+ $dbh = DBI->connect(
+ $myconfig->{dbconnect}, $myconfig->{dbuser},
+ $myconfig->{dbpasswd}, { AutoCommit => 0 }
+ ) or $self->dberror;
- # set db options
- if ($myconfig->{dboptions}) {
- $dbh->do($myconfig->{dboptions});
- }
+ # set db options
+ if ( $myconfig->{dboptions} ) {
+ $dbh->do( $myconfig->{dboptions} );
+ }
- $dbh;
+ $dbh;
}
-
sub dbquote {
- my ($self, $var) = @_;
+ my ( $self, $var ) = @_;
- if ($var eq ''){
- $_ = "NULL";
- } else {
- $_ = $self->{dbh}->quote($var);
- }
- $_;
+ if ( $var eq '' ) {
+ $_ = "NULL";
+ }
+ else {
+ $_ = $self->{dbh}->quote($var);
+ }
+ $_;
}
-
sub update_balance {
- # This is a dangerous private function. All apps calling it must
- # be careful to avoid SQL injection issues
- my ($self, $dbh, $table, $field, $where, $value) = @_;
+ # This is a dangerous private function. All apps calling it must
+ # be careful to avoid SQL injection issues
- # if we have a value, go do it
- if ($value) {
- # retrieve balance from table
- my $query = "SELECT $field FROM $table WHERE $where FOR UPDATE";
- my ($balance) = $dbh->selectrow_array($query);
+ my ( $self, $dbh, $table, $field, $where, $value ) = @_;
- $balance += $value;
- # update balance
- $query = "UPDATE $table SET $field = $balance WHERE $where";
- $dbh->do($query) || $self->dberror($query);
- }
-}
+ # if we have a value, go do it
+ if ($value) {
+
+ # retrieve balance from table
+ my $query = "SELECT $field FROM $table WHERE $where FOR UPDATE";
+ my ($balance) = $dbh->selectrow_array($query);
+
+ $balance += $value;
+ # update balance
+ $query = "UPDATE $table SET $field = $balance WHERE $where";
+ $dbh->do($query) || $self->dberror($query);
+ }
+}
sub update_exchangerate {
- my ($self, $dbh, $curr, $transdate, $buy, $sell) = @_;
+ my ( $self, $dbh, $curr, $transdate, $buy, $sell ) = @_;
- # some sanity check for currency
- return if ($curr eq "");
+ # some sanity check for currency
+ return if ( $curr eq "" );
- my $query = qq|
+ my $query = qq|
SELECT curr
FROM exchangerate
WHERE curr = ?
AND transdate = ?
FOR UPDATE|;
- my $sth = $self->{dbh}->prepare($query);
- $sth->execute($curr, $transdate) || $self->dberror($query);
-
- my $set;
- my @queryargs;
-
- if ($buy && $sell) {
- $set = "buy = ?, sell = ?";
- @queryargs = ($buy, $sell);
- } elsif ($buy) {
- $set = "buy = ?";
- @queryargs = ($buy);
- } elsif ($sell) {
- $set = "sell = ?";
- @queryargs = ($sell);
- }
-
- if ($sth->fetchrow_array) {
- $query = qq|UPDATE exchangerate
+ my $sth = $self->{dbh}->prepare($query);
+ $sth->execute( $curr, $transdate ) || $self->dberror($query);
+
+ my $set;
+ my @queryargs;
+
+ if ( $buy && $sell ) {
+ $set = "buy = ?, sell = ?";
+ @queryargs = ( $buy, $sell );
+ }
+ elsif ($buy) {
+ $set = "buy = ?";
+ @queryargs = ($buy);
+ }
+ elsif ($sell) {
+ $set = "sell = ?";
+ @queryargs = ($sell);
+ }
+
+ if ( $sth->fetchrow_array ) {
+ $query = qq|UPDATE exchangerate
SET $set
WHERE curr = ?
AND transdate = ?|;
- push (@queryargs, $curr, $transdate);
+ push( @queryargs, $curr, $transdate );
- } else {
- $query = qq|
+ }
+ else {
+ $query = qq|
INSERT INTO exchangerate (
curr, buy, sell, transdate)
VALUES (?, ?, ?, ?)|;
- @queryargs = ($curr, $buy, $sell, $transdate);
- }
- $sth->finish;
- $sth = $self->{dbh}->prepare($query);
+ @queryargs = ( $curr, $buy, $sell, $transdate );
+ }
+ $sth->finish;
+ $sth = $self->{dbh}->prepare($query);
- $sth->execute(@queryargs) || $self->dberror($query);
+ $sth->execute(@queryargs) || $self->dberror($query);
}
-
sub save_exchangerate {
- my ($self, $myconfig, $currency, $transdate, $rate, $fld) = @_;
+ my ( $self, $myconfig, $currency, $transdate, $rate, $fld ) = @_;
- my ($buy, $sell) = (0, 0);
- $buy = $rate if $fld eq 'buy';
- $sell = $rate if $fld eq 'sell';
+ my ( $buy, $sell ) = ( 0, 0 );
+ $buy = $rate if $fld eq 'buy';
+ $sell = $rate if $fld eq 'sell';
- $self->update_exchangerate(
- $self->{dbh},
- $currency,
- $transdate,
- $buy,
- $sell);
+ $self->update_exchangerate( $self->{dbh}, $currency, $transdate, $buy,
+ $sell );
- $dbh->commit;
+ $dbh->commit;
}
-
sub get_exchangerate {
- my ($self, $dbh, $curr, $transdate, $fld) = @_;
+ my ( $self, $dbh, $curr, $transdate, $fld ) = @_;
- my $exchangerate = 1;
+ my $exchangerate = 1;
- if ($transdate) {
- my $query = qq|
+ if ($transdate) {
+ my $query = qq|
SELECT $fld FROM exchangerate
WHERE curr = ? AND transdate = ?|;
- $sth = $self->{dbh}->prepare($query);
- $sth->execute($curr, $transdate);
+ $sth = $self->{dbh}->prepare($query);
+ $sth->execute( $curr, $transdate );
- ($exchangerate) = $sth->fetchrow_array;
- }
+ ($exchangerate) = $sth->fetchrow_array;
+ }
- $exchangerate;
- $sth->finish;
- $self->{dbh}->commit;
+ $exchangerate;
+ $sth->finish;
+ $self->{dbh}->commit;
}
-
sub check_exchangerate {
- my ($self, $myconfig, $currency, $transdate, $fld) = @_;
-
- return "" unless $transdate;
+ my ( $self, $myconfig, $currency, $transdate, $fld ) = @_;
+ return "" unless $transdate;
- my $query = qq|
+ my $query = qq|
SELECT $fld
FROM exchangerate
WHERE curr = ? AND transdate = ?|;
- my $sth = $self->{dbh}->prepare($query);
- $sth->execute($currenct, $transdate);
- my ($exchangerate) = $sth->fetchrow_array;
+ my $sth = $self->{dbh}->prepare($query);
+ $sth->execute( $currenct, $transdate );
+ my ($exchangerate) = $sth->fetchrow_array;
- $sth->finish;
- $self->{dbh}->commit;
+ $sth->finish;
+ $self->{dbh}->commit;
- $exchangerate;
+ $exchangerate;
}
-
sub add_shipto {
- my ($self, $dbh, $id) = @_;
+ my ( $self, $dbh, $id ) = @_;
- my $shipto;
+ my $shipto;
- foreach my $item (qw(name address1 address2 city state
- zipcode country contact phone fax email)) {
+ foreach my $item (
+ qw(name address1 address2 city state
+ zipcode country contact phone fax email)
+ )
+ {
- if ($self->{"shipto$item"} ne "") {
- $shipto = 1 if ($self->{$item} ne $self->{"shipto$item"});
- }
- }
+ if ( $self->{"shipto$item"} ne "" ) {
+ $shipto = 1 if ( $self->{$item} ne $self->{"shipto$item"} );
+ }
+ }
- if ($shipto) {
- my $query = qq|
+ if ($shipto) {
+ my $query = qq|
INSERT INTO shipto
(trans_id, shiptoname, shiptoaddress1,
shiptoaddress2, shiptocity, shiptostate,
@@ -1678,125 +1757,123 @@ sub add_shipto {
VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|;
- $sth = $self->{dbh}->prepare($query) || $self->dberror($query);
- $sth->execute(
- $id, $self->{shiptoname}, $self->{shiptoaddress1},
- $self->{shiptoaddress2}, $self->{shiptocity},
- $self->{shiptostate},
- $self->{shiptozipcode}, $self->{shiptocountry},
- $self->{shiptocontact}, $self->{shiptophone},
- $self->{shiptofax}, $self->{shiptoemail}
- ) || $self->dberror($query);
- $sth->finish;
- $self->{dbh}->commit;
- }
+ $sth = $self->{dbh}->prepare($query) || $self->dberror($query);
+ $sth->execute(
+ $id, $self->{shiptoname},
+ $self->{shiptoaddress1}, $self->{shiptoaddress2},
+ $self->{shiptocity}, $self->{shiptostate},
+ $self->{shiptozipcode}, $self->{shiptocountry},
+ $self->{shiptocontact}, $self->{shiptophone},
+ $self->{shiptofax}, $self->{shiptoemail}
+ ) || $self->dberror($query);
+ $sth->finish;
+ $self->{dbh}->commit;
+ }
}
-
sub get_employee {
- my ($self, $dbh) = @_;
+ my ( $self, $dbh ) = @_;
- my $login = $self->{login};
- $login =~ s/@.*//;
+ my $login = $self->{login};
+ $login =~ s/@.*//;
- my $query = qq|SELECT name, id
+ my $query = qq|SELECT name, id
FROM employees
WHERE login = ?|;
- $sth = $self->{dbh}->prepare($query);
- $sth->execute($login);
- my (@a) = $sth->fetchrow_array();
- $a[1] *= 1;
+ $sth = $self->{dbh}->prepare($query);
+ $sth->execute($login);
+ my (@a) = $sth->fetchrow_array();
+ $a[1] *= 1;
- $sth->finish;
- $self->{dbh}->commit;
+ $sth->finish;
+ $self->{dbh}->commit;
- @a;
+ @a;
}
-
# this sub gets the id and name from $table
sub get_name {
- my ($self, $myconfig, $table, $transdate) = @_;
+ my ( $self, $myconfig, $table, $transdate ) = @_;
- # connect to database
+ # connect to database
- my @queryargs;
- my $where;
- if ($transdate) {
- $where = qq|
+ my @queryargs;
+ my $where;
+ if ($transdate) {
+ $where = qq|
AND (startdate IS NULL OR startdate <= ?)
AND (enddate IS NULL OR enddate >= ?)|;
- @queryargs = ($transdate, $transdate);
- }
+ @queryargs = ( $transdate, $transdate );
+ }
- my $name = $self->like(lc $self->{$table});
+ my $name = $self->like( lc $self->{$table} );
- my $query = qq|
+ my $query = qq|
SELECT * FROM $table
WHERE (lower(name) LIKE ? OR ${table}number LIKE ?)
$where
ORDER BY name|;
- unshift(@queryargs, $name, $name);
- my $sth = $self->{dbh}->prepare($query);
+ unshift( @queryargs, $name, $name );
+ my $sth = $self->{dbh}->prepare($query);
- $sth->execute(@queryargs) || $self->dberror($query);
+ $sth->execute(@queryargs) || $self->dberror($query);
- my $i = 0;
- @{ $self->{name_list} } = ();
+ my $i = 0;
+ @{ $self->{name_list} } = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push(@{ $self->{name_list} }, $ref);
- $i++;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push( @{ $self->{name_list} }, $ref );
+ $i++;
+ }
- $sth->finish;
- $self->{dbh}->commit;
+ $sth->finish;
+ $self->{dbh}->commit;
- $i;
+ $i;
}
-
sub all_vc {
- my ($self, $myconfig, $vc, $module, $dbh, $transdate, $job) = @_;
+ my ( $self, $myconfig, $vc, $module, $dbh, $transdate, $job ) = @_;
- my $ref;
- my $disconnect = 0;
+ my $ref;
+ my $disconnect = 0;
- $dbh = $self->{dbh};
+ $dbh = $self->{dbh};
- my $sth;
+ my $sth;
- my $query = qq|SELECT count(*) FROM $vc|;
- my $where;
- my @queryargs = ();
+ my $query = qq|SELECT count(*) FROM $vc|;
+ my $where;
+ my @queryargs = ();
- if ($transdate) {
- $query .= qq| WHERE (startdate IS NULL OR startdate <= ?)
+ if ($transdate) {
+ $query .= qq| WHERE (startdate IS NULL OR startdate <= ?)
AND (enddate IS NULL OR enddate >= ?)|;
- @queryargs = ($transdate, $transdate);
- }
+ @queryargs = ( $transdate, $transdate );
+ }
+
+ $sth = $dbh->prepare($query);
- $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs);
- $sth->execute(@queryargs);
+ my ($count) = $sth->fetchrow_array;
- my ($count) = $sth->fetchrow_array;
+ $sth->finish;
+ @queryargs = ();
- $sth->finish;
- @queryargs = ();
- # build selection list
- if ($count < $myconfig->{vclimit}) {
+ # build selection list
+ if ( $count < $myconfig->{vclimit} ) {
- $self->{"${vc}_id"} *= 1;
+ $self->{"${vc}_id"} *= 1;
- $query = qq|SELECT id, name
+ $query = qq|SELECT id, name
FROM $vc
WHERE 1=1
$where
@@ -1808,310 +1885,312 @@ sub all_vc {
WHERE id = ?
ORDER BY name|;
- push(@queryargs, $self->{"${vc}_id"});
+ push( @queryargs, $self->{"${vc}_id"} );
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $self->dberror($query);
- @{ $self->{"all_$vc"} } = ();
+ @{ $self->{"all_$vc"} } = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $self->{"all_$vc"} }, $ref;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $self->{"all_$vc"} }, $ref;
+ }
- $sth->finish;
+ $sth->finish;
- }
+ }
- # get self
- if (! $self->{employee_id}) {
- ($self->{employee}, $self->{employee_id}) = split /--/, $self->{employee};
- ($self->{employee}, $self->{employee_id}) = $self->get_employee($dbh) unless $self->{employee_id};
- }
+ # get self
+ if ( !$self->{employee_id} ) {
+ ( $self->{employee}, $self->{employee_id} ) = split /--/,
+ $self->{employee};
+ ( $self->{employee}, $self->{employee_id} ) = $self->get_employee($dbh)
+ unless $self->{employee_id};
+ }
- $self->all_employees($myconfig, $dbh, $transdate, 1);
+ $self->all_employees( $myconfig, $dbh, $transdate, 1 );
- $self->all_departments($myconfig, $dbh, $vc);
+ $self->all_departments( $myconfig, $dbh, $vc );
- $self->all_projects($myconfig, $dbh, $transdate, $job);
+ $self->all_projects( $myconfig, $dbh, $transdate, $job );
- # get language codes
- $query = qq|SELECT *
+ # get language codes
+ $query = qq|SELECT *
FROM language
ORDER BY 2|;
- $sth = $dbh->prepare($query);
- $sth->execute || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
- $self->{all_language} = ();
+ $self->{all_language} = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $self->{all_language} }, $ref;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $self->{all_language} }, $ref;
+ }
- $sth->finish;
- $self->all_taxaccounts($myconfig, $dbh, $transdate);
- $self->{dbh}->commit;
+ $sth->finish;
+ $self->all_taxaccounts( $myconfig, $dbh, $transdate );
+ $self->{dbh}->commit;
}
-
sub all_taxaccounts {
- my ($self, $myconfig, $dbh2, $transdate) = @_;
+ my ( $self, $myconfig, $dbh2, $transdate ) = @_;
- my $dbh = $self->{dbh};
+ my $dbh = $self->{dbh};
- my $sth;
- my $query;
- my $where;
+ my $sth;
+ my $query;
+ my $where;
- my @queryargs = ();
+ my @queryargs = ();
- if ($transdate) {
- $where = qq| AND (t.validto >= ? OR t.validto IS NULL)|;
- push(@queryargs, $transdate);
- }
+ if ($transdate) {
+ $where = qq| AND (t.validto >= ? OR t.validto IS NULL)|;
+ push( @queryargs, $transdate );
+ }
- if ($self->{taxaccounts}) {
+ if ( $self->{taxaccounts} ) {
- # rebuild tax rates
- $query = qq|SELECT t.rate, t.taxnumber
+ # rebuild tax rates
+ $query = qq|SELECT t.rate, t.taxnumber
FROM tax t
JOIN chart c ON (c.id = t.chart_id)
WHERE c.accno = ?
$where
ORDER BY accno, validto|;
- $sth = $dbh->prepare($query) || $self->dberror($query);
+ $sth = $dbh->prepare($query) || $self->dberror($query);
- foreach my $accno (split / /, $self->{taxaccounts}) {
- $sth->execute($accno, @queryargs);
- ($self->{"${accno}_rate"}, $self->{"${accno}_taxnumber"}) = $sth->fetchrow_array;
- $sth->finish;
- }
- }
- $self->{dbh}->commit;
+ foreach my $accno ( split / /, $self->{taxaccounts} ) {
+ $sth->execute( $accno, @queryargs );
+ ( $self->{"${accno}_rate"}, $self->{"${accno}_taxnumber"} ) =
+ $sth->fetchrow_array;
+ $sth->finish;
+ }
+ }
+ $self->{dbh}->commit;
}
-
sub all_employees {
- my ($self, $myconfig, $dbh2, $transdate, $sales) = @_;
+ my ( $self, $myconfig, $dbh2, $transdate, $sales ) = @_;
+
+ my $dbh = $self->{dbh};
+ my @whereargs = ();
- my $dbh = $self->{dbh};
- my @whereargs = ();
- # setup employees/sales contacts
- my $query = qq|SELECT id, name
+ # setup employees/sales contacts
+ my $query = qq|SELECT id, name
FROM employees
WHERE 1 = 1|;
- if ($transdate) {
- $query .= qq| AND (startdate IS NULL OR startdate <= ?)
+ if ($transdate) {
+ $query .= qq| AND (startdate IS NULL OR startdate <= ?)
AND (enddate IS NULL OR enddate >= ?)|;
- @whereargs = ($transdate, $transdate);
- } else {
- $query .= qq| AND enddate IS NULL|;
- }
-
- if ($sales) {
- $query .= qq| AND sales = '1'|;
- }
-
- $query .= qq| ORDER BY name|;
- my $sth = $dbh->prepare($query);
- $sth->execute(@whereargs) || $self->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $self->{all_employee} }, $ref;
- }
-
- $sth->finish;
- $dbh->commit;
+ @whereargs = ( $transdate, $transdate );
+ }
+ else {
+ $query .= qq| AND enddate IS NULL|;
+ }
+
+ if ($sales) {
+ $query .= qq| AND sales = '1'|;
+ }
+
+ $query .= qq| ORDER BY name|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute(@whereargs) || $self->dberror($query);
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $self->{all_employee} }, $ref;
+ }
+
+ $sth->finish;
+ $dbh->commit;
}
-
-
sub all_projects {
- my ($self, $myconfig, $dbh2, $transdate, $job) = @_;
+ my ( $self, $myconfig, $dbh2, $transdate, $job ) = @_;
- my $dbh = $self->{dbh};
- my @queryargs = ();
+ my $dbh = $self->{dbh};
+ my @queryargs = ();
- my $where = "1 = 1";
+ my $where = "1 = 1";
- $where = qq|id NOT IN (SELECT id
+ $where = qq|id NOT IN (SELECT id
FROM parts
- WHERE project_id > 0)| if ! $job;
+ WHERE project_id > 0)| if !$job;
- my $query = qq|SELECT *
+ my $query = qq|SELECT *
FROM project
WHERE $where|;
- if ($self->{language_code}) {
+ if ( $self->{language_code} ) {
- $query = qq|
+ $query = qq|
SELECT pr.*, t.description AS translation
FROM project pr
LEFT JOIN translation t ON (t.trans_id = pr.id)
WHERE t.language_code = ?|;
- push(@queryargs, $self->{language_code});
- }
+ push( @queryargs, $self->{language_code} );
+ }
- if ($transdate) {
- $query .= qq| AND (startdate IS NULL OR startdate <= ?)
+ if ($transdate) {
+ $query .= qq| AND (startdate IS NULL OR startdate <= ?)
AND (enddate IS NULL OR enddate >= ?)|;
- push(@queryargs, $transdate, $transdate);
- }
+ push( @queryargs, $transdate, $transdate );
+ }
- $query .= qq| ORDER BY projectnumber|;
+ $query .= qq| ORDER BY projectnumber|;
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs)|| $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $self->dberror($query);
- @{ $self->{all_project} } = ();
+ @{ $self->{all_project} } = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $self->{all_project} }, $ref;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $self->{all_project} }, $ref;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub all_departments {
- my ($self, $myconfig, $dbh2, $vc) = @_;
+ my ( $self, $myconfig, $dbh2, $vc ) = @_;
- $dbh = $self->{dbh};
+ $dbh = $self->{dbh};
- my $where = "1 = 1";
+ my $where = "1 = 1";
- if ($vc) {
- if ($vc eq 'customer') {
- $where = " role = 'P'";
- }
- }
+ if ($vc) {
+ if ( $vc eq 'customer' ) {
+ $where = " role = 'P'";
+ }
+ }
- my $query = qq|SELECT id, description
+ my $query = qq|SELECT id, description
FROM department
WHERE $where
ORDER BY 2|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $self->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
- @{ $self->{all_department} } = ();
+ @{ $self->{all_department} } = ();
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $self->{all_department} }, $ref;
- }
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $self->{all_department} }, $ref;
+ }
- $sth->finish;
- $self->all_years($myconfig);
- $dbh->commit;
+ $sth->finish;
+ $self->all_years($myconfig);
+ $dbh->commit;
}
-
sub all_years {
- my ($self, $myconfig, $dbh2) = @_;
+ my ( $self, $myconfig, $dbh2 ) = @_;
- $dbh = $self->{dbh};
+ $dbh = $self->{dbh};
- # get years
- my $query = qq|
+ # get years
+ my $query = qq|
SELECT (SELECT MIN(transdate) FROM acc_trans),
(SELECT MAX(transdate) FROM acc_trans)|;
- my ($startdate, $enddate) = $dbh->selectrow_array($query);
-
- if ($myconfig->{dateformat} =~ /^yy/) {
- ($startdate) = split /\W/, $startdate;
- ($enddate) = split /\W/, $enddate;
- } else {
- (@_) = split /\W/, $startdate;
- $startdate = $_[2];
- (@_) = split /\W/, $enddate;
- $enddate = $_[2];
- }
-
- $self->{all_years} = ();
- $startdate = substr($startdate,0,4);
- $enddate = substr($enddate,0,4);
-
- while ($enddate >= $startdate) {
- push @{ $self->{all_years} }, $enddate--;
- }
-
- #this should probably be changed to use locale
- %{ $self->{all_month} } = (
- '01' => 'January',
- '02' => 'February',
- '03' => 'March',
- '04' => 'April',
- '05' => 'May ',
- '06' => 'June',
- '07' => 'July',
- '08' => 'August',
- '09' => 'September',
- '10' => 'October',
- '11' => 'November',
- '12' => 'December' );
-
- $dbh->commit;
+ my ( $startdate, $enddate ) = $dbh->selectrow_array($query);
+
+ if ( $myconfig->{dateformat} =~ /^yy/ ) {
+ ($startdate) = split /\W/, $startdate;
+ ($enddate) = split /\W/, $enddate;
+ }
+ else {
+ (@_) = split /\W/, $startdate;
+ $startdate = $_[2];
+ (@_) = split /\W/, $enddate;
+ $enddate = $_[2];
+ }
+
+ $self->{all_years} = ();
+ $startdate = substr( $startdate, 0, 4 );
+ $enddate = substr( $enddate, 0, 4 );
+
+ while ( $enddate >= $startdate ) {
+ push @{ $self->{all_years} }, $enddate--;
+ }
+
+ #this should probably be changed to use locale
+ %{ $self->{all_month} } = (
+ '01' => 'January',
+ '02' => 'February',
+ '03' => 'March',
+ '04' => 'April',
+ '05' => 'May ',
+ '06' => 'June',
+ '07' => 'July',
+ '08' => 'August',
+ '09' => 'September',
+ '10' => 'October',
+ '11' => 'November',
+ '12' => 'December'
+ );
+
+ $dbh->commit;
}
-
sub create_links {
- my ($self, $module, $myconfig, $vc, $job) = @_;
-
- # get last customers or vendors
- my ($query, $sth);
+ my ( $self, $module, $myconfig, $vc, $job ) = @_;
- $dbh = $self->{dbh};
+ # get last customers or vendors
+ my ( $query, $sth );
- my %xkeyref = ();
+ $dbh = $self->{dbh};
+ my %xkeyref = ();
- # now get the account numbers
- $query = qq|SELECT accno, description, link
+ # now get the account numbers
+ $query = qq|SELECT accno, description, link
FROM chart
WHERE link LIKE ?
ORDER BY accno|;
- $sth = $dbh->prepare($query);
- $sth->execute("%"."$module%") || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( "%" . "$module%" ) || $self->dberror($query);
+
+ $self->{accounts} = "";
- $self->{accounts} = "";
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ foreach my $key ( split /:/, $ref->{link} ) {
- foreach my $key (split /:/, $ref->{link}) {
+ if ( $key =~ /$module/ ) {
- if ($key =~ /$module/) {
- # cross reference for keys
- $xkeyref{$ref->{accno}} = $key;
+ # cross reference for keys
+ $xkeyref{ $ref->{accno} } = $key;
- push @{ $self->{"${module}_links"}{$key} },
- { accno => $ref->{accno},
- description => $ref->{description} };
+ push @{ $self->{"${module}_links"}{$key} },
+ {
+ accno => $ref->{accno},
+ description => $ref->{description}
+ };
- $self->{accounts} .= "$ref->{accno} "
- unless $key =~ /tax/;
- }
- }
- }
+ $self->{accounts} .= "$ref->{accno} "
+ unless $key =~ /tax/;
+ }
+ }
+ }
- $sth->finish;
+ $sth->finish;
- my $arap = ($vc eq 'customer') ? 'ar' : 'ap';
+ my $arap = ( $vc eq 'customer' ) ? 'ar' : 'ap';
- if ($self->{id}) {
+ if ( $self->{id} ) {
- $query = qq|
+ $query = qq|
SELECT a.invnumber, a.transdate,
a.${vc}_id, a.datepaid, a.duedate, a.ordnumber,
a.taxincluded, a.curr AS currency, a.notes,
@@ -2126,43 +2205,42 @@ sub create_links {
LEFT JOIN department d ON (d.id = a.department_id)
WHERE a.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($self->{id}) || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $self->{id} ) || $self->dberror($query);
- $ref = $sth->fetchrow_hashref(NAME_lc);
+ $ref = $sth->fetchrow_hashref(NAME_lc);
- foreach $key (keys %$ref) {
- $self->{$key} = $ref->{$key};
- }
+ foreach $key ( keys %$ref ) {
+ $self->{$key} = $ref->{$key};
+ }
- $sth->finish;
+ $sth->finish;
-
- # get printed, emailed
- $query = qq|
+ # get printed, emailed
+ $query = qq|
SELECT s.printed, s.emailed, s.spoolfile, s.formname
FROM status s WHERE s.trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($self->{id}) || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $self->{id} ) || $self->dberror($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $self->{printed} .= "$ref->{formname} "
- if $ref->{printed};
- $self->{emailed} .= "$ref->{formname} "
- if $ref->{emailed};
- $self->{queued} .= "$ref->{formname} ".
- "$ref->{spoolfile} " if $ref->{spoolfile};
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $self->{printed} .= "$ref->{formname} "
+ if $ref->{printed};
+ $self->{emailed} .= "$ref->{formname} "
+ if $ref->{emailed};
+ $self->{queued} .= "$ref->{formname} " . "$ref->{spoolfile} "
+ if $ref->{spoolfile};
+ }
- $sth->finish;
- for (qw(printed emailed queued)) { $self->{$_} =~ s/ +$//g }
+ $sth->finish;
+ for (qw(printed emailed queued)) { $self->{$_} =~ s/ +$//g }
- # get recurring
- $self->get_recurring($dbh);
+ # get recurring
+ $self->get_recurring($dbh);
- # get amounts from individual entries
- $query = qq|
+ # get amounts from individual entries
+ $query = qq|
SELECT c.accno, c.description, a.source, a.amount,
a.memo, a.transdate, a.cleared, a.project_id,
p.projectnumber
@@ -2173,98 +2251,99 @@ sub create_links {
AND a.fx_transaction = '0'
ORDER BY transdate|;
- $sth = $dbh->prepare($query);
- $sth->execute($self->{id}) || $self->dberror($query);
-
+ $sth = $dbh->prepare($query);
+ $sth->execute( $self->{id} ) || $self->dberror($query);
- my $fld = ($vc eq 'customer') ? 'buy' : 'sell';
+ my $fld = ( $vc eq 'customer' ) ? 'buy' : 'sell';
- $self->{exchangerate} = $self->get_exchangerate($dbh,
- $self->{currency}, $self->{transdate}, $fld);
+ $self->{exchangerate} =
+ $self->get_exchangerate( $dbh, $self->{currency}, $self->{transdate},
+ $fld );
- # store amounts in {acc_trans}{$key} for multiple accounts
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{exchangerate} = $self->get_exchangerate($dbh,
- $self->{currency},
- $ref->{transdate},
- $fld);
+ # store amounts in {acc_trans}{$key} for multiple accounts
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{exchangerate} =
+ $self->get_exchangerate( $dbh, $self->{currency},
+ $ref->{transdate}, $fld );
- push @{ $self->{acc_trans}{$xkeyref{$ref->{accno}}} },
- $ref;
- }
+ push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref;
+ }
- $sth->finish;
+ $sth->finish;
- for (qw(curr closedto revtrans)){
- $query = qq|
+ for (qw(curr closedto revtrans)) {
+ $query = qq|
SELECT value FROM defaults
WHERE setting_key = '$_'|;
- $sth = $dbh->prepare($query);
- $sth->execute || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
- ($val) = $sth->fetchrow_array();
- if ($_ eq 'curr'){
- $self->{currencies} = $val;
- } else {
- $self->{$_} = $val;
- }
- $sth->finish;
- }
+ ($val) = $sth->fetchrow_array();
+ if ( $_ eq 'curr' ) {
+ $self->{currencies} = $val;
+ }
+ else {
+ $self->{$_} = $val;
+ }
+ $sth->finish;
+ }
- } else {
+ }
+ else {
- for (qw(current_date curr closedto revtrans)){
- $query = qq|
+ for (qw(current_date curr closedto revtrans)) {
+ $query = qq|
SELECT value FROM defaults
WHERE setting_key = '$_'|;
- $sth = $dbh->prepare($query);
- $sth->execute || $self->dberror($query);
-
- ($val) = $sth->fetchrow_array();
- if ($_ eq 'curr'){
- $self->{currencies} = $val;
- } elsif ($_ eq 'current_date'){
- $self->{transdate} = $val;
- } else {
- $self->{$_} = $val;
- }
- $sth->finish;
- }
-
- if (! $self->{"$self->{vc}_id"}) {
- $self->lastname_used($myconfig, $dbh, $vc, $module);
- }
- }
-
- $self->all_vc($myconfig, $vc, $module, $dbh, $self->{transdate}, $job);
- $self->{dbh}->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
+
+ ($val) = $sth->fetchrow_array();
+ if ( $_ eq 'curr' ) {
+ $self->{currencies} = $val;
+ }
+ elsif ( $_ eq 'current_date' ) {
+ $self->{transdate} = $val;
+ }
+ else {
+ $self->{$_} = $val;
+ }
+ $sth->finish;
+ }
+
+ if ( !$self->{"$self->{vc}_id"} ) {
+ $self->lastname_used( $myconfig, $dbh, $vc, $module );
+ }
+ }
+
+ $self->all_vc( $myconfig, $vc, $module, $dbh, $self->{transdate}, $job );
+ $self->{dbh}->commit;
}
-
sub lastname_used {
- my ($self, $myconfig, $dbh2, $vc, $module) = @_;
+ my ( $self, $myconfig, $dbh2, $vc, $module ) = @_;
- $vc ||= $self->{vc};
- my $dbh = $self->{dbh};
+ $vc ||= $self->{vc};
+ my $dbh = $self->{dbh};
- my $arap = ($vc eq 'customer') ? "ar" : "ap";
- my $where = "1 = 1";
- my $sth;
+ my $arap = ( $vc eq 'customer' ) ? "ar" : "ap";
+ my $where = "1 = 1";
+ my $sth;
- if ($self->{type} =~ /_order/) {
- $arap = 'oe';
- $where = "quotation = '0'";
- }
+ if ( $self->{type} =~ /_order/ ) {
+ $arap = 'oe';
+ $where = "quotation = '0'";
+ }
- if ($self->{type} =~ /_quotation/) {
- $arap = 'oe';
- $where = "quotation = '1'";
- }
+ if ( $self->{type} =~ /_quotation/ ) {
+ $arap = 'oe';
+ $where = "quotation = '1'";
+ }
- my $query = qq|
+ my $query = qq|
SELECT id
FROM $arap
WHERE id IN
@@ -2272,11 +2351,11 @@ sub lastname_used {
FROM $arap
WHERE $where AND ${vc}_id > 0)|;
- my ($trans_id) = $dbh->selectrow_array($query);
+ my ($trans_id) = $dbh->selectrow_array($query);
- $trans_id *= 1;
+ $trans_id *= 1;
- $query = qq|
+ $query = qq|
SELECT ct.name AS $vc, a.curr AS currency, a.${vc}_id,
current_date + ct.terms AS duedate,
a.department_id, d.description AS department, ct.notes,
@@ -2286,273 +2365,269 @@ sub lastname_used {
LEFT JOIN department d ON (a.department_id = d.id)
WHERE a.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($trans_id)|| $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute($trans_id) || $self->dberror($query);
- my $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $self->{$_} = $ref->{$_} }
- $sth->finish;
- $dbh->commit;
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $self->{$_} = $ref->{$_} }
+ $sth->finish;
+ $dbh->commit;
}
-
-
sub current_date {
- my ($self, $myconfig, $thisdate, $days) = @_;
+ my ( $self, $myconfig, $thisdate, $days ) = @_;
- my $dbh = $self->{dbh};
- my $query;
+ my $dbh = $self->{dbh};
+ my $query;
- $days *= 1;
- if ($thisdate) {
+ $days *= 1;
+ if ($thisdate) {
- my $dateformat = $myconfig->{dateformat};
+ my $dateformat = $myconfig->{dateformat};
- if ($myconfig->{dateformat} !~ /^y/) {
- my @a = split /\D/, $thisdate;
- $dateformat .= "yy" if (length $a[2] > 2);
- }
+ if ( $myconfig->{dateformat} !~ /^y/ ) {
+ my @a = split /\D/, $thisdate;
+ $dateformat .= "yy" if ( length $a[2] > 2 );
+ }
- if ($thisdate !~ /\D/) {
- $dateformat = 'yyyymmdd';
- }
+ if ( $thisdate !~ /\D/ ) {
+ $dateformat = 'yyyymmdd';
+ }
- $query = qq|SELECT to_date(?, ?)
+ $query = qq|SELECT to_date(?, ?)
+ ?::interval AS thisdate|;
- @queryargs = ($thisdate, $dateformat, $days);
-
- } else {
- $query = qq|SELECT current_date AS thisdate|;
- @queryargs = ();
- }
-
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs);
- ($thisdate) = $sth->fetchrow_array;
- $dbh->commit;
- $thisdate;
+ @queryargs = ( $thisdate, $dateformat, $days );
+
+ }
+ else {
+ $query = qq|SELECT current_date AS thisdate|;
+ @queryargs = ();
+ }
+
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs);
+ ($thisdate) = $sth->fetchrow_array;
+ $dbh->commit;
+ $thisdate;
}
-
sub like {
- my ($self, $str) = @_;
- "%$str%";
+ my ( $self, $str ) = @_;
+ "%$str%";
}
-
sub redo_rows {
- my ($self, $flds, $new, $count, $numrows) = @_;
+ my ( $self, $flds, $new, $count, $numrows ) = @_;
- my @ndx = ();
+ my @ndx = ();
- for (1 .. $count) {
- push @ndx, { num => $new->[$_-1]->{runningnumber}, ndx => $_ }
- }
+ for ( 1 .. $count ) {
+ push @ndx, { num => $new->[ $_ - 1 ]->{runningnumber}, ndx => $_ };
+ }
- my $i = 0;
- # fill rows
- foreach my $item (sort { $a->{num} <=> $b->{num} } @ndx) {
- $i++;
- $j = $item->{ndx} - 1;
- for (@{$flds}) { $self->{"${_}_$i"} = $new->[$j]->{$_} }
- }
+ my $i = 0;
- # delete empty rows
- for $i ($count + 1 .. $numrows) {
- for (@{$flds}) { delete $self->{"${_}_$i"} }
- }
-}
+ # fill rows
+ foreach my $item ( sort { $a->{num} <=> $b->{num} } @ndx ) {
+ $i++;
+ $j = $item->{ndx} - 1;
+ for ( @{$flds} ) { $self->{"${_}_$i"} = $new->[$j]->{$_} }
+ }
+ # delete empty rows
+ for $i ( $count + 1 .. $numrows ) {
+ for ( @{$flds} ) { delete $self->{"${_}_$i"} }
+ }
+}
sub get_partsgroup {
- my ($self, $myconfig, $p) = @_;
+ my ( $self, $myconfig, $p ) = @_;
- my $dbh = $self->{dbh};
+ my $dbh = $self->{dbh};
- my $query = qq|SELECT DISTINCT pg.id, pg.partsgroup
+ my $query = qq|SELECT DISTINCT pg.id, pg.partsgroup
FROM partsgroup pg
JOIN parts p ON (p.partsgroup_id = pg.id)|;
- my $where;
- my $sortorder = "partsgroup";
+ my $where;
+ my $sortorder = "partsgroup";
- if ($p->{searchitems} eq 'part') {
- $where = qq| WHERE (p.inventory_accno_id > 0
+ if ( $p->{searchitems} eq 'part' ) {
+ $where = qq| WHERE (p.inventory_accno_id > 0
AND p.income_accno_id > 0)|;
- }
+ }
- if ($p->{searchitems} eq 'service') {
- $where = qq| WHERE p.inventory_accno_id IS NULL|;
- }
+ if ( $p->{searchitems} eq 'service' ) {
+ $where = qq| WHERE p.inventory_accno_id IS NULL|;
+ }
- if ($p->{searchitems} eq 'assembly') {
- $where = qq| WHERE p.assembly = '1'|;
- }
+ if ( $p->{searchitems} eq 'assembly' ) {
+ $where = qq| WHERE p.assembly = '1'|;
+ }
- if ($p->{searchitems} eq 'labor') {
- $where = qq| WHERE p.inventory_accno_id > 0 AND p.income_accno_id IS NULL|;
- }
+ if ( $p->{searchitems} eq 'labor' ) {
+ $where =
+ qq| WHERE p.inventory_accno_id > 0 AND p.income_accno_id IS NULL|;
+ }
- if ($p->{searchitems} eq 'nolabor') {
- $where = qq| WHERE p.income_accno_id > 0|;
- }
+ if ( $p->{searchitems} eq 'nolabor' ) {
+ $where = qq| WHERE p.income_accno_id > 0|;
+ }
- if ($p->{all}) {
- $query = qq|SELECT id, partsgroup
+ if ( $p->{all} ) {
+ $query = qq|SELECT id, partsgroup
FROM partsgroup|;
- }
- my @queryargs = ();
+ }
+ my @queryargs = ();
- if ($p->{language_code}) {
- $sortorder = "translation";
+ if ( $p->{language_code} ) {
+ $sortorder = "translation";
- $query = qq|
+ $query = qq|
SELECT DISTINCT pg.id, pg.partsgroup,
t.description AS translation
FROM partsgroup pg
JOIN parts p ON (p.partsgroup_id = pg.id)
LEFT JOIN translation t ON (t.trans_id = pg.id
AND t.language_code = ?)|;
- @queryargs = ($p->{language_code});
- }
+ @queryargs = ( $p->{language_code} );
+ }
- $query .= qq| $where ORDER BY $sortorder|;
+ $query .= qq| $where ORDER BY $sortorder|;
- my $sth = $dbh->prepare($query);
- $sth->execute(@queryargs)|| $self->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $self->dberror($query);
- $self->{all_partsgroup} = ();
+ $self->{all_partsgroup} = ();
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $self->{all_partsgroup} }, $ref;
- }
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $self->{all_partsgroup} }, $ref;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub update_status {
- my ($self, $myconfig) = @_;
+ my ( $self, $myconfig ) = @_;
- # no id return
- return unless $self->{id};
+ # no id return
+ return unless $self->{id};
- my $dbh = $self->{dbh};
+ my $dbh = $self->{dbh};
- my %queued = split / +/, $self->{queued};
- my $spoolfile = ($queued{$self->{formname}}) ? "'$queued{$self->{formname}}'" : undef;
+ my %queued = split / +/, $self->{queued};
+ my $spoolfile =
+ ( $queued{ $self->{formname} } ) ? "'$queued{$self->{formname}}'" : undef;
- my $query = qq|DELETE FROM status
+ my $query = qq|DELETE FROM status
WHERE formname = ?
AND trans_id = ?|;
- $sth=$dbh->prepare($query);
- $sth->execute($self->{formname}, $self->{id}) || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $self->{formname}, $self->{id} ) || $self->dberror($query);
- $sth->finish;
+ $sth->finish;
- my $printed = ($self->{printed} =~ /$self->{formname}/) ? "1" : "0";
- my $emailed = ($self->{emailed} =~ /$self->{formname}/) ? "1" : "0";
+ my $printed = ( $self->{printed} =~ /$self->{formname}/ ) ? "1" : "0";
+ my $emailed = ( $self->{emailed} =~ /$self->{formname}/ ) ? "1" : "0";
- $query = qq|
+ $query = qq|
INSERT INTO status
(trans_id, printed, emailed, spoolfile, formname)
VALUES (?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute($self->{id}, $printed, $emailed, $spoolfile,
- $self->{formname});
- $sth->finish;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $self->{id}, $printed, $emailed, $spoolfile,
+ $self->{formname} );
+ $sth->finish;
- $dbh->commit;
+ $dbh->commit;
}
-
sub save_status {
- my ($self) = @_;
+ my ($self) = @_;
- $dbh = $self->{dbh};
+ $dbh = $self->{dbh};
- my $formnames = $self->{printed};
- my $emailforms = $self->{emailed};
+ my $formnames = $self->{printed};
+ my $emailforms = $self->{emailed};
- my $query = qq|DELETE FROM status
+ my $query = qq|DELETE FROM status
WHERE trans_id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($self->{id});
- $sth->finish;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $self->{id} );
+ $sth->finish;
- my %queued;
- my $formname;
+ my %queued;
+ my $formname;
- if ($self->{queued}) {
+ if ( $self->{queued} ) {
- %queued = split / +/, $self->{queued};
+ %queued = split / +/, $self->{queued};
- foreach $formname (keys %queued) {
+ foreach $formname ( keys %queued ) {
- $printed = ($self->{printed} =~ /$formname/) ? "1" : "0";
- $emailed = ($self->{emailed} =~ /$formname/) ? "1" : "0";
+ $printed = ( $self->{printed} =~ /$formname/ ) ? "1" : "0";
+ $emailed = ( $self->{emailed} =~ /$formname/ ) ? "1" : "0";
- if ($queued{$formname}) {
- $query = qq|
+ if ( $queued{$formname} ) {
+ $query = qq|
INSERT INTO status
(trans_id, printed, emailed,
spoolfile, formname)
VALUES (?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute($self->{id}, $pinted, $emailed,
- $queued{$formname}, $formname)
- || $self->dberror($query);
- $sth->finish;
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $self->{id}, $pinted, $emailed,
+ $queued{$formname}, $formname )
+ || $self->dberror($query);
+ $sth->finish;
+ }
- $formnames =~ s/$formname//;
- $emailforms =~ s/$formname//;
+ $formnames =~ s/$formname//;
+ $emailforms =~ s/$formname//;
- }
- }
+ }
+ }
- # save printed, emailed info
- $formnames =~ s/^ +//g;
- $emailforms =~ s/^ +//g;
+ # save printed, emailed info
+ $formnames =~ s/^ +//g;
+ $emailforms =~ s/^ +//g;
- my %status = ();
- for (split / +/, $formnames) { $status{$_}{printed} = 1 }
- for (split / +/, $emailforms) { $status{$_}{emailed} = 1 }
+ my %status = ();
+ for ( split / +/, $formnames ) { $status{$_}{printed} = 1 }
+ for ( split / +/, $emailforms ) { $status{$_}{emailed} = 1 }
- foreach my $formname (keys %status) {
- $printed = ($formnames =~ /$self->{formname}/) ? "1" : "0";
- $emailed = ($emailforms =~ /$self->{formname}/) ? "1" : "0";
+ foreach my $formname ( keys %status ) {
+ $printed = ( $formnames =~ /$self->{formname}/ ) ? "1" : "0";
+ $emailed = ( $emailforms =~ /$self->{formname}/ ) ? "1" : "0";
- $query = qq|
+ $query = qq|
INSERT INTO status (trans_id, printed, emailed,
formname)
VALUES (?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute($self->{id}, $printed, $emailed, $formname);
- $sth->finish;
- }
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $self->{id}, $printed, $emailed, $formname );
+ $sth->finish;
+ }
+ $dbh->commit;
}
-
sub get_recurring {
- my ($self) = @_;
+ my ($self) = @_;
- $dbh = $self->{dbh};
- my $query = qq/
+ $dbh = $self->{dbh};
+ my $query = qq/
SELECT s.*, se.formname || ':' || se.format AS emaila,
se.message, sp.formname || ':' ||
sp.format || ':' || sp.printer AS printa
@@ -2561,596 +2636,631 @@ sub get_recurring {
LEFT JOIN recurringprint sp ON (s.id = sp.id)
WHERE s.id = ?/;
- my $sth = $dbh->prepare($query);
- $sth->execute($self->{id}) || $self->dberror($query);
-
- for (qw(email print)) { $self->{"recurring$_"} = "" }
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- for (keys %$ref) { $self->{"recurring$_"} = $ref->{$_} }
- $self->{recurringemail} .= "$ref->{emaila}:";
- $self->{recurringprint} .= "$ref->{printa}:";
- for (qw(emaila printa)) { delete $self->{"recurring$_"} }
- }
-
- $sth->finish;
- chop $self->{recurringemail};
- chop $self->{recurringprint};
-
- if ($self->{recurringstartdate}) {
- $self->{recurringreference} = $self->escape($self->{recurringreference},1);
- $self->{recurringmessage} = $self->escape($self->{recurringmessage},1);
- for (qw(reference startdate repeat unit howmany
- payment print email message)) {
-
- $self->{recurring} .= qq|$self->{"recurring$_"},|
- }
-
- chop $self->{recurring};
- }
- $dbh->commit;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $self->{id} ) || $self->dberror($query);
+
+ for (qw(email print)) { $self->{"recurring$_"} = "" }
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ for ( keys %$ref ) { $self->{"recurring$_"} = $ref->{$_} }
+ $self->{recurringemail} .= "$ref->{emaila}:";
+ $self->{recurringprint} .= "$ref->{printa}:";
+ for (qw(emaila printa)) { delete $self->{"recurring$_"} }
+ }
+
+ $sth->finish;
+ chop $self->{recurringemail};
+ chop $self->{recurringprint};
+
+ if ( $self->{recurringstartdate} ) {
+ $self->{recurringreference} =
+ $self->escape( $self->{recurringreference}, 1 );
+ $self->{recurringmessage} =
+ $self->escape( $self->{recurringmessage}, 1 );
+ for (
+ qw(reference startdate repeat unit howmany
+ payment print email message)
+ )
+ {
+
+ $self->{recurring} .= qq|$self->{"recurring$_"},|;
+ }
+
+ chop $self->{recurring};
+ }
+ $dbh->commit;
}
-
sub save_recurring {
- my ($self, $dbh2, $myconfig) = @_;
+ my ( $self, $dbh2, $myconfig ) = @_;
- my $dbh = $self->{dbh};
+ my $dbh = $self->{dbh};
- my $query;
+ my $query;
- $query = qq|DELETE FROM recurring
+ $query = qq|DELETE FROM recurring
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($self->{id}) || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $self->{id} ) || $self->dberror($query);
- $query = qq|DELETE FROM recurringemail
+ $query = qq|DELETE FROM recurringemail
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($self->{id}) || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $self->{id} ) || $self->dberror($query);
- $query = qq|DELETE FROM recurringprint
+ $query = qq|DELETE FROM recurringprint
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($self->{id}) || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $self->{id} ) || $self->dberror($query);
- if ($self->{recurring}) {
+ if ( $self->{recurring} ) {
- my %s = ();
- ($s{reference}, $s{startdate}, $s{repeat}, $s{unit},
- $s{howmany}, $s{payment}, $s{print}, $s{email},
- $s{message})
- = split /,/, $self->{recurring};
+ my %s = ();
+ (
+ $s{reference}, $s{startdate}, $s{repeat},
+ $s{unit}, $s{howmany}, $s{payment},
+ $s{print}, $s{email}, $s{message}
+ ) = split /,/, $self->{recurring};
- if ($s{howmany} == 0){
- $self->error("Cannot set to recur 0 times");
- }
- for (qw(reference message)) { $s{$_} = $self->unescape($s{$_}) }
- for (qw(repeat howmany payment)) { $s{$_} *= 1 }
+ if ( $s{howmany} == 0 ) {
+ $self->error("Cannot set to recur 0 times");
+ }
+ for (qw(reference message)) { $s{$_} = $self->unescape( $s{$_} ) }
+ for (qw(repeat howmany payment)) { $s{$_} *= 1 }
- # calculate enddate
- my $advance = $s{repeat} * ($s{howmany} - 1);
- my %interval;
- $interval{'Pg'} =
- "(date '$s{startdate}' + interval '$advance $s{unit}')";
+ # calculate enddate
+ my $advance = $s{repeat} * ( $s{howmany} - 1 );
+ my %interval;
+ $interval{'Pg'} =
+ "(date '$s{startdate}' + interval '$advance $s{unit}')";
- $query = qq|SELECT $interval{$myconfig->{dbdriver}}|;
+ $query = qq|SELECT $interval{$myconfig->{dbdriver}}|;
- my ($enddate) = $dbh->selectrow_array($query);
+ my ($enddate) = $dbh->selectrow_array($query);
- # calculate nextdate
- $query = qq|
+ # calculate nextdate
+ $query = qq|
SELECT current_date - date ? AS a,
date ? - current_date AS b|;
- $sth = $dbh->prepare($query);
- $sth->execute($s{startdate}, $enddate);
- my ($a, $b) = $sth->fetchrow_array;
-
- if ($a + $b) {
- $advance = int(($a / ($a + $b)) * ($s{howmany} - 1) + 1) * $s{repeat};
- } else {
- $advance = 0;
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $s{startdate}, $enddate );
+ my ( $a, $b ) = $sth->fetchrow_array;
- my $nextdate = $enddate;
- if ($advance > 0) {
- if ($advance < ($s{repeat} * $s{howmany})) {
- %interval = ( 'Pg' => "(date '$s{startdate}' + interval '$advance $s{unit}')",
- 'DB2' => qq|(date ('$s{startdate}') + "$advance $s{unit}")|,);
+ if ( $a + $b ) {
+ $advance =
+ int( ( $a / ( $a + $b ) ) * ( $s{howmany} - 1 ) + 1 ) *
+ $s{repeat};
+ }
+ else {
+ $advance = 0;
+ }
- $interval{Oracle} = $interval{PgPP} = $interval{Pg};
+ my $nextdate = $enddate;
+ if ( $advance > 0 ) {
+ if ( $advance < ( $s{repeat} * $s{howmany} ) ) {
+ %interval = (
+ 'Pg' =>
+ "(date '$s{startdate}' + interval '$advance $s{unit}')",
+ 'DB2' => qq|(date ('$s{startdate}') + "$advance $s{unit}")|,
+ );
+ $interval{Oracle} = $interval{PgPP} = $interval{Pg};
- $query = qq|SELECT $interval{$myconfig->{dbdriver}}|;
+ $query = qq|SELECT $interval{$myconfig->{dbdriver}}|;
- ($nextdate) = $dbh->selectrow_array($query);
- }
+ ($nextdate) = $dbh->selectrow_array($query);
+ }
- } else {
- $nextdate = $s{startdate};
- }
+ }
+ else {
+ $nextdate = $s{startdate};
+ }
- if ($self->{recurringnextdate}) {
+ if ( $self->{recurringnextdate} ) {
- $nextdate = $self->{recurringnextdate};
+ $nextdate = $self->{recurringnextdate};
- $query = qq|SELECT '$enddate' - date '$nextdate'|;
+ $query = qq|SELECT '$enddate' - date '$nextdate'|;
- if ($dbh->selectrow_array($query) < 0) {
- undef $nextdate;
- }
- }
+ if ( $dbh->selectrow_array($query) < 0 ) {
+ undef $nextdate;
+ }
+ }
- $self->{recurringpayment} *= 1;
+ $self->{recurringpayment} *= 1;
- $query = qq|
+ $query = qq|
INSERT INTO recurring
(id, reference, startdate, enddate, nextdate,
repeat, unit, howmany, payment)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute($self->{id}, $s{reference}, $s{startdate},
- $enddate, $nextdate, $s{repeat}, $s{unit}, $s{howmany},
- $s{payment});
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $self->{id}, $s{reference}, $s{startdate},
+ $enddate, $nextdate, $s{repeat},
+ $s{unit}, $s{howmany}, $s{payment}
+ );
+ my @p;
+ my $p;
+ my $i;
+ my $sth;
- my @p;
- my $p;
- my $i;
- my $sth;
+ if ( $s{email} ) {
- if ($s{email}) {
- # formname:format
- @p = split /:/, $s{email};
+ # formname:format
+ @p = split /:/, $s{email};
- $query = qq|INSERT INTO recurringemail (id, formname, format, message)
+ $query =
+ qq|INSERT INTO recurringemail (id, formname, format, message)
VALUES (?, ?, ?, ?)|;
- $sth = $dbh->prepare($query) || $self->dberror($query);
+ $sth = $dbh->prepare($query) || $self->dberror($query);
- for ($i = 0; $i <= $#p; $i += 2) {
- $sth->execute($self->{id}, $p[$i], $p[$i+1],
- $s{message});
- }
+ for ( $i = 0 ; $i <= $#p ; $i += 2 ) {
+ $sth->execute( $self->{id}, $p[$i], $p[ $i + 1 ], $s{message} );
+ }
- $sth->finish;
- }
+ $sth->finish;
+ }
- if ($s{print}) {
- # formname:format:printer
- @p = split /:/, $s{print};
+ if ( $s{print} ) {
- $query = qq|INSERT INTO recurringprint (id, formname, format, printer)
+ # formname:format:printer
+ @p = split /:/, $s{print};
+
+ $query =
+ qq|INSERT INTO recurringprint (id, formname, format, printer)
VALUES (?, ?, ?, ?)|;
- $sth = $dbh->prepare($query) || $self->dberror($query);
+ $sth = $dbh->prepare($query) || $self->dberror($query);
- for ($i = 0; $i <= $#p; $i += 3) {
- $p = ($p[$i+2]) ? $p[$i+2] : "";
- $sth->execute($self->{id}, $p[$i], $p[$i+1], $p);
- }
+ for ( $i = 0 ; $i <= $#p ; $i += 3 ) {
+ $p = ( $p[ $i + 2 ] ) ? $p[ $i + 2 ] : "";
+ $sth->execute( $self->{id}, $p[$i], $p[ $i + 1 ], $p );
+ }
- $sth->finish;
- }
- }
+ $sth->finish;
+ }
+ }
- $dbh->commit;
+ $dbh->commit;
}
-
sub save_intnotes {
- my ($self, $myconfig, $vc) = @_;
+ my ( $self, $myconfig, $vc ) = @_;
- # no id return
- return unless $self->{id};
+ # no id return
+ return unless $self->{id};
- my $dbh = $self->dbconnect($myconfig);
+ my $dbh = $self->dbconnect($myconfig);
- my $query = qq|UPDATE $vc SET intnotes = ? WHERE id = ?|;
+ my $query = qq|UPDATE $vc SET intnotes = ? WHERE id = ?|;
- $sth=$dbh->prepare($query);
- $sth->execute($self->{intnotes}, $self->{id}) || $self->dberror($query);
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $self->{intnotes}, $self->{id} ) || $self->dberror($query);
+ $dbh->commit;
}
-
sub update_defaults {
- my ($self, $myconfig, $fld) = @_;
+ my ( $self, $myconfig, $fld ) = @_;
- if (!$self->{dbh} && $self){
- $self->db_init($myconfig);
- }
-
- my $dbh = $self->{dbh};
+ if ( !$self->{dbh} && $self ) {
+ $self->db_init($myconfig);
+ }
- if (!$self){
- $dbh = $_[3];
- }
+ my $dbh = $self->{dbh};
- my $query = qq|
+ if ( !$self ) {
+ $dbh = $_[3];
+ }
+
+ my $query = qq|
SELECT value FROM defaults
WHERE setting_key = ? FOR UPDATE|;
- $sth = $dbh->prepare($query);
- $sth->execute($fld);
- ($_) = $sth->fetchrow_array();
-
- $_ = "0" unless $_;
-
- # check for and replace
- # <?lsmb DATE ?>, <?lsmb YYMMDD ?>, <?lsmb YEAR ?>, <?lsmb MONTH ?>, <?lsmb DAY ?> or variations of
- # <?lsmb NAME 1 1 3 ?>, <?lsmb BUSINESS ?>, <?lsmb BUSINESS 10 ?>, <?lsmb CURR... ?>
- # <?lsmb DESCRIPTION 1 1 3 ?>, <?lsmb ITEM 1 1 3 ?>, <?lsmb PARTSGROUP 1 1 3 ?> only for parts
- # <?lsmb PHONE ?> for customer and vendors
-
- my $num = $_;
- ($num) = $num =~ /(\d+)/;
-
- if (defined $num) {
- my $incnum;
- # if we have leading zeros check how long it is
-
- if ($num =~ /^0/) {
- my $l = length $num;
- $incnum = $num + 1;
- $l -= length $incnum;
-
- # pad it out with zeros
- my $padzero = "0" x $l;
- $incnum = ("0" x $l) . $incnum;
- } else {
- $incnum = $num + 1;
- }
-
- s/$num/$incnum/;
- }
-
- my $dbvar = $_;
- my $var = $_;
- my $str;
- my $param;
-
- if (/<\?lsmb /) {
-
- while (/<\?lsmb /) {
-
- s/<\?lsmb .*? \?>//;
- last unless $&;
- $param = $&;
- $str = "";
-
- if ($param =~ /<\?lsmb date \?>/i) {
- $str = ($self->split_date($myconfig->{dateformat}, $self->{transdate}))[0];
- $var =~ s/$param/$str/;
- }
-
- if ($param =~ /<\?lsmb (name|business|description|item|partsgroup|phone|custom)/i) {
-
- my $fld = lc $&;
- $fld =~ s/<\?lsmb //;
-
- if ($fld =~ /name/) {
- if ($self->{type}) {
- $fld = $self->{vc};
- }
- }
-
- my $p = $param;
- $p =~ s/(<|>|%)//g;
- my @p = split / /, $p;
- my @n = split / /, uc $self->{$fld};
-
- if ($#p > 0) {
-
- for (my $i = 1; $i <= $#p; $i++) {
- $str .= substr($n[$i-1], 0, $p[$i]);
- }
-
- } else {
- ($str) = split /--/, $self->{$fld};
- }
-
- $var =~ s/$param/$str/;
- $var =~ s/\W//g if $fld eq 'phone';
- }
-
- if ($param =~ /<\?lsmb (yy|mm|dd)/i) {
-
- my $p = $param;
- $p =~ s/(<|>|%)//g;
- my $spc = $p;
- $spc =~ s/\w//g;
- $spc = substr($spc, 0, 1);
- my %d = ( yy => 1, mm => 2, dd => 3 );
- my @p = ();
-
- my @a = $self->split_date($myconfig->{dateformat}, $self->{transdate});
- for (sort keys %d) { push @p, $a[$d{$_}] if ($p =~ /$_/) }
- $str = join $spc, @p;
- $var =~ s/$param/$str/;
- }
-
- if ($param =~ /<\?lsmb curr/i) {
- $var =~ s/$param/$self->{currency}/;
- }
- }
- }
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute($fld);
+ ($_) = $sth->fetchrow_array();
+
+ $_ = "0" unless $_;
+
+# check for and replace
+# <?lsmb DATE ?>, <?lsmb YYMMDD ?>, <?lsmb YEAR ?>, <?lsmb MONTH ?>, <?lsmb DAY ?> or variations of
+# <?lsmb NAME 1 1 3 ?>, <?lsmb BUSINESS ?>, <?lsmb BUSINESS 10 ?>, <?lsmb CURR... ?>
+# <?lsmb DESCRIPTION 1 1 3 ?>, <?lsmb ITEM 1 1 3 ?>, <?lsmb PARTSGROUP 1 1 3 ?> only for parts
+# <?lsmb PHONE ?> for customer and vendors
+
+ my $num = $_;
+ ($num) = $num =~ /(\d+)/;
+
+ if ( defined $num ) {
+ my $incnum;
+
+ # if we have leading zeros check how long it is
+
+ if ( $num =~ /^0/ ) {
+ my $l = length $num;
+ $incnum = $num + 1;
+ $l -= length $incnum;
+
+ # pad it out with zeros
+ my $padzero = "0" x $l;
+ $incnum = ( "0" x $l ) . $incnum;
+ }
+ else {
+ $incnum = $num + 1;
+ }
+
+ s/$num/$incnum/;
+ }
+
+ my $dbvar = $_;
+ my $var = $_;
+ my $str;
+ my $param;
+
+ if (/<\?lsmb /) {
+
+ while (/<\?lsmb /) {
+
+ s/<\?lsmb .*? \?>//;
+ last unless $&;
+ $param = $&;
+ $str = "";
+
+ if ( $param =~ /<\?lsmb date \?>/i ) {
+ $str = (
+ $self->split_date(
+ $myconfig->{dateformat},
+ $self->{transdate}
+ )
+ )[0];
+ $var =~ s/$param/$str/;
+ }
+
+ if ( $param =~
+/<\?lsmb (name|business|description|item|partsgroup|phone|custom)/i
+ )
+ {
+
+ my $fld = lc $&;
+ $fld =~ s/<\?lsmb //;
+
+ if ( $fld =~ /name/ ) {
+ if ( $self->{type} ) {
+ $fld = $self->{vc};
+ }
+ }
+
+ my $p = $param;
+ $p =~ s/(<|>|%)//g;
+ my @p = split / /, $p;
+ my @n = split / /, uc $self->{$fld};
+
+ if ( $#p > 0 ) {
+
+ for ( my $i = 1 ; $i <= $#p ; $i++ ) {
+ $str .= substr( $n[ $i - 1 ], 0, $p[$i] );
+ }
+
+ }
+ else {
+ ($str) = split /--/, $self->{$fld};
+ }
+
+ $var =~ s/$param/$str/;
+ $var =~ s/\W//g if $fld eq 'phone';
+ }
+
+ if ( $param =~ /<\?lsmb (yy|mm|dd)/i ) {
+
+ my $p = $param;
+ $p =~ s/(<|>|%)//g;
+ my $spc = $p;
+ $spc =~ s/\w//g;
+ $spc = substr( $spc, 0, 1 );
+ my %d = ( yy => 1, mm => 2, dd => 3 );
+ my @p = ();
+
+ my @a = $self->split_date( $myconfig->{dateformat},
+ $self->{transdate} );
+ for ( sort keys %d ) { push @p, $a[ $d{$_} ] if ( $p =~ /$_/ ) }
+ $str = join $spc, @p;
+ $var =~ s/$param/$str/;
+ }
+
+ if ( $param =~ /<\?lsmb curr/i ) {
+ $var =~ s/$param/$self->{currency}/;
+ }
+ }
+ }
+
+ $query = qq|
UPDATE defaults
SET value = ?
WHERE setting_key = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($dbvar, $fld) || $self->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $dbvar, $fld ) || $self->dberror($query);
- $dbh->commit;
+ $dbh->commit;
- $var;
+ $var;
}
sub db_prepare_vars {
- my $self = shift;
+ my $self = shift;
- for (@_){
- if (!$self->{$_} and $self->{$_} ne "0"){
- undef $self->{$_};
- }
- }
+ for (@_) {
+ if ( !$self->{$_} and $self->{$_} ne "0" ) {
+ undef $self->{$_};
+ }
+ }
}
sub split_date {
- my ($self, $dateformat, $date) = @_;
-
- my @d = localtime;
- my $mm;
- my $dd;
- my $yy;
- my $rv;
-
- if (! $date) {
- $dd = $d[3];
- $mm = ++$d[4];
- $yy = substr($d[5],-2);
- $mm = substr("0$mm", -2);
- $dd = substr("0$dd", -2);
- }
-
- if ($dateformat =~ /^yy/) {
-
- if ($date) {
-
- if ($date =~ /\D/) {
- ($yy, $mm, $dd) = split /\D/, $date;
- $mm *= 1;
- $dd *= 1;
- $mm = substr("0$mm", -2);
- $dd = substr("0$dd", -2);
- $yy = substr($yy, -2);
- $rv = "$yy$mm$dd";
- } else {
- $rv = $date;
- }
- } else {
- $rv = "$yy$mm$dd";
- }
- }
-
- if ($dateformat =~ /^mm/) {
-
- if ($date) {
-
- if ($date =~ /\D/) {
- ($mm, $dd, $yy) = split /\D/, $date;
- $mm *= 1;
- $dd *= 1;
- $mm = substr("0$mm", -2);
- $dd = substr("0$dd", -2);
- $yy = substr($yy, -2);
- $rv = "$mm$dd$yy";
- } else {
- $rv = $date;
- }
- } else {
- $rv = "$mm$dd$yy";
- }
- }
-
- if ($dateformat =~ /^dd/) {
-
- if ($date) {
-
- if ($date =~ /\D/) {
- ($dd, $mm, $yy) = split /\D/, $date;
- $mm *= 1;
- $dd *= 1;
- $mm = substr("0$mm", -2);
- $dd = substr("0$dd", -2);
- $yy = substr($yy, -2);
- $rv = "$dd$mm$yy";
- } else {
- $rv = $date;
- }
- } else {
- $rv = "$dd$mm$yy";
- }
- }
-
- ($rv, $yy, $mm, $dd);
+ my ( $self, $dateformat, $date ) = @_;
+
+ my @d = localtime;
+ my $mm;
+ my $dd;
+ my $yy;
+ my $rv;
+
+ if ( !$date ) {
+ $dd = $d[3];
+ $mm = ++$d[4];
+ $yy = substr( $d[5], -2 );
+ $mm = substr( "0$mm", -2 );
+ $dd = substr( "0$dd", -2 );
+ }
+
+ if ( $dateformat =~ /^yy/ ) {
+
+ if ($date) {
+
+ if ( $date =~ /\D/ ) {
+ ( $yy, $mm, $dd ) = split /\D/, $date;
+ $mm *= 1;
+ $dd *= 1;
+ $mm = substr( "0$mm", -2 );
+ $dd = substr( "0$dd", -2 );
+ $yy = substr( $yy, -2 );
+ $rv = "$yy$mm$dd";
+ }
+ else {
+ $rv = $date;
+ }
+ }
+ else {
+ $rv = "$yy$mm$dd";
+ }
+ }
+
+ if ( $dateformat =~ /^mm/ ) {
+
+ if ($date) {
+
+ if ( $date =~ /\D/ ) {
+ ( $mm, $dd, $yy ) = split /\D/, $date;
+ $mm *= 1;
+ $dd *= 1;
+ $mm = substr( "0$mm", -2 );
+ $dd = substr( "0$dd", -2 );
+ $yy = substr( $yy, -2 );
+ $rv = "$mm$dd$yy";
+ }
+ else {
+ $rv = $date;
+ }
+ }
+ else {
+ $rv = "$mm$dd$yy";
+ }
+ }
+
+ if ( $dateformat =~ /^dd/ ) {
+
+ if ($date) {
+
+ if ( $date =~ /\D/ ) {
+ ( $dd, $mm, $yy ) = split /\D/, $date;
+ $mm *= 1;
+ $dd *= 1;
+ $mm = substr( "0$mm", -2 );
+ $dd = substr( "0$dd", -2 );
+ $yy = substr( $yy, -2 );
+ $rv = "$dd$mm$yy";
+ }
+ else {
+ $rv = $date;
+ }
+ }
+ else {
+ $rv = "$dd$mm$yy";
+ }
+ }
+
+ ( $rv, $yy, $mm, $dd );
}
-
sub from_to {
- my ($self, $yyyy, $mm, $interval) = @_;
+ my ( $self, $yyyy, $mm, $interval ) = @_;
- my @t;
- my $dd = 1;
- my $fromdate = "$yyyy-${mm}-01";
- my $bd = 1;
+ my @t;
+ my $dd = 1;
+ my $fromdate = "$yyyy-${mm}-01";
+ my $bd = 1;
- if (defined $interval) {
+ if ( defined $interval ) {
- if ($interval == 12) {
- $yyyy++;
- } else {
+ if ( $interval == 12 ) {
+ $yyyy++;
+ }
+ else {
- if (($mm += $interval) > 12) {
- $mm -= 12;
- $yyyy++;
- }
+ if ( ( $mm += $interval ) > 12 ) {
+ $mm -= 12;
+ $yyyy++;
+ }
- if ($interval == 0) {
- @t = localtime(time);
- $dd = $t[3];
- $mm = $t[4] + 1;
- $yyyy = $t[5] + 1900;
- $bd = 0;
- }
- }
+ if ( $interval == 0 ) {
+ @t = localtime(time);
+ $dd = $t[3];
+ $mm = $t[4] + 1;
+ $yyyy = $t[5] + 1900;
+ $bd = 0;
+ }
+ }
- } else {
+ }
+ else {
- if (++$mm > 12) {
- $mm -= 12;
- $yyyy++;
- }
- }
+ if ( ++$mm > 12 ) {
+ $mm -= 12;
+ $yyyy++;
+ }
+ }
- $mm--;
- @t = localtime(Time::Local::timelocal(0,0,0,$dd,$mm,$yyyy) - $bd);
+ $mm--;
+ @t = localtime( Time::Local::timelocal( 0, 0, 0, $dd, $mm, $yyyy ) - $bd );
- $t[4]++;
- $t[4] = substr("0$t[4]",-2);
- $t[3] = substr("0$t[3]",-2);
- $t[5] += 1900;
+ $t[4]++;
+ $t[4] = substr( "0$t[4]", -2 );
+ $t[3] = substr( "0$t[3]", -2 );
+ $t[5] += 1900;
- ($self->format_date($fromdate),
- $self->format_date("$t[5]-$t[4]-$t[3]"));
+ ( $self->format_date($fromdate), $self->format_date("$t[5]-$t[4]-$t[3]") );
}
sub audittrail {
- my ($self, $dbh, $myconfig, $audittrail) = @_;
+ my ( $self, $dbh, $myconfig, $audittrail ) = @_;
- # table, $reference, $formname, $action, $id, $transdate) = @_;
+ # table, $reference, $formname, $action, $id, $transdate) = @_;
- my $query;
- my $rv;
- my $disconnect;
+ my $query;
+ my $rv;
+ my $disconnect;
- if (! $dbh) {
- $dbh = $self->{dbh};
- }
+ if ( !$dbh ) {
+ $dbh = $self->{dbh};
+ }
- # if we have an id add audittrail, otherwise get a new timestamp
+ # if we have an id add audittrail, otherwise get a new timestamp
- my @queryargs;
+ my @queryargs;
- if ($audittrail->{id}) {
+ if ( $audittrail->{id} ) {
- $query = qq|
+ $query = qq|
SELECT value FROM defaults
WHERE setting_key = 'audittrail'|;
- if ($dbh->selectrow_array($query)) {
+ if ( $dbh->selectrow_array($query) ) {
- my ($null, $employee_id) = $self->get_employee($dbh);
+ my ( $null, $employee_id ) = $self->get_employee($dbh);
- if ($self->{audittrail} && !$myconfig) {
+ if ( $self->{audittrail} && !$myconfig ) {
- chop $self->{audittrail};
+ chop $self->{audittrail};
- my @a = split /\|/, $self->{audittrail};
- my %newtrail = ();
- my $key;
- my $i;
- my @flds = qw(tablename reference formname action transdate);
+ my @a = split /\|/, $self->{audittrail};
+ my %newtrail = ();
+ my $key;
+ my $i;
+ my @flds = qw(tablename reference formname action transdate);
- # put into hash and remove dups
- while (@a) {
- $key = "$a[2]$a[3]";
- $i = 0;
- $newtrail{$key} = { map { $_ => $a[$i++] } @flds };
- splice @a, 0, 5;
- }
+ # put into hash and remove dups
+ while (@a) {
+ $key = "$a[2]$a[3]";
+ $i = 0;
+ $newtrail{$key} = { map { $_ => $a[ $i++ ] } @flds };
+ splice @a, 0, 5;
+ }
- $query = qq|
+ $query = qq|
INSERT INTO audittrail
(trans_id, tablename, reference,
formname, action, transdate,
employee_id)
VALUES (?, ?, ?, ?, ?, ?, ?)|;
- my $sth = $dbh->prepare($query) || $self->dberror($query);
+ my $sth = $dbh->prepare($query) || $self->dberror($query);
- foreach $key (sort { $newtrail{$a}{transdate} cmp $newtrail{$b}{transdate} } keys %newtrail) {
+ foreach $key (
+ sort {
+ $newtrail{$a}{transdate} cmp $newtrail{$b}{transdate}
+ } keys %newtrail
+ )
+ {
- $i = 2;
- $sth->bind_param(1, $audittrail->{id});
+ $i = 2;
+ $sth->bind_param( 1, $audittrail->{id} );
- for (@flds) { $sth->bind_param($i++, $newtrail{$key}{$_}) }
- $sth->bind_param($i++, $employee_id);
- $sth->execute || $self->dberror;
- $sth->finish;
- }
- }
+ for (@flds) {
+ $sth->bind_param( $i++, $newtrail{$key}{$_} );
+ }
+ $sth->bind_param( $i++, $employee_id );
+ $sth->execute || $self->dberror;
+ $sth->finish;
+ }
+ }
- if ($audittrail->{transdate}) {
+ if ( $audittrail->{transdate} ) {
- $query = qq|
+ $query = qq|
INSERT INTO audittrail (
trans_id, tablename, reference,
formname, action, employee_id,
transdate)
VALUES (?, ?, ?, ?, ?, ?, ?)|;
- @queryargs = (
- $audittrail->{id},
- $audittrail->{tablename},
- $audittrail->{reference},
- $audittrail->{formname},
- $audittrail->{action},
- $employee_id,
- $audittrail->{transdate}
- );
- } else {
- $query = qq|
+ @queryargs = (
+ $audittrail->{id}, $audittrail->{tablename},
+ $audittrail->{reference}, $audittrail->{formname},
+ $audittrail->{action}, $employee_id,
+ $audittrail->{transdate}
+ );
+ }
+ else {
+ $query = qq|
INSERT INTO audittrail
(trans_id, tablename, reference,
formname, action, employee_id)
VALUES (?, ?, ?, ?, ?, ?)|;
- @queryargs = (
- $audittrail->{id},
- $audittrail->{tablename},
- $audittrail->{reference},
- $audittrail->{formname},
- $audittrail->{action},
- $employee_id,
- );
- }
-
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs)||$self->dberror($query);
- }
-
- } else {
-
- $query = qq|SELECT current_timestamp|;
- my ($timestamp) = $dbh->selectrow_array($query);
-
- $rv = "$audittrail->{tablename}|$audittrail->{reference}|$audittrail->{formname}|$audittrail->{action}|$timestamp|";
- }
-
- $dbh->commit;
- $rv;
+ @queryargs = (
+ $audittrail->{id}, $audittrail->{tablename},
+ $audittrail->{reference}, $audittrail->{formname},
+ $audittrail->{action}, $employee_id,
+ );
+ }
+
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $self->dberror($query);
+ }
+
+ }
+ else {
+
+ $query = qq|SELECT current_timestamp|;
+ my ($timestamp) = $dbh->selectrow_array($query);
+
+ $rv =
+"$audittrail->{tablename}|$audittrail->{reference}|$audittrail->{formname}|$audittrail->{action}|$timestamp|";
+ }
+
+ $dbh->commit;
+ $rv;
}
1;
diff --git a/LedgerSMB/GL.pm b/LedgerSMB/GL.pm
index dab7b0a1..a5c39dbb 100644
--- a/LedgerSMB/GL.pm
+++ b/LedgerSMB/GL.pm
@@ -1,5 +1,5 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
#
@@ -33,141 +33,138 @@
package GL;
-
sub delete_transaction {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my %audittrail = (
- tablename => 'gl',
- reference => $form->{reference},
- formname => 'transaction',
- action => 'deleted',
- id => $form->{id} );
+ my %audittrail = (
+ tablename => 'gl',
+ reference => $form->{reference},
+ formname => 'transaction',
+ action => 'deleted',
+ id => $form->{id}
+ );
- $form->audittrail($dbh, "", \%audittrail);
- my $id = $dbh->quote($form->{id});
- my $query = qq|DELETE FROM gl WHERE id = $id|;
- $dbh->do($query) || $form->dberror($query);
+ $form->audittrail( $dbh, "", \%audittrail );
+ my $id = $dbh->quote( $form->{id} );
+ my $query = qq|DELETE FROM gl WHERE id = $id|;
+ $dbh->do($query) || $form->dberror($query);
- $query = qq|DELETE FROM acc_trans WHERE trans_id = $id|;
- $dbh->do($query) || $form->dberror($query);
+ $query = qq|DELETE FROM acc_trans WHERE trans_id = $id|;
+ $dbh->do($query) || $form->dberror($query);
- # commit and redirect
- my $rc = $dbh->commit;
+ # commit and redirect
+ my $rc = $dbh->commit;
- $rc;
+ $rc;
}
-
sub post_transaction {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $null;
+ my $project_id;
+ my $department_id;
+ my $i;
- my $null;
- my $project_id;
- my $department_id;
- my $i;
+ # connect to database, turn off AutoCommit
+ my $dbh = $form->{dbh};
- # connect to database, turn off AutoCommit
- my $dbh = $form->{dbh};
+ my $query;
+ my $sth;
- my $query;
- my $sth;
+ my $id = $dbh->quote( $form->{id} );
+ if ( $form->{id} ) {
- my $id = $dbh->quote($form->{id});
- if ($form->{id}) {
+ $query = qq|SELECT id FROM gl WHERE id = $id|;
+ ( $form->{id} ) = $dbh->selectrow_array($query);
- $query = qq|SELECT id FROM gl WHERE id = $id|;
- ($form->{id}) = $dbh->selectrow_array($query);
+ if ( $form->{id} ) {
- if ($form->{id}) {
- # delete individual transactions
- $query = qq|
+ # delete individual transactions
+ $query = qq|
DELETE FROM acc_trans WHERE trans_id = $id|;
- $dbh->do($query) || $form->dberror($query);
- }
- }
+ $dbh->do($query) || $form->dberror($query);
+ }
+ }
- if (! $form->{id}) {
+ if ( !$form->{id} ) {
- my $uid = localtime;
- $uid .= "$$";
+ my $uid = localtime;
+ $uid .= "$$";
- $query = qq|
+ $query = qq|
INSERT INTO gl (reference, employee_id)
VALUES ('$uid', (SELECT id FROM employee
WHERE login = ?))|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{login}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{login} ) || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT id
FROM gl
WHERE reference = '$uid'|;
-
- ($form->{id}) = $dbh->selectrow_array($query);
- }
- ($null, $department_id) = split /--/, $form->{department};
- $department_id *= 1;
+ ( $form->{id} ) = $dbh->selectrow_array($query);
+ }
- $form->{reference} = $form->update_defaults(
- $myconfig, 'glnumber', $dbh)
- unless $form->{reference};
- $form->{reference} ||= $form->{id};
+ ( $null, $department_id ) = split /--/, $form->{department};
+ $department_id *= 1;
- $query = qq|
+ $form->{reference} = $form->update_defaults( $myconfig, 'glnumber', $dbh )
+ unless $form->{reference};
+ $form->{reference} ||= $form->{id};
+
+ $query = qq|
UPDATE gl
- SET reference = |.$dbh->quote($form->{reference}).qq|,
- description = |.$dbh->quote($form->{description}).qq|,
- notes = |.$dbh->quote($form->{notes}).qq|,
+ SET reference = | . $dbh->quote( $form->{reference} ) . qq|,
+ description = | . $dbh->quote( $form->{description} ) . qq|,
+ notes = | . $dbh->quote( $form->{notes} ) . qq|,
transdate = ?,
department_id = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{transdate}, $department_id, $form->{id})
- || $form->dberror($query);
-
- my $amount = 0;
- my $posted = 0;
- my $debit;
- my $credit;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{transdate}, $department_id, $form->{id} )
+ || $form->dberror($query);
- # insert acc_trans transactions
- for $i (1 .. $form->{rowcount}) {
+ my $amount = 0;
+ my $posted = 0;
+ my $debit;
+ my $credit;
- $debit = $form->parse_amount($myconfig, $form->{"debit_$i"});
- $credit = $form->parse_amount($myconfig, $form->{"credit_$i"});
+ # insert acc_trans transactions
+ for $i ( 1 .. $form->{rowcount} ) {
- # extract accno
- ($accno) = split(/--/, $form->{"accno_$i"});
+ $debit = $form->parse_amount( $myconfig, $form->{"debit_$i"} );
+ $credit = $form->parse_amount( $myconfig, $form->{"credit_$i"} );
- if ($credit) {
- $amount = $credit;
- $posted = 0;
- }
+ # extract accno
+ ($accno) = split( /--/, $form->{"accno_$i"} );
- if ($debit) {
- $amount = $debit * -1;
- $posted = 0;
- }
+ if ($credit) {
+ $amount = $credit;
+ $posted = 0;
+ }
- # add the record
- if (! $posted) {
+ if ($debit) {
+ $amount = $debit * -1;
+ $posted = 0;
+ }
- ($null, $project_id) = split /--/,
- $form->{"projectnumber_$i"};
- $project_id ||= undef;
+ # add the record
+ if ( !$posted ) {
+ ( $null, $project_id ) = split /--/, $form->{"projectnumber_$i"};
+ $project_id ||= undef;
- $query = qq|
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate, source, project_id,
@@ -177,232 +174,228 @@ sub post_transaction {
WHERE accno = ?),
?, ?, ?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $accno, $amount,
- $form->{transdate}, $form->{"source_$i"},
- $project_id, $form->{"fx_transaction_$i"},
- $form->{"memo_$i"}, $form->{"cleared_$i"}
- ) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{id}, $accno,
+ $amount, $form->{transdate},
+ $form->{"source_$i"}, $project_id,
+ $form->{"fx_transaction_$i"}, $form->{"memo_$i"},
+ $form->{"cleared_$i"}
+ ) || $form->dberror($query);
- $posted = 1;
- }
- }
+ $posted = 1;
+ }
+ }
- my %audittrail = (
- tablename => 'gl',
- reference => $form->{reference},
- formname => 'transaction',
- action => 'posted',
- id => $form->{id} );
+ my %audittrail = (
+ tablename => 'gl',
+ reference => $form->{reference},
+ formname => 'transaction',
+ action => 'posted',
+ id => $form->{id}
+ );
- $form->audittrail($dbh, "", \%audittrail);
+ $form->audittrail( $dbh, "", \%audittrail );
- $form->save_recurring($dbh, $myconfig);
+ $form->save_recurring( $dbh, $myconfig );
- # commit and redirect
- my $rc = $dbh->commit;
+ # commit and redirect
+ my $rc = $dbh->commit;
- $rc;
+ $rc;
}
-
-
sub all_transactions {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
- my $query;
- my $sth;
- my $var;
- my $null;
-
- my ($glwhere, $arwhere, $apwhere) = ("1 = 1", "1 = 1", "1 = 1");
-
- if ($form->{reference} ne "") {
- $var = $dbh->quote($form->like(lc $form->{reference}));
- $glwhere .= " AND lower(g.reference) LIKE $var";
- $arwhere .= " AND lower(a.invnumber) LIKE $var";
- $apwhere .= " AND lower(a.invnumber) LIKE $var";
- }
-
- if ($form->{department} ne "") {
- ($null, $var) = split /--/, $form->{department};
- $var = $dbh->quote($var);
- $glwhere .= " AND g.department_id = $var";
- $arwhere .= " AND a.department_id = $var";
- $apwhere .= " AND a.department_id = $var";
- }
-
- if ($form->{source} ne "") {
- $var = $dbh->quote($form->like(lc $form->{source}));
- $glwhere .= " AND lower(ac.source) LIKE $var";
- $arwhere .= " AND lower(ac.source) LIKE $var";
- $apwhere .= " AND lower(ac.source) LIKE $var";
- }
-
- if ($form->{memo} ne "") {
- $var = $form->like(lc $form->{memo});
- $glwhere .= " AND lower(ac.memo) LIKE $var";
- $arwhere .= " AND lower(ac.memo) LIKE $var";
- $apwhere .= " AND lower(ac.memo) LIKE $var";
- }
-
- ($form->{datefrom}, $form->{dateto}) = $form->from_to(
- $form->{year}, $form->{month}, $form->{interval})
- if $form->{year} && $form->{month};
-
- if ($form->{datefrom}) {
- $glwhere .= " AND ac.transdate >= ".
- $dbh->quote($form->{datefrom});
- $arwhere .= " AND ac.transdate >= ".
- $dbh->quote($form->{datefrom});
- $apwhere .= " AND ac.transdate >= ".
- $dbh->quote($form->{datefrom});
- }
-
- if ($form->{dateto}) {
- $glwhere .= " AND ac.transdate <= ".
- $dbh->quote($form->{dateto});
- $arwhere .= " AND ac.transdate <= ".
- $dbh->quote($form->{dateto});
- $apwhere .= " AND ac.transdate <= ".
- $dbh->quote($form->{dateto});
- }
-
- if ($form->{amountfrom}) {
- $glwhere .= " AND abs(ac.amount) >= ".
- $dbh->quote($form->{amountfrom});
- $arwhere .= " AND abs(ac.amount) >= ".
- $dbh->quote($form->{amountfrom});
- $apwhere .= " AND abs(ac.amount) >= ".
- $dbh->quote($form->{amountfrom});
- }
-
- if ($form->{amountto}) {
- $glwhere .= " AND abs(ac.amount) <= ".
- $dbh->quote($form->{amountto});
- $arwhere .= " AND abs(ac.amount) <= ".
- $dbh->quote($form->{amountto});
- $apwhere .= " AND abs(ac.amount) <= ".
- $dbh->quote($form->{amountto});
- }
-
- if ($form->{description}) {
-
- $var = $dbh->quote($form->like(lc $form->{description}));
- $glwhere .= " AND lower(g.description) LIKE $var";
- $arwhere .= " AND (lower(ct.name) LIKE $var
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+ my $query;
+ my $sth;
+ my $var;
+ my $null;
+
+ my ( $glwhere, $arwhere, $apwhere ) = ( "1 = 1", "1 = 1", "1 = 1" );
+
+ if ( $form->{reference} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{reference} ) );
+ $glwhere .= " AND lower(g.reference) LIKE $var";
+ $arwhere .= " AND lower(a.invnumber) LIKE $var";
+ $apwhere .= " AND lower(a.invnumber) LIKE $var";
+ }
+
+ if ( $form->{department} ne "" ) {
+ ( $null, $var ) = split /--/, $form->{department};
+ $var = $dbh->quote($var);
+ $glwhere .= " AND g.department_id = $var";
+ $arwhere .= " AND a.department_id = $var";
+ $apwhere .= " AND a.department_id = $var";
+ }
+
+ if ( $form->{source} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{source} ) );
+ $glwhere .= " AND lower(ac.source) LIKE $var";
+ $arwhere .= " AND lower(ac.source) LIKE $var";
+ $apwhere .= " AND lower(ac.source) LIKE $var";
+ }
+
+ if ( $form->{memo} ne "" ) {
+ $var = $form->like( lc $form->{memo} );
+ $glwhere .= " AND lower(ac.memo) LIKE $var";
+ $arwhere .= " AND lower(ac.memo) LIKE $var";
+ $apwhere .= " AND lower(ac.memo) LIKE $var";
+ }
+
+ ( $form->{datefrom}, $form->{dateto} ) =
+ $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
+ if $form->{year} && $form->{month};
+
+ if ( $form->{datefrom} ) {
+ $glwhere .= " AND ac.transdate >= " . $dbh->quote( $form->{datefrom} );
+ $arwhere .= " AND ac.transdate >= " . $dbh->quote( $form->{datefrom} );
+ $apwhere .= " AND ac.transdate >= " . $dbh->quote( $form->{datefrom} );
+ }
+
+ if ( $form->{dateto} ) {
+ $glwhere .= " AND ac.transdate <= " . $dbh->quote( $form->{dateto} );
+ $arwhere .= " AND ac.transdate <= " . $dbh->quote( $form->{dateto} );
+ $apwhere .= " AND ac.transdate <= " . $dbh->quote( $form->{dateto} );
+ }
+
+ if ( $form->{amountfrom} ) {
+ $glwhere .=
+ " AND abs(ac.amount) >= " . $dbh->quote( $form->{amountfrom} );
+ $arwhere .=
+ " AND abs(ac.amount) >= " . $dbh->quote( $form->{amountfrom} );
+ $apwhere .=
+ " AND abs(ac.amount) >= " . $dbh->quote( $form->{amountfrom} );
+ }
+
+ if ( $form->{amountto} ) {
+ $glwhere .=
+ " AND abs(ac.amount) <= " . $dbh->quote( $form->{amountto} );
+ $arwhere .=
+ " AND abs(ac.amount) <= " . $dbh->quote( $form->{amountto} );
+ $apwhere .=
+ " AND abs(ac.amount) <= " . $dbh->quote( $form->{amountto} );
+ }
+
+ if ( $form->{description} ) {
+
+ $var = $dbh->quote( $form->like( lc $form->{description} ) );
+ $glwhere .= " AND lower(g.description) LIKE $var";
+ $arwhere .= " AND (lower(ct.name) LIKE $var
OR lower(ac.memo) LIKE $var
OR a.id IN (SELECT DISTINCT trans_id
FROM invoice
WHERE lower(description) LIKE $var))";
- $apwhere .= " AND (lower(ct.name) LIKE $var
+ $apwhere .= " AND (lower(ct.name) LIKE $var
OR lower(ac.memo) LIKE $var
OR a.id IN (SELECT DISTINCT trans_id
FROM invoice
WHERE lower(description) LIKE $var))";
- }
-
- if ($form->{notes}) {
- $var = $dbh->quote($form->like(lc $form->{notes}));
- $glwhere .= " AND lower(g.notes) LIKE $var";
- $arwhere .= " AND lower(a.notes) LIKE $var";
- $apwhere .= " AND lower(a.notes) LIKE $var";
- }
-
- if ($form->{accno}) {
- $var = $dbh->quote($form->{accno});
- $glwhere .= " AND c.accno = $var";
- $arwhere .= " AND c.accno = $var";
- $apwhere .= " AND c.accno = $var";
- }
-
- if ($form->{gifi_accno}) {
- $var = $dbh->quote($form->{gifiaccno});
- $glwhere .= " AND c.gifi_accno = $var";
- $arwhere .= " AND c.gifi_accno = $var";
- $apwhere .= " AND c.gifi_accno = $var";
- }
-
- if ($form->{category} ne 'X') {
- $var = $dbh->quote($form->{gifiaccno});
- $glwhere .= " AND c.category = $var";
- $arwhere .= " AND c.category = $var";
- $apwhere .= " AND c.category = $var";
- }
-
- if ($form->{accno}) {
- my $accno = $dbh->quote($form->{accno});
-
- # get category for account
- $query = qq|SELECT category, link, contra, description
+ }
+
+ if ( $form->{notes} ) {
+ $var = $dbh->quote( $form->like( lc $form->{notes} ) );
+ $glwhere .= " AND lower(g.notes) LIKE $var";
+ $arwhere .= " AND lower(a.notes) LIKE $var";
+ $apwhere .= " AND lower(a.notes) LIKE $var";
+ }
+
+ if ( $form->{accno} ) {
+ $var = $dbh->quote( $form->{accno} );
+ $glwhere .= " AND c.accno = $var";
+ $arwhere .= " AND c.accno = $var";
+ $apwhere .= " AND c.accno = $var";
+ }
+
+ if ( $form->{gifi_accno} ) {
+ $var = $dbh->quote( $form->{gifiaccno} );
+ $glwhere .= " AND c.gifi_accno = $var";
+ $arwhere .= " AND c.gifi_accno = $var";
+ $apwhere .= " AND c.gifi_accno = $var";
+ }
+
+ if ( $form->{category} ne 'X' ) {
+ $var = $dbh->quote( $form->{gifiaccno} );
+ $glwhere .= " AND c.category = $var";
+ $arwhere .= " AND c.category = $var";
+ $apwhere .= " AND c.category = $var";
+ }
+
+ if ( $form->{accno} ) {
+ my $accno = $dbh->quote( $form->{accno} );
+
+ # get category for account
+ $query = qq|SELECT category, link, contra, description
FROM chart
WHERE accno = $accno|;
- ($form->{category}, $form->{link}, $form->{contra},
- $form->{account_description}) = $dbh->selectrow_array($query);
+ (
+ $form->{category}, $form->{link}, $form->{contra},
+ $form->{account_description}
+ ) = $dbh->selectrow_array($query);
- if ($form->{datefrom}) {
+ if ( $form->{datefrom} ) {
- $query = qq|
+ $query = qq|
SELECT SUM(ac.amount)
FROM acc_trans ac
JOIN chart c ON (ac.chart_id = c.id)
WHERE c.accno = $accno
- AND ac.transdate < date |.
- $dbh->quote($form->{datefrom});
+ AND ac.transdate < date | . $dbh->quote( $form->{datefrom} );
- ($form->{balance}) = $dbh->selectrow_array($query);
- }
- }
+ ( $form->{balance} ) = $dbh->selectrow_array($query);
+ }
+ }
- if ($form->{gifi_accno}) {
- my $gifi = $dbh->quote($form->{gifi_accno});
+ if ( $form->{gifi_accno} ) {
+ my $gifi = $dbh->quote( $form->{gifi_accno} );
- # get category for account
- $query = qq|SELECT c.category, c.link, c.contra, g.description
+ # get category for account
+ $query = qq|SELECT c.category, c.link, c.contra, g.description
FROM chart c
LEFT JOIN gifi g ON (g.accno = c.gifi_accno)
WHERE c.gifi_accno = $gifi|;
- ($form->{category}, $form->{link}, $form->{contra},
- $form->{gifi_account_description}) = $dbh->selectrow_array(
- $query);
+ (
+ $form->{category}, $form->{link}, $form->{contra},
+ $form->{gifi_account_description}
+ ) = $dbh->selectrow_array($query);
- if ($form->{datefrom}) {
+ if ( $form->{datefrom} ) {
- $query = qq|
+ $query = qq|
SELECT SUM(ac.amount)
FROM acc_trans ac
JOIN chart c ON (ac.chart_id = c.id)
WHERE c.gifi_accno = $gifi
- AND ac.transdate < date |.
- $dbh->quote($form->{datefrom});
+ AND ac.transdate < date | . $dbh->quote( $form->{datefrom} );
- ($form->{balance}) = $dbh->selectrow_array($query);
- }
- }
+ ( $form->{balance} ) = $dbh->selectrow_array($query);
+ }
+ }
- my $false = 'FALSE';
+ my $false = 'FALSE';
- my %ordinal = (
- id => 1,
- reference => 4,
- description => 5,
- transdate => 6,
- source => 7,
- accno => 9,
- department => 15,
- memo => 16 );
+ my %ordinal = (
+ id => 1,
+ reference => 4,
+ description => 5,
+ transdate => 6,
+ source => 7,
+ accno => 9,
+ department => 15,
+ memo => 16
+ );
- my @a = (id, transdate, reference, source, description, accno);
- my $sortorder = $form->sort_order(\@a, \%ordinal);
+ my @a = ( id, transdate, reference, source, description, accno );
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
- my $query = qq|SELECT g.id, 'gl' AS type, $false AS invoice, g.reference,
+ my $query = qq|SELECT g.id, 'gl' AS type, $false AS invoice, g.reference,
g.description, ac.transdate, ac.source,
ac.amount, c.accno, c.gifi_accno, g.notes, c.link,
'' AS till, ac.cleared, d.description AS department,
@@ -442,150 +435,153 @@ sub all_transactions {
WHERE $apwhere
ORDER BY $sortorder|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- # gl
- if ($ref->{type} eq "gl") {
- $ref->{module} = "gl";
- }
-
- # ap
- if ($ref->{type} eq "ap") {
-
- if ($ref->{invoice}) {
- $ref->{module} = "ir";
- } else {
- $ref->{module} = "ap";
- }
- }
-
- # ar
- if ($ref->{type} eq "ar") {
-
- if ($ref->{invoice}) {
- $ref->{module} = ($ref->{till}) ? "ps" : "is";
- } else {
- $ref->{module} = "ar";
- }
- }
-
- if ($ref->{amount} < 0) {
- $ref->{debit} = $ref->{amount} * -1;
- $ref->{credit} = 0;
- } else {
- $ref->{credit} = $ref->{amount};
- $ref->{debit} = 0;
- }
-
- push @{ $form->{GL} }, $ref;
- }
-
- $sth->finish;
- $dbh->commit;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ # gl
+ if ( $ref->{type} eq "gl" ) {
+ $ref->{module} = "gl";
+ }
+
+ # ap
+ if ( $ref->{type} eq "ap" ) {
+
+ if ( $ref->{invoice} ) {
+ $ref->{module} = "ir";
+ }
+ else {
+ $ref->{module} = "ap";
+ }
+ }
+
+ # ar
+ if ( $ref->{type} eq "ar" ) {
+
+ if ( $ref->{invoice} ) {
+ $ref->{module} = ( $ref->{till} ) ? "ps" : "is";
+ }
+ else {
+ $ref->{module} = "ar";
+ }
+ }
+
+ if ( $ref->{amount} < 0 ) {
+ $ref->{debit} = $ref->{amount} * -1;
+ $ref->{credit} = 0;
+ }
+ else {
+ $ref->{credit} = $ref->{amount};
+ $ref->{debit} = 0;
+ }
+
+ push @{ $form->{GL} }, $ref;
+ }
+
+ $sth->finish;
+ $dbh->commit;
}
-
sub transaction {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my ($query, $sth, $ref);
+ my ( $query, $sth, $ref );
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- if ($form->{id}) {
+ if ( $form->{id} ) {
- $query = "SELECT setting_key, value
+ $query = "SELECT setting_key, value
FROM defaults
WHERE setting_key IN
('closedto', 'revtrans')";
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- my $results = $sth->fetchall_hashref('setting_key');
- $form->{closedto} = $results->{'closedto'}->{'value'};
- $form->{revtrans} = $results->{'revtrans'}->{'value'};
- $sth->finish;
+ my $results = $sth->fetchall_hashref('setting_key');
+ $form->{closedto} = $results->{'closedto'}->{'value'};
+ $form->{revtrans} = $results->{'revtrans'}->{'value'};
+ $sth->finish;
- $query = qq|SELECT g.*, d.description AS department
+ $query = qq|SELECT g.*, d.description AS department
FROM gl g
LEFT JOIN department d ON (d.id = g.department_id)
WHERE g.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
- # retrieve individual rows
- $query = qq|SELECT ac.*, c.accno, c.description, p.projectnumber
+ # retrieve individual rows
+ $query = qq|SELECT ac.*, c.accno, c.description, p.projectnumber
FROM acc_trans ac
JOIN chart c ON (ac.chart_id = c.id)
LEFT JOIN project p ON (p.id = ac.project_id)
WHERE ac.trans_id = ?
ORDER BY accno|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
- if ($ref->{fx_transaction}) {
- $form->{transfer} = 1;
- }
- push @{ $form->{GL} }, $ref;
- }
+ if ( $ref->{fx_transaction} ) {
+ $form->{transfer} = 1;
+ }
+ push @{ $form->{GL} }, $ref;
+ }
- # get recurring transaction
- $form->get_recurring($dbh);
+ # get recurring transaction
+ $form->get_recurring($dbh);
- } else {
+ }
+ else {
- $query = "SELECT current_date AS transdate, setting_key, value
+ $query = "SELECT current_date AS transdate, setting_key, value
FROM defaults
WHERE setting_key IN
('closedto', 'revtrans')";
-
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
- my $results = $sth->fetchall_hashref('setting_key');
- $form->{closedto} = $results->{'closedto'}->{'value'};
- $form->{revtrans} = $results->{'revtrans'}->{'value'};
- $form->{transdate} = $results->{'revtrans'}->{'transdate'};
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ my $results = $sth->fetchall_hashref('setting_key');
+ $form->{closedto} = $results->{'closedto'}->{'value'};
+ $form->{revtrans} = $results->{'revtrans'}->{'value'};
+ $form->{transdate} = $results->{'revtrans'}->{'transdate'};
+ }
- $sth->finish;
+ $sth->finish;
- # get chart of accounts
- $query = qq|SELECT accno,description
+ # get chart of accounts
+ $query = qq|SELECT accno,description
FROM chart
WHERE charttype = 'A'
ORDER BY accno|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_accno} }, $ref;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_accno} }, $ref;
+ }
- $sth->finish;
+ $sth->finish;
- # get departments
- $form->all_departments($myconfig, $dbh);
+ # get departments
+ $form->all_departments( $myconfig, $dbh );
- # get projects
- $form->all_projects($myconfig, $dbh, $form->{transdate});
+ # get projects
+ $form->all_projects( $myconfig, $dbh, $form->{transdate} );
- $dbh->commit;
+ $dbh->commit;
}
diff --git a/LedgerSMB/HR.pm b/LedgerSMB/HR.pm
index 33e9b18a..c9869e15 100644
--- a/LedgerSMB/HR.pm
+++ b/LedgerSMB/HR.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -33,103 +33,102 @@
package HR;
-
sub get_employee {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my $query;
- my $sth;
- my $ref;
- my $notid = "";
-
- if ($form->{id}) {
- $query = qq|SELECT e.* FROM employees e WHERE e.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror(__FILE__.':'.__LINE__.':'.$query);
-
- $ref = $sth->fetchrow_hashref(NAME_lc);
-
- # check if employee can be deleted, orphaned
- $form->{status} = "orphaned" unless $ref->{login};
-
-
- $ref->{employeelogin} = $ref->{login};
- delete $ref->{login};
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
-
- $sth->finish;
-
- # get manager
- $form->{managerid} *= 1;
-
- $sth = $dbh->prepare("SELECT name FROM employees WHERE id = ?");
- $sth->execute($form->{managerid});
- ($form->{manager}) = $sth->fetchrow_array;
-
-
- $notid = qq|AND id != |.$dbh->quote($form->{id});
-
- } else {
-
- ($form->{startdate}) = $dbh->selectrow_array("SELECT current_date");
-
- }
-
- # get managers
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my $query;
+ my $sth;
+ my $ref;
+ my $notid = "";
+
+ if ( $form->{id} ) {
+ $query = qq|SELECT e.* FROM employees e WHERE e.id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} )
+ || $form->dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
+
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+
+ # check if employee can be deleted, orphaned
+ $form->{status} = "orphaned" unless $ref->{login};
+
+ $ref->{employeelogin} = $ref->{login};
+ delete $ref->{login};
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+
+ $sth->finish;
+
+ # get manager
+ $form->{managerid} *= 1;
+
+ $sth = $dbh->prepare("SELECT name FROM employees WHERE id = ?");
+ $sth->execute( $form->{managerid} );
+ ( $form->{manager} ) = $sth->fetchrow_array;
+
+ $notid = qq|AND id != | . $dbh->quote( $form->{id} );
+
+ }
+ else {
+
+ ( $form->{startdate} ) = $dbh->selectrow_array("SELECT current_date");
+
+ }
+
+ # get managers
+ $query = qq|
SELECT id, name
FROM employees
WHERE sales = '1'
AND role = 'manager'
$notid
ORDER BY 2|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror(__FILE__.':'.__LINE__.':'.$query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_manager} }, $ref;
- }
- $sth->finish;
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_manager} }, $ref;
+ }
+ $sth->finish;
- $dbh->commit;
+ $dbh->commit;
}
-
-
sub save_employee {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
- my $query;
- my $sth;
+ my $dbh = $form->{dbh};
+ my $query;
+ my $sth;
- if (! $form->{id}) {
- my $uid = localtime;
- $uid .= "$$";
+ if ( !$form->{id} ) {
+ my $uid = localtime;
+ $uid .= "$$";
- $query = qq|INSERT INTO employees (name) VALUES ('$uid')|;
- $dbh->do($query) || $form->dberror(__FILE__.':'.__LINE__.':'.$query);
-
- $query = qq|SELECT id FROM employees WHERE name = '$uid'|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror(__FILE__.':'.__LINE__.':'.$query);
+ $query = qq|INSERT INTO employees (name) VALUES ('$uid')|;
+ $dbh->do($query)
+ || $form->dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
- ($form->{id}) = $sth->fetchrow_array;
- $sth->finish;
- }
+ $query = qq|SELECT id FROM employees WHERE name = '$uid'|;
+ $sth = $dbh->prepare($query);
+ $sth->execute
+ || $form->dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
- my ($null, $managerid) = split /--/, $form->{manager};
- $managerid *= 1;
- $form->{sales} *= 1;
+ ( $form->{id} ) = $sth->fetchrow_array;
+ $sth->finish;
+ }
- $form->{employeenumber} = $form->update_defaults(
- $myconfig, "employeenumber", $dbh)
- if ! $form->{employeenumber};
+ my ( $null, $managerid ) = split /--/, $form->{manager};
+ $managerid *= 1;
+ $form->{sales} *= 1;
- $query = qq|
+ $form->{employeenumber} =
+ $form->update_defaults( $myconfig, "employeenumber", $dbh )
+ if !$form->{employeenumber};
+
+ $query = qq|
UPDATE employees
SET employeenumber = ?,
name = ?,
@@ -153,109 +152,106 @@ sub save_employee {
bic = ?,
managerid = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $form->{dob} ||= undef;
- $form->{startdate} ||= undef;
- $form->{enddate} ||= undef;
- $sth->execute(
- $form->{employeenumber}, $form->{name}, $form->{address1},
- $form->{address2}, $form->{city}, $form->{state},
- $form->{zipcode}, $form->{country}, $form->{workphone},
- $form->{homephone}, $form->{startdate}, $form->{enddate},
- $form->{notes}, $form->{role}, $form->{sales}, $form->{email},
- $form->{ssn}, $form->{dob}, $form->{iban}, $form->{bic},
- $managerid, $form->{id}
- ) || $form->dberror(__FILE__.':'.__LINE__.':'.$query);
-
-
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $form->{dob} ||= undef;
+ $form->{startdate} ||= undef;
+ $form->{enddate} ||= undef;
+ $sth->execute(
+ $form->{employeenumber}, $form->{name}, $form->{address1},
+ $form->{address2}, $form->{city}, $form->{state},
+ $form->{zipcode}, $form->{country}, $form->{workphone},
+ $form->{homephone}, $form->{startdate}, $form->{enddate},
+ $form->{notes}, $form->{role}, $form->{sales},
+ $form->{email}, $form->{ssn}, $form->{dob},
+ $form->{iban}, $form->{bic}, $managerid,
+ $form->{id}
+ ) || $form->dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
+
+ $dbh->commit;
}
-
sub delete_employee {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
- # connect to database
- my $dbh = $form->{dbh};
+ # delete employee
- # delete employee
-
- my $query = qq|
+ my $query = qq|
DELETE FROM employees
- WHERE id = |.$dbh->quote($form->{id});
- $dbh->do($query) || $form->dberror(__FILE__.':'.__LINE__.':'.$query);
+ WHERE id = | . $dbh->quote( $form->{id} );
+ $dbh->do($query)
+ || $form->dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
- $dbh->commit;
+ $dbh->commit;
}
-
sub employees {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my $where = "1 = 1";
- $form->{sort} = ($form->{sort}) ? $form->{sort} : "name";
- my @a = qw(name);
- my $sortorder = $form->sort_order(\@a);
-
- my $var;
-
- if ($form->{startdatefrom}) {
- $where .= " AND e.startdate >= ".
- $dbh->quote($form->{startdatefrom});
- }
- if ($form->{startdateto}) {
- $where .= " AND e.startddate <= ".
- $dbh->quote($form->{startdateto});
- }
- if ($form->{name} ne "") {
- $var = $dbh->quote($form->like(lc $form->{name}));
- $where .= " AND lower(e.name) LIKE $var";
- }
- if ($form->{notes} ne "") {
- $var = $dbh->quote($form->like(lc $form->{notes}));
- $where .= " AND lower(e.notes) LIKE $var";
- }
- if ($form->{sales} eq 'Y') {
- $where .= " AND e.sales = '1'";
- }
- if ($form->{status} eq 'orphaned') {
- $where .= qq| AND e.login IS NULL|;
- }
- if ($form->{status} eq 'active') {
- $where .= qq| AND e.enddate IS NULL|;
- }
- if ($form->{status} eq 'inactive') {
- $where .= qq| AND e.enddate <= current_date|;
- }
-
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my $where = "1 = 1";
+ $form->{sort} = ( $form->{sort} ) ? $form->{sort} : "name";
+ my @a = qw(name);
+ my $sortorder = $form->sort_order( \@a );
+
+ my $var;
+
+ if ( $form->{startdatefrom} ) {
+ $where .=
+ " AND e.startdate >= " . $dbh->quote( $form->{startdatefrom} );
+ }
+ if ( $form->{startdateto} ) {
+ $where .= " AND e.startddate <= " . $dbh->quote( $form->{startdateto} );
+ }
+ if ( $form->{name} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{name} ) );
+ $where .= " AND lower(e.name) LIKE $var";
+ }
+ if ( $form->{notes} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{notes} ) );
+ $where .= " AND lower(e.notes) LIKE $var";
+ }
+ if ( $form->{sales} eq 'Y' ) {
+ $where .= " AND e.sales = '1'";
+ }
+ if ( $form->{status} eq 'orphaned' ) {
+ $where .= qq| AND e.login IS NULL|;
+ }
+ if ( $form->{status} eq 'active' ) {
+ $where .= qq| AND e.enddate IS NULL|;
+ }
+ if ( $form->{status} eq 'inactive' ) {
+ $where .= qq| AND e.enddate <= current_date|;
+ }
+
+ my $query = qq|
SELECT e.*, m.name AS manager
FROM employees e
LEFT JOIN employees m ON (m.id = e.managerid)
WHERE $where
ORDER BY $sortorder|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror(__FILE__.':'.__LINE__.':'.$query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror( __FILE__ . ':' . __LINE__ . ':' . $query );
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{address} = "";
- for (qw(address1 address2 city state zipcode country)) {
- $ref->{address} .= "$ref->{$_} ";
- }
- push @{ $form->{all_employee} }, $ref;
- }
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{address} = "";
+ for (qw(address1 address2 city state zipcode country)) {
+ $ref->{address} .= "$ref->{$_} ";
+ }
+ push @{ $form->{all_employee} }, $ref;
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
1;
diff --git a/LedgerSMB/IC.pm b/LedgerSMB/IC.pm
index 5594c176..943f6b36 100644
--- a/LedgerSMB/IC.pm
+++ b/LedgerSMB/IC.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -33,15 +33,14 @@
package IC;
-
sub get_part {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to db
- my $dbh = $form->{dbh};
- my $i;
+ # connect to db
+ my $dbh = $form->{dbh};
+ my $i;
- my $query = qq|
+ my $query = qq|
SELECT p.*, c1.accno AS inventory_accno,
c1.description AS inventory_description,
c2.accno AS income_accno,
@@ -54,23 +53,23 @@ sub get_part {
LEFT JOIN chart c3 ON (p.expense_accno_id = c3.id)
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
WHERE p.id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- my $ref = $sth->fetchrow_hashref(NAME_lc);
-
- # copy to $form variables
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
-
- # part, service item or labor
- $form->{item} = ($form->{inventory_accno_id}) ? 'part' : 'service';
- $form->{item} = 'labor' if ! $form->{income_accno_id};
-
- if ($form->{assembly}) {
- $form->{item} = 'assembly';
-
- # retrieve assembly items
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+
+ # copy to $form variables
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
+
+ # part, service item or labor
+ $form->{item} = ( $form->{inventory_accno_id} ) ? 'part' : 'service';
+ $form->{item} = 'labor' if !$form->{income_accno_id};
+
+ if ( $form->{assembly} ) {
+ $form->{item} = 'assembly';
+
+ # retrieve assembly items
+ $query = qq|
SELECT p.id, p.partnumber, p.description,
p.sellprice, p.weight, a.qty, a.bom, a.adj,
p.unit, p.lastcost, p.listprice,
@@ -80,67 +79,65 @@ sub get_part {
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
WHERE a.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $form->{assembly_rows} = 0;
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $form->{assembly_rows}++;
- foreach my $key ( keys %{ $ref } ) {
- $form->{"${key}_$form->{assembly_rows}"}
- = $ref->{$key};
- }
- }
- $sth->finish;
-
- }
-
- # setup accno hash for <option checked>
- # {amount} is used in create_links
- for (qw(inventory income expense)) {
- $form->{amount}{"IC_$_"}
- = {
- accno => $form->{"${_}_accno"},
- description => $form->{"${_}_description"}
- };
- };
-
-
- if ($form->{item} =~ /(part|assembly)/) {
-
- if ($form->{makemodel} ne "") {
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $form->{assembly_rows} = 0;
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $form->{assembly_rows}++;
+ foreach my $key ( keys %{$ref} ) {
+ $form->{"${key}_$form->{assembly_rows}"} = $ref->{$key};
+ }
+ }
+ $sth->finish;
+
+ }
+
+ # setup accno hash for <option checked>
+ # {amount} is used in create_links
+ for (qw(inventory income expense)) {
+ $form->{amount}{"IC_$_"} = {
+ accno => $form->{"${_}_accno"},
+ description => $form->{"${_}_description"}
+ };
+ }
+
+ if ( $form->{item} =~ /(part|assembly)/ ) {
+
+ if ( $form->{makemodel} ne "" ) {
+ $query = qq|
SELECT make, model
FROM makemodel
WHERE parts_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{makemodels} }, $ref;
- }
- $sth->finish;
- }
- }
-
- # now get accno for taxes
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{makemodels} }, $ref;
+ }
+ $sth->finish;
+ }
+ }
+
+ # now get accno for taxes
+ $query = qq|
SELECT c.accno FROM chart c, partstax pt
WHERE pt.chart_id = c.id AND pt.parts_id = ?|;
-
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- while (($key) = $sth->fetchrow_array) {
- $form->{amount}{$key} = $key;
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ while ( ($key) = $sth->fetchrow_array ) {
+ $form->{amount}{$key} = $key;
+ }
- $sth->finish;
+ $sth->finish;
- my $id = $dbh->quote($form->{id});
- # is it an orphan
- $query = qq|
+ my $id = $dbh->quote( $form->{id} );
+
+ # is it an orphan
+ $query = qq|
SELECT parts_id FROM invoice WHERE parts_id = $id
UNION
SELECT parts_id FROM orderitems WHERE parts_id = $id
@@ -148,20 +145,21 @@ sub get_part {
SELECT parts_id FROM assembly WHERE parts_id = $id
UNION
SELECT parts_id FROM jcitems WHERE parts_id = $id|;
- ($form->{orphaned}) = $dbh->selectrow_array($query);
- $form->{orphaned} = !$form->{orphaned};
+ ( $form->{orphaned} ) = $dbh->selectrow_array($query);
+ $form->{orphaned} = !$form->{orphaned};
+
+ $form->{orphaned} = 0 if $form->{project_id};
- $form->{orphaned} = 0 if $form->{project_id};
+ if ( $form->{item} eq 'assembly' ) {
+ if ( $form->{orphaned} ) {
+ $form->{orphaned} = !$form->{onhand};
+ }
+ }
- if ($form->{item} eq 'assembly') {
- if ($form->{orphaned}) {
- $form->{orphaned} = !$form->{onhand};
- }
- }
+ if ( $form->{item} =~ /(part|service)/ ) {
- if ($form->{item} =~ /(part|service)/) {
- # get vendors
- $query = qq|
+ # get vendors
+ $query = qq|
SELECT v.id, v.name, pv.partnumber,
pv.lastcost, pv.leadtime,
pv.curr AS vendorcurr
@@ -169,19 +167,19 @@ sub get_part {
JOIN vendor v ON (v.id = pv.vendor_id)
WHERE pv.parts_id = ?
ORDER BY 2|;
-
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{vendormatrix} }, $ref;
- }
- $sth->finish;
- }
-
- # get matrix
- if ($form->{item} ne 'labor') {
- $query = qq|
+
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{vendormatrix} }, $ref;
+ }
+ $sth->finish;
+ }
+
+ # get matrix
+ if ( $form->{item} ne 'labor' ) {
+ $query = qq|
SELECT pc.pricebreak, pc.sellprice AS customerprice,
pc.curr AS customercurr, pc.validfrom,
pc.validto, c.name, c.id AS cid,
@@ -191,202 +189,203 @@ sub get_part {
LEFT JOIN pricegroup g ON (g.id = pc.pricegroup_id)
WHERE pc.parts_id = ?
ORDER BY c.name, g.pricegroup, pc.pricebreak|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{customermatrix} }, $ref;
- }
- $sth->finish;
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{customermatrix} }, $ref;
+ }
+ $sth->finish;
+ }
- $form->run_custom_queries('parts', 'SELECT');
-
-}
+ $form->run_custom_queries( 'parts', 'SELECT' );
+}
sub save {
- my ($self, $myconfig, $form) = @_;
-
- ($form->{inventory_accno}) = split(/--/, $form->{IC_inventory});
- ($form->{expense_accno}) = split(/--/, $form->{IC_expense});
- ($form->{income_accno}) = split(/--/, $form->{IC_income});
-
- my $dbh = $form->{dbh};
-
- # undo amount formatting
- for (qw(rop weight listprice sellprice lastcost stock)) {
- $form->{$_} = $form->parse_amount($myconfig, $form->{$_});
- }
-
- $form->{makemodel} = (($form->{make_1}) || ($form->{model_1})) ? 1 : 0;
-
- $form->{assembly} = ($form->{item} eq 'assembly') ? 1 : 0;
- for (qw(alternate obsolete onhand)) { $form->{$_} *= 1 }
-
- my $query;
- my $sth;
- my $i;
- my $null;
- my $vendor_id;
- my $customer_id;
-
- if ($form->{id}) {
-
- # get old price
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ ( $form->{inventory_accno} ) = split( /--/, $form->{IC_inventory} );
+ ( $form->{expense_accno} ) = split( /--/, $form->{IC_expense} );
+ ( $form->{income_accno} ) = split( /--/, $form->{IC_income} );
+
+ my $dbh = $form->{dbh};
+
+ # undo amount formatting
+ for (qw(rop weight listprice sellprice lastcost stock)) {
+ $form->{$_} = $form->parse_amount( $myconfig, $form->{$_} );
+ }
+
+ $form->{makemodel} =
+ ( ( $form->{make_1} ) || ( $form->{model_1} ) ) ? 1 : 0;
+
+ $form->{assembly} = ( $form->{item} eq 'assembly' ) ? 1 : 0;
+ for (qw(alternate obsolete onhand)) { $form->{$_} *= 1 }
+
+ my $query;
+ my $sth;
+ my $i;
+ my $null;
+ my $vendor_id;
+ my $customer_id;
+
+ if ( $form->{id} ) {
+
+ # get old price
+ $query = qq|
SELECT id, listprice, sellprice, lastcost, weight,
project_id
FROM parts
WHERE id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id});
- my ($id, $listprice, $sellprice, $lastcost, $weight,
- $project_id)
- = $sth->fetchrow_array();
-
- if ($id) {
-
- if (!$project_id) {
- # if item is part of an assembly
- # adjust all assemblies
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} );
+ my ( $id, $listprice, $sellprice, $lastcost, $weight, $project_id ) =
+ $sth->fetchrow_array();
+
+ if ($id) {
+
+ if ( !$project_id ) {
+
+ # if item is part of an assembly
+ # adjust all assemblies
+ $query = qq|
SELECT id, qty, adj
FROM assembly
WHERE parts_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) ||
- $form->dberror($query);
- while (my ($id, $qty, $adj)
- = $sth->fetchrow_array) {
-
- &update_assembly(
- $dbh, $form, $id, $qty, $adj,
- $listprice * 1, $sellprice * 1,
- $lastcost * 1, $weight * 1);
- }
- $sth->finish;
- }
-
- if ($form->{item} =~ /(part|service)/) {
- # delete partsvendor records
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} )
+ || $form->dberror($query);
+ while ( my ( $id, $qty, $adj ) = $sth->fetchrow_array ) {
+
+ &update_assembly(
+ $dbh, $form,
+ $id, $qty,
+ $adj, $listprice * 1,
+ $sellprice * 1, $lastcost * 1,
+ $weight * 1
+ );
+ }
+ $sth->finish;
+ }
+
+ if ( $form->{item} =~ /(part|service)/ ) {
+
+ # delete partsvendor records
+ $query = qq|
DELETE FROM partsvendor
WHERE parts_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id})
- || $form->dberror($query);
- }
-
- if ($form->{item} !~ /(service|labor)/) {
- # delete makemodel records
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} )
+ || $form->dberror($query);
+ }
+
+ if ( $form->{item} !~ /(service|labor)/ ) {
+
+ # delete makemodel records
+ $query = qq|
DELETE FROM makemodel
WHERE parts_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id})
- || $form->dberror($query);
- }
-
- if ($form->{item} eq 'assembly') {
-
- if ($form->{onhand}) {
- &adjust_inventory(
- $dbh, $form, $form->{id},
- $form->{onhand} * -1);
- }
-
- if ($form->{orphaned}) {
- # delete assembly records
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} )
+ || $form->dberror($query);
+ }
+
+ if ( $form->{item} eq 'assembly' ) {
+
+ if ( $form->{onhand} ) {
+ &adjust_inventory( $dbh, $form, $form->{id},
+ $form->{onhand} * -1 );
+ }
+
+ if ( $form->{orphaned} ) {
+
+ # delete assembly records
+ $query = qq|
DELETE FROM assembly
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id})
- || $form->dberror($query);
- } else {
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} )
+ || $form->dberror($query);
+ }
+ else {
- for $i (1 ..
- $form->{assembly_rows} - 1) {
+ for $i ( 1 .. $form->{assembly_rows} - 1 ) {
- # update BOM, A only
- for (qw(bom adj)) {
- $form->{"${_}_$i"}
- *= 1;
- }
+ # update BOM, A only
+ for (qw(bom adj)) {
+ $form->{"${_}_$i"} *= 1;
+ }
- $query = qq|
+ $query = qq|
UPDATE assembly
SET bom = ?,
adj = ?
WHERE id = ?
AND parts_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{"bom_$i"},
- $form->{"adj_$i"},
- $form->{id},
- $form->{"id_$i"}
- )|| $form->dberror(
- $query);
- }
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{"bom_$i"}, $form->{"adj_$i"},
+ $form->{id}, $form->{"id_$i"}
+ ) || $form->dberror($query);
+ }
+ }
- $form->{onhand} += $form->{stock};
+ $form->{onhand} += $form->{stock};
- }
+ }
- # delete tax records
- $query = qq|DELETE FROM partstax WHERE parts_id = ?|;
+ # delete tax records
+ $query = qq|DELETE FROM partstax WHERE parts_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id})|| $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- # delete matrix
- $query = qq|
+ # delete matrix
+ $query = qq|
DELETE FROM partscustomer
WHERE parts_id = ?|;
-
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id})|| $form->dberror($query);
- } else {
- $query = qq|INSERT INTO parts (id) VALUES (?)|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id})|| $form->dberror($query);
- }
-
- }
-
-
- if (!$form->{id}) {
- my $uid = localtime;
- $uid .= "$$";
-
- $query = qq|INSERT INTO parts (partnumber) VALUES ('$uid')|;
- $dbh->do($query) || $form->dberror($query);
-
- $query = qq|SELECT id FROM parts WHERE partnumber = '$uid'|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
- ($form->{id}) = $sth->fetchrow_array;
- $sth->finish;
-
- $form->{orphaned} = 1;
- $form->{onhand} = ($form->{stock} * 1)
- if $form->{item} eq 'assembly';
- }
-
- my $partsgroup_id;
- ($null, $partsgroup_id) = split /--/, $form->{partsgroup};
- $partsgroup_id *= 1;
-
- $form->{partnumber} = $form->update_defaults(
- $myconfig, "partnumber", $dbh) if ! $form->{partnumber};
-
- if (!$form->{priceupdate}){
- $form->{priceupdate} = 'now';
- }
- $query = qq|
+
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ }
+ else {
+ $query = qq|INSERT INTO parts (id) VALUES (?)|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ }
+
+ }
+
+ if ( !$form->{id} ) {
+ my $uid = localtime;
+ $uid .= "$$";
+
+ $query = qq|INSERT INTO parts (partnumber) VALUES ('$uid')|;
+ $dbh->do($query) || $form->dberror($query);
+
+ $query = qq|SELECT id FROM parts WHERE partnumber = '$uid'|;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+ ( $form->{id} ) = $sth->fetchrow_array;
+ $sth->finish;
+
+ $form->{orphaned} = 1;
+ $form->{onhand} = ( $form->{stock} * 1 )
+ if $form->{item} eq 'assembly';
+ }
+
+ my $partsgroup_id;
+ ( $null, $partsgroup_id ) = split /--/, $form->{partsgroup};
+ $partsgroup_id *= 1;
+
+ $form->{partnumber} =
+ $form->update_defaults( $myconfig, "partnumber", $dbh )
+ if !$form->{partnumber};
+
+ if ( !$form->{priceupdate} ) {
+ $form->{priceupdate} = 'now';
+ }
+ $query = qq|
UPDATE parts
SET partnumber = ?,
description = ?,
@@ -414,212 +413,205 @@ sub save {
microfiche = ?,
partsgroup_id = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{partnumber}, $form->{description}, $form->{makemodel},
- $form->{alternate}, $form->{assembly}, $form->{listprice},
- $form->{sellprice}, $form->{lastcost}, $form->{weight},
- $form->{priceupdate}, $form->{unit}, $form->{notes},
- $form->{rop}, $form->{bin}, $form->{inventory_accno},
- $form->{income_accno}, $form->{expense_accno},
- $form->{obsolete}, $form->{image}, $form->{drawing},
- $form->{microfiche}, $partsgroup_id, $form->{id}
- ) || $form->dberror($query);
-
-
- # insert makemodel records
- if ($form->{item} =~ /(part|assembly)/) {
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{partnumber}, $form->{description},
+ $form->{makemodel}, $form->{alternate},
+ $form->{assembly}, $form->{listprice},
+ $form->{sellprice}, $form->{lastcost},
+ $form->{weight}, $form->{priceupdate},
+ $form->{unit}, $form->{notes},
+ $form->{rop}, $form->{bin},
+ $form->{inventory_accno}, $form->{income_accno},
+ $form->{expense_accno}, $form->{obsolete},
+ $form->{image}, $form->{drawing},
+ $form->{microfiche}, $partsgroup_id,
+ $form->{id}
+ ) || $form->dberror($query);
+
+ # insert makemodel records
+ if ( $form->{item} =~ /(part|assembly)/ ) {
+ $query = qq|
INSERT INTO makemodel (parts_id, make, model)
VALUES (?, ?, ?)|;
- $sth = $dbh->prepare($query) || $form->dberror($query);
- for $i (1 .. $form->{makemodel_rows}) {
- if (($form->{"make_$i"} ne "")
- || ($form->{"model_$i"} ne "")) {
- $sth->execute(
- $form->{id}, $form->{"make_$i"},
- $form->{"model_$i"}
- ) || $form->dberror($query);
- }
- }
- }
-
-
- # insert taxes
- $query = qq|
+ $sth = $dbh->prepare($query) || $form->dberror($query);
+ for $i ( 1 .. $form->{makemodel_rows} ) {
+ if ( ( $form->{"make_$i"} ne "" )
+ || ( $form->{"model_$i"} ne "" ) )
+ {
+ $sth->execute( $form->{id}, $form->{"make_$i"},
+ $form->{"model_$i"} )
+ || $form->dberror($query);
+ }
+ }
+ }
+
+ # insert taxes
+ $query = qq|
INSERT INTO partstax (parts_id, chart_id)
VALUES (?, (SELECT id FROM chart WHERE accno = ?))|;
- $sth = $dbh->prepare($query);
- for (split / /, $form->{taxaccounts}) {
- if ($form->{"IC_tax_$_"}) {
- $sth->execute($form->{id}, $_)
- || $form->dberror($query);
- }
- }
-
-
- @a = localtime;
- $a[5] += 1900;
- $a[4]++;
- $a[4] = substr("0$a[4]", -2);
- $a[3] = substr("0$a[3]", -2);
- my $shippingdate = "$a[5]$a[4]$a[3]";
-
- ($form->{employee}, $form->{employee_id}) = $form->get_employee($dbh);
-
- # add assembly records
- if ($form->{item} eq 'assembly' && !$project_id) {
-
- if ($form->{orphaned}) {
- $query = qq|
+ $sth = $dbh->prepare($query);
+ for ( split / /, $form->{taxaccounts} ) {
+ if ( $form->{"IC_tax_$_"} ) {
+ $sth->execute( $form->{id}, $_ )
+ || $form->dberror($query);
+ }
+ }
+
+ @a = localtime;
+ $a[5] += 1900;
+ $a[4]++;
+ $a[4] = substr( "0$a[4]", -2 );
+ $a[3] = substr( "0$a[3]", -2 );
+ my $shippingdate = "$a[5]$a[4]$a[3]";
+
+ ( $form->{employee}, $form->{employee_id} ) = $form->get_employee($dbh);
+
+ # add assembly records
+ if ( $form->{item} eq 'assembly' && !$project_id ) {
+
+ if ( $form->{orphaned} ) {
+ $query = qq|
INSERT INTO assembly
(id, parts_id, qty, bom, adj)
VALUES (?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- for $i (1 .. $form->{assembly_rows}) {
- $form->{"qty_$i"} = $form->parse_amount(
- $myconfig, $form->{"qty_$i"});
- if(!$form->{"bom_$i"}){
+ $sth = $dbh->prepare($query);
+ for $i ( 1 .. $form->{assembly_rows} ) {
+ $form->{"qty_$i"} =
+ $form->parse_amount( $myconfig, $form->{"qty_$i"} );
+ if ( !$form->{"bom_$i"} ) {
$form->{"bom_$i"} = undef;
}
-
- if ($form->{"id_$i"} && $form->{"qty_$i"}){
- $sth->execute(
- $form->{id}, $form->{"id_$i"},
- $form->{"qty_$i"}, $form->{"bom_$i"},
- $form->{"adj_$i"}
- ) || $form->dberror($query);
+
+ if ( $form->{"id_$i"} && $form->{"qty_$i"} ) {
+ $sth->execute(
+ $form->{id}, $form->{"id_$i"},
+ $form->{"qty_$i"}, $form->{"bom_$i"},
+ $form->{"adj_$i"}
+ ) || $form->dberror($query);
+ }
+ }
+ }
+
+ # adjust onhand for the parts
+ if ( $form->{onhand} ) {
+ &adjust_inventory( $dbh, $form, $form->{id}, $form->{onhand} );
+ }
+ }
+
+ # add vendors
+ if ( $form->{item} ne 'assembly' ) {
+ $updparts{ $form->{id} } = 1;
+
+ for $i ( 1 .. $form->{vendor_rows} ) {
+ if ( ( $form->{"vendor_$i"} ne "" )
+ && $form->{"lastcost_$i"} )
+ {
+
+ ( $null, $vendor_id ) = split /--/, $form->{"vendor_$i"};
+
+ for (qw(lastcost leadtime)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( $myconfig, $form->{"${_}_$i"} );
}
- }
- }
- # adjust onhand for the parts
- if ($form->{onhand}) {
- &adjust_inventory(
- $dbh, $form, $form->{id}, $form->{onhand});
- }
- }
-
-
- # add vendors
- if ($form->{item} ne 'assembly') {
- $updparts{$form->{id}} = 1;
-
- for $i (1 .. $form->{vendor_rows}) {
- if (($form->{"vendor_$i"} ne "")
- && $form->{"lastcost_$i"}) {
-
- ($null, $vendor_id)
- = split /--/, $form->{"vendor_$i"};
-
- for (qw(lastcost leadtime)) {
- $form->{"${_}_$i"}
- = $form->parse_amount(
- $myconfig,
- $form->{"${_}_$i"});
- }
-
- $query = qq|
+
+ $query = qq|
INSERT INTO partsvendor
(vendor_id, parts_id,
partnumber, lastcost,
leadtime, curr)
VALUES (?, ?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $vendor_id, $form->{id},
- $form->{"partnumber_$i"},
- $form->{"lastcost_$i"},
- $form->{"leadtime_$i"},
- $form->{"vendorcurr_$i"}
- )|| $form->dberror($query);
- }
- }
- }
-
-
- # add pricematrix
- for $i (1 .. $form->{customer_rows}) {
-
- for (qw(pricebreak customerprice)) {
- $form->{"${_}_$i"} = $form->parse_amount(
- $myconfig, $form->{"${_}_$i"});
- }
-
- if ($form->{"customerprice_$i"}) {
-
- ($null, $customer_id)
- = split /--/, $form->{"customer_$i"};
- $customer_id *= 1;
-
- ($null, $pricegroup_id)
- = split /--/, $form->{"pricegroup_$i"};
-
- my $validfrom;
- my $validto;
- $validfrom = $form->{"validfrom_$i"} if $form->{"validfrom_$i"};
- $validto = $form->{"validto_$i"} if $form->{"validto_$i"};
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $vendor_id, $form->{id},
+ $form->{"partnumber_$i"}, $form->{"lastcost_$i"},
+ $form->{"leadtime_$i"}, $form->{"vendorcurr_$i"}
+ ) || $form->dberror($query);
+ }
+ }
+ }
+
+ # add pricematrix
+ for $i ( 1 .. $form->{customer_rows} ) {
+
+ for (qw(pricebreak customerprice)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( $myconfig, $form->{"${_}_$i"} );
+ }
+
+ if ( $form->{"customerprice_$i"} ) {
+
+ ( $null, $customer_id ) = split /--/, $form->{"customer_$i"};
+ $customer_id *= 1;
+
+ ( $null, $pricegroup_id ) = split /--/, $form->{"pricegroup_$i"};
+
+ my $validfrom;
+ my $validto;
+ $validfrom = $form->{"validfrom_$i"} if $form->{"validfrom_$i"};
+ $validto = $form->{"validto_$i"} if $form->{"validto_$i"};
+ $query = qq|
INSERT INTO partscustomer
(parts_id, customer_id,
pricegroup_id, pricebreak,
sellprice, curr,
validfrom, validto)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $customer_id, $pricegroup_id,
- $form->{"pricebreak_$i"},
- $form->{"customerprice_$i"},
- $form->{"customercurr_$i"},
- $validfrom, $validto
- )|| $form->dberror($query);
- }
- }
-
- my $rc = $dbh->commit;
-
- $form->run_custom_queries('parts', 'UPDATE');
- $rc;
-
-}
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{id}, $customer_id,
+ $pricegroup_id, $form->{"pricebreak_$i"},
+ $form->{"customerprice_$i"}, $form->{"customercurr_$i"},
+ $validfrom, $validto
+ ) || $form->dberror($query);
+ }
+ }
+ my $rc = $dbh->commit;
+ $form->run_custom_queries( 'parts', 'UPDATE' );
+ $rc;
+
+}
sub update_assembly {
- my ($dbh, $form, $id, $qty, $adj, $listprice, $sellprice, $lastcost,
- $weight) = @_;
-
- my $formlistprice = $form->{listprice};
- my $formsellprice = $form->{sellprice};
-
- if (!$adj) {
- $formlistprice = $listprice;
- $formsellprice = $sellprice;
- }
-
- my $query = qq|SELECT id, qty, adj FROM assembly WHERE parts_id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($id) || $form->dberror($query);
-
- $form->{$id} = 1; # Not sure what this is for...
- # In fact, we don't seem to use it... Chris T
-
- while (my ($pid, $aqty, $aadj) = $sth->fetchrow_array) {
- &update_assembly($dbh, $form, $pid, $aqty * $qty, $aadj,
- $listprice, $sellprice, $lastcost, $weight)
- if !$form->{$pid};
- }
- $sth->finish;
- $qty = $dbh->quote($qty);
- $formlistprice = $dbh->quote($formlistprice );
- $listprice = $dbh->quote($listprice );
- $formsellprice = $dbh->quote($formsellprice );
- $formlastcost = $dbh->quote($form->{lastcost});
- $lastcost = $dbh->quote($lastcost);
- $weight = $dbh->quote($weight);
- $id = $dbh->quote($id);
-
- $query = qq|
+ my (
+ $dbh, $form, $id, $qty, $adj,
+ $listprice, $sellprice, $lastcost, $weight
+ ) = @_;
+
+ my $formlistprice = $form->{listprice};
+ my $formsellprice = $form->{sellprice};
+
+ if ( !$adj ) {
+ $formlistprice = $listprice;
+ $formsellprice = $sellprice;
+ }
+
+ my $query = qq|SELECT id, qty, adj FROM assembly WHERE parts_id = ?|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute($id) || $form->dberror($query);
+
+ $form->{$id} = 1; # Not sure what this is for...
+ # In fact, we don't seem to use it... Chris T
+
+ while ( my ( $pid, $aqty, $aadj ) = $sth->fetchrow_array ) {
+ &update_assembly(
+ $dbh, $form, $pid, $aqty * $qty, $aadj,
+ $listprice, $sellprice, $lastcost, $weight
+ ) if !$form->{$pid};
+ }
+ $sth->finish;
+ $qty = $dbh->quote($qty);
+ $formlistprice = $dbh->quote($formlistprice);
+ $listprice = $dbh->quote($listprice);
+ $formsellprice = $dbh->quote($formsellprice);
+ $formlastcost = $dbh->quote( $form->{lastcost} );
+ $lastcost = $dbh->quote($lastcost);
+ $weight = $dbh->quote($weight);
+ $id = $dbh->quote($id);
+
+ $query = qq|
UPDATE parts
SET listprice = listprice +
$qty * ($formlistprice - $listprice),
@@ -630,47 +622,43 @@ sub update_assembly {
weight = weight +
$qty * ($form->{weight} - $weight)
WHERE id = $id|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $form->dberror($query);
+
+ delete $form->{$id};
- delete $form->{$id};
-
}
+sub retrieve_assemblies {
+ my ( $self, $myconfig, $form ) = @_;
+ # connect to database
+ my $dbh = $form->{dbh};
-sub retrieve_assemblies {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my $where = '1 = 1';
-
- if ($form->{partnumber} ne "") {
- my $partnumber = $dbh->quote($form->like(
- lc $form->{partnumber}));
- $where .= " AND lower(p.partnumber) LIKE $partnumber";
- }
-
- if ($form->{description} ne "") {
- my $description = $dbh->($form->like(lc $form->{description}));
- $where .= " AND lower(p.description) LIKE $description";
- }
- $where .= qq| AND p.obsolete = '0'
+ my $where = '1 = 1';
+
+ if ( $form->{partnumber} ne "" ) {
+ my $partnumber = $dbh->quote( $form->like( lc $form->{partnumber} ) );
+ $where .= " AND lower(p.partnumber) LIKE $partnumber";
+ }
+
+ if ( $form->{description} ne "" ) {
+ my $description = $dbh->( $form->like( lc $form->{description} ) );
+ $where .= " AND lower(p.description) LIKE $description";
+ }
+ $where .= qq| AND p.obsolete = '0'
AND p.project_id IS NULL|;
- my %ordinal = (
- 'partnumber' => 2,
- 'description' => 3,
- 'bin' => 4
- );
-
- my @a = qw(partnumber description bin);
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
-
- # retrieve assembly items
- my $query = qq|
+ my %ordinal = (
+ 'partnumber' => 2,
+ 'description' => 3,
+ 'bin' => 4
+ );
+
+ my @a = qw(partnumber description bin);
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ # retrieve assembly items
+ my $query = qq|
SELECT p.id, p.partnumber, p.description, p.bin, p.onhand,
p.rop
FROM parts p
@@ -678,338 +666,328 @@ sub retrieve_assemblies {
AND p.assembly = '1'
ORDER BY $sortorder|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ $query = qq|
SELECT sum(p.inventory_accno_id), p.assembly
FROM parts p
JOIN assembly a ON (a.parts_id = p.id)
WHERE a.id = ?
GROUP BY p.assembly|;
- my $svh = $dbh->prepare($query) || $form->dberror($query);
-
- my $inh;
- if ($form->{checkinventory}) {
- $query = qq|
+ my $svh = $dbh->prepare($query) || $form->dberror($query);
+
+ my $inh;
+ if ( $form->{checkinventory} ) {
+ $query = qq|
SELECT p.id, p.onhand, a.qty
FROM parts p
JOIN assembly a ON (a.parts_id = p.id)
WHERE (p.inventory_accno_id > 0 OR p.assembly)
AND p.income_accno_id > 0 AND a.id = ?|;
- $inh = $dbh->prepare($query) || $form->dberror($query);
- }
-
- my %available = ();
- my %required;
- my $ref;
- my $aref;
- my $stock;
- my $howmany;
- my $ok;
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $svh->execute($ref->{id});
- ($ref->{inventory}, $ref->{assembly}) = $svh->fetchrow_array;
- $svh->finish;
-
- if ($ref->{inventory} || $ref->{assembly}) {
- $ok = 1;
- if ($form->{checkinventory}) {
- $inh->execute($ref->{id})
- || $form->dberror($query);;
- $ok = 0;
- %required = ();
-
- while ($aref
- = $inh->fetchrow_hashref(NAME_lc)) {
-
- $available{$aref->{id}} =
- (exists $available{$aref->{id}})
- ? $available{$aref->{id}}
- : $aref->{onhand};
- $required{$aref->{id}} = $aref->{qty};
-
- if ($available{$aref->{id}}
- >= $aref->{qty}) {
-
- $howmany =
- ($aref->{qty})
- ? int $available{
- $aref->{id}}
- /$aref->{qty}
- : 1;
- if ($stock) {
- $stock =
- ($stock
- > $howmany)
- ? $howmany
- : $stock;
- } else {
- $stock = $howmany;
- }
- $ok = 1;
-
- $available{$aref->{id}}
- -= $aref->{qty}
- * $stock;
-
- } else {
- $ok = 0;
- for (keys %required) {
- $available{$_} +=
- $required{$_}
- * $stock;
- }
- $stock = 0;
- last;
- }
- }
- $inh->finish;
- $ref->{stock} = $stock;
-
- }
- push @{ $form->{assembly_items} }, $ref if $ok;
- }
- }
- $sth->finish;
-
- $dbh->commit;
-
-}
+ $inh = $dbh->prepare($query) || $form->dberror($query);
+ }
+
+ my %available = ();
+ my %required;
+ my $ref;
+ my $aref;
+ my $stock;
+ my $howmany;
+ my $ok;
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $svh->execute( $ref->{id} );
+ ( $ref->{inventory}, $ref->{assembly} ) = $svh->fetchrow_array;
+ $svh->finish;
+
+ if ( $ref->{inventory} || $ref->{assembly} ) {
+ $ok = 1;
+ if ( $form->{checkinventory} ) {
+ $inh->execute( $ref->{id} )
+ || $form->dberror($query);
+ $ok = 0;
+ %required = ();
+
+ while ( $aref = $inh->fetchrow_hashref(NAME_lc) ) {
+
+ $available{ $aref->{id} } =
+ ( exists $available{ $aref->{id} } )
+ ? $available{ $aref->{id} }
+ : $aref->{onhand};
+ $required{ $aref->{id} } = $aref->{qty};
+
+ if ( $available{ $aref->{id} } >= $aref->{qty} ) {
+
+ $howmany =
+ ( $aref->{qty} )
+ ? int $available{ $aref->{id} } / $aref->{qty}
+ : 1;
+ if ($stock) {
+ $stock =
+ ( $stock > $howmany )
+ ? $howmany
+ : $stock;
+ }
+ else {
+ $stock = $howmany;
+ }
+ $ok = 1;
+
+ $available{ $aref->{id} } -= $aref->{qty} * $stock;
+
+ }
+ else {
+ $ok = 0;
+ for ( keys %required ) {
+ $available{$_} += $required{$_} * $stock;
+ }
+ $stock = 0;
+ last;
+ }
+ }
+ $inh->finish;
+ $ref->{stock} = $stock;
+ }
+ push @{ $form->{assembly_items} }, $ref if $ok;
+ }
+ }
+ $sth->finish;
+
+ $dbh->commit;
+
+}
sub restock_assemblies {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
-
- for my $i (1 .. $form->{rowcount}) {
- $form->{"qty_$i"} = $form->parse_amount(
- $myconfig, $form->{"qty_$i"});
+ # connect to database
+ my $dbh = $form->{dbh};
- if ($form->{"qty_$i"}) {
- &adjust_inventory(
- $dbh, $form, $form->{"id_$i"},
- $form->{"qty_$i"});
- }
-
- }
+ for my $i ( 1 .. $form->{rowcount} ) {
+ $form->{"qty_$i"} = $form->parse_amount( $myconfig, $form->{"qty_$i"} );
- my $rc = $dbh->commit;
+ if ( $form->{"qty_$i"} ) {
+ &adjust_inventory( $dbh, $form, $form->{"id_$i"},
+ $form->{"qty_$i"} );
+ }
- $rc;
+ }
-}
+ my $rc = $dbh->commit;
+ $rc;
+
+}
sub adjust_inventory {
- # Private method. Do not commit transaction at end of function...
- my ($dbh, $form, $id, $qty) = @_;
- my $query = qq|
+ # Private method. Do not commit transaction at end of function...
+ my ( $dbh, $form, $id, $qty ) = @_;
+
+ my $query = qq|
SELECT p.id, p.inventory_accno_id, p.assembly, a.qty
FROM parts p
JOIN assembly a ON (a.parts_id = p.id)
WHERE a.id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($id) || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute($id) || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
- # is it a service item then loop
- if (! $ref->{inventory_accno_id}) {
- next if ! $ref->{assembly};
- }
-
- # adjust parts onhand
- $form->update_balance(
- $dbh, "parts", "onhand", qq|id = $ref->{id}|,
- $qty * $ref->{qty} * -1);
- }
+ # is it a service item then loop
+ if ( !$ref->{inventory_accno_id} ) {
+ next if !$ref->{assembly};
+ }
- $sth->finish;
+ # adjust parts onhand
+ $form->update_balance(
+ $dbh, "parts", "onhand",
+ qq|id = $ref->{id}|,
+ $qty * $ref->{qty} * -1
+ );
+ }
- # update assembly
- $form->update_balance($dbh, "parts", "onhand", qq|id = $id|, $qty);
+ $sth->finish;
-}
+ # update assembly
+ $form->update_balance( $dbh, "parts", "onhand", qq|id = $id|, $qty );
+}
sub delete {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my $query;
-
- $query = qq|DELETE FROM parts WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $query = qq|DELETE FROM partstax WHERE parts_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
-
- if ($form->{item} ne 'assembly') {
- $query = qq|DELETE FROM partsvendor WHERE parts_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- }
-
- # check if it is a part, assembly or service
- if ($form->{item} ne 'service') {
- $query = qq|DELETE FROM makemodel WHERE parts_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- }
-
- if ($form->{item} eq 'assembly') {
- $query = qq|DELETE FROM assembly WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- }
-
-
- $query = qq|DELETE FROM inventory WHERE parts_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $query = qq|DELETE FROM partscustomer WHERE parts_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $query = qq|DELETE FROM translation WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- # commit
- my $rc = $dbh->commit;
-
- $rc;
-
-}
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my $query;
+
+ $query = qq|DELETE FROM parts WHERE id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $query = qq|DELETE FROM partstax WHERE parts_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ if ( $form->{item} ne 'assembly' ) {
+ $query = qq|DELETE FROM partsvendor WHERE parts_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ }
+
+ # check if it is a part, assembly or service
+ if ( $form->{item} ne 'service' ) {
+ $query = qq|DELETE FROM makemodel WHERE parts_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ }
+
+ if ( $form->{item} eq 'assembly' ) {
+ $query = qq|DELETE FROM assembly WHERE id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ }
+ $query = qq|DELETE FROM inventory WHERE parts_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $query = qq|DELETE FROM partscustomer WHERE parts_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $query = qq|DELETE FROM translation WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ # commit
+ my $rc = $dbh->commit;
+
+ $rc;
+
+}
sub assembly_item {
- my ($self, $myconfig, $form) = @_;
- my $dbh = $form->{dbh};
-
- my $i = $form->{assembly_rows};
- my $var;
- my $null;
- my $where = "p.obsolete = '0'";
-
- if ($form->{"partnumber_$i"} ne "") {
- $var = $dbh->quote($form->like(lc $form->{"partnumber_$i"}));
- $where .= " AND lower(p.partnumber) LIKE $var";
- }
- if ($form->{"description_$i"} ne "") {
- $var = $dbh->quote($form->like(lc $form->{"description_$i"}));
- $where .= " AND lower(p.description) LIKE $var";
- }
- if ($form->{"partsgroup_$i"} ne "") {
- ($null, $var) = split /--/, $form->{"partsgroup_$i"};
- $var = $dbh->quote($var);
- $where .= qq| AND p.partsgroup_id = $var|;
- }
-
- if ($form->{id}) {
- $where .= " AND p.id != ".$dbh->quote($form->{id});
- }
-
- if ($form->{"description_$i"} ne "") {
- $where .= " ORDER BY p.description";
- } else {
- $where .= " ORDER BY p.partnumber";
- }
-
-
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+ my $dbh = $form->{dbh};
+
+ my $i = $form->{assembly_rows};
+ my $var;
+ my $null;
+ my $where = "p.obsolete = '0'";
+
+ if ( $form->{"partnumber_$i"} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{"partnumber_$i"} ) );
+ $where .= " AND lower(p.partnumber) LIKE $var";
+ }
+ if ( $form->{"description_$i"} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{"description_$i"} ) );
+ $where .= " AND lower(p.description) LIKE $var";
+ }
+ if ( $form->{"partsgroup_$i"} ne "" ) {
+ ( $null, $var ) = split /--/, $form->{"partsgroup_$i"};
+ $var = $dbh->quote($var);
+ $where .= qq| AND p.partsgroup_id = $var|;
+ }
+
+ if ( $form->{id} ) {
+ $where .= " AND p.id != " . $dbh->quote( $form->{id} );
+ }
+
+ if ( $form->{"description_$i"} ne "" ) {
+ $where .= " ORDER BY p.description";
+ }
+ else {
+ $where .= " ORDER BY p.partnumber";
+ }
+
+ my $query = qq|
SELECT p.id, p.partnumber, p.description, p.sellprice,
p.weight, p.onhand, p.unit, p.lastcost,
pg.partsgroup, p.partsgroup_id
FROM parts p
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
WHERE $where|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{item_list} }, $ref;
- }
-
- $sth->finish;
-
-}
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{item_list} }, $ref;
+ }
+
+ $sth->finish;
+}
sub all_parts {
- my ($self, $myconfig, $form) = @_;
-
- $dbh = $form->{dbh};
- my $where = '1 = 1';
- my $null;
- my $var;
- my $ref;
-
- for (qw(partnumber drawing microfiche)) {
- if ($form->{$_} ne "") {
- $var = $dbh->quote($form->like(lc $form->{$_}));
- $where .= " AND lower(p.$_) LIKE $var";
- }
- }
- # special case for description
- if ($form->{description} ne "") {
- unless ($form->{bought} || $form->{sold} || $form->{onorder}
- || $form->{ordered} || $form->{rfq} || $form->{quoted}
- ) {
-
- $var = $dbh->quote($form->like(
- lc $form->{description}));
- $where .= " AND lower(p.description) LIKE $var";
- }
- }
-
- # assembly components
- my $assemblyflds;
- if ($form->{searchitems} eq 'component') {
- $assemblyflds = qq|, p1.partnumber AS assemblypartnumber,
+ my ( $self, $myconfig, $form ) = @_;
+
+ $dbh = $form->{dbh};
+ my $where = '1 = 1';
+ my $null;
+ my $var;
+ my $ref;
+
+ for (qw(partnumber drawing microfiche)) {
+ if ( $form->{$_} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{$_} ) );
+ $where .= " AND lower(p.$_) LIKE $var";
+ }
+ }
+
+ # special case for description
+ if ( $form->{description} ne "" ) {
+ unless ( $form->{bought}
+ || $form->{sold}
+ || $form->{onorder}
+ || $form->{ordered}
+ || $form->{rfq}
+ || $form->{quoted} )
+ {
+
+ $var = $dbh->quote( $form->like( lc $form->{description} ) );
+ $where .= " AND lower(p.description) LIKE $var";
+ }
+ }
+
+ # assembly components
+ my $assemblyflds;
+ if ( $form->{searchitems} eq 'component' ) {
+ $assemblyflds = qq|, p1.partnumber AS assemblypartnumber,
a.id AS assembly_id|;
- }
-
- # special case for serialnumber
- if ($form->{l_serialnumber}) {
- if ($form->{serialnumber} ne "") {
- $var = $dbh->quote(
- $form->like(lc $form->{serialnumber}));
- $where .= " AND lower(i.serialnumber) LIKE $var";
- }
- }
-
- if (($form->{warehouse} ne "") || $form->{l_warehouse}) {
- $form->{l_warehouse} = 1;
- }
-
- if ($form->{searchitems} eq 'part') {
- $where .= " AND p.inventory_accno_id > 0 AND p.income_accno_id > 0";
- }
- if ($form->{searchitems} eq 'assembly') {
- $form->{bought} = "";
- $where .= " AND p.assembly = '1'";
- }
- if ($form->{searchitems} eq 'service') {
- $where .= " AND p.assembly = '0' AND p.inventory_accno_id IS NULL";
- }
- if ($form->{searchitems} eq 'labor') {
- $where .= " AND p.inventory_accno_id > 0 AND p.income_accno_id IS NULL";
- }
-
- # items which were never bought, sold or on an order
- if ($form->{itemstatus} eq 'orphaned') {
- $where .= qq|
+ }
+
+ # special case for serialnumber
+ if ( $form->{l_serialnumber} ) {
+ if ( $form->{serialnumber} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{serialnumber} ) );
+ $where .= " AND lower(i.serialnumber) LIKE $var";
+ }
+ }
+
+ if ( ( $form->{warehouse} ne "" ) || $form->{l_warehouse} ) {
+ $form->{l_warehouse} = 1;
+ }
+
+ if ( $form->{searchitems} eq 'part' ) {
+ $where .= " AND p.inventory_accno_id > 0 AND p.income_accno_id > 0";
+ }
+ if ( $form->{searchitems} eq 'assembly' ) {
+ $form->{bought} = "";
+ $where .= " AND p.assembly = '1'";
+ }
+ if ( $form->{searchitems} eq 'service' ) {
+ $where .= " AND p.assembly = '0' AND p.inventory_accno_id IS NULL";
+ }
+ if ( $form->{searchitems} eq 'labor' ) {
+ $where .= " AND p.inventory_accno_id > 0 AND p.income_accno_id IS NULL";
+ }
+
+ # items which were never bought, sold or on an order
+ if ( $form->{itemstatus} eq 'orphaned' ) {
+ $where .= qq|
AND p.onhand = 0
AND p.id NOT IN (SELECT p.id FROM parts p
JOIN invoice i
@@ -1023,65 +1001,67 @@ sub all_parts {
AND p.id NOT IN (SELECT p.id FROM parts p
JOIN jcitems j
ON (p.id = j.parts_id))|;
- }
-
- if ($form->{itemstatus} eq 'active') {
- $where .= " AND p.obsolete = '0'";
- }
- if ($form->{itemstatus} eq 'obsolete') {
- $where .= " AND p.obsolete = '1'";
- }
- if ($form->{itemstatus} eq 'onhand') {
- $where .= " AND p.onhand > 0";
- }
- if ($form->{itemstatus} eq 'short') {
- $where .= " AND p.onhand < p.rop";
- }
-
- my $makemodelflds = qq|, '', ''|;;
- my $makemodeljoin;
-
- if (($form->{make} ne "") || $form->{l_make} || ($form->{model} ne "")
- || $form->{l_model}) {
- $makemodelflds = qq|, m.make, m.model|;
- $makemodeljoin = qq|LEFT JOIN makemodel m ON (m.parts_id = p.id)|;
-
- if ($form->{make} ne "") {
- $var = $dbh->quote($form->like(lc $form->{make}));
- $where .= " AND lower(m.make) LIKE $var";
- }
- if ($form->{model} ne "") {
- $var = $dbh->quote($form->like(lc $form->{model}));
- $where .= " AND lower(m.model) LIKE $var";
- }
- }
- if ($form->{partsgroup} ne "") {
- ($null, $var) = split /--/, $form->{partsgroup};
- $where .= qq| AND p.partsgroup_id = | . $dbh->quote($var);
- }
-
-
- my %ordinal = (
- 'partnumber' => 2,
- 'description' => 3,
- 'bin' => 6,
- 'priceupdate' => 13,
- 'drawing' => 15,
- 'microfiche' => 16,
- 'partsgroup' => 18,
- 'make' => 21,
- 'model' => 22,
- 'assemblypartnumber' => 23
- );
-
- my @a = qw(partnumber description);
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
- my $query = qq|SELECT value FROM defaults WHERE setting_key = 'curr'|;
- my ($curr) = $dbh->selectrow_array($query);
- $curr =~ s/:.*//;
- $curr = $dbh->quote($curr);
- my $flds = qq|
+ }
+
+ if ( $form->{itemstatus} eq 'active' ) {
+ $where .= " AND p.obsolete = '0'";
+ }
+ if ( $form->{itemstatus} eq 'obsolete' ) {
+ $where .= " AND p.obsolete = '1'";
+ }
+ if ( $form->{itemstatus} eq 'onhand' ) {
+ $where .= " AND p.onhand > 0";
+ }
+ if ( $form->{itemstatus} eq 'short' ) {
+ $where .= " AND p.onhand < p.rop";
+ }
+
+ my $makemodelflds = qq|, '', ''|;
+ my $makemodeljoin;
+
+ if ( ( $form->{make} ne "" )
+ || $form->{l_make}
+ || ( $form->{model} ne "" )
+ || $form->{l_model} )
+ {
+ $makemodelflds = qq|, m.make, m.model|;
+ $makemodeljoin = qq|LEFT JOIN makemodel m ON (m.parts_id = p.id)|;
+
+ if ( $form->{make} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{make} ) );
+ $where .= " AND lower(m.make) LIKE $var";
+ }
+ if ( $form->{model} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{model} ) );
+ $where .= " AND lower(m.model) LIKE $var";
+ }
+ }
+ if ( $form->{partsgroup} ne "" ) {
+ ( $null, $var ) = split /--/, $form->{partsgroup};
+ $where .= qq| AND p.partsgroup_id = | . $dbh->quote($var);
+ }
+
+ my %ordinal = (
+ 'partnumber' => 2,
+ 'description' => 3,
+ 'bin' => 6,
+ 'priceupdate' => 13,
+ 'drawing' => 15,
+ 'microfiche' => 16,
+ 'partsgroup' => 18,
+ 'make' => 21,
+ 'model' => 22,
+ 'assemblypartnumber' => 23
+ );
+
+ my @a = qw(partnumber description);
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ my $query = qq|SELECT value FROM defaults WHERE setting_key = 'curr'|;
+ my ($curr) = $dbh->selectrow_array($query);
+ $curr =~ s/:.*//;
+ $curr = $dbh->quote($curr);
+ my $flds = qq|
p.id, p.partnumber, p.description, p.onhand, p.unit,
p.bin, p.sellprice, p.listprice, p.lastcost, p.rop,
p.avgcost,
@@ -1092,7 +1072,7 @@ sub all_parts {
$makemodelflds $assemblyflds
|;
- $query = qq|
+ $query = qq|
SELECT $flds
FROM parts p
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
@@ -1103,12 +1083,12 @@ sub all_parts {
WHERE $where
ORDER BY $sortorder|;
- # redo query for components report
- if ($form->{searchitems} eq 'component') {
-
- $flds =~ s/p.onhand/a.qty AS onhand/;
-
- $query = qq|
+ # redo query for components report
+ if ( $form->{searchitems} eq 'component' ) {
+
+ $flds =~ s/p.onhand/a.qty AS onhand/;
+
+ $query = qq|
SELECT $flds
FROM assembly a
JOIN parts p ON (a.parts_id = p.id)
@@ -1120,91 +1100,92 @@ sub all_parts {
$makemodeljoin
WHERE $where
ORDER BY $sortorder|;
- }
-
-
- # rebuild query for bought and sold items
- if ($form->{bought} || $form->{sold} || $form->{onorder}
- || $form->{ordered} || $form->{rfq} || $form->{quoted}
- ) {
-
- $form->sort_order();
- @a = qw(partnumber description curr employee name
- serialnumber id);
- push @a, "invnumber" if ($form->{bought} || $form->{sold});
- push @a, "ordnumber" if ($form->{onorder} || $form->{ordered});
- push @a, "quonumber" if ($form->{rfq} || $form->{quoted});
-
- %ordinal = (
- 'partnumber' => 2,
- 'description' => 3,
- 'serialnumber' => 4,
- 'bin' => 7,
- 'priceupdate' => 14,
- 'partsgroup' => 19,
- 'invnumber' => 20,
- 'ordnumber' => 21,
- 'quonumber' => 22,
- 'name' => 24,
- 'employee' => 25,
- 'curr' => 26,
- 'make' => 29,
- 'model' => 30
- );
-
- $sortorder = $form->sort_order(\@a, \%ordinal);
-
- my $union = "";
- $query = "";
-
- if ($form->{bought} || $form->{sold}) {
-
- my $invwhere = "$where";
- my $transdate =
- ($form->{method} eq 'accrual')
- ? "transdate"
- : "datepaid";
-
- $invwhere .= " AND i.assemblyitem = '0'";
- $invwhere .= " AND a.$transdate >= " .
- $dbh->quote($form->{transdatefrom})
- if $form->{transdatefrom};
- $invwhere .= " AND a.$transdate <= " .
- $dbh->quote($form->{transdateto})
- if $form->{transdateto};
-
- if ($form->{description} ne "") {
- $var = dbh->quote(
- $form->like(lc $form->{description}));
- $invwhere .=
- " AND lower(i.description) LIKE $var";
- }
-
- if ($form->{open} || $form->{closed}) {
- if ($form->{open} && $form->{closed}) {
- if ($form->{method} eq 'cash') {
- $invwhere .=
- " AND a.amount = a.paid";
- }
- } else {
- if ($form->{open}) {
- if ($form->{method} eq 'cash') {
- $invwhere .=
- " AND a.id = 0";
- } else {
- $invwhere .=
- " AND NOT a.amount = a.paid";
- }
- } else {
- $invwhere .=
- " AND a.amount = a.paid";
- }
- }
- } else {
- $invwhere .= " AND a.id = 0";
- }
-
- my $flds = qq|
+ }
+
+ # rebuild query for bought and sold items
+ if ( $form->{bought}
+ || $form->{sold}
+ || $form->{onorder}
+ || $form->{ordered}
+ || $form->{rfq}
+ || $form->{quoted} )
+ {
+
+ $form->sort_order();
+ @a = qw(partnumber description curr employee name
+ serialnumber id);
+ push @a, "invnumber" if ( $form->{bought} || $form->{sold} );
+ push @a, "ordnumber" if ( $form->{onorder} || $form->{ordered} );
+ push @a, "quonumber" if ( $form->{rfq} || $form->{quoted} );
+
+ %ordinal = (
+ 'partnumber' => 2,
+ 'description' => 3,
+ 'serialnumber' => 4,
+ 'bin' => 7,
+ 'priceupdate' => 14,
+ 'partsgroup' => 19,
+ 'invnumber' => 20,
+ 'ordnumber' => 21,
+ 'quonumber' => 22,
+ 'name' => 24,
+ 'employee' => 25,
+ 'curr' => 26,
+ 'make' => 29,
+ 'model' => 30
+ );
+
+ $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ my $union = "";
+ $query = "";
+
+ if ( $form->{bought} || $form->{sold} ) {
+
+ my $invwhere = "$where";
+ my $transdate =
+ ( $form->{method} eq 'accrual' )
+ ? "transdate"
+ : "datepaid";
+
+ $invwhere .= " AND i.assemblyitem = '0'";
+ $invwhere .=
+ " AND a.$transdate >= " . $dbh->quote( $form->{transdatefrom} )
+ if $form->{transdatefrom};
+ $invwhere .=
+ " AND a.$transdate <= " . $dbh->quote( $form->{transdateto} )
+ if $form->{transdateto};
+
+ if ( $form->{description} ne "" ) {
+ $var = dbh->quote( $form->like( lc $form->{description} ) );
+ $invwhere .= " AND lower(i.description) LIKE $var";
+ }
+
+ if ( $form->{open} || $form->{closed} ) {
+ if ( $form->{open} && $form->{closed} ) {
+ if ( $form->{method} eq 'cash' ) {
+ $invwhere .= " AND a.amount = a.paid";
+ }
+ }
+ else {
+ if ( $form->{open} ) {
+ if ( $form->{method} eq 'cash' ) {
+ $invwhere .= " AND a.id = 0";
+ }
+ else {
+ $invwhere .= " AND NOT a.amount = a.paid";
+ }
+ }
+ else {
+ $invwhere .= " AND a.amount = a.paid";
+ }
+ }
+ }
+ else {
+ $invwhere .= " AND a.id = 0";
+ }
+
+ my $flds = qq|
p.id, p.partnumber, i.description,
i.serialnumber, i.qty AS onhand, i.unit, p.bin,
i.sellprice, p.listprice, p.lastcost, p.rop,
@@ -1215,13 +1196,11 @@ sub all_parts {
e.name AS employee, a.curr, a.till, p.notes
$makemodelfld|;
+ if ( $form->{bought} ) {
+ my $rflds = $flds;
+ $rflds =~ s/i.qty AS onhand/i.qty * -1 AS onhand/;
- if ($form->{bought}) {
- my $rflds = $flds;
- $rflds =~
- s/i.qty AS onhand/i.qty * -1 AS onhand/;
-
- $query = qq|
+ $query = qq|
SELECT $rflds, 'ir' AS module,
'' AS type,
(SELECT sell
@@ -1242,12 +1221,12 @@ sub all_parts {
ON (a.employee_id = e.id)
$makemodeljoin
WHERE $invwhere|;
- $union = "
+ $union = "
UNION ALL";
- }
+ }
- if ($form->{sold}) {
- $query .= qq|
+ if ( $form->{sold} ) {
+ $query .= qq|
$union
SELECT $flds, 'is' AS module,
'' AS type,
@@ -1269,39 +1248,39 @@ sub all_parts {
ON (a.employee_id = e.id)
$makemodeljoin
WHERE $invwhere|;
- $union = "
+ $union = "
UNION ALL";
- }
- }
+ }
+ }
- if ($form->{onorder} || $form->{ordered}) {
- my $ordwhere = "$where
+ if ( $form->{onorder} || $form->{ordered} ) {
+ my $ordwhere = "$where
AND a.quotation = '0'";
- $ordwhere .= " AND a.transdate >= ".
- $dbh->quote($form->{transdatefrom})
- if $form->{transdatefrom};
- $ordwhere .= " AND a.transdate <= ".
- $dbh->quote($form->{transdateto})
- if $form->{transdateto};
-
- if ($form->{description} ne "") {
- $var = $dbh->quote(
- $form->like(lc $form->{description}));
- $ordwhere .= " AND lower(i.description) LIKE $var";
- }
-
- if ($form->{open} || $form->{closed}) {
- unless ($form->{open} && $form->{closed}) {
- $ordwhere .= " AND a.closed = '0'"
- if $form->{open};
- $ordwhere .= " AND a.closed = '1'"
- if $form->{closed};
- }
- } else {
- $ordwhere .= " AND a.id = 0";
- }
-
- $flds = qq|
+ $ordwhere .=
+ " AND a.transdate >= " . $dbh->quote( $form->{transdatefrom} )
+ if $form->{transdatefrom};
+ $ordwhere .=
+ " AND a.transdate <= " . $dbh->quote( $form->{transdateto} )
+ if $form->{transdateto};
+
+ if ( $form->{description} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{description} ) );
+ $ordwhere .= " AND lower(i.description) LIKE $var";
+ }
+
+ if ( $form->{open} || $form->{closed} ) {
+ unless ( $form->{open} && $form->{closed} ) {
+ $ordwhere .= " AND a.closed = '0'"
+ if $form->{open};
+ $ordwhere .= " AND a.closed = '1'"
+ if $form->{closed};
+ }
+ }
+ else {
+ $ordwhere .= " AND a.id = 0";
+ }
+
+ $flds = qq|
p.id, p.partnumber, i.description,
i.serialnumber, i.qty AS onhand, i.unit, p.bin,
i.sellprice, p.listprice, p.lastcost, p.rop,
@@ -1313,8 +1292,8 @@ sub all_parts {
p.notes
$makemodelfld|;
- if ($form->{ordered}) {
- $query .= qq|
+ if ( $form->{ordered} ) {
+ $query .= qq|
$union
SELECT $flds, 'oe' AS module,
'sales_order' AS type,
@@ -1336,12 +1315,12 @@ sub all_parts {
$makemodeljoin
WHERE $ordwhere
AND a.customer_id > 0|;
- $union = "
+ $union = "
UNION ALL";
- }
-
- if ($form->{onorder}) {
- $flds = qq|
+ }
+
+ if ( $form->{onorder} ) {
+ $flds = qq|
p.id, p.partnumber, i.description,
i.serialnumber, i.qty AS onhand, i.unit,
p.bin, i.sellprice, p.listprice,
@@ -1353,8 +1332,8 @@ sub all_parts {
i.trans_id, ct.name,e.name AS employee,
a.curr, '0' AS till, p.notes
$makemodelfld|;
-
- $query .= qq|
+
+ $query .= qq|
$union
SELECT $flds, 'oe' AS module,
'purchase_order' AS type,
@@ -1376,39 +1355,38 @@ sub all_parts {
$makemodeljoin
WHERE $ordwhere
AND a.vendor_id > 0|;
- }
-
- }
-
- if ($form->{rfq} || $form->{quoted}) {
- my $quowhere = "$where
+ }
+
+ }
+
+ if ( $form->{rfq} || $form->{quoted} ) {
+ my $quowhere = "$where
AND a.quotation = '1'";
- $quowhere .= " AND a.transdate >= ".
- $dbh->quote($form->{transdatefrom})
- if $form->{transdatefrom};
- $quowhere .= " AND a.transdate <= ".
- $dbh->quote($form->{transdateto})
- if $form->{transdateto};
-
- if ($form->{description} ne "") {
- $var = $dbh->quote(
- $form->like(lc $form->{description}));
- $quowhere .= " AND lower(i.description) LIKE $var";
- }
-
- if ($form->{open} || $form->{closed}) {
- unless ($form->{open} && $form->{closed}) {
- $ordwhere .= " AND a.closed = '0'"
- if $form->{open};
- $ordwhere .= " AND a.closed = '1'"
- if $form->{closed};
- }
- } else {
- $ordwhere .= " AND a.id = 0";
- }
-
-
- $flds = qq|
+ $quowhere .=
+ " AND a.transdate >= " . $dbh->quote( $form->{transdatefrom} )
+ if $form->{transdatefrom};
+ $quowhere .=
+ " AND a.transdate <= " . $dbh->quote( $form->{transdateto} )
+ if $form->{transdateto};
+
+ if ( $form->{description} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{description} ) );
+ $quowhere .= " AND lower(i.description) LIKE $var";
+ }
+
+ if ( $form->{open} || $form->{closed} ) {
+ unless ( $form->{open} && $form->{closed} ) {
+ $ordwhere .= " AND a.closed = '0'"
+ if $form->{open};
+ $ordwhere .= " AND a.closed = '1'"
+ if $form->{closed};
+ }
+ }
+ else {
+ $ordwhere .= " AND a.id = 0";
+ }
+
+ $flds = qq|
p.id, p.partnumber, i.description,
i.serialnumber, i.qty AS onhand, i.unit, p.bin,
i.sellprice, p.listprice, p.lastcost, p.rop,
@@ -1419,8 +1397,8 @@ sub all_parts {
e.name AS employee, a.curr, '0' AS till, p.notes
$makemodelfld|;
- if ($form->{quoted}) {
- $query .= qq|
+ if ( $form->{quoted} ) {
+ $query .= qq|
$union
SELECT $flds, 'oe' AS module,
'sales_quotation' AS type,
@@ -1443,12 +1421,12 @@ sub all_parts {
$makemodeljoin
WHERE $quowhere
AND a.customer_id > 0|;
- $union = "
+ $union = "
UNION ALL";
- }
-
- if ($form->{rfq}) {
- $flds = qq|
+ }
+
+ if ( $form->{rfq} ) {
+ $flds = qq|
p.id, p.partnumber, i.description,
i.serialnumber, i.qty AS onhand,
i.unit, p.bin, i.sellprice, p.listprice,
@@ -1461,7 +1439,7 @@ sub all_parts {
a.curr, '0' AS till, p.notes
$makemodelfld|;
- $query .= qq|
+ $query .= qq|
$union
SELECT $flds, 'oe' AS module,
'request_quotation' AS type,
@@ -1483,44 +1461,44 @@ sub all_parts {
$makemodeljoin
WHERE $quowhere
AND a.vendor_id > 0|;
- }
+ }
- }
+ }
- $query .= qq|
+ $query .= qq|
ORDER BY $sortorder|;
- }
+ }
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT c.accno
FROM chart c
JOIN partstax pt ON (pt.chart_id = c.id)
WHERE pt.parts_id = ?
ORDER BY accno|;
- my $pth = $dbh->prepare($query) || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $pth->execute($ref->{id});
- while (($accno) = $pth->fetchrow_array) {
- $ref->{tax} .= "$accno ";
- }
- $pth->finish;
-
- push @{ $form->{parts} }, $ref;
- }
- $sth->finish;
-
- @a = ();
-
- # include individual items for assembly
- if (($form->{searchitems} eq 'assembly') && $form->{individual}) {
-
- if ($form->{sold} || $form->{ordered} || $form->{quoted}) {
- $flds = qq|
+ my $pth = $dbh->prepare($query) || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $pth->execute( $ref->{id} );
+ while ( ($accno) = $pth->fetchrow_array ) {
+ $ref->{tax} .= "$accno ";
+ }
+ $pth->finish;
+
+ push @{ $form->{parts} }, $ref;
+ }
+ $sth->finish;
+
+ @a = ();
+
+ # include individual items for assembly
+ if ( ( $form->{searchitems} eq 'assembly' ) && $form->{individual} ) {
+
+ if ( $form->{sold} || $form->{ordered} || $form->{quoted} ) {
+ $flds = qq|
p.id, p.partnumber, p.description,
p.onhand AS perassembly, p.unit, p.bin,
p.sellprice, p.listprice, p.lastcost, p.rop,
@@ -1528,108 +1506,111 @@ sub all_parts {
p.drawing, p.microfiche, p.assembly,
pg.partsgroup, p.notes
$makemodelflds $assemblyflds |;
- } else {
- # replace p.onhand with a.qty AS onhand
- $flds =~ s/p\.onhand/a.qty AS perassembly/;
- }
-
- for (@{ $form->{parts} }) {
- push @a, $_;
- $_->{perassembly} = 1;
- $flds =~ s/p\.onhand*AS perassembly/p\.onhand, a\.qty AS perassembly/;
- push @a, &include_assembly(
- $dbh, $myconfig, $form, $_->{id}, $flds,
- $makemodeljoin);
- push @a, {id => $_->{id}, assemblyitem => 1};
- }
-
- # copy assemblies to $form->{parts}
- @{ $form->{parts} } = @a;
-
- }
-
-
- @a = ();
- if (($form->{warehouse} ne "") || $form->{l_warehouse}) {
-
- if ($form->{warehouse} ne "") {
- my ($desc, $var) = split /--/, $form->{warehouse};
- $var = $dbh->quote($var);
- $desc = $dbh->quote($desc);
- $query = qq|
+ }
+ else {
+
+ # replace p.onhand with a.qty AS onhand
+ $flds =~ s/p\.onhand/a.qty AS perassembly/;
+ }
+
+ for ( @{ $form->{parts} } ) {
+ push @a, $_;
+ $_->{perassembly} = 1;
+ $flds =~
+ s/p\.onhand*AS perassembly/p\.onhand, a\.qty AS perassembly/;
+ push @a,
+ &include_assembly( $dbh, $myconfig, $form, $_->{id}, $flds,
+ $makemodeljoin );
+ push @a, { id => $_->{id}, assemblyitem => 1 };
+ }
+
+ # copy assemblies to $form->{parts}
+ @{ $form->{parts} } = @a;
+
+ }
+
+ @a = ();
+ if ( ( $form->{warehouse} ne "" ) || $form->{l_warehouse} ) {
+
+ if ( $form->{warehouse} ne "" ) {
+ my ( $desc, $var ) = split /--/, $form->{warehouse};
+ $var = $dbh->quote($var);
+ $desc = $dbh->quote($desc);
+ $query = qq|
SELECT SUM(qty) AS onhand,
$desc AS description
FROM inventory
WHERE warehouse_id = $var
AND parts_id = ?|;
- } else {
- $query = qq|
+ }
+ else {
+ $query = qq|
SELECT SUM(i.qty) AS onhand,
w.description AS warehouse
FROM inventory i
JOIN warehouse w ON (w.id = i.warehouse_id)
WHERE i.parts_id = ?
GROUP BY w.description|;
- }
+ }
- $sth = $dbh->prepare($query) || $form->dberror($query);
+ $sth = $dbh->prepare($query) || $form->dberror($query);
- for (@{ $form->{parts} }) {
+ for ( @{ $form->{parts} } ) {
- $sth->execute($_->{id}) || $form->dberror($query);
-
- if ($form->{warehouse} ne "") {
-
- $ref = $sth->fetchrow_hashref(NAME_lc);
- if ($ref->{onhand} != 0) {
- $_->{onhand} = $ref->{onhand};
- push @a, $_;
- }
+ $sth->execute( $_->{id} ) || $form->dberror($query);
- } else {
+ if ( $form->{warehouse} ne "" ) {
- push @a, $_;
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- if ($ref->{onhand} > 0) {
- push @a, $ref;
- }
- }
- }
-
- $sth->finish;
- }
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ if ( $ref->{onhand} != 0 ) {
+ $_->{onhand} = $ref->{onhand};
+ push @a, $_;
+ }
- @{ $form->{parts} } = @a;
+ }
+ else {
- }
+ push @a, $_;
- $dbh->commit;
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ if ( $ref->{onhand} > 0 ) {
+ push @a, $ref;
+ }
+ }
+ }
-}
+ $sth->finish;
+ }
+
+ @{ $form->{parts} } = @a;
+
+ }
+
+ $dbh->commit;
+}
sub include_assembly {
- my ($dbh, $myconfig, $form, $id, $flds, $makemodeljoin) = @_;
-
- $form->{stagger}++;
- if ($form->{stagger} > $form->{pncol}) {
- $form->{pncol} = $form->{stagger};
- }
-
- $form->{$id} = 1;
-
-
- my @a = qw(partnumber description bin);
- if ($form->{sort} eq 'partnumber') {
- $sortorder = "TRUE";
- } else {
- @a = grep !/$form->{sort}/, @a;
- $sortorder = "$form->{sort} $form->{direction}, ". join ',', @a;
- }
-
- @a = ();
- my $query = qq|
+ my ( $dbh, $myconfig, $form, $id, $flds, $makemodeljoin ) = @_;
+
+ $form->{stagger}++;
+ if ( $form->{stagger} > $form->{pncol} ) {
+ $form->{pncol} = $form->{stagger};
+ }
+
+ $form->{$id} = 1;
+
+ my @a = qw(partnumber description bin);
+ if ( $form->{sort} eq 'partnumber' ) {
+ $sortorder = "TRUE";
+ }
+ else {
+ @a = grep !/$form->{sort}/, @a;
+ $sortorder = "$form->{sort} $form->{direction}, " . join ',', @a;
+ }
+
+ @a = ();
+ my $query = qq|
SELECT $flds
FROM parts p
JOIN assembly a ON (a.parts_id = p.id)
@@ -1640,69 +1621,68 @@ sub include_assembly {
$makemodeljoin
WHERE a.id = ?
ORDER BY $sortorder|;
- my $sth = $dbh->prepare($query);
- $sth->execute($id) || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{assemblyitem} = 1;
- $ref->{stagger} = $form->{stagger};
-
- push @a, $ref;
- if ($ref->{assembly} && !$form->{$ref->{id}}) {
- push @a, &include_assembly(
- $dbh, $myconfig, $form, $ref->{id}, $flds,
- $makemodeljoin);
- if ($form->{stagger} > $form->{pncol}) {
- $form->{pncol} = $form->{stagger};
- }
- }
- }
- $sth->finish;
-
- $form->{$id} = 0;
- $form->{stagger}--;
-
- @a;
+ my $sth = $dbh->prepare($query);
+ $sth->execute($id) || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{assemblyitem} = 1;
+ $ref->{stagger} = $form->{stagger};
+
+ push @a, $ref;
+ if ( $ref->{assembly} && !$form->{ $ref->{id} } ) {
+ push @a,
+ &include_assembly( $dbh, $myconfig, $form, $ref->{id}, $flds,
+ $makemodeljoin );
+ if ( $form->{stagger} > $form->{pncol} ) {
+ $form->{pncol} = $form->{stagger};
+ }
+ }
+ }
+ $sth->finish;
+
+ $form->{$id} = 0;
+ $form->{stagger}--;
+
+ @a;
}
-
sub requirements {
- my ($self, $myconfig, $form) = @_;
- my $dbh = $form->{dbh};
-
- my $null;
- my $var;
- my $ref;
-
- my $where = qq|p.obsolete = '0'|;
- my $dwhere;
-
- for (qw(partnumber description)) {
- if ($form->{$_} ne "") {
- $var = $dbh->quote($form->like(lc $form->{$_}));
- $where .= qq| AND lower(p.$_) LIKE $var|;
- }
- }
-
- if ($form->{partsgroup} ne "") {
- ($null, $var) = split /--/, $form->{partsgroup};
- $var = $dbh->quote($var);
- $where .= qq| AND p.partsgroup_id = $var|;
- }
-
- # connect to database
-
- my ($transdatefrom, $transdateto);
- if ($form->{year}) {
- ($transdatefrom, $transdateto)
- = $form->from_to($form->{year}, '01', 12);
-
- $dwhere = qq| AND a.transdate >= '$transdatefrom'
+ my ( $self, $myconfig, $form ) = @_;
+ my $dbh = $form->{dbh};
+
+ my $null;
+ my $var;
+ my $ref;
+
+ my $where = qq|p.obsolete = '0'|;
+ my $dwhere;
+
+ for (qw(partnumber description)) {
+ if ( $form->{$_} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{$_} ) );
+ $where .= qq| AND lower(p.$_) LIKE $var|;
+ }
+ }
+
+ if ( $form->{partsgroup} ne "" ) {
+ ( $null, $var ) = split /--/, $form->{partsgroup};
+ $var = $dbh->quote($var);
+ $where .= qq| AND p.partsgroup_id = $var|;
+ }
+
+ # connect to database
+
+ my ( $transdatefrom, $transdateto );
+ if ( $form->{year} ) {
+ ( $transdatefrom, $transdateto ) =
+ $form->from_to( $form->{year}, '01', 12 );
+
+ $dwhere = qq| AND a.transdate >= '$transdatefrom'
AND a.transdate <= '$transdateto'|;
- }
-
- $query = qq|
+ }
+
+ $query = qq|
SELECT p.id, p.partnumber, p.description, sum(i.qty) AS qty,
p.onhand, extract(MONTH FROM a.transdate) AS month,
'0' AS so, '0' AS po
@@ -1712,19 +1692,19 @@ sub requirements {
WHERE $where $dwhere AND p.inventory_accno_id > 0
GROUP BY p.id, p.partnumber, p.description, p.onhand,
extract(MONTH FROM a.transdate)|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- my %parts;
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $parts{$ref->{id}} = $ref;
- }
- $sth->finish;
-
- my %ofld = ( customer => so, vendor => po );
-
- for (qw(customer vendor)) {
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ my %parts;
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $parts{ $ref->{id} } = $ref;
+ }
+ $sth->finish;
+
+ my %ofld = ( customer => so, vendor => po );
+
+ for (qw(customer vendor)) {
+ $query = qq|
SELECT p.id, p.partnumber, p.description,
sum(qty) - sum(ship) AS $ofld{$_}, p.onhand,
0 AS month
@@ -1736,22 +1716,22 @@ sub requirements {
AND a.${_}_id > 0
GROUP BY p.id, p.partnumber, p.description, p.onhand,
month|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- if (exists $parts{$ref->{id}}->{$ofld{$_}}) {
- $parts{$ref->{id}}->{$ofld{$_}}
- += $ref->{$ofld{$_}};
- } else {
- $parts{$ref->{id}} = $ref;
- }
- }
- $sth->finish;
- }
-
- # add assemblies from open sales orders
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ if ( exists $parts{ $ref->{id} }->{ $ofld{$_} } ) {
+ $parts{ $ref->{id} }->{ $ofld{$_} } += $ref->{ $ofld{$_} };
+ }
+ else {
+ $parts{ $ref->{id} } = $ref;
+ }
+ }
+ $sth->finish;
+ }
+
+ # add assemblies from open sales orders
+ $query = qq|
SELECT DISTINCT a.id AS orderid, b.id, i.qty - i.ship AS qty
FROM parts p
JOIN assembly b ON (b.parts_id = p.id)
@@ -1760,30 +1740,33 @@ sub requirements {
WHERE $where
AND (p.inventory_accno_id > 0 OR p.assembly = '1')
AND a.closed = '0'|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- &requirements_assembly(
- $dbh, $form, \%parts, $ref->{id}, $ref->{qty}, $where)
- if $ref->{qty};
- }
- $sth->finish;
-
- $dbh->commit;
-
- for (sort { $parts{$a}->{$form->{sort}} cmp $parts{$b}->{$form->{sort}}} keys %parts) {
- push @{ $form->{parts} }, $parts{$_};
- }
-
-}
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ &requirements_assembly( $dbh, $form, \%parts, $ref->{id}, $ref->{qty},
+ $where )
+ if $ref->{qty};
+ }
+ $sth->finish;
+
+ $dbh->commit;
+
+ for (
+ sort { $parts{$a}->{ $form->{sort} } cmp $parts{$b}->{ $form->{sort} } }
+ keys %parts
+ )
+ {
+ push @{ $form->{parts} }, $parts{$_};
+ }
+}
sub requirements_assembly {
- my ($dbh, $form, $parts, $id, $qty, $where) = @_;
+ my ( $dbh, $form, $parts, $id, $qty, $where ) = @_;
- # assemblies
- my $query = qq|
+ # assemblies
+ my $query = qq|
SELECT p.id, p.partnumber, p.description, a.qty * ? AS so,
p.onhand, p.assembly, p.partsgroup_id
FROM assembly a
@@ -1797,110 +1780,112 @@ sub requirements_assembly {
FROM assembly a
JOIN parts p ON (p.id = a.parts_id)
WHERE a.id = ? AND p.assembly = '1'|;
-
- my $sth = $dbh->prepare($query);
- $sth->execute($qty, $id, $qty, $id) || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- if ($ref->{assembly}) {
- &requirements_assembly(
- $dbh, $form, $parts, $ref->{id}, $ref->{so},
- $where);
- next;
- }
-
- if (exists $parts->{$ref->{id}}{so}) {
- $parts->{$ref->{id}}{so} += $ref->{so};
- } else {
- $parts->{$ref->{id}} = $ref;
- }
- }
- $sth->finish;
-
-}
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $qty, $id, $qty, $id ) || $form->dberror($query);
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ if ( $ref->{assembly} ) {
+ &requirements_assembly( $dbh, $form, $parts, $ref->{id}, $ref->{so},
+ $where );
+ next;
+ }
+
+ if ( exists $parts->{ $ref->{id} }{so} ) {
+ $parts->{ $ref->{id} }{so} += $ref->{so};
+ }
+ else {
+ $parts->{ $ref->{id} } = $ref;
+ }
+ }
+ $sth->finish;
+
+}
sub create_links {
- my ($self, $module, $myconfig, $form) = @_;
+ my ( $self, $module, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
- # connect to database
- my $dbh = $form->{dbh};
-
- my $ref;
+ my $ref;
- my $query = qq|
+ my $query = qq|
SELECT accno, description, link
FROM chart
WHERE link LIKE ?
ORDER BY accno|;
- my $sth = $dbh->prepare($query);
- $sth->execute("%$module%") || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- foreach my $key (split /:/, $ref->{link}) {
- if ($key =~ /$module/) {
- push @{ $form->{"${module}_links"}{$key} },
- { accno => $ref->{accno},
- description => $ref->{description} };
- }
- }
- }
- $sth->finish;
-
- if ($form->{item} ne 'assembly') {
- $query = qq|SELECT count(*) FROM vendor|;
- my ($count) = $dbh->selectrow_array($query);
-
- if ($count < $myconfig->{vclimit}) {
- $query = qq|SELECT id, name FROM vendor ORDER BY name|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_vendor} }, $ref;
- }
- $sth->finish;
- }
- }
-
- # pricegroups, customers
- $query = qq|SELECT count(*) FROM customer|;
- ($count) = $dbh->selectrow_array($query);
-
- if ($count < $myconfig->{vclimit}) {
- $query = qq|SELECT id, name FROM customer ORDER BY name|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_customer} }, $ref;
- }
- $sth->finish;
- }
-
- $query = qq|SELECT id, pricegroup FROM pricegroup ORDER BY pricegroup|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_pricegroup} }, $ref;
- }
- $sth->finish;
-
-
- if ($form->{id}) {
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute("%$module%") || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ foreach my $key ( split /:/, $ref->{link} ) {
+ if ( $key =~ /$module/ ) {
+ push @{ $form->{"${module}_links"}{$key} },
+ {
+ accno => $ref->{accno},
+ description => $ref->{description}
+ };
+ }
+ }
+ }
+ $sth->finish;
+
+ if ( $form->{item} ne 'assembly' ) {
+ $query = qq|SELECT count(*) FROM vendor|;
+ my ($count) = $dbh->selectrow_array($query);
+
+ if ( $count < $myconfig->{vclimit} ) {
+ $query = qq|SELECT id, name FROM vendor ORDER BY name|;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_vendor} }, $ref;
+ }
+ $sth->finish;
+ }
+ }
+
+ # pricegroups, customers
+ $query = qq|SELECT count(*) FROM customer|;
+ ($count) = $dbh->selectrow_array($query);
+
+ if ( $count < $myconfig->{vclimit} ) {
+ $query = qq|SELECT id, name FROM customer ORDER BY name|;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_customer} }, $ref;
+ }
+ $sth->finish;
+ }
+
+ $query = qq|SELECT id, pricegroup FROM pricegroup ORDER BY pricegroup|;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_pricegroup} }, $ref;
+ }
+ $sth->finish;
+
+ if ( $form->{id} ) {
+ $query = qq|
SELECT value FROM defaults
WHERE setting_key = 'weightunit'|;
- ($form->{weightunit}) = $dbh->selectrow_array($query);
- $query = qq|
+ ( $form->{weightunit} ) = $dbh->selectrow_array($query);
+ $query = qq|
SELECT value FROM defaults
WHERE setting_key = 'curr'|;
- ($form->{currencies}) = $dbh->selectrow_array($query);
+ ( $form->{currencies} ) = $dbh->selectrow_array($query);
- } else {
- # Dieter: FIXME left joins not working
- $query = qq|
+ }
+ else {
+
+ # Dieter: FIXME left joins not working
+ $query = qq|
SELECT (SELECT value FROM defaults
WHERE setting_key = 'weightunit')
AS weightunit, current_date AS priceupdate,
@@ -1920,46 +1905,45 @@ sub create_links {
AND c3.id IN (SELECT value FROM defaults
WHERE setting_key
= 'expense_accno_id')|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (qw(weightunit priceupdate currencies)) {
- $form->{$_} = $ref->{$_};
- }
- # setup accno hash, {amount} is used in create_links
- for (qw(inventory income expense)) {
- $form->{amount}{"IC_$_"}
- = {
- accno => $ref->{"${_}_accno"},
- description => $ref->{"${_}_description"}
- };
- }
-
- $sth->finish;
- }
-
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
-}
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for (qw(weightunit priceupdate currencies)) {
+ $form->{$_} = $ref->{$_};
+ }
+ # setup accno hash, {amount} is used in create_links
+ for (qw(inventory income expense)) {
+ $form->{amount}{"IC_$_"} = {
+ accno => $ref->{"${_}_accno"},
+ description => $ref->{"${_}_description"}
+ };
+ }
+
+ $sth->finish;
+ }
+
+ $dbh->commit;
+
+}
sub get_warehouses {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
+ my $dbh = $form->{dbh};
- my $query = qq|SELECT id, description FROM warehouse|;
+ my $query = qq|SELECT id, description FROM warehouse|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_warehouse} }, $ref;
- }
- $sth->finish;
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_warehouse} }, $ref;
+ }
+ $sth->finish;
- $dbh->commit;
+ $dbh->commit;
}
diff --git a/LedgerSMB/IR.pm b/LedgerSMB/IR.pm
index 87719d4d..1dab91d7 100644
--- a/LedgerSMB/IR.pm
+++ b/LedgerSMB/IR.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -37,241 +37,237 @@ use LedgerSMB::PriceMatrix;
use LedgerSMB::Sysconfig;
use Math::BigFloat;
-
sub post_invoice {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- for (1 .. $form->{rowcount}){
- unless ($form->{"deliverydate_$_"}){
- $form->{"deliverydate_$_"} = $form->{transdate};
- }
-
- }
- my $query;
- my $sth;
- my $ref;
- my $null;
- my $project_id;
- my $exchangerate = 0;
- my $allocated;
- my $taxrate;
- my $taxamount;
- my $diff = 0;
- my $item;
- my $invoice_id;
- my $keepcleared;
-
- ($null, $form->{employee_id}) = split /--/, $form->{employee};
-
- unless ($form->{employee_id}) {
- ($form->{employee}, $form->{employee_id})
- = $form->get_employee($dbh);
- }
-
- ($null, $form->{department_id}) = split(/--/, $form->{department});
- $form->{department_id} *= 1;
-
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ for ( 1 .. $form->{rowcount} ) {
+ unless ( $form->{"deliverydate_$_"} ) {
+ $form->{"deliverydate_$_"} = $form->{transdate};
+ }
+
+ }
+ my $query;
+ my $sth;
+ my $ref;
+ my $null;
+ my $project_id;
+ my $exchangerate = 0;
+ my $allocated;
+ my $taxrate;
+ my $taxamount;
+ my $diff = 0;
+ my $item;
+ my $invoice_id;
+ my $keepcleared;
+
+ ( $null, $form->{employee_id} ) = split /--/, $form->{employee};
+
+ unless ( $form->{employee_id} ) {
+ ( $form->{employee}, $form->{employee_id} ) = $form->get_employee($dbh);
+ }
+
+ ( $null, $form->{department_id} ) = split( /--/, $form->{department} );
+ $form->{department_id} *= 1;
+
+ $query = qq|
SELECT (SELECT value FROM defaults
WHERE setting_key = 'fxgain_accno_id')
AS fxgain_accno_id,
(SELECT value FROM defaults
WHERE setting_key = 'fxloss_accno_id')
AS fxloss_accno_id|;
- my ($fxgain_accno_id, $fxloss_accno_id) = $dbh->selectrow_array($query);
-
- $query = qq|
+ my ( $fxgain_accno_id, $fxloss_accno_id ) = $dbh->selectrow_array($query);
+
+ $query = qq|
SELECT inventory_accno_id, income_accno_id, expense_accno_id
FROM parts
WHERE id = ?|;
- my $pth = $dbh->prepare($query) || $form->dberror($query);
-
- my %updparts = ();
-
- if ($form->{id}) {
+ my $pth = $dbh->prepare($query) || $form->dberror($query);
+
+ my %updparts = ();
+
+ if ( $form->{id} ) {
+
+ my $sth;
- my $sth;
+ $keepcleared = 1;
- $keepcleared = 1;
+ $query = qq|SELECT id FROM ap WHERE id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} );
- $query = qq|SELECT id FROM ap WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id});
-
- if ($sth->fetchrow_array) {
- $query = qq|
+ if ( $sth->fetchrow_array ) {
+ $query = qq|
SELECT p.id, p.inventory_accno_id,
p.income_accno_id
FROM invoice i
JOIN parts p ON (p.id = i.parts_id)
WHERE i.trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- while ($ref = $sth->fetchrow_hashref) {
- if ($ref->{inventory_accno_id}
- && $ref->{income_accno_id}) {
-
- $updparts{$ref->{id}} = 1;
- }
- }
- $sth->finish;
-
- &reverse_invoice($dbh, $form);
- } else {
- $query = qq|INSERT INTO ap (id) VALUES (?)|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- }
- }
-
- my $uid = localtime;
- $uid .= "$$";
-
- if (! $form->{id}) {
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ while ( $ref = $sth->fetchrow_hashref ) {
+ if ( $ref->{inventory_accno_id}
+ && $ref->{income_accno_id} )
+ {
+
+ $updparts{ $ref->{id} } = 1;
+ }
+ }
+ $sth->finish;
+
+ &reverse_invoice( $dbh, $form );
+ }
+ else {
+ $query = qq|INSERT INTO ap (id) VALUES (?)|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ }
+ }
+
+ my $uid = localtime;
+ $uid .= "$$";
+
+ if ( !$form->{id} ) {
+
+ $query = qq|
INSERT INTO ap (invnumber, employee_id)
VALUES ('$uid', (SELECT id FROM employee
- WHERE login = ?))|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{login}) || $form->dberror($query);
-
- $query = qq|SELECT id FROM ap WHERE invnumber = '$uid'|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- ($form->{id}) = $sth->fetchrow_array;
- $sth->finish;
-
- }
-
- my $amount;
- my $grossamount;
- my $allocated;
- my $invamount = 0;
- my $invnetamount = 0;
-
- if ($form->{currency} eq $form->{defaultcurrency}) {
- $form->{exchangerate} = 1;
- } else {
- $exchangerate =
- $form->check_exchangerate(
- $myconfig, $form->{currency},
- $form->{transdate}, 'sell');
- }
-
- $form->{exchangerate} =
- ($exchangerate)
- ? $exchangerate
- : $form->parse_amount($myconfig, $form->{exchangerate});
-
- for my $i (1 .. $form->{rowcount}) {
- $form->{"qty_$i"} =
- $form->parse_amount($myconfig, $form->{"qty_$i"});
-
- if ($form->{"qty_$i"}) {
-
- $pth->execute($form->{"id_$i"});
- $ref = $pth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) {
- $form->{"${_}_$i"} = $ref->{$_};
- }
- $pth->finish;
-
- # project
-
- if ($form->{"projectnumber_$i"} ne "") {
- ($null, $project_id) =
- split /--/, $form->{"projectnumber_$i"};
- }
-
- # undo discount formatting
- $form->{"discount_$i"} =
- $form->parse_amount(
- $myconfig,
- $form->{"discount_$i"}) / 100;
-
- # keep entered selling price
- my $fxsellprice =
- $form->parse_amount(
- $myconfig, $form->{"sellprice_$i"});
-
- my ($dec) = ($fxsellprice =~ /\.(\d+)/);
- $dec = length $dec;
- my $decimalplaces = ($dec > 2) ? $dec : 2;
-
- # deduct discount
- $form->{"sellprice_$i"} =
- $fxsellprice - $form->round_amount(
- $fxsellprice * $form->{"discount_$i"},
- $decimalplaces);
-
- # linetotal
- my $fxlinetotal = $form->round_amount(
- $form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
-
- $amount = $fxlinetotal * $form->{exchangerate};
- my $linetotal = $form->round_amount($amount, 2);
- $fxdiff += $amount - $linetotal;
-
- @taxaccounts = Tax::init_taxes(
- $form, $form->{"taxaccounts_$i"});
-
- $tax = Math::BigFloat->bzero();
- $fxtax = Math::BigFloat->bzero();
-
- if ($form->{taxincluded}) {
- $tax += $amount = Tax::calculate_taxes(
- \@taxaccounts, $form, $linetotal, 1);
-
- $form->{"sellprice_$i"}
- -= $amount / $form->{"qty_$i"};
- } else {
- $tax += $amount = Tax::calculate_taxes(
- \@taxaccounts, $form, $linetotal, 0);
-
- $fxtax += Tax::calculate_taxes(
- \@taxaccounts, $form, $fxlinetotal, 0);
- }
-
- for (@taxaccounts) {
- $form->{acc_trans}{$form->{id}}{$_->account}{amount} += $_->value;
- }
-
- $grossamount = $form->round_amount($linetotal, 2);
-
- if ($form->{taxincluded}) {
- $amount = $form->round_amount($tax, 2);
- $linetotal -= $form->round_amount(
- $tax - $diff, 2);
- $diff = ($amount - $tax);
- }
-
- $amount = $form->round_amount($linetotal, 2);
- $allocated = 0;
-
- # adjust and round sellprice
- $form->{"sellprice_$i"} = $form->round_amount(
- $form->{"sellprice_$i"} * $form->{exchangerate},
- $decimalplaces);
-
- # save detail record in invoice table
- $query = qq|
+ WHERE login = ?))|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{login} ) || $form->dberror($query);
+
+ $query = qq|SELECT id FROM ap WHERE invnumber = '$uid'|;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ ( $form->{id} ) = $sth->fetchrow_array;
+ $sth->finish;
+
+ }
+
+ my $amount;
+ my $grossamount;
+ my $allocated;
+ my $invamount = 0;
+ my $invnetamount = 0;
+
+ if ( $form->{currency} eq $form->{defaultcurrency} ) {
+ $form->{exchangerate} = 1;
+ }
+ else {
+ $exchangerate =
+ $form->check_exchangerate( $myconfig, $form->{currency},
+ $form->{transdate}, 'sell' );
+ }
+
+ $form->{exchangerate} =
+ ($exchangerate)
+ ? $exchangerate
+ : $form->parse_amount( $myconfig, $form->{exchangerate} );
+
+ for my $i ( 1 .. $form->{rowcount} ) {
+ $form->{"qty_$i"} = $form->parse_amount( $myconfig, $form->{"qty_$i"} );
+
+ if ( $form->{"qty_$i"} ) {
+
+ $pth->execute( $form->{"id_$i"} );
+ $ref = $pth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) {
+ $form->{"${_}_$i"} = $ref->{$_};
+ }
+ $pth->finish;
+
+ # project
+
+ if ( $form->{"projectnumber_$i"} ne "" ) {
+ ( $null, $project_id ) =
+ split /--/, $form->{"projectnumber_$i"};
+ }
+
+ # undo discount formatting
+ $form->{"discount_$i"} =
+ $form->parse_amount( $myconfig, $form->{"discount_$i"} ) / 100;
+
+ # keep entered selling price
+ my $fxsellprice =
+ $form->parse_amount( $myconfig, $form->{"sellprice_$i"} );
+
+ my ($dec) = ( $fxsellprice =~ /\.(\d+)/ );
+ $dec = length $dec;
+ my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ # deduct discount
+ $form->{"sellprice_$i"} = $fxsellprice -
+ $form->round_amount( $fxsellprice * $form->{"discount_$i"},
+ $decimalplaces );
+
+ # linetotal
+ my $fxlinetotal =
+ $form->round_amount( $form->{"sellprice_$i"} * $form->{"qty_$i"},
+ 2 );
+
+ $amount = $fxlinetotal * $form->{exchangerate};
+ my $linetotal = $form->round_amount( $amount, 2 );
+ $fxdiff += $amount - $linetotal;
+
+ @taxaccounts = Tax::init_taxes( $form, $form->{"taxaccounts_$i"} );
+
+ $tax = Math::BigFloat->bzero();
+ $fxtax = Math::BigFloat->bzero();
+
+ if ( $form->{taxincluded} ) {
+ $tax += $amount =
+ Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 1 );
+
+ $form->{"sellprice_$i"} -= $amount / $form->{"qty_$i"};
+ }
+ else {
+ $tax += $amount =
+ Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 0 );
+
+ $fxtax +=
+ Tax::calculate_taxes( \@taxaccounts, $form, $fxlinetotal, 0 );
+ }
+
+ for (@taxaccounts) {
+ $form->{acc_trans}{ $form->{id} }{ $_->account }{amount} +=
+ $_->value;
+ }
+
+ $grossamount = $form->round_amount( $linetotal, 2 );
+
+ if ( $form->{taxincluded} ) {
+ $amount = $form->round_amount( $tax, 2 );
+ $linetotal -= $form->round_amount( $tax - $diff, 2 );
+ $diff = ( $amount - $tax );
+ }
+
+ $amount = $form->round_amount( $linetotal, 2 );
+ $allocated = 0;
+
+ # adjust and round sellprice
+ $form->{"sellprice_$i"} =
+ $form->round_amount(
+ $form->{"sellprice_$i"} * $form->{exchangerate},
+ $decimalplaces );
+
+ # save detail record in invoice table
+ $query = qq|
INSERT INTO invoice (description)
VALUES ('$uid')|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT id FROM invoice
WHERE description = '$uid'|;
- ($invoice_id) = $dbh->selectrow_array($query);
+ ($invoice_id) = $dbh->selectrow_array($query);
- $form->debug;
+ $form->debug;
- $query = qq|
+ $query = qq|
UPDATE invoice
SET trans_id = ?,
parts_id = ?,
@@ -287,44 +283,41 @@ sub post_invoice {
serialnumber = ?,
notes = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $form->{"id_$i"},
- $form->{"description_$i"}, $form->{"qty_$i"} * -1,
- $form->{"sellprice_$i"}, $fxsellprice,
- $form->{"discount_$i"}, $allocated,
- $form->{"unit_$i"}, $form->{"deliverydate_$i"},
- $project_id, $form->{"serialnumber_$i"},
- $form->{"notes_$i"}, $invoice_id)
- || $form->dberror($query);
-
-
- if ($form->{"inventory_accno_id_$i"}) {
-
- # add purchase to inventory
- push @{ $form->{acc_trans}{lineitems} },
- {chart_id =>
- $form->{"inventory_accno_id_$i"},
- amount => $amount,
- fxgrossamount => $fxlinetotal +
- $form->round_amount($fxtax, 2),
- grossamount => $grossamount,
- project_id => $project_id,
- invoice_id => $invoice_id };
-
-
- $updparts{$form->{"id_$i"}} = 1;
-
- # update parts table
- $form->update_balance(
- $dbh, "parts", "onhand",
- qq|id = $form->{"id_$i"}|,
- $form->{"qty_$i"})
- unless $form->{shipped};
-
-
- # check if we sold the item
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{id}, $form->{"id_$i"},
+ $form->{"description_$i"}, $form->{"qty_$i"} * -1,
+ $form->{"sellprice_$i"}, $fxsellprice,
+ $form->{"discount_$i"}, $allocated,
+ $form->{"unit_$i"}, $form->{"deliverydate_$i"},
+ $project_id, $form->{"serialnumber_$i"},
+ $form->{"notes_$i"}, $invoice_id
+ ) || $form->dberror($query);
+
+ if ( $form->{"inventory_accno_id_$i"} ) {
+
+ # add purchase to inventory
+ push @{ $form->{acc_trans}{lineitems} },
+ {
+ chart_id => $form->{"inventory_accno_id_$i"},
+ amount => $amount,
+ fxgrossamount => $fxlinetotal +
+ $form->round_amount( $fxtax, 2 ),
+ grossamount => $grossamount,
+ project_id => $project_id,
+ invoice_id => $invoice_id
+ };
+
+ $updparts{ $form->{"id_$i"} } = 1;
+
+ # update parts table
+ $form->update_balance( $dbh, "parts", "onhand",
+ qq|id = $form->{"id_$i"}|,
+ $form->{"qty_$i"} )
+ unless $form->{shipped};
+
+ # check if we sold the item
+ $query = qq|
SELECT i.id, i.qty, i.allocated,
i.trans_id, i.project_id,
p.inventory_accno_id,
@@ -335,28 +328,25 @@ sub post_invoice {
WHERE i.parts_id = ?
AND (i.qty + i.allocated) > 0
ORDER BY transdate|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{"id_$i"})
- || $form->dberror($query);
-
- my $totalqty = $form->{"qty_$i"};
-
- while (my $ref =
- $sth->fetchrow_hashref(NAME_lc)) {
-
- my $qty = $ref->{qty}
- + $ref->{allocated};
-
- if (($qty - $totalqty) > 0) {
- $qty = $totalqty;
- }
-
- $linetotal = $form->round_amount(
- $form->{"sellprice_$i"} * $qty,
- 2);
-
- if ($linetotal) {
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{"id_$i"} )
+ || $form->dberror($query);
+
+ my $totalqty = $form->{"qty_$i"};
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ my $qty = $ref->{qty} + $ref->{allocated};
+
+ if ( ( $qty - $totalqty ) > 0 ) {
+ $qty = $totalqty;
+ }
+
+ $linetotal =
+ $form->round_amount( $form->{"sellprice_$i"} * $qty, 2 );
+
+ if ($linetotal) {
+ $query = qq|
INSERT INTO acc_trans
(trans_id,
chart_id,
@@ -367,19 +357,15 @@ sub post_invoice {
VALUES (?, ?, ?, ?,
?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $ref->{trans_id},
- $ref->{inventory_accno_id},
- $linetotal,
- $ref->{transdate},
- $ref->{project_id},
- $invoice_id
- ) || $form->dberror(
- $query);
-
- # add expense
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $ref->{trans_id}, $ref->{inventory_accno_id},
+ $linetotal, $ref->{transdate},
+ $ref->{project_id}, $invoice_id
+ ) || $form->dberror($query);
+
+ # add expense
+ $query = qq|
INSERT INTO acc_trans
(trans_id,
chart_id,
@@ -389,203 +375,199 @@ sub post_invoice {
invoice_id)
VALUES (?, ?, ?, ?,
?, ?)|;
- $sth = $dbh->prepare($query) ;
- $sth->execute(
- $ref->{trans_id},
- $ref->{expense_accno_id},
- $linetotal * -1,
- $ref->{transdate},
- $ref->{project_id},
- $invoice_id
- ) || $form->dberror(
- $query);
- }
-
- # update allocated for sold item
- $form->update_balance(
- $dbh, "invoice", "allocated",
- qq|id = $ref->{id}|, $qty * -1);
-
- $allocated += $qty;
-
- last if (($totalqty -= $qty) <= 0);
- }
-
- $sth->finish;
-
- } else {
-
- # add purchase to expense
- push @{ $form->{acc_trans}{lineitems} }, {
- chart_id =>
- $form->{"expense_accno_id_$i"},
- amount => $amount,
- fxgrossamount => $fxlinetotal
- + $form->round_amount(
- $fxtax, 2),
- grossamount => $grossamount,
- project_id => $project_id,
- invoice_id => $invoice_id };
-
- }
- }
- }
-
- $form->{paid} = 0;
- for $i (1 .. $form->{paidaccounts}) {
- $form->{"paid_$i"} =
- $form->parse_amount($myconfig, $form->{"paid_$i"});
- $form->{paid} += $form->{"paid_$i"};
- $form->{datepaid} = $form->{"datepaid_$i"}
- if ($form->{"datepaid_$i"});
- }
-
- # add lineitems + tax
- $amount = 0;
- $grossamount = 0;
- $fxgrossamount = 0;
- for (@{ $form->{acc_trans}{lineitems} }) {
- $amount += $_->{amount};
- $grossamount += $_->{grossamount};
- $fxgrossamount += $_->{fxgrossamount};
- }
- $invnetamount = $amount;
-
- $amount = 0;
- for (split / /, $form->{taxaccounts}) {
- $amount += $form->{acc_trans}{$form->{id}}{$_}{amount}
- = $form->round_amount(
- $form->{acc_trans}{$form->{id}}{$_}{amount}, 2);
-
- $form->{acc_trans}{$form->{id}}{$_}{amount} *= -1;
- }
- $invamount = $invnetamount + $amount;
-
- $diff = 0;
- if ($form->{taxincluded}) {
- $diff = $form->round_amount($grossamount - $invamount, 2);
- $invamount += $diff;
- }
- $fxdiff = $form->round_amount($fxdiff,2);
- $invnetamount += $fxdiff;
- $invamount += $fxdiff;
-
- if ($form->round_amount($form->{paid} - $fxgrossamount,2) == 0) {
- $form->{paid} = $invamount;
- } else {
- $form->{paid} = $form->round_amount(
- $form->{paid} * $form->{exchangerate}, 2);
- }
-
- foreach $ref (sort { $b->{amount} <=> $a->{amount} }
- @ { $form->{acc_trans}{lineitems} }) {
-
- $amount = $ref->{amount} + $diff + $fxdiff;
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $ref->{trans_id}, $ref->{expense_accno_id},
+ $linetotal * -1, $ref->{transdate},
+ $ref->{project_id}, $invoice_id
+ ) || $form->dberror($query);
+ }
+
+ # update allocated for sold item
+ $form->update_balance( $dbh, "invoice", "allocated",
+ qq|id = $ref->{id}|,
+ $qty * -1 );
+
+ $allocated += $qty;
+
+ last if ( ( $totalqty -= $qty ) <= 0 );
+ }
+
+ $sth->finish;
+
+ }
+ else {
+
+ # add purchase to expense
+ push @{ $form->{acc_trans}{lineitems} },
+ {
+ chart_id => $form->{"expense_accno_id_$i"},
+ amount => $amount,
+ fxgrossamount => $fxlinetotal +
+ $form->round_amount( $fxtax, 2 ),
+ grossamount => $grossamount,
+ project_id => $project_id,
+ invoice_id => $invoice_id
+ };
+
+ }
+ }
+ }
+
+ $form->{paid} = 0;
+ for $i ( 1 .. $form->{paidaccounts} ) {
+ $form->{"paid_$i"} =
+ $form->parse_amount( $myconfig, $form->{"paid_$i"} );
+ $form->{paid} += $form->{"paid_$i"};
+ $form->{datepaid} = $form->{"datepaid_$i"}
+ if ( $form->{"datepaid_$i"} );
+ }
+
+ # add lineitems + tax
+ $amount = 0;
+ $grossamount = 0;
+ $fxgrossamount = 0;
+ for ( @{ $form->{acc_trans}{lineitems} } ) {
+ $amount += $_->{amount};
+ $grossamount += $_->{grossamount};
+ $fxgrossamount += $_->{fxgrossamount};
+ }
+ $invnetamount = $amount;
+
+ $amount = 0;
+ for ( split / /, $form->{taxaccounts} ) {
+ $amount += $form->{acc_trans}{ $form->{id} }{$_}{amount} =
+ $form->round_amount( $form->{acc_trans}{ $form->{id} }{$_}{amount},
+ 2 );
+
+ $form->{acc_trans}{ $form->{id} }{$_}{amount} *= -1;
+ }
+ $invamount = $invnetamount + $amount;
+
+ $diff = 0;
+ if ( $form->{taxincluded} ) {
+ $diff = $form->round_amount( $grossamount - $invamount, 2 );
+ $invamount += $diff;
+ }
+ $fxdiff = $form->round_amount( $fxdiff, 2 );
+ $invnetamount += $fxdiff;
+ $invamount += $fxdiff;
+
+ if ( $form->round_amount( $form->{paid} - $fxgrossamount, 2 ) == 0 ) {
+ $form->{paid} = $invamount;
+ }
+ else {
+ $form->{paid} =
+ $form->round_amount( $form->{paid} * $form->{exchangerate}, 2 );
+ }
+
+ foreach $ref ( sort { $b->{amount} <=> $a->{amount} }
+ @{ $form->{acc_trans}{lineitems} } )
+ {
+
+ $amount = $ref->{amount} + $diff + $fxdiff;
+ $query = qq|
INSERT INTO acc_trans (trans_id, chart_id, amount,
transdate, project_id, invoice_id)
VALUES (?, ?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $ref->{chart_id}, $amount * -1,
- $form->{transdate}, $ref->{project_id},
- $ref->{invoice_id}) || $form->dberror($query);
- $diff = 0;
- $fxdiff = 0;
- }
-
- $form->{payables} = $invamount;
-
- delete $form->{acc_trans}{lineitems};
-
- # update exchangerate
- if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) {
- $form->update_exchangerate(
- $dbh, $form->{currency}, $form->{transdate}, 0,
- $form->{exchangerate});
- }
-
- # record payable
- if ($form->{payables}) {
- ($accno) = split /--/, $form->{AP};
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{id}, $ref->{chart_id}, $amount * -1,
+ $form->{transdate}, $ref->{project_id}, $ref->{invoice_id}
+ ) || $form->dberror($query);
+ $diff = 0;
+ $fxdiff = 0;
+ }
+
+ $form->{payables} = $invamount;
+
+ delete $form->{acc_trans}{lineitems};
+
+ # update exchangerate
+ if ( ( $form->{currency} ne $form->{defaultcurrency} ) && !$exchangerate ) {
+ $form->update_exchangerate( $dbh, $form->{currency}, $form->{transdate},
+ 0, $form->{exchangerate} );
+ }
+
+ # record payable
+ if ( $form->{payables} ) {
+ ($accno) = split /--/, $form->{AP};
+
+ $query = qq|
INSERT INTO acc_trans (trans_id, chart_id, amount,
transdate)
VALUES (?, (SELECT id FROM chart WHERE accno = ?),
?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $accno, $form->{payables},
- $form->{transdate}
- ) || $form->dberror($query);
- }
-
- foreach my $trans_id (keys %{$form->{acc_trans}}) {
- foreach my $accno (keys %{ $form->{acc_trans}{$trans_id} }) {
- $amount = $form->round_amount(
- $form->{acc_trans}{$trans_id}{$accno}{amount},
- 2);
-
- if ($amount) {
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $accno, $form->{payables},
+ $form->{transdate} )
+ || $form->dberror($query);
+ }
+
+ foreach my $trans_id ( keys %{ $form->{acc_trans} } ) {
+ foreach my $accno ( keys %{ $form->{acc_trans}{$trans_id} } ) {
+ $amount =
+ $form->round_amount(
+ $form->{acc_trans}{$trans_id}{$accno}{amount}, 2 );
+
+ if ($amount) {
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate)
VALUES (?, (SELECT id FROM chart
WHERE accno = ?),
?, ?)|;
- $sth =$dbh->prepare($query);
- $sth->execute(
- $trans_id, $accno, $amount,
- $form->{transdate}
- ) || $form->dberror($query);
- }
- }
- }
-
- # if there is no amount but a payment record payable
- if ($invamount == 0) {
- $form->{payables} = 1;
- }
-
- my $cleared = 0;
-
- # record payments and offsetting AP
- for my $i (1 .. $form->{paidaccounts}) {
-
- if ($form->{"paid_$i"}) {
- my ($accno) = split /--/, $form->{"AP_paid_$i"};
- $form->{"datepaid_$i"} = $form->{transdate}
- unless ($form->{"datepaid_$i"});
-
- $form->{datepaid} = $form->{"datepaid_$i"};
-
- $exchangerate = 0;
-
- if ($form->{currency} eq $form->{defaultcurrency}) {
- $form->{"exchangerate_$i"} = 1;
- } else {
- $exchangerate = $form->check_exchangerate(
- $myconfig, $form->{currency},
- $form->{"datepaid_$i"}, 'sell');
-
- $form->{"exchangerate_$i"} =
- ($exchangerate)
- ? $exchangerate
- : $form->parse_amount(
- $myconfig,
- $form->{"exchangerate_$i"});
- }
-
-
- # record AP
- $amount = ($form->round_amount(
- $form->{"paid_$i"} * $form->{exchangerate},
- 2)) * -1;
-
- if ($form->{payables}) {
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $trans_id, $accno, $amount, $form->{transdate} )
+ || $form->dberror($query);
+ }
+ }
+ }
+
+ # if there is no amount but a payment record payable
+ if ( $invamount == 0 ) {
+ $form->{payables} = 1;
+ }
+
+ my $cleared = 0;
+
+ # record payments and offsetting AP
+ for my $i ( 1 .. $form->{paidaccounts} ) {
+
+ if ( $form->{"paid_$i"} ) {
+ my ($accno) = split /--/, $form->{"AP_paid_$i"};
+ $form->{"datepaid_$i"} = $form->{transdate}
+ unless ( $form->{"datepaid_$i"} );
+
+ $form->{datepaid} = $form->{"datepaid_$i"};
+
+ $exchangerate = 0;
+
+ if ( $form->{currency} eq $form->{defaultcurrency} ) {
+ $form->{"exchangerate_$i"} = 1;
+ }
+ else {
+ $exchangerate =
+ $form->check_exchangerate( $myconfig, $form->{currency},
+ $form->{"datepaid_$i"}, 'sell' );
+
+ $form->{"exchangerate_$i"} =
+ ($exchangerate)
+ ? $exchangerate
+ : $form->parse_amount( $myconfig,
+ $form->{"exchangerate_$i"} );
+ }
+
+ # record AP
+ $amount = (
+ $form->round_amount(
+ $form->{"paid_$i"} * $form->{exchangerate}, 2
+ )
+ ) * -1;
+
+ if ( $form->{payables} ) {
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate)
@@ -593,19 +575,18 @@ sub post_invoice {
WHERE accno = ?),
?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $form->{AP}, $amount,
- $form->{"datepaid_$i"}
- ) || $form->dberror($query);
- }
-
- if ($keepcleared) {
- $cleared = ($form->{"cleared_$i"}) ? 1 : 0;
- }
-
- # record payment
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $form->{AP}, $amount,
+ $form->{"datepaid_$i"} )
+ || $form->dberror($query);
+ }
+
+ if ($keepcleared) {
+ $cleared = ( $form->{"cleared_$i"} ) ? 1 : 0;
+ }
+
+ # record payment
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate, source, memo, cleared)
@@ -613,22 +594,21 @@ sub post_invoice {
WHERE accno = ?),
?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $accno, $form->{"paid_$i"},
- $form->{"datepaid_$i"}, $form->{"source_$i"},
- $form->{"memo_$i"}, $cleared
- ) || $form->dberror($query);
-
- # exchangerate difference
- $amount = $form->round_amount(
- $form->{"paid_$i"}
- * $form->{"exchangerate_$i"}
- - $form->{"paid_$i"},
- 2);
-
- if ($amount) {
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $accno, $form->{"paid_$i"},
+ $form->{"datepaid_$i"},
+ $form->{"source_$i"}, $form->{"memo_$i"}, $cleared )
+ || $form->dberror($query);
+
+ # exchangerate difference
+ $amount = $form->round_amount(
+ $form->{"paid_$i"} * $form->{"exchangerate_$i"} -
+ $form->{"paid_$i"},
+ 2
+ );
+
+ if ($amount) {
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate, source,
@@ -636,65 +616,61 @@ sub post_invoice {
VALUES (?, (SELECT id FROM chart
WHERE accno = ?),
?, ?, ?, '1', ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $accno, $amount,
- $form->{"datepaid_$i"},
- $form->{"source_$i"}, $cleared
- ) || $form->dberror($query);
-
- }
-
- # gain/loss
- $amount = $form->round_amount(
- $form->round_amount(
- $form->{"paid_$i"}
- * $form->{exchangerate},2)
- - $form->round_amount(
- $form->{"paid_$i"}
- * $form->{"exchangerate_$i"},2)
- , 2);
-
- if ($amount) {
- my $accno_id =
- ($amount > 0)
- ? $fxgain_accno_id
- : $fxloss_accno_id;
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $accno, $amount,
+ $form->{"datepaid_$i"},
+ $form->{"source_$i"}, $cleared )
+ || $form->dberror($query);
+
+ }
+
+ # gain/loss
+ $amount = $form->round_amount(
+ $form->round_amount( $form->{"paid_$i"} * $form->{exchangerate},
+ 2 ) - $form->round_amount(
+ $form->{"paid_$i"} * $form->{"exchangerate_$i"}, 2
+ ),
+ 2
+ );
+
+ if ($amount) {
+ my $accno_id =
+ ( $amount > 0 )
+ ? $fxgain_accno_id
+ : $fxloss_accno_id;
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate, fx_transaction,
cleared)
VALUES (?, ?, ?, ?, '1', ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $accno_id, $amount,
- $form->{"datepaid_$i"}, $cleared
- ) || $form->dberror($query);
- }
-
- # update exchange rate
- if (($form->{currency} ne $form->{defaultcurrency})
- && !$exchangerate) {
-
- $form->update_exchangerate(
- $dbh, $form->{currency},
- $form->{"datepaid_$i"}, 0,
- $form->{"exchangerate_$i"});
- }
- }
- }
-
- # set values which could be empty
- $form->{taxincluded} *= 1;
-
- $form->{invnumber} =
- $form->update_defaults($myconfig, "vinumber", $dbh)
- unless $form->{invnumber};
-
- # save AP record
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $accno_id, $amount,
+ $form->{"datepaid_$i"}, $cleared )
+ || $form->dberror($query);
+ }
+
+ # update exchange rate
+ if ( ( $form->{currency} ne $form->{defaultcurrency} )
+ && !$exchangerate )
+ {
+
+ $form->update_exchangerate( $dbh, $form->{currency},
+ $form->{"datepaid_$i"},
+ 0, $form->{"exchangerate_$i"} );
+ }
+ }
+ }
+
+ # set values which could be empty
+ $form->{taxincluded} *= 1;
+
+ $form->{invnumber} = $form->update_defaults( $myconfig, "vinumber", $dbh )
+ unless $form->{invnumber};
+
+ # save AP record
+ $query = qq|
UPDATE ap
SET invnumber = ?,
ordnumber = ?,
@@ -719,86 +695,86 @@ sub post_invoice {
ponumber = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{invnumber}, $form->{ordnumber}, $form->{quonumber},
- $form->{transdate}, $form->{vendor_id}, $invamount,
- $invnetamount, $form->{paid}, $form->{datepaid},
- $form->{duedate}, $form->{shippingpoint}, $form->{shipvia},
- $form->{taxincluded}, $form->{notes}, $form->{intnotes},
- $form->{currency}, $form->{department_id}, $form->{employee_id},
- $form->{language_code}, $form->{ponumber}, $form->{id}
- ) || $form->dberror($query);
- # add shipto
- $form->{name} = $form->{vendor};
- $form->{name} =~ s/--$form->{vendor_id}//;
- $form->add_shipto($dbh, $form->{id});
-
- my %audittrail = (
- tablename => 'ap',
- reference => $form->{invnumber},
- formname => $form->{type},
- action => 'posted',
- id => $form->{id} );
-
- $form->audittrail($dbh, "", \%audittrail);
-
- my $rc = $dbh->commit;
-
- foreach $item (keys %updparts) {
- $item = $dbh->quote($item);
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{invnumber}, $form->{ordnumber}, $form->{quonumber},
+ $form->{transdate}, $form->{vendor_id}, $invamount,
+ $invnetamount, $form->{paid}, $form->{datepaid},
+ $form->{duedate}, $form->{shippingpoint}, $form->{shipvia},
+ $form->{taxincluded}, $form->{notes}, $form->{intnotes},
+ $form->{currency}, $form->{department_id}, $form->{employee_id},
+ $form->{language_code}, $form->{ponumber}, $form->{id}
+ ) || $form->dberror($query);
+
+ # add shipto
+ $form->{name} = $form->{vendor};
+ $form->{name} =~ s/--$form->{vendor_id}//;
+ $form->add_shipto( $dbh, $form->{id} );
+
+ my %audittrail = (
+ tablename => 'ap',
+ reference => $form->{invnumber},
+ formname => $form->{type},
+ action => 'posted',
+ id => $form->{id}
+ );
+
+ $form->audittrail( $dbh, "", \%audittrail );
+
+ my $rc = $dbh->commit;
+
+ foreach $item ( keys %updparts ) {
+ $item = $dbh->quote($item);
+ $query = qq|
UPDATE parts
SET avgcost = avgcost($item),
lastcost = lastcost($item)
WHERE id = $item|;
- $dbh->prepare($query) || $form->dberror($query);
- $dbh->commit;
- }
-
- $rc;
-
-}
+ $dbh->prepare($query) || $form->dberror($query);
+ $dbh->commit;
+ }
+ $rc;
+}
sub reverse_invoice {
- my ($dbh, $form) = @_;
-
- my $query = qq|SELECT id FROM ap
+ my ( $dbh, $form ) = @_;
+
+ my $query = qq|SELECT id FROM ap
WHERE id = $form->{id}|;
- my ($id) = $dbh->selectrow_array($query);
+ my ($id) = $dbh->selectrow_array($query);
- return unless $id;
-
- # reverse inventory items
- $query = qq|
+ return unless $id;
+
+ # reverse inventory items
+ $query = qq|
SELECT i.parts_id, p.inventory_accno_id, p.expense_accno_id,
i.qty, i.allocated, i.sellprice, i.project_id
FROM invoice i, parts p
WHERE i.parts_id = p.id
AND i.trans_id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- my $netamount = 0;
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $netamount += $form->round_amount($ref->{sellprice} * $ref->{qty} * -1, 2);
-
- if ($ref->{inventory_accno_id}) {
- # update onhand
- $form->update_balance($dbh,
- "parts",
- "onhand",
- qq|id = $ref->{parts_id}|,
- $ref->{qty});
-
- # if $ref->{allocated} > 0 than we sold that many items
- if ($ref->{allocated} > 0) {
-
- # get references for sold items
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ my $netamount = 0;
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $netamount +=
+ $form->round_amount( $ref->{sellprice} * $ref->{qty} * -1, 2 );
+
+ if ( $ref->{inventory_accno_id} ) {
+
+ # update onhand
+ $form->update_balance( $dbh, "parts", "onhand",
+ qq|id = $ref->{parts_id}|,
+ $ref->{qty} );
+
+ # if $ref->{allocated} > 0 than we sold that many items
+ if ( $ref->{allocated} > 0 ) {
+
+ # get references for sold items
+ $query = qq|
SELECT i.id, i.trans_id, i.allocated,
a.transdate
FROM invoice i, ar a
@@ -806,181 +782,169 @@ sub reverse_invoice {
AND i.allocated < 0
AND i.trans_id = a.id
ORDER BY transdate DESC|;
- my $sth = $dbh->prepare($query);
- $sth->execute($ref->{parts_id})
- || $form->dberror($query);
-
- while (my $pthref =
- $sth->fetchrow_hashref(NAME_lc)) {
-
- my $qty = $ref->{allocated};
-
- if (($ref->{allocated} +
- $pthref->{allocated})
- > 0) {
- $qty = $pthref->{allocated}
- * -1;
- }
-
- my $amount = $form->round_amount(
- $ref->{sellprice} * $qty, 2);
-
- #adjust allocated
- $form->update_balance(
- $dbh, "invoice", "allocated",
- qq|id = $pthref->{id}|, $qty);
-
- # add reversal for sale
- $ref->{project_id} *= 1;
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $ref->{parts_id} )
+ || $form->dberror($query);
+
+ while ( my $pthref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ my $qty = $ref->{allocated};
+
+ if ( ( $ref->{allocated} + $pthref->{allocated} ) > 0 ) {
+ $qty = $pthref->{allocated} * -1;
+ }
+
+ my $amount =
+ $form->round_amount( $ref->{sellprice} * $qty, 2 );
+
+ #adjust allocated
+ $form->update_balance( $dbh, "invoice", "allocated",
+ qq|id = $pthref->{id}|, $qty );
+
+ # add reversal for sale
+ $ref->{project_id} *= 1;
+ $query = qq|
INSERT INTO acc_trans
(trans_id,
chart_id, amount,
transdate,
project_id)
VALUES (?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $pthref->{trans_id},
- $ref->{expense_accno_id},
- $amount, $form->{transdate},
- $ref->{project_id}
- ) || $form->dberror($query);
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $pthref->{trans_id},
+ $ref->{expense_accno_id},
+ $amount, $form->{transdate}, $ref->{project_id} )
+ || $form->dberror($query);
+
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id,
amount, transdate,
project_id)
VALUES (?, ?, ?, ?, ?)|;
- $sth = $dbh->do($query);
- $sth->execute(
- $pthref->{trans_id},
- $ref->{inventory_accno_id},
- $amount * -1,
- $form->{transdate},
- $ref->{project_id}
- ) || $form->dberror($query);
- last if (($ref->{allocated} -= $qty)
- <= 0);
- }
- $sth->finish;
- }
- }
- }
- $sth->finish;
-
- # delete acc_trans
- $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
- $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- # delete invoice entries
- $query = qq|DELETE FROM invoice WHERE trans_id = ?|;
- $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $query = qq|DELETE FROM shipto WHERE trans_id = ?|;
- $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $dbh->commit;
-
-}
-
+ $sth = $dbh->do($query);
+ $sth->execute(
+ $pthref->{trans_id},
+ $ref->{inventory_accno_id},
+ $amount * -1,
+ $form->{transdate}, $ref->{project_id}
+ ) || $form->dberror($query);
+ last if ( ( $ref->{allocated} -= $qty ) <= 0 );
+ }
+ $sth->finish;
+ }
+ }
+ }
+ $sth->finish;
+
+ # delete acc_trans
+ $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
+ $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ # delete invoice entries
+ $query = qq|DELETE FROM invoice WHERE trans_id = ?|;
+ $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $query = qq|DELETE FROM shipto WHERE trans_id = ?|;
+ $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $dbh->commit;
+}
sub delete_invoice {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my %audittrail = (
- tablename => 'ap',
- reference => $form->{invnumber},
- formname => $form->{type},
- action => 'deleted',
- id => $form->{id} );
-
- $form->audittrail($dbh, "", \%audittrail);
-
- my $query = qq|SELECT parts_id FROM invoice WHERE trans_id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- my $item;
- my %updparts = ();
- while (($item) = $sth->fetchrow_array) {
- $updparts{$item} = 1;
- }
- $sth->finish;
-
- &reverse_invoice($dbh, $form);
-
- # delete AP record
- $query = qq|DELETE FROM ap WHERE id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- # delete spool files
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my %audittrail = (
+ tablename => 'ap',
+ reference => $form->{invnumber},
+ formname => $form->{type},
+ action => 'deleted',
+ id => $form->{id}
+ );
+
+ $form->audittrail( $dbh, "", \%audittrail );
+
+ my $query = qq|SELECT parts_id FROM invoice WHERE trans_id = ?|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ my $item;
+ my %updparts = ();
+ while ( ($item) = $sth->fetchrow_array ) {
+ $updparts{$item} = 1;
+ }
+ $sth->finish;
+
+ &reverse_invoice( $dbh, $form );
+
+ # delete AP record
+ $query = qq|DELETE FROM ap WHERE id = ?|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ # delete spool files
+ $query = qq|
SELECT spoolfile FROM status
WHERE trans_id = ?
AND spoolfile IS NOT NULL|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- my $spoolfile;
- my @spoolfiles = ();
-
- while (($spoolfile) = $sth->fetchrow_array) {
- push @spoolfiles, $spoolfile;
- }
- $sth->finish;
-
- # delete status entries
- $query = qq|DELETE FROM status WHERE trans_id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
-
- if ($rc) {
- foreach $item (keys %updparts) {
- $item = $dbh->quote($item);
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ my $spoolfile;
+ my @spoolfiles = ();
+
+ while ( ($spoolfile) = $sth->fetchrow_array ) {
+ push @spoolfiles, $spoolfile;
+ }
+ $sth->finish;
+
+ # delete status entries
+ $query = qq|DELETE FROM status WHERE trans_id = ?|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ if ($rc) {
+ foreach $item ( keys %updparts ) {
+ $item = $dbh->quote($item);
+ $query = qq|
UPDATE parts
SET avgcost = avgcost($item),
lastcost = lastcost($item)
WHERE id = $item|;
- $dbh->do($query) || $form->dberror($query);
- }
-
- foreach $spoolfile (@spoolfiles) {
- unlink "${LedgerSMB::Sysconfig::spool}/$spoolfile"
- if $spoolfile;
- }
- }
-
- my $rc = $dbh->commit;
-
- $rc;
-
-}
+ $dbh->do($query) || $form->dberror($query);
+ }
+ foreach $spoolfile (@spoolfiles) {
+ unlink "${LedgerSMB::Sysconfig::spool}/$spoolfile"
+ if $spoolfile;
+ }
+ }
+ my $rc = $dbh->commit;
+
+ $rc;
+
+}
sub retrieve_invoice {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
+ my ( $self, $myconfig, $form ) = @_;
- my $query;
+ # connect to database
+ my $dbh = $form->{dbh};
- if ($form->{id}) {
- # get default accounts and last invoice number
- $query = qq|
+ my $query;
+
+ if ( $form->{id} ) {
+
+ # get default accounts and last invoice number
+ $query = qq|
SELECT (select c.accno FROM chart c
WHERE c.id = (SELECT value FROM defaults
WHERE setting_key =
@@ -1012,8 +976,9 @@ sub retrieve_invoice {
AS fxloss_accno,
(SELECT value FROM defaults
WHERE setting_key = 'curr') AS currencies|;
- } else {
- $query = qq|
+ }
+ else {
+ $query = qq|
SELECT (select c.accno FROM chart c
WHERE c.id = (SELECT value FROM defaults
WHERE setting_key =
@@ -1046,48 +1011,47 @@ sub retrieve_invoice {
(SELECT value FROM defaults
WHERE setting_key = 'curr') AS currencies,
current_date AS transdate|;
- }
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ }
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- my $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) {
- $form->{$_} = $ref->{$_};
- }
- $sth->finish;
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) {
+ $form->{$_} = $ref->{$_};
+ }
+ $sth->finish;
+ if ( $form->{id} ) {
- if ($form->{id}) {
-
- $query = qq|
+ $query = qq|
SELECT a.invnumber, a.transdate, a.duedate,
a.ordnumber, a.quonumber, a.paid, a.taxincluded,
a.notes, a.intnotes, a.curr AS currency,
a.vendor_id, a.language_code, a.ponumber
FROM ap a
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) {
- $form->{$_} = $ref->{$_};
- }
- $sth->finish;
-
- # get shipto
- $query = qq|SELECT * FROM shipto WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) {
- $form->{$_} = $ref->{$_};
- }
- $sth->finish;
-
- # retrieve individual items
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) {
+ $form->{$_} = $ref->{$_};
+ }
+ $sth->finish;
+
+ # get shipto
+ $query = qq|SELECT * FROM shipto WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) {
+ $form->{$_} = $ref->{$_};
+ }
+ $sth->finish;
+
+ # retrieve individual items
+ $query = qq|
SELECT p.partnumber, i.description, i.qty,
i.fxsellprice, i.sellprice,
i.parts_id AS id, i.unit, p.bin,
@@ -1108,113 +1072,112 @@ sub retrieve_invoice {
AND t.language_code = ?)
WHERE i.trans_id = ?
ORDER BY i.id|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{language_code}, $form->{id})
- || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{language_code}, $form->{id} )
+ || $form->dberror($query);
- # exchangerate defaults
- &exchangerate_defaults($dbh, $form);
+ # exchangerate defaults
+ &exchangerate_defaults( $dbh, $form );
- # price matrix and vendor partnumber
- my $pmh = PriceMatrix::price_matrix_query($dbh, $form);
+ # price matrix and vendor partnumber
+ my $pmh = PriceMatrix::price_matrix_query( $dbh, $form );
- # tax rates for part
- $query = qq|
+ # tax rates for part
+ $query = qq|
SELECT c.accno
FROM chart c
JOIN partstax pt ON (pt.chart_id = c.id)
WHERE pt.parts_id = ?|;
- my $tth = $dbh->prepare($query);
-
- my $ptref;
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- my ($dec) = ($ref->{fxsellprice} =~ /\.(\d+)/);
- $dec = length $dec;
- my $decimalplaces = ($dec > 2) ? $dec : 2;
-
- $tth->execute($ref->{id});
- $ref->{taxaccounts} = "";
- my $taxrate = 0;
-
- while ($ptref = $tth->fetchrow_hashref(NAME_lc)) {
- $ref->{taxaccounts} .= "$ptref->{accno} ";
- $taxrate += $form->{"$ptref->{accno}_rate"};
- }
-
- $tth->finish;
- chop $ref->{taxaccounts};
-
- # price matrix
- $ref->{sellprice} = $form->round_amount(
- $ref->{fxsellprice}
- * $form->{$form->{currency}},
- $decimalplaces);
- PriceMatrix::price_matrix(
- $pmh, $ref, $decimalplaces, $form, $myconfig);
-
- $ref->{sellprice} = $ref->{fxsellprice};
- $ref->{qty} *= -1;
-
- $ref->{partsgroup} = $ref->{partsgrouptranslation}
- if $ref->{partsgrouptranslation};
-
- push @{ $form->{invoice_details} }, $ref;
-
- }
-
- $sth->finish;
-
- }
-
-
- my $rc = $dbh->commit;
-
- $rc;
-
-}
+ my $tth = $dbh->prepare($query);
+
+ my $ptref;
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ my ($dec) = ( $ref->{fxsellprice} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ $tth->execute( $ref->{id} );
+ $ref->{taxaccounts} = "";
+ my $taxrate = 0;
+
+ while ( $ptref = $tth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{taxaccounts} .= "$ptref->{accno} ";
+ $taxrate += $form->{"$ptref->{accno}_rate"};
+ }
+
+ $tth->finish;
+ chop $ref->{taxaccounts};
+
+ # price matrix
+ $ref->{sellprice} =
+ $form->round_amount(
+ $ref->{fxsellprice} * $form->{ $form->{currency} },
+ $decimalplaces );
+ PriceMatrix::price_matrix( $pmh, $ref, $decimalplaces, $form,
+ $myconfig );
+
+ $ref->{sellprice} = $ref->{fxsellprice};
+ $ref->{qty} *= -1;
+
+ $ref->{partsgroup} = $ref->{partsgrouptranslation}
+ if $ref->{partsgrouptranslation};
+
+ push @{ $form->{invoice_details} }, $ref;
+
+ }
+
+ $sth->finish;
+
+ }
+
+ my $rc = $dbh->commit;
+ $rc;
+
+}
sub retrieve_item {
- my ($self, $myconfig, $form) = @_;
-
- $dbh = $form->{dbh};
- my $i = $form->{rowcount};
- my $null;
- my $var;
-
- # don't include assemblies or obsolete parts
- my $where = "WHERE p.assembly = '0' AND p.obsolete = '0'";
-
- if ($form->{"partnumber_$i"} ne "") {
- $var = $dbh->quote($form->like(lc $form->{"partnumber_$i"}));
- $where .= " AND lower(p.partnumber) LIKE $var";
- }
-
- if ($form->{"description_$i"} ne "") {
- $var = $dbh->quote($form->like(lc $form->{"description_$i"}));
- if ($form->{language_code} ne "") {
- $where .= " AND lower(t1.description) LIKE $var";
- } else {
- $where .= " AND lower(p.description) LIKE $var";
- }
- }
-
- if ($form->{"partsgroup_$i"} ne "") {
- ($null, $var) = split /--/, $form->{"partsgroup_$i"};
- $var = $dbh->quote($var);
- $where .= qq| AND p.partsgroup_id = $var|;
- }
-
- if ($form->{"description_$i"} ne "") {
- $where .= " ORDER BY 3";
- } else {
- $where .= " ORDER BY 2";
- }
-
-
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ $dbh = $form->{dbh};
+ my $i = $form->{rowcount};
+ my $null;
+ my $var;
+
+ # don't include assemblies or obsolete parts
+ my $where = "WHERE p.assembly = '0' AND p.obsolete = '0'";
+
+ if ( $form->{"partnumber_$i"} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{"partnumber_$i"} ) );
+ $where .= " AND lower(p.partnumber) LIKE $var";
+ }
+
+ if ( $form->{"description_$i"} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{"description_$i"} ) );
+ if ( $form->{language_code} ne "" ) {
+ $where .= " AND lower(t1.description) LIKE $var";
+ }
+ else {
+ $where .= " AND lower(p.description) LIKE $var";
+ }
+ }
+
+ if ( $form->{"partsgroup_$i"} ne "" ) {
+ ( $null, $var ) = split /--/, $form->{"partsgroup_$i"};
+ $var = $dbh->quote($var);
+ $where .= qq| AND p.partsgroup_id = $var|;
+ }
+
+ if ( $form->{"description_$i"} ne "" ) {
+ $where .= " ORDER BY 3";
+ }
+ else {
+ $where .= " ORDER BY 2";
+ }
+
+ my $query = qq|
SELECT p.id, p.partnumber, p.description,
pg.partsgroup, p.partsgroup_id,
p.lastcost AS sellprice, p.unit, p.bin, p.onhand,
@@ -1230,120 +1193,118 @@ sub retrieve_item {
ON (t2.trans_id = p.partsgroup_id
AND t2.language_code = ?)
$where|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{language_code}, $form->{language_code})
- || $form->dberror($query);
-
- # foreign currency
- &exchangerate_defaults($dbh, $form);
-
- # taxes
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{language_code}, $form->{language_code} )
+ || $form->dberror($query);
+
+ # foreign currency
+ &exchangerate_defaults( $dbh, $form );
+
+ # taxes
+ $query = qq|
SELECT c.accno
FROM chart c
JOIN partstax pt ON (pt.chart_id = c.id)
WHERE pt.parts_id = ?|;
- my $tth = $dbh->prepare($query) || $form->dberror($query);
-
- # price matrix
- my $pmh = PriceMatrix::price_matrix_query($dbh, $form);
-
- my $ref;
- my $ptref;
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- my ($dec) = ($ref->{sellprice} =~ /\.(\d+)/);
- $dec = length $dec;
- my $decimalplaces = ($dec > 2) ? $dec : 2;
-
- # get taxes for part
- $tth->execute($ref->{id});
-
- $ref->{taxaccounts} = "";
- while ($ptref = $tth->fetchrow_hashref(NAME_lc)) {
- $ref->{taxaccounts} .= "$ptref->{accno} ";
- }
- $tth->finish;
- chop $ref->{taxaccounts};
-
- # get vendor price and partnumber
- PriceMatrix::price_matrix(
- $pmh, $ref, $decimalplaces, $form, $myconfig);
-
- $ref->{description} = $ref->{translation}
- if $ref->{translation};
- $ref->{partsgroup} = $ref->{grouptranslation}
- if $ref->{grouptranslation};
-
- push @{ $form->{item_list} }, $ref;
-
- }
-
- $sth->finish;
- $dbh->commit;
-
-}
+ my $tth = $dbh->prepare($query) || $form->dberror($query);
+
+ # price matrix
+ my $pmh = PriceMatrix::price_matrix_query( $dbh, $form );
+
+ my $ref;
+ my $ptref;
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ my ($dec) = ( $ref->{sellprice} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ # get taxes for part
+ $tth->execute( $ref->{id} );
+
+ $ref->{taxaccounts} = "";
+ while ( $ptref = $tth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{taxaccounts} .= "$ptref->{accno} ";
+ }
+ $tth->finish;
+ chop $ref->{taxaccounts};
+ # get vendor price and partnumber
+ PriceMatrix::price_matrix( $pmh, $ref, $decimalplaces, $form,
+ $myconfig );
+
+ $ref->{description} = $ref->{translation}
+ if $ref->{translation};
+ $ref->{partsgroup} = $ref->{grouptranslation}
+ if $ref->{grouptranslation};
+
+ push @{ $form->{item_list} }, $ref;
+
+ }
+
+ $sth->finish;
+ $dbh->commit;
+
+}
sub exchangerate_defaults {
- my ($dbh, $form) = @_;
+ my ( $dbh, $form ) = @_;
- my $var;
-
- # get default currencies
- my $query = qq|
+ my $var;
+
+ # get default currencies
+ my $query = qq|
SELECT substr(value,1,3), value FROM defaults
WHERE setting_key = 'curr'|;
- my $eth = $dbh->prepare($query) || $form->dberror($query);
- $eth->execute;
- ($form->{defaultcurrency}, $form->{currencies}) = $eth->fetchrow_array;
- $eth->finish;
+ my $eth = $dbh->prepare($query) || $form->dberror($query);
+ $eth->execute;
+ ( $form->{defaultcurrency}, $form->{currencies} ) = $eth->fetchrow_array;
+ $eth->finish;
- $query = qq|
+ $query = qq|
SELECT sell
FROM exchangerate
WHERE curr = ?
AND transdate = ?|;
- my $eth1 = $dbh->prepare($query) || $form->dberror($query);
+ my $eth1 = $dbh->prepare($query) || $form->dberror($query);
- $query = qq/
+ $query = qq/
SELECT max(transdate || ' ' || sell || ' ' || curr)
FROM exchangerate
WHERE curr = ?/;
- my $eth2 = $dbh->prepare($query) || $form->dberror($query);
-
- # get exchange rates for transdate or max
- foreach $var (split /:/, substr($form->{currencies},4)) {
- $eth1->execute($var, $form->{transdate});
- ($form->{$var}) = $eth1->fetchrow_array;
- if (! $form->{$var} ) {
- $eth2->execute($var);
-
- ($form->{$var}) = $eth2->fetchrow_array;
- ($null, $form->{$var}) = split / /, $form->{$var};
- $form->{$var} = 1 unless $form->{$var};
- $eth2->finish;
- }
- $eth1->finish;
- }
-
- $form->{$form->{currency}} = $form->{exchangerate}
- if $form->{exchangerate};
- $form->{$form->{currency}} ||= 1;
- $form->{$form->{defaultcurrency}} = 1;
-
-}
+ my $eth2 = $dbh->prepare($query) || $form->dberror($query);
+
+ # get exchange rates for transdate or max
+ foreach $var ( split /:/, substr( $form->{currencies}, 4 ) ) {
+ $eth1->execute( $var, $form->{transdate} );
+ ( $form->{$var} ) = $eth1->fetchrow_array;
+ if ( !$form->{$var} ) {
+ $eth2->execute($var);
+
+ ( $form->{$var} ) = $eth2->fetchrow_array;
+ ( $null, $form->{$var} ) = split / /, $form->{$var};
+ $form->{$var} = 1 unless $form->{$var};
+ $eth2->finish;
+ }
+ $eth1->finish;
+ }
+
+ $form->{ $form->{currency} } = $form->{exchangerate}
+ if $form->{exchangerate};
+ $form->{ $form->{currency} } ||= 1;
+ $form->{ $form->{defaultcurrency} } = 1;
+}
sub vendor_details {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
+ my ( $self, $myconfig, $form ) = @_;
- # get rest for the vendor
- my $query = qq|
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ # get rest for the vendor
+ my $query = qq|
SELECT vendornumber, name, address1, address2, city, state,
zipcode, country, contact, phone as vendorphone,
fax as vendorfax, vendornumber,
@@ -1351,45 +1312,46 @@ sub vendor_details {
gifi_accno AS gifi, startdate, enddate
FROM vendor
WHERE id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{vendor_id}) || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{vendor_id} ) || $form->dberror($query);
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) {
- $form->{$_} = $ref->{$_};
- }
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) {
+ $form->{$_} = $ref->{$_};
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub item_links {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my $query = qq|
+ my $query = qq|
SELECT accno, description, link
FROM chart
WHERE link LIKE '%IC%'
ORDER BY accno|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- foreach my $key (split(/:/, $ref->{link})) {
- if ($key =~ /IC/) {
- push @{ $form->{IC_links}{$key} },
- { accno => $ref->{accno},
- description => $ref->{description} };
- }
- }
- }
-
- $sth->finish;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ foreach my $key ( split( /:/, $ref->{link} ) ) {
+ if ( $key =~ /IC/ ) {
+ push @{ $form->{IC_links}{$key} },
+ {
+ accno => $ref->{accno},
+ description => $ref->{description}
+ };
+ }
+ }
+ }
+
+ $sth->finish;
}
1;
diff --git a/LedgerSMB/IS.pm b/LedgerSMB/IS.pm
index 86aea81b..be4cbcb1 100644
--- a/LedgerSMB/IS.pm
+++ b/LedgerSMB/IS.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -36,625 +36,626 @@ use LedgerSMB::Tax;
use LedgerSMB::PriceMatrix;
use LedgerSMB::Sysconfig;
-
sub invoice_details {
- use LedgerSMB::CP;
- my ($self, $myconfig, $form) = @_;
+ use LedgerSMB::CP;
+ my ( $self, $myconfig, $form ) = @_;
- $form->{duedate} = $form->{transdate} unless ($form->{duedate});
+ $form->{duedate} = $form->{transdate} unless ( $form->{duedate} );
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my $query = qq|
+ my $query = qq|
SELECT ?::date - ?::date
AS terms, value
FROM defaults
WHERE setting_key = 'weightunit'|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{duedate}, $form->{transdate})
- || $form->dberror($query);
-
- ($form->{terms}, $form->{weightunit}) = $sth->fetchrow_array;
- $sth->finish;
-
- # this is for the template
- $form->{invdate} = $form->{transdate};
-
- my $tax = 0;
- my $item;
- my $i;
- my @sortlist = ();
- my $projectnumber;
- my $projectdescription;
- my $projectnumber_id;
- my $translation;
- my $partsgroup;
-
-
- my @taxaccounts;
- my %taxaccounts;
- my $tax;
- my $taxrate;
- my $taxamount;
-
- my %translations;
-
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{duedate}, $form->{transdate} )
+ || $form->dberror($query);
+
+ ( $form->{terms}, $form->{weightunit} ) = $sth->fetchrow_array;
+ $sth->finish;
+
+ # this is for the template
+ $form->{invdate} = $form->{transdate};
+
+ my $tax = 0;
+ my $item;
+ my $i;
+ my @sortlist = ();
+ my $projectnumber;
+ my $projectdescription;
+ my $projectnumber_id;
+ my $translation;
+ my $partsgroup;
+
+ my @taxaccounts;
+ my %taxaccounts;
+ my $tax;
+ my $taxrate;
+ my $taxamount;
+
+ my %translations;
+
+ $query = qq|
SELECT p.description, t.description
FROM project p
LEFT JOIN translation t
ON (t.trans_id = p.id
AND t.language_code = ?)
WHERE id = ?|;
- my $prh = $dbh->prepare($query) || $form->dberror($query);
+ my $prh = $dbh->prepare($query) || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT inventory_accno_id, income_accno_id,
expense_accno_id, assembly, weight FROM parts
WHERE id = ?|;
- my $pth = $dbh->prepare($query) || $form->dberror($query);
-
- my $sortby;
-
- # sort items by project and partsgroup
- for $i (1 .. $form->{rowcount} - 1) {
-
- # account numbers
- $pth->execute($form->{"id_$i"});
- $ref = $pth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
- $pth->finish;
-
- $projectnumber_id = 0;
- $projectnumber = "";
- $form->{partsgroup} = "";
- $form->{projectnumber} = "";
-
- if ($form->{groupprojectnumber} || $form->{grouppartsgroup}) {
-
- $inventory_accno_id =
- ($form->{"inventory_accno_id_$i"}
- || $form->{"assembly_$i"})
- ? "1"
- : "";
-
- if ($form->{groupprojectnumber}) {
- ($projectnumber, $projectnumber_id) =
- split /--/, $form->{"projectnumber_$i"};
- }
- if ($form->{grouppartsgroup}) {
- ($form->{partsgroup}) =
- split /--/, $form->{"partsgroup_$i"};
- }
-
- if ($projectnumber_id && $form->{groupprojectnumber}) {
- if ($translation{$projectnumber_id}) {
- $form->{projectnumber} =
- $translation{$projectnumber_id};
- } else {
- # get project description
- $prh->execute($projectnumber_id,
- $form->{language_code});
-
- ($projectdescription, $translation) =
- $prh->fetchrow_array;
-
- $prh->finish;
-
- $form->{projectnumber} =
- ($translation)
- ? "$projectnumber, $translation"
- : "$projectnumber, ".
- "$projectdescription";
-
- $translation{$projectnumber_id} =
- $form->{projectnumber};
- }
- }
-
- if ($form->{grouppartsgroup} && $form->{partsgroup}) {
- $form->{projectnumber} .= " / "
- if $projectnumber_id;
- $form->{projectnumber} .= $form->{partsgroup};
- }
-
- $form->format_string(projectnumber);
-
- }
-
- $sortby = qq|$projectnumber$form->{partsgroup}|;
- if ($form->{sortby} ne 'runningnumber') {
- for (qw(partnumber description bin)) {
- $sortby .= $form->{"${_}_$i"}
- if $form->{sortby} eq $_;
- }
- }
-
- push @sortlist, [ $i,
- qq|$projectnumber$form->{partsgroup}|.
- qq|$inventory_accno_id|,
- $form->{projectnumber}, $projectnumber_id,
- $form->{partsgroup}, $sortby ];
-
- }
-
- # sort the whole thing by project and group
- @sortlist = sort { $a->[5] cmp $b->[5] } @sortlist;
-
- my $runningnumber = 1;
- my $sameitem = "";
- my $subtotal;
- my $k = scalar @sortlist;
- my $j = 0;
-
- foreach $item (@sortlist) {
-
- $i = $item->[0];
- $j++;
-
- # heading
- if ($form->{groupprojectnumber} || $form->{grouppartsgroup}) {
- if ($item->[1] ne $sameitem) {
- $sameitem = $item->[1];
-
- $ok = 0;
-
- if ($form->{groupprojectnumber}) {
- $ok = $form->{"projectnumber_$i"};
- }
- if ($form->{grouppartsgroup}) {
- $ok = $form->{"partsgroup_$i"}
- unless $ok;
- }
-
- if ($ok) {
-
- if ($form->{"inventory_accno_id_$i"}
- || $form->{"assembly_$i"}) {
-
- push(@{ $form->{part} }, "");
- push(@{ $form->{service} },
- NULL);
- } else {
- push(@{ $form->{part} }, NULL);
- push(@{ $form->{service} }, "");
- }
-
- push(@{ $form->{description} },
- $item->[2]);
- for (
- qw(taxrates runningnumber number
- sku serialnumber bin qty ship
- unit deliverydate projectnumber
- sellprice listprice netprice
- discount discountrate linetotal
- weight itemnotes)
- ) {
- push(@{ $form->{$_} }, "");
- }
- push(@{ $form->{lineitems} },
- { amount => 0, tax => 0 });
- }
- }
- }
-
- $form->{"qty_$i"} =
- $form->parse_amount($myconfig, $form->{"qty_$i"});
-
- if ($form->{"qty_$i"}) {
-
- $form->{totalqty} += $form->{"qty_$i"};
- $form->{totalship} += $form->{"qty_$i"};
- $form->{totalweight} += ($form->{"qty_$i"}
- * $form->{"weight_$i"});
-
- $form->{totalweightship} += ($form->{"qty_$i"}
- * $form->{"weight_$i"});
-
- # add number, description and qty to $form->{number}...
- push(@{ $form->{runningnumber} }, $runningnumber++);
- push(@{ $form->{number} }, $form->{"partnumber_$i"});
- push(@{ $form->{sku} }, $form->{"sku_$i"});
- push(@{ $form->{serialnumber} },
- $form->{"serialnumber_$i"});
-
- push(@{ $form->{bin} }, $form->{"bin_$i"});
- push(@{ $form->{description} },
- $form->{"description_$i"});
- push(@{ $form->{itemnotes} }, $form->{"notes_$i"});
- push(@{ $form->{qty} },
- $form->format_amount(
- $myconfig, $form->{"qty_$i"}));
-
- push(@{ $form->{ship} },
- $form->format_amount(
- $myconfig, $form->{"qty_$i"}));
-
- push(@{ $form->{unit} }, $form->{"unit_$i"});
- push(@{ $form->{deliverydate} },
- $form->{"deliverydate_$i"});
-
- push(@{ $form->{projectnumber} },
- $form->{"projectnumber_$i"});
-
- push(@{ $form->{sellprice} }, $form->{"sellprice_$i"});
-
- push(@{ $form->{listprice} }, $form->{"listprice_$i"});
-
- push(@{ $form->{weight} },
- $form->format_amount(
- $myconfig,
- $form->{"weight_$i"}
- * $form->{"qty_$i"}));
-
- my $sellprice =
- $form->parse_amount(
- $myconfig, $form->{"sellprice_$i"});
-
- my ($dec) = ($sellprice =~ /\.(\d+)/);
- $dec = length $dec;
- my $decimalplaces = ($dec > 2) ? $dec : 2;
-
- my $discount =
- $form->round_amount(
- $sellprice
- * $form->parse_amount(
- $myconfig,
- $form->{"discount_$i"})
- /100,
- $decimalplaces);
-
- # keep a netprice as well, (sellprice - discount)
- $form->{"netprice_$i"} = $sellprice - $discount;
-
- my $linetotal = $form->round_amount(
- $form->{"qty_$i"} * $form->{"netprice_$i"}, 2);
-
- if ($form->{"inventory_accno_id_$i"}
- || $form->{"assembly_$i"}) {
-
- push(@{ $form->{part} }, $form->{"sku_$i"});
- push(@{ $form->{service} }, NULL);
- $form->{totalparts} += $linetotal;
- } else {
- push(@{ $form->{service} }, $form->{"sku_$i"});
- push(@{ $form->{part} }, NULL);
- $form->{totalservices} += $linetotal;
- }
-
- push(@{ $form->{netprice} },
- ($form->{"netprice_$i"})
- ? $form->format_amount(
- $myconfig, $form->{"netprice_$i"},
- $decimalplaces)
- : " ");
-
- $discount =
- ($discount)
- ? $form->format_amount(
- $myconfig, $discount * -1,
- $decimalplaces)
- : " ";
- $linetotal = ($linetotal) ? $linetotal : " ";
-
- push(@{ $form->{discount} }, $discount);
- push(@{ $form->{discountrate} },
- $form->format_amount(
- $myconfig, $form->{"discount_$i"}));
-
- $form->{total} += $linetotal;
-
- # this is for the subtotals for grouping
- $subtotal += $linetotal;
-
- $form->{"linetotal_$i"} =
- $form->format_amount($myconfig, $linetotal, 2);
-
- push(@{ $form->{linetotal} }, $form->{"linetotal_$i"});
-
- @taxaccounts = Tax::init_taxes(
- $form, $form->{"taxaccounts_$i"});
-
- my $ml = 1;
- my @taxrates = ();
-
- $tax = 0;
-
- if ($form->{taxincluded}) {
- $taxamount = Tax::calculate_taxes(
- \@taxaccounts, $form, $linetotal, 1);
- $taxbase = ($linetotal - $taxamount);
- $tax += Tax::extract_taxes(
- \@taxaccounts, $form, $linetotal);
- } else {
- $taxamount = Tax::calculate_taxes(
- \@taxaccounts, $form, $linetotal, 0);
- $tax += Tax::apply_taxes(
- \@taxaccounts, $form, $linetotal);
- }
-
- foreach $item (@taxaccounts) {
- push @taxrates, 100 * $item->rate;
- $taxaccounts{$item->account} += $item->value;
- if ($form->{taxincluded}) {
- $taxbase{$item->account} += $taxbase;
- } else {
- $taxbase{$item->account} += $linetotal;
- }
- }
-
- push(@{ $form->{lineitems} },
- { amount => $linetotal,
- tax => $form->round_amount($tax, 2) });
-
- push(@{ $form->{taxrates} },
- join' ', sort { $a <=> $b } @taxrates);
-
- if ($form->{"assembly_$i"}) {
- $form->{stagger} = -1;
- &assembly_details(
- $myconfig, $form, $dbh,
- $form->{"id_$i"},
- $oid{$myconfig->{dbdriver}},
- $form->{"qty_$i"});
- }
-
- }
-
- # add subtotal
- if ($form->{groupprojectnumber} || $form->{grouppartsgroup}) {
- if ($subtotal) {
- if ($j < $k) {
- # look at next item
- if ($sortlist[$j]->[1] ne $sameitem) {
-
- if ($form->{"inventory_accno_id_$j"} || $form->{"assembly_$i"}) {
-
-
- push(@{ $form->{part} },
- "");
- push(@{$form->{service}},
- NULL);
- } else {
- push(@{$form->{service}},
- "");
-
- push(@{ $form->{part} },
- NULL);
- }
-
- for (
- qw(taxrates
- runningnumber number sku
- serialnumber bin qty
- ship unit deliverydate
- projectnumber sellprice
- listprice netprice
- discount discountrate
- weight itemnotes)
- ) {
-
- push(@{ $form->{$_} },
- "")
- }
-
- push(@{ $form->{description} },
- $form->{groupsubtotaldescription});
-
- push(@{ $form->{lineitems} },
- { amount => 0,
- tax => 0 });
-
-
- if ($form->{groupsubtotaldescription} ne "") {
-
- push(@{ $form->{linetotal} },
- $form->format_amount(
- $myconfig,
- $subtotal,
- 2));
- } else {
- push(@{$form->{linetotal}},
- "");
- }
- $subtotal = 0;
- }
-
- } else {
-
- # got last item
- if ($form->{groupsubtotaldescription}
- ne "") {
-
- if ($form->{"inventory_accno_id_$j"} || $form->{"assembly_$i"}) {
-
- push(@{ $form->{part} },
- "");
-
- push(@{$form->{service}},
- NULL);
- } else {
- push(@{$form->{service}},
- "");
-
- push(@{ $form->{part} },
- NULL);
- }
-
- for (
- qw(taxrates
- runningnumber number sku
- serialnumber bin qty
- ship unit deliverydate
- projectnumber sellprice
- listprice netprice
- discount discountrate
- weight itemnotes)
- ) {
-
- push(@{ $form->{$_} },
- "");
- }
-
- push(@{ $form->{description} },
- $form->{groupsubtotaldescription});
-
- push(@{ $form->{linetotal} },
- $form->format_amount(
- $myconfig,
- $subtotal,
- 2));
- push(@{ $form->{lineitems} },
- { amount => 0,
- tax => 0 });
- }
- }
- }
- }
- }
-
-
- $tax = 0;
- foreach my $item (sort keys %taxaccounts) {
- if ($form->round_amount($taxaccounts{$item}, 2)) {
- $tax += $taxamount =
- $form->round_amount($taxaccounts{$item}, 2);
-
- push(@{ $form->{taxbaseinclusive} },
- $form->{"${item}_taxbaseinclusive"}
- = $form->format_amount(
- $myconfig,
- $taxbase{$item} + $tax, 2));
-
- push(@{ $form->{taxbase} },
- $form->{"${item}_taxbase"}
- = $form->format_amount(
- $myconfig, $taxbase{$item}, 2));
-
- push(@{ $form->{tax} },
- $form->{"${item}_tax"}
- = $form->format_amount(
- $myconfig, $taxamount, 2));
-
- push(@{ $form->{taxdescription} },
- $form->{"${item}_description"});
-
- $form->{"${item}_taxrate"}
- = $form->format_amount(
- $myconfig,
- $form->{"${item}_rate"} * 100);
- push(@{ $form->{taxrate} }, $form->{"${item}_taxrate"});
- push(@{ $form->{taxnumber} },
- $form->{"${item}_taxnumber"});
- }
- }
-
- # adjust taxes for lineitems
- my $total = 0;
- for (@{ $form->{lineitems} }) {
- $total += $_->{tax};
- }
- if ($form->round_amount($total,2) != $form->round_amount($tax,2)) {
- # get largest amount
- for (reverse sort { $a->{tax} <=> $b->{tax} }
- @{ $form->{lineitems} }) {
-
- $_->{tax} -= $total - $tax;
- last;
- }
- }
- $i = 1;
- for (@{ $form->{lineitems} }) {
- push(@{ $form->{linetax} },
- $form->format_amount($myconfig, $_->{tax}, 2, ""));
- }
-
-
- for $i (1 .. $form->{paidaccounts}) {
- if ($form->{"paid_$i"}) {
- push(@{ $form->{payment} }, $form->{"paid_$i"});
- my ($accno, $description)
- = split /--/, $form->{"AR_paid_$i"};
-
- push(@{ $form->{paymentaccount} }, $description);
- push(@{ $form->{paymentdate} }, $form->{"datepaid_$i"});
- push(@{ $form->{paymentsource} }, $form->{"source_$i"});
- push(@{ $form->{paymentmemo} }, $form->{"memo_$i"});
-
- $form->{paid}
- += $form->parse_amount(
- $myconfig, $form->{"paid_$i"});
- }
- }
-
- for (qw(totalparts totalservices)) {
- $form->{$_} = $form->format_amount($myconfig, $form->{$_}, 2);
- }
- for (qw(totalqty totalship totalweight)) {
- $form->{$_} = $form->format_amount($myconfig, $form->{$_});
- }
- $form->{subtotal} = $form->format_amount($myconfig, $form->{total}, 2);
- $form->{invtotal} =
- ($form->{taxincluded}) ? $form->{total} : $form->{total} + $tax;
-
- my $c;
- if ($form->{language_code} ne "") {
- $c = new CP $form->{language_code};
- } else {
- $c = new CP $myconfig->{countrycode};
- }
- $c->init;
- my $whole;
- ($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);
-
- $form->format_string(qw(text_amount text_decimal));
-
- $form->{total}
- = $form->format_amount(
- $myconfig, $form->{invtotal} - $form->{paid}, 2);
-
- $form->{invtotal}
- = $form->format_amount($myconfig, $form->{invtotal}, 2);
-
- $form->{paid} = $form->format_amount($myconfig, $form->{paid}, 2);
-
- $dbh->commit;
-
-}
+ my $pth = $dbh->prepare($query) || $form->dberror($query);
+
+ my $sortby;
+
+ # sort items by project and partsgroup
+ for $i ( 1 .. $form->{rowcount} - 1 ) {
+
+ # account numbers
+ $pth->execute( $form->{"id_$i"} );
+ $ref = $pth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
+ $pth->finish;
+
+ $projectnumber_id = 0;
+ $projectnumber = "";
+ $form->{partsgroup} = "";
+ $form->{projectnumber} = "";
+
+ if ( $form->{groupprojectnumber} || $form->{grouppartsgroup} ) {
+
+ $inventory_accno_id =
+ ( $form->{"inventory_accno_id_$i"} || $form->{"assembly_$i"} )
+ ? "1"
+ : "";
+
+ if ( $form->{groupprojectnumber} ) {
+ ( $projectnumber, $projectnumber_id ) =
+ split /--/, $form->{"projectnumber_$i"};
+ }
+ if ( $form->{grouppartsgroup} ) {
+ ( $form->{partsgroup} ) =
+ split /--/, $form->{"partsgroup_$i"};
+ }
+
+ if ( $projectnumber_id && $form->{groupprojectnumber} ) {
+ if ( $translation{$projectnumber_id} ) {
+ $form->{projectnumber} = $translation{$projectnumber_id};
+ }
+ else {
+
+ # get project description
+ $prh->execute( $projectnumber_id, $form->{language_code} );
+
+ ( $projectdescription, $translation ) =
+ $prh->fetchrow_array;
+
+ $prh->finish;
+
+ $form->{projectnumber} =
+ ($translation)
+ ? "$projectnumber, $translation"
+ : "$projectnumber, " . "$projectdescription";
+
+ $translation{$projectnumber_id} = $form->{projectnumber};
+ }
+ }
+
+ if ( $form->{grouppartsgroup} && $form->{partsgroup} ) {
+ $form->{projectnumber} .= " / "
+ if $projectnumber_id;
+ $form->{projectnumber} .= $form->{partsgroup};
+ }
+
+ $form->format_string(projectnumber);
+
+ }
+
+ $sortby = qq|$projectnumber$form->{partsgroup}|;
+ if ( $form->{sortby} ne 'runningnumber' ) {
+ for (qw(partnumber description bin)) {
+ $sortby .= $form->{"${_}_$i"}
+ if $form->{sortby} eq $_;
+ }
+ }
+
+ push @sortlist,
+ [
+ $i,
+ qq|$projectnumber$form->{partsgroup}| . qq|$inventory_accno_id|,
+ $form->{projectnumber},
+ $projectnumber_id,
+ $form->{partsgroup},
+ $sortby
+ ];
+
+ }
+
+ # sort the whole thing by project and group
+ @sortlist = sort { $a->[5] cmp $b->[5] } @sortlist;
+
+ my $runningnumber = 1;
+ my $sameitem = "";
+ my $subtotal;
+ my $k = scalar @sortlist;
+ my $j = 0;
+
+ foreach $item (@sortlist) {
+
+ $i = $item->[0];
+ $j++;
+
+ # heading
+ if ( $form->{groupprojectnumber} || $form->{grouppartsgroup} ) {
+ if ( $item->[1] ne $sameitem ) {
+ $sameitem = $item->[1];
+
+ $ok = 0;
+
+ if ( $form->{groupprojectnumber} ) {
+ $ok = $form->{"projectnumber_$i"};
+ }
+ if ( $form->{grouppartsgroup} ) {
+ $ok = $form->{"partsgroup_$i"}
+ unless $ok;
+ }
+
+ if ($ok) {
+
+ if ( $form->{"inventory_accno_id_$i"}
+ || $form->{"assembly_$i"} )
+ {
+
+ push( @{ $form->{part} }, "" );
+ push( @{ $form->{service} }, NULL );
+ }
+ else {
+ push( @{ $form->{part} }, NULL );
+ push( @{ $form->{service} }, "" );
+ }
+
+ push( @{ $form->{description} }, $item->[2] );
+ for (
+ qw(taxrates runningnumber number
+ sku serialnumber bin qty ship
+ unit deliverydate projectnumber
+ sellprice listprice netprice
+ discount discountrate linetotal
+ weight itemnotes)
+ )
+ {
+ push( @{ $form->{$_} }, "" );
+ }
+ push( @{ $form->{lineitems} }, { amount => 0, tax => 0 } );
+ }
+ }
+ }
+
+ $form->{"qty_$i"} = $form->parse_amount( $myconfig, $form->{"qty_$i"} );
+
+ if ( $form->{"qty_$i"} ) {
+
+ $form->{totalqty} += $form->{"qty_$i"};
+ $form->{totalship} += $form->{"qty_$i"};
+ $form->{totalweight} +=
+ ( $form->{"qty_$i"} * $form->{"weight_$i"} );
+
+ $form->{totalweightship} +=
+ ( $form->{"qty_$i"} * $form->{"weight_$i"} );
+
+ # add number, description and qty to $form->{number}...
+ push( @{ $form->{runningnumber} }, $runningnumber++ );
+ push( @{ $form->{number} }, $form->{"partnumber_$i"} );
+ push( @{ $form->{sku} }, $form->{"sku_$i"} );
+ push( @{ $form->{serialnumber} }, $form->{"serialnumber_$i"} );
+
+ push( @{ $form->{bin} }, $form->{"bin_$i"} );
+ push( @{ $form->{description} }, $form->{"description_$i"} );
+ push( @{ $form->{itemnotes} }, $form->{"notes_$i"} );
+ push(
+ @{ $form->{qty} },
+ $form->format_amount( $myconfig, $form->{"qty_$i"} )
+ );
+
+ push(
+ @{ $form->{ship} },
+ $form->format_amount( $myconfig, $form->{"qty_$i"} )
+ );
+
+ push( @{ $form->{unit} }, $form->{"unit_$i"} );
+ push( @{ $form->{deliverydate} }, $form->{"deliverydate_$i"} );
+
+ push( @{ $form->{projectnumber} }, $form->{"projectnumber_$i"} );
+
+ push( @{ $form->{sellprice} }, $form->{"sellprice_$i"} );
+
+ push( @{ $form->{listprice} }, $form->{"listprice_$i"} );
+
+ push(
+ @{ $form->{weight} },
+ $form->format_amount(
+ $myconfig, $form->{"weight_$i"} * $form->{"qty_$i"}
+ )
+ );
+
+ my $sellprice =
+ $form->parse_amount( $myconfig, $form->{"sellprice_$i"} );
+
+ my ($dec) = ( $sellprice =~ /\.(\d+)/ );
+ $dec = length $dec;
+ my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ my $discount = $form->round_amount(
+ $sellprice *
+ $form->parse_amount( $myconfig, $form->{"discount_$i"} ) /
+ 100,
+ $decimalplaces
+ );
+
+ # keep a netprice as well, (sellprice - discount)
+ $form->{"netprice_$i"} = $sellprice - $discount;
+
+ my $linetotal =
+ $form->round_amount( $form->{"qty_$i"} * $form->{"netprice_$i"},
+ 2 );
+
+ if ( $form->{"inventory_accno_id_$i"}
+ || $form->{"assembly_$i"} )
+ {
+
+ push( @{ $form->{part} }, $form->{"sku_$i"} );
+ push( @{ $form->{service} }, NULL );
+ $form->{totalparts} += $linetotal;
+ }
+ else {
+ push( @{ $form->{service} }, $form->{"sku_$i"} );
+ push( @{ $form->{part} }, NULL );
+ $form->{totalservices} += $linetotal;
+ }
+
+ push(
+ @{ $form->{netprice} },
+ ( $form->{"netprice_$i"} )
+ ? $form->format_amount( $myconfig, $form->{"netprice_$i"},
+ $decimalplaces )
+ : " "
+ );
+
+ $discount =
+ ($discount)
+ ? $form->format_amount( $myconfig, $discount * -1,
+ $decimalplaces )
+ : " ";
+ $linetotal = ($linetotal) ? $linetotal : " ";
+
+ push( @{ $form->{discount} }, $discount );
+ push(
+ @{ $form->{discountrate} },
+ $form->format_amount( $myconfig, $form->{"discount_$i"} )
+ );
+
+ $form->{total} += $linetotal;
+
+ # this is for the subtotals for grouping
+ $subtotal += $linetotal;
+
+ $form->{"linetotal_$i"} =
+ $form->format_amount( $myconfig, $linetotal, 2 );
+
+ push( @{ $form->{linetotal} }, $form->{"linetotal_$i"} );
+
+ @taxaccounts = Tax::init_taxes( $form, $form->{"taxaccounts_$i"} );
+
+ my $ml = 1;
+ my @taxrates = ();
+
+ $tax = 0;
+
+ if ( $form->{taxincluded} ) {
+ $taxamount =
+ Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 1 );
+ $taxbase = ( $linetotal - $taxamount );
+ $tax += Tax::extract_taxes( \@taxaccounts, $form, $linetotal );
+ }
+ else {
+ $taxamount =
+ Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 0 );
+ $tax += Tax::apply_taxes( \@taxaccounts, $form, $linetotal );
+ }
+
+ foreach $item (@taxaccounts) {
+ push @taxrates, 100 * $item->rate;
+ $taxaccounts{ $item->account } += $item->value;
+ if ( $form->{taxincluded} ) {
+ $taxbase{ $item->account } += $taxbase;
+ }
+ else {
+ $taxbase{ $item->account } += $linetotal;
+ }
+ }
+
+ push(
+ @{ $form->{lineitems} },
+ {
+ amount => $linetotal,
+ tax => $form->round_amount( $tax, 2 )
+ }
+ );
+
+ push( @{ $form->{taxrates} },
+ join ' ', sort { $a <=> $b } @taxrates );
+
+ if ( $form->{"assembly_$i"} ) {
+ $form->{stagger} = -1;
+ &assembly_details( $myconfig, $form, $dbh, $form->{"id_$i"},
+ $oid{ $myconfig->{dbdriver} },
+ $form->{"qty_$i"} );
+ }
+
+ }
+
+ # add subtotal
+ if ( $form->{groupprojectnumber} || $form->{grouppartsgroup} ) {
+ if ($subtotal) {
+ if ( $j < $k ) {
+
+ # look at next item
+ if ( $sortlist[$j]->[1] ne $sameitem ) {
+
+ if ( $form->{"inventory_accno_id_$j"}
+ || $form->{"assembly_$i"} )
+ {
+
+ push( @{ $form->{part} }, "" );
+ push( @{ $form->{service} }, NULL );
+ }
+ else {
+ push( @{ $form->{service} }, "" );
+
+ push( @{ $form->{part} }, NULL );
+ }
+
+ for (
+ qw(taxrates
+ runningnumber number sku
+ serialnumber bin qty
+ ship unit deliverydate
+ projectnumber sellprice
+ listprice netprice
+ discount discountrate
+ weight itemnotes)
+ )
+ {
+
+ push( @{ $form->{$_} }, "" );
+ }
+
+ push(
+ @{ $form->{description} },
+ $form->{groupsubtotaldescription}
+ );
+
+ push(
+ @{ $form->{lineitems} },
+ {
+ amount => 0,
+ tax => 0
+ }
+ );
+
+ if ( $form->{groupsubtotaldescription} ne "" ) {
+
+ push(
+ @{ $form->{linetotal} },
+ $form->format_amount( $myconfig, $subtotal, 2 )
+ );
+ }
+ else {
+ push( @{ $form->{linetotal} }, "" );
+ }
+ $subtotal = 0;
+ }
+
+ }
+ else {
+
+ # got last item
+ if ( $form->{groupsubtotaldescription} ne "" ) {
+
+ if ( $form->{"inventory_accno_id_$j"}
+ || $form->{"assembly_$i"} )
+ {
+
+ push( @{ $form->{part} }, "" );
+
+ push( @{ $form->{service} }, NULL );
+ }
+ else {
+ push( @{ $form->{service} }, "" );
+
+ push( @{ $form->{part} }, NULL );
+ }
+
+ for (
+ qw(taxrates
+ runningnumber number sku
+ serialnumber bin qty
+ ship unit deliverydate
+ projectnumber sellprice
+ listprice netprice
+ discount discountrate
+ weight itemnotes)
+ )
+ {
+
+ push( @{ $form->{$_} }, "" );
+ }
+
+ push(
+ @{ $form->{description} },
+ $form->{groupsubtotaldescription}
+ );
+
+ push(
+ @{ $form->{linetotal} },
+ $form->format_amount( $myconfig, $subtotal, 2 )
+ );
+ push(
+ @{ $form->{lineitems} },
+ {
+ amount => 0,
+ tax => 0
+ }
+ );
+ }
+ }
+ }
+ }
+ }
+
+ $tax = 0;
+ foreach my $item ( sort keys %taxaccounts ) {
+ if ( $form->round_amount( $taxaccounts{$item}, 2 ) ) {
+ $tax += $taxamount = $form->round_amount( $taxaccounts{$item}, 2 );
+
+ push(
+ @{ $form->{taxbaseinclusive} },
+ $form->{"${item}_taxbaseinclusive"} =
+ $form->format_amount( $myconfig, $taxbase{$item} + $tax, 2 )
+ );
+
+ push(
+ @{ $form->{taxbase} },
+ $form->{"${item}_taxbase"} =
+ $form->format_amount( $myconfig, $taxbase{$item}, 2 )
+ );
+
+ push(
+ @{ $form->{tax} },
+ $form->{"${item}_tax"} =
+ $form->format_amount( $myconfig, $taxamount, 2 )
+ );
+
+ push( @{ $form->{taxdescription} },
+ $form->{"${item}_description"} );
+
+ $form->{"${item}_taxrate"} =
+ $form->format_amount( $myconfig, $form->{"${item}_rate"} * 100 );
+ push( @{ $form->{taxrate} }, $form->{"${item}_taxrate"} );
+ push( @{ $form->{taxnumber} }, $form->{"${item}_taxnumber"} );
+ }
+ }
+
+ # adjust taxes for lineitems
+ my $total = 0;
+ for ( @{ $form->{lineitems} } ) {
+ $total += $_->{tax};
+ }
+ if ( $form->round_amount( $total, 2 ) != $form->round_amount( $tax, 2 ) ) {
+
+ # get largest amount
+ for ( reverse sort { $a->{tax} <=> $b->{tax} } @{ $form->{lineitems} } )
+ {
+
+ $_->{tax} -= $total - $tax;
+ last;
+ }
+ }
+ $i = 1;
+ for ( @{ $form->{lineitems} } ) {
+ push(
+ @{ $form->{linetax} },
+ $form->format_amount( $myconfig, $_->{tax}, 2, "" )
+ );
+ }
+
+ for $i ( 1 .. $form->{paidaccounts} ) {
+ if ( $form->{"paid_$i"} ) {
+ push( @{ $form->{payment} }, $form->{"paid_$i"} );
+ my ( $accno, $description ) = split /--/, $form->{"AR_paid_$i"};
+
+ push( @{ $form->{paymentaccount} }, $description );
+ push( @{ $form->{paymentdate} }, $form->{"datepaid_$i"} );
+ push( @{ $form->{paymentsource} }, $form->{"source_$i"} );
+ push( @{ $form->{paymentmemo} }, $form->{"memo_$i"} );
+
+ $form->{paid} +=
+ $form->parse_amount( $myconfig, $form->{"paid_$i"} );
+ }
+ }
+
+ for (qw(totalparts totalservices)) {
+ $form->{$_} = $form->format_amount( $myconfig, $form->{$_}, 2 );
+ }
+ for (qw(totalqty totalship totalweight)) {
+ $form->{$_} = $form->format_amount( $myconfig, $form->{$_} );
+ }
+ $form->{subtotal} = $form->format_amount( $myconfig, $form->{total}, 2 );
+ $form->{invtotal} =
+ ( $form->{taxincluded} ) ? $form->{total} : $form->{total} + $tax;
+
+ my $c;
+ if ( $form->{language_code} ne "" ) {
+ $c = new CP $form->{language_code};
+ }
+ else {
+ $c = new CP $myconfig->{countrycode};
+ }
+ $c->init;
+ my $whole;
+ ( $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 );
+
+ $form->format_string(qw(text_amount text_decimal));
+
+ $form->{total} =
+ $form->format_amount( $myconfig, $form->{invtotal} - $form->{paid}, 2 );
+
+ $form->{invtotal} = $form->format_amount( $myconfig, $form->{invtotal}, 2 );
+
+ $form->{paid} = $form->format_amount( $myconfig, $form->{paid}, 2 );
+
+ $dbh->commit;
+}
sub assembly_details {
- my ($myconfig, $form, $dbh2, $id, $oid, $qty) = @_;
- $dbh = $form->{dbh};
- my $sm = "";
- my $spacer;
-
- $form->{stagger}++;
- if ($form->{format} eq 'html') {
- $spacer = "&nbsp;" x (3 * ($form->{stagger} - 1))
- if $form->{stagger} > 1;
- }
- if ($form->{format} =~ /(postscript|pdf)/) {
- if ($form->{stagger} > 1) {
- $spacer = ($form->{stagger} - 1) * 3;
- $spacer = '\rule{'.$spacer.'mm}{0mm}';
- }
- }
-
- # get parts and push them onto the stack
- my $sortorder = "";
-
- if ($form->{grouppartsgroup}) {
- $sortorder = qq|ORDER BY pg.partsgroup|;
- }
-
- my $query = qq|
+ my ( $myconfig, $form, $dbh2, $id, $oid, $qty ) = @_;
+ $dbh = $form->{dbh};
+ my $sm = "";
+ my $spacer;
+
+ $form->{stagger}++;
+ if ( $form->{format} eq 'html' ) {
+ $spacer = "&nbsp;" x ( 3 * ( $form->{stagger} - 1 ) )
+ if $form->{stagger} > 1;
+ }
+ if ( $form->{format} =~ /(postscript|pdf)/ ) {
+ if ( $form->{stagger} > 1 ) {
+ $spacer = ( $form->{stagger} - 1 ) * 3;
+ $spacer = '\rule{' . $spacer . 'mm}{0mm}';
+ }
+ }
+
+ # get parts and push them onto the stack
+ my $sortorder = "";
+
+ if ( $form->{grouppartsgroup} ) {
+ $sortorder = qq|ORDER BY pg.partsgroup|;
+ }
+
+ my $query = qq|
SELECT p.partnumber, p.description, p.unit, a.qty,
pg.partsgroup, p.partnumber AS sku
FROM assembly a
@@ -663,119 +664,122 @@ sub assembly_details {
WHERE a.bom = '1'
AND a.id = ?
$sortorder|;
- my $sth = $dbh->prepare($query);
- $sth->execute($id) || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- for (qw(partnumber description partsgroup)) {
- $form->{"a_$_"} = $ref->{$_};
- $form->format_string("a_$_");
- }
-
- if ($form->{grouppartsgroup} && $ref->{partsgroup} ne $sm) {
- for (
- qw(taxrates runningnumber number sku
- serialnumber unit qty ship bin deliverydate
- projectnumber sellprice listprice netprice
- discount discountrate linetotal weight
- itemnotes)
- ) {
-
- push(@{ $form->{$_} }, "");
- }
- $sm =
- ($form->{"a_partsgroup"})
- ? $form->{"a_partsgroup"}
- : "--";
-
- push(@{ $form->{description} }, "$spacer$sm");
- push(@{ $form->{lineitems} },
- { amount => 0, tax => 0 });
- }
-
- if ($form->{stagger}) {
-
- push(@{ $form->{description} },
- $form->format_amount(
- $myconfig,
- $ref->{qty} * $form->{"qty_$i"})
- .qq| -- $form->{"a_partnumber"}|
- .qq|, $form->{"a_description"}|);
-
- for (
- qw(taxrates runningnumber number sku
- serialnumber unit qty ship bin deliverydate
- projectnumber sellprice listprice netprice
- discount discountrate linetotal weight
- itemnotes)
- ) {
- push(@{ $form->{$_} }, "");
- }
-
- } else {
-
- push(@{ $form->{description} },
- qq|$form->{"a_description"}|);
-
- push(@{ $form->{number} }, $form->{"a_partnumber"});
- push(@{ $form->{sku} }, $form->{"a_partnumber"});
-
- for (
- qw(taxrates runningnumber ship serialnumber
- reqdate projectnumber sellprice listprice
- netprice discount discountrate linetotal weight
- itemnotes)
- ) {
-
- push(@{ $form->{$_} }, "");
- }
-
- }
-
- push(@{ $form->{lineitems} }, { amount => 0, tax => 0 });
-
- push(@{ $form->{qty} },
- $form->format_amount($myconfig, $ref->{qty} * $qty));
-
- for (qw(unit bin)) {
- $form->{"a_$_"} = $ref->{$_};
- $form->format_string("a_$_");
- push(@{ $form->{$_} }, $form->{"a_$_"});
- }
-
- }
- $sth->finish;
-
- $form->{stagger}--;
-
-}
+ my $sth = $dbh->prepare($query);
+ $sth->execute($id) || $form->dberror($query);
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ for (qw(partnumber description partsgroup)) {
+ $form->{"a_$_"} = $ref->{$_};
+ $form->format_string("a_$_");
+ }
+
+ if ( $form->{grouppartsgroup} && $ref->{partsgroup} ne $sm ) {
+ for (
+ qw(taxrates runningnumber number sku
+ serialnumber unit qty ship bin deliverydate
+ projectnumber sellprice listprice netprice
+ discount discountrate linetotal weight
+ itemnotes)
+ )
+ {
+
+ push( @{ $form->{$_} }, "" );
+ }
+ $sm =
+ ( $form->{"a_partsgroup"} )
+ ? $form->{"a_partsgroup"}
+ : "--";
+
+ push( @{ $form->{description} }, "$spacer$sm" );
+ push( @{ $form->{lineitems} }, { amount => 0, tax => 0 } );
+ }
+
+ if ( $form->{stagger} ) {
+
+ push(
+ @{ $form->{description} },
+ $form->format_amount( $myconfig,
+ $ref->{qty} * $form->{"qty_$i"} )
+ . qq| -- $form->{"a_partnumber"}|
+ . qq|, $form->{"a_description"}|
+ );
+
+ for (
+ qw(taxrates runningnumber number sku
+ serialnumber unit qty ship bin deliverydate
+ projectnumber sellprice listprice netprice
+ discount discountrate linetotal weight
+ itemnotes)
+ )
+ {
+ push( @{ $form->{$_} }, "" );
+ }
+
+ }
+ else {
+
+ push( @{ $form->{description} }, qq|$form->{"a_description"}| );
+
+ push( @{ $form->{number} }, $form->{"a_partnumber"} );
+ push( @{ $form->{sku} }, $form->{"a_partnumber"} );
+
+ for (
+ qw(taxrates runningnumber ship serialnumber
+ reqdate projectnumber sellprice listprice
+ netprice discount discountrate linetotal weight
+ itemnotes)
+ )
+ {
+
+ push( @{ $form->{$_} }, "" );
+ }
+
+ }
+
+ push( @{ $form->{lineitems} }, { amount => 0, tax => 0 } );
+
+ push(
+ @{ $form->{qty} },
+ $form->format_amount( $myconfig, $ref->{qty} * $qty )
+ );
+
+ for (qw(unit bin)) {
+ $form->{"a_$_"} = $ref->{$_};
+ $form->format_string("a_$_");
+ push( @{ $form->{$_} }, $form->{"a_$_"} );
+ }
+
+ }
+ $sth->finish;
+
+ $form->{stagger}--;
+}
sub project_description {
- my ($self, $dbh2, $id) = @_;
- $dbh = $form->{dbh};
- my $query = qq|
+ my ( $self, $dbh2, $id ) = @_;
+ $dbh = $form->{dbh};
+ my $query = qq|
SELECT description
FROM project
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($id);
- ($_) = $sth->fetchrow_array;
+ $sth = $dbh->prepare($query);
+ $sth->execute($id);
+ ($_) = $sth->fetchrow_array;
- $_;
+ $_;
}
-
sub customer_details {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
-
- # get rest for the customer
- my $query = qq|
+ my $dbh = $form->{dbh};
+
+ # get rest for the customer
+ my $query = qq|
SELECT customernumber, name, address1, address2, city,
state, zipcode, country,
contact, phone as customerphone, fax as customerfax,
@@ -783,232 +787,225 @@ sub customer_details {
bic, startdate, enddate
FROM customer
WHERE id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{customer_id}) || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{customer_id} ) || $form->dberror($query);
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub post_invoice {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my $query;
- my $sth;
- my $null;
- my $project_id;
- my $exchangerate = 0;
- my $keepcleared = 0;
-
- %$form->{acc_trans} = ();
-
- ($null, $form->{employee_id}) = split /--/, $form->{employee};
- unless ($form->{employee_id}) {
- ($form->{employee}, $form->{employee_id})
- = $form->get_employee($dbh);
- }
-
- ($null, $form->{department_id}) = split(/--/, $form->{department});
- $form->{department_id} *= 1;
-
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my $query;
+ my $sth;
+ my $null;
+ my $project_id;
+ my $exchangerate = 0;
+ my $keepcleared = 0;
+
+ %$form->{acc_trans} = ();
+
+ ( $null, $form->{employee_id} ) = split /--/, $form->{employee};
+ unless ( $form->{employee_id} ) {
+ ( $form->{employee}, $form->{employee_id} ) = $form->get_employee($dbh);
+ }
+
+ ( $null, $form->{department_id} ) = split( /--/, $form->{department} );
+ $form->{department_id} *= 1;
+
+ $query = qq|
SELECT (SELECT value FROM defaults
WHERE setting_key = 'fxgain_accno_id')
AS fxgain_accno_id,
(SELECT value FROM defaults
WHERE setting_key = 'fxloss_accno_id')
AS fxloss_accno_id|;
- my ($fxgain_accno_id, $fxloss_accno_id) = $dbh->selectrow_array($query);
+ my ( $fxgain_accno_id, $fxloss_accno_id ) = $dbh->selectrow_array($query);
- $query = qq|
+ $query = qq|
SELECT p.assembly, p.inventory_accno_id,
p.income_accno_id, p.expense_accno_id, p.project_id
FROM parts p
WHERE p.id = ?|;
- my $pth = $dbh->prepare($query) || $form->dberror($query);
-
- if ($form->{id}) {
- $keepcleared = 1;
- $query = qq|SELECT id FROM ar WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id});
-
- if ($sth->fetchrow_array) {
- &reverse_invoice($dbh, $form);
- } else {
- $query = qq|INSERT INTO ar (id) VALUES (?)|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- }
-
- }
-
- my $uid = localtime;
- $uid .= "$$";
-
- if (! $form->{id}) {
-
- $query = qq|
+ my $pth = $dbh->prepare($query) || $form->dberror($query);
+
+ if ( $form->{id} ) {
+ $keepcleared = 1;
+ $query = qq|SELECT id FROM ar WHERE id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} );
+
+ if ( $sth->fetchrow_array ) {
+ &reverse_invoice( $dbh, $form );
+ }
+ else {
+ $query = qq|INSERT INTO ar (id) VALUES (?)|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ }
+
+ }
+
+ my $uid = localtime;
+ $uid .= "$$";
+
+ if ( !$form->{id} ) {
+
+ $query = qq|
INSERT INTO ar (invnumber, employee_id)
VALUES ('$uid', ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{employee_id}) || $form->dberror($query);
-
- $query = qq|SELECT id FROM ar WHERE invnumber = '$uid'|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- ($form->{id}) = $sth->fetchrow_array;
- $sth->finish;
-
- @queries = $form->run_custom_queries('ar', 'INSERT');
- }
-
-
- if ($form->{currency} eq $form->{defaultcurrency}) {
- $form->{exchangerate} = 1;
- } else {
- $exchangerate =
- $form->check_exchangerate(
- $myconfig, $form->{currency},
- $form->{transdate}, 'buy');
- }
-
- $form->{exchangerate} =
- ($exchangerate)
- ? $exchangerate
- : $form->parse_amount($myconfig, $form->{exchangerate});
-
- my $i;
- my $item;
- my $allocated = 0;
- my $taxrate;
- my $tax;
- my $fxtax;
- my @taxaccounts;
- my $amount;
- my $grossamount;
- my $invamount = 0;
- my $invnetamount = 0;
- my $diff = 0;
- my $ml;
- my $invoice_id;
- my $ndx;
-
- foreach $i (1 .. $form->{rowcount}) {
- $form->{"qty_$i"} =
- $form->parse_amount($myconfig, $form->{"qty_$i"});
-
- if ($form->{"qty_$i"}) {
-
- $pth->execute($form->{"id_$i"});
- $ref = $pth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
- $pth->finish;
-
- # project
- if ($form->{"projectnumber_$i"}) {
- ($null, $project_id)
- = split /--/,
- $form->{"projectnumber_$i"};
- }
- $project_id = $form->{"project_id_$i"}
- if $form->{"project_id_$i"};
-
- # keep entered selling price
- my $fxsellprice =
- $form->parse_amount(
- $myconfig, $form->{"sellprice_$i"});
-
- my ($dec) = ($fxsellprice =~ /\.(\d+)/);
- $dec = length $dec;
- my $decimalplaces = ($dec > 2) ? $dec : 2;
-
- # undo discount formatting
- $form->{"discount_$i"} =
- $form->parse_amount(
- $myconfig, $form->{"discount_$i"})/100;
-
- # deduct discount
- $form->{"sellprice_$i"} = $fxsellprice
- - $form->round_amount(
- $fxsellprice * $form->{"discount_$i"},
- $decimalplaces);
-
- # linetotal
- my $fxlinetotal = $form->round_amount(
- $form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
-
- $amount = $fxlinetotal * $form->{exchangerate};
- my $linetotal = $form->round_amount($amount, 2);
- $fxdiff += $amount - $linetotal;
-
- @taxaccounts = Tax::init_taxes(
- $form, $form->{"taxaccounts_$i"});
- $ml = 1;
- $tax = 0;
- $fxtax = 0;
-
- if ($form->{taxincluded}) {
- $tax += $amount =
- Tax::calculate_taxes(
- \@taxaccounts, $form,
- $linetotal, 1);
- $form->{"sellprice_$i"} -= $amount
- / $form->{"qty_$i"};
-
- $fxtax += Tax::calculate_taxes(
- \@taxaccounts, $form, $linetotal, 1);
- } else {
- $tax += $amount = Tax::calculate_taxes(
- \@taxaccounts, $form, $linetotal, 0);
-
- $fxtax += Tax::calculate_taxes(
- \@taxaccounts, $form, $linetotal, 0);
- }
-
- $grossamount = $form->round_amount($linetotal, 2);
-
- if ($form->{taxincluded}) {
- $amount = $form->round_amount($tax, 2);
- $linetotal -= $form->round_amount(
- $tax - $diff, 2);
- $diff = ($amount - $tax);
- }
-
- # add linetotal to income
- $amount = $form->round_amount($linetotal, 2);
-
- push @{ $form->{acc_trans}{lineitems} }, {
- chart_id => $form->{"income_accno_id_$i"},
- amount => $amount,
- fxgrossamount => $fxlinetotal + $fxtax,
- grossamount => $grossamount,
- project_id => $project_id };
-
- $ndx = $#{@{$form->{acc_trans}{lineitems}}};
-
- $form->{"sellprice_$i"} =
- $form->round_amount(
- $form->{"sellprice_$i"}
- * $form->{exchangerate},
- $decimalplaces);
-
- if ($form->{"inventory_accno_id_$i"}
- || $form->{"assembly_$i"}) {
-
- if ($form->{"assembly_$i"}) {
- # If the assembly consists of all
- # services, we don't keep inventory,
- # so we should not update it
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{employee_id} ) || $form->dberror($query);
+
+ $query = qq|SELECT id FROM ar WHERE invnumber = '$uid'|;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ ( $form->{id} ) = $sth->fetchrow_array;
+ $sth->finish;
+
+ @queries = $form->run_custom_queries( 'ar', 'INSERT' );
+ }
+
+ if ( $form->{currency} eq $form->{defaultcurrency} ) {
+ $form->{exchangerate} = 1;
+ }
+ else {
+ $exchangerate =
+ $form->check_exchangerate( $myconfig, $form->{currency},
+ $form->{transdate}, 'buy' );
+ }
+
+ $form->{exchangerate} =
+ ($exchangerate)
+ ? $exchangerate
+ : $form->parse_amount( $myconfig, $form->{exchangerate} );
+
+ my $i;
+ my $item;
+ my $allocated = 0;
+ my $taxrate;
+ my $tax;
+ my $fxtax;
+ my @taxaccounts;
+ my $amount;
+ my $grossamount;
+ my $invamount = 0;
+ my $invnetamount = 0;
+ my $diff = 0;
+ my $ml;
+ my $invoice_id;
+ my $ndx;
+
+ foreach $i ( 1 .. $form->{rowcount} ) {
+ $form->{"qty_$i"} = $form->parse_amount( $myconfig, $form->{"qty_$i"} );
+
+ if ( $form->{"qty_$i"} ) {
+
+ $pth->execute( $form->{"id_$i"} );
+ $ref = $pth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
+ $pth->finish;
+
+ # project
+ if ( $form->{"projectnumber_$i"} ) {
+ ( $null, $project_id ) = split /--/,
+ $form->{"projectnumber_$i"};
+ }
+ $project_id = $form->{"project_id_$i"}
+ if $form->{"project_id_$i"};
+
+ # keep entered selling price
+ my $fxsellprice =
+ $form->parse_amount( $myconfig, $form->{"sellprice_$i"} );
+
+ my ($dec) = ( $fxsellprice =~ /\.(\d+)/ );
+ $dec = length $dec;
+ my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ # undo discount formatting
+ $form->{"discount_$i"} =
+ $form->parse_amount( $myconfig, $form->{"discount_$i"} ) / 100;
+
+ # deduct discount
+ $form->{"sellprice_$i"} = $fxsellprice -
+ $form->round_amount( $fxsellprice * $form->{"discount_$i"},
+ $decimalplaces );
+
+ # linetotal
+ my $fxlinetotal =
+ $form->round_amount( $form->{"sellprice_$i"} * $form->{"qty_$i"},
+ 2 );
+
+ $amount = $fxlinetotal * $form->{exchangerate};
+ my $linetotal = $form->round_amount( $amount, 2 );
+ $fxdiff += $amount - $linetotal;
+
+ @taxaccounts = Tax::init_taxes( $form, $form->{"taxaccounts_$i"} );
+ $ml = 1;
+ $tax = 0;
+ $fxtax = 0;
+
+ if ( $form->{taxincluded} ) {
+ $tax += $amount =
+ Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 1 );
+ $form->{"sellprice_$i"} -= $amount / $form->{"qty_$i"};
+
+ $fxtax +=
+ Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 1 );
+ }
+ else {
+ $tax += $amount =
+ Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 0 );
+
+ $fxtax +=
+ Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 0 );
+ }
+
+ $grossamount = $form->round_amount( $linetotal, 2 );
+
+ if ( $form->{taxincluded} ) {
+ $amount = $form->round_amount( $tax, 2 );
+ $linetotal -= $form->round_amount( $tax - $diff, 2 );
+ $diff = ( $amount - $tax );
+ }
+
+ # add linetotal to income
+ $amount = $form->round_amount( $linetotal, 2 );
+
+ push @{ $form->{acc_trans}{lineitems} },
+ {
+ chart_id => $form->{"income_accno_id_$i"},
+ amount => $amount,
+ fxgrossamount => $fxlinetotal + $fxtax,
+ grossamount => $grossamount,
+ project_id => $project_id
+ };
+
+ $ndx = $#{ @{ $form->{acc_trans}{lineitems} } };
+
+ $form->{"sellprice_$i"} =
+ $form->round_amount(
+ $form->{"sellprice_$i"} * $form->{exchangerate},
+ $decimalplaces );
+
+ if ( $form->{"inventory_accno_id_$i"}
+ || $form->{"assembly_$i"} )
+ {
+
+ if ( $form->{"assembly_$i"} ) {
+
+ # If the assembly consists of all
+ # services, we don't keep inventory,
+ # so we should not update it
+ $query = qq|
SELECT sum(
p.inventory_accno_id),
p.assembly
@@ -1017,55 +1014,52 @@ sub post_invoice {
ON (a.parts_id = p.id)
WHERE a.id = $form->{"id_$i"}
GROUP BY p.assembly|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{"id_$i"})
- || $form->dberror($query);
- my ($inv, $assembly)
- = $sth->fetchrow_array;
- $sth->finish;
-
- if ($inv || $assembly) {
- $form->update_balance($dbh,
- "parts",
- "onhand",
- qq|id = |.
- qq|$form->{"id_$i"}|,
- $form->{"qty_$i"} * -1)
- unless $form->{shipped};
- }
-
- &process_assembly(
- $dbh, $form, $form->{"id_$i"},
- $form->{"qty_$i"}, $project_id);
- } else {
- $form->update_balance(
- $dbh, "parts", "onhand",
- qq|id = $form->{"id_$i"}|,
- $form->{"qty_$i"} * -1)
- unless $form->{shipped};
-
- $allocated = &cogs(
- $dbh, $form, $form->{"id_$i"},
- $form->{"qty_$i"}, $project_id);
- }
- }
-
- # save detail record in invoice table
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{"id_$i"} )
+ || $form->dberror($query);
+ my ( $inv, $assembly ) = $sth->fetchrow_array;
+ $sth->finish;
+
+ if ( $inv || $assembly ) {
+ $form->update_balance(
+ $dbh, "parts", "onhand",
+ qq|id = | . qq|$form->{"id_$i"}|,
+ $form->{"qty_$i"} * -1
+ ) unless $form->{shipped};
+ }
+
+ &process_assembly( $dbh, $form, $form->{"id_$i"},
+ $form->{"qty_$i"}, $project_id );
+ }
+ else {
+ $form->update_balance(
+ $dbh, "parts", "onhand",
+ qq|id = $form->{"id_$i"}|,
+ $form->{"qty_$i"} * -1
+ ) unless $form->{shipped};
+
+ $allocated =
+ &cogs( $dbh, $form, $form->{"id_$i"}, $form->{"qty_$i"},
+ $project_id );
+ }
+ }
+
+ # save detail record in invoice table
+ $query = qq|
INSERT INTO invoice (description)
VALUES ('$uid')|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT id FROM invoice
WHERE description = '$uid'|;
- ($invoice_id) = $dbh->selectrow_array($query);
+ ($invoice_id) = $dbh->selectrow_array($query);
- unless ($form->{"deliverydate_$i"}){
- undef $form->{"deliverydate_$i"};
- }
- $query = qq|
+ unless ( $form->{"deliverydate_$i"} ) {
+ undef $form->{"deliverydate_$i"};
+ }
+ $query = qq|
UPDATE invoice
SET trans_id = ?,
parts_id = ?,
@@ -1082,128 +1076,123 @@ sub post_invoice {
notes = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $form->{"id_$i"},
- $form->{"description_$i"}, $form->{"qty_$i"},
- $form->{"sellprice_$i"}, $fxsellprice,
- $form->{"discount_$i"}, $allocated,
- $form->{"unit_$i"}, $form->{"deliverydate_$i"},
- $project_id, $form->{"serialnumber_$i"},
- $form->{"notes_$i"}, $invoice_id)
- || $form->dberror($query);
-
- # add invoice_id
- $form->{acc_trans}{lineitems}[$ndx]->{invoice_id}
- = $invoice_id;
-
- }
- }
-
- $form->{paid} = 0;
- for $i (1 .. $form->{paidaccounts}) {
- $form->{"paid_$i"} =
- $form->parse_amount($myconfig, $form->{"paid_$i"});
- $form->{paid} += $form->{"paid_$i"};
- $form->{datepaid} = $form->{"datepaid_$i"}
- if ($form->{"paid_$i"});
- }
-
- # add lineitems + tax
- $amount = 0;
- $grossamount = 0;
- $fxgrossamount = 0;
-
- for (@{ $form->{acc_trans}{lineitems} }) {
- $amount += $_->{amount};
- $grossamount += $_->{grossamount};
- $fxgrossamount += $_->{fxgrossamount};
- }
- $invnetamount = $amount;
-
- $amount = 0;
-
- for (split / /, $form->{taxaccounts}) {
- $amount +=
- $form->{acc_trans}{$form->{id}}{$_}{amount} =
- $form->round_amount(
- $form->{acc_trans}{$form->{id}}{$_}{amount},
- 2);
- }
- $invamount = $invnetamount + $amount;
-
- $diff = 0;
-
- if ($form->{taxincluded}) {
- $diff = $form->round_amount($grossamount - $invamount, 2);
- $invamount += $diff;
- }
- $fxdiff = $form->round_amount($fxdiff,2);
- $invnetamount += $fxdiff;
- $invamount += $fxdiff;
-
- if ($form->round_amount($form->{paid} - $fxgrossamount,2) == 0) {
- $form->{paid} = $invamount;
- } else {
- $form->{paid} = $form->round_amount(
- $form->{paid} * $form->{exchangerate}, 2);
- }
-
- foreach $ref (sort { $b->{amount} <=> $a->{amount} }
- @ { $form->{acc_trans}{lineitems} }) {
-
- $amount = $ref->{amount} + $diff + $fxdiff;
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{id}, $form->{"id_$i"},
+ $form->{"description_$i"}, $form->{"qty_$i"},
+ $form->{"sellprice_$i"}, $fxsellprice,
+ $form->{"discount_$i"}, $allocated,
+ $form->{"unit_$i"}, $form->{"deliverydate_$i"},
+ $project_id, $form->{"serialnumber_$i"},
+ $form->{"notes_$i"}, $invoice_id
+ ) || $form->dberror($query);
+
+ # add invoice_id
+ $form->{acc_trans}{lineitems}[$ndx]->{invoice_id} = $invoice_id;
+
+ }
+ }
+
+ $form->{paid} = 0;
+ for $i ( 1 .. $form->{paidaccounts} ) {
+ $form->{"paid_$i"} =
+ $form->parse_amount( $myconfig, $form->{"paid_$i"} );
+ $form->{paid} += $form->{"paid_$i"};
+ $form->{datepaid} = $form->{"datepaid_$i"}
+ if ( $form->{"paid_$i"} );
+ }
+
+ # add lineitems + tax
+ $amount = 0;
+ $grossamount = 0;
+ $fxgrossamount = 0;
+
+ for ( @{ $form->{acc_trans}{lineitems} } ) {
+ $amount += $_->{amount};
+ $grossamount += $_->{grossamount};
+ $fxgrossamount += $_->{fxgrossamount};
+ }
+ $invnetamount = $amount;
+
+ $amount = 0;
+
+ for ( split / /, $form->{taxaccounts} ) {
+ $amount += $form->{acc_trans}{ $form->{id} }{$_}{amount} =
+ $form->round_amount( $form->{acc_trans}{ $form->{id} }{$_}{amount},
+ 2 );
+ }
+ $invamount = $invnetamount + $amount;
+
+ $diff = 0;
+
+ if ( $form->{taxincluded} ) {
+ $diff = $form->round_amount( $grossamount - $invamount, 2 );
+ $invamount += $diff;
+ }
+ $fxdiff = $form->round_amount( $fxdiff, 2 );
+ $invnetamount += $fxdiff;
+ $invamount += $fxdiff;
+
+ if ( $form->round_amount( $form->{paid} - $fxgrossamount, 2 ) == 0 ) {
+ $form->{paid} = $invamount;
+ }
+ else {
+ $form->{paid} =
+ $form->round_amount( $form->{paid} * $form->{exchangerate}, 2 );
+ }
+
+ foreach $ref ( sort { $b->{amount} <=> $a->{amount} }
+ @{ $form->{acc_trans}{lineitems} } )
+ {
+
+ $amount = $ref->{amount} + $diff + $fxdiff;
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate, project_id, invoice_id)
VALUES (?, ?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $ref->{chart_id}, $amount,
- $form->{transdate}, $ref->{project_id},
- $ref->{invoice_id})
- || $form->dberror($query);
- $diff = 0;
- $fxdiff = 0;
- }
-
- $form->{receivables} = $invamount * -1;
-
- delete $form->{acc_trans}{lineitems};
-
- # update exchangerate
- if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) {
- $form->update_exchangerate(
- $dbh, $form->{currency}, $form->{transdate},
- $form->{exchangerate}, 0);
- }
-
- # record receivable
- if ($form->{receivables}) {
- ($accno) = split /--/, $form->{AR};
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $ref->{chart_id}, $amount,
+ $form->{transdate}, $ref->{project_id}, $ref->{invoice_id} )
+ || $form->dberror($query);
+ $diff = 0;
+ $fxdiff = 0;
+ }
+
+ $form->{receivables} = $invamount * -1;
+
+ delete $form->{acc_trans}{lineitems};
+
+ # update exchangerate
+ if ( ( $form->{currency} ne $form->{defaultcurrency} ) && !$exchangerate ) {
+ $form->update_exchangerate( $dbh, $form->{currency}, $form->{transdate},
+ $form->{exchangerate}, 0 );
+ }
+
+ # record receivable
+ if ( $form->{receivables} ) {
+ ($accno) = split /--/, $form->{AR};
+
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount, transdate)
VALUES (?, (SELECT id FROM chart WHERE accno = ?),
?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $accno, $form->{receivables},
- $form->{transdate})
- || $form->dberror($query);
- }
-
- foreach my $trans_id (keys %{$form->{acc_trans}}) {
- foreach my $accno (keys %{$form->{acc_trans}{$trans_id}}) {
- $amount = $form->round_amount(
- $form->{acc_trans}{$trans_id}{$accno}{amount},
- 2);
- if ($amount) {
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $accno, $form->{receivables},
+ $form->{transdate} )
+ || $form->dberror($query);
+ }
+
+ foreach my $trans_id ( keys %{ $form->{acc_trans} } ) {
+ foreach my $accno ( keys %{ $form->{acc_trans}{$trans_id} } ) {
+ $amount =
+ $form->round_amount(
+ $form->{acc_trans}{$trans_id}{$accno}{amount}, 2 );
+ if ($amount) {
+
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate)
@@ -1211,78 +1200,73 @@ sub post_invoice {
WHERE accno = ?),
?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $trans_id, $accno, $amount,
- $form->{transdate})
- || $form->dberror($query);
- }
- }
- }
-
-
- # if there is no amount but a payment record receivable
- if ($invamount == 0) {
- $form->{receivables} = 1;
- }
-
- my $cleared = 0;
-
- # record payments and offsetting AR
- for $i (1 .. $form->{paidaccounts}) {
-
- if ($form->{"paid_$i"}) {
- my ($accno) = split /--/, $form->{"AR_paid_$i"};
- $form->{"datepaid_$i"} = $form->{transdate}
- unless ($form->{"datepaid_$i"});
-
- $form->{datepaid} = $form->{"datepaid_$i"};
-
- $exchangerate = 0;
-
- if ($form->{currency} eq $form->{defaultcurrency}) {
- $form->{"exchangerate_$i"} = 1;
- } else {
- $exchangerate =
- $form->check_exchangerate(
- $myconfig, $form->{currency},
- $form->{"datepaid_$i"}, 'buy');
-
- $form->{"exchangerate_$i"} =
- ($exchangerate)
- ? $exchangerate
- : $form->parse_amount(
- $myconfig,
- $form->{"exchangerate_$i"});
- }
-
-
- # record AR
- $amount = $form->round_amount(
- $form->{"paid_$i"} * $form->{exchangerate}, 2);
-
- if ($form->{receivables}) {
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $trans_id, $accno, $amount, $form->{transdate} )
+ || $form->dberror($query);
+ }
+ }
+ }
+
+ # if there is no amount but a payment record receivable
+ if ( $invamount == 0 ) {
+ $form->{receivables} = 1;
+ }
+
+ my $cleared = 0;
+
+ # record payments and offsetting AR
+ for $i ( 1 .. $form->{paidaccounts} ) {
+
+ if ( $form->{"paid_$i"} ) {
+ my ($accno) = split /--/, $form->{"AR_paid_$i"};
+ $form->{"datepaid_$i"} = $form->{transdate}
+ unless ( $form->{"datepaid_$i"} );
+
+ $form->{datepaid} = $form->{"datepaid_$i"};
+
+ $exchangerate = 0;
+
+ if ( $form->{currency} eq $form->{defaultcurrency} ) {
+ $form->{"exchangerate_$i"} = 1;
+ }
+ else {
+ $exchangerate =
+ $form->check_exchangerate( $myconfig, $form->{currency},
+ $form->{"datepaid_$i"}, 'buy' );
+
+ $form->{"exchangerate_$i"} =
+ ($exchangerate)
+ ? $exchangerate
+ : $form->parse_amount( $myconfig,
+ $form->{"exchangerate_$i"} );
+ }
+
+ # record AR
+ $amount =
+ $form->round_amount( $form->{"paid_$i"} * $form->{exchangerate},
+ 2 );
+
+ if ( $form->{receivables} ) {
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate)
VALUES (?, (SELECT id FROM chart
WHERE accno = ?),
?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $form->{AR}, $amount,
- $form->{"datepaid_$i"})
- || $form->dberror($query);
- }
-
- # record payment
- $amount = $form->{"paid_$i"} * -1;
- if ($keepcleared) {
- $cleared = ($form->{"cleared_$i"}) ? 1 : 0;
- }
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $form->{AR}, $amount,
+ $form->{"datepaid_$i"} )
+ || $form->dberror($query);
+ }
+
+ # record payment
+ $amount = $form->{"paid_$i"} * -1;
+ if ($keepcleared) {
+ $cleared = ( $form->{"cleared_$i"} ) ? 1 : 0;
+ }
+
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate, source, memo, cleared)
@@ -1290,23 +1274,25 @@ sub post_invoice {
WHERE accno = ?),
?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $accno, $amount,
- $form->{"datepaid_$i"}, $form->{"source_$i"},
- $form->{"memo_$i"}, $cleared)
- || $form->dberror($query);
-
- # exchangerate difference
- $amount = $form->round_amount(
- ($form->round_amount(
- $form->{"paid_$i"}
- * $form->{"exchangerate_$i"}
- - $form->{"paid_$i"}, 2)) * -1,
- 2);
-
- if ($amount) {
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $accno, $amount, $form->{"datepaid_$i"},
+ $form->{"source_$i"}, $form->{"memo_$i"}, $cleared )
+ || $form->dberror($query);
+
+ # exchangerate difference
+ $amount = $form->round_amount(
+ (
+ $form->round_amount(
+ $form->{"paid_$i"} * $form->{"exchangerate_$i"} -
+ $form->{"paid_$i"},
+ 2
+ )
+ ) * -1,
+ 2
+ );
+
+ if ($amount) {
+ $query = qq|
INSERT INTO acc_trans
(trans_id, chart_id, amount,
transdate, source,
@@ -1315,68 +1301,67 @@ sub post_invoice {
WHERE accno = >),
?, ?, ?, '1', ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $accno, $amount,
- $form->{"datepaid_$i"},
- $form->{"source_$i"}, $cleared )
- || $form->dberror($query);
- }
-
- # gain/loss
- $amount = $form->round_amount(
- ($form->round_amount(
- $form->{"paid_$i"}
- * $form->{exchangerate},2)
- - $form->round_amount(
- $form->{"paid_$i"}
- * $form->{"exchangerate_$i"},2)
- ) * -1,
- 2);
-
- if ($amount) {
- my $accno_id =
- ($amount > 0)
- ? $fxgain_accno_id
- : $fxloss_accno_id;
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $accno, $amount,
+ $form->{"datepaid_$i"},
+ $form->{"source_$i"}, $cleared )
+ || $form->dberror($query);
+ }
+
+ # gain/loss
+ $amount = $form->round_amount(
+ (
+ $form->round_amount(
+ $form->{"paid_$i"} * $form->{exchangerate}, 2 ) -
+ $form->round_amount(
+ $form->{"paid_$i"} * $form->{"exchangerate_$i"}, 2
+ )
+ ) * -1,
+ 2
+ );
+
+ if ($amount) {
+ my $accno_id =
+ ( $amount > 0 )
+ ? $fxgain_accno_id
+ : $fxloss_accno_id;
+
+ $query = qq|
INSERT INTO acc_trans (
trans_id, chart_id, amount,
transdate, fx_transaction,
cleared)
VALUES (?, ?, ?, ?, '1', ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $accno_id, $amount,
- $form->{"datepaid_$i"}, $cleared)
- || $form->dberror($query);
- }
-
- # update exchange rate
- if (($form->{currency} ne $form->{defaultcurrency})
- && !$exchangerate) {
-
- $form->update_exchangerate(
- $dbh, $form->{currency},
- $form->{"datepaid_$i"},
- $form->{"exchangerate_$i"}, 0);
- }
- }
- }
-
- # set values which could be empty to 0
- $form->{terms} *= 1;
- $form->{taxincluded} *= 1;
-
-
- $form->{invnumber} =
- $form->update_defaults($myconfig, "sinumber", $dbh)
- unless $form->{invnumber};
-
- # save AR record
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $accno_id, $amount,
+ $form->{"datepaid_$i"}, $cleared )
+ || $form->dberror($query);
+ }
+
+ # update exchange rate
+ if ( ( $form->{currency} ne $form->{defaultcurrency} )
+ && !$exchangerate )
+ {
+
+ $form->update_exchangerate(
+ $dbh, $form->{currency},
+ $form->{"datepaid_$i"},
+ $form->{"exchangerate_$i"}, 0
+ );
+ }
+ }
+ }
+
+ # set values which could be empty to 0
+ $form->{terms} *= 1;
+ $form->{taxincluded} *= 1;
+
+ $form->{invnumber} = $form->update_defaults( $myconfig, "sinumber", $dbh )
+ unless $form->{invnumber};
+
+ # save AR record
+ $query = qq|
UPDATE ar set
invnumber = ?,
ordnumber = ?,
@@ -1404,49 +1389,52 @@ sub post_invoice {
WHERE id = ?
|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{invnumber}, $form->{ordnumber}, $form->{quonumber},
- $form->{transdate}, $form->{customer_id}, $invamount,
- $invnetamount, $form->{paid}, $form->{datepaid},
- $form->{duedate}, $form->{shippingpoint}, $form->{shipvia},
- $form->{terms}, $form->{notes}, $form->{intnotes},
- $form->{taxincluded}, $form->{currency}, $form->{department_id},
- $form->{employee_id}, $till, $form->{language_code},
- $form->{ponumber}, $form->{id})
- || $form->dberror($query);
-
- # add shipto
- $form->{name} = $form->{customer};
- $form->{name} =~ s/--$form->{customer_id}//;
- $form->add_shipto($dbh, $form->{id});
-
- # save printed, emailed and queued
- $form->save_status($dbh);
-
- my %audittrail = (
- tablename => 'ar',
- reference => $form->{invnumber},
- formname => $form->{type},
- action => 'posted',
- id => $form->{id} );
-
- $form->audittrail($dbh, "", \%audittrail);
-
- $form->save_recurring($dbh, $myconfig);
-
- my $rc = $dbh->commit;
-
-
- $rc;
-
-}
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{invnumber}, $form->{ordnumber},
+ $form->{quonumber}, $form->{transdate},
+ $form->{customer_id}, $invamount,
+ $invnetamount, $form->{paid},
+ $form->{datepaid}, $form->{duedate},
+ $form->{shippingpoint}, $form->{shipvia},
+ $form->{terms}, $form->{notes},
+ $form->{intnotes}, $form->{taxincluded},
+ $form->{currency}, $form->{department_id},
+ $form->{employee_id}, $till,
+ $form->{language_code}, $form->{ponumber},
+ $form->{id}
+ ) || $form->dberror($query);
+
+ # add shipto
+ $form->{name} = $form->{customer};
+ $form->{name} =~ s/--$form->{customer_id}//;
+ $form->add_shipto( $dbh, $form->{id} );
+
+ # save printed, emailed and queued
+ $form->save_status($dbh);
+
+ my %audittrail = (
+ tablename => 'ar',
+ reference => $form->{invnumber},
+ formname => $form->{type},
+ action => 'posted',
+ id => $form->{id}
+ );
+
+ $form->audittrail( $dbh, "", \%audittrail );
+
+ $form->save_recurring( $dbh, $myconfig );
+
+ my $rc = $dbh->commit;
+
+ $rc;
+}
sub process_assembly {
- my ($dbh2, $form, $id, $totalqty, $project_id) = @_;
- my $dbh = $form->{dbh};
- my $query = qq|
+ my ( $dbh2, $form, $id, $totalqty, $project_id ) = @_;
+ my $dbh = $form->{dbh};
+ my $query = qq|
SELECT a.parts_id, a.qty, p.assembly,
p.partnumber, p.description, p.unit,
p.inventory_accno_id, p.income_accno_id,
@@ -1454,58 +1442,56 @@ sub process_assembly {
FROM assembly a
JOIN parts p ON (a.parts_id = p.id)
WHERE a.id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($id) || $form->dberror($query);
-
- my $allocated;
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- $allocated = 0;
-
- $ref->{inventory_accno_id} *= 1;
- $ref->{expense_accno_id} *= 1;
-
- # multiply by number of assemblies
- $ref->{qty} *= $totalqty;
-
- if ($ref->{assembly}) {
- &process_assembly(
- $dbh, $form, $ref->{parts_id}, $ref->{qty},
- $project_id);
- next;
- } else {
- if ($ref->{inventory_accno_id}) {
- $allocated = &cogs(
- $dbh, $form, $ref->{parts_id},
- $ref->{qty}, $project_id);
- }
- }
-
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute($id) || $form->dberror($query);
+
+ my $allocated;
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ $allocated = 0;
+
+ $ref->{inventory_accno_id} *= 1;
+ $ref->{expense_accno_id} *= 1;
+
+ # multiply by number of assemblies
+ $ref->{qty} *= $totalqty;
+
+ if ( $ref->{assembly} ) {
+ &process_assembly( $dbh, $form, $ref->{parts_id}, $ref->{qty},
+ $project_id );
+ next;
+ }
+ else {
+ if ( $ref->{inventory_accno_id} ) {
+ $allocated =
+ &cogs( $dbh, $form, $ref->{parts_id}, $ref->{qty},
+ $project_id );
+ }
+ }
+
+ $query = qq|
INSERT INTO invoice
(trans_id, description, parts_id, qty,
sellprice, fxsellprice, allocated,
assemblyitem, unit)
VALUES (?, ?, ?, ?, 0, 0, ?, 't', ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $ref->{description}, $ref->{parts_id},
- $ref->{qty}, $allocated, $ref->{unit})
- || $form->dberror($query);
-
- }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $ref->{description}, $ref->{parts_id},
+ $ref->{qty}, $allocated, $ref->{unit} )
+ || $form->dberror($query);
- $sth->finish;
+ }
-}
+ $sth->finish;
+}
sub cogs {
- my ($dbh2, $form, $id, $totalqty, $project_id) = @_;
- my $dbh = $form->{dbh};
- my $query = qq|
+ my ( $dbh2, $form, $id, $totalqty, $project_id ) = @_;
+ my $dbh = $form->{dbh};
+ my $query = qq|
SELECT i.id, i.trans_id, i.qty, i.allocated, i.sellprice,
i.fxsellprice, p.inventory_accno_id,
p.expense_accno_id
@@ -1514,235 +1500,235 @@ sub cogs {
AND i.parts_id = ?
AND (i.qty + i.allocated) < 0
ORDER BY trans_id|;
- my $sth = $dbh->prepare($query);
- $sth->execute($id) || $form->dberror($query);
-
- my $allocated = 0;
- my $qty;
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- if (($qty = (($ref->{qty} * -1) - $ref->{allocated}))
- > $totalqty) {
- $qty = $totalqty;
- }
-
- $form->update_balance(
- $dbh, "invoice", "allocated", qq|id = $ref->{id}|,
- $qty);
-
- # total expenses and inventory
- # sellprice is the cost of the item
- my $linetotal = $form->round_amount(
- $ref->{sellprice} * $qty, 2);
-
- # add expense
- push @{ $form->{acc_trans}{lineitems} }, {
- chart_id => $ref->{expense_accno_id},
- amount => $linetotal * -1,
- project_id => $project_id,
- invoice_id => $ref->{id} };
-
- # deduct inventory
- push @{ $form->{acc_trans}{lineitems} }, {
- chart_id => $ref->{inventory_accno_id},
- amount => $linetotal,
- project_id => $project_id,
- invoice_id => $ref->{id} };
-
- # add allocated
- $allocated += -$qty;
-
- last if (($totalqty -= $qty) <= 0);
- }
-
- $sth->finish;
-
- $allocated;
- $dbh->commit;
+ my $sth = $dbh->prepare($query);
+ $sth->execute($id) || $form->dberror($query);
+
+ my $allocated = 0;
+ my $qty;
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ if ( ( $qty = ( ( $ref->{qty} * -1 ) - $ref->{allocated} ) ) >
+ $totalqty )
+ {
+ $qty = $totalqty;
+ }
+
+ $form->update_balance( $dbh, "invoice", "allocated",
+ qq|id = $ref->{id}|, $qty );
+
+ # total expenses and inventory
+ # sellprice is the cost of the item
+ my $linetotal = $form->round_amount( $ref->{sellprice} * $qty, 2 );
+
+ # add expense
+ push @{ $form->{acc_trans}{lineitems} },
+ {
+ chart_id => $ref->{expense_accno_id},
+ amount => $linetotal * -1,
+ project_id => $project_id,
+ invoice_id => $ref->{id}
+ };
+
+ # deduct inventory
+ push @{ $form->{acc_trans}{lineitems} },
+ {
+ chart_id => $ref->{inventory_accno_id},
+ amount => $linetotal,
+ project_id => $project_id,
+ invoice_id => $ref->{id}
+ };
+
+ # add allocated
+ $allocated += -$qty;
+
+ last if ( ( $totalqty -= $qty ) <= 0 );
+ }
+
+ $sth->finish;
+
+ $allocated;
+ $dbh->commit;
}
-
-
sub reverse_invoice {
- my ($dbh2, $form) = @_;
- my $dbh = $form->{dbh};
- my $query = qq|
+ my ( $dbh2, $form ) = @_;
+ my $dbh = $form->{dbh};
+ my $query = qq|
SELECT id FROM ar
WHERE id = ?|;
- my $sth;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id});
- my ($id) = $sth->fetchrow_array;
+ my $sth;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} );
+ my ($id) = $sth->fetchrow_array;
- return unless $id;
+ return unless $id;
- # reverse inventory items
- my $query = qq|
+ # reverse inventory items
+ my $query = qq|
SELECT i.id, i.parts_id, i.qty, i.assemblyitem, p.assembly,
p.inventory_accno_id
FROM invoice i
JOIN parts p ON (i.parts_id = p.id)
WHERE i.trans_id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- if ($ref->{inventory_accno_id} || $ref->{assembly}) {
-
- # if the invoice item is not an assemblyitem
- # adjust parts onhand
- if (!$ref->{assemblyitem}) {
- # adjust onhand in parts table
- $form->update_balance(
- $dbh, "parts", "onhand",
- qq|id = $ref->{parts_id}|, $ref->{qty});
- }
-
- # loop if it is an assembly
- next if ($ref->{assembly});
-
- # de-allocated purchases
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ if ( $ref->{inventory_accno_id} || $ref->{assembly} ) {
+
+ # if the invoice item is not an assemblyitem
+ # adjust parts onhand
+ if ( !$ref->{assemblyitem} ) {
+
+ # adjust onhand in parts table
+ $form->update_balance( $dbh, "parts", "onhand",
+ qq|id = $ref->{parts_id}|,
+ $ref->{qty} );
+ }
+
+ # loop if it is an assembly
+ next if ( $ref->{assembly} );
+
+ # de-allocated purchases
+ $query = qq|
SELECT id, trans_id, allocated
FROM invoice
WHERE parts_id = ?
AND allocated > 0
ORDER BY trans_id DESC|;
- my $sth = $dbh->prepare($query);
- $sth->execute($ref->{parts_id})
- || $form->dberror($query);
-
- while (my $inhref = $sth->fetchrow_hashref(NAME_lc)) {
- $qty = $ref->{qty};
- if (($ref->{qty} - $inhref->{allocated}) > 0) {
- $qty = $inhref->{allocated};
- }
-
- # update invoice
- $form->update_balance(
- $dbh, "invoice", "allocated",
- qq|id = $inhref->{id}|, $qty * -1);
-
- last if (($ref->{qty} -= $qty) <= 0);
- }
- $sth->finish;
- }
- }
-
- $sth->finish;
-
- # delete acc_trans
- $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
-
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- # delete invoice entries
- $query = qq|DELETE FROM invoice WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $query = qq|DELETE FROM shipto WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $dbh->commit;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $ref->{parts_id} )
+ || $form->dberror($query);
-}
+ while ( my $inhref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $qty = $ref->{qty};
+ if ( ( $ref->{qty} - $inhref->{allocated} ) > 0 ) {
+ $qty = $inhref->{allocated};
+ }
+
+ # update invoice
+ $form->update_balance( $dbh, "invoice", "allocated",
+ qq|id = $inhref->{id}|,
+ $qty * -1 );
+
+ last if ( ( $ref->{qty} -= $qty ) <= 0 );
+ }
+ $sth->finish;
+ }
+ }
+
+ $sth->finish;
+ # delete acc_trans
+ $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ # delete invoice entries
+ $query = qq|DELETE FROM invoice WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $query = qq|DELETE FROM shipto WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $dbh->commit;
+
+}
sub delete_invoice {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
- my $sth;
-
- &reverse_invoice($dbh, $form);
-
- my %audittrail = (
- tablename => 'ar',
- reference => $form->{invnumber},
- formname => $form->{type},
- action => 'deleted',
- id => $form->{id} );
-
- $form->audittrail($dbh, "", \%audittrail);
-
- # delete AR record
- my $query = qq|DELETE FROM ar WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- # delete spool files
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+ my $sth;
+
+ &reverse_invoice( $dbh, $form );
+
+ my %audittrail = (
+ tablename => 'ar',
+ reference => $form->{invnumber},
+ formname => $form->{type},
+ action => 'deleted',
+ id => $form->{id}
+ );
+
+ $form->audittrail( $dbh, "", \%audittrail );
+
+ # delete AR record
+ my $query = qq|DELETE FROM ar WHERE id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ # delete spool files
+ $query = qq|
SELECT spoolfile FROM status
WHERE trans_id = $form->{id} AND spoolfile IS NOT NULL|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- my $spoolfile;
- my @spoolfiles = ();
-
- while (($spoolfile) = $sth->fetchrow_array) {
- push @spoolfiles, $spoolfile;
- }
- $sth->finish;
-
- # delete status entries
- $query = qq|DELETE FROM status WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- my $rc = $dbh->commit;
-
- if ($rc) {
- foreach $spoolfile (@spoolfiles) {
- unlink "${LedgerSMB::Sysconfig::spool}/$spoolfile"
- if $spoolfile;
- }
- }
-
- $dbh->commit;
-
- $rc;
-
-}
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ my $spoolfile;
+ my @spoolfiles = ();
+ while ( ($spoolfile) = $sth->fetchrow_array ) {
+ push @spoolfiles, $spoolfile;
+ }
+ $sth->finish;
+ # delete status entries
+ $query = qq|DELETE FROM status WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ my $rc = $dbh->commit;
+
+ if ($rc) {
+ foreach $spoolfile (@spoolfiles) {
+ unlink "${LedgerSMB::Sysconfig::spool}/$spoolfile"
+ if $spoolfile;
+ }
+ }
+
+ $dbh->commit;
+
+ $rc;
+
+}
sub retrieve_invoice {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
- my $query;
+ my $query;
- if ($form->{id}) {
- # get default accounts and last invoice number
- $query = qq|
+ if ( $form->{id} ) {
+
+ # get default accounts and last invoice number
+ $query = qq|
SELECT value AS currencies FROM defaults
WHERE setting_key = 'curr'|;
- } else {
- $query = qq|
+ }
+ else {
+ $query = qq|
SELECT value AS currencies, current_date AS transdate
FROM defaults
WHERE setting_key = 'curr'|;
- }
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- my $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
-
-
- if ($form->{id}) {
-
- # retrieve invoice
- $query = qq|
+ }
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
+
+ if ( $form->{id} ) {
+
+ # retrieve invoice
+ $query = qq|
SELECT a.invnumber, a.ordnumber, a.quonumber,
a.transdate, a.paid,
a.shippingpoint, a.shipvia, a.terms, a.notes,
@@ -1755,24 +1741,24 @@ sub retrieve_invoice {
LEFT JOIN employees e ON (e.id = a.employee_id)
WHERE a.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
- # get shipto
- $query = qq|SELECT * FROM shipto WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ # get shipto
+ $query = qq|SELECT * FROM shipto WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
- # retrieve individual items
- $query = qq|
+ # retrieve individual items
+ $query = qq|
SELECT i.description, i.qty, i.fxsellprice,
i.sellprice, i.discount, i.parts_id AS id,
i.unit, i.deliverydate, i.project_id,
@@ -1794,115 +1780,116 @@ sub retrieve_invoice {
WHERE i.trans_id = ?
AND NOT i.assemblyitem = '1'
ORDER BY i.id|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{language_code}, $form->{id})
- || $form->dberror($query);
-
- # foreign currency
- &exchangerate_defaults($dbh, $form);
-
- # query for price matrix
- my $pmh = PriceMatrix::price_matrix_query($dbh, $form);
-
- # taxes
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{language_code}, $form->{id} )
+ || $form->dberror($query);
+
+ # foreign currency
+ &exchangerate_defaults( $dbh, $form );
+
+ # query for price matrix
+ my $pmh = PriceMatrix::price_matrix_query( $dbh, $form );
+
+ # taxes
+ $query = qq|
SELECT c.accno
FROM chart c
JOIN partstax pt ON (pt.chart_id = c.id)
WHERE pt.parts_id = ?|;
- my $tth = $dbh->prepare($query) || $form->dberror($query);
-
- my $taxrate;
- my $ptref;
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- my ($dec) = ($ref->{fxsellprice} =~ /\.(\d+)/);
- $dec = length $dec;
- my $decimalplaces = ($dec > 2) ? $dec : 2;
-
- $tth->execute($ref->{id});
-
- $ref->{taxaccounts} = "";
- $taxrate = 0;
-
- while ($ptref = $tth->fetchrow_hashref(NAME_lc)) {
- $ref->{taxaccounts} .= "$ptref->{accno} ";
- $taxrate += $form->{"$ptref->{accno}_rate"};
- }
- $tth->finish;
- chop $ref->{taxaccounts};
-
- # price matrix
- $ref->{sellprice} =
- ($ref->{fxsellprice}
- * $form->{$form->{currency}});
- PriceMatrix::price_matrix(
- $pmh, $ref, $form->{transdate}, $decimalplaces,
- $form, $myconfig);
- $ref->{sellprice} = $ref->{fxsellprice};
-
- $ref->{partsgroup} = $ref->{partsgrouptranslation}
- if $ref->{partsgrouptranslation};
-
- push @{ $form->{invoice_details} }, $ref;
- }
- $sth->finish;
-
- }
-
-
- @queries = $form->run_custom_queries('ar', 'SELECT');
- my $rc = $dbh->commit;
- $rc;
+ my $tth = $dbh->prepare($query) || $form->dberror($query);
-}
+ my $taxrate;
+ my $ptref;
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ my ($dec) = ( $ref->{fxsellprice} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ $tth->execute( $ref->{id} );
+
+ $ref->{taxaccounts} = "";
+ $taxrate = 0;
+
+ while ( $ptref = $tth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{taxaccounts} .= "$ptref->{accno} ";
+ $taxrate += $form->{"$ptref->{accno}_rate"};
+ }
+ $tth->finish;
+ chop $ref->{taxaccounts};
+ # price matrix
+ $ref->{sellprice} =
+ ( $ref->{fxsellprice} * $form->{ $form->{currency} } );
+ PriceMatrix::price_matrix( $pmh, $ref, $form->{transdate},
+ $decimalplaces, $form, $myconfig );
+ $ref->{sellprice} = $ref->{fxsellprice};
+
+ $ref->{partsgroup} = $ref->{partsgrouptranslation}
+ if $ref->{partsgrouptranslation};
+
+ push @{ $form->{invoice_details} }, $ref;
+ }
+ $sth->finish;
+
+ }
+
+ @queries = $form->run_custom_queries( 'ar', 'SELECT' );
+ my $rc = $dbh->commit;
+ $rc;
+
+}
sub retrieve_item {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my $i = $form->{rowcount};
- my $null;
- my $var;
-
- my $where = "WHERE p.obsolete = '0' AND NOT p.income_accno_id IS NULL";
-
- if ($form->{"partnumber_$i"} ne "") {
- $var = $dbh->quote($form->like(lc $form->{"partnumber_$i"}));
- $where .= " AND lower(p.partnumber) LIKE $var";
- }
- if ($form->{"description_$i"} ne "") {
- $var = $dbh->quote($form->like(lc $form->{"description_$i"}));
-
- if ($form->{language_code} ne "") {
- $where .= " AND lower(t1.description) LIKE $var";
- } else {
- $where .= " AND lower(p.description) LIKE $var";
- }
- }
-
- if ($form->{"partsgroup_$i"} ne "") {
- ($null, $var) = split /--/, $form->{"partsgroup_$i"};
- $var = $dbh->quote($var);
- if ($var == 0) {
- # search by partsgroup, this is for the POS
- $where .= qq| AND pg.partsgroup = |.
- $dbh->quote($form->{"partsgroup_$i"});
- } else {
- $where .= qq| AND p.partsgroup_id = $var|;
- }
- }
-
- if ($form->{"description_$i"} ne "") {
- $where .= " ORDER BY 3";
- } else {
- $where .= " ORDER BY 2";
- }
-
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my $i = $form->{rowcount};
+ my $null;
+ my $var;
+
+ my $where = "WHERE p.obsolete = '0' AND NOT p.income_accno_id IS NULL";
+
+ if ( $form->{"partnumber_$i"} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{"partnumber_$i"} ) );
+ $where .= " AND lower(p.partnumber) LIKE $var";
+ }
+ if ( $form->{"description_$i"} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{"description_$i"} ) );
+
+ if ( $form->{language_code} ne "" ) {
+ $where .= " AND lower(t1.description) LIKE $var";
+ }
+ else {
+ $where .= " AND lower(p.description) LIKE $var";
+ }
+ }
+
+ if ( $form->{"partsgroup_$i"} ne "" ) {
+ ( $null, $var ) = split /--/, $form->{"partsgroup_$i"};
+ $var = $dbh->quote($var);
+ if ( $var == 0 ) {
+
+ # search by partsgroup, this is for the POS
+ $where .=
+ qq| AND pg.partsgroup = |
+ . $dbh->quote( $form->{"partsgroup_$i"} );
+ }
+ else {
+ $where .= qq| AND p.partsgroup_id = $var|;
+ }
+ }
+
+ if ( $form->{"description_$i"} ne "" ) {
+ $where .= " ORDER BY 3";
+ }
+ else {
+ $where .= " ORDER BY 2";
+ }
+
+ my $query = qq|
SELECT p.id, p.partnumber, p.description, p.sellprice,
p.listprice, p.lastcost, p.unit, p.assembly, p.bin,
p.onhand, p.notes, p.inventory_accno_id,
@@ -1918,120 +1905,115 @@ sub retrieve_item {
ON (t2.trans_id = p.partsgroup_id
AND t2.language_code = ?)
$where|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{language_code}, $form->{language_code})
- || $form->dberror($query);
-
- my $ref;
- my $ptref;
-
- # setup exchange rates
- &exchangerate_defaults($dbh, $form);
-
- # taxes
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{language_code}, $form->{language_code} )
+ || $form->dberror($query);
+
+ my $ref;
+ my $ptref;
+
+ # setup exchange rates
+ &exchangerate_defaults( $dbh, $form );
+
+ # taxes
+ $query = qq|
SELECT c.accno
FROM chart c
JOIN partstax pt ON (c.id = pt.chart_id)
WHERE pt.parts_id = ?|;
- my $tth = $dbh->prepare($query) || $form->dberror($query);
+ my $tth = $dbh->prepare($query) || $form->dberror($query);
+ # price matrix
+ my $pmh = PriceMatrix::price_matrix_query( $dbh, $form );
- # price matrix
- my $pmh = PriceMatrix::price_matrix_query($dbh, $form);
+ my $transdate = $form->datetonum( $myconfig, $form->{transdate} );
- my $transdate = $form->datetonum($myconfig, $form->{transdate});
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
- my ($dec) = ($ref->{sellprice} =~ /\.(\d+)/);
- $dec = length $dec;
- my $decimalplaces = ($dec > 2) ? $dec : 2;
+ my ($dec) = ( $ref->{sellprice} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
- # get taxes for part
- $tth->execute($ref->{id});
+ # get taxes for part
+ $tth->execute( $ref->{id} );
- $ref->{taxaccounts} = "";
+ $ref->{taxaccounts} = "";
- while ($ptref = $tth->fetchrow_hashref(NAME_lc)) {
- $ref->{taxaccounts} .= "$ptref->{accno} ";
- }
- $tth->finish;
- chop $ref->{taxaccounts};
+ while ( $ptref = $tth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{taxaccounts} .= "$ptref->{accno} ";
+ }
+ $tth->finish;
+ chop $ref->{taxaccounts};
- # get matrix
- PriceMatrix::price_matrix(
- $pmh, $ref, $transdate, $decimalplaces, $form,
- $myconfig);
+ # get matrix
+ PriceMatrix::price_matrix( $pmh, $ref, $transdate, $decimalplaces,
+ $form, $myconfig );
- $ref->{description} = $ref->{translation}
- if $ref->{translation};
+ $ref->{description} = $ref->{translation}
+ if $ref->{translation};
- $ref->{partsgroup} = $ref->{grouptranslation}
- if $ref->{grouptranslation};
-
- push @{ $form->{item_list} }, $ref;
+ $ref->{partsgroup} = $ref->{grouptranslation}
+ if $ref->{grouptranslation};
- }
-
- $sth->finish;
- $dbh->commit;
-
-}
+ push @{ $form->{item_list} }, $ref;
+
+ }
+
+ $sth->finish;
+ $dbh->commit;
+}
sub exchangerate_defaults {
- my ($dbh2, $form) = @_;
- $dbh = $form->{dbh};
+ my ( $dbh2, $form ) = @_;
+ $dbh = $form->{dbh};
+ my $var;
- my $var;
-
- # get default currencies
- my $query = qq|
+ # get default currencies
+ my $query = qq|
SELECT substr(value,1,3), value FROM defaults
WHERE setting_key = 'curr'|;
- my $eth = $dbh->prepare($query) || $form->dberror($query);
- $eth->execute;
- ($form->{defaultcurrency}, $form->{currencies}) = $eth->fetchrow_array;
- $eth->finish;
+ my $eth = $dbh->prepare($query) || $form->dberror($query);
+ $eth->execute;
+ ( $form->{defaultcurrency}, $form->{currencies} ) = $eth->fetchrow_array;
+ $eth->finish;
- $query = qq|
+ $query = qq|
SELECT buy
FROM exchangerate
WHERE curr = ?
AND transdate = ?|;
- my $eth1 = $dbh->prepare($query) || $form->dberror($query);
+ my $eth1 = $dbh->prepare($query) || $form->dberror($query);
- $query = qq/
+ $query = qq/
SELECT max(transdate || ' ' || buy || ' ' || curr)
FROM exchangerate
WHERE curr = ?/;
- my $eth2 = $dbh->prepare($query) || $form->dberror($query);
-
- # get exchange rates for transdate or max
- foreach $var (split /:/, substr($form->{currencies},4)) {
- $eth1->execute($var, $form->{transdate});
- ($form->{$var}) = $eth1->fetchrow_array;
-
- if (! $form->{$var} ) {
- $eth2->execute($var);
-
- ($form->{$var}) = $eth2->fetchrow_array;
- ($null, $form->{$var}) = split / /, $form->{$var};
- $form->{$var} = 1 unless $form->{$var};
- $eth2->finish;
- }
- $eth1->finish;
- }
-
- $form->{$form->{currency}} = $form->{exchangerate}
- if $form->{exchangerate};
- $form->{$form->{currency}} ||= 1;
- $form->{$form->{defaultcurrency}} = 1;
+ my $eth2 = $dbh->prepare($query) || $form->dberror($query);
-}
+ # get exchange rates for transdate or max
+ foreach $var ( split /:/, substr( $form->{currencies}, 4 ) ) {
+ $eth1->execute( $var, $form->{transdate} );
+ ( $form->{$var} ) = $eth1->fetchrow_array;
+
+ if ( !$form->{$var} ) {
+ $eth2->execute($var);
+ ( $form->{$var} ) = $eth2->fetchrow_array;
+ ( $null, $form->{$var} ) = split / /, $form->{$var};
+ $form->{$var} = 1 unless $form->{$var};
+ $eth2->finish;
+ }
+ $eth1->finish;
+ }
+
+ $form->{ $form->{currency} } = $form->{exchangerate}
+ if $form->{exchangerate};
+ $form->{ $form->{currency} } ||= 1;
+ $form->{ $form->{defaultcurrency} } = 1;
+
+}
1;
diff --git a/LedgerSMB/Inifile.pm b/LedgerSMB/Inifile.pm
index 839c19f3..1b89502c 100644
--- a/LedgerSMB/Inifile.pm
+++ b/LedgerSMB/Inifile.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -35,60 +35,57 @@
package Inifile;
-
sub new {
- my ($type, $file) = @_;
+ my ( $type, $file ) = @_;
- warn "$type has no copy constructor! creating a new object."
- if ref($type);
- $type = ref($type) || $type;
- my $self = bless {}, $type;
- $self->add_file($file) if defined $file;
+ warn "$type has no copy constructor! creating a new object."
+ if ref($type);
+ $type = ref($type) || $type;
+ my $self = bless {}, $type;
+ $self->add_file($file) if defined $file;
- return $self;
+ return $self;
}
-
sub add_file {
- my ($self, $file) = @_;
-
- my $id = "";
- my %menuorder = ();
-
- for (@{$self->{ORDER}}) { $menuorder{$_} = 1 }
-
- open FH, '<', "$file" or Form->error("$file : $!");
-
- while (<FH>) {
- next if /^(#|;|\s)/;
- last if /^\./;
-
- chop;
-
- # strip comments
- s/\s*(#|;).*//g;
-
- # remove any trailing whitespace
- s/^\s*(.*?)\s*$/$1/;
-
- if (/^\[/) {
- s/(\[|\])//g;
- $id = $_;
- push @{$self->{ORDER}}, $_ if ! $menuorder{$_};
- $menuorder{$_} = 1;
- next;
- }
-
- # add key=value to $id
- my ($key, $value) = split /=/, $_, 2;
-
- $self->{$id}{$key} = $value;
-
- }
- close FH;
-
-}
+ my ( $self, $file ) = @_;
+
+ my $id = "";
+ my %menuorder = ();
+
+ for ( @{ $self->{ORDER} } ) { $menuorder{$_} = 1 }
+
+ open FH, '<', "$file" or Form->error("$file : $!");
+
+ while (<FH>) {
+ next if /^(#|;|\s)/;
+ last if /^\./;
+ chop;
+
+ # strip comments
+ s/\s*(#|;).*//g;
+
+ # remove any trailing whitespace
+ s/^\s*(.*?)\s*$/$1/;
+
+ if (/^\[/) {
+ s/(\[|\])//g;
+ $id = $_;
+ push @{ $self->{ORDER} }, $_ if !$menuorder{$_};
+ $menuorder{$_} = 1;
+ next;
+ }
+
+ # add key=value to $id
+ my ( $key, $value ) = split /=/, $_, 2;
+
+ $self->{$id}{$key} = $value;
+
+ }
+ close FH;
+
+}
1;
diff --git a/LedgerSMB/JC.pm b/LedgerSMB/JC.pm
index fb82c8ee..0fdbcdb9 100644
--- a/LedgerSMB/JC.pm
+++ b/LedgerSMB/JC.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -19,7 +19,7 @@
# Author: DWS Systems Inc.
# Web: http://www.sql-ledger.org
#
-# Contributors:
+# Contributors:
#
#======================================================================
#
@@ -31,32 +31,31 @@
#
#======================================================================
-
package JC;
use LedgerSMB::IS;
use LedgerSMB::PriceMatrix;
use LedgerSMB::Sysconfig;
-
sub get_jcitems {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my $query = qq|SELECT current_date|;
- ($form->{transdate}) = $dbh->selectrow_array($query);
-
- ($form->{employee}, $form->{employee_id}) = $form->get_employee($dbh);
-
- my $dateformat = $myconfig->{dateformat};
- $dateformat =~ s/yy/yyyy/;
- $dateformat =~ s/yyyyyy/yyyy/;
-
- if ($form->{id}) {
- # retrieve timecard/storescard
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my $query = qq|SELECT current_date|;
+ ( $form->{transdate} ) = $dbh->selectrow_array($query);
+
+ ( $form->{employee}, $form->{employee_id} ) = $form->get_employee($dbh);
+
+ my $dateformat = $myconfig->{dateformat};
+ $dateformat =~ s/yy/yyyy/;
+ $dateformat =~ s/yyyyyy/yyyy/;
+
+ if ( $form->{id} ) {
+
+ # retrieve timecard/storescard
+ $query = qq|
SELECT j.*, to_char(j.checkedin, 'HH24:MI:SS')
AS checkedina,
to_char(j.checkedout, 'HH24:MI:SS')
@@ -72,124 +71,123 @@ sub get_jcitems {
JOIN parts p ON (p.id = j.parts_id)
JOIN project pr ON (pr.id = j.project_id)
WHERE j.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($dateformat, $form->{id})
- || $form->dberror($query);
-
- $ref = $sth->fetchrow_hashref(NAME_lc);
-
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
- $form->{project} = ($form->{project}) ? "job" : "project";
- for (qw(checkedin checkedout)) {
- $form->{$_} = $form->{"${_}a"};
- delete $form->{"${_}a"};
- }
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $dateformat, $form->{id} )
+ || $form->dberror($query);
+
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
+ $form->{project} = ( $form->{project} ) ? "job" : "project";
+ for (qw(checkedin checkedout)) {
+ $form->{$_} = $form->{"${_}a"};
+ delete $form->{"${_}a"};
+ }
+
+ $query = qq|
SELECT s.printed, s.spoolfile, s.formname
FROM status s
WHERE s.formname = ?
AND s.trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{type}, $form->{id})
- || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $form->{printed} .= "$ref->{formname} "
- if $ref->{printed};
- $form->{queued} .=
- "$ref->{formname} $ref->{spoolfile} "
- if $ref->{spoolfile};
- }
- $sth->finish;
- for (qw(printed queued)) { $form->{$_} =~ s/ +$//g }
- }
-
- JC->jcitems_links($myconfig, $form, $dbh);
-
- # get language codes
- $query = qq|SELECT * FROM language ORDER BY 2|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- $form->{all_language} = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_language} }, $ref;
- }
- $sth->finish;
-
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{type}, $form->{id} )
+ || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $form->{printed} .= "$ref->{formname} "
+ if $ref->{printed};
+ $form->{queued} .= "$ref->{formname} $ref->{spoolfile} "
+ if $ref->{spoolfile};
+ }
+ $sth->finish;
+ for (qw(printed queued)) { $form->{$_} =~ s/ +$//g }
+ }
+
+ JC->jcitems_links( $myconfig, $form, $dbh );
+
+ # get language codes
+ $query = qq|SELECT * FROM language ORDER BY 2|;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ $form->{all_language} = ();
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_language} }, $ref;
+ }
+ $sth->finish;
+
+ $dbh->commit;
}
-
sub jcitems_links {
- my ($self, $myconfig, $form, $dbh) = @_;
-
- my $disconnect = 0;
-
- if (! $dbh) {
- $dbh = $form->{dbh};
- }
-
- my $query;
-
- if ($form->{project_id}) {
- $form->{orphaned} = 1;
- $query = qq|SELECT parts_id FROM project WHERE id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{project_id});
-
- if ($sth->fetchrow_array) {
- $form->{project} = 'job';
- $query = qq|
+ my ( $self, $myconfig, $form, $dbh ) = @_;
+
+ my $disconnect = 0;
+
+ if ( !$dbh ) {
+ $dbh = $form->{dbh};
+ }
+
+ my $query;
+
+ if ( $form->{project_id} ) {
+ $form->{orphaned} = 1;
+ $query = qq|SELECT parts_id FROM project WHERE id = ?|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{project_id} );
+
+ if ( $sth->fetchrow_array ) {
+ $form->{project} = 'job';
+ $query = qq|
SELECT id
FROM project
WHERE parts_id > 0
AND production > completed
AND id = $form->{project_id}|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{project_id});
- ($form->{orphaned}) = $sth->fetchrow_array();
- $sth->finish;
- } else {
- $form->{project} = 'project';
- }
- $sth->finish;
- }
-
- JC->jcparts($myconfig, $form, $dbh);
-
- $form->all_employees($myconfig, $dbh, $form->{transdate});
-
- my $where;
-
- if ($form->{transdate}) {
- $where .= qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{project_id} );
+ ( $form->{orphaned} ) = $sth->fetchrow_array();
+ $sth->finish;
+ }
+ else {
+ $form->{project} = 'project';
+ }
+ $sth->finish;
+ }
+
+ JC->jcparts( $myconfig, $form, $dbh );
+
+ $form->all_employees( $myconfig, $dbh, $form->{transdate} );
+
+ my $where;
+
+ if ( $form->{transdate} ) {
+ $where .= qq|
AND (enddate IS NULL
- OR enddate >= |.
- $dbh->quote($form->{transdate}).qq|)
- AND (startdate <= |.
- $dbh->quote($form->{transdate}).qq|
+ OR enddate >= | . $dbh->quote( $form->{transdate} ) . qq|)
+ AND (startdate <= | . $dbh->quote( $form->{transdate} ) . qq|
OR startdate IS NULL)|;
- }
-
- if ($form->{project} eq 'job') {
- $query = qq|
+ }
+
+ if ( $form->{project} eq 'job' ) {
+ $query = qq|
SELECT pr.*
FROM project pr
WHERE pr.parts_id > 0
AND pr.production > pr.completed
$where|;
- } elsif ($form->{project} eq 'project') {
- $query = qq|
+ }
+ elsif ( $form->{project} eq 'project' ) {
+ $query = qq|
SELECT pr.*
FROM project pr
WHERE pr.parts_id IS NULL
$where|;
- } else {
- $query = qq|
+ }
+ else {
+ $query = qq|
SELECT pr.*
FROM project pr
WHERE 1=1
@@ -199,49 +197,48 @@ sub jcitems_links {
FROM project pr
WHERE pr.parts_id > 0
AND pr.production = pr.completed|;
- }
+ }
- if ($form->{project_id}) {
- $query .= qq|
+ if ( $form->{project_id} ) {
+ $query .= qq|
UNION
SELECT *
FROM project
- WHERE id = |.$dbh->quote($form->{project_id});
- }
-
- $query .= qq|
+ WHERE id = | . $dbh->quote( $form->{project_id} );
+ }
+
+ $query .= qq|
ORDER BY projectnumber|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_project} }, $ref;
- }
- $sth->finish;
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_project} }, $ref;
+ }
+ $sth->finish;
}
-
sub jcparts {
- my ($self, $myconfig, $form, $dbh) = @_;
-
- my ($null, $project_id) = split /--/, $form->{projectnumber};
- $project_id = $dbh->quote($project_id);
-
- my $query = qq|SELECT customer_id FROM project WHERE id = $project_id|;
- my ($customer_id) = $dbh->selectrow_array($query);
- $customer_id = $dbh->quote($customer_id);;
-
- my $where;
-
- if ($form->{project} eq 'job') {
- $where = " AND p.income_accno_id IS NULL";
- if ($form->{type} eq 'storescard') {
- $where = " AND p.inventory_accno_id > 0
+ my ( $self, $myconfig, $form, $dbh ) = @_;
+
+ my ( $null, $project_id ) = split /--/, $form->{projectnumber};
+ $project_id = $dbh->quote($project_id);
+
+ my $query = qq|SELECT customer_id FROM project WHERE id = $project_id|;
+ my ($customer_id) = $dbh->selectrow_array($query);
+ $customer_id = $dbh->quote($customer_id);
+
+ my $where;
+
+ if ( $form->{project} eq 'job' ) {
+ $where = " AND p.income_accno_id IS NULL";
+ if ( $form->{type} eq 'storescard' ) {
+ $where = " AND p.inventory_accno_id > 0
AND p.income_accno_id > 0";
- }
-
- $query = qq|
+ }
+
+ $query = qq|
SELECT p.id, p.partnumber, p.description,
p.sellprice,
p.unit, t.description AS translation
@@ -249,16 +246,17 @@ sub jcparts {
LEFT JOIN translation t
ON (t.trans_id = p.id
AND t.language_code
- = |.$dbh->quote($form->{language_code}).qq|)
+ = | . $dbh->quote( $form->{language_code} ) . qq|)
WHERE p.obsolete = '0'
$where|;
- } elsif ($form->{project} eq 'project') {
- $where = " AND p.inventory_accno_id IS NULL";
- if ($form->{type} eq 'storescard') {
- $where = " AND p.inventory_accno_id > 0";
- }
-
- $query = qq|
+ }
+ elsif ( $form->{project} eq 'project' ) {
+ $where = " AND p.inventory_accno_id IS NULL";
+ if ( $form->{type} eq 'storescard' ) {
+ $where = " AND p.inventory_accno_id > 0";
+ }
+
+ $query = qq|
SELECT p.id, p.partnumber, p.description,
p.sellprice, p.unit,
t.description AS translation
@@ -266,12 +264,13 @@ sub jcparts {
LEFT JOIN translation t
ON (t.trans_id = p.id
AND t.language_code
- = |.$dbh->quote($form->{language_code}).qq|)
+ = | . $dbh->quote( $form->{language_code} ) . qq|)
WHERE p.obsolete = '0'
AND p.assembly = '0' $where|;
- } else {
-
- $query = qq|
+ }
+ else {
+
+ $query = qq|
SELECT p.id, p.partnumber, p.description,
p.sellprice, p.unit,
t.description AS translation
@@ -279,7 +278,7 @@ sub jcparts {
LEFT JOIN translation t
ON (t.trans_id = p.id
AND t.language_code
- = |.$dbh->quote($form->{language_code}).qq|)
+ = | . $dbh->quote( $form->{language_code} ) . qq|)
WHERE p.obsolete = '0'
AND p.income_accno_id IS NULL
UNION
@@ -290,185 +289,183 @@ sub jcparts {
LEFT JOIN translation t
ON (t.trans_id = p.id
AND t.language_code
- = |.$dbh->quote($form->{language_code}).qq|)
+ = | . $dbh->quote( $form->{language_code} ) . qq|)
WHERE p.obsolete = '0'
AND p.assembly = '0'
AND p.inventory_accno_id IS NULL|;
- }
+ }
- $query .= qq|
+ $query .= qq|
ORDER BY 2|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- my $pmh = PriceMatrix::price_matrix_query($dbh, $form);
- IS::exchangerate_defaults($dbh, $form);
+ my $pmh = PriceMatrix::price_matrix_query( $dbh, $form );
+ IS::exchangerate_defaults( $dbh, $form );
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{description} = $ref->{translation}
- if $ref->{translation};
- PriceMatrix::price_matrix(
- $pmh, $ref, $form->{transdate}, 4, $form, $myconfig);
- push @{ $form->{all_parts} }, $ref;
- }
- $sth->finish;
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{description} = $ref->{translation}
+ if $ref->{translation};
+ PriceMatrix::price_matrix( $pmh, $ref, $form->{transdate}, 4, $form,
+ $myconfig );
+ push @{ $form->{all_parts} }, $ref;
+ }
+ $sth->finish;
}
-
sub delete_timecard {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my %audittrail = (
- tablename => 'jcitems',
- reference => $form->{id},
- formname => $form->{type},
- action => 'deleted',
- id => $form->{id} );
-
- $form->audittrail($dbh, "", \%audittrail);
-
- my $query = qq|DELETE FROM jcitems WHERE id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id})|| $form->dberror($query);
-
- # delete spool files
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my %audittrail = (
+ tablename => 'jcitems',
+ reference => $form->{id},
+ formname => $form->{type},
+ action => 'deleted',
+ id => $form->{id}
+ );
+
+ $form->audittrail( $dbh, "", \%audittrail );
+
+ my $query = qq|DELETE FROM jcitems WHERE id = ?|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ # delete spool files
+ $query = qq|
SELECT spoolfile FROM status
WHERE formname = ?
AND trans_id = ?
AND spoolfile IS NOT NULL|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{type}, $form->{id}) || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{type}, $form->{id} ) || $form->dberror($query);
- my $spoolfile;
- my @spoolfiles = ();
+ my $spoolfile;
+ my @spoolfiles = ();
- while (($spoolfile) = $sth->fetchrow_array) {
- push @spoolfiles, $spoolfile;
- }
- $sth->finish;
+ while ( ($spoolfile) = $sth->fetchrow_array ) {
+ push @spoolfiles, $spoolfile;
+ }
+ $sth->finish;
- # delete status entries
- $query = qq|
+ # delete status entries
+ $query = qq|
DELETE
FROM status
WHERE formname = ?
AND trans_id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{type}, $form->{id}) || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{type}, $form->{id} ) || $form->dberror($query);
- my $rc = $dbh->commit;
+ my $rc = $dbh->commit;
- if ($rc) {
- foreach $spoolfile (@spoolfiles) {
- unlink "${LedgerSMB::Sysconfig::spool}/$spoolfile"
- if $spoolfile;
- }
- }
+ if ($rc) {
+ foreach $spoolfile (@spoolfiles) {
+ unlink "${LedgerSMB::Sysconfig::spool}/$spoolfile"
+ if $spoolfile;
+ }
+ }
- $dbh->{commit};
+ $dbh->{commit};
- $rc;
+ $rc;
}
-
sub jcitems {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my $query;
- my $where = "1 = 1";
- my $null;
- my $var;
-
- if ($form->{projectnumber}) {
- ($null, $var) = split /--/, $form->{projectnumber};
- $var = $dbh->quote($var);
- $where .= " AND j.project_id = $var";
-
- $query = qq|SELECT parts_id FROM project WHERE id = $var|;
- my ($job) = $dbh->selectrow_array($query);
- $form->{project} = ($job) ? "job" : "project";
-
- }
- if ($form->{partnumber}) {
- ($null, $var) = split /--/, $form->{partnumber};
- $var = $dbh->quote($var);
- $where .= " AND j.parts_id = $var";
-
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my $query;
+ my $where = "1 = 1";
+ my $null;
+ my $var;
+
+ if ( $form->{projectnumber} ) {
+ ( $null, $var ) = split /--/, $form->{projectnumber};
+ $var = $dbh->quote($var);
+ $where .= " AND j.project_id = $var";
+
+ $query = qq|SELECT parts_id FROM project WHERE id = $var|;
+ my ($job) = $dbh->selectrow_array($query);
+ $form->{project} = ($job) ? "job" : "project";
+
+ }
+ if ( $form->{partnumber} ) {
+ ( $null, $var ) = split /--/, $form->{partnumber};
+ $var = $dbh->quote($var);
+ $where .= " AND j.parts_id = $var";
+
+ $query = qq|
SELECT inventory_accno_id
FROM parts
WHERE id = $var|;
- my ($job) = $dbh->selectrow_array($query);
- $form->{project} = ($job) ? "job" : "project";
-
- }
- if ($form->{employee}) {
- ($null, $var) = split /--/, $form->{employee};
- $var = $dbh->quote($var);
- $where .= " AND j.employee_id = $var";
- }
- if ($form->{open} || $form->{closed}) {
- unless ($form->{open} && $form->{closed}) {
- $where .= " AND j.qty != j.allocated" if $form->{open};
- $where .= " AND j.qty = j.allocated"
- if $form->{closed};
- }
- }
-
- ($form->{startdatefrom}, $form->{startdateto})
- = $form->from_to(
- $form->{year}, $form->{month}, $form->{interval})
- if $form->{year} && $form->{month};
-
- $where .= " AND j.checkedin >= ".$dbh->quote($form->{startdatefrom})
- if $form->{startdatefrom};
- $where .= " AND j.checkedout < date ".
- $dbh->quote($form->{startdateto})." + 1"
- if $form->{startdateto};
-
- my %ordinal = (
- id => 1,
- description => 2,
- transdate => 7,
- partnumber => 9,
- projectnumber => 10,
- projectdescription => 11,
- );
-
- my @a = (transdate, projectnumber);
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
- my $dateformat = $myconfig->{dateformat};
- $dateformat =~ s/yy$/yyyy/;
- $dateformat =~ s/yyyyyy/yyyy/;
-
- if ($form->{project} eq 'job') {
- if ($form->{type} eq 'timecard') {
- $where .= "
+ my ($job) = $dbh->selectrow_array($query);
+ $form->{project} = ($job) ? "job" : "project";
+
+ }
+ if ( $form->{employee} ) {
+ ( $null, $var ) = split /--/, $form->{employee};
+ $var = $dbh->quote($var);
+ $where .= " AND j.employee_id = $var";
+ }
+ if ( $form->{open} || $form->{closed} ) {
+ unless ( $form->{open} && $form->{closed} ) {
+ $where .= " AND j.qty != j.allocated" if $form->{open};
+ $where .= " AND j.qty = j.allocated"
+ if $form->{closed};
+ }
+ }
+
+ ( $form->{startdatefrom}, $form->{startdateto} ) =
+ $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
+ if $form->{year} && $form->{month};
+
+ $where .= " AND j.checkedin >= " . $dbh->quote( $form->{startdatefrom} )
+ if $form->{startdatefrom};
+ $where .=
+ " AND j.checkedout < date " . $dbh->quote( $form->{startdateto} ) . " + 1"
+ if $form->{startdateto};
+
+ my %ordinal = (
+ id => 1,
+ description => 2,
+ transdate => 7,
+ partnumber => 9,
+ projectnumber => 10,
+ projectdescription => 11,
+ );
+
+ my @a = ( transdate, projectnumber );
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ my $dateformat = $myconfig->{dateformat};
+ $dateformat =~ s/yy$/yyyy/;
+ $dateformat =~ s/yyyyyy/yyyy/;
+
+ if ( $form->{project} eq 'job' ) {
+ if ( $form->{type} eq 'timecard' ) {
+ $where .= "
AND pr.parts_id > 0
AND p.income_accno_id IS NULL";
- }
-
- if ($form->{type} eq 'storescard') {
- $where .= "
+ }
+
+ if ( $form->{type} eq 'storescard' ) {
+ $where .= "
AND pr.parts_id > 0
AND p.income_accno_id > 0";
- }
- }
- if ($form->{project} eq 'project') {
- $where .= " AND pr.parts_id IS NULL";
- }
-
- $query = qq|
+ }
+ }
+ if ( $form->{project} eq 'project' ) {
+ $where .= " AND pr.parts_id IS NULL";
+ }
+
+ $query = qq|
SELECT j.id, j.description, j.qty, j.allocated,
to_char(j.checkedin, 'HH24:MI') AS checkedin,
to_char(j.checkedout, 'HH24:MI') AS checkedout,
@@ -487,101 +484,100 @@ sub jcitems {
WHERE $where
ORDER BY employee, employeenumber, $sortorder|;
- $sth = $dbh->prepare($query);
- $sth->execute($dateformat) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute($dateformat) || $form->dberror($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{project} = ($ref->{parts_id}) ? "job" : "project";
- $ref->{transdate} = $ref->{transdatea};
- delete $ref->{transdatea};
- push @{ $form->{transactions} }, $ref;
- }
- $sth->finish;
-
- $dbh->commit;
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{project} = ( $ref->{parts_id} ) ? "job" : "project";
+ $ref->{transdate} = $ref->{transdatea};
+ delete $ref->{transdatea};
+ push @{ $form->{transactions} }, $ref;
+ }
+ $sth->finish;
-}
+ $dbh->commit;
+}
sub save {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my $query;
- my $sth;
-
- my ($null, $project_id) = split /--/, $form->{projectnumber};
-
- if ($form->{id}) {
- # check if it was a job
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my $query;
+ my $sth;
+
+ my ( $null, $project_id ) = split /--/, $form->{projectnumber};
+
+ if ( $form->{id} ) {
+
+ # check if it was a job
+ $query = qq|
SELECT pr.parts_id, pr.production - pr.completed
FROM project pr
JOIN jcitems j ON (j.project_id = pr.id)
WHERE j.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id});
- my ($job_id, $qty) = $sth->fetchrow_array();
- $sth->finish;
- if ($job_id && $qty == 0) {
- return -1;
- }
-
- # check if new one belongs to a job
- if ($project_id) {
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} );
+ my ( $job_id, $qty ) = $sth->fetchrow_array();
+ $sth->finish;
+ if ( $job_id && $qty == 0 ) {
+ return -1;
+ }
+
+ # check if new one belongs to a job
+ if ($project_id) {
+ $query = qq|
SELECT pr.parts_id,
pr.production - pr.completed
FROM project pr
WHERE pr.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($project_id);
- my ($job_id, $qty) = $sth->fetchrow_array();
-
- if ($job_id && $qty == 0) {
- $dbh->disconnect;
- return -2;
- }
- }
-
- } else {
- my $uid = localtime;
- $uid .= "$$";
-
- $query = qq|INSERT INTO jcitems (description) VALUES ('$uid')|;
- $dbh->do($query) || $form->dberror($query);
-
- $query = qq|SELECT id FROM jcitems WHERE description = '$uid'|;
- ($form->{id}) = $dbh->selectrow_array($query);
- }
-
- for (qw(inhour inmin insec outhour outmin outsec)) {
- $form->{$_} = substr("00$form->{$_}", -2);
- }
- for (qw(qty sellprice allocated)) {
- $form->{$_} = $form->parse_amount($myconfig, $form->{$_});
- }
-
- my $checkedin = "$form->{inhour}$form->{inmin}$form->{insec}";
- my $checkedout = "$form->{outhour}$form->{outmin}$form->{outsec}";
-
- my $outdate = $form->{transdate};
- if ($checkedout < $checkedin) {
- $outdate = $form->add_date(
- $myconfig, $form->{transdate}, 1, 'days');
- }
-
- ($null, $form->{employee_id}) = split /--/, $form->{employee};
- unless ($form->{employee_id}) {
- ($form->{employee}, $form->{employee_id})
- = $form->get_employee($dbh);
- }
-
- my $parts_id;
- ($null, $parts_id) = split /--/, $form->{partnumber};
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute($project_id);
+ my ( $job_id, $qty ) = $sth->fetchrow_array();
+
+ if ( $job_id && $qty == 0 ) {
+ $dbh->disconnect;
+ return -2;
+ }
+ }
+
+ }
+ else {
+ my $uid = localtime;
+ $uid .= "$$";
+
+ $query = qq|INSERT INTO jcitems (description) VALUES ('$uid')|;
+ $dbh->do($query) || $form->dberror($query);
+
+ $query = qq|SELECT id FROM jcitems WHERE description = '$uid'|;
+ ( $form->{id} ) = $dbh->selectrow_array($query);
+ }
+
+ for (qw(inhour inmin insec outhour outmin outsec)) {
+ $form->{$_} = substr( "00$form->{$_}", -2 );
+ }
+ for (qw(qty sellprice allocated)) {
+ $form->{$_} = $form->parse_amount( $myconfig, $form->{$_} );
+ }
+
+ my $checkedin = "$form->{inhour}$form->{inmin}$form->{insec}";
+ my $checkedout = "$form->{outhour}$form->{outmin}$form->{outsec}";
+
+ my $outdate = $form->{transdate};
+ if ( $checkedout < $checkedin ) {
+ $outdate = $form->add_date( $myconfig, $form->{transdate}, 1, 'days' );
+ }
+
+ ( $null, $form->{employee_id} ) = split /--/, $form->{employee};
+ unless ( $form->{employee_id} ) {
+ ( $form->{employee}, $form->{employee_id} ) = $form->get_employee($dbh);
+ }
+
+ my $parts_id;
+ ( $null, $parts_id ) = split /--/, $form->{partnumber};
+
+ $query = qq|
UPDATE jcitems
SET project_id = ?,
parts_id = ?,
@@ -596,36 +592,41 @@ sub save {
employee_id = ?,
notes = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $project_id, $parts_id, $form->{description}, $form->{qty},
- $form->{allocated}, $form->{sellprice}, $form->{sellprice},
- $form->{serialnumber},
- "$form->{transdate} $form->{inhour}:$form->{inmin}:".
- $form->{insec},
- "$outdate $form->{outhour}:$form->{outmin}:$form->{outsec}",
- $form->{employee_id}, $form->{notes}, $form->{id}
- ) || $form->dberror($query);
-
- # save printed, queued
- $form->save_status($dbh);
-
- my %audittrail = (
- tablename => 'jcitems',
- reference => $form->{id},
- formname => $form->{type},
- action => 'saved',
- id => $form->{id} );
-
- $form->audittrail($dbh, "", \%audittrail);
-
- my $rc = $dbh->commit;
-
- $rc;
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $project_id,
+ $parts_id,
+ $form->{description},
+ $form->{qty},
+ $form->{allocated},
+ $form->{sellprice},
+ $form->{sellprice},
+ $form->{serialnumber},
+ "$form->{transdate} $form->{inhour}:$form->{inmin}:" . $form->{insec},
+ "$outdate $form->{outhour}:$form->{outmin}:$form->{outsec}",
+ $form->{employee_id},
+ $form->{notes},
+ $form->{id}
+ ) || $form->dberror($query);
+
+ # save printed, queued
+ $form->save_status($dbh);
+
+ my %audittrail = (
+ tablename => 'jcitems',
+ reference => $form->{id},
+ formname => $form->{type},
+ action => 'saved',
+ id => $form->{id}
+ );
+
+ $form->audittrail( $dbh, "", \%audittrail );
+
+ my $rc = $dbh->commit;
+
+ $rc;
}
-
-
1;
diff --git a/LedgerSMB/Locale.pm b/LedgerSMB/Locale.pm
index c6192510..122794b4 100644
--- a/LedgerSMB/Locale.pm
+++ b/LedgerSMB/Locale.pm
@@ -3,15 +3,15 @@
# Locale support module for LedgerSMB
# LedgerSMB::Locale
#
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
-# with permission. It is released under the GNU General Public License
-# Version 2 or, at your option, any later version. See COPYRIGHT file for
+# with permission. It is released under the GNU General Public License
+# Version 2 or, at your option, any later version. See COPYRIGHT file for
# details.
#
#
@@ -29,17 +29,17 @@ use base 'Locale::Maketext';
use Locale::Maketext::Lexicon;
use Encode;
-Locale::Maketext::Lexicon->import({
- '*' => [
- Gettext => "${LedgerSMB::Sysconfig::localepath}/*.po",
- ],
- _auto => 1,
- _decode => 1,
-});
+Locale::Maketext::Lexicon->import(
+ {
+ '*' => [ Gettext => "${LedgerSMB::Sysconfig::localepath}/*.po", ],
+ _auto => 1,
+ _decode => 1,
+ }
+);
sub text {
- my ($self, $text, @params) = @_;
- return $self->maketext($text, @params);
+ my ( $self, $text, @params ) = @_;
+ return $self->maketext( $text, @params );
}
##sub date {
@@ -47,89 +47,94 @@ sub text {
## return $date;
##}
sub date {
- my ($self, $myconfig, $date, $longformat) = @_;
-
- my @longmonth = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
- @longmonth = ("January", "February", "March", "April", "May ", "June",
- "July", "August", "September", "October", "November",
- "December") if $longformat;
- my $longdate = '';
-
- return '' if not $date;
-
- my $spc = '';
- my $yy = '';
- my $mm = '';
- my $dd = '';
-
- # get separator
- $spc = $myconfig->{dateformat};
- $spc =~ s/\w//g;
- $spc = substr($spc, 0, 1);
-
- if (!$longformat && $date =~ /^\d{4}\D/){ # reparsing date at this point
- # causes problems!
- return $date;
- }
- if ($date =~ /\D/) {
-
- if ($myconfig->{dateformat} =~ /^yy/) {
- ($yy, $mm, $dd) = split /\D/, $date;
- }
-
- if ($myconfig->{dateformat} =~ /^mm/) {
- ($mm, $dd, $yy) = split /\D/, $date;
- }
-
- if ($myconfig->{dateformat} =~ /^dd/) {
- ($dd, $mm, $yy) = split /\D/, $date;
- }
-
- } else {
-
- $date = substr($date, 2);
- ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
- }
-
- $dd *= 1;
- $mm--;
- $yy += 2000 if length $yy == 2;
-
- if ($myconfig->{dateformat} =~ /^dd/) {
-
- $mm++;
- $dd = substr("0$dd", -2);
- $mm = substr("0$mm", -2);
- $longdate = "$dd$spc$mm$spc$yy";
-
- if (defined $longformat) {
- $longdate = "$dd";
- $longdate .= ($spc eq '.') ? ". " : " ";
- $longdate .= &text($self, $longmonth[--$mm])." $yy";
- }
-
- } elsif ($myconfig->{dateformat} =~ /^yy/) {
-
- $mm++;
- $dd = substr("0$dd", -2);
- $mm = substr("0$mm", -2);
- $longdate = "$yy$spc$mm$spc$dd";
-
- if (defined $longformat) {
- $longdate = &text($self, $longmonth[--$mm])." $dd $yy";
- }
-
- } else {
-
- $mm++;
- $dd = substr("0$dd", -2);
- $mm = substr("0$mm", -2);
- $longdate = "$mm$spc$dd$spc$yy";
-
- if (defined $longformat) {
- $longdate = &text($self, $longmonth[--$mm])." $dd $yy";
- }
- }
+ my ( $self, $myconfig, $date, $longformat ) = @_;
+
+ my @longmonth = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
+ @longmonth = (
+ "January", "February", "March", "April",
+ "May ", "June", "July", "August",
+ "September", "October", "November", "December"
+ ) if $longformat;
+ my $longdate = '';
+
+ return '' if not $date;
+
+ my $spc = '';
+ my $yy = '';
+ my $mm = '';
+ my $dd = '';
+
+ # get separator
+ $spc = $myconfig->{dateformat};
+ $spc =~ s/\w//g;
+ $spc = substr( $spc, 0, 1 );
+
+ if ( !$longformat && $date =~ /^\d{4}\D/ ) { # reparsing date at this point
+ # causes problems!
+ return $date;
+ }
+ if ( $date =~ /\D/ ) {
+
+ if ( $myconfig->{dateformat} =~ /^yy/ ) {
+ ( $yy, $mm, $dd ) = split /\D/, $date;
+ }
+
+ if ( $myconfig->{dateformat} =~ /^mm/ ) {
+ ( $mm, $dd, $yy ) = split /\D/, $date;
+ }
+
+ if ( $myconfig->{dateformat} =~ /^dd/ ) {
+ ( $dd, $mm, $yy ) = split /\D/, $date;
+ }
+
+ }
+ else {
+
+ $date = substr( $date, 2 );
+ ( $yy, $mm, $dd ) = ( $date =~ /(..)(..)(..)/ );
+ }
+
+ $dd *= 1;
+ $mm--;
+ $yy += 2000 if length $yy == 2;
+
+ if ( $myconfig->{dateformat} =~ /^dd/ ) {
+
+ $mm++;
+ $dd = substr( "0$dd", -2 );
+ $mm = substr( "0$mm", -2 );
+ $longdate = "$dd$spc$mm$spc$yy";
+
+ if ( defined $longformat ) {
+ $longdate = "$dd";
+ $longdate .= ( $spc eq '.' ) ? ". " : " ";
+ $longdate .= &text( $self, $longmonth[ --$mm ] ) . " $yy";
+ }
+
+ }
+ elsif ( $myconfig->{dateformat} =~ /^yy/ ) {
+
+ $mm++;
+ $dd = substr( "0$dd", -2 );
+ $mm = substr( "0$mm", -2 );
+ $longdate = "$yy$spc$mm$spc$dd";
+
+ if ( defined $longformat ) {
+ $longdate = &text( $self, $longmonth[ --$mm ] ) . " $dd $yy";
+ }
+
+ }
+ else {
+
+ $mm++;
+ $dd = substr( "0$dd", -2 );
+ $mm = substr( "0$mm", -2 );
+ $longdate = "$mm$spc$dd$spc$yy";
+
+ if ( defined $longformat ) {
+ $longdate = &text( $self, $longmonth[ --$mm ] ) . " $dd $yy";
+ }
+ }
}
1;
diff --git a/LedgerSMB/Location.pm b/LedgerSMB/Location.pm
index dc4b0123..929e1a6c 100644
--- a/LedgerSMB/Location.pm
+++ b/LedgerSMB/Location.pm
@@ -1,3 +1,4 @@
+
=head1 NAME
LedgerSMB::Location - LedgerSMB class for managing Business Locations
@@ -38,29 +39,29 @@ our $VERSION = '1.0.0';
our @ISA = qw(LedgerSMB::DBObject);
sub AUTOLOAD {
- my $self = shift;
- my $AUTOLOAD = $LedgerSMB::Location::AUTOLOAD;
- $AUTOLOAD =~ s/^.*:://;
- my $procname = "location_$AUTOLOAD";
- $self->exec_method(procname => "location_$AUTOLOAD", args => \@_);
+ my $self = shift;
+ my $AUTOLOAD = $LedgerSMB::Location::AUTOLOAD;
+ $AUTOLOAD =~ s/^.*:://;
+ my $procname = "location_$AUTOLOAD";
+ $self->exec_method( procname => "location_$AUTOLOAD", args => \@_ );
}
sub save {
- $ref = shift @{$self->exec_method(procname =>"location_save")};
- $self->merge($ref, 'id');
+ $ref = shift @{ $self->exec_method( procname => "location_save" ) };
+ $self->merge( $ref, 'id' );
}
sub get {
- $ref = shift @{$self->exec_method(procname =>'location_get')};
- $self->merge($ref, keys %{$ref});
+ $ref = shift @{ $self->exec_method( procname => 'location_get' ) };
+ $self->merge( $ref, keys %{$ref} );
}
sub search {
- $self->{search_results} =
- $self->exec_method(procname => 'location_search');
+ $self->{search_results} =
+ $self->exec_method( procname => 'location_search' );
}
sub list_all {
- $self->{search_results} =
- $self->exec_method(procname => 'location_list_all');
+ $self->{search_results} =
+ $self->exec_method( procname => 'location_list_all' );
}
diff --git a/LedgerSMB/Log.pm b/LedgerSMB/Log.pm
index 0613132b..d102705d 100644
--- a/LedgerSMB/Log.pm
+++ b/LedgerSMB/Log.pm
@@ -1,3 +1,4 @@
+
=head1 NAME
LedgerSMB::Log - LedgerSMB logging and debugging framework
@@ -56,33 +57,34 @@ our $VERSION = '1.0.0';
our $log_line;
-sub print {
- if (!$LedgerSMB::Sysconfig::logging){
- return 0;
- }
- shift;
- $log_line = sprintf('[%s] [%s] %i %s', scalar(localtime), +shift, $$, join(' ',@_))."\n";
- print STDERR $log_line;
+sub print {
+ if ( !$LedgerSMB::Sysconfig::logging ) {
+ return 0;
+ }
+ shift;
+ $log_line = sprintf( '[%s] [%s] %i %s',
+ scalar(localtime), +shift, $$, join( ' ', @_ ) )
+ . "\n";
+ print STDERR $log_line;
}
-
-sub emerg { shift->print('emerg',@_) }
-sub alert { shift->print('alert',@_) }
-sub crit { shift->print('crit',@_) }
-sub error { shift->print('error',@_) }
-sub warn { shift->print('warn',@_) }
-sub notice { shift->print('notice',@_) }
-sub info { shift->print('info',@_) }
-sub debug { shift->print('debug',@_) }
-
-sub longmess { shift->print('debug',Carp::longmess(@_)) }
-
-sub dump {
- my $self = shift;
- my $d = Data::Dumper->new([@_]);
- $d->Sortkeys(1);
- $self->print('debug',$d->Dump());
+sub emerg { shift->print( 'emerg', @_ ) }
+sub alert { shift->print( 'alert', @_ ) }
+sub crit { shift->print( 'crit', @_ ) }
+sub error { shift->print( 'error', @_ ) }
+sub warn { shift->print( 'warn', @_ ) }
+sub notice { shift->print( 'notice', @_ ) }
+sub info { shift->print( 'info', @_ ) }
+sub debug { shift->print( 'debug', @_ ) }
+
+sub longmess { shift->print( 'debug', Carp::longmess(@_) ) }
+
+sub dump {
+ my $self = shift;
+ my $d = Data::Dumper->new( [@_] );
+ $d->Sortkeys(1);
+ $self->print( 'debug', $d->Dump() );
}
1;
diff --git a/LedgerSMB/Mailer.pm b/LedgerSMB/Mailer.pm
index 05a711bd..eb1d4a9b 100644
--- a/LedgerSMB/Mailer.pm
+++ b/LedgerSMB/Mailer.pm
@@ -1,5 +1,5 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
#
@@ -19,7 +19,7 @@
# Author: DWS Systems Inc.
# Web: http://www.sql-ledger.org
#
-# Contributors:
+# Contributors:
#
# Original Author and copyright holder:
# Dieter Simader dsmimader@sql-ledger.com
@@ -40,85 +40,85 @@ use MIME::Base64;
use LedgerSMB::Sysconfig;
sub new {
- my ($type) = @_;
- my $self = {};
+ my ($type) = @_;
+ my $self = {};
- bless $self, $type;
+ bless $self, $type;
}
-
sub send {
- my ($self) = @_;
-
- my $domain = $self->{from};
- $domain =~ s/(.*?\@|>)//g;
- my $msgid = "$boundary\@$domain";
-
-
- $self->{contenttype} = "text/plain" unless $self->{contenttype};
-
- my %h;
- for (qw(from to cc bcc)) {
- $self->{$_} =~ s/\&lt;/</g;
- $self->{$_} =~ s/\&gt;/>/g;
- $self->{$_} =~ s/(\/|\\|\$)//g;
- $h{$_} = $self->{$_};
- }
-
- $h{subject} =
- ($self->{subject} =~ /([\x00-\x1F]|[\x7B-\xFFFF])/)
- ? "Subject: =?$self->{charset}?B?".
- MIME::Base64::encode($self->{subject},"")."?="
- : "Subject: $self->{subject}";
-
- my $msg = MIME::Lite->new(
- 'From' => $self->{from},
- 'To' => $self->{to},
- 'Cc' => $self->{cc},
- 'Bcc' => $self->{bcc},
- 'Subject' => $self->{subject},
- 'Type' => 'TEXT',
- 'Data' => $self->{message},
- );
- $msg->add('Disposition-Notification-To' => $self->{from})
- if $self->{notify};
- $msg->replace('X-Mailer' => "LedgerSMB $self->{version}");
-
- if (@{ $self->{attachments} }) {
- foreach my $attachment (@{ $self->{attachments} }) {
-
- my $application =
- ($attachment =~
- /(^\w+$)|\.(html|text|txt|sql)$/)
- ? "text"
- : "application";
-
- my $filename = $attachment;
- # strip path
- $filename =~ s/(.*\/|$self->{fileid})//g;
- $msg->attach(
- 'Type' => "$application/$self->{format}",
- 'Path' => $attachment,
- 'Filename' => $filename,
- 'Disposition' => 'attachment',
- );
- }
-
- }
-
- if (${LedgerSMB::Sysconfig::smtphost}) {
- $msg->send('smtp', ${LedgerSMB::Sysconfig::smtphost},
- Timeout => ${LedgerSMB::Sysconfig::smtptimeout}) ||
- return $!;
- } else {
- $msg->send('sendmail', ${LedgerSMB::Sysconfig::sendmail}) ||
- return $!;
- }
-
- return "";
-
-}
+ my ($self) = @_;
+
+ my $domain = $self->{from};
+ $domain =~ s/(.*?\@|>)//g;
+ my $msgid = "$boundary\@$domain";
+
+ $self->{contenttype} = "text/plain" unless $self->{contenttype};
+
+ my %h;
+ for (qw(from to cc bcc)) {
+ $self->{$_} =~ s/\&lt;/</g;
+ $self->{$_} =~ s/\&gt;/>/g;
+ $self->{$_} =~ s/(\/|\\|\$)//g;
+ $h{$_} = $self->{$_};
+ }
+
+ $h{subject} =
+ ( $self->{subject} =~ /([\x00-\x1F]|[\x7B-\xFFFF])/ )
+ ? "Subject: =?$self->{charset}?B?"
+ . MIME::Base64::encode( $self->{subject}, "" ) . "?="
+ : "Subject: $self->{subject}";
+
+ my $msg = MIME::Lite->new(
+ 'From' => $self->{from},
+ 'To' => $self->{to},
+ 'Cc' => $self->{cc},
+ 'Bcc' => $self->{bcc},
+ 'Subject' => $self->{subject},
+ 'Type' => 'TEXT',
+ 'Data' => $self->{message},
+ );
+ $msg->add( 'Disposition-Notification-To' => $self->{from} )
+ if $self->{notify};
+ $msg->replace( 'X-Mailer' => "LedgerSMB $self->{version}" );
+
+ if ( @{ $self->{attachments} } ) {
+ foreach my $attachment ( @{ $self->{attachments} } ) {
+
+ my $application =
+ ( $attachment =~ /(^\w+$)|\.(html|text|txt|sql)$/ )
+ ? "text"
+ : "application";
+
+ my $filename = $attachment;
+
+ # strip path
+ $filename =~ s/(.*\/|$self->{fileid})//g;
+ $msg->attach(
+ 'Type' => "$application/$self->{format}",
+ 'Path' => $attachment,
+ 'Filename' => $filename,
+ 'Disposition' => 'attachment',
+ );
+ }
+
+ }
+
+ if ( ${LedgerSMB::Sysconfig::smtphost} ) {
+ $msg->send(
+ 'smtp',
+ ${LedgerSMB::Sysconfig::smtphost},
+ Timeout => ${LedgerSMB::Sysconfig::smtptimeout}
+ ) || return $!;
+ }
+ else {
+ $msg->send( 'sendmail', ${LedgerSMB::Sysconfig::sendmail} )
+ || return $!;
+ }
+
+ return "";
+}
1;
diff --git a/LedgerSMB/Menu.pm b/LedgerSMB/Menu.pm
index 344bb7d7..d8aad77c 100644
--- a/LedgerSMB/Menu.pm
+++ b/LedgerSMB/Menu.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -36,85 +36,83 @@ package Menu;
use LedgerSMB::Inifile;
@ISA = qw/Inifile/;
-
sub menuitem {
- my ($self, $myconfig, $form, $item) = @_;
-
- my $module = ($self->{$item}{module})
- ? $self->{$item}{module} : $form->{script};
- my $action = ($self->{$item}{action})
- ? $self->{$item}{action} : "section_menu";
- my $target = ($self->{$item}{target})
- ? $self->{$item}{target} : "";
-
- my $level = $form->escape($item);
- my $str = qq|<a style="display:block;"|.
- qq|href="$module?path=$form->{path}&amp;action=$action&amp;|.
- qq|level=$level&amp;login=$form->{login}&amp;|.
- qq|timeout=$form->{timeout}&amp;sessionid=$form->{sessionid}|.
- qq|&amp;js=$form->{js}|;
-
- my @vars = qw(module action target href);
-
- if ($self->{$item}{href}) {
- $str = qq|<a href="$self->{$item}{href}|;
- @vars = qw(module target href);
- }
-
- for (@vars) { delete $self->{$item}{$_} }
-
- delete $self->{$item}{submenu};
-
- # add other params
- foreach my $key (keys %{ $self->{$item} }) {
- $str .= "&amp;".$form->escape($key)."=";
- ($value, $conf) = split /=/, $self->{$item}{$key}, 2;
- $value = "$myconfig->{$value}$conf"
- if $self->{$item}{$key} =~ /=/;
-
- $str .= $form->escape($value);
- }
-
- $str .= qq|#id$form->{tag}| if $target eq 'acc_menu';
-
- if ($target) {
- $str .= qq|" target="$target"|;
- }
- else{
- $str .= '"';
- }
-
- $str .= qq|>|;
-
-}
+ my ( $self, $myconfig, $form, $item ) = @_;
+ my $module =
+ ( $self->{$item}{module} ) ? $self->{$item}{module} : $form->{script};
+ my $action =
+ ( $self->{$item}{action} ) ? $self->{$item}{action} : "section_menu";
+ my $target = ( $self->{$item}{target} ) ? $self->{$item}{target} : "";
-sub access_control {
- my ($self, $myconfig, $menulevel) = @_;
-
- my @menu = ();
+ my $level = $form->escape($item);
+ my $str =
+ qq|<a style="display:block;"|
+ . qq|href="$module?path=$form->{path}&amp;action=$action&amp;|
+ . qq|level=$level&amp;login=$form->{login}&amp;|
+ . qq|timeout=$form->{timeout}&amp;sessionid=$form->{sessionid}|
+ . qq|&amp;js=$form->{js}|;
+
+ my @vars = qw(module action target href);
- if ($menulevel eq "") {
- @menu = grep { !/--/ } @{ $self->{ORDER} };
- } else {
- @menu = grep { /^${menulevel}--/; } @{ $self->{ORDER} };
- }
+ if ( $self->{$item}{href} ) {
+ $str = qq|<a href="$self->{$item}{href}|;
+ @vars = qw(module target href);
+ }
- my @a = split /;/, $myconfig->{acs};
- my $excl = ();
+ for (@vars) { delete $self->{$item}{$_} }
- # remove --AR, --AP from array
- grep { ($a, $b) = split /--/; s/--$a$//; } @a;
+ delete $self->{$item}{submenu};
- for (@a) { $excl{$_} = 1 }
+ # add other params
+ foreach my $key ( keys %{ $self->{$item} } ) {
+ $str .= "&amp;" . $form->escape($key) . "=";
+ ( $value, $conf ) = split /=/, $self->{$item}{$key}, 2;
+ $value = "$myconfig->{$value}$conf"
+ if $self->{$item}{$key} =~ /=/;
- @a = ();
- for (@menu) { push @a, $_ unless $excl{$_} }
+ $str .= $form->escape($value);
+ }
- @a;
+ $str .= qq|#id$form->{tag}| if $target eq 'acc_menu';
+
+ if ($target) {
+ $str .= qq|" target="$target"|;
+ }
+ else {
+ $str .= '"';
+ }
+
+ $str .= qq|>|;
}
+sub access_control {
+ my ( $self, $myconfig, $menulevel ) = @_;
+
+ my @menu = ();
+
+ if ( $menulevel eq "" ) {
+ @menu = grep { !/--/ } @{ $self->{ORDER} };
+ }
+ else {
+ @menu = grep { /^${menulevel}--/; } @{ $self->{ORDER} };
+ }
+
+ my @a = split /;/, $myconfig->{acs};
+ my $excl = ();
+
+ # remove --AR, --AP from array
+ grep { ( $a, $b ) = split /--/; s/--$a$//; } @a;
+
+ for (@a) { $excl{$_} = 1 }
+
+ @a = ();
+ for (@menu) { push @a, $_ unless $excl{$_} }
+
+ @a;
+
+}
1;
diff --git a/LedgerSMB/Num2text.pm b/LedgerSMB/Num2text.pm
index 8382df5c..25bdc95f 100644
--- a/LedgerSMB/Num2text.pm
+++ b/LedgerSMB/Num2text.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -19,7 +19,7 @@
# Author: DWS Systems Inc.
# Web: http://www.sql-ledger.org
#
-# Contributors:
+# Contributors:
#
#======================================================================
#
@@ -33,993 +33,1053 @@
# The conversion routines can be tested with for example:
# perl <<EOF
-# use LedgerSMB::CP;
-# my $c = CP->new('da');
-# $c->init;
-# for(0 .. 202, 999 .. 1002, 1999 .. 2002, 999999 .. 1000002, 999999999 .. 1000000002)
+# use LedgerSMB::CP;
+# my $c = CP->new('da');
+# $c->init;
+# for(0 .. 202, 999 .. 1002, 1999 .. 2002, 999999 .. 1000002, 999999999 .. 1000000002)
# {print $_.":".$c->num2text($_)."\n";};'
# EOF
sub init {
- my $self = shift;
- my $locale = $self->{'locale'};
- my $langtag = substr($locale->language_tag, 0, 2);
- $self->{'numrules'} = 'en';
- $self->{'numrules'} = $langtag if
- grep {/$langtag/} (qw/ca de es et fr hu it nl ru da/);
- $self->{'numrules'} = 'es' if $self->{'numrules'} eq 'ca';
- $self->{'numrules'} = 'de' if $self->{'numrules'} eq 'ru';
-
- %{ $self->{numbername} } =
- (0 => $locale->text('Zero'),
- 1 => $locale->text('One'),
- '1o' => $locale->text('One-o'),
- 2 => $locale->text('Two'),
- 3 => $locale->text('Three'),
- 4 => $locale->text('Four'),
- 5 => $locale->text('Five'),
- 6 => $locale->text('Six'),
- 7 => $locale->text('Seven'),
- 8 => $locale->text('Eight'),
- 9 => $locale->text('Nine'),
- 10 => $locale->text('Ten'),
- 11 => $locale->text('Eleven'),
- '11o' => $locale->text('Eleven-o'),
- 12 => $locale->text('Twelve'),
- 13 => $locale->text('Thirteen'),
- 14 => $locale->text('Fourteen'),
- 15 => $locale->text('Fifteen'),
- 16 => $locale->text('Sixteen'),
- 17 => $locale->text('Seventeen'),
- 18 => $locale->text('Eighteen'),
- 19 => $locale->text('Nineteen'),
- 20 => $locale->text('Twenty'),
- 21 => $locale->text('Twenty One'),
- '21o' => $locale->text('Twenty One-o'),
- 22 => $locale->text('Twenty Two'),
- 23 => $locale->text('Twenty Three'),
- 24 => $locale->text('Twenty Four'),
- 25 => $locale->text('Twenty Five'),
- 26 => $locale->text('Twenty Six'),
- 27 => $locale->text('Twenty Seven'),
- 28 => $locale->text('Twenty Eight'),
- 29 => $locale->text('Twenty Nine'),
- 30 => $locale->text('Thirty'),
- 40 => $locale->text('Forty'),
- 50 => $locale->text('Fifty'),
- 60 => $locale->text('Sixty'),
- 70 => $locale->text('Seventy'),
- 80 => $locale->text('Eighty'),
- 90 => $locale->text('Ninety'),
- 10**2 => $locale->text('Hundred'),
- 500 => $locale->text('Five Hundred'),
- 700 => $locale->text('Seven Hundred'),
- 900 => $locale->text('Nine Hundred'),
- 10**3 => $locale->text('Thousand'),
- 10**6 => $locale->text('Million'),
- 10**9 => $locale->text('Billion'),
- 10**12 => $locale->text('Trillion'),
- );
+ my $self = shift;
+ my $locale = $self->{'locale'};
+ my $langtag = substr( $locale->language_tag, 0, 2 );
+ $self->{'numrules'} = 'en';
+ $self->{'numrules'} = $langtag
+ if grep { /$langtag/ } (qw/ca de es et fr hu it nl ru da/);
+ $self->{'numrules'} = 'es' if $self->{'numrules'} eq 'ca';
+ $self->{'numrules'} = 'de' if $self->{'numrules'} eq 'ru';
+
+ %{ $self->{numbername} } = (
+ 0 => $locale->text('Zero'),
+ 1 => $locale->text('One'),
+ '1o' => $locale->text('One-o'),
+ 2 => $locale->text('Two'),
+ 3 => $locale->text('Three'),
+ 4 => $locale->text('Four'),
+ 5 => $locale->text('Five'),
+ 6 => $locale->text('Six'),
+ 7 => $locale->text('Seven'),
+ 8 => $locale->text('Eight'),
+ 9 => $locale->text('Nine'),
+ 10 => $locale->text('Ten'),
+ 11 => $locale->text('Eleven'),
+ '11o' => $locale->text('Eleven-o'),
+ 12 => $locale->text('Twelve'),
+ 13 => $locale->text('Thirteen'),
+ 14 => $locale->text('Fourteen'),
+ 15 => $locale->text('Fifteen'),
+ 16 => $locale->text('Sixteen'),
+ 17 => $locale->text('Seventeen'),
+ 18 => $locale->text('Eighteen'),
+ 19 => $locale->text('Nineteen'),
+ 20 => $locale->text('Twenty'),
+ 21 => $locale->text('Twenty One'),
+ '21o' => $locale->text('Twenty One-o'),
+ 22 => $locale->text('Twenty Two'),
+ 23 => $locale->text('Twenty Three'),
+ 24 => $locale->text('Twenty Four'),
+ 25 => $locale->text('Twenty Five'),
+ 26 => $locale->text('Twenty Six'),
+ 27 => $locale->text('Twenty Seven'),
+ 28 => $locale->text('Twenty Eight'),
+ 29 => $locale->text('Twenty Nine'),
+ 30 => $locale->text('Thirty'),
+ 40 => $locale->text('Forty'),
+ 50 => $locale->text('Fifty'),
+ 60 => $locale->text('Sixty'),
+ 70 => $locale->text('Seventy'),
+ 80 => $locale->text('Eighty'),
+ 90 => $locale->text('Ninety'),
+ 10**2 => $locale->text('Hundred'),
+ 500 => $locale->text('Five Hundred'),
+ 700 => $locale->text('Seven Hundred'),
+ 900 => $locale->text('Nine Hundred'),
+ 10**3 => $locale->text('Thousand'),
+ 10**6 => $locale->text('Million'),
+ 10**9 => $locale->text('Billion'),
+ 10**12 => $locale->text('Trillion'),
+ );
}
-
sub num2text {
- my ($self, $amount) = @_;
-
- return $self->num2text_de($amount) if $self->{'numrules'} eq 'de';
- return $self->num2text_es($amount) if $self->{'numrules'} eq 'es';
- return $self->num2text_nl($amount) if $self->{'numrules'} eq 'nl';
- return $self->num2text_hu($amount) if $self->{'numrules'} eq 'hu';
- return $self->num2text_et($amount) if $self->{'numrules'} eq 'et';
- return $self->num2text_fr($amount) if $self->{'numrules'} eq 'fr';
- return $self->num2text_it($amount) if $self->{'numrules'} eq 'it';
- return $self->num2text_da($amount) if $self->{'numrules'} eq 'da';
- return $self->num2text_en($amount);
+ my ( $self, $amount ) = @_;
+
+ return $self->num2text_de($amount) if $self->{'numrules'} eq 'de';
+ return $self->num2text_es($amount) if $self->{'numrules'} eq 'es';
+ return $self->num2text_nl($amount) if $self->{'numrules'} eq 'nl';
+ return $self->num2text_hu($amount) if $self->{'numrules'} eq 'hu';
+ return $self->num2text_et($amount) if $self->{'numrules'} eq 'et';
+ return $self->num2text_fr($amount) if $self->{'numrules'} eq 'fr';
+ return $self->num2text_it($amount) if $self->{'numrules'} eq 'it';
+ return $self->num2text_da($amount) if $self->{'numrules'} eq 'da';
+ return $self->num2text_en($amount);
}
-
sub num2text_en {
- my ($self, $amount) = @_;
-
- return $self->{numbername}{0} unless $amount;
-
- my @textnumber = ();
-
- # split amount into chunks of 3
- my @num = reverse split //, abs($amount);
- my @numblock = ();
- my @a;
- my $i;
-
- while (@num) {
- @a = ();
- for (1 .. 3) {
- push @a, shift @num;
- }
- push @numblock, join / /, reverse @a;
- }
-
- while (@numblock) {
-
- $i = $#numblock;
- @num = split //, $numblock[$i];
-
- if ($numblock[$i] == 0) {
- pop @numblock;
- next;
- }
-
- if ($numblock[$i] > 99) {
- # the one from hundreds
- push @textnumber, $self->{numbername}{$num[0]};
-
- # add hundred designation
- push @textnumber, $self->{numbername}{10**2};
-
- # reduce numblock
- $numblock[$i] -= $num[0] * 100;
-
- }
-
- $numblock[$i] *= 1;
-
- if ($numblock[$i] > 9) {
- # tens
- push @textnumber, $self->format_ten_en($numblock[$i]);
- } elsif ($numblock[$i] > 0) {
- # ones
- push @textnumber, $self->{numbername}{$numblock[$i]};
- }
-
- # add thousand, million
- if ($i) {
- $num = 10**($i * 3);
- push @textnumber, $self->{numbername}{$num};
- }
-
- pop @numblock;
-
- }
-
- join ' ', @textnumber;
+ my ( $self, $amount ) = @_;
-}
+ return $self->{numbername}{0} unless $amount;
+ my @textnumber = ();
+
+ # split amount into chunks of 3
+ my @num = reverse split //, abs($amount);
+ my @numblock = ();
+ my @a;
+ my $i;
+
+ while (@num) {
+ @a = ();
+ for ( 1 .. 3 ) {
+ push @a, shift @num;
+ }
+ push @numblock, join / /, reverse @a;
+ }
+
+ while (@numblock) {
+
+ $i = $#numblock;
+ @num = split //, $numblock[$i];
+
+ if ( $numblock[$i] == 0 ) {
+ pop @numblock;
+ next;
+ }
+
+ if ( $numblock[$i] > 99 ) {
+
+ # the one from hundreds
+ push @textnumber, $self->{numbername}{ $num[0] };
+
+ # add hundred designation
+ push @textnumber, $self->{numbername}{ 10**2 };
+
+ # reduce numblock
+ $numblock[$i] -= $num[0] * 100;
+
+ }
+
+ $numblock[$i] *= 1;
+
+ if ( $numblock[$i] > 9 ) {
+
+ # tens
+ push @textnumber, $self->format_ten_en( $numblock[$i] );
+ }
+ elsif ( $numblock[$i] > 0 ) {
+
+ # ones
+ push @textnumber, $self->{numbername}{ $numblock[$i] };
+ }
+
+ # add thousand, million
+ if ($i) {
+ $num = 10**( $i * 3 );
+ push @textnumber, $self->{numbername}{$num};
+ }
+
+ pop @numblock;
+
+ }
+
+ join ' ', @textnumber;
-sub format_ten_en {
- my ($self, $amount) = @_;
-
- my $textnumber = "";
- my @num = split //, $amount;
-
- if ($amount > 20) {
- $textnumber = $self->{numbername}{$num[0]*10};
- $amount = $num[1];
- } else {
- $textnumber = $self->{numbername}{$amount};
- $amount = 0;
- }
-
- $textnumber .= " ".$self->{numbername}{$amount} if $amount;
-
- $textnumber;
-
}
+sub format_ten_en {
+ my ( $self, $amount ) = @_;
-sub num2text_de {
- my ($self, $amount) = @_;
-
- return $self->{numbername}{0} unless $amount;
-
- my @textnumber = ();
-
- # split amount into chunks of 3
- my @num = reverse split //, abs($amount);
- my @numblock = ();
- my ($i, $appendn);
- my @a = ();
-
- while (@num) {
- @a = ();
- for (1 .. 3) {
- push @a, shift @num;
- }
- push @numblock, join / /, reverse @a;
- }
-
- my $belowhundred = !$#numblock;
-
- while (@numblock) {
-
- $i = $#numblock;
- @num = split //, $numblock[$i];
- $appendn = "";
-
- $numblock[$i] *= 1;
-
- if ($numblock[$i] == 0) {
- pop @numblock;
- next;
- }
-
- if ($numblock[$i] > 99) {
- # the one from hundreds
- push @textnumber, $self->{numbername}{$num[0]};
-
- # add hundred designation
- push @textnumber, $self->{numbername}{10**2};
-
- # reduce numblock
- $numblock[$i] -= $num[0] * 100;
- }
-
- $appendn = 'en' if ($i == 2);
- $appendn = 'n' if ($i > 2);
-
- if ($numblock[$i] > 9) {
- # tens
- push @textnumber, $self->format_ten_de($numblock[$i], $belowhundred);
- } elsif ($numblock[$i] > 1) {
- # ones
- push @textnumber, $self->{numbername}{$numblock[$i]};
- } elsif ($numblock[$i] == 1) {
- if ($i == 0) {
- push @textnumber, $self->{numbername}{$numblock[$i]}.'s';
- } else {
- if ($i >= 2) {
- push @textnumber, $self->{numbername}{$numblock[$i]}.'e';
- } else {
- push @textnumber, $self->{numbername}{$numblock[$i]};
- }
- }
- $appendn = "";
- }
-
- # add thousand, million
- if ($i) {
- $amount = 10**($i * 3);
- push @textnumber, $self->{numbername}{$amount}.$appendn;
- }
-
- pop @numblock;
-
- }
-
- join '', @textnumber;
+ my $textnumber = "";
+ my @num = split //, $amount;
+
+ if ( $amount > 20 ) {
+ $textnumber = $self->{numbername}{ $num[0] * 10 };
+ $amount = $num[1];
+ }
+ else {
+ $textnumber = $self->{numbername}{$amount};
+ $amount = 0;
+ }
+
+ $textnumber .= " " . $self->{numbername}{$amount} if $amount;
+
+ $textnumber;
}
+sub num2text_de {
+ my ( $self, $amount ) = @_;
+
+ return $self->{numbername}{0} unless $amount;
+
+ my @textnumber = ();
+
+ # split amount into chunks of 3
+ my @num = reverse split //, abs($amount);
+ my @numblock = ();
+ my ( $i, $appendn );
+ my @a = ();
+
+ while (@num) {
+ @a = ();
+ for ( 1 .. 3 ) {
+ push @a, shift @num;
+ }
+ push @numblock, join / /, reverse @a;
+ }
+
+ my $belowhundred = !$#numblock;
+
+ while (@numblock) {
+
+ $i = $#numblock;
+ @num = split //, $numblock[$i];
+ $appendn = "";
+
+ $numblock[$i] *= 1;
+
+ if ( $numblock[$i] == 0 ) {
+ pop @numblock;
+ next;
+ }
+
+ if ( $numblock[$i] > 99 ) {
+
+ # the one from hundreds
+ push @textnumber, $self->{numbername}{ $num[0] };
+
+ # add hundred designation
+ push @textnumber, $self->{numbername}{ 10**2 };
+
+ # reduce numblock
+ $numblock[$i] -= $num[0] * 100;
+ }
+
+ $appendn = 'en' if ( $i == 2 );
+ $appendn = 'n' if ( $i > 2 );
+
+ if ( $numblock[$i] > 9 ) {
+
+ # tens
+ push @textnumber,
+ $self->format_ten_de( $numblock[$i], $belowhundred );
+ }
+ elsif ( $numblock[$i] > 1 ) {
+
+ # ones
+ push @textnumber, $self->{numbername}{ $numblock[$i] };
+ }
+ elsif ( $numblock[$i] == 1 ) {
+ if ( $i == 0 ) {
+ push @textnumber, $self->{numbername}{ $numblock[$i] } . 's';
+ }
+ else {
+ if ( $i >= 2 ) {
+ push @textnumber,
+ $self->{numbername}{ $numblock[$i] } . 'e';
+ }
+ else {
+ push @textnumber, $self->{numbername}{ $numblock[$i] };
+ }
+ }
+ $appendn = "";
+ }
+
+ # add thousand, million
+ if ($i) {
+ $amount = 10**( $i * 3 );
+ push @textnumber, $self->{numbername}{$amount} . $appendn;
+ }
+
+ pop @numblock;
+
+ }
+
+ join '', @textnumber;
-sub format_ten_de {
- my ($self, $amount, $belowhundred) = @_;
-
- my $textnumber = "";
- my @num = split //, $amount;
-
- if ($amount > 20) {
- if ($num[1] == 0) {
- $textnumber = $self->{numbername}{$amount};
- } else {
- if ($belowhundred) {
- $amount = $num[0] * 10;
- $textnumber = $self->{numbername}{$num[1]}.'und'.$self->{numbername}{$amount};
- } else {
- $amount = $num[0] * 10;
- $textnumber = $self->{numbername}{$amount}.$self->{numbername}{$num[1]};
- $textnumber .= 's' if ($num[1] == 1);
- }
- }
- } else {
- $textnumber = $self->{numbername}{$amount};
- }
-
- $textnumber;
-
}
+sub format_ten_de {
+ my ( $self, $amount, $belowhundred ) = @_;
+
+ my $textnumber = "";
+ my @num = split //, $amount;
+
+ if ( $amount > 20 ) {
+ if ( $num[1] == 0 ) {
+ $textnumber = $self->{numbername}{$amount};
+ }
+ else {
+ if ($belowhundred) {
+ $amount = $num[0] * 10;
+ $textnumber =
+ $self->{numbername}{ $num[1] } . 'und'
+ . $self->{numbername}{$amount};
+ }
+ else {
+ $amount = $num[0] * 10;
+ $textnumber =
+ $self->{numbername}{$amount} . $self->{numbername}{ $num[1] };
+ $textnumber .= 's' if ( $num[1] == 1 );
+ }
+ }
+ }
+ else {
+ $textnumber = $self->{numbername}{$amount};
+ }
+
+ $textnumber;
+
+}
sub num2text_et {
- my ($self, $amount) = @_;
-
- return $self->{numbername}{0} unless $amount;
-
- my @textnumber = ();
-
- # split amount into chunks of 3
- my @num = reverse split //, abs($amount);
- my @numblock = ();
- my ($i, $appendit);
- my @a = ();
-
- while (@num) {
- @a = ();
- for (1 .. 3) {
- push @a, shift @num;
- }
- push @numblock, join / /, reverse @a;
- }
-
- while (@numblock) {
-
- $i = $#numblock;
- $numblock[$i] *= 1;
- @num = split //, $numblock[$i];
-
- $appendit = "it";
- $hundred = 0;
-
- if ($numblock[$i] == 0) {
- pop @numblock;
- next;
- }
-
- if ($numblock[$i] > 99) {
- # the one from hundreds
- push @textnumber, "$self->{numbername}{$num[0]}$self->{numbername}{10**2}";
- # reduce numblock
- $numblock[$i] -= $num[0] * 100;
- @num = split //, $numblock[$i];
- $hundred = 1;
- }
-
- if ($numblock[$i] > 19) {
- # 20 - 99
- push @textnumber, "$self->{numbername}{$num[0]}kümmend";
- @num = split //, $numblock[$i];
- push @textnumber, $self->{numbername}{$num[1]} if $num[1] > 0;
-
- } elsif ($numblock[$i] > 10) {
- # 11 - 19
- if ($hundred) {
- @num = split //, $numblock[$i];
- }
- $num = $num[1];
-
- push @textnumber, "$self->{numbername}{$num}teist";
-
- } elsif ($numblock[$i] > 1) {
- # ones
- push @textnumber, $self->{numbername}{$numblock[$i]};
-
- } elsif ($numblock[$i] == 1) {
- push @textnumber, $self->{numbername}{$num[0]};
- $appendit = "";
-
- }
-
- # add thousand, million
- if ($i) {
- $amount = 10**($i * 3);
- $appendit = ($i == 1) ? "" : $appendit;
- push @textnumber, "$self->{numbername}{$amount}$appendit";
- }
-
- pop @numblock;
-
- }
-
- join ' ', @textnumber;
+ my ( $self, $amount ) = @_;
-}
+ return $self->{numbername}{0} unless $amount;
+ my @textnumber = ();
-sub num2text_es {
- my ($self, $amount) = @_;
-
- return $self->{numbername}{0} unless $amount;
-
- my @textnumber = ();
-
- # split amount into chunks of 3
- my @num = reverse split //, abs($amount);
- my @numblock = ();
- my $stripun = 0;
- my @a = ();
- my $i;
-
- while (@num) {
- @a = ();
- for (1 .. 3) {
- push @a, shift @num;
- }
- push @numblock, join / /, reverse @a;
- }
-
- # special case for 1000
- if ($numblock[1] eq '1' && $numblock[0] gt '000') {
- # remove first array element from textnumber
- $stripun = 1;
- }
-
- while (@numblock) {
-
- $i = $#numblock;
- @num = split //, $numblock[$i];
-
- $numblock[$i] *= 1;
-
- if ($numblock[$i] == 0) {
- pop @numblock;
- next;
- }
-
- if ($numblock[$i] > 99) {
- if ($num[0] == 1) {
- push @textnumber, $self->{numbername}{10**2};
- } else {
- # special case for 500, 700, 900
- if (grep /$num[0]/, (5,7,9)) {
- push @textnumber, $self->{numbername}{"${num[0]}00"};
-
- } else {
-
- # the one from hundreds, append cientos
- push @textnumber, $self->{numbername}{$num[0]}.$self->{numbername}{10**2}.'s';
-
- }
- }
-
- # reduce numblock
- $numblock[$i] -= $num[0] * 100;
- }
-
- if ($numblock[$i] > 9) {
- # tens
- push @textnumber, $self->format_ten_es($numblock[$i], $i);
- } elsif ($numblock[$i] > 0) {
- # ones
- $num = $numblock[$i];
- $num .= 'o' if ($num == 1 && $i == 0);
- push @textnumber, $self->{numbername}{$num};
- }
-
- # add thousand, million
- if ($i) {
- $num = 10**($i * 3);
- if ($numblock[$i] > 1) {
- if ($i == 2 || $i == 4) {
- $a = $self->{numbername}{$num}."es";
- $a =~ s/ó/o/;
- push @textnumber, $a;
- } elsif ($i == 3) {
- $num = 10**($i * 2);
- $a = "$self->{10**3} $self->{numbername}{$num}"."es";
- $a =~ s/ó/o/;
- push @textnumber, $a;
- } else {
- if ($i == 1) {
- push @textnumber, $self->{numbername}{$num};
- } else {
- push @textnumber, $self->{numbername}{$num}.'s';
- }
- }
- } else {
- push @textnumber, $self->{numbername}{$num};
- }
- }
-
- pop @numblock;
-
- }
-
- shift @textnumber if $stripun;
-
- join ' ', @textnumber;
+ # split amount into chunks of 3
+ my @num = reverse split //, abs($amount);
+ my @numblock = ();
+ my ( $i, $appendit );
+ my @a = ();
+
+ while (@num) {
+ @a = ();
+ for ( 1 .. 3 ) {
+ push @a, shift @num;
+ }
+ push @numblock, join / /, reverse @a;
+ }
+
+ while (@numblock) {
+
+ $i = $#numblock;
+ $numblock[$i] *= 1;
+ @num = split //, $numblock[$i];
+
+ $appendit = "it";
+ $hundred = 0;
+
+ if ( $numblock[$i] == 0 ) {
+ pop @numblock;
+ next;
+ }
+
+ if ( $numblock[$i] > 99 ) {
+
+ # the one from hundreds
+ push @textnumber,
+ "$self->{numbername}{$num[0]}$self->{numbername}{10**2}";
+
+ # reduce numblock
+ $numblock[$i] -= $num[0] * 100;
+ @num = split //, $numblock[$i];
+ $hundred = 1;
+ }
+
+ if ( $numblock[$i] > 19 ) {
+
+ # 20 - 99
+ push @textnumber, "$self->{numbername}{$num[0]}kümmend";
+ @num = split //, $numblock[$i];
+ push @textnumber, $self->{numbername}{ $num[1] } if $num[1] > 0;
+
+ }
+ elsif ( $numblock[$i] > 10 ) {
+
+ # 11 - 19
+ if ($hundred) {
+ @num = split //, $numblock[$i];
+ }
+ $num = $num[1];
+
+ push @textnumber, "$self->{numbername}{$num}teist";
+
+ }
+ elsif ( $numblock[$i] > 1 ) {
+
+ # ones
+ push @textnumber, $self->{numbername}{ $numblock[$i] };
+
+ }
+ elsif ( $numblock[$i] == 1 ) {
+ push @textnumber, $self->{numbername}{ $num[0] };
+ $appendit = "";
+
+ }
+
+ # add thousand, million
+ if ($i) {
+ $amount = 10**( $i * 3 );
+ $appendit = ( $i == 1 ) ? "" : $appendit;
+ push @textnumber, "$self->{numbername}{$amount}$appendit";
+ }
+
+ pop @numblock;
+
+ }
+
+ join ' ', @textnumber;
}
+sub num2text_es {
+ my ( $self, $amount ) = @_;
+
+ return $self->{numbername}{0} unless $amount;
+
+ my @textnumber = ();
+
+ # split amount into chunks of 3
+ my @num = reverse split //, abs($amount);
+ my @numblock = ();
+ my $stripun = 0;
+ my @a = ();
+ my $i;
+
+ while (@num) {
+ @a = ();
+ for ( 1 .. 3 ) {
+ push @a, shift @num;
+ }
+ push @numblock, join / /, reverse @a;
+ }
+
+ # special case for 1000
+ if ( $numblock[1] eq '1' && $numblock[0] gt '000' ) {
+
+ # remove first array element from textnumber
+ $stripun = 1;
+ }
+
+ while (@numblock) {
+
+ $i = $#numblock;
+ @num = split //, $numblock[$i];
+
+ $numblock[$i] *= 1;
+
+ if ( $numblock[$i] == 0 ) {
+ pop @numblock;
+ next;
+ }
+
+ if ( $numblock[$i] > 99 ) {
+ if ( $num[0] == 1 ) {
+ push @textnumber, $self->{numbername}{ 10**2 };
+ }
+ else {
+
+ # special case for 500, 700, 900
+ if ( grep /$num[0]/, ( 5, 7, 9 ) ) {
+ push @textnumber, $self->{numbername}{"${num[0]}00"};
+
+ }
+ else {
+
+ # the one from hundreds, append cientos
+ push @textnumber,
+ $self->{numbername}{ $num[0] }
+ . $self->{numbername}{ 10**2 } . 's';
+
+ }
+ }
+
+ # reduce numblock
+ $numblock[$i] -= $num[0] * 100;
+ }
+
+ if ( $numblock[$i] > 9 ) {
+
+ # tens
+ push @textnumber, $self->format_ten_es( $numblock[$i], $i );
+ }
+ elsif ( $numblock[$i] > 0 ) {
+
+ # ones
+ $num = $numblock[$i];
+ $num .= 'o' if ( $num == 1 && $i == 0 );
+ push @textnumber, $self->{numbername}{$num};
+ }
+
+ # add thousand, million
+ if ($i) {
+ $num = 10**( $i * 3 );
+ if ( $numblock[$i] > 1 ) {
+ if ( $i == 2 || $i == 4 ) {
+ $a = $self->{numbername}{$num} . "es";
+ $a =~ s/ó/o/;
+ push @textnumber, $a;
+ }
+ elsif ( $i == 3 ) {
+ $num = 10**( $i * 2 );
+ $a = "$self->{10**3} $self->{numbername}{$num}" . "es";
+ $a =~ s/ó/o/;
+ push @textnumber, $a;
+ }
+ else {
+ if ( $i == 1 ) {
+ push @textnumber, $self->{numbername}{$num};
+ }
+ else {
+ push @textnumber, $self->{numbername}{$num} . 's';
+ }
+ }
+ }
+ else {
+ push @textnumber, $self->{numbername}{$num};
+ }
+ }
+
+ pop @numblock;
+
+ }
+
+ shift @textnumber if $stripun;
+
+ join ' ', @textnumber;
-sub format_ten_es {
- my ($self, $amount, $i) = @_;
-
- my $textnumber = "";
- my @num = split //, $amount;
-
- if ($amount > 30) {
- $textnumber = $self->{numbername}{$num[0]*10};
- $amount = $num[1];
- } else {
- $amount .= 'o' if ($num[1] == 1 && $i == 0);
- $textnumber = $self->{numbername}{$amount};
- $amount = 0;
- }
-
- $textnumber .= " y ".$self->{numbername}{$amount} if $amount;
-
- $textnumber;
-
}
+sub format_ten_es {
+ my ( $self, $amount, $i ) = @_;
-sub num2text_fr {
- my ($self, $amount) = @_;
-
- return $self->{numbername}{0} unless $amount;
-
- my @textnumber = ();
-
- # split amount into chunks of 3
- my @num = reverse split //, abs($amount);
- my @numblock = ();
- my @a;
- my $i;
-
- while (@num) {
- @a = ();
- for (1 .. 3) {
- push @a, shift @num;
- }
- push @numblock, join / /, reverse @a;
- }
-
- my $cent=0;
-
- while (@numblock) {
-
- $i = $#numblock;
- @num = split //, $numblock[$i];
-
- if ($numblock[$i] == 0) {
- pop @numblock;
- next;
- }
-
- if ($numblock[$i] > 99) {
- $cent=1;
-
- # the one from hundreds
-
- if ($num[0] > 1) {
- push @textnumber, $self->{numbername}{$num[0]};
- }
-
- # reduce numblock
- $numblock[$i] -= $num[0] * 100;
-
- # add hundred designation
- if ($num[0] > 1) {
- if($numblock[$i] > 0) {
- push @textnumber, $self->{numbername}{10**2};
- } else {
- push @textnumber, "$self->{numbername}{10**2}s";
- }
- } else {
- push @textnumber, $self->{numbername}{10**2};
- }
-
- }
-
- $numblock[$i] *= 1;
-
- if ($numblock[$i] > 9) {
- # tens
- push @textnumber, $self->format_ten_fr($numblock[$i]);
- } elsif ($numblock[$i] > 0) {
- # ones
- if ($i == 1) {
- if ($cent == 1) {
- push @textnumber, $self->{numbername}{$numblock[$i]};
- }
- $cent = 0;
- } else {
- push @textnumber, $self->{numbername}{$numblock[$i]};
- }
- }
-
- # add thousand, million
- if ($i) {
- $num = 10**($i * 3);
- if ($i == 1) {
- push @textnumber, $self->{numbername}{$num};
- } elsif ($numblock[$i] > 1) {
- push @textnumber, "$self->{numbername}{$num}s";
- } else {
- push @textnumber, "$self->{numbername}{$num}";
- }
- }
-
- pop @numblock;
-
- }
-
- join ' ', @textnumber;
+ my $textnumber = "";
+ my @num = split //, $amount;
+
+ if ( $amount > 30 ) {
+ $textnumber = $self->{numbername}{ $num[0] * 10 };
+ $amount = $num[1];
+ }
+ else {
+ $amount .= 'o' if ( $num[1] == 1 && $i == 0 );
+ $textnumber = $self->{numbername}{$amount};
+ $amount = 0;
+ }
+
+ $textnumber .= " y " . $self->{numbername}{$amount} if $amount;
+
+ $textnumber;
}
+sub num2text_fr {
+ my ( $self, $amount ) = @_;
+
+ return $self->{numbername}{0} unless $amount;
+
+ my @textnumber = ();
+
+ # split amount into chunks of 3
+ my @num = reverse split //, abs($amount);
+ my @numblock = ();
+ my @a;
+ my $i;
+
+ while (@num) {
+ @a = ();
+ for ( 1 .. 3 ) {
+ push @a, shift @num;
+ }
+ push @numblock, join / /, reverse @a;
+ }
+
+ my $cent = 0;
+
+ while (@numblock) {
+
+ $i = $#numblock;
+ @num = split //, $numblock[$i];
+
+ if ( $numblock[$i] == 0 ) {
+ pop @numblock;
+ next;
+ }
+
+ if ( $numblock[$i] > 99 ) {
+ $cent = 1;
+
+ # the one from hundreds
+
+ if ( $num[0] > 1 ) {
+ push @textnumber, $self->{numbername}{ $num[0] };
+ }
+
+ # reduce numblock
+ $numblock[$i] -= $num[0] * 100;
+
+ # add hundred designation
+ if ( $num[0] > 1 ) {
+ if ( $numblock[$i] > 0 ) {
+ push @textnumber, $self->{numbername}{ 10**2 };
+ }
+ else {
+ push @textnumber, "$self->{numbername}{10**2}s";
+ }
+ }
+ else {
+ push @textnumber, $self->{numbername}{ 10**2 };
+ }
+
+ }
+
+ $numblock[$i] *= 1;
+
+ if ( $numblock[$i] > 9 ) {
+
+ # tens
+ push @textnumber, $self->format_ten_fr( $numblock[$i] );
+ }
+ elsif ( $numblock[$i] > 0 ) {
+
+ # ones
+ if ( $i == 1 ) {
+ if ( $cent == 1 ) {
+ push @textnumber, $self->{numbername}{ $numblock[$i] };
+ }
+ $cent = 0;
+ }
+ else {
+ push @textnumber, $self->{numbername}{ $numblock[$i] };
+ }
+ }
+
+ # add thousand, million
+ if ($i) {
+ $num = 10**( $i * 3 );
+ if ( $i == 1 ) {
+ push @textnumber, $self->{numbername}{$num};
+ }
+ elsif ( $numblock[$i] > 1 ) {
+ push @textnumber, "$self->{numbername}{$num}s";
+ }
+ else {
+ push @textnumber, "$self->{numbername}{$num}";
+ }
+ }
+
+ pop @numblock;
+
+ }
+
+ join ' ', @textnumber;
-sub format_ten_fr {
- my ($self, $amount) = @_;
-
- my $textnumber = "";
- my @num = split //, $amount;
-
- if ($amount > 20) {
- if ($num[0] == 8) {
- if ($num[1] > 0) {
- $textnumber = $self->{numbername}{$num[0]*10};
- } else {
- $textnumber = "$self->{numbername}{$num[0]*10}s";
- }
- $amount = $num[1];
- } elsif ($num[0] == 7 || $num[0] == 9) {
- if ($num[1] > 0) {
- $textnumber = $self->{numbername}{($num[0]-1)*10};
-
- $textnumber .= " et" if ($num[1] == 1 && $num[0] == 7);
-
- $amount -= ($num[0]-1)*10;
- } else {
- $textnumber = $self->{numbername}{$num[0]*10};
- $amount = $num[1];
- }
- } else {
- $textnumber = $self->{numbername}{$num[0]*10};
- $textnumber .= " et" if ($num[1] == 1);
- $amount = $num[1];
- }
- } else {
- $textnumber = "$self->{numbername}{$amount}";
- $amount = 0;
- }
-
- $textnumber .= " ".$self->{numbername}{$amount} if $amount;
-
- $textnumber;
-
}
+sub format_ten_fr {
+ my ( $self, $amount ) = @_;
+
+ my $textnumber = "";
+ my @num = split //, $amount;
+
+ if ( $amount > 20 ) {
+ if ( $num[0] == 8 ) {
+ if ( $num[1] > 0 ) {
+ $textnumber = $self->{numbername}{ $num[0] * 10 };
+ }
+ else {
+ $textnumber = "$self->{numbername}{$num[0]*10}s";
+ }
+ $amount = $num[1];
+ }
+ elsif ( $num[0] == 7 || $num[0] == 9 ) {
+ if ( $num[1] > 0 ) {
+ $textnumber = $self->{numbername}{ ( $num[0] - 1 ) * 10 };
+
+ $textnumber .= " et" if ( $num[1] == 1 && $num[0] == 7 );
+
+ $amount -= ( $num[0] - 1 ) * 10;
+ }
+ else {
+ $textnumber = $self->{numbername}{ $num[0] * 10 };
+ $amount = $num[1];
+ }
+ }
+ else {
+ $textnumber = $self->{numbername}{ $num[0] * 10 };
+ $textnumber .= " et" if ( $num[1] == 1 );
+ $amount = $num[1];
+ }
+ }
+ else {
+ $textnumber = "$self->{numbername}{$amount}";
+ $amount = 0;
+ }
+
+ $textnumber .= " " . $self->{numbername}{$amount} if $amount;
+
+ $textnumber;
-sub num2text_hu {
- my ($self, $amount) = @_;
-
- return $self->{numbername}{0} unless $amount;
-
- my @textnumber = ();
-
- # split amount into chunks of 3
- my @num = reverse split //, abs($amount);
- my @numblock = ();
- my @a;
- my $i;
- my $res;
- while (@num) {
- @a = ();
- for (1 .. 3) {
- push @a, shift @num;
- }
- push @numblock, join / /, reverse @a;
- }
- while (@numblock) {
- $i = $#numblock;
- @num = split //, $numblock[$i];
-
- if ($numblock[$i] == 0) {
- pop @numblock;
- next;
- }
- if ($numblock[$i] > 99) {
- push @textnumber, $self->{numbername}{$num[0]};
-
- # add hundred designation
- push @textnumber, $self->{numbername}{10**2};
-
- # reduce numblock
- $numblock[$i] -= $num[0] * 100;
-
- }
-
- $numblock[$i] *= 1;
- if ($numblock[$i] > 9) {
- # tens
- push @textnumber, $self->format_ten_hu($numblock[$i]);
- } elsif ($numblock[$i] > 0) {
- # ones
- push @textnumber, $self->{numbername}{$numblock[$i]};
- }
-
- # add thousand, million
- if ($i) {
- if ($i==1 && $amount < 2000){
-
- $num = 10**($i * 3);
- push @textnumber, $self->{numbername}{$num};
- } else {
-
- $num = 10**($i * 3);
- push @textnumber, $self->{numbername}{$num}."-";
- }
- }
-
- pop @numblock;
-
- }
- $res=ucfirst join '', @textnumber;
- $res=~s/(\-)$//;
- return $res;
}
+sub num2text_hu {
+ my ( $self, $amount ) = @_;
+
+ return $self->{numbername}{0} unless $amount;
+
+ my @textnumber = ();
+
+ # split amount into chunks of 3
+ my @num = reverse split //, abs($amount);
+ my @numblock = ();
+ my @a;
+ my $i;
+ my $res;
+ while (@num) {
+ @a = ();
+ for ( 1 .. 3 ) {
+ push @a, shift @num;
+ }
+ push @numblock, join / /, reverse @a;
+ }
+ while (@numblock) {
+ $i = $#numblock;
+ @num = split //, $numblock[$i];
+
+ if ( $numblock[$i] == 0 ) {
+ pop @numblock;
+ next;
+ }
+ if ( $numblock[$i] > 99 ) {
+ push @textnumber, $self->{numbername}{ $num[0] };
+
+ # add hundred designation
+ push @textnumber, $self->{numbername}{ 10**2 };
+
+ # reduce numblock
+ $numblock[$i] -= $num[0] * 100;
+
+ }
+
+ $numblock[$i] *= 1;
+ if ( $numblock[$i] > 9 ) {
+
+ # tens
+ push @textnumber, $self->format_ten_hu( $numblock[$i] );
+ }
+ elsif ( $numblock[$i] > 0 ) {
+
+ # ones
+ push @textnumber, $self->{numbername}{ $numblock[$i] };
+ }
+
+ # add thousand, million
+ if ($i) {
+ if ( $i == 1 && $amount < 2000 ) {
+
+ $num = 10**( $i * 3 );
+ push @textnumber, $self->{numbername}{$num};
+ }
+ else {
+
+ $num = 10**( $i * 3 );
+ push @textnumber, $self->{numbername}{$num} . "-";
+ }
+ }
+
+ pop @numblock;
+
+ }
+ $res = ucfirst join '', @textnumber;
+ $res =~ s/(\-)$//;
+ return $res;
+}
sub format_ten_hu {
- my ($self, $amount) = @_;
+ my ( $self, $amount ) = @_;
- my $textnumber = "";
- my @num = split //, $amount;
- if ($amount > 30) {
- $textnumber = $self->{numbername}{$num[0]*10};
- $amount = $num[1];
- } else {
- $textnumber = $self->{numbername}{$amount};
- $amount = 0;
- }
+ my $textnumber = "";
+ my @num = split //, $amount;
+ if ( $amount > 30 ) {
+ $textnumber = $self->{numbername}{ $num[0] * 10 };
+ $amount = $num[1];
+ }
+ else {
+ $textnumber = $self->{numbername}{$amount};
+ $amount = 0;
+ }
- $textnumber .= "".$self->{numbername}{$amount} if $amount;
+ $textnumber .= "" . $self->{numbername}{$amount} if $amount;
- $textnumber;
+ $textnumber;
}
-
sub num2text_nl {
- my ($self, $amount) = @_;
-
- return $self->{numbername}{0} unless $amount;
-
- my @textnumber = ('**');
-
- # split amount into chunks of 3
- my @num = reverse split //, abs($amount);
- my @numblock = ();
- my ($i, $appendn);
- my @a = ();
-
- while (@num) {
- @a = ();
- for (1 .. 3) {
- push @a, shift @num;
- }
- push @numblock, join / /, reverse @a;
- }
-
-
- while (@numblock) {
-
- $i = $#numblock;
- @num = split //, $numblock[$i];
-
- $numblock[$i] *= 1;
-
- if ($numblock[$i] == 0) {
- pop @numblock;
- next;
- }
-
- if ($numblock[$i] > 99) {
- # the one from hundreds
- push @textnumber, $self->{numbername}{$num[0]};
-
- # add hundred designation
- push @textnumber, $self->{numbername}{10**2};
-
- # reduce numblock
- $numblock[$i] -= $num[0] * 100;
- }
-
- if ($numblock[$i] > 9) {
- # tens
- push @textnumber, $self->format_ten_nl($numblock[$i]);
- } else {
- # ones
- push @textnumber, $self->{numbername}{$numblock[$i]};
- }
-
- # add thousand, million
- if ($i) {
- $amount = 10**($i * 3);
- push @textnumber, $self->{numbername}{$amount};
- }
-
- pop @numblock;
-
- }
-
- push @textnumber, '**';
- join '', @textnumber;
+ my ( $self, $amount ) = @_;
-}
+ return $self->{numbername}{0} unless $amount;
+ my @textnumber = ('**');
+
+ # split amount into chunks of 3
+ my @num = reverse split //, abs($amount);
+ my @numblock = ();
+ my ( $i, $appendn );
+ my @a = ();
+
+ while (@num) {
+ @a = ();
+ for ( 1 .. 3 ) {
+ push @a, shift @num;
+ }
+ push @numblock, join / /, reverse @a;
+ }
+
+ while (@numblock) {
+
+ $i = $#numblock;
+ @num = split //, $numblock[$i];
+
+ $numblock[$i] *= 1;
+
+ if ( $numblock[$i] == 0 ) {
+ pop @numblock;
+ next;
+ }
+
+ if ( $numblock[$i] > 99 ) {
+
+ # the one from hundreds
+ push @textnumber, $self->{numbername}{ $num[0] };
+
+ # add hundred designation
+ push @textnumber, $self->{numbername}{ 10**2 };
+
+ # reduce numblock
+ $numblock[$i] -= $num[0] * 100;
+ }
+
+ if ( $numblock[$i] > 9 ) {
+
+ # tens
+ push @textnumber, $self->format_ten_nl( $numblock[$i] );
+ }
+ else {
+
+ # ones
+ push @textnumber, $self->{numbername}{ $numblock[$i] };
+ }
+
+ # add thousand, million
+ if ($i) {
+ $amount = 10**( $i * 3 );
+ push @textnumber, $self->{numbername}{$amount};
+ }
+
+ pop @numblock;
+
+ }
+
+ push @textnumber, '**';
+ join '', @textnumber;
-sub format_ten_nl {
- my ($self, $amount) = @_;
-
- my $textnumber = "";
- my @num = split //, $amount;
-
- if ($amount > 20) {
- # reverse one and ten and glue together with 'en'
- $amount = $num[0] * 10;
- $textnumber = $self->{numbername}{$num[1]}.'en'.$self->{numbername}{$amount};
- } else {
- $textnumber = $self->{numbername}{$amount};
- }
-
- $textnumber;
-
}
+sub format_ten_nl {
+ my ( $self, $amount ) = @_;
-sub num2text_it {
- my ($self, $amount) = @_;
-
- return $self->{numbername}{0} unless $amount;
-
- my @textnumber = ();
-
- # split amount into chunks of 3
- my @num = reverse split //, abs($amount);
- my @numblock = ();
- my ($i, $appendn);
- my @a = ();
-
- while (@num) {
- @a = ();
- for (1 .. 3) {
- push @a, shift @num;
- }
- push @numblock, join / /, reverse @a;
- }
-
- while (@numblock) {
-
- $i = $#numblock;
- @num = split //, $numblock[$i];
-
- $numblock[$i] *= 1;
-
- if ($numblock[$i] == 0) {
- pop @numblock;
- next;
- }
-
- if ($numblock[$i] > 99) {
- # the one from hundreds
- push @textnumber, $self->{numbername}{$num[0]};
-
- # add hundred designation
- push @textnumber, $self->{numbername}{10**2};
-
- # reduce numblock
- $numblock[$i] -= $num[0] * 100;
- }
-
- if ($numblock[$i] > 9) {
- # tens
- push @textnumber, $self->format_ten_it($numblock[$i]);
- } elsif ($numblock[$i] > 1) {
- # ones
- push @textnumber, $self->{numbername}{$numblock[$i]};
- }
-
- # add thousand, million
- if ($i) {
- $amount = 10**($i * 3);
- push @textnumber, $self->{numbername}{$amount};
- }
-
- pop @numblock;
-
- }
-
- join '', @textnumber;
+ my $textnumber = "";
+ my @num = split //, $amount;
+
+ if ( $amount > 20 ) {
+
+ # reverse one and ten and glue together with 'en'
+ $amount = $num[0] * 10;
+ $textnumber =
+ $self->{numbername}{ $num[1] } . 'en' . $self->{numbername}{$amount};
+ }
+ else {
+ $textnumber = $self->{numbername}{$amount};
+ }
+
+ $textnumber;
}
+sub num2text_it {
+ my ( $self, $amount ) = @_;
+
+ return $self->{numbername}{0} unless $amount;
+
+ my @textnumber = ();
+
+ # split amount into chunks of 3
+ my @num = reverse split //, abs($amount);
+ my @numblock = ();
+ my ( $i, $appendn );
+ my @a = ();
+
+ while (@num) {
+ @a = ();
+ for ( 1 .. 3 ) {
+ push @a, shift @num;
+ }
+ push @numblock, join / /, reverse @a;
+ }
+
+ while (@numblock) {
+
+ $i = $#numblock;
+ @num = split //, $numblock[$i];
+
+ $numblock[$i] *= 1;
+
+ if ( $numblock[$i] == 0 ) {
+ pop @numblock;
+ next;
+ }
+
+ if ( $numblock[$i] > 99 ) {
+
+ # the one from hundreds
+ push @textnumber, $self->{numbername}{ $num[0] };
+
+ # add hundred designation
+ push @textnumber, $self->{numbername}{ 10**2 };
+
+ # reduce numblock
+ $numblock[$i] -= $num[0] * 100;
+ }
+
+ if ( $numblock[$i] > 9 ) {
+
+ # tens
+ push @textnumber, $self->format_ten_it( $numblock[$i] );
+ }
+ elsif ( $numblock[$i] > 1 ) {
+
+ # ones
+ push @textnumber, $self->{numbername}{ $numblock[$i] };
+ }
+
+ # add thousand, million
+ if ($i) {
+ $amount = 10**( $i * 3 );
+ push @textnumber, $self->{numbername}{$amount};
+ }
+
+ pop @numblock;
+
+ }
+
+ join '', @textnumber;
-sub format_ten_it {
- my ($self, $amount) = @_;
-
- my $textnumber = "";
- my @num = split //, $amount;
-
- if ($amount > 20) {
- if ($num[1] == 0) {
- $textnumber = $self->{numbername}{$amount};
- } else {
- $amount = $num[0] * 10;
- $textnumber = $self->{numbername}{$amount}.$self->{numbername}{$num[1]};
- }
- } else {
- $textnumber = $self->{numbername}{$amount};
- }
-
- $textnumber;
-
}
+sub format_ten_it {
+ my ( $self, $amount ) = @_;
+
+ my $textnumber = "";
+ my @num = split //, $amount;
+
+ if ( $amount > 20 ) {
+ if ( $num[1] == 0 ) {
+ $textnumber = $self->{numbername}{$amount};
+ }
+ else {
+ $amount = $num[0] * 10;
+ $textnumber =
+ $self->{numbername}{$amount} . $self->{numbername}{ $num[1] };
+ }
+ }
+ else {
+ $textnumber = $self->{numbername}{$amount};
+ }
+
+ $textnumber;
+
+}
# A special (swedish-like) spelling of danish check numbers
sub num2text_da {
- my ($self, $amount) = @_;
-
- # Handle 0
- return $self->{numbername}{0} unless $amount;
-
- # List of collected digits
- my @textnumber = ();
-
- # split amount into chunks of 3
- my @num = reverse split //, abs($amount);
- my @numblock = ();
- my @a = ();
- while (@num) {
- @a = ();
- for (1 .. 3) {
- push @a, shift @num;
- }
- push @numblock, join / /, reverse @a;
- }
-
- my $i;
- my $bigplural;
- while (@numblock) {
- $i = $#numblock;
- $numblock[$i] *= 1;
-
- if ($numblock[$i] == 0) {
- pop @numblock;
- next;
- }
-
- # Plural suffix "er" for million and up, not for tusinde
- $bigpluralsuffix = "";
- $bigpluralsuffix = "er" if ($i > 1 && $numblock[$i] > 1);
-
- if ($numblock[$i] > 99) {
- @num = split //, $numblock[$i];
-
- # the one from hundreds
- push @textnumber, $self->{numbername}{$num[0]};
-
- # add hundred designation
- push @textnumber, $self->{numbername}{100};
-
- # reduce numblock
- $numblock[$i] -= $num[0] * 100;
- }
-
- if ($numblock[$i] > 9) {
- @num = split //, $numblock[$i];
-
- # the one from tens
- push @textnumber, $self->{numbername}{$num[0]};
-
- # add ten designation
- push @textnumber, $self->{numbername}{10};
-
- # reduce numblock
- $numblock[$i] -= $num[0] * 10;
- }
-
- if ($numblock[$i] > 0) {
- # the ones left in the block
- if($numblock[$i] == 1 && $i != 1) {
- push @textnumber, $self->{numbername}{'1o'}; # Special case for "Et" tusinde
- } else {
- push @textnumber, $self->{numbername}{$numblock[$i]};
- }
- }
-
- # add thousand, million, etc
- if ($i) {
- $amount = 10**($i * 3);
- push @textnumber, $self->{numbername}{$amount}.$bigpluralsuffix;
- }
-
- pop @numblock;
- }
-
- join '', @textnumber;
+ my ( $self, $amount ) = @_;
+
+ # Handle 0
+ return $self->{numbername}{0} unless $amount;
+
+ # List of collected digits
+ my @textnumber = ();
+
+ # split amount into chunks of 3
+ my @num = reverse split //, abs($amount);
+ my @numblock = ();
+ my @a = ();
+ while (@num) {
+ @a = ();
+ for ( 1 .. 3 ) {
+ push @a, shift @num;
+ }
+ push @numblock, join / /, reverse @a;
+ }
+
+ my $i;
+ my $bigplural;
+ while (@numblock) {
+ $i = $#numblock;
+ $numblock[$i] *= 1;
+
+ if ( $numblock[$i] == 0 ) {
+ pop @numblock;
+ next;
+ }
+
+ # Plural suffix "er" for million and up, not for tusinde
+ $bigpluralsuffix = "";
+ $bigpluralsuffix = "er" if ( $i > 1 && $numblock[$i] > 1 );
+
+ if ( $numblock[$i] > 99 ) {
+ @num = split //, $numblock[$i];
+
+ # the one from hundreds
+ push @textnumber, $self->{numbername}{ $num[0] };
+
+ # add hundred designation
+ push @textnumber, $self->{numbername}{100};
+
+ # reduce numblock
+ $numblock[$i] -= $num[0] * 100;
+ }
+
+ if ( $numblock[$i] > 9 ) {
+ @num = split //, $numblock[$i];
+
+ # the one from tens
+ push @textnumber, $self->{numbername}{ $num[0] };
+
+ # add ten designation
+ push @textnumber, $self->{numbername}{10};
+
+ # reduce numblock
+ $numblock[$i] -= $num[0] * 10;
+ }
+
+ if ( $numblock[$i] > 0 ) {
+
+ # the ones left in the block
+ if ( $numblock[$i] == 1 && $i != 1 ) {
+ push @textnumber,
+ $self->{numbername}{'1o'}; # Special case for "Et" tusinde
+ }
+ else {
+ push @textnumber, $self->{numbername}{ $numblock[$i] };
+ }
+ }
+
+ # add thousand, million, etc
+ if ($i) {
+ $amount = 10**( $i * 3 );
+ push @textnumber, $self->{numbername}{$amount} . $bigpluralsuffix;
+ }
+
+ pop @numblock;
+ }
+
+ join '', @textnumber;
}
diff --git a/LedgerSMB/OE.pm b/LedgerSMB/OE.pm
index de624ddd..9dc7cea3 100644
--- a/LedgerSMB/OE.pm
+++ b/LedgerSMB/OE.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -23,8 +23,8 @@
#
#======================================================================
#
-# This file has undergone whitespace cleanup
-#
+# This file has undergone whitespace cleanup
+#
#======================================================================
#
# Order entry module
@@ -36,47 +36,46 @@ package OE;
use LedgerSMB::Tax;
use LedgerSMB::Sysconfig;
-
sub transactions {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my $query;
- my $null;
- my $var;
- my $ordnumber = 'ordnumber';
- my $quotation = '0';
- my $department;
-
- my $rate = ($form->{vc} eq 'customer') ? 'buy' : 'sell';
-
- ($form->{transdatefrom}, $form->{transdateto}) =
- $form->from_to($form->{year}, $form->{month}, $form->{interval})
- if $form->{year} && $form->{month};
-
- if ($form->{type} =~ /_quotation$/) {
- $quotation = '1';
- $ordnumber = 'quonumber';
- }
-
- my $number = $form->like(lc $form->{$ordnumber});
- my $name = $form->like(lc $form->{$form->{vc}});
- my @dptargs = ();
-
- for (qw(department employee)) {
- if ($form->{$_}) {
- ($null, $var) = split /--/, $form->{$_};
- $department .= " AND o.${_}_id = ?";
- push @dptargs, $var;
- }
- }
-
- if ($form->{vc} ne 'customer'){ # Sanitize $form->{vc}
- $form->{vc} = 'vendor';
- }
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my $query;
+ my $null;
+ my $var;
+ my $ordnumber = 'ordnumber';
+ my $quotation = '0';
+ my $department;
+
+ my $rate = ( $form->{vc} eq 'customer' ) ? 'buy' : 'sell';
+
+ ( $form->{transdatefrom}, $form->{transdateto} ) =
+ $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
+ if $form->{year} && $form->{month};
+
+ if ( $form->{type} =~ /_quotation$/ ) {
+ $quotation = '1';
+ $ordnumber = 'quonumber';
+ }
+
+ my $number = $form->like( lc $form->{$ordnumber} );
+ my $name = $form->like( lc $form->{ $form->{vc} } );
+ my @dptargs = ();
+
+ for (qw(department employee)) {
+ if ( $form->{$_} ) {
+ ( $null, $var ) = split /--/, $form->{$_};
+ $department .= " AND o.${_}_id = ?";
+ push @dptargs, $var;
+ }
+ }
+
+ if ( $form->{vc} ne 'customer' ) { # Sanitize $form->{vc}
+ $form->{vc} = 'vendor';
+ }
+ my $query = qq|
SELECT o.id, o.ordnumber, o.transdate, o.reqdate,
o.amount, ct.name, o.netamount, o.$form->{vc}_id,
ex.$rate AS exchangerate, o.closed, o.quonumber,
@@ -91,35 +90,36 @@ sub transactions {
WHERE o.quotation = ?
$department|;
- my @queryargs = @dptargs;
- unshift @queryargs, $quotation;
-
- my %ordinal = (
- id => 1,
- ordnumber => 2,
- transdate => 3,
- reqdate => 4,
- name => 6,
- quonumber => 11,
- shipvia => 13,
- employee => 14,
- manager => 15,
- curr => 16,
- ponumber => 17);
-
- my @a = (transdate, $ordnumber, name);
- push @a, "employee" if $form->{l_employee};
- if ($form->{type} !~ /(ship|receive)_order/) {
- push @a, "manager" if $form->{l_manager};
- }
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
- # build query if type eq (ship|receive)_order
- if ($form->{type} =~ /(ship|receive)_order/) {
-
- my ($warehouse, $warehouse_id) = split /--/, $form->{warehouse};
-
- $query = qq|
+ my @queryargs = @dptargs;
+ unshift @queryargs, $quotation;
+
+ my %ordinal = (
+ id => 1,
+ ordnumber => 2,
+ transdate => 3,
+ reqdate => 4,
+ name => 6,
+ quonumber => 11,
+ shipvia => 13,
+ employee => 14,
+ manager => 15,
+ curr => 16,
+ ponumber => 17
+ );
+
+ my @a = ( transdate, $ordnumber, name );
+ push @a, "employee" if $form->{l_employee};
+ if ( $form->{type} !~ /(ship|receive)_order/ ) {
+ push @a, "manager" if $form->{l_manager};
+ }
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ # build query if type eq (ship|receive)_order
+ if ( $form->{type} =~ /(ship|receive)_order/ ) {
+
+ my ( $warehouse, $warehouse_id ) = split /--/, $form->{warehouse};
+
+ $query = qq|
SELECT DISTINCT o.id, o.ordnumber, o.transdate,
o.reqdate, o.amount, ct.name, o.netamount,
o.$form->{vc}_id, ex.$rate AS exchangerate,
@@ -131,13 +131,13 @@ sub transactions {
JOIN orderitems oi ON (oi.trans_id = o.id)
JOIN parts p ON (p.id = oi.parts_id)|;
- if ($warehouse_id && $form->{type} eq 'ship_order') {
- $query .= qq|
+ if ( $warehouse_id && $form->{type} eq 'ship_order' ) {
+ $query .= qq|
JOIN inventory i ON (oi.parts_id = i.parts_id)
|;
- }
+ }
- $query .= qq|
+ $query .= qq|
LEFT JOIN employees e ON (o.employee_id = e.id)
LEFT JOIN exchangerate ex
ON (ex.curr = o.curr
@@ -146,10 +146,10 @@ sub transactions {
AND (p.inventory_accno_id > 0 OR p.assembly = '1')
AND oi.qty != oi.ship
$department|;
- @queryargs = @dptargs; #reset @queryargs
-
- if ($warehouse_id && $form->{type} eq 'ship_order') {
- $query .= qq|
+ @queryargs = @dptargs; #reset @queryargs
+
+ if ( $warehouse_id && $form->{type} eq 'ship_order' ) {
+ $query .= qq|
AND i.warehouse_id = ?
AND (
SELECT SUM(i.qty)
@@ -157,185 +157,192 @@ sub transactions {
WHERE oi.parts_id = i.parts_id
AND i.warehouse_id = ?
) > 0|;
- push(@queryargs, $warehouse_id, $warehouse_id);
- }
-
- }
-
- if ($form->{"$form->{vc}_id"}) {
- $query .= qq| AND o.$form->{vc}_id = $form->{"$form->{vc}_id"}|;
- } elsif ($form->{$form->{vc}} ne "") {
- $query .= " AND lower(ct.name) LIKE ?";
- push @queryargs, $name;
- }
-
- if ($form->{$ordnumber} ne "") {
- $query .= " AND lower(?) LIKE ?";
- push @queryargs, $ordnumber, $number;
- $form->{open} = 1;
- $form->{closed} = 1;
- }
- if ($form->{ponumber} ne "") {
- $query .= " AND lower(ponumber) LIKE ?";
- push @queryargs, $form->{ponumber};
- }
-
- if (!$form->{open} && !$form->{closed}) {
- $query .= " AND o.id = 0";
- } elsif (!($form->{open} && $form->{closed})) {
- $query .= ($form->{open}) ?
- " AND o.closed = '0'" : " AND o.closed = '1'";
- }
-
- if ($form->{shipvia} ne "") {
- $var = $form->like(lc $form->{shipvia});
- $query .= " AND lower(o.shipvia) LIKE ?";
- push @queryargs, $var;
- }
-
- if ($form->{description} ne "") {
- $var = $form->like(lc $form->{description});
- $query .= " AND o.id IN (SELECT DISTINCT trans_id
+ push( @queryargs, $warehouse_id, $warehouse_id );
+ }
+
+ }
+
+ if ( $form->{"$form->{vc}_id"} ) {
+ $query .= qq| AND o.$form->{vc}_id = $form->{"$form->{vc}_id"}|;
+ }
+ elsif ( $form->{ $form->{vc} } ne "" ) {
+ $query .= " AND lower(ct.name) LIKE ?";
+ push @queryargs, $name;
+ }
+
+ if ( $form->{$ordnumber} ne "" ) {
+ $query .= " AND lower(?) LIKE ?";
+ push @queryargs, $ordnumber, $number;
+ $form->{open} = 1;
+ $form->{closed} = 1;
+ }
+ if ( $form->{ponumber} ne "" ) {
+ $query .= " AND lower(ponumber) LIKE ?";
+ push @queryargs, $form->{ponumber};
+ }
+
+ if ( !$form->{open} && !$form->{closed} ) {
+ $query .= " AND o.id = 0";
+ }
+ elsif ( !( $form->{open} && $form->{closed} ) ) {
+ $query .=
+ ( $form->{open} ) ? " AND o.closed = '0'" : " AND o.closed = '1'";
+ }
+
+ if ( $form->{shipvia} ne "" ) {
+ $var = $form->like( lc $form->{shipvia} );
+ $query .= " AND lower(o.shipvia) LIKE ?";
+ push @queryargs, $var;
+ }
+
+ if ( $form->{description} ne "" ) {
+ $var = $form->like( lc $form->{description} );
+ $query .= " AND o.id IN (SELECT DISTINCT trans_id
FROM orderitems
WHERE lower(description) LIKE '$var')";
- push @queryargs, $var;
- }
-
- if ($form->{transdatefrom}) {
- $query .= " AND o.transdate >= ?";
- push @queryargs, $form->{transdatefrom};
- }
- if ($form->{transdateto}) {
- $query .= " AND o.transdate <= ?";
- push @queryargs, $form->{transdateto};
- }
-
- $query .= " ORDER by $sortorder";
-
- my $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $form->dberror($query);
-
- my %oid = ();
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{exchangerate} = 1 unless $ref->{exchangerate};
- if ($ref->{id} != $oid{id}{$ref->{id}}) {
- push @{ $form->{OE} }, $ref;
- $oid{vc}{$ref->{curr}}{$ref->{"$form->{vc}_id"}}++;
- }
- $oid{id}{$ref->{id}} = $ref->{id};
- }
- $sth->finish;
-
- $dbh->commit;
-
- if ($form->{type} =~ /^consolidate_/) {
- @a = ();
- foreach $ref (@{ $form->{OE} }) {
- push @a, $ref if $oid{vc}{$ref->{curr}}
- {$ref->{"$form->{vc}_id"}} > 1;
- }
-
- @{ $form->{OE} } = @a;
- }
+ push @queryargs, $var;
+ }
+
+ if ( $form->{transdatefrom} ) {
+ $query .= " AND o.transdate >= ?";
+ push @queryargs, $form->{transdatefrom};
+ }
+ if ( $form->{transdateto} ) {
+ $query .= " AND o.transdate <= ?";
+ push @queryargs, $form->{transdateto};
+ }
+
+ $query .= " ORDER by $sortorder";
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $form->dberror($query);
+
+ my %oid = ();
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{exchangerate} = 1 unless $ref->{exchangerate};
+ if ( $ref->{id} != $oid{id}{ $ref->{id} } ) {
+ push @{ $form->{OE} }, $ref;
+ $oid{vc}{ $ref->{curr} }{ $ref->{"$form->{vc}_id"} }++;
+ }
+ $oid{id}{ $ref->{id} } = $ref->{id};
+ }
+ $sth->finish;
+
+ $dbh->commit;
+
+ if ( $form->{type} =~ /^consolidate_/ ) {
+ @a = ();
+ foreach $ref ( @{ $form->{OE} } ) {
+ push @a, $ref
+ if $oid{vc}{ $ref->{curr} }{ $ref->{"$form->{vc}_id"} } > 1;
+ }
+
+ @{ $form->{OE} } = @a;
+ }
}
-
-
sub save {
- my ($self, $myconfig, $form) = @_;
-
- $form->db_prepare_vars("quonumber", "transdate", "vendor_id",
- "customer_id", "reqdate", "taxincluded", "shippingpoint",
- "shipvia", "currency", "department_id",
- "employee_id", "language_code", "ponumber", "terms");
- # connect to database, turn off autocommit
- my $dbh = $form->{dbh};
- my @queryargs;
- my $quotation;
- my $ordnumber;
- my $numberfld;
- $form->{vc} = ($form->{vc} eq 'customer') ? 'customer': 'vendor';
- if ($form->{type} =~ /_order$/) {
- $quotation = "0";
- $ordnumber = "ordnumber";
- $numberfld = ($form->{vc} eq 'customer') ? "sonumber" :
- "ponumber";
- } else {
- $quotation = "1";
- $ordnumber = "quonumber";
- $numberfld = ($form->{vc} eq 'customer') ? "sqnumber" :
- "rfqnumber";
- }
-
- $form->{"$ordnumber"} = $form->update_defaults(
- $myconfig, $numberfld, $dbh)
- unless $form->{ordnumber};
-
-
- my $query;
- my $sth;
- my $null;
- my $exchangerate = 0;
-
- ($null, $form->{employee_id}) = split /--/, $form->{employee};
- if (! $form->{employee_id}) {
- ($form->{employee}, $form->{employee_id}) =
- $form->get_employee($dbh);
- $form->{employee} = "$form->{employee}--$form->{employee_id}";
- }
-
- my $ml = ($form->{type} eq 'sales_order') ? 1 : -1;
-
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ $form->db_prepare_vars(
+ "quonumber", "transdate", "vendor_id", "customer_id",
+ "reqdate", "taxincluded", "shippingpoint", "shipvia",
+ "currency", "department_id", "employee_id", "language_code",
+ "ponumber", "terms"
+ );
+
+ # connect to database, turn off autocommit
+ my $dbh = $form->{dbh};
+ my @queryargs;
+ my $quotation;
+ my $ordnumber;
+ my $numberfld;
+ $form->{vc} = ( $form->{vc} eq 'customer' ) ? 'customer' : 'vendor';
+ if ( $form->{type} =~ /_order$/ ) {
+ $quotation = "0";
+ $ordnumber = "ordnumber";
+ $numberfld =
+ ( $form->{vc} eq 'customer' )
+ ? "sonumber"
+ : "ponumber";
+ }
+ else {
+ $quotation = "1";
+ $ordnumber = "quonumber";
+ $numberfld =
+ ( $form->{vc} eq 'customer' )
+ ? "sqnumber"
+ : "rfqnumber";
+ }
+
+ $form->{"$ordnumber"} =
+ $form->update_defaults( $myconfig, $numberfld, $dbh )
+ unless $form->{ordnumber};
+
+ my $query;
+ my $sth;
+ my $null;
+ my $exchangerate = 0;
+
+ ( $null, $form->{employee_id} ) = split /--/, $form->{employee};
+ if ( !$form->{employee_id} ) {
+ ( $form->{employee}, $form->{employee_id} ) = $form->get_employee($dbh);
+ $form->{employee} = "$form->{employee}--$form->{employee_id}";
+ }
+
+ my $ml = ( $form->{type} eq 'sales_order' ) ? 1 : -1;
+
+ $query = qq|
SELECT p.assembly, p.project_id
FROM parts p WHERE p.id = ?|;
- my $pth = $dbh->prepare($query) || $form->dberror($query);
-
-
- if ($form->{id}) {
- $query = qq|SELECT id FROM oe WHERE id = $form->{id}|;
-
- if ($dbh->selectrow_array($query)) {
- &adj_onhand($dbh, $form, $ml)
- if $form->{type} =~ /_order$/;
-
- $query = qq|DELETE FROM orderitems WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $query = qq|DELETE FROM shipto WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- } else { # id is not in the database
- delete $form->{id};
- }
-
- }
-
- my $did_insert = 0;
- if (! $form->{id}) {
- $query = qq|SELECT nextval('id')|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
- ($form->{id}) = $sth->fetchrow_array;
- $sth->finish;
-
- my $uid = localtime;
- $uid .= "$$";
- if (!$form->{reqdate}){
- $form->{reqdate} = undef;
- }
- if (!$form->{transdate}){
- $form->{transdate} = "now";
- }
-
- if (($form->{closed} ne 't') and ($form->{closed} ne "1")){
- $form->{closed} = 'f';
- }
- # $form->{id} is safe because it is only pulled *from* the db.
- $query = qq|
+ my $pth = $dbh->prepare($query) || $form->dberror($query);
+
+ if ( $form->{id} ) {
+ $query = qq|SELECT id FROM oe WHERE id = $form->{id}|;
+
+ if ( $dbh->selectrow_array($query) ) {
+ &adj_onhand( $dbh, $form, $ml )
+ if $form->{type} =~ /_order$/;
+
+ $query = qq|DELETE FROM orderitems WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $query = qq|DELETE FROM shipto WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ }
+ else { # id is not in the database
+ delete $form->{id};
+ }
+
+ }
+
+ my $did_insert = 0;
+ if ( !$form->{id} ) {
+ $query = qq|SELECT nextval('id')|;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+ ( $form->{id} ) = $sth->fetchrow_array;
+ $sth->finish;
+
+ my $uid = localtime;
+ $uid .= "$$";
+ if ( !$form->{reqdate} ) {
+ $form->{reqdate} = undef;
+ }
+ if ( !$form->{transdate} ) {
+ $form->{transdate} = "now";
+ }
+
+ if ( ( $form->{closed} ne 't' ) and ( $form->{closed} ne "1" ) ) {
+ $form->{closed} = 'f';
+ }
+
+ # $form->{id} is safe because it is only pulled *from* the db.
+ $query = qq|
INSERT INTO oe
(id, ordnumber, quonumber, transdate, vendor_id,
customer_id, reqdate, shippingpoint, shipvia,
@@ -347,211 +354,207 @@ sub save {
?, ?, ?, ?,
?, ?, ?, ?, ?,
?, ?, ?, ?, ?)|;
- @queryargs = (
- $form->{ordnumber}, $form->{quonumber},
- $form->{transdate}, $form->{vendor_id},
- $form->{customer_id}, $form->{reqdate},
- $form->{shippingpoint}, $form->{shipvia},
- $form->{notes}, $form->{intnotes}, $form->{currency},
- $form->{closed}, $form->{department_id},
- $form->{employee_id}, $form->{language_code},
- $form->{ponumber}, $form->{terms}, $quotation);
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $form->dberror($query);
- $sth->finish;
-
- @queries = $form->run_custom_queries('oe', 'INSERT');
-
- }
-
- my $amount;
- my $linetotal;
- my $discount;
- my $project_id;
- my $taxrate;
- my $taxamount;
- my $fxsellprice;
- my %taxbase;
- my @taxaccounts;
- my %taxaccounts;
- my $netamount = 0;
-
- my $rowcount = $form->{rowcount};
- for my $i (1 .. $rowcount) {
- $form->db_prepare_vars("orderitems_id_$i", "id_$i",
- "description_$i", "project_id_$i", "ship_$i");
-
- for (qw(qty ship)) {
- $form->{"${_}_$i"} = $form->parse_amount(
- $myconfig, $form->{"${_}_$i"}
- );
- }
-
- $form->{"discount_$i"} = $form->parse_amount(
- $myconfig, $form->{"discount_$i"}
- ) / 100;
-
- $form->{"sellprice_$i"} = $form->parse_amount(
- $myconfig, $form->{"sellprice_$i"}
- );
-
- if ($form->{"qty_$i"}) {
- $pth->execute($form->{"id_$i"});
- $ref = $pth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
- $pth->finish;
-
- $fxsellprice = $form->{"sellprice_$i"};
-
- my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- my $decimalplaces = ($dec > 2) ? $dec : 2;
-
- $discount = $form->round_amount(
- $form->{"sellprice_$i"} *
- $form->{"discount_$i"},
- $decimalplaces
- );
- $form->{"sellprice_$i"} = $form->round_amount(
- $form->{"sellprice_$i"} - $discount,
- $decimalplaces
- );
-
- $linetotal = $form->round_amount(
- $form->{"sellprice_$i"} * $form->{"qty_$i"}, 2
- );
-
- @taxaccounts = Tax::init_taxes($form,
- $form->{"taxaccounts_$i"});
- if ($form->{taxincluded}) {
- $taxamount = Tax::calculate_taxes(\@taxaccounts,
- $form, $linetotal, 1);
- $form->{"sellprice_$i"} = Tax::extract_taxes(\@taxaccounts,
- $form, $form->{"sellprice_$i"});
- $taxbase = Tax::extract_taxes(\@taxaccounts,
- $form, $linetotal);
- } else {
- $taxamount = Tax::apply_taxes(\@taxaccounts,
- $form, $linetotal);
- $taxbase = $linetotal;
- }
-
- if (@taxaccounts && $form->round_amount($taxamount, 2)
- == 0) {
- if ($form->{taxincluded}) {
- foreach $item (@taxaccounts) {
- $taxamount =
- $form->round_amount(
- $item->value, 2);
- $taxaccounts{$item->account} +=
- $taxamount;
- $taxdiff += $taxamount;
- $taxbase{$item->account} +=
- $taxbase;
- }
- $taxaccounts{$taxaccounts[0]->account}
- += $taxdiff;
- } else {
- foreach $item (@taxaccounts) {
- $taxaccounts{$item->account} +=
- $item->value;
- $taxbase{$item->account} +=
- $taxbase;
- }
- }
- } else {
- foreach $item (@taxaccounts) {
- $taxaccounts{$item->account} +=
- $item->value;
- $taxbase{$item->account} += $taxbase;
- }
- }
-
- $netamount += $form->{"sellprice_$i"}
- * $form->{"qty_$i"};
-
- if ($form->{"projectnumber_$i"} ne "") {
- ($null, $project_id)
- = split /--/,
- $form->{"projectnumber_$i"};
- }
- $project_id = $form->{"project_id_$i"}
- if $form->{"project_id_$i"};
-
- if (!$form->{"reqdate_$i"}){
- $form->{"reqdate_$i"} = undef;
- }
-
- @queryargs = ();
- # save detail record in orderitems table
- $query = qq|INSERT INTO orderitems (|;
- if ($form->{"orderitems_id_$i"}){
- $query .= "id, ";
- }
- $query .= qq|
+ @queryargs = (
+ $form->{ordnumber}, $form->{quonumber},
+ $form->{transdate}, $form->{vendor_id},
+ $form->{customer_id}, $form->{reqdate},
+ $form->{shippingpoint}, $form->{shipvia},
+ $form->{notes}, $form->{intnotes},
+ $form->{currency}, $form->{closed},
+ $form->{department_id}, $form->{employee_id},
+ $form->{language_code}, $form->{ponumber},
+ $form->{terms}, $quotation
+ );
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $form->dberror($query);
+ $sth->finish;
+
+ @queries = $form->run_custom_queries( 'oe', 'INSERT' );
+
+ }
+
+ my $amount;
+ my $linetotal;
+ my $discount;
+ my $project_id;
+ my $taxrate;
+ my $taxamount;
+ my $fxsellprice;
+ my %taxbase;
+ my @taxaccounts;
+ my %taxaccounts;
+ my $netamount = 0;
+
+ my $rowcount = $form->{rowcount};
+ for my $i ( 1 .. $rowcount ) {
+ $form->db_prepare_vars(
+ "orderitems_id_$i", "id_$i",
+ "description_$i", "project_id_$i",
+ "ship_$i"
+ );
+
+ for (qw(qty ship)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( $myconfig, $form->{"${_}_$i"} );
+ }
+
+ $form->{"discount_$i"} =
+ $form->parse_amount( $myconfig, $form->{"discount_$i"} ) / 100;
+
+ $form->{"sellprice_$i"} =
+ $form->parse_amount( $myconfig, $form->{"sellprice_$i"} );
+
+ if ( $form->{"qty_$i"} ) {
+ $pth->execute( $form->{"id_$i"} );
+ $ref = $pth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
+ $pth->finish;
+
+ $fxsellprice = $form->{"sellprice_$i"};
+
+ my ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ $discount =
+ $form->round_amount(
+ $form->{"sellprice_$i"} * $form->{"discount_$i"},
+ $decimalplaces );
+ $form->{"sellprice_$i"} =
+ $form->round_amount( $form->{"sellprice_$i"} - $discount,
+ $decimalplaces );
+
+ $linetotal =
+ $form->round_amount( $form->{"sellprice_$i"} * $form->{"qty_$i"},
+ 2 );
+
+ @taxaccounts = Tax::init_taxes( $form, $form->{"taxaccounts_$i"} );
+ if ( $form->{taxincluded} ) {
+ $taxamount =
+ Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 1 );
+ $form->{"sellprice_$i"} =
+ Tax::extract_taxes( \@taxaccounts, $form,
+ $form->{"sellprice_$i"} );
+ $taxbase =
+ Tax::extract_taxes( \@taxaccounts, $form, $linetotal );
+ }
+ else {
+ $taxamount =
+ Tax::apply_taxes( \@taxaccounts, $form, $linetotal );
+ $taxbase = $linetotal;
+ }
+
+ if ( @taxaccounts && $form->round_amount( $taxamount, 2 ) == 0 ) {
+ if ( $form->{taxincluded} ) {
+ foreach $item (@taxaccounts) {
+ $taxamount = $form->round_amount( $item->value, 2 );
+ $taxaccounts{ $item->account } += $taxamount;
+ $taxdiff += $taxamount;
+ $taxbase{ $item->account } += $taxbase;
+ }
+ $taxaccounts{ $taxaccounts[0]->account } += $taxdiff;
+ }
+ else {
+ foreach $item (@taxaccounts) {
+ $taxaccounts{ $item->account } += $item->value;
+ $taxbase{ $item->account } += $taxbase;
+ }
+ }
+ }
+ else {
+ foreach $item (@taxaccounts) {
+ $taxaccounts{ $item->account } += $item->value;
+ $taxbase{ $item->account } += $taxbase;
+ }
+ }
+
+ $netamount += $form->{"sellprice_$i"} * $form->{"qty_$i"};
+
+ if ( $form->{"projectnumber_$i"} ne "" ) {
+ ( $null, $project_id ) = split /--/,
+ $form->{"projectnumber_$i"};
+ }
+ $project_id = $form->{"project_id_$i"}
+ if $form->{"project_id_$i"};
+
+ if ( !$form->{"reqdate_$i"} ) {
+ $form->{"reqdate_$i"} = undef;
+ }
+
+ @queryargs = ();
+
+ # save detail record in orderitems table
+ $query = qq|INSERT INTO orderitems (|;
+ if ( $form->{"orderitems_id_$i"} ) {
+ $query .= "id, ";
+ }
+ $query .= qq|
trans_id, parts_id, description, qty, sellprice,
discount, unit, reqdate, project_id, ship,
serialnumber, notes)
VALUES (|;
- if ($form->{"orderitems_id_$i"}){
- $query .= "?, ";
- push @queryargs, $form->{"orderitems_id_$i"};
- }
- $query .= qq| ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- push (@queryargs,
- $form->{id}, $form->{"id_$i"},
- $form->{"description_$i"}, $form->{"qty_$i"},
- $fxsellprice, $form->{"discount_$i"},
- $form->{"unit_$i"}, $form->{"reqdate_$i"},
- $project_id, $form->{"ship_$i"},
- $form->{"serialnumber_$i"},
- $form->{"notes_$i"});
- $sth->execute(@queryargs) || $form->dberror($query);
-
- $form->{"sellprice_$i"} = $fxsellprice;
- }
- $form->{"discount_$i"} *= 100;
- }
-
-
- # set values which could be empty
- for (qw(vendor_id customer_id taxincluded closed quotation))
- { $form->{$_} *= 1 }
-
- # add up the tax
- my $tax = 0;
- for (keys %taxaccounts) { $tax += $taxaccounts{$_} }
-
- $amount = $form->round_amount($netamount + $tax, 2);
- $netamount = $form->round_amount($netamount, 2);
-
- if ($form->{currency} eq $form->{defaultcurrency}) {
- $form->{exchangerate} = 1;
- } else {
- $exchangerate = $form->check_exchangerate(
- $myconfig, $form->{currency}, $form->{transdate},
- ($form->{vc} eq 'customer') ? 'buy' : 'sell');
- }
-
- $form->{exchangerate} = ($exchangerate) ? $exchangerate :
- $form->parse_amount($myconfig, $form->{exchangerate});
-
-
- ($null, $form->{department_id}) = split(/--/, $form->{department});
- for (qw(department_id terms)) { $form->{$_} *= 1 }
- if ($did_insert){
- $query = qq|
+ if ( $form->{"orderitems_id_$i"} ) {
+ $query .= "?, ";
+ push @queryargs, $form->{"orderitems_id_$i"};
+ }
+ $query .= qq| ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
+ $sth = $dbh->prepare($query);
+ push( @queryargs,
+ $form->{id}, $form->{"id_$i"},
+ $form->{"description_$i"}, $form->{"qty_$i"},
+ $fxsellprice, $form->{"discount_$i"},
+ $form->{"unit_$i"}, $form->{"reqdate_$i"},
+ $project_id, $form->{"ship_$i"},
+ $form->{"serialnumber_$i"}, $form->{"notes_$i"} );
+ $sth->execute(@queryargs) || $form->dberror($query);
+
+ $form->{"sellprice_$i"} = $fxsellprice;
+ }
+ $form->{"discount_$i"} *= 100;
+ }
+
+ # set values which could be empty
+ for (qw(vendor_id customer_id taxincluded closed quotation)) {
+ $form->{$_} *= 1;
+ }
+
+ # add up the tax
+ my $tax = 0;
+ for ( keys %taxaccounts ) { $tax += $taxaccounts{$_} }
+
+ $amount = $form->round_amount( $netamount + $tax, 2 );
+ $netamount = $form->round_amount( $netamount, 2 );
+
+ if ( $form->{currency} eq $form->{defaultcurrency} ) {
+ $form->{exchangerate} = 1;
+ }
+ else {
+ $exchangerate =
+ $form->check_exchangerate( $myconfig, $form->{currency},
+ $form->{transdate},
+ ( $form->{vc} eq 'customer' ) ? 'buy' : 'sell' );
+ }
+
+ $form->{exchangerate} =
+ ($exchangerate)
+ ? $exchangerate
+ : $form->parse_amount( $myconfig, $form->{exchangerate} );
+
+ ( $null, $form->{department_id} ) = split( /--/, $form->{department} );
+ for (qw(department_id terms)) { $form->{$_} *= 1 }
+ if ($did_insert) {
+ $query = qq|
UPDATE oe SET
amount = ?,
netamount = ?,
taxincluded = ?
WHERE id = ?|;
- @queryargs = ($amount, $netamount, $form->{taxincluded},
- $form->{id});
- } else {
- # save OE record
- $query = qq|
+ @queryargs = ( $amount, $netamount, $form->{taxincluded}, $form->{id} );
+ }
+ else {
+
+ # save OE record
+ $query = qq|
UPDATE oe set
ordnumber = ?,
quonumber = ?,
@@ -576,215 +579,190 @@ sub save {
terms = ?
WHERE id = ?|;
- if (!$form->{reqdate}){
- $form->{reqdate} = undef;
- }
-
- @queryargs = ($form->{ordnumber},
- $form->{quonumber},
- $form->{transdate},
- $form->{vendor_id},
- $form->{customer_id},
- $amount,
- $netamount,
- $form->{reqdate},
- $form->{taxincluded},
- $form->{shippingpoint},
- $form->{shipvia},
- $form->{notes},
- $form->{intnotes},
- $form->{currency},
- $form->{closed},
- $quotation,
- $form->{department_id},
- $form->{employee_id},
- $form->{language_code},
- $form->{ponumber},
- $form->{terms},
- $form->{id});
- }
- $sth = $dbh->prepare($query);
- $sth->execute(@queryargs) || $form->dberror($query);
-
- if (!$did_insert){
- @queries = $form->run_custom_queries('oe', 'UPDATE');
- }
-
-
- $form->{ordtotal} = $amount;
-
- # add shipto
- $form->{name} = $form->{$form->{vc}};
- $form->{name} =~ s/--$form->{"$form->{vc}_id"}//;
- $form->add_shipto($dbh, $form->{id});
-
- # save printed, emailed, queued
- $form->save_status($dbh);
-
- if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) {
- if ($form->{vc} eq 'customer') {
- $form->update_exchangerate(
- $dbh,
- $form->{currency},
- $form->{transdate},
- $form->{exchangerate},
- 0);
- }
- if ($form->{vc} eq 'vendor') {
- $form->update_exchangerate(
- $dbh,
- $form->{currency},
- $form->{transdate},
- 0,
- $form->{exchangerate});
- }
- }
-
-
- if ($form->{type} =~ /_order$/) {
- # adjust onhand
- &adj_onhand($dbh, $form, $ml * -1);
- &adj_inventory($dbh, $myconfig, $form);
- }
-
- my %audittrail = (
- tablename => 'oe',
- reference => ($form->{type} =~ /_order$/)
- ? $form->{ordnumber} : $form->{quonumber},
- formname => $form->{type},
- action => 'saved',
- id => $form->{id} );
-
- $form->audittrail($dbh, "", \%audittrail);
-
- $form->save_recurring($dbh, $myconfig);
-
- my $rc = $dbh->commit;
-
- $rc;
+ if ( !$form->{reqdate} ) {
+ $form->{reqdate} = undef;
+ }
+
+ @queryargs = (
+ $form->{ordnumber}, $form->{quonumber},
+ $form->{transdate}, $form->{vendor_id},
+ $form->{customer_id}, $amount,
+ $netamount, $form->{reqdate},
+ $form->{taxincluded}, $form->{shippingpoint},
+ $form->{shipvia}, $form->{notes},
+ $form->{intnotes}, $form->{currency},
+ $form->{closed}, $quotation,
+ $form->{department_id}, $form->{employee_id},
+ $form->{language_code}, $form->{ponumber},
+ $form->{terms}, $form->{id}
+ );
+ }
+ $sth = $dbh->prepare($query);
+ $sth->execute(@queryargs) || $form->dberror($query);
+
+ if ( !$did_insert ) {
+ @queries = $form->run_custom_queries( 'oe', 'UPDATE' );
+ }
+
+ $form->{ordtotal} = $amount;
+
+ # add shipto
+ $form->{name} = $form->{ $form->{vc} };
+ $form->{name} =~ s/--$form->{"$form->{vc}_id"}//;
+ $form->add_shipto( $dbh, $form->{id} );
+
+ # save printed, emailed, queued
+ $form->save_status($dbh);
+
+ if ( ( $form->{currency} ne $form->{defaultcurrency} ) && !$exchangerate ) {
+ if ( $form->{vc} eq 'customer' ) {
+ $form->update_exchangerate( $dbh, $form->{currency},
+ $form->{transdate}, $form->{exchangerate}, 0 );
+ }
+ if ( $form->{vc} eq 'vendor' ) {
+ $form->update_exchangerate( $dbh, $form->{currency},
+ $form->{transdate}, 0, $form->{exchangerate} );
+ }
+ }
+
+ if ( $form->{type} =~ /_order$/ ) {
+
+ # adjust onhand
+ &adj_onhand( $dbh, $form, $ml * -1 );
+ &adj_inventory( $dbh, $myconfig, $form );
+ }
+
+ my %audittrail = (
+ tablename => 'oe',
+ reference => ( $form->{type} =~ /_order$/ )
+ ? $form->{ordnumber}
+ : $form->{quonumber},
+ formname => $form->{type},
+ action => 'saved',
+ id => $form->{id}
+ );
+
+ $form->audittrail( $dbh, "", \%audittrail );
+
+ $form->save_recurring( $dbh, $myconfig );
+
+ my $rc = $dbh->commit;
+
+ $rc;
}
-
-
sub delete {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- # delete spool files
- my $query = qq|
+ # delete spool files
+ my $query = qq|
SELECT spoolfile FROM status
WHERE trans_id = ?
AND spoolfile IS NOT NULL|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- my $spoolfile;
- my @spoolfiles = ();
+ my $spoolfile;
+ my @spoolfiles = ();
- while (($spoolfile) = $sth->fetchrow_array) {
- push @spoolfiles, $spoolfile;
- }
- $sth->finish;
+ while ( ($spoolfile) = $sth->fetchrow_array ) {
+ push @spoolfiles, $spoolfile;
+ }
+ $sth->finish;
-
- $query = qq|
+ $query = qq|
SELECT o.parts_id, o.ship, p.inventory_accno_id, p.assembly
FROM orderitems o
JOIN parts p ON (p.id = o.parts_id)
WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- if ($form->{type} =~ /_order$/) {
- $ml = ($form->{type} eq 'purchase_order') ? -1 : 1;
- while (my ($id, $ship, $inv, $assembly)
- = $sth->fetchrow_array) {
- $form->update_balance(
- $dbh,
- "parts",
- "onhand",
- "id = $id",
- $ship * $ml)
- if ($inv || $assembly);
- }
- }
- $sth->finish;
-
- # delete inventory
- $query = qq|DELETE FROM inventory WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- $sth->finish;
-
- # delete status entries
- $query = qq|DELETE FROM status WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- $sth->finish;
-
- # delete OE record
- $query = qq|DELETE FROM oe WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- $sth->finish;
-
- # delete individual entries
- $query = qq|DELETE FROM orderitems WHERE trans_id = ?|;
- $sth->finish;
-
- $query = qq|DELETE FROM shipto WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
- $sth->finish;
-
- my %audittrail = (
- tablename => 'oe',
- reference => ($form->{type} =~ /_order$/)
- ? $form->{ordnumber} : $form->{quonumber},
- formname => $form->{type},
- action => 'deleted',
- id => $form->{id} );
-
- $form->audittrail($dbh, "", \%audittrail);
-
- my $rc = $dbh->commit;
-
- if ($rc) {
- foreach $spoolfile (@spoolfiles) {
- unlink "${LedgerSMB::Sysconfig::spool}/$spoolfile" if $spoolfile;
- }
- }
-
- $rc;
-
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ if ( $form->{type} =~ /_order$/ ) {
+ $ml = ( $form->{type} eq 'purchase_order' ) ? -1 : 1;
+ while ( my ( $id, $ship, $inv, $assembly ) = $sth->fetchrow_array ) {
+ $form->update_balance( $dbh, "parts", "onhand", "id = $id",
+ $ship * $ml )
+ if ( $inv || $assembly );
+ }
+ }
+ $sth->finish;
+
+ # delete inventory
+ $query = qq|DELETE FROM inventory WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ $sth->finish;
+
+ # delete status entries
+ $query = qq|DELETE FROM status WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ $sth->finish;
+
+ # delete OE record
+ $query = qq|DELETE FROM oe WHERE id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ $sth->finish;
+
+ # delete individual entries
+ $query = qq|DELETE FROM orderitems WHERE trans_id = ?|;
+ $sth->finish;
+
+ $query = qq|DELETE FROM shipto WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ $sth->finish;
+
+ my %audittrail = (
+ tablename => 'oe',
+ reference => ( $form->{type} =~ /_order$/ )
+ ? $form->{ordnumber}
+ : $form->{quonumber},
+ formname => $form->{type},
+ action => 'deleted',
+ id => $form->{id}
+ );
+
+ $form->audittrail( $dbh, "", \%audittrail );
+
+ my $rc = $dbh->commit;
+
+ if ($rc) {
+ foreach $spoolfile (@spoolfiles) {
+ unlink "${LedgerSMB::Sysconfig::spool}/$spoolfile" if $spoolfile;
+ }
+ }
+
+ $rc;
+
}
+sub retrieve {
+ use LedgerSMB::PriceMatrix;
+ my ( $self, $myconfig, $form ) = @_;
+ # connect to database
+ my $dbh = $form->{dbh};
-sub retrieve {
- use LedgerSMB::PriceMatrix;
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my $query;
- my $sth;
- my $var;
- my $ref;
-
- $query = qq|
+ my $query;
+ my $sth;
+ my $var;
+ my $ref;
+
+ $query = qq|
SELECT value, current_date FROM defaults
WHERE setting_key = 'curr'|;
- ($form->{currencies}, $form->{transdate}) =
- $dbh->selectrow_array($query);
-
- if ($form->{id}) {
-
- # retrieve order
- $query = qq|
+ ( $form->{currencies}, $form->{transdate} ) = $dbh->selectrow_array($query);
+
+ if ( $form->{id} ) {
+
+ # retrieve order
+ $query = qq|
SELECT o.ordnumber, o.transdate, o.reqdate, o.terms,
o.taxincluded, o.shippingpoint, o.shipvia,
o.notes, o.intnotes, o.curr AS currency,
@@ -799,43 +777,42 @@ sub retrieve {
LEFT JOIN employees e ON (o.employee_id = e.id)
LEFT JOIN department d ON (o.department_id = d.id)
WHERE o.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
-
- $query = qq|SELECT * FROM shipto WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
- $sth->finish;
-
- # get printed, emailed and queued
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
+
+ $query = qq|SELECT * FROM shipto WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
+
+ # get printed, emailed and queued
+ $query = qq|
SELECT s.printed, s.emailed, s.spoolfile, s.formname
FROM status s
WHERE s.trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $form->{printed} .= "$ref->{formname} "
- if $ref->{printed};
- $form->{emailed} .= "$ref->{formname} "
- if $ref->{emailed};
- $form->{queued} .= "$ref->{formname} $ref->{spoolfile} "
- if $ref->{spoolfile};
- }
- $sth->finish;
- for (qw(printed emailed queued)) { $form->{$_} =~ s/ +$//g }
-
-
- # retrieve individual items
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $form->{printed} .= "$ref->{formname} "
+ if $ref->{printed};
+ $form->{emailed} .= "$ref->{formname} "
+ if $ref->{emailed};
+ $form->{queued} .= "$ref->{formname} $ref->{spoolfile} "
+ if $ref->{spoolfile};
+ }
+ $sth->finish;
+ for (qw(printed emailed queued)) { $form->{$_} =~ s/ +$//g }
+
+ # retrieve individual items
+ $query = qq|
SELECT o.id AS orderitems_id, p.partnumber, p.assembly,
o.description, o.qty, o.sellprice,
o.parts_id AS id, o.unit, o.discount, p.bin,
@@ -855,764 +832,773 @@ sub retrieve {
AND t.language_code = ?)
WHERE o.trans_id = ?
ORDER BY o.id|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{language_code}, $form->{id})
- || $form->dberror($query);
-
- # foreign exchange rates
- &exchangerate_defaults($dbh, $form);
-
- # query for price matrix
- my $pmh = PriceMatrix::price_matrix_query($dbh, $form);
-
- # taxes
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{language_code}, $form->{id} )
+ || $form->dberror($query);
+
+ # foreign exchange rates
+ &exchangerate_defaults( $dbh, $form );
+
+ # query for price matrix
+ my $pmh = PriceMatrix::price_matrix_query( $dbh, $form );
+
+ # taxes
+ $query = qq|
SELECT c.accno FROM chart c
JOIN partstax pt ON (pt.chart_id = c.id)
WHERE pt.parts_id = ?|;
- my $tth = $dbh->prepare($query) || $form->dberror($query);
-
- my $taxrate;
- my $ptref;
- my $sellprice;
- my $listprice;
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- ($decimalplaces) = ($ref->{sellprice} =~ /\.(\d+)/);
- $decimalplaces = length $decimalplaces;
- $decimalplaces = ($decimalplaces > 2) ?
- $decimalplaces : 2;
-
- $tth->execute($ref->{id});
- $ref->{taxaccounts} = "";
- $taxrate = 0;
-
- while ($ptref = $tth->fetchrow_hashref(NAME_lc)) {
- $ref->{taxaccounts} .= "$ptref->{accno} ";
- $taxrate += $form->{"$ptref->{accno}_rate"};
- }
- $tth->finish;
- chop $ref->{taxaccounts};
-
- # preserve price
- $sellprice = $ref->{sellprice};
-
- # multiply by exchangerate
- $ref->{sellprice} = $form->round_amount(
- $ref->{sellprice} * $form->{$form->{currency}},
- $decimalplaces
- );
-
- for (qw(listprice lastcost)) {
- $ref->{$_} = $form->round_amount(
- $ref->{$_} / $form->{$form->{currency}},
- $decimalplaces
- );
- }
-
- # partnumber and price matrix
- PriceMatrix::price_matrix(
- $pmh, $ref, $form->{transdate}, $decimalplaces,
- $form, $myconfig);
-
- $ref->{sellprice} = $sellprice;
-
- $ref->{partsgroup} = $ref->{partsgrouptranslation}
- if $ref->{partsgrouptranslation};
-
- push @{ $form->{form_details} }, $ref;
-
- }
- $sth->finish;
-
- # get recurring transaction
- $form->get_recurring;
-
- @queries = $form->run_custom_queries('oe', 'SELECT');
- $form->{dbh}->commit;
- } else {
-
- # get last name used
- $form->lastname_used($myconfig, $dbh, $form->{vc})
- unless $form->{"$form->{vc}_id"};
-
- delete $form->{notes};
-
- }
-
- $dbh->commit;
+ my $tth = $dbh->prepare($query) || $form->dberror($query);
-}
+ my $taxrate;
+ my $ptref;
+ my $sellprice;
+ my $listprice;
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ ($decimalplaces) = ( $ref->{sellprice} =~ /\.(\d+)/ );
+ $decimalplaces = length $decimalplaces;
+ $decimalplaces = ( $decimalplaces > 2 ) ? $decimalplaces : 2;
+
+ $tth->execute( $ref->{id} );
+ $ref->{taxaccounts} = "";
+ $taxrate = 0;
+
+ while ( $ptref = $tth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{taxaccounts} .= "$ptref->{accno} ";
+ $taxrate += $form->{"$ptref->{accno}_rate"};
+ }
+ $tth->finish;
+ chop $ref->{taxaccounts};
+
+ # preserve price
+ $sellprice = $ref->{sellprice};
+
+ # multiply by exchangerate
+ $ref->{sellprice} =
+ $form->round_amount(
+ $ref->{sellprice} * $form->{ $form->{currency} },
+ $decimalplaces );
+
+ for (qw(listprice lastcost)) {
+ $ref->{$_} =
+ $form->round_amount(
+ $ref->{$_} / $form->{ $form->{currency} },
+ $decimalplaces );
+ }
+
+ # partnumber and price matrix
+ PriceMatrix::price_matrix( $pmh, $ref, $form->{transdate},
+ $decimalplaces, $form, $myconfig );
+ $ref->{sellprice} = $sellprice;
+
+ $ref->{partsgroup} = $ref->{partsgrouptranslation}
+ if $ref->{partsgrouptranslation};
+
+ push @{ $form->{form_details} }, $ref;
+
+ }
+ $sth->finish;
+
+ # get recurring transaction
+ $form->get_recurring;
+
+ @queries = $form->run_custom_queries( 'oe', 'SELECT' );
+ $form->{dbh}->commit;
+ }
+ else {
+
+ # get last name used
+ $form->lastname_used( $myconfig, $dbh, $form->{vc} )
+ unless $form->{"$form->{vc}_id"};
+
+ delete $form->{notes};
+
+ }
+
+ $dbh->commit;
+
+}
sub exchangerate_defaults {
- my ($dbh2, $form) = @_;
- $dbh = $form->{dbh};
- my $var;
- my $buysell = ($form->{vc} eq "customer") ? "buy" : "sell";
-
- # get default currencies
- my $query = qq|
+ my ( $dbh2, $form ) = @_;
+ $dbh = $form->{dbh};
+ my $var;
+ my $buysell = ( $form->{vc} eq "customer" ) ? "buy" : "sell";
+
+ # get default currencies
+ my $query = qq|
SELECT substr(value,1,3), value FROM defaults
WHERE setting_key = 'curr'|;
- ($form->{defaultcurrency}, $form->{currencies})
- = $dbh->selectrow_array($query);
+ ( $form->{defaultcurrency}, $form->{currencies} ) =
+ $dbh->selectrow_array($query);
- $query = qq|
+ $query = qq|
SELECT $buysell
FROM exchangerate
WHERE curr = ?
AND transdate = ?|;
- my $eth1 = $dbh->prepare($query) || $form->dberror($query);
- $query = qq~
+ my $eth1 = $dbh->prepare($query) || $form->dberror($query);
+ $query = qq~
SELECT max(transdate || ' ' || $buysell || ' ' || curr)
FROM exchangerate
WHERE curr = ?~;
- my $eth2 = $dbh->prepare($query) || $form->dberror($query);
-
- # get exchange rates for transdate or max
- foreach $var (split /:/, substr($form->{currencies},4)) {
- $eth1->execute($var, $form->{transdate});
- ($form->{$var}) = $eth1->fetchrow_array;
- if (! $form->{$var} ) {
- $eth2->execute($var);
-
- ($form->{$var}) = $eth2->fetchrow_array;
- ($null, $form->{$var}) = split / /, $form->{$var};
- $form->{$var} = 1 unless $form->{$var};
- $eth2->finish;
- }
- $eth1->finish;
- }
-
- $form->{$form->{currency}} = $form->{exchangerate}
- if $form->{exchangerate};
- $form->{$form->{currency}} ||= 1;
- $form->{$form->{defaultcurrency}} = 1;
-
-}
+ my $eth2 = $dbh->prepare($query) || $form->dberror($query);
+
+ # get exchange rates for transdate or max
+ foreach $var ( split /:/, substr( $form->{currencies}, 4 ) ) {
+ $eth1->execute( $var, $form->{transdate} );
+ ( $form->{$var} ) = $eth1->fetchrow_array;
+ if ( !$form->{$var} ) {
+ $eth2->execute($var);
+
+ ( $form->{$var} ) = $eth2->fetchrow_array;
+ ( $null, $form->{$var} ) = split / /, $form->{$var};
+ $form->{$var} = 1 unless $form->{$var};
+ $eth2->finish;
+ }
+ $eth1->finish;
+ }
+
+ $form->{ $form->{currency} } = $form->{exchangerate}
+ if $form->{exchangerate};
+ $form->{ $form->{currency} } ||= 1;
+ $form->{ $form->{defaultcurrency} } = 1;
+}
sub order_details {
- use LedgerSMB::CP;
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
- my $query;
- my $sth;
-
- my $item;
- my $i;
- my @sortlist = ();
- my $projectnumber;
- my $projectdescription;
- my $projectnumber_id;
- my $translation;
- my $partsgroup;
-
- my @queryargs;
-
- my @taxaccounts;
- my %taxaccounts; # I don't think this works.
- my $tax;
- my $taxrate;
- my $taxamount;
-
- my %translations;
-
- my $language_code = $form->{dbh}->quote($form->{language_code});
- $query = qq|
+ use LedgerSMB::CP;
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+ my $query;
+ my $sth;
+
+ my $item;
+ my $i;
+ my @sortlist = ();
+ my $projectnumber;
+ my $projectdescription;
+ my $projectnumber_id;
+ my $translation;
+ my $partsgroup;
+
+ my @queryargs;
+
+ my @taxaccounts;
+ my %taxaccounts; # I don't think this works.
+ my $tax;
+ my $taxrate;
+ my $taxamount;
+
+ my %translations;
+
+ my $language_code = $form->{dbh}->quote( $form->{language_code} );
+ $query = qq|
SELECT p.description, t.description
FROM project p
LEFT JOIN translation t ON (t.trans_id = p.id AND
t.language_code = $language_code)
WHERE id = ?|;
- my $prh = $dbh->prepare($query) || $form->dberror($query);
+ my $prh = $dbh->prepare($query) || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT inventory_accno_id, income_accno_id,
expense_accno_id, assembly FROM parts
WHERE id = ?|;
- my $pth = $dbh->prepare($query) || $form->dberror($query);
-
- my $sortby;
-
- # sort items by project and partsgroup
- for $i (1 .. $form->{rowcount}) {
-
- if ($form->{"id_$i"}) {
- # account numbers
- $pth->execute($form->{"id_$i"});
- $ref = $pth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
- $pth->finish;
-
- $projectnumber_id = 0;
- $projectnumber = "";
- $form->{partsgroup} = "";
- $form->{projectnumber} = "";
-
- if ($form->{groupprojectnumber}
- || $form->{grouppartsgroup}) {
-
- $inventory_accno_id =
- ($form->{"inventory_accno_id_$i"} ||
- $form->{"assembly_$i"}) ? "1" : "";
-
- if ($form->{groupprojectnumber}) {
- ($projectnumber, $projectnumber_id) =
- split /--/,
- $form->{"projectnumber_$i"};
- }
- if ($form->{grouppartsgroup}) {
- ($form->{partsgroup}) = split /--/,
- $form->{"partsgroup_$i"};
- }
-
- if ($projectnumber_id &&
- $form->{groupprojectnumber}) {
- if ($translation{$projectnumber_id}) {
- $form->{projectnumber} =
- $translation{$projectnumber_id};
- } else {
- # get project description
- $prh->execute(
- $projectnumber_id);
- ($projectdescription,
- $translation) =
- $prh->fetchrow_array;
- $prh->finish;
-
- $form->{projectnumber} =
- ($translation) ?
- "$projectnumber, \n" .
- "$translation"
- : "$projectnumber, \n" .
- "$projectdescription";
-
- $translation{$projectnumber_id}
- = $form->{projectnumber};
- }
- }
-
- if ($form->{grouppartsgroup}
- && $form->{partsgroup}) {
- $form->{projectnumber} .= " / "
- if $projectnumber_id;
- $form->{projectnumber} .=
- $form->{partsgroup};
- }
-
- $form->format_string(projectnumber);
-
- }
-
- $sortby = qq|$projectnumber$form->{partsgroup}|;
-
- if ($form->{sortby} ne 'runningnumber') {
- for (qw(partnumber description bin)) {
- $sortby .= $form->{"${_}_$i"}
- if $form->{sortby} eq $_;
- }
- }
-
- push @sortlist, [ $i,
- "$projectnumber$form->{partsgroup}".
- "$inventory_accno_id",
- $form->{projectnumber}, $projectnumber_id,
- $form->{partsgroup}, $sortby ];
- }
-
- }
-
- delete $form->{projectnumber};
-
- # sort the whole thing by project and group
- @sortlist = sort { $a->[5] cmp $b->[5] } @sortlist;
-
-
- # if there is a warehouse limit picking
- if ($form->{warehouse_id} && $form->{formname} =~
- /(pick|packing)_list/) {
- # run query to check for inventory
- $query = qq|
+ my $pth = $dbh->prepare($query) || $form->dberror($query);
+
+ my $sortby;
+
+ # sort items by project and partsgroup
+ for $i ( 1 .. $form->{rowcount} ) {
+
+ if ( $form->{"id_$i"} ) {
+
+ # account numbers
+ $pth->execute( $form->{"id_$i"} );
+ $ref = $pth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
+ $pth->finish;
+
+ $projectnumber_id = 0;
+ $projectnumber = "";
+ $form->{partsgroup} = "";
+ $form->{projectnumber} = "";
+
+ if ( $form->{groupprojectnumber}
+ || $form->{grouppartsgroup} )
+ {
+
+ $inventory_accno_id =
+ ( $form->{"inventory_accno_id_$i"} || $form->{"assembly_$i"} )
+ ? "1"
+ : "";
+
+ if ( $form->{groupprojectnumber} ) {
+ ( $projectnumber, $projectnumber_id ) =
+ split /--/, $form->{"projectnumber_$i"};
+ }
+ if ( $form->{grouppartsgroup} ) {
+ ( $form->{partsgroup} ) = split /--/,
+ $form->{"partsgroup_$i"};
+ }
+
+ if ( $projectnumber_id
+ && $form->{groupprojectnumber} )
+ {
+ if ( $translation{$projectnumber_id} ) {
+ $form->{projectnumber} =
+ $translation{$projectnumber_id};
+ }
+ else {
+
+ # get project description
+ $prh->execute($projectnumber_id);
+ ( $projectdescription, $translation ) =
+ $prh->fetchrow_array;
+ $prh->finish;
+
+ $form->{projectnumber} =
+ ($translation)
+ ? "$projectnumber, \n" . "$translation"
+ : "$projectnumber, \n" . "$projectdescription";
+
+ $translation{$projectnumber_id} =
+ $form->{projectnumber};
+ }
+ }
+
+ if ( $form->{grouppartsgroup}
+ && $form->{partsgroup} )
+ {
+ $form->{projectnumber} .= " / "
+ if $projectnumber_id;
+ $form->{projectnumber} .= $form->{partsgroup};
+ }
+
+ $form->format_string(projectnumber);
+
+ }
+
+ $sortby = qq|$projectnumber$form->{partsgroup}|;
+
+ if ( $form->{sortby} ne 'runningnumber' ) {
+ for (qw(partnumber description bin)) {
+ $sortby .= $form->{"${_}_$i"}
+ if $form->{sortby} eq $_;
+ }
+ }
+
+ push @sortlist,
+ [
+ $i,
+ "$projectnumber$form->{partsgroup}" . "$inventory_accno_id",
+ $form->{projectnumber},
+ $projectnumber_id,
+ $form->{partsgroup},
+ $sortby
+ ];
+ }
+
+ }
+
+ delete $form->{projectnumber};
+
+ # sort the whole thing by project and group
+ @sortlist = sort { $a->[5] cmp $b->[5] } @sortlist;
+
+ # if there is a warehouse limit picking
+ if ( $form->{warehouse_id} && $form->{formname} =~ /(pick|packing)_list/ ) {
+
+ # run query to check for inventory
+ $query = qq|
SELECT sum(qty) AS qty FROM inventory
WHERE parts_id = ? AND warehouse_id = ?|;
- $sth = $dbh->prepare($query) || $form->dberror($query);
-
- for $i (1 .. $form->{rowcount}) {
- $sth->execute($form->{"id_$i"}, $form->{warehouse_id})
- || $form->dberror;
-
- ($qty) = $sth->fetchrow_array;
- $sth->finish;
-
- $form->{"qty_$i"} = 0 if $qty == 0;
-
- if ($form->parse_amount($myconfig, $form->{"ship_$i"})
- > $qty) {
- $form->{"ship_$i"} =
- $form->format_amount($myconfig, $qty);
- }
- }
- }
-
-
- my $runningnumber = 1;
- my $sameitem = "";
- my $subtotal;
- my $k = scalar @sortlist;
- my $j = 0;
-
- foreach $item (@sortlist) {
- $i = $item->[0];
- $j++;
-
- if ($form->{groupprojectnumber} || $form->{grouppartsgroup}) {
- if ($item->[1] ne $sameitem) {
- $sameitem = $item->[1];
-
- $ok = 0;
-
- if ($form->{groupprojectnumber}) {
- $ok = $form->{"projectnumber_$i"};
- }
- if ($form->{grouppartsgroup}) {
- $ok = $form->{"partsgroup_$i"}
- unless $ok;
- }
-
- if ($ok) {
- if ($form->{"inventory_accno_id_$i"}
- || $form->{"assembly_$i"}) {
-
- push(@{ $form->{part} }, "");
- push(@{ $form->{service} },
- NULL);
- } else {
- push(@{ $form->{part} }, NULL);
- push(@{ $form->{service} }, "");
- }
-
- push(@{ $form->{description} },
- $item->[2]);
- for (
- qw(taxrates runningnumber
- number sku qty ship unit bin
- serialnumber requiredate
- projectnumber sellprice
- listprice netprice discount
- discountrate linetotal weight
- itemnotes)
- ) {
- push(@{ $form->{$_} }, "");
- }
- push(@{ $form->{lineitems} },
- { amount => 0, tax => 0 });
- }
- }
- }
-
-
- $form->{"qty_$i"} = $form->parse_amount(
- $myconfig, $form->{"qty_$i"});
- $form->{"ship_$i"} = $form->parse_amount(
- $myconfig, $form->{"ship_$i"});
-
- if ($form->{"qty_$i"}) {
-
- $form->{totalqty} += $form->{"qty_$i"};
- $form->{totalship} += $form->{"ship_$i"};
- $form->{totalweight} += ($form->{"weight_$i"}
- * $form->{"qty_$i"});
- $form->{totalweightship} += ($form->{"weight_$i"}
- * $form->{"ship_$i"});
-
- # add number, description and qty to $form->{number}
- push(@{ $form->{runningnumber} }, $runningnumber++);
- push(@{ $form->{number} },
- qq|$form->{"partnumber_$i"}|);
- push(@{ $form->{sku} }, qq|$form->{"sku_$i"}|);
- push(@{ $form->{description} },
- qq|$form->{"description_$i"}|);
- push(@{ $form->{itemnotes} }, $form->{"notes_$i"});
- push(@{ $form->{qty} }, $form->format_amount(
- $myconfig, $form->{"qty_$i"}));
- push(@{ $form->{ship} }, $form->format_amount(
- $myconfig, $form->{"ship_$i"}));
- push(@{ $form->{unit} }, qq|$form->{"unit_$i"}|);
- push(@{ $form->{bin} }, qq|$form->{"bin_$i"}|);
- push(@{ $form->{serialnumber} },
- qq|$form->{"serialnumber_$i"}|);
- push(@{ $form->{requiredate} },
- qq|$form->{"reqdate_$i"}|);
- push(@{ $form->{projectnumber} },
- qq|$form->{"projectnumber_$i"}|);
-
- push(@{ $form->{sellprice} }, $form->{"sellprice_$i"});
-
- push(@{ $form->{listprice} }, $form->{"listprice_$i"});
-
- push(@{ $form->{weight} }, $form->format_amount(
- $myconfig,
- $form->{"weight_$i"} * $form->{"ship_$i"}));
-
- my $sellprice = $form->parse_amount(
- $myconfig, $form->{"sellprice_$i"});
- my ($dec) = ($sellprice =~ /\.(\d+)/);
- $dec = length $dec;
- my $decimalplaces = ($dec > 2) ? $dec : 2;
-
- my $discount = $form->round_amount(
- $sellprice * $form->parse_amount(
- $myconfig,
- $form->{"discount_$i"}) / 100,
- $decimalplaces);
-
- # keep a netprice as well, (sellprice - discount)
- $form->{"netprice_$i"} = $sellprice - $discount;
-
- my $linetotal = $form->round_amount(
- $form->{"qty_$i"} * $form->{"netprice_$i"}, 2);
-
- if ($form->{"inventory_accno_id_$i"}
- || $form->{"assembly_$i"}) {
-
- push(@{ $form->{part} }, $form->{"sku_$i"});
- push(@{ $form->{service} }, NULL);
- $form->{totalparts} += $linetotal;
- } else {
- push(@{ $form->{service} }, $form->{"sku_$i"});
- push(@{ $form->{part} }, NULL);
- $form->{totalservices} += $linetotal;
- }
-
- push(@{ $form->{netprice} },
- ($form->{"netprice_$i"})
- ? $form->format_amount(
- $myconfig,
- $form->{"netprice_$i"},
- $decimalplaces)
- : " ");
-
- $discount = ($discount)
- ? $form->format_amount(
- $myconfig,
- $discount * -1,
- $decimalplaces)
- : " ";
-
- push(@{ $form->{discount} }, $discount);
- push(@{ $form->{discountrate} },
- $form->format_amount($myconfig,
- $form->{"discount_$i"}));
-
- $form->{ordtotal} += $linetotal;
-
- # this is for the subtotals for grouping
- $subtotal += $linetotal;
-
- $form->{"linetotal_$i"} = $form->format_amount(
- $myconfig, $linetotal, 2);
- push(@{ $form->{linetotal} }, $form->{"linetotal_$i"});
-
- @taxaccounts = Tax::init_taxes($form,
- $form->{"taxaccounts_$i"});
-
- my $ml = 1;
- my @taxrates = ();
-
- $tax = 0;
-
- $taxamount = Tax::calculate_taxes(\@taxaccounts,
- $form, $linetotal, 1);
- $taxbase = Tax::extract_taxes(\@taxaccounts,
- $form, $linetotal);
- foreach $item (@taxaccounts) {
- push @taxrates, Math::BigFloat->new(100) *
- $item->rate;
- if ($form->{taxincluded}) {
- $taxaccounts{$item->account} +=
- $item->value;
- $taxbase{$item->account} += $taxbase;
- } else {
- Tax::apply_taxes(\@taxaccounts, $form,
- $linetotal);
- $taxbase{$item->account} += $linetotal;
- $taxaccounts{$item->account} +=
- $item->value;
- }
- }
- if ($form->{taxincluded}) {
- $tax += Tax::calculate_taxes(\@taxaccounts,
- $form, $linetotal, 1);
- } else {
- $tax += Tax::calculate_taxes(\@taxaccounts,
- $form, $linetotal, 0);
- }
-
- push(@{ $form->{lineitems} },
- { amount => $linetotal,
- tax => $form->round_amount($tax, 2) });
- push(@{ $form->{taxrates} },
- join ' ', sort { $a <=> $b } @taxrates);
-
- if ($form->{"assembly_$i"}) {
- $form->{stagger} = -1;
- &assembly_details($myconfig,
- $form, $dbh, $form->{"id_$i"},
- $oid{$myconfig->{dbdriver}},
- $form->{"qty_$i"});
- }
-
- }
-
- # add subtotal
- if ($form->{groupprojectnumber} || $form->{grouppartsgroup}) {
- if ($subtotal) {
- if ($j < $k) {
- # look at next item
- if ($sortlist[$j]->[1] ne $sameitem) {
-
- if ($form->{"inventory_accno_id_$i"}
- || $form->{"assembly_$i"}) {
-
- push(@{ $form->{part} },
- "");
- push(@{
- $form->{service}
- }, NULL);
- } else {
- push(@{
- $form->{service}
- }, "");
- push(@{ $form->{part} },
- NULL);
- }
-
- for (qw(
- taxrates runningnumber
- number sku qty ship unit
- bin serialnumber
- requiredate
- projectnumber sellprice
- listprice netprice
- discount discountrate
- weight itemnotes)
- ) {
-
- push(@{ $form->{$_} },
- "");
- }
-
- push(@{ $form->{description} },
- $form->{groupsubtotaldescription});
-
- push(@{ $form->{lineitems} },
- { amount => 0,
- tax => 0 });
-
- if ($form->{groupsubtotaldescription}
- ne "") {
- push(@{
- $form->{linetotal}
- },
- $form->format_amount($myconfig, $subtotal, 2));
- } else {
- push(@{
- $form->{linetotal}
- }, "");
- }
- $subtotal = 0;
- }
-
- } else {
-
- # got last item
- if ($form->{groupsubtotaldescription}
- ne "") {
-
- if ($form->{"inventory_accno_id_$i"}
- || $form->{"assembly_$i"}) {
- push(@{ $form->{part} },
- "");
- push(@{
- $form->{service}
- }, NULL);
- } else {
- push(@{
- $form->{service}
- }, "");
- push(@{ $form->{part} },
- NULL);
- }
-
- for (qw(
- taxrates runningnumber
- number sku qty ship unit
- bin serialnumber
- requiredate
- projectnumber sellprice
- listprice netprice
- discount discountrate
- weight itemnotes)
- ) {
-
- push(@{ $form->{$_} },
- "");
- }
-
- push(@{ $form->{description} },
- $form->{groupsubtotaldescription});
-
- push(@{ $form->{linetotal} },
- $form->format_amount(
- $myconfig,
- $subtotal,
- 2));
- push(@{ $form->{lineitems} },
- { amount => 0,
- tax => 0 });
- }
- }
- }
- }
- }
-
-
- $tax = 0;
-
- foreach $item (sort keys %taxaccounts) {
- if ($form->round_amount($taxaccounts{$item}, 2)) {
- $tax += $taxamount = $form->round_amount(
- $taxaccounts{$item}, 2);
-
- push(@{ $form->{taxbaseinclusive} },
- $form->{"${item}_taxbaseinclusive"}
- = $form->round_amount(
- $taxbase{$item} + $tax, 2));
- push(@{ $form->{taxbase} },
- $form->{"${item}_taxbase"}
- = $form->format_amount($myconfig,
- $taxbase{$item}, 2));
- push(@{ $form->{tax} },
- $form->{"${item}_tax"}
- = $form->format_amount($myconfig,
- $taxamount, 2));
-
- push(@{ $form->{taxdescription} },
- $form->{"${item}_description"});
-
- $form->{"${item}_taxrate"} =
- $form->format_amount($myconfig,
- $form->{"${item}_rate"} * 100);
-
- push(@{ $form->{taxrate} }, $form->{"${item}_taxrate"});
-
- push(@{ $form->{taxnumber} },
- $form->{"${item}_taxnumber"});
- }
- }
-
- # adjust taxes for lineitems
- my $total = 0;
- for (@{ $form->{lineitems} }) {
- $total += $_->{tax};
- }
- if ($form->round_amount($total,2) != $form->round_amount($tax,2)) {
- # get largest amount
- for (reverse sort { $a->{tax} <=> $b->{tax} }
- @{ $form->{lineitems} }) {
-
- $_->{tax} -= $total - $tax;
- last;
- }
- }
- $i = 1;
- for (@{ $form->{lineitems} }) {
- push(@{ $form->{linetax} },
- $form->format_amount($myconfig, $_->{tax}, 2, ""));
- }
-
-
- for (qw(totalparts totalservices)) {
- $form->{$_} = $form->format_amount($myconfig, $form->{$_}, 2);
- }
- for (qw(totalqty totalship totalweight)) {
- $form->{$_} = $form->format_amount($myconfig, $form->{$_});
- }
- $form->{subtotal} = $form->format_amount($myconfig, $form->{ordtotal},
- 2);
- $form->{ordtotal} = ($form->{taxincluded})
- ? $form->{ordtotal}
- : $form->{ordtotal} + $tax;
-
- my $c;
- if ($form->{language_code} ne "") {
- $c = new CP $form->{language_code};
- } else {
- $c = new CP $myconfig->{countrycode};
- }
- $c->init;
- my $whole;
- ($whole, $form->{decimal}) = split /\./, $form->{ordtotal};
- $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);
-
- # format amounts
- $form->{quototal} = $form->{ordtotal} =
- $form->format_amount($myconfig, $form->{ordtotal}, 2);
-
- $form->format_string(qw(text_amount text_decimal));
-
- $query = qq|
+ $sth = $dbh->prepare($query) || $form->dberror($query);
+
+ for $i ( 1 .. $form->{rowcount} ) {
+ $sth->execute( $form->{"id_$i"}, $form->{warehouse_id} )
+ || $form->dberror;
+
+ ($qty) = $sth->fetchrow_array;
+ $sth->finish;
+
+ $form->{"qty_$i"} = 0 if $qty == 0;
+
+ if ( $form->parse_amount( $myconfig, $form->{"ship_$i"} ) > $qty ) {
+ $form->{"ship_$i"} = $form->format_amount( $myconfig, $qty );
+ }
+ }
+ }
+
+ my $runningnumber = 1;
+ my $sameitem = "";
+ my $subtotal;
+ my $k = scalar @sortlist;
+ my $j = 0;
+
+ foreach $item (@sortlist) {
+ $i = $item->[0];
+ $j++;
+
+ if ( $form->{groupprojectnumber} || $form->{grouppartsgroup} ) {
+ if ( $item->[1] ne $sameitem ) {
+ $sameitem = $item->[1];
+
+ $ok = 0;
+
+ if ( $form->{groupprojectnumber} ) {
+ $ok = $form->{"projectnumber_$i"};
+ }
+ if ( $form->{grouppartsgroup} ) {
+ $ok = $form->{"partsgroup_$i"}
+ unless $ok;
+ }
+
+ if ($ok) {
+ if ( $form->{"inventory_accno_id_$i"}
+ || $form->{"assembly_$i"} )
+ {
+
+ push( @{ $form->{part} }, "" );
+ push( @{ $form->{service} }, NULL );
+ }
+ else {
+ push( @{ $form->{part} }, NULL );
+ push( @{ $form->{service} }, "" );
+ }
+
+ push( @{ $form->{description} }, $item->[2] );
+ for (
+ qw(taxrates runningnumber
+ number sku qty ship unit bin
+ serialnumber requiredate
+ projectnumber sellprice
+ listprice netprice discount
+ discountrate linetotal weight
+ itemnotes)
+ )
+ {
+ push( @{ $form->{$_} }, "" );
+ }
+ push( @{ $form->{lineitems} }, { amount => 0, tax => 0 } );
+ }
+ }
+ }
+
+ $form->{"qty_$i"} = $form->parse_amount( $myconfig, $form->{"qty_$i"} );
+ $form->{"ship_$i"} =
+ $form->parse_amount( $myconfig, $form->{"ship_$i"} );
+
+ if ( $form->{"qty_$i"} ) {
+
+ $form->{totalqty} += $form->{"qty_$i"};
+ $form->{totalship} += $form->{"ship_$i"};
+ $form->{totalweight} +=
+ ( $form->{"weight_$i"} * $form->{"qty_$i"} );
+ $form->{totalweightship} +=
+ ( $form->{"weight_$i"} * $form->{"ship_$i"} );
+
+ # add number, description and qty to $form->{number}
+ push( @{ $form->{runningnumber} }, $runningnumber++ );
+ push( @{ $form->{number} }, qq|$form->{"partnumber_$i"}| );
+ push( @{ $form->{sku} }, qq|$form->{"sku_$i"}| );
+ push( @{ $form->{description} }, qq|$form->{"description_$i"}| );
+ push( @{ $form->{itemnotes} }, $form->{"notes_$i"} );
+ push(
+ @{ $form->{qty} },
+ $form->format_amount( $myconfig, $form->{"qty_$i"} )
+ );
+ push(
+ @{ $form->{ship} },
+ $form->format_amount( $myconfig, $form->{"ship_$i"} )
+ );
+ push( @{ $form->{unit} }, qq|$form->{"unit_$i"}| );
+ push( @{ $form->{bin} }, qq|$form->{"bin_$i"}| );
+ push( @{ $form->{serialnumber} }, qq|$form->{"serialnumber_$i"}| );
+ push( @{ $form->{requiredate} }, qq|$form->{"reqdate_$i"}| );
+ push( @{ $form->{projectnumber} },
+ qq|$form->{"projectnumber_$i"}| );
+
+ push( @{ $form->{sellprice} }, $form->{"sellprice_$i"} );
+
+ push( @{ $form->{listprice} }, $form->{"listprice_$i"} );
+
+ push(
+ @{ $form->{weight} },
+ $form->format_amount(
+ $myconfig, $form->{"weight_$i"} * $form->{"ship_$i"}
+ )
+ );
+
+ my $sellprice =
+ $form->parse_amount( $myconfig, $form->{"sellprice_$i"} );
+ my ($dec) = ( $sellprice =~ /\.(\d+)/ );
+ $dec = length $dec;
+ my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ my $discount = $form->round_amount(
+ $sellprice *
+ $form->parse_amount( $myconfig, $form->{"discount_$i"} ) /
+ 100,
+ $decimalplaces
+ );
+
+ # keep a netprice as well, (sellprice - discount)
+ $form->{"netprice_$i"} = $sellprice - $discount;
+
+ my $linetotal =
+ $form->round_amount( $form->{"qty_$i"} * $form->{"netprice_$i"},
+ 2 );
+
+ if ( $form->{"inventory_accno_id_$i"}
+ || $form->{"assembly_$i"} )
+ {
+
+ push( @{ $form->{part} }, $form->{"sku_$i"} );
+ push( @{ $form->{service} }, NULL );
+ $form->{totalparts} += $linetotal;
+ }
+ else {
+ push( @{ $form->{service} }, $form->{"sku_$i"} );
+ push( @{ $form->{part} }, NULL );
+ $form->{totalservices} += $linetotal;
+ }
+
+ push(
+ @{ $form->{netprice} },
+ ( $form->{"netprice_$i"} )
+ ? $form->format_amount( $myconfig, $form->{"netprice_$i"},
+ $decimalplaces )
+ : " "
+ );
+
+ $discount =
+ ($discount)
+ ? $form->format_amount( $myconfig, $discount * -1,
+ $decimalplaces )
+ : " ";
+
+ push( @{ $form->{discount} }, $discount );
+ push(
+ @{ $form->{discountrate} },
+ $form->format_amount( $myconfig, $form->{"discount_$i"} )
+ );
+
+ $form->{ordtotal} += $linetotal;
+
+ # this is for the subtotals for grouping
+ $subtotal += $linetotal;
+
+ $form->{"linetotal_$i"} =
+ $form->format_amount( $myconfig, $linetotal, 2 );
+ push( @{ $form->{linetotal} }, $form->{"linetotal_$i"} );
+
+ @taxaccounts = Tax::init_taxes( $form, $form->{"taxaccounts_$i"} );
+
+ my $ml = 1;
+ my @taxrates = ();
+
+ $tax = 0;
+
+ $taxamount =
+ Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 1 );
+ $taxbase = Tax::extract_taxes( \@taxaccounts, $form, $linetotal );
+ foreach $item (@taxaccounts) {
+ push @taxrates, Math::BigFloat->new(100) * $item->rate;
+ if ( $form->{taxincluded} ) {
+ $taxaccounts{ $item->account } += $item->value;
+ $taxbase{ $item->account } += $taxbase;
+ }
+ else {
+ Tax::apply_taxes( \@taxaccounts, $form, $linetotal );
+ $taxbase{ $item->account } += $linetotal;
+ $taxaccounts{ $item->account } += $item->value;
+ }
+ }
+ if ( $form->{taxincluded} ) {
+ $tax +=
+ Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 1 );
+ }
+ else {
+ $tax +=
+ Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 0 );
+ }
+
+ push(
+ @{ $form->{lineitems} },
+ {
+ amount => $linetotal,
+ tax => $form->round_amount( $tax, 2 )
+ }
+ );
+ push( @{ $form->{taxrates} },
+ join ' ', sort { $a <=> $b } @taxrates );
+
+ if ( $form->{"assembly_$i"} ) {
+ $form->{stagger} = -1;
+ &assembly_details( $myconfig, $form, $dbh, $form->{"id_$i"},
+ $oid{ $myconfig->{dbdriver} },
+ $form->{"qty_$i"} );
+ }
+
+ }
+
+ # add subtotal
+ if ( $form->{groupprojectnumber} || $form->{grouppartsgroup} ) {
+ if ($subtotal) {
+ if ( $j < $k ) {
+
+ # look at next item
+ if ( $sortlist[$j]->[1] ne $sameitem ) {
+
+ if ( $form->{"inventory_accno_id_$i"}
+ || $form->{"assembly_$i"} )
+ {
+
+ push( @{ $form->{part} }, "" );
+ push( @{ $form->{service} }, NULL );
+ }
+ else {
+ push( @{ $form->{service} }, "" );
+ push( @{ $form->{part} }, NULL );
+ }
+
+ for (
+ qw(
+ taxrates runningnumber
+ number sku qty ship unit
+ bin serialnumber
+ requiredate
+ projectnumber sellprice
+ listprice netprice
+ discount discountrate
+ weight itemnotes)
+ )
+ {
+
+ push( @{ $form->{$_} }, "" );
+ }
+
+ push(
+ @{ $form->{description} },
+ $form->{groupsubtotaldescription}
+ );
+
+ push(
+ @{ $form->{lineitems} },
+ {
+ amount => 0,
+ tax => 0
+ }
+ );
+
+ if ( $form->{groupsubtotaldescription} ne "" ) {
+ push(
+ @{ $form->{linetotal} },
+ $form->format_amount( $myconfig, $subtotal, 2 )
+ );
+ }
+ else {
+ push( @{ $form->{linetotal} }, "" );
+ }
+ $subtotal = 0;
+ }
+
+ }
+ else {
+
+ # got last item
+ if ( $form->{groupsubtotaldescription} ne "" ) {
+
+ if ( $form->{"inventory_accno_id_$i"}
+ || $form->{"assembly_$i"} )
+ {
+ push( @{ $form->{part} }, "" );
+ push( @{ $form->{service} }, NULL );
+ }
+ else {
+ push( @{ $form->{service} }, "" );
+ push( @{ $form->{part} }, NULL );
+ }
+
+ for (
+ qw(
+ taxrates runningnumber
+ number sku qty ship unit
+ bin serialnumber
+ requiredate
+ projectnumber sellprice
+ listprice netprice
+ discount discountrate
+ weight itemnotes)
+ )
+ {
+
+ push( @{ $form->{$_} }, "" );
+ }
+
+ push(
+ @{ $form->{description} },
+ $form->{groupsubtotaldescription}
+ );
+
+ push(
+ @{ $form->{linetotal} },
+ $form->format_amount( $myconfig, $subtotal, 2 )
+ );
+ push(
+ @{ $form->{lineitems} },
+ {
+ amount => 0,
+ tax => 0
+ }
+ );
+ }
+ }
+ }
+ }
+ }
+
+ $tax = 0;
+
+ foreach $item ( sort keys %taxaccounts ) {
+ if ( $form->round_amount( $taxaccounts{$item}, 2 ) ) {
+ $tax += $taxamount = $form->round_amount( $taxaccounts{$item}, 2 );
+
+ push(
+ @{ $form->{taxbaseinclusive} },
+ $form->{"${item}_taxbaseinclusive"} =
+ $form->round_amount( $taxbase{$item} + $tax, 2 )
+ );
+ push(
+ @{ $form->{taxbase} },
+ $form->{"${item}_taxbase"} =
+ $form->format_amount( $myconfig, $taxbase{$item}, 2 )
+ );
+ push(
+ @{ $form->{tax} },
+ $form->{"${item}_tax"} =
+ $form->format_amount( $myconfig, $taxamount, 2 )
+ );
+
+ push( @{ $form->{taxdescription} },
+ $form->{"${item}_description"} );
+
+ $form->{"${item}_taxrate"} =
+ $form->format_amount( $myconfig, $form->{"${item}_rate"} * 100 );
+
+ push( @{ $form->{taxrate} }, $form->{"${item}_taxrate"} );
+
+ push( @{ $form->{taxnumber} }, $form->{"${item}_taxnumber"} );
+ }
+ }
+
+ # adjust taxes for lineitems
+ my $total = 0;
+ for ( @{ $form->{lineitems} } ) {
+ $total += $_->{tax};
+ }
+ if ( $form->round_amount( $total, 2 ) != $form->round_amount( $tax, 2 ) ) {
+
+ # get largest amount
+ for ( reverse sort { $a->{tax} <=> $b->{tax} } @{ $form->{lineitems} } )
+ {
+
+ $_->{tax} -= $total - $tax;
+ last;
+ }
+ }
+ $i = 1;
+ for ( @{ $form->{lineitems} } ) {
+ push(
+ @{ $form->{linetax} },
+ $form->format_amount( $myconfig, $_->{tax}, 2, "" )
+ );
+ }
+
+ for (qw(totalparts totalservices)) {
+ $form->{$_} = $form->format_amount( $myconfig, $form->{$_}, 2 );
+ }
+ for (qw(totalqty totalship totalweight)) {
+ $form->{$_} = $form->format_amount( $myconfig, $form->{$_} );
+ }
+ $form->{subtotal} = $form->format_amount( $myconfig, $form->{ordtotal}, 2 );
+ $form->{ordtotal} =
+ ( $form->{taxincluded} )
+ ? $form->{ordtotal}
+ : $form->{ordtotal} + $tax;
+
+ my $c;
+ if ( $form->{language_code} ne "" ) {
+ $c = new CP $form->{language_code};
+ }
+ else {
+ $c = new CP $myconfig->{countrycode};
+ }
+ $c->init;
+ my $whole;
+ ( $whole, $form->{decimal} ) = split /\./, $form->{ordtotal};
+ $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 );
+
+ # format amounts
+ $form->{quototal} = $form->{ordtotal} =
+ $form->format_amount( $myconfig, $form->{ordtotal}, 2 );
+
+ $form->format_string(qw(text_amount text_decimal));
+
+ $query = qq|
SELECT value FROM defaults
WHERE setting_key = 'weightunit'|;
- ($form->{weightunit}) = $dbh->selectrow_array($query);
-
- $dbh->commit;
+ ( $form->{weightunit} ) = $dbh->selectrow_array($query);
-}
+ $dbh->commit;
+}
sub assembly_details {
- my ($myconfig, $form, $dbh, $id, $oid, $qty) = @_;
-
- my $sm = "";
- my $spacer;
-
- $form->{stagger}++;
- if ($form->{format} eq 'html') {
- $spacer = "&nbsp;" x (3 * ($form->{stagger} - 1))
- if $form->{stagger} > 1;
- }
- if ($form->{format} =~ /(postscript|pdf)/) {
- if ($form->{stagger} > 1) {
- $spacer = ($form->{stagger} - 1) * 3;
- $spacer = '\rule{'.$spacer.'mm}{0mm}';
- }
- }
-
- # get parts and push them onto the stack
- my $sortorder = "";
-
- if ($form->{grouppartsgroup}) {
- $sortorder = qq|ORDER BY pg.partsgroup, a.id|;
- } else {
- $sortorder = qq|ORDER BY a.id|;
- }
-
- my $where = ($form->{formname} eq 'work_order')
- ? "1 = 1"
- : "a.bom = '1'";
-
- my $query = qq|
+ my ( $myconfig, $form, $dbh, $id, $oid, $qty ) = @_;
+
+ my $sm = "";
+ my $spacer;
+
+ $form->{stagger}++;
+ if ( $form->{format} eq 'html' ) {
+ $spacer = "&nbsp;" x ( 3 * ( $form->{stagger} - 1 ) )
+ if $form->{stagger} > 1;
+ }
+ if ( $form->{format} =~ /(postscript|pdf)/ ) {
+ if ( $form->{stagger} > 1 ) {
+ $spacer = ( $form->{stagger} - 1 ) * 3;
+ $spacer = '\rule{' . $spacer . 'mm}{0mm}';
+ }
+ }
+
+ # get parts and push them onto the stack
+ my $sortorder = "";
+
+ if ( $form->{grouppartsgroup} ) {
+ $sortorder = qq|ORDER BY pg.partsgroup, a.id|;
+ }
+ else {
+ $sortorder = qq|ORDER BY a.id|;
+ }
+
+ my $where =
+ ( $form->{formname} eq 'work_order' )
+ ? "1 = 1"
+ : "a.bom = '1'";
+
+ my $query = qq|
SELECT p.partnumber, p.description, p.unit, a.qty,
pg.partsgroup, p.partnumber AS sku, p.assembly, p.id,
p.bin
@@ -1622,331 +1608,325 @@ sub assembly_details {
WHERE $where
AND a.id = ?
$sortorder|;
- my $sth = $dbh->prepare($query);
- $sth->execute($id) || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- for (qw(partnumber description partsgroup)) {
- $form->{"a_$_"} = $ref->{$_};
- $form->format_string("a_$_");
- }
-
- if ($form->{grouppartsgroup} && $ref->{partsgroup} ne $sm) {
- for (qw(
- taxrates number sku unit qty runningnumber ship
- bin serialnumber requiredate projectnumber
- sellprice listprice netprice discount
- discountrate linetotal weight itemnotes)
- ) {
-
- push(@{ $form->{$_} }, "");
- }
- $sm = ($form->{"a_partsgroup"})
- ? $form->{"a_partsgroup"} : "";
- push(@{ $form->{description} }, "$spacer$sm");
-
- push(@{ $form->{lineitems} },
- { amount => 0, tax => 0 });
-
- }
-
- if ($form->{stagger}) {
-
- push(@{ $form->{description} },
- qq|$spacer$form->{"a_partnumber"}, |.
- qq|$form->{"a_description"}|);
-
- for (qw(
- taxrates number sku runningnumber ship
- serialnumber requiredate projectnumber
- sellprice listprice netprice discount
- discountrate linetotal weight itemnotes)
- ) {
-
- push(@{ $form->{$_} }, "")
- }
-
- } else {
-
- push(@{ $form->{description} },
- qq|$form->{"a_description"}|);
- push(@{ $form->{sku} }, $form->{"a_partnumber"});
- push(@{ $form->{number} }, $form->{"a_partnumber"});
-
- for (qw(
- taxrates runningnumber ship serialnumber
- requiredate projectnumber sellprice listprice
- netprice discount discountrate linetotal weight
- itemnotes)
- ) {
-
- push(@{ $form->{$_} }, "")
- }
-
- }
-
- push(@{ $form->{lineitems} }, { amount => 0, tax => 0 });
-
- push(@{ $form->{qty} }, $form->format_amount(
- $myconfig, $ref->{qty} * $qty));
-
- for (qw(unit bin)) {
- $form->{"a_$_"} = $ref->{$_};
- $form->format_string("a_$_");
- push(@{ $form->{$_} }, $form->{"a_$_"});
- }
-
- if ($ref->{assembly} && $form->{formname} eq 'work_order') {
- &assembly_details(
- $myconfig, $form, $dbh, $ref->{id}, $oid,
- $ref->{qty} * $qty);
- }
-
- }
- $sth->finish;
-
- $form->{stagger}--;
-
-}
+ my $sth = $dbh->prepare($query);
+ $sth->execute($id) || $form->dberror($query);
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ for (qw(partnumber description partsgroup)) {
+ $form->{"a_$_"} = $ref->{$_};
+ $form->format_string("a_$_");
+ }
+
+ if ( $form->{grouppartsgroup} && $ref->{partsgroup} ne $sm ) {
+ for (
+ qw(
+ taxrates number sku unit qty runningnumber ship
+ bin serialnumber requiredate projectnumber
+ sellprice listprice netprice discount
+ discountrate linetotal weight itemnotes)
+ )
+ {
+
+ push( @{ $form->{$_} }, "" );
+ }
+ $sm = ( $form->{"a_partsgroup"} ) ? $form->{"a_partsgroup"} : "";
+ push( @{ $form->{description} }, "$spacer$sm" );
+
+ push( @{ $form->{lineitems} }, { amount => 0, tax => 0 } );
+
+ }
+
+ if ( $form->{stagger} ) {
+
+ push(
+ @{ $form->{description} },
+ qq|$spacer$form->{"a_partnumber"}, |
+ . qq|$form->{"a_description"}|
+ );
+
+ for (
+ qw(
+ taxrates number sku runningnumber ship
+ serialnumber requiredate projectnumber
+ sellprice listprice netprice discount
+ discountrate linetotal weight itemnotes)
+ )
+ {
+
+ push( @{ $form->{$_} }, "" );
+ }
+
+ }
+ else {
+
+ push( @{ $form->{description} }, qq|$form->{"a_description"}| );
+ push( @{ $form->{sku} }, $form->{"a_partnumber"} );
+ push( @{ $form->{number} }, $form->{"a_partnumber"} );
+
+ for (
+ qw(
+ taxrates runningnumber ship serialnumber
+ requiredate projectnumber sellprice listprice
+ netprice discount discountrate linetotal weight
+ itemnotes)
+ )
+ {
+
+ push( @{ $form->{$_} }, "" );
+ }
+
+ }
+
+ push( @{ $form->{lineitems} }, { amount => 0, tax => 0 } );
+
+ push(
+ @{ $form->{qty} },
+ $form->format_amount( $myconfig, $ref->{qty} * $qty )
+ );
+
+ for (qw(unit bin)) {
+ $form->{"a_$_"} = $ref->{$_};
+ $form->format_string("a_$_");
+ push( @{ $form->{$_} }, $form->{"a_$_"} );
+ }
+
+ if ( $ref->{assembly} && $form->{formname} eq 'work_order' ) {
+ &assembly_details( $myconfig, $form, $dbh, $ref->{id}, $oid,
+ $ref->{qty} * $qty );
+ }
+
+ }
+ $sth->finish;
+
+ $form->{stagger}--;
+}
sub project_description {
- my ($self, $dbh, $id) = @_;
+ my ( $self, $dbh, $id ) = @_;
- my $query = qq|
+ my $query = qq|
SELECT description
FROM project
WHERE id = $id|;
- ($_) = $dbh->selectrow_array($query);
-
- $_;
+ ($_) = $dbh->selectrow_array($query);
-}
+ $_;
+}
sub get_warehouses {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
- # setup warehouses
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ # setup warehouses
+ my $query = qq|
SELECT id, description
FROM warehouse
ORDER BY 2|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_warehouse} }, $ref;
- }
- $sth->finish;
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_warehouse} }, $ref;
+ }
+ $sth->finish;
- $dbh->commit;
+ $dbh->commit;
}
-
sub save_inventory {
- my ($self, $myconfig, $form) = @_;
-
- my ($null, $warehouse_id) = split /--/, $form->{warehouse};
- $warehouse_id *= 1;
-
- my $ml = ($form->{type} eq 'ship_order') ? -1 : 1;
-
- my $dbh = $form->{dbh};
- my $sth;
- my $wth;
- my $serialnumber;
- my $ship;
-
- my ($null, $employee_id) = split /--/, $form->{employee};
- ($null, $employee_id) = $form->get_employee($dbh) if ! $employee_id;
-
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my ( $null, $warehouse_id ) = split /--/, $form->{warehouse};
+ $warehouse_id *= 1;
+
+ my $ml = ( $form->{type} eq 'ship_order' ) ? -1 : 1;
+
+ my $dbh = $form->{dbh};
+ my $sth;
+ my $wth;
+ my $serialnumber;
+ my $ship;
+
+ my ( $null, $employee_id ) = split /--/, $form->{employee};
+ ( $null, $employee_id ) = $form->get_employee($dbh) if !$employee_id;
+
+ $query = qq|
SELECT serialnumber, ship
FROM orderitems
WHERE trans_id = ?
AND id = ?
FOR UPDATE|;
- $sth = $dbh->prepare($query) || $form->dberror($query);
+ $sth = $dbh->prepare($query) || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT sum(qty)
FROM inventory
WHERE parts_id = ?
AND warehouse_id = ?|;
- $wth = $dbh->prepare($query) || $form->dberror($query);
-
+ $wth = $dbh->prepare($query) || $form->dberror($query);
+
+ for my $i ( 1 .. $form->{rowcount} ) {
+ $form->{"ship_$i"} = 0 unless $form->{"ship_$i"};
- for my $i (1 .. $form->{rowcount}) {
- $form->{"ship_$i"} = 0 unless $form->{"ship_$i"};
+ $ship =
+ ( abs( $form->{"ship_$i"} ) > abs( $form->{"qty_$i"} ) )
+ ? $form->{"qty_$i"}
+ : $form->{"ship_$i"};
- $ship = (abs($form->{"ship_$i"}) > abs($form->{"qty_$i"}))
- ? $form->{"qty_$i"}
- : $form->{"ship_$i"};
-
- if ($warehouse_id && $form->{type} eq 'ship_order') {
+ if ( $warehouse_id && $form->{type} eq 'ship_order' ) {
- $wth->execute($form->{"id_$i"}, $warehouse_id)
- || $form->dberror;
+ $wth->execute( $form->{"id_$i"}, $warehouse_id )
+ || $form->dberror;
- ($qty) = $wth->fetchrow_array;
- $wth->finish;
+ ($qty) = $wth->fetchrow_array;
+ $wth->finish;
- if ($ship > $qty) {
- $ship = $qty;
- }
- }
+ if ( $ship > $qty ) {
+ $ship = $qty;
+ }
+ }
-
- if ($ship) {
+ if ($ship) {
- if (!$form->{shippingdate}){
- $form->{shippingdate} = undef;
- }
+ if ( !$form->{shippingdate} ) {
+ $form->{shippingdate} = undef;
+ }
- $ship *= $ml;
- $query = qq|
+ $ship *= $ml;
+ $query = qq|
INSERT INTO inventory
(parts_id, warehouse_id, qty, trans_id,
orderitems_id, shippingdate,
employee_id)
VALUES
(?, ?, ?, ?, ?, ?, ?)|;
- $sth2 = $dbh->prepare($query);
- $sth2->execute(
- $form->{"id_$i"}, $warehouse_id,
- $ship, $form->{"id"},
- $form->{"orderitems_id_$i"},
- $form->{shippingdate},
- $employee_id
- ) || $form->dberror($query);
- $sth2->finish;
-
- # add serialnumber, ship to orderitems
- $sth->execute(
- $form->{id}, $form->{"orderitems_id_$i"})
- || $form->dberror;
- ($serialnumber, $ship) = $sth->fetchrow_array;
- $sth->finish;
-
- $serialnumber .= " " if $serialnumber;
- $serialnumber .= qq|$form->{"serialnumber_$i"}|;
- $ship += $form->{"ship_$i"};
-
- $query = qq|
+ $sth2 = $dbh->prepare($query);
+ $sth2->execute( $form->{"id_$i"}, $warehouse_id, $ship,
+ $form->{"id"}, $form->{"orderitems_id_$i"},
+ $form->{shippingdate}, $employee_id )
+ || $form->dberror($query);
+ $sth2->finish;
+
+ # add serialnumber, ship to orderitems
+ $sth->execute( $form->{id}, $form->{"orderitems_id_$i"} )
+ || $form->dberror;
+ ( $serialnumber, $ship ) = $sth->fetchrow_array;
+ $sth->finish;
+
+ $serialnumber .= " " if $serialnumber;
+ $serialnumber .= qq|$form->{"serialnumber_$i"}|;
+ $ship += $form->{"ship_$i"};
+
+ $query = qq|
UPDATE orderitems SET
serialnumber = '$serialnumber',
ship = $ship,
reqdate = '$form->{shippingdate}'
WHERE trans_id = $form->{id}
AND id = $form->{"orderitems_id_$i"}|;
- $sth2 = $dbh->prepare($query);
- $sth2->execute(
- $serialnumber, $ship,
- $form->{shippingdate}, $form->{id},
- $form->{"orderitems_id_$i"}
- ) || $form->dberror($query);
- $sth2->finish;
-
- # update order with ship via
- $query = qq|
+ $sth2 = $dbh->prepare($query);
+ $sth2->execute( $serialnumber, $ship, $form->{shippingdate},
+ $form->{id}, $form->{"orderitems_id_$i"} )
+ || $form->dberror($query);
+ $sth2->finish;
+
+ # update order with ship via
+ $query = qq|
UPDATE oe SET
shippingpoint = ?,
shipvia = ?
WHERE id = ?|;
- $sth2 = $dbh->prepare($query);
- $sth2->execute(
- $form->{shippingpoint}, $form->{shipvia},
- $form->{id}
- ) || $form->dberror($query);
- $sth2->finish;
+ $sth2 = $dbh->prepare($query);
+ $sth2->execute( $form->{shippingpoint},
+ $form->{shipvia}, $form->{id} )
+ || $form->dberror($query);
+ $sth2->finish;
- # update onhand for parts
- $form->update_balance($dbh,
- "parts",
- "onhand",
- qq|id = $form->{"id_$i"}|,
- $form->{"ship_$i"} * $ml);
+ # update onhand for parts
+ $form->update_balance(
+ $dbh, "parts", "onhand",
+ qq|id = $form->{"id_$i"}|,
+ $form->{"ship_$i"} * $ml
+ );
- }
- }
+ }
+ }
- my $rc = $dbh->commit;
+ my $rc = $dbh->commit;
- $rc;
+ $rc;
}
-
sub adj_onhand {
- my ($dbh, $form, $ml) = @_;
+ my ( $dbh, $form, $ml ) = @_;
- my $query = qq|
+ my $query = qq|
SELECT oi.parts_id, oi.ship, p.inventory_accno_id, p.assembly
FROM orderitems oi
JOIN parts p ON (p.id = oi.parts_id)
WHERE oi.trans_id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT sum(p.inventory_accno_id), p.assembly
FROM parts p
JOIN assembly a ON (a.parts_id = p.id)
WHERE a.id = ?
GROUP BY p.assembly|;
- my $ath = $dbh->prepare($query) || $form->dberror($query);
+ my $ath = $dbh->prepare($query) || $form->dberror($query);
- my $ref;
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ my $ref;
- if ($ref->{inventory_accno_id} || $ref->{assembly}) {
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
- # do not update if assembly consists of all services
- if ($ref->{assembly}) {
- $ath->execute($ref->{parts_id})
- || $form->dberror($query);
+ if ( $ref->{inventory_accno_id} || $ref->{assembly} ) {
- my ($inv, $assembly) = $ath->fetchrow_array;
- $ath->finish;
+ # do not update if assembly consists of all services
+ if ( $ref->{assembly} ) {
+ $ath->execute( $ref->{parts_id} )
+ || $form->dberror($query);
- next unless ($inv || $assembly);
-
- }
+ my ( $inv, $assembly ) = $ath->fetchrow_array;
+ $ath->finish;
- # adjust onhand in parts table
- $form->update_balance($dbh,
- "parts",
- "onhand",
- qq|id = $ref->{parts_id}|,
- $ref->{ship} * $ml);
- }
- }
-
- $sth->finish;
+ next unless ( $inv || $assembly );
-}
+ }
+ # adjust onhand in parts table
+ $form->update_balance(
+ $dbh, "parts", "onhand",
+ qq|id = $ref->{parts_id}|,
+ $ref->{ship} * $ml
+ );
+ }
+ }
+
+ $sth->finish;
+
+}
sub adj_inventory {
- my ($dbh, $myconfig, $form) = @_;
+ my ( $dbh, $myconfig, $form ) = @_;
-
- # increase/reduce qty in inventory table
- my $query = qq|
+ # increase/reduce qty in inventory table
+ my $query = qq|
SELECT oi.id, oi.parts_id, oi.ship
FROM orderitems oi
WHERE oi.trans_id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- my $id = $dbh->quote($form->{id});
- $query = qq|
+ my $id = $dbh->quote( $form->{id} );
+ $query = qq|
SELECT qty,
(SELECT SUM(qty) FROM inventory
WHERE trans_id = $id
@@ -1954,99 +1934,96 @@ sub adj_inventory {
FROM inventory
WHERE trans_id = $id
AND orderitems_id = ?|;
- my $ith = $dbh->prepare($query) || $form->dberror($query);
-
- my $qty;
- my $ml = ($form->{type} =~ /(ship|sales)_order/) ? -1 : 1;
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- $ith->execute($ref->{id}, $ref->{id}) || $form->dberror($query);
-
- my $ship = $ref->{ship};
- while (my $inv = $ith->fetchrow_hashref(NAME_lc)) {
-
- if (($qty = (($inv->{total} * $ml) - $ship)) >= 0) {
- $qty = $inv->{qty} * $ml
- if ($qty > ($inv->{qty} * $ml));
-
- $form->update_balance($dbh,
- "inventory",
- "qty",
- qq|$oid{$myconfig->{dbdriver}} |.
- qq|= $inv->{oid}|,
- $qty * -1 * $ml);
- $ship -= $qty;
- }
- }
- $ith->finish;
-
- }
- $sth->finish;
-
- # delete inventory entries if qty = 0
- $query = qq|
+ my $ith = $dbh->prepare($query) || $form->dberror($query);
+
+ my $qty;
+ my $ml = ( $form->{type} =~ /(ship|sales)_order/ ) ? -1 : 1;
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ $ith->execute( $ref->{id}, $ref->{id} ) || $form->dberror($query);
+
+ my $ship = $ref->{ship};
+ while ( my $inv = $ith->fetchrow_hashref(NAME_lc) ) {
+
+ if ( ( $qty = ( ( $inv->{total} * $ml ) - $ship ) ) >= 0 ) {
+ $qty = $inv->{qty} * $ml
+ if ( $qty > ( $inv->{qty} * $ml ) );
+
+ $form->update_balance(
+ $dbh, "inventory", "qty",
+ qq|$oid{$myconfig->{dbdriver}} | . qq|= $inv->{oid}|,
+ $qty * -1 * $ml
+ );
+ $ship -= $qty;
+ }
+ }
+ $ith->finish;
+
+ }
+ $sth->finish;
+
+ # delete inventory entries if qty = 0
+ $query = qq|
DELETE FROM inventory
WHERE trans_id = ?
AND qty = 0|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
}
-
sub get_inventory {
- my ($self, $myconfig, $form) = @_;
-
- my $where;
- my $query;
- my $null;
- my $fromwarehouse_id;
- my $towarehouse_id;
- my $var;
-
- my $dbh = $form->{dbh};
-
- if ($form->{partnumber} ne "") {
- $var = $dbh->quote($form->like(lc $form->{partnumber}));
- $where .= "
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $where;
+ my $query;
+ my $null;
+ my $fromwarehouse_id;
+ my $towarehouse_id;
+ my $var;
+
+ my $dbh = $form->{dbh};
+
+ if ( $form->{partnumber} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{partnumber} ) );
+ $where .= "
AND lower(p.partnumber) LIKE '$var'";
- }
- if ($form->{description} ne "") {
- $var = $dbh->quote($form->like(lc $form->{description}));
- $where .= "
+ }
+ if ( $form->{description} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{description} ) );
+ $where .= "
AND lower(p.description) LIKE '$var'";
- }
- if ($form->{partsgroup} ne "") {
- ($null, $var) = split /--/, $form->{partsgroup};
- $var = $dbh->quote($var);
- $where .= "
+ }
+ if ( $form->{partsgroup} ne "" ) {
+ ( $null, $var ) = split /--/, $form->{partsgroup};
+ $var = $dbh->quote($var);
+ $where .= "
AND pg.id = $var";
- }
-
-
- ($null, $fromwarehouse_id) = split /--/, $form->{fromwarehouse};
- $fromwarehouse_id = $dbh->quote($fromwarehouse_id);
-
- ($null, $towarehouse_id) = split /--/, $form->{towarehouse};
- $towarehouse_id = $dbh->quote($towarehouse_id);
-
- my %ordinal = (
- partnumber => 2,
- description => 3,
- partsgroup => 5,
- warehouse => 6,
- );
-
- my @a = (partnumber, warehouse);
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
- if ($fromwarehouse_id) {
- if ($towarehouse_id) {
- $where .= "
+ }
+
+ ( $null, $fromwarehouse_id ) = split /--/, $form->{fromwarehouse};
+ $fromwarehouse_id = $dbh->quote($fromwarehouse_id);
+
+ ( $null, $towarehouse_id ) = split /--/, $form->{towarehouse};
+ $towarehouse_id = $dbh->quote($towarehouse_id);
+
+ my %ordinal = (
+ partnumber => 2,
+ description => 3,
+ partsgroup => 5,
+ warehouse => 6,
+ );
+
+ my @a = ( partnumber, warehouse );
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ if ($fromwarehouse_id) {
+ if ($towarehouse_id) {
+ $where .= "
AND NOT i.warehouse_id = $towarehouse_id";
- }
- $query = qq|
+ }
+ $query = qq|
SELECT p.id, p.partnumber, p.description,
sum(i.qty) * 2 AS onhand, sum(i.qty) AS qty,
pg.partsgroup, w.description AS warehouse,
@@ -2060,9 +2037,10 @@ sub get_inventory {
GROUP BY p.id, p.partnumber, p.description,
pg.partsgroup, w.description, i.warehouse_id
ORDER BY $sortorder|;
- } else {
- if ($towarehouse_id) {
- $query = qq|
+ }
+ else {
+ if ($towarehouse_id) {
+ $query = qq|
SELECT p.id, p.partnumber, p.description,
p.onhand,
(SELECT SUM(qty)
@@ -2076,9 +2054,9 @@ sub get_inventory {
WHERE p.onhand > 0
$where
UNION|;
- }
+ }
- $query .= qq|
+ $query .= qq|
SELECT p.id, p.partnumber, p.description,
sum(i.qty) * 2 AS onhand, sum(i.qty) AS qty,
pg.partsgroup, w.description AS warehouse,
@@ -2092,349 +2070,341 @@ sub get_inventory {
GROUP BY p.id, p.partnumber, p.description,
pg.partsgroup, w.description, i.warehouse_id
ORDER BY $sortorder|;
- }
-
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{qty} = $ref->{onhand} - $ref->{qty};
- push @{ $form->{all_inventory} }, $ref if $ref->{qty} > 0;
- }
- $sth->finish;
-
- $dbh->commit;
-}
+ }
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{qty} = $ref->{onhand} - $ref->{qty};
+ push @{ $form->{all_inventory} }, $ref if $ref->{qty} > 0;
+ }
+ $sth->finish;
+ $dbh->commit;
+}
sub transfer {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- ($form->{employee}, $form->{employee_id}) = $form->get_employee($dbh);
-
- my @a = localtime;
- $a[5] += 1900;
- $a[4]++;
- $a[4] = substr("0$a[4]", -2);
- $a[3] = substr("0$a[3]", -2);
- $shippingdate = "$a[5]$a[4]$a[3]";
-
- my %total = ();
-
-
-
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ ( $form->{employee}, $form->{employee_id} ) = $form->get_employee($dbh);
+
+ my @a = localtime;
+ $a[5] += 1900;
+ $a[4]++;
+ $a[4] = substr( "0$a[4]", -2 );
+ $a[3] = substr( "0$a[3]", -2 );
+ $shippingdate = "$a[5]$a[4]$a[3]";
+
+ my %total = ();
+
+ my $query = qq|
INSERT INTO inventory
(warehouse_id, parts_id, qty, shippingdate, employee_id)
VALUES (?, ?, ?, '$shippingdate', $form->{employee_id})|;
- $sth = $dbh->prepare($query) || $form->dberror($query);
-
- my $qty;
-
- for my $i (1 .. $form->{rowcount}) {
- $qty = $form->parse_amount($myconfig, $form->{"transfer_$i"});
-
- $qty = $form->{"qty_$i"} if ($qty > $form->{"qty_$i"});
-
- if ($qty > 0) {
- # to warehouse
- if ($form->{warehouse_id}) {
- $sth->execute($form->{warehouse_id},
- $form->{"id_$i"}, $qty,
- $shippingdate, $form->{employee_id})
- || $form->dberror;
- $sth->finish;
- }
-
- # from warehouse
- if ($form->{"warehouse_id_$i"}) {
- $sth->execute($form->{"warehouse_id_$i"},
- $form->{"id_$i"}, $qty * -1)
- || $form->dberror;
- $sth->finish;
- }
- }
- }
-
- my $rc = $dbh->commit;
- $dbh->commit;
-
- $rc;
+ $sth = $dbh->prepare($query) || $form->dberror($query);
-}
+ my $qty;
+
+ for my $i ( 1 .. $form->{rowcount} ) {
+ $qty = $form->parse_amount( $myconfig, $form->{"transfer_$i"} );
+ $qty = $form->{"qty_$i"} if ( $qty > $form->{"qty_$i"} );
+
+ if ( $qty > 0 ) {
+
+ # to warehouse
+ if ( $form->{warehouse_id} ) {
+ $sth->execute( $form->{warehouse_id}, $form->{"id_$i"}, $qty,
+ $shippingdate, $form->{employee_id} )
+ || $form->dberror;
+ $sth->finish;
+ }
+
+ # from warehouse
+ if ( $form->{"warehouse_id_$i"} ) {
+ $sth->execute( $form->{"warehouse_id_$i"},
+ $form->{"id_$i"}, $qty * -1 )
+ || $form->dberror;
+ $sth->finish;
+ }
+ }
+ }
+
+ my $rc = $dbh->commit;
+ $dbh->commit;
+
+ $rc;
+
+}
sub get_soparts {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my $id;
- my $ref;
-
- # store required items from selected sales orders
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my $id;
+ my $ref;
+
+ # store required items from selected sales orders
+ my $query = qq|
SELECT p.id, oi.qty - oi.ship AS required, p.assembly
FROM orderitems oi
JOIN parts p ON (p.id = oi.parts_id)
WHERE oi.trans_id = ?|;
- my $sth = $dbh->prepare($query) || $form->dberror($query);
-
- for (my $i = 1; $i <= $form->{rowcount}; $i++) {
+ my $sth = $dbh->prepare($query) || $form->dberror($query);
- if ($form->{"ndx_$i"}) {
+ for ( my $i = 1 ; $i <= $form->{rowcount} ; $i++ ) {
- $sth->execute($form->{"ndx_$i"});
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- &add_items_required(
- "", $dbh, $form, $ref->{id},
- $ref->{required}, $ref->{assembly});
- }
- $sth->finish;
- }
+ if ( $form->{"ndx_$i"} ) {
- }
+ $sth->execute( $form->{"ndx_$i"} );
- $query = qq|SELECT current_date|;
- ($form->{transdate}) = $dbh->selectrow_array($query);
-
- # foreign exchange rates
- &exchangerate_defaults($dbh, $form);
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ &add_items_required( "", $dbh, $form, $ref->{id},
+ $ref->{required}, $ref->{assembly} );
+ }
+ $sth->finish;
+ }
- $dbh->commit;
+ }
-}
+ $query = qq|SELECT current_date|;
+ ( $form->{transdate} ) = $dbh->selectrow_array($query);
+
+ # foreign exchange rates
+ &exchangerate_defaults( $dbh, $form );
+
+ $dbh->commit;
+}
sub add_items_required {
- my ($self, $dbh, $form, $parts_id, $required, $assembly) = @_;
-
- my $query;
- my $sth;
- my $ref;
-
- if ($assembly) {
- $query = qq|
+ my ( $self, $dbh, $form, $parts_id, $required, $assembly ) = @_;
+
+ my $query;
+ my $sth;
+ my $ref;
+
+ if ($assembly) {
+ $query = qq|
SELECT p.id, a.qty, p.assembly
FROM assembly a
JOIN parts p ON (p.id = a.parts_id)
WHERE a.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- &add_items_required(
- "", $dbh, $form, $ref->{id},
- $required * $ref->{qty}, $ref->{assembly});
- }
- $sth->finish;
-
- } else {
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ &add_items_required( "", $dbh, $form, $ref->{id},
+ $required * $ref->{qty},
+ $ref->{assembly} );
+ }
+ $sth->finish;
+
+ }
+ else {
+
+ $query = qq|
SELECT partnumber, description, lastcost
FROM parts
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($parts_id) || $form->dberror($query);
- $ref = $sth->fetchrow_hashref(NAME_lc);
- for (keys %$ref) {
- $form->{orderitems}{$parts_id}{$_} = $ref->{$_};
- }
- $sth->finish;
+ $sth = $dbh->prepare($query);
+ $sth->execute($parts_id) || $form->dberror($query);
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for ( keys %$ref ) {
+ $form->{orderitems}{$parts_id}{$_} = $ref->{$_};
+ }
+ $sth->finish;
- $form->{orderitems}{$parts_id}{required} += $required;
+ $form->{orderitems}{$parts_id}{required} += $required;
- $query = qq|
+ $query = qq|
SELECT pv.partnumber, pv.leadtime, pv.lastcost, pv.curr,
pv.vendor_id, v.name
FROM partsvendor pv
JOIN vendor v ON (v.id = pv.vendor_id)
WHERE pv.parts_id = ?|;
- $sth = $dbh->prepare($query) || $form->dberror($query);
+ $sth = $dbh->prepare($query) || $form->dberror($query);
- # get cost and vendor
- $sth->execute($parts_id);
+ # get cost and vendor
+ $sth->execute($parts_id);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- for (keys %$ref) {
- $form->{orderitems}{$parts_id}{partsvendor}
- {$ref->{vendor_id}}{$_} = $ref->{$_};
- }
- }
- $sth->finish;
-
- }
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ for ( keys %$ref ) {
+ $form->{orderitems}{$parts_id}{partsvendor}{ $ref->{vendor_id} }
+ {$_} = $ref->{$_};
+ }
+ }
+ $sth->finish;
-}
+ }
+}
sub generate_orders {
- my ($self, $myconfig, $form) = @_;
-
- my $i;
- my %a;
- my $query;
- my $sth;
-
- for ($i = 1; $i <= $form->{rowcount}; $i++) {
- for (qw(qty lastcost)) {
- $form->{"${_}_$i"} = $form->parse_amount(
- $myconfig, $form->{"${_}_$i"});
- }
-
- if ($form->{"qty_$i"}) {
- ($vendor, $vendor_id) =
- split /--/, $form->{"vendor_$i"};
- if ($vendor_id) {
- $a{$vendor_id}{$form->{"id_$i"}}{qty}
- += $form->{"qty_$i"};
- for (qw(curr lastcost)) {
- $a{$vendor_id}{$form->{"id_$i"}}{$_}
- = $form->{"${_}_$i"};
- }
- }
- }
- }
-
- # connect to database
- my $dbh = $form->{dbh};
-
- # foreign exchange rates
- &exchangerate_defaults($dbh, $form);
-
- my $amount;
- my $netamount;
- my $curr = "";
- my %tax;
- my $taxincluded = 0;
- my $vendor_id;
-
- my $description;
- my $unit;
-
- my $sellprice;
-
- foreach $vendor_id (keys %a) {
-
- %tax = ();
-
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $i;
+ my %a;
+ my $query;
+ my $sth;
+
+ for ( $i = 1 ; $i <= $form->{rowcount} ; $i++ ) {
+ for (qw(qty lastcost)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( $myconfig, $form->{"${_}_$i"} );
+ }
+
+ if ( $form->{"qty_$i"} ) {
+ ( $vendor, $vendor_id ) =
+ split /--/, $form->{"vendor_$i"};
+ if ($vendor_id) {
+ $a{$vendor_id}{ $form->{"id_$i"} }{qty} += $form->{"qty_$i"};
+ for (qw(curr lastcost)) {
+ $a{$vendor_id}{ $form->{"id_$i"} }{$_} = $form->{"${_}_$i"};
+ }
+ }
+ }
+ }
+
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ # foreign exchange rates
+ &exchangerate_defaults( $dbh, $form );
+
+ my $amount;
+ my $netamount;
+ my $curr = "";
+ my %tax;
+ my $taxincluded = 0;
+ my $vendor_id;
+
+ my $description;
+ my $unit;
+
+ my $sellprice;
+
+ foreach $vendor_id ( keys %a ) {
+
+ %tax = ();
+
+ $query = qq|
SELECT v.curr, v.taxincluded, t.rate, c.accno
FROM vendor v
LEFT JOIN vendortax vt ON (v.id = vt.vendor_id)
LEFT JOIN tax t ON (t.chart_id = vt.chart_id)
LEFT JOIN chart c ON (c.id = t.chart_id)
WHERE v.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($vendor_id) || $form->dberror($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $curr = $ref->{curr};
- $taxincluded = $ref->{taxincluded};
- $tax{$ref->{accno}} = $ref->{rate};
- }
- $sth->finish;
-
- $curr ||= $form->{defaultcurrency};
- $taxincluded *= 1;
-
- my $uid = localtime;
- $uid .= "$$";
-
- # TODO: Make this function insert as much as possible
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute($vendor_id) || $form->dberror($query);
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $curr = $ref->{curr};
+ $taxincluded = $ref->{taxincluded};
+ $tax{ $ref->{accno} } = $ref->{rate};
+ }
+ $sth->finish;
+
+ $curr ||= $form->{defaultcurrency};
+ $taxincluded *= 1;
+
+ my $uid = localtime;
+ $uid .= "$$";
+
+ # TODO: Make this function insert as much as possible
+ $query = qq|
INSERT INTO oe (ordnumber)
VALUES ('$uid')|;
- $dbh->do($query) || $form->dberror($query);
-
- $query = qq|SELECT id FROM oe WHERE ordnumber = '$uid'|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
- my ($id) = $sth->fetchrow_array;
- $sth->finish;
-
- $amount = 0;
- $netamount = 0;
-
- foreach my $parts_id (keys %{ $a{$vendor_id} }) {
-
- if (($form->{$curr}
- * $form->{$a{$vendor_id}{$parts_id}{curr}}) > 0) {
-
- $sellprice = $a{$vendor_id}{$parts_id}{lastcost}
- / $form->{$curr}
- * $form->{$a{$vendor_id}{$parts_id}
- {curr}};
- } else {
- $sellprice =
- $a{$vendor_id}{$parts_id}{lastcost};
- }
- $sellprice = $form->round_amount($sellprice, 2);
-
- my $linetotal = $form->round_amount(
- $sellprice * $a{$vendor_id}{$parts_id}{qty}, 2);
-
- $query = qq|
+ $dbh->do($query) || $form->dberror($query);
+
+ $query = qq|SELECT id FROM oe WHERE ordnumber = '$uid'|;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+ my ($id) = $sth->fetchrow_array;
+ $sth->finish;
+
+ $amount = 0;
+ $netamount = 0;
+
+ foreach my $parts_id ( keys %{ $a{$vendor_id} } ) {
+
+ if ( ( $form->{$curr} * $form->{ $a{$vendor_id}{$parts_id}{curr} } )
+ > 0 )
+ {
+
+ $sellprice =
+ $a{$vendor_id}{$parts_id}{lastcost} / $form->{$curr} *
+ $form->{ $a{$vendor_id}{$parts_id}{curr} };
+ }
+ else {
+ $sellprice = $a{$vendor_id}{$parts_id}{lastcost};
+ }
+ $sellprice = $form->round_amount( $sellprice, 2 );
+
+ my $linetotal =
+ $form->round_amount( $sellprice * $a{$vendor_id}{$parts_id}{qty},
+ 2 );
+
+ $query = qq|
SELECT p.description, p.unit, c.accno
FROM parts p
LEFT JOIN partstax pt ON (p.id = pt.parts_id)
LEFT JOIN chart c ON (c.id = pt.chart_id)
WHERE p.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($parts_id) || $form->dberror($query);
-
- my $rate = 0;
- my $taxes = '';
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $description = $ref->{description};
- $unit = $ref->{unit};
- $rate += $tax{$ref->{accno}};
- $taxes .= "$ref->{accno} ";
- }
- $sth->finish;
- chop $taxes;
- my @taxaccounts = Tax::init_taxes($form, $taxes);
-
- $netamount += $linetotal;
- if ($taxincluded) {
- $amount += $linetotal;
- } else {
- $amount += $form->round_amount(
- Tax::apply_taxes(\@taxaccounts, $form,
- $linetotal), 2);
- }
-
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute($parts_id) || $form->dberror($query);
+
+ my $rate = 0;
+ my $taxes = '';
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $description = $ref->{description};
+ $unit = $ref->{unit};
+ $rate += $tax{ $ref->{accno} };
+ $taxes .= "$ref->{accno} ";
+ }
+ $sth->finish;
+ chop $taxes;
+ my @taxaccounts = Tax::init_taxes( $form, $taxes );
+
+ $netamount += $linetotal;
+ if ($taxincluded) {
+ $amount += $linetotal;
+ }
+ else {
+ $amount +=
+ $form->round_amount(
+ Tax::apply_taxes( \@taxaccounts, $form, $linetotal ), 2 );
+ }
+
+ $query = qq|
INSERT INTO orderitems
(trans_id, parts_id, description,
qty, ship, sellprice, unit)
VALUES
(?, ?, ?, ?, 0, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $id, $parts_id, $description,
- $a{vendor_id}{parts_id}{qty}, $sellprice,
- $unit
- ) || $form->dberror($query);
-
- }
-
- my $ordnumber = $form->update_defaults($myconfig, 'ponumber');
-
- my $null;
- my $employee_id;
- my $department_id;
-
- ($null, $employee_id) = $form->get_employee($dbh);
- ($null, $department_id) = split /--/, $form->{department};
- $department_id *= 1;
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $id, $parts_id, $description,
+ $a{vendor_id}{parts_id}{qty},
+ $sellprice, $unit )
+ || $form->dberror($query);
+
+ }
+
+ my $ordnumber = $form->update_defaults( $myconfig, 'ponumber' );
+
+ my $null;
+ my $employee_id;
+ my $department_id;
+
+ ( $null, $employee_id ) = $form->get_employee($dbh);
+ ( $null, $department_id ) = split /--/, $form->{department};
+ $department_id *= 1;
+
+ $query = qq|
UPDATE oe SET
ordnumber = ?,
transdate = current_date,
@@ -2448,152 +2418,149 @@ sub generate_orders {
department_id = ?,
ponumber = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $ordnumber, $vendor_id, $amount, $netamount,
- $taxincluded, $curr, $employee_id,
- $department_id, $form->{ponumber}, $id
- ) || $form->dberror($query);
-
- }
-
- my $rc = $dbh->commit;
-
- $rc;
-
-}
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $ordnumber, $vendor_id, $amount,
+ $netamount, $taxincluded, $curr,
+ $employee_id, $department_id, $form->{ponumber},
+ $id
+ ) || $form->dberror($query);
+ }
+
+ my $rc = $dbh->commit;
+
+ $rc;
+
+}
sub consolidate_orders {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my $i;
- my $id;
- my $ref;
- my %oe = ();
-
- my $query = qq|SELECT * FROM oe WHERE id = ?|;
- my $sth = $dbh->prepare($query) || $form->dberror($query);
-
- for ($i = 1; $i <= $form->{rowcount}; $i++) {
- # retrieve order
- if ($form->{"ndx_$i"}) {
- $sth->execute($form->{"ndx_$i"});
-
- $ref = $sth->fetchrow_hashref(NAME_lc);
- $ref->{ndx} = $i;
- $oe{oe}{$ref->{curr}}{$ref->{id}} = $ref;
-
- $oe{vc}{$ref->{curr}}{$ref->{"$form->{vc}_id"}}++;
- $sth->finish;
- }
- }
-
- $query = qq|SELECT * FROM orderitems WHERE trans_id = ?|;
- $sth = $dbh->prepare($query) || $form->dberror($query);
-
- foreach $curr (keys %{ $oe{oe} }) {
-
- foreach $id (sort {
- $oe{oe}{$curr}{$a}->{ndx}
- <=> $oe{oe}{$curr}{$b}->{ndx} }
- keys %{ $oe{oe}{$curr} }) {
-
- # retrieve order
- $vc_id = $oe{oe}{$curr}{$id}->{"$form->{vc}_id"};
-
- if ($oe{vc}{$oe{oe}{$curr}{$id}->{curr}}{$vc_id} > 1) {
-
- push @{ $oe{orders}{$curr}{$vc_id} }, $id;
-
- $sth->execute($id);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $oe{orderitems}{$curr}{$id} },
- $ref;
- }
- $sth->finish;
-
- }
- }
- }
-
-
- my $ordnumber = $form->{ordnumber};
- my $numberfld = ($form->{vc} eq 'customer') ? 'sonumber' : 'ponumber';
-
- my ($department, $department_id) = $form->{department};
- $department_id *= 1;
-
- my $uid = localtime;
- $uid .= "$$";
-
- my @orderitems = ();
-
- foreach $curr (keys %{ $oe{orders} }) {
-
- foreach $vc_id (sort {
- $a <=> $b
- } keys %{ $oe{orders}{$curr} }) {
-
- # the orders
- @orderitems = ();
- $form->{customer_id} = $form->{vendor_id} = 0;
- $form->{"$form->{vc}_id"} = $vc_id;
- $amount = 0;
- $netamount = 0;
-
- foreach $id (@{ $oe{orders}{$curr}{$vc_id} }) {
-
- # header
- $ref = $oe{oe}{$curr}{$id};
-
- $amount += $ref->{amount};
- $netamount += $ref->{netamount};
-
- $id = $dbh->quore($id);
- foreach $item
- (@{ $oe{orderitems}{$curr}{$id} }) {
-
- push @orderitems, $item;
- }
-
- # close order
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my $i;
+ my $id;
+ my $ref;
+ my %oe = ();
+
+ my $query = qq|SELECT * FROM oe WHERE id = ?|;
+ my $sth = $dbh->prepare($query) || $form->dberror($query);
+
+ for ( $i = 1 ; $i <= $form->{rowcount} ; $i++ ) {
+
+ # retrieve order
+ if ( $form->{"ndx_$i"} ) {
+ $sth->execute( $form->{"ndx_$i"} );
+
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ $ref->{ndx} = $i;
+ $oe{oe}{ $ref->{curr} }{ $ref->{id} } = $ref;
+
+ $oe{vc}{ $ref->{curr} }{ $ref->{"$form->{vc}_id"} }++;
+ $sth->finish;
+ }
+ }
+
+ $query = qq|SELECT * FROM orderitems WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query) || $form->dberror($query);
+
+ foreach $curr ( keys %{ $oe{oe} } ) {
+
+ foreach $id (
+ sort { $oe{oe}{$curr}{$a}->{ndx} <=> $oe{oe}{$curr}{$b}->{ndx} }
+ keys %{ $oe{oe}{$curr} }
+ )
+ {
+
+ # retrieve order
+ $vc_id = $oe{oe}{$curr}{$id}->{"$form->{vc}_id"};
+
+ if ( $oe{vc}{ $oe{oe}{$curr}{$id}->{curr} }{$vc_id} > 1 ) {
+
+ push @{ $oe{orders}{$curr}{$vc_id} }, $id;
+
+ $sth->execute($id);
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $oe{orderitems}{$curr}{$id} }, $ref;
+ }
+ $sth->finish;
+
+ }
+ }
+ }
+
+ my $ordnumber = $form->{ordnumber};
+ my $numberfld = ( $form->{vc} eq 'customer' ) ? 'sonumber' : 'ponumber';
+
+ my ( $department, $department_id ) = $form->{department};
+ $department_id *= 1;
+
+ my $uid = localtime;
+ $uid .= "$$";
+
+ my @orderitems = ();
+
+ foreach $curr ( keys %{ $oe{orders} } ) {
+
+ foreach $vc_id ( sort { $a <=> $b } keys %{ $oe{orders}{$curr} } ) {
+
+ # the orders
+ @orderitems = ();
+ $form->{customer_id} = $form->{vendor_id} = 0;
+ $form->{"$form->{vc}_id"} = $vc_id;
+ $amount = 0;
+ $netamount = 0;
+
+ foreach $id ( @{ $oe{orders}{$curr}{$vc_id} } ) {
+
+ # header
+ $ref = $oe{oe}{$curr}{$id};
+
+ $amount += $ref->{amount};
+ $netamount += $ref->{netamount};
+
+ $id = $dbh->quore($id);
+ foreach $item ( @{ $oe{orderitems}{$curr}{$id} } ) {
+
+ push @orderitems, $item;
+ }
+
+ # close order
+ $query = qq|
UPDATE oe SET
closed = '1'
WHERE id = $id|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $form->dberror($query);
- # reset shipped
- $query = qq|
+ # reset shipped
+ $query = qq|
UPDATE orderitems SET
ship = 0
WHERE trans_id = $id|;
- $dbh->do($query) || $form->dberror($query);
- }
+ $dbh->do($query) || $form->dberror($query);
+ }
- $ordnumber ||= $form->update_defaults(
- $myconfig, $numberfld, $dbh);
+ $ordnumber ||=
+ $form->update_defaults( $myconfig, $numberfld, $dbh );
- #fixme: Change this
- $query = qq|
+ #fixme: Change this
+ $query = qq|
INSERT INTO oe (ordnumber) VALUES ('$uid')|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT id
FROM oe
WHERE ordnumber = '$uid'|;
- ($id) = $dbh->selectrow_array($query);
+ ($id) = $dbh->selectrow_array($query);
+
+ $ref->{employee_id} *= 1;
- $ref->{employee_id} *= 1;
-
- $query = qq|
+ $query = qq|
UPDATE oe SET
- ordnumber = |.$dbh->quote($ordnumber).qq|,
+ ordnumber = | . $dbh->quote($ordnumber) . qq|,
transdate = current_date,
vendor_id = ?,
customer_id = ?,
@@ -2611,24 +2578,28 @@ sub consolidate_orders {
ponumber = ?,
department_id = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute (
- $form->{vendor_id}, $form->{customer_id}, $amount, $netamount,
- $form->{reqdate}, $form->{taxincluded}, $form->{shippingpoint},
- $form->{notes}, $curr, $ref->{employee_id}, $form->{intnotes},
- $form->{shipvia}, $ref->{language_code}, $form->{po_number},
- $department_id, $id
- ) || $form->dberror($query);
-
-
- # add items
- foreach $item (@orderitems) {
- for (qw(
- qty sellprice discount project_id ship)
- ) {
- $item->{$_} *= 1;
- }
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{vendor_id}, $form->{customer_id},
+ $amount, $netamount,
+ $form->{reqdate}, $form->{taxincluded},
+ $form->{shippingpoint}, $form->{notes},
+ $curr, $ref->{employee_id},
+ $form->{intnotes}, $form->{shipvia},
+ $ref->{language_code}, $form->{po_number},
+ $department_id, $id
+ ) || $form->dberror($query);
+
+ # add items
+ foreach $item (@orderitems) {
+ for (
+ qw(
+ qty sellprice discount project_id ship)
+ )
+ {
+ $item->{$_} *= 1;
+ }
+ $query = qq|
INSERT INTO orderitems
(trans_id, parts_id, description,
qty, sellprice, discount, unit, reqdate,
@@ -2636,27 +2607,25 @@ sub consolidate_orders {
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $id, $item->{parts_id}, $item->{description},
- $item->{qty}, $item->{sellprice},
- $item->{discount}, $item->{unit},
- $form->{reqdate}, $item->{project_id},
- $item->{ship}, $item->{serialnumber},
- $item->{notes}
- ) || $form->dberror($query);
-
- }
- }
- }
-
-
- $rc = $dbh->commit;
-
- $rc;
-
-}
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $id, $item->{parts_id},
+ $item->{description}, $item->{qty},
+ $item->{sellprice}, $item->{discount},
+ $item->{unit}, $form->{reqdate},
+ $item->{project_id}, $item->{ship},
+ $item->{serialnumber}, $item->{notes}
+ ) || $form->dberror($query);
+
+ }
+ }
+ }
+
+ $rc = $dbh->commit;
+ $rc;
+
+}
1;
diff --git a/LedgerSMB/OP.pm b/LedgerSMB/OP.pm
index 13f9da01..3a07f036 100644
--- a/LedgerSMB/OP.pm
+++ b/LedgerSMB/OP.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -35,37 +35,36 @@
package OP;
sub overpayment {
- my ($self, $myconfig, $form, $dbh, $amount, $ml) = @_;
-
- my $fxamount = $form->round_amount($amount * $form->{exchangerate}, 2);
- my ($paymentaccno) = split /--/, $form->{account};
+ my ( $self, $myconfig, $form, $dbh, $amount, $ml ) = @_;
+
+ my $fxamount = $form->round_amount( $amount * $form->{exchangerate}, 2 );
+ my ($paymentaccno) = split /--/, $form->{account};
- my ($null, $department_id) = split /--/, $form->{department};
- $department_id *= 1;
+ my ( $null, $department_id ) = split /--/, $form->{department};
+ $department_id *= 1;
- my $uid = localtime;
- $uid .= "$$";
+ my $uid = localtime;
+ $uid .= "$$";
- # add AR/AP header transaction with a payment
- my $login = $dbh->quote($form->{login});
- $query = qq|
+ # add AR/AP header transaction with a payment
+ my $login = $dbh->quote( $form->{login} );
+ $query = qq|
INSERT INTO $form->{arap} (invnumber, employee_id)
VALUES ('$uid', (SELECT id FROM employee
WHERE login = $login))|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $form->dberror($query);
- $query = qq|SELECT id FROM $form->{arap} WHERE invnumber = '$uid'|;
- ($uid) = $dbh->selectrow_array($query);
+ $query = qq|SELECT id FROM $form->{arap} WHERE invnumber = '$uid'|;
+ ($uid) = $dbh->selectrow_array($query);
- my $invnumber = $form->{invnumber};
- $invnumber = $form->update_defaults(
- $myconfig,
- ($form->{arap} eq 'ar')
- ? "sinumber"
- : "vinumber",
- $dbh) unless $invnumber;
+ my $invnumber = $form->{invnumber};
+ $invnumber =
+ $form->update_defaults( $myconfig, ( $form->{arap} eq 'ar' )
+ ? "sinumber"
+ : "vinumber", $dbh )
+ unless $invnumber;
- $query = qq|
+ $query = qq|
UPDATE $form->{arap}
set invnumber = ?,
$form->{vc}_id = ?,
@@ -78,63 +77,64 @@ sub overpayment {
curr = ?,
department_id = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $invnumber, $form->{"$form->{vc}_id"}, $form->{datepaid},
- $form->{datepaid}, $form->{datepaid}, $fxamount,
- $form->{currency}, $department_id, $uid
- ) || $form->dberror($query);
-
- # add AR/AP
- ($accno) = split /--/, $form->{$form->{ARAP}};
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $invnumber, $form->{"$form->{vc}_id"},
+ $form->{datepaid}, $form->{datepaid},
+ $form->{datepaid}, $fxamount,
+ $form->{currency}, $department_id,
+ $uid
+ ) || $form->dberror($query);
+
+ # add AR/AP
+ ($accno) = split /--/, $form->{ $form->{ARAP} };
+
+ $query = qq|
INSERT INTO acc_trans (trans_id, chart_id, transdate, amount)
VALUES (?, (SELECT id FROM chart
WHERE accno = ?), ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute($uid, $accno, $form->{datepaid}, $fxamount * $ml)
- || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $uid, $accno, $form->{datepaid}, $fxamount * $ml )
+ || $form->dberror($query);
- # add payment
- $query = qq|
+ # add payment
+ $query = qq|
INSERT INTO acc_trans (trans_id, chart_id, transdate,
amount, source, memo)
VALUES (?, (SELECT id FROM chart WHERE accno = ?),
?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $uid, $paymentaccno, $form->{datepaid}, $amount * $ml * -1,
- $form->{source}, $form->{memo}
- )|| $form->dberror($query);
-
- # add exchangerate difference
- if ($fxamount != $amount) {
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $uid, $paymentaccno, $form->{datepaid}, $amount * $ml * -1,
+ $form->{source}, $form->{memo} )
+ || $form->dberror($query);
+
+ # add exchangerate difference
+ if ( $fxamount != $amount ) {
+ $query = qq|
INSERT INTO acc_trans (trans_id, chart_id, transdate,
amount, cleared, fx_transaction, source)
VALUES (?, (SELECT id FROM chart WHERE accno = ?),
?, ?, '1', '1', ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute($uid, $paymentaccno, $form->{datepaid},
- ($fxamount - $amount) * $ml * -1, $form->{source}
- ) || $form->dberror($query);
- }
-
- my %audittrail = (
- tablename => $form->{arap},
- reference => $invnumber,
- formname =>
- ($form->{arap} eq 'ar')
- ? 'deposit'
- : 'pre-payment',
- action => 'posted',
- id => $uid );
-
- $form->audittrail($dbh, "", \%audittrail);
-
-}
+ $sth = $dbh->prepare($query);
+ $sth->execute( $uid, $paymentaccno, $form->{datepaid},
+ ( $fxamount - $amount ) * $ml * -1,
+ $form->{source} )
+ || $form->dberror($query);
+ }
+
+ my %audittrail = (
+ tablename => $form->{arap},
+ reference => $invnumber,
+ formname => ( $form->{arap} eq 'ar' )
+ ? 'deposit'
+ : 'pre-payment',
+ action => 'posted',
+ id => $uid
+ );
+ $form->audittrail( $dbh, "", \%audittrail );
+
+}
1;
diff --git a/LedgerSMB/PE.pm b/LedgerSMB/PE.pm
index 099f94ce..209f6767 100644
--- a/LedgerSMB/PE.pm
+++ b/LedgerSMB/PE.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -34,61 +34,62 @@
package PE;
-
sub projects {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- $form->{sort} = "projectnumber" unless $form->{sort};
- my @a = ($form->{sort});
- my %ordinal = ( projectnumber => 2,
- description => 3,
- startdate => 4,
- enddate => 5,
- );
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
- my $query;
- my $where = "WHERE 1=1";
-
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ $form->{sort} = "projectnumber" unless $form->{sort};
+ my @a = ( $form->{sort} );
+ my %ordinal = (
+ projectnumber => 2,
+ description => 3,
+ startdate => 4,
+ enddate => 5,
+ );
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ my $query;
+ my $where = "WHERE 1=1";
+
+ $query = qq|
SELECT pr.*, c.name
FROM project pr
LEFT JOIN customer c ON (c.id = pr.customer_id)|;
- if ($form->{type} eq 'job') {
- $where .= qq| AND pr.id NOT IN (SELECT DISTINCT id
+ if ( $form->{type} eq 'job' ) {
+ $where .= qq| AND pr.id NOT IN (SELECT DISTINCT id
FROM parts
WHERE project_id > 0)|;
- }
-
- my $var;
- if ($form->{projectnumber} ne "") {
- $var = $dbh->quote($form->like(lc $form->{projectnumber}));
- $where .= " AND lower(pr.projectnumber) LIKE $var";
- }
- if ($form->{description} ne "") {
- $var = $dbh->quote($form->like(lc $form->{description}));
- $where .= " AND lower(pr.description) LIKE $var";
- }
-
- ($form->{startdatefrom}, $form->{startdateto})
- = $form->from_to(
- $form->{year}, $form->{month}, $form->{interval})
- if $form->{year} && $form->{month};
-
- if ($form->{startdatefrom}) {
- $where .= " AND (pr.startdate IS NULL OR pr.startdate >= ".
- $dbh->quote($form->{startdatefrom}).")";
- }
- if ($form->{startdateto}) {
- $where .= " AND (pr.startdate IS NULL OR pr.startdate <= ".
- $dbh->quote($form->{startdateto}).")";
- }
-
- if ($form->{status} eq 'orphaned') {
- $where .= qq| AND pr.id NOT IN (SELECT DISTINCT project_id
+ }
+
+ my $var;
+ if ( $form->{projectnumber} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{projectnumber} ) );
+ $where .= " AND lower(pr.projectnumber) LIKE $var";
+ }
+ if ( $form->{description} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{description} ) );
+ $where .= " AND lower(pr.description) LIKE $var";
+ }
+
+ ( $form->{startdatefrom}, $form->{startdateto} ) =
+ $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
+ if $form->{year} && $form->{month};
+
+ if ( $form->{startdatefrom} ) {
+ $where .=
+ " AND (pr.startdate IS NULL OR pr.startdate >= "
+ . $dbh->quote( $form->{startdatefrom} ) . ")";
+ }
+ if ( $form->{startdateto} ) {
+ $where .=
+ " AND (pr.startdate IS NULL OR pr.startdate <= "
+ . $dbh->quote( $form->{startdateto} ) . ")";
+ }
+
+ if ( $form->{status} eq 'orphaned' ) {
+ $where .= qq| AND pr.id NOT IN (SELECT DISTINCT project_id
FROM acc_trans
WHERE project_id > 0
UNION
@@ -105,66 +106,64 @@ sub projects {
WHERE project_id > 0)
|;
- }
- if ($form->{status} eq 'active') {
- $where .= qq|
+ }
+ if ( $form->{status} eq 'active' ) {
+ $where .= qq|
AND (pr.enddate IS NULL
OR pr.enddate >= current_date)|;
- }
- if ($form->{status} eq 'inactive') {
- $where .= qq| AND pr.enddate <= current_date|;
- }
+ }
+ if ( $form->{status} eq 'inactive' ) {
+ $where .= qq| AND pr.enddate <= current_date|;
+ }
- $query .= qq|
+ $query .= qq|
$where
ORDER BY $sortorder|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- my $i = 0;
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_project} }, $ref;
- $i++;
- }
+ my $i = 0;
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_project} }, $ref;
+ $i++;
+ }
- $sth->finish;
- $dbh->commit;
-
- $i;
+ $sth->finish;
+ $dbh->commit;
-}
+ $i;
+}
sub get_project {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
- my $dbh = $form->{dbh};
+ my $query;
+ my $sth;
+ my $ref;
+ my $where;
- my $query;
- my $sth;
- my $ref;
- my $where;
-
- if ($form->{id}) {
+ if ( $form->{id} ) {
-
- $query = qq|
+ $query = qq|
SELECT pr.*, c.name AS customer
FROM project pr
LEFT JOIN customer c ON (c.id = pr.customer_id)
WHERE pr.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $ref = $sth->fetchrow_hashref(NAME_lc);
-
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
+ $ref = $sth->fetchrow_hashref(NAME_lc);
- $sth->finish;
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
- # check if it is orphaned
- $query = qq|
+ $sth->finish;
+
+ # check if it is orphaned
+ $query = qq|
SELECT count(*)
FROM acc_trans
WHERE project_id = ?
@@ -180,176 +179,170 @@ sub get_project {
SELECT count(*)
FROM jcitems
WHERE project_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $form->{id}, $form->{id}, $form->{id}
- )|| $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $form->{id}, $form->{id}, $form->{id} )
+ || $form->dberror($query);
- my $count;
- while (($count) = $sth->fetchrow_array) {
- $form->{orphaned} += $count;
- }
- $sth->finish;
- $form->{orphaned} = !$form->{orphaned};
- }
+ my $count;
+ while ( ($count) = $sth->fetchrow_array ) {
+ $form->{orphaned} += $count;
+ }
+ $sth->finish;
+ $form->{orphaned} = !$form->{orphaned};
+ }
- PE->get_customer($myconfig, $form, $dbh);
+ PE->get_customer( $myconfig, $form, $dbh );
- $form->run_custom_queries('project', 'SELECT');
+ $form->run_custom_queries( 'project', 'SELECT' );
- $dbh->commit;
+ $dbh->commit;
}
-
sub save_project {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- $form->{customer_id} ||= undef;
-
- $form->{projectnumber}
- = $form->update_defaults($myconfig, "projectnumber", $dbh)
- unless $form->{projectnumber};
- my $enddate;
- my $startdate;
- $enddate = $form->{enddate} if $form->{enddate};
- $startdate = $form->{startdate} if $form->{startdate};
-
- if ($form->{id}) {
-
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ $form->{customer_id} ||= undef;
+
+ $form->{projectnumber} =
+ $form->update_defaults( $myconfig, "projectnumber", $dbh )
+ unless $form->{projectnumber};
+ my $enddate;
+ my $startdate;
+ $enddate = $form->{enddate} if $form->{enddate};
+ $startdate = $form->{startdate} if $form->{startdate};
+
+ if ( $form->{id} ) {
+
+ $query = qq|
UPDATE project
SET projectnumber = ?,
description = ?,
startdate = ?,
enddate = ?,
customer_id = ?
- WHERE id = |.$dbh->quote($form->{id});
- } else {
-
- $query = qq|
+ WHERE id = | . $dbh->quote( $form->{id} );
+ }
+ else {
+
+ $query = qq|
INSERT INTO project (projectnumber, description,
startdate, enddate, customer_id)
VALUES (?, ?, ?, ?, ?)|;
- }
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{projectnumber}, $form->{description},
- $startdate, $enddate, $form->{customer_id}
- ) || $form->dberror($query);
- $form->run_custom_queries('project', 'UPDATE');
-
- $dbh->commit;
+ }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{projectnumber},
+ $form->{description}, $startdate, $enddate, $form->{customer_id} )
+ || $form->dberror($query);
+ $form->run_custom_queries( 'project', 'UPDATE' );
-}
+ $dbh->commit;
+}
sub list_stock {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
- my $var;
- my $where = "1 = 1";
+ my $var;
+ my $where = "1 = 1";
- if ($form->{status} eq 'active') {
- $where = qq|
+ if ( $form->{status} eq 'active' ) {
+ $where = qq|
(pr.enddate IS NULL OR pr.enddate >= current_date)
AND pr.completed < pr.production|;
- }
- if ($form->{status} eq 'inactive') {
- $where = qq|pr.completed = pr.production|;
- }
-
- if ($form->{projectnumber}) {
- $var = $dbh->quote($form->like(lc $form->{projectnumber}));
- $where .= " AND lower(pr.projectnumber) LIKE $var";
- }
-
- if ($form->{description}) {
- $var = $dbh->quote($form->like(lc $form->{description}));
- $where .= " AND lower(pr.description) LIKE $var";
- }
-
- $form->{sort} = "projectnumber" unless $form->{sort};
- my @a = ($form->{sort});
- my %ordinal = ( projectnumber => 2, description => 3 );
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
- my $query = qq|
+ }
+ if ( $form->{status} eq 'inactive' ) {
+ $where = qq|pr.completed = pr.production|;
+ }
+
+ if ( $form->{projectnumber} ) {
+ $var = $dbh->quote( $form->like( lc $form->{projectnumber} ) );
+ $where .= " AND lower(pr.projectnumber) LIKE $var";
+ }
+
+ if ( $form->{description} ) {
+ $var = $dbh->quote( $form->like( lc $form->{description} ) );
+ $where .= " AND lower(pr.description) LIKE $var";
+ }
+
+ $form->{sort} = "projectnumber" unless $form->{sort};
+ my @a = ( $form->{sort} );
+ my %ordinal = ( projectnumber => 2, description => 3 );
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ my $query = qq|
SELECT pr.*, p.partnumber
FROM project pr
JOIN parts p ON (p.id = pr.parts_id)
WHERE $where
ORDER BY $sortorder|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_project} }, $ref;
- }
- $sth->finish;
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_project} }, $ref;
+ }
+ $sth->finish;
- $query = qq|SELECT current_date|;
- ($form->{stockingdate}) = $dbh->selectrow_array($query)
- if !$form->{stockingdate};
-
- $dbh->commit;
-
-}
+ $query = qq|SELECT current_date|;
+ ( $form->{stockingdate} ) = $dbh->selectrow_array($query)
+ if !$form->{stockingdate};
+ $dbh->commit;
+
+}
sub jobs {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- $form->{sort} = "projectnumber" unless $form->{sort};
- my @a = ($form->{sort});
- my %ordinal = (projectnumber => 2, description => 3, startdate => 4);
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ $form->{sort} = "projectnumber" unless $form->{sort};
+ my @a = ( $form->{sort} );
+ my %ordinal = ( projectnumber => 2, description => 3, startdate => 4 );
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ my $query = qq|
SELECT pr.*, p.partnumber, p.onhand, c.name
FROM project pr
JOIN parts p ON (p.id = pr.parts_id)
LEFT JOIN customer c ON (c.id = pr.customer_id)
WHERE 1=1|;
- if ($form->{projectnumber} ne "") {
- $var = $dbh->quote($form->like(lc $form->{projectnumber}));
- $query .= " AND lower(pr.projectnumber) LIKE $var";
- }
- if ($form->{description} ne "") {
- $var = $dbh->quote($form->like(lc $form->{description}));
- $query .= " AND lower(pr.description) LIKE $var";
- }
-
- ($form->{startdatefrom}, $form->{startdateto})
- = $form->from_to($form->{year}, $form->{month},
- $form->{interval})
- if $form->{year} && $form->{month};
-
- if ($form->{startdatefrom}) {
- $query .= " AND pr.startdate >= ".
- $dbh->quote($form->{startdatefrom});
- }
- if ($form->{startdateto}) {
- $query .= " AND pr.startdate <= ".
- $dbh->quote($form->{startdateto});
- }
-
- if ($form->{status} eq 'active') {
- $query .= qq| AND NOT pr.production = pr.completed|;
- }
- if ($form->{status} eq 'inactive') {
- $query .= qq| AND pr.production = pr.completed|;
- }
- if ($form->{status} eq 'orphaned') {
- $query .= qq|
+ if ( $form->{projectnumber} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{projectnumber} ) );
+ $query .= " AND lower(pr.projectnumber) LIKE $var";
+ }
+ if ( $form->{description} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{description} ) );
+ $query .= " AND lower(pr.description) LIKE $var";
+ }
+
+ ( $form->{startdatefrom}, $form->{startdateto} ) =
+ $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
+ if $form->{year} && $form->{month};
+
+ if ( $form->{startdatefrom} ) {
+ $query .=
+ " AND pr.startdate >= " . $dbh->quote( $form->{startdatefrom} );
+ }
+ if ( $form->{startdateto} ) {
+ $query .= " AND pr.startdate <= " . $dbh->quote( $form->{startdateto} );
+ }
+
+ if ( $form->{status} eq 'active' ) {
+ $query .= qq| AND NOT pr.production = pr.completed|;
+ }
+ if ( $form->{status} eq 'inactive' ) {
+ $query .= qq| AND pr.production = pr.completed|;
+ }
+ if ( $form->{status} eq 'orphaned' ) {
+ $query .= qq|
AND pr.completed = 0
AND (pr.id NOT IN
(SELECT DISTINCT project_id
@@ -364,42 +357,41 @@ sub jobs {
FROM jcitems
WHERE project_id > 0)
)|;
- }
+ }
- $query .= qq|
+ $query .= qq|
ORDER BY $sortorder|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_project} }, $ref;
- }
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_project} }, $ref;
+ }
- $sth->finish;
-
- $dbh->commit;
-
-}
+ $sth->finish;
+ $dbh->commit;
+
+}
sub get_job {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- # connect to database
- my $dbh = $form->{dbh};
+ # connect to database
+ my $dbh = $form->{dbh};
- my $query;
- my $sth;
- my $ref;
+ my $query;
+ my $sth;
+ my $ref;
- if ($form->{id}) {
- $query = qq|
+ if ( $form->{id} ) {
+ $query = qq|
SELECT value FROM defaults
WHERE setting_key = 'weightunit'|;
- ($form->{weightunit}) = $dbh->selectrow_array($query);
+ ( $form->{weightunit} ) = $dbh->selectrow_array($query);
- $query = qq|
+ $query = qq|
SELECT pr.*, p.partnumber,
p.description AS partdescription, p.unit,
p.listprice, p.sellprice, p.priceupdate,
@@ -413,25 +405,27 @@ sub get_job {
LEFT JOIN chart ch ON (ch.id = p.income_accno_id)
LEFT JOIN customer c ON (c.id = pr.customer_id)
LEFT JOIN partsgroup pg ON (pg.id = p.partsgroup_id)
- WHERE pr.id = |.$dbh->quote($form->{id});
- } else {
- $query = qq|
+ WHERE pr.id = | . $dbh->quote( $form->{id} );
+ }
+ else {
+ $query = qq|
SELECT value, current_date AS startdate FROM defaults
WHERE setting_key = 'weightunit'|;
- }
+ }
+
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ $ref = $sth->fetchrow_hashref(NAME_lc);
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
- $ref = $sth->fetchrow_hashref(NAME_lc);
-
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
+ $sth->finish;
- $sth->finish;
+ if ( $form->{id} ) {
- if ($form->{id}) {
- # check if it is orphaned
- $query = qq|
+ # check if it is orphaned
+ $query = qq|
SELECT count(*)
FROM invoice
WHERE project_id = ?
@@ -443,165 +437,167 @@ sub get_job {
SELECT count(*)
FROM jcitems
WHERE project_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{id}, $form->{id}, $form->{id}
- )|| $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id}, $form->{id}, $form->{id} )
+ || $form->dberror($query);
- my $count;
+ my $count;
- my $count;
- while (($count) = $sth->fetchrow_array) {
- $form->{orphaned} += $count;
- }
- $sth->finish;
+ my $count;
+ while ( ($count) = $sth->fetchrow_array ) {
+ $form->{orphaned} += $count;
+ }
+ $sth->finish;
- }
+ }
- $form->{orphaned} = !$form->{orphaned};
-
- $query = qq|
+ $form->{orphaned} = !$form->{orphaned};
+
+ $query = qq|
SELECT accno, description, link
FROM chart
WHERE link LIKE ?
ORDER BY accno|;
- $sth = $dbh->prepare($query);
- $sth->execute('%IC%') || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- for (split /:/, $ref->{link}) {
- if (/IC/) {
- push @{ $form->{IC_links}{$_} },
- { accno => $ref->{accno},
- description => $ref->{description} };
- }
- }
- }
- $sth->finish;
-
- if ($form->{id}) {
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute('%IC%') || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ for ( split /:/, $ref->{link} ) {
+ if (/IC/) {
+ push @{ $form->{IC_links}{$_} },
+ {
+ accno => $ref->{accno},
+ description => $ref->{description}
+ };
+ }
+ }
+ }
+ $sth->finish;
+
+ if ( $form->{id} ) {
+ $query = qq|
SELECT ch.accno
FROM parts p
JOIN partstax pt ON (pt.parts_id = p.id)
JOIN chart ch ON (pt.chart_id = ch.id)
WHERE p.id = ?|;
-
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $form->{amount}{$ref->{accno}} = $ref->{accno};
- }
- $sth->finish;
- }
-
- PE->get_customer($myconfig, $form, $dbh);
-
- $dbh->commit;
-}
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $form->{amount}{ $ref->{accno} } = $ref->{accno};
+ }
+ $sth->finish;
+ }
+
+ PE->get_customer( $myconfig, $form, $dbh );
+
+ $dbh->commit;
+
+}
sub get_customer {
- my ($self, $myconfig, $form, $dbh) = @_;
-
- if (! $dbh) {
- $dbh = $form->{dbh};
- }
-
- my $query;
- my $sth;
- my $ref;
-
- if (! $form->{startdate}) {
- $query = qq|SELECT current_date|;
- ($form->{startdate}) = $dbh->selectrow_array($query);
- }
-
- my $where = qq|(startdate >= |.$dbh->quote($form->{startdate}).
- qq| OR startdate IS NULL OR enddate IS NULL)|;
-
- if ($form->{enddate}) {
- $where .= qq| AND (enddate >= |.$dbh->quote($form->{enddate}).
- qq| OR enddate IS NULL)|;
- } else {
- $where .=
- qq| AND (enddate >= current_date OR enddate IS NULL)|;
- }
-
- $query = qq|
+ my ( $self, $myconfig, $form, $dbh ) = @_;
+
+ if ( !$dbh ) {
+ $dbh = $form->{dbh};
+ }
+
+ my $query;
+ my $sth;
+ my $ref;
+
+ if ( !$form->{startdate} ) {
+ $query = qq|SELECT current_date|;
+ ( $form->{startdate} ) = $dbh->selectrow_array($query);
+ }
+
+ my $where =
+ qq|(startdate >= |
+ . $dbh->quote( $form->{startdate} )
+ . qq| OR startdate IS NULL OR enddate IS NULL)|;
+
+ if ( $form->{enddate} ) {
+ $where .=
+ qq| AND (enddate >= |
+ . $dbh->quote( $form->{enddate} )
+ . qq| OR enddate IS NULL)|;
+ }
+ else {
+ $where .= qq| AND (enddate >= current_date OR enddate IS NULL)|;
+ }
+
+ $query = qq|
SELECT count(*)
FROM customer
WHERE $where|;
- my ($count) = $dbh->selectrow_array($query);
+ my ($count) = $dbh->selectrow_array($query);
- if ($count < $myconfig->{vclimit}) {
- $query = qq|
+ if ( $count < $myconfig->{vclimit} ) {
+ $query = qq|
SELECT id, name
FROM customer
WHERE $where|;
- if ($form->{customer_id}) {
- $query .= qq|
+ if ( $form->{customer_id} ) {
+ $query .= qq|
UNION
SELECT id,name
FROM customer
- WHERE id = |.
- $dbh->quote($form->{customer_id});
- }
+ WHERE id = | . $dbh->quote( $form->{customer_id} );
+ }
- $query .= qq|
+ $query .= qq|
ORDER BY name|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- @{ $form->{all_customer} } = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_customer} }, $ref;
- }
- $sth->finish;
- }
+ @{ $form->{all_customer} } = ();
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_customer} }, $ref;
+ }
+ $sth->finish;
+ }
}
-
sub save_job {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my ($income_accno) = split /--/, $form->{IC_income};
-
- my ($partsgroup, $partsgroup_id) = split /--/, $form->{partsgroup};
-
- if ($form->{id}) {
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my ($income_accno) = split /--/, $form->{IC_income};
+
+ my ( $partsgroup, $partsgroup_id ) = split /--/, $form->{partsgroup};
+
+ if ( $form->{id} ) {
+ $query = qq|
SELECT id FROM project
- WHERE id = |.$dbh->quote($form->{id});
- ($form->{id}) = $dbh->selectrow_array($query);
- }
-
- if (!$form->{id}) {
- my $uid = localtime;
- $uid .= "$$";
-
- $query = qq|
+ WHERE id = | . $dbh->quote( $form->{id} );
+ ( $form->{id} ) = $dbh->selectrow_array($query);
+ }
+
+ if ( !$form->{id} ) {
+ my $uid = localtime;
+ $uid .= "$$";
+
+ $query = qq|
INSERT INTO project (projectnumber)
VALUES ('$uid')|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT id FROM project
WHERE projectnumber = '$uid'|;
- ($form->{id}) = $dbh->selectrow_array($query);
- }
+ ( $form->{id} ) = $dbh->selectrow_array($query);
+ }
- $form->{projectnumber}
- = $form->update_defaults($myconfig, "projectnumber", $dbh)
- unless $form->{projectnumber};
+ $form->{projectnumber} =
+ $form->update_defaults( $myconfig, "projectnumber", $dbh )
+ unless $form->{projectnumber};
- $query = qq|
+ $query = qq|
UPDATE project
SET projectnumber = ?,
description = ?,
@@ -611,31 +607,30 @@ sub save_job {
production = ?,
customer_id = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $form->{projectnumber}, $form->{description},
- $form->{startdate}, $form->{enddate}, $form->{id},
- $form->{production}, $form->{customer_id}, $form->{id}
- ) || $form->dberror($query);
-
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $form->{projectnumber}, $form->{description}, $form->{startdate},
+ $form->{enddate}, $form->{id}, $form->{production},
+ $form->{customer_id}, $form->{id}
+ ) || $form->dberror($query);
+
+ #### add/edit assembly
+ $query = qq|SELECT id FROM parts WHERE id = | . $dbh->quote( $form->{id} );
+ my ($id) = $dbh->selectrow_array($query);
+
+ if ( !$id ) {
+ $query = qq|
+ INSERT INTO parts (id)
+ VALUES (| . $dbh->quote( $form->{id} ) . qq|)|;
+ $dbh->do($query) || $form->dberror($query);
+ }
- #### add/edit assembly
- $query = qq|SELECT id FROM parts WHERE id = |.$dbh->quote($form->{id});
- my ($id) = $dbh->selectrow_array($query);
+ my $partnumber =
+ ( $form->{partnumber} )
+ ? $form->{partnumber}
+ : $form->{projectnumber};
- if (!$id) {
- $query = qq|
- INSERT INTO parts (id)
- VALUES (|.$dbh->quote($form->{id}).qq|)|;
- $dbh->do($query) || $form->dberror($query);
- }
-
- my $partnumber =
- ($form->{partnumber})
- ? $form->{partnumber}
- : $form->{projectnumber};
-
- $query = qq|
+ $query = qq|
UPDATE parts
SET partnumber = ?,
description = ?,
@@ -654,155 +649,155 @@ sub save_job {
project_id = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $partnumber, $form->{partdescription},
- $form->{priceupdate},
- $form->parse_amount($myconfig, $form->{listprice}),
- $form->parse_amount($myconfig, $form->{sellprice}),
- $form->parse_amount($myconfig, $form->{weight}),
- $form->{bin}, $form->{unit}, $form->{notes},
- $income_accno,
- ($partsgroup_id) ? $partsgroup_id : undef,
- $form->{id}, $form->{id}
- ) || $form->dberror($query);
-
- $query = qq|DELETE FROM partstax WHERE parts_id = |.
- $dbh->qupte($form->{id});
- $dbh->do($query) || $form->dberror($query);
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $partnumber,
+ $form->{partdescription},
+ $form->{priceupdate},
+ $form->parse_amount( $myconfig, $form->{listprice} ),
+ $form->parse_amount( $myconfig, $form->{sellprice} ),
+ $form->parse_amount( $myconfig, $form->{weight} ),
+ $form->{bin},
+ $form->{unit},
+ $form->{notes},
+ $income_accno,
+ ($partsgroup_id) ? $partsgroup_id : undef,
+ $form->{id},
+ $form->{id}
+ ) || $form->dberror($query);
+
+ $query =
+ qq|DELETE FROM partstax WHERE parts_id = | . $dbh->qupte( $form->{id} );
+ $dbh->do($query) || $form->dberror($query);
+
+ $query = qq|
INSERT INTO partstax (parts_id, chart_id)
VALUES (?, (SELECT id FROM chart WHERE accno = ?))|;
- $sth = $dbh->prepare($query);
- for (split / /, $form->{taxaccounts}) {
- if ($form->{"IC_tax_$_"}) {
- $sth->execute($form->{id}, $_)
- || $form->dberror($query);
- }
- }
-
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ for ( split / /, $form->{taxaccounts} ) {
+ if ( $form->{"IC_tax_$_"} ) {
+ $sth->execute( $form->{id}, $_ )
+ || $form->dberror($query);
+ }
+ }
-}
+ $dbh->commit;
+}
sub stock_assembly {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my $ref;
-
- my $query = qq|SELECT * FROM project WHERE id = ?|;
- my $sth = $dbh->prepare($query) || $form->dberror($query);
-
- $query = qq|SELECT COUNT(*) FROM parts WHERE project_id = ?|;
- my $rvh = $dbh->prepare($query) || $form->dberror($query);
-
- if (! $form->{stockingdate}) {
- $query = qq|SELECT current_date|;
- ($form->{stockingdate}) = $dbh->selectrow_array($query);
- }
-
- $query = qq|SELECT * FROM parts WHERE id = ?|;
- my $pth = $dbh->prepare($query) || $form->dberror($query);
-
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my $ref;
+
+ my $query = qq|SELECT * FROM project WHERE id = ?|;
+ my $sth = $dbh->prepare($query) || $form->dberror($query);
+
+ $query = qq|SELECT COUNT(*) FROM parts WHERE project_id = ?|;
+ my $rvh = $dbh->prepare($query) || $form->dberror($query);
+
+ if ( !$form->{stockingdate} ) {
+ $query = qq|SELECT current_date|;
+ ( $form->{stockingdate} ) = $dbh->selectrow_array($query);
+ }
+
+ $query = qq|SELECT * FROM parts WHERE id = ?|;
+ my $pth = $dbh->prepare($query) || $form->dberror($query);
+
+ $query = qq|
SELECT j.*, p.lastcost FROM jcitems j
JOIN parts p ON (p.id = j.parts_id)
WHERE j.project_id = ?
- AND j.checkedin <= |.
- $dbh->quote($form->{stockingdate}).qq|
+ AND j.checkedin <= | . $dbh->quote( $form->{stockingdate} ) . qq|
ORDER BY parts_id|;
- my $jth = $dbh->prepare($query) || $form->dberror($query);
+ my $jth = $dbh->prepare($query) || $form->dberror($query);
- $query = qq|
+ $query = qq|
INSERT INTO assembly (id, parts_id, qty, bom, adj)
VALUES (?, ?, ?, '0', '0')|;
- my $ath = $dbh->prepare($query) || $form->dberror($query);
-
- my $i = 0;
- my $sold;
- my $ship;
-
- while (1) {
- $i++;
- last unless $form->{"id_$i"};
-
- $stock = $form->parse_amount($myconfig, $form->{"stock_$i"});
-
- if ($stock) {
- $sth->execute($form->{"id_$i"});
- $ref = $sth->fetchrow_hashref(NAME_lc);
-
- if ($stock >($ref->{production} - $ref->{completed})) {
- $stock = $ref->{production}
- - $ref->{completed};
- }
- if (($stock * -1) > $ref->{completed}) {
- $stock = $ref->{completed} * -1;
- }
-
- $pth->execute($form->{"id_$i"});
- $pref = $pth->fetchrow_hashref(NAME_lc);
-
- my %assembly = ();
- my $lastcost = 0;
- my $sellprice = 0;
- my $listprice = 0;
-
- $jth->execute($form->{"id_$i"});
- while ($jref = $jth->fetchrow_hashref(NAME_lc)) {
- $assembly{qty}{$jref->{parts_id}}
- += ($jref->{qty} - $jref->{allocated});
- $assembly{parts_id}{$jref->{parts_id}}
- = $jref->{parts_id};
- $assembly{jcitems}{$jref->{id}} = $jref->{id};
- $lastcost += $form->round_amount(
- $jref->{lastcost} * ($jref->{qty}
- - $jref->{allocated}),
- 2);
- $sellprice += $form->round_amount(
- $jref->{sellprice} * ($jref->{qty}
- - $jref->{allocated}),
- 2);
- $listprice += $form->round_amount(
- $jref->{listprice} * ($jref->{qty}
- - $jref->{allocated}),
- 2);
- }
- $jth->finish;
-
- $uid = localtime;
- $uid .= "$$";
-
- $query = qq|
+ my $ath = $dbh->prepare($query) || $form->dberror($query);
+
+ my $i = 0;
+ my $sold;
+ my $ship;
+
+ while (1) {
+ $i++;
+ last unless $form->{"id_$i"};
+
+ $stock = $form->parse_amount( $myconfig, $form->{"stock_$i"} );
+
+ if ($stock) {
+ $sth->execute( $form->{"id_$i"} );
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+
+ if ( $stock > ( $ref->{production} - $ref->{completed} ) ) {
+ $stock = $ref->{production} - $ref->{completed};
+ }
+ if ( ( $stock * -1 ) > $ref->{completed} ) {
+ $stock = $ref->{completed} * -1;
+ }
+
+ $pth->execute( $form->{"id_$i"} );
+ $pref = $pth->fetchrow_hashref(NAME_lc);
+
+ my %assembly = ();
+ my $lastcost = 0;
+ my $sellprice = 0;
+ my $listprice = 0;
+
+ $jth->execute( $form->{"id_$i"} );
+ while ( $jref = $jth->fetchrow_hashref(NAME_lc) ) {
+ $assembly{qty}{ $jref->{parts_id} } +=
+ ( $jref->{qty} - $jref->{allocated} );
+ $assembly{parts_id}{ $jref->{parts_id} } = $jref->{parts_id};
+ $assembly{jcitems}{ $jref->{id} } = $jref->{id};
+ $lastcost +=
+ $form->round_amount(
+ $jref->{lastcost} * ( $jref->{qty} - $jref->{allocated} ),
+ 2 );
+ $sellprice += $form->round_amount(
+ $jref->{sellprice} * ( $jref->{qty} - $jref->{allocated} ),
+ 2
+ );
+ $listprice += $form->round_amount(
+ $jref->{listprice} * ( $jref->{qty} - $jref->{allocated} ),
+ 2
+ );
+ }
+ $jth->finish;
+
+ $uid = localtime;
+ $uid .= "$$";
+
+ $query = qq|
INSERT INTO parts (partnumber)
VALUES ('$uid')|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $form->dberror($query);
- $query = qq|
+ $query = qq|
SELECT id
FROM parts
WHERE partnumber = '$uid'|;
- ($uid) = $dbh->selectrow_array($query);
-
- $lastcost = $form->round_amount($lastcost / $stock, 2);
- $sellprice =
- ($pref->{sellprice})
- ? $pref->{sellprice}
- : $form->round_amount($sellprice / $stock, 2);
- $listprice =
- ($pref->{listprice})
- ? $pref->{listprice}
- : $form->round_amount($listprice / $stock, 2);
-
- $rvh->execute($form->{"id_$i"});
- my ($rev) = $rvh->fetchrow_array;
- $rvh->finish;
-
- $query = qq|
+ ($uid) = $dbh->selectrow_array($query);
+
+ $lastcost = $form->round_amount( $lastcost / $stock, 2 );
+ $sellprice =
+ ( $pref->{sellprice} )
+ ? $pref->{sellprice}
+ : $form->round_amount( $sellprice / $stock, 2 );
+ $listprice =
+ ( $pref->{listprice} )
+ ? $pref->{listprice}
+ : $form->round_amount( $listprice / $stock, 2 );
+
+ $rvh->execute( $form->{"id_$i"} );
+ my ($rev) = $rvh->fetchrow_array;
+ $rvh->finish;
+
+ $query = qq|
UPDATE parts
SET partnumber = ?,
description = ?,
@@ -819,188 +814,181 @@ sub stock_assembly {
bin = ?,
project_id = ?
WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- "$pref->{partnumber}-$rev",
- $pref->{partdescription},
- $form->{stockingdate}, $pref->{unit},
- $listprice, $sellprice, $lastcost,
- $pref->{weight}, $stock, $pref->{notes},
- $pref->{income_accno_id}, $pref->{bin},
- $form->{"id_$i"}, $uid
- )|| $form->dberror($query);
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ "$pref->{partnumber}-$rev", $pref->{partdescription},
+ $form->{stockingdate}, $pref->{unit},
+ $listprice, $sellprice,
+ $lastcost, $pref->{weight},
+ $stock, $pref->{notes},
+ $pref->{income_accno_id}, $pref->{bin},
+ $form->{"id_$i"}, $uid
+ ) || $form->dberror($query);
+
+ $query = qq|
INSERT INTO partstax (parts_id, chart_id)
SELECT ?, chart_id FROM partstax
WHERE parts_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($uid, $pref->{id})
- || $form->dberror($query);
-
-
- $pth->finish;
-
- for (keys %{$assembly{parts_id}}) {
- if ($assembly{qty}{$_}) {
- $ath->execute(
- $uid, $assembly{parts_id}{$_},
- $form->round_amount(
- $assembly{qty}{$_}
- / $stock,
- 4));
- $ath->finish;
- }
- }
-
- $form->update_balance(
- $dbh, "project", "completed",
- qq|id = $form->{"id_$i"}|, $stock);
-
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $uid, $pref->{id} )
+ || $form->dberror($query);
+
+ $pth->finish;
+
+ for ( keys %{ $assembly{parts_id} } ) {
+ if ( $assembly{qty}{$_} ) {
+ $ath->execute(
+ $uid,
+ $assembly{parts_id}{$_},
+ $form->round_amount( $assembly{qty}{$_} / $stock, 4 )
+ );
+ $ath->finish;
+ }
+ }
+
+ $form->update_balance( $dbh, "project", "completed",
+ qq|id = $form->{"id_$i"}|, $stock );
+
+ $query = qq|
UPDATE jcitems
SET allocated = qty
WHERE allocated != qty
AND checkedin <= ?
AND project_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{stockingdate}, $form->{"id_$i"})
- || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{stockingdate}, $form->{"id_$i"} )
+ || $form->dberror($query);
- $sth->finish;
-
- }
+ $sth->finish;
- }
+ }
- my $rc = $dbh->commit;
-
- $rc;
+ }
-}
+ my $rc = $dbh->commit;
+ $rc;
+
+}
sub delete_project {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- $query = qq|DELETE FROM project WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $query = qq|DELETE FROM translation
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ $query = qq|DELETE FROM project WHERE id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $query = qq|DELETE FROM translation
WHERE trans_id = $form->{id}|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- my $rc = $dbh->commit;
+ my $rc = $dbh->commit;
- $rc;
-
-}
+ $rc;
+}
sub delete_partsgroup {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- $query = qq|DELETE FROM partsgroup WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $query = qq|DELETE FROM translation WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- my $rc = $dbh->commit;
-
- $rc;
-
-}
+ my ( $self, $myconfig, $form ) = @_;
+ my $dbh = $form->{dbh};
-sub delete_pricegroup {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- $query = qq|DELETE FROM pricegroup WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- my $rc = $dbh->commit;
-
- $rc;
+ $query = qq|DELETE FROM partsgroup WHERE id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $query = qq|DELETE FROM translation WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ my $rc = $dbh->commit;
+
+ $rc;
}
+sub delete_pricegroup {
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ $query = qq|DELETE FROM pricegroup WHERE id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ my $rc = $dbh->commit;
+
+ $rc;
+
+}
sub delete_job {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my %audittrail = (
- tablename => 'project',
- reference => $form->{id},
- formname => $form->{type},
- action => 'deleted',
- id => $form->{id} );
-
- $form->audittrail($dbh, "", \%audittrail);
-
- my $query = qq|DELETE FROM project WHERE id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $query = qq|DELETE FROM translation WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- # delete all the assemblies
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my %audittrail = (
+ tablename => 'project',
+ reference => $form->{id},
+ formname => $form->{type},
+ action => 'deleted',
+ id => $form->{id}
+ );
+
+ $form->audittrail( $dbh, "", \%audittrail );
+
+ my $query = qq|DELETE FROM project WHERE id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $query = qq|DELETE FROM translation WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ # delete all the assemblies
+ $query = qq|
DELETE FROM assembly a
JOIN parts p ON (a.id = p.id)
WHERE p.project_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
-
- $query = qq|DELETE FROM parts WHERE project_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- my $rc = $dbh->commit;
+ $query = qq|DELETE FROM parts WHERE project_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $rc;
+ my $rc = $dbh->commit;
-}
+ $rc;
+}
sub partsgroups {
- my ($self, $myconfig, $form) = @_;
-
- my $var;
-
- my $dbh = $form->{dbh};
-
- $form->{sort} = "partsgroup" unless $form->{partsgroup};
- my @a = (partsgroup);
- my $sortorder = $form->sort_order(\@a);
-
- my $query = qq|SELECT g.* FROM partsgroup g|;
-
- my $where = "1 = 1";
-
- if ($form->{partsgroup} ne "") {
- $var = $dbh->quote($form->like(lc $form->{partsgroup}));
- $where .= " AND lower(partsgroup) LIKE '$var'";
- }
- $query .= qq| WHERE $where ORDER BY $sortorder|;
-
- if ($form->{status} eq 'orphaned') {
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $var;
+
+ my $dbh = $form->{dbh};
+
+ $form->{sort} = "partsgroup" unless $form->{partsgroup};
+ my @a = (partsgroup);
+ my $sortorder = $form->sort_order( \@a );
+
+ my $query = qq|SELECT g.* FROM partsgroup g|;
+
+ my $where = "1 = 1";
+
+ if ( $form->{partsgroup} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{partsgroup} ) );
+ $where .= " AND lower(partsgroup) LIKE '$var'";
+ }
+ $query .= qq| WHERE $where ORDER BY $sortorder|;
+
+ if ( $form->{status} eq 'orphaned' ) {
+ $query = qq|
SELECT g.*
FROM partsgroup g
LEFT JOIN parts p ON (p.partsgroup_id = g.id)
@@ -1011,101 +999,98 @@ sub partsgroups {
JOIN parts p ON (p.partsgroup_id = g.id)
WHERE $where
ORDER BY $sortorder|;
- }
+ }
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- my $i = 0;
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{item_list} }, $ref;
- $i++;
- }
+ my $i = 0;
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{item_list} }, $ref;
+ $i++;
+ }
- $sth->finish;
-
- $i;
+ $sth->finish;
-}
+ $i;
+}
sub save_partsgroup {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- if ($form->{id}) {
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ if ( $form->{id} ) {
+ $query = qq|
UPDATE partsgroup
- SET partsgroup = |.
- $dbh->quote($form->{partsgroup}).qq|
+ SET partsgroup = | . $dbh->quote( $form->{partsgroup} ) . qq|
WHERE id = $form->{id}|;
- } else {
- $query = qq|
+ }
+ else {
+ $query = qq|
INSERT INTO partsgroup (partsgroup)
- VALUES (|.$dbh->quote($form->{partsgroup}).qq|)|;
- }
- $dbh->do($query) || $form->dberror($query);
+ VALUES (| . $dbh->quote( $form->{partsgroup} ) . qq|)|;
+ }
+ $dbh->do($query) || $form->dberror($query);
- $dbh->commit;
+ $dbh->commit;
}
-
sub get_partsgroup {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
-
- my $query = qq|SELECT * FROM partsgroup WHERE id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ my $dbh = $form->{dbh};
- my $ref = $sth->fetchrow_hashref(NAME_lc);
-
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
+ my $query = qq|SELECT * FROM partsgroup WHERE id = ?|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $sth->finish;
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
- # check if it is orphaned
- $query = qq|SELECT count(*) FROM parts WHERE partsgroup_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
- ($form->{orphaned}) = $sth->fetchrow_array;
- $form->{orphaned} = !$form->{orphaned};
-
- $sth->finish;
-
- $dbh->commit;
+ $sth->finish;
-}
+ # check if it is orphaned
+ $query = qq|SELECT count(*) FROM parts WHERE partsgroup_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+ ( $form->{orphaned} ) = $sth->fetchrow_array;
+ $form->{orphaned} = !$form->{orphaned};
+
+ $sth->finish;
+
+ $dbh->commit;
+
+}
sub pricegroups {
- my ($self, $myconfig, $form) = @_;
-
- my $var;
-
- my $dbh = $form->{dbh};
-
- $form->{sort} = "pricegroup" unless $form->{sort};
- my @a = (pricegroup);
- my $sortorder = $form->sort_order(\@a);
-
- my $query = qq|SELECT g.* FROM pricegroup g|;
-
- my $where = "1 = 1";
-
- if ($form->{pricegroup} ne "") {
- $var = $dbh->quote($form->like(lc $form->{pricegroup}));
- $where .= " AND lower(pricegroup) LIKE $var";
- }
- $query .= qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $var;
+
+ my $dbh = $form->{dbh};
+
+ $form->{sort} = "pricegroup" unless $form->{sort};
+ my @a = (pricegroup);
+ my $sortorder = $form->sort_order( \@a );
+
+ my $query = qq|SELECT g.* FROM pricegroup g|;
+
+ my $where = "1 = 1";
+
+ if ( $form->{pricegroup} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{pricegroup} ) );
+ $where .= " AND lower(pricegroup) LIKE $var";
+ }
+ $query .= qq|
WHERE $where ORDER BY $sortorder|;
-
- if ($form->{status} eq 'orphaned') {
- $query = qq|
+
+ if ( $form->{status} eq 'orphaned' ) {
+ $query = qq|
SELECT g.*
FROM pricegroup g
WHERE $where
@@ -1113,396 +1098,387 @@ sub pricegroups {
FROM partscustomer
WHERE pricegroup_id > 0)
ORDER BY $sortorder|;
- }
+ }
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- my $i = 0;
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{item_list} }, $ref;
- $i++;
- }
+ my $i = 0;
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{item_list} }, $ref;
+ $i++;
+ }
- $sth->finish;
- $dbh->commit;
-
- $i;
+ $sth->finish;
+ $dbh->commit;
-}
+ $i;
+}
sub save_pricegroup {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- if ($form->{id}) {
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ if ( $form->{id} ) {
+ $query = qq|
UPDATE pricegroup SET
pricegroup = ?
- WHERE id = |.$dbh->quote($form->{id});
- } else {
- $query = qq|
+ WHERE id = | . $dbh->quote( $form->{id} );
+ }
+ else {
+ $query = qq|
INSERT INTO pricegroup (pricegroup)
VALUES (?)|;
- }
- $sth = $dbh->prepare($query);
- $sth->execute($form->{pricegroup}) || $form->dberror($query);
-
- $dbh->commit;
+ }
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{pricegroup} ) || $form->dberror($query);
-}
+ $dbh->commit;
+}
sub get_pricegroup {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
-
- my $query = qq|SELECT * FROM pricegroup WHERE id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ my $dbh = $form->{dbh};
- my $ref = $sth->fetchrow_hashref(NAME_lc);
-
- for (keys %$ref) { $form->{$_} = $ref->{$_} }
+ my $query = qq|SELECT * FROM pricegroup WHERE id = ?|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $sth->finish;
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
- # check if it is orphaned
- $query = "SELECT count(*) FROM partscustomer WHERE pricegroup_id = ?";
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query);
+ for ( keys %$ref ) { $form->{$_} = $ref->{$_} }
- ($form->{orphaned}) = $sth->fetchrow_array;
- $form->{orphaned} = !$form->{orphaned};
+ $sth->finish;
- $sth->finish;
-
- $dbh->commit;
+ # check if it is orphaned
+ $query = "SELECT count(*) FROM partscustomer WHERE pricegroup_id = ?";
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
-}
+ ( $form->{orphaned} ) = $sth->fetchrow_array;
+ $form->{orphaned} = !$form->{orphaned};
+
+ $sth->finish;
+ $dbh->commit;
+
+}
sub description_translations {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
- my $where = "1 = 1";
- my $var;
- my $ref;
-
- for (qw(partnumber description)) {
- if ($form->{$_}) {
- $var = $dbh->quote($form->like(lc $form->{$_}));
- $where .= " AND lower(p.$_) LIKE $var";
- }
- }
-
- $where .= " AND p.obsolete = '0'";
- $where .= " AND p.id = ".$dbh->quote($form->{id}) if $form->{id};
-
-
- my %ordinal = ( 'partnumber' => 2, 'description' => 3 );
-
- my @a = qw(partnumber description);
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+ my $where = "1 = 1";
+ my $var;
+ my $ref;
+
+ for (qw(partnumber description)) {
+ if ( $form->{$_} ) {
+ $var = $dbh->quote( $form->like( lc $form->{$_} ) );
+ $where .= " AND lower(p.$_) LIKE $var";
+ }
+ }
+
+ $where .= " AND p.obsolete = '0'";
+ $where .= " AND p.id = " . $dbh->quote( $form->{id} ) if $form->{id};
+
+ my %ordinal = ( 'partnumber' => 2, 'description' => 3 );
+
+ my @a = qw(partnumber description);
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ my $query = qq|
SELECT l.description AS language,
t.description AS translation, l.code
FROM translation t
JOIN language l ON (l.code = t.language_code)
WHERE trans_id = ?
ORDER BY 1|;
- my $tth = $dbh->prepare($query);
-
- $query = qq|
+ my $tth = $dbh->prepare($query);
+
+ $query = qq|
SELECT p.id, p.partnumber, p.description
FROM parts p
WHERE $where
ORDER BY $sortorder|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- my $tra;
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{translations} }, $ref;
+ my $tra;
- # get translations for description
- $tth->execute($ref->{id}) || $form->dberror;
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{translations} }, $ref;
- while ($tra = $tth->fetchrow_hashref(NAME_lc)) {
- $form->{trans_id} = $ref->{id};
- $tra->{id} = $ref->{id};
- push @{ $form->{translations} }, $tra;
- }
- $tth->finish;
+ # get translations for description
+ $tth->execute( $ref->{id} ) || $form->dberror;
- }
- $sth->finish;
+ while ( $tra = $tth->fetchrow_hashref(NAME_lc) ) {
+ $form->{trans_id} = $ref->{id};
+ $tra->{id} = $ref->{id};
+ push @{ $form->{translations} }, $tra;
+ }
+ $tth->finish;
- &get_language("", $dbh, $form) if $form->{id};
+ }
+ $sth->finish;
- $dbh->commit;
+ &get_language( "", $dbh, $form ) if $form->{id};
-}
+ $dbh->commit;
+}
sub partsgroup_translations {
- my ($self, $myconfig, $form) = @_;
- my $dbh = $form->{dbh};
+ my ( $self, $myconfig, $form ) = @_;
+ my $dbh = $form->{dbh};
- my $where = "1 = 1";
- my $ref;
- my $var;
+ my $where = "1 = 1";
+ my $ref;
+ my $var;
- if ($form->{description}) {
- $var = $dbh->quote($form->like(lc $form->{description}));
- $where .= " AND lower(p.partsgroup) LIKE $var";
- }
- $where .= " AND p.id = ".$dbh->quote($form->{id}) if $form->{id};
-
+ if ( $form->{description} ) {
+ $var = $dbh->quote( $form->like( lc $form->{description} ) );
+ $where .= " AND lower(p.partsgroup) LIKE $var";
+ }
+ $where .= " AND p.id = " . $dbh->quote( $form->{id} ) if $form->{id};
- my $query = qq|
+ my $query = qq|
SELECT l.description AS language,
t.description AS translation, l.code
FROM translation t
JOIN language l ON (l.code = t.language_code)
WHERE trans_id = ?
ORDER BY 1|;
- my $tth = $dbh->prepare($query);
-
- $form->sort_order();
-
- $query = qq|
+ my $tth = $dbh->prepare($query);
+
+ $form->sort_order();
+
+ $query = qq|
SELECT p.id, p.partsgroup AS description
FROM partsgroup p
WHERE $where
ORDER BY 2 $form->{direction}|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- my $tra;
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{translations} }, $ref;
+ my $tra;
- # get translations for partsgroup
- $tth->execute($ref->{id}) || $form->dberror;
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{translations} }, $ref;
- while ($tra = $tth->fetchrow_hashref(NAME_lc)) {
- $form->{trans_id} = $ref->{id};
- push @{ $form->{translations} }, $tra;
- }
- $tth->finish;
+ # get translations for partsgroup
+ $tth->execute( $ref->{id} ) || $form->dberror;
- }
- $sth->finish;
+ while ( $tra = $tth->fetchrow_hashref(NAME_lc) ) {
+ $form->{trans_id} = $ref->{id};
+ push @{ $form->{translations} }, $tra;
+ }
+ $tth->finish;
- &get_language("", $dbh, $form) if $form->{id};
+ }
+ $sth->finish;
- $dbh->commit;
+ &get_language( "", $dbh, $form ) if $form->{id};
-}
+ $dbh->commit;
+}
sub project_translations {
- my ($self, $myconfig, $form) = @_;
- my $dbh = $form->{dbh};
-
- my $where = "1 = 1";
- my $var;
- my $ref;
-
- for (qw(projectnumber description)) {
- if ($form->{$_}) {
- $var = $dbh->quote($form->like(lc $form->{$_}));
- $where .= " AND lower(p.$_) LIKE $var";
- }
- }
-
- $where .= " AND p.id = ".$dbh->quote($form->{id}) if $form->{id};
-
-
- my %ordinal = ( 'projectnumber' => 2, 'description' => 3 );
-
- my @a = qw(projectnumber description);
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+ my $dbh = $form->{dbh};
+
+ my $where = "1 = 1";
+ my $var;
+ my $ref;
+
+ for (qw(projectnumber description)) {
+ if ( $form->{$_} ) {
+ $var = $dbh->quote( $form->like( lc $form->{$_} ) );
+ $where .= " AND lower(p.$_) LIKE $var";
+ }
+ }
+
+ $where .= " AND p.id = " . $dbh->quote( $form->{id} ) if $form->{id};
+
+ my %ordinal = ( 'projectnumber' => 2, 'description' => 3 );
+
+ my @a = qw(projectnumber description);
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ my $query = qq|
SELECT l.description AS language,
t.description AS translation, l.code
FROM translation t
JOIN language l ON (l.code = t.language_code)
WHERE trans_id = ?
ORDER BY 1|;
- my $tth = $dbh->prepare($query);
-
- $query = qq|
+ my $tth = $dbh->prepare($query);
+
+ $query = qq|
SELECT p.id, p.projectnumber, p.description
FROM project p
WHERE $where
ORDER BY $sortorder|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- my $tra;
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{translations} }, $ref;
+ my $tra;
- # get translations for description
- $tth->execute($ref->{id}) || $form->dberror;
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{translations} }, $ref;
- while ($tra = $tth->fetchrow_hashref(NAME_lc)) {
- $form->{trans_id} = $ref->{id};
- $tra->{id} = $ref->{id};
- push @{ $form->{translations} }, $tra;
- }
- $tth->finish;
+ # get translations for description
+ $tth->execute( $ref->{id} ) || $form->dberror;
- }
- $sth->finish;
+ while ( $tra = $tth->fetchrow_hashref(NAME_lc) ) {
+ $form->{trans_id} = $ref->{id};
+ $tra->{id} = $ref->{id};
+ push @{ $form->{translations} }, $tra;
+ }
+ $tth->finish;
- &get_language("", $dbh, $form) if $form->{id};
+ }
+ $sth->finish;
- $dbh->commit;
+ &get_language( "", $dbh, $form ) if $form->{id};
-}
+ $dbh->commit;
+}
sub get_language {
- my ($self, $dbh, $form) = @_;
-
- my $query = qq|SELECT * FROM language ORDER BY 2|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my ( $self, $dbh, $form ) = @_;
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_language} }, $ref;
- }
- $sth->finish;
+ my $query = qq|SELECT * FROM language ORDER BY 2|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
-}
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_language} }, $ref;
+ }
+ $sth->finish;
+}
sub save_translation {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
+ my $dbh = $form->{dbh};
- my $query = qq|DELETE FROM translation WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id})|| $form->dberror($query);
+ my $query = qq|DELETE FROM translation WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
- $query = qq|
+ $query = qq|
INSERT INTO translation (trans_id, language_code, description)
VALUES (?, ?, ?)|;
- my $sth = $dbh->prepare($query) || $form->dberror($query);
-
- foreach my $i (1 .. $form->{translation_rows}) {
- if ($form->{"language_code_$i"} ne "") {
- $sth->execute($form->{id}, $form->{"language_code_$i"},
- $form->{"translation_$i"});
- $sth->finish;
- }
- }
- $dbh->commit;
+ my $sth = $dbh->prepare($query) || $form->dberror($query);
+
+ foreach my $i ( 1 .. $form->{translation_rows} ) {
+ if ( $form->{"language_code_$i"} ne "" ) {
+ $sth->execute(
+ $form->{id},
+ $form->{"language_code_$i"},
+ $form->{"translation_$i"}
+ );
+ $sth->finish;
+ }
+ }
+ $dbh->commit;
}
-
sub delete_translation {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my $query = qq|DELETE FROM translation WHERE trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id})|| $form->dberror($query);
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
- $dbh->commit;
+ my $query = qq|DELETE FROM translation WHERE trans_id = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{id} ) || $form->dberror($query);
+
+ $dbh->commit;
}
sub timecard_get_currency {
- my $self = shift @_;
- my $form = shift @_;
- my $dbh = $form->{dbh};
- my $query = qq|SELECT curr FROM customer WHERE id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{customer_id});
- my ($curr) = $sth->fetchrow_array;
- $form->{currency} = $curr;
+ my $self = shift @_;
+ my $form = shift @_;
+ my $dbh = $form->{dbh};
+ my $query = qq|SELECT curr FROM customer WHERE id = ?|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{customer_id} );
+ my ($curr) = $sth->fetchrow_array;
+ $form->{currency} = $curr;
}
-
sub project_sales_order {
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->{dbh};
-
- my $query = qq|SELECT current_date|;
- my ($transdate) = $dbh->selectrow_array($query);
-
- $form->all_years($myconfig, $dbh);
-
- $form->all_projects($myconfig, $dbh, $transdate);
-
- $form->all_employees($myconfig, $dbh, $transdate);
-
- $dbh->commit;
+ my ( $self, $myconfig, $form ) = @_;
-}
+ # connect to database
+ my $dbh = $form->{dbh};
+
+ my $query = qq|SELECT current_date|;
+ my ($transdate) = $dbh->selectrow_array($query);
+
+ $form->all_years( $myconfig, $dbh );
+ $form->all_projects( $myconfig, $dbh, $transdate );
+
+ $form->all_employees( $myconfig, $dbh, $transdate );
+
+ $dbh->commit;
+
+}
sub get_jcitems {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my $null;
- my $var;
- my $where;
-
- if ($form->{projectnumber}) {
- ($null, $var) = split /--/, $form->{projectnumber};
- $var = $dbh->quote($var);
- $where .= " AND j.project_id = $var";
- }
-
- if ($form->{employee}) {
- ($null, $var) = split /--/, $form->{employee};
- $var = $dbh->quote($var);
- $where .= " AND j.employee_id = $var";
- }
-
- ($form->{transdatefrom}, $form->{transdateto})
- = $form->from_to(
- $form->{year}, $form->{month}, $form->{interval})
- if $form->{year} && $form->{month};
-
- if ($form->{transdatefrom}) {
- $where .= " AND j.checkedin >= ".
- $dbh->quote($form->{transdatefrom});
- }
- if ($form->{transdateto}) {
- $where .= " AND j.checkedout <= (date ".
- $dbh->quote($form->{transdateto}) .
- " + interval '1 days')";
- }
-
- my $query;
- my $ref;
-
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my $null;
+ my $var;
+ my $where;
+
+ if ( $form->{projectnumber} ) {
+ ( $null, $var ) = split /--/, $form->{projectnumber};
+ $var = $dbh->quote($var);
+ $where .= " AND j.project_id = $var";
+ }
+
+ if ( $form->{employee} ) {
+ ( $null, $var ) = split /--/, $form->{employee};
+ $var = $dbh->quote($var);
+ $where .= " AND j.employee_id = $var";
+ }
+
+ ( $form->{transdatefrom}, $form->{transdateto} ) =
+ $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
+ if $form->{year} && $form->{month};
+
+ if ( $form->{transdatefrom} ) {
+ $where .=
+ " AND j.checkedin >= " . $dbh->quote( $form->{transdatefrom} );
+ }
+ if ( $form->{transdateto} ) {
+ $where .=
+ " AND j.checkedout <= (date "
+ . $dbh->quote( $form->{transdateto} )
+ . " + interval '1 days')";
+ }
+
+ my $query;
+ my $ref;
+
+ $query = qq|
SELECT j.id, j.description, j.qty - j.allocated AS qty,
j.sellprice, j.parts_id, pr.$form->{vc}_id,
j.project_id, j.checkedin::date AS transdate,
@@ -1517,83 +1493,80 @@ sub get_jcitems {
AND j.allocated != j.qty $where
ORDER BY pr.projectnumber, c.name, j.checkedin::date|;
- if ($form->{summary}) {
- $query =~ s/j\.description/p\.description/;
- $query =~ s/c\.name,/c\.name, j\.parts_id, /;
- }
-
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ if ( $form->{summary} ) {
+ $query =~ s/j\.description/p\.description/;
+ $query =~ s/c\.name,/c\.name, j\.parts_id, /;
+ }
+
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- # tax accounts
- $query = qq|
+ # tax accounts
+ $query = qq|
SELECT c.accno
FROM chart c
JOIN partstax pt ON (pt.chart_id = c.id)
WHERE pt.parts_id = ?|;
- my $tth = $dbh->prepare($query) || $form->dberror($query);
- my $ptref;
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- $tth->execute($ref->{parts_id});
- $ref->{taxaccounts} = "";
- while ($ptref = $tth->fetchrow_hashref(NAME_lc)) {
- $ref->{taxaccounts} .= "$ptref->{accno} ";
- }
- $tth->finish;
- chop $ref->{taxaccounts};
-
- $ref->{amount} = $ref->{sellprice} * $ref->{qty};
-
- push @{ $form->{jcitems} }, $ref;
- }
-
- $sth->finish;
-
- $query = qq|SELECT value FROM defaults WHERE setting_key = 'curr'|;
- ($form->{currency}) = $dbh->selectrow_array($query);
- $form->{currency} =~ s/:.*//;
- $form->{defaultcurrency} = $form->{currency};
-
- $query = qq|
+ my $tth = $dbh->prepare($query) || $form->dberror($query);
+ my $ptref;
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ $tth->execute( $ref->{parts_id} );
+ $ref->{taxaccounts} = "";
+ while ( $ptref = $tth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{taxaccounts} .= "$ptref->{accno} ";
+ }
+ $tth->finish;
+ chop $ref->{taxaccounts};
+
+ $ref->{amount} = $ref->{sellprice} * $ref->{qty};
+
+ push @{ $form->{jcitems} }, $ref;
+ }
+
+ $sth->finish;
+
+ $query = qq|SELECT value FROM defaults WHERE setting_key = 'curr'|;
+ ( $form->{currency} ) = $dbh->selectrow_array($query);
+ $form->{currency} =~ s/:.*//;
+ $form->{defaultcurrency} = $form->{currency};
+
+ $query = qq|
SELECT c.accno, t.rate
FROM tax t
JOIN chart c ON (c.id = t.chart_id)|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $form->{taxaccounts} .= "$ref->{accno} ";
- $form->{"$ref->{accno}_rate"} = $ref->{rate};
- }
- chop $form->{taxaccounts};
- $sth->finish;
-
- $dbh->commit;
-
-}
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $form->{taxaccounts} .= "$ref->{accno} ";
+ $form->{"$ref->{accno}_rate"} = $ref->{rate};
+ }
+ chop $form->{taxaccounts};
+ $sth->finish;
+ $dbh->commit;
-sub allocate_projectitems {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- for my $i (1 .. $form->{rowcount}) {
- for (split / /, $form->{"jcitems_$i"}) {
- my ($id, $qty) = split /:/, $_;
- $form->update_balance(
- $dbh, 'jcitems', 'allocated', "id = $id",
- $qty);
- }
- }
-
- $rc = $dbh->commit;
-
- $rc;
-
}
+sub allocate_projectitems {
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ for my $i ( 1 .. $form->{rowcount} ) {
+ for ( split / /, $form->{"jcitems_$i"} ) {
+ my ( $id, $qty ) = split /:/, $_;
+ $form->update_balance( $dbh, 'jcitems', 'allocated', "id = $id",
+ $qty );
+ }
+ }
+
+ $rc = $dbh->commit;
+
+ $rc;
+
+}
1;
diff --git a/LedgerSMB/PriceMatrix.pm b/LedgerSMB/PriceMatrix.pm
index c604e982..68fa5b12 100644
--- a/LedgerSMB/PriceMatrix.pm
+++ b/LedgerSMB/PriceMatrix.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -14,7 +14,7 @@
# maintainers, and copyright holders, see the CONTRIBUTORS file.
#
# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
-# Copyright (C) 2001
+# Copyright (C) 2001
#
# Author: DWS Systems Inc.
# Web: http://www.sql-ledger.org
@@ -23,30 +23,29 @@
#
#======================================================================
#
-# This file has undergone whitespace cleanup
-#
+# This file has undergone whitespace cleanup
+#
#======================================================================
#
# Price Matrix module
-#
+#
#
#======================================================================
package PriceMatrix;
sub price_matrix_query {
- my ($dbh, $form) = @_;
+ my ( $dbh, $form ) = @_;
- my $query;
- my $sth;
+ my $query;
+ my $sth;
- my @queryargs;
+ my @queryargs;
- if ($form->{customer_id}) {
- my $defaultcurrency = $form->{dbh}->quote(
- $form->{defaultcurrency});
- my $customer_id = $form->{dbh}->quote($form->{customer_id});
- $query = qq|
+ if ( $form->{customer_id} ) {
+ my $defaultcurrency = $form->{dbh}->quote( $form->{defaultcurrency} );
+ my $customer_id = $form->{dbh}->quote( $form->{customer_id} );
+ $query = qq|
SELECT p.id AS parts_id, 0 AS customer_id,
0 AS pricegroup_id, 0 AS pricebreak,
p.sellprice, NULL AS validfrom, NULL AS validto,
@@ -91,122 +90,129 @@ sub price_matrix_query {
ORDER BY customer_id DESC, pricegroup_id DESC,
pricebreak
|;
- $sth = $dbh->prepare($query) || $form->dberror($query);
- } elsif ($form->{vendor_id}) {
- my $vendor_id = $form->{dbh}->quote($form->{vendor_id});
- # price matrix and vendor's partnumber
- $query = qq|
+ $sth = $dbh->prepare($query) || $form->dberror($query);
+ }
+ elsif ( $form->{vendor_id} ) {
+ my $vendor_id = $form->{dbh}->quote( $form->{vendor_id} );
+
+ # price matrix and vendor's partnumber
+ $query = qq|
SELECT partnumber
FROM partsvendor
WHERE parts_id = ?
AND vendor_id = $vendor_id|;
- $sth = $dbh->prepare($query) || $form->dberror($query);
- }
-
- $sth;
-}
+ $sth = $dbh->prepare($query) || $form->dberror($query);
+ }
+ $sth;
+}
sub price_matrix {
- my ($pmh, $ref, $transdate, $decimalplaces, $form, $myconfig) = @_;
- $ref->{pricematrix} = "";
- my $customerprice;
- my $pricegroupprice;
- my $sellprice;
- my $mref;
- my %p = ();
-
- # depends if this is a customer or vendor
- if ($form->{customer_id}) {
- $pmh->execute($ref->{id}, $ref->{id}, $ref->{id}, $ref->{id});
-
- while ($mref = $pmh->fetchrow_hashref(NAME_lc)) {
-
- # check date
- if ($mref->{validfrom}) {
- next if $transdate < $form->datetonum(
- $myconfig, $mref->{validfrom});
- }
- if ($mref->{validto}) {
- next if $transdate > $form->datetonum(
- $myconfig, $mref->{validto});
- }
-
- # convert price
- $sellprice = $form->round_amount($mref->{sellprice}
- * $form->{$mref->{curr}}, $decimalplaces);
-
- if ($mref->{customer_id}) {
- $ref->{sellprice} = $sellprice
- if !$mref->{pricebreak};
- $p{$mref->{pricebreak}} = $sellprice;
- $customerprice = 1;
- }
-
- if ($mref->{pricegroup_id}) {
- if (! $customerprice) {
- $ref->{sellprice} = $sellprice
- if !$mref->{pricebreak};
- $p{$mref->{pricebreak}} = $sellprice;
- }
- $pricegroupprice = 1;
- }
-
- if (!$customerprice && !$pricegroupprice) {
- $p{$mref->{pricebreak}} = $sellprice;
- }
-
- }
- $pmh->finish;
-
- if (%p) {
- if ($ref->{sellprice}) {
- $p{0} = $ref->{sellprice};
- }
- for (sort { $a <=> $b } keys %p) {
- $ref->{pricematrix} .= "${_}:$p{$_} ";
- }
- } else {
- if ($init) {
- $ref->{sellprice} = $form->round_amount(
- $ref->{sellprice}, $decimalplaces);
- } else {
- $ref->{sellprice} = $form->round_amount(
- $ref->{sellprice} *
- (1 - $form->{tradediscount}),
- $decimalplaces);
- }
- $ref->{pricematrix} = "0:$ref->{sellprice} "
- if $ref->{sellprice};
- }
- chop $ref->{pricematrix};
-
- }
-
-
- if ($form->{vendor_id}) {
- $pmh->execute($ref->{id});
-
- $mref = $pmh->fetchrow_hashref(NAME_lc);
-
- if ($mref->{partnumber} ne "") {
- $ref->{partnumber} = $mref->{partnumber};
- }
-
- if ($mref->{lastcost}) {
- # do a conversion
- $ref->{sellprice} = $form->round_amount(
- $mref->{lastcost} * $form->{$mref->{curr}},
- $decimalplaces);
- }
- $pmh->finish;
-
- $ref->{sellprice} *= 1;
-
- # add 0:price to matrix
- $ref->{pricematrix} = "0:$ref->{sellprice}";
-
- }
+ my ( $pmh, $ref, $transdate, $decimalplaces, $form, $myconfig ) = @_;
+ $ref->{pricematrix} = "";
+ my $customerprice;
+ my $pricegroupprice;
+ my $sellprice;
+ my $mref;
+ my %p = ();
+
+ # depends if this is a customer or vendor
+ if ( $form->{customer_id} ) {
+ $pmh->execute( $ref->{id}, $ref->{id}, $ref->{id}, $ref->{id} );
+
+ while ( $mref = $pmh->fetchrow_hashref(NAME_lc) ) {
+
+ # check date
+ if ( $mref->{validfrom} ) {
+ next
+ if $transdate <
+ $form->datetonum( $myconfig, $mref->{validfrom} );
+ }
+ if ( $mref->{validto} ) {
+ next
+ if $transdate >
+ $form->datetonum( $myconfig, $mref->{validto} );
+ }
+
+ # convert price
+ $sellprice =
+ $form->round_amount(
+ $mref->{sellprice} * $form->{ $mref->{curr} },
+ $decimalplaces );
+
+ if ( $mref->{customer_id} ) {
+ $ref->{sellprice} = $sellprice
+ if !$mref->{pricebreak};
+ $p{ $mref->{pricebreak} } = $sellprice;
+ $customerprice = 1;
+ }
+
+ if ( $mref->{pricegroup_id} ) {
+ if ( !$customerprice ) {
+ $ref->{sellprice} = $sellprice
+ if !$mref->{pricebreak};
+ $p{ $mref->{pricebreak} } = $sellprice;
+ }
+ $pricegroupprice = 1;
+ }
+
+ if ( !$customerprice && !$pricegroupprice ) {
+ $p{ $mref->{pricebreak} } = $sellprice;
+ }
+
+ }
+ $pmh->finish;
+
+ if (%p) {
+ if ( $ref->{sellprice} ) {
+ $p{0} = $ref->{sellprice};
+ }
+ for ( sort { $a <=> $b } keys %p ) {
+ $ref->{pricematrix} .= "${_}:$p{$_} ";
+ }
+ }
+ else {
+ if ($init) {
+ $ref->{sellprice} =
+ $form->round_amount( $ref->{sellprice}, $decimalplaces );
+ }
+ else {
+ $ref->{sellprice} =
+ $form->round_amount(
+ $ref->{sellprice} * ( 1 - $form->{tradediscount} ),
+ $decimalplaces );
+ }
+ $ref->{pricematrix} = "0:$ref->{sellprice} "
+ if $ref->{sellprice};
+ }
+ chop $ref->{pricematrix};
+
+ }
+
+ if ( $form->{vendor_id} ) {
+ $pmh->execute( $ref->{id} );
+
+ $mref = $pmh->fetchrow_hashref(NAME_lc);
+
+ if ( $mref->{partnumber} ne "" ) {
+ $ref->{partnumber} = $mref->{partnumber};
+ }
+
+ if ( $mref->{lastcost} ) {
+
+ # do a conversion
+ $ref->{sellprice} =
+ $form->round_amount( $mref->{lastcost} * $form->{ $mref->{curr} },
+ $decimalplaces );
+ }
+ $pmh->finish;
+
+ $ref->{sellprice} *= 1;
+
+ # add 0:price to matrix
+ $ref->{pricematrix} = "0:$ref->{sellprice}";
+
+ }
}
1;
diff --git a/LedgerSMB/RC.pm b/LedgerSMB/RC.pm
index 48f184cd..a7aa1d1f 100644
--- a/LedgerSMB/RC.pm
+++ b/LedgerSMB/RC.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -33,261 +33,256 @@
package RC;
-
-sub getposlines{
- my ($self, $myconfig, $form) = @_;
- %pos_config = %{$form->{pos_config}};
- %pos_sources = %{$form->{pos_sources}};
- my $sources = '';
- foreach $key (keys %pos_sources){
- $sources .= ", '$key'";
- }
- $sources =~ s/^,\s*//;
- my $dbh = $form->{dbh};
-
- my $query = qq|
+sub getposlines {
+ my ( $self, $myconfig, $form ) = @_;
+ %pos_config = %{ $form->{pos_config} };
+ %pos_sources = %{ $form->{pos_sources} };
+ my $sources = '';
+ foreach $key ( keys %pos_sources ) {
+ $sources .= ", '$key'";
+ }
+ $sources =~ s/^,\s*//;
+ my $dbh = $form->{dbh};
+
+ my $query = qq|
SELECT sum(amount) AS amount, source FROM acc_trans
WHERE chart_id = (SELECT id FROM chart
WHERE accno = ?)
AND transdate = date 'NOW' AND cleared IS NOT TRUE
GROUP BY source|;
- my $sth = $dbh->prepare($query);
- $sth->execute($pos_config{till_accno}) || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{$form->{TB}}, $ref;
- }
- $sth->finish;
- my $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $pos_config{till_accno} ) || $form->dberror($query);
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{TB} }, $ref;
+ }
+ $sth->finish;
+ my $query = qq|
SELECT sum(amount) AS sum FROM acc_trans
WHERE chart_id = (SELECT id FROM chart WHERE accno = ?)
AND transdate = date 'NOW'
AND cleared IS NOT TRUE|;
- my $sth = $dbh->prepare($query);
- $sth->execute($pos_config{till_accno}) || $form->dberror($query);
- my $ref = $sth->fetchrow_hashref(NAME_lc);
- $form->{sum} = $ref->{sum};
- $sth->finish;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $pos_config{till_accno} ) || $form->dberror($query);
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+ $form->{sum} = $ref->{sum};
+ $sth->finish;
}
sub clear_till {
- my ($self, $myconfig, $form) = @_;
- %pos_config = %{$form->{pos_config}};
- %pos_sources = %{$form->{pos_sources}};
- my $sources = '';
- foreach $key (keys %pos_sources){
- $sources .= ", '$key'";
- }
- $sources =~ s/^,\s//;
- my $dbh = $form->{dbh};
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+ %pos_config = %{ $form->{pos_config} };
+ %pos_sources = %{ $form->{pos_sources} };
+ my $sources = '';
+ foreach $key ( keys %pos_sources ) {
+ $sources .= ", '$key'";
+ }
+ $sources =~ s/^,\s//;
+ my $dbh = $form->{dbh};
+ my $query = qq|
UPDATE acc_trans
SET cleared = TRUE
WHERE chart_id =
(SELECT id FROM chart WHERE accno = ?)
AND transdate = date 'NOW'|;
- my $sth = $dbh->prepare($query);
- $sth->execute($pos_config{till_accno}) || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $pos_config{till_accno} ) || $form->dberror($query);
}
-sub getbalance{
- my ($self, $myconfig, $form) = @_;
- my $dbh = $form->{dbh};
+sub getbalance {
+ my ( $self, $myconfig, $form ) = @_;
+ my $dbh = $form->{dbh};
- my $query = qq|
+ my $query = qq|
SELECT sum(amount) AS balance
FROM acc_trans
WHERE chart_id = (SELECT id FROM chart WHERE accno = ?)|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{accno}) || $form->dberror($query);
- my $ref = $sth->fetchrow_hashref(NAME_lc);
- $form->{balance} = $ref->{balance};
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{accno} ) || $form->dberror($query);
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+ $form->{balance} = $ref->{balance};
}
-
sub paymentaccounts {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
+ my $dbh = $form->{dbh};
- my $query = qq|
+ my $query = qq|
SELECT accno, description
FROM chart
WHERE link LIKE '%_paid%'
AND (category = 'A' OR category = 'L')
ORDER BY accno|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{PR} }, $ref;
- }
- $sth->finish;
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{PR} }, $ref;
+ }
+ $sth->finish;
- $form->all_years($myconfig, $dbh);
+ $form->all_years( $myconfig, $dbh );
}
-
sub payment_transactions {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my $query;
- my $sth;
-
- $query = qq|SELECT category FROM chart WHERE accno = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{accno});
- ($form->{category}) = $sth->fetchrow_array();
-
- my $cleared;
-
- ($form->{fromdate}, $form->{todate})
- = $form->from_to(
- $form->{year}, $form->{month}, $form->{interval})
- if $form->{year} && $form->{month};
-
- my $transdate = qq| AND ac.transdate < date |.
- $dbh->quote($form->{fromdate});
-
- if (! $form->{fromdate}) {
- $cleared = qq| AND ac.cleared = '1'|;
- $transdate = "";
- }
-
- # get beginning balance
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my $query;
+ my $sth;
+
+ $query = qq|SELECT category FROM chart WHERE accno = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{accno} );
+ ( $form->{category} ) = $sth->fetchrow_array();
+
+ my $cleared;
+
+ ( $form->{fromdate}, $form->{todate} ) =
+ $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
+ if $form->{year} && $form->{month};
+
+ my $transdate =
+ qq| AND ac.transdate < date | . $dbh->quote( $form->{fromdate} );
+
+ if ( !$form->{fromdate} ) {
+ $cleared = qq| AND ac.cleared = '1'|;
+ $transdate = "";
+ }
+
+ # get beginning balance
+ $query = qq|
SELECT sum(ac.amount)
FROM acc_trans ac
JOIN chart ch ON (ch.id = ac.chart_id)
WHERE ch.accno = ? $transdate $cleared |;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{accno});
- ($form->{beginningbalance}) = $sth->fetchrow_array();
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{accno} );
+ ( $form->{beginningbalance} ) = $sth->fetchrow_array();
- $query = qq|
+ $query = qq|
SELECT sum(ac.amount)
FROM acc_trans ac
JOIN chart ch ON (ch.id = ac.chart_id)
WHERE ch.accno = ? AND ac.fx_transaction = '1'
$transdate $cleared|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{accno});
- ($form->{fx_balance}) = $sth->fetchrow_array();
-
-
- $transdate = "";
- if ($form->{todate}) {
- $transdate = qq| AND ac.transdate <= date |.
- $dbh->quote($form->{todate});
- }
-
- # get statement balance
- $query = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{accno} );
+ ( $form->{fx_balance} ) = $sth->fetchrow_array();
+
+ $transdate = "";
+ if ( $form->{todate} ) {
+ $transdate =
+ qq| AND ac.transdate <= date | . $dbh->quote( $form->{todate} );
+ }
+
+ # get statement balance
+ $query = qq|
SELECT sum(ac.amount)
FROM acc_trans ac
JOIN chart ch ON (ch.id = ac.chart_id)
WHERE ch.accno = ? $transdate|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{accno});
- ($form->{endingbalance}) = $sth->fetchrow_array();
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{accno} );
+ ( $form->{endingbalance} ) = $sth->fetchrow_array();
- # fx balance
- $query = qq|
+ # fx balance
+ $query = qq|
SELECT sum(ac.amount)
FROM acc_trans ac
JOIN chart ch ON (ch.id = ac.chart_id)
WHERE ch.accno = ? AND ac.fx_transaction = '1' $transdate |;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{accno});
- ($form->{fx_endingbalance}) = $sth->fetchrow_array();
-
-
- $cleared = qq| AND ac.cleared = '0'| unless $form->{fromdate};
-
- if ($form->{report}) {
- $cleared = qq| AND NOT (ac.cleared = '0' OR ac.cleared = '1')|;
- if ($form->{cleared}) {
- $cleared = qq| AND ac.cleared = '1'|;
- }
- if ($form->{outstanding}) {
- $cleared =
- ($form->{cleared})
- ? ""
- : qq| AND ac.cleared = '0'|;
- }
- if (! $form->{fromdate}) {
- $form->{beginningbalance} = 0;
- $form->{fx_balance} = 0;
- }
- }
-
- my $fx_transaction;
- if ($form->{fx_transaction}) {
- $fx_transaction = qq|
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{accno} );
+ ( $form->{fx_endingbalance} ) = $sth->fetchrow_array();
+
+ $cleared = qq| AND ac.cleared = '0'| unless $form->{fromdate};
+
+ if ( $form->{report} ) {
+ $cleared = qq| AND NOT (ac.cleared = '0' OR ac.cleared = '1')|;
+ if ( $form->{cleared} ) {
+ $cleared = qq| AND ac.cleared = '1'|;
+ }
+ if ( $form->{outstanding} ) {
+ $cleared =
+ ( $form->{cleared} )
+ ? ""
+ : qq| AND ac.cleared = '0'|;
+ }
+ if ( !$form->{fromdate} ) {
+ $form->{beginningbalance} = 0;
+ $form->{fx_balance} = 0;
+ }
+ }
+
+ my $fx_transaction;
+ if ( $form->{fx_transaction} ) {
+ $fx_transaction = qq|
AND NOT (ac.chart_id IN
(SELECT value FROM defaults
WHERE setting_key = 'fxgain_accno_id'
UNION
SELECT value FROM defaults
WHERE setting_key = 'fxloss_accno_id'))|;
- } else {
- $fx_transaction = qq|
+ }
+ else {
+ $fx_transaction = qq|
AND ac.fx_transaction = '0'|;
- }
-
-
- if ($form->{summary}) {
- $query = qq|
+ }
+
+ if ( $form->{summary} ) {
+ $query = qq|
SELECT ac.transdate, ac.source,
sum(ac.amount) AS amount, ac.cleared
FROM acc_trans ac
JOIN chart ch ON (ac.chart_id = ch.id)
- WHERE ch.accno = |.$dbh->quote($form->{accno}).qq|
+ WHERE ch.accno = | . $dbh->quote( $form->{accno} ) . qq|
AND ac.amount >= 0 $fx_transaction $cleared|;
- $query .= " AND ac.transdate >= ".$dbh->quote($form->{fromdate})
- if $form->{fromdate};
- $query .= " AND ac.transdate <= ".$dbh->quote($form->{todate})
- if $form->{todate};
- $query .= " GROUP BY ac.source, ac.transdate, ac.cleared";
- $query .= qq|
+ $query .= " AND ac.transdate >= " . $dbh->quote( $form->{fromdate} )
+ if $form->{fromdate};
+ $query .= " AND ac.transdate <= " . $dbh->quote( $form->{todate} )
+ if $form->{todate};
+ $query .= " GROUP BY ac.source, ac.transdate, ac.cleared";
+ $query .= qq|
UNION ALL
SELECT ac.transdate, ac.source,
sum(ac.amount) AS amount, ac.cleared
FROM acc_trans ac
JOIN chart ch ON (ac.chart_id = ch.id)
- WHERE ch.accno = |.$dbh->quote($form->{accno}).qq|
+ WHERE ch.accno = | . $dbh->quote( $form->{accno} ) . qq|
AND ac.amount < 0 $fx_transaction $cleared|;
- $query .= " AND ac.transdate >= ".$dbh->quote($form->{fromdate})
- if $form->{fromdate};
- $query .= " AND ac.transdate <= ".$dbh->quote($form->{todate})
- if $form->{todate};
- $query .= " GROUP BY ac.source, ac.transdate, ac.cleared";
-
- $query .= " ORDER BY 1,2";
-
- } else {
-
- $query = qq|
+ $query .= " AND ac.transdate >= " . $dbh->quote( $form->{fromdate} )
+ if $form->{fromdate};
+ $query .= " AND ac.transdate <= " . $dbh->quote( $form->{todate} )
+ if $form->{todate};
+ $query .= " GROUP BY ac.source, ac.transdate, ac.cleared";
+
+ $query .= " ORDER BY 1,2";
+
+ }
+ else {
+
+ $query = qq|
SELECT ac.transdate, ac.source, ac.fx_transaction,
ac.amount, ac.cleared, g.id, g.description
FROM acc_trans ac
JOIN chart ch ON (ac.chart_id = ch.id)
JOIN gl g ON (g.id = ac.trans_id)
- WHERE ch.accno = |.$dbh->quote($form->{accno}).qq|
+ WHERE ch.accno = | . $dbh->quote( $form->{accno} ) . qq|
$fx_transaction $cleared|;
- $query .= " AND ac.transdate >= ".$dbh->quote($form->{fromdate})
- if $form->{fromdate};
- $query .= " AND ac.transdate <= ".$dbh->quote($form->{todate})
- if $form->{todate};
- $query .= qq|
+ $query .= " AND ac.transdate >= " . $dbh->quote( $form->{fromdate} )
+ if $form->{fromdate};
+ $query .= " AND ac.transdate <= " . $dbh->quote( $form->{todate} )
+ if $form->{todate};
+ $query .= qq|
UNION ALL
SELECT ac.transdate, ac.source, ac.fx_transaction,
ac.amount, ac.cleared, a.id, n.name
@@ -295,13 +290,13 @@ sub payment_transactions {
JOIN chart ch ON (ac.chart_id = ch.id)
JOIN ar a ON (a.id = ac.trans_id)
JOIN customer n ON (n.id = a.customer_id)
- WHERE ch.accno = |.$dbh->quote($form->{accno}).qq|
+ WHERE ch.accno = | . $dbh->quote( $form->{accno} ) . qq|
$fx_transaction $cleared|;
- $query .= " AND ac.transdate >= ".$dbh->quote($form->{fromdate})
- if $form->{fromdate};
- $query .= " AND ac.transdate <= ".$dbh->quote($form->{todate})
- if $form->{todate};
- $query .= qq|
+ $query .= " AND ac.transdate >= " . $dbh->quote( $form->{fromdate} )
+ if $form->{fromdate};
+ $query .= " AND ac.transdate <= " . $dbh->quote( $form->{todate} )
+ if $form->{todate};
+ $query .= qq|
UNION ALL
SELECT ac.transdate, ac.source, ac.fx_transaction,
ac.amount, ac.cleared, a.id, n.name
@@ -309,31 +304,31 @@ sub payment_transactions {
JOIN chart ch ON (ac.chart_id = ch.id)
JOIN ap a ON (a.id = ac.trans_id)
JOIN vendor n ON (n.id = a.vendor_id)
- WHERE ch.accno = |.$dbh->quote($form->{accno}).qq|
+ WHERE ch.accno = | . $dbh->quote( $form->{accno} ) . qq|
$fx_transaction $cleared|;
- $query .= " AND ac.transdate >= ".$dbh->quote($form->{fromdate})
- if $form->{fromdate};
- $query .= " AND ac.transdate <= ".$dbh->quote($form->{todate})
- if $form->{todate};
-
- $query .= " ORDER BY 1,2,3";
- }
-
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- my $dr;
- my $cr;
-
- if ($form->{summary}) {
- $query = qq|
+ $query .= " AND ac.transdate >= " . $dbh->quote( $form->{fromdate} )
+ if $form->{fromdate};
+ $query .= " AND ac.transdate <= " . $dbh->quote( $form->{todate} )
+ if $form->{todate};
+
+ $query .= " ORDER BY 1,2,3";
+ }
+
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ my $dr;
+ my $cr;
+
+ if ( $form->{summary} ) {
+ $query = qq|
SELECT c.name
FROM customer c
JOIN ar a ON (c.id = a.customer_id)
JOIN acc_trans ac ON (a.id = ac.trans_id)
JOIN chart ch ON (ac.chart_id = ch.id)
WHERE ac.transdate = ?
- AND ch.accno = |.$dbh->quote($form->{accno}).qq|
+ AND ch.accno = | . $dbh->quote( $form->{accno} ) . qq|
AND (ac.source = ? OR ac.source IS NULL)
AND ac.amount >= 0 $cleared
UNION
@@ -343,7 +338,7 @@ sub payment_transactions {
JOIN acc_trans ac ON (a.id = ac.trans_id)
JOIN chart ch ON (ac.chart_id = ch.id)
WHERE ac.transdate = ?
- AND ch.accno = |.$dbh->quote($form->{accno}).qq|
+ AND ch.accno = | . $dbh->quote( $form->{accno} ) . qq|
AND (ac.source = ? OR ac.source IS NULL)
AND ac.amount > 0 $cleared
UNION
@@ -352,21 +347,21 @@ sub payment_transactions {
JOIN acc_trans ac ON (g.id = ac.trans_id)
JOIN chart ch ON (ac.chart_id = ch.id)
WHERE ac.transdate = ?
- AND ch.accno = |.$dbh->quote($form->{accno}).qq|
+ AND ch.accno = | . $dbh->quote( $form->{accno} ) . qq|
AND (ac.source = ? OR ac.source IS NULL)
AND ac.amount >= 0 $cleared|;
-
- $query .= " ORDER BY 1";
- $dr = $dbh->prepare($query);
- $query = qq|
+ $query .= " ORDER BY 1";
+ $dr = $dbh->prepare($query);
+
+ $query = qq|
SELECT c.name
FROM customer c
JOIN ar a ON (c.id = a.customer_id)
JOIN acc_trans ac ON (a.id = ac.trans_id)
JOIN chart ch ON (ac.chart_id = ch.id)
WHERE ac.transdate = ?
- AND ch.accno = |.$dbh->quote($form->{accno}).qq|
+ AND ch.accno = | . $dbh->quote( $form->{accno} ) . qq|
AND (ac.source = ? OR ac.source IS NULL)
AND ac.amount < 0 $cleared
UNION
@@ -376,7 +371,7 @@ sub payment_transactions {
JOIN acc_trans ac ON (a.id = ac.trans_id)
JOIN chart ch ON (ac.chart_id = ch.id)
WHERE ac.transdate = ?
- AND ch.accno = |.$dbh->quote($form->{accno}).qq|
+ AND ch.accno = | . $dbh->quote( $form->{accno} ) . qq|
AND (ac.source = ? OR ac.source IS NULL)
AND ac.amount < 0 $cleared
UNION
@@ -385,119 +380,115 @@ sub payment_transactions {
JOIN acc_trans ac ON (g.id = ac.trans_id)
JOIN chart ch ON (ac.chart_id = ch.id)
WHERE ac.transdate = ?
- AND ch.accno = |.$dbh->quote($form->{accno}).qq|
+ AND ch.accno = | . $dbh->quote( $form->{accno} ) . qq|
AND (ac.source = ? OR ac.source IS NULL)
AND ac.amount < 0 $cleared|;
-
- $query .= " ORDER BY 1";
- $cr = $dbh->prepare($query);
- }
-
- my $name;
- my $ref;
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- if ($form->{summary}) {
-
- if ($ref->{amount} > 0) {
- $dr->execute(
- $ref->{transdate}, $ref->{source},
- $ref->{transdate}, $ref->{source},
- $ref->{transdate}, $ref->{source});
- $ref->{oldcleared} = $ref->{cleared};
- $ref->{name} = ();
-
- while (($name) = $dr->fetchrow_array) {
- push @{ $ref->{name} }, $name;
- }
- $dr->finish;
- } else {
-
- $cr->execute(
- $ref->{transdate}, $ref->{source},
- $ref->{transdate}, $ref->{source},
- $ref->{transdate}, $ref->{source});
- $ref->{oldcleared} = $ref->{cleared};
- $ref->{name} = ();
- while (($name) = $cr->fetchrow_array) {
- push @{ $ref->{name} }, $name;
- }
- $cr->finish;
-
- }
-
- } else {
- push @{ $ref->{name} }, $ref->{description};
- }
-
- push @{ $form->{PR} }, $ref;
-
- }
- $sth->finish;
-
- $dbh->commit;
-
-}
+ $query .= " ORDER BY 1";
+ $cr = $dbh->prepare($query);
+ }
+
+ my $name;
+ my $ref;
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ if ( $form->{summary} ) {
+
+ if ( $ref->{amount} > 0 ) {
+ $dr->execute(
+ $ref->{transdate}, $ref->{source}, $ref->{transdate},
+ $ref->{source}, $ref->{transdate}, $ref->{source}
+ );
+ $ref->{oldcleared} = $ref->{cleared};
+ $ref->{name} = ();
+
+ while ( ($name) = $dr->fetchrow_array ) {
+ push @{ $ref->{name} }, $name;
+ }
+ $dr->finish;
+ }
+ else {
+
+ $cr->execute(
+ $ref->{transdate}, $ref->{source}, $ref->{transdate},
+ $ref->{source}, $ref->{transdate}, $ref->{source}
+ );
+ $ref->{oldcleared} = $ref->{cleared};
+ $ref->{name} = ();
+ while ( ($name) = $cr->fetchrow_array ) {
+ push @{ $ref->{name} }, $name;
+ }
+ $cr->finish;
+
+ }
+
+ }
+ else {
+ push @{ $ref->{name} }, $ref->{description};
+ }
+
+ push @{ $form->{PR} }, $ref;
+
+ }
+ $sth->finish;
+
+ $dbh->commit;
+
+}
sub reconcile {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
+ my $dbh = $form->{dbh};
- my $query = qq|SELECT id FROM chart
+ my $query = qq|SELECT id FROM chart
WHERE accno = '$form->{accno}'|;
- my ($chart_id) = $dbh->selectrow_array($query);
- $chart_id *= 1;
-
- $query = qq|
+ my ($chart_id) = $dbh->selectrow_array($query);
+ $chart_id *= 1;
+
+ $query = qq|
SELECT trans_id FROM acc_trans
WHERE (source = ? OR source IS NULL) AND transdate = ?
AND cleared = '0'
- AND chart_id = |.$dbh->quote($chart_id);
- my $sth = $dbh->prepare($query) || $form->dberror($query);
-
- my $i;
- my $trans_id;
+ AND chart_id = | . $dbh->quote($chart_id);
+ my $sth = $dbh->prepare($query) || $form->dberror($query);
- $query = qq|
+ my $i;
+ my $trans_id;
+
+ $query = qq|
UPDATE acc_trans
SET cleared = '1'
WHERE cleared = '0' AND trans_id = ? AND transdate = ?
- AND chart_id = |.$dbh->quote($chart_id);
- my $tth = $dbh->prepare($query) || $form->dberror($query);
-
- # clear flags
- for $i (1 .. $form->{rowcount}) {
- if ($form->{"cleared_$i"} && ! $form->{"oldcleared_$i"}) {
- if ($form->{summary}) {
- $sth->execute(
- $form->{"source_$i"},
- $form->{"transdate_$i"}
- ) || $form->dberror;
-
- while (($trans_id) = $sth->fetchrow_array) {
- $tth->execute(
- $trans_id,
- $form->{"transdate_$i"}
- ) || $form->dberror;
- $tth->finish;
- }
- $sth->finish;
-
- } else {
-
- $tth->execute(
- $form->{"id_$i"},
- $form->{"transdate_$i"}
- ) || $form->dberror;
- $tth->finish;
- }
- }
- }
-
- $dbh->commit;
+ AND chart_id = | . $dbh->quote($chart_id);
+ my $tth = $dbh->prepare($query) || $form->dberror($query);
+
+ # clear flags
+ for $i ( 1 .. $form->{rowcount} ) {
+ if ( $form->{"cleared_$i"} && !$form->{"oldcleared_$i"} ) {
+ if ( $form->{summary} ) {
+ $sth->execute( $form->{"source_$i"}, $form->{"transdate_$i"} )
+ || $form->dberror;
+
+ while ( ($trans_id) = $sth->fetchrow_array ) {
+ $tth->execute( $trans_id, $form->{"transdate_$i"} )
+ || $form->dberror;
+ $tth->finish;
+ }
+ $sth->finish;
+
+ }
+ else {
+
+ $tth->execute( $form->{"id_$i"}, $form->{"transdate_$i"} )
+ || $form->dberror;
+ $tth->finish;
+ }
+ }
+ }
+
+ $dbh->commit;
}
diff --git a/LedgerSMB/RESTXML/Document/Base.pm b/LedgerSMB/RESTXML/Document/Base.pm
index e8feaa96..986b4148 100644
--- a/LedgerSMB/RESTXML/Document/Base.pm
+++ b/LedgerSMB/RESTXML/Document/Base.pm
@@ -5,26 +5,27 @@ use XML::Twig;
use LedgerSMB::Log;
use Carp;
-sub handle_post {
- my ($self, $args) = @_;
+sub handle_post {
+ my ( $self, $args ) = @_;
- return $args->{handler}->unsupported('the POST method is not implemented.');
+ return $args->{handler}->unsupported('the POST method is not implemented.');
}
-sub handle_put {
- my ($self, $args) = @_;
- return $self->{handler}->unsupported('the PUT method is not implemented.');
+sub handle_put {
+ my ( $self, $args ) = @_;
+ return $self->{handler}->unsupported('the PUT method is not implemented.');
}
sub handle_delete {
- my ($self, $args) = @_;
- return $self->{handler}->unsupported('the DELETE method is not implemented.');
+ my ( $self, $args ) = @_;
+ return $self->{handler}
+ ->unsupported('the DELETE method is not implemented.');
}
sub handle_get {
- my ($self, $args) = @_;
+ my ( $self, $args ) = @_;
- return $self->{handler}->unsupported('the GET method is not implemented.');
+ return $self->{handler}->unsupported('the GET method is not implemented.');
}
=head3 hash_to_twig
@@ -45,18 +46,25 @@ nodes at once.
=cut
-sub hash_to_twig {
- my ($self, $args) = @_;
-
- my $hash = $args->{hash} || croak "Need a hash to convert to use hash_to_twig";
- my $name = $args->{name} || croak "Need a root element name to use hash_to_twig";
- my @keyorder = keys %$hash;
-
- @keyorder = sort @keyorder unless defined($args->{sort}) and $args->{sort} == 0;
-
- return XML::Twig::Elt->new($name,$args->{root_attr}||{}, map {
- XML::Twig::Elt->new($_, {'#CDATA'=>1}, $hash->{$_})
- } @keyorder );
+sub hash_to_twig {
+ my ( $self, $args ) = @_;
+
+ my $hash = $args->{hash}
+ || croak "Need a hash to convert to use hash_to_twig";
+ my $name = $args->{name}
+ || croak "Need a root element name to use hash_to_twig";
+ my @keyorder = keys %$hash;
+
+ @keyorder = sort @keyorder
+ unless defined( $args->{sort} )
+ and $args->{sort} == 0;
+
+ return XML::Twig::Elt->new(
+ $name,
+ $args->{root_attr} || {},
+ map { XML::Twig::Elt->new( $_, { '#CDATA' => 1 }, $hash->{$_} ) }
+ @keyorder
+ );
}
1;
diff --git a/LedgerSMB/RESTXML/Document/Customer.pm b/LedgerSMB/RESTXML/Document/Customer.pm
index 3a494965..b2e19753 100644
--- a/LedgerSMB/RESTXML/Document/Customer.pm
+++ b/LedgerSMB/RESTXML/Document/Customer.pm
@@ -3,21 +3,22 @@ use strict;
use warnings;
use base qw(LedgerSMB::RESTXML::Document::Base);
+sub handle_get {
+ my ( $self, $args ) = @_;
+ my $user = $args->{user};
+ my $dbh = $args->{dbh};
+ my $handler = $args->{handler};
-sub handle_get {
- my ($self, $args) = @_;
- my $user = $args->{user};
- my $dbh = $args->{dbh};
- my $handler = $args->{handler};
+ my $res = $dbh->selectrow_hashref( q{SELECT * from customer where id = ?},
+ undef, $args->{args}[0] );
- my $res = $dbh->selectrow_hashref(q{SELECT * from customer where id = ?}, undef, $args->{args}[0]);
-
- if(!$res) {
- $handler->not_found("No customer with the id $args->{args}[0] found");
- } else {
- $handler->respond($self->hash_to_twig({name=>'Customer',hash=>$res}));
- }
+ if ( !$res ) {
+ $handler->not_found("No customer with the id $args->{args}[0] found");
+ }
+ else {
+ $handler->respond(
+ $self->hash_to_twig( { name => 'Customer', hash => $res } ) );
+ }
}
-
1;
diff --git a/LedgerSMB/RESTXML/Document/Customer_Search.pm b/LedgerSMB/RESTXML/Document/Customer_Search.pm
index 7456f9d3..9f2fb3d6 100644
--- a/LedgerSMB/RESTXML/Document/Customer_Search.pm
+++ b/LedgerSMB/RESTXML/Document/Customer_Search.pm
@@ -4,43 +4,58 @@ use warnings;
use base qw(LedgerSMB::RESTXML::Document::Base);
use LedgerSMB::Log;
-sub handle_get {
- my ($self, $args) = @_;
- my $user = $args->{user};
- my $dbh = $args->{dbh};
- my $handler = $args->{handler};
-
- my $query = $handler->read_query();
-
- my %terms;
-
- for my $field ($query->param()) {
- # TODO: BIG GAPING HOLE HERE.
- $terms{$field} = $query->param($field);
- }
-
- if($terms{_keyword}) {
- %terms = (
- name=>$terms{_keyword},
- customernumber=>$terms{_keyword},
- contact=>$terms{_keyword}
- );
- }
- my $sql = 'SELECT id,name,phone,customernumber FROM customer WHERE '.join(' OR ',map { "$_ like ?" } sort keys %terms);
-
-
- my $res = $dbh->prepare($sql);
-
- $res->execute(map { "$terms{$_}\%" } sort keys %terms) or return $handler->error($dbh->errstr);
-
- my @rows;
- my $row;
- push @rows, $row while $row = $res->fetchrow_hashref();
-
- $res->finish();
-
- $handler->respond(XML::Twig::Elt->new('Customer_Search_Response',{'xmlns:xlink'=>"http://www.w3.org/1999/xlink"},map {
- $self->hash_to_twig({name=>'Customer',root_attr=>{'xlink:href'=>"Customer/$_->{id}"}, hash=>$_});
- } @rows));
+sub handle_get {
+ my ( $self, $args ) = @_;
+ my $user = $args->{user};
+ my $dbh = $args->{dbh};
+ my $handler = $args->{handler};
+
+ my $query = $handler->read_query();
+
+ my %terms;
+
+ for my $field ( $query->param() ) {
+
+ # TODO: BIG GAPING HOLE HERE.
+ $terms{$field} = $query->param($field);
+ }
+
+ if ( $terms{_keyword} ) {
+ %terms = (
+ name => $terms{_keyword},
+ customernumber => $terms{_keyword},
+ contact => $terms{_keyword}
+ );
+ }
+ my $sql =
+ 'SELECT id,name,phone,customernumber FROM customer WHERE '
+ . join( ' OR ', map { "$_ like ?" } sort keys %terms );
+
+ my $res = $dbh->prepare($sql);
+
+ $res->execute( map { "$terms{$_}\%" } sort keys %terms )
+ or return $handler->error( $dbh->errstr );
+
+ my @rows;
+ my $row;
+ push @rows, $row while $row = $res->fetchrow_hashref();
+
+ $res->finish();
+
+ $handler->respond(
+ XML::Twig::Elt->new(
+ 'Customer_Search_Response',
+ { 'xmlns:xlink' => "http://www.w3.org/1999/xlink" },
+ map {
+ $self->hash_to_twig(
+ {
+ name => 'Customer',
+ root_attr => { 'xlink:href' => "Customer/$_->{id}" },
+ hash => $_
+ }
+ );
+ } @rows
+ )
+ );
}
1;
diff --git a/LedgerSMB/RESTXML/Document/Part.pm b/LedgerSMB/RESTXML/Document/Part.pm
index 072f9b80..97394494 100644
--- a/LedgerSMB/RESTXML/Document/Part.pm
+++ b/LedgerSMB/RESTXML/Document/Part.pm
@@ -3,21 +3,22 @@ use strict;
use warnings;
use base qw(LedgerSMB::RESTXML::Document::Base);
+sub handle_get {
+ my ( $self, $args ) = @_;
+ my $user = $args->{user};
+ my $dbh = $args->{dbh};
+ my $handler = $args->{handler};
-sub handle_get {
- my ($self, $args) = @_;
- my $user = $args->{user};
- my $dbh = $args->{dbh};
- my $handler = $args->{handler};
+ my $res = $dbh->selectrow_hashref( q{SELECT * from part where id = ?},
+ undef, $args->{args}[0] );
- my $res = $dbh->selectrow_hashref(q{SELECT * from part where id = ?}, undef, $args->{args}[0]);
-
- if(!$res) {
- $handler->not_found("No part with the id $args->{args}[0] found");
- } else {
- $handler->respond($self->hash_to_twig({name=>'Customer',hash=>$res}));
- }
+ if ( !$res ) {
+ $handler->not_found("No part with the id $args->{args}[0] found");
+ }
+ else {
+ $handler->respond(
+ $self->hash_to_twig( { name => 'Customer', hash => $res } ) );
+ }
}
-
1;
diff --git a/LedgerSMB/RESTXML/Document/Part_Search.pm b/LedgerSMB/RESTXML/Document/Part_Search.pm
index 927c67c0..9339dcc2 100644
--- a/LedgerSMB/RESTXML/Document/Part_Search.pm
+++ b/LedgerSMB/RESTXML/Document/Part_Search.pm
@@ -4,42 +4,57 @@ use warnings;
use base qw(LedgerSMB::RESTXML::Document::Base);
use LedgerSMB::Log;
-sub handle_get {
- my ($self, $args) = @_;
- my $user = $args->{user};
- my $dbh = $args->{dbh};
- my $handler = $args->{handler};
-
- my $query = $handler->read_query();
-
- my %terms;
-
- for my $field ($query->param()) {
- # TODO: BIG GAPING HOLE HERE.
- $terms{$field} = $query->param($field);
- }
-
- if($terms{_keyword}) {
- %terms = (
- description=>$terms{_keyword},
- partnumber=>$terms{_keyword},
- );
- }
- my $sql = 'SELECT id,description,partnumber FROM parts WHERE '.join(' OR ',map { "$_ like ?" } sort keys %terms);
-
-
- my $res = $dbh->prepare($sql);
-
- $res->execute(map { "$terms{$_}\%" } sort keys %terms) or return $handler->error($dbh->errstr);
-
- my @rows;
- my $row;
- push @rows, $row while $row = $res->fetchrow_hashref();
-
- $res->finish();
-
- $handler->respond(XML::Twig::Elt->new('Part_Search_Response',{'xmlns:xlink'=>"http://www.w3.org/1999/xlink"},map {
- $self->hash_to_twig({name=>'Part',root_attr=>{'xlink:href'=>"Part/$_->{id}"}, hash=>$_});
- } @rows));
+sub handle_get {
+ my ( $self, $args ) = @_;
+ my $user = $args->{user};
+ my $dbh = $args->{dbh};
+ my $handler = $args->{handler};
+
+ my $query = $handler->read_query();
+
+ my %terms;
+
+ for my $field ( $query->param() ) {
+
+ # TODO: BIG GAPING HOLE HERE.
+ $terms{$field} = $query->param($field);
+ }
+
+ if ( $terms{_keyword} ) {
+ %terms = (
+ description => $terms{_keyword},
+ partnumber => $terms{_keyword},
+ );
+ }
+ my $sql =
+ 'SELECT id,description,partnumber FROM parts WHERE '
+ . join( ' OR ', map { "$_ like ?" } sort keys %terms );
+
+ my $res = $dbh->prepare($sql);
+
+ $res->execute( map { "$terms{$_}\%" } sort keys %terms )
+ or return $handler->error( $dbh->errstr );
+
+ my @rows;
+ my $row;
+ push @rows, $row while $row = $res->fetchrow_hashref();
+
+ $res->finish();
+
+ $handler->respond(
+ XML::Twig::Elt->new(
+ 'Part_Search_Response',
+ { 'xmlns:xlink' => "http://www.w3.org/1999/xlink" },
+ map {
+ $self->hash_to_twig(
+ {
+ name => 'Part',
+ root_attr => { 'xlink:href' => "Part/$_->{id}" },
+ hash => $_
+ }
+ );
+ } @rows
+ )
+ );
}
1;
diff --git a/LedgerSMB/RESTXML/Document/SalesOrder.pm b/LedgerSMB/RESTXML/Document/SalesOrder.pm
index acb4d5aa..b2f96256 100644
--- a/LedgerSMB/RESTXML/Document/SalesOrder.pm
+++ b/LedgerSMB/RESTXML/Document/SalesOrder.pm
@@ -3,15 +3,12 @@ use strict;
use warnings;
use base qw(LedgerSMB::RESTXML::Document::Base);
+sub handle_get {
+ my ( $self, $args ) = @_;
-
-sub handle_get {
- my ($self, $args) = @_;
-
- print "Content-type: text/html\n\n";
- print "It still works";
+ print "Content-type: text/html\n\n";
+ print "It still works";
}
-
1;
diff --git a/LedgerSMB/RESTXML/Document/Session.pm b/LedgerSMB/RESTXML/Document/Session.pm
index 1db36502..ed99b06b 100644
--- a/LedgerSMB/RESTXML/Document/Session.pm
+++ b/LedgerSMB/RESTXML/Document/Session.pm
@@ -16,18 +16,15 @@ use strict;
use warnings;
use base qw(LedgerSMB::RESTXML::Document::Base);
-
-sub handle_get {
- my ($self, $args) = @_;
-
+sub handle_get {
+ my ( $self, $args ) = @_;
}
-sub handle_post {
- my ($self, $args) = @_;
- print "Content-type: text/html\n\nhi";
-
-}
+sub handle_post {
+ my ( $self, $args ) = @_;
+ print "Content-type: text/html\n\nhi";
+}
1;
diff --git a/LedgerSMB/RESTXML/Handler.pm b/LedgerSMB/RESTXML/Handler.pm
index 006c2ead..0939da7f 100644
--- a/LedgerSMB/RESTXML/Handler.pm
+++ b/LedgerSMB/RESTXML/Handler.pm
@@ -17,61 +17,73 @@ CGI_handle is the gateway for the RESTful lsmb API.
=cut
-sub cgi_handle {
- my $self = shift;
-
- my $method = $ENV{REQUEST_METHOD};
- my $pathinfo = $ENV{PATH_INFO};
-
- #pull off the leading slash, we need it in the form document/arguments/foo
- $pathinfo =~ s#^/##;
-
-
- my $function = 'handle_'.lc($method);
- my ($user, $module, @args) = split '/',$pathinfo;
- $user = LedgerSMB::User->fetch_config($user);
-
- my $dbh = $self->connect_db($user);
-
- # non-word characters are forbidden, usually a sign of someone being sneaky.
- $module =~ s#\W##;
-
- my $document_module = $self->try_to_load($module);
-
- if($document_module) {
- if($document_module->can($function)) {
- my $returnValue = $document_module->$function({dbh=>$dbh, args=>\@args, handler=>$self, user=>$user});
-
- #return $self->return_serialized_response($returnValue);
-
- } else {
- return $self->unsupported("$module cannot handle method $method");
- }
- } else {
- return $self->not_found("Could not find a handler for document type $module: <pre>$@</pre>");
- }
+sub cgi_handle {
+ my $self = shift;
+
+ my $method = $ENV{REQUEST_METHOD};
+ my $pathinfo = $ENV{PATH_INFO};
+
+ #pull off the leading slash, we need it in the form document/arguments/foo
+ $pathinfo =~ s#^/##;
+
+ my $function = 'handle_' . lc($method);
+ my ( $user, $module, @args ) = split '/', $pathinfo;
+ $user = LedgerSMB::User->fetch_config($user);
+
+ my $dbh = $self->connect_db($user);
+
+ # non-word characters are forbidden, usually a sign of someone being sneaky.
+ $module =~ s#\W##;
+
+ my $document_module = $self->try_to_load($module);
+
+ if ($document_module) {
+ if ( $document_module->can($function) ) {
+ my $returnValue = $document_module->$function(
+ {
+ dbh => $dbh,
+ args => \@args,
+ handler => $self,
+ user => $user
+ }
+ );
+
+ #return $self->return_serialized_response($returnValue);
+
+ }
+ else {
+ return $self->unsupported("$module cannot handle method $method");
+ }
+ }
+ else {
+ return $self->not_found(
+ "Could not find a handler for document type $module: <pre>$@</pre>"
+ );
+ }
}
-sub cgi_report_error {
- my $self = shift;
- my $message = shift;
- my $code = shift||500;
-
- print "Status: $code\n";
- print "Content-Type: text/html\n\n";
- print "<html><body>\n";
- print "<h1>REST API error</h1>";
- print "<blockquote>$message</blockquote>";
- print "</body></html>";
+sub cgi_report_error {
+ my $self = shift;
+ my $message = shift;
+ my $code = shift || 500;
+
+ print "Status: $code\n";
+ print "Content-Type: text/html\n\n";
+ print "<html><body>\n";
+ print "<h1>REST API error</h1>";
+ print "<blockquote>$message</blockquote>";
+ print "</body></html>";
}
-sub cgi_read_query {
- my $self = shift;
-
- use CGI;
- my $cgi = CGI->new();
- return $cgi;
+sub cgi_read_query {
+ my $self = shift;
+
+ use CGI;
+ my $cgi = CGI->new();
+
+ return $cgi;
}
+
# ------------------------------------------------------------------------------------------------------------------------
=head3 try_to_load
@@ -83,20 +95,21 @@ document to try to load. returns a blessed anonymous hashref if the module
=cut
-sub try_to_load {
- my $self = shift;
- my $module = shift;
+sub try_to_load {
+ my $self = shift;
+ my $module = shift;
- eval qq{
+ eval qq{
use LedgerSMB::RESTXML::Document::$module;
};
- if($@) {
- warn "Cannot load $module: $@" unless $@ =~ /Can't locate LedgerSMB\//i;
-
- return undef;
- } else {
- return bless {}, "LedgerSMB::RESTXML::Document::$module";
- }
+ if ($@) {
+ warn "Cannot load $module: $@" unless $@ =~ /Can't locate LedgerSMB\//i;
+
+ return undef;
+ }
+ else {
+ return bless {}, "LedgerSMB::RESTXML::Document::$module";
+ }
}
=head3 connect_db
@@ -105,67 +118,71 @@ Given a user's config, returns a database connection handle.
=cut
-sub connect_db {
- my ($self, $myconfig) = @_;
+sub connect_db {
+ my ( $self, $myconfig ) = @_;
- my $dbh = DBI->connect(
- $myconfig->{dbconnect}, $myconfig->{dbuser},
- $myconfig->{dbpasswd})
- or carp "Error connecting to the db :$DBI::errstr";
+ my $dbh = DBI->connect( $myconfig->{dbconnect},
+ $myconfig->{dbuser}, $myconfig->{dbpasswd} )
+ or carp "Error connecting to the db :$DBI::errstr";
- return $dbh;
+ return $dbh;
}
# lets see how far XML::Simple can take us.
use XML::Simple;
use Scalar::Util qw(blessed);
-sub return_serialized_response {
- my ($self, $response) = @_;
+sub return_serialized_response {
+ my ( $self, $response ) = @_;
- print "Content-type: text/xml\n\n";
+ print "Content-type: text/xml\n\n";
- if(blessed $response && $response->isa('XML::Twig::Elt')) {
- print qq{<?xml version="1.0"?>\n};
- print $response->sprint();
- } else {
- my $xs = XML::Simple->new(NoAttr=>1,RootName=>'LedgerSMBResponse',XMLDecl=>1);
+ if ( blessed $response && $response->isa('XML::Twig::Elt') ) {
+ print qq{<?xml version="1.0"?>\n};
+ print $response->sprint();
+ }
+ else {
+ my $xs = XML::Simple->new(
+ NoAttr => 1,
+ RootName => 'LedgerSMBResponse',
+ XMLDecl => 1
+ );
- print $xs->XMLout($response);
- }
+ print $xs->XMLout($response);
+ }
- return;
+ return;
}
-sub read_query {
- my ($self) = @_;
+sub read_query {
+ my ($self) = @_;
- # for now.
- return $self->cgi_read_query();
+ # for now.
+ return $self->cgi_read_query();
}
# =------------------------- POSSIBLE WAYS FOR MODULES TO RESPOND.
-sub respond {
- my ($self, $data) = @_;
+sub respond {
+ my ( $self, $data ) = @_;
- return $self->return_serialized_response($data);
+ return $self->return_serialized_response($data);
}
-sub not_found {
- my ($self, $message) = @_;
+sub not_found {
+ my ( $self, $message ) = @_;
- $self->cgi_report_error($message,404);
+ $self->cgi_report_error( $message, 404 );
}
-sub unsupported {
- my ($self, $message) = @_;
- $self->cgi_report_error($message, 501)
+sub unsupported {
+ my ( $self, $message ) = @_;
+ $self->cgi_report_error( $message, 501 );
}
-sub error {
- my ($self, $message) = @_;
+sub error {
+ my ( $self, $message ) = @_;
- $self->cgi_report_error($message,500);
+ $self->cgi_report_error( $message, 500 );
}
1;
diff --git a/LedgerSMB/RP.pm b/LedgerSMB/RP.pm
index f778ae67..797488d0 100644
--- a/LedgerSMB/RP.pm
+++ b/LedgerSMB/RP.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -34,39 +34,41 @@
package RP;
sub inventory_activity {
- my ($self, $myconfig, $form) = @_;
- ($form->{fromdate}, $form->{todate}) =
- $form->from_to($form->{fromyear}, $form->{frommonth},
- $form->{interval})
- if $form->{fromyear} && $form->{frommonth};
-
- my $dbh = $form->{dbh};
-
- unless ($form->{sort_col}){
- $form->{sort_col} = 'partnumber';
- }
-
-
- my $where = '';
- if ($form->{fromdate}){
- $where .= "AND coalesce(ar.duedate, ap.duedate) >= ".
- $dbh->quote($form->{fromdate});
- }
- if ($form->{todate}){
- $where .= "AND coalesce(ar.duedate, ap.duedate) < ".
- $dbh->quote($form->{todate}). " ";
- }
- if ($form->{partnumber}){
- $where .= qq| AND p.partnumber ILIKE |.
- $dbh->quote('%'."$form->{partnumber}%");
- }
- if ($form->{description}){
- $where .= q| AND p.description ILIKE |
- .$dbh->quote('%'."$form->{description}%");
- }
- $where =~ s/^\s?AND/WHERE/;
-
- my $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+ ( $form->{fromdate}, $form->{todate} ) =
+ $form->from_to( $form->{fromyear}, $form->{frommonth}, $form->{interval} )
+ if $form->{fromyear} && $form->{frommonth};
+
+ my $dbh = $form->{dbh};
+
+ unless ( $form->{sort_col} ) {
+ $form->{sort_col} = 'partnumber';
+ }
+
+ my $where = '';
+ if ( $form->{fromdate} ) {
+ $where .=
+ "AND coalesce(ar.duedate, ap.duedate) >= "
+ . $dbh->quote( $form->{fromdate} );
+ }
+ if ( $form->{todate} ) {
+ $where .=
+ "AND coalesce(ar.duedate, ap.duedate) < "
+ . $dbh->quote( $form->{todate} ) . " ";
+ }
+ if ( $form->{partnumber} ) {
+ $where .=
+ qq| AND p.partnumber ILIKE |
+ . $dbh->quote( '%' . "$form->{partnumber}%" );
+ }
+ if ( $form->{description} ) {
+ $where .=
+ q| AND p.description ILIKE |
+ . $dbh->quote( '%' . "$form->{description}%" );
+ }
+ $where =~ s/^\s?AND/WHERE/;
+
+ my $query = qq|
SELECT min(p.description) AS description,
min(p.partnumber) AS partnumber, sum(
CASE WHEN i.qty > 0 THEN i.qty ELSE 0 END) AS sold,
@@ -85,671 +87,828 @@ sub inventory_activity {
$where
GROUP BY i.parts_id
ORDER BY $form->{sort_col}|;
- my $sth = $dbh->prepare($query) || $form->dberror($query);
- $sth->execute() || $form->dberror($query);
- @cols = qw(description sold revenue partnumber received expense);
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{net_income} = $ref->{revenue} - $ref->{expense};
- map {$ref->{$_} =~ s/^\s*//} @cols;
- map {$ref->{$_} =~ s/\s*$//} @cols;
- push @{$form->{TB}}, $ref;
- }
- $sth->finish;
- $dbh->commit;
-
-}
-
+ my $sth = $dbh->prepare($query) || $form->dberror($query);
+ $sth->execute() || $form->dberror($query);
+ @cols = qw(description sold revenue partnumber received expense);
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{net_income} = $ref->{revenue} - $ref->{expense};
+ map { $ref->{$_} =~ s/^\s*// } @cols;
+ map { $ref->{$_} =~ s/\s*$// } @cols;
+ push @{ $form->{TB} }, $ref;
+ }
+ $sth->finish;
+ $dbh->commit;
+}
sub yearend_statement {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ # if todate < existing yearends, delete GL and yearends
+ my $query = qq|SELECT trans_id FROM yearend WHERE transdate >= ?|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{todate} ) || $form->dberror($query);
+
+ my @trans_id = ();
+ my $id;
+ while ( ($id) = $sth->fetchrow_array ) {
+ push @trans_id, $id;
+ }
+ $sth->finish;
+
+ $query = qq|DELETE FROM gl WHERE id = ?|;
+ $sth = $dbh->prepare($query) || $form->dberror($query);
+
+ $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
+ my $ath = $dbh->prepare($query) || $form->dberror($query);
+
+ foreach $id (@trans_id) {
+ $sth->execute($id);
+ $ath->execute($id);
+
+ $sth->finish;
+ $ath->finish;
+ }
+
+ my $last_period = 0;
+ my @categories = qw(I E);
+ my $category;
+
+ $form->{decimalplaces} *= 1;
+
+ &get_accounts( $dbh, 0, $form->{fromdate}, $form->{todate}, $form,
+ \@categories );
+
+ $dbh->commit;
+
+ # now we got $form->{I}{accno}{ }
+ # and $form->{E}{accno}{ }
+
+ my %account = (
+ 'I' => {
+ 'label' => 'income',
+ 'labels' => 'income',
+ 'ml' => 1
+ },
+ 'E' => {
+ 'label' => 'expense',
+ 'labels' => 'expenses',
+ 'ml' => -1
+ }
+ );
+
+ foreach $category (@categories) {
+ foreach $key ( sort keys %{ $form->{$category} } ) {
+ if ( $form->{$category}{$key}{charttype} eq 'A' ) {
+ $form->{"total_$account{$category}{labels}_this_period"} +=
+ $form->{$category}{$key}{this} * $account{$category}{ml};
+ }
+ }
+ }
+
+ # totals for income and expenses
+ $form->{total_income_this_period} =
+ $form->round_amount( $form->{total_income_this_period},
+ $form->{decimalplaces} );
+ $form->{total_expenses_this_period} =
+ $form->round_amount( $form->{total_expenses_this_period},
+ $form->{decimalplaces} );
+
+ # total for income/loss
+ $form->{total_this_period} =
+ $form->{total_income_this_period} - $form->{total_expenses_this_period};
- # if todate < existing yearends, delete GL and yearends
- my $query = qq|SELECT trans_id FROM yearend WHERE transdate >= ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{todate}) || $form->dberror($query);
-
- my @trans_id = ();
- my $id;
- while (($id) = $sth->fetchrow_array) {
- push @trans_id, $id;
- }
- $sth->finish;
-
- $query = qq|DELETE FROM gl WHERE id = ?|;
- $sth = $dbh->prepare($query) || $form->dberror($query);
-
- $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
- my $ath = $dbh->prepare($query) || $form->dberror($query);
-
- foreach $id (@trans_id) {
- $sth->execute($id);
- $ath->execute($id);
-
- $sth->finish;
- $ath->finish;
- }
-
-
- my $last_period = 0;
- my @categories = qw(I E);
- my $category;
-
- $form->{decimalplaces} *= 1;
-
- &get_accounts($dbh, 0, $form->{fromdate}, $form->{todate}, $form, \@categories);
-
- $dbh->commit;
-
-
- # now we got $form->{I}{accno}{ }
- # and $form->{E}{accno}{ }
-
- my %account = (
- 'I' => {
- 'label' => 'income',
- 'labels' => 'income',
- 'ml' => 1 },
- 'E' => {
- 'label' => 'expense',
- 'labels' => 'expenses',
- 'ml' => -1 }
- );
-
- foreach $category (@categories) {
- foreach $key (sort keys %{ $form->{$category} }) {
- if ($form->{$category}{$key}{charttype} eq 'A') {
- $form->{"total_$account{$category}{labels}_this_period"}
- += $form->{$category}{$key}{this}
- * $account{$category}{ml};
- }
- }
- }
-
-
- # totals for income and expenses
- $form->{total_income_this_period} = $form->round_amount(
- $form->{total_income_this_period}, $form->{decimalplaces});
- $form->{total_expenses_this_period} = $form->round_amount(
- $form->{total_expenses_this_period}, $form->{decimalplaces});
-
- # total for income/loss
- $form->{total_this_period}
- = $form->{total_income_this_period}
- - $form->{total_expenses_this_period};
-
}
-
sub income_statement {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my $last_period = 0;
- my @categories = qw(I E);
- my $category;
-
- $form->{decimalplaces} *= 1;
-
- if (! ($form->{fromdate} || $form->{todate})) {
- if ($form->{fromyear} && $form->{frommonth}) {
- ($form->{fromdate}, $form->{todate})
- = $form->from_to(
- $form->{fromyear},
- $form->{frommonth}, $form->{interval});
- }
- }
-
- &get_accounts(
- $dbh, $last_period, $form->{fromdate}, $form->{todate},
- $form, \@categories, 1);
-
- if (! ($form->{comparefromdate} || $form->{comparetodate})) {
- if ($form->{compareyear} && $form->{comparemonth}) {
- ($form->{comparefromdate}, $form->{comparetodate})
- = $form->from_to(
- $form->{compareyear},
- $form->{comparemonth},
- $form->{interval});
- }
- }
-
- # if there are any compare dates
- if ($form->{comparefromdate} || $form->{comparetodate}) {
- $last_period = 1;
-
- &get_accounts(
- $dbh, $last_period, $form->{comparefromdate},
- $form->{comparetodate}, $form, \@categories, 1);
- }
-
-
- $dbh->commit;
-
-
- # now we got $form->{I}{accno}{ }
- # and $form->{E}{accno}{ }
-
- my %account = (
- 'I' => {
- 'label' => 'income',
- 'labels' => 'income',
- 'ml' => 1 },
- 'E' => {
- 'label' => 'expense',
- 'labels' => 'expenses',
- 'ml' => -1 }
- );
-
- my $str;
-
- foreach $category (@categories) {
-
- foreach $key (sort keys %{ $form->{$category} }) {
- # push description onto array
-
- $str = ($form->{l_heading}) ? $form->{padding} : "";
-
- if ($form->{$category}{$key}{charttype} eq "A") {
- $str .=
- ($form->{l_accno})
- ? "$form->{$category}{$key}{accno} - $form->{$category}{$key}{description}"
- : "$form->{$category}{$key}{description}";
- }
- if ($form->{$category}{$key}{charttype} eq "H") {
- if ($account{$category}{subtotal}
- && $form->{l_subtotal}) {
-
- $dash = "- ";
- push(@{$form->{"$account{$category}{label}_account"}},
- "$str$form->{bold}$account{$category}{subdescription}$form->{endbold}");
-
- push(@{$form->{"$account{$category}{labels}_this_period"}},
- $form->format_amount(
- $myconfig,
- $account{$category}{subthis}
- * $account{$category}{ml},
- $form->{decimalplaces},
- $dash));
-
- if ($last_period) {
- # Chris T: Giving up on
- # Formatting this one :-(
- push(@{$form->{"$account{$category}{labels}_last_period"}}, $form->format_amount($myconfig, $account{$category}{sublast} * $account{$category}{ml}, $form->{decimalplaces}, $dash));
- }
-
- }
-
- $str = "$form->{br}$form->{bold}$form->{$category}{$key}{description}$form->{endbold}";
-
- $account{$category}{subthis}
- = $form->{$category}{$key}{this};
- $account{$category}{sublast}
- = $form->{$category}{$key}{last};
- $account{$category}{subdescription}
- = $form->{$category}{$key}{description};
- $account{$category}{subtotal} = 1;
-
- $form->{$category}{$key}{this} = 0;
- $form->{$category}{$key}{last} = 0;
-
- next unless $form->{l_heading};
-
- $dash = " ";
- }
-
- push(@{$form->{"$account{$category}{label}_account"}},
- $str);
-
- if ($form->{$category}{$key}{charttype} eq 'A') {
- $form->{"total_$account{$category}{labels}_this_period"} += $form->{$category}{$key}{this} * $account{$category}{ml};
-
- $dash = "- ";
- }
-
- push(@{$form->{"$account{$category}{labels}_this_period"}}, $form->format_amount($myconfig, $form->{$category}{$key}{this} * $account{$category}{ml}, $form->{decimalplaces}, $dash));
-
- # add amount or - for last period
- if ($last_period) {
- $form->{"total_$account{$category}{labels}_last_period"} += $form->{$category}{$key}{last} * $account{$category}{ml};
-
- push(@{$form->{"$account{$category}{labels}_last_period"}}, $form->format_amount($myconfig,$form->{$category}{$key}{last} * $account{$category}{ml}, $form->{decimalplaces}, $dash));
- }
- }
-
- $str = ($form->{l_heading}) ? $form->{padding} : "";
- if ($account{$category}{subtotal} && $form->{l_subtotal}) {
- push(@{$form->{"$account{$category}{label}_account"}}, "$str$form->{bold}$account{$category}{subdescription}$form->{endbold}");
- push(@{$form->{"$account{$category}{labels}_this_period"}}, $form->format_amount($myconfig, $account{$category}{subthis} * $account{$category}{ml}, $form->{decimalplaces}, $dash));
-
- if ($last_period) {
- push(@{$form->{"$account{$category}{labels}_last_period"}}, $form->format_amount($myconfig, $account{$category}{sublast} * $account{$category}{ml}, $form->{decimalplaces}, $dash));
- }
- }
-
- }
-
-
- # totals for income and expenses
- $form->{total_income_this_period} = $form->round_amount($form->{total_income_this_period}, $form->{decimalplaces});
- $form->{total_expenses_this_period} = $form->round_amount($form->{total_expenses_this_period}, $form->{decimalplaces});
-
- # total for income/loss
- $form->{total_this_period} = $form->{total_income_this_period} - $form->{total_expenses_this_period};
-
- if ($last_period) {
- # total for income/loss
- $form->{total_last_period} = $form->format_amount($myconfig, $form->{total_income_last_period} - $form->{total_expenses_last_period}, $form->{decimalplaces}, "- ");
-
- # totals for income and expenses for last_period
- $form->{total_income_last_period} = $form->format_amount($myconfig, $form->{total_income_last_period}, $form->{decimalplaces}, "- ");
- $form->{total_expenses_last_period} = $form->format_amount($myconfig, $form->{total_expenses_last_period}, $form->{decimalplaces}, "- ");
-
- }
-
-
- $form->{total_income_this_period} = $form->format_amount($myconfig,$form->{total_income_this_period}, $form->{decimalplaces}, "- ");
- $form->{total_expenses_this_period} = $form->format_amount($myconfig,$form->{total_expenses_this_period}, $form->{decimalplaces}, "- ");
- $form->{total_this_period} = $form->format_amount($myconfig,$form->{total_this_period}, $form->{decimalplaces}, "- ");
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my $last_period = 0;
+ my @categories = qw(I E);
+ my $category;
+
+ $form->{decimalplaces} *= 1;
+
+ if ( !( $form->{fromdate} || $form->{todate} ) ) {
+ if ( $form->{fromyear} && $form->{frommonth} ) {
+ ( $form->{fromdate}, $form->{todate} ) =
+ $form->from_to( $form->{fromyear}, $form->{frommonth},
+ $form->{interval} );
+ }
+ }
+
+ &get_accounts( $dbh, $last_period, $form->{fromdate}, $form->{todate},
+ $form, \@categories, 1 );
+
+ if ( !( $form->{comparefromdate} || $form->{comparetodate} ) ) {
+ if ( $form->{compareyear} && $form->{comparemonth} ) {
+ ( $form->{comparefromdate}, $form->{comparetodate} ) =
+ $form->from_to( $form->{compareyear}, $form->{comparemonth},
+ $form->{interval} );
+ }
+ }
+
+ # if there are any compare dates
+ if ( $form->{comparefromdate} || $form->{comparetodate} ) {
+ $last_period = 1;
+
+ &get_accounts(
+ $dbh, $last_period,
+ $form->{comparefromdate},
+ $form->{comparetodate},
+ $form, \@categories, 1
+ );
+ }
+
+ $dbh->commit;
+
+ # now we got $form->{I}{accno}{ }
+ # and $form->{E}{accno}{ }
+
+ my %account = (
+ 'I' => {
+ 'label' => 'income',
+ 'labels' => 'income',
+ 'ml' => 1
+ },
+ 'E' => {
+ 'label' => 'expense',
+ 'labels' => 'expenses',
+ 'ml' => -1
+ }
+ );
+
+ my $str;
+
+ foreach $category (@categories) {
+
+ foreach $key ( sort keys %{ $form->{$category} } ) {
+
+ # push description onto array
+
+ $str = ( $form->{l_heading} ) ? $form->{padding} : "";
+
+ if ( $form->{$category}{$key}{charttype} eq "A" ) {
+ $str .=
+ ( $form->{l_accno} )
+ ? "$form->{$category}{$key}{accno} - $form->{$category}{$key}{description}"
+ : "$form->{$category}{$key}{description}";
+ }
+ if ( $form->{$category}{$key}{charttype} eq "H" ) {
+ if ( $account{$category}{subtotal}
+ && $form->{l_subtotal} )
+ {
+
+ $dash = "- ";
+ push(
+ @{ $form->{"$account{$category}{label}_account"} },
+"$str$form->{bold}$account{$category}{subdescription}$form->{endbold}"
+ );
+
+ push(
+ @{
+ $form->{"$account{$category}{labels}_this_period"}
+ },
+ $form->format_amount(
+ $myconfig,
+ $account{$category}{subthis} *
+ $account{$category}{ml},
+ $form->{decimalplaces},
+ $dash
+ )
+ );
+
+ if ($last_period) {
+
+ # Chris T: Giving up on
+ # Formatting this one :-(
+ push(
+ @{
+ $form->{
+ "$account{$category}{labels}_last_period"}
+ },
+ $form->format_amount(
+ $myconfig,
+ $account{$category}{sublast} *
+ $account{$category}{ml},
+ $form->{decimalplaces},
+ $dash
+ )
+ );
+ }
+
+ }
+
+ $str =
+"$form->{br}$form->{bold}$form->{$category}{$key}{description}$form->{endbold}";
+
+ $account{$category}{subthis} = $form->{$category}{$key}{this};
+ $account{$category}{sublast} = $form->{$category}{$key}{last};
+ $account{$category}{subdescription} =
+ $form->{$category}{$key}{description};
+ $account{$category}{subtotal} = 1;
+
+ $form->{$category}{$key}{this} = 0;
+ $form->{$category}{$key}{last} = 0;
+
+ next unless $form->{l_heading};
+
+ $dash = " ";
+ }
+
+ push( @{ $form->{"$account{$category}{label}_account"} }, $str );
+
+ if ( $form->{$category}{$key}{charttype} eq 'A' ) {
+ $form->{"total_$account{$category}{labels}_this_period"} +=
+ $form->{$category}{$key}{this} * $account{$category}{ml};
+
+ $dash = "- ";
+ }
+
+ push(
+ @{ $form->{"$account{$category}{labels}_this_period"} },
+ $form->format_amount(
+ $myconfig,
+ $form->{$category}{$key}{this} * $account{$category}{ml},
+ $form->{decimalplaces}, $dash
+ )
+ );
+
+ # add amount or - for last period
+ if ($last_period) {
+ $form->{"total_$account{$category}{labels}_last_period"} +=
+ $form->{$category}{$key}{last} * $account{$category}{ml};
+
+ push(
+ @{ $form->{"$account{$category}{labels}_last_period"} },
+ $form->format_amount(
+ $myconfig,
+ $form->{$category}{$key}{last} *
+ $account{$category}{ml},
+ $form->{decimalplaces},
+ $dash
+ )
+ );
+ }
+ }
+
+ $str = ( $form->{l_heading} ) ? $form->{padding} : "";
+ if ( $account{$category}{subtotal} && $form->{l_subtotal} ) {
+ push(
+ @{ $form->{"$account{$category}{label}_account"} },
+"$str$form->{bold}$account{$category}{subdescription}$form->{endbold}"
+ );
+ push(
+ @{ $form->{"$account{$category}{labels}_this_period"} },
+ $form->format_amount(
+ $myconfig,
+ $account{$category}{subthis} * $account{$category}{ml},
+ $form->{decimalplaces}, $dash
+ )
+ );
+
+ if ($last_period) {
+ push(
+ @{ $form->{"$account{$category}{labels}_last_period"} },
+ $form->format_amount(
+ $myconfig,
+ $account{$category}{sublast} * $account{$category}{ml},
+ $form->{decimalplaces},
+ $dash
+ )
+ );
+ }
+ }
+
+ }
+
+ # totals for income and expenses
+ $form->{total_income_this_period} =
+ $form->round_amount( $form->{total_income_this_period},
+ $form->{decimalplaces} );
+ $form->{total_expenses_this_period} =
+ $form->round_amount( $form->{total_expenses_this_period},
+ $form->{decimalplaces} );
+
+ # total for income/loss
+ $form->{total_this_period} =
+ $form->{total_income_this_period} - $form->{total_expenses_this_period};
+
+ if ($last_period) {
+
+ # total for income/loss
+ $form->{total_last_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_income_last_period} -
+ $form->{total_expenses_last_period},
+ $form->{decimalplaces},
+ "- "
+ );
+
+ # totals for income and expenses for last_period
+ $form->{total_income_last_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_income_last_period},
+ $form->{decimalplaces}, "- "
+ );
+ $form->{total_expenses_last_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_expenses_last_period},
+ $form->{decimalplaces}, "- "
+ );
+
+ }
+
+ $form->{total_income_this_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_income_this_period},
+ $form->{decimalplaces}, "- "
+ );
+ $form->{total_expenses_this_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_expenses_this_period},
+ $form->{decimalplaces}, "- "
+ );
+ $form->{total_this_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_this_period},
+ $form->{decimalplaces}, "- "
+ );
}
-
sub balance_sheet {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my $last_period = 0;
- my @categories = qw(A L Q);
-
- my $null;
-
- if ($form->{asofdate}) {
- if ($form->{asofyear} && $form->{asofmonth}) {
- if ($form->{asofdate} !~ /\W/) {
- $form->{asofdate}
- = "$form->{asofyear}$form->{asofmonth}$form->{asofdate}";
- }
- }
- } else {
- if ($form->{asofyear} && $form->{asofmonth}) {
- ($null, $form->{asofdate})
- = $form->from_to(
- $form->{asofyear}, $form->{asofmonth});
- }
- }
-
- # if there are any dates construct a where
- if ($form->{asofdate}) {
-
- $form->{this_period} = "$form->{asofdate}";
- $form->{period} = "$form->{asofdate}";
-
- }
-
- $form->{decimalplaces} *= 1;
-
- &get_accounts(
- $dbh, $last_period, "", $form->{asofdate}, $form,
- \@categories, 1);
-
- if ($form->{compareasofdate}) {
- if ($form->{compareasofyear} && $form->{compareasofmonth}) {
- if ($form->{compareasofdate} !~ /\W/) {
- $form->{compareasofdate} = "$form->{compareasofyear}$form->{compareasofmonth}$form->{compareasofdate}";
- }
- }
- } else {
- if ($form->{compareasofyear} && $form->{compareasofmonth}) {
- ($null, $form->{compareasofdate}) = $form->from_to(
- $form->{compareasofyear},
- $form->{compareasofmonth});
- }
- }
-
- # if there are any compare dates
- if ($form->{compareasofdate}) {
-
- $last_period = 1;
- &get_accounts(
- $dbh, $last_period, "", $form->{compareasofdate},
- $form, \@categories, 1);
-
- $form->{last_period} = "$form->{compareasofdate}";
-
- }
-
-
- $dbh->commit;
-
-
- # now we got $form->{A}{accno}{ } assets
- # and $form->{L}{accno}{ } liabilities
- # and $form->{Q}{accno}{ } equity
- # build asset accounts
-
- my $str;
- my $key;
-
- my %account = (
- 'A' => {
- 'label' => 'asset',
- 'labels' => 'assets',
- 'ml' => -1 },
- 'L' => {
- 'label' => 'liability',
- 'labels' => 'liabilities',
- 'ml' => 1 },
- 'Q' => {
- 'label' => 'equity',
- 'labels' => 'equity',
- 'ml' => 1 }
- );
-
-
- foreach $category (@categories) {
-
- foreach $key (sort keys %{ $form->{$category} }) {
-
- $str = ($form->{l_heading}) ? $form->{padding} : "";
-
- if ($form->{$category}{$key}{charttype} eq "A") {
- $str .=
- ($form->{l_accno})
- ? "$form->{$category}{$key}{accno} - $form->{$category}{$key}{description}"
- : "$form->{$category}{$key}{description}";
- }
- if ($form->{$category}{$key}{charttype} eq "H") {
- if ($account{$category}{subtotal}
- && $form->{l_subtotal}) {
-
- $dash = "- ";
- push(@{$form->{"$account{$category}{label}_account"}}, "$str$form->{bold}$account{$category}{subdescription}$form->{endbold}");
- push(@{$form->{"$account{$category}{label}_this_period"}}, $form->format_amount($myconfig, $account{$category}{subthis} * $account{$category}{ml}, $form->{decimalplaces}, $dash));
-
- if ($last_period) {
- push(@{$form->{"$account{$category}{label}_last_period"}}, $form->format_amount($myconfig, $account{$category}{sublast} * $account{$category}{ml}, $form->{decimalplaces}, $dash));
- }
- }
-
- $str = "$form->{bold}$form->{$category}{$key}{description}$form->{endbold}";
-
- $account{$category}{subthis} = $form->{$category}{$key}{this};
- $account{$category}{sublast} = $form->{$category}{$key}{last};
- $account{$category}{subdescription} = $form->{$category}{$key}{description};
- $account{$category}{subtotal} = 1;
-
- $form->{$category}{$key}{this} = 0;
- $form->{$category}{$key}{last} = 0;
-
- next unless $form->{l_heading};
-
- $dash = " ";
- }
-
- # push description onto array
- push(@{$form->{"$account{$category}{label}_account"}},
- $str);
-
- if ($form->{$category}{$key}{charttype} eq 'A') {
- $form->{"total_$account{$category}{labels}_this_period"} += $form->{$category}{$key}{this} * $account{$category}{ml};
- $dash = "- ";
- }
-
- push(@{$form->{"$account{$category}{label}_this_period"}}, $form->format_amount($myconfig, $form->{$category}{$key}{this} * $account{$category}{ml}, $form->{decimalplaces}, $dash));
-
- if ($last_period) {
- $form->{"total_$account{$category}{labels}_last_period"} += $form->{$category}{$key}{last} * $account{$category}{ml};
-
- push(@{$form->{"$account{$category}{label}_last_period"}}, $form->format_amount($myconfig, $form->{$category}{$key}{last} * $account{$category}{ml}, $form->{decimalplaces}, $dash));
- }
- }
-
- $str = ($form->{l_heading}) ? $form->{padding} : "";
- if ($account{$category}{subtotal} && $form->{l_subtotal}) {
- push(@{$form->{"$account{$category}{label}_account"}}, "$str$form->{bold}$account{$category}{subdescription}$form->{endbold}");
- push(@{$form->{"$account{$category}{label}_this_period"}}, $form->format_amount($myconfig, $account{$category}{subthis} * $account{$category}{ml}, $form->{decimalplaces}, $dash));
-
- if ($last_period) {
- push(@{$form->{"$account{$category}{label}_last_period"}}, $form->format_amount($myconfig, $account{$category}{sublast} * $account{$category}{ml}, $form->{decimalplaces}, $dash));
- }
- }
-
- }
-
-
- # totals for assets, liabilities
- $form->{total_assets_this_period} = $form->round_amount(
- $form->{total_assets_this_period}, $form->{decimalplaces});
- $form->{total_liabilities_this_period} = $form->round_amount(
- $form->{total_liabilities_this_period},
- $form->{decimalplaces});
- $form->{total_equity_this_period} = $form->round_amount(
- $form->{total_equity_this_period}, $form->{decimalplaces});
-
- # calculate earnings
- $form->{earnings_this_period} = $form->{total_assets_this_period}
- - $form->{total_liabilities_this_period}
- - $form->{total_equity_this_period};
-
- push(@{$form->{equity_this_period}},
- $form->format_amount(
- $myconfig, $form->{earnings_this_period},
- $form->{decimalplaces}, "- "));
-
- $form->{total_equity_this_period} = $form->round_amount(
- $form->{total_equity_this_period}
- + $form->{earnings_this_period},
- $form->{decimalplaces});
-
- # add liability + equity
- $form->{total_this_period} = $form->format_amount(
- $myconfig,
- $form->{total_liabilities_this_period}
- + $form->{total_equity_this_period},
- $form->{decimalplaces}, "- ");
-
-
- if ($last_period) {
- # totals for assets, liabilities
- $form->{total_assets_last_period} = $form->round_amount(
- $form->{total_assets_last_period},
- $form->{decimalplaces});
- $form->{total_liabilities_last_period} = $form->round_amount(
- $form->{total_liabilities_last_period},
- $form->{decimalplaces});
- $form->{total_equity_last_period} = $form->round_amount(
- $form->{total_equity_last_period},
- $form->{decimalplaces});
-
- # calculate retained earnings
- $form->{earnings_last_period}
- = $form->{total_assets_last_period}
- - $form->{total_liabilities_last_period}
- - $form->{total_equity_last_period};
-
- push(@{$form->{equity_last_period}},
- $form->format_amount(
- $myconfig,$form->{earnings_last_period},
- $form->{decimalplaces}, "- "));
-
- $form->{total_equity_last_period} = $form->round_amount(
- $form->{total_equity_last_period}
- + $form->{earnings_last_period},
- $form->{decimalplaces});
-
- # add liability + equity
- $form->{total_last_period} = $form->format_amount(
- $myconfig,
- $form->{total_liabilities_last_period}
- + $form->{total_equity_last_period},
- $form->{decimalplaces}, "- ");
-
- }
-
-
- $form->{total_liabilities_last_period} = $form->format_amount(
- $myconfig, $form->{total_liabilities_last_period},
- $form->{decimalplaces}, "- ")
- if ($form->{total_liabilities_last_period});
-
- $form->{total_equity_last_period} = $form->format_amount(
- $myconfig, $form->{total_equity_last_period},
- $form->{decimalplaces}, "- ")
- if ($form->{total_equity_last_period});
-
- $form->{total_assets_last_period} = $form->format_amount(
- $myconfig, $form->{total_assets_last_period},
- $form->{decimalplaces}, "- ")
- if ($form->{total_assets_last_period});
-
- $form->{total_assets_this_period} = $form->format_amount(
- $myconfig, $form->{total_assets_this_period},
- $form->{decimalplaces}, "- ");
-
- $form->{total_liabilities_this_period} = $form->format_amount(
- $myconfig, $form->{total_liabilities_this_period},
- $form->{decimalplaces}, "- ");
-
- $form->{total_equity_this_period} = $form->format_amount(
- $myconfig, $form->{total_equity_this_period},
- $form->{decimalplaces}, "- ");
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my $last_period = 0;
+ my @categories = qw(A L Q);
+
+ my $null;
+
+ if ( $form->{asofdate} ) {
+ if ( $form->{asofyear} && $form->{asofmonth} ) {
+ if ( $form->{asofdate} !~ /\W/ ) {
+ $form->{asofdate} =
+ "$form->{asofyear}$form->{asofmonth}$form->{asofdate}";
+ }
+ }
+ }
+ else {
+ if ( $form->{asofyear} && $form->{asofmonth} ) {
+ ( $null, $form->{asofdate} ) =
+ $form->from_to( $form->{asofyear}, $form->{asofmonth} );
+ }
+ }
+
+ # if there are any dates construct a where
+ if ( $form->{asofdate} ) {
+
+ $form->{this_period} = "$form->{asofdate}";
+ $form->{period} = "$form->{asofdate}";
+
+ }
+
+ $form->{decimalplaces} *= 1;
+
+ &get_accounts( $dbh, $last_period, "", $form->{asofdate}, $form,
+ \@categories, 1 );
+
+ if ( $form->{compareasofdate} ) {
+ if ( $form->{compareasofyear} && $form->{compareasofmonth} ) {
+ if ( $form->{compareasofdate} !~ /\W/ ) {
+ $form->{compareasofdate} =
+"$form->{compareasofyear}$form->{compareasofmonth}$form->{compareasofdate}";
+ }
+ }
+ }
+ else {
+ if ( $form->{compareasofyear} && $form->{compareasofmonth} ) {
+ ( $null, $form->{compareasofdate} ) =
+ $form->from_to( $form->{compareasofyear},
+ $form->{compareasofmonth} );
+ }
+ }
+
+ # if there are any compare dates
+ if ( $form->{compareasofdate} ) {
+
+ $last_period = 1;
+ &get_accounts( $dbh, $last_period, "", $form->{compareasofdate},
+ $form, \@categories, 1 );
+
+ $form->{last_period} = "$form->{compareasofdate}";
+
+ }
+
+ $dbh->commit;
+
+ # now we got $form->{A}{accno}{ } assets
+ # and $form->{L}{accno}{ } liabilities
+ # and $form->{Q}{accno}{ } equity
+ # build asset accounts
+
+ my $str;
+ my $key;
+
+ my %account = (
+ 'A' => {
+ 'label' => 'asset',
+ 'labels' => 'assets',
+ 'ml' => -1
+ },
+ 'L' => {
+ 'label' => 'liability',
+ 'labels' => 'liabilities',
+ 'ml' => 1
+ },
+ 'Q' => {
+ 'label' => 'equity',
+ 'labels' => 'equity',
+ 'ml' => 1
+ }
+ );
+
+ foreach $category (@categories) {
+
+ foreach $key ( sort keys %{ $form->{$category} } ) {
+
+ $str = ( $form->{l_heading} ) ? $form->{padding} : "";
+
+ if ( $form->{$category}{$key}{charttype} eq "A" ) {
+ $str .=
+ ( $form->{l_accno} )
+ ? "$form->{$category}{$key}{accno} - $form->{$category}{$key}{description}"
+ : "$form->{$category}{$key}{description}";
+ }
+ if ( $form->{$category}{$key}{charttype} eq "H" ) {
+ if ( $account{$category}{subtotal}
+ && $form->{l_subtotal} )
+ {
+
+ $dash = "- ";
+ push(
+ @{ $form->{"$account{$category}{label}_account"} },
+"$str$form->{bold}$account{$category}{subdescription}$form->{endbold}"
+ );
+ push(
+ @{ $form->{"$account{$category}{label}_this_period"} },
+ $form->format_amount(
+ $myconfig,
+ $account{$category}{subthis} *
+ $account{$category}{ml},
+ $form->{decimalplaces},
+ $dash
+ )
+ );
+
+ if ($last_period) {
+ push(
+ @{
+ $form->{
+ "$account{$category}{label}_last_period"}
+ },
+ $form->format_amount(
+ $myconfig,
+ $account{$category}{sublast} *
+ $account{$category}{ml},
+ $form->{decimalplaces},
+ $dash
+ )
+ );
+ }
+ }
+
+ $str =
+"$form->{bold}$form->{$category}{$key}{description}$form->{endbold}";
+
+ $account{$category}{subthis} = $form->{$category}{$key}{this};
+ $account{$category}{sublast} = $form->{$category}{$key}{last};
+ $account{$category}{subdescription} =
+ $form->{$category}{$key}{description};
+ $account{$category}{subtotal} = 1;
+
+ $form->{$category}{$key}{this} = 0;
+ $form->{$category}{$key}{last} = 0;
+
+ next unless $form->{l_heading};
+
+ $dash = " ";
+ }
+
+ # push description onto array
+ push( @{ $form->{"$account{$category}{label}_account"} }, $str );
+
+ if ( $form->{$category}{$key}{charttype} eq 'A' ) {
+ $form->{"total_$account{$category}{labels}_this_period"} +=
+ $form->{$category}{$key}{this} * $account{$category}{ml};
+ $dash = "- ";
+ }
+
+ push(
+ @{ $form->{"$account{$category}{label}_this_period"} },
+ $form->format_amount(
+ $myconfig,
+ $form->{$category}{$key}{this} * $account{$category}{ml},
+ $form->{decimalplaces}, $dash
+ )
+ );
+
+ if ($last_period) {
+ $form->{"total_$account{$category}{labels}_last_period"} +=
+ $form->{$category}{$key}{last} * $account{$category}{ml};
+
+ push(
+ @{ $form->{"$account{$category}{label}_last_period"} },
+ $form->format_amount(
+ $myconfig,
+ $form->{$category}{$key}{last} *
+ $account{$category}{ml},
+ $form->{decimalplaces},
+ $dash
+ )
+ );
+ }
+ }
+
+ $str = ( $form->{l_heading} ) ? $form->{padding} : "";
+ if ( $account{$category}{subtotal} && $form->{l_subtotal} ) {
+ push(
+ @{ $form->{"$account{$category}{label}_account"} },
+"$str$form->{bold}$account{$category}{subdescription}$form->{endbold}"
+ );
+ push(
+ @{ $form->{"$account{$category}{label}_this_period"} },
+ $form->format_amount(
+ $myconfig,
+ $account{$category}{subthis} * $account{$category}{ml},
+ $form->{decimalplaces}, $dash
+ )
+ );
+
+ if ($last_period) {
+ push(
+ @{ $form->{"$account{$category}{label}_last_period"} },
+ $form->format_amount(
+ $myconfig,
+ $account{$category}{sublast} * $account{$category}{ml},
+ $form->{decimalplaces},
+ $dash
+ )
+ );
+ }
+ }
+
+ }
+
+ # totals for assets, liabilities
+ $form->{total_assets_this_period} =
+ $form->round_amount( $form->{total_assets_this_period},
+ $form->{decimalplaces} );
+ $form->{total_liabilities_this_period} =
+ $form->round_amount( $form->{total_liabilities_this_period},
+ $form->{decimalplaces} );
+ $form->{total_equity_this_period} =
+ $form->round_amount( $form->{total_equity_this_period},
+ $form->{decimalplaces} );
+
+ # calculate earnings
+ $form->{earnings_this_period} =
+ $form->{total_assets_this_period} -
+ $form->{total_liabilities_this_period} -
+ $form->{total_equity_this_period};
+
+ push(
+ @{ $form->{equity_this_period} },
+ $form->format_amount(
+ $myconfig, $form->{earnings_this_period},
+ $form->{decimalplaces}, "- "
+ )
+ );
+
+ $form->{total_equity_this_period} =
+ $form->round_amount(
+ $form->{total_equity_this_period} + $form->{earnings_this_period},
+ $form->{decimalplaces} );
+
+ # add liability + equity
+ $form->{total_this_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_liabilities_this_period} +
+ $form->{total_equity_this_period},
+ $form->{decimalplaces},
+ "- "
+ );
+
+ if ($last_period) {
+
+ # totals for assets, liabilities
+ $form->{total_assets_last_period} =
+ $form->round_amount( $form->{total_assets_last_period},
+ $form->{decimalplaces} );
+ $form->{total_liabilities_last_period} =
+ $form->round_amount( $form->{total_liabilities_last_period},
+ $form->{decimalplaces} );
+ $form->{total_equity_last_period} =
+ $form->round_amount( $form->{total_equity_last_period},
+ $form->{decimalplaces} );
+
+ # calculate retained earnings
+ $form->{earnings_last_period} =
+ $form->{total_assets_last_period} -
+ $form->{total_liabilities_last_period} -
+ $form->{total_equity_last_period};
+
+ push(
+ @{ $form->{equity_last_period} },
+ $form->format_amount(
+ $myconfig, $form->{earnings_last_period},
+ $form->{decimalplaces}, "- "
+ )
+ );
+
+ $form->{total_equity_last_period} =
+ $form->round_amount(
+ $form->{total_equity_last_period} + $form->{earnings_last_period},
+ $form->{decimalplaces} );
+
+ # add liability + equity
+ $form->{total_last_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_liabilities_last_period} +
+ $form->{total_equity_last_period},
+ $form->{decimalplaces},
+ "- "
+ );
+
+ }
+
+ $form->{total_liabilities_last_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_liabilities_last_period},
+ $form->{decimalplaces}, "- "
+ ) if ( $form->{total_liabilities_last_period} );
+
+ $form->{total_equity_last_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_equity_last_period},
+ $form->{decimalplaces}, "- "
+ ) if ( $form->{total_equity_last_period} );
+
+ $form->{total_assets_last_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_assets_last_period},
+ $form->{decimalplaces}, "- "
+ ) if ( $form->{total_assets_last_period} );
+
+ $form->{total_assets_this_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_assets_this_period},
+ $form->{decimalplaces}, "- "
+ );
+
+ $form->{total_liabilities_this_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_liabilities_this_period},
+ $form->{decimalplaces}, "- "
+ );
+
+ $form->{total_equity_this_period} = $form->format_amount(
+ $myconfig,
+ $form->{total_equity_this_period},
+ $form->{decimalplaces}, "- "
+ );
}
-
sub get_accounts {
- my ($dbh, $last_period, $fromdate, $todate, $form, $categories,
- $excludeyearend) = @_;
-
- my $department_id;
- my $project_id;
-
- ($null, $department_id) = split /--/, $form->{department};
- ($null, $project_id) = split /--/, $form->{projectnumber};
-
- my $query;
- my $dpt_where;
- my $dpt_join;
- my $project;
- my $where = "1 = 1";
- my $glwhere = "";
- my $subwhere = "";
- my $yearendwhere = "1 = 1";
- my $item;
-
- my $category = "AND (";
- foreach $item (@{ $categories }) {
- $category .= qq|c.category = |.$dbh->quote($item).qq| OR |;
- }
- $category =~ s/OR $/\)/;
-
-
- # get headings
- $query = qq|
+ my ( $dbh, $last_period, $fromdate, $todate, $form, $categories,
+ $excludeyearend )
+ = @_;
+
+ my $department_id;
+ my $project_id;
+
+ ( $null, $department_id ) = split /--/, $form->{department};
+ ( $null, $project_id ) = split /--/, $form->{projectnumber};
+
+ my $query;
+ my $dpt_where;
+ my $dpt_join;
+ my $project;
+ my $where = "1 = 1";
+ my $glwhere = "";
+ my $subwhere = "";
+ my $yearendwhere = "1 = 1";
+ my $item;
+
+ my $category = "AND (";
+ foreach $item ( @{$categories} ) {
+ $category .= qq|c.category = | . $dbh->quote($item) . qq| OR |;
+ }
+ $category =~ s/OR $/\)/;
+
+ # get headings
+ $query = qq|
SELECT accno, description, category
FROM chart c
WHERE c.charttype = 'H' $category
ORDER BY c.accno|;
- if ($form->{accounttype} eq 'gifi'){
- $query = qq|
+ if ( $form->{accounttype} eq 'gifi' ) {
+ $query = qq|
SELECT g.accno, g.description, c.category
FROM gifi g
JOIN chart c ON (c.gifi_accno = g.accno)
WHERE c.charttype = 'H' $category
ORDER BY g.accno|;
- }
-
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- my @headingaccounts = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)){
- $form->{$ref->{category}}{$ref->{accno}}{description}
- = "$ref->{description}";
-
- $form->{$ref->{category}}{$ref->{accno}}{charttype} = "H";
- $form->{$ref->{category}}{$ref->{accno}}{accno} = $ref->{accno};
-
- push @headingaccounts, $ref->{accno};
- }
-
- $sth->finish;
-
- if ($form->{method} eq 'cash' && !$todate) {
- ($todate) = $dbh->selectrow_array(qq|SELECT current_date|);
- }
-
- if ($fromdate) {
- if ($form->{method} eq 'cash') {
- $subwhere .= " AND transdate >= ".
- $dbh->quote($fromdate);
- $glwhere = " AND ac.transdate >= ".
- $dbh->quote($fromdate);
- } else {
- $where .= " AND ac.transdate >= ".
- $dbh->quote($fromdate);
- }
- }
-
- if ($todate) {
- $where .= " AND ac.transdate <= ".$dbh->quote($todate);
- $subwhere .= " AND transdate <= ".$dbh->quote($todate);
- $yearendwhere = "ac.transdate < ".$dbh->quote($todate);
- }
-
- if ($excludeyearend) {
- $ywhere = "
+ }
+
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ my @headingaccounts = ();
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $form->{ $ref->{category} }{ $ref->{accno} }{description} =
+ "$ref->{description}";
+
+ $form->{ $ref->{category} }{ $ref->{accno} }{charttype} = "H";
+ $form->{ $ref->{category} }{ $ref->{accno} }{accno} = $ref->{accno};
+
+ push @headingaccounts, $ref->{accno};
+ }
+
+ $sth->finish;
+
+ if ( $form->{method} eq 'cash' && !$todate ) {
+ ($todate) = $dbh->selectrow_array(qq|SELECT current_date|);
+ }
+
+ if ($fromdate) {
+ if ( $form->{method} eq 'cash' ) {
+ $subwhere .= " AND transdate >= " . $dbh->quote($fromdate);
+ $glwhere = " AND ac.transdate >= " . $dbh->quote($fromdate);
+ }
+ else {
+ $where .= " AND ac.transdate >= " . $dbh->quote($fromdate);
+ }
+ }
+
+ if ($todate) {
+ $where .= " AND ac.transdate <= " . $dbh->quote($todate);
+ $subwhere .= " AND transdate <= " . $dbh->quote($todate);
+ $yearendwhere = "ac.transdate < " . $dbh->quote($todate);
+ }
+
+ if ($excludeyearend) {
+ $ywhere = "
AND ac.trans_id NOT IN (SELECT trans_id FROM yearend)";
-
- if ($todate) {
- $ywhere = "
+
+ if ($todate) {
+ $ywhere = "
AND ac.trans_id NOT IN
(SELECT trans_id FROM yearend
- WHERE transdate <= ".$dbh->quote($todate).")";
- }
-
- if ($fromdate) {
- $ywhere = "
+ WHERE transdate <= " . $dbh->quote($todate) . ")";
+ }
+
+ if ($fromdate) {
+ $ywhere = "
AND ac.trans_id NOT IN
(SELECT trans_id FROM yearend
- WHERE transdate >= ".$dbh->quote($fromdate).
- ")";
- if ($todate) {
- $ywhere = "
+ WHERE transdate >= " . $dbh->quote($fromdate) . ")";
+ if ($todate) {
+ $ywhere = "
AND ac.trans_id NOT IN
(SELECT trans_id FROM yearend
WHERE transdate >= "
- .$dbh->quote($fromdate)."
- AND transdate <= ".
- $dbh->quote($todate).")";
- }
- }
- }
-
- if ($department_id) {
- $dpt_join = qq|
+ . $dbh->quote($fromdate) . "
+ AND transdate <= " . $dbh->quote($todate) . ")";
+ }
+ }
+ }
+
+ if ($department_id) {
+ $dpt_join = qq|
JOIN department t ON (a.department_id = t.id)|;
- $dpt_where = qq|
+ $dpt_where = qq|
AND t.id = $department_id|;
- }
+ }
- if ($project_id) {
- $project = qq|
+ if ($project_id) {
+ $project = qq|
AND ac.project_id = $project_id|;
- }
+ }
+ if ( $form->{accounttype} eq 'gifi' ) {
- if ($form->{accounttype} eq 'gifi') {
-
- if ($form->{method} eq 'cash') {
+ if ( $form->{method} eq 'cash' ) {
- $query = qq|
+ $query = qq|
SELECT g.accno, sum(ac.amount) AS amount,
g.description, c.category
FROM acc_trans ac
@@ -848,10 +1007,9 @@ sub get_accounts {
$project
GROUP BY c.category|;
- if ($excludeyearend) {
-
+ if ($excludeyearend) {
- $query .= qq|
+ $query .= qq|
UNION ALL
@@ -872,20 +1030,20 @@ sub get_accounts {
$dpt_where $project
GROUP BY g.accno, g.description,
c.category|;
- }
+ }
- } else {
+ }
+ else {
- if ($department_id) {
- $dpt_join = qq|
+ if ($department_id) {
+ $dpt_join = qq|
JOIN dpt_trans t
ON (t.trans_id = ac.trans_id)|;
- $dpt_where = qq|
- AND t.department_id = |.
- $dbh->quote($department_id);
- }
+ $dpt_where = qq|
+ AND t.department_id = | . $dbh->quote($department_id);
+ }
- $query = qq|
+ $query = qq|
SELECT g.accno, SUM(ac.amount) AS amount,
g.description, c.category
FROM acc_trans ac
@@ -907,9 +1065,9 @@ sub get_accounts {
AND c.gifi_accno = '' $project
GROUP BY c.category|;
- if ($excludeyearend) {
+ if ($excludeyearend) {
- $query .= qq|
+ $query .= qq|
UNION ALL
@@ -937,14 +1095,15 @@ sub get_accounts {
GROUP BY g.accno,
g.description,
c.category|;
- }
- }
-
- } else { # standard account
+ }
+ }
+
+ }
+ else { # standard account
- if ($form->{method} eq 'cash') {
+ if ( $form->{method} eq 'cash' ) {
- $query = qq|
+ $query = qq|
SELECT c.accno, sum(ac.amount) AS amount,
c.description, c.category
FROM acc_trans ac
@@ -985,11 +1144,11 @@ sub get_accounts {
$project
GROUP BY c.accno, c.description, c.category|;
- if ($excludeyearend) {
+ if ($excludeyearend) {
- # this is for the yearend
-
- $query .= qq|
+ # this is for the yearend
+
+ $query .= qq|
UNION ALL
@@ -1008,20 +1167,20 @@ sub get_accounts {
$project
GROUP BY c.accno, c.description,
c.category|;
- }
+ }
- } else {
-
- if ($department_id) {
- $dpt_join = qq|
+ }
+ else {
+
+ if ($department_id) {
+ $dpt_join = qq|
JOIN dpt_trans t
ON (t.trans_id = ac.trans_id)|;
- $dpt_where = qq| AND t.department_id = |.
- $dbh->quote($department_id);
- }
+ $dpt_where =
+ qq| AND t.department_id = | . $dbh->quote($department_id);
+ }
-
- $query = qq|
+ $query = qq|
SELECT c.accno, sum(ac.amount) AS amount,
c.description, c.category
FROM acc_trans ac
@@ -1031,9 +1190,9 @@ sub get_accounts {
$project
GROUP BY c.accno, c.description, c.category|;
- if ($excludeyearend) {
+ if ($excludeyearend) {
- $query .= qq|
+ $query .= qq|
UNION ALL
@@ -1052,115 +1211,109 @@ sub get_accounts {
$project
GROUP BY c.accno, c.description,
c.category|;
- }
- }
- }
-
- my @accno;
- my $accno;
- my $ref;
-
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- # get last heading account
- @accno = grep { $_ le "$ref->{accno}" } @headingaccounts;
- $accno = pop @accno;
- if ($accno && ($accno ne $ref->{accno}) ) {
- if ($last_period) {
- $form->{$ref->{category}}{$accno}{last}
- += $ref->{amount};
- } else {
- $form->{$ref->{category}}{$accno}{this}
- += $ref->{amount};
- }
- }
-
- $form->{$ref->{category}}{$ref->{accno}}{accno}
- = $ref->{accno};
- $form->{$ref->{category}}{$ref->{accno}}{description}
- = $ref->{description};
- $form->{$ref->{category}}{$ref->{accno}}{charttype} = "A";
-
- if ($last_period) {
- $form->{$ref->{category}}{$ref->{accno}}{last}
- += $ref->{amount};
- } else {
- $form->{$ref->{category}}{$ref->{accno}}{this}
- += $ref->{amount};
- }
- }
- $sth->finish;
-
-
- # remove accounts with zero balance
- foreach $category (@{ $categories }) {
- foreach $accno (keys %{ $form->{$category} }) {
- $form->{$category}{$accno}{last} = $form->round_amount(
- $form->{$category}{$accno}{last},
- $form->{decimalplaces});
- $form->{$category}{$accno}{this} = $form->round_amount(
- $form->{$category}{$accno}{this},
- $form->{decimalplaces});
-
- delete $form->{$category}{$accno}
- if ($form->{$category}{$accno}{this} == 0
- && $form->{$category}{$accno}{last}
- == 0);
- }
- }
+ }
+ }
+ }
+
+ my @accno;
+ my $accno;
+ my $ref;
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+
+ # get last heading account
+ @accno = grep { $_ le "$ref->{accno}" } @headingaccounts;
+ $accno = pop @accno;
+ if ( $accno && ( $accno ne $ref->{accno} ) ) {
+ if ($last_period) {
+ $form->{ $ref->{category} }{$accno}{last} += $ref->{amount};
+ }
+ else {
+ $form->{ $ref->{category} }{$accno}{this} += $ref->{amount};
+ }
+ }
+
+ $form->{ $ref->{category} }{ $ref->{accno} }{accno} = $ref->{accno};
+ $form->{ $ref->{category} }{ $ref->{accno} }{description} =
+ $ref->{description};
+ $form->{ $ref->{category} }{ $ref->{accno} }{charttype} = "A";
+
+ if ($last_period) {
+ $form->{ $ref->{category} }{ $ref->{accno} }{last} +=
+ $ref->{amount};
+ }
+ else {
+ $form->{ $ref->{category} }{ $ref->{accno} }{this} +=
+ $ref->{amount};
+ }
+ }
+ $sth->finish;
+
+ # remove accounts with zero balance
+ foreach $category ( @{$categories} ) {
+ foreach $accno ( keys %{ $form->{$category} } ) {
+ $form->{$category}{$accno}{last} =
+ $form->round_amount( $form->{$category}{$accno}{last},
+ $form->{decimalplaces} );
+ $form->{$category}{$accno}{this} =
+ $form->round_amount( $form->{$category}{$accno}{this},
+ $form->{decimalplaces} );
+
+ delete $form->{$category}{$accno}
+ if ( $form->{$category}{$accno}{this} == 0
+ && $form->{$category}{$accno}{last} == 0 );
+ }
+ }
}
+sub trial_balance {
+ my ( $self, $myconfig, $form ) = @_;
+ my $dbh = $form->{dbh};
-sub trial_balance {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my ($query, $sth, $ref);
- my %balance = ();
- my %trb = ();
- my $null;
- my $department_id;
- my $project_id;
- my @headingaccounts = ();
- my $dpt_where;
- my $dpt_join;
- my $project;
-
- my $where = "1 = 1";
- my $invwhere = $where;
-
- ($null, $department_id) = split /--/, $form->{department};
- ($null, $project_id) = split /--/, $form->{projectnumber};
-
- if ($department_id) {
- $dpt_join = qq|
+ my ( $query, $sth, $ref );
+ my %balance = ();
+ my %trb = ();
+ my $null;
+ my $department_id;
+ my $project_id;
+ my @headingaccounts = ();
+ my $dpt_where;
+ my $dpt_join;
+ my $project;
+
+ my $where = "1 = 1";
+ my $invwhere = $where;
+
+ ( $null, $department_id ) = split /--/, $form->{department};
+ ( $null, $project_id ) = split /--/, $form->{projectnumber};
+
+ if ($department_id) {
+ $dpt_join = qq|
JOIN dpt_trans t ON (ac.trans_id = t.trans_id)|;
- $dpt_where = qq|
- AND t.department_id = |.$dbh->quote($department_id);
- }
-
-
- if ($project_id) {
- $project = qq|
- AND ac.project_id = |.$dbh->quote($project_id);
- }
-
- ($form->{fromdate}, $form->{todate}) = $form->from_to(
- $form->{year}, $form->{month}, $form->{interval})
- if $form->{year} && $form->{month};
-
- # get beginning balances
- if ($form->{fromdate}) {
-
- if ($form->{accounttype} eq 'gifi') {
-
- $query = qq|
+ $dpt_where = qq|
+ AND t.department_id = | . $dbh->quote($department_id);
+ }
+
+ if ($project_id) {
+ $project = qq|
+ AND ac.project_id = | . $dbh->quote($project_id);
+ }
+
+ ( $form->{fromdate}, $form->{todate} ) =
+ $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
+ if $form->{year} && $form->{month};
+
+ # get beginning balances
+ if ( $form->{fromdate} ) {
+
+ if ( $form->{accounttype} eq 'gifi' ) {
+
+ $query = qq|
SELECT g.accno, c.category,
SUM(ac.amount) AS amount,
g.description, c.contra
@@ -1172,10 +1325,11 @@ sub trial_balance {
$dpt_where $project
GROUP BY g.accno, c.category, g.description,
c.contra|;
-
- } else {
-
- $query = qq|
+
+ }
+ else {
+
+ $query = qq|
SELECT c.accno, c.category,
SUM(ac.amount) AS amount,
c.description, c.contra
@@ -1186,83 +1340,74 @@ sub trial_balance {
$dpt_where $project
GROUP BY c.accno, c.category, c.description,
c.contra|;
-
- }
-
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{amount} = $form->round_amount($ref->{amount},
- 2);
- $balance{$ref->{accno}} = $ref->{amount};
-
- if ($form->{all_accounts}) {
- $trb{$ref->{accno}}{description}
- = $ref->{description};
- $trb{$ref->{accno}}{charttype}
- = 'A';
- $trb{$ref->{accno}}{category}
- = $ref->{category};
- $trb{$ref->{accno}}{contra}
- = $ref->{contra};
- }
-
- }
- $sth->finish;
-
- }
-
-
- # get headings
- $query = qq|
+
+ }
+
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{amount} = $form->round_amount( $ref->{amount}, 2 );
+ $balance{ $ref->{accno} } = $ref->{amount};
+
+ if ( $form->{all_accounts} ) {
+ $trb{ $ref->{accno} }{description} = $ref->{description};
+ $trb{ $ref->{accno} }{charttype} = 'A';
+ $trb{ $ref->{accno} }{category} = $ref->{category};
+ $trb{ $ref->{accno} }{contra} = $ref->{contra};
+ }
+
+ }
+ $sth->finish;
+
+ }
+
+ # get headings
+ $query = qq|
SELECT c.accno, c.description, c.category FROM chart c
WHERE c.charttype = 'H'
ORDER by c.accno|;
- if ($form->{accounttype} eq 'gifi'){
- $query = qq|
+ if ( $form->{accounttype} eq 'gifi' ) {
+ $query = qq|
SELECT g.accno, g.description, c.category, c.contra
FROM gifi g
JOIN chart c ON (c.gifi_accno = g.accno)
WHERE c.charttype = 'H'
ORDER BY g.accno|;
- }
-
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $trb{$ref->{accno}}{description} = $ref->{description};
- $trb{$ref->{accno}}{charttype} = 'H';
- $trb{$ref->{accno}}{category} = $ref->{category};
- $trb{$ref->{accno}}{contra} = $ref->{contra};
-
- push @headingaccounts, $ref->{accno};
- }
-
- $sth->finish;
-
-
- if ($form->{fromdate} || $form->{todate}) {
- if ($form->{fromdate}) {
- $where .= " AND ac.transdate >= "
- .$dbh->quote($form->{fromdate});
- $invwhere .= " AND a.transdate >= ".
- $dbh->quote($form->{fromdate});
- }
- if ($form->{todate}) {
- $where .= " AND ac.transdate <= ".
- $dbh->quote($form->{todate});
- $invwhere .= " AND a.transdate <= "
- .$dbh->quote($form->{todate});
- }
- }
-
-
- if ($form->{accounttype} eq 'gifi') {
-
- $query = qq|
+ }
+
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $trb{ $ref->{accno} }{description} = $ref->{description};
+ $trb{ $ref->{accno} }{charttype} = 'H';
+ $trb{ $ref->{accno} }{category} = $ref->{category};
+ $trb{ $ref->{accno} }{contra} = $ref->{contra};
+
+ push @headingaccounts, $ref->{accno};
+ }
+
+ $sth->finish;
+
+ if ( $form->{fromdate} || $form->{todate} ) {
+ if ( $form->{fromdate} ) {
+ $where .=
+ " AND ac.transdate >= " . $dbh->quote( $form->{fromdate} );
+ $invwhere .=
+ " AND a.transdate >= " . $dbh->quote( $form->{fromdate} );
+ }
+ if ( $form->{todate} ) {
+ $where .= " AND ac.transdate <= " . $dbh->quote( $form->{todate} );
+ $invwhere .=
+ " AND a.transdate <= " . $dbh->quote( $form->{todate} );
+ }
+ }
+
+ if ( $form->{accounttype} eq 'gifi' ) {
+
+ $query = qq|
SELECT g.accno, g.description, c.category,
SUM(ac.amount) AS amount, c.contra
FROM acc_trans ac
@@ -1272,10 +1417,11 @@ sub trial_balance {
WHERE $where $dpt_where $project
GROUP BY g.accno, g.description, c.category, c.contra
ORDER BY accno|;
-
- } else {
- $query = qq|
+ }
+ else {
+
+ $query = qq|
SELECT c.accno, c.description, c.category,
SUM(ac.amount) AS amount, c.contra
FROM acc_trans ac
@@ -1285,13 +1431,13 @@ sub trial_balance {
GROUP BY c.accno, c.description, c.category, c.contra
ORDER BY accno|;
- }
+ }
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- # prepare query for each account
- $query = qq|
+ # prepare query for each account
+ $query = qq|
SELECT (SELECT SUM(ac.amount) * -1 FROM acc_trans ac
JOIN chart c ON (c.id = ac.chart_id)
$dpt_join
@@ -1303,9 +1449,9 @@ sub trial_balance {
WHERE $where $dpt_where $project AND ac.amount > 0
AND c.accno = ?) AS credit |;
- if ($form->{accounttype} eq 'gifi') {
+ if ( $form->{accounttype} eq 'gifi' ) {
- $query = qq|
+ $query = qq|
SELECT (SELECT SUM(ac.amount) * -1
FROM acc_trans ac
JOIN chart c ON (c.id = ac.chart_id)
@@ -1319,187 +1465,176 @@ sub trial_balance {
$dpt_join
WHERE $where $dpt_where $project AND ac.amount > 0
AND c.gifi_accno = ?) AS credit|;
-
- }
-
- $drcr = $dbh->prepare($query);
-
- # calculate debit and credit for the period
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- $trb{$ref->{accno}}{description} = $ref->{description};
- $trb{$ref->{accno}}{charttype} = 'A';
- $trb{$ref->{accno}}{category} = $ref->{category};
- $trb{$ref->{accno}}{contra} = $ref->{contra};
- $trb{$ref->{accno}}{amount} += $ref->{amount};
- }
- $sth->finish;
-
- my ($debit, $credit);
-
- foreach my $accno (sort keys %trb) {
- $ref = ();
-
- $ref->{accno} = $accno;
- for (qw(description category contra charttype amount)) {
- $ref->{$_} = $trb{$accno}{$_};
- }
-
- $ref->{balance} = $balance{$ref->{accno}};
- if ($trb{$accno}{charttype} eq 'A') {
- if ($project_id) {
-
- if ($ref->{amount} < 0) {
- $ref->{debit} = $ref->{amount} * -1;
- } else {
- $ref->{credit} = $ref->{amount};
- }
- next if $form->round_amount(
- $ref->{amount}, 2) == 0;
-
- } else {
-
- # get DR/CR
- $drcr->execute($ref->{accno}, $ref->{accno})
- || $form->dberror($query);
-
- ($debit, $credit) = (0,0);
- while (($debit, $credit)
- = $drcr->fetchrow_array) {
- $ref->{debit} += $debit;
- $ref->{credit} += $credit;
- }
- $drcr->finish;
-
- }
-
- $ref->{debit} = $form->round_amount($ref->{debit}, 2);
- $ref->{credit}
- = $form->round_amount($ref->{credit}, 2);
-
- if (!$form->{all_accounts}) {
- next
- if $form->round_amount(
- $ref->{debit} + $ref->{credit},
- 2)
- == 0;
- }
- }
-
- # add subtotal
- @accno = grep { $_ le "$ref->{accno}" } @headingaccounts;
- $accno = pop @accno;
- if ($accno) {
- $trb{$accno}{debit} += $ref->{debit};
- $trb{$accno}{credit} += $ref->{credit};
- }
-
- push @{ $form->{TB} }, $ref;
-
- }
-
- $dbh->commit;
-
- # debits and credits for headings
- foreach $accno (@headingaccounts) {
- foreach $ref (@{ $form->{TB} }) {
- if ($accno eq $ref->{accno}) {
- $ref->{debit} = $trb{$accno}{debit};
- $ref->{credit} = $trb{$accno}{credit};
- }
- }
- }
+ }
+
+ $drcr = $dbh->prepare($query);
+
+ # calculate debit and credit for the period
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $trb{ $ref->{accno} }{description} = $ref->{description};
+ $trb{ $ref->{accno} }{charttype} = 'A';
+ $trb{ $ref->{accno} }{category} = $ref->{category};
+ $trb{ $ref->{accno} }{contra} = $ref->{contra};
+ $trb{ $ref->{accno} }{amount} += $ref->{amount};
+ }
+ $sth->finish;
+
+ my ( $debit, $credit );
+
+ foreach my $accno ( sort keys %trb ) {
+ $ref = ();
+
+ $ref->{accno} = $accno;
+ for (qw(description category contra charttype amount)) {
+ $ref->{$_} = $trb{$accno}{$_};
+ }
+
+ $ref->{balance} = $balance{ $ref->{accno} };
+
+ if ( $trb{$accno}{charttype} eq 'A' ) {
+ if ($project_id) {
+
+ if ( $ref->{amount} < 0 ) {
+ $ref->{debit} = $ref->{amount} * -1;
+ }
+ else {
+ $ref->{credit} = $ref->{amount};
+ }
+ next if $form->round_amount( $ref->{amount}, 2 ) == 0;
+
+ }
+ else {
+
+ # get DR/CR
+ $drcr->execute( $ref->{accno}, $ref->{accno} )
+ || $form->dberror($query);
+
+ ( $debit, $credit ) = ( 0, 0 );
+ while ( ( $debit, $credit ) = $drcr->fetchrow_array ) {
+ $ref->{debit} += $debit;
+ $ref->{credit} += $credit;
+ }
+ $drcr->finish;
+
+ }
+
+ $ref->{debit} = $form->round_amount( $ref->{debit}, 2 );
+ $ref->{credit} = $form->round_amount( $ref->{credit}, 2 );
+
+ if ( !$form->{all_accounts} ) {
+ next
+ if $form->round_amount( $ref->{debit} + $ref->{credit}, 2 ) ==
+ 0;
+ }
+ }
+
+ # add subtotal
+ @accno = grep { $_ le "$ref->{accno}" } @headingaccounts;
+ $accno = pop @accno;
+ if ($accno) {
+ $trb{$accno}{debit} += $ref->{debit};
+ $trb{$accno}{credit} += $ref->{credit};
+ }
+
+ push @{ $form->{TB} }, $ref;
+
+ }
+
+ $dbh->commit;
+
+ # debits and credits for headings
+ foreach $accno (@headingaccounts) {
+ foreach $ref ( @{ $form->{TB} } ) {
+ if ( $accno eq $ref->{accno} ) {
+ $ref->{debit} = $trb{$accno}{debit};
+ $ref->{credit} = $trb{$accno}{credit};
+ }
+ }
+ }
}
-
sub aging {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
- my $invoice = ($form->{arap} eq 'ar') ? 'is' : 'ir';
-
- my $query = qq|SELECT value FROM defaults WHERE setting_key = 'curr'|;
- ($form->{currencies}) = $dbh->selectrow_array($query);
-
- ($null, $form->{todate})
- = $form->from_to($form->{year}, $form->{month})
- if $form->{year} && $form->{month};
-
- if (! $form->{todate}) {
- $query = qq|SELECT current_date|;
- ($form->{todate}) = $dbh->selectrow_array($query);
- }
-
- my $where = "1 = 1";
- my $name;
- my $null;
- my $ref;
- my $transdate = ($form->{overdue}) ? "duedate" : "transdate";
-
- if ($form->{"$form->{ct}_id"}) {
- $where .= qq| AND ct.id = |.
- $dbh->quote($form->{"$form->{ct}_id"});
- } else {
- if ($form->{$form->{ct}} ne "") {
- $name = $dbh->quote($form->like(
- lc $form->{$form->{ct}}));
- $where .= qq| AND lower(ct.name) LIKE $name|
- if $form->{$form->{ct}};
- }
- }
-
- if ($form->{department}) {
- ($null, $department_id) = split /--/, $form->{department};
- $where .= qq| AND a.department_id = |.
- $dbh->quote($department_id);
- }
-
- # select outstanding vendors or customers, depends on $ct
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+ my $invoice = ( $form->{arap} eq 'ar' ) ? 'is' : 'ir';
+
+ my $query = qq|SELECT value FROM defaults WHERE setting_key = 'curr'|;
+ ( $form->{currencies} ) = $dbh->selectrow_array($query);
+
+ ( $null, $form->{todate} ) = $form->from_to( $form->{year}, $form->{month} )
+ if $form->{year} && $form->{month};
+
+ if ( !$form->{todate} ) {
+ $query = qq|SELECT current_date|;
+ ( $form->{todate} ) = $dbh->selectrow_array($query);
+ }
+
+ my $where = "1 = 1";
+ my $name;
+ my $null;
+ my $ref;
+ my $transdate = ( $form->{overdue} ) ? "duedate" : "transdate";
+
+ if ( $form->{"$form->{ct}_id"} ) {
+ $where .= qq| AND ct.id = | . $dbh->quote( $form->{"$form->{ct}_id"} );
+ }
+ else {
+ if ( $form->{ $form->{ct} } ne "" ) {
+ $name = $dbh->quote( $form->like( lc $form->{ $form->{ct} } ) );
+ $where .= qq| AND lower(ct.name) LIKE $name|
+ if $form->{ $form->{ct} };
+ }
+ }
+
+ if ( $form->{department} ) {
+ ( $null, $department_id ) = split /--/, $form->{department};
+ $where .= qq| AND a.department_id = | . $dbh->quote($department_id);
+ }
+
+ # select outstanding vendors or customers, depends on $ct
+ $query = qq|
SELECT DISTINCT ct.id, ct.name, ct.language_code
FROM $form->{ct} ct
JOIN $form->{arap} a ON (a.$form->{ct}_id = ct.id)
WHERE $where AND a.paid != a.amount
AND (a.$transdate <= ?)
ORDER BY ct.name|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{todate}) || $form->dberror;
-
- my @ot = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @ot, $ref;
- }
- $sth->finish;
-
- my $buysell = ($form->{arap} eq 'ar') ? 'buy' : 'sell';
-
- my $todate = $dbh->quote($form->{todate});
- my %interval = (
- 'c0' => "(date $todate - interval '0 days')",
- 'c30' => "(date $todate - interval '30 days')",
- 'c60' => "(date $todate - interval '60 days')",
- 'c90' => "(date $todate - interval '90 days')"
- );
-
-
-
- # for each company that has some stuff outstanding
- $form->{currencies} ||= ":";
-
-
- $where = qq|a.paid != a.amount AND c.id = ? AND a.curr = ?|;
-
- if ($department_id) {
- $where .= qq| AND a.department_id = |.
- $dbh->quote($department_id);
- }
-
- $query = "";
- my $union = "";
-
- if ($form->{c0}) {
- $query .= qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{todate} ) || $form->dberror;
+
+ my @ot = ();
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @ot, $ref;
+ }
+ $sth->finish;
+
+ my $buysell = ( $form->{arap} eq 'ar' ) ? 'buy' : 'sell';
+
+ my $todate = $dbh->quote( $form->{todate} );
+ my %interval = (
+ 'c0' => "(date $todate - interval '0 days')",
+ 'c30' => "(date $todate - interval '30 days')",
+ 'c60' => "(date $todate - interval '60 days')",
+ 'c90' => "(date $todate - interval '90 days')"
+ );
+
+ # for each company that has some stuff outstanding
+ $form->{currencies} ||= ":";
+
+ $where = qq|a.paid != a.amount AND c.id = ? AND a.curr = ?|;
+
+ if ($department_id) {
+ $where .= qq| AND a.department_id = | . $dbh->quote($department_id);
+ }
+
+ $query = "";
+ my $union = "";
+
+ if ( $form->{c0} ) {
+ $query .= qq|
SELECT c.id AS ctid, c.$form->{ct}number, c.name,
c.address1, c.address2, c.city, c.state,
c.zipcode, c.country, c.contact, c.email,
@@ -1520,13 +1655,13 @@ sub aging {
WHERE $where AND ( a.$transdate <= $interval{c0}
AND a.$transdate >= $interval{c30} )|;
- $union = qq|UNION|;
+ $union = qq|UNION|;
- }
-
- if ($form->{c30}) {
+ }
- $query .= qq|
+ if ( $form->{c30} ) {
+
+ $query .= qq|
$union
@@ -1549,13 +1684,13 @@ sub aging {
WHERE $where AND (a.$transdate < $interval{c30}
AND a.$transdate >= $interval{c60})|;
- $union = qq|UNION|;
+ $union = qq|UNION|;
- }
+ }
- if ($form->{c60}) {
+ if ( $form->{c60} ) {
- $query .= qq|
+ $query .= qq|
$union
SELECT c.id AS ctid, c.$form->{ct}number, c.name,
@@ -1577,13 +1712,13 @@ sub aging {
WHERE $where AND (a.$transdate < $interval{c60}
AND a.$transdate >= $interval{c90})|;
- $union = qq|UNION|;
+ $union = qq|UNION|;
- }
+ }
- if ($form->{c90}) {
+ if ( $form->{c90} ) {
- $query .= qq|
+ $query .= qq|
$union
SELECT c.id AS ctid, c.$form->{ct}number, c.name,
c.address1, c.address2, c.city, c.state,
@@ -1603,210 +1738,203 @@ sub aging {
JOIN $form->{ct} c ON (a.$form->{ct}_id = c.id)
WHERE $where
AND a.$transdate < $interval{c90}|;
- }
- $query .= qq| ORDER BY ctid, $transdate, invnumber|;
- $sth = $dbh->prepare($query) || $form->dberror($query);
-
- my @var = ();
-
- if ($form->{c0} + $form->{c30} + $form->{c60} + $form->{c90}) {
- foreach $curr (split /:/, $form->{currencies}) {
-
- foreach $item (@ot) {
-
- @var = ();
- for (qw(c0 c30 c60 c90)) {
- push @var, ($item->{id}, $curr)
- if $form->{$_} }
-
- $sth->execute(@var);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)){
- $ref->{module} =
- ($ref->{invoice})
- ? $invoice
- : $form->{arap};
- $ref->{module} = 'ps' if $ref->{till};
- $ref->{exchangerate} = 1
- unless $ref->{exchangerate};
- $ref->{language_code}
- = $item->{language_code};
- push @{ $form->{AG} }, $ref;
- }
- $sth->finish;
-
- }
- }
- }
-
- # get language
- my $query = qq|SELECT * FROM language ORDER BY 2|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{all_language} }, $ref;
- }
- $sth->finish;
-
- $dbh->commit;
+ }
+ $query .= qq| ORDER BY ctid, $transdate, invnumber|;
+ $sth = $dbh->prepare($query) || $form->dberror($query);
+
+ my @var = ();
+
+ if ( $form->{c0} + $form->{c30} + $form->{c60} + $form->{c90} ) {
+ foreach $curr ( split /:/, $form->{currencies} ) {
+
+ foreach $item (@ot) {
+
+ @var = ();
+ for (qw(c0 c30 c60 c90)) {
+ push @var, ( $item->{id}, $curr )
+ if $form->{$_};
+ }
+
+ $sth->execute(@var);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{module} =
+ ( $ref->{invoice} )
+ ? $invoice
+ : $form->{arap};
+ $ref->{module} = 'ps' if $ref->{till};
+ $ref->{exchangerate} = 1
+ unless $ref->{exchangerate};
+ $ref->{language_code} = $item->{language_code};
+ push @{ $form->{AG} }, $ref;
+ }
+ $sth->finish;
+
+ }
+ }
+ }
+
+ # get language
+ my $query = qq|SELECT * FROM language ORDER BY 2|;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{all_language} }, $ref;
+ }
+ $sth->finish;
+
+ $dbh->commit;
}
-
sub get_customer {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
- my $dbh = $form->{dbh};
+ my $dbh = $form->{dbh};
- my $query = qq|
+ my $query = qq|
SELECT name, email, cc, bcc FROM $form->{ct} ct
WHERE ct.id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($form->{"$form->{ct}_id"});
- ($form->{$form->{ct}}, $form->{email}, $form->{cc}, $form->{bcc})
- = $sth->fetchrow_array();
-
- $dbh->commit;
+ $sth = $dbh->prepare($query);
+ $sth->execute( $form->{"$form->{ct}_id"} );
+ ( $form->{ $form->{ct} }, $form->{email}, $form->{cc}, $form->{bcc} ) =
+ $sth->fetchrow_array();
-}
+ $dbh->commit;
+}
sub get_taxaccounts {
- my ($self, $myconfig, $form) = @_;
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+ my $ARAP = uc $form->{db};
- my $dbh = $form->{dbh};
- my $ARAP = uc $form->{db};
-
- # get tax accounts
- my $query = qq|
+ # get tax accounts
+ my $query = qq|
SELECT DISTINCT c.accno, c.description
FROM chart c
JOIN tax t ON (c.id = t.chart_id)
WHERE c.link LIKE '%${ARAP}_tax%'
ORDER BY c.accno|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror;
- my $ref = ();
- while ($ref = $sth->fetchrow_hashref(NAME_lc) ) {
- push @{ $form->{taxaccounts} }, $ref;
- }
- $sth->finish;
+ my $ref = ();
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{taxaccounts} }, $ref;
+ }
+ $sth->finish;
- # get gifi tax accounts
- my $query = qq|
+ # get gifi tax accounts
+ my $query = qq|
SELECT DISTINCT g.accno, g.description
FROM gifi g
JOIN chart c ON (c.gifi_accno= g.accno)
JOIN tax t ON (c.id = t.chart_id)
WHERE c.link LIKE '%${ARAP}_tax%'
ORDER BY accno|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror;
- while ($ref = $sth->fetchrow_hashref(NAME_lc) ) {
- push @{ $form->{gifi_taxaccounts} }, $ref;
- }
- $sth->finish;
+ while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{gifi_taxaccounts} }, $ref;
+ }
+ $sth->finish;
- $dbh->commit;
+ $dbh->commit;
}
-
-
sub tax_report {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my ($null, $department_id) = split /--/, $form->{department};
-
- # build WHERE
- my $where = "1 = 1";
- my $cashwhere = "";
-
- if ($department_id) {
- $where .= qq|AND a.department_id = |.
- $dbh->quote($department_id);
- }
-
- my $query;
- my $sth;
- my $accno;
-
- if ($form->{accno}) {
- if ($form->{accno} =~ /^gifi_/) {
- ($null, $accno) = split /_/, $form->{accno};
- $accno = $dbh->quote($accno);
- $accno = qq| AND ch.gifi_accno = $accno|;
- } else {
- $accno = $dbh->quote($form->{accno});
- $accno = qq| AND ch.accno = $accno|;
- }
- }
-
- my $table;
- my $ARAP;
-
- if ($form->{db} eq 'ar') {
- $table = "customer";
- $ARAP = "AR";
- }
- if ($form->{db} eq 'ap') {
- $table = "vendor";
- $ARAP = "AP";
- }
-
- my $transdate = "a.transdate";
-
- ($form->{fromdate}, $form->{todate}) =
- $form->from_to($form->{year},$form->{month}, $form->{interval})
- if $form->{year} && $form->{month};
-
- # if there are any dates construct a where
- if ($form->{fromdate} || $form->{todate}) {
- if ($form->{fromdate}) {
- $where .= " AND $transdate >= '$form->{fromdate}'";
- }
- if ($form->{todate}) {
- $where .= " AND $transdate <= '$form->{todate}'";
- }
- }
-
-
- if ($form->{method} eq 'cash') {
- $transdate = "a.datepaid";
-
- my $todate = $form->{todate};
- if (! $todate) {
- ($todate) = $dbh->selectrow_array(
- qq|SELECT current_date|);
- }
-
- $cashwhere = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my ( $null, $department_id ) = split /--/, $form->{department};
+
+ # build WHERE
+ my $where = "1 = 1";
+ my $cashwhere = "";
+
+ if ($department_id) {
+ $where .= qq|AND a.department_id = | . $dbh->quote($department_id);
+ }
+
+ my $query;
+ my $sth;
+ my $accno;
+
+ if ( $form->{accno} ) {
+ if ( $form->{accno} =~ /^gifi_/ ) {
+ ( $null, $accno ) = split /_/, $form->{accno};
+ $accno = $dbh->quote($accno);
+ $accno = qq| AND ch.gifi_accno = $accno|;
+ }
+ else {
+ $accno = $dbh->quote( $form->{accno} );
+ $accno = qq| AND ch.accno = $accno|;
+ }
+ }
+
+ my $table;
+ my $ARAP;
+
+ if ( $form->{db} eq 'ar' ) {
+ $table = "customer";
+ $ARAP = "AR";
+ }
+ if ( $form->{db} eq 'ap' ) {
+ $table = "vendor";
+ $ARAP = "AP";
+ }
+
+ my $transdate = "a.transdate";
+
+ ( $form->{fromdate}, $form->{todate} ) =
+ $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
+ if $form->{year} && $form->{month};
+
+ # if there are any dates construct a where
+ if ( $form->{fromdate} || $form->{todate} ) {
+ if ( $form->{fromdate} ) {
+ $where .= " AND $transdate >= '$form->{fromdate}'";
+ }
+ if ( $form->{todate} ) {
+ $where .= " AND $transdate <= '$form->{todate}'";
+ }
+ }
+
+ if ( $form->{method} eq 'cash' ) {
+ $transdate = "a.datepaid";
+
+ my $todate = $form->{todate};
+ if ( !$todate ) {
+ ($todate) = $dbh->selectrow_array(qq|SELECT current_date|);
+ }
+
+ $cashwhere = qq|
AND ac.trans_id IN (
SELECT trans_id
FROM acc_trans
JOIN chart ON (chart_id = chart.id)
WHERE link LIKE '%${ARAP}_paid%'
- AND $transdate <= |.$dbh->quote($todate).qq|
+ AND $transdate <= | . $dbh->quote($todate) . qq|
AND a.paid = a.amount)|;
- }
+ }
-
- my $ml = ($form->{db} eq 'ar') ? 1 : -1;
-
- my %ordinal = ( 'transdate' => 3, 'invnumber' => 4, 'name' => 5 );
-
- my @a = qw(transdate invnumber name);
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
- if ($form->{summary}) {
-
- $query = qq|
+ my $ml = ( $form->{db} eq 'ar' ) ? 1 : -1;
+
+ my %ordinal = ( 'transdate' => 3, 'invnumber' => 4, 'name' => 5 );
+
+ my @a = qw(transdate invnumber name);
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ if ( $form->{summary} ) {
+
+ $query = qq|
SELECT a.id, a.invoice, $transdate AS transdate,
a.invnumber, n.name, a.netamount,
ac.amount * $ml AS tax, a.till
@@ -1816,10 +1944,11 @@ sub tax_report {
JOIN $table n ON (n.id = a.${table}_id)
WHERE $where $accno $cashwhere |;
- if ($form->{fromdate}) {
- # include open transactions from previous period
- if ($cashwhere) {
- $query .= qq|
+ if ( $form->{fromdate} ) {
+
+ # include open transactions from previous period
+ if ($cashwhere) {
+ $query .= qq|
UNION
SELECT a.id, a.invoice,
@@ -1832,13 +1961,13 @@ sub tax_report {
JOIN $table n ON (n.id = a.${table}_id)
WHERE a.datepaid >= '$form->{fromdate}'
$accno $cashwhere|;
- }
- }
-
-
- } else {
+ }
+ }
- $query = qq|
+ }
+ else {
+
+ $query = qq|
SELECT a.id, '0' AS invoice, $transdate AS transdate,
a.invnumber, n.name, a.netamount,
ac.amount * $ml AS tax, a.notes AS description,
@@ -1873,9 +2002,9 @@ sub tax_report {
AND pt.chart_id = ch.id)
WHERE $where $accno AND a.invoice = '1' $cashwhere|;
- if ($form->{fromdate}) {
- if ($cashwhere) {
- $query .= qq|
+ if ( $form->{fromdate} ) {
+ if ($cashwhere) {
+ $query .= qq|
UNION
SELECT a.id, '0' AS invoice,
@@ -1924,16 +2053,16 @@ sub tax_report {
WHERE a.datepaid >= '$form->{fromdate}'
$accno AND a.invoice = '1'
$cashwhere|;
- }
- }
- }
+ }
+ }
+ }
+ if ( $form->{report} =~ /nontaxable/ ) {
- if ($form->{report} =~ /nontaxable/) {
-
- if ($form->{summary}) {
- # only gather up non-taxable transactions
- $query = qq|
+ if ( $form->{summary} ) {
+
+ # only gather up non-taxable transactions
+ $query = qq|
SELECT DISTINCT a.id, a.invoice,
$transdate AS transdate, a.invnumber,
n.name, a.netamount, a.till
@@ -1943,9 +2072,9 @@ sub tax_report {
WHERE $where AND a.netamount = a.amount
$cashwhere|;
- if ($form->{fromdate}) {
- if ($cashwhere) {
- $query .= qq|
+ if ( $form->{fromdate} ) {
+ if ($cashwhere) {
+ $query .= qq|
UNION
SELECT DISTINCT a.id, a.invoice,
@@ -1962,13 +2091,14 @@ sub tax_report {
AND
a.netamount = a.amount
$cashwhere|;
- }
- }
-
- } else {
+ }
+ }
+
+ }
+ else {
- # gather up details for non-taxable transactions
- $query = qq|
+ # gather up details for non-taxable transactions
+ $query = qq|
SELECT a.id, '0' AS invoice,
$transdate AS transdate, a.invnumber,
n.name, a.netamount,
@@ -2001,9 +2131,9 @@ sub tax_report {
GROUP BY a.id, a.invnumber, $transdate, n.name,
ac.description, a.till|;
- if ($form->{fromdate}) {
- if ($cashwhere) {
- $query .= qq|
+ if ( $form->{fromdate} ) {
+ if ($cashwhere) {
+ $query .= qq|
UNION
SELECT a.id, '0' AS invoice,
$transdate AS transdate,
@@ -2055,145 +2185,141 @@ sub tax_report {
GROUP BY a.id, a.invnumber,
$transdate, n.name,
ac.description, a.till|;
- }
- }
+ }
+ }
- }
- }
+ }
+ }
-
- $query .= qq| ORDER by $sortorder|;
+ $query .= qq| ORDER by $sortorder|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while ( my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{tax} = $form->round_amount($ref->{tax}, 2);
- if ($form->{report} =~ /nontaxable/) {
- push @{ $form->{TR} }, $ref if $ref->{netamount};
- } else {
- push @{ $form->{TR} }, $ref if $ref->{tax};
- }
- }
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ $ref->{tax} = $form->round_amount( $ref->{tax}, 2 );
+ if ( $form->{report} =~ /nontaxable/ ) {
+ push @{ $form->{TR} }, $ref if $ref->{netamount};
+ }
+ else {
+ push @{ $form->{TR} }, $ref if $ref->{tax};
+ }
+ }
- $sth->finish;
- $dbh->commit;
+ $sth->finish;
+ $dbh->commit;
}
-
sub paymentaccounts {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
+ my ( $self, $myconfig, $form ) = @_;
- my $ARAP = uc $form->{db};
-
- # get A(R|P)_paid accounts
- my $query = qq|
+ my $dbh = $form->{dbh};
+
+ my $ARAP = uc $form->{db};
+
+ # get A(R|P)_paid accounts
+ my $query = qq|
SELECT accno, description FROM chart
WHERE link LIKE '%${ARAP}_paid%'
ORDER BY accno|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{PR} }, $ref;
- }
- $sth->finish;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{PR} }, $ref;
+ }
+ $sth->finish;
- $form->all_years($myconfig, $dbh);
-
- $dbh->{dbh};
+ $form->all_years( $myconfig, $dbh );
+
+ $dbh->{dbh};
}
-
sub payments {
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = $form->{dbh};
-
- my $ml = 1;
- if ($form->{db} eq 'ar') {
- $table = 'customer';
- $ml = -1;
- }
- if ($form->{db} eq 'ap') {
- $table = 'vendor';
- }
-
-
- my $query;
- my $sth;
- my $dpt_join;
- my $where;
- my $var;
-
- if ($form->{department_id}) {
- $dpt_join = qq| JOIN dpt_trans t ON (t.trans_id = ac.trans_id)|;
-
- $where = qq| AND t.department_id = |.
- $dbh->quote($form->{department_id});
- }
-
- ($form->{fromdate}, $form->{todate}) = $form->from_to(
- $form->{year}, $form->{month}, $form->{interval})
- if $form->{year} && $form->{month};
-
- if ($form->{fromdate}) {
- $where .= " AND ac.transdate >= "
- .$dbh->quote($form->{fromdate});
- }
- if ($form->{todate}) {
- $where .= " AND ac.transdate <= ".$dbh->quote($form->{todate});
- }
- if (!$form->{fx_transaction}) {
- $where .= " AND ac.fx_transaction = '0'";
- }
-
- if ($form->{description} ne "") {
- $var = $dbh->quote($form->like(lc $form->{description}));
- $where .= " AND lower(c.name) LIKE $var";
- }
- if ($form->{source} ne "") {
- $var = $dbh->quote($form->like(lc $form->{source}));
- $where .= " AND lower(ac.source) LIKE $var";
- }
- if ($form->{memo} ne "") {
- $var = $dbh->quote($form->like(lc $form->{memo}));
- $where .= " AND lower(ac.memo) LIKE $var";
- }
-
- my %ordinal = (
- 'name' => 1,
- 'transdate' => 2,
- 'source' => 4,
- 'employee' => 6,
- 'till' => 7
- );
-
- my @a = qw(name transdate employee);
- my $sortorder = $form->sort_order(\@a, \%ordinal);
-
- my $glwhere = $where;
- $glwhere =~ s/\(c.name\)/\(g.description\)/;
-
- # cycle through each id
- foreach my $accno (split(/ /, $form->{paymentaccounts})) {
-
- $query = qq|
+ my ( $self, $myconfig, $form ) = @_;
+
+ my $dbh = $form->{dbh};
+
+ my $ml = 1;
+ if ( $form->{db} eq 'ar' ) {
+ $table = 'customer';
+ $ml = -1;
+ }
+ if ( $form->{db} eq 'ap' ) {
+ $table = 'vendor';
+ }
+
+ my $query;
+ my $sth;
+ my $dpt_join;
+ my $where;
+ my $var;
+
+ if ( $form->{department_id} ) {
+ $dpt_join = qq| JOIN dpt_trans t ON (t.trans_id = ac.trans_id)|;
+
+ $where =
+ qq| AND t.department_id = | . $dbh->quote( $form->{department_id} );
+ }
+
+ ( $form->{fromdate}, $form->{todate} ) =
+ $form->from_to( $form->{year}, $form->{month}, $form->{interval} )
+ if $form->{year} && $form->{month};
+
+ if ( $form->{fromdate} ) {
+ $where .= " AND ac.transdate >= " . $dbh->quote( $form->{fromdate} );
+ }
+ if ( $form->{todate} ) {
+ $where .= " AND ac.transdate <= " . $dbh->quote( $form->{todate} );
+ }
+ if ( !$form->{fx_transaction} ) {
+ $where .= " AND ac.fx_transaction = '0'";
+ }
+
+ if ( $form->{description} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{description} ) );
+ $where .= " AND lower(c.name) LIKE $var";
+ }
+ if ( $form->{source} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{source} ) );
+ $where .= " AND lower(ac.source) LIKE $var";
+ }
+ if ( $form->{memo} ne "" ) {
+ $var = $dbh->quote( $form->like( lc $form->{memo} ) );
+ $where .= " AND lower(ac.memo) LIKE $var";
+ }
+
+ my %ordinal = (
+ 'name' => 1,
+ 'transdate' => 2,
+ 'source' => 4,
+ 'employee' => 6,
+ 'till' => 7
+ );
+
+ my @a = qw(name transdate employee);
+ my $sortorder = $form->sort_order( \@a, \%ordinal );
+
+ my $glwhere = $where;
+ $glwhere =~ s/\(c.name\)/\(g.description\)/;
+
+ # cycle through each id
+ foreach my $accno ( split( / /, $form->{paymentaccounts} ) ) {
+
+ $query = qq|
SELECT id, accno, description
FROM chart
WHERE accno = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($accno) || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute($accno) || $form->dberror($query);
- my $ref = $sth->fetchrow_hashref(NAME_lc);
- push @{ $form->{PR} }, $ref;
- $sth->finish;
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+ push @{ $form->{PR} }, $ref;
+ $sth->finish;
- $query = qq|
+ $query = qq|
SELECT c.name, ac.transdate,
sum(ac.amount) * $ml AS paid, ac.source,
ac.memo, e.name AS employee, a.till, a.curr
@@ -2204,21 +2330,21 @@ sub payments {
$dpt_join
WHERE ac.chart_id = $ref->{id} $where|;
- if ($form->{till} ne "") {
- $query .= " AND a.invoice = '1' AND NOT a.till IS NULL";
-
- if ($myconfig->{role} eq 'user') {
- $query .= " AND e.login = '$form->{login}'";
- }
- }
+ if ( $form->{till} ne "" ) {
+ $query .= " AND a.invoice = '1' AND NOT a.till IS NULL";
+
+ if ( $myconfig->{role} eq 'user' ) {
+ $query .= " AND e.login = '$form->{login}'";
+ }
+ }
- $query .= qq|
+ $query .= qq|
GROUP BY c.name, ac.transdate, ac.source, ac.memo,
e.name, a.till, a.curr|;
-
- if ($form->{till} eq "") {
-
- $query .= qq|
+
+ if ( $form->{till} eq "" ) {
+
+ $query .= qq|
UNION
SELECT g.description, ac.transdate,
sum(ac.amount) * $ml AS paid, ac.source,
@@ -2234,25 +2360,23 @@ sub payments {
GROUP BY g.description, ac.transdate,
ac.source, ac.memo, e.name|;
- }
+ }
- $query .= qq| ORDER BY $sortorder|;
+ $query .= qq| ORDER BY $sortorder|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
- while (my $pr = $sth->fetchrow_hashref(NAME_lc)) {
- push @{ $form->{$ref->{id}} }, $pr;
- }
- $sth->finish;
+ while ( my $pr = $sth->fetchrow_hashref(NAME_lc) ) {
+ push @{ $form->{ $ref->{id} } }, $pr;
+ }
+ $sth->finish;
- }
-
- $dbh->commit;
-
-}
+ }
+ $dbh->commit;
-1;
+}
+1;
diff --git a/LedgerSMB/Report.pm b/LedgerSMB/Report.pm
index 66d19d5a..4fcc0201 100644
--- a/LedgerSMB/Report.pm
+++ b/LedgerSMB/Report.pm
@@ -1,7 +1,9 @@
+
=head1: LedgerSMB::Report: Stub function for custom reports.
=head1: Copyright (c) 2007. LedgerSMB Core Team
=cut
+
package LedgerSMB::Report;
use base qw(LedgerSMB::DBObject);
use strict;
diff --git a/LedgerSMB/Session.pm b/LedgerSMB/Session.pm
index 76ed27ce..dbc2d1c3 100644
--- a/LedgerSMB/Session.pm
+++ b/LedgerSMB/Session.pm
@@ -1,13 +1,13 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
-# with permission. It is released under the GNU General Public License
-# Version 2 or, at your option, any later version. See COPYRIGHT file for
+# with permission. It is released under the GNU General Public License
+# Version 2 or, at your option, any later version. See COPYRIGHT file for
# details.
# This is a simple abstraction layer allowing other session handling mechanisms
@@ -16,8 +16,8 @@ package Session;
use LedgerSMB::Sysconfig;
-if (!${LedgerSMB::Sysconfig::session}){
- ${LedgerSMB::Sysconfig::session} = 'DB';
+if ( !${LedgerSMB::Sysconfig::session} ) {
+ ${LedgerSMB::Sysconfig::session} = 'DB';
}
-require "LedgerSMB/Session/".${LedgerSMB::Sysconfig::session}.".pm";
+require "LedgerSMB/Session/" . ${LedgerSMB::Sysconfig::session} . ".pm";
diff --git a/LedgerSMB/Session/DB.pm b/LedgerSMB/Session/DB.pm
index eb550c62..592d0922 100755
--- a/LedgerSMB/Session/DB.pm
+++ b/LedgerSMB/Session/DB.pm
@@ -1,13 +1,13 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
-# with permission. It is released under the GNU General Public License
-# Version 2 or, at your option, any later version. See COPYRIGHT file for
+# with permission. It is released under the GNU General Public License
+# Version 2 or, at your option, any later version. See COPYRIGHT file for
# details.
#
#
@@ -24,248 +24,285 @@
#
# destroy - destroys session
#
-# password_check - compares the password with the stored cryted password
+# password_check - compares the password with the stored cryted password
# (ver. < 1.2) and the md5 one (ver. >= 1.2)
#====================================================================
package Session;
sub session_check {
- use Time::HiRes qw(gettimeofday);
+ use Time::HiRes qw(gettimeofday);
- my ($cookie, $form) = @_;
- my ($sessionID, $transactionID, $token) = split /:/, $cookie;
+ my ( $cookie, $form ) = @_;
+ my ( $sessionID, $transactionID, $token ) = split /:/, $cookie;
- # use the central database handle
- my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
+ # use the central database handle
+ my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
- my $checkQuery = $dbh->prepare("SELECT u.username, s.transaction_id
+ my $checkQuery = $dbh->prepare(
+ "SELECT u.username, s.transaction_id
FROM session as s, users as u
WHERE s.session_id = ?
AND s.token = ?
AND s.users_id = u.id
- AND s.last_used > now() - ?::interval");
+ AND s.last_used > now() - ?::interval"
+ );
- my $updateAge = $dbh->prepare("UPDATE session
+ my $updateAge = $dbh->prepare(
+ "UPDATE session
SET last_used = now(),
transaction_id = ?
- WHERE session_id = ?;");
-
- #must be an integer
- $sessionID =~ s/[^0-9]//g;
- $sessionID = int $sessionID;
+ WHERE session_id = ?;"
+ );
- $transactionID =~ s/[^0-9]//g;
- $transactionID = int $transactionID;
+ #must be an integer
+ $sessionID =~ s/[^0-9]//g;
+ $sessionID = int $sessionID;
- #must be 32 chars long and contain hex chars
- $token =~ s/[^0-9a-f]//g;
- $token = substr($token, 0, 32);
+ $transactionID =~ s/[^0-9]//g;
+ $transactionID = int $transactionID;
- if (!$myconfig{timeout}){
- $timeout = "1 day";
- } else {
- $timeout = "$myconfig{timeout} seconds";
- }
+ #must be 32 chars long and contain hex chars
+ $token =~ s/[^0-9a-f]//g;
+ $token = substr( $token, 0, 32 );
- $checkQuery->execute($sessionID, $token, $timeout)
- || $form->dberror(__FILE__.':'.__LINE__.': Looking for session: ');
- my $sessionValid = $checkQuery->rows;
+ if ( !$myconfig{timeout} ) {
+ $timeout = "1 day";
+ }
+ else {
+ $timeout = "$myconfig{timeout} seconds";
+ }
- if($sessionValid){
+ $checkQuery->execute( $sessionID, $token, $timeout )
+ || $form->dberror(
+ __FILE__ . ':' . __LINE__ . ': Looking for session: ' );
+ my $sessionValid = $checkQuery->rows;
- #user has a valid session cookie, now check the user
- my ($sessionLogin, $sessionTransaction) = $checkQuery->fetchrow_array;
+ if ($sessionValid) {
- my $login = $form->{login};
- $login =~ s/[^a-zA-Z0-9._+@'-]//g;
+ #user has a valid session cookie, now check the user
+ my ( $sessionLogin, $sessionTransaction ) = $checkQuery->fetchrow_array;
- if(($sessionLogin eq $login) and ($sessionTransaction eq $transactionID)){
+ my $login = $form->{login};
+ $login =~ s/[^a-zA-Z0-9._+@'-]//g;
- #microseconds are more than random enough for transaction_id
- my ($ignore, $newTransactionID) = gettimeofday();
+ if ( ( $sessionLogin eq $login )
+ and ( $sessionTransaction eq $transactionID ) )
+ {
- $newTransactionID = int $newTransactionID;
-
- $updateAge->execute($newTransactionID, $sessionID)
- || $form->dberror(__FILE__.':'.__LINE__.': Updating session age: ');
+ #microseconds are more than random enough for transaction_id
+ my ( $ignore, $newTransactionID ) = gettimeofday();
- $newCookieValue = $sessionID . ':'.$newTransactionID.':' . $token;
+ $newTransactionID = int $newTransactionID;
- #now update the cookie in the browser
- print qq|Set-Cookie: LedgerSMB=$newCookieValue; path=/;\n|;
- return 1;
+ $updateAge->execute( $newTransactionID, $sessionID )
+ || $form->dberror(
+ __FILE__ . ':' . __LINE__ . ': Updating session age: ' );
- } else {
- #something's wrong, they have the cookie, but wrong user or the wrong transaction id. Hijack attempt?
- #destroy the session
- my $sessionDestroy = $dbh->prepare("");
+ $newCookieValue =
+ $sessionID . ':' . $newTransactionID . ':' . $token;
- #delete the cookie in the browser
- print qq|Set-Cookie: LedgerSMB=; path=/;\n|;
- return 0;
- }
-
- } else {
- #cookie is not valid
- #delete the cookie in the browser
- print qq|Set-Cookie: LedgerSMB=; path=/;\n|;
- return 0;
- }
-}
+ #now update the cookie in the browser
+ print qq|Set-Cookie: LedgerSMB=$newCookieValue; path=/;\n|;
+ return 1;
-sub session_create {
+ }
+ else {
- use Time::HiRes qw(gettimeofday);
+#something's wrong, they have the cookie, but wrong user or the wrong transaction id. Hijack attempt?
+#destroy the session
+ my $sessionDestroy = $dbh->prepare("");
- #microseconds are more than random enough for transaction_id
- my ($ignore, $newTransactionID) = gettimeofday();
- $newTransactionID = int $newTransactionID;
+ #delete the cookie in the browser
+ print qq|Set-Cookie: LedgerSMB=; path=/;\n|;
+ return 0;
+ }
- my ($form) = @_;
+ }
+ else {
- if (! $ENV{HTTP_HOST}){
- #don't create cookies or sessions for CLI use
- return 1;
- }
-
- # use the central database handle
- my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
-
- # TODO Change this to use %myconfig
- my $deleteExisting = $dbh->prepare(
- "DELETE
- FROM session
- WHERE session.users_id = (select id from users where username = ?)
- AND age(last_used) > ?::interval");
-
- my $seedRandom = $dbh->prepare("SELECT setseed(?);");
+ #cookie is not valid
+ #delete the cookie in the browser
+ print qq|Set-Cookie: LedgerSMB=; path=/;\n|;
+ return 0;
+ }
+}
- my $fetchSequence = $dbh->prepare("SELECT nextval('session_session_id_seq'), md5(random());");
-
- my $createNew = $dbh->prepare("INSERT INTO session (session_id, users_id, token, transaction_id)
- VALUES(?, (SELECT id
- FROM users
- WHERE username = ?), ?, ?);");
+sub session_create {
+ use Time::HiRes qw(gettimeofday);
- # this is assuming that $form->{login} is safe, which might be a bad assumption
- # so, I'm going to remove some chars, which might make previously valid logins invalid
- my $login = $form->{login};
- $login =~ s/[^a-zA-Z0-9._+@'-]//g;
+ #microseconds are more than random enough for transaction_id
+ my ( $ignore, $newTransactionID ) = gettimeofday();
+ $newTransactionID = int $newTransactionID;
- #delete any existing stale sessions with this login if they exist
- if (!$myconfig{timeout}){
- $myconfig{timeout} = 86400;
- }
+ my ($form) = @_;
- $deleteExisting->execute($login, "$myconfig{timeout} seconds")
- || $form->dberror(__FILE__.':'.__LINE__.': Delete from session: ');
+ if ( !$ENV{HTTP_HOST} ) {
- #doing the random stuff in the db so that LedgerSMB won't
- #require a good random generator - maybe this should be reviewed, pgsql's isn't great either
- $fetchSequence->execute() || $form->dberror(__FILE__.':'.__LINE__.': Fetch sequence id: ');
- my ($newSessionID, $newToken) = $fetchSequence->fetchrow_array;
+ #don't create cookies or sessions for CLI use
+ return 1;
+ }
- #create a new session
- $createNew->execute($newSessionID, $login, $newToken, $newTransactionID)
- || $form->dberror(__FILE__.':'.__LINE__.': Create new session: ');
+ # use the central database handle
+ my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
- #reseed the random number generator
- my $randomSeed = 1.0 * ('0.'. (time() ^ ($$ + ($$ <<15))));
+ # TODO Change this to use %myconfig
+ my $deleteExisting = $dbh->prepare(
+ "DELETE
+ FROM session
+ WHERE session.users_id = (select id from users where username = ?)
+ AND age(last_used) > ?::interval"
+ );
- $seedRandom->execute($randomSeed)
- || $form->dberror(__FILE__.':'.__LINE__.': Reseed random generator: ');
+ my $seedRandom = $dbh->prepare("SELECT setseed(?);");
- $newCookieValue = $newSessionID . ':'.$newTransactionID.':' . $newToken;
+ my $fetchSequence =
+ $dbh->prepare("SELECT nextval('session_session_id_seq'), md5(random());");
- #now set the cookie in the browser
- #TODO set domain from ENV, also set path to install path
- print qq|Set-Cookie: LedgerSMB=$newCookieValue; path=/;\n|;
- $form->{LedgerSMB} = $newCookieValue;
+ my $createNew = $dbh->prepare(
+ "INSERT INTO session (session_id, users_id, token, transaction_id)
+ VALUES(?, (SELECT id
+ FROM users
+ WHERE username = ?), ?, ?);"
+ );
+
+# this is assuming that $form->{login} is safe, which might be a bad assumption
+# so, I'm going to remove some chars, which might make previously valid logins invalid
+ my $login = $form->{login};
+ $login =~ s/[^a-zA-Z0-9._+@'-]//g;
+
+ #delete any existing stale sessions with this login if they exist
+ if ( !$myconfig{timeout} ) {
+ $myconfig{timeout} = 86400;
+ }
+
+ $deleteExisting->execute( $login, "$myconfig{timeout} seconds" )
+ || $form->dberror(
+ __FILE__ . ':' . __LINE__ . ': Delete from session: ' );
+
+#doing the random stuff in the db so that LedgerSMB won't
+#require a good random generator - maybe this should be reviewed, pgsql's isn't great either
+ $fetchSequence->execute()
+ || $form->dberror( __FILE__ . ':' . __LINE__ . ': Fetch sequence id: ' );
+ my ( $newSessionID, $newToken ) = $fetchSequence->fetchrow_array;
+
+ #create a new session
+ $createNew->execute( $newSessionID, $login, $newToken, $newTransactionID )
+ || $form->dberror( __FILE__ . ':' . __LINE__ . ': Create new session: ' );
+
+ #reseed the random number generator
+ my $randomSeed = 1.0 * ( '0.' . ( time() ^ ( $$ + ( $$ << 15 ) ) ) );
+
+ $seedRandom->execute($randomSeed)
+ || $form->dberror(
+ __FILE__ . ':' . __LINE__ . ': Reseed random generator: ' );
+
+ $newCookieValue = $newSessionID . ':' . $newTransactionID . ':' . $newToken;
+
+ #now set the cookie in the browser
+ #TODO set domain from ENV, also set path to install path
+ print qq|Set-Cookie: LedgerSMB=$newCookieValue; path=/;\n|;
+ $form->{LedgerSMB} = $newCookieValue;
}
sub session_destroy {
- my ($form) = @_;
+ my ($form) = @_;
- my $login = $form->{login};
- $login =~ s/[^a-zA-Z0-9._+@'-]//g;
+ my $login = $form->{login};
+ $login =~ s/[^a-zA-Z0-9._+@'-]//g;
- # use the central database handle
- my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
+ # use the central database handle
+ my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
- my $deleteExisting = $dbh->prepare("
+ my $deleteExisting = $dbh->prepare( "
DELETE FROM session
WHERE users_id = (select id from users where username = ?)
- ");
+ " );
- $deleteExisting->execute($login)
- || $form->dberror(__FILE__.':'.__LINE__.': Delete from session: ');
+ $deleteExisting->execute($login)
+ || $form->dberror(
+ __FILE__ . ':' . __LINE__ . ': Delete from session: ' );
- #delete the cookie in the browser
- print qq|Set-Cookie: LedgerSMB=; path=/;\n|;
+ #delete the cookie in the browser
+ print qq|Set-Cookie: LedgerSMB=; path=/;\n|;
}
sub password_check {
- use Digest::MD5;
+ use Digest::MD5;
- my ($form, $username, $password) = @_;
+ my ( $form, $username, $password ) = @_;
- $username =~ s/[^a-zA-Z0-9._+@'-]//g;
+ $username =~ s/[^a-zA-Z0-9._+@'-]//g;
- # use the central database handle
- my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
+ # use the central database handle
+ my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
- my $fetchPassword = $dbh->prepare("SELECT u.username, uc.password, uc.crypted_password
+ my $fetchPassword = $dbh->prepare(
+ "SELECT u.username, uc.password, uc.crypted_password
FROM users as u, users_conf as uc
WHERE u.username = ?
- AND u.id = uc.id;");
+ AND u.id = uc.id;"
+ );
- $fetchPassword->execute($username) || $form->dberror(__FILE__.':'.__LINE__.': Fetching password : ');
+ $fetchPassword->execute($username)
+ || $form->dberror( __FILE__ . ':' . __LINE__ . ': Fetching password : ' );
- my ($dbusername, $md5Password, $cryptPassword) = $fetchPassword->fetchrow_array;
+ my ( $dbusername, $md5Password, $cryptPassword ) =
+ $fetchPassword->fetchrow_array;
- if ($dbusername ne $username) {
- # User data retrieved from db not for the requested user
- return 0;
- } elsif ($cryptPassword){
- #First time login from old system, check crypted password
+ if ( $dbusername ne $username ) {
- if ((crypt $password, substr($username, 0, 2)) eq $cryptPassword) {
+ # User data retrieved from db not for the requested user
+ return 0;
+ }
+ elsif ($cryptPassword) {
- #password was good, convert to md5 password and null crypted
- my $updatePassword = $dbh->prepare("UPDATE users_conf
+ #First time login from old system, check crypted password
+
+ if ( ( crypt $password, substr( $username, 0, 2 ) ) eq $cryptPassword )
+ {
+
+ #password was good, convert to md5 password and null crypted
+ my $updatePassword = $dbh->prepare(
+ "UPDATE users_conf
SET password = md5(?),
crypted_password = null
FROM users
WHERE users_conf.id = users.id
- AND users.username = ?;");
-
- $updatePassword->execute($password, $username)
- || $form->dberror(__FILE__.':'.__LINE__.': Converting password : ');
-
- return 1;
-
- } else {
- return 0; #password failed
- }
-
- } elsif ($md5Password){
-
- if ($md5Password ne (Digest::MD5::md5_hex $password) ) {
- return 0;
- }
- else {
- return 1;
- }
-
- } else {
- #both the md5Password and cryptPasswords were blank
- return 0;
- }
+ AND users.username = ?;"
+ );
+
+ $updatePassword->execute( $password, $username )
+ || $form->dberror(
+ __FILE__ . ':' . __LINE__ . ': Converting password : ' );
+
+ return 1;
+
+ }
+ else {
+ return 0; #password failed
+ }
+
+ }
+ elsif ($md5Password) {
+
+ if ( $md5Password ne ( Digest::MD5::md5_hex $password) ) {
+ return 0;
+ }
+ else {
+ return 1;
+ }
+
+ }
+ else {
+
+ #both the md5Password and cryptPasswords were blank
+ return 0;
+ }
}
1;
diff --git a/LedgerSMB/Setting.pm b/LedgerSMB/Setting.pm
index 2f439610..282bfd8e 100644
--- a/LedgerSMB/Setting.pm
+++ b/LedgerSMB/Setting.pm
@@ -1,3 +1,4 @@
+
=head1 NAME
LedgerSMB::Setting - LedgerSMB class for managing Business Locations
@@ -44,107 +45,118 @@ our $VERSION = '1.0.0';
our @ISA = qw(LedgerSMB::DBObject);
sub AUTOLOAD {
- my $self = shift;
- my $AUTOLOAD = $LedgerSMB::Setting::AUTOLOAD;
- $AUTOLOAD =~ s/^.*:://;
- $self->exec_method(procname => "setting_$AUTOLOAD", args =>\@_);
+ my $self = shift;
+ my $AUTOLOAD = $LedgerSMB::Setting::AUTOLOAD;
+ $AUTOLOAD =~ s/^.*:://;
+ $self->exec_method( procname => "setting_$AUTOLOAD", args => \@_ );
}
sub get {
- my $self = shift;
- my $hashref = shift @{$self->exec_method(procname => 'setting_get')};
- $self->merge($hashref, 'value');
+ my $self = shift;
+ my $hashref = shift @{ $self->exec_method( procname => 'setting_get' ) };
+ $self->merge( $hashref, 'value' );
}
sub parse_increment {
- my $self = shift;
- my $myconfig = shift;
-
- # Long-run, we may want to run this via Parse::RecDescent, but this is
- # at least a start for here. Chris T.
-
- # Replaces Form::UpdateDefaults
-
- $_ = $self->incriment;
- # check for and replace
- # <?lsmb DATE ?>, <?lsmb YYMMDD ?>, <?lsmb YEAR ?>, <?lsmb MONTH ?>, <?lsmb DAY ?> or variations of
- # <?lsmb NAME 1 1 3 ?>, <?lsmb BUSINESS ?>, <?lsmb BUSINESS 10 ?>, <?lsmb CURR... ?>
- # <?lsmb DESCRIPTION 1 1 3 ?>, <?lsmb ITEM 1 1 3 ?>, <?lsmb PARTSGROUP 1 1 3 ?> only for parts
- # <?lsmb PHONE ?> for customer and vendors
-
- my $dbvar = $_;
- my $var = $_;
- my $str;
- my $param;
-
- if (/<\?lsmb /) {
-
- while (/<\?lsmb /) {
-
- s/<\?lsmb .*? \?>//;
- last unless $&;
- $param = $&;
- $str = "";
-
- if ($param =~ /<\?lsmb date \?>/i) {
- $str = ($self->split_date($myconfig->{dateformat}, $self->{transdate}))[0];
- $var =~ s/$param/$str/;
- }
-
- if ($param =~ /<\?lsmb (name|business|description|item|partsgroup|phone|custom)/i) {
-
- my $fld = lc $&;
- $fld =~ s/<\?lsmb //;
-
- if ($fld =~ /name/) {
- if ($self->{type}) {
- $fld = $self->{vc};
- }
- }
-
- my $p = $param;
- $p =~ s/(<|>|%)//g;
- my @p = split / /, $p;
- my @n = split / /, uc $self->{$fld};
-
- if ($#p > 0) {
-
- for (my $i = 1; $i <= $#p; $i++) {
- $str .= substr($n[$i-1], 0, $p[$i]);
- }
-
- } else {
- ($str) = split /--/, $self->{$fld};
- }
-
- $var =~ s/$param/$str/;
- $var =~ s/\W//g if $fld eq 'phone';
- }
-
- if ($param =~ /<\?lsmb (yy|mm|dd)/i) {
-
- my $p = $param;
- $p =~ s/(<|>|%)//g;
- my $spc = $p;
- $spc =~ s/\w//g;
- $spc = substr($spc, 0, 1);
- my %d = ( yy => 1, mm => 2, dd => 3 );
- my @p = ();
-
- my @a = $self->split_date($myconfig->{dateformat}, $self->{transdate});
- for (sort keys %d) { push @p, $a[$d{$_}] if ($p =~ /$_/) }
- $str = join $spc, @p;
- $var =~ s/$param/$str/;
- }
-
- if ($param =~ /<\?lsmb curr/i) {
- $var =~ s/$param/$self->{currency}/;
- }
- }
- }
-
- $self->{value} = $var;
- $var;
+ my $self = shift;
+ my $myconfig = shift;
+
+ # Long-run, we may want to run this via Parse::RecDescent, but this is
+ # at least a start for here. Chris T.
+
+ # Replaces Form::UpdateDefaults
+
+ $_ = $self->incriment;
+
+# check for and replace
+# <?lsmb DATE ?>, <?lsmb YYMMDD ?>, <?lsmb YEAR ?>, <?lsmb MONTH ?>, <?lsmb DAY ?> or variations of
+# <?lsmb NAME 1 1 3 ?>, <?lsmb BUSINESS ?>, <?lsmb BUSINESS 10 ?>, <?lsmb CURR... ?>
+# <?lsmb DESCRIPTION 1 1 3 ?>, <?lsmb ITEM 1 1 3 ?>, <?lsmb PARTSGROUP 1 1 3 ?> only for parts
+# <?lsmb PHONE ?> for customer and vendors
+
+ my $dbvar = $_;
+ my $var = $_;
+ my $str;
+ my $param;
+
+ if (/<\?lsmb /) {
+
+ while (/<\?lsmb /) {
+
+ s/<\?lsmb .*? \?>//;
+ last unless $&;
+ $param = $&;
+ $str = "";
+
+ if ( $param =~ /<\?lsmb date \?>/i ) {
+ $str = (
+ $self->split_date(
+ $myconfig->{dateformat},
+ $self->{transdate}
+ )
+ )[0];
+ $var =~ s/$param/$str/;
+ }
+
+ if ( $param =~
+/<\?lsmb (name|business|description|item|partsgroup|phone|custom)/i
+ )
+ {
+
+ my $fld = lc $&;
+ $fld =~ s/<\?lsmb //;
+
+ if ( $fld =~ /name/ ) {
+ if ( $self->{type} ) {
+ $fld = $self->{vc};
+ }
+ }
+
+ my $p = $param;
+ $p =~ s/(<|>|%)//g;
+ my @p = split / /, $p;
+ my @n = split / /, uc $self->{$fld};
+
+ if ( $#p > 0 ) {
+
+ for ( my $i = 1 ; $i <= $#p ; $i++ ) {
+ $str .= substr( $n[ $i - 1 ], 0, $p[$i] );
+ }
+
+ }
+ else {
+ ($str) = split /--/, $self->{$fld};
+ }
+
+ $var =~ s/$param/$str/;
+ $var =~ s/\W//g if $fld eq 'phone';
+ }
+
+ if ( $param =~ /<\?lsmb (yy|mm|dd)/i ) {
+
+ my $p = $param;
+ $p =~ s/(<|>|%)//g;
+ my $spc = $p;
+ $spc =~ s/\w//g;
+ $spc = substr( $spc, 0, 1 );
+ my %d = ( yy => 1, mm => 2, dd => 3 );
+ my @p = ();
+
+ my @a = $self->split_date( $myconfig->{dateformat},
+ $self->{transdate} );
+ for ( sort keys %d ) { push @p, $a[ $d{$_} ] if ( $p =~ /$_/ ) }
+ $str = join $spc, @p;
+ $var =~ s/$param/$str/;
+ }
+
+ if ( $param =~ /<\?lsmb curr/i ) {
+ $var =~ s/$param/$self->{currency}/;
+ }
+ }
+ }
+
+ $self->{value} = $var;
+ $var;
}
diff --git a/LedgerSMB/Sysconfig.pm b/LedgerSMB/Sysconfig.pm
index bfb9c890..361f3c6b 100644
--- a/LedgerSMB/Sysconfig.pm
+++ b/LedgerSMB/Sysconfig.pm
@@ -1,4 +1,4 @@
-# This is the new configuration file for LedgerSMB. Eventually all system
+# This is the new configuration file for LedgerSMB. Eventually all system
# configuration directives will go here, This will probably not fully replace
# the ledger-smb.conf until 1.3, however.
@@ -6,23 +6,28 @@ package LedgerSMB::Sysconfig;
use LedgerSMB::Form;
use Config::Std;
-use DBI qw(:sql_types);
+use DBI qw(:sql_types);
binmode STDOUT, ':utf8';
# For Win32, change $pathsep to ';';
-$pathsep=':';
+$pathsep = ':';
-$session='DB';
-$logging=0; # No logging on by default
+$session = 'DB';
+$logging = 0; # No logging on by default
@io_lineitem_columns = qw(unit onhand sellprice discount linetotal);
# Whitelist for redirect destination
-@scripts = ('aa.pl', 'admin.pl', 'am.pl', 'ap.pl', 'ar.pl', 'arap.pl',
- 'arapprn.pl', 'bp.pl', 'ca.pl', 'cp.pl', 'ct.pl', 'gl.pl', 'hr.pl',
- 'ic.pl', 'io.pl', 'ir.pl', 'is.pl', 'jc.pl', 'login.pl', 'menu.pl',
- 'oe.pl', 'pe.pl', 'pos.pl', 'ps.pl', 'pw.pl', 'rc.pl', 'rp.pl');
+@scripts = (
+ 'aa.pl', 'admin.pl', 'am.pl', 'ap.pl',
+ 'ar.pl', 'arap.pl', 'arapprn.pl', 'bp.pl',
+ 'ca.pl', 'cp.pl', 'ct.pl', 'gl.pl',
+ 'hr.pl', 'ic.pl', 'io.pl', 'ir.pl',
+ 'is.pl', 'jc.pl', 'login.pl', 'menu.pl',
+ 'oe.pl', 'pe.pl', 'pos.pl', 'ps.pl',
+ 'pw.pl', 'rc.pl', 'rp.pl'
+);
# if you have latex installed set to 1
$latex = 1;
@@ -46,7 +51,7 @@ $memberfile = "users/members";
$sendmail = "/usr/sbin/sendmail -t";
# SMTP settings
-$smtphost = '';
+$smtphost = '';
$smtptimout = 60;
# set language for login and admin
@@ -62,64 +67,68 @@ $gzip = "gzip -S .gz";
$localepath = 'locale/po';
# available printers
-%printer = ( Laser => 'lpr -Plaser',
- Epson => 'lpr -PEpson',
- );
+%printer = (
+ Laser => 'lpr -Plaser',
+ Epson => 'lpr -PEpson',
+);
my %config;
-read_config('ledgersmb.conf' => %config) or die;
+read_config( 'ledgersmb.conf' => %config ) or die;
# Root variables
-for $var (qw(pathsep logging check_max_invoices language session latex
- db_autoupdate)){
+for $var (
+ qw(pathsep logging check_max_invoices language session latex
+ db_autoupdate)
+ )
+{
${$var} = $config{''}{$var} if $config{''}{$var};
}
-%printer = %{$config{printers}} if $config{printers};
+%printer = %{ $config{printers} } if $config{printers};
# ENV Paths
-for $var (qw(PATH PERL5LIB)){
-$ENV{$var} .= $pathsep.(join $pathsep, @{$config{environment}{$var}}) if
- $config{environment}{$var};
+for $var (qw(PATH PERL5LIB)) {
+ $ENV{$var} .= $pathsep . ( join $pathsep, @{ $config{environment}{$var} } )
+ if $config{environment}{$var};
}
# Application-specific paths
-for $var (qw(localepath spool templates images)){
- ${$var} = $config{paths}{$var} if $config{paths}{$var};
+for $var (qw(localepath spool templates images)) {
+ ${$var} = $config{paths}{$var} if $config{paths}{$var};
}
# Programs
-for $var (qw(gzip)){
- ${$var} = $config{programs}{$var} if $config{programs}{$var};
+for $var (qw(gzip)) {
+ ${$var} = $config{programs}{$var} if $config{programs}{$var};
}
# mail configuration
-for $var (qw(sendmail smpthost smtptimeout)){
- ${$var} = $config{mail}{$var} if $config{mail}{$var};
+for $var (qw(sendmail smpthost smtptimeout)) {
+ ${$var} = $config{mail}{$var} if $config{mail}{$var};
}
-
# We used to have a global dbconnect but have moved to single entries
-for $var (qw(DBhost DBport DBname DBUserName DBPassword)){
- ${"global".$var} = $config{globaldb}{$var} if $config{globaldb}{$var};
+for $var (qw(DBhost DBport DBname DBUserName DBPassword)) {
+ ${ "global" . $var } = $config{globaldb}{$var} if $config{globaldb}{$var};
}
#putting this in an if clause for now so not to break other devel users
-if ($config{globaldb}{DBname}){
- my $dbconnect = "dbi:Pg:dbname=$globalDBname host=$globalDBhost
+if ( $config{globaldb}{DBname} ) {
+ my $dbconnect = "dbi:Pg:dbname=$globalDBname host=$globalDBhost
port=$globalDBport user=$globalDBUserName
- password=$globalDBPassword"; # for easier debugging
- $GLOBALDBH = DBI->connect($dbconnect);
- if (!$GLOBALDBH){
- $form = new Form;
- $form->error("No GlobalDBH Configured or Could not Connect");
- }
+ password=$globalDBPassword"; # for easier debugging
+ $GLOBALDBH = DBI->connect($dbconnect);
+ if ( !$GLOBALDBH ) {
+ $form = new Form;
+ $form->error("No GlobalDBH Configured or Could not Connect");
+ }
}
-# These lines prevent other apps in mod_perl from seeing the global db
+
+# These lines prevent other apps in mod_perl from seeing the global db
# connection info
my $globalDBConnect = undef;
-my $globalUserName = undef;
-my $globalPassword = undef;
+my $globalUserName = undef;
+my $globalPassword = undef;
1;
diff --git a/LedgerSMB/Tax.pm b/LedgerSMB/Tax.pm
index 6d4c7956..edf3bccc 100644
--- a/LedgerSMB/Tax.pm
+++ b/LedgerSMB/Tax.pm
@@ -4,15 +4,15 @@
# LedgerSMB::Tax
# Default simple tax application
#
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
-# with permission. It is released under the GNU General Public License
-# Version 2 or, at your option, any later version. See COPYRIGHT file for
+# with permission. It is released under the GNU General Public License
+# Version 2 or, at your option, any later version. See COPYRIGHT file for
# details.
#
#
@@ -30,71 +30,74 @@ package Tax;
use Math::BigFloat;
sub init_taxes {
- my ($form, $taxaccounts) = @_;
- my $dbh = $form->{dbh};
- @taxes = ();
- my @accounts = split / /, $taxaccounts;
- my $query = qq|SELECT t.taxnumber, c.description,
+ my ( $form, $taxaccounts ) = @_;
+ my $dbh = $form->{dbh};
+ @taxes = ();
+ my @accounts = split / /, $taxaccounts;
+ my $query = qq|SELECT t.taxnumber, c.description,
t.rate, t.chart_id, t.pass, m.taxmodulename
FROM tax t INNER JOIN chart c ON (t.chart_id = c.id)
INNER JOIN taxmodule m ON (t.taxmodule_id = m.taxmodule_id)
WHERE c.accno = ?|;
- my $sth = $dbh->prepare($query);
- foreach $taxaccount (@accounts) {
- $sth->execute($taxaccount) || $form->dberror($query);
- my $ref = $sth->fetchrow_hashref;
+ my $sth = $dbh->prepare($query);
+ foreach $taxaccount (@accounts) {
+ $sth->execute($taxaccount) || $form->dberror($query);
+ my $ref = $sth->fetchrow_hashref;
- my $module = $ref->{'taxmodulename'};
- require "LedgerSMB/Taxes/${module}.pm";
- $module =~ s/\//::/g;
- my $tax = (eval 'Taxes::'.$module)->new();
+ my $module = $ref->{'taxmodulename'};
+ require "LedgerSMB/Taxes/${module}.pm";
+ $module =~ s/\//::/g;
+ my $tax = ( eval 'Taxes::' . $module )->new();
- $tax->pass($ref->{'pass'});
- $tax->account($taxaccount);
- $tax->rate(Math::BigFloat->new($ref->{'rate'}));
- $tax->taxnumber($ref->{'taxnumber'});
- $tax->chart($ref->{'chart'});
- $tax->description($ref->{'description'});
- $tax->value(Math::BigFloat->bzero());
+ $tax->pass( $ref->{'pass'} );
+ $tax->account($taxaccount);
+ $tax->rate( Math::BigFloat->new( $ref->{'rate'} ) );
+ $tax->taxnumber( $ref->{'taxnumber'} );
+ $tax->chart( $ref->{'chart'} );
+ $tax->description( $ref->{'description'} );
+ $tax->value( Math::BigFloat->bzero() );
- push @taxes, $tax;
- $sth->finish;
- }
- return @taxes;
+ push @taxes, $tax;
+ $sth->finish;
+ }
+ return @taxes;
}
sub calculate_taxes {
- my ($taxes, $form, $subtotal, $extract) = @_;
- my $total = Math::BigFloat->bzero();
- my %passes;
- foreach my $tax (@taxes) {
- push @{$passes{$tax->pass}}, $tax;
- }
- my @passkeys = sort keys %passes;
- @passkeys = reverse @passkeys if $extract;
- foreach my $pass (@passkeys) {
- my $passrate = Math::BigFloat->bzero();
- my $passtotal = Math::BigFloat->bzero();
- foreach my $tax (@{$passes{$pass}}) {
- $passrate += $tax->rate;
- }
- foreach my $tax (@{$passes{$pass}}) {
- $passtotal += $tax->apply_tax($form, $subtotal + $total) if not $extract;
- $passtotal += $tax->extract_tax($form, $subtotal - $total, $passrate) if $extract;
- }
- $total += $passtotal;
- }
- return $total;
+ my ( $taxes, $form, $subtotal, $extract ) = @_;
+ my $total = Math::BigFloat->bzero();
+ my %passes;
+ foreach my $tax (@taxes) {
+ push @{ $passes{ $tax->pass } }, $tax;
+ }
+ my @passkeys = sort keys %passes;
+ @passkeys = reverse @passkeys if $extract;
+ foreach my $pass (@passkeys) {
+ my $passrate = Math::BigFloat->bzero();
+ my $passtotal = Math::BigFloat->bzero();
+ foreach my $tax ( @{ $passes{$pass} } ) {
+ $passrate += $tax->rate;
+ }
+ foreach my $tax ( @{ $passes{$pass} } ) {
+ $passtotal += $tax->apply_tax( $form, $subtotal + $total )
+ if not $extract;
+ $passtotal +=
+ $tax->extract_tax( $form, $subtotal - $total, $passrate )
+ if $extract;
+ }
+ $total += $passtotal;
+ }
+ return $total;
}
sub apply_taxes {
- my ($taxes, $form, $subtotal) = @_;
- return $subtotal + calculate_taxes($taxes, $form, $subtotal, 0);
+ my ( $taxes, $form, $subtotal ) = @_;
+ return $subtotal + calculate_taxes( $taxes, $form, $subtotal, 0 );
}
sub extract_taxes {
- my ($taxes, $form, $subtotal) = @_;
- return $subtotal - calculate_taxes($taxes, $form, $subtotal, 1);
+ my ( $taxes, $form, $subtotal ) = @_;
+ return $subtotal - calculate_taxes( $taxes, $form, $subtotal, 1 );
}
1;
diff --git a/LedgerSMB/Taxes/Simple.pm b/LedgerSMB/Taxes/Simple.pm
index 57777be4..bbcf539b 100755
--- a/LedgerSMB/Taxes/Simple.pm
+++ b/LedgerSMB/Taxes/Simple.pm
@@ -4,15 +4,15 @@
# Taxes::Simple
# Default simple tax application
#
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
-# with permission. It is released under the GNU General Public License
-# Version 2 or, at your option, any later version. See COPYRIGHT file for
+# with permission. It is released under the GNU General Public License
+# Version 2 or, at your option, any later version. See COPYRIGHT file for
# details.
#
#
@@ -30,35 +30,35 @@ use Class::Struct;
use Math::BigFloat;
struct Taxes::Simple => {
- taxnumber => '$',
- description => '$',
- rate => 'Math::BigFloat',
- chart => '$',
- account => '$',
- value => 'Math::BigFloat',
- pass => '$'
+ taxnumber => '$',
+ description => '$',
+ rate => 'Math::BigFloat',
+ chart => '$',
+ account => '$',
+ value => 'Math::BigFloat',
+ pass => '$'
};
sub calculate_tax {
- my ($self, $form, $subtotal, $extract, $passrate) = @_;
- my $rate = $self->rate;
- my $tax = $subtotal * $rate / (Math::BigFloat->bone() + $passrate);
- $tax = $subtotal * $rate if not $extract;
- return $tax;
+ my ( $self, $form, $subtotal, $extract, $passrate ) = @_;
+ my $rate = $self->rate;
+ my $tax = $subtotal * $rate / ( Math::BigFloat->bone() + $passrate );
+ $tax = $subtotal * $rate if not $extract;
+ return $tax;
}
sub apply_tax {
- my ($self, $form, $subtotal) = @_;
- my $tax = $self->calculate_tax($form, $subtotal, 0);
- $self->value($tax);
- return $tax;
+ my ( $self, $form, $subtotal ) = @_;
+ my $tax = $self->calculate_tax( $form, $subtotal, 0 );
+ $self->value($tax);
+ return $tax;
}
sub extract_tax {
- my ($self, $form, $subtotal, $passrate) = @_;
- my $tax = $self->calculate_tax($form, $subtotal, 1, $passrate);
- $self->value($tax);
- return $tax;
+ my ( $self, $form, $subtotal, $passrate ) = @_;
+ my $tax = $self->calculate_tax( $form, $subtotal, 1, $passrate );
+ $self->value($tax);
+ return $tax;
}
1;
diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm
index 2c1a9d8f..93254df1 100755
--- a/LedgerSMB/Template.pm
+++ b/LedgerSMB/Template.pm
@@ -3,15 +3,15 @@
# Template support module for LedgerSMB
# LedgerSMB::Template
#
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
#
# Copyright (C) 2007
# This work contains copyrighted information from a number of sources all used
-# with permission. It is released under the GNU General Public License
-# Version 2 or, at your option, any later version. See COPYRIGHT file for
+# with permission. It is released under the GNU General Public License
+# Version 2 or, at your option, any later version. See COPYRIGHT file for
# details.
#
#
@@ -27,61 +27,77 @@ use LedgerSMB::Sysconfig;
package LedgerSMB::Template;
sub new {
- my $class = shift;
- my $self = {};
- $self->{myconfig} = shift;
- $self->{template} = shift;
- $self->{format} = shift;
- $self->{language} = shift;
- $self->{output} = '';
- bless $self, $class;
- return $self;
+ my $class = shift;
+ my $self = {};
+ $self->{myconfig} = shift;
+ $self->{template} = shift;
+ $self->{format} = shift;
+ $self->{language} = shift;
+ $self->{output} = '';
+ bless $self, $class;
+ return $self;
}
sub valid_language {
- my $self = shift;
- # XXX Actually perform validity checks
- return 1;
+ my $self = shift;
+
+ # XXX Actually perform validity checks
+ return 1;
}
sub render {
- my $self = shift;
- my $vars = shift;
- my $template;
+ my $self = shift;
+ my $vars = shift;
+ my $template;
- if (not defined $self->{language}) {
- $template = Template->new({
- INCLUDE_PATH => $self->{'myconfig'}->{'templates'},
- START_TAG => quotemeta('<?lsmb'),
- END_TAG => quotemeta('?>'),
- DELIMITER => ';',
- }) || throw Error::Simple Template->error();
- } elsif ($self->valid_language()) {
- $template = Template->new({
- INCLUDE_PATH => "$self->{'myconfig'}->{'templates'}/$self->{language};$self->{'myconfig'}->{'templates'}",
- START_TAG => quotemeta('<?lsmb'),
- END_TAG => quotemeta('?>'),
- DELIMITER => ';',
- }) || throw Error::Simple Template->error();
- } else {
- throw Error::Simple 'Invalid language';
- }
+ if ( not defined $self->{language} ) {
+ $template = Template->new(
+ {
+ INCLUDE_PATH => $self->{'myconfig'}->{'templates'},
+ START_TAG => quotemeta('<?lsmb'),
+ END_TAG => quotemeta('?>'),
+ DELIMITER => ';',
+ }
+ ) || throw Error::Simple Template->error();
+ }
+ elsif ( $self->valid_language() ) {
+ $template = Template->new(
+ {
+ INCLUDE_PATH =>
+"$self->{'myconfig'}->{'templates'}/$self->{language};$self->{'myconfig'}->{'templates'}",
+ START_TAG => quotemeta('<?lsmb'),
+ END_TAG => quotemeta('?>'),
+ DELIMITER => ';',
+ }
+ ) || throw Error::Simple Template->error();
+ }
+ else {
+ throw Error::Simple 'Invalid language';
+ }
- eval "require LedgerSMB::Template::$self->{format}";
- if ($@) {
- throw Error::Simple $@;
- }
+ eval "require LedgerSMB::Template::$self->{format}";
+ if ($@) {
+ throw Error::Simple $@;
+ }
- my $cleanvars = &{"LedgerSMB::Template::$self->{format}::preprocess"}($vars);
- if (not $template->process(
- &{"LedgerSMB::Template::$self->{format}::get_template"}($self->{template}),
- $cleanvars, \$self->{output}, binmode => ':utf8')) {
- throw Error::Simple $template->error();
- }
+ my $cleanvars =
+ &{"LedgerSMB::Template::$self->{format}::preprocess"}($vars);
+ if (
+ not $template->process(
+ &{"LedgerSMB::Template::$self->{format}::get_template"}(
+ $self->{template} ),
+ $cleanvars,
+ \$self->{output},
+ binmode => ':utf8'
+ )
+ )
+ {
+ throw Error::Simple $template->error();
+ }
- &{"LedgerSMB::Template::$self->{format}::postprocess"}($self);
+ &{"LedgerSMB::Template::$self->{format}::postprocess"}($self);
- return $self->{output};
+ return $self->{output};
}
1;
diff --git a/LedgerSMB/Template/HTML.pm b/LedgerSMB/Template/HTML.pm
index 8e610e26..62834f70 100755
--- a/LedgerSMB/Template/HTML.pm
+++ b/LedgerSMB/Template/HTML.pm
@@ -1,3 +1,4 @@
+
=head1 NAME
LedgerSMB::Template::HTML Template support module for LedgerSMB
@@ -29,29 +30,31 @@ use CGI;
package LedgerSMB::Template::HTML;
sub get_template {
- my $name = shift;
- return "${name}.html";
+ my $name = shift;
+ return "${name}.html";
}
sub preprocess {
- my $rawvars = shift;
- my $vars;
- my $type = ref $rawvars;
-
-#XXX fix escaping function
- if ($type eq 'ARRAY') {
- } elsif ($type eq 'HASH') {
- for (keys %{$rawvars}) {
- $vars->{$_} = preprocess($rawvars[$_]);
- }
- } else {
- return CGI::escapeHTML($rawvars);
- }
+ my $rawvars = shift;
+ my $vars;
+ my $type = ref $rawvars;
+
+ #XXX fix escaping function
+ if ( $type eq 'ARRAY' ) {
+ }
+ elsif ( $type eq 'HASH' ) {
+ for ( keys %{$rawvars} ) {
+ $vars->{$_} = preprocess( $rawvars[$_] );
+ }
+ }
+ else {
+ return CGI::escapeHTML($rawvars);
+ }
}
sub postprocess {
- my $parent = shift;
- return;
+ my $parent = shift;
+ return;
}
1;
diff --git a/LedgerSMB/User.pm b/LedgerSMB/User.pm
index 71199a1a..914bdfb9 100644
--- a/LedgerSMB/User.pm
+++ b/LedgerSMB/User.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -18,7 +18,7 @@
#
# Author: DWS Systems Inc.
# Web: http://www.sql-ledger.org
-#
+#
# Contributors: Jim Rawlings <jim@your-dba.com>
#
#======================================================================
@@ -34,20 +34,21 @@
package LedgerSMB::User;
use LedgerSMB::Sysconfig;
use LedgerSMB::Session;
-use Data::Dumper;
+use Data::Dumper;
sub new {
-
- my ($type, $login) = @_;
- my $self = {};
- if ($login ne "") {
+ my ( $type, $login ) = @_;
+ my $self = {};
+
+ if ( $login ne "" ) {
+
+ # use central db
+ my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
- # use central db
- my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
-
- # for now, this is querying the table directly... ugly
- my $fetchUserPrefs = $dbh->prepare("SELECT acs, address, businessnumber,
+ # for now, this is querying the table directly... ugly
+ my $fetchUserPrefs = $dbh->prepare(
+ "SELECT acs, address, businessnumber,
company, countrycode, currency,
dateformat, dbdriver, dbhost, dbname,
dboptions, dbpasswd, dbport, dbuser,
@@ -57,68 +58,77 @@ sub new {
timeout, vclimit, u.username
FROM users_conf as uc, users as u
WHERE u.username = ?
- AND u.id = uc.id;");
+ AND u.id = uc.id;"
+ );
- $fetchUserPrefs->execute($login);
+ $fetchUserPrefs->execute($login);
- my $userHashRef = $fetchUserPrefs->fetchrow_hashref;
+ my $userHashRef = $fetchUserPrefs->fetchrow_hashref;
- while ( my ($key, $value) = each(%{$userHashRef}) ) {
- $self->{$key} = $value;
- }
+ while ( my ( $key, $value ) = each( %{$userHashRef} ) ) {
+ $self->{$key} = $value;
+ }
+
+ chomp( $self->{dbport} );
+ chomp( $self->{dbname} );
+ chomp( $self->{dbhost} );
- chomp($self->{dbport});
- chomp($self->{dbname});
- chomp($self->{dbhost});
+ $self->{dbconnect} =
+ 'dbi:Pg:dbname='
+ . $self->{dbname}
+ . ';host='
+ . $self->{dbhost}
+ . ';port='
+ . $self->{dbport};
- $self->{dbconnect} = 'dbi:Pg:dbname='.$self->{dbname}.';host='.$self->{dbhost}.';port='.$self->{dbport};
+ if ( $self->{username} ) {
+ $self->{login} = $login;
+ }
+ }
- if($self->{username}){
- $self->{login} = $login;
- }
- }
-
- bless $self, $type;
+ bless $self, $type;
}
sub country_codes {
- use Locale::Country;
- use Locale::Language;
+ use Locale::Country;
+ use Locale::Language;
+
+ my %cc = ();
- my %cc = ();
-
- # scan the locale directory and read in the LANGUAGE files
- opendir DIR, "${LedgerSMB::Sysconfig::localepath}";
+ # scan the locale directory and read in the LANGUAGE files
+ opendir DIR, "${LedgerSMB::Sysconfig::localepath}";
- my @dir = grep !/^\..*$/, readdir DIR;
+ my @dir = grep !/^\..*$/, readdir DIR;
- foreach my $dir (@dir) {
- $dir = substr($dir, 0, -3);
- $cc{$dir} = code2language(substr($dir, 0, 2));
- $cc{$dir} .= ("/" . code2country(substr($dir, 3, 2)))
- if length($dir) > 2;
- $cc{$dir} .= (" " . substr($dir, 6)) if length($dir) > 5;
- }
+ foreach my $dir (@dir) {
+ $dir = substr( $dir, 0, -3 );
+ $cc{$dir} = code2language( substr( $dir, 0, 2 ) );
+ $cc{$dir} .= ( "/" . code2country( substr( $dir, 3, 2 ) ) )
+ if length($dir) > 2;
+ $cc{$dir} .= ( " " . substr( $dir, 6 ) ) if length($dir) > 5;
+ }
- closedir(DIR);
+ closedir(DIR);
- %cc;
+ %cc;
}
sub fetch_config {
-#I'm hoping that this function will go and is a temporary bridge
-#until we get rid of %myconfig elsewhere in the code
-
- my ($self, $login) = @_;
-
- if ($login ne "") {
-
- # use central db
- my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
-
- # for now, this is querying the table directly... ugly
- my $fetchUserPrefs = $dbh->prepare("SELECT acs, address, businessnumber,
+
+ #I'm hoping that this function will go and is a temporary bridge
+ #until we get rid of %myconfig elsewhere in the code
+
+ my ( $self, $login ) = @_;
+
+ if ( $login ne "" ) {
+
+ # use central db
+ my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
+
+ # for now, this is querying the table directly... ugly
+ my $fetchUserPrefs = $dbh->prepare(
+ "SELECT acs, address, businessnumber,
company, countrycode, currency,
dateformat, dbdriver, dbhost, dbname,
dboptions, dbpasswd, dbport, dbuser,
@@ -128,607 +138,608 @@ sub fetch_config {
timeout, vclimit, u.username
FROM users_conf as uc, users as u
WHERE u.username = ?
- AND u.id = uc.id;");
-
- $fetchUserPrefs->execute($login);
+ AND u.id = uc.id;"
+ );
- my $userHashRef = $fetchUserPrefs->fetchrow_hashref;
+ $fetchUserPrefs->execute($login);
- while ( my ($key, $value) = each(%{$userHashRef}) ) {
- $myconfig{$key} = $value;
- }
+ my $userHashRef = $fetchUserPrefs->fetchrow_hashref;
- chomp($myconfig{'dbport'});
- chomp($myconfig{'dbname'});
- chomp($myconfig{'dbhost'});
+ while ( my ( $key, $value ) = each( %{$userHashRef} ) ) {
+ $myconfig{$key} = $value;
+ }
- $myconfig{'login'} = $login;
- $myconfig{'dbconnect'} = 'dbi:Pg:dbname='.$myconfig{'dbname'}.';host='.$myconfig{'dbhost'}.';port='.$myconfig{'dbport'};
- }
-
- return \%myconfig;
+ chomp( $myconfig{'dbport'} );
+ chomp( $myconfig{'dbname'} );
+ chomp( $myconfig{'dbhost'} );
+
+ $myconfig{'login'} = $login;
+ $myconfig{'dbconnect'} =
+ 'dbi:Pg:dbname='
+ . $myconfig{'dbname'}
+ . ';host='
+ . $myconfig{'dbhost'}
+ . ';port='
+ . $myconfig{'dbport'};
+ }
+
+ return \%myconfig;
}
sub login {
- my ($self, $form) = @_;
+ my ( $self, $form ) = @_;
- my $rc = -1;
-
- if ($self->{login} ne "") {
- if (! Session::password_check($form, $form->{login}, $form->{password})) {
- return -1;
- }
+ my $rc = -1;
- #this is really dumb, but %myconfig will have to stay until 1.3
- while ( my ($key, $value) = each(%{$self}) ) {
- $myconfig{$key} = $value;
- }
+ if ( $self->{login} ne "" ) {
+ if (
+ !Session::password_check(
+ $form, $form->{login}, $form->{password}
+ )
+ )
+ {
+ return -1;
+ }
+
+ #this is really dumb, but %myconfig will have to stay until 1.3
+ while ( my ( $key, $value ) = each( %{$self} ) ) {
+ $myconfig{$key} = $value;
+ }
- # check if database is down
- my $dbh = DBI->connect(
- $myconfig{dbconnect}, $myconfig{dbuser},
- $myconfig{dbpasswd})
- or $self->error(__FILE__.':'.__LINE__.': '.$DBI::errstr);
+ # check if database is down
+ my $dbh =
+ DBI->connect( $myconfig{dbconnect}, $myconfig{dbuser},
+ $myconfig{dbpasswd} )
+ or $self->error( __FILE__ . ':' . __LINE__ . ': ' . $DBI::errstr );
- # we got a connection, check the version
- my $query = qq|
+ # we got a connection, check the version
+ my $query = qq|
SELECT value FROM defaults
WHERE setting_key = 'version'|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror(__FILE__.':'.__LINE__.$query);
-
- my ($dbversion) = $sth->fetchrow_array;
- $sth->finish;
-
- # add login to employee table if it does not exist
- # no error check for employee table, ignore if it does not exist
- my $login = $self->{login};
- $login =~ s/@.*//;
- $query = qq|SELECT id FROM employees WHERE login = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($login);
-
- my ($id) = $sth->fetchrow_array;
- $sth->finish;
-
- if (! $id) {
- my ($employeenumber) =
- $form->update_defaults(
- \%myconfig, "employeenumber", $dbh);
-
- $query = qq|
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror( __FILE__ . ':' . __LINE__ . $query );
+
+ my ($dbversion) = $sth->fetchrow_array;
+ $sth->finish;
+
+ # add login to employee table if it does not exist
+ # no error check for employee table, ignore if it does not exist
+ my $login = $self->{login};
+ $login =~ s/@.*//;
+ $query = qq|SELECT id FROM employees WHERE login = ?|;
+ $sth = $dbh->prepare($query);
+ $sth->execute($login);
+
+ my ($id) = $sth->fetchrow_array;
+ $sth->finish;
+
+ if ( !$id ) {
+ my ($employeenumber) =
+ $form->update_defaults( \%myconfig, "employeenumber", $dbh );
+
+ $query = qq|
INSERT INTO employees
(login, employeenumber, name,
workphone, role)
VALUES (?, ?, ?, ?, ?)|;
- $sth = $dbh->prepare($query);
- $sth->execute(
- $login, $employeenumber, $myconfig{name},
- $myconfig{tel}, $myconfig{role});
- }
- $dbh->disconnect;
-
- $rc = 0;
-
-
- if ($form->{dbversion} ne $dbversion) {
- $rc = -3;
- $dbupdate = (calc_version($dbversion)
- < calc_version($form->{dbversion}));
- }
-
- if ($dbupdate) {
- $rc = -4;
-
- # if DB2 bale out
- if ($myconfig{dbdriver} eq 'DB2') {
- $rc = -2;
- }
- }
- }
-
- $rc;
-
-}
+ $sth = $dbh->prepare($query);
+ $sth->execute(
+ $login, $employeenumber, $myconfig{name},
+ $myconfig{tel}, $myconfig{role}
+ );
+ }
+ $dbh->disconnect;
+ $rc = 0;
+
+ if ( $form->{dbversion} ne $dbversion ) {
+ $rc = -3;
+ $dbupdate =
+ ( calc_version($dbversion) < calc_version( $form->{dbversion} ) );
+ }
+
+ if ($dbupdate) {
+ $rc = -4;
+
+ # if DB2 bale out
+ if ( $myconfig{dbdriver} eq 'DB2' ) {
+ $rc = -2;
+ }
+ }
+ }
+
+ $rc;
+
+}
sub check_recurring {
- my ($self, $form) = @_;
+ my ( $self, $form ) = @_;
- my $dbh = DBI->connect(
- $self->{dbconnect}, $self->{dbuser}, $self->{dbpasswd})
- or $form->dberror(__FILE__.':'.__LINE__);
+ my $dbh =
+ DBI->connect( $self->{dbconnect}, $self->{dbuser}, $self->{dbpasswd} )
+ or $form->dberror( __FILE__ . ':' . __LINE__ );
- my $query = qq|
+ my $query = qq|
SELECT count(*) FROM recurring
WHERE enddate >= current_date AND nextdate <= current_date|;
- ($_) = $dbh->selectrow_array($query);
-
- $dbh->disconnect;
+ ($_) = $dbh->selectrow_array($query);
- $_;
+ $dbh->disconnect;
-}
+ $_;
+}
sub dbconnect_vars {
- my ($form, $db) = @_;
-
- my %dboptions = (
- 'Pg' => {
- 'yy-mm-dd' => 'set DateStyle to \'ISO\'',
- 'mm/dd/yy' => 'set DateStyle to \'SQL, US\'',
- 'mm-dd-yy' => 'set DateStyle to \'POSTGRES, US\'',
- 'dd/mm/yy' => 'set DateStyle to \'SQL, EUROPEAN\'',
- 'dd-mm-yy' => 'set DateStyle to \'POSTGRES, EUROPEAN\'',
- 'dd.mm.yy' => 'set DateStyle to \'GERMAN\''
- }
- );
-
-
- $form->{dboptions} = $dboptions{$form->{dbdriver}}{$form->{dateformat}};
-
- $form->{dbconnect} = "dbi:$form->{dbdriver}:dbname=$db";
- $form->{dbconnect} .= ";host=$form->{dbhost}";
- $form->{dbconnect} .= ";port=$form->{dbport}";
-
-}
+ my ( $form, $db ) = @_;
+
+ my %dboptions = (
+ 'Pg' => {
+ 'yy-mm-dd' => 'set DateStyle to \'ISO\'',
+ 'mm/dd/yy' => 'set DateStyle to \'SQL, US\'',
+ 'mm-dd-yy' => 'set DateStyle to \'POSTGRES, US\'',
+ 'dd/mm/yy' => 'set DateStyle to \'SQL, EUROPEAN\'',
+ 'dd-mm-yy' => 'set DateStyle to \'POSTGRES, EUROPEAN\'',
+ 'dd.mm.yy' => 'set DateStyle to \'GERMAN\''
+ }
+ );
+
+ $form->{dboptions} = $dboptions{ $form->{dbdriver} }{ $form->{dateformat} };
+ $form->{dbconnect} = "dbi:$form->{dbdriver}:dbname=$db";
+ $form->{dbconnect} .= ";host=$form->{dbhost}";
+ $form->{dbconnect} .= ";port=$form->{dbport}";
+
+}
sub dbdrivers {
- my @drivers = DBI->available_drivers();
+ my @drivers = DBI->available_drivers();
- # return (grep { /(Pg|Oracle|DB2)/ } @drivers);
- return (grep { /Pg$/ } @drivers);
+ # return (grep { /(Pg|Oracle|DB2)/ } @drivers);
+ return ( grep { /Pg$/ } @drivers );
}
-
sub dbsources {
- my ($self, $form) = @_;
+ my ( $self, $form ) = @_;
+
+ my @dbsources = ();
+ my ( $sth, $query );
- my @dbsources = ();
- my ($sth, $query);
-
- $form->{dbdefault} = $form->{dbuser} unless $form->{dbdefault};
- $form->{sid} = $form->{dbdefault};
- &dbconnect_vars($form, $form->{dbdefault});
+ $form->{dbdefault} = $form->{dbuser} unless $form->{dbdefault};
+ $form->{sid} = $form->{dbdefault};
+ &dbconnect_vars( $form, $form->{dbdefault} );
- my $dbh = DBI->connect(
- $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
- or $form->dberror(__FILE__.':'.__LINE__);
+ my $dbh =
+ DBI->connect( $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd} )
+ or $form->dberror( __FILE__ . ':' . __LINE__ );
+ if ( $form->{dbdriver} eq 'Pg' ) {
- if ($form->{dbdriver} eq 'Pg') {
+ $query = qq|SELECT datname FROM pg_database|;
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror( __FILE__ . ':' . __LINE__ . $query );
- $query = qq|SELECT datname FROM pg_database|;
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror(__FILE__.':'.__LINE__.$query);
-
- while (my ($db) = $sth->fetchrow_array) {
+ while ( my ($db) = $sth->fetchrow_array ) {
- if ($form->{only_acc_db}) {
+ if ( $form->{only_acc_db} ) {
- next if ($db =~ /^template/);
+ next if ( $db =~ /^template/ );
- &dbconnect_vars($form, $db);
- my $dbh = DBI->connect(
- $form->{dbconnect}, $form->{dbuser},
- $form->{dbpasswd})
- or $form->dberror(__FILE__.':'.__LINE__);
+ &dbconnect_vars( $form, $db );
+ my $dbh =
+ DBI->connect( $form->{dbconnect}, $form->{dbuser},
+ $form->{dbpasswd} )
+ or $form->dberror( __FILE__ . ':' . __LINE__ );
- $query = qq|
+ $query = qq|
SELECT tablename FROM pg_tables
WHERE tablename = 'defaults'
AND tableowner = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{dbuser})
- || $form->dberror(__FILE__.':'.__LINE__.$query);
-
- if ($sth->fetchrow_array) {
- push @dbsources, $db;
- }
- $sth->finish;
- $dbh->disconnect;
- next;
- }
- push @dbsources, $db;
- }
- }
-
- $sth->finish;
- $dbh->disconnect;
-
- return @dbsources;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{dbuser} )
+ || $form->dberror( __FILE__ . ':' . __LINE__ . $query );
+
+ if ( $sth->fetchrow_array ) {
+ push @dbsources, $db;
+ }
+ $sth->finish;
+ $dbh->disconnect;
+ next;
+ }
+ push @dbsources, $db;
+ }
+ }
-}
+ $sth->finish;
+ $dbh->disconnect;
-
-sub dbcreate {
- my ($self, $form) = @_;
-
- my %dbcreate = ( 'Pg' => qq|CREATE DATABASE "$form->{db}" WITH ENCODING = 'UNICODE'| );
-
- $form->{sid} = $form->{dbdefault};
- &dbconnect_vars($form, $form->{dbdefault});
- # The below line connects to Template1 or another template file in order
- # to create the db. One must disconnect and reconnect later.
- if ($form->{dbsuperuser}){
- my $superdbh = DBI->connect(
- $form->{dbconnect},
- $form->{dbsuperuser},
- $form->{dbsuperpasswd})
- or $form->dberror(__FILE__.':'.__LINE__);
- my $query = qq|$dbcreate{$form->{dbdriver}}|;
- $superdbh->do($query) || $form->dberror(__FILE__.':'.__LINE__.$query);
-
- $superdbh->disconnect;
- }
- #Reassign for the work below
-
- &dbconnect_vars($form, $form->{db});
-
- my $dbh = DBI->connect(
- $form->{dbconnect},
- $form->{dbuser},
- $form->{dbpasswd})
- or $form->dberror(__FILE__.':'.__LINE__);
- if ($form->{dbsuperuser}){
- my $superdbh = DBI->connect(
- $form->{dbconnect},
- $form->{dbsuperuser},
- $form->{dbsuperpasswd})
- or $form->dberror(__FILE__.':'.__LINE__);
- # JD: We need to check for plpgsql,
- # if it isn't there create it, if we can't error
- # Good chance I will have to do this twice as I get
- # used to the way the code is structured
-
- my %langcreate = ( 'Pg' => qq|CREATE LANGUAGE plpgsql|);
- my $query = qq|$langcreate{$form->{dbdriver}}|;
- $superdbh->do($query);
- $superdbh->disconnect;
- }
- # create the tables
- my $dbdriver =
- ($form->{dbdriver} =~ /Pg/)
- ? 'Pg'
- : $form->{dbdriver};
-
- my $filename = qq|sql/Pg-database.sql|;
- $self->process_query($form, $dbh, $filename);
-
- # load gifi
- ($filename) = split /_/, $form->{chart};
- $filename =~ s/_//;
- $self->process_query($form, $dbh, "sql/${filename}-gifi.sql");
-
- # load chart of accounts
- $filename = qq|sql/$form->{chart}-chart.sql|;
- $self->process_query($form, $dbh, $filename);
-
-
- # create custom tables and functions
- my $item;
- foreach $item (qw(tables functions)) {
- $filename = "sql/${dbdriver}-custom_${item}.sql";
- if (-f "$filename") {
- $self->process_query($form, $dbh, $filename);
- }
- }
-
- $dbh->disconnect;
+ return @dbsources;
}
+sub dbcreate {
+ my ( $self, $form ) = @_;
+
+ my %dbcreate =
+ ( 'Pg' => qq|CREATE DATABASE "$form->{db}" WITH ENCODING = 'UNICODE'| );
+
+ $form->{sid} = $form->{dbdefault};
+ &dbconnect_vars( $form, $form->{dbdefault} );
+
+ # The below line connects to Template1 or another template file in order
+ # to create the db. One must disconnect and reconnect later.
+ if ( $form->{dbsuperuser} ) {
+ my $superdbh =
+ DBI->connect( $form->{dbconnect}, $form->{dbsuperuser},
+ $form->{dbsuperpasswd} )
+ or $form->dberror( __FILE__ . ':' . __LINE__ );
+ my $query = qq|$dbcreate{$form->{dbdriver}}|;
+ $superdbh->do($query)
+ || $form->dberror( __FILE__ . ':' . __LINE__ . $query );
+
+ $superdbh->disconnect;
+ }
+
+ #Reassign for the work below
+
+ &dbconnect_vars( $form, $form->{db} );
+
+ my $dbh =
+ DBI->connect( $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd} )
+ or $form->dberror( __FILE__ . ':' . __LINE__ );
+ if ( $form->{dbsuperuser} ) {
+ my $superdbh =
+ DBI->connect( $form->{dbconnect}, $form->{dbsuperuser},
+ $form->{dbsuperpasswd} )
+ or $form->dberror( __FILE__ . ':' . __LINE__ );
+
+ # JD: We need to check for plpgsql,
+ # if it isn't there create it, if we can't error
+ # Good chance I will have to do this twice as I get
+ # used to the way the code is structured
+
+ my %langcreate = ( 'Pg' => qq|CREATE LANGUAGE plpgsql| );
+ my $query = qq|$langcreate{$form->{dbdriver}}|;
+ $superdbh->do($query);
+ $superdbh->disconnect;
+ }
+
+ # create the tables
+ my $dbdriver =
+ ( $form->{dbdriver} =~ /Pg/ )
+ ? 'Pg'
+ : $form->{dbdriver};
+
+ my $filename = qq|sql/Pg-database.sql|;
+ $self->process_query( $form, $dbh, $filename );
+
+ # load gifi
+ ($filename) = split /_/, $form->{chart};
+ $filename =~ s/_//;
+ $self->process_query( $form, $dbh, "sql/${filename}-gifi.sql" );
+
+ # load chart of accounts
+ $filename = qq|sql/$form->{chart}-chart.sql|;
+ $self->process_query( $form, $dbh, $filename );
+
+ # create custom tables and functions
+ my $item;
+ foreach $item (qw(tables functions)) {
+ $filename = "sql/${dbdriver}-custom_${item}.sql";
+ if ( -f "$filename" ) {
+ $self->process_query( $form, $dbh, $filename );
+ }
+ }
+ $dbh->disconnect;
-sub process_query {
- my ($self, $form, $dbh, $filename) = @_;
-
- return unless (-f $filename);
-
- $ENV{PGPASSWORD} = $form->{dbpasswd};
- $ENV{PGUSER} = $form->{dbuser};
- $ENV{PGDATABASE} = $form->{db};
- $ENV{PGHOST} = $form->{dbhost};
- $ENV{PGPORT} = $form->{pgport};
-
- $results = `psql -f $filename 2>&1`;
- if ($?){
- $form->error($!);
- }
- elsif ($results =~ /error/i){
- $form->error($results);
- }
}
-
+sub process_query {
+ my ( $self, $form, $dbh, $filename ) = @_;
+
+ return unless ( -f $filename );
+
+ $ENV{PGPASSWORD} = $form->{dbpasswd};
+ $ENV{PGUSER} = $form->{dbuser};
+ $ENV{PGDATABASE} = $form->{db};
+ $ENV{PGHOST} = $form->{dbhost};
+ $ENV{PGPORT} = $form->{pgport};
+
+ $results = `psql -f $filename 2>&1`;
+ if ($?) {
+ $form->error($!);
+ }
+ elsif ( $results =~ /error/i ) {
+ $form->error($results);
+ }
+}
sub dbdelete {
- my ($self, $form) = @_;
+ my ( $self, $form ) = @_;
- $form->{sid} = $form->{dbdefault};
- &dbconnect_vars($form, $form->{dbdefault});
- my $dbh = DBI->connect(
- $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
- or $form->dberror(__FILE__.':'.__LINE__);
- my $query = qq|DROP DATABASE "$form->{db}"|;
- $dbh->do($query) || $form->dberror(__FILE__.':'.__LINE__.$query);
+ $form->{sid} = $form->{dbdefault};
+ &dbconnect_vars( $form, $form->{dbdefault} );
+ my $dbh =
+ DBI->connect( $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd} )
+ or $form->dberror( __FILE__ . ':' . __LINE__ );
+ my $query = qq|DROP DATABASE "$form->{db}"|;
+ $dbh->do($query) || $form->dberror( __FILE__ . ':' . __LINE__ . $query );
- $dbh->disconnect;
+ $dbh->disconnect;
}
-
-
sub dbsources_unused {
- my ($self, $form, $memfile) = @_;
+ my ( $self, $form, $memfile ) = @_;
- my @dbexcl = ();
- my @dbsources = ();
-
- $form->error(__FILE__.':'.__LINE__.": $memfile locked!") if (-f "${memfile}.LCK");
-
- # open members file
- open(FH, '<', "$memfile") or $form->error(__FILE__.':'.__LINE__.": $memfile : $!");
+ my @dbexcl = ();
+ my @dbsources = ();
- while (<FH>) {
- if (/^dbname=/) {
- my ($null,$item) = split /=/;
- push @dbexcl, $item;
- }
- }
+ $form->error( __FILE__ . ':' . __LINE__ . ": $memfile locked!" )
+ if ( -f "${memfile}.LCK" );
- close FH;
+ # open members file
+ open( FH, '<', "$memfile" )
+ or $form->error( __FILE__ . ':' . __LINE__ . ": $memfile : $!" );
- $form->{only_acc_db} = 1;
- my @db = &dbsources("", $form);
+ while (<FH>) {
+ if (/^dbname=/) {
+ my ( $null, $item ) = split /=/;
+ push @dbexcl, $item;
+ }
+ }
- push @dbexcl, $form->{dbdefault};
+ close FH;
- foreach $item (@db) {
- unless (grep /$item$/, @dbexcl) {
- push @dbsources, $item;
- }
- }
+ $form->{only_acc_db} = 1;
+ my @db = &dbsources( "", $form );
- return @dbsources;
+ push @dbexcl, $form->{dbdefault};
-}
+ foreach $item (@db) {
+ unless ( grep /$item$/, @dbexcl ) {
+ push @dbsources, $item;
+ }
+ }
+ return @dbsources;
+
+}
sub dbneedsupdate {
- my ($self, $form) = @_;
+ my ( $self, $form ) = @_;
+
+ my %dbsources = ();
+ my $query;
- my %dbsources = ();
- my $query;
-
- $form->{sid} = $form->{dbdefault};
- &dbconnect_vars($form, $form->{dbdefault});
+ $form->{sid} = $form->{dbdefault};
+ &dbconnect_vars( $form, $form->{dbdefault} );
- my $dbh = DBI->connect(
- $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
- or $form->dberror(__FILE__.':'.__LINE__);
+ my $dbh =
+ DBI->connect( $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd} )
+ or $form->dberror( __FILE__ . ':' . __LINE__ );
- if ($form->{dbdriver} =~ /Pg/) {
+ if ( $form->{dbdriver} =~ /Pg/ ) {
- $query = qq|
+ $query = qq|
SELECT d.datname
FROM pg_database d, pg_user u
WHERE d.datdba = u.usesysid
AND u.usename = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{dbuser}) || $form->dberror(__FILE__.':'.__LINE__.$query);
-
- while (my ($db) = $sth->fetchrow_array) {
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $form->{dbuser} )
+ || $form->dberror( __FILE__ . ':' . __LINE__ . $query );
+
+ while ( my ($db) = $sth->fetchrow_array ) {
- next if ($db =~ /^template/);
+ next if ( $db =~ /^template/ );
- &dbconnect_vars($form, $db);
-
- my $dbh = DBI->connect(
- $form->{dbconnect}, $form->{dbuser},
- $form->{dbpasswd})
- or $form->dberror(__FILE__.':'.__LINE__);
+ &dbconnect_vars( $form, $db );
- $query = qq|
+ my $dbh =
+ DBI->connect( $form->{dbconnect}, $form->{dbuser},
+ $form->{dbpasswd} )
+ or $form->dberror( __FILE__ . ':' . __LINE__ );
+
+ $query = qq|
SELECT tablename
FROM pg_tables
WHERE tablename = 'defaults'|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror(__FILE__.':'.__LINE__.$query);
+ my $sth = $dbh->prepare($query);
+ $sth->execute
+ || $form->dberror( __FILE__ . ':' . __LINE__ . $query );
- if ($sth->fetchrow_array) {
- $query = qq|
+ if ( $sth->fetchrow_array ) {
+ $query = qq|
SELECT value FROM defaults
WHERE setting_key = 'version'|;
- my $sth = $dbh->prepare($query);
- $sth->execute;
-
- if (my ($version) = $sth->fetchrow_array) {
- $dbsources{$db} = $version;
- }
- $sth->finish;
- }
- $sth->finish;
- $dbh->disconnect;
- }
- $sth->finish;
- }
-
-
-
- $dbh->disconnect;
-
- %dbsources;
+ my $sth = $dbh->prepare($query);
+ $sth->execute;
+
+ if ( my ($version) = $sth->fetchrow_array ) {
+ $dbsources{$db} = $version;
+ }
+ $sth->finish;
+ }
+ $sth->finish;
+ $dbh->disconnect;
+ }
+ $sth->finish;
+ }
-}
+ $dbh->disconnect;
+
+ %dbsources;
+}
sub dbupdate {
- my ($self, $form) = @_;
-
- $form->{sid} = $form->{dbdefault};
-
- my @upgradescripts = ();
- my $query;
- my $rc = -2;
-
- if ($form->{dbupdate}) {
- # read update scripts into memory
- opendir SQLDIR, "sql/." or $form->error(__FILE__.':'.__LINE__.': '.$!);
- @upgradescripts =
- sort script_version
- grep /$form->{dbdriver}-upgrade-.*?\.sql$/,
- readdir SQLDIR;
- closedir SQLDIR;
- }
-
-
- foreach my $db (split / /, $form->{dbupdate}) {
-
- next unless $form->{$db};
-
- # strip db from dataset
- $db =~ s/^db//;
- &dbconnect_vars($form, $db);
-
- my $dbh = DBI->connect(
- $form->{dbconnect}, $form->{dbuser},
- $form->{dbpasswd}, {AutoCommit => 0})
- or $form->dberror(__FILE__.':'.__LINE__);
-
- # check version
- $query = qq|
+ my ( $self, $form ) = @_;
+
+ $form->{sid} = $form->{dbdefault};
+
+ my @upgradescripts = ();
+ my $query;
+ my $rc = -2;
+
+ if ( $form->{dbupdate} ) {
+
+ # read update scripts into memory
+ opendir SQLDIR, "sql/."
+ or $form->error( __FILE__ . ':' . __LINE__ . ': ' . $! );
+ @upgradescripts =
+ sort script_version grep /$form->{dbdriver}-upgrade-.*?\.sql$/,
+ readdir SQLDIR;
+ closedir SQLDIR;
+ }
+
+ foreach my $db ( split / /, $form->{dbupdate} ) {
+
+ next unless $form->{$db};
+
+ # strip db from dataset
+ $db =~ s/^db//;
+ &dbconnect_vars( $form, $db );
+
+ my $dbh = DBI->connect(
+ $form->{dbconnect}, $form->{dbuser},
+ $form->{dbpasswd}, { AutoCommit => 0 }
+ ) or $form->dberror( __FILE__ . ':' . __LINE__ );
+
+ # check version
+ $query = qq|
SELECT value FROM defaults
WHERE setting_key = 'version'|;
- my $sth = $dbh->prepare($query);
- # no error check, let it fall through
- $sth->execute;
-
- my $version = $sth->fetchrow_array;
- $sth->finish;
-
- next unless $version;
-
- $version = calc_version($version);
- my $dbversion = calc_version($form->{dbversion});
-
- foreach my $upgradescript (@upgradescripts) {
- my $a = $upgradescript;
- $a =~ s/(^$form->{dbdriver}-upgrade-|\.sql$)//g;
-
- my ($mindb, $maxdb) = split /-/, $a;
- $mindb = calc_version($mindb);
- $maxdb = calc_version($maxdb);
-
- next if ($version >= $maxdb);
-
- # exit if there is no upgrade script or version == mindb
- last if ($version < $mindb || $version >= $dbversion);
-
- # apply upgrade
- $self->process_query($form, $dbh, "sql/$upgradescript");
- $dbh->commit;
- $version = $maxdb;
-
- }
-
- $rc = 0;
- $dbh->disconnect;
-
- }
-
- $rc;
+ my $sth = $dbh->prepare($query);
+
+ # no error check, let it fall through
+ $sth->execute;
+
+ my $version = $sth->fetchrow_array;
+ $sth->finish;
+
+ next unless $version;
+
+ $version = calc_version($version);
+ my $dbversion = calc_version( $form->{dbversion} );
+
+ foreach my $upgradescript (@upgradescripts) {
+ my $a = $upgradescript;
+ $a =~ s/(^$form->{dbdriver}-upgrade-|\.sql$)//g;
+
+ my ( $mindb, $maxdb ) = split /-/, $a;
+ $mindb = calc_version($mindb);
+ $maxdb = calc_version($maxdb);
+
+ next if ( $version >= $maxdb );
+
+ # exit if there is no upgrade script or version == mindb
+ last if ( $version < $mindb || $version >= $dbversion );
+
+ # apply upgrade
+ $self->process_query( $form, $dbh, "sql/$upgradescript" );
+ $dbh->commit;
+ $version = $maxdb;
+
+ }
+
+ $rc = 0;
+ $dbh->disconnect;
+
+ }
+
+ $rc;
}
-
sub calc_version {
-
- my @v = split /\./, $_[0];
- my $version = 0;
- my $i;
-
- for ($i = 0; $i <= $#v; $i++) {
- $version *= 1000;
- $version += $v[$i];
- }
-
- return $version;
-
+
+ my @v = split /\./, $_[0];
+ my $version = 0;
+ my $i;
+
+ for ( $i = 0 ; $i <= $#v ; $i++ ) {
+ $version *= 1000;
+ $version += $v[$i];
+ }
+
+ return $version;
+
}
-
sub script_version {
- my ($my_a, $my_b) = ($a, $b);
-
- my ($a_from, $a_to, $b_from, $b_to);
- my ($res_a, $res_b, $i);
-
- $my_a =~ s/.*-upgrade-//;
- $my_a =~ s/.sql$//;
- $my_b =~ s/.*-upgrade-//;
- $my_b =~ s/.sql$//;
- ($a_from, $a_to) = split(/-/, $my_a);
- ($b_from, $b_to) = split(/-/, $my_b);
-
- $res_a = calc_version($a_from);
- $res_b = calc_version($b_from);
-
- if ($res_a == $res_b) {
- $res_a = calc_version($a_to);
- $res_b = calc_version($b_to);
- }
-
- return $res_a <=> $res_b;
-
+ my ( $my_a, $my_b ) = ( $a, $b );
+
+ my ( $a_from, $a_to, $b_from, $b_to );
+ my ( $res_a, $res_b, $i );
+
+ $my_a =~ s/.*-upgrade-//;
+ $my_a =~ s/.sql$//;
+ $my_b =~ s/.*-upgrade-//;
+ $my_b =~ s/.sql$//;
+ ( $a_from, $a_to ) = split( /-/, $my_a );
+ ( $b_from, $b_to ) = split( /-/, $my_b );
+
+ $res_a = calc_version($a_from);
+ $res_b = calc_version($b_from);
+
+ if ( $res_a == $res_b ) {
+ $res_a = calc_version($a_to);
+ $res_b = calc_version($b_to);
+ }
+
+ return $res_a <=> $res_b;
+
}
sub save_member {
- my ($self) = @_;
+ my ($self) = @_;
- # replace \r\n with \n
- for (qw(address signature)) { $self->{$_} =~ s/\r?\n/\\n/g }
+ # replace \r\n with \n
+ for (qw(address signature)) { $self->{$_} =~ s/\r?\n/\\n/g }
- # use central db
- my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
+ # use central db
+ my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
- #check to see if the user exists already
- my $userCheck = $dbh->prepare("SELECT id FROM users WHERE username = ?");
- $userCheck->execute($self->{login});
- my ($userID) = $userCheck->fetchrow_array;
+ #check to see if the user exists already
+ my $userCheck = $dbh->prepare("SELECT id FROM users WHERE username = ?");
+ $userCheck->execute( $self->{login} );
+ my ($userID) = $userCheck->fetchrow_array;
- if (! $self->{dbhost}) {
- $self->{dbhost} = 'localhost';
- }
- if (! $self->{dbport}) {
- $self->{dbport} = '5432';
- }
+ if ( !$self->{dbhost} ) {
+ $self->{dbhost} = 'localhost';
+ }
+ if ( !$self->{dbport} ) {
+ $self->{dbport} = '5432';
+ }
+
+ my $userConfExists = 0;
- my $userConfExists = 0;
+ if ($userID) {
- if($userID){
- #got an id, check to see if it's in the users_conf table
- my $userConfCheck = $dbh->prepare("SELECT password, 1 FROM users_conf WHERE id = ?");
- $userConfCheck->execute($userID);
+ #got an id, check to see if it's in the users_conf table
+ my $userConfCheck =
+ $dbh->prepare("SELECT password, 1 FROM users_conf WHERE id = ?");
+ $userConfCheck->execute($userID);
- ($oldPassword, $userConfExists) = $userConfCheck->fetchrow_array;
- }
- else{
- my $userConfAdd = $dbh->prepare("SELECT create_user(?);");
- $userConfAdd->execute($self->{login});
- ($userID) = $userConfAdd->fetchrow_array;
- }
+ ( $oldPassword, $userConfExists ) = $userConfCheck->fetchrow_array;
+ }
+ else {
+ my $userConfAdd = $dbh->prepare("SELECT create_user(?);");
+ $userConfAdd->execute( $self->{login} );
+ ($userID) = $userConfAdd->fetchrow_array;
+ }
- if($userConfExists){
+ if ($userConfExists) {
- # for now, this is updating the table directly... ugly
- my $userConfUpdate = $dbh->prepare("UPDATE users_conf
+ # for now, this is updating the table directly... ugly
+ my $userConfUpdate = $dbh->prepare(
+ "UPDATE users_conf
SET acs = ?, address = ?, businessnumber = ?,
company = ?, countrycode = ?, currency = ?,
dateformat = ?, dbdriver = ?,
@@ -740,37 +751,47 @@ sub save_member {
sid = ?, signature = ?, stylesheet = ?,
tel = ?, templates = ?, timeout = ?,
vclimit = ?
- WHERE id = ?;");
-
- $userConfUpdate->execute($self->{acs}, $self->{address}, $self->{businessnumber},
- $self->{company}, $self->{countrycode}, $self->{currency},
- $self->{dateformat}, $self->{dbdriver},
- $self->{dbhost}, $self->{dbname}, $self->{dboptions},
- $self->{dbpasswd}, $self->{dbport}, $self->{dbuser},
- $self->{email}, $self->{fax}, $self->{menuwidth},
- $self->{name}, $self->{numberformat},
- $self->{print}, $self->{printer}, $self->{role},
- $self->{sid}, $self->{signature}, $self->{stylesheet},
- $self->{tel}, $self->{templates}, $self->{timeout},
- $self->{vclimit}, $userID);
-
-
- if($oldPassword ne $self->{password}){
- # if they're supplying a 32 char password that matches their old password
- # assume they don't want to change passwords
-
- $userConfUpdate = $dbh->prepare("UPDATE users_conf
+ WHERE id = ?;"
+ );
+
+ $userConfUpdate->execute(
+ $self->{acs}, $self->{address},
+ $self->{businessnumber}, $self->{company},
+ $self->{countrycode}, $self->{currency},
+ $self->{dateformat}, $self->{dbdriver},
+ $self->{dbhost}, $self->{dbname},
+ $self->{dboptions}, $self->{dbpasswd},
+ $self->{dbport}, $self->{dbuser},
+ $self->{email}, $self->{fax},
+ $self->{menuwidth}, $self->{name},
+ $self->{numberformat}, $self->{print},
+ $self->{printer}, $self->{role},
+ $self->{sid}, $self->{signature},
+ $self->{stylesheet}, $self->{tel},
+ $self->{templates}, $self->{timeout},
+ $self->{vclimit}, $userID
+ );
+
+ if ( $oldPassword ne $self->{password} ) {
+
+ # if they're supplying a 32 char password that matches their old password
+ # assume they don't want to change passwords
+
+ $userConfUpdate = $dbh->prepare(
+ "UPDATE users_conf
SET password = md5(?)
- WHERE id = ?");
+ WHERE id = ?"
+ );
- $userConfUpdate->execute($self->{password}, $userID);
+ $userConfUpdate->execute( $self->{password}, $userID );
- }
+ }
- }
- else{
+ }
+ else {
- my $userConfInsert = $dbh->prepare("INSERT INTO users_conf(acs, address, businessnumber,
+ my $userConfInsert = $dbh->prepare(
+ "INSERT INTO users_conf(acs, address, businessnumber,
company, countrycode, currency,
dateformat, dbdriver,
dbhost, dbname, dboptions, dbpasswd,
@@ -780,138 +801,145 @@ sub save_member {
timeout, vclimit, id, password)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
- ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, md5(?));");
-
- $userConfInsert->execute($self->{acs}, $self->{address}, $self->{businessnumber},
- $self->{company}, $self->{countrycode}, $self->{currency},
- $self->{dateformat}, $self->{dbdriver},
- $self->{dbhost}, $self->{dbname}, $self->{dboptions},
- $self->{dbpasswd}, $self->{dbport}, $self->{dbuser},
- $self->{email}, $self->{fax}, $self->{menuwidth},
- $self->{name}, $self->{numberformat},
- $self->{print}, $self->{printer}, $self->{role},
- $self->{sid}, $self->{signature}, $self->{stylesheet},
- $self->{tel}, $self->{templates}, $self->{timeout},
- $self->{vclimit}, $userID, $self->{password});
-
- }
-
- if (! $self->{'admin'}) {
-
- $self->{dbpasswd} =~ s/\\'/'/g;
- $self->{dbpasswd} =~ s/\\\\/\\/g;
-
- # format dbconnect and dboptions string
- &dbconnect_vars($self, $self->{dbname});
-
- # check if login is in database
- my $dbh = DBI->connect(
- $self->{dbconnect}, $self->{dbuser}, $self->{dbpasswd},
- {AutoCommit => 0})
- or $self->error($DBI::errstr);
-
- # add login to employees table if it does not exist
- my $login = $self->{login};
- $login =~ s/@.*//;
- my $sth = $dbh->prepare("SELECT id FROM employees WHERE login = ?;");
- $sth->execute($login);
-
- my ($id) = $sth->fetchrow_array;
- $sth->finish;
- my $employeenumber;
- my @values;
- if ($id) {
-
- $query = qq|UPDATE employees SET
+ ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, md5(?));"
+ );
+
+ $userConfInsert->execute(
+ $self->{acs}, $self->{address},
+ $self->{businessnumber}, $self->{company},
+ $self->{countrycode}, $self->{currency},
+ $self->{dateformat}, $self->{dbdriver},
+ $self->{dbhost}, $self->{dbname},
+ $self->{dboptions}, $self->{dbpasswd},
+ $self->{dbport}, $self->{dbuser},
+ $self->{email}, $self->{fax},
+ $self->{menuwidth}, $self->{name},
+ $self->{numberformat}, $self->{print},
+ $self->{printer}, $self->{role},
+ $self->{sid}, $self->{signature},
+ $self->{stylesheet}, $self->{tel},
+ $self->{templates}, $self->{timeout},
+ $self->{vclimit}, $userID,
+ $self->{password}
+ );
+
+ }
+
+ if ( !$self->{'admin'} ) {
+
+ $self->{dbpasswd} =~ s/\\'/'/g;
+ $self->{dbpasswd} =~ s/\\\\/\\/g;
+
+ # format dbconnect and dboptions string
+ &dbconnect_vars( $self, $self->{dbname} );
+
+ # check if login is in database
+ my $dbh = DBI->connect(
+ $self->{dbconnect}, $self->{dbuser},
+ $self->{dbpasswd}, { AutoCommit => 0 }
+ ) or $self->error($DBI::errstr);
+
+ # add login to employees table if it does not exist
+ my $login = $self->{login};
+ $login =~ s/@.*//;
+ my $sth = $dbh->prepare("SELECT id FROM employees WHERE login = ?;");
+ $sth->execute($login);
+
+ my ($id) = $sth->fetchrow_array;
+ $sth->finish;
+ my $employeenumber;
+ my @values;
+ if ($id) {
+
+ $query = qq|UPDATE employees SET
role = ?,
email = ?,
name = ?
WHERE login = ?|;
- @values = ($self->{role}, $self->{email}, $self->{name}, $login);
+ @values = ( $self->{role}, $self->{email}, $self->{name}, $login );
- } else {
+ }
+ else {
- my ($employeenumber) = Form::update_defaults(
- "", \%$self, "employeenumber", $dbh);
- $query = qq|
+ my ($employeenumber) =
+ Form::update_defaults( "", \%$self, "employeenumber", $dbh );
+ $query = qq|
INSERT INTO employees
(login, employeenumber, name,
workphone, role, email, sales)
VALUES (?, ?, ?, ?, ?, ?, '1')|;
-
- @values = ($login, $employeenumber, $self->{name}, $self->{tel},
- $self->{role}, $self->{email})
- }
- $sth = $dbh->prepare($query);
- $sth->execute(@values);
- $dbh->commit;
- $dbh->disconnect;
+ @values = (
+ $login, $employeenumber, $self->{name},
+ $self->{tel}, $self->{role}, $self->{email}
+ );
+ }
- }
-}
+ $sth = $dbh->prepare($query);
+ $sth->execute(@values);
+ $dbh->commit;
+ $dbh->disconnect;
+ }
+}
sub delete_login {
- my ($self, $form) = @_;
-
- my $dbh = DBI->connect(
- $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd},
- {AutoCommit => 0})
- or $form->dberror(__FILE__.':'.__LINE__);
-
- my $login = $form->{login};
- $login =~ s/@.*//;
- my $query = qq|SELECT id FROM employees WHERE login = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($login) || $form->dberror(__FILE__.':'.__LINE__.': '.$query);
-
- my ($id) = $sth->fetchrow_array;
- $sth->finish;
-
- my $query = qq|
+ my ( $self, $form ) = @_;
+
+ my $dbh = DBI->connect(
+ $form->{dbconnect}, $form->{dbuser},
+ $form->{dbpasswd}, { AutoCommit => 0 }
+ ) or $form->dberror( __FILE__ . ':' . __LINE__ );
+
+ my $login = $form->{login};
+ $login =~ s/@.*//;
+ my $query = qq|SELECT id FROM employees WHERE login = ?|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute($login)
+ || $form->dberror( __FILE__ . ':' . __LINE__ . ': ' . $query );
+
+ my ($id) = $sth->fetchrow_array;
+ $sth->finish;
+
+ my $query = qq|
UPDATE employees
SET login = NULL,
enddate = current_date
WHERE login = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($login);
- $dbh->commit;
- $dbh->disconnect;
+ $sth = $dbh->prepare($query);
+ $sth->execute($login);
+ $dbh->commit;
+ $dbh->disconnect;
}
-
sub config_vars {
-
- my @conf =
- qw(acs address businessnumber company countrycode
- currency dateformat dbconnect dbdriver dbhost dbname dboptions
- dbpasswd dbport dbuser email fax menuwidth name numberformat
- password printer role sid signature stylesheet tel templates
- timeout vclimit);
- @conf;
+ my @conf = qw(acs address businessnumber company countrycode
+ currency dateformat dbconnect dbdriver dbhost dbname dboptions
+ dbpasswd dbport dbuser email fax menuwidth name numberformat
+ password printer role sid signature stylesheet tel templates
+ timeout vclimit);
-}
+ @conf;
+}
sub error {
- my ($self, $msg) = @_;
-
- if ($ENV{GATEWAY_INTERFACE}) {
- print qq|Content-Type: text/html\n\n|.
- qq|<body bgcolor=ffffff>\n\n|.
- qq|<h2><font color=red>Error!</font></h2>\n|.
- qq|<p><b>$msg</b>|;
-
- }
-
- die "Error: $msg\n";
-
-}
+ my ( $self, $msg ) = @_;
+
+ if ( $ENV{GATEWAY_INTERFACE} ) {
+ print qq|Content-Type: text/html\n\n|
+ . qq|<body bgcolor=ffffff>\n\n|
+ . qq|<h2><font color=red>Error!</font></h2>\n|
+ . qq|<p><b>$msg</b>|;
+ }
+
+ die "Error: $msg\n";
+
+}
1;
diff --git a/LedgerSMB/locales.pl b/LedgerSMB/locales.pl
index 0bfc2503..e4ade0d0 100755
--- a/LedgerSMB/locales.pl
+++ b/LedgerSMB/locales.pl
@@ -8,26 +8,30 @@ use FileHandle;
use Getopt::Long;
Getopt::Long::Configure('bundling');
-$basedir = "../..";
-$bindir = "$basedir/bin";
+$basedir = "../..";
+$bindir = "$basedir/bin";
$customdir = "$bindir/custom";
-$menufile = "menu.ini";
+$menufile = "menu.ini";
my $excludeCustom = 0;
-my $buildAll = 0;
-my $noMissing = 0;
-my $goodOpt = 0;
-$goodOpt = GetOptions (
- 'n' => \$excludeCustom, 'no-custom' => \$excludeCustom,
- 'a' => \$buildAll, 'build-all' => \$buildAll,
- 'm' => \$noMissing, 'no-missing' => \$noMissing);
-
-if (!$goodOpt) {
- printf "Invalid options\n";
- exit 1;
+my $buildAll = 0;
+my $noMissing = 0;
+my $goodOpt = 0;
+$goodOpt = GetOptions(
+ 'n' => \$excludeCustom,
+ 'no-custom' => \$excludeCustom,
+ 'a' => \$buildAll,
+ 'build-all' => \$buildAll,
+ 'm' => \$noMissing,
+ 'no-missing' => \$noMissing
+);
+
+if ( !$goodOpt ) {
+ printf "Invalid options\n";
+ exit 1;
}
-open(FH, "LANGUAGE");
+open( FH, "LANGUAGE" );
$language = <FH>;
close(FH);
chomp $language;
@@ -44,325 +48,338 @@ closedir DIR;
@customfiles = () if ($excludeCustom);
if ($excludeCustom) {
- @menufiles = ($menufile);
-} else {
- opendir DIR, "$bindir" or die "$!";
- @menufiles = grep { /.*?_$menufile$/ } readdir DIR;
- closedir DIR;
+ @menufiles = ($menufile);
+}
+else {
+ opendir DIR, "$bindir" or die "$!";
+ @menufiles = grep { /.*?_$menufile$/ } readdir DIR;
+ closedir DIR;
## unshift @menufiles, $menufile;
## opendir DIR, "$customdir" or die "$!";
## @menufiles = grep { /^$menufile$/ } readdir DIR;
## closedir DIR;
- unshift @menufiles, $menufile;
+ unshift @menufiles, $menufile;
}
-if (-f "all") {
- eval { require "all"; };
- %all = %{$self{texts}};
- %{$self{texts}} = ();
-} else {
- # build %all file from individual files
- foreach $file (@progfiles) {
- &scanfile("$bindir/$file");
- }
+if ( -f "all" ) {
+ eval { require "all"; };
+ %all = %{ $self{texts} };
+ %{ $self{texts} } = ();
}
-
+else {
+
+ # build %all file from individual files
+ foreach $file (@progfiles) {
+ &scanfile("$bindir/$file");
+ }
+}
+
# remove the old missing file
-if (-f 'missing') {
- unlink "missing";
+if ( -f 'missing' ) {
+ unlink "missing";
}
-
+
foreach $file (@progfiles) {
-
- next if -d "$bindir/$file";
- %locale = ();
- %submit = ();
- %subrt = ();
- @missing = ();
- %missing = ();
-
- &scanfile("$bindir/$file");
-
- # scan custom_{module}.pl or {login}_{module}.pl files
- foreach $customfile (@customfiles) {
- if ($customfile =~ /_$file/) {
- if (-f "$bindir/$customfile") {
- &scanfile("$bindir/$customfile");
- }
+
+ next if -d "$bindir/$file";
+ %locale = ();
+ %submit = ();
+ %subrt = ();
+ @missing = ();
+ %missing = ();
+
+ &scanfile("$bindir/$file");
+
+ # scan custom_{module}.pl or {login}_{module}.pl files
+ foreach $customfile (@customfiles) {
+ if ( $customfile =~ /_$file/ ) {
+ if ( -f "$bindir/$customfile" ) {
+ &scanfile("$bindir/$customfile");
+ }
+ }
}
- }
-
- # if this is the menu.pl file
- if ($file eq 'menu.pl') {
- foreach $item (@menufiles) {
- &scanmenu("$basedir/$item");
+
+ # if this is the menu.pl file
+ if ( $file eq 'menu.pl' ) {
+ foreach $item (@menufiles) {
+ &scanmenu("$basedir/$item");
+ }
}
- }
-
- $file =~ s/\.pl//;
-
- if (-f "$file.missing") {
- eval { require "$file.missing"; };
- unlink "$file.missing";
-
- for (keys %$missing) {
- $self{texts}{$_} ||= $missing->{$_};
+
+ $file =~ s/\.pl//;
+
+ if ( -f "$file.missing" ) {
+ eval { require "$file.missing"; };
+ unlink "$file.missing";
+
+ for ( keys %$missing ) {
+ $self{texts}{$_} ||= $missing->{$_};
+ }
}
- }
- open FH, '>', "$file" or die "$! : $file";
+ open FH, '>', "$file" or die "$! : $file";
- if ($charset) {
- print FH qq|\$self{charset} = '$charset';\n\n|;
- }
+ if ($charset) {
+ print FH qq|\$self{charset} = '$charset';\n\n|;
+ }
- print FH q|$self{texts} = {
+ print FH q|$self{texts} = {
|;
- foreach $key (sort keys %locale) {
- $text = ($self{texts}{$key}) ? $self{texts}{$key} : $all{$key};
- $count++;
-
- $text =~ s/'/\\'/g;
- $text =~ s/\\$/\\\\/;
-
- $keytext = $key;
- $keytext =~ s/'/\\'/g;
- $keytext =~ s/\\$/\\\\/;
-
- if (!$text) {
- $notext++;
- push @missing, $keytext;
- next;
+ foreach $key ( sort keys %locale ) {
+ $text = ( $self{texts}{$key} ) ? $self{texts}{$key} : $all{$key};
+ $count++;
+
+ $text =~ s/'/\\'/g;
+ $text =~ s/\\$/\\\\/;
+
+ $keytext = $key;
+ $keytext =~ s/'/\\'/g;
+ $keytext =~ s/\\$/\\\\/;
+
+ if ( !$text ) {
+ $notext++;
+ push @missing, $keytext;
+ next;
+ }
+
+ print FH qq| '$keytext'|
+ . ( ' ' x ( 27 - length($keytext) ) )
+ . qq| => '$text',\n|;
}
-
- print FH qq| '$keytext'|.(' ' x (27-length($keytext))).qq| => '$text',\n|;
- }
- print FH q|};
+ print FH q|};
$self{subs} = {
|;
-
- foreach $key (sort keys %subrt) {
- $text = $key;
- $text =~ s/'/\\'/g;
- $text =~ s/\\$/\\\\/;
- print FH qq| '$text'|.(' ' x (27-length($text))).qq| => '$text',\n|;
- }
-
- foreach $key (sort keys %submit) {
- $text = ($self{texts}{$key}) ? $self{texts}{$key} : $all{$key};
- next unless $text;
-
- $text =~ s/'/\\'/g;
- $text =~ s/\\$/\\\\/;
-
- $english_sub = $key;
- $english_sub =~ s/'/\\'/g;
- $english_sub =~ s/\\$/\\\\/;
- $english_sub = lc $key;
-
- $translated_sub = lc $text;
- $english_sub =~ s/( |-|,|\/|\.$)/_/g;
- $translated_sub =~ s/( |-|,|\/|\.$)/_/g;
- print FH qq| '$translated_sub'|.(' ' x (27-length($translated_sub))).qq| => '$english_sub',\n|;
- }
-
- print FH q|};
+
+ foreach $key ( sort keys %subrt ) {
+ $text = $key;
+ $text =~ s/'/\\'/g;
+ $text =~ s/\\$/\\\\/;
+ print FH qq| '$text'|
+ . ( ' ' x ( 27 - length($text) ) )
+ . qq| => '$text',\n|;
+ }
+
+ foreach $key ( sort keys %submit ) {
+ $text = ( $self{texts}{$key} ) ? $self{texts}{$key} : $all{$key};
+ next unless $text;
+
+ $text =~ s/'/\\'/g;
+ $text =~ s/\\$/\\\\/;
+
+ $english_sub = $key;
+ $english_sub =~ s/'/\\'/g;
+ $english_sub =~ s/\\$/\\\\/;
+ $english_sub = lc $key;
+
+ $translated_sub = lc $text;
+ $english_sub =~ s/( |-|,|\/|\.$)/_/g;
+ $translated_sub =~ s/( |-|,|\/|\.$)/_/g;
+ print FH qq| '$translated_sub'|
+ . ( ' ' x ( 27 - length($translated_sub) ) )
+ . qq| => '$english_sub',\n|;
+ }
+
+ print FH q|};
1;
|;
- close FH;
+ close FH;
- if (!$noMissing) {
- if (@missing) {
- open FH, '>', "$file.missing" or die "$! : missing";
+ if ( !$noMissing ) {
+ if (@missing) {
+ open FH, '>', "$file.missing" or die "$! : missing";
- print FH qq|# module $file
+ print FH qq|# module $file
# add the missing texts and run locales.pl to rebuild
\$missing = {
|;
- foreach $text (@missing) {
- $text =~ s/'/\\'/g;
- $text =~ s/\\$/\\\\/;
- print FH qq| '$text'|.(' ' x (27-length($text))).qq| => '',\n|;
- }
+ foreach $text (@missing) {
+ $text =~ s/'/\\'/g;
+ $text =~ s/\\$/\\\\/;
+ print FH qq| '$text'|
+ . ( ' ' x ( 27 - length($text) ) )
+ . qq| => '',\n|;
+ }
- print FH q|};
+ print FH q|};
1;
|;
- close FH;
-
+ close FH;
+
+ }
}
- }
-
- # redo the all file
- if ($buildAll) {
- open FH, '>', "all" or die "$! : all";
+ # redo the all file
+ if ($buildAll) {
+ open FH, '>', "all" or die "$! : all";
- print FH q|# These are all the texts to build the translations files.
+ print FH q|# These are all the texts to build the translations files.
# to build unique strings edit the module files instead
# this file is just a shortcut to build strings which are the same
|;
- if ($charset) {
- print FH qq|\$self{charset} = '$charset';\n\n|;
- }
+ if ($charset) {
+ print FH qq|\$self{charset} = '$charset';\n\n|;
+ }
- print FH q|
+ print FH q|
$self{texts} = {
|;
- foreach $key (sort keys %all) {
- $keytext = $key;
- $keytext =~ s/'/\\'/g;
- $keytext =~ s/\\$/\\\\/;
-
- $text = $all{$key};
- $text =~ s/'/\\'/g;
- $text =~ s/\\$/\\\\/;
- print FH qq| '$keytext'|.(' ' x (27-length($keytext))).qq| => '$text',\n|;
- }
+ foreach $key ( sort keys %all ) {
+ $keytext = $key;
+ $keytext =~ s/'/\\'/g;
+ $keytext =~ s/\\$/\\\\/;
- print FH q|};
+ $text = $all{$key};
+ $text =~ s/'/\\'/g;
+ $text =~ s/\\$/\\\\/;
+ print FH qq| '$keytext'|
+ . ( ' ' x ( 27 - length($keytext) ) )
+ . qq| => '$text',\n|;
+ }
+
+ print FH q|};
1;
|;
- close FH;
-
- }
+ close FH;
+
+ }
}
-$per = sprintf("%.1f", ($count - $notext) / $count * 100);
+$per = sprintf( "%.1f", ( $count - $notext ) / $count * 100 );
print "\n$language - ${per}%\n";
exit;
-# eof
+# eof
sub scanfile {
- my ($file, $level) = @_;
-
- my $fh = new FileHandle;
- return unless (-e $file or $file !~ /custom/);
- open $fh, '<', "$file" or die "$! : $file";
-
- $file =~ s/\.pl//;
- $file =~ s/$bindir\///;
-
- %temp = ();
- for (keys %{$self{texts}}) {
- $temp{$_} = $self{texts}{$_};
- }
-
- # read translation file if it exists
- if (-f $file) {
- eval { do "$file"; };
- for (keys %{$self{texts}}) {
- $all{$_} ||= $self{texts}{$_};
- if ($level) {
- $temp{$_} ||= $self{texts}{$_};
- } else {
- $temp{$_} = $self{texts}{$_};
- }
+ my ( $file, $level ) = @_;
+
+ my $fh = new FileHandle;
+ return unless ( -e $file or $file !~ /custom/ );
+ open $fh, '<', "$file" or die "$! : $file";
+
+ $file =~ s/\.pl//;
+ $file =~ s/$bindir\///;
+
+ %temp = ();
+ for ( keys %{ $self{texts} } ) {
+ $temp{$_} = $self{texts}{$_};
}
- }
-
- %{$self{texts}} = ();
- for (sort keys %temp) {
- $self{texts}{$_} = $temp{$_};
- }
-
-
- while (<$fh>) {
- # is this another file
- if (/require\s+\W.*\.pl/) {
- my $newfile = $&;
- $newfile =~ s/require\s+\W//;
- $newfile =~ s/\$form->{path}\///;
- &scanfile("$basedir/$newfile", 1) if $newfile !~ /_/;
+
+ # read translation file if it exists
+ if ( -f $file ) {
+ eval { do "$file"; };
+ for ( keys %{ $self{texts} } ) {
+ $all{$_} ||= $self{texts}{$_};
+ if ($level) {
+ $temp{$_} ||= $self{texts}{$_};
+ }
+ else {
+ $temp{$_} = $self{texts}{$_};
+ }
+ }
}
-
- # is this a sub ?
- if (/^sub /) {
- ($null, $subrt) = split / +/;
- $subrt{$subrt} = 1;
- next;
+
+ %{ $self{texts} } = ();
+ for ( sort keys %temp ) {
+ $self{texts}{$_} = $temp{$_};
}
-
- my $rc = 1;
-
- while ($rc) {
- if (/Locale/) {
- if (!/^use /) {
- my ($null, $country) = split /,/;
- $country =~ s/^ +["']//;
- $country =~ s/["'].*//;
- }
- }
-
- if (/\$locale->text.*?\W\)/) {
- my $string = $&;
- $string =~ s/\$locale->text\(\s*['"(q|qq)]['\/\\\|~]*//;
- $string =~ s/\W\)+.*$//;
-
- # if there is no $ in the string record it
- unless ($string =~ /\$\D.*/) {
- # this guarantees one instance of string
- $locale{$string} = 1;
-
- # is it a submit button before $locale->
- if (/type="?submit"?/i) {
- $submit{$string} = 1;
- }
- }
- }
-
- # exit loop if there are no more locales on this line
- ($rc) = ($' =~ /\$locale->text/);
- # strip text
- s/^.*?\$locale->text.*?\)//;
+
+ while (<$fh>) {
+
+ # is this another file
+ if (/require\s+\W.*\.pl/) {
+ my $newfile = $&;
+ $newfile =~ s/require\s+\W//;
+ $newfile =~ s/\$form->{path}\///;
+ &scanfile( "$basedir/$newfile", 1 ) if $newfile !~ /_/;
+ }
+
+ # is this a sub ?
+ if (/^sub /) {
+ ( $null, $subrt ) = split / +/;
+ $subrt{$subrt} = 1;
+ next;
+ }
+
+ my $rc = 1;
+
+ while ($rc) {
+ if (/Locale/) {
+ if ( !/^use / ) {
+ my ( $null, $country ) = split /,/;
+ $country =~ s/^ +["']//;
+ $country =~ s/["'].*//;
+ }
+ }
+
+ if (/\$locale->text.*?\W\)/) {
+ my $string = $&;
+ $string =~ s/\$locale->text\(\s*['"(q|qq)]['\/\\\|~]*//;
+ $string =~ s/\W\)+.*$//;
+
+ # if there is no $ in the string record it
+ unless ( $string =~ /\$\D.*/ ) {
+
+ # this guarantees one instance of string
+ $locale{$string} = 1;
+
+ # is it a submit button before $locale->
+ if (/type="?submit"?/i) {
+ $submit{$string} = 1;
+ }
+ }
+ }
+
+ # exit loop if there are no more locales on this line
+ ($rc) = ( $' =~ /\$locale->text/ );
+
+ # strip text
+ s/^.*?\$locale->text.*?\)//;
+ }
}
- }
- close($fh);
+ close($fh);
}
-
sub scanmenu {
- my $file = shift;
-
- my $fh = new FileHandle;
- open $fh, '<', "$file" or die "$! : $file";
-
- my @a = grep /^\[/, <$fh>;
- close($fh);
-
- # strip []
- grep { s/(\[|\])//g } @a;
-
- foreach my $item (@a) {
- $item =~ s/ *$//;
- @b = split /--/, $item;
- foreach $string (@b) {
- chomp $string;
- if ($string !~ /^\s*$/) {
- $locale{$string} = 1;
- }
+ my $file = shift;
+
+ my $fh = new FileHandle;
+ open $fh, '<', "$file" or die "$! : $file";
+
+ my @a = grep /^\[/, <$fh>;
+ close($fh);
+
+ # strip []
+ grep { s/(\[|\])//g } @a;
+
+ foreach my $item (@a) {
+ $item =~ s/ *$//;
+ @b = split /--/, $item;
+ foreach $string (@b) {
+ chomp $string;
+ if ( $string !~ /^\s*$/ ) {
+ $locale{$string} = 1;
+ }
+ }
}
- }
-
-}
+}
diff --git a/SL2LS.pl b/SL2LS.pl
index 3a92b88a..3a04c334 100755
--- a/SL2LS.pl
+++ b/SL2LS.pl
@@ -5,16 +5,17 @@
# Simple script. Right now, all that needs to be done is that the SL directory
# needs to be deleted and the sql-ledger.conf needs to be renamed.
-$filedie = "To install manually:\n" .
- " Rename the sql-ledger.conf to ledger-smb.conf\n".
- " Delete the SL directory (optional but HIGHLY recommended)\n";
-open (SL, "< sql-ledger.conf") || die (
- "Could not open sql-ledger.conf: $! \n\n $filedie");
-open (LS, "> ledger-smb.conf") || die (
- "Could not open ledger-smb.conf: $! \n $filedie");
+$filedie =
+ "To install manually:\n"
+ . " Rename the sql-ledger.conf to ledger-smb.conf\n"
+ . " Delete the SL directory (optional but HIGHLY recommended)\n";
+open( SL, "< sql-ledger.conf" )
+ || die("Could not open sql-ledger.conf: $! \n\n $filedie");
+open( LS, "> ledger-smb.conf" )
+ || die("Could not open ledger-smb.conf: $! \n $filedie");
-while ($line = <SL>){
- print LS $line;
+while ( $line = <SL> ) {
+ print LS $line;
}
unlink "sql-ledger.conf";
@@ -24,20 +25,21 @@ unlink "sql-ledger.conf";
&recursive_unlink("SL");
sub recursive_unlink {
- ($dir) = shift @_;
- print "Recursively deleting $dir\n";
- opendir (DIR, $dir);
- while ($file = readdir DIR){
- if ($file !~ /^\.+$/){
- $file = "$dir/$file";
- if (-f $file){
- unlink $file;
- } elsif (-d $file){
- &recursive_unlink("$file");
- }
- }
- }
- closedir(DIR);
- print "Removing $dir\n";
- rmdir $dir;
+ ($dir) = shift @_;
+ print "Recursively deleting $dir\n";
+ opendir( DIR, $dir );
+ while ( $file = readdir DIR ) {
+ if ( $file !~ /^\.+$/ ) {
+ $file = "$dir/$file";
+ if ( -f $file ) {
+ unlink $file;
+ }
+ elsif ( -d $file ) {
+ &recursive_unlink("$file");
+ }
+ }
+ }
+ closedir(DIR);
+ print "Removing $dir\n";
+ rmdir $dir;
}
diff --git a/admin.pl b/admin.pl
index a3b9de31..c4ae2d48 100755
--- a/admin.pl
+++ b/admin.pl
@@ -9,9 +9,9 @@
# 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,
+# 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):
@@ -53,19 +53,18 @@ require "common.pl";
$| = 1;
-if ($ENV{CONTENT_LENGTH}) {
- read(STDIN, $_, $ENV{CONTENT_LENGTH});
+if ( $ENV{CONTENT_LENGTH} ) {
+ read( STDIN, $_, $ENV{CONTENT_LENGTH} );
}
-if ($ENV{QUERY_STRING}) {
- $_ = $ENV{QUERY_STRING};
+if ( $ENV{QUERY_STRING} ) {
+ $_ = $ENV{QUERY_STRING};
}
-if ($ARGV[0]) {
- $_ = $ARGV[0];
+if ( $ARGV[0] ) {
+ $_ = $ARGV[0];
}
-
%form = split /[&=]/;
# fix for apache 2.0 bug
@@ -74,7 +73,7 @@ map { $form{$_} =~ s/\\$// } keys %form;
# name of this script
$0 =~ tr/\\/\//;
$pos = rindex $0, '/';
-$script = substr($0, $pos + 1);
+$script = substr( $0, $pos + 1 );
#this needs to be a db based function
#if (-e "${LedgerSMB::Sysconfig::userspath}/nologin" && $script ne 'admin.pl') {
@@ -84,26 +83,26 @@ $script = substr($0, $pos + 1);
# exit;
#}
+if ( $form{path} ) {
-if ($form{path}) {
-
- if ($form{path} ne 'bin/lynx'){ $form{path} = 'bin/mozilla';}
+ if ( $form{path} ne 'bin/lynx' ) { $form{path} = 'bin/mozilla'; }
- $ARGV[0] = "$_&script=$script";
- require "bin/$script";
+ $ARGV[0] = "$_&script=$script";
+ require "bin/$script";
-} else {
+}
+else {
- $form{terminal} = "lynx";
+ $form{terminal} = "lynx";
- if ($ENV{HTTP_USER_AGENT} !~ /lynx/i) {
- $form{terminal} = "mozilla";
- }
+ if ( $ENV{HTTP_USER_AGENT} !~ /lynx/i ) {
+ $form{terminal} = "mozilla";
+ }
- $ARGV[0] = "path=bin/$form{terminal}&script=$script";
- map { $ARGV[0] .= "&${_}=$form{$_}" } keys %form;
+ $ARGV[0] = "path=bin/$form{terminal}&script=$script";
+ map { $ARGV[0] .= "&${_}=$form{$_}" } keys %form;
- require "bin/$script";
+ require "bin/$script";
}
diff --git a/bin/aa.pl b/bin/aa.pl
index e1f346f3..08a766f2 100644
--- a/bin/aa.pl
+++ b/bin/aa.pl
@@ -1,1652 +1,2127 @@
-#=====================================================================
-# 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
-#
-# Contributors:
-#
-#
-# Author: DWS Systems Inc.
-# Web: http://www.ledgersmb.org/
-#
-# Contributors:
-#
-# 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.
-#======================================================================
-#
-# AR / AP
-#
-#======================================================================
-
-use LedgerSMB::Tax;
-
-# any custom scripts for this one
-if (-f "bin/custom/aa.pl") {
- eval { require "bin/custom/aa.pl"; };
-}
-if (-f "bin/custom/$form->{login}_aa.pl") {
- eval { require "bin/custom/$form->{login}_aa.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 add {
-
- $form->{title} = "Add";
- $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
-
- &create_links;
-
- $form->{focus} = "amount_1";
- &display_form;
-
-}
-
-
-sub edit {
-
- $form->{title} = "Edit";
-
- &create_links;
- &display_form;
-
-}
-
-
-sub display_form {
-
- &form_header;
- &form_footer;
-
-}
-
-
-sub create_links {
-
- $form->create_links($form->{ARAP}, \%myconfig, $form->{vc});
-
- $duedate = $form->{duedate};
- $taxincluded = $form->{taxincluded};
-
- $form->{formname} = "transaction";
- $form->{format} = "postscript" if $myconfig{printer};
- $form->{media} = $myconfig{printer};
-
- $form->{selectformname} = qq|<option value="transaction">|.$locale->text('Transaction');
-
- if (${LedgerSMB::Sysconfig::latex}) {
- if ($form->{ARAP} eq 'AR') {
- $form->{selectformname} .= qq|
- <option value="receipt">|.$locale->text('Receipt');
- } else {
- $form->{selectformname} .= qq|
- <option value="check">|.$locale->text('Check');
- }
- }
-
- # currencies
- @curr = split /:/, $form->{currencies};
- $form->{defaultcurrency} = $curr[0];
- chomp $form->{defaultcurrency};
-
- for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
-
- AA->get_name(\%myconfig, \%$form);
-
- $form->{currency} =~ s/ //g;
- $form->{duedate} = $duedate if $duedate;
- $form->{taxincluded} = $taxincluded if $form->{id};
-
- $form->{notes} = $form->{intnotes} if !$form->{id};
-
- $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
- $form->{oldtransdate} = $form->{transdate};
-
- # customers/vendors
- $form->{"select$form->{vc}"} = "";
- if (@{ $form->{"all_$form->{vc}"} }) {
- $form->{$form->{vc}} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
- for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
-
- # departments
- if (@{ $form->{all_department} }) {
- $form->{selectdepartment} = "<option>\n";
- $form->{department} = "$form->{department}--$form->{department_id}" if $form->{department_id};
-
- for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
- }
-
- $form->{employee} = "$form->{employee}--$form->{employee_id}";
- # sales staff
- if (@{ $form->{all_employee} }) {
- $form->{selectemployee} = "";
- for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
-
- # projects
- if (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} = "<option>\n";
- for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
- }
-
- if (@{ $form->{all_language} }) {
- $form->{selectlanguage} = "<option>\n";
- for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
- }
-
- # forex
- $form->{forex} = $form->{exchangerate};
- $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
-
- $netamount = 0;
- $tax = 0;
- $taxrate = 0;
- $ml = ($form->{ARAP} eq 'AR') ? 1 : -1;
-
- foreach $key (keys %{ $form->{"$form->{ARAP}_links"} }) {
-
- $form->{"select$key"} = "";
- foreach $ref (@{ $form->{"$form->{ARAP}_links"}{$key} }) {
- if ($key eq "$form->{ARAP}_tax") {
- $form->{"select$form->{ARAP}_tax_$ref->{accno}"} = "<option>$ref->{accno}--$ref->{description}\n";
- next;
- }
- $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
- }
-
- # if there is a value we have an old entry
- for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
- if ($key eq "$form->{ARAP}_paid") {
- $form->{"$form->{ARAP}_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
- $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount} * -1 * $ml;
- $form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};
- $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i-1]->{source};
- $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i-1]->{memo};
-
- $form->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate};
-
- $form->{paidaccounts}++;
- } else {
-
- $akey = $key;
- $akey =~ s/$form->{ARAP}_//;
-
- if ($key eq "$form->{ARAP}_tax") {
- $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
- $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = $form->{acc_trans}{$key}->[$i-1]->{amount} * $ml;
-
- $tax += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
- $taxrate += $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
-
- } else {
- $form->{"${akey}_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount} * $ml;
-
- if ($akey eq 'amount') {
- $form->{"description_$i"} = $form->{acc_trans}{$key}->[$i-1]->{memo};
- $form->{rowcount}++;
- $netamount += $form->{"${akey}_$i"};
-
- $form->{"projectnumber_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}--$form->{acc_trans}{$key}->[$i-1]->{project_id}" if $form->{acc_trans}{$key}->[$i-1]->{project_id};
- } else {
- $form->{invtotal} = $form->{acc_trans}{$key}->[$i-1]->{amount} * -1 * $ml;
- }
- $form->{"${key}_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
- }
- }
- }
- }
-
- $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
-
- if ($form->{taxincluded}) {
- $diff = 0;
- # add tax to individual amounts
- # XXX needs alteration for conditional taxes
- for $i (1 .. $form->{rowcount}) {
- if ($netamount) {
- $amount = $form->{"amount_$i"} * (1 + $tax / $netamount);
- $form->{"amount_$i"} = $form->round_amount($amount, 2);
- }
- }
- }
-
- $form->{invtotal} = $netamount + $tax;
-
- # check if calculated is equal to stored
- # taxincluded is terrible to calculate
- # this works only if all taxes are checked
-
- @taxaccounts = Tax::init_taxes($form, $form->{taxaccounts});
-
- if ($form->{id}) {
- if ($form->{taxincluded}) {
-
- $amount = Tax::calculate_taxes(\@taxaccounts, $form,
- $form->{invtotal}, 1);
- $tax = $form->round_amount($amount, 2);
-
- } else {
- $tax = $form->round_amount(Tax::calculate_taxes(\@taxaccounts,
- $form, $netamount, 0));
- }
- foreach $item (@taxaccounts) {
- $tax{$item->account} = $form->round_amount($item->value, 2);
- $form->{"calctax_".$item->account} = 1 if $item->value and (
- $tax{$item->account} == $form->{"tax_".$item->account});
- }
- } else {
- for (@taxaccounts) { $form->{"calctax_".$_->account} = 1 }
- }
-
-
- $form->{rowcount}++ if ($form->{id} || !$form->{rowcount});
-
- $form->{$form->{ARAP}} = $form->{"$form->{ARAP}_1"};
- $form->{rowcount} = 1 unless $form->{"$form->{ARAP}_amount_1"};
-
- $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
-
- # readonly
- if (! $form->{readonly}) {
- $form->{readonly} = 1 if $myconfig{acs} =~ /$form->{ARAP}--Add Transaction/;
- }
-
-}
-
-
-sub form_header {
-
- $title = $form->{title};
- $form->{title} = $locale->text("$title $form->{ARAP} Transaction");
-
- $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
-
-# $locale->text('Add AR Transaction')
-# $locale->text('Edit AR Transaction')
-# $locale->text('Add AP Transaction')
-# $locale->text('Edit AP Transaction')
-
- # set option selected
- for ("$form->{ARAP}", "currency") {
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/<option>\Q$form->{$_}\E/<option selected>$form->{$_}/;
- }
-
- for ("$form->{vc}", "department", "employee", "formname") {
- $form->{"select$_"} = $form->unescape($form->{"select$_"});
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
- }
-
- $form->{selectprojectnumber} = $form->unescape($form->{selectprojectnumber});
-
- # format amounts
- $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><input type=hidden name=exchangerate value=$form->{exchangerate}>$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>
-|;
-
- $taxincluded = "";
- if ($form->{taxaccounts}) {
- $taxincluded = qq|
- <tr>
- <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
- <th align=left nowrap>|.$locale->text('Tax Included').qq|</th>
- </tr>
-|;
- }
-
-
- if (($rows = $form->numtextrows($form->{notes}, 50) - 1) < 2) {
- $rows = 2;
- }
- $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
-
- $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};
-
-
- $n = ($form->{creditremaining} < 0) ? "0" : "1";
-
- $name = ($form->{"select$form->{vc}"}) ? qq|<select name="$form->{vc}">$form->{"select$form->{vc}"}</select>| : qq|<input name="$form->{vc}" value="$form->{$form->{vc}}" size=35>|;
-
- $employee = qq|
- <input type=hidden name=employee value="$form->{employee}">
-|;
-
- if ($form->{selectemployee}) {
- $label = ($form->{ARAP} eq 'AR') ? $locale->text('Salesperson') : $locale->text('Employee');
-
- $employee = qq|
- <tr>
- <th align=right nowrap>$label</th>
- <td><select name=employee>$form->{selectemployee}</select></td>
- <input type=hidden name=selectemployee value="|.$form->escape($form->{selectemployee},1).qq|">
- </tr>
-|;
- }
-
- $focus = ($form->{focus}) ? $form->{focus} : "amount_$form->{rowcount}";
-
- $form->header;
-
- print qq|
-<body onload="document.forms[0].${focus}.focus()" />
-
-<form method=post action=$form->{script}>
-
-<input type=hidden name=type value="$form->{formname}">
-<input type=hidden name=title value="$title">
-
-|;
-
- $form->hide_form(qw(id printed emailed sort closedto locked oldtransdate audittrail recurring checktax));
-
- if ($form->{vc} eq 'customer') {
- $label = $locale->text('Customer');
- } else {
- $label = $locale->text('Vendor');
- }
-
- $form->hide_form("old$form->{vc}", "$form->{vc}_id", "terms", "creditlimit", "creditremaining", "selectcurrency", "defaultcurrency", "select$form->{ARAP}_amount", "rowcount");
-
- print qq|
-
-<table width=100%>
- <tr class=listtop>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr valign=top>
- <td>
- <table width=100%>
- <tr valign=top>
- <td>
- <table>
- <tr>
- <th align="right" nowrap>$label</th>
- <td colspan=3>$name</td>
- <input type=hidden name="select$form->{vc}" value="|.$form->escape($form->{"select$form->{vc}"},1).qq|">
- </tr>
- <tr>
- <td></td>
- <td colspan=3>
- <table width=100%>
- <tr>
- <th align=left nowrap>|.$locale->text('Credit Limit').qq|</th>
- <td>$form->{creditlimit}</td>
- <th align=left nowrap>|.$locale->text('Remaining').qq|</th>
- <td class="plus$n">|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</td>
- </tr>
- </table>
- </td>
- </tr>
- $exchangerate
- $department
- $taxincluded
- </table>
- </td>
- <td align=right>
- <table>
- $employee
- <tr>
- <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
- <td><input name=invnumber size=20 value="$form->{invnumber}"></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
- <td><input name=ordnumber size=20 value="$form->{ordnumber}"></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Invoice Date').qq|</th>
- <td><input name=transdate size=11 title="($myconfig{'dateformat'})" value=$form->{transdate}></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Due Date').qq|</th>
- <td><input name=duedate size=11 title="$myconfig{'dateformat'}" value=$form->{duedate}></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('PO Number').qq|</th>
- <td><input name=ponumber size=20 value="$form->{ponumber}"></td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">
- <tr>
- <td>
- <table>
-|;
-
- $project = qq|
- <th>|.$locale->text('Project').qq|</th>
-| if $form->{selectprojectnumber};
-
- print qq|
- <tr>
- <th>|.$locale->text('Amount').qq|</th>
- <th></th>
- <th>|.$locale->text('Account').qq|</th>
- <th>|.$locale->text('Description').qq|</th>
- $project
- </tr>
-|;
-
- for $i (1 .. $form->{rowcount}) {
-
- $selectamount = $form->{"select$form->{ARAP}_amount"};
- $selectamount =~ s/option>\Q$form->{"$form->{ARAP}_amount_$i"}\E/option selected>$form->{"$form->{ARAP}_amount_$i"}/;
-
- $selectprojectnumber = $form->{selectprojectnumber};
- $selectprojectnumber =~ s/(<option value="\Q$form->{"projectnumber_$i"}\E")/$1 selected/;
-
- # format amounts
- $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
-
- $project = qq|
- <td align=right><select name="projectnumber_$i">$selectprojectnumber</select></td>
-| if $form->{selectprojectnumber};
-
- if (($rows = $form->numtextrows($form->{"description_$i"}, 40)) > 1) {
- $description = qq|<td><textarea name="description_$i" rows=$rows cols=40>$form->{"description_$i"}</textarea></td>|;
- } else {
- $description = qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
- }
-
- print qq|
- <tr valign=top>
- <td><input name="amount_$i" size=10 value="$form->{"amount_$i"}" accesskey="$i"></td>
- <td></td>
- <td><select name="$form->{ARAP}_amount_$i">$selectamount</select></td>
- $description
- $project
- </tr>
-|;
- }
-
- foreach $item (split / /, $form->{taxaccounts}) {
-
- $form->{"calctax_$item"} = ($form->{"calctax_$item"}) ? "checked" : "";
-
- $form->{"tax_$item"} = $form->format_amount(\%myconfig, $form->{"tax_$item"}, 2);
-
- print qq|
- <tr>
- <td><input name="tax_$item" size=10 value=$form->{"tax_$item"}></td>
- <td align=right><input name="calctax_$item" class=checkbox type=checkbox value=1 $form->{"calctax_$item"}></td>
- <td><select name="$form->{ARAP}_tax_$item">$form->{"select$form->{ARAP}_tax_$item"}</select></td>
- </tr>
-|;
-
- $form->hide_form("${item}_rate", "${item}_description", "${item}_taxnumber", "select$form->{ARAP}_tax_$item");
- }
-
- $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
-
- $form->hide_form("oldinvtotal", "oldtotalpaid", "taxaccounts", "select$form->{ARAP}");
-
- print qq|
- <tr>
- <th align=left>$form->{invtotal}</th>
- <td></td>
- <td><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select></td>
- </tr>
- <tr>
- <th align=right>|.$locale->text('Notes').qq|</th>
- <td></td>
- <td colspan=3>$notes</td>
- </tr>
- </table>
- </td>
- </tr>
-
- <tr class=listheading>
- <th class=listheading>|.$locale->text('Payments').qq|</th>
- </tr>
-
- <tr>
- <td>
- <table width=100%>
-|;
-
- if ($form->{currency} eq $form->{defaultcurrency}) {
- @column_index = qw(datepaid source memo paid ARAP_paid);
- } else {
- @column_index = qw(datepaid source memo paid exchangerate ARAP_paid);
- }
-
- $column_data{datepaid} = "<th>".$locale->text('Date')."</th>";
- $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
- $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";
- $column_data{ARAP_paid} = "<th>".$locale->text('Account')."</th>";
- $column_data{source} = "<th>".$locale->text('Source')."</th>";
- $column_data{memo} = "<th>".$locale->text('Memo')."</th>";
-
- print "
- <tr>
-";
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print "
- </tr>
-";
-
-
- $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
- for $i (1 .. $form->{paidaccounts}) {
-
- $form->hide_form("cleared_$i");
-
- print "
- <tr>
-";
-
- $form->{"select$form->{ARAP}_paid_$i"} = $form->{"select$form->{ARAP}_paid"};
- $form->{"select$form->{ARAP}_paid_$i"} =~ s/option>\Q$form->{"$form->{ARAP}_paid_$i"}\E/option selected>$form->{"$form->{ARAP}_paid_$i"}/;
-
- # format amounts
- $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
- $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
-
- $exchangerate = qq|&nbsp;|;
- if ($form->{currency} ne $form->{defaultcurrency}) {
- if ($form->{"forex_$i"}) {
- $form->hide_form("exchangerate_$i");
- $exchangerate = qq|$form->{"exchangerate_$i"}|;
- } else {
- $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
- }
- }
-
- $form->hide_form("forex_$i");
-
- $column_data{paid} = qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
- $column_data{ARAP_paid} = qq|<td align=center><select name="$form->{ARAP}_paid_$i">$form->{"select$form->{ARAP}_paid_$i"}</select></td>|;
- $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
- $column_data{datepaid} = qq|<td align=center><input name="datepaid_$i" size=11 value=$form->{"datepaid_$i"}></td>|;
- $column_data{source} = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
- $column_data{memo} = qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
-
- for (@column_index) { print qq|$column_data{$_}\n| }
-
- print "
- </tr>
-";
- }
-
- $form->hide_form("paidaccounts", "select$form->{ARAP}_paid");
-
- print qq|
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-|;
-
-}
-
-
-sub form_footer {
-
- $form->hide_form(qw(callback path login sessionid));
-
- $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('Schedule')
-# type=submit $locale->text('Ship to')
-# type=submit $locale->text('Post as new')
-# type=submit $locale->text('Print and Post as new')
-# type=submit $locale->text('Delete')
-
- if (! $form->{readonly}) {
-
- &print_options;
-
- print "<br>";
-
- %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') },
- 'post_as_new' => { ndx => 5, key => 'N', value => $locale->text('Post as new') },
- 'print_and_post_as_new' => { ndx => 6, key => 'W', value => $locale->text('Print and Post as new') },
- 'schedule' => { ndx => 7, key => 'H', value => $locale->text('Schedule') },
- 'delete' => { ndx => 8, key => 'D', value => $locale->text('Delete') },
- );
-
- if ($form->{id}) {
-
- if ($form->{locked} || ($transdate && $transdate <= $closedto)) {
- for ("post", "print_and_post", "delete") { delete $button{$_} }
- }
-
- if (!${LedgerSMB::Sysconfig::latex}) {
- for ("print_and_post", "print_and_post_as_new") { delete $button{$_} }
- }
-
- } else {
-
- for ("post_as_new", "print_and_post_as_new", "delete") { delete $button{$_} }
- delete $button{"print_and_post"} if ! ${LedgerSMB::Sysconfig::latex};
-
- if ($transdate && $transdate <= $closedto) {
- for ("post", "print_and_post") { delete $button{$_} }
- }
- }
-
- 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 update {
- my $display = shift;
-
- if (!$display) {
-
- $form->{invtotal} = 0;
-
- $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
-
- @flds = ("amount", "$form->{ARAP}_amount", "projectnumber", "description");
- $count = 0;
- @a = ();
- for $i (1 .. $form->{rowcount}) {
- $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
- if ($form->{"amount_$i"}) {
- push @a, {};
- $j = $#a;
-
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
- }
- }
-
- $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
- $form->{rowcount} = $count + 1;
-
- for (1 .. $form->{rowcount}) { $form->{invtotal} += $form->{"amount_$_"} }
-
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, ($form->{ARAP} eq 'AR') ? 'buy' : 'sell')));
-
- if ($newname = &check_name($form->{vc})) {
- $form->{notes} = $form->{intnotes} unless $form->{id};
- &rebuild_vc($form->{vc}, $form->{ARAP}, $form->{transdate});
- }
- if ($form->{transdate} ne $form->{oldtransdate}) {
- $form->{duedate} = $form->current_date(\%myconfig, $form->{transdate}, $form->{terms} * 1);
- $form->{oldtransdate} = $form->{transdate};
- $newproj = &rebuild_vc($form->{vc}, $form->{ARAP}, $form->{transdate}) if ! $newname;
- $form->all_projects(\%myconfig, undef, $form->{transdate}) if ! $newproj;
-
- $form->{selectemployee} = "";
- if (@{ $form->{all_employee} }) {
- for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
- }
- }
-
- # recalculate taxes
- @taxaccounts = split / /, $form->{taxaccounts};
-
- for (@taxaccounts) { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) }
-
- @taxaccounts = Tax::init_taxes($form, $form->{taxaccounts});
- if ($form->{taxincluded}) {
- $totaltax = Tax::calculate_taxes(\@taxaccounts, $form,
- $form->{invtotal}, 1);
- } else {
- $totaltax = Tax::calculate_taxes(\@taxaccounts, $form,
- $form->{invtotal}, 0);
- }
- foreach $item (@taxaccounts) {
- $taccno = $item->account;
- if ($form->{calctax}) {
- $form->{"calctax_$taccno"} = 1;
- $form->{"tax_$taccno"} = $form->round_amount($item->value, 2);
- }
- $form->{"select$form->{ARAP}_tax_$taccno"} = qq|<option>$taccno--$form->{"${taccno}_description"}|;
- }
-
- $form->{invtotal} = ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
-
- $j = 1;
- for $i (1 .. $form->{paidaccounts}) {
- if ($form->{"paid_$i"}) {
- for (qw(datepaid source memo cleared)) { $form->{"${_}_$j"} = $form->{"${_}_$i"} }
- for (qw(paid exchangerate)) { $form->{"${_}_$j"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- $totalpaid += $form->{"paid_$j"};
-
- $form->{"exchangerate_$j"} = $exchangerate if ($form->{"forex_$j"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$j"}, ($form->{ARAP} eq 'AR') ? 'buy' : 'sell')));
-
- if ($j++ != $i) {
- for (qw(datepaid source memo paid exchangerate forex cleared)) { delete $form->{"${_}_$i"} }
- }
- } else {
- for (qw(datepaid source memo paid exchangerate forex cleared)) { delete $form->{"${_}_$i"} }
- }
- }
- $form->{paidaccounts} = $j;
-
- $form->{creditremaining} -= ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} - $form->{oldinvtotal});
- $form->{oldinvtotal} = $form->{invtotal};
- $form->{oldtotalpaid} = $totalpaid;
-
- &display_form;
-
-}
-
-
-sub post {
-
- $label = ($form->{vc} eq 'customer') ? $locale->text('Customer missing!') : $locale->text('Vendor missing!');
-
- # check if there is an invoice number, invoice and due date
- $form->isblank("transdate", $locale->text('Invoice Date missing!'));
- $form->isblank("duedate", $locale->text('Due Date missing!'));
- $form->isblank($form->{vc}, $label);
-
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
- $transdate = $form->datetonum(\%myconfig, $form->{transdate});
-
- $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
-
- $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
-
- for $i (1 .. $form->{paidaccounts}) {
- if ($form->{"paid_$i"}) {
- $datepaid = $form->datetonum(\%myconfig, $form->{"datepaid_$i"});
-
- $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
-
- $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
-
- if ($form->{currency} ne $form->{defaultcurrency}) {
- $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
- $form->isblank("exchangerate_$i", $locale->text('Exchange rate for payment missing!'));
- }
- }
- }
-
- # if oldname ne name redo form
- ($name) = split /--/, $form->{$form->{vc}};
- if ($form->{"old$form->{vc}"} ne qq|$name--$form->{"$form->{vc}_id"}|) {
- &update;
- exit;
- }
-
- if (! $form->{repost}) {
- if ($form->{id}) {
- &repost;
- exit;
- }
- }
-
- if (AA->post_transaction(\%myconfig, \%$form)) {
- $form->update_status(\%myconfig);
- if ($form->{printandpost}){
- &{ "print_$form->{formname}" }($old_form, 1);
- }
- $form->redirect($locale->text('Transaction posted!'));
- } else {
- $form->error($locale->text('Cannot post transaction!'));
- }
-
-}
-
-
-sub delete {
-
- $form->{title} = $locale->text('Confirm!');
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-|;
-
- $form->{action} = "yes";
- $form->hide_form;
-
- print qq|
-<h2 class=confirm>$form->{title}</h2>
-
-<h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{invnumber}</h4>
-
-<button name="action" class="submit" type="submit" value="yes">|.$locale->text('Yes').qq|</button>
-</form>
-
-</body>
-</html>
-|;
-
-}
-
-
-
-sub yes {
-
- if (AA->delete_transaction(\%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool})) {
- $form->redirect($locale->text('Transaction deleted!'));
- } else {
- $form->error($locale->text('Cannot delete transaction!'));
- }
-
-}
-
-
-sub search {
-
- $form->create_links($form->{ARAP}, \%myconfig, $form->{vc});
-
- $form->{"select$form->{ARAP}"} = "<option>\n";
- for (@{ $form->{"$form->{ARAP}_links"}{$form->{ARAP}} }) { $form->{"select$form->{ARAP}"} .= "<option>$_->{accno}--$_->{description}\n" }
-
- if (@{ $form->{"all_$form->{vc}"} }) {
- $selectname = "";
- for (@{ $form->{"all_$form->{vc}"} }) { $selectname .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- $selectname = qq|<select name="$form->{vc}"><option>\n$selectname</select>|;
- } else {
- $selectname = qq|<input name=$form->{vc} size=35>|;
- }
-
- # departments
- if (@{ $form->{all_department} }) {
- $form->{selectdepartment} = "<option>\n";
-
- for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
-
- $l_department = qq|<input name="l_department" class=checkbox type=checkbox value=Y> |.$locale->text('Department');
-
- $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->{all_employee} }) {
- $form->{selectemployee} = "<option>\n";
- for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
-
- $employeelabel = ($form->{ARAP} eq 'AR') ? $locale->text('Salesperson') : $locale->text('Employee');
-
- $employee = qq|
- <tr>
- <th align=right nowrap>$employeelabel</th>
- <td colspan=3><select name=employee>$form->{selectemployee}</select></td>
- </tr>
-|;
-
- $l_employee = qq|<input name="l_employee" class=checkbox type=checkbox value=Y> $employeelabel|;
-
- $l_manager = qq|<input name="l_manager" class=checkbox type=checkbox value=Y> |.$locale->text('Manager');
- }
-
-
- $form->{title} = ($form->{ARAP} eq 'AR') ? $locale->text('AR Transactions') : $locale->text('AP Transactions');
-
- $invnumber = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
- <td colspan=3><input name=invnumber size=20></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
- <td colspan=3><input name=ordnumber size=20></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('PO Number').qq|</th>
- <td colspan=3><input name=ponumber size=20></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Source').qq|</th>
- <td colspan=3><input name=source size=40></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Description').qq|</th>
- <td colspan=3><input name=description size=40></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Notes').qq|</th>
- <td colspan=3><input name=notes size=40></td>
- </tr>
-|;
-
- $openclosed = qq|
- <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>
-|;
-
- $summary = qq|
- <tr>
- <td><input name=summary type=radio class=radio value=1 checked> |.$locale->text('Summary').qq|</td>
- <td><input name=summary type=radio class=radio value=0> |.$locale->text('Detail').qq|
- </td>
- </tr>
-|;
-
-
- if ($form->{outstanding}) {
- $form->{title} = ($form->{ARAP} eq 'AR') ? $locale->text('AR Outstanding') : $locale->text('AP Outstanding');
- $invnumber = "";
- $openclosed = "";
- $summary = "";
- }
-
- 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>
-|;
- }
-
-
- $name = $locale->text('Customer');
- $l_name = qq|<input name="l_name" class=checkbox type=checkbox value=Y checked> $name|;
- $l_till = qq|<input name="l_till" class=checkbox type=checkbox value=Y> |.$locale->text('Till');
-
- if ($form->{vc} eq 'vendor') {
- $name = $locale->text('Vendor');
- $l_till = "";
- $l_name = qq|<input name="l_name" class=checkbox type=checkbox value=Y checked> $name|;
- }
-
- @a = ();
- push @a, qq|<input name="l_runningnumber" class=checkbox type=checkbox value=Y> |.$locale->text('No.');
- push @a, qq|<input name="l_id" class=checkbox type=checkbox value=Y> |.$locale->text('ID');
- push @a, qq|<input name="l_invnumber" class=checkbox type=checkbox value=Y checked> |.$locale->text('Invoice Number');
- push @a, qq|<input name="l_ordnumber" class=checkbox type=checkbox value=Y> |.$locale->text('Order Number');
- push @a, qq|<input name="l_ponumber" class=checkbox type=checkbox value=Y> |.$locale->text('PO Number');
- push @a, qq|<input name="l_transdate" class=checkbox type=checkbox value=Y checked> |.$locale->text('Invoice Date');
- push @a, $l_name;
- push @a, $l_employee if $l_employee;
- push @a, $l_manager if $l_employee;
- push @a, $l_department if $l_department;
- push @a, qq|<input name="l_netamount" class=checkbox type=checkbox value=Y> |.$locale->text('Amount');
- push @a, qq|<input name="l_tax" class=checkbox type=checkbox value=Y> |.$locale->text('Tax');
- push @a, qq|<input name="l_amount" class=checkbox type=checkbox value=Y checked> |.$locale->text('Total');
- push @a, qq|<input name="l_curr" class=checkbox type=checkbox value=Y> |.$locale->text('Currency');
- push @a, qq|<input name="l_datepaid" class=checkbox type=checkbox value=Y> |.$locale->text('Date Paid');
- push @a, qq|<input name="l_paid" class=checkbox type=checkbox value=Y checked> |.$locale->text('Paid');
- push @a, qq|<input name="l_duedate" class=checkbox type=checkbox value=Y> |.$locale->text('Due Date');
- push @a, qq|<input name="l_due" class=checkbox type=checkbox value=Y> |.$locale->text('Amount Due');
- push @a, qq|<input name="l_notes" class=checkbox type=checkbox value=Y> |.$locale->text('Notes');
- push @a, $l_till if $l_till;
- push @a, qq|<input name="l_shippingpoint" class=checkbox type=checkbox value=Y> |.$locale->text('Shipping Point');
- push @a, qq|<input name="l_shipvia" class=checkbox type=checkbox value=Y> |.$locale->text('Ship via');
-
- $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>
- <table>
- <tr>
- <th align=right>|.$locale->text('Account').qq|</th>
- <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select></td>
- </tr>
- <tr>
- <th align=right>$name</th>
- <td colspan=3>$selectname</td>
- </tr>
- $employee
- $department
- $invnumber
- <tr>
- <th align=right>|.$locale->text('Ship via').qq|</th>
- <td colspan=3><input name=shipvia size=40></td>
- </tr>
- <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>
- <table>
- <tr>
- <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
- <td>
- <table width=100%>
- $openclosed
- $summary
-|;
-
- $form->{sort} = "transdate";
- $form->hide_form(qw(title outstanding sort));
-
-
- while (@a) {
- for (1 .. 5) {
- print qq|<td nowrap>|. shift @a;
- print qq|</td>\n|;
- }
- print qq|</tr>\n|;
- }
-
- print qq|
- <tr>
- <td nowrap><input name="l_subtotal" class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<br>
-<input type="hidden" name="action" value="continue">
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>|;
-
- $form->hide_form(qw(nextsub path login sessionid));
-
- print qq|
-</form>
-|;
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
-
-</body>
-</html>
-|;
-
-}
-
-
-sub transactions {
-
- if ($form->{$form->{vc}}) {
- $form->{$form->{vc}} = $form->unescape($form->{$form->{vc}});
- ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}});
- }
-
- AA->transactions(\%myconfig, \%$form);
-
- $href = "$form->{script}?action=transactions";
- for (qw(direction oldsort till outstanding path login sessionid summary)) { $href .= qq|&$_=$form->{$_}| }
- $href .= "&title=".$form->escape($form->{title});
-
- $form->sort_order();
-
- $callback = "$form->{script}?action=transactions";
- for (qw(direction oldsort till outstanding path login sessionid summary)) { $callback .= qq|&$_=$form->{$_}| }
- $callback .= "&title=".$form->escape($form->{title},1);
-
- if ($form->{$form->{ARAP}}) {
- $callback .= "&$form->{ARAP}=".$form->escape($form->{$form->{ARAP}},1);
- $href .= "&$form->{ARAP}=".$form->escape($form->{$form->{ARAP}});
- $form->{$form->{ARAP}} =~ s/--/ /;
- $option = $locale->text('Account')." : $form->{$form->{ARAP}}";
- }
-
- if ($form->{$form->{vc}}) {
- $callback .= "&$form->{vc}=".$form->escape($form->{$form->{vc}},1).qq|--$form->{"$form->{vc}_id"}|;
- $href .= "&$form->{vc}=".$form->escape($form->{$form->{vc}}).qq|--$form->{"$form->{vc}_id"}|;
- $option .= "\n<br>" if ($option);
- $name = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor');
- $option .= "$name : $form->{$form->{vc}}";
- }
- if ($form->{department}) {
- $callback .= "&department=".$form->escape($form->{department},1);
- $href .= "&department=".$form->escape($form->{department});
- ($department) = split /--/, $form->{department};
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Department')." : $department";
- }
- if ($form->{employee}) {
- $callback .= "&employee=".$form->escape($form->{employee},1);
- $href .= "&employee=".$form->escape($form->{employee});
- ($employee) = split /--/, $form->{employee};
- $option .= "\n<br>" if ($option);
- if ($form->{ARAP} eq 'AR') {
- $option .= $locale->text('Salesperson');
- } else {
- $option .= $locale->text('Employee');
- }
- $option .= " : $employee";
- }
-
- 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->{ponumber}) {
- $callback .= "&ponumber=".$form->escape($form->{ponumber},1);
- $href .= "&ponumber=".$form->escape($form->{ponumber});
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('PO Number')." : $form->{ponumber}";
- }
- 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->{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->{notes}) {
- $callback .= "&notes=".$form->escape($form->{notes},1);
- $href .= "&notes=".$form->escape($form->{notes});
- $option .= "\n<br>" if $option;
- $option .= $locale->text('Notes')." : $form->{notes}";
- }
- if ($form->{shipvia}) {
- $callback .= "&shipvia=".$form->escape($form->{shipvia},1);
- $href .= "&shipvia=".$form->escape($form->{shipvia});
- $option .= "\n<br>" if $option;
- $option .= $locale->text('Ship via')." : $form->{shipvia}";
- }
- 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 [_1]', $locale->date(\%myconfig, $form->{transdateto}, 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');
- }
-
- @columns = $form->sort_columns(qw(transdate id invnumber ordnumber ponumber name netamount tax amount paid due curr datepaid duedate notes till employee manager shippingpoint shipvia department));
- pop @columns if $form->{department};
- unshift @columns, "runningnumber";
-
- foreach $item (@columns) {
- if ($form->{"l_$item"} eq "Y") {
- push @column_index, $item;
-
- if ($form->{l_curr} && $item =~ /(amount|tax|paid|due)/) {
- push @column_index, "fx_$item";
- }
-
- # add column to href and callback
- $callback .= "&l_$item=Y";
- $href .= "&l_$item=Y";
- }
- }
-
- if (!$form->{summary}) {
- foreach $item (qw(source debit credit accno description projectnumber)) {
- push @column_index, $item;
- }
- }
-
- if ($form->{l_subtotal} eq 'Y') {
- $callback .= "&l_subtotal=Y";
- $href .= "&l_subtotal=Y";
- }
-
- $employee = ($form->{ARAP} eq 'AR') ? $locale->text('Salesperson') : $locale->text('Employee');
- $name = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor');
-
- $column_header{runningnumber} = qq|<th class=listheading>&nbsp;</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{duedate} = "<th><a class=listheading href=$href&sort=duedate>".$locale->text('Due 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{ponumber} = "<th><a class=listheading href=$href&sort=ponumber>".$locale->text('PO Number')."</a></th>";
- $column_header{name} = "<th><a class=listheading href=$href&sort=name>$name</a></th>";
- $column_header{netamount} = "<th class=listheading>" . $locale->text('Amount') . "</th>";
- $column_header{tax} = "<th class=listheading>" . $locale->text('Tax') . "</th>";
- $column_header{amount} = "<th class=listheading>" . $locale->text('Total') . "</th>";
- $column_header{paid} = "<th class=listheading>" . $locale->text('Paid') . "</th>";
- $column_header{datepaid} = "<th><a class=listheading href=$href&sort=datepaid>" . $locale->text('Date Paid') . "</a></th>";
- $column_header{due} = "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
- $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>";
- $column_header{employee} = "<th><a class=listheading href=$href&sort=employee>$employee</th>";
- $column_header{manager} = "<th><a class=listheading href=$href&sort=manager>".$locale->text('Manager')."</th>";
- $column_header{till} = "<th class=listheading><a class=listheading href=$href&sort=till>".$locale->text('Till')."</th>";
-
- $column_header{shippingpoint} = "<th><a class=listheading href=$href&sort=shippingpoint>" . $locale->text('Shipping Point') . "</a></th>";
- $column_header{shipvia} = "<th><a class=listheading href=$href&sort=shipvia>" . $locale->text('Ship via') . "</a></th>";
-
- $column_header{curr} = "<th><a class=listheading href=$href&sort=curr>" . $locale->text('Curr') . "</a></th>";
- for (qw(amount tax netamount paid due)) { $column_header{"fx_$_"} = "<th>&nbsp;</th>" }
-
- $column_header{department} = "<th><a class=listheading href=$href&sort=department>" . $locale->text('Department') . "</a></th>";
-
- $column_header{accno} = "<th><a class=listheading href=$href&sort=accno>" . $locale->text('Account') . "</a></th>";
- $column_header{source} = "<th><a class=listheading href=$href&sort=source>" . $locale->text('Source') . "</a></th>";
- $column_header{debit} = "<th class=listheading>" . $locale->text('Debit') . "</th>";
- $column_header{credit} = "<th class=listheading>" . $locale->text('Credit') . "</th>";
- $column_header{projectnumber} = "<th><a class=listheading href=$href&sort=projectnumber>" . $locale->text('Project') . "</a></th>";
- $column_header{description} = "<th><a class=listheading href=$href&sort=linedescription>" . $locale->text('Description') . "</a></th>";
-
- $form->{title} = ($form->{title}) ? $form->{title} : $locale->text('AR Transactions');
-
- $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>
-|;
-
-
- # 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&/;
-
- if (@{ $form->{transactions} }) {
- $sameitem = $form->{transactions}->[0]->{$form->{sort}};
- }
-
- # sums and tax on reports by Antonio Gallardo
- #
- $i = 0;
- foreach $ref (@{ $form->{transactions} }) {
-
- $i++;
-
- if ($form->{l_subtotal} eq 'Y') {
- if ($sameitem ne $ref->{$form->{sort}}) {
- &subtotal;
- $sameitem = $ref->{$form->{sort}};
- }
- }
-
- if ($form->{l_curr}) {
- for (qw(netamount amount paid)) { $ref->{"fx_$_"} = $ref->{$_}/$ref->{exchangerate} }
-
- for (qw(netamount amount paid)) { $column_data{"fx_$_"} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{"fx_$_"}, 2, "&nbsp;")."</td>" }
-
- $column_data{fx_tax} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{fx_amount} - $ref->{fx_netamount}, 2, "&nbsp;")."</td>";
- $column_data{fx_due} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{fx_amount} - $ref->{fx_paid}, 2, "&nbsp;")."</td>";
-
- $subtotalfxnetamount += $ref->{fx_netamount};
- $subtotalfxamount += $ref->{fx_amount};
- $subtotalfxpaid += $ref->{fx_paid};
-
- $totalfxnetamount += $ref->{fx_netamount};
- $totalfxamount += $ref->{fx_amount};
- $totalfxpaid += $ref->{fx_paid};
-
- }
-
- $column_data{runningnumber} = "<td align=right>$i</td>";
-
- for (qw(netamount amount paid debit credit)) { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;")."</td>" }
-
- $column_data{tax} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} - $ref->{netamount}, 2, "&nbsp;")."</td>";
- $column_data{due} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} - $ref->{paid}, 2, "&nbsp;")."</td>";
-
-
- $subtotalnetamount += $ref->{netamount};
- $subtotalamount += $ref->{amount};
- $subtotalpaid += $ref->{paid};
- $subtotaldebit += $ref->{debit};
- $subtotalcredit += $ref->{credit};
-
- $totalnetamount += $ref->{netamount};
- $totalamount += $ref->{amount};
- $totalpaid += $ref->{paid};
- $totaldebit += $ref->{debit};
- $totalcredit += $ref->{credit};
-
- $module = ($ref->{invoice}) ? ($form->{ARAP} eq 'AR') ? "is.pl" : "ir.pl" : $form->{script};
- $module = ($ref->{till}) ? "ps.pl" : $module;
-
- $column_data{invnumber} = "<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}&nbsp;</a></td>";
-
- for (qw(notes description)) { $ref->{$_} =~ s/\r?\n/<br>/g }
- for (qw(transdate datepaid duedate department ordnumber ponumber notes shippingpoint shipvia employee manager till source description projectnumber)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
- for (qw(id curr)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
-
- $column_data{accno} = qq|<td><a href=ca.pl?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&action=list_transactions&accounttype=standard&accno=$ref->{accno}&fromdate=$form->{transdatefrom}&todate=$form->{transdateto}&sort=transdate&l_subtotal=$form->{l_subtotal}&prevreport=$callback>$ref->{accno}</a></td>|;
-
- $column_data{name} = qq|<td><a href=ct.pl?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&action=edit&id=$ref->{"$form->{vc}_id"}&db=$form->{vc}&callback=$callback>$ref->{name}</a></td>|;
-
- if ($ref->{id} != $sameid) {
- $j++; $j %= 2;
- }
-
- print "
- <tr class=listrow$j>
-";
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
- </tr>
-|;
-
- $sameid = $ref->{id};
-
-
- }
-
- if ($form->{l_subtotal} eq 'Y') {
- &subtotal;
- $sameitem = $ref->{$form->{sort}};
- }
-
- # print totals
- print qq|
- <tr class=listtotal>
-|;
-
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $column_data{netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;")."</th>";
- $column_data{tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalnetamount, 2, "&nbsp;")."</th>";
- $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, 2, "&nbsp;")."</th>";
- $column_data{paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;")."</th>";
- $column_data{due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalpaid, 2, "&nbsp;")."</th>";
- $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;")."</th>";
- $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;")."</th>";
-
- if ($form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal}) {
- $column_data{fx_netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxnetamount, 2, "&nbsp;")."</th>";
- $column_data{fx_tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount - $totalfxnetamount, 2, "&nbsp;")."</th>";
- $column_data{fx_amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount, 2, "&nbsp;")."</th>";
- $column_data{fx_paid} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxpaid, 2, "&nbsp;")."</th>";
- $column_data{fx_due} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount - $totalfxpaid, 2, "&nbsp;")."</th>";
- }
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- if ($myconfig{acs} !~ /$form->{ARAP}--$form->{ARAP}/) {
- $i = 1;
- if ($form->{ARAP} eq 'AR') {
- $button{'AR--Add Transaction'}{code} = qq|<button class="submit" type="submit" name="action" value="ar_transaction">|.$locale->text('AR Transaction').qq|</button> |;
- $button{'AR--Add Transaction'}{order} = $i++;
- $button{'AR--Sales Invoice'}{code} = qq|<button class="submit" type="submit" name="action" value="sales_invoice_">|.$locale->text('Sales Invoice.').qq|</button> |;
- $button{'AR--Sales Invoice'}{order} = $i++;
- } else {
- $button{'AP--Add Transaction'}{code} = qq|<button class="submit" type="submit" name="action" value="ap_transaction">|.$locale->text('AP Transaction').qq|</button> |;
- $button{'AP--Add Transaction'}{order} = $i++;
- $button{'AP--Vendor Invoice'}{code} = qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|.$locale->text('Vendor Invoice.').qq|</button> |;
- $button{'AP--Vendor Invoice'}{order} = $i++;
- }
-
- foreach $item (split /;/, $myconfig{acs}) {
- delete $button{$item};
- }
- }
-
- 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("callback", "path", "login", "sessionid", "$form->{vc}", "$form->{vc}_id");
-
- if (! $form->{till}) {
- 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 subtotal {
-
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $column_data{tax} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, 2, "&nbsp;")."</th>";
- $column_data{amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount, 2, "&nbsp;")."</th>";
- $column_data{paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalpaid, 2, "&nbsp;")."</th>";
- $column_data{due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalpaid, 2, "&nbsp;")."</th>";
- $column_data{debit} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;")."</th>";
- $column_data{credit} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;")."</th>";
-
- if ($form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal}) {
- $column_data{fx_tax} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxamount - $subtotalfxnetamount, 2, "&nbsp;")."</th>";
- $column_data{fx_amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxamount, 2, "&nbsp;")."</th>";
- $column_data{fx_paid} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxpaid, 2, "&nbsp;")."</th>";
- $column_data{fx_due} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxmount - $subtotalfxpaid, 2, "&nbsp;")."</th>";
- }
-
- $subtotalnetamount = 0;
- $subtotalamount = 0;
- $subtotalpaid = 0;
- $subtotaldebit = 0;
- $subtotalcredit = 0;
-
- $subtotalfxnetamount = 0;
- $subtotalfxamount = 0;
- $subtotalfxpaid = 0;
-
- print "<tr class=listsubtotal>";
-
- for (@column_index) { print "\n$column_data{$_}" }
-
-print "
-</tr>
-";
-
-}
-
-
-
+#=====================================================================
+# 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
+#
+# Contributors:
+#
+#
+# Author: DWS Systems Inc.
+# Web: http://www.ledgersmb.org/
+#
+# Contributors:
+#
+# 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.
+#======================================================================
+#
+# AR / AP
+#
+#======================================================================
+
+use LedgerSMB::Tax;
+
+# any custom scripts for this one
+if ( -f "bin/custom/aa.pl" ) {
+ eval { require "bin/custom/aa.pl"; };
+}
+if ( -f "bin/custom/$form->{login}_aa.pl" ) {
+ eval { require "bin/custom/$form->{login}_aa.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 add {
+
+ $form->{title} = "Add";
+ $form->{callback} =
+"$form->{script}?action=add&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
+
+ &create_links;
+
+ $form->{focus} = "amount_1";
+ &display_form;
+
+}
+
+sub edit {
+
+ $form->{title} = "Edit";
+
+ &create_links;
+ &display_form;
+
+}
+
+sub display_form {
+
+ &form_header;
+ &form_footer;
+
+}
+
+sub create_links {
+
+ $form->create_links( $form->{ARAP}, \%myconfig, $form->{vc} );
+
+ $duedate = $form->{duedate};
+ $taxincluded = $form->{taxincluded};
+
+ $form->{formname} = "transaction";
+ $form->{format} = "postscript" if $myconfig{printer};
+ $form->{media} = $myconfig{printer};
+
+ $form->{selectformname} =
+ qq|<option value="transaction">| . $locale->text('Transaction');
+
+ if ( ${LedgerSMB::Sysconfig::latex} ) {
+ if ( $form->{ARAP} eq 'AR' ) {
+ $form->{selectformname} .= qq|
+ <option value="receipt">| . $locale->text('Receipt');
+ }
+ else {
+ $form->{selectformname} .= qq|
+ <option value="check">| . $locale->text('Check');
+ }
+ }
+
+ # currencies
+ @curr = split /:/, $form->{currencies};
+ $form->{defaultcurrency} = $curr[0];
+ chomp $form->{defaultcurrency};
+
+ for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
+
+ AA->get_name( \%myconfig, \%$form );
+
+ $form->{currency} =~ s/ //g;
+ $form->{duedate} = $duedate if $duedate;
+ $form->{taxincluded} = $taxincluded if $form->{id};
+
+ $form->{notes} = $form->{intnotes} if !$form->{id};
+
+ $form->{"old$form->{vc}"} =
+ qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
+ $form->{oldtransdate} = $form->{transdate};
+
+ # customers/vendors
+ $form->{"select$form->{vc}"} = "";
+ if ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{ $form->{vc} } =
+ qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
+ for ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{"select$form->{vc}"} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
+
+ # departments
+ if ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} = "<option>\n";
+ $form->{department} = "$form->{department}--$form->{department_id}"
+ if $form->{department_id};
+
+ for ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+ }
+
+ $form->{employee} = "$form->{employee}--$form->{employee_id}";
+
+ # sales staff
+ if ( @{ $form->{all_employee} } ) {
+ $form->{selectemployee} = "";
+ for ( @{ $form->{all_employee} } ) {
+ $form->{selectemployee} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
+
+ # projects
+ if ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} = "<option>\n";
+ for ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} .=
+qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
+ }
+ }
+
+ if ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} = "<option>\n";
+ for ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} .=
+ qq|<option value="$_->{code}">$_->{description}\n|;
+ }
+ }
+
+ # forex
+ $form->{forex} = $form->{exchangerate};
+ $exchangerate = ( $form->{exchangerate} ) ? $form->{exchangerate} : 1;
+
+ $netamount = 0;
+ $tax = 0;
+ $taxrate = 0;
+ $ml = ( $form->{ARAP} eq 'AR' ) ? 1 : -1;
+
+ foreach $key ( keys %{ $form->{"$form->{ARAP}_links"} } ) {
+
+ $form->{"select$key"} = "";
+ foreach $ref ( @{ $form->{"$form->{ARAP}_links"}{$key} } ) {
+ if ( $key eq "$form->{ARAP}_tax" ) {
+ $form->{"select$form->{ARAP}_tax_$ref->{accno}"} =
+ "<option>$ref->{accno}--$ref->{description}\n";
+ next;
+ }
+ $form->{"select$key"} .=
+ "<option>$ref->{accno}--$ref->{description}\n";
+ }
+
+ # if there is a value we have an old entry
+ for $i ( 1 .. scalar @{ $form->{acc_trans}{$key} } ) {
+ if ( $key eq "$form->{ARAP}_paid" ) {
+ $form->{"$form->{ARAP}_paid_$i"} =
+"$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
+ $form->{"paid_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{amount} * -1 * $ml;
+ $form->{"datepaid_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{transdate};
+ $form->{"source_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{source};
+ $form->{"memo_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{memo};
+
+ $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{exchangerate};
+
+ $form->{paidaccounts}++;
+ }
+ else {
+
+ $akey = $key;
+ $akey =~ s/$form->{ARAP}_//;
+
+ if ( $key eq "$form->{ARAP}_tax" ) {
+ $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}
+ = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
+ $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}
+ = $form->{acc_trans}{$key}->[ $i - 1 ]->{amount} * $ml;
+
+ $tax +=
+ $form->{
+ "${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
+ $taxrate +=
+ $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
+
+ }
+ else {
+ $form->{"${akey}_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{amount} * $ml;
+
+ if ( $akey eq 'amount' ) {
+ $form->{"description_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{memo};
+ $form->{rowcount}++;
+ $netamount += $form->{"${akey}_$i"};
+
+ $form->{"projectnumber_$i"} =
+"$form->{acc_trans}{$key}->[$i-1]->{projectnumber}--$form->{acc_trans}{$key}->[$i-1]->{project_id}"
+ if $form->{acc_trans}{$key}->[ $i - 1 ]->{project_id};
+ }
+ else {
+ $form->{invtotal} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{amount} * -1 *
+ $ml;
+ }
+ $form->{"${key}_$i"} =
+"$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
+ }
+ }
+ }
+ }
+
+ $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
+
+ if ( $form->{taxincluded} ) {
+ $diff = 0;
+
+ # add tax to individual amounts
+ # XXX needs alteration for conditional taxes
+ for $i ( 1 .. $form->{rowcount} ) {
+ if ($netamount) {
+ $amount = $form->{"amount_$i"} * ( 1 + $tax / $netamount );
+ $form->{"amount_$i"} = $form->round_amount( $amount, 2 );
+ }
+ }
+ }
+
+ $form->{invtotal} = $netamount + $tax;
+
+ # check if calculated is equal to stored
+ # taxincluded is terrible to calculate
+ # this works only if all taxes are checked
+
+ @taxaccounts = Tax::init_taxes( $form, $form->{taxaccounts} );
+
+ if ( $form->{id} ) {
+ if ( $form->{taxincluded} ) {
+
+ $amount =
+ Tax::calculate_taxes( \@taxaccounts, $form, $form->{invtotal},
+ 1 );
+ $tax = $form->round_amount( $amount, 2 );
+
+ }
+ else {
+ $tax =
+ $form->round_amount(
+ Tax::calculate_taxes( \@taxaccounts, $form, $netamount, 0 ) );
+ }
+ foreach $item (@taxaccounts) {
+ $tax{ $item->account } = $form->round_amount( $item->value, 2 );
+ $form->{ "calctax_" . $item->account } = 1
+ if $item->value
+ and
+ ( $tax{ $item->account } == $form->{ "tax_" . $item->account } );
+ }
+ }
+ else {
+ for (@taxaccounts) { $form->{ "calctax_" . $_->account } = 1 }
+ }
+
+ $form->{rowcount}++ if ( $form->{id} || !$form->{rowcount} );
+
+ $form->{ $form->{ARAP} } = $form->{"$form->{ARAP}_1"};
+ $form->{rowcount} = 1 unless $form->{"$form->{ARAP}_amount_1"};
+
+ $form->{locked} =
+ ( $form->{revtrans} )
+ ? '1'
+ : ( $form->datetonum( \%myconfig, $form->{transdate} ) <=
+ $form->datetonum( \%myconfig, $form->{closedto} ) );
+
+ # readonly
+ if ( !$form->{readonly} ) {
+ $form->{readonly} = 1
+ if $myconfig{acs} =~ /$form->{ARAP}--Add Transaction/;
+ }
+
+}
+
+sub form_header {
+
+ $title = $form->{title};
+ $form->{title} = $locale->text("$title $form->{ARAP} Transaction");
+
+ $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
+
+ # $locale->text('Add AR Transaction')
+ # $locale->text('Edit AR Transaction')
+ # $locale->text('Add AP Transaction')
+ # $locale->text('Edit AP Transaction')
+
+ # set option selected
+ for ( "$form->{ARAP}", "currency" ) {
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~
+ s/<option>\Q$form->{$_}\E/<option selected>$form->{$_}/;
+ }
+
+ for ( "$form->{vc}", "department", "employee", "formname" ) {
+ $form->{"select$_"} = $form->unescape( $form->{"select$_"} );
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
+ }
+
+ $form->{selectprojectnumber} =
+ $form->unescape( $form->{selectprojectnumber} );
+
+ # format amounts
+ $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><input type=hidden name=exchangerate value=$form->{exchangerate}>$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>
+|;
+
+ $taxincluded = "";
+ if ( $form->{taxaccounts} ) {
+ $taxincluded = qq|
+ <tr>
+ <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
+ <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
+ </tr>
+|;
+ }
+
+ if ( ( $rows = $form->numtextrows( $form->{notes}, 50 ) - 1 ) < 2 ) {
+ $rows = 2;
+ }
+ $notes =
+qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
+
+ $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};
+
+ $n = ( $form->{creditremaining} < 0 ) ? "0" : "1";
+
+ $name =
+ ( $form->{"select$form->{vc}"} )
+ ? qq|<select name="$form->{vc}">$form->{"select$form->{vc}"}</select>|
+ : qq|<input name="$form->{vc}" value="$form->{$form->{vc}}" size=35>|;
+
+ $employee = qq|
+ <input type=hidden name=employee value="$form->{employee}">
+|;
+
+ if ( $form->{selectemployee} ) {
+ $label =
+ ( $form->{ARAP} eq 'AR' )
+ ? $locale->text('Salesperson')
+ : $locale->text('Employee');
+
+ $employee = qq|
+ <tr>
+ <th align=right nowrap>$label</th>
+ <td><select name=employee>$form->{selectemployee}</select></td>
+ <input type=hidden name=selectemployee value="|
+ . $form->escape( $form->{selectemployee}, 1 ) . qq|">
+ </tr>
+|;
+ }
+
+ $focus = ( $form->{focus} ) ? $form->{focus} : "amount_$form->{rowcount}";
+
+ $form->header;
+
+ print qq|
+<body onload="document.forms[0].${focus}.focus()" />
+
+<form method=post action=$form->{script}>
+
+<input type=hidden name=type value="$form->{formname}">
+<input type=hidden name=title value="$title">
+
+|;
+
+ $form->hide_form(
+ qw(id printed emailed sort closedto locked oldtransdate audittrail recurring checktax)
+ );
+
+ if ( $form->{vc} eq 'customer' ) {
+ $label = $locale->text('Customer');
+ }
+ else {
+ $label = $locale->text('Vendor');
+ }
+
+ $form->hide_form(
+ "old$form->{vc}", "$form->{vc}_id",
+ "terms", "creditlimit",
+ "creditremaining", "selectcurrency",
+ "defaultcurrency", "select$form->{ARAP}_amount",
+ "rowcount"
+ );
+
+ print qq|
+
+<table width=100%>
+ <tr class=listtop>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr valign=top>
+ <td>
+ <table width=100%>
+ <tr valign=top>
+ <td>
+ <table>
+ <tr>
+ <th align="right" nowrap>$label</th>
+ <td colspan=3>$name</td>
+ <input type=hidden name="select$form->{vc}" value="|
+ . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|">
+ </tr>
+ <tr>
+ <td></td>
+ <td colspan=3>
+ <table width=100%>
+ <tr>
+ <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
+ <td>$form->{creditlimit}</td>
+ <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
+ <td class="plus$n">|
+ . $form->format_amount( \%myconfig, $form->{creditremaining}, 0, "0" )
+ . qq|</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ $exchangerate
+ $department
+ $taxincluded
+ </table>
+ </td>
+ <td align=right>
+ <table>
+ $employee
+ <tr>
+ <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
+ <td><input name=invnumber size=20 value="$form->{invnumber}"></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
+ <td><input name=ordnumber size=20 value="$form->{ordnumber}"></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
+ <td><input name=transdate size=11 title="($myconfig{'dateformat'})" value=$form->{transdate}></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
+ <td><input name=duedate size=11 title="$myconfig{'dateformat'}" value=$form->{duedate}></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('PO Number') . qq|</th>
+ <td><input name=ponumber size=20 value="$form->{ponumber}"></td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <input type=hidden name=selectprojectnumber value="|
+ . $form->escape( $form->{selectprojectnumber}, 1 ) . qq|">
+ <tr>
+ <td>
+ <table>
+|;
+
+ $project = qq|
+ <th>| . $locale->text('Project') . qq|</th>
+| if $form->{selectprojectnumber};
+
+ print qq|
+ <tr>
+ <th>| . $locale->text('Amount') . qq|</th>
+ <th></th>
+ <th>| . $locale->text('Account') . qq|</th>
+ <th>| . $locale->text('Description') . qq|</th>
+ $project
+ </tr>
+|;
+
+ for $i ( 1 .. $form->{rowcount} ) {
+
+ $selectamount = $form->{"select$form->{ARAP}_amount"};
+ $selectamount =~
+s/option>\Q$form->{"$form->{ARAP}_amount_$i"}\E/option selected>$form->{"$form->{ARAP}_amount_$i"}/;
+
+ $selectprojectnumber = $form->{selectprojectnumber};
+ $selectprojectnumber =~
+ s/(<option value="\Q$form->{"projectnumber_$i"}\E")/$1 selected/;
+
+ # format amounts
+ $form->{"amount_$i"} =
+ $form->format_amount( \%myconfig, $form->{"amount_$i"}, 2 );
+
+ $project = qq|
+ <td align=right><select name="projectnumber_$i">$selectprojectnumber</select></td>
+| if $form->{selectprojectnumber};
+
+ if ( ( $rows = $form->numtextrows( $form->{"description_$i"}, 40 ) ) >
+ 1 )
+ {
+ $description =
+qq|<td><textarea name="description_$i" rows=$rows cols=40>$form->{"description_$i"}</textarea></td>|;
+ }
+ else {
+ $description =
+qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
+ }
+
+ print qq|
+ <tr valign=top>
+ <td><input name="amount_$i" size=10 value="$form->{"amount_$i"}" accesskey="$i"></td>
+ <td></td>
+ <td><select name="$form->{ARAP}_amount_$i">$selectamount</select></td>
+ $description
+ $project
+ </tr>
+|;
+ }
+
+ foreach $item ( split / /, $form->{taxaccounts} ) {
+
+ $form->{"calctax_$item"} =
+ ( $form->{"calctax_$item"} ) ? "checked" : "";
+
+ $form->{"tax_$item"} =
+ $form->format_amount( \%myconfig, $form->{"tax_$item"}, 2 );
+
+ print qq|
+ <tr>
+ <td><input name="tax_$item" size=10 value=$form->{"tax_$item"}></td>
+ <td align=right><input name="calctax_$item" class=checkbox type=checkbox value=1 $form->{"calctax_$item"}></td>
+ <td><select name="$form->{ARAP}_tax_$item">$form->{"select$form->{ARAP}_tax_$item"}</select></td>
+ </tr>
+|;
+
+ $form->hide_form(
+ "${item}_rate", "${item}_description",
+ "${item}_taxnumber", "select$form->{ARAP}_tax_$item"
+ );
+ }
+
+ $form->{invtotal} =
+ $form->format_amount( \%myconfig, $form->{invtotal}, 2 );
+
+ $form->hide_form( "oldinvtotal", "oldtotalpaid", "taxaccounts",
+ "select$form->{ARAP}" );
+
+ print qq|
+ <tr>
+ <th align=left>$form->{invtotal}</th>
+ <td></td>
+ <td><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select></td>
+ </tr>
+ <tr>
+ <th align=right>| . $locale->text('Notes') . qq|</th>
+ <td></td>
+ <td colspan=3>$notes</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+
+ <tr class=listheading>
+ <th class=listheading>| . $locale->text('Payments') . qq|</th>
+ </tr>
+
+ <tr>
+ <td>
+ <table width=100%>
+|;
+
+ if ( $form->{currency} eq $form->{defaultcurrency} ) {
+ @column_index = qw(datepaid source memo paid ARAP_paid);
+ }
+ else {
+ @column_index = qw(datepaid source memo paid exchangerate ARAP_paid);
+ }
+
+ $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
+ $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
+ $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
+ $column_data{ARAP_paid} = "<th>" . $locale->text('Account') . "</th>";
+ $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
+ $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
+
+ print "
+ <tr>
+";
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print "
+ </tr>
+";
+
+ $form->{paidaccounts}++ if ( $form->{"paid_$form->{paidaccounts}"} );
+ for $i ( 1 .. $form->{paidaccounts} ) {
+
+ $form->hide_form("cleared_$i");
+
+ print "
+ <tr>
+";
+
+ $form->{"select$form->{ARAP}_paid_$i"} =
+ $form->{"select$form->{ARAP}_paid"};
+ $form->{"select$form->{ARAP}_paid_$i"} =~
+s/option>\Q$form->{"$form->{ARAP}_paid_$i"}\E/option selected>$form->{"$form->{ARAP}_paid_$i"}/;
+
+ # format amounts
+ $form->{"paid_$i"} =
+ $form->format_amount( \%myconfig, $form->{"paid_$i"}, 2 );
+ $form->{"exchangerate_$i"} =
+ $form->format_amount( \%myconfig, $form->{"exchangerate_$i"} );
+
+ $exchangerate = qq|&nbsp;|;
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ if ( $form->{"forex_$i"} ) {
+ $form->hide_form("exchangerate_$i");
+ $exchangerate = qq|$form->{"exchangerate_$i"}|;
+ }
+ else {
+ $exchangerate =
+qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
+ }
+ }
+
+ $form->hide_form("forex_$i");
+
+ $column_data{paid} =
+qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
+ $column_data{ARAP_paid} =
+qq|<td align=center><select name="$form->{ARAP}_paid_$i">$form->{"select$form->{ARAP}_paid_$i"}</select></td>|;
+ $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
+ $column_data{datepaid} =
+qq|<td align=center><input name="datepaid_$i" size=11 value=$form->{"datepaid_$i"}></td>|;
+ $column_data{source} =
+qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
+ $column_data{memo} =
+qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
+
+ for (@column_index) { print qq|$column_data{$_}\n| }
+
+ print "
+ </tr>
+";
+ }
+
+ $form->hide_form( "paidaccounts", "select$form->{ARAP}_paid" );
+
+ print qq|
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+|;
+
+}
+
+sub form_footer {
+
+ $form->hide_form(qw(callback path login sessionid));
+
+ $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('Schedule')
+ # type=submit $locale->text('Ship to')
+ # type=submit $locale->text('Post as new')
+ # type=submit $locale->text('Print and Post as new')
+ # type=submit $locale->text('Delete')
+
+ if ( !$form->{readonly} ) {
+
+ &print_options;
+
+ print "<br>";
+
+ %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')
+ },
+ 'post_as_new' =>
+ { ndx => 5, key => 'N', value => $locale->text('Post as new') },
+ 'print_and_post_as_new' => {
+ ndx => 6,
+ key => 'W',
+ value => $locale->text('Print and Post as new')
+ },
+ 'schedule' =>
+ { ndx => 7, key => 'H', value => $locale->text('Schedule') },
+ 'delete' =>
+ { ndx => 8, key => 'D', value => $locale->text('Delete') },
+ );
+
+ if ( $form->{id} ) {
+
+ if ( $form->{locked} || ( $transdate && $transdate <= $closedto ) )
+ {
+ for ( "post", "print_and_post", "delete" ) {
+ delete $button{$_};
+ }
+ }
+
+ if ( !${LedgerSMB::Sysconfig::latex} ) {
+ for ( "print_and_post", "print_and_post_as_new" ) {
+ delete $button{$_};
+ }
+ }
+
+ }
+ else {
+
+ for ( "post_as_new", "print_and_post_as_new", "delete" ) {
+ delete $button{$_};
+ }
+ delete $button{"print_and_post"} if !${LedgerSMB::Sysconfig::latex};
+
+ if ( $transdate && $transdate <= $closedto ) {
+ for ( "post", "print_and_post" ) { delete $button{$_} }
+ }
+ }
+
+ 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 update {
+ my $display = shift;
+
+ if ( !$display ) {
+
+ $form->{invtotal} = 0;
+
+ $form->{exchangerate} =
+ $form->parse_amount( \%myconfig, $form->{exchangerate} );
+
+ @flds =
+ ( "amount", "$form->{ARAP}_amount", "projectnumber", "description" );
+ $count = 0;
+ @a = ();
+ for $i ( 1 .. $form->{rowcount} ) {
+ $form->{"amount_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"amount_$i"} );
+ if ( $form->{"amount_$i"} ) {
+ push @a, {};
+ $j = $#a;
+
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
+ }
+
+ $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
+ $form->{rowcount} = $count + 1;
+
+ for ( 1 .. $form->{rowcount} ) {
+ $form->{invtotal} += $form->{"amount_$_"};
+ }
+
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate = $form->check_exchangerate(
+ \%myconfig, $form->{currency}, $form->{transdate},
+ ( $form->{ARAP} eq 'AR' ) ? 'buy' : 'sell'
+ )
+ )
+ );
+
+ if ( $newname = &check_name( $form->{vc} ) ) {
+ $form->{notes} = $form->{intnotes} unless $form->{id};
+ &rebuild_vc( $form->{vc}, $form->{ARAP}, $form->{transdate} );
+ }
+ if ( $form->{transdate} ne $form->{oldtransdate} ) {
+ $form->{duedate} =
+ $form->current_date( \%myconfig, $form->{transdate},
+ $form->{terms} * 1 );
+ $form->{oldtransdate} = $form->{transdate};
+ $newproj =
+ &rebuild_vc( $form->{vc}, $form->{ARAP}, $form->{transdate} )
+ if !$newname;
+ $form->all_projects( \%myconfig, undef, $form->{transdate} )
+ if !$newproj;
+
+ $form->{selectemployee} = "";
+ if ( @{ $form->{all_employee} } ) {
+ for ( @{ $form->{all_employee} } ) {
+ $form->{selectemployee} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
+ }
+ }
+
+ # recalculate taxes
+ @taxaccounts = split / /, $form->{taxaccounts};
+
+ for (@taxaccounts) {
+ $form->{"tax_$_"} =
+ $form->parse_amount( \%myconfig, $form->{"tax_$_"} );
+ }
+
+ @taxaccounts = Tax::init_taxes( $form, $form->{taxaccounts} );
+ if ( $form->{taxincluded} ) {
+ $totaltax =
+ Tax::calculate_taxes( \@taxaccounts, $form, $form->{invtotal}, 1 );
+ }
+ else {
+ $totaltax =
+ Tax::calculate_taxes( \@taxaccounts, $form, $form->{invtotal}, 0 );
+ }
+ foreach $item (@taxaccounts) {
+ $taccno = $item->account;
+ if ( $form->{calctax} ) {
+ $form->{"calctax_$taccno"} = 1;
+ $form->{"tax_$taccno"} = $form->round_amount( $item->value, 2 );
+ }
+ $form->{"select$form->{ARAP}_tax_$taccno"} =
+ qq|<option>$taccno--$form->{"${taccno}_description"}|;
+ }
+
+ $form->{invtotal} =
+ ( $form->{taxincluded} )
+ ? $form->{invtotal}
+ : $form->{invtotal} + $totaltax;
+
+ $j = 1;
+ for $i ( 1 .. $form->{paidaccounts} ) {
+ if ( $form->{"paid_$i"} ) {
+ for (qw(datepaid source memo cleared)) {
+ $form->{"${_}_$j"} = $form->{"${_}_$i"};
+ }
+ for (qw(paid exchangerate)) {
+ $form->{"${_}_$j"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ $totalpaid += $form->{"paid_$j"};
+
+ $form->{"exchangerate_$j"} = $exchangerate
+ if (
+ $form->{"forex_$j"} = (
+ $exchangerate = $form->check_exchangerate(
+ \%myconfig, $form->{currency},
+ $form->{"datepaid_$j"},
+ ( $form->{ARAP} eq 'AR' ) ? 'buy' : 'sell'
+ )
+ )
+ );
+
+ if ( $j++ != $i ) {
+ for (qw(datepaid source memo paid exchangerate forex cleared)) {
+ delete $form->{"${_}_$i"};
+ }
+ }
+ }
+ else {
+ for (qw(datepaid source memo paid exchangerate forex cleared)) {
+ delete $form->{"${_}_$i"};
+ }
+ }
+ }
+ $form->{paidaccounts} = $j;
+
+ $form->{creditremaining} -=
+ ( $form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
+ $form->{oldinvtotal} );
+ $form->{oldinvtotal} = $form->{invtotal};
+ $form->{oldtotalpaid} = $totalpaid;
+
+ &display_form;
+
+}
+
+sub post {
+
+ $label =
+ ( $form->{vc} eq 'customer' )
+ ? $locale->text('Customer missing!')
+ : $locale->text('Vendor missing!');
+
+ # check if there is an invoice number, invoice and due date
+ $form->isblank( "transdate", $locale->text('Invoice Date missing!') );
+ $form->isblank( "duedate", $locale->text('Due Date missing!') );
+ $form->isblank( $form->{vc}, $label );
+
+ $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
+ $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
+
+ $form->error(
+ $locale->text('Cannot post transaction for a closed period!') )
+ if ( $transdate <= $closedto );
+
+ $form->isblank( "exchangerate", $locale->text('Exchange rate missing!') )
+ if ( $form->{currency} ne $form->{defaultcurrency} );
+
+ for $i ( 1 .. $form->{paidaccounts} ) {
+ if ( $form->{"paid_$i"} ) {
+ $datepaid = $form->datetonum( \%myconfig, $form->{"datepaid_$i"} );
+
+ $form->isblank( "datepaid_$i",
+ $locale->text('Payment date missing!') );
+
+ $form->error(
+ $locale->text('Cannot post payment for a closed period!') )
+ if ( $datepaid <= $closedto );
+
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ $form->{"exchangerate_$i"} = $form->{exchangerate}
+ if ( $transdate == $datepaid );
+ $form->isblank( "exchangerate_$i",
+ $locale->text('Exchange rate for payment missing!') );
+ }
+ }
+ }
+
+ # if oldname ne name redo form
+ ($name) = split /--/, $form->{ $form->{vc} };
+ if ( $form->{"old$form->{vc}"} ne qq|$name--$form->{"$form->{vc}_id"}| ) {
+ &update;
+ exit;
+ }
+
+ if ( !$form->{repost} ) {
+ if ( $form->{id} ) {
+ &repost;
+ exit;
+ }
+ }
+
+ if ( AA->post_transaction( \%myconfig, \%$form ) ) {
+ $form->update_status( \%myconfig );
+ if ( $form->{printandpost} ) {
+ &{"print_$form->{formname}"}( $old_form, 1 );
+ }
+ $form->redirect( $locale->text('Transaction posted!') );
+ }
+ else {
+ $form->error( $locale->text('Cannot post transaction!') );
+ }
+
+}
+
+sub delete {
+
+ $form->{title} = $locale->text('Confirm!');
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+|;
+
+ $form->{action} = "yes";
+ $form->hide_form;
+
+ print qq|
+<h2 class=confirm>$form->{title}</h2>
+
+<h4>|
+ . $locale->text('Are you sure you want to delete Transaction')
+ . qq| $form->{invnumber}</h4>
+
+<button name="action" class="submit" type="submit" value="yes">|
+ . $locale->text('Yes')
+ . qq|</button>
+</form>
+
+</body>
+</html>
+|;
+
+}
+
+sub yes {
+
+ if (
+ AA->delete_transaction(
+ \%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool}
+ )
+ )
+ {
+ $form->redirect( $locale->text('Transaction deleted!') );
+ }
+ else {
+ $form->error( $locale->text('Cannot delete transaction!') );
+ }
+
+}
+
+sub search {
+
+ $form->create_links( $form->{ARAP}, \%myconfig, $form->{vc} );
+
+ $form->{"select$form->{ARAP}"} = "<option>\n";
+ for ( @{ $form->{"$form->{ARAP}_links"}{ $form->{ARAP} } } ) {
+ $form->{"select$form->{ARAP}"} .=
+ "<option>$_->{accno}--$_->{description}\n";
+ }
+
+ if ( @{ $form->{"all_$form->{vc}"} } ) {
+ $selectname = "";
+ for ( @{ $form->{"all_$form->{vc}"} } ) {
+ $selectname .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ $selectname =
+ qq|<select name="$form->{vc}"><option>\n$selectname</select>|;
+ }
+ else {
+ $selectname = qq|<input name=$form->{vc} size=35>|;
+ }
+
+ # departments
+ if ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} = "<option>\n";
+
+ for ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+
+ $l_department =
+ qq|<input name="l_department" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Department');
+
+ $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->{all_employee} } ) {
+ $form->{selectemployee} = "<option>\n";
+ for ( @{ $form->{all_employee} } ) {
+ $form->{selectemployee} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+
+ $employeelabel =
+ ( $form->{ARAP} eq 'AR' )
+ ? $locale->text('Salesperson')
+ : $locale->text('Employee');
+
+ $employee = qq|
+ <tr>
+ <th align=right nowrap>$employeelabel</th>
+ <td colspan=3><select name=employee>$form->{selectemployee}</select></td>
+ </tr>
+|;
+
+ $l_employee =
+qq|<input name="l_employee" class=checkbox type=checkbox value=Y> $employeelabel|;
+
+ $l_manager =
+ qq|<input name="l_manager" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Manager');
+ }
+
+ $form->{title} =
+ ( $form->{ARAP} eq 'AR' )
+ ? $locale->text('AR Transactions')
+ : $locale->text('AP Transactions');
+
+ $invnumber = qq|
+ <tr>
+ <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
+ <td colspan=3><input name=invnumber size=20></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
+ <td colspan=3><input name=ordnumber size=20></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('PO Number') . qq|</th>
+ <td colspan=3><input name=ponumber size=20></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Source') . qq|</th>
+ <td colspan=3><input name=source size=40></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Description') . qq|</th>
+ <td colspan=3><input name=description size=40></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
+ <td colspan=3><input name=notes size=40></td>
+ </tr>
+|;
+
+ $openclosed = qq|
+ <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>
+|;
+
+ $summary = qq|
+ <tr>
+ <td><input name=summary type=radio class=radio value=1 checked> |
+ . $locale->text('Summary')
+ . qq|</td>
+ <td><input name=summary type=radio class=radio value=0> |
+ . $locale->text('Detail') . qq|
+ </td>
+ </tr>
+|;
+
+ if ( $form->{outstanding} ) {
+ $form->{title} =
+ ( $form->{ARAP} eq 'AR' )
+ ? $locale->text('AR Outstanding')
+ : $locale->text('AP Outstanding');
+ $invnumber = "";
+ $openclosed = "";
+ $summary = "";
+ }
+
+ 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>
+|;
+ }
+
+ $name = $locale->text('Customer');
+ $l_name =
+qq|<input name="l_name" class=checkbox type=checkbox value=Y checked> $name|;
+ $l_till =
+ qq|<input name="l_till" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Till');
+
+ if ( $form->{vc} eq 'vendor' ) {
+ $name = $locale->text('Vendor');
+ $l_till = "";
+ $l_name =
+qq|<input name="l_name" class=checkbox type=checkbox value=Y checked> $name|;
+ }
+
+ @a = ();
+ push @a,
+ qq|<input name="l_runningnumber" class=checkbox type=checkbox value=Y> |
+ . $locale->text('No.');
+ push @a, qq|<input name="l_id" class=checkbox type=checkbox value=Y> |
+ . $locale->text('ID');
+ push @a,
+qq|<input name="l_invnumber" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Invoice Number');
+ push @a,
+ qq|<input name="l_ordnumber" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Order Number');
+ push @a, qq|<input name="l_ponumber" class=checkbox type=checkbox value=Y> |
+ . $locale->text('PO Number');
+ push @a,
+qq|<input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Invoice Date');
+ push @a, $l_name;
+ push @a, $l_employee if $l_employee;
+ push @a, $l_manager if $l_employee;
+ push @a, $l_department if $l_department;
+ push @a,
+ qq|<input name="l_netamount" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Amount');
+ push @a, qq|<input name="l_tax" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Tax');
+ push @a,
+ qq|<input name="l_amount" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Total');
+ push @a, qq|<input name="l_curr" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Currency');
+ push @a, qq|<input name="l_datepaid" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Date Paid');
+ push @a,
+ qq|<input name="l_paid" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Paid');
+ push @a, qq|<input name="l_duedate" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Due Date');
+ push @a, qq|<input name="l_due" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Amount Due');
+ push @a, qq|<input name="l_notes" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Notes');
+ push @a, $l_till if $l_till;
+ push @a,
+ qq|<input name="l_shippingpoint" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Shipping Point');
+ push @a, qq|<input name="l_shipvia" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Ship via');
+
+ $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>
+ <table>
+ <tr>
+ <th align=right>| . $locale->text('Account') . qq|</th>
+ <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select></td>
+ </tr>
+ <tr>
+ <th align=right>$name</th>
+ <td colspan=3>$selectname</td>
+ </tr>
+ $employee
+ $department
+ $invnumber
+ <tr>
+ <th align=right>| . $locale->text('Ship via') . qq|</th>
+ <td colspan=3><input name=shipvia size=40></td>
+ </tr>
+ <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>
+ <table>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
+ <td>
+ <table width=100%>
+ $openclosed
+ $summary
+|;
+
+ $form->{sort} = "transdate";
+ $form->hide_form(qw(title outstanding sort));
+
+ while (@a) {
+ for ( 1 .. 5 ) {
+ print qq|<td nowrap>| . shift @a;
+ print qq|</td>\n|;
+ }
+ print qq|</tr>\n|;
+ }
+
+ print qq|
+ <tr>
+ <td nowrap><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Subtotal')
+ . qq|</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+
+<br>
+<input type="hidden" name="action" value="continue">
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>|;
+
+ $form->hide_form(qw(nextsub path login sessionid));
+
+ print qq|
+</form>
+|;
+
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
+
+</body>
+</html>
+|;
+
+}
+
+sub transactions {
+
+ if ( $form->{ $form->{vc} } ) {
+ $form->{ $form->{vc} } = $form->unescape( $form->{ $form->{vc} } );
+ ( $form->{ $form->{vc} }, $form->{"$form->{vc}_id"} ) =
+ split( /--/, $form->{ $form->{vc} } );
+ }
+
+ AA->transactions( \%myconfig, \%$form );
+
+ $href = "$form->{script}?action=transactions";
+ for (qw(direction oldsort till outstanding path login sessionid summary)) {
+ $href .= qq|&$_=$form->{$_}|;
+ }
+ $href .= "&title=" . $form->escape( $form->{title} );
+
+ $form->sort_order();
+
+ $callback = "$form->{script}?action=transactions";
+ for (qw(direction oldsort till outstanding path login sessionid summary)) {
+ $callback .= qq|&$_=$form->{$_}|;
+ }
+ $callback .= "&title=" . $form->escape( $form->{title}, 1 );
+
+ if ( $form->{ $form->{ARAP} } ) {
+ $callback .=
+ "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} }, 1 );
+ $href .= "&$form->{ARAP}=" . $form->escape( $form->{ $form->{ARAP} } );
+ $form->{ $form->{ARAP} } =~ s/--/ /;
+ $option = $locale->text('Account') . " : $form->{$form->{ARAP}}";
+ }
+
+ if ( $form->{ $form->{vc} } ) {
+ $callback .=
+ "&$form->{vc}="
+ . $form->escape( $form->{ $form->{vc} }, 1 )
+ . qq|--$form->{"$form->{vc}_id"}|;
+ $href .=
+ "&$form->{vc}="
+ . $form->escape( $form->{ $form->{vc} } )
+ . qq|--$form->{"$form->{vc}_id"}|;
+ $option .= "\n<br>" if ($option);
+ $name =
+ ( $form->{vc} eq 'customer' )
+ ? $locale->text('Customer')
+ : $locale->text('Vendor');
+ $option .= "$name : $form->{$form->{vc}}";
+ }
+ if ( $form->{department} ) {
+ $callback .= "&department=" . $form->escape( $form->{department}, 1 );
+ $href .= "&department=" . $form->escape( $form->{department} );
+ ($department) = split /--/, $form->{department};
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Department') . " : $department";
+ }
+ if ( $form->{employee} ) {
+ $callback .= "&employee=" . $form->escape( $form->{employee}, 1 );
+ $href .= "&employee=" . $form->escape( $form->{employee} );
+ ($employee) = split /--/, $form->{employee};
+ $option .= "\n<br>" if ($option);
+ if ( $form->{ARAP} eq 'AR' ) {
+ $option .= $locale->text('Salesperson');
+ }
+ else {
+ $option .= $locale->text('Employee');
+ }
+ $option .= " : $employee";
+ }
+
+ 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->{ponumber} ) {
+ $callback .= "&ponumber=" . $form->escape( $form->{ponumber}, 1 );
+ $href .= "&ponumber=" . $form->escape( $form->{ponumber} );
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('PO Number') . " : $form->{ponumber}";
+ }
+ 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->{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->{notes} ) {
+ $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
+ $href .= "&notes=" . $form->escape( $form->{notes} );
+ $option .= "\n<br>" if $option;
+ $option .= $locale->text('Notes') . " : $form->{notes}";
+ }
+ if ( $form->{shipvia} ) {
+ $callback .= "&shipvia=" . $form->escape( $form->{shipvia}, 1 );
+ $href .= "&shipvia=" . $form->escape( $form->{shipvia} );
+ $option .= "\n<br>" if $option;
+ $option .= $locale->text('Ship via') . " : $form->{shipvia}";
+ }
+ 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 [_1]',
+ $locale->date( \%myconfig, $form->{transdateto}, 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');
+ }
+
+ @columns =
+ $form->sort_columns(
+ qw(transdate id invnumber ordnumber ponumber name netamount tax amount paid due curr datepaid duedate notes till employee manager shippingpoint shipvia department)
+ );
+ pop @columns if $form->{department};
+ unshift @columns, "runningnumber";
+
+ foreach $item (@columns) {
+ if ( $form->{"l_$item"} eq "Y" ) {
+ push @column_index, $item;
+
+ if ( $form->{l_curr} && $item =~ /(amount|tax|paid|due)/ ) {
+ push @column_index, "fx_$item";
+ }
+
+ # add column to href and callback
+ $callback .= "&l_$item=Y";
+ $href .= "&l_$item=Y";
+ }
+ }
+
+ if ( !$form->{summary} ) {
+ foreach $item (qw(source debit credit accno description projectnumber))
+ {
+ push @column_index, $item;
+ }
+ }
+
+ if ( $form->{l_subtotal} eq 'Y' ) {
+ $callback .= "&l_subtotal=Y";
+ $href .= "&l_subtotal=Y";
+ }
+
+ $employee =
+ ( $form->{ARAP} eq 'AR' )
+ ? $locale->text('Salesperson')
+ : $locale->text('Employee');
+ $name =
+ ( $form->{vc} eq 'customer' )
+ ? $locale->text('Customer')
+ : $locale->text('Vendor');
+
+ $column_header{runningnumber} = qq|<th class=listheading>&nbsp;</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{duedate} =
+ "<th><a class=listheading href=$href&sort=duedate>"
+ . $locale->text('Due 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{ponumber} =
+ "<th><a class=listheading href=$href&sort=ponumber>"
+ . $locale->text('PO Number')
+ . "</a></th>";
+ $column_header{name} =
+ "<th><a class=listheading href=$href&sort=name>$name</a></th>";
+ $column_header{netamount} =
+ "<th class=listheading>" . $locale->text('Amount') . "</th>";
+ $column_header{tax} =
+ "<th class=listheading>" . $locale->text('Tax') . "</th>";
+ $column_header{amount} =
+ "<th class=listheading>" . $locale->text('Total') . "</th>";
+ $column_header{paid} =
+ "<th class=listheading>" . $locale->text('Paid') . "</th>";
+ $column_header{datepaid} =
+ "<th><a class=listheading href=$href&sort=datepaid>"
+ . $locale->text('Date Paid')
+ . "</a></th>";
+ $column_header{due} =
+ "<th class=listheading>" . $locale->text('Amount Due') . "</th>";
+ $column_header{notes} =
+ "<th class=listheading>" . $locale->text('Notes') . "</th>";
+ $column_header{employee} =
+ "<th><a class=listheading href=$href&sort=employee>$employee</th>";
+ $column_header{manager} =
+ "<th><a class=listheading href=$href&sort=manager>"
+ . $locale->text('Manager') . "</th>";
+ $column_header{till} =
+ "<th class=listheading><a class=listheading href=$href&sort=till>"
+ . $locale->text('Till') . "</th>";
+
+ $column_header{shippingpoint} =
+ "<th><a class=listheading href=$href&sort=shippingpoint>"
+ . $locale->text('Shipping Point')
+ . "</a></th>";
+ $column_header{shipvia} =
+ "<th><a class=listheading href=$href&sort=shipvia>"
+ . $locale->text('Ship via')
+ . "</a></th>";
+
+ $column_header{curr} =
+ "<th><a class=listheading href=$href&sort=curr>"
+ . $locale->text('Curr')
+ . "</a></th>";
+ for (qw(amount tax netamount paid due)) {
+ $column_header{"fx_$_"} = "<th>&nbsp;</th>";
+ }
+
+ $column_header{department} =
+ "<th><a class=listheading href=$href&sort=department>"
+ . $locale->text('Department')
+ . "</a></th>";
+
+ $column_header{accno} =
+ "<th><a class=listheading href=$href&sort=accno>"
+ . $locale->text('Account')
+ . "</a></th>";
+ $column_header{source} =
+ "<th><a class=listheading href=$href&sort=source>"
+ . $locale->text('Source')
+ . "</a></th>";
+ $column_header{debit} =
+ "<th class=listheading>" . $locale->text('Debit') . "</th>";
+ $column_header{credit} =
+ "<th class=listheading>" . $locale->text('Credit') . "</th>";
+ $column_header{projectnumber} =
+ "<th><a class=listheading href=$href&sort=projectnumber>"
+ . $locale->text('Project')
+ . "</a></th>";
+ $column_header{description} =
+ "<th><a class=listheading href=$href&sort=linedescription>"
+ . $locale->text('Description')
+ . "</a></th>";
+
+ $form->{title} =
+ ( $form->{title} ) ? $form->{title} : $locale->text('AR Transactions');
+
+ $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>
+|;
+
+ # 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&/;
+
+ if ( @{ $form->{transactions} } ) {
+ $sameitem = $form->{transactions}->[0]->{ $form->{sort} };
+ }
+
+ # sums and tax on reports by Antonio Gallardo
+ #
+ $i = 0;
+ foreach $ref ( @{ $form->{transactions} } ) {
+
+ $i++;
+
+ if ( $form->{l_subtotal} eq 'Y' ) {
+ if ( $sameitem ne $ref->{ $form->{sort} } ) {
+ &subtotal;
+ $sameitem = $ref->{ $form->{sort} };
+ }
+ }
+
+ if ( $form->{l_curr} ) {
+ for (qw(netamount amount paid)) {
+ $ref->{"fx_$_"} = $ref->{$_} / $ref->{exchangerate};
+ }
+
+ for (qw(netamount amount paid)) {
+ $column_data{"fx_$_"} = "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{"fx_$_"}, 2,
+ "&nbsp;" )
+ . "</td>";
+ }
+
+ $column_data{fx_tax} = "<td align=right>"
+ . $form->format_amount( \%myconfig,
+ $ref->{fx_amount} - $ref->{fx_netamount},
+ 2, "&nbsp;" )
+ . "</td>";
+ $column_data{fx_due} = "<td align=right>"
+ . $form->format_amount( \%myconfig,
+ $ref->{fx_amount} - $ref->{fx_paid},
+ 2, "&nbsp;" )
+ . "</td>";
+
+ $subtotalfxnetamount += $ref->{fx_netamount};
+ $subtotalfxamount += $ref->{fx_amount};
+ $subtotalfxpaid += $ref->{fx_paid};
+
+ $totalfxnetamount += $ref->{fx_netamount};
+ $totalfxamount += $ref->{fx_amount};
+ $totalfxpaid += $ref->{fx_paid};
+
+ }
+
+ $column_data{runningnumber} = "<td align=right>$i</td>";
+
+ for (qw(netamount amount paid debit credit)) {
+ $column_data{$_} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" )
+ . "</td>";
+ }
+
+ $column_data{tax} = "<td align=right>"
+ . $form->format_amount( \%myconfig,
+ $ref->{amount} - $ref->{netamount},
+ 2, "&nbsp;" )
+ . "</td>";
+ $column_data{due} = "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{amount} - $ref->{paid},
+ 2, "&nbsp;" )
+ . "</td>";
+
+ $subtotalnetamount += $ref->{netamount};
+ $subtotalamount += $ref->{amount};
+ $subtotalpaid += $ref->{paid};
+ $subtotaldebit += $ref->{debit};
+ $subtotalcredit += $ref->{credit};
+
+ $totalnetamount += $ref->{netamount};
+ $totalamount += $ref->{amount};
+ $totalpaid += $ref->{paid};
+ $totaldebit += $ref->{debit};
+ $totalcredit += $ref->{credit};
+
+ $module =
+ ( $ref->{invoice} )
+ ? ( $form->{ARAP} eq 'AR' ) ? "is.pl" : "ir.pl"
+ : $form->{script};
+ $module = ( $ref->{till} ) ? "ps.pl" : $module;
+
+ $column_data{invnumber} =
+"<td><a href=$module?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}&nbsp;</a></td>";
+
+ for (qw(notes description)) { $ref->{$_} =~ s/\r?\n/<br>/g }
+ for (
+ qw(transdate datepaid duedate department ordnumber ponumber notes shippingpoint shipvia employee manager till source description projectnumber)
+ )
+ {
+ $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
+ }
+ for (qw(id curr)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
+
+ $column_data{accno} =
+qq|<td><a href=ca.pl?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&action=list_transactions&accounttype=standard&accno=$ref->{accno}&fromdate=$form->{transdatefrom}&todate=$form->{transdateto}&sort=transdate&l_subtotal=$form->{l_subtotal}&prevreport=$callback>$ref->{accno}</a></td>|;
+
+ $column_data{name} =
+qq|<td><a href=ct.pl?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&action=edit&id=$ref->{"$form->{vc}_id"}&db=$form->{vc}&callback=$callback>$ref->{name}</a></td>|;
+
+ if ( $ref->{id} != $sameid ) {
+ $j++;
+ $j %= 2;
+ }
+
+ print "
+ <tr class=listrow$j>
+";
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
+ </tr>
+|;
+
+ $sameid = $ref->{id};
+
+ }
+
+ if ( $form->{l_subtotal} eq 'Y' ) {
+ &subtotal;
+ $sameitem = $ref->{ $form->{sort} };
+ }
+
+ # print totals
+ print qq|
+ <tr class=listtotal>
+|;
+
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{netamount} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{tax} = "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalamount - $totalnetamount,
+ 2, "&nbsp;" )
+ . "</th>";
+ $column_data{amount} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalamount, 2, "&nbsp;" ) . "</th>";
+ $column_data{paid} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" ) . "</th>";
+ $column_data{due} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalamount - $totalpaid, 2,
+ "&nbsp;" )
+ . "</th>";
+ $column_data{debit} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totaldebit, 2, "&nbsp;" ) . "</th>";
+ $column_data{credit} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalcredit, 2, "&nbsp;" ) . "</th>";
+
+ if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
+ $column_data{fx_netamount} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalfxnetamount, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{fx_tax} = "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig,
+ $totalfxamount - $totalfxnetamount,
+ 2, "&nbsp;" )
+ . "</th>";
+ $column_data{fx_amount} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalfxamount, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{fx_paid} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalfxpaid, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{fx_due} = "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalfxamount - $totalfxpaid,
+ 2, "&nbsp;" )
+ . "</th>";
+ }
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ if ( $myconfig{acs} !~ /$form->{ARAP}--$form->{ARAP}/ ) {
+ $i = 1;
+ if ( $form->{ARAP} eq 'AR' ) {
+ $button{'AR--Add Transaction'}{code} =
+qq|<button class="submit" type="submit" name="action" value="ar_transaction">|
+ . $locale->text('AR Transaction')
+ . qq|</button> |;
+ $button{'AR--Add Transaction'}{order} = $i++;
+ $button{'AR--Sales Invoice'}{code} =
+qq|<button class="submit" type="submit" name="action" value="sales_invoice_">|
+ . $locale->text('Sales Invoice.')
+ . qq|</button> |;
+ $button{'AR--Sales Invoice'}{order} = $i++;
+ }
+ else {
+ $button{'AP--Add Transaction'}{code} =
+qq|<button class="submit" type="submit" name="action" value="ap_transaction">|
+ . $locale->text('AP Transaction')
+ . qq|</button> |;
+ $button{'AP--Add Transaction'}{order} = $i++;
+ $button{'AP--Vendor Invoice'}{code} =
+qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|
+ . $locale->text('Vendor Invoice.')
+ . qq|</button> |;
+ $button{'AP--Vendor Invoice'}{order} = $i++;
+ }
+
+ foreach $item ( split /;/, $myconfig{acs} ) {
+ delete $button{$item};
+ }
+ }
+
+ 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(
+ "callback", "path", "login", "sessionid",
+ "$form->{vc}", "$form->{vc}_id"
+ );
+
+ if ( !$form->{till} ) {
+ 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 subtotal {
+
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{tax} = "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalamount - $subtotalnetamount,
+ 2, "&nbsp;" )
+ . "</th>";
+ $column_data{amount} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalamount, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{paid} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalpaid, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{due} = "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalamount - $subtotalpaid,
+ 2, "&nbsp;" )
+ . "</th>";
+ $column_data{debit} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{credit} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" )
+ . "</th>";
+
+ if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
+ $column_data{fx_tax} = "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig,
+ $subtotalfxamount - $subtotalfxnetamount,
+ 2, "&nbsp;" )
+ . "</th>";
+ $column_data{fx_amount} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalfxamount, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{fx_paid} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalfxpaid, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{fx_due} = "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig,
+ $subtotalfxmount - $subtotalfxpaid,
+ 2, "&nbsp;" )
+ . "</th>";
+ }
+
+ $subtotalnetamount = 0;
+ $subtotalamount = 0;
+ $subtotalpaid = 0;
+ $subtotaldebit = 0;
+ $subtotalcredit = 0;
+
+ $subtotalfxnetamount = 0;
+ $subtotalfxamount = 0;
+ $subtotalfxpaid = 0;
+
+ print "<tr class=listsubtotal>";
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print "
+</tr>
+";
+
+}
+
diff --git a/bin/admin.pl b/bin/admin.pl
index 38c51c20..2754dac4 100644
--- a/bin/admin.pl
+++ b/bin/admin.pl
@@ -1,9 +1,9 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
#
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -43,52 +43,58 @@ use LedgerSMB::Session;
$form = new Form;
-$locale = LedgerSMB::Locale->get_handle(${LedgerSMB::Sysconfig::language}) or
- $form->error(__FILE__.':'.__LINE__.': '."Locale not loaded: $!\n");
+$locale = LedgerSMB::Locale->get_handle( ${LedgerSMB::Sysconfig::language} )
+ or
+ $form->error( __FILE__ . ':' . __LINE__ . ': ' . "Locale not loaded: $!\n" );
$locale->encoding('UTF-8');
$form->{charset} = 'UTF-8';
eval { require DBI; };
-$form->error(__FILE__.':'.__LINE__.': '.$locale->text('DBI not installed!')) if ($@);
+$form->error(
+ __FILE__ . ':' . __LINE__ . ': ' . $locale->text('DBI not installed!') )
+ if ($@);
$form->{stylesheet} = "ledgersmb.css";
-$form->{favicon} = "favicon.ico";
-$form->{timeout} = 600;
+$form->{favicon} = "favicon.ico";
+$form->{timeout} = 600;
require "bin/pw.pl";
# customization
-if (-f "bin/custom/$form->{script}") {
- eval { require "bin/custom/$form->{script}"; };
- $form->error(__FILE__.':'.__LINE__.': '.$@) if ($@);
+if ( -f "bin/custom/$form->{script}" ) {
+ eval { require "bin/custom/$form->{script}"; };
+ $form->error( __FILE__ . ':' . __LINE__ . ': ' . $@ ) if ($@);
}
+if ( $form->{action} ) {
+ &check_password unless $form->{action} eq 'logout';
+ &{ $form->{action} };
-if ($form->{action}) {
- &check_password unless $form->{action} eq 'logout';
- &{ $form->{action} };
-
-} else {
+}
+else {
- # if there are no drivers bail out
- $form->error(__FILE__.':'.__LINE__.': '.$locale->text('No Database Drivers available!')) unless (LedgerSMB::User->dbdrivers);
+ # if there are no drivers bail out
+ $form->error( __FILE__ . ':' . __LINE__ . ': '
+ . $locale->text('No Database Drivers available!') )
+ unless ( LedgerSMB::User->dbdrivers );
- $root = LedgerSMB::User->new('admin');
+ $root = LedgerSMB::User->new('admin');
- &adminlogin;
+ &adminlogin;
}
1;
-# end
+# end
sub adminlogin {
- my ($errorMessage) = @_;
+ my ($errorMessage) = @_;
- $form->{title} = qq|LedgerSMB $form->{version} |.$locale->text('Administration');
+ $form->{title} =
+ qq|LedgerSMB $form->{version} | . $locale->text('Administration');
- $myheaderadd = qq|
+ $myheaderadd = qq|
<script language="JavaScript" type="text/javascript">
<!--
function sf(){
@@ -97,19 +103,25 @@ sub adminlogin {
// End -->
</script>
|;
- $form->header(undef, $myheaderadd);
+ $form->header( undef, $myheaderadd );
- print qq|
+ print qq|
<body class="admin" onload="sf()">
<div align="center">
<a href="http://www.ledgersmb.org/"><img src="images/ledgersmb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
- <h1 class="login">|.$locale->text('Version').qq| $form->{version} <br />|.$locale->text('Administration').qq|</h1>
+ <h1 class="login">|
+ . $locale->text('Version')
+ . qq| $form->{version} <br />|
+ . $locale->text('Administration')
+ . qq|</h1>
<form method="post" action="admin.pl" name="admin">
<table>
<tr>
- <th>|.$locale->text('Password').qq|</th>
+ <th>| . $locale->text('Password') . qq|</th>
<td><input type="password" name="password" /></td>
- <td><button type="submit" class="submit" name="action" value="login">|.$locale->text('Login').qq|</button></td>
+ <td><button type="submit" class="submit" name="action" value="login">|
+ . $locale->text('Login')
+ . qq|</button></td>
</tr>
</table>
<input type="hidden" name="action" value="login" />
@@ -117,17 +129,19 @@ sub adminlogin {
</form>
|;
- if($errorMessage){
- print qq|<p><span style="font-weight:bold; color:red;">$errorMessage</span></p><br />|;
- }
+ if ($errorMessage) {
+ print
+qq|<p><span style="font-weight:bold; color:red;">$errorMessage</span></p><br />|;
+ }
- print qq|
+ print qq|
<br /><br />
<p><a href="login.pl"
- >|.$locale->text("Application Login").qq|</a></p>
+ >| . $locale->text("Application Login") . qq|</a></p>
<br /><br />
- <a style="font-size: 0.8em;" href="http://www.ledgersmb.org/">|.$locale->text('LedgerSMB website').qq|</a>
+ <a style="font-size: 0.8em;" href="http://www.ledgersmb.org/">|
+ . $locale->text('LedgerSMB website') . qq|</a>
</div>
</body>
</html>
@@ -135,60 +149,68 @@ sub adminlogin {
}
-
sub login {
- &list_users;
+ &list_users;
}
-
sub logout {
- $form->{callback} = "admin.pl?action=adminlogin";
- Session::session_destroy($form);
- $form->redirect($locale->text('You are logged out'));
+ $form->{callback} = "admin.pl?action=adminlogin";
+ Session::session_destroy($form);
+ $form->redirect( $locale->text('You are logged out') );
}
-
sub add_user {
- $form->{title} = "LedgerSMB ".$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Add User');
+ $form->{title} =
+ "LedgerSMB "
+ . $locale->text('Accounting') . " "
+ . $locale->text('Administration') . " / "
+ . $locale->text('Add User');
- if (-f "css/ledgersmb.css") {
- $myconfig->{stylesheet} = "ledgersmb.css";
- }
+ if ( -f "css/ledgersmb.css" ) {
+ $myconfig->{stylesheet} = "ledgersmb.css";
+ }
- $myconfig->{vclimit} = 1000;
- $myconfig->{menuwidth} = 155;
- $myconfig->{timeout} = 3600;
+ $myconfig->{vclimit} = 1000;
+ $myconfig->{menuwidth} = 155;
+ $myconfig->{timeout} = 3600;
- &form_header;
- &form_footer;
+ &form_header;
+ &form_footer;
}
-
sub edit {
- $form->{title} = "LedgerSMB ".$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Edit User');
- $form->{edit} = 1;
+ $form->{title} =
+ "LedgerSMB "
+ . $locale->text('Accounting') . " "
+ . $locale->text('Administration') . " / "
+ . $locale->text('Edit User');
+ $form->{edit} = 1;
- &form_header;
- &form_footer;
+ &form_header;
+ &form_footer;
}
-
sub form_footer {
- if ($form->{edit}) {
- $delete = qq|<button type="submit" class="submit" name="action" value="delete">|.$locale->text('Delete').qq|</button>
+ if ( $form->{edit} ) {
+ $delete =
+ qq|<button type="submit" class="submit" name="action" value="delete">|
+ . $locale->text('Delete')
+ . qq|</button>
<input type="hidden" name="edit" value="1" />|;
- }
+ }
- print qq|
+ print qq|
<input name="callback" type="hidden" value="$form->{script}?action=list_users&amp;path=$form->{path}" />
<input type="hidden" name="path" value="$form->{path}" />
- <button type="submit" class="submit" name="action" value="save">|.$locale->text('Save').qq|</button>
+ <button type="submit" class="submit" name="action" value="save">|
+ . $locale->text('Save')
+ . qq|</button>
$delete
</form>
</body>
@@ -196,50 +218,58 @@ sub form_footer {
|;
}
-
sub list_users {
+ # use the central database handle
+ my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
- # use the central database handle
- my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
-
- my $fetchMembers = $dbh->selectall_arrayref("SELECT uc.name, uc.company, uc.templates, uc.dbuser, uc.dbdriver, uc.dbname, uc.dbhost, u.username
+ my $fetchMembers = $dbh->selectall_arrayref(
+"SELECT uc.name, uc.company, uc.templates, uc.dbuser, uc.dbdriver, uc.dbname, uc.dbhost, u.username
FROM users as u, users_conf as uc
WHERE u.id = uc.id
AND u.id > 1
- ORDER BY u.username;", { Slice => {} });
-
- my @memberArray = ();
- my @member = ();
-
- foreach my $memberArray ( @$fetchMembers ) {
- $member{$memberArray->{username}} = $memberArray;
- }
-
- # type=submit $locale->text('Pg Database Administration')
- # type=submit $locale->text('PgPP Database Administration')
-
- foreach $item (LedgerSMB::User->dbdrivers) {
- $dbdrivers .= qq|<button name="action" type="submit" class="submit" value="|.(lc $item).'_database_administration">'.$locale->text("$item Database Administration").qq|</button>|;
- }
-
-
- $column_header{login} = qq|<th>|.$locale->text('Login').qq|</th>|;
- $column_header{name} = qq|<th>|.$locale->text('Name').qq|</th>|;
- $column_header{company} = qq|<th>|.$locale->text('Company').qq|</th>|;
- $column_header{dbdriver} = qq|<th>|.$locale->text('Driver').qq|</th>|;
- $column_header{dbhost} = qq|<th>|.$locale->text('Host').qq|</th>|;
- $column_header{dataset} = qq|<th>|.$locale->text('Dataset').qq|</th>|;
- $column_header{templates} = qq|<th>|.$locale->text('Templates').qq|</th>|;
-
- @column_index = qw(login name company dbdriver dbhost dataset templates);
-
- $form->{title} = "LedgerSMB ".$locale->text('Accounting')." ".$locale->text('Administration');
-
- $form->{login} = "admin";
- $form->header;
-
- print qq|
+ ORDER BY u.username;", { Slice => {} }
+ );
+
+ my @memberArray = ();
+ my @member = ();
+
+ foreach my $memberArray (@$fetchMembers) {
+ $member{ $memberArray->{username} } = $memberArray;
+ }
+
+ # type=submit $locale->text('Pg Database Administration')
+ # type=submit $locale->text('PgPP Database Administration')
+
+ foreach $item ( LedgerSMB::User->dbdrivers ) {
+ $dbdrivers .=
+ qq|<button name="action" type="submit" class="submit" value="|
+ . ( lc $item )
+ . '_database_administration">'
+ . $locale->text("$item Database Administration")
+ . qq|</button>|;
+ }
+
+ $column_header{login} = qq|<th>| . $locale->text('Login') . qq|</th>|;
+ $column_header{name} = qq|<th>| . $locale->text('Name') . qq|</th>|;
+ $column_header{company} = qq|<th>| . $locale->text('Company') . qq|</th>|;
+ $column_header{dbdriver} = qq|<th>| . $locale->text('Driver') . qq|</th>|;
+ $column_header{dbhost} = qq|<th>| . $locale->text('Host') . qq|</th>|;
+ $column_header{dataset} = qq|<th>| . $locale->text('Dataset') . qq|</th>|;
+ $column_header{templates} =
+ qq|<th>| . $locale->text('Templates') . qq|</th>|;
+
+ @column_index = qw(login name company dbdriver dbhost dataset templates);
+
+ $form->{title} =
+ "LedgerSMB "
+ . $locale->text('Accounting') . " "
+ . $locale->text('Administration');
+
+ $form->{login} = "admin";
+ $form->header;
+
+ print qq|
<body class="admin">
<form method="post" action="$form->{script}">
<table width="100%">
@@ -252,35 +282,35 @@ sub list_users {
<table width="100%">
<tr class="listheading">|;
- for (@column_index) { print "$column_header{$_}\n" }
+ for (@column_index) { print "$column_header{$_}\n" }
- print qq| </tr>|;
+ print qq| </tr>|;
- foreach $key (sort keys %member) {
+ foreach $key ( sort keys %member ) {
- $href = "$script?action=edit&amp;login=$key&amp;path=$form->{path}";
- $href =~ s/ /%20/g;
+ $href = "$script?action=edit&amp;login=$key&amp;path=$form->{path}";
+ $href =~ s/ /%20/g;
- $member{$key}{templates} =~ s/^${LedgerSMB::Sysconfig::templates}\///;
+ $member{$key}{templates} =~ s/^${LedgerSMB::Sysconfig::templates}\///;
- $column_data{login} = qq|<td><a href="$href">$key</a></td>|;
- $column_data{name} = qq|<td>$member{$key}{name}</td>|;
- $column_data{company} = qq|<td>$member{$key}{company}</td>|;
- $column_data{dbdriver} = qq|<td>$member{$key}{dbdriver}</td>|;
- $column_data{dbhost} = qq|<td>$member{$key}{dbhost}</td>|;
- $column_data{dataset} = qq|<td>$member{$key}{dbname}</td>|;
- $column_data{templates} = qq|<td>$member{$key}{templates}</td>|;
+ $column_data{login} = qq|<td><a href="$href">$key</a></td>|;
+ $column_data{name} = qq|<td>$member{$key}{name}</td>|;
+ $column_data{company} = qq|<td>$member{$key}{company}</td>|;
+ $column_data{dbdriver} = qq|<td>$member{$key}{dbdriver}</td>|;
+ $column_data{dbhost} = qq|<td>$member{$key}{dbhost}</td>|;
+ $column_data{dataset} = qq|<td>$member{$key}{dbname}</td>|;
+ $column_data{templates} = qq|<td>$member{$key}{templates}</td>|;
- $i++; $i %= 2;
- print qq| <tr class="listrow$i">|;
+ $i++;
+ $i %= 2;
+ print qq| <tr class="listrow$i">|;
- for (@column_index) { print "$column_data{$_}\n"; }
+ for (@column_index) { print "$column_data{$_}\n"; }
- print qq| </tr>|;
- }
+ print qq| </tr>|;
+ }
-
- print qq| </table>
+ print qq| </table>
</td>
</tr>
<tr>
@@ -289,149 +319,183 @@ sub list_users {
</table>
<input type="hidden" name="path" value="$form->{path}" />
<br />
- <button type="submit" class="submit" name="action" value="add_user">|.$locale->text('Add User').qq|</button>
- <button type="submit" class="submit" name="action" value="change_admin_password">|.$locale->text('Change Admin Password').qq|</button>
+ <button type="submit" class="submit" name="action" value="add_user">|
+ . $locale->text('Add User')
+ . qq|</button>
+ <button type="submit" class="submit" name="action" value="change_admin_password">|
+ . $locale->text('Change Admin Password')
+ . qq|</button>
$dbdrivers
$nologin
- <button type="submit" class="submit" name="action" value="logout">|.$locale->text('Logout').qq|</button>
+ <button type="submit" class="submit" name="action" value="logout">|
+ . $locale->text('Logout')
+ . qq|</button>
</form>
- |.$locale->text('Click on login name to edit!').qq|
+ | . $locale->text('Click on login name to edit!') . qq|
<br />
- |.$locale->text('To add a user to a group edit a name, change the login name and save. A new user with the same variables will then be saved under the new login name.').qq|
+ |
+ . $locale->text(
+'To add a user to a group edit a name, change the login name and save. A new user with the same variables will then be saved under the new login name.'
+ )
+ . qq|
</body>
</html>|;
}
-
sub form_header {
- # if there is a login, get user
- if ($form->{login}) {
-
- # get user
- %{$myconfig} = %{LedgerSMB::User->fetch_config($form->{login})};
-
- for (qw(company address signature)) { $myconfig->{$_} = $form->quote($myconfig->{$_}) }
- for (qw(address signature)) { $myconfig->{$_} =~ s/\\n/\n/g }
-
- # strip basedir from templates directory
- $myconfig->{templates} =~ s/^${LedgerSMB::Sysconfig::templates}\///;
- }
-
- foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
- $dateformat .= ($item eq $myconfig->{dateformat}) ? "<option selected>$item</option>\n" : "<option>$item</option>\n";
- }
-
- my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00);
- push @formats, '1 000.00';
- foreach $item (@formats) {
- $numberformat .= ($item eq $myconfig->{numberformat}) ? "<option selected>$item</option>\n" : "<option>$item</option>\n";
- }
-
-
- %countrycodes = LedgerSMB::User->country_codes;
- $countrycodes = "";
- my $selectedcode = ($myconfig->{countrycode}) ?
- $myconfig->{countrycode} : 'en';
-
- foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
- $countrycodes .= ($selectedcode eq $key) ? qq|<option selected value="$key">$countrycodes{$key}</option>|
- : qq|<option value="$key">$countrycodes{$key}</option>|;
- }
-
- # is there a templates basedir
- if (! -d "${LedgerSMB::Sysconfig::templates}") {
- $form->error(__FILE__.':'.__LINE__.': '.$locale->text('Directory [_1] does not exist', ${LedgerSMB::Sysconfig::templates}));
- }
-
- opendir TEMPLATEDIR, "${LedgerSMB::Sysconfig::templates}/." or $form->error(__FILE__.':'.__LINE__.': '."$templates : $!");
- @all = grep !/(^\.\.?|^\.svn)/, readdir TEMPLATEDIR;
- closedir TEMPLATEDIR;
-
- @allhtml = sort grep /\.html/, @all;
-
- @alldir = ();
- for (@all) {
-
- if (-d "${LedgerSMB::Sysconfig::templates}/$_") {
- push @alldir, $_;
- }
- }
-
- @allhtml = reverse grep !/Default/, @allhtml;
- push @allhtml, 'Default';
- @allhtml = reverse @allhtml;
-
- foreach $item (sort @alldir) {
-
- if ($item eq $myconfig->{templates}) {
- $usetemplates .= qq|<option selected value="$item">$item</option>\n|;
- } else {
- $usetemplates .= qq|<option value="$item">$item</option>\n|;
- }
- }
-
- $lastitem = $allhtml[0];
- $lastitem =~ s/-.*//g;
- $mastertemplates = qq|<option value="$lastitem">$lastitem</option>\n|;
-
- foreach $item (@allhtml) {
-
- $item =~ s/-.*//g;
-
- if ($item ne $lastitem) {
- $mastertemplates .= qq|<option value="$item">$item</option>\n|;
- $lastitem = $item;
- }
- }
-
- opendir CSS, "css/.";
- @all = grep /.*\.css$/, readdir CSS;
- closedir CSS;
-
- foreach $item (@all) {
-
- if ($item eq $myconfig->{stylesheet}) {
- $selectstylesheet .= qq|<option selected value="$item">$item</option>\n|;
- } else {
- $selectstylesheet .= qq|<option value="$item">$item</option>\n|;
- }
- }
-
- $selectstylesheet .= "<option></option>\n";
-
- if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
-
- $selectprinter = "<option></option>\n";
-
- foreach $item (sort keys %{LedgerSMB::Sysconfig::printer}) {
-
- if ($myconfig->{printer} eq $item) {
- $selectprinter .= qq|<option value="$item" selected>$item</option>\n|;
- } else {
- $selectprinter .= qq|<option value="$item">$item</option>\n|;
- }
- }
-
- $printer = qq|
+ # if there is a login, get user
+ if ( $form->{login} ) {
+
+ # get user
+ %{$myconfig} = %{ LedgerSMB::User->fetch_config( $form->{login} ) };
+
+ for (qw(company address signature)) {
+ $myconfig->{$_} = $form->quote( $myconfig->{$_} );
+ }
+ for (qw(address signature)) { $myconfig->{$_} =~ s/\\n/\n/g }
+
+ # strip basedir from templates directory
+ $myconfig->{templates} =~ s/^${LedgerSMB::Sysconfig::templates}\///;
+ }
+
+ foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd))
+ {
+ $dateformat .=
+ ( $item eq $myconfig->{dateformat} )
+ ? "<option selected>$item</option>\n"
+ : "<option>$item</option>\n";
+ }
+
+ my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00);
+ push @formats, '1 000.00';
+ foreach $item (@formats) {
+ $numberformat .=
+ ( $item eq $myconfig->{numberformat} )
+ ? "<option selected>$item</option>\n"
+ : "<option>$item</option>\n";
+ }
+
+ %countrycodes = LedgerSMB::User->country_codes;
+ $countrycodes = "";
+ my $selectedcode =
+ ( $myconfig->{countrycode} ) ? $myconfig->{countrycode} : 'en';
+
+ foreach $key ( sort { $countrycodes{$a} cmp $countrycodes{$b} }
+ keys %countrycodes )
+ {
+ $countrycodes .=
+ ( $selectedcode eq $key )
+ ? qq|<option selected value="$key">$countrycodes{$key}</option>|
+ : qq|<option value="$key">$countrycodes{$key}</option>|;
+ }
+
+ # is there a templates basedir
+ if ( !-d "${LedgerSMB::Sysconfig::templates}" ) {
+ $form->error(
+ __FILE__ . ':' . __LINE__ . ': '
+ . $locale->text(
+ 'Directory [_1] does not exist',
+ ${LedgerSMB::Sysconfig::templates}
+ )
+ );
+ }
+
+ opendir TEMPLATEDIR, "${LedgerSMB::Sysconfig::templates}/."
+ or $form->error( __FILE__ . ':' . __LINE__ . ': ' . "$templates : $!" );
+ @all = grep !/(^\.\.?|^\.svn)/, readdir TEMPLATEDIR;
+ closedir TEMPLATEDIR;
+
+ @allhtml = sort grep /\.html/, @all;
+
+ @alldir = ();
+ for (@all) {
+
+ if ( -d "${LedgerSMB::Sysconfig::templates}/$_" ) {
+ push @alldir, $_;
+ }
+ }
+
+ @allhtml = reverse grep !/Default/, @allhtml;
+ push @allhtml, 'Default';
+ @allhtml = reverse @allhtml;
+
+ foreach $item ( sort @alldir ) {
+
+ if ( $item eq $myconfig->{templates} ) {
+ $usetemplates .=
+ qq|<option selected value="$item">$item</option>\n|;
+ }
+ else {
+ $usetemplates .= qq|<option value="$item">$item</option>\n|;
+ }
+ }
+
+ $lastitem = $allhtml[0];
+ $lastitem =~ s/-.*//g;
+ $mastertemplates = qq|<option value="$lastitem">$lastitem</option>\n|;
+
+ foreach $item (@allhtml) {
+
+ $item =~ s/-.*//g;
+
+ if ( $item ne $lastitem ) {
+ $mastertemplates .= qq|<option value="$item">$item</option>\n|;
+ $lastitem = $item;
+ }
+ }
+
+ opendir CSS, "css/.";
+ @all = grep /.*\.css$/, readdir CSS;
+ closedir CSS;
+
+ foreach $item (@all) {
+
+ if ( $item eq $myconfig->{stylesheet} ) {
+ $selectstylesheet .=
+ qq|<option selected value="$item">$item</option>\n|;
+ }
+ else {
+ $selectstylesheet .= qq|<option value="$item">$item</option>\n|;
+ }
+ }
+
+ $selectstylesheet .= "<option></option>\n";
+
+ if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) {
+
+ $selectprinter = "<option></option>\n";
+
+ foreach $item ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
+
+ if ( $myconfig->{printer} eq $item ) {
+ $selectprinter .=
+ qq|<option value="$item" selected>$item</option>\n|;
+ }
+ else {
+ $selectprinter .= qq|<option value="$item">$item</option>\n|;
+ }
+ }
+
+ $printer = qq|
<tr>
- <th align="right">|.$locale->text('Printer').qq|</th>
+ <th align="right">| . $locale->text('Printer') . qq|</th>
<td><select name="printer">$selectprinter</select></td>
</tr>
|;
- }
+ }
- $user = $form->{login};
- $form->{login} = "admin";
- $form->header;
- $form->{login} = $user;
+ $user = $form->{login};
+ $form->{login} = "admin";
+ $form->header;
+ $form->{login} = $user;
- print qq|
+ print qq|
<body class="admin">
<form method="post" action="admin.pl">
<table width="100%">
@@ -441,39 +505,39 @@ sub form_header {
<td>
<table>
<tr>
- <th align="right">|.$locale->text('Login').qq|</th>
+ <th align="right">| . $locale->text('Login') . qq|</th>
<td><input name="login" value="$myconfig->{login}" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Password').qq|</th>
+ <th align="right">| . $locale->text('Password') . qq|</th>
<td><input type="password" name="new_password" size="8" value="$myconfig->{password}" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Name').qq|</th>
+ <th align="right">| . $locale->text('Name') . qq|</th>
<td><input name="name" size="15" value="$myconfig->{name}" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('E-mail').qq|</th>
+ <th align="right">| . $locale->text('E-mail') . qq|</th>
<td><input name="email" size="30" value="$myconfig->{email}" /></td>
</tr>
<tr valign="top">
- <th align="right">|.$locale->text('Signature').qq|</th>
+ <th align="right">| . $locale->text('Signature') . qq|</th>
<td><textarea name="signature" rows="3" cols="35">$myconfig->{signature}</textarea></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Phone').qq|</th>
+ <th align="right">| . $locale->text('Phone') . qq|</th>
<td><input name="tel" size="14" value="$myconfig->{tel}" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Fax').qq|</th>
+ <th align="right">| . $locale->text('Fax') . qq|</th>
<td><input name="fax" size="14" value="$myconfig->{fax}" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Company').qq|</th>
+ <th align="right">| . $locale->text('Company') . qq|</th>
<td><input name="company" size="35" value="$myconfig->{company}" /></td>
</tr>
<tr valign="top">
- <th align="right">|.$locale->text('Address').qq|</th>
+ <th align="right">| . $locale->text('Address') . qq|</th>
<td><textarea name="address" rows="4" cols="35">$myconfig->{address}</textarea></td>
</tr>
</table>
@@ -481,44 +545,44 @@ sub form_header {
<td>
<table>
<tr>
- <th align="right">|.$locale->text('Date Format').qq|</th>
+ <th align="right">| . $locale->text('Date Format') . qq|</th>
<td><select name="dateformat">$dateformat</select></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Number Format').qq|</th>
+ <th align="right">| . $locale->text('Number Format') . qq|</th>
<td><select name="numberformat">$numberformat</select></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Dropdown Limit').qq|</th>
+ <th align="right">| . $locale->text('Dropdown Limit') . qq|</th>
<td><input name="vclimit" value="$myconfig->{vclimit}" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Menu Width').qq|</th>
+ <th align="right">| . $locale->text('Menu Width') . qq|</th>
<td><input name="menuwidth" value="$myconfig->{menuwidth}" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Language').qq|</th>
+ <th align="right">| . $locale->text('Language') . qq|</th>
<td><select name="countrycode">$countrycodes</select></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Session Timeout').qq|</th>
+ <th align="right">| . $locale->text('Session Timeout') . qq|</th>
<td><input name="newtimeout" value="$myconfig->{timeout}" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Stylesheet').qq|</th>
+ <th align="right">| . $locale->text('Stylesheet') . qq|</th>
<td><select name="userstylesheet">$selectstylesheet</select></td>
</tr>
$printer
<tr>
- <th align="right">|.$locale->text('Use Templates').qq|</th>
+ <th align="right">| . $locale->text('Use Templates') . qq|</th>
<td><select name="usetemplates">$usetemplates</select></td>
</tr>
<tr>
- <th align="right">|.$locale->text('New Templates').qq|</th>
+ <th align="right">| . $locale->text('New Templates') . qq|</th>
<td><input name="newtemplates" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Setup Templates').qq|</th>
+ <th align="right">| . $locale->text('Setup Templates') . qq|</th>
<td><select name="mastertemplates">$mastertemplates</select></td>
</tr>
</table>
@@ -526,48 +590,50 @@ sub form_header {
</td>
</tr>
<tr class="listheading">
- <th colspan="2">|.$locale->text('Database').qq|</th>
+ <th colspan="2">| . $locale->text('Database') . qq|</th>
</tr>|;
- # list section for database drivers
- foreach $item (LedgerSMB::User->dbdrivers) {
+ # list section for database drivers
+ foreach $item ( LedgerSMB::User->dbdrivers ) {
- print qq|
+ print qq|
<tr>
<td colspan="2">
<table>
<tr>|;
- $checked = "checked";
+ $checked = "checked";
- if ($myconfig->{dbdriver} eq $item) {
+ if ( $myconfig->{dbdriver} eq $item ) {
- for (qw(dbhost dbport dbuser dbpasswd dbname sid)) { $form->{"${item}_$_"} = $myconfig->{$_} }
- $checked = "checked";
- }
+ for (qw(dbhost dbport dbuser dbpasswd dbname sid)) {
+ $form->{"${item}_$_"} = $myconfig->{$_};
+ }
+ $checked = "checked";
+ }
- print qq|
- <th align="right">|.$locale->text('Driver').qq|</th>
+ print qq|
+ <th align="right">| . $locale->text('Driver') . qq|</th>
<td><input name="dbdriver" type="radio" class="radio" value="$item" $checked />&nbsp;$item</td>
- <th align="right">|.$locale->text('Host').qq|</th>
+ <th align="right">| . $locale->text('Host') . qq|</th>
<td><input name="${item}_dbhost" size="30" value="$form->{"${item}_dbhost"}" /></td>
</tr>
<tr>|;
- print qq|
- <th align="right">|.$locale->text('Dataset').qq|</th>
+ print qq|
+ <th align="right">| . $locale->text('Dataset') . qq|</th>
<td><input name="${item}_dbname" size="15" value="$form->{"${item}_dbname"}" /></td>
- <th align="right">|.$locale->text('Port').qq|</th>
+ <th align="right">| . $locale->text('Port') . qq|</th>
<td><input name="${item}_dbport" size="4" value="$form->{"${item}_dbport"}" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('User').qq|</th>
+ <th align="right">| . $locale->text('User') . qq|</th>
<td><input name="${item}_dbuser" size="15" value="$form->{"${item}_dbuser"}" /></td>
- <th align="right">|.$locale->text('Password').qq|</th>
+ <th align="right">| . $locale->text('Password') . qq|</th>
<td><input name="${item}_dbpasswd" type="password" size="10" value="$form->{"${item}_dbpasswd"}" /></td>
</tr>|;
- print qq|
+ print qq|
</table>
<input type="hidden" name="old_dbpasswd" value="$myconfig->{dbpasswd}" />
</td>
@@ -577,115 +643,122 @@ sub form_header {
</tr>
|;
- }
+ }
+ # access control
+ open( FH, '<', $menufile )
+ or $form->error( __FILE__ . ':' . __LINE__ . ': ' . "$menufile : $!" );
- # access control
- open(FH, '<', $menufile) or $form->error(__FILE__.':'.__LINE__.': '."$menufile : $!");
- # scan for first menu level
- @a = <FH>;
- close(FH);
+ # scan for first menu level
+ @a = <FH>;
+ close(FH);
- if (open(FH, '<', "custom_$menufile")) {
- push @a, <FH>;
- }
+ if ( open( FH, '<', "custom_$menufile" ) ) {
+ push @a, <FH>;
+ }
- close(FH);
+ close(FH);
- foreach $item (@a) {
+ foreach $item (@a) {
- next unless $item =~ /\[\w+/;
- next if $item =~ /\#/;
+ next unless $item =~ /\[\w+/;
+ next if $item =~ /\#/;
- $item =~ s/(\[|\])//g;
- chop $item;
+ $item =~ s/(\[|\])//g;
+ chop $item;
- if ($item =~ /--/) {
+ if ( $item =~ /--/ ) {
- ($level, $menuitem) = split /--/, $item, 2;
- } else {
+ ( $level, $menuitem ) = split /--/, $item, 2;
+ }
+ else {
- $level = $item;
- $menuitem = $item;
- push @acsorder, $item;
- }
+ $level = $item;
+ $menuitem = $item;
+ push @acsorder, $item;
+ }
- push @{ $acs{$level} }, $menuitem;
+ push @{ $acs{$level} }, $menuitem;
- }
+ }
- %role = ( 'admin' => $locale->text('Administrator'),
- 'user' => $locale->text('User'),
- 'supervisor' => $locale->text('Supervisor'),
- 'manager' => $locale->text('Manager'));
+ %role = (
+ 'admin' => $locale->text('Administrator'),
+ 'user' => $locale->text('User'),
+ 'supervisor' => $locale->text('Supervisor'),
+ 'manager' => $locale->text('Manager')
+ );
- $selectrole = "";
+ $selectrole = "";
- foreach $item (qw(user admin supervisor manager)) {
- $selectrole .= ($myconfig->{role} eq $item) ? "<option selected value=\"$item\">$role{$item}</option>\n"
- : "<option value=\"$item\">$role{$item}</option>\n";
- }
+ foreach $item (qw(user admin supervisor manager)) {
+ $selectrole .=
+ ( $myconfig->{role} eq $item )
+ ? "<option selected value=\"$item\">$role{$item}</option>\n"
+ : "<option value=\"$item\">$role{$item}</option>\n";
+ }
- print qq|
+ print qq|
<tr class="listheading">
- <th colspan="2">|.$locale->text('Access Control').qq|</th>
+ <th colspan="2">| . $locale->text('Access Control') . qq|</th>
</tr>
<tr>
<td><select name="role">$selectrole</select></td>
</tr>
|;
- foreach $item (split /;/, $myconfig->{acs}) {
- ($key, $value) = split /--/, $item, 2;
- $excl{$key}{$value} = 1;
- }
+ foreach $item ( split /;/, $myconfig->{acs} ) {
+ ( $key, $value ) = split /--/, $item, 2;
+ $excl{$key}{$value} = 1;
+ }
- foreach $key (@acsorder) {
+ foreach $key (@acsorder) {
- $checked = "checked";
+ $checked = "checked";
- if ($form->{login}) {
- $checked = ($excl{$key}{$key}) ? "" : "checked";
- }
+ if ( $form->{login} ) {
+ $checked = ( $excl{$key}{$key} ) ? "" : "checked";
+ }
- # can't have variable names with & and spaces
- $item = $form->escape("${key}--$key",1);
+ # can't have variable names with & and spaces
+ $item = $form->escape( "${key}--$key", 1 );
- $acsheading = $key;
- $acsheading =~ s/ /&nbsp;/g;
+ $acsheading = $key;
+ $acsheading =~ s/ /&nbsp;/g;
- $acsheading = qq|
+ $acsheading = qq|
<td align="left" nowrap="nowrap" style="background-color: #C7E9F7" colspan="2">
<input name="$item" class="checkbox" type="checkbox" value="1" $checked />&nbsp;$acsheading</td><tr><td>\n|;
- $menuitems .= "$item;";
- $acsdata = "<td style=\"background-color: #F0F0F0\">";
+ $menuitems .= "$item;";
+ $acsdata = "<td style=\"background-color: #F0F0F0\">";
- foreach $item (@{ $acs{$key} }) {
+ foreach $item ( @{ $acs{$key} } ) {
- next if ($key eq $item);
+ next if ( $key eq $item );
- $checked = "checked";
+ $checked = "checked";
- if ($form->{login}) {
- $checked = ($excl{$key}{$item}) ? "" : "checked";
- }
+ if ( $form->{login} ) {
+ $checked = ( $excl{$key}{$item} ) ? "" : "checked";
+ }
- $acsitem = $form->escape("${key}--$item",1);
+ $acsitem = $form->escape( "${key}--$item", 1 );
- $acsdata .= qq|<br /><input name="$acsitem" class="checkbox" type="checkbox" value="1" $checked />&nbsp;$item|;
- $menuitems .= "$acsitem;";
- }
+ $acsdata .=
+qq|<br /><input name="$acsitem" class="checkbox" type="checkbox" value="1" $checked />&nbsp;$item|;
+ $menuitems .= "$acsitem;";
+ }
- $acsdata .= "
+ $acsdata .= "
</td>";
- print qq|
+ print qq|
<tr valign="top">$acsheading $acsdata
</tr>
|;
- }
+ }
- print qq|<input type="hidden" name="acs" value="$menuitems" />
+ print qq|<input type="hidden" name="acs" value="$menuitems" />
<tr>
<td colspan="2"><hr size="3" noshade /></td>
</tr>
@@ -695,193 +768,224 @@ sub form_header {
}
-
sub save {
- $form->{callback} = "admin.pl?action=list_users";
- # no driver checked
- $form->error(__FILE__.':'.__LINE__.': '.$locale->text('Database Driver not checked!')) unless $form->{dbdriver};
+ $form->{callback} = "admin.pl?action=list_users";
- # no spaces allowed in login name
- $form->{login} =~ s/ //g;
+ # no driver checked
+ $form->error( __FILE__ . ':' . __LINE__ . ': '
+ . $locale->text('Database Driver not checked!') )
+ unless $form->{dbdriver};
- $form->isblank("login", $locale->text('Login name missing!'));
+ # no spaces allowed in login name
+ $form->{login} =~ s/ //g;
- # check for duplicates
- if (!$form->{edit}) {
+ $form->isblank( "login", $locale->text('Login name missing!') );
- $temp = LedgerSMB::User->new($form->{login});
+ # check for duplicates
+ if ( !$form->{edit} ) {
- if ($temp->{login}) {
- $form->error(__FILE__.':'.__LINE__.': '.$locale->text('[_1] is already a member!', $form->{login}));
- }
- }
+ $temp = LedgerSMB::User->new( $form->{login} );
- # no spaces allowed in directories
- $form->{newtemplates} =~ s/( |\.\.|\*)//g;
+ if ( $temp->{login} ) {
+ $form->error( __FILE__ . ':' . __LINE__ . ': '
+ . $locale->text( '[_1] is already a member!', $form->{login} )
+ );
+ }
+ }
- if ($form->{newtemplates} ne "") {
- $form->{templates} = $form->{newtemplates};
- } else {
- $form->{templates} = ($form->{usetemplates}) ? $form->{usetemplates} : $form->{login};
- }
+ # no spaces allowed in directories
+ $form->{newtemplates} =~ s/( |\.\.|\*)//g;
- # is there a basedir
- if (! -d "${LedgerSMB::Sysconfig::templates}") {
- $form->error(__FILE__.':'.__LINE__.': '.$locale->text('Directory [_1] does not exist', ${LedgerSMB::Sysconfig::templates}));
- }
+ if ( $form->{newtemplates} ne "" ) {
+ $form->{templates} = $form->{newtemplates};
+ }
+ else {
+ $form->{templates} =
+ ( $form->{usetemplates} ) ? $form->{usetemplates} : $form->{login};
+ }
- # add base directory to $form->{templates}
- $form->{templates} = "${LedgerSMB::Sysconfig::templates}/$form->{templates}";
+ # is there a basedir
+ if ( !-d "${LedgerSMB::Sysconfig::templates}" ) {
+ $form->error(
+ __FILE__ . ':' . __LINE__ . ': '
+ . $locale->text(
+ 'Directory [_1] does not exist',
+ ${LedgerSMB::Sysconfig::templates}
+ )
+ );
+ }
- $myconfig = LedgerSMB::User->new("${LedgerSMB::Sysconfig::memberfile}", "$form->{login}");
+ # add base directory to $form->{templates}
+ $form->{templates} =
+ "${LedgerSMB::Sysconfig::templates}/$form->{templates}";
- # redo acs variable and delete all the acs codes
- @acs = split /;/, $form->{acs};
- $form->{acs} = "";
+ $myconfig = LedgerSMB::User->new( "${LedgerSMB::Sysconfig::memberfile}",
+ "$form->{login}" );
- foreach $item (@acs) {
+ # redo acs variable and delete all the acs codes
+ @acs = split /;/, $form->{acs};
+ $form->{acs} = "";
- $item = $form->escape($item,1);
+ foreach $item (@acs) {
- if (!$form->{$item}) {
- $form->{acs} .= $form->unescape($form->unescape("$item")).";";
- }
+ $item = $form->escape( $item, 1 );
- delete $form->{$item};
- }
+ if ( !$form->{$item} ) {
+ $form->{acs} .= $form->unescape( $form->unescape("$item") ) . ";";
+ }
- # check which database was filled in
+ delete $form->{$item};
+ }
- $form->{dbhost} = $form->{"$form->{dbdriver}_dbhost"};
- $form->{dbport} = $form->{"$form->{dbdriver}_dbport"};
- $form->{dbpasswd} = $form->{"$form->{dbdriver}_dbpasswd"};
- $form->{dbuser} = $form->{"$form->{dbdriver}_dbuser"};
- $form->{dbname} = $form->{"$form->{dbdriver}_dbname"};
- $form->isblank("dbname", $locale->text('Dataset missing!'));
- $form->isblank("dbuser", $locale->text('Database User missing!'));
+ # check which database was filled in
- foreach $item (keys %{$form}) {
- $myconfig->{$item} = $form->{$item};
- }
+ $form->{dbhost} = $form->{"$form->{dbdriver}_dbhost"};
+ $form->{dbport} = $form->{"$form->{dbdriver}_dbport"};
+ $form->{dbpasswd} = $form->{"$form->{dbdriver}_dbpasswd"};
+ $form->{dbuser} = $form->{"$form->{dbdriver}_dbuser"};
+ $form->{dbname} = $form->{"$form->{dbdriver}_dbname"};
+ $form->isblank( "dbname", $locale->text('Dataset missing!') );
+ $form->isblank( "dbuser", $locale->text('Database User missing!') );
- $myconfig->{password} = $form->{new_password};
- $myconfig->{timeout} = $form->{newtimeout};
+ foreach $item ( keys %{$form} ) {
+ $myconfig->{$item} = $form->{$item};
+ }
- delete $myconfig->{stylesheet};
+ $myconfig->{password} = $form->{new_password};
+ $myconfig->{timeout} = $form->{newtimeout};
- if ($form->{userstylesheet}) {
- $myconfig->{stylesheet} = $form->{userstylesheet};
- }
+ delete $myconfig->{stylesheet};
- $myconfig->{packpw} = 1;
+ if ( $form->{userstylesheet} ) {
+ $myconfig->{stylesheet} = $form->{userstylesheet};
+ }
- $myconfig->save_member($form);
- # create user template directory and copy master files
- if (! -d "$form->{templates}") {
+ $myconfig->{packpw} = 1;
- umask(002);
+ $myconfig->save_member($form);
- if (mkdir "$form->{templates}", oct("771")) {
+ # create user template directory and copy master files
+ if ( !-d "$form->{templates}" ) {
- umask(007);
+ umask(002);
- # copy templates to the directory
- opendir TEMPLATEDIR, "${LedgerSMB::Sysconfig::templates}/." or $form->error(__FILE__.':'.__LINE__.': '."$templates : $!");
- @templates = grep /$form->{mastertemplates}-/, readdir TEMPLATEDIR;
- closedir TEMPLATEDIR;
+ if ( mkdir "$form->{templates}", oct("771") ) {
- foreach $file (@templates) {
+ umask(007);
- open(TEMP, '<', "${LedgerSMB::Sysconfig::templates}/$file") or $form->error(__FILE__.':'.__LINE__.': '."$templates/$file : $!");
+ # copy templates to the directory
+ opendir TEMPLATEDIR, "${LedgerSMB::Sysconfig::templates}/."
+ or $form->error(
+ __FILE__ . ':' . __LINE__ . ': ' . "$templates : $!" );
+ @templates = grep /$form->{mastertemplates}-/, readdir TEMPLATEDIR;
+ closedir TEMPLATEDIR;
- $file =~ s/$form->{mastertemplates}-//;
- open(NEW, '>', "$form->{templates}/$file") or $form->error(__FILE__.':'.__LINE__.': '."$form->{templates}/$file : $!");
+ foreach $file (@templates) {
- while ($line = <TEMP>) {
- print NEW $line;
- }
+ open( TEMP, '<', "${LedgerSMB::Sysconfig::templates}/$file" )
+ or $form->error( __FILE__ . ':' . __LINE__ . ': '
+ . "$templates/$file : $!" );
- close(TEMP);
- close(NEW);
- }
+ $file =~ s/$form->{mastertemplates}-//;
+ open( NEW, '>', "$form->{templates}/$file" )
+ or $form->error( __FILE__ . ':' . __LINE__ . ': '
+ . "$form->{templates}/$file : $!" );
- } else {
- $form->error(__FILE__.':'.__LINE__.': '."$form->{templates} : $!");
- }
- }
+ while ( $line = <TEMP> ) {
+ print NEW $line;
+ }
- $form->redirect($locale->text('User saved!'));
-}
+ close(TEMP);
+ close(NEW);
+ }
+ }
+ else {
+ $form->error(
+ __FILE__ . ':' . __LINE__ . ': ' . "$form->{templates} : $!" );
+ }
+ }
+
+ $form->redirect( $locale->text('User saved!') );
+}
sub delete {
- $form->{callback} = "admin.pl?action=list_users";
+ $form->{callback} = "admin.pl?action=list_users";
- $form->{templates} = ($form->{templates}) ? "${LedgerSMB::Sysconfig::templates}/$form->{templates}" : "$templates/$form->{login}";
+ $form->{templates} =
+ ( $form->{templates} )
+ ? "${LedgerSMB::Sysconfig::templates}/$form->{templates}"
+ : "$templates/$form->{login}";
- # scan %user for $templatedir
- foreach $login (keys %user) {
- last if ($found = ($form->{templates} eq $user{$login}));
- }
+ # scan %user for $templatedir
+ foreach $login ( keys %user ) {
+ last if ( $found = ( $form->{templates} eq $user{$login} ) );
+ }
- # if found keep directory otherwise delete
- if (!$found) {
- # delete it if there is a template directory
- $dir = "$form->{templates}";
- if (-d "$dir") {
- unlink <$dir/*>;
- rmdir "$dir";
- }
- }
+ # if found keep directory otherwise delete
+ if ( !$found ) {
- my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
+ # delete it if there is a template directory
+ $dir = "$form->{templates}";
+ if ( -d "$dir" ) {
+ unlink <$dir/*>;
+ rmdir "$dir";
+ }
+ }
- #users_conf
- my $deleteUser = $dbh->prepare("DELETE FROM users_conf USING users WHERE users.username = ? and users.id = users_conf.id;");
- $deleteUser->execute($form->{login});
+ my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
- #and now users
- $deleteUser = $dbh->prepare("DELETE FROM users WHERE username = ?;");
- $deleteUser->execute($form->{login});
+ #users_conf
+ my $deleteUser =
+ $dbh->prepare(
+"DELETE FROM users_conf USING users WHERE users.username = ? and users.id = users_conf.id;"
+ );
+ $deleteUser->execute( $form->{login} );
- $form->redirect($locale->text('User deleted!'));
-}
+ #and now users
+ $deleteUser = $dbh->prepare("DELETE FROM users WHERE username = ?;");
+ $deleteUser->execute( $form->{login} );
+ $form->redirect( $locale->text('User deleted!') );
+}
sub login_name {
- my $login = shift;
- $login =~ s/\[\]//g;
- return ($login) ? $login : undef;
+ my $login = shift;
+ $login =~ s/\[\]//g;
+ return ($login) ? $login : undef;
}
-
sub change_admin_password {
- $form->{title} = qq|LedgerSMB |.$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Change Admin Password');
+ $form->{title} =
+ qq|LedgerSMB |
+ . $locale->text('Accounting') . " "
+ . $locale->text('Administration') . " / "
+ . $locale->text('Change Admin Password');
- $form->{login} = "admin";
- $form->header;
+ $form->{login} = "admin";
+ $form->header;
- print qq|
+ print qq|
<body class="admin">
<form method="post" action="$form->{script}">
<table>
<tr class="listheading">
- <th>|.$locale->text('Change Password').qq|</th>
+ <th>| . $locale->text('Change Password') . qq|</th>
</tr>
<tr size="5"></tr>
<tr>
<td>
<table width="100%">
<tr>
- <th align="right">|.$locale->text('Password').qq|</th>
+ <th align="right">| . $locale->text('Password') . qq|</th>
<td><input type="password" name="new_password" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Confirm').qq|</th>
+ <th align="right">| . $locale->text('Confirm') . qq|</th>
<td><input type="password" name="confirm_password" /></td>
</tr>
</table>
@@ -891,7 +995,9 @@ sub change_admin_password {
<br />
<hr size="3" noshade />
<input type="hidden" name="path" value="$form->{path}" />
- <p><button type="submit" class="submit" name="action" value="change_password">|.$locale->text('Change Password').qq|</button></p>
+ <p><button type="submit" class="submit" name="action" value="change_password">|
+ . $locale->text('Change Password')
+ . qq|</button></p>
</form>
</body>
</html>
@@ -899,103 +1005,112 @@ sub change_admin_password {
}
-
sub change_password {
- # Do we want to force a login after changing the password?
- $form->{callback} = "admin.pl?";
+ # Do we want to force a login after changing the password?
+ $form->{callback} = "admin.pl?";
- $form->error(__FILE__.':'.__LINE__.': '.$locale->text('Passwords do not match!')) if $form->{new_password} ne $form->{confirm_password};
+ $form->error( __FILE__ . ':' . __LINE__ . ': '
+ . $locale->text('Passwords do not match!') )
+ if $form->{new_password} ne $form->{confirm_password};
- # use the central database handle
- my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
+ # use the central database handle
+ my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
- my $updateAdminPassword = $dbh->prepare("UPDATE users_conf
+ my $updateAdminPassword = $dbh->prepare(
+ "UPDATE users_conf
SET password = md5(?)
- WHERE id = 1");
+ WHERE id = 1"
+ );
- $updateAdminPassword->execute($form->{new_password});
+ $updateAdminPassword->execute( $form->{new_password} );
- $form->{callback} = "$form->{script}?action=list_users&amp;path=$form->{path}";
- $form->redirect($locale->text('Password changed!'));
+ $form->{callback} =
+ "$form->{script}?action=list_users&amp;path=$form->{path}";
+ $form->redirect( $locale->text('Password changed!') );
}
sub check_password {
- $root = LedgerSMB::User->new('admin');
-
- if ($form->{password}) {
-
- $form->{callback} .= "&amp;password=$form->{password}" if $form->{callback};
-
- if ($root->{password} ne (Digest::MD5::md5_hex $form->{password}) ) {
- &adminlogin($locale->text('Access Denied!'));
- exit;
- }
- else{
- Session::session_create($root);
- }
- }
- else {
-
- $ENV{HTTP_COOKIE} =~ s/;\s*/;/g;
- @cookies = split /;/, $ENV{HTTP_COOKIE};
- foreach (@cookies) {
- ($name,$value) = split /=/, $_, 2;
- $cookie{$name} = $value;
- }
-
- if(!Session::session_check($cookie{"LedgerSMB"}, $root)){
- &adminlogin($locale->text('Session expired!'));
- exit;
- }
- }
+ $root = LedgerSMB::User->new('admin');
+
+ if ( $form->{password} ) {
+
+ $form->{callback} .= "&amp;password=$form->{password}"
+ if $form->{callback};
+
+ if ( $root->{password} ne ( Digest::MD5::md5_hex $form->{password} ) ) {
+ &adminlogin( $locale->text('Access Denied!') );
+ exit;
+ }
+ else {
+ Session::session_create($root);
+ }
+ }
+ else {
+
+ $ENV{HTTP_COOKIE} =~ s/;\s*/;/g;
+ @cookies = split /;/, $ENV{HTTP_COOKIE};
+ foreach (@cookies) {
+ ( $name, $value ) = split /=/, $_, 2;
+ $cookie{$name} = $value;
+ }
+
+ if ( !Session::session_check( $cookie{"LedgerSMB"}, $root ) ) {
+ &adminlogin( $locale->text('Session expired!') );
+ exit;
+ }
+ }
}
-
sub pg_database_administration {
- $form->{dbdriver} = 'Pg';
- &dbselect_source;
+ $form->{dbdriver} = 'Pg';
+ &dbselect_source;
}
-
sub pgpp_database_administration {
- $form->{dbdriver} = 'PgPP';
- &dbselect_source;
+ $form->{dbdriver} = 'PgPP';
+ &dbselect_source;
}
-
sub dbdriver_defaults {
- # load some defaults for the selected driver
- %driverdefaults = ( 'Pg' => { dbport => '5432',
- dbuser => '',
- dbdefault => 'template1',
- dbhost => 'localhost',
- connectstring => $locale->text('Connect to')
- } );
+ # load some defaults for the selected driver
+ %driverdefaults = (
+ 'Pg' => {
+ dbport => '5432',
+ dbuser => '',
+ dbdefault => 'template1',
+ dbhost => 'localhost',
+ connectstring => $locale->text('Connect to')
+ }
+ );
- $driverdefaults{PgPP} = $driverdefaults{Pg};
+ $driverdefaults{PgPP} = $driverdefaults{Pg};
- for (keys %{ $driverdefaults{Pg} }) { $form->{$_} = $driverdefaults{$form->{dbdriver}}{$_} }
+ for ( keys %{ $driverdefaults{Pg} } ) {
+ $form->{$_} = $driverdefaults{ $form->{dbdriver} }{$_};
+ }
}
-
sub dbselect_source {
- &dbdriver_defaults;
+ &dbdriver_defaults;
- $form->{title} = "LedgerSMB ".$locale->text('Accounting')." / ".$locale->text('Database Administration');
+ $form->{title} =
+ "LedgerSMB "
+ . $locale->text('Accounting') . " / "
+ . $locale->text('Database Administration');
- $form->{login} = "admin";
- $form->header;
+ $form->{login} = "admin";
+ $form->header;
- #an insane amount of table nesting here, this should be cleaned up.
- print qq|
+ #an insane amount of table nesting here, this should be cleaned up.
+ print qq|
<body class="admin">
<center>
<h2>$form->{title}</h2>
@@ -1005,21 +1120,21 @@ sub dbselect_source {
<td>
<table>
<tr class="listheading">
- <th colspan="4">|.$locale->text('Database').qq|</th>
+ <th colspan="4">| . $locale->text('Database') . qq|</th>
</tr>
<tr>
<td>
<table>
<tr>
- <th align="right">|.$locale->text('Host').qq|</th>
+ <th align="right">| . $locale->text('Host') . qq|</th>
<td><input name="dbhost" size="25" value="$form->{dbhost}" /></td>
- <th align="right">|.$locale->text('Port').qq|</th>
+ <th align="right">| . $locale->text('Port') . qq|</th>
<td><input name="dbport" size="5" value="$form->{dbport}" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('User').qq|</th>
+ <th align="right">| . $locale->text('User') . qq|</th>
<td><input name="dbuser" size="10" value="$form->{dbuser}" /></td>
- <th align="right">|.$locale->text('Password').qq|</th>
+ <th align="right">| . $locale->text('Password') . qq|</th>
<td><input type="password" name="dbpasswd" size="10" /></td>
</tr>
<tr>
@@ -1027,9 +1142,9 @@ sub dbselect_source {
<td colspan="3"><input name="dbdefault" size="10" value="$form->{dbdefault}" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text("Superuser").qq|</th>
+ <th align="right">| . $locale->text("Superuser") . qq|</th>
<td><input name="dbsuperuser" size="10" value="$form->{dbsuperuser}" /></td>
- <th align="right">|.$locale->text('Password').qq|</th>
+ <th align="right">| . $locale->text('Password') . qq|</th>
<td><input type="password" name="dbsuperpasswd" size="10" /></td>
</tr>
</table>
@@ -1043,56 +1158,65 @@ sub dbselect_source {
<input name="callback" type="hidden" value="$form->{script}?action=list_users&amp;path=$form->{path}" />
<input type="hidden" name="path" value="$form->{path}" />
<br />
- <button type="submit" class="submit" name="action" value="create_dataset">|.$locale->text('Create Company').qq|</button>
- <button type="submit" class="submit" name="action" value="delete_dataset">|.$locale->text('Delete Company').qq|</button>
+ <button type="submit" class="submit" name="action" value="create_dataset">|
+ . $locale->text('Create Company')
+ . qq|</button>
+ <button type="submit" class="submit" name="action" value="delete_dataset">|
+ . $locale->text('Delete Company')
+ . qq|</button>
</form>
- <p>|.$locale->text('This is a preliminary check for existing sources. Nothing will be created or deleted at this stage!')
- .qq|</p>
+ <p>|
+ . $locale->text(
+'This is a preliminary check for existing sources. Nothing will be created or deleted at this stage!'
+ )
+ . qq|</p>
</center>
</body>
</html>
|;
}
-
sub continue {
- &{ $form->{nextsub} };
+ &{ $form->{nextsub} };
}
-
sub dbupdate {
- $form->{callback} = "admin.pl?action=list_users";
+ $form->{callback} = "admin.pl?action=list_users";
- LedgerSMB::User->dbupdate(\%$form);
- $form->redirect($locale->text('Dataset updated!'));
+ LedgerSMB::User->dbupdate( \%$form );
+ $form->redirect( $locale->text('Dataset updated!') );
}
-
sub create_dataset {
- @dbsources = sort LedgerSMB::User->dbsources(\%$form);
+ @dbsources = sort LedgerSMB::User->dbsources( \%$form );
- opendir SQLDIR, "sql/." or $form->error(__FILE__.':'.__LINE__.': '.$!);
+ opendir SQLDIR, "sql/."
+ or $form->error( __FILE__ . ':' . __LINE__ . ': ' . $! );
- foreach $item (sort grep /-chart\.sql/, readdir SQLDIR) {
- next if ($item eq 'Default-chart.sql');
- $item =~ s/-chart\.sql//;
- push @charts, qq|<input name="chart" class="radio" type="radio" value="$item" />$item|;
- }
+ foreach $item ( sort grep /-chart\.sql/, readdir SQLDIR ) {
+ next if ( $item eq 'Default-chart.sql' );
+ $item =~ s/-chart\.sql//;
+ push @charts,
+qq|<input name="chart" class="radio" type="radio" value="$item" />$item|;
+ }
- closedir SQLDIR;
+ closedir SQLDIR;
- # add Default at beginning
- unshift @charts, qq|<input name="chart" class="radio" type="radio" value="Default" checked />Default|;
+ # add Default at beginning
+ unshift @charts,
+qq|<input name="chart" class="radio" type="radio" value="Default" checked />Default|;
- $form->{title} = "LedgerSMB ".$locale->text('Accounting')
- ." ".$locale->text('Database Administration')
- ." / ".$locale->text('Create Dataset');
- $form->{login} = "admin";
- $form->header;
+ $form->{title} =
+ "LedgerSMB "
+ . $locale->text('Accounting') . " "
+ . $locale->text('Database Administration') . " / "
+ . $locale->text('Create Dataset');
+ $form->{login} = "admin";
+ $form->header;
- print qq|
+ print qq|
<body class="admin">
<center>
<h2>$form->{title}</h2>
@@ -1102,36 +1226,42 @@ sub create_dataset {
<th colspan="2">&nbsp;</th>
</tr>
<tr>
- <th align="right" nowrap="nowrap">|.$locale->text('Existing Datasets').qq|</th>
+ <th align="right" nowrap="nowrap">|
+ . $locale->text('Existing Datasets')
+ . qq|</th>
<td>
|;
- for (@dbsources) { print "[&nbsp;$_&nbsp;] " }
+ for (@dbsources) { print "[&nbsp;$_&nbsp;] " }
- print qq|
+ print qq|
</td>
</tr>
<tr>
- <th align="right" nowrap="nowrap">|.$locale->text('Create Dataset').qq|</th>
+ <th align="right" nowrap="nowrap">|
+ . $locale->text('Create Dataset')
+ . qq|</th>
<td><input name="db" /></td>
</tr>
<tr>
- <th align="right" nowrap="nowrap">|.$locale->text('Create Chart of Accounts').qq|</th>
+ <th align="right" nowrap="nowrap">|
+ . $locale->text('Create Chart of Accounts')
+ . qq|</th>
<td>
<table>
|;
- while (@charts) {
- print qq| <tr>|;
+ while (@charts) {
+ print qq| <tr>|;
- for (0 .. 2) { print "<td>$charts[$_]</td>\n" }
+ for ( 0 .. 2 ) { print "<td>$charts[$_]</td>\n" }
- print qq| </tr>|;
+ print qq| </tr>|;
- splice @charts, 0, 3;
- }
+ splice @charts, 0, 3;
+ }
- print qq| </table>
+ print qq| </table>
</td>
</tr>
<tr>
@@ -1142,13 +1272,17 @@ sub create_dataset {
</table>
|;
- $form->hide_form(qw(dbdriver dbsuperuser dbsuperpasswd dbuser dbhost dbport dbpasswd dbdefault path));
+ $form->hide_form(
+ qw(dbdriver dbsuperuser dbsuperpasswd dbuser dbhost dbport dbpasswd dbdefault path)
+ );
- print qq|
+ print qq|
<input name="callback" type="hidden" value="$form->{script}?action=list_users&amp;path=$form->{path}" />
<input type="hidden" name="nextsub" value="dbcreate" />
<br />
- <button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+ <button type="submit" class="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
</body>
</html>
@@ -1156,30 +1290,32 @@ sub create_dataset {
}
-
sub dbcreate {
- $form->isblank("db", $locale->text('Dataset missing!'));
+ $form->isblank( "db", $locale->text('Dataset missing!') );
- LedgerSMB::User->dbcreate(\%$form);
+ LedgerSMB::User->dbcreate( \%$form );
- $form->{title} = "LedgerSMB ".$locale->text('Accounting')
- ." ".$locale->text('Database Administration')
- ." / ".$locale->text('Create Dataset');
+ $form->{title} =
+ "LedgerSMB "
+ . $locale->text('Accounting') . " "
+ . $locale->text('Database Administration') . " / "
+ . $locale->text('Create Dataset');
- $form->{login} = "admin";
- $form->header;
+ $form->{login} = "admin";
+ $form->header;
- print qq|
+ print qq|
<body class="admin">
<center>
<h2>$form->{title}</h2>
<form method="post" action="$form->{script}">|
- .$locale->text('Dataset [_1] successfully created!', $form->{db})
- .qq|
+ . $locale->text( 'Dataset [_1] successfully created!', $form->{db} ) . qq|
<input type="hidden" name="path" value="$form->{path}" />
<input type="hidden" name="nextsub" value="list_users" />
- <p><button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button></p>
+ <p><button type="submit" class="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button></p>
</form>
</center>
</body>
@@ -1187,27 +1323,31 @@ sub dbcreate {
|;
}
-
sub delete_dataset {
- if (@dbsources = LedgerSMB::User->dbsources_unused(\%$form)) {
+ if ( @dbsources = LedgerSMB::User->dbsources_unused( \%$form ) ) {
- foreach $item (sort @dbsources) {
- $dbsources .= qq|<input name="db" class="radio" type="radio" value="$item" />&nbsp;$item |;
- }
+ foreach $item ( sort @dbsources ) {
+ $dbsources .=
+qq|<input name="db" class="radio" type="radio" value="$item" />&nbsp;$item |;
+ }
- } else {
- $form->error(__FILE__.':'.__LINE__.': '.$locale->text('Nothing to delete!'));
- }
+ }
+ else {
+ $form->error( __FILE__ . ':' . __LINE__ . ': '
+ . $locale->text('Nothing to delete!') );
+ }
- $form->{title} = "LedgerSMB ".$locale->text('Accounting')
- ." ".$locale->text('Database Administration')
- ." / ".$locale->text('Delete Dataset');
+ $form->{title} =
+ "LedgerSMB "
+ . $locale->text('Accounting') . " "
+ . $locale->text('Database Administration') . " / "
+ . $locale->text('Delete Dataset');
- $form->{login} = "admin";
- $form->header;
+ $form->{login} = "admin";
+ $form->header;
- print qq|
+ print qq|
<body class="admin">
<h2>$form->{title}</h2>
<form method="post" action="$form->{script}" />
@@ -1222,7 +1362,10 @@ sub delete_dataset {
<input type="hidden" name="nextsub" value="dbdelete" />
<table width="100%">
<tr class="listheading">
- <th>|.$locale->text('The following Datasets are not in use and can be deleted').qq|</th>
+ <th>|
+ . $locale->text(
+ 'The following Datasets are not in use and can be deleted')
+ . qq|</th>
</tr>
<tr>
<td>
@@ -1233,7 +1376,9 @@ sub delete_dataset {
<td>
<hr size="3" noshade />
<br />
- <button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+ <button type="submit" class="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</td>
</tr>
</table>
@@ -1244,53 +1389,56 @@ sub delete_dataset {
}
-
sub dbdelete {
- if (!$form->{db}) {
- $form->error(__FILE__.':'.__LINE__.': '.$locale->text('No Dataset selected!'));
- }
+ if ( !$form->{db} ) {
+ $form->error( __FILE__ . ':' . __LINE__ . ': '
+ . $locale->text('No Dataset selected!') );
+ }
- LedgerSMB::User->dbdelete(\%$form);
+ LedgerSMB::User->dbdelete( \%$form );
- $form->{title} = "LedgerSMB ".$locale->text('Accounting')
- ." ".$locale->text('Database Administration')
- ." / ".$locale->text('Delete Dataset');
+ $form->{title} =
+ "LedgerSMB "
+ . $locale->text('Accounting') . " "
+ . $locale->text('Database Administration') . " / "
+ . $locale->text('Delete Dataset');
- $form->{login} = "admin";
- $form->header;
+ $form->{login} = "admin";
+ $form->header;
- print qq|
+ print qq|
<body class="admin">
<center>
<h2>$form->{title}</h2>
- $form->{db} |.$locale->text('successfully deleted!')
- .qq|
+ $form->{db} | . $locale->text('successfully deleted!') . qq|
<form method="post" action="$form->{script}" />
<input type="hidden" name="path" value="$form->{path}" />
<input type="hidden" name="nextsub" value="list_users" />
- <p><button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button></p>
+ <p><button type="submit" class="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button></p>
</form>
</body>
</html>
|;
}
-
sub unlock_system {
- # This needs to be done with a db tool
- # unlink "${LedgerSMB::Sysconfig::userspath}/nologin";
- $form->{callback} = "$form->{script}?action=list_users&amp;path=$form->{path}";
- $form->redirect($locale->text('Lockfile removed!'));
+ # This needs to be done with a db tool
+ # unlink "${LedgerSMB::Sysconfig::userspath}/nologin";
+ $form->{callback} =
+ "$form->{script}?action=list_users&amp;path=$form->{path}";
+ $form->redirect( $locale->text('Lockfile removed!') );
}
-
sub lock_system {
- # This needs to be done with a db tool
- #open(FH, '>', "${LedgerSMB::Sysconfig::userspath}/nologin") or $form->error($locale->text('Cannot create Lock!'));
- #close(FH);
- $form->{callback} = "$form->{script}?action=list_users&amp;path=$form->{path}";
- $form->redirect($locale->text('Lockfile created!'));
+# This needs to be done with a db tool
+#open(FH, '>', "${LedgerSMB::Sysconfig::userspath}/nologin") or $form->error($locale->text('Cannot create Lock!'));
+#close(FH);
+ $form->{callback} =
+ "$form->{script}?action=list_users&amp;path=$form->{path}";
+ $form->redirect( $locale->text('Lockfile created!') );
}
diff --git a/bin/am.pl b/bin/am.pl
index 4dc4bab6..1764384d 100644
--- a/bin/am.pl
+++ b/bin/am.pl
@@ -1,9 +1,9 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
#
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -32,7 +32,6 @@
#
#======================================================================
-
use LedgerSMB::AM;
use LedgerSMB::CA;
use LedgerSMB::Form;
@@ -40,76 +39,72 @@ use LedgerSMB::User;
use LedgerSMB::RP;
use LedgerSMB::GL;
-
1;
+
# end of main
+sub add { &{"add_$form->{type}"} }
+sub edit { &{"edit_$form->{type}"} }
+sub save { &{"save_$form->{type}"} }
+sub delete { &{"delete_$form->{type}"} }
+sub save_as_new {
-sub add { &{ "add_$form->{type}" } };
-sub edit { &{ "edit_$form->{type}" } };
-sub save { &{ "save_$form->{type}" } };
-sub delete { &{ "delete_$form->{type}" } };
+ delete $form->{id};
+ &save;
-sub save_as_new {
+}
+
+sub add_account {
- delete $form->{id};
+ $form->{title} = "Add";
+ $form->{charttype} = "A";
- &save;
+ $form->{callback} =
+"$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
+
+ &account_header;
+ &form_footer;
}
+sub edit_account {
-sub add_account {
-
- $form->{title} = "Add";
- $form->{charttype} = "A";
-
- $form->{callback} = "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
+ $form->{title} = "Edit";
- &account_header;
- &form_footer;
-
-}
+ $form->{accno} =~ s/\\'/'/g;
+ $form->{accno} =~ s/\\\\/\\/g;
+ AM->get_account( \%myconfig, \%$form );
-sub edit_account {
-
- $form->{title} = "Edit";
-
- $form->{accno} =~ s/\\'/'/g;
- $form->{accno} =~ s/\\\\/\\/g;
-
- AM->get_account(\%myconfig, \%$form);
-
- foreach my $item (split(/:/, $form->{link})) {
- $form->{$item} = "checked";
- }
+ foreach my $item ( split( /:/, $form->{link} ) ) {
+ $form->{$item} = "checked";
+ }
- &account_header;
- &form_footer;
+ &account_header;
+ &form_footer;
}
-
sub account_header {
- $form->{title} = $locale->text("$form->{title} Account");
-
- $checked{$form->{charttype}} = "checked";
- $checked{contra} = "checked" if $form->{contra};
- $checked{"$form->{category}_"} = "checked";
-
- for (qw(accno description)) { $form->{$_} = $form->quote($form->{$_}) }
+ $form->{title} = $locale->text("$form->{title} Account");
+
+ $checked{ $form->{charttype} } = "checked";
+ $checked{contra} = "checked" if $form->{contra};
+ $checked{"$form->{category}_"} = "checked";
-# this is for our parser only!
-# type=submit $locale->text('Add Account')
-# type=submit $locale->text('Edit Account')
+ for (qw(accno description)) { $form->{$_} = $form->quote( $form->{$_} ) }
- $form->header;
+ # this is for our parser only!
+ # type=submit $locale->text('Add Account')
+ # type=submit $locale->text('Edit Account')
- print qq|
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -132,86 +127,122 @@ sub account_header {
<td>
<table>
<tr>
- <th align="right">|.$locale->text('Account Number').qq|</th>
+ <th align="right">| . $locale->text('Account Number') . qq|</th>
<td><input name=accno size=20 value="$form->{accno}"></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Description').qq|</th>
+ <th align="right">| . $locale->text('Description') . qq|</th>
<td><input name=description size=40 value="$form->{description}"></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Account Type').qq|</th>
+ <th align="right">| . $locale->text('Account Type') . qq|</th>
<td>
<table>
<tr valign=top>
- <td><input name=category type=radio class=radio value=A $checked{A_}>&nbsp;|.$locale->text('Asset').qq|\n<br>
- <input name=category type=radio class=radio value=L $checked{L_}>&nbsp;|.$locale->text('Liability').qq|\n<br>
- <input name=category type=radio class=radio value=Q $checked{Q_}>&nbsp;|.$locale->text('Equity').qq|\n<br>
- <input name=category type=radio class=radio value=I $checked{I_}>&nbsp;|.$locale->text('Income').qq|\n<br>
- <input name=category type=radio class=radio value=E $checked{E_}>&nbsp;|.$locale->text('Expense')
- .qq|</td>
+ <td><input name=category type=radio class=radio value=A $checked{A_}>&nbsp;|
+ . $locale->text('Asset')
+ . qq|\n<br>
+ <input name=category type=radio class=radio value=L $checked{L_}>&nbsp;|
+ . $locale->text('Liability')
+ . qq|\n<br>
+ <input name=category type=radio class=radio value=Q $checked{Q_}>&nbsp;|
+ . $locale->text('Equity')
+ . qq|\n<br>
+ <input name=category type=radio class=radio value=I $checked{I_}>&nbsp;|
+ . $locale->text('Income')
+ . qq|\n<br>
+ <input name=category type=radio class=radio value=E $checked{E_}>&nbsp;|
+ . $locale->text('Expense')
+ . qq|</td>
<td>
- <input name=contra class=checkbox type=checkbox value=1 $checked{contra}>&nbsp;|.$locale->text('Contra').qq|
+ <input name=contra class=checkbox type=checkbox value=1 $checked{contra}>&nbsp;|
+ . $locale->text('Contra') . qq|
</td>
<td>
- <input name=charttype type=radio class=radio value="H" $checked{H}>&nbsp;|.$locale->text('Heading').qq|<br>
- <input name=charttype type=radio class=radio value="A" $checked{A}>&nbsp;|.$locale->text('Account')
- .qq|</td>
+ <input name=charttype type=radio class=radio value="H" $checked{H}>&nbsp;|
+ . $locale->text('Heading') . qq|<br>
+ <input name=charttype type=radio class=radio value="A" $checked{A}>&nbsp;|
+ . $locale->text('Account')
+ . qq|</td>
</tr>
</table>
</td>
</tr>
|;
-
-if ($form->{charttype} eq "A") {
- print qq|
+ if ( $form->{charttype} eq "A" ) {
+ print qq|
<tr>
<td colspan=2>
<table>
<tr>
- <th align=left>|.$locale->text('Is this a summary account to record').qq|</th>
+ <th align=left>|
+ . $locale->text('Is this a summary account to record')
+ . qq|</th>
<td>
- <input name=AR class=checkbox type=checkbox value=AR $form->{AR}>&nbsp;|.$locale->text('AR')
- .qq|&nbsp;<input name=AP class=checkbox type=checkbox value=AP $form->{AP}>&nbsp;|.$locale->text('AP')
- .qq|&nbsp;<input name=IC class=checkbox type=checkbox value=IC $form->{IC}>&nbsp;|.$locale->text('Inventory')
- .qq|</td>
+ <input name=AR class=checkbox type=checkbox value=AR $form->{AR}>&nbsp;|
+ . $locale->text('AR')
+ . qq|&nbsp;<input name=AP class=checkbox type=checkbox value=AP $form->{AP}>&nbsp;|
+ . $locale->text('AP')
+ . qq|&nbsp;<input name=IC class=checkbox type=checkbox value=IC $form->{IC}>&nbsp;|
+ . $locale->text('Inventory')
+ . qq|</td>
</tr>
</table>
</td>
</tr>
<tr>
- <th colspan=2>|.$locale->text('Include in drop-down menus').qq|</th>
+ <th colspan=2>| . $locale->text('Include in drop-down menus') . qq|</th>
</tr>
<tr valign=top>
<td colspan=2>
<table width=100%>
<tr>
- <th align=left>|.$locale->text('Receivables').qq|</th>
- <th align=left>|.$locale->text('Payables').qq|</th>
- <th align=left>|.$locale->text('Tracking Items').qq|</th>
- <th align=left>|.$locale->text('Non-tracking Items').qq|</th>
+ <th align=left>| . $locale->text('Receivables') . qq|</th>
+ <th align=left>| . $locale->text('Payables') . qq|</th>
+ <th align=left>| . $locale->text('Tracking Items') . qq|</th>
+ <th align=left>| . $locale->text('Non-tracking Items') . qq|</th>
</tr>
<tr>
<td>
- <input name=AR_amount class=checkbox type=checkbox value=AR_amount $form->{AR_amount}>&nbsp;|.$locale->text('Income').qq|\n<br>
- <input name=AR_paid class=checkbox type=checkbox value=AR_paid $form->{AR_paid}>&nbsp;|.$locale->text('Payment').qq|\n<br>
- <input name=AR_tax class=checkbox type=checkbox value=AR_tax $form->{AR_tax}>&nbsp;|.$locale->text('Tax') .qq|
+ <input name=AR_amount class=checkbox type=checkbox value=AR_amount $form->{AR_amount}>&nbsp;|
+ . $locale->text('Income')
+ . qq|\n<br>
+ <input name=AR_paid class=checkbox type=checkbox value=AR_paid $form->{AR_paid}>&nbsp;|
+ . $locale->text('Payment')
+ . qq|\n<br>
+ <input name=AR_tax class=checkbox type=checkbox value=AR_tax $form->{AR_tax}>&nbsp;|
+ . $locale->text('Tax') . qq|
</td>
<td>
- <input name=AP_amount class=checkbox type=checkbox value=AP_amount $form->{AP_amount}>&nbsp;|.$locale->text('Expense/Asset').qq|\n<br>
- <input name=AP_paid class=checkbox type=checkbox value=AP_paid $form->{AP_paid}>&nbsp;|.$locale->text('Payment').qq|\n<br>
- <input name=AP_tax class=checkbox type=checkbox value=AP_tax $form->{AP_tax}>&nbsp;|.$locale->text('Tax') .qq|
+ <input name=AP_amount class=checkbox type=checkbox value=AP_amount $form->{AP_amount}>&nbsp;|
+ . $locale->text('Expense/Asset')
+ . qq|\n<br>
+ <input name=AP_paid class=checkbox type=checkbox value=AP_paid $form->{AP_paid}>&nbsp;|
+ . $locale->text('Payment')
+ . qq|\n<br>
+ <input name=AP_tax class=checkbox type=checkbox value=AP_tax $form->{AP_tax}>&nbsp;|
+ . $locale->text('Tax') . qq|
</td>
<td>
- <input name=IC_sale class=checkbox type=checkbox value=IC_sale $form->{IC_sale}>&nbsp;|.$locale->text('Income').qq|\n<br>
- <input name=IC_cogs class=checkbox type=checkbox value=IC_cogs $form->{IC_cogs}>&nbsp;|.$locale->text('COGS').qq|\n<br>
- <input name=IC_taxpart class=checkbox type=checkbox value=IC_taxpart $form->{IC_taxpart}>&nbsp;|.$locale->text('Tax') .qq|
+ <input name=IC_sale class=checkbox type=checkbox value=IC_sale $form->{IC_sale}>&nbsp;|
+ . $locale->text('Income')
+ . qq|\n<br>
+ <input name=IC_cogs class=checkbox type=checkbox value=IC_cogs $form->{IC_cogs}>&nbsp;|
+ . $locale->text('COGS')
+ . qq|\n<br>
+ <input name=IC_taxpart class=checkbox type=checkbox value=IC_taxpart $form->{IC_taxpart}>&nbsp;|
+ . $locale->text('Tax') . qq|
</td>
<td>
- <input name=IC_income class=checkbox type=checkbox value=IC_income $form->{IC_income}>&nbsp;|.$locale->text('Income').qq|\n<br>
- <input name=IC_expense class=checkbox type=checkbox value=IC_expense $form->{IC_expense}>&nbsp;|.$locale->text('Expense').qq|\n<br>
- <input name=IC_taxservice class=checkbox type=checkbox value=IC_taxservice $form->{IC_taxservice}>&nbsp;|.$locale->text('Tax') .qq|
+ <input name=IC_income class=checkbox type=checkbox value=IC_income $form->{IC_income}>&nbsp;|
+ . $locale->text('Income')
+ . qq|\n<br>
+ <input name=IC_expense class=checkbox type=checkbox value=IC_expense $form->{IC_expense}>&nbsp;|
+ . $locale->text('Expense')
+ . qq|\n<br>
+ <input name=IC_taxservice class=checkbox type=checkbox value=IC_taxservice $form->{IC_taxservice}>&nbsp;|
+ . $locale->text('Tax') . qq|
</td>
</tr>
</table>
@@ -220,11 +251,11 @@ if ($form->{charttype} eq "A") {
<tr>
</tr>
|;
-}
+ }
-print qq|
+ print qq|
<tr>
- <th align="right">|.$locale->text('GIFI').qq|</th>
+ <th align="right">| . $locale->text('GIFI') . qq|</th>
<td><input name=gifi_accno size=9 value="$form->{gifi_accno}"></td>
</tr>
</table>
@@ -238,36 +269,42 @@ print qq|
}
-
sub form_footer {
- $form->hide_form(qw(callback path login sessionid));
+ $form->hide_form(qw(callback path login sessionid));
-# type=submit $locale->text('Save')
-# type=submit $locale->text('Save as new')
-# type=submit $locale->text('Delete')
+ # type=submit $locale->text('Save')
+ # type=submit $locale->text('Save as new')
+ # type=submit $locale->text('Delete')
- %button = ();
-
- if ($form->{id}) {
- $button{'save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
- $button{'save_as_new'} = { ndx => 7, key => 'N', value => $locale->text('Save as new') };
-
- if ($form->{orphaned}) {
- $button{'delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') };
+ %button = ();
+
+ if ( $form->{id} ) {
+ $button{'save'} =
+ { ndx => 3, key => 'S', value => $locale->text('Save') };
+ $button{'save_as_new'} =
+ { ndx => 7, key => 'N', value => $locale->text('Save as new') };
+
+ if ( $form->{orphaned} ) {
+ $button{'delete'} =
+ { ndx => 16, key => 'D', value => $locale->text('Delete') };
+ }
+ }
+ else {
+ $button{'save'} =
+ { ndx => 3, key => 'S', value => $locale->text('Save') };
}
- } else {
- $button{'save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
- }
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
+ for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
+ $form->print_button( \%button, $_ );
+ }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
</form>
</body>
@@ -276,59 +313,80 @@ sub form_footer {
}
-
sub save_account {
- $form->isblank("accno", $locale->text('Account Number missing!'));
- $form->isblank("category", $locale->text('Account Type missing!'));
-
- # check for conflicting accounts
- if ($form->{AR} || $form->{AP} || $form->{IC}) {
- $a = "";
- for (qw(AR AP IC)) { $a .= $form->{$_} }
- $form->error($locale->text('Cannot set account for more than one of AR, AP or IC')) if length $a > 2;
+ $form->isblank( "accno", $locale->text('Account Number missing!') );
+ $form->isblank( "category", $locale->text('Account Type missing!') );
+
+ # check for conflicting accounts
+ if ( $form->{AR} || $form->{AP} || $form->{IC} ) {
+ $a = "";
+ for (qw(AR AP IC)) { $a .= $form->{$_} }
+ $form->error(
+ $locale->text(
+ 'Cannot set account for more than one of AR, AP or IC')
+ ) if length $a > 2;
+
+ for (
+ qw(AR_amount AR_tax AR_paid AP_amount AP_tax AP_paid IC_taxpart IC_taxservice IC_sale IC_cogs IC_income IC_expense)
+ )
+ {
+ $form->error(
+ "$form->{AR}$form->{AP}$form->{IC} "
+ . $locale->text(
+ 'account cannot be set to any other type of account')
+ ) if $form->{$_};
+ }
+ }
- for (qw(AR_amount AR_tax AR_paid AP_amount AP_tax AP_paid IC_taxpart IC_taxservice IC_sale IC_cogs IC_income IC_expense)) { $form->error("$form->{AR}$form->{AP}$form->{IC} ". $locale->text('account cannot be set to any other type of account')) if $form->{$_} }
- }
+ foreach $item ( "AR", "AP" ) {
+ $i = 0;
+ for ( "${item}_amount", "${item}_paid", "${item}_tax" ) {
+ $i++ if $form->{$_};
+ }
+ $form->error(
+ $locale->text( 'Cannot set multiple options for [_1]', $item ) )
+ if $i > 1;
+ }
- foreach $item ("AR", "AP") {
- $i = 0;
- for ("${item}_amount", "${item}_paid", "${item}_tax") { $i++ if $form->{$_} }
- $form->error($locale->text('Cannot set multiple options for [_1]', $item)) if $i > 1;
- }
-
- if (AM->save_account(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Account saved!'));
- } else {
- $form->error($locale->text('Cannot save account!'));
- }
+ if ( AM->save_account( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Account saved!') );
+ }
+ else {
+ $form->error( $locale->text('Cannot save account!') );
+ }
}
-
sub list_account {
- CA->all_accounts(\%myconfig, \%$form);
+ CA->all_accounts( \%myconfig, \%$form );
- $form->{title} = $locale->text('Chart of Accounts');
-
- # construct callback
- $callback = "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+ $form->{title} = $locale->text('Chart of Accounts');
- @column_index = qw(accno gifi_accno description debit credit link);
+ # construct callback
+ $callback =
+"$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- $column_header{accno} = qq|<th class=listtop>|.$locale->text('Account').qq|</a></th>|;
- $column_header{gifi_accno} = qq|<th class=listtop>|.$locale->text('GIFI').qq|</a></th>|;
- $column_header{description} = qq|<th class=listtop>|.$locale->text('Description').qq|</a></th>|;
- $column_header{debit} = qq|<th class=listtop>|.$locale->text('Debit').qq|</a></th>|;
- $column_header{credit} = qq|<th class=listtop>|.$locale->text('Credit').qq|</a></th>|;
- $column_header{link} = qq|<th class=listtop>|.$locale->text('Link').qq|</a></th>|;
+ @column_index = qw(accno gifi_accno description debit credit link);
+ $column_header{accno} =
+ qq|<th class=listtop>| . $locale->text('Account') . qq|</a></th>|;
+ $column_header{gifi_accno} =
+ qq|<th class=listtop>| . $locale->text('GIFI') . qq|</a></th>|;
+ $column_header{description} =
+ qq|<th class=listtop>| . $locale->text('Description') . qq|</a></th>|;
+ $column_header{debit} =
+ qq|<th class=listtop>| . $locale->text('Debit') . qq|</a></th>|;
+ $column_header{credit} =
+ qq|<th class=listtop>| . $locale->text('Credit') . qq|</a></th>|;
+ $column_header{link} =
+ qq|<th class=listtop>| . $locale->text('Link') . qq|</a></th>|;
- $form->header;
- $colspan = $#column_index + 1;
+ $form->header;
+ $colspan = $#column_index + 1;
- print qq|
+ print qq|
<body>
<table width=100%>
@@ -339,60 +397,69 @@ sub list_account {
<tr class="listheading">
|;
- for (@column_index) { print "$column_header{$_}\n" }
-
- print qq|
+ for (@column_index) { print "$column_header{$_}\n" }
+
+ print qq|
</tr>
|;
- # escape callback
- $callback = $form->escape($callback);
-
- foreach $ca (@{ $form->{CA} }) {
-
- $ca->{debit} = "&nbsp;";
- $ca->{credit} = "&nbsp;";
+ # escape callback
+ $callback = $form->escape($callback);
- if ($ca->{amount} > 0) {
- $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2, "&nbsp;");
- }
- if ($ca->{amount} < 0) {
- $ca->{debit} = $form->format_amount(\%myconfig, -$ca->{amount}, 2, "&nbsp;");
- }
+ foreach $ca ( @{ $form->{CA} } ) {
+
+ $ca->{debit} = "&nbsp;";
+ $ca->{credit} = "&nbsp;";
+
+ if ( $ca->{amount} > 0 ) {
+ $ca->{credit} =
+ $form->format_amount( \%myconfig, $ca->{amount}, 2, "&nbsp;" );
+ }
+ if ( $ca->{amount} < 0 ) {
+ $ca->{debit} =
+ $form->format_amount( \%myconfig, -$ca->{amount}, 2, "&nbsp;" );
+ }
- $ca->{link} =~ s/:/<br>/og;
+ $ca->{link} =~ s/:/<br>/og;
- $gifi_accno = $form->escape($ca->{gifi_accno});
-
- if ($ca->{charttype} eq "H") {
- print qq|<tr class="listheading">|;
+ $gifi_accno = $form->escape( $ca->{gifi_accno} );
- $column_data{accno} = qq|<th><a class="listheading" href="$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{accno}</a></th>|;
- $column_data{gifi_accno} = qq|<th class="listheading"><a href="$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{gifi_accno}</a>&nbsp;</th>|;
- $column_data{description} = qq|<th class="listheading">$ca->{description}&nbsp;</th>|;
- $column_data{debit} = qq|<th>&nbsp;</th>|;
- $column_data{credit} = qq| <th>&nbsp;</th>|;
- $column_data{link} = qq|<th>&nbsp;</th>|;
+ if ( $ca->{charttype} eq "H" ) {
+ print qq|<tr class="listheading">|;
- } else {
- $i++; $i %= 2;
- print qq|
+ $column_data{accno} =
+qq|<th><a class="listheading" href="$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{accno}</a></th>|;
+ $column_data{gifi_accno} =
+qq|<th class="listheading"><a href="$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{gifi_accno}</a>&nbsp;</th>|;
+ $column_data{description} =
+ qq|<th class="listheading">$ca->{description}&nbsp;</th>|;
+ $column_data{debit} = qq|<th>&nbsp;</th>|;
+ $column_data{credit} = qq| <th>&nbsp;</th>|;
+ $column_data{link} = qq|<th>&nbsp;</th>|;
+
+ }
+ else {
+ $i++;
+ $i %= 2;
+ print qq|
<tr valign=top class="listrow$i">|;
- $column_data{accno} = qq|<td><a href="$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{accno}</a></td>|;
- $column_data{gifi_accno} = qq|<td><a href="$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{gifi_accno}</a>&nbsp;</td>|;
- $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
- $column_data{debit} = qq|<td align="right">$ca->{debit}</td>|;
- $column_data{credit} = qq|<td align="right">$ca->{credit}</td>|;
- $column_data{link} = qq|<td>$ca->{link}&nbsp;</td>|;
-
- }
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print "</tr>\n";
- }
-
- print qq|
+ $column_data{accno} =
+qq|<td><a href="$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{accno}</a></td>|;
+ $column_data{gifi_accno} =
+qq|<td><a href="$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{gifi_accno}</a>&nbsp;</td>|;
+ $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
+ $column_data{debit} = qq|<td align="right">$ca->{debit}</td>|;
+ $column_data{credit} = qq|<td align="right">$ca->{credit}</td>|;
+ $column_data{link} = qq|<td>$ca->{link}&nbsp;</td>|;
+
+ }
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print "</tr>\n";
+ }
+
+ print qq|
<tr><td colspan="$colspan"><hr size="3" noshade /></td></tr>
</table>
@@ -402,48 +469,54 @@ sub list_account {
}
-
sub delete_account {
- $form->{title} = $locale->text('Delete Account');
+ $form->{title} = $locale->text('Delete Account');
- foreach $id (qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)) {
- if ($form->{id} == $form->{$id}) {
- $form->error($locale->text('Cannot delete default account!'));
+ foreach $id (
+ qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
+ )
+ {
+ if ( $form->{id} == $form->{$id} ) {
+ $form->error( $locale->text('Cannot delete default account!') );
+ }
}
- }
- if (AM->delete_account(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Account deleted!'));
- } else {
- $form->error($locale->text('Cannot delete account!'));
- }
+ if ( AM->delete_account( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Account deleted!') );
+ }
+ else {
+ $form->error( $locale->text('Cannot delete account!') );
+ }
}
-
sub list_gifi {
- @{ $form->{fields} } = qw(accno description);
- $form->{table} = "gifi";
-
- AM->gifi_accounts(\%myconfig, \%$form);
+ @{ $form->{fields} } = qw(accno description);
+ $form->{table} = "gifi";
- $form->{title} = $locale->text('GIFI');
-
- # construct callback
- $callback = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+ AM->gifi_accounts( \%myconfig, \%$form );
+
+ $form->{title} = $locale->text('GIFI');
- @column_index = qw(accno description);
+ # construct callback
+ $callback =
+"$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- $column_header{accno} = qq|<th class="listheading">|.$locale->text('GIFI').qq|</a></th>|;
- $column_header{description} = qq|<th class="listheading">|.$locale->text('Description').qq|</a></th>|;
+ @column_index = qw(accno description);
+ $column_header{accno} =
+ qq|<th class="listheading">| . $locale->text('GIFI') . qq|</a></th>|;
+ $column_header{description} =
+ qq|<th class="listheading">|
+ . $locale->text('Description')
+ . qq|</a></th>|;
- $form->header;
- $colspan = $#column_index + 1;
+ $form->header;
+ $colspan = $#column_index + 1;
- print qq|
+ print qq|
<body>
<table width=100%>
@@ -454,32 +527,34 @@ sub list_gifi {
<tr class="listheading">
|;
- for (@column_index) { print "$column_header{$_}\n" }
-
- print qq|
+ for (@column_index) { print "$column_header{$_}\n" }
+
+ print qq|
</tr>
|;
- # escape callback
- $callback = $form->escape($callback);
-
- foreach $ca (@{ $form->{ALL} }) {
-
- $i++; $i %= 2;
-
- print qq|
+ # escape callback
+ $callback = $form->escape($callback);
+
+ foreach $ca ( @{ $form->{ALL} } ) {
+
+ $i++;
+ $i %= 2;
+
+ print qq|
<tr valign=top class=listrow$i>|;
-
- $accno = $form->escape($ca->{accno});
- $column_data{accno} = qq|<td><a href=$form->{script}?action=edit_gifi&coa=1&accno=$accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ca->{accno}</td>|;
- $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print "</tr>\n";
- }
-
- print qq|
+
+ $accno = $form->escape( $ca->{accno} );
+ $column_data{accno} =
+qq|<td><a href=$form->{script}?action=edit_gifi&coa=1&accno=$accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ca->{accno}</td>|;
+ $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print "</tr>\n";
+ }
+
+ print qq|
<tr>
<td colspan=$colspan><hr size=3 noshade></td>
</tr>
@@ -491,47 +566,46 @@ sub list_gifi {
}
-
sub add_gifi {
- $form->{title} = "Add";
-
- # construct callback
- $form->{callback} = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+ $form->{title} = "Add";
- $form->{coa} = 1;
-
- &gifi_header;
- &gifi_footer;
-
-}
+ # construct callback
+ $form->{callback} =
+"$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+ $form->{coa} = 1;
-sub edit_gifi {
-
- $form->{title} = "Edit";
-
- AM->get_gifi(\%myconfig, \%$form);
+ &gifi_header;
+ &gifi_footer;
- $form->error($locale->text('Account does not exist!')) unless $form->{accno};
-
- &gifi_header;
- &gifi_footer;
-
}
+sub edit_gifi {
+
+ $form->{title} = "Edit";
+
+ AM->get_gifi( \%myconfig, \%$form );
+
+ $form->error( $locale->text('Account does not exist!') )
+ unless $form->{accno};
+
+ &gifi_header;
+ &gifi_footer;
+
+}
sub gifi_header {
- $form->{title} = $locale->text("$form->{title} GIFI");
-
-# $locale->text('Add GIFI')
-# $locale->text('Edit GIFI')
+ $form->{title} = $locale->text("$form->{title} GIFI");
+
+ # $locale->text('Add GIFI')
+ # $locale->text('Edit GIFI')
- for (qw(accno description)) { $form->{$_} = $form->quote($form->{$_}) }
+ for (qw(accno description)) { $form->{$_} = $form->quote( $form->{$_} ) }
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -548,11 +622,11 @@ sub gifi_header {
<td>
<table>
<tr>
- <th align="right">|.$locale->text('GIFI').qq|</th>
+ <th align="right">| . $locale->text('GIFI') . qq|</th>
<td><input name=accno size=20 value="$form->{accno}"></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Description').qq|</th>
+ <th align="right">| . $locale->text('Description') . qq|</th>
<td><input name=description size=60 value="$form->{description}"></td>
</tr>
</table>
@@ -566,37 +640,40 @@ sub gifi_header {
}
-
sub gifi_footer {
- $form->hide_form(qw(callback path login sessionid));
-
-# type=submit $locale->text('Save')
-# type=submit $locale->text('Copy to COA')
-# type=submit $locale->text('Delete')
+ $form->hide_form(qw(callback path login sessionid));
- %button = ();
-
- $button{'save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
-
- if ($form->{accno}) {
- if ($form->{orphaned}) {
- $button{'delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') };
+ # type=submit $locale->text('Save')
+ # type=submit $locale->text('Copy to COA')
+ # type=submit $locale->text('Delete')
+
+ %button = ();
+
+ $button{'save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
+
+ if ( $form->{accno} ) {
+ if ( $form->{orphaned} ) {
+ $button{'delete'} =
+ { ndx => 16, key => 'D', value => $locale->text('Delete') };
+ }
+ }
+
+ if ( $form->{coa} ) {
+ $button{'copy_to_coa'} =
+ { ndx => 7, key => 'C', value => $locale->text('Copy to COA') };
}
- }
-
- if ($form->{coa}) {
- $button{'copy_to_coa'} = { ndx => 7, key => 'C', value => $locale->text('Copy to COA') };
- }
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
+ for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
+ $form->print_button( \%button, $_ );
+ }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -605,90 +682,97 @@ sub gifi_footer {
}
-
sub save_gifi {
- $form->isblank("accno", $locale->text('GIFI missing!'));
- AM->save_gifi(\%myconfig, \%$form);
- $form->redirect($locale->text('GIFI saved!'));
+ $form->isblank( "accno", $locale->text('GIFI missing!') );
+ AM->save_gifi( \%myconfig, \%$form );
+ $form->redirect( $locale->text('GIFI saved!') );
}
-
sub copy_to_coa {
- $form->isblank("accno", $locale->text('GIFI missing!'));
+ $form->isblank( "accno", $locale->text('GIFI missing!') );
- AM->save_gifi(\%myconfig, \%$form);
+ AM->save_gifi( \%myconfig, \%$form );
- delete $form->{id};
- $form->{gifi_accno} = $form->{accno};
-
- $form->{title} = "Add";
- $form->{charttype} = "A";
-
- &account_header;
- &form_footer;
-
-}
+ delete $form->{id};
+ $form->{gifi_accno} = $form->{accno};
+
+ $form->{title} = "Add";
+ $form->{charttype} = "A";
+ &account_header;
+ &form_footer;
+
+}
sub delete_gifi {
- AM->delete_gifi(\%myconfig, \%$form);
- $form->redirect($locale->text('GIFI deleted!'));
+ AM->delete_gifi( \%myconfig, \%$form );
+ $form->redirect( $locale->text('GIFI deleted!') );
}
-
sub add_department {
- $form->{title} = "Add";
- $form->{role} = "P";
-
- $form->{callback} = "$form->{script}?action=add_department&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
+ $form->{title} = "Add";
+ $form->{role} = "P";
- &department_header;
- &form_footer;
+ $form->{callback} =
+"$form->{script}?action=add_department&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
-}
+ &department_header;
+ &form_footer;
+}
sub edit_department {
- $form->{title} = "Edit";
+ $form->{title} = "Edit";
- AM->get_department(\%myconfig, \%$form);
+ AM->get_department( \%myconfig, \%$form );
- &department_header;
- &form_footer;
+ &department_header;
+ &form_footer;
}
-
sub list_department {
- AM->departments(\%myconfig, \%$form);
+ AM->departments( \%myconfig, \%$form );
- $href = "$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+ $href =
+"$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- $form->sort_order();
-
- $form->{callback} = "$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- $callback = $form->escape($form->{callback});
-
- $form->{title} = $locale->text('Departments');
+ $form->sort_order();
+
+ $form->{callback} =
+"$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- @column_index = qw(description cost profit);
+ $callback = $form->escape( $form->{callback} );
- $column_header{description} = qq|<th width=90%><a class="listheading" href=$href>|.$locale->text('Description').qq|</a></th>|;
- $column_header{cost} = qq|<th class="listheading" nowrap>|.$locale->text('Cost Center').qq|</th>|;
- $column_header{profit} = qq|<th class="listheading" nowrap>|.$locale->text('Profit Center').qq|</th>|;
+ $form->{title} = $locale->text('Departments');
- $form->header;
+ @column_index = qw(description cost profit);
- print qq|
+ $column_header{description} =
+ qq|<th width=90%><a class="listheading" href=$href>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
+ $column_header{cost} =
+ qq|<th class="listheading" nowrap>|
+ . $locale->text('Cost Center')
+ . qq|</th>|;
+ $column_header{profit} =
+ qq|<th class="listheading" nowrap>|
+ . $locale->text('Profit Center')
+ . qq|</th>|;
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -702,35 +786,37 @@ sub list_department {
<tr class="listheading">
|;
- for (@column_index) { print "$column_header{$_}\n" }
+ for (@column_index) { print "$column_header{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
- foreach $ref (@{ $form->{ALL} }) {
-
- $i++; $i %= 2;
-
- print qq|
+ foreach $ref ( @{ $form->{ALL} } ) {
+
+ $i++;
+ $i %= 2;
+
+ print qq|
<tr valign=top class=listrow$i>
|;
- $costcenter = ($ref->{role} eq "C") ? "*" : "&nbsp;";
- $profitcenter = ($ref->{role} eq "P") ? "*" : "&nbsp;";
-
- $column_data{description} = qq|<td><a href=$form->{script}?action=edit_department&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
- $column_data{cost} = qq|<td align=center>$costcenter</td>|;
- $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
+ $costcenter = ( $ref->{role} eq "C" ) ? "*" : "&nbsp;";
+ $profitcenter = ( $ref->{role} eq "P" ) ? "*" : "&nbsp;";
- for (@column_index) { print "$column_data{$_}\n" }
+ $column_data{description} =
+qq|<td><a href=$form->{script}?action=edit_department&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
+ $column_data{cost} = qq|<td align=center>$costcenter</td>|;
+ $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
- print qq|
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
</tr>
|;
- }
+ }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -743,49 +829,53 @@ sub list_department {
<form method=post action=$form->{script}>
|;
- $form->{type} = "department";
-
- $form->hide_form(qw(type callback path login sessionid));
-
- print qq|
-<button class="submit" type="submit" name="action" value="add_department">|.$locale->text('Add Department').qq|"</button>|;
+ $form->{type} = "department";
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ $form->hide_form(qw(type callback path login sessionid));
- print qq|
+ print qq|
+<button class="submit" type="submit" name="action" value="add_department">|
+ . $locale->text('Add Department')
+ . qq|"</button>|;
+
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
</form>
</body>
</html>
|;
-
-}
+}
sub department_header {
- $form->{title} = $locale->text("$form->{title} Department");
+ $form->{title} = $locale->text("$form->{title} Department");
-# $locale->text('Add Department')
-# $locale->text('Edit Department')
+ # $locale->text('Add Department')
+ # $locale->text('Edit Department')
- $form->{description} = $form->quote($form->{description});
+ $form->{description} = $form->quote( $form->{description} );
- if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
- $description = qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
- } else {
- $description = qq|<input name=description size=60 value="$form->{description}">|;
- }
+ if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) {
+ $description =
+qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
+ }
+ else {
+ $description =
+ qq|<input name=description size=60 value="$form->{description}">|;
+ }
- $costcenter = "checked" if $form->{role} eq "C";
- $profitcenter = "checked" if $form->{role} eq "P";
-
- $form->header;
+ $costcenter = "checked" if $form->{role} eq "C";
+ $profitcenter = "checked" if $form->{role} eq "P";
+
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -799,13 +889,15 @@ sub department_header {
</tr>
<tr height="5"></tr>
<tr>
- <th align="right">|.$locale->text('Description').qq|</th>
+ <th align="right">| . $locale->text('Description') . qq|</th>
<td>$description</td>
</tr>
<tr>
<td></td>
- <td><input type=radio style=radio name=role value="C" $costcenter> |.$locale->text('Cost Center').qq|
- <input type=radio style=radio name=role value="P" $profitcenter> |.$locale->text('Profit Center').qq|
+ <td><input type=radio style=radio name=role value="C" $costcenter> |
+ . $locale->text('Cost Center') . qq|
+ <input type=radio style=radio name=role value="P" $profitcenter> |
+ . $locale->text('Profit Center') . qq|
</td>
<tr>
<td colspan=2><hr size=3 noshade></td>
@@ -815,72 +907,75 @@ sub department_header {
}
-
sub save_department {
- $form->isblank("description", $locale->text('Description missing!'));
- AM->save_department(\%myconfig, \%$form);
- $form->redirect($locale->text('Department saved!'));
+ $form->isblank( "description", $locale->text('Description missing!') );
+ AM->save_department( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Department saved!') );
}
-
sub delete_department {
- AM->delete_department(\%myconfig, \%$form);
- $form->redirect($locale->text('Department deleted!'));
+ AM->delete_department( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Department deleted!') );
}
-
sub add_business {
- $form->{title} = "Add";
-
- $form->{callback} = "$form->{script}?action=add_business&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
+ $form->{title} = "Add";
- &business_header;
- &form_footer;
+ $form->{callback} =
+"$form->{script}?action=add_business&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
-}
+ &business_header;
+ &form_footer;
+}
sub edit_business {
- $form->{title} = "Edit";
+ $form->{title} = "Edit";
- AM->get_business(\%myconfig, \%$form);
+ AM->get_business( \%myconfig, \%$form );
- &business_header;
+ &business_header;
- $form->{orphaned} = 1;
- &form_footer;
+ $form->{orphaned} = 1;
+ &form_footer;
}
-
sub list_business {
- AM->business(\%myconfig, \%$form);
+ AM->business( \%myconfig, \%$form );
- $href = "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+ $href =
+"$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- $form->sort_order();
-
- $form->{callback} = "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- $callback = $form->escape($form->{callback});
-
- $form->{title} = $locale->text('Type of Business');
+ $form->sort_order();
- @column_index = qw(description discount);
+ $form->{callback} =
+"$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- $column_header{description} = qq|<th width=90%><a class="listheading" href=$href>|.$locale->text('Description').qq|</a></th>|;
- $column_header{discount} = qq|<th class="listheading">|.$locale->text('Discount').qq| %</th>|;
+ $callback = $form->escape( $form->{callback} );
- $form->header;
+ $form->{title} = $locale->text('Type of Business');
- print qq|
+ @column_index = qw(description discount);
+
+ $column_header{description} =
+ qq|<th width=90%><a class="listheading" href=$href>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
+ $column_header{discount} =
+ qq|<th class="listheading">| . $locale->text('Discount') . qq| %</th>|;
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -894,33 +989,37 @@ sub list_business {
<tr class="listheading">
|;
- for (@column_index) { print "$column_header{$_}\n" }
+ for (@column_index) { print "$column_header{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
- foreach $ref (@{ $form->{ALL} }) {
-
- $i++; $i %= 2;
-
- print qq|
+ foreach $ref ( @{ $form->{ALL} } ) {
+
+ $i++;
+ $i %= 2;
+
+ print qq|
<tr valign=top class=listrow$i>
|;
- $discount = $form->format_amount(\%myconfig, $ref->{discount} * 100, 2, "&nbsp");
-
- $column_data{description} = qq|<td><a href=$form->{script}?action=edit_business&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
- $column_data{discount} = qq|<td align="right">$discount</td>|;
-
- for (@column_index) { print "$column_data{$_}\n" }
+ $discount =
+ $form->format_amount( \%myconfig, $ref->{discount} * 100, 2,
+ "&nbsp" );
- print qq|
+ $column_data{description} =
+qq|<td><a href=$form->{script}?action=edit_business&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
+ $column_data{discount} = qq|<td align="right">$discount</td>|;
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
</tr>
|;
- }
+ }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -933,42 +1032,44 @@ sub list_business {
<form method=post action=$form->{script}>
|;
- $form->{type} = "business";
-
- $form->hide_form(qw(type callback path login sessionid));
+ $form->{type} = "business";
- print qq|
-<button class="submit" type="submit" name="action" value="add_business">|.$locale->text('Add Business').qq|</button>|;
+ $form->hide_form(qw(type callback path login sessionid));
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ print qq|
+<button class="submit" type="submit" name="action" value="add_business">|
+ . $locale->text('Add Business')
+ . qq|</button>|;
- print qq|
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
</form>
</body>
</html>
|;
-
-}
+}
sub business_header {
- $form->{title} = $locale->text("$form->{title} Business");
+ $form->{title} = $locale->text("$form->{title} Business");
-# $locale->text('Add Business')
-# $locale->text('Edit Business')
+ # $locale->text('Add Business')
+ # $locale->text('Edit Business')
- $form->{description} = $form->quote($form->{description});
- $form->{discount} = $form->format_amount(\%myconfig, $form->{discount} * 100);
+ $form->{description} = $form->quote( $form->{description} );
+ $form->{discount} =
+ $form->format_amount( \%myconfig, $form->{discount} * 100 );
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -985,11 +1086,11 @@ sub business_header {
<td>
<table>
<tr>
- <th align="right">|.$locale->text('Type of Business').qq|</th>
+ <th align="right">| . $locale->text('Type of Business') . qq|</th>
<td><input name=description size=30 value="$form->{description}"></td>
<tr>
<tr>
- <th align="right">|.$locale->text('Discount').qq| %</th>
+ <th align="right">| . $locale->text('Discount') . qq| %</th>
<td><input name=discount size=5 value=$form->{discount}></td>
</tr>
</table>
@@ -1003,77 +1104,81 @@ sub business_header {
}
-
sub save_business {
- $form->isblank("description", $locale->text('Description missing!'));
- AM->save_business(\%myconfig, \%$form);
- $form->redirect($locale->text('Business saved!'));
+ $form->isblank( "description", $locale->text('Description missing!') );
+ AM->save_business( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Business saved!') );
}
-
sub delete_business {
- AM->delete_business(\%myconfig, \%$form);
- $form->redirect($locale->text('Business deleted!'));
+ AM->delete_business( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Business deleted!') );
}
-
-
sub add_sic {
- $form->{title} = "Add";
-
- $form->{callback} = "$form->{script}?action=add_sic&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
+ $form->{title} = "Add";
- &sic_header;
- &form_footer;
+ $form->{callback} =
+"$form->{script}?action=add_sic&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
-}
+ &sic_header;
+ &form_footer;
+}
sub edit_sic {
- $form->{title} = "Edit";
+ $form->{title} = "Edit";
- $form->{code} =~ s/\\'/'/g;
- $form->{code} =~ s/\\\\/\\/g;
-
- AM->get_sic(\%myconfig, \%$form);
- $form->{id} = $form->{code};
+ $form->{code} =~ s/\\'/'/g;
+ $form->{code} =~ s/\\\\/\\/g;
- &sic_header;
+ AM->get_sic( \%myconfig, \%$form );
+ $form->{id} = $form->{code};
- $form->{orphaned} = 1;
- &form_footer;
+ &sic_header;
-}
+ $form->{orphaned} = 1;
+ &form_footer;
+}
sub list_sic {
- AM->sic(\%myconfig, \%$form);
+ AM->sic( \%myconfig, \%$form );
- $href = "$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- $form->sort_order();
+ $href =
+"$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- $form->{callback} = "$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- $callback = $form->escape($form->{callback});
-
- $form->{title} = $locale->text('Standard Industrial Codes');
+ $form->sort_order();
- @column_index = $form->sort_columns(qw(code description));
+ $form->{callback} =
+"$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- $column_header{code} = qq|<th><a class="listheading" href=$href&sort=code>|.$locale->text('Code').qq|</a></th>|;
- $column_header{description} = qq|<th><a class="listheading" href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
+ $callback = $form->escape( $form->{callback} );
- $form->header;
+ $form->{title} = $locale->text('Standard Industrial Codes');
- print qq|
+ @column_index = $form->sort_columns(qw(code description));
+
+ $column_header{code} =
+ qq|<th><a class="listheading" href=$href&sort=code>|
+ . $locale->text('Code')
+ . qq|</a></th>|;
+ $column_header{description} =
+ qq|<th><a class="listheading" href=$href&sort=description>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -1087,41 +1192,45 @@ sub list_sic {
<tr class="listheading">
|;
- for (@column_index) { print "$column_header{$_}\n" }
+ for (@column_index) { print "$column_header{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
- foreach $ref (@{ $form->{ALL} }) {
-
- $i++; $i %= 2;
-
- if ($ref->{sictype} eq 'H') {
- print qq|
+ foreach $ref ( @{ $form->{ALL} } ) {
+
+ $i++;
+ $i %= 2;
+
+ if ( $ref->{sictype} eq 'H' ) {
+ print qq|
<tr valign=top class="listheading">
|;
- $column_data{code} = qq|<th><a href=$form->{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</th>|;
- $column_data{description} = qq|<th>$ref->{description}</th>|;
-
- } else {
- print qq|
+ $column_data{code} =
+qq|<th><a href=$form->{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</th>|;
+ $column_data{description} = qq|<th>$ref->{description}</th>|;
+
+ }
+ else {
+ print qq|
<tr valign=top class=listrow$i>
|;
- $column_data{code} = qq|<td><a href=$form->{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</td>|;
- $column_data{description} = qq|<td>$ref->{description}</td>|;
+ $column_data{code} =
+qq|<td><a href=$form->{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</td>|;
+ $column_data{description} = qq|<td>$ref->{description}</td>|;
+
+ }
- }
-
- for (@column_index) { print "$column_data{$_}\n" }
+ for (@column_index) { print "$column_data{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
- }
+ }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -1134,42 +1243,43 @@ sub list_sic {
<form method=post action=$form->{script}>
|;
- $form->{type} = "sic";
-
- $form->hide_form(qw(type callback path login sessionid));
-
- print qq|
-<button class="submit" type="submit" name="action" value="add_sic">|.$locale->text('Add SIC').qq|</button>|;
+ $form->{type} = "sic";
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ $form->hide_form(qw(type callback path login sessionid));
- print qq|
+ print qq|
+<button class="submit" type="submit" name="action" value="add_sic">|
+ . $locale->text('Add SIC')
+ . qq|</button>|;
+
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
</form>
</body>
</html>
|;
-
-}
+}
sub sic_header {
- $form->{title} = $locale->text("$form->{title} SIC");
+ $form->{title} = $locale->text("$form->{title} SIC");
-# $locale->text('Add SIC')
-# $locale->text('Edit SIC')
+ # $locale->text('Add SIC')
+ # $locale->text('Edit SIC')
- for (qw(code description)) { $form->{$_} = $form->quote($form->{$_}) }
+ for (qw(code description)) { $form->{$_} = $form->quote( $form->{$_} ) }
- $checked = ($form->{sictype} eq 'H') ? "checked" : "";
+ $checked = ( $form->{sictype} eq 'H' ) ? "checked" : "";
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -1183,15 +1293,17 @@ sub sic_header {
</tr>
<tr height="5"></tr>
<tr>
- <th align="right">|.$locale->text('Code').qq|</th>
+ <th align="right">| . $locale->text('Code') . qq|</th>
<td><input name=code size=10 value="$form->{code}"></td>
<tr>
<tr>
<td></td>
- <th align=left><input name=sictype class=checkbox type=checkbox value="H" $checked> |.$locale->text('Heading').qq|</th>
+ <th align=left><input name=sictype class=checkbox type=checkbox value="H" $checked> |
+ . $locale->text('Heading')
+ . qq|</th>
<tr>
<tr>
- <th align="right">|.$locale->text('Description').qq|</th>
+ <th align="right">| . $locale->text('Description') . qq|</th>
<td><input name=description size=60 value="$form->{description}"></td>
</tr>
<td colspan=2><hr size=3 noshade></td>
@@ -1201,77 +1313,82 @@ sub sic_header {
}
-
sub save_sic {
- $form->isblank("code", $locale->text('Code missing!'));
- $form->isblank("description", $locale->text('Description missing!'));
- AM->save_sic(\%myconfig, \%$form);
- $form->redirect($locale->text('SIC saved!'));
+ $form->isblank( "code", $locale->text('Code missing!') );
+ $form->isblank( "description", $locale->text('Description missing!') );
+ AM->save_sic( \%myconfig, \%$form );
+ $form->redirect( $locale->text('SIC saved!') );
}
-
sub delete_sic {
- AM->delete_sic(\%myconfig, \%$form);
- $form->redirect($locale->text('SIC deleted!'));
+ AM->delete_sic( \%myconfig, \%$form );
+ $form->redirect( $locale->text('SIC deleted!') );
}
-
sub add_language {
- $form->{title} = "Add";
-
- $form->{callback} = "$form->{script}?action=add_language&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
+ $form->{title} = "Add";
- &language_header;
- &form_footer;
+ $form->{callback} =
+"$form->{script}?action=add_language&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
-}
+ &language_header;
+ &form_footer;
+}
sub edit_language {
- $form->{title} = "Edit";
+ $form->{title} = "Edit";
- $form->{code} =~ s/\\'/'/g;
- $form->{code} =~ s/\\\\/\\/g;
-
- AM->get_language(\%myconfig, \%$form);
- $form->{id} = $form->{code};
+ $form->{code} =~ s/\\'/'/g;
+ $form->{code} =~ s/\\\\/\\/g;
- &language_header;
+ AM->get_language( \%myconfig, \%$form );
+ $form->{id} = $form->{code};
- $form->{orphaned} = 1;
- &form_footer;
+ &language_header;
-}
+ $form->{orphaned} = 1;
+ &form_footer;
+}
sub list_language {
- AM->language(\%myconfig, \%$form);
+ AM->language( \%myconfig, \%$form );
- $href = "$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- $form->sort_order();
+ $href =
+"$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- $form->{callback} = "$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- $callback = $form->escape($form->{callback});
-
- $form->{title} = $locale->text('Languages');
+ $form->sort_order();
+
+ $form->{callback} =
+"$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- @column_index = $form->sort_columns(qw(code description));
+ $callback = $form->escape( $form->{callback} );
- $column_header{code} = qq|<th><a class="listheading" href=$href&sort=code>|.$locale->text('Code').qq|</a></th>|;
- $column_header{description} = qq|<th><a class="listheading" href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
+ $form->{title} = $locale->text('Languages');
- $form->header;
+ @column_index = $form->sort_columns(qw(code description));
- print qq|
+ $column_header{code} =
+ qq|<th><a class="listheading" href=$href&sort=code>|
+ . $locale->text('Code')
+ . qq|</a></th>|;
+ $column_header{description} =
+ qq|<th><a class="listheading" href=$href&sort=description>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -1285,31 +1402,33 @@ sub list_language {
<tr class="listheading">
|;
- for (@column_index) { print "$column_header{$_}\n" }
+ for (@column_index) { print "$column_header{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
- foreach $ref (@{ $form->{ALL} }) {
-
- $i++; $i %= 2;
+ foreach $ref ( @{ $form->{ALL} } ) {
- print qq|
+ $i++;
+ $i %= 2;
+
+ print qq|
<tr valign=top class=listrow$i>
|;
- $column_data{code} = qq|<td><a href=$form->{script}?action=edit_language&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</td>|;
- $column_data{description} = qq|<td>$ref->{description}</td>|;
-
- for (@column_index) { print "$column_data{$_}\n" }
+ $column_data{code} =
+qq|<td><a href=$form->{script}?action=edit_language&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}</td>|;
+ $column_data{description} = qq|<td>$ref->{description}</td>|;
- print qq|
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
</tr>
|;
- }
+ }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -1322,40 +1441,41 @@ sub list_language {
<form method=post action=$form->{script}>
|;
- $form->{type} = "language";
+ $form->{type} = "language";
- $form->hide_form(qw(type callback path login sessionid));
-
- print qq|
-<button class="submit" type="submit" name="action" value="add_language">|.$locale->text('Add Language').qq|</button>|;
+ $form->hide_form(qw(type callback path login sessionid));
+
+ print qq|
+<button class="submit" type="submit" name="action" value="add_language">|
+ . $locale->text('Add Language')
+ . qq|</button>|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
</html>
|;
-
-}
+}
sub language_header {
- $form->{title} = $locale->text("$form->{title} Language");
+ $form->{title} = $locale->text("$form->{title} Language");
-# $locale->text('Add Language')
-# $locale->text('Edit Language')
+ # $locale->text('Add Language')
+ # $locale->text('Edit Language')
- for (qw(code description)) { $form->{$_} = $form->quote($form->{$_}) }
+ for (qw(code description)) { $form->{$_} = $form->quote( $form->{$_} ) }
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -1369,11 +1489,11 @@ sub language_header {
</tr>
<tr height="5"></tr>
<tr>
- <th align="right">|.$locale->text('Code').qq|</th>
+ <th align="right">| . $locale->text('Code') . qq|</th>
<td><input name=code size=10 value="$form->{code}"></td>
<tr>
<tr>
- <th align="right">|.$locale->text('Description').qq|</th>
+ <th align="right">| . $locale->text('Description') . qq|</th>
<td><input name=description size=60 value="$form->{description}"></td>
</tr>
<td colspan=2><hr size=3 noshade></td>
@@ -1383,75 +1503,85 @@ sub language_header {
}
-
sub save_language {
- $form->isblank("code", $locale->text('Code missing!'));
- $form->isblank("description", $locale->text('Description missing!'));
+ $form->isblank( "code", $locale->text('Code missing!') );
+ $form->isblank( "description", $locale->text('Description missing!') );
- $form->{code} =~ s/(\.\.|\*)//g;
-
- AM->save_language(\%myconfig, \%$form);
+ $form->{code} =~ s/(\.\.|\*)//g;
+
+ AM->save_language( \%myconfig, \%$form );
- if (! -d "$myconfig{templates}/$form->{code}") {
-
- umask(002);
-
- if (mkdir "$myconfig{templates}/$form->{code}", oct("771")) {
-
- umask(007);
+ if ( !-d "$myconfig{templates}/$form->{code}" ) {
- opendir TEMPLATEDIR, "$myconfig{templates}" or $form->error("$myconfig{templates} : $!");
- @templates = grep !/^(\.|\.\.)/, readdir TEMPLATEDIR;
- closedir TEMPLATEDIR;
+ umask(002);
- foreach $file (@templates) {
- if (-f "$myconfig{templates}/$file") {
- open(TEMP, '<', "$myconfig{templates}/$file") or $form->error("$myconfig{templates}/$file : $!");
+ if ( mkdir "$myconfig{templates}/$form->{code}", oct("771") ) {
- open(NEW, '>', "$myconfig{templates}/$form->{code}/$file") or $form->error("$myconfig{templates}/$form->{code}/$file : $!");
+ umask(007);
- while ($line = <TEMP>) {
- print NEW $line;
- }
- close(TEMP);
- close(NEW);
- }
- }
- } else {
- $form->error("${templates}/$form->{code} : $!");
+ opendir TEMPLATEDIR, "$myconfig{templates}"
+ or $form->error("$myconfig{templates} : $!");
+ @templates = grep !/^(\.|\.\.)/, readdir TEMPLATEDIR;
+ closedir TEMPLATEDIR;
+
+ foreach $file (@templates) {
+ if ( -f "$myconfig{templates}/$file" ) {
+ open( TEMP, '<', "$myconfig{templates}/$file" )
+ or $form->error("$myconfig{templates}/$file : $!");
+
+ open( NEW, '>', "$myconfig{templates}/$form->{code}/$file" )
+ or $form->error(
+ "$myconfig{templates}/$form->{code}/$file : $!");
+
+ while ( $line = <TEMP> ) {
+ print NEW $line;
+ }
+ close(TEMP);
+ close(NEW);
+ }
+ }
+ }
+ else {
+ $form->error("${templates}/$form->{code} : $!");
+ }
}
- }
-
- $form->redirect($locale->text('Language saved!'));
-}
+ $form->redirect( $locale->text('Language saved!') );
+}
sub delete_language {
- $form->{title} = $locale->text('Confirm!');
+ $form->{title} = $locale->text('Confirm!');
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
|;
- for (qw(action nextsub)) { delete $form->{$_} }
-
- $form->hide_form;
+ for (qw(action nextsub)) { delete $form->{$_} }
+
+ $form->hide_form;
- print qq|
+ print qq|
<h2 class=confirm>$form->{title}</h2>
-<h4>|.$locale->text('Deleting a language will also delete the templates for the language [_1]', $form->{invnumber}).qq|</h4>
+<h4>|
+ . $locale->text(
+'Deleting a language will also delete the templates for the language [_1]',
+ $form->{invnumber}
+ )
+ . qq|</h4>
<input type=hidden name=action value=continue>
<input type=hidden name=nextsub value=yes_delete_language>
-<button name="action" class="submit" type="submit" value="continue">|.$locale->text('Continue').qq|</button>
+<button name="action" class="submit" type="submit" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
</body>
@@ -1460,62 +1590,68 @@ sub delete_language {
}
-
sub yes_delete_language {
-
- AM->delete_language(\%myconfig, \%$form);
- # delete templates
- $dir = "$myconfig{templates}/$form->{code}";
- if (-d $dir) {
- unlink <$dir/*>;
- rmdir "$myconfig{templates}/$form->{code}";
- }
- $form->redirect($locale->text('Language deleted!'));
+ AM->delete_language( \%myconfig, \%$form );
-}
+ # delete templates
+ $dir = "$myconfig{templates}/$form->{code}";
+ if ( -d $dir ) {
+ unlink <$dir/*>;
+ rmdir "$myconfig{templates}/$form->{code}";
+ }
+ $form->redirect( $locale->text('Language deleted!') );
+}
sub display_stylesheet {
-
- $form->{file} = "css/$myconfig{stylesheet}";
- &display_form;
-
-}
+ $form->{file} = "css/$myconfig{stylesheet}";
+ &display_form;
+
+}
sub list_templates {
- AM->language(\%myconfig, \%$form);
-
- if (! @{ $form->{ALL} }) {
- &display_form;
- exit;
- }
+ AM->language( \%myconfig, \%$form );
- unshift @{ $form->{ALL} }, { code => '.', description => $locale->text('Default Template') };
-
- $href = "$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- $form->sort_order();
+ if ( !@{ $form->{ALL} } ) {
+ &display_form;
+ exit;
+ }
- $form->{callback} = "$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- $callback = $form->escape($form->{callback});
+ unshift @{ $form->{ALL} },
+ { code => '.', description => $locale->text('Default Template') };
- chomp $myconfig{templates};
- $form->{file} =~ s/$myconfig{templates}//;
- $form->{file} =~ s/\///;
- $form->{title} = $form->{file};
+ $href =
+"$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- @column_index = $form->sort_columns(qw(code description));
+ $form->sort_order();
- $column_header{code} = qq|<th><a class="listheading" href=$href&sort=code>|.$locale->text('Code').qq|</a></th>|;
- $column_header{description} = qq|<th><a class="listheading" href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
+ $form->{callback} =
+"$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- $form->header;
+ $callback = $form->escape( $form->{callback} );
- print qq|
+ chomp $myconfig{templates};
+ $form->{file} =~ s/$myconfig{templates}//;
+ $form->{file} =~ s/\///;
+ $form->{title} = $form->{file};
+
+ @column_index = $form->sort_columns(qw(code description));
+
+ $column_header{code} =
+ qq|<th><a class="listheading" href=$href&sort=code>|
+ . $locale->text('Code')
+ . qq|</a></th>|;
+ $column_header{description} =
+ qq|<th><a class="listheading" href=$href&sort=description>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -1529,31 +1665,33 @@ sub list_templates {
<tr class="listheading">
|;
- for (@column_index) { print "$column_header{$_}\n" }
+ for (@column_index) { print "$column_header{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
- foreach $ref (@{ $form->{ALL} }) {
-
- $i++; $i %= 2;
+ foreach $ref ( @{ $form->{ALL} } ) {
- print qq|
+ $i++;
+ $i %= 2;
+
+ print qq|
<tr valign=top class=listrow$i>
|;
- $column_data{code} = qq|<td><a href=$form->{script}?action=display_form&file=$myconfig{templates}/$ref->{code}/$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&code=$ref->{code}&callback=$callback>$ref->{code}</td>|;
- $column_data{description} = qq|<td>$ref->{description}</td>|;
-
- for (@column_index) { print "$column_data{$_}\n" }
+ $column_data{code} =
+qq|<td><a href=$form->{script}?action=display_form&file=$myconfig{templates}/$ref->{code}/$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&code=$ref->{code}&callback=$callback>$ref->{code}</td>|;
+ $column_data{description} = qq|<td>$ref->{description}</td>|;
+
+ for (@column_index) { print "$column_data{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
- }
+ }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -1574,37 +1712,37 @@ sub list_templates {
<input type=hidden name=sessionid value=$form->{sessionid}>
|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
</html>
|;
-
-}
+}
sub display_form {
- AM->load_template(\%myconfig, \%$form);
+ AM->load_template( \%myconfig, \%$form );
- $form->{title} = $form->{file};
+ $form->{title} = $form->{file};
- $form->{body} =~ s/<%include (.*?)%>/<a href=$form->{script}\?action=display_form&file=$myconfig{templates}\/$form->{code}\/$1&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}>$1<\/a>/g;
+ $form->{body} =~
+s/<%include (.*?)%>/<a href=$form->{script}\?action=display_form&file=$myconfig{templates}\/$form->{code}\/$1&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}>$1<\/a>/g;
- # if it is anything but html
- if ($form->{file} !~ /\.html$/) {
- $form->{body} = "<pre>\n$form->{body}\n</pre>";
- }
-
- $form->header;
+ # if it is anything but html
+ if ( $form->{file} !~ /\.html$/ ) {
+ $form->{body} = "<pre>\n$form->{body}\n</pre>";
+ }
- print qq|
+ $form->header;
+
+ print qq|
<body>
$form->{body}
@@ -1612,19 +1750,21 @@ $form->{body}
<form method=post action=$form->{script}>
|;
- $form->{type} = "template";
+ $form->{type} = "template";
- $form->hide_form(qw(file type path login sessionid));
-
- print qq|
-<button name="action" type="submit" class="submit" value="edit">|.$locale->text('Edit').qq|</button>|;
+ $form->hide_form(qw(file type path login sessionid));
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ print qq|
+<button name="action" type="submit" class="submit" value="edit">|
+ . $locale->text('Edit')
+ . qq|</button>|;
- print qq|
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
</form>
</body>
@@ -1633,19 +1773,18 @@ $form->{body}
}
-
sub edit_template {
- AM->load_template(\%myconfig, \%$form);
+ AM->load_template( \%myconfig, \%$form );
- $form->{title} = $locale->text('Edit Template');
- # convert &nbsp to &amp;nbsp;
- $form->{body} =~ s/&nbsp;/&amp;nbsp;/gi;
-
+ $form->{title} = $locale->text('Edit Template');
- $form->header;
-
- print qq|
+ # convert &nbsp to &amp;nbsp;
+ $form->{body} =~ s/&nbsp;/&amp;nbsp;/gi;
+
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -1664,14 +1803,16 @@ $form->{body}
</textarea>
<br>
-<button type="submit" class="submit" name="action" value="save">|.$locale->text('Save').qq|</button>|;
+<button type="submit" class="submit" name="action" value="save">|
+ . $locale->text('Save')
+ . qq|</button>|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print q|
+ print q|
</form>
@@ -1681,36 +1822,38 @@ $form->{body}
}
-
sub save_template {
- AM->save_template(\%myconfig, \%$form);
- $form->redirect($locale->text('Template saved!'));
-
-}
+ AM->save_template( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Template saved!') );
+}
sub defaults {
-
- # get defaults for account numbers and last numbers
- AM->get_all_defaults(\%$form);
- foreach $key (keys %{ $form->{accno} }) {
- foreach $accno (sort keys %{ $form->{accno}{$key} }) {
- $form->{account}{$key} .= "<option>$accno--$form->{accno}{$key}{$accno}{description}\n";
- $form->{accno}{$form->{accno}{$key}{$accno}{id}} = $accno;
+ # get defaults for account numbers and last numbers
+ AM->get_all_defaults( \%$form );
+
+ foreach $key ( keys %{ $form->{accno} } ) {
+ foreach $accno ( sort keys %{ $form->{accno}{$key} } ) {
+ $form->{account}{$key} .=
+ "<option>$accno--$form->{accno}{$key}{$accno}{description}\n";
+ $form->{accno}{ $form->{accno}{$key}{$accno}{id} } = $accno;
+ }
}
- }
- for (qw(IC IC_inventory IC_income IC_expense FX_gain FX_loss)) { $form->{account}{$_} =~ s/>$form->{accno}{$form->{defaults}{$_}}/ selected>$form->{accno}{$form->{defaults}{$_}}/ }
+ for (qw(IC IC_inventory IC_income IC_expense FX_gain FX_loss)) {
+ $form->{account}{$_} =~
+s/>$form->{accno}{$form->{defaults}{$_}}/ selected>$form->{accno}{$form->{defaults}{$_}}/;
+ }
- for (qw(accno defaults)) { delete $form->{$_} }
-
- $form->{title} = $locale->text('System Defaults');
-
- $form->header;
-
- print qq|
+ for (qw(accno defaults)) { delete $form->{$_} }
+
+ $form->{title} = $locale->text('System Defaults');
+
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -1723,47 +1866,57 @@ sub defaults {
<td>
<table>
<tr>
- <th align="right">|.$locale->text('Business Number').qq|</th>
+ <th align="right">| . $locale->text('Business Number') . qq|</th>
<td><input name=businessnumber size=25 value="$form->{businessnumber}"></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Weight Unit').qq|</th>
+ <th align="right">| . $locale->text('Weight Unit') . qq|</th>
<td><input name=weightunit size=5 value="$form->{weightunit}"></td>
</tr>
</table>
</td>
</tr>
<tr>
- <th class="listheading">|.$locale->text('Last Numbers & Default Accounts').qq|</th>
+ <th class="listheading">|
+ . $locale->text('Last Numbers & Default Accounts')
+ . qq|</th>
</tr>
<tr>
<td>
<table>
<tr>
- <th align="right" nowrap>|.$locale->text('Inventory').qq|</th>
+ <th align="right" nowrap>| . $locale->text('Inventory') . qq|</th>
<td><select name=IC>$form->{account}{IC}</select></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Income').qq|</th>
+ <th align="right" nowrap>| . $locale->text('Income') . qq|</th>
<td><select name=IC_income>$form->{account}{IC_income}</select></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Expense').qq|</th>
+ <th align="right" nowrap>| . $locale->text('Expense') . qq|</th>
<td><select name=IC_expense>$form->{account}{IC_expense}</select></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Foreign Exchange Gain').qq|</th>
+ <th align="right" nowrap>|
+ . $locale->text('Foreign Exchange Gain')
+ . qq|</th>
<td><select name=FX_gain>$form->{account}{FX_gain}</select></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Foreign Exchange Loss').qq|</th>
+ <th align="right" nowrap>|
+ . $locale->text('Foreign Exchange Loss')
+ . qq|</th>
<td><select name=FX_loss>$form->{account}{FX_loss}</select></td>
</tr>
</table>
</td>
</tr>
<tr>
- <th align=left>|.$locale->text('Enter up to 3 letters separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies').qq|</th>
+ <th align=left>|
+ . $locale->text(
+'Enter up to 3 letters separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies'
+ )
+ . qq|</th>
</tr>
<tr>
<td>
@@ -1774,51 +1927,59 @@ sub defaults {
<td>
<table>
<tr>
- <th align="right" nowrap>|.$locale->text('GL Reference Number').qq|</th>
+ <th align="right" nowrap>| . $locale->text('GL Reference Number') . qq|</th>
<td><input name=glnumber size=40 value="$form->{glnumber}"></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Sales Invoice/AR Transaction Number').qq|</th>
+ <th align="right" nowrap>|
+ . $locale->text('Sales Invoice/AR Transaction Number')
+ . qq|</th>
<td><input name=sinumber size=40 value="$form->{sinumber}"></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Sales Order Number').qq|</th>
+ <th align="right" nowrap>| . $locale->text('Sales Order Number') . qq|</th>
<td><input name=sonumber size=40 value="$form->{sonumber}"></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Vendor Invoice/AP Transaction Number').qq|</th>
+ <th align="right" nowrap>|
+ . $locale->text('Vendor Invoice/AP Transaction Number')
+ . qq|</th>
<td><input name=vinumber size=40 value="$form->{vinumber}"></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Purchase Order Number').qq|</th>
+ <th align="right" nowrap>|
+ . $locale->text('Purchase Order Number')
+ . qq|</th>
<td><input name=ponumber size=40 value="$form->{ponumber}"></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Sales Quotation Number').qq|</th>
+ <th align="right" nowrap>|
+ . $locale->text('Sales Quotation Number')
+ . qq|</th>
<td><input name=sqnumber size=40 value="$form->{sqnumber}"></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('RFQ Number').qq|</th>
+ <th align="right" nowrap>| . $locale->text('RFQ Number') . qq|</th>
<td><input name=rfqnumber size=40 value="$form->{rfqnumber}"></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Part Number').qq|</th>
+ <th align="right" nowrap>| . $locale->text('Part Number') . qq|</th>
<td><input name=partnumber size=40 value="$form->{partnumber}"></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Job/Project Number').qq|</th>
+ <th align="right" nowrap>| . $locale->text('Job/Project Number') . qq|</th>
<td><input name=projectnumber size=40 value="$form->{projectnumber}"></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Employee Number').qq|</th>
+ <th align="right" nowrap>| . $locale->text('Employee Number') . qq|</th>
<td><input name=employeenumber size=40 value="$form->{employeenumber}"></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Customer Number').qq|</th>
+ <th align="right" nowrap>| . $locale->text('Customer Number') . qq|</th>
<td><input name=customernumber size=40 value="$form->{customernumber}"></td>
</tr>
<tr>
- <th align="right" nowrap>|.$locale->text('Vendor Number').qq|</th>
+ <th align="right" nowrap>| . $locale->text('Vendor Number') . qq|</th>
<td><input name=vendornumber size=40 value="$form->{vendornumber}"></td>
</tr>
</table>
@@ -1830,17 +1991,19 @@ sub defaults {
</table>
|;
- $form->hide_form(qw(path login sessionid));
-
- print qq|
-<button type="submit" class="submit" name="action" value="save">|.$locale->text('Save').qq|</button>|;
+ $form->hide_form(qw(path login sessionid));
+
+ print qq|
+<button type="submit" class="submit" name="action" value="save">|
+ . $locale->text('Save')
+ . qq|</button>|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -1849,37 +2012,36 @@ sub defaults {
}
-
sub taxes {
-
- # get tax account numbers
- AM->taxes(\%myconfig, \%$form);
-
- $i = 0;
- foreach $ref (@{ $form->{taxrates} }) {
- $i++;
- $form->{"taxrate_$i"} = $form->format_amount(\%myconfig, $ref->{rate});
- $form->{"taxdescription_$i"} = $ref->{description};
-
- for (qw(taxnumber validto pass taxmodulename)) {
- $form->{"${_}_$i"} = $ref->{$_};
- }
- $form->{taxaccounts} .= "$ref->{id}_$i ";
- }
- chop $form->{taxaccounts};
-
- &display_taxes;
-}
+ # get tax account numbers
+ AM->taxes( \%myconfig, \%$form );
+ $i = 0;
+ foreach $ref ( @{ $form->{taxrates} } ) {
+ $i++;
+ $form->{"taxrate_$i"} =
+ $form->format_amount( \%myconfig, $ref->{rate} );
+ $form->{"taxdescription_$i"} = $ref->{description};
+
+ for (qw(taxnumber validto pass taxmodulename)) {
+ $form->{"${_}_$i"} = $ref->{$_};
+ }
+ $form->{taxaccounts} .= "$ref->{id}_$i ";
+ }
+ chop $form->{taxaccounts};
+
+ &display_taxes;
+
+}
sub display_taxes {
-
- $form->{title} = $locale->text('Taxes');
-
- $form->header;
-
- print qq|
+
+ $form->{title} = $locale->text('Taxes');
+
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -1893,54 +2055,60 @@ sub display_taxes {
<table>
<tr>
<th></th>
- <th>|.$locale->text('Rate').qq| (%)</th>
- <th>|.$locale->text('Number').qq|</th>
- <th>|.$locale->text('Valid To').qq|</th>
- <th>|.$locale->text('Ordering').qq|</th>
- <th>|.$locale->text('Tax Rules').qq|</th>
+ <th>| . $locale->text('Rate') . qq| (%)</th>
+ <th>| . $locale->text('Number') . qq|</th>
+ <th>| . $locale->text('Valid To') . qq|</th>
+ <th>| . $locale->text('Ordering') . qq|</th>
+ <th>| . $locale->text('Tax Rules') . qq|</th>
</tr>
|;
- for (split(/ /, $form->{taxaccounts})) {
-
- ($null, $i) = split /_/, $_;
-
- $form->{"taxrate_$i"} = $form->format_amount(\%myconfig, $form->{"taxrate_$i"});
-
- $form->hide_form("taxdescription_$i");
-
- print qq|
+ for ( split( / /, $form->{taxaccounts} ) ) {
+
+ ( $null, $i ) = split /_/, $_;
+
+ $form->{"taxrate_$i"} =
+ $form->format_amount( \%myconfig, $form->{"taxrate_$i"} );
+
+ $form->hide_form("taxdescription_$i");
+
+ print qq|
<tr>
<th align="right">|;
-
- if ($form->{"taxdescription_$i"} eq $sametax) {
- print "";
- } else {
- print qq|$form->{"taxdescription_$i"}|;
- }
-
- print qq|</th>
+
+ if ( $form->{"taxdescription_$i"} eq $sametax ) {
+ print "";
+ }
+ else {
+ print qq|$form->{"taxdescription_$i"}|;
+ }
+
+ print qq|</th>
<td><input name="taxrate_$i" size=6 value=$form->{"taxrate_$i"}></td>
<td><input name="taxnumber_$i" value="$form->{"taxnumber_$i"}"></td>
<td><input name="validto_$i" size=11 value="$form->{"validto_$i"}" title="$myconfig{dateformat}"></td>
<td><input name="pass_$i" size=6 value="$form->{"pass_$i"}"></td>
<td><select name="taxmodule_id_$i" size=1>|;
- foreach my $taxmodule (sort keys %$form) {
- next if ($taxmodule !~ /^taxmodule_/);
- next if ($taxmodule =~ /^taxmodule_id_/);
- my $modulenum = $taxmodule;
- $modulenum =~ s/^taxmodule_//;
- print '<option label="'.$form->{$taxmodule}.'" value="'.$modulenum . '"';
- print " SELECTED " if $form->{$taxmodule} eq $form->{"taxmodulename_$i"};
- print ">".$form->{$taxmodule}."</option>\n";
- }
- print qq|</select></td>
+ foreach my $taxmodule ( sort keys %$form ) {
+ next if ( $taxmodule !~ /^taxmodule_/ );
+ next if ( $taxmodule =~ /^taxmodule_id_/ );
+ my $modulenum = $taxmodule;
+ $modulenum =~ s/^taxmodule_//;
+ print '<option label="'
+ . $form->{$taxmodule}
+ . '" value="'
+ . $modulenum . '"';
+ print " SELECTED "
+ if $form->{$taxmodule} eq $form->{"taxmodulename_$i"};
+ print ">" . $form->{$taxmodule} . "</option>\n";
+ }
+ print qq|</select></td>
</tr> |;
- $sametax = $form->{"taxdescription_$i"};
-
- }
+ $sametax = $form->{"taxdescription_$i"};
- print qq|
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -1950,23 +2118,27 @@ sub display_taxes {
</table>
|;
- $form->hide_form(qw(taxaccounts path login sessionid));
- foreach my $taxmodule (sort keys %$form) {
- next if ($taxmodule !~ /^taxmodule_/);
- next if ($taxmodule =~ /^taxmodule_id_/);
- $form->hide_form("$taxmodule");
- }
-
- print qq|
-<button type="submit" class="submit" name="action" value="update">|.$locale->text('Update').qq|</button>
-<button type="submit" class="submit" name="action" value="save_taxes">|.$locale->text('Save').qq|</button>|;
+ $form->hide_form(qw(taxaccounts path login sessionid));
+ foreach my $taxmodule ( sort keys %$form ) {
+ next if ( $taxmodule !~ /^taxmodule_/ );
+ next if ( $taxmodule =~ /^taxmodule_id_/ );
+ $form->hide_form("$taxmodule");
+ }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ print qq|
+<button type="submit" class="submit" name="action" value="update">|
+ . $locale->text('Update')
+ . qq|</button>
+<button type="submit" class="submit" name="action" value="save_taxes">|
+ . $locale->text('Save')
+ . qq|</button>|;
+
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -1975,119 +2147,146 @@ sub display_taxes {
}
-
sub update {
- @a = split / /, $form->{taxaccounts};
- $ndx = $#a + 1;
-
- foreach $item (@a) {
- ($accno, $i) = split /_/, $item;
- push @t, $accno;
- $form->{"taxmodulename_$i"} = $form->{"taxmodule_".$form->{"taxmodule_id_$i"}};
-
- if ($form->{"validto_$i"}) {
- $j = $i + 1;
- if ($form->{"taxdescription_$i"} ne $form->{"taxdescription_$j"}) {
- #insert line
- for ($j = $ndx + 1; $j > $i; $j--) {
- $k = $j - 1;
- for (qw(taxrate taxdescription taxnumber validto)) { $form->{"${_}_$j"} = $form->{"${_}_$k"} }
- }
- $ndx++;
- $k = $i + 1;
- for (qw(taxdescription taxnumber)) { $form->{"${_}_$k"} = $form->{"${_}_$i"} }
- for (qw(taxrate validto)) { $form->{"${_}_$k"} = "" }
- push @t, $accno;
- }
- } else {
- # remove line
- $j = $i + 1;
- if ($form->{"taxdescription_$i"} eq $form->{"taxdescription_$j"}) {
- for ($j = $i + 1; $j <= $ndx; $j++) {
- $k = $j + 1;
- for (qw(taxrate taxdescription taxnumber validto)) { $form->{"${_}_$j"} = $form->{"${_}_$k"} }
- }
- $ndx--;
- splice @t, $i-1, 1;
- }
- }
-
- }
-
- $i = 1;
- $form->{taxaccounts} = "";
- for (@t) {
- $form->{taxaccounts} .= "${_}_$i ";
- $i++;
- }
- chop $form->{taxaccounts};
-
- &display_taxes;
-
-}
+ @a = split / /, $form->{taxaccounts};
+ $ndx = $#a + 1;
+
+ foreach $item (@a) {
+ ( $accno, $i ) = split /_/, $item;
+ push @t, $accno;
+ $form->{"taxmodulename_$i"} =
+ $form->{ "taxmodule_" . $form->{"taxmodule_id_$i"} };
+
+ if ( $form->{"validto_$i"} ) {
+ $j = $i + 1;
+ if ( $form->{"taxdescription_$i"} ne $form->{"taxdescription_$j"} )
+ {
+
+ #insert line
+ for ( $j = $ndx + 1 ; $j > $i ; $j-- ) {
+ $k = $j - 1;
+ for (qw(taxrate taxdescription taxnumber validto)) {
+ $form->{"${_}_$j"} = $form->{"${_}_$k"};
+ }
+ }
+ $ndx++;
+ $k = $i + 1;
+ for (qw(taxdescription taxnumber)) {
+ $form->{"${_}_$k"} = $form->{"${_}_$i"};
+ }
+ for (qw(taxrate validto)) { $form->{"${_}_$k"} = "" }
+ push @t, $accno;
+ }
+ }
+ else {
+
+ # remove line
+ $j = $i + 1;
+ if ( $form->{"taxdescription_$i"} eq $form->{"taxdescription_$j"} )
+ {
+ for ( $j = $i + 1 ; $j <= $ndx ; $j++ ) {
+ $k = $j + 1;
+ for (qw(taxrate taxdescription taxnumber validto)) {
+ $form->{"${_}_$j"} = $form->{"${_}_$k"};
+ }
+ }
+ $ndx--;
+ splice @t, $i - 1, 1;
+ }
+ }
+ }
+ $i = 1;
+ $form->{taxaccounts} = "";
+ for (@t) {
+ $form->{taxaccounts} .= "${_}_$i ";
+ $i++;
+ }
+ chop $form->{taxaccounts};
-sub config {
+ &display_taxes;
- foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
- $dateformat .= ($item eq $myconfig{dateformat}) ? "<option selected>$item\n" : "<option>$item\n";
- }
+}
- my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00);
- push @formats, '1 000.00';
- foreach $item (@formats) {
- $numberformat .= ($item eq $myconfig{numberformat}) ? "<option selected>$item\n" : "<option>$item\n";
- }
+sub config {
- for (qw(name company address signature)) { $myconfig{$_} = $form->quote($myconfig{$_}) }
- for (qw(address signature)) { $myconfig{$_} =~ s/\\n/\n/g }
+ foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd))
+ {
+ $dateformat .=
+ ( $item eq $myconfig{dateformat} )
+ ? "<option selected>$item\n"
+ : "<option>$item\n";
+ }
- %countrycodes = LedgerSMB::User->country_codes;
- $countrycodes = '';
- my $selectedcode = ($myconfig{countrycode}) ? $myconfig{countrycode} : 'en';
-
- foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
- $countrycodes .= ($selectedcode eq $key) ? "<option selected value=$key>$countrycodes{$key}\n" : "<option value=$key>$countrycodes{$key}\n";
- }
-
- opendir CSS, "css/.";
- @all = grep /.*\.css$/, readdir CSS;
- closedir CSS;
-
- foreach $item (@all) {
- if ($item eq $myconfig{stylesheet}) {
- $selectstylesheet .= qq|<option selected>$item\n|;
- } else {
- $selectstylesheet .= qq|<option>$item\n|;
- }
- }
- $selectstylesheet .= "<option>\n";
-
- if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
- $selectprinter = "<option>\n";
- foreach $item (sort keys %{LedgerSMB::Sysconfig::printer}) {
- if ($myconfig{printer} eq $item) {
- $selectprinter .= qq|<option value="$item" selected>$item\n|;
- } else {
- $selectprinter .= qq|<option value="$item">$item\n|;
- }
+ my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00);
+ push @formats, '1 000.00';
+ foreach $item (@formats) {
+ $numberformat .=
+ ( $item eq $myconfig{numberformat} )
+ ? "<option selected>$item\n"
+ : "<option>$item\n";
}
- $printer = qq|
+ for (qw(name company address signature)) {
+ $myconfig{$_} = $form->quote( $myconfig{$_} );
+ }
+ for (qw(address signature)) { $myconfig{$_} =~ s/\\n/\n/g }
+
+ %countrycodes = LedgerSMB::User->country_codes;
+ $countrycodes = '';
+ my $selectedcode =
+ ( $myconfig{countrycode} ) ? $myconfig{countrycode} : 'en';
+
+ foreach $key ( sort { $countrycodes{$a} cmp $countrycodes{$b} }
+ keys %countrycodes )
+ {
+ $countrycodes .=
+ ( $selectedcode eq $key )
+ ? "<option selected value=$key>$countrycodes{$key}\n"
+ : "<option value=$key>$countrycodes{$key}\n";
+ }
+
+ opendir CSS, "css/.";
+ @all = grep /.*\.css$/, readdir CSS;
+ closedir CSS;
+
+ foreach $item (@all) {
+ if ( $item eq $myconfig{stylesheet} ) {
+ $selectstylesheet .= qq|<option selected>$item\n|;
+ }
+ else {
+ $selectstylesheet .= qq|<option>$item\n|;
+ }
+ }
+ $selectstylesheet .= "<option>\n";
+
+ if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) {
+ $selectprinter = "<option>\n";
+ foreach $item ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
+ if ( $myconfig{printer} eq $item ) {
+ $selectprinter .= qq|<option value="$item" selected>$item\n|;
+ }
+ else {
+ $selectprinter .= qq|<option value="$item">$item\n|;
+ }
+ }
+
+ $printer = qq|
<tr>
- <th align="right">|.$locale->text('Printer').qq|</th>
+ <th align="right">| . $locale->text('Printer') . qq|</th>
<td><select name=printer>$selectprinter</select></td>
</tr>
|;
- }
-
- $form->{title} = $locale->text('Edit Preferences for [_1]', $form->{login});
-
- $form->header;
+ }
+
+ $form->{title} =
+ $locale->text( 'Edit Preferences for [_1]', $form->{login} );
- print qq|
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -2105,31 +2304,31 @@ sub config {
<td>
<table>
<tr>
- <th align="right">|.$locale->text('Name').qq|</th>
+ <th align="right">| . $locale->text('Name') . qq|</th>
<td><input name=name size=20 value="$myconfig{name}"></td>
</tr>
<tr>
- <th align="right">|.$locale->text('E-mail').qq|</th>
+ <th align="right">| . $locale->text('E-mail') . qq|</th>
<td><input name=email size=35 value="$myconfig{email}"></td>
</tr>
<tr valign=top>
- <th align="right">|.$locale->text('Signature').qq|</th>
+ <th align="right">| . $locale->text('Signature') . qq|</th>
<td><textarea name=signature rows=3 cols=35>$myconfig{signature}</textarea></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Phone').qq|</th>
+ <th align="right">| . $locale->text('Phone') . qq|</th>
<td><input name=tel size=14 value="$myconfig{tel}"></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Fax').qq|</th>
+ <th align="right">| . $locale->text('Fax') . qq|</th>
<td><input name=fax size=14 value="$myconfig{fax}"></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Company').qq|</th>
+ <th align="right">| . $locale->text('Company') . qq|</th>
<td><input name=company size=35 value="$myconfig{company}"></td>
</tr>
<tr valign=top>
- <th align="right">|.$locale->text('Address').qq|</th>
+ <th align="right">| . $locale->text('Address') . qq|</th>
<td><textarea name=address rows=4 cols=35>$myconfig{address}</textarea></td>
</tr>
</table>
@@ -2137,39 +2336,39 @@ sub config {
<td>
<table>
<tr>
- <th align="right">|.$locale->text('Password').qq|</th>
+ <th align="right">| . $locale->text('Password') . qq|</th>
<td><input type=password name=new_password size=10 value=$myconfig{password}></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Confirm').qq|</th>
+ <th align="right">| . $locale->text('Confirm') . qq|</th>
<td><input type=password name=confirm_password size=10></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Date Format').qq|</th>
+ <th align="right">| . $locale->text('Date Format') . qq|</th>
<td><select name=dateformat>$dateformat</select></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Number Format').qq|</th>
+ <th align="right">| . $locale->text('Number Format') . qq|</th>
<td><select name=numberformat>$numberformat</select></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Dropdown Limit').qq|</th>
+ <th align="right">| . $locale->text('Dropdown Limit') . qq|</th>
<td><input name=vclimit size=10 value="$myconfig{vclimit}"></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Menu Width').qq|</th>
+ <th align="right">| . $locale->text('Menu Width') . qq|</th>
<td><input name=menuwidth size=10 value="$myconfig{menuwidth}"></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Language').qq|</th>
+ <th align="right">| . $locale->text('Language') . qq|</th>
<td><select name=countrycode>$countrycodes</select></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Session Timeout').qq|</th>
+ <th align="right">| . $locale->text('Session Timeout') . qq|</th>
<td><input name=timeout size=10 value="$myconfig{timeout}"></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Stylesheet').qq|</th>
+ <th align="right">| . $locale->text('Stylesheet') . qq|</th>
<td><select name=usestylesheet>$selectstylesheet</select></td>
</tr>
$printer
@@ -2184,17 +2383,19 @@ sub config {
</table>
|;
- $form->hide_form(qw(path login sessionid));
-
- print qq|
-<button type="submit" class="submit" name="action" value="save">|.$locale->text('Save').qq|</button>|;
+ $form->hide_form(qw(path login sessionid));
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ print qq|
+<button type="submit" class="submit" name="action" value="save">|
+ . $locale->text('Save')
+ . qq|</button>|;
- print qq|
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
</form>
</body>
@@ -2203,84 +2404,91 @@ sub config {
}
-
sub save_defaults {
- if (AM->save_defaults(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Defaults saved!'));
- } else {
- $form->error($locale->text('Cannot save defaults!'));
- }
+ if ( AM->save_defaults( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Defaults saved!') );
+ }
+ else {
+ $form->error( $locale->text('Cannot save defaults!') );
+ }
}
-
sub save_taxes {
- if (AM->save_taxes(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Taxes saved!'));
- } else {
- $form->error($locale->text('Cannot save taxes!'));
- }
+ if ( AM->save_taxes( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Taxes saved!') );
+ }
+ else {
+ $form->error( $locale->text('Cannot save taxes!') );
+ }
}
-
sub save_preferences {
- $form->{stylesheet} = $form->{usestylesheet};
+ $form->{stylesheet} = $form->{usestylesheet};
- if ($form->{new_password} ne $form->{old_password}) {
- $form->error($locale->text('Password does not match!')) if $form->{new_password} ne $form->{confirm_password};
- }
+ if ( $form->{new_password} ne $form->{old_password} ) {
+ $form->error( $locale->text('Password does not match!') )
+ if $form->{new_password} ne $form->{confirm_password};
+ }
- if (AM->save_preferences(\%myconfig, \%$form)) {
- $form->info($locale->text('Preferences saved!'));
- } else {
- $form->error($locale->text('Cannot save preferences!'));
- }
+ if ( AM->save_preferences( \%myconfig, \%$form ) ) {
+ $form->info( $locale->text('Preferences saved!') );
+ }
+ else {
+ $form->error( $locale->text('Cannot save preferences!') );
+ }
}
-
sub backup {
- if ($form->{media} eq 'email') {
- $form->error($locale->text('No email address for [_1]', $myconfig{name})) unless ($myconfig{email});
- }
+ if ( $form->{media} eq 'email' ) {
+ $form->error(
+ $locale->text( 'No email address for [_1]', $myconfig{name} ) )
+ unless ( $myconfig{email} );
+ }
- $SIG{INT} = 'IGNORE';
- AM->backup(\%myconfig, \%$form, ${LedgerSMB::Sysconfig::userspath}, ${LedgerSMB::Sysconfig::gzip});
+ $SIG{INT} = 'IGNORE';
+ AM->backup(
+ \%myconfig, \%$form,
+ ${LedgerSMB::Sysconfig::userspath},
+ ${LedgerSMB::Sysconfig::gzip}
+ );
- if ($form->{media} eq 'email') {
- $form->redirect($locale->text('Backup sent to [_1]', $myconfig{email}));
- }
+ if ( $form->{media} eq 'email' ) {
+ $form->redirect(
+ $locale->text( 'Backup sent to [_1]', $myconfig{email} ) );
+ }
}
+sub audit_control {
+ $form->{title} = $locale->text('Audit Control');
-sub audit_control {
+ AM->closedto( \%myconfig, \%$form );
- $form->{title} = $locale->text('Audit Control');
+ if ( $form->{revtrans} ) {
+ $checked{revtransY} = "checked";
+ }
+ else {
+ $checked{revtransN} = "checked";
+ }
- AM->closedto(\%myconfig, \%$form);
-
- if ($form->{revtrans}) {
- $checked{revtransY} = "checked";
- } else {
- $checked{revtransN} = "checked";
- }
-
- if ($form->{audittrail}) {
- $checked{audittrailY} = "checked";
- } else {
- $checked{audittrailN} = "checked";
- }
-
- $form->header;
-
- print qq|
+ if ( $form->{audittrail} ) {
+ $checked{audittrailY} = "checked";
+ }
+ else {
+ $checked{audittrailN} = "checked";
+ }
+
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -2296,19 +2504,29 @@ sub audit_control {
<td>
<table>
<tr>
- <th align="right">|.$locale->text('Enforce transaction reversal for all dates').qq|</th>
- <td><input name=revtrans class=radio type=radio value="1" $checked{revtransY}> |.$locale->text('Yes').qq| <input name=revtrans class=radio type=radio value="0" $checked{revtransN}> |.$locale->text('No').qq|</td>
+ <th align="right">|
+ . $locale->text('Enforce transaction reversal for all dates')
+ . qq|</th>
+ <td><input name=revtrans class=radio type=radio value="1" $checked{revtransY}> |
+ . $locale->text('Yes')
+ . qq| <input name=revtrans class=radio type=radio value="0" $checked{revtransN}> |
+ . $locale->text('No')
+ . qq|</td>
</tr>
<tr>
- <th align="right">|.$locale->text('Close Books up to').qq|</th>
+ <th align="right">| . $locale->text('Close Books up to') . qq|</th>
<td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Activate Audit trail').qq|</th>
- <td><input name=audittrail class=radio type=radio value="1" $checked{audittrailY}> |.$locale->text('Yes').qq| <input name=audittrail class=radio type=radio value="0" $checked{audittrailN}> |.$locale->text('No').qq|</td>
+ <th align="right">| . $locale->text('Activate Audit trail') . qq|</th>
+ <td><input name=audittrail class=radio type=radio value="1" $checked{audittrailY}> |
+ . $locale->text('Yes')
+ . qq| <input name=audittrail class=radio type=radio value="0" $checked{audittrailN}> |
+ . $locale->text('No')
+ . qq|</td>
</tr>
<tr>
- <th align="right">|.$locale->text('Remove Audit trail up to').qq|</th>
+ <th align="right">| . $locale->text('Remove Audit trail up to') . qq|</th>
<td><input name=removeaudittrail size=11 title="$myconfig{dateformat}"></td>
</tr>
</table>
@@ -2321,7 +2539,9 @@ sub audit_control {
<br>
<input type=hidden name=nextsub value=doclose>
<input type=hidden name=action value=continue>
-<button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+<button type="submit" class="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
@@ -2331,86 +2551,94 @@ sub audit_control {
}
-
sub doclose {
- AM->closebooks(\%myconfig, \%$form);
-
- if ($form->{revtrans}) {
- $msg = $locale->text('Transaction reversal enforced for all dates');
- } else {
-
- if ($form->{closedto}) {
- $msg = $locale->text('Transaction reversal enforced up to')
- ." ".$locale->date(\%myconfig, $form->{closedto}, 1);
- } else {
- $msg = $locale->text('Books are open');
- }
- }
-
- $msg .= "<p>";
- if ($form->{audittrail}) {
- $msg .= $locale->text('Audit trail enabled');
- } else {
- $msg .= $locale->text('Audit trail disabled');
- }
-
- $msg .= "<p>";
- if ($form->{removeaudittrail}) {
- $msg .= $locale->text('Audit trail removed up to')
- ." ".$locale->date(\%myconfig, $form->{removeaudittrail}, 1);
- }
-
- $form->redirect($msg);
-
-}
+ AM->closebooks( \%myconfig, \%$form );
+ if ( $form->{revtrans} ) {
+ $msg = $locale->text('Transaction reversal enforced for all dates');
+ }
+ else {
+
+ if ( $form->{closedto} ) {
+ $msg =
+ $locale->text('Transaction reversal enforced up to') . " "
+ . $locale->date( \%myconfig, $form->{closedto}, 1 );
+ }
+ else {
+ $msg = $locale->text('Books are open');
+ }
+ }
-sub add_warehouse {
+ $msg .= "<p>";
+ if ( $form->{audittrail} ) {
+ $msg .= $locale->text('Audit trail enabled');
+ }
+ else {
+ $msg .= $locale->text('Audit trail disabled');
+ }
- $form->{title} = "Add";
-
- $form->{callback} = "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
+ $msg .= "<p>";
+ if ( $form->{removeaudittrail} ) {
+ $msg .=
+ $locale->text('Audit trail removed up to') . " "
+ . $locale->date( \%myconfig, $form->{removeaudittrail}, 1 );
+ }
- &warehouse_header;
- &form_footer;
+ $form->redirect($msg);
}
+sub add_warehouse {
+
+ $form->{title} = "Add";
+
+ $form->{callback} =
+"$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
+
+ &warehouse_header;
+ &form_footer;
+
+}
sub edit_warehouse {
- $form->{title} = "Edit";
+ $form->{title} = "Edit";
- AM->get_warehouse(\%myconfig, \%$form);
+ AM->get_warehouse( \%myconfig, \%$form );
- &warehouse_header;
- &form_footer;
+ &warehouse_header;
+ &form_footer;
}
-
sub list_warehouse {
- AM->warehouses(\%myconfig, \%$form);
+ AM->warehouses( \%myconfig, \%$form );
- $href = "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+ $href =
+"$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- $form->sort_order();
-
- $form->{callback} = "$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+ $form->sort_order();
- $callback = $form->escape($form->{callback});
-
- $form->{title} = $locale->text('Warehouses');
+ $form->{callback} =
+"$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+
+ $callback = $form->escape( $form->{callback} );
+
+ $form->{title} = $locale->text('Warehouses');
- @column_index = qw(description);
+ @column_index = qw(description);
- $column_header{description} = qq|<th width=100%><a class="listheading" href=$href>|.$locale->text('Description').qq|</a></th>|;
+ $column_header{description} =
+ qq|<th width=100%><a class="listheading" href=$href>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<table width=100%>
@@ -2424,30 +2652,32 @@ sub list_warehouse {
<tr class="listheading">
|;
- for (@column_index) { print "$column_header{$_}\n" }
+ for (@column_index) { print "$column_header{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
- foreach $ref (@{ $form->{ALL} }) {
-
- $i++; $i %= 2;
-
- print qq|
+ foreach $ref ( @{ $form->{ALL} } ) {
+
+ $i++;
+ $i %= 2;
+
+ print qq|
<tr valign=top class=listrow$i>
|;
- $column_data{description} = qq|<td><a href=$form->{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
+ $column_data{description} =
+qq|<td><a href=$form->{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</td>|;
- for (@column_index) { print "$column_data{$_}\n" }
+ for (@column_index) { print "$column_data{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
- }
+ }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -2460,48 +2690,50 @@ sub list_warehouse {
<form method=post action=$form->{script}>
|;
- $form->{type} = "warehouse";
+ $form->{type} = "warehouse";
- $form->hide_form(qw(type callback path login sessionid));
-
- print qq|
-<button class="submit" type="submit" name="action" value="add_warehouse">|.$locale->text('Add Warehouse').qq|</button>|;
+ $form->hide_form(qw(type callback path login sessionid));
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ print qq|
+<button class="submit" type="submit" name="action" value="add_warehouse">|
+ . $locale->text('Add Warehouse')
+ . qq|</button>|;
- print qq|
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
</form>
</body>
</html>
|;
-
-}
-
+}
sub warehouse_header {
- $form->{title} = $locale->text("$form->{title} Warehouse");
+ $form->{title} = $locale->text("$form->{title} Warehouse");
-# $locale->text('Add Warehouse')
-# $locale->text('Edit Warehouse')
+ # $locale->text('Add Warehouse')
+ # $locale->text('Edit Warehouse')
- $form->{description} = $form->quote($form->{description});
+ $form->{description} = $form->quote( $form->{description} );
- if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
- $description = qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
- } else {
- $description = qq|<input name=description size=60 value="$form->{description}">|;
- }
+ if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) {
+ $description =
+qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
+ }
+ else {
+ $description =
+ qq|<input name=description size=60 value="$form->{description}">|;
+ }
-
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -2515,7 +2747,7 @@ sub warehouse_header {
</tr>
<tr height="5"></tr>
<tr>
- <th align="right">|.$locale->text('Description').qq|</th>
+ <th align="right">| . $locale->text('Description') . qq|</th>
<td>$description</td>
</tr>
<tr>
@@ -2526,34 +2758,33 @@ sub warehouse_header {
}
-
sub save_warehouse {
- $form->isblank("description", $locale->text('Description missing!'));
- AM->save_warehouse(\%myconfig, \%$form);
- $form->redirect($locale->text('Warehouse saved!'));
+ $form->isblank( "description", $locale->text('Description missing!') );
+ AM->save_warehouse( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Warehouse saved!') );
}
-
sub delete_warehouse {
- AM->delete_warehouse(\%myconfig, \%$form);
- $form->redirect($locale->text('Warehouse deleted!'));
+ AM->delete_warehouse( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Warehouse deleted!') );
}
-
sub yearend {
- AM->earningsaccounts(\%myconfig, \%$form);
- $chart = "";
- for (@{ $form->{chart} }) { $chart .= "<option>$_->{accno}--$_->{description}" }
-
- $form->{title} = $locale->text('Yearend');
- $form->header;
-
- print qq|
+ AM->earningsaccounts( \%myconfig, \%$form );
+ $chart = "";
+ for ( @{ $form->{chart} } ) {
+ $chart .= "<option>$_->{accno}--$_->{description}";
+ }
+
+ $form->{title} = $locale->text('Yearend');
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -2570,24 +2801,30 @@ sub yearend {
<td>
<table>
<tr>
- <th align="right">|.$locale->text('Yearend').qq|</th>
+ <th align="right">| . $locale->text('Yearend') . qq|</th>
<td><input name=todate size=11 title="$myconfig{dateformat}" value=$todate></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Reference').qq|</th>
- <td><input name=reference size=20 value="|.$locale->text('Yearend').qq|"></td>
+ <th align="right">| . $locale->text('Reference') . qq|</th>
+ <td><input name=reference size=20 value="|
+ . $locale->text('Yearend')
+ . qq|"></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Description').qq|</th>
+ <th align="right">| . $locale->text('Description') . qq|</th>
<td><textarea name=description rows=3 cols=50 wrap=soft></textarea></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Retained Earnings').qq|</th>
+ <th align="right">| . $locale->text('Retained Earnings') . qq|</th>
<td><select name=accno>$chart</select></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Method').qq|</th>
- <td><input name=method class=radio type=radio value=accrual checked>&nbsp;|.$locale->text('Accrual').qq|&nbsp;<input name=method class=radio type=radio value=cash>&nbsp;|.$locale->text('Cash').qq|</td>
+ <th align="right">| . $locale->text('Method') . qq|</th>
+ <td><input name=method class=radio type=radio value=accrual checked>&nbsp;|
+ . $locale->text('Accrual')
+ . qq|&nbsp;<input name=method class=radio type=radio value=cash>&nbsp;|
+ . $locale->text('Cash')
+ . qq|</td>
</tr>
</table>
</td>
@@ -2599,79 +2836,81 @@ sub yearend {
<input type=hidden name=nextsub value=generate_yearend>
|;
- $form->hide_form(qw(path login sessionid));
-
- print qq|
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>|;
+ $form->hide_form(qw(path login sessionid));
-}
+ print qq|
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>|;
+}
sub generate_yearend {
- $form->isblank("todate", $locale->text('Yearend date missing!'));
+ $form->isblank( "todate", $locale->text('Yearend date missing!') );
- RP->yearend_statement(\%myconfig, \%$form);
-
- $form->{transdate} = $form->{todate};
+ RP->yearend_statement( \%myconfig, \%$form );
- $earnings = 0;
-
- $form->{rowcount} = 1;
- foreach $key (keys %{ $form->{I} }) {
- if ($form->{I}{$key}{charttype} eq "A") {
- $form->{"debit_$form->{rowcount}"} = $form->{I}{$key}{this};
- $earnings += $form->{I}{$key}{this};
- $form->{"accno_$form->{rowcount}"} = $key;
- $form->{rowcount}++;
- $ok = 1;
- }
- }
-
- foreach $key (keys %{ $form->{E} }) {
- if ($form->{E}{$key}{charttype} eq "A") {
- $form->{"credit_$form->{rowcount}"} = $form->{E}{$key}{this} * -1;
- $earnings += $form->{E}{$key}{this};
- $form->{"accno_$form->{rowcount}"} = $key;
- $form->{rowcount}++;
- $ok = 1;
- }
- }
- if ($earnings > 0) {
- $form->{"credit_$form->{rowcount}"} = $earnings;
- $form->{"accno_$form->{rowcount}"} = $form->{accno}
- } else {
- $form->{"debit_$form->{rowcount}"} = $earnings * -1;
- $form->{"accno_$form->{rowcount}"} = $form->{accno}
- }
-
- if ($ok) {
- if (AM->post_yearend(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Yearend posted!'));
- } else {
- $form->error($locale->text('Yearend posting failed!'));
- }
- } else {
- $form->error('Nothing to do!');
- }
-
-}
+ $form->{transdate} = $form->{todate};
+
+ $earnings = 0;
+
+ $form->{rowcount} = 1;
+ foreach $key ( keys %{ $form->{I} } ) {
+ if ( $form->{I}{$key}{charttype} eq "A" ) {
+ $form->{"debit_$form->{rowcount}"} = $form->{I}{$key}{this};
+ $earnings += $form->{I}{$key}{this};
+ $form->{"accno_$form->{rowcount}"} = $key;
+ $form->{rowcount}++;
+ $ok = 1;
+ }
+ }
+
+ foreach $key ( keys %{ $form->{E} } ) {
+ if ( $form->{E}{$key}{charttype} eq "A" ) {
+ $form->{"credit_$form->{rowcount}"} = $form->{E}{$key}{this} * -1;
+ $earnings += $form->{E}{$key}{this};
+ $form->{"accno_$form->{rowcount}"} = $key;
+ $form->{rowcount}++;
+ $ok = 1;
+ }
+ }
+ if ( $earnings > 0 ) {
+ $form->{"credit_$form->{rowcount}"} = $earnings;
+ $form->{"accno_$form->{rowcount}"} = $form->{accno};
+ }
+ else {
+ $form->{"debit_$form->{rowcount}"} = $earnings * -1;
+ $form->{"accno_$form->{rowcount}"} = $form->{accno};
+ }
+ if ($ok) {
+ if ( AM->post_yearend( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Yearend posted!') );
+ }
+ else {
+ $form->error( $locale->text('Yearend posting failed!') );
+ }
+ }
+ else {
+ $form->error('Nothing to do!');
+ }
+}
sub company_logo {
-
- $myconfig{address} =~ s/\\n/<br>/g;
- $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
- $form->{stylesheet} = $myconfig{stylesheet};
+ $myconfig{address} =~ s/\\n/<br>/g;
+ $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
- $form->{title} = $locale->text('About');
-
- # create the logo screen
- $form->header;
+ $form->{stylesheet} = $myconfig{stylesheet};
+
+ $form->{title} = $locale->text('About');
+
+ # create the logo screen
+ $form->header;
- print qq|
+ print qq|
<body>
<pre>
@@ -2679,7 +2918,7 @@ sub company_logo {
</pre>
<center>
<a href="http://www.ledgersmb.org/" target="_blank"><img src="images/ledgersmb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
-<h1 class="login">|.$locale->text('Version').qq| $form->{version}</h1>
+<h1 class="login">| . $locale->text('Version') . qq| $form->{version}</h1>
<p>
|.$locale->text('Company').qq| :
@@ -2692,15 +2931,15 @@ $myconfig{company}
<p>
<table border=0>
<tr>
- <th align="right">|.$locale->text('User').qq|</th>
+ <th align="right">| . $locale->text('User') . qq|</th>
<td>$myconfig{name}</td>
</tr>
<tr>
- <th align="right">|.$locale->text('Dataset').qq|</th>
+ <th align="right">| . $locale->text('Dataset') . qq|</th>
<td>$myconfig{dbname}</td>
</tr>
<tr>
- <th align="right">|.$locale->text('Database Host').qq|</th>
+ <th align="right">| . $locale->text('Database Host') . qq|</th>
<td>$myconfig{dbhost}</td>
</tr>
</table>
@@ -2713,52 +2952,70 @@ $myconfig{company}
}
-
sub recurring_transactions {
-# $locale->text('Day')
-# $locale->text('Days')
-# $locale->text('Month')
-# $locale->text('Months')
-# $locale->text('Week')
-# $locale->text('Weeks')
-# $locale->text('Year')
-# $locale->text('Years')
+ # $locale->text('Day')
+ # $locale->text('Days')
+ # $locale->text('Month')
+ # $locale->text('Months')
+ # $locale->text('Week')
+ # $locale->text('Weeks')
+ # $locale->text('Year')
+ # $locale->text('Years')
- $form->{stylesheet} = $myconfig{stylesheet};
+ $form->{stylesheet} = $myconfig{stylesheet};
- $form->{title} = $locale->text('Recurring Transactions');
+ $form->{title} = $locale->text('Recurring Transactions');
- $column_header{id} = "";
+ $column_header{id} = "";
- AM->recurring_transactions(\%myconfig, \%$form);
+ AM->recurring_transactions( \%myconfig, \%$form );
- $href = "$form->{script}?action=recurring_transactions";
- for (qw(direction oldsort path login sessionid)) { $href .= qq|&$_=$form->{$_}| }
-
- $form->sort_order();
-
- # create the logo screen
- $form->header;
+ $href = "$form->{script}?action=recurring_transactions";
+ for (qw(direction oldsort path login sessionid)) {
+ $href .= qq|&$_=$form->{$_}|;
+ }
- @column_index = qw(ndx reference description);
-
- push @column_index, qw(nextdate enddate id amount curr repeat howmany recurringemail recurringprint);
-
- $column_header{reference} = qq|<th><a class="listheading" href="$href&sort=reference">|.$locale->text('Reference').q|</a></th>|;
- $column_header{ndx} = q|<th class="listheading">&nbsp;</th>|;
- $column_header{id} = q|<th class="listheading">|.$locale->text('ID').q|</th>|;
- $column_header{description} = q|<th class="listheading">|.$locale->text('Description').q|</th>|;
- $column_header{nextdate} = qq|<th><a class="listheading" href="$href&sort=nextdate">|.$locale->text('Next').q|</a></th>|;
- $column_header{enddate} = qq|<th><a class="listheading" href="$href&sort=enddate">|.$locale->text('Ends').q|</a></th>|;
- $column_header{amount} = q|<th class="listheading">|.$locale->text('Amount').q|</th>|;
- $column_header{curr} = q|<th class="listheading">&nbsp;</th>|;
- $column_header{repeat} = q|<th class="listheading">|.$locale->text('Every').q|</th>|;
- $column_header{howmany} = q|<th class="listheading">|.$locale->text('Times').q|</th>|;
- $column_header{recurringemail} = q|<th class="listheading">|.$locale->text('E-mail').q|</th>|;
- $column_header{recurringprint} = q|<th class="listheading">|.$locale->text('Print').q|</th>|;
-
-print qq|
+ $form->sort_order();
+
+ # create the logo screen
+ $form->header;
+
+ @column_index = qw(ndx reference description);
+
+ push @column_index,
+ qw(nextdate enddate id amount curr repeat howmany recurringemail recurringprint);
+
+ $column_header{reference} =
+ qq|<th><a class="listheading" href="$href&sort=reference">|
+ . $locale->text('Reference')
+ . q|</a></th>|;
+ $column_header{ndx} = q|<th class="listheading">&nbsp;</th>|;
+ $column_header{id} =
+ q|<th class="listheading">| . $locale->text('ID') . q|</th>|;
+ $column_header{description} =
+ q|<th class="listheading">| . $locale->text('Description') . q|</th>|;
+ $column_header{nextdate} =
+ qq|<th><a class="listheading" href="$href&sort=nextdate">|
+ . $locale->text('Next')
+ . q|</a></th>|;
+ $column_header{enddate} =
+ qq|<th><a class="listheading" href="$href&sort=enddate">|
+ . $locale->text('Ends')
+ . q|</a></th>|;
+ $column_header{amount} =
+ q|<th class="listheading">| . $locale->text('Amount') . q|</th>|;
+ $column_header{curr} = q|<th class="listheading">&nbsp;</th>|;
+ $column_header{repeat} =
+ q|<th class="listheading">| . $locale->text('Every') . q|</th>|;
+ $column_header{howmany} =
+ q|<th class="listheading">| . $locale->text('Times') . q|</th>|;
+ $column_header{recurringemail} =
+ q|<th class="listheading">| . $locale->text('E-mail') . q|</th>|;
+ $column_header{recurringprint} =
+ q|<th class="listheading">| . $locale->text('Print') . q|</th>|;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -2774,100 +3031,122 @@ print qq|
<tr class="listheading">
|;
- for (@column_index) { print "\n$column_header{$_}" }
+ for (@column_index) { print "\n$column_header{$_}" }
- print qq|
+ print qq|
</tr>
|;
- $i = 1;
- $colspan = $#column_index + 1;
+ $i = 1;
+ $colspan = $#column_index + 1;
- %tr = ( ar => $locale->text('AR'),
- ap => $locale->text('AP'),
- gl => $locale->text('GL'),
- so => $locale->text('Sales Orders'),
- po => $locale->text('Purchase Orders'),
- );
+ %tr = (
+ ar => $locale->text('AR'),
+ ap => $locale->text('AP'),
+ gl => $locale->text('GL'),
+ so => $locale->text('Sales Orders'),
+ po => $locale->text('Purchase Orders'),
+ );
- %f = &formnames;
-
- foreach $transaction (sort keys %{ $form->{transactions} }) {
- print qq|
+ %f = &formnames;
+
+ foreach $transaction ( sort keys %{ $form->{transactions} } ) {
+ print qq|
<tr>
<th class="listheading" colspan=$colspan>$tr{$transaction}</th>
</tr>
|;
-
- foreach $ref (@{ $form->{transactions}{$transaction} }) {
-
- for (@column_index) { $column_data{$_} = "<td nowrap>$ref->{$_}</td>" }
-
- if ($ref->{repeat} > 1) {
- $unit = $locale->text(ucfirst $ref->{unit});
- $repeat = "$ref->{repeat} $unit";
- } else {
- chop $ref->{unit};
- $unit = $locale->text(ucfirst $ref->{unit});
- $repeat = $unit;
- }
-
- $column_data{ndx} = qq|<td></td>|;
-
- if (!$ref->{expired}) {
- if ($ref->{overdue} <= 0) {
- $k++;
- $column_data{ndx} = qq|<td nowrap><input name="ndx_$k" class=checkbox type=checkbox value=$ref->{id} checked></td>|;
- }
- }
-
- $reference = ($ref->{reference}) ? $ref->{reference} : $locale->text('Next Number');
- $column_data{reference} = qq|<td nowrap><a href=$form->{script}?action=edit_recurring&id=$ref->{id}&vc=$ref->{vc}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&module=$ref->{module}&invoice=$ref->{invoice}&transaction=$ref->{transaction}&recurringnextdate=$ref->{nextdate}>$reference</a></td>|;
-
- $module = "$ref->{module}.pl";
- $type = "";
- if ($ref->{module} eq 'ar') {
- $module = "is.pl" if $ref->{invoice};
- $ref->{amount} /= $ref->{exchangerate};
- }
- if ($ref->{module} eq 'ap') {
- $module = "ir.pl" if $ref->{invoice};
- $ref->{amount} /= $ref->{exchangerate};
- }
- if ($ref->{module} eq 'oe') {
- $type = ($ref->{vc} eq 'customer') ? "sales_order" : "purchase_order";
- }
-
- $column_data{id} = qq|<td><a href="$module?action=edit&id=$ref->{id}&vc=$ref->{vc}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$type&readonly=1">$ref->{id}</a></td>|;
-
- $column_data{repeat} = qq|<td align="right" nowrap>$repeat</td>|;
- $column_data{howmany} = qq|<td align="right" nowrap>|.$form->format_amount(\%myconfig, $ref->{howmany})."</td>";
- $column_data{amount} = qq|<td align="right" nowrap>|.$form->format_amount(\%myconfig, $ref->{amount}, 2)."</td>";
-
- $column_data{recurringemail} = "<td nowrap>";
- @f = split /:/, $ref->{recurringemail};
- for (0 .. $#f) { $column_data{recurringemail} .= "$f{$f[$_]}<br>" }
- $column_data{recurringemail} .= "</td>";
-
- $column_data{recurringprint} = "<td nowrap>";
- @f = split /:/, $ref->{recurringprint};
- for (0 .. $#f) { $column_data{recurringprint} .= "$f{$f[$_]}<br>" }
- $column_data{recurringprint} .= "</td>";
-
- $j++; $j %= 2;
- print qq|
+
+ foreach $ref ( @{ $form->{transactions}{$transaction} } ) {
+
+ for (@column_index) {
+ $column_data{$_} = "<td nowrap>$ref->{$_}</td>";
+ }
+
+ if ( $ref->{repeat} > 1 ) {
+ $unit = $locale->text( ucfirst $ref->{unit} );
+ $repeat = "$ref->{repeat} $unit";
+ }
+ else {
+ chop $ref->{unit};
+ $unit = $locale->text( ucfirst $ref->{unit} );
+ $repeat = $unit;
+ }
+
+ $column_data{ndx} = qq|<td></td>|;
+
+ if ( !$ref->{expired} ) {
+ if ( $ref->{overdue} <= 0 ) {
+ $k++;
+ $column_data{ndx} =
+qq|<td nowrap><input name="ndx_$k" class=checkbox type=checkbox value=$ref->{id} checked></td>|;
+ }
+ }
+
+ $reference =
+ ( $ref->{reference} )
+ ? $ref->{reference}
+ : $locale->text('Next Number');
+ $column_data{reference} =
+qq|<td nowrap><a href=$form->{script}?action=edit_recurring&id=$ref->{id}&vc=$ref->{vc}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&module=$ref->{module}&invoice=$ref->{invoice}&transaction=$ref->{transaction}&recurringnextdate=$ref->{nextdate}>$reference</a></td>|;
+
+ $module = "$ref->{module}.pl";
+ $type = "";
+ if ( $ref->{module} eq 'ar' ) {
+ $module = "is.pl" if $ref->{invoice};
+ $ref->{amount} /= $ref->{exchangerate};
+ }
+ if ( $ref->{module} eq 'ap' ) {
+ $module = "ir.pl" if $ref->{invoice};
+ $ref->{amount} /= $ref->{exchangerate};
+ }
+ if ( $ref->{module} eq 'oe' ) {
+ $type =
+ ( $ref->{vc} eq 'customer' )
+ ? "sales_order"
+ : "purchase_order";
+ }
+
+ $column_data{id} =
+qq|<td><a href="$module?action=edit&id=$ref->{id}&vc=$ref->{vc}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$type&readonly=1">$ref->{id}</a></td>|;
+
+ $column_data{repeat} = qq|<td align="right" nowrap>$repeat</td>|;
+ $column_data{howmany} =
+ qq|<td align="right" nowrap>|
+ . $form->format_amount( \%myconfig, $ref->{howmany} ) . "</td>";
+ $column_data{amount} =
+ qq|<td align="right" nowrap>|
+ . $form->format_amount( \%myconfig, $ref->{amount}, 2 ) . "</td>";
+
+ $column_data{recurringemail} = "<td nowrap>";
+ @f = split /:/, $ref->{recurringemail};
+ for ( 0 .. $#f ) {
+ $column_data{recurringemail} .= "$f{$f[$_]}<br>";
+ }
+ $column_data{recurringemail} .= "</td>";
+
+ $column_data{recurringprint} = "<td nowrap>";
+ @f = split /:/, $ref->{recurringprint};
+ for ( 0 .. $#f ) {
+ $column_data{recurringprint} .= "$f{$f[$_]}<br>";
+ }
+ $column_data{recurringprint} .= "</td>";
+
+ $j++;
+ $j %= 2;
+ print qq|
<tr class=listrow$j>
|;
- for (@column_index) { print "\n$column_data{$_}" }
+ for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ print qq|
</tr>
|;
+ }
}
- }
- print qq|
+ print qq|
</tr>
</table>
</td>
@@ -2880,17 +3159,20 @@ print qq|
<input name=lastndx type=hidden value=$k>
|;
- $form->hide_form(qw(path login sessionid));
+ $form->hide_form(qw(path login sessionid));
- print qq|
-<button class="submit" type="submit" name="action" value="process_transactions">|.$locale->text('Process Transactions').qq|</button>| if $k;
+ print qq|
+<button class="submit" type="submit" name="action" value="process_transactions">|
+ . $locale->text('Process Transactions')
+ . qq|</button>|
+ if $k;
+
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
+ print qq|
</form>
</body>
@@ -2899,401 +3181,514 @@ print qq|
}
-
sub edit_recurring {
- %links = ( ar => 'create_links',
- ap => 'create_links',
- gl => 'create_links',
- is => 'invoice_links',
- ir => 'invoice_links',
- oe => 'order_links',
- );
- %prepare = ( is => 'prepare_invoice',
- ir => 'prepare_invoice',
- oe => 'prepare_order',
- );
-
- $form->{callback} = "$form->{script}?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- $form->{type} = "transaction";
-
- if ($form->{module} eq 'ar') {
- if ($form->{invoice}) {
- $form->{type} = "invoice";
- $form->{module} = "is";
- }
- }
- if ($form->{module} eq 'ap') {
- if ($form->{invoice}) {
- $form->{type} = "invoice";
- $form->{module} = "ir";
- }
- }
-
- if ($form->{module} eq 'oe') {
- %tr = ( so => sales_order,
- po => purchase_order,
- );
-
- $form->{type} = $tr{$form->{transaction}};
- }
+ %links = (
+ ar => 'create_links',
+ ap => 'create_links',
+ gl => 'create_links',
+ is => 'invoice_links',
+ ir => 'invoice_links',
+ oe => 'order_links',
+ );
+ %prepare = (
+ is => 'prepare_invoice',
+ ir => 'prepare_invoice',
+ oe => 'prepare_order',
+ );
+
+ $form->{callback} =
+"$form->{script}?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+
+ $form->{type} = "transaction";
+
+ if ( $form->{module} eq 'ar' ) {
+ if ( $form->{invoice} ) {
+ $form->{type} = "invoice";
+ $form->{module} = "is";
+ }
+ }
+ if ( $form->{module} eq 'ap' ) {
+ if ( $form->{invoice} ) {
+ $form->{type} = "invoice";
+ $form->{module} = "ir";
+ }
+ }
- $form->{script} = "$form->{module}.pl";
- do "bin/$form->{script}";
+ if ( $form->{module} eq 'oe' ) {
+ %tr = (
+ so => sales_order,
+ po => purchase_order,
+ );
- &{ $links{$form->{module}} };
-
- # return if transaction doesn't exist
- $form->redirect unless $form->{recurring};
-
- if ($prepare{$form->{module}}) {
- &{ $prepare{$form->{module}} };
- }
-
- $form->{selectformat} = qq|<option value="html">html\n|;
- if (${LedgerSMB::Sysconfig::latex}) {
- $form->{selectformat} .= qq|
- <option value="postscript">|.$locale->text('Postscript').qq|
- <option value="pdf">|.$locale->text('PDF');
- }
+ $form->{type} = $tr{ $form->{transaction} };
+ }
- &schedule;
-
-}
+ $form->{script} = "$form->{module}.pl";
+ do "bin/$form->{script}";
+ &{ $links{ $form->{module} } };
-sub process_transactions {
+ # return if transaction doesn't exist
+ $form->redirect unless $form->{recurring};
- # save variables
- my $pt = new Form;
- for (keys %$form) { $pt->{$_} = $form->{$_} }
+ if ( $prepare{ $form->{module} } ) {
+ &{ $prepare{ $form->{module} } };
+ }
- my $defaultprinter;
- while (my ($key, $value) = each %{LedgerSMB::Sysconfig::printer}) {
- if ($value =~ /lpr/) {
- $defaultprinter = $key;
- last;
+ $form->{selectformat} = qq|<option value="html">html\n|;
+ if ( ${LedgerSMB::Sysconfig::latex} ) {
+ $form->{selectformat} .= qq|
+ <option value="postscript">| . $locale->text('Postscript') . qq|
+ <option value="pdf">| . $locale->text('PDF');
}
- }
- $myconfig{vclimit} = 0;
- %f = &formnames;
-
- for (my $i = 1; $i <= $pt->{lastndx}; $i++) {
- if ($pt->{"ndx_$i"}) {
- $id = $pt->{"ndx_$i"};
-
- # process transaction
- AM->recurring_details(\%myconfig, \%$pt, $id);
-
- $header = $form->{header};
- # reset $form
- for (keys %$form) { delete $form->{$_}; }
- for (qw(login path sessionid stylesheet timeout)) { $form->{$_} = $pt->{$_}; }
- $form->{id} = $id;
- $form->{header} = $header;
-
- # post, print, email
- if ($pt->{arid} || $pt->{apid} || $pt->{oeid}) {
- if ($pt->{arid} || $pt->{apid}) {
- if ($pt->{arid}) {
- $form->{script} = ($pt->{invoice}) ? "is.pl" : "ar.pl";
- $form->{ARAP} = "AR";
- $form->{module} = "ar";
- $invfld = "sinumber";
- } else {
- $form->{script} = ($pt->{invoice}) ? "ir.pl" : "ap.pl";
- $form->{ARAP} = "AP";
- $form->{module} = "ap";
- $invfld = "vinumber";
- }
- do "bin/$form->{script}";
-
- if ($pt->{invoice}) {
- &invoice_links;
- &prepare_invoice;
-
- for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) }
-
- } else {
- &create_links;
-
- $form->{type} = "transaction";
- for (1 .. $form->{rowcount} - 1) { $form->{"amount_$_"} = $form->format_amount(\%myconfig, $form->{"amount_$_"}, 2) }
- for (1 .. $form->{paidaccounts}) { $form->{"paid_$_"} = $form->format_amount(\%myconfig, $form->{"paid_$_"}, 2) }
-
- }
-
- delete $form->{"$form->{ARAP}_links"};
- for (qw(acc_trans invoice_details)) { delete $form->{$_} }
- for (qw(department employee language month partsgroup project years)) { delete $form->{"all_$_"} }
-
- $form->{invnumber} = $pt->{reference};
- $form->{transdate} = $pt->{nextdate};
-
- # tax accounts
- $form->all_taxaccounts(\%myconfig, undef, $form->{transdate});
-
- # calculate duedate
- $form->{duedate} = $form->add_date(\%myconfig, $form->{transdate}, $pt->{overdue}, "days");
-
- if ($pt->{payment}) {
- # calculate date paid
- for ($j = 1; $j <= $form->{paidaccounts}; $j++) {
- $form->{"datepaid_$j"} = $form->add_date(\%myconfig, $form->{transdate}, $pt->{paid}, "days");
-
- ($form->{"$form->{ARAP}_paid_$j"}) = split /--/, $form->{"$form->{ARAP}_paid_$j"};
- delete $form->{"cleared_$j"};
- }
-
- $form->{paidaccounts}++;
- } else {
- $form->{paidaccounts} = -1;
- }
-
- for (qw(id recurring intnotes printed emailed queued)) { delete $form->{$_} }
-
- ($form->{$form->{ARAP}}) = split /--/, $form->{$form->{ARAP}};
-
- $form->{invnumber} = $form->update_defaults(\%myconfig, "$invfld") unless $form->{invnumber};
- $form->{reference} = $form->{invnumber};
- for (qw(invnumber reference)) { $form->{$_} = $form->unquote($form->{$_}) }
-
- if ($pt->{invoice}) {
- if ($pt->{arid}) {
- $form->info("\n".$locale->text('Posting Sales Invoice [_1]', $form->{invnumber}));
- $ok = IS->post_invoice(\%myconfig, \%$form);
- } else {
- $form->info("\n".$locale->text('Posting Vendor Invoice [_1]', $form->{invnumber}));
- $ok = IR->post_invoice(\%myconfig, \%$form);
- }
- } else {
- if ($pt->{arid}) {
- $form->info("\n".$locale->text('Posting Transaction [_1]', $form->{invnumber}));
- } else {
- $form->info("\n".$locale->text('Posting Transaction [_1]', $form->{invnumber}));
- }
-
- $ok = AA->post_transaction(\%myconfig, \%$form);
-
- }
- $form->info(" ..... ".$locale->text('done'));
-
- # print form
- if (${LedgerSMB::Sysconfig::latex} && $ok) {
- $ok = &print_recurring(\%$pt, $defaultprinter);
- }
-
- &email_recurring(\%$pt) if $ok;
-
- } else {
-
- # order
- $form->{script} = "oe.pl";
- $form->{module} = "oe";
-
- $ordnumber = "ordnumber";
- if ($pt->{customer_id}) {
- $form->{vc} = "customer";
- $form->{type} = "sales_order";
- $ordfld = "sonumber";
- $flabel = $locale->text('Sales Order');
- } else {
- $form->{vc} = "vendor";
- $form->{type} = "purchase_order";
- $ordfld = "ponumber";
- $flabel = $locale->text('Purchase Order');
- }
- require "bin/$form->{script}";
-
- &order_links;
- &prepare_order;
-
- for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) }
-
- $form->{$ordnumber} = $pt->{reference};
- $form->{transdate} = $pt->{nextdate};
-
- # calculate reqdate
- $form->{reqdate} = $form->add_date(\%myconfig, $form->{transdate}, $pt->{req}, "days") if $form->{reqdate};
-
- for (qw(id recurring intnotes printed emailed queued)) { delete $form->{$_} }
- for (1 .. $form->{rowcount}) { delete $form->{"orderitems_id_$_"} }
-
- $form->{$ordnumber} = $form->update_defaults(\%myconfig, "$ordfld") unless $form->{$ordnumber};
- $form->{reference} = $form->{$ordnumber};
- for ("$ordnumber", "reference") { $form->{$_} = $form->unquote($form->{$_}) }
- $form->{closed} = 0;
-
- $form->info("\n".$locale->text('Saving [_1] [_2]', $flabel, $form->{$ordnumber}));
- if ($ok = OE->save(\%myconfig, \%$form)) {
- $form->info(" ..... ".$locale->text('done'));
- } else {
- $form->info(" ..... ".$locale->text('failed'));
- }
-
- # print form
- if (${LedgerSMB::Sysconfig::latex} && $ok) {
- &print_recurring(\%$pt, $defaultprinter);
- }
-
- &email_recurring(\%$pt);
-
- }
-
- } else {
- # GL transaction
- GL->transaction(\%myconfig, \%$form);
-
- $form->{reference} = $pt->{reference};
- $form->{transdate} = $pt->{nextdate};
-
- $j = 1;
- foreach $ref (@{ $form->{GL} }) {
- $form->{"accno_$j"} = "$ref->{accno}--$ref->{description}";
-
- $form->{"projectnumber_$j"} = "$ref->{projectnumber}--$ref->{project_id}" if $ref->{project_id};
- $form->{"fx_transaction_$j"} = $ref->{fx_transaction};
-
- if ($ref->{amount} < 0) {
- $form->{"debit_$j"} = $ref->{amount} * -1;
- } else {
- $form->{"credit_$j"} = $ref->{amount};
- }
-
- $j++;
- }
-
- $form->{rowcount} = $j;
-
- for (qw(id recurring)) { delete $form->{$_} }
- $form->info("\n".$locale->text('Posting GL Transaction [_1]', $form->{reference}));
- $ok = GL->post_transaction(\%myconfig, \%$form);
- $form->info(" ..... ".$locale->text('done'));
-
- }
-
- AM->update_recurring(\%myconfig, \%$pt, $id) if $ok;
-
- }
- }
-
- $form->{callback} = "am.pl?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&header=$form->{header}";
- $form->redirect;
+ &schedule;
}
+sub process_transactions {
-sub print_recurring {
- my ($pt, $defaultprinter) = @_;
- use List::Util qw(first);
+ # save variables
+ my $pt = new Form;
+ for ( keys %$form ) { $pt->{$_} = $form->{$_} }
+
+ my $defaultprinter;
+ while ( my ( $key, $value ) = each %{LedgerSMB::Sysconfig::printer} ) {
+ if ( $value =~ /lpr/ ) {
+ $defaultprinter = $key;
+ last;
+ }
+ }
+
+ $myconfig{vclimit} = 0;
+ %f = &formnames;
+
+ for ( my $i = 1 ; $i <= $pt->{lastndx} ; $i++ ) {
+ if ( $pt->{"ndx_$i"} ) {
+ $id = $pt->{"ndx_$i"};
+
+ # process transaction
+ AM->recurring_details( \%myconfig, \%$pt, $id );
+
+ $header = $form->{header};
+
+ # reset $form
+ for ( keys %$form ) { delete $form->{$_}; }
+ for (qw(login path sessionid stylesheet timeout)) {
+ $form->{$_} = $pt->{$_};
+ }
+ $form->{id} = $id;
+ $form->{header} = $header;
+
+ # post, print, email
+ if ( $pt->{arid} || $pt->{apid} || $pt->{oeid} ) {
+ if ( $pt->{arid} || $pt->{apid} ) {
+ if ( $pt->{arid} ) {
+ $form->{script} =
+ ( $pt->{invoice} ) ? "is.pl" : "ar.pl";
+ $form->{ARAP} = "AR";
+ $form->{module} = "ar";
+ $invfld = "sinumber";
+ }
+ else {
+ $form->{script} =
+ ( $pt->{invoice} ) ? "ir.pl" : "ap.pl";
+ $form->{ARAP} = "AP";
+ $form->{module} = "ap";
+ $invfld = "vinumber";
+ }
+ do "bin/$form->{script}";
+
+ if ( $pt->{invoice} ) {
+ &invoice_links;
+ &prepare_invoice;
+
+ for ( keys %$form ) {
+ $form->{$_} = $form->unquote( $form->{$_} );
+ }
+
+ }
+ else {
+ &create_links;
+
+ $form->{type} = "transaction";
+ for ( 1 .. $form->{rowcount} - 1 ) {
+ $form->{"amount_$_"} =
+ $form->format_amount( \%myconfig,
+ $form->{"amount_$_"}, 2 );
+ }
+ for ( 1 .. $form->{paidaccounts} ) {
+ $form->{"paid_$_"} =
+ $form->format_amount( \%myconfig,
+ $form->{"paid_$_"}, 2 );
+ }
+
+ }
+
+ delete $form->{"$form->{ARAP}_links"};
+ for (qw(acc_trans invoice_details)) { delete $form->{$_} }
+ for (
+ qw(department employee language month partsgroup project years)
+ )
+ {
+ delete $form->{"all_$_"};
+ }
+
+ $form->{invnumber} = $pt->{reference};
+ $form->{transdate} = $pt->{nextdate};
+
+ # tax accounts
+ $form->all_taxaccounts( \%myconfig, undef,
+ $form->{transdate} );
+
+ # calculate duedate
+ $form->{duedate} =
+ $form->add_date( \%myconfig, $form->{transdate},
+ $pt->{overdue}, "days" );
+
+ if ( $pt->{payment} ) {
+
+ # calculate date paid
+ for ( $j = 1 ; $j <= $form->{paidaccounts} ; $j++ ) {
+ $form->{"datepaid_$j"} =
+ $form->add_date( \%myconfig, $form->{transdate},
+ $pt->{paid}, "days" );
+
+ ( $form->{"$form->{ARAP}_paid_$j"} ) = split /--/,
+ $form->{"$form->{ARAP}_paid_$j"};
+ delete $form->{"cleared_$j"};
+ }
+
+ $form->{paidaccounts}++;
+ }
+ else {
+ $form->{paidaccounts} = -1;
+ }
+
+ for (qw(id recurring intnotes printed emailed queued)) {
+ delete $form->{$_};
+ }
+
+ ( $form->{ $form->{ARAP} } ) = split /--/,
+ $form->{ $form->{ARAP} };
+
+ $form->{invnumber} =
+ $form->update_defaults( \%myconfig, "$invfld" )
+ unless $form->{invnumber};
+ $form->{reference} = $form->{invnumber};
+ for (qw(invnumber reference)) {
+ $form->{$_} = $form->unquote( $form->{$_} );
+ }
+
+ if ( $pt->{invoice} ) {
+ if ( $pt->{arid} ) {
+ $form->info(
+ "\n"
+ . $locale->text(
+ 'Posting Sales Invoice [_1]',
+ $form->{invnumber}
+ )
+ );
+ $ok = IS->post_invoice( \%myconfig, \%$form );
+ }
+ else {
+ $form->info(
+ "\n"
+ . $locale->text(
+ 'Posting Vendor Invoice [_1]',
+ $form->{invnumber}
+ )
+ );
+ $ok = IR->post_invoice( \%myconfig, \%$form );
+ }
+ }
+ else {
+ if ( $pt->{arid} ) {
+ $form->info(
+ "\n"
+ . $locale->text(
+ 'Posting Transaction [_1]',
+ $form->{invnumber}
+ )
+ );
+ }
+ else {
+ $form->info(
+ "\n"
+ . $locale->text(
+ 'Posting Transaction [_1]',
+ $form->{invnumber}
+ )
+ );
+ }
+
+ $ok = AA->post_transaction( \%myconfig, \%$form );
+
+ }
+ $form->info( " ..... " . $locale->text('done') );
+
+ # print form
+ if ( ${LedgerSMB::Sysconfig::latex} && $ok ) {
+ $ok = &print_recurring( \%$pt, $defaultprinter );
+ }
+
+ &email_recurring( \%$pt ) if $ok;
+
+ }
+ else {
+
+ # order
+ $form->{script} = "oe.pl";
+ $form->{module} = "oe";
+
+ $ordnumber = "ordnumber";
+ if ( $pt->{customer_id} ) {
+ $form->{vc} = "customer";
+ $form->{type} = "sales_order";
+ $ordfld = "sonumber";
+ $flabel = $locale->text('Sales Order');
+ }
+ else {
+ $form->{vc} = "vendor";
+ $form->{type} = "purchase_order";
+ $ordfld = "ponumber";
+ $flabel = $locale->text('Purchase Order');
+ }
+ require "bin/$form->{script}";
+
+ &order_links;
+ &prepare_order;
+
+ for ( keys %$form ) {
+ $form->{$_} = $form->unquote( $form->{$_} );
+ }
+
+ $form->{$ordnumber} = $pt->{reference};
+ $form->{transdate} = $pt->{nextdate};
+
+ # calculate reqdate
+ $form->{reqdate} =
+ $form->add_date( \%myconfig, $form->{transdate},
+ $pt->{req}, "days" )
+ if $form->{reqdate};
+
+ for (qw(id recurring intnotes printed emailed queued)) {
+ delete $form->{$_};
+ }
+ for ( 1 .. $form->{rowcount} ) {
+ delete $form->{"orderitems_id_$_"};
+ }
+
+ $form->{$ordnumber} =
+ $form->update_defaults( \%myconfig, "$ordfld" )
+ unless $form->{$ordnumber};
+ $form->{reference} = $form->{$ordnumber};
+ for ( "$ordnumber", "reference" ) {
+ $form->{$_} = $form->unquote( $form->{$_} );
+ }
+ $form->{closed} = 0;
+
+ $form->info(
+ "\n"
+ . $locale->text(
+ 'Saving [_1] [_2]',
+ $flabel, $form->{$ordnumber}
+ )
+ );
+ if ( $ok = OE->save( \%myconfig, \%$form ) ) {
+ $form->info( " ..... " . $locale->text('done') );
+ }
+ else {
+ $form->info( " ..... " . $locale->text('failed') );
+ }
+
+ # print form
+ if ( ${LedgerSMB::Sysconfig::latex} && $ok ) {
+ &print_recurring( \%$pt, $defaultprinter );
+ }
+
+ &email_recurring( \%$pt );
+
+ }
+
+ }
+ else {
+
+ # GL transaction
+ GL->transaction( \%myconfig, \%$form );
+
+ $form->{reference} = $pt->{reference};
+ $form->{transdate} = $pt->{nextdate};
+
+ $j = 1;
+ foreach $ref ( @{ $form->{GL} } ) {
+ $form->{"accno_$j"} = "$ref->{accno}--$ref->{description}";
+
+ $form->{"projectnumber_$j"} =
+ "$ref->{projectnumber}--$ref->{project_id}"
+ if $ref->{project_id};
+ $form->{"fx_transaction_$j"} = $ref->{fx_transaction};
+
+ if ( $ref->{amount} < 0 ) {
+ $form->{"debit_$j"} = $ref->{amount} * -1;
+ }
+ else {
+ $form->{"credit_$j"} = $ref->{amount};
+ }
+
+ $j++;
+ }
+
+ $form->{rowcount} = $j;
+
+ for (qw(id recurring)) { delete $form->{$_} }
+ $form->info(
+ "\n"
+ . $locale->text(
+ 'Posting GL Transaction [_1]',
+ $form->{reference}
+ )
+ );
+ $ok = GL->post_transaction( \%myconfig, \%$form );
+ $form->info( " ..... " . $locale->text('done') );
+
+ }
+
+ AM->update_recurring( \%myconfig, \%$pt, $id ) if $ok;
+
+ }
+ }
+
+ $form->{callback} =
+"am.pl?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&header=$form->{header}";
+ $form->redirect;
- my %f = &formnames;
- my $ok = 1;
-
- if ($pt->{recurringprint}) {
- @f = split /:/, $pt->{recurringprint};
- for ($j = 0; $j <= $#f; $j += 3) {
- $media = $f[$j+2];
- $media ||= $myconfig->{printer}
- if ${LedgerSMB::Sysconfig::printer}{$myconfig->{printer}};
- $media ||= $defaultprinter;
-
- $form->info("\n".$locale->text('Printing')." ".$locale->text($f{$f[$j]})." $form->{reference}");
-
- @a = ("perl", "$form->{script}", "action=reprint&module=$form->{module}&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&id=$form->{id}&formname=$f[$j]&format=$f[$j+1]&media=$media&vc=$form->{vc}&ARAP=$form->{ARAP}");
-
- $form->error($locale->text('Invalid redirect')) unless
- first {$_ eq $form->{script}} @{LedgerSMB::Sysconfig::scripts};
- $ok = !(system(@a));
-
- if ($ok) {
- $form->info(" ..... ".$locale->text('done'));
- } else {
- $form->info(" ..... ".$locale->text('failed'));
- last;
- }
- }
- }
-
- $ok;
-
}
+sub print_recurring {
+ my ( $pt, $defaultprinter ) = @_;
+ use List::Util qw(first);
+
+ my %f = &formnames;
+ my $ok = 1;
+
+ if ( $pt->{recurringprint} ) {
+ @f = split /:/, $pt->{recurringprint};
+ for ( $j = 0 ; $j <= $#f ; $j += 3 ) {
+ $media = $f[ $j + 2 ];
+ $media ||= $myconfig->{printer}
+ if ${LedgerSMB::Sysconfig::printer}{ $myconfig->{printer} };
+ $media ||= $defaultprinter;
+
+ $form->info( "\n"
+ . $locale->text('Printing') . " "
+ . $locale->text( $f{ $f[$j] } )
+ . " $form->{reference}" );
+
+ @a = (
+ "perl", "$form->{script}",
+"action=reprint&module=$form->{module}&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&id=$form->{id}&formname=$f[$j]&format=$f[$j+1]&media=$media&vc=$form->{vc}&ARAP=$form->{ARAP}"
+ );
+
+ $form->error( $locale->text('Invalid redirect') )
+ unless first { $_ eq $form->{script} }
+ @{LedgerSMB::Sysconfig::scripts};
+ $ok = !( system(@a) );
+
+ if ($ok) {
+ $form->info( " ..... " . $locale->text('done') );
+ }
+ else {
+ $form->info( " ..... " . $locale->text('failed') );
+ last;
+ }
+ }
+ }
-sub email_recurring {
- my ($pt) = @_;
- use List::Util qw(first);
+ $ok;
- my %f = &formnames;
- my $ok = 1;
-
- if ($pt->{recurringemail}) {
-
- @f = split /:/, $pt->{recurringemail};
- for ($j = 0; $j <= $#f; $j += 2) {
-
- $form->info("\n".$locale->text('Sending')." ".$locale->text($f{$f[$j]})." $form->{reference}");
-
- # no email, bail out
- if (!$form->{email}) {
- $form->info(" ..... ".$locale->text('E-mail address missing!'));
- last;
- }
-
- $message = $form->escape($pt->{message},1);
-
- @a = ("perl", "$form->{script}", "action=reprint&module=$form->{module}&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&id=$form->{id}&formname=$f[$j]&format=$f[$j+1]&media=email&vc=$form->{vc}&ARAP=$form->{ARAP}&message=$message");
-
- $form->error($locale->text('Invalid redirect')) unless
- first {$_ eq $form->{script}} @{LedgerSMB::Sysconfig::scripts};
- $ok = !(system(@a));
-
- if ($ok) {
- $form->info(" ..... ".$locale->text('done'));
- } else {
- $form->info(" ..... ".$locale->text('failed'));
- last;
- }
- }
- }
-
- $ok;
-
}
+sub email_recurring {
+ my ($pt) = @_;
+ use List::Util qw(first);
+
+ my %f = &formnames;
+ my $ok = 1;
+
+ if ( $pt->{recurringemail} ) {
+
+ @f = split /:/, $pt->{recurringemail};
+ for ( $j = 0 ; $j <= $#f ; $j += 2 ) {
+
+ $form->info( "\n"
+ . $locale->text('Sending') . " "
+ . $locale->text( $f{ $f[$j] } )
+ . " $form->{reference}" );
+
+ # no email, bail out
+ if ( !$form->{email} ) {
+ $form->info(
+ " ..... " . $locale->text('E-mail address missing!') );
+ last;
+ }
+
+ $message = $form->escape( $pt->{message}, 1 );
+
+ @a = (
+ "perl", "$form->{script}",
+"action=reprint&module=$form->{module}&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&id=$form->{id}&formname=$f[$j]&format=$f[$j+1]&media=email&vc=$form->{vc}&ARAP=$form->{ARAP}&message=$message"
+ );
+
+ $form->error( $locale->text('Invalid redirect') )
+ unless first { $_ eq $form->{script} }
+ @{LedgerSMB::Sysconfig::scripts};
+ $ok = !( system(@a) );
+
+ if ($ok) {
+ $form->info( " ..... " . $locale->text('done') );
+ }
+ else {
+ $form->info( " ..... " . $locale->text('failed') );
+ last;
+ }
+ }
+ }
+
+ $ok;
+}
sub formnames {
-
-# $locale->text('Transaction')
-# $locale->text('Invoice')
-# $locale->text('Credit Invoice')
-# $locale->text('Debit Invoice')
-# $locale->text('Packing List')
-# $locale->text('Pick List')
-# $locale->text('Sales Order')
-# $locale->text('Work Order')
-# $locale->text('Purchase Order')
-# $locale->text('Bin List')
-
- my %f = ( transaction => 'Transaction',
- invoice => 'Invoice',
- credit_invoice => 'Credit Invoice',
- debit_invoice => 'Debit Invoice',
- packing_list => 'Packing List',
- pick_list => 'Pick List',
- sales_order => 'Sales Order',
- work_order => 'Work Order',
- purchase_order => 'Purchase Order',
- bin_list => 'Bin List',
- );
-
- %f;
-
-}
-
-
-sub continue { &{ $form->{nextsub} } };
+
+ # $locale->text('Transaction')
+ # $locale->text('Invoice')
+ # $locale->text('Credit Invoice')
+ # $locale->text('Debit Invoice')
+ # $locale->text('Packing List')
+ # $locale->text('Pick List')
+ # $locale->text('Sales Order')
+ # $locale->text('Work Order')
+ # $locale->text('Purchase Order')
+ # $locale->text('Bin List')
+
+ my %f = (
+ transaction => 'Transaction',
+ invoice => 'Invoice',
+ credit_invoice => 'Credit Invoice',
+ debit_invoice => 'Debit Invoice',
+ packing_list => 'Packing List',
+ pick_list => 'Pick List',
+ sales_order => 'Sales Order',
+ work_order => 'Work Order',
+ purchase_order => 'Purchase Order',
+ bin_list => 'Bin List',
+ );
+
+ %f;
+
+}
+
+sub continue { &{ $form->{nextsub} } }
diff --git a/bin/ap.pl b/bin/ap.pl
index c3ce73cf..f6e009c4 100644
--- a/bin/ap.pl
+++ b/bin/ap.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -52,9 +52,10 @@ require "bin/arap.pl";
require "bin/arapprn.pl";
require "bin/aa.pl";
-$form->{vc} = 'vendor';
+$form->{vc} = 'vendor';
$form->{ARAP} = 'AP';
1;
+
# end of main
diff --git a/bin/ar.pl b/bin/ar.pl
index dd08ee71..c8f9f423 100644
--- a/bin/ar.pl
+++ b/bin/ar.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -47,9 +47,10 @@ require "bin/arap.pl";
require "bin/arapprn.pl";
require "bin/aa.pl";
-$form->{vc} = 'customer';
+$form->{vc} = 'customer';
$form->{ARAP} = 'AR';
1;
+
# end of main
diff --git a/bin/arap.pl b/bin/arap.pl
index e210d0d8..bce15aae 100644
--- a/bin/arap.pl
+++ b/bin/arap.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -41,108 +41,130 @@
use LedgerSMB::AA;
# any custom scripts for this one
-if (-f "bin/custom/arap.pl") {
- eval { require "bin/custom/arap.pl"; };
+if ( -f "bin/custom/arap.pl" ) {
+ eval { require "bin/custom/arap.pl"; };
}
-if (-f "bin/custom/$form->{login}_arap.pl") {
- eval { require "bin/custom/$form->{login}_arap.pl"; };
+if ( -f "bin/custom/$form->{login}_arap.pl" ) {
+ eval { require "bin/custom/$form->{login}_arap.pl"; };
}
-
1;
-# end of main
+# end of main
sub check_name {
- my ($name) = @_;
-
- my ($new_name, $new_id) = split /--/, $form->{$name};
- my $rv = 0;
-
- # if we use a selection
- if ($form->{"select$name"}) {
- if ($form->{"old$name"} ne $form->{$name}) {
- # this is needed for is, ir and oe
- for (split / /, $form->{taxaccounts}) { delete $form->{"${_}_rate"} }
-
- # for credit calculations
- $form->{oldinvtotal} = 0;
- $form->{oldtotalpaid} = 0;
- $form->{calctax} = 1;
-
- $form->{"${name}_id"} = $new_id;
- AA->get_name(\%myconfig, \%$form);
-
- $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
- $form->{currency} =~ s/ //g;
-
- # put employee together if there is a new employee_id
- $form->{employee} = "$form->{employee}--$form->{employee_id}" if $form->{employee_id};
-
- $rv = 1;
- }
- } else {
-
- # check name, combine name and id
- if ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|) {
- # this is needed for is, ir and oe
- for (split / /, $form->{taxaccounts}) { delete $form->{"${_}_rate"} }
-
- # for credit calculations
- $form->{oldinvtotal} = 0;
- $form->{oldtotalpaid} = 0;
- $form->{calctax} = 1;
-
- # return one name or a list of names in $form->{name_list}
- if (($rv = $form->get_name(\%myconfig, $name, $form->{transdate})) > 1) {
- &select_name($name);
- exit;
- }
-
- if ($rv == 1) {
- # we got one name
- $form->{"${name}_id"} = $form->{name_list}[0]->{id};
- $form->{$name} = $form->{name_list}[0]->{name};
- $form->{"old$name"} = qq|$form->{$name}--$form->{"${name}_id"}|;
-
- AA->get_name(\%myconfig, \%$form);
-
- $form->{currency} =~ s/ //g;
- # put employee together if there is a new employee_id
- $form->{employee} = "$form->{employee}--$form->{employee_id}" if $form->{employee_id};
+ my ($name) = @_;
+
+ my ( $new_name, $new_id ) = split /--/, $form->{$name};
+ my $rv = 0;
+
+ # if we use a selection
+ if ( $form->{"select$name"} ) {
+ if ( $form->{"old$name"} ne $form->{$name} ) {
+
+ # this is needed for is, ir and oe
+ for ( split / /, $form->{taxaccounts} ) {
+ delete $form->{"${_}_rate"};
+ }
+
+ # for credit calculations
+ $form->{oldinvtotal} = 0;
+ $form->{oldtotalpaid} = 0;
+ $form->{calctax} = 1;
+
+ $form->{"${name}_id"} = $new_id;
+ AA->get_name( \%myconfig, \%$form );
- } else {
- # name is not on file
- $msg = ucfirst $name . " not on file!";
- $form->error($locale->text($msg));
- }
+ $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
+ $form->{currency} =~ s/ //g;
+
+ # put employee together if there is a new employee_id
+ $form->{employee} = "$form->{employee}--$form->{employee_id}"
+ if $form->{employee_id};
+
+ $rv = 1;
+ }
+ }
+ else {
+
+ # check name, combine name and id
+ if ( $form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}| )
+ {
+
+ # this is needed for is, ir and oe
+ for ( split / /, $form->{taxaccounts} ) {
+ delete $form->{"${_}_rate"};
+ }
+
+ # for credit calculations
+ $form->{oldinvtotal} = 0;
+ $form->{oldtotalpaid} = 0;
+ $form->{calctax} = 1;
+
+ # return one name or a list of names in $form->{name_list}
+ if (
+ (
+ $rv =
+ $form->get_name( \%myconfig, $name, $form->{transdate} )
+ ) > 1
+ )
+ {
+ &select_name($name);
+ exit;
+ }
+
+ if ( $rv == 1 ) {
+
+ # we got one name
+ $form->{"${name}_id"} = $form->{name_list}[0]->{id};
+ $form->{$name} = $form->{name_list}[0]->{name};
+ $form->{"old$name"} = qq|$form->{$name}--$form->{"${name}_id"}|;
+
+ AA->get_name( \%myconfig, \%$form );
+
+ $form->{currency} =~ s/ //g;
+
+ # put employee together if there is a new employee_id
+ $form->{employee} = "$form->{employee}--$form->{employee_id}"
+ if $form->{employee_id};
+
+ }
+ else {
+
+ # name is not on file
+ $msg = ucfirst $name . " not on file!";
+ $form->error( $locale->text($msg) );
+ }
+ }
}
- }
- $rv;
+ $rv;
}
# $locale->text('Customer not on file!')
# $locale->text('Vendor not on file!')
-
sub select_name {
- my ($table) = @_;
-
- @column_index = qw(ndx name address);
+ my ($table) = @_;
+
+ @column_index = qw(ndx name address);
- $label = ucfirst $table;
- $column_data{ndx} = qq|<th>&nbsp;</th>|;
- $column_data{name} = qq|<th class=listheading>|.$locale->text($label).qq|</th>|;
- $column_data{address} = qq|<th class=listheading colspan=5>|.$locale->text('Address').qq|</th>|;
-
- # list items with radio button on a form
- $form->header;
+ $label = ucfirst $table;
+ $column_data{ndx} = qq|<th>&nbsp;</th>|;
+ $column_data{name} =
+ qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
+ $column_data{address} =
+ qq|<th class=listheading colspan=5>|
+ . $locale->text('Address')
+ . qq|</th>|;
- $title = $locale->text('Select from one of the names below');
+ # list items with radio button on a form
+ $form->header;
- print qq|
+ $title = $locale->text('Select from one of the names below');
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -157,41 +179,46 @@ sub select_name {
<table width=100%>
<tr class=listheading>|;
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
</tr>
|;
- @column_index = qw(ndx name address city state zipcode country);
-
- my $i = 0;
- foreach $ref (@{ $form->{name_list} }) {
- $checked = ($i++) ? "" : "checked";
-
- $ref->{name} = $form->quote($ref->{name});
-
- $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
- $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
- $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}</td>|;
- for (qw(city state zipcode country)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
-
- $j++; $j %= 2;
- print qq|
+ @column_index = qw(ndx name address city state zipcode country);
+
+ my $i = 0;
+ foreach $ref ( @{ $form->{name_list} } ) {
+ $checked = ( $i++ ) ? "" : "checked";
+
+ $ref->{name} = $form->quote( $ref->{name} );
+
+ $column_data{ndx} =
+qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
+ $column_data{name} =
+qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
+ $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}</td>|;
+ for (qw(city state zipcode country)) {
+ $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>|;
+ }
+
+ $j++;
+ $j %= 2;
+ print qq|
<tr class=listrow$j>|;
- for (@column_index) { print "\n$column_data{$_}" }
+ for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ print qq|
</tr>
<input name="new_id_$i" type=hidden value=$ref->{id}>
|;
- }
-
- print qq|
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -204,18 +231,20 @@ sub select_name {
|;
- # delete variables
- for (qw(nextsub name_list)) { delete $form->{$_} }
-
- $form->{action} = "name_selected";
-
- $form->hide_form;
+ # delete variables
+ for (qw(nextsub name_list)) { delete $form->{$_} }
- print qq|
+ $form->{action} = "name_selected";
+
+ $form->hide_form;
+
+ print qq|
<input type=hidden name=nextsub value=name_selected>
<input type=hidden name=vc value="$table">
<br>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
</body>
@@ -224,120 +253,129 @@ sub select_name {
}
+sub name_selected {
+ # replace the variable with the one checked
-sub name_selected {
+ # index for new item
+ $i = $form->{ndx};
- # replace the variable with the one checked
+ $form->{ $form->{vc} } = $form->{"new_name_$i"};
+ $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
+ $form->{"old$form->{vc}"} =
+ qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
- # index for new item
- $i = $form->{ndx};
-
- $form->{$form->{vc}} = $form->{"new_name_$i"};
- $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
- $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
+ # delete all the new_ variables
+ for $i ( 1 .. $form->{lastndx} ) {
+ for (qw(id, name)) { delete $form->{"new_${_}_$i"} }
+ }
- # delete all the new_ variables
- for $i (1 .. $form->{lastndx}) {
- for (qw(id, name)) { delete $form->{"new_${_}_$i"} }
- }
-
- for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
+ for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
- AA->get_name(\%myconfig, \%$form);
+ AA->get_name( \%myconfig, \%$form );
- # put employee together if there is a new employee_id
- $form->{employee} = "$form->{employee}--$form->{employee_id}" if $form->{employee_id};
+ # put employee together if there is a new employee_id
+ $form->{employee} = "$form->{employee}--$form->{employee_id}"
+ if $form->{employee_id};
- &update(1);
+ &update(1);
}
-
sub rebuild_vc {
- my ($vc, $ARAP, $transdate, $job) = @_;
-
- ($null, $form->{employee_id}) = split /--/, $form->{employee};
- $form->all_vc(\%myconfig, $vc, $ARAP, undef, $transdate, $job);
- $form->{"select$vc"} = "";
- for (@{ $form->{"all_$vc"} }) { $form->{"select$vc"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
-
- $form->{selectprojectnumber} = "";
- if (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} = "<option>\n";
- for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
- }
-
- 1;
-}
+ my ( $vc, $ARAP, $transdate, $job ) = @_;
+
+ ( $null, $form->{employee_id} ) = split /--/, $form->{employee};
+ $form->all_vc( \%myconfig, $vc, $ARAP, undef, $transdate, $job );
+ $form->{"select$vc"} = "";
+ for ( @{ $form->{"all_$vc"} } ) {
+ $form->{"select$vc"} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ $form->{selectprojectnumber} = "";
+ if ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} = "<option>\n";
+ for ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} .=
+qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
+ }
+ }
+ 1;
+}
sub add_transaction {
- my ($module) = @_;
-
- delete $form->{script};
- $form->{action} = "add";
- $form->{type} = "invoice" if $module =~ /(is|ir)/;
+ my ($module) = @_;
- $form->{callback} = $form->escape($form->{callback},1);
- $argv = "";
- for (keys %$form) { $argv .= "$_=$form->{$_}&" if $_ ne 'dbh' }
+ delete $form->{script};
+ $form->{action} = "add";
+ $form->{type} = "invoice" if $module =~ /(is|ir)/;
- $form->{callback} = "$module.pl?$argv";
+ $form->{callback} = $form->escape( $form->{callback}, 1 );
+ $argv = "";
+ for ( keys %$form ) { $argv .= "$_=$form->{$_}&" if $_ ne 'dbh' }
- $form->redirect;
-
-}
+ $form->{callback} = "$module.pl?$argv";
+ $form->redirect;
+}
sub check_project {
- for $i (1 .. $form->{rowcount}) {
- $form->{"project_id_$i"} = "" unless $form->{"projectnumber_$i"};
- if ($form->{"projectnumber_$i"} ne $form->{"oldprojectnumber_$i"}) {
- if ($form->{"projectnumber_$i"}) {
- # get new project
- $form->{projectnumber} = $form->{"projectnumber_$i"};
- if (($rows = PE->projects(\%myconfig, $form)) > 1) {
- # check form->{project_list} how many there are
- $form->{rownumber} = $i;
- &select_project;
- exit;
- }
-
- if ($rows == 1) {
- $form->{"project_id_$i"} = $form->{project_list}->[0]->{id};
- $form->{"projectnumber_$i"} = $form->{project_list}->[0]->{projectnumber};
- $form->{"oldprojectnumber_$i"} = $form->{project_list}->[0]->{projectnumber};
- } else {
- # not on file
- $form->error($locale->text('Project not on file!'));
- }
- } else {
- $form->{"oldprojectnumber_$i"} = "";
- }
- }
- }
+ for $i ( 1 .. $form->{rowcount} ) {
+ $form->{"project_id_$i"} = "" unless $form->{"projectnumber_$i"};
+ if ( $form->{"projectnumber_$i"} ne $form->{"oldprojectnumber_$i"} ) {
+ if ( $form->{"projectnumber_$i"} ) {
+
+ # get new project
+ $form->{projectnumber} = $form->{"projectnumber_$i"};
+ if ( ( $rows = PE->projects( \%myconfig, $form ) ) > 1 ) {
+
+ # check form->{project_list} how many there are
+ $form->{rownumber} = $i;
+ &select_project;
+ exit;
+ }
+
+ if ( $rows == 1 ) {
+ $form->{"project_id_$i"} = $form->{project_list}->[0]->{id};
+ $form->{"projectnumber_$i"} =
+ $form->{project_list}->[0]->{projectnumber};
+ $form->{"oldprojectnumber_$i"} =
+ $form->{project_list}->[0]->{projectnumber};
+ }
+ else {
+
+ # not on file
+ $form->error( $locale->text('Project not on file!') );
+ }
+ }
+ else {
+ $form->{"oldprojectnumber_$i"} = "";
+ }
+ }
+ }
}
-
sub select_project {
-
- @column_index = qw(ndx projectnumber description);
- $column_data{ndx} = qq|<th>&nbsp;</th>|;
- $column_data{projectnumber} = qq|<th>|.$locale->text('Number').qq|</th>|;
- $column_data{description} = qq|<th>|.$locale->text('Description').qq|</th>|;
-
- # list items with radio button on a form
- $form->header;
+ @column_index = qw(ndx projectnumber description);
+
+ $column_data{ndx} = qq|<th>&nbsp;</th>|;
+ $column_data{projectnumber} =
+ qq|<th>| . $locale->text('Number') . qq|</th>|;
+ $column_data{description} =
+ qq|<th>| . $locale->text('Description') . qq|</th>|;
- $title = $locale->text('Select from one of the projects below');
+ # list items with radio button on a form
+ $form->header;
- print qq|
+ $title = $locale->text('Select from one of the projects below');
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -354,38 +392,41 @@ sub select_project {
<table width=100%>
<tr class=listheading>|;
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
</tr>
|;
- my $i = 0;
- foreach $ref (@{ $form->{project_list} }) {
- $checked = ($i++) ? "" : "checked";
-
- $ref->{name} = $form->quote($ref->{name});
-
- $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
- $column_data{projectnumber} = qq|<td><input name="new_projectnumber_$i" type=hidden value="$ref->{projectnumber}">$ref->{projectnumber}</td>|;
- $column_data{description} = qq|<td>$ref->{description}</td>|;
-
- $j++; $j %= 2;
- print qq|
+ my $i = 0;
+ foreach $ref ( @{ $form->{project_list} } ) {
+ $checked = ( $i++ ) ? "" : "checked";
+
+ $ref->{name} = $form->quote( $ref->{name} );
+
+ $column_data{ndx} =
+qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
+ $column_data{projectnumber} =
+qq|<td><input name="new_projectnumber_$i" type=hidden value="$ref->{projectnumber}">$ref->{projectnumber}</td>|;
+ $column_data{description} = qq|<td>$ref->{description}</td>|;
+
+ $j++;
+ $j %= 2;
+ print qq|
<tr class=listrow$j>|;
- for (@column_index) { print "\n$column_data{$_}" }
+ for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ print qq|
</tr>
<input name="new_id_$i" type=hidden value=$ref->{id}>
|;
- }
-
- print qq|
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -398,17 +439,19 @@ sub select_project {
|;
- # delete list variable
- for (qw(nextsub project_list)) { delete $form->{$_} }
-
- $form->{action} = "project_selected";
-
- $form->hide_form;
+ # delete list variable
+ for (qw(nextsub project_list)) { delete $form->{$_} }
+
+ $form->{action} = "project_selected";
- print qq|
+ $form->hide_form;
+
+ print qq|
<input type=hidden name=nextsub value=project_selected>
<br>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
</body>
@@ -417,97 +460,108 @@ sub select_project {
}
-
sub project_selected {
-
- # replace the variable with the one checked
-
- # index for new item
- $i = $form->{ndx};
-
- $form->{"projectnumber_$form->{rownumber}"} = $form->{"new_projectnumber_$i"};
- $form->{"oldprojectnumber_$form->{rownumber}"} = $form->{"new_projectnumber_$i"};
- $form->{"project_id_$form->{rownumber}"} = $form->{"new_id_$i"};
-
- # delete all the new_ variables
- for $i (1 .. $form->{lastndx}) {
- for (qw(id projectnumber description)) { delete $form->{"new_${_}_$i"} }
- }
-
- for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
-
- if ($form->{update}) {
- &{ $form->{update} };
- } else {
- &update;
- }
-}
+ # replace the variable with the one checked
+ # index for new item
+ $i = $form->{ndx};
-sub post_as_new {
+ $form->{"projectnumber_$form->{rownumber}"} =
+ $form->{"new_projectnumber_$i"};
+ $form->{"oldprojectnumber_$form->{rownumber}"} =
+ $form->{"new_projectnumber_$i"};
+ $form->{"project_id_$form->{rownumber}"} = $form->{"new_id_$i"};
+
+ # delete all the new_ variables
+ for $i ( 1 .. $form->{lastndx} ) {
+ for (qw(id projectnumber description)) { delete $form->{"new_${_}_$i"} }
+ }
- for (qw(id printed emailed queued)) { delete $form->{$_} }
- &post;
+ for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
+
+ if ( $form->{update} ) {
+ &{ $form->{update} };
+ }
+ else {
+ &update;
+ }
}
+sub post_as_new {
+
+ for (qw(id printed emailed queued)) { delete $form->{$_} }
+ &post;
+
+}
sub print_and_post_as_new {
- for (qw(id printed emailed queued)) { delete $form->{$_} }
- &print_and_post;
+ for (qw(id printed emailed queued)) { delete $form->{$_} }
+ &print_and_post;
}
-
sub repost {
- if ($form->{type} =~ /_order/) {
- if ($form->{print_and_save}) {
- $form->{nextsub} = "print_and_save";
- $msg = $locale->text('You are printing and saving an existing order');
- } else {
- $form->{nextsub} = "save";
- $msg = $locale->text('You are saving an existing order');
- }
- } elsif ($form->{type} =~ /_quotation/) {
- if ($form->{print_and_save}) {
- $form->{nextsub} = "print_and_save";
- $msg = $locale->text('You are printing and saving an existing quotation');
- } else {
- $form->{nextsub} = "save";
- $msg = $locale->text('You are saving an existing quotation');
- }
- } else {
- if ($form->{print_and_post}) {
- $form->{nextsub} = "print_and_post";
- $msg = $locale->text('You are printing and posting an existing transaction!');
- } else {
- $form->{nextsub} = "post";
- $msg = $locale->text('You are posting an existing transaction!');
- }
- }
-
- delete $form->{action};
- $form->{repost} = 1;
-
- $form->header;
-
- print qq|
+ if ( $form->{type} =~ /_order/ ) {
+ if ( $form->{print_and_save} ) {
+ $form->{nextsub} = "print_and_save";
+ $msg =
+ $locale->text('You are printing and saving an existing order');
+ }
+ else {
+ $form->{nextsub} = "save";
+ $msg = $locale->text('You are saving an existing order');
+ }
+ }
+ elsif ( $form->{type} =~ /_quotation/ ) {
+ if ( $form->{print_and_save} ) {
+ $form->{nextsub} = "print_and_save";
+ $msg =
+ $locale->text(
+ 'You are printing and saving an existing quotation');
+ }
+ else {
+ $form->{nextsub} = "save";
+ $msg = $locale->text('You are saving an existing quotation');
+ }
+ }
+ else {
+ if ( $form->{print_and_post} ) {
+ $form->{nextsub} = "print_and_post";
+ $msg =
+ $locale->text(
+ 'You are printing and posting an existing transaction!');
+ }
+ else {
+ $form->{nextsub} = "post";
+ $msg = $locale->text('You are posting an existing transaction!');
+ }
+ }
+
+ delete $form->{action};
+ $form->{repost} = 1;
+
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
|;
- $form->hide_form;
+ $form->hide_form;
- print qq|
-<h2 class=confirm>|.$locale->text('Warning!').qq|</h2>
+ 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>
+<button name="action" class="submit" type="submit" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
</body>
@@ -516,53 +570,60 @@ sub repost {
}
-
sub schedule {
-
- ($form->{recurringreference}, $form->{recurringstartdate}, $form->{recurringrepeat}, $form->{recurringunit}, $form->{recurringhowmany}, $form->{recurringpayment}, $form->{recurringprint}, $form->{recurringemail}, $form->{recurringmessage}) = split /,/, $form->{recurring};
- $form->{recurringreference} = $form->quote($form->unescape($form->{recurringreference}));
- $form->{recurringmessage} = $form->quote($form->unescape($form->{recurringmessage}));
+ (
+ $form->{recurringreference}, $form->{recurringstartdate},
+ $form->{recurringrepeat}, $form->{recurringunit},
+ $form->{recurringhowmany}, $form->{recurringpayment},
+ $form->{recurringprint}, $form->{recurringemail},
+ $form->{recurringmessage}
+ ) = split /,/, $form->{recurring};
+
+ $form->{recurringreference} =
+ $form->quote( $form->unescape( $form->{recurringreference} ) );
+ $form->{recurringmessage} =
+ $form->quote( $form->unescape( $form->{recurringmessage} ) );
- $form->{recurringstartdate} ||= $form->{transdate};
- $recurringpayment = "checked" if $form->{recurringpayment};
+ $form->{recurringstartdate} ||= $form->{transdate};
+ $recurringpayment = "checked" if $form->{recurringpayment};
- if ($form->{paidaccounts}) {
- $postpayment = qq|
+ if ( $form->{paidaccounts} ) {
+ $postpayment = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Include Payment').qq|</th>
+ <th align=right nowrap>| . $locale->text('Include Payment') . qq|</th>
<td><input name=recurringpayment type=checkbox class=checkbox value=1 $recurringpayment></td>
</tr>
|;
- }
+ }
- if ($form->{recurringnextdate}) {
- $nextdate = qq|
+ if ( $form->{recurringnextdate} ) {
+ $nextdate = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Next Date').qq|</th>
+ <th align=right nowrap>| . $locale->text('Next Date') . qq|</th>
<td><input name=recurringnextdate size=11 title="($myconfig{'dateformat'})" value=$form->{recurringnextdate}></td>
</tr>
|;
- }
-
- @a = split /<option/, $form->unescape($form->{selectformname});
- %formname = ();
-
- for ($i = 1; $i <= $#a; $i++) {
- $a[$i] =~ /"(.*)"/;
- $v = $1;
- $a[$i] =~ />(.*)/;
- $formname{$v} = $1;
- }
- for (qw(check receipt)) { delete $formname{$_} }
-
- $selectformat = $form->unescape($form->{selectformat});
-
- if ($form->{type} !~ /transaction/ && %formname) {
- $email = qq|
+ }
+
+ @a = split /<option/, $form->unescape( $form->{selectformname} );
+ %formname = ();
+
+ for ( $i = 1 ; $i <= $#a ; $i++ ) {
+ $a[$i] =~ /"(.*)"/;
+ $v = $1;
+ $a[$i] =~ />(.*)/;
+ $formname{$v} = $1;
+ }
+ for (qw(check receipt)) { delete $formname{$_} }
+
+ $selectformat = $form->unescape( $form->{selectformat} );
+
+ if ( $form->{type} !~ /transaction/ && %formname ) {
+ $email = qq|
<table>
<tr>
- <th colspan=2 class=listheading>|.$locale->text('E-mail').qq|</th>
+ <th colspan=2 class=listheading>| . $locale->text('E-mail') . qq|</th>
</tr>
<tr>
@@ -570,40 +631,41 @@ sub schedule {
<table>
|;
- # formname:format
- @p = split /:/, $form->{recurringemail};
- %p = ();
- for ($i = 0; $i <= $#p; $i += 2) {
- $p{$p[$i]}{format} = $p[$i+1];
- }
-
- foreach $item (keys %formname) {
-
- $checked = ($p{$item}{format}) ? "checked" : "";
- $selectformat =~ s/ selected//;
- $p{$item}{format} ||= "pdf";
- $selectformat =~ s/(<option value="\Q$p{$item}{format}\E")/$1 selected/;
-
- $email .= qq|
+ # formname:format
+ @p = split /:/, $form->{recurringemail};
+ %p = ();
+ for ( $i = 0 ; $i <= $#p ; $i += 2 ) {
+ $p{ $p[$i] }{format} = $p[ $i + 1 ];
+ }
+
+ foreach $item ( keys %formname ) {
+
+ $checked = ( $p{$item}{format} ) ? "checked" : "";
+ $selectformat =~ s/ selected//;
+ $p{$item}{format} ||= "pdf";
+ $selectformat =~
+ s/(<option value="\Q$p{$item}{format}\E")/$1 selected/;
+
+ $email .= qq|
<tr>
<td><input name="email$item" type=checkbox class=checkbox value=1 $checked></td>
<th align=left>$formname{$item}</th>
<td><select name="emailformat$item">$selectformat</select></td>
</tr>
|;
- }
-
- $email .= qq|
+ }
+
+ $email .= qq|
</table>
</td>
</tr>
</table>
|;
- $message = qq|
+ $message = qq|
<table>
<tr>
- <th class=listheading>|.$locale->text('E-mail message').qq|</th>
+ <th class=listheading>| . $locale->text('E-mail message') . qq|</th>
</tr>
<tr>
@@ -612,27 +674,31 @@ sub schedule {
</table>
|;
- }
-
-
- if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} && %formname) {
- $selectprinter = qq|<option>\n|;
- for (sort keys %{LedgerSMB::Sysconfig::printer}) { $selectprinter .= qq|<option value="$_">$_\n| }
-
- # formname:format:printer
- @p = split /:/, $form->{recurringprint};
-
- %p = ();
- for ($i = 0; $i <= $#p; $i += 3) {
- $p{$p[$i]}{formname} = $p[$i];
- $p{$p[$i]}{format} = $p[$i+1];
- $p{$p[$i]}{printer} = $p[$i+2];
}
-
- $print = qq|
+
+ if ( %{LedgerSMB::Sysconfig::printer}
+ && ${LedgerSMB::Sysconfig::latex}
+ && %formname )
+ {
+ $selectprinter = qq|<option>\n|;
+ for ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
+ $selectprinter .= qq|<option value="$_">$_\n|;
+ }
+
+ # formname:format:printer
+ @p = split /:/, $form->{recurringprint};
+
+ %p = ();
+ for ( $i = 0 ; $i <= $#p ; $i += 3 ) {
+ $p{ $p[$i] }{formname} = $p[$i];
+ $p{ $p[$i] }{format} = $p[ $i + 1 ];
+ $p{ $p[$i] }{printer} = $p[ $i + 2 ];
+ }
+
+ $print = qq|
<table>
<tr>
- <th colspan=2 class=listheading>|.$locale->text('Print').qq|</th>
+ <th colspan=2 class=listheading>| . $locale->text('Print') . qq|</th>
</tr>
<tr>
@@ -640,19 +706,21 @@ sub schedule {
<table>
|;
- $selectformat =~ s/<option.*html//;
- foreach $item (keys %formname) {
-
- $selectprinter =~ s/ selected//;
- $selectprinter =~ s/(<option value="\Q$p{$item}{printer}\E")/$1 selected/;
-
- $checked = ($p{$item}{formname}) ? "checked" : "";
-
- $selectformat =~ s/ selected//;
- $p{$item}{format} ||= "postscript";
- $selectformat =~ s/(<option value="\Q$p{$item}{format}\E")/$1 selected/;
-
- $print .= qq|
+ $selectformat =~ s/<option.*html//;
+ foreach $item ( keys %formname ) {
+
+ $selectprinter =~ s/ selected//;
+ $selectprinter =~
+ s/(<option value="\Q$p{$item}{printer}\E")/$1 selected/;
+
+ $checked = ( $p{$item}{formname} ) ? "checked" : "";
+
+ $selectformat =~ s/ selected//;
+ $p{$item}{format} ||= "postscript";
+ $selectformat =~
+ s/(<option value="\Q$p{$item}{format}\E")/$1 selected/;
+
+ $print .= qq|
<tr>
<td><input name="print$item" type=checkbox class=checkbox value=1 $checked></td>
<th align=left>$formname{$item}</th>
@@ -660,62 +728,61 @@ sub schedule {
<td><select name="printformat$item">$selectformat</select></td>
</tr>
|;
- }
-
- $print .= qq|
+ }
+
+ $print .= qq|
</table>
</td>
</tr>
</table>
|;
+ }
+
+ $selectrepeat = "";
+ for ( 1 .. 31 ) { $selectrepeat .= qq|<option value="$_">$_\n| }
+ $selectrepeat =~ s/(<option value="$form->{recurringrepeat}")/$1 selected/;
+
+ $selectunit = qq|<option value="days">| . $locale->text('Day(s)') . qq|
+ <option value="weeks">| . $locale->text('Week(s)') . qq|
+ <option value="months">| . $locale->text('Month(s)') . qq|
+ <option value="years">| . $locale->text('Year(s)');
+
+ if ( $form->{recurringunit} ) {
+ $selectunit =~ s/(<option value="$form->{recurringunit}")/$1 selected/;
+ }
- }
-
- $selectrepeat = "";
- for (1 .. 31) { $selectrepeat .= qq|<option value="$_">$_\n| }
- $selectrepeat =~ s/(<option value="$form->{recurringrepeat}")/$1 selected/;
-
- $selectunit = qq|<option value="days">|.$locale->text('Day(s)').qq|
- <option value="weeks">|.$locale->text('Week(s)').qq|
- <option value="months">|.$locale->text('Month(s)').qq|
- <option value="years">|.$locale->text('Year(s)');
-
- if ($form->{recurringunit}) {
- $selectunit =~ s/(<option value="$form->{recurringunit}")/$1 selected/;
- }
-
- if ($form->{$form->{vc}}) {
- $description = $form->{$form->{vc}};
- } else {
- $description = $form->{description};
- }
-
- $repeat = qq|
+ if ( $form->{ $form->{vc} } ) {
+ $description = $form->{ $form->{vc} };
+ }
+ else {
+ $description = $form->{description};
+ }
+
+ $repeat = qq|
<table>
<tr>
- <th colspan=3 class=listheading>|.$locale->text('Repeat').qq|</th>
+ <th colspan=3 class=listheading>| . $locale->text('Repeat') . qq|</th>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Every').qq|</th>
+ <th align=right nowrap>| . $locale->text('Every') . qq|</th>
<td><select name=recurringrepeat>$selectrepeat</td>
<td><select name=recurringunit>$selectunit</td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('For').qq|</th>
+ <th align=right nowrap>| . $locale->text('For') . qq|</th>
<td><input name=recurringhowmany size=3 value=$form->{recurringhowmany}></td>
- <th align=left nowrap>|.$locale->text('time(s)').qq|</th>
+ <th align=left nowrap>| . $locale->text('time(s)') . qq|</th>
</tr>
</table>
|;
-
- $title = $locale->text('Recurring Transaction for [_1]', $description);
+ $title = $locale->text( 'Recurring Transaction for [_1]', $description );
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -732,11 +799,11 @@ sub schedule {
<td>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Reference').qq|</th>
+ <th align=right nowrap>| . $locale->text('Reference') . qq|</th>
<td><input name=recurringreference size=20 value="$form->{recurringreference}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Startdate').qq|</th>
+ <th align=right nowrap>| . $locale->text('Startdate') . qq|</th>
<td><input name=recurringstartdate size=11 title="($myconfig{'dateformat'})" value=$form->{recurringstartdate}></td>
</tr>
$nextdate
@@ -777,26 +844,34 @@ sub schedule {
<br>
|;
-# type=submit $locale->text('Save Schedule')
-# type=submit $locale->text('Delete Schedule')
+ # type=submit $locale->text('Save Schedule')
+ # type=submit $locale->text('Delete Schedule')
- %button = ('save_schedule' => { ndx => 1, key => 'S', value => $locale->text('Save Schedule') },
- 'delete_schedule' => { ndx => 16, key => 'D', value => $locale->text('Delete Schedule') },
- );
-
- $form->print_button(\%button, 'save_schedule');
-
- if ($form->{recurring}) {
- $form->print_button(\%button, 'delete_schedule');
- }
+ %button = (
+ 'save_schedule' =>
+ { ndx => 1, key => 'S', value => $locale->text('Save Schedule') },
+ 'delete_schedule' =>
+ { ndx => 16, key => 'D', value => $locale->text('Delete Schedule') },
+ );
- # delete variables
- for (qw(action recurring)) { delete $form->{$_} }
- for (qw(reference startdate nextdate enddate repeat unit howmany payment print email message)) { delete $form->{"recurring$_"} }
+ $form->print_button( \%button, 'save_schedule' );
- $form->hide_form;
+ if ( $form->{recurring} ) {
+ $form->print_button( \%button, 'delete_schedule' );
+ }
- print qq|
+ # delete variables
+ for (qw(action recurring)) { delete $form->{$_} }
+ for (
+ qw(reference startdate nextdate enddate repeat unit howmany payment print email message)
+ )
+ {
+ delete $form->{"recurring$_"};
+ }
+
+ $form->hide_form;
+
+ print qq|
</form>
@@ -806,128 +881,157 @@ sub schedule {
}
-
sub save_schedule {
- $form->{recurring} = "";
+ $form->{recurring} = "";
- $form->{recurringreference} = $form->escape($form->{recurringreference},1);
- $form->{recurringmessage} = $form->escape($form->{recurringmessage},1);
- if ($form->{recurringstartdate}) {
- for (qw(reference startdate repeat unit howmany payment)) { $form->{recurring} .= qq|$form->{"recurring$_"},| }
- }
+ $form->{recurringreference} =
+ $form->escape( $form->{recurringreference}, 1 );
+ $form->{recurringmessage} = $form->escape( $form->{recurringmessage}, 1 );
+ if ( $form->{recurringstartdate} ) {
+ for (qw(reference startdate repeat unit howmany payment)) {
+ $form->{recurring} .= qq|$form->{"recurring$_"},|;
+ }
+ }
- @a = split /<option/, $form->unescape($form->{selectformname});
- @p = ();
+ @a = split /<option/, $form->unescape( $form->{selectformname} );
+ @p = ();
- for ($i = 1; $i <= $#a; $i++) {
- $a[$i] =~ /"(.*)"/;
- push @p, $1;
- }
+ for ( $i = 1 ; $i <= $#a ; $i++ ) {
+ $a[$i] =~ /"(.*)"/;
+ push @p, $1;
+ }
- $recurringemail = "";
- for (@p) { $recurringemail .= qq|$_:$form->{"emailformat$_"}:| if $form->{"email$_"} }
- chop $recurringemail;
-
- $recurringprint = "";
- for (@p) { $recurringprint .= qq|$_:$form->{"printformat$_"}:$form->{"printprinter$_"}:| if $form->{"print$_"} }
- chop $recurringprint;
+ $recurringemail = "";
+ for (@p) {
+ $recurringemail .= qq|$_:$form->{"emailformat$_"}:|
+ if $form->{"email$_"};
+ }
+ chop $recurringemail;
- $form->{recurring} .= qq|$recurringprint,$recurringemail,$form->{recurringmessage}| if $recurringemail || $recurringprint;
+ $recurringprint = "";
+ for (@p) {
+ $recurringprint .=
+ qq|$_:$form->{"printformat$_"}:$form->{"printprinter$_"}:|
+ if $form->{"print$_"};
+ }
+ chop $recurringprint;
- $form->save_recurring(undef, \%myconfig) if $form->{id};
+ $form->{recurring} .=
+ qq|$recurringprint,$recurringemail,$form->{recurringmessage}|
+ if $recurringemail || $recurringprint;
- if ($form->{recurringid}) {
- $form->redirect;
- } else {
- &update;
- }
+ $form->save_recurring( undef, \%myconfig ) if $form->{id};
-}
+ if ( $form->{recurringid} ) {
+ $form->redirect;
+ }
+ else {
+ &update;
+ }
+}
sub delete_schedule {
- $form->{recurring} = "";
+ $form->{recurring} = "";
- $form->save_recurring(undef, \%myconfig) if $form->{id};
+ $form->save_recurring( undef, \%myconfig ) if $form->{id};
- if ($form->{recurringid}) {
- $form->redirect;
- } else {
- &update;
- }
+ if ( $form->{recurringid} ) {
+ $form->redirect;
+ }
+ else {
+ &update;
+ }
}
-
sub reprint {
- $myconfig{vclimit} = 0;
- $pf = "print_form";
-
- for (qw(format formname media message)) { $temp{$_} = $form->{$_} }
-
- if ($form->{module} eq 'oe') {
- &order_links;
- &prepare_order;
- delete $form->{order_details};
- for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) }
- } else {
- if ($form->{type} eq 'invoice') {
- &invoice_links;
- &prepare_invoice;
- for (keys %$form) { $form->{$_} = $form->unquote($form->{$_}) }
- } else {
- &create_links;
- $form->{rowcount}--;
- for (1 .. $form->{rowcount}) { $form->{"amount_$_"} = $form->format_amount(\%myconfig, $form->{"amount_$_"}, 2) }
- for (split / /, $form->{taxaccounts}) { $form->{"tax_$_"} = $form->format_amount(\%myconfig, $form->{"tax_$_"}, 2) }
- $pf = "print_transaction";
- }
- for (qw(acc_trans invoice_details)) { delete $form->{$_} }
- }
-
- for (qw(department employee language month partsgroup project years)) { delete $form->{"all_$_"} }
-
- for (keys %temp) { $form->{$_} = $temp{$_} }
-
- $form->{rowcount}++;
- $form->{paidaccounts}++;
-
- delete $form->{paid};
-
- for (1 .. $form->{paidaccounts}) { $form->{"paid_$_"} = $form->format_amount(\%myconfig, $form->{"paid_$_"}, 2) }
-
- $form->{copies} = 1;
-
- &$pf;
-
- if ($form->{media} eq 'email') {
- # add email message
- $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};
-
- $form->{intnotes} .= qq|\n\n| if $form->{intnotes};
- $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\n|
- .$locale->text('Message: ');
-
- $form->{intnotes} .= ($form->{message}) ? $form->{message} : $locale->text('sent');
-
- $form->save_intnotes(\%myconfig, $form->{module});
- }
-
-}
+ $myconfig{vclimit} = 0;
+ $pf = "print_form";
+
+ for (qw(format formname media message)) { $temp{$_} = $form->{$_} }
+ if ( $form->{module} eq 'oe' ) {
+ &order_links;
+ &prepare_order;
+ delete $form->{order_details};
+ for ( keys %$form ) { $form->{$_} = $form->unquote( $form->{$_} ) }
+ }
+ else {
+ if ( $form->{type} eq 'invoice' ) {
+ &invoice_links;
+ &prepare_invoice;
+ for ( keys %$form ) { $form->{$_} = $form->unquote( $form->{$_} ) }
+ }
+ else {
+ &create_links;
+ $form->{rowcount}--;
+ for ( 1 .. $form->{rowcount} ) {
+ $form->{"amount_$_"} =
+ $form->format_amount( \%myconfig, $form->{"amount_$_"}, 2 );
+ }
+ for ( split / /, $form->{taxaccounts} ) {
+ $form->{"tax_$_"} =
+ $form->format_amount( \%myconfig, $form->{"tax_$_"}, 2 );
+ }
+ $pf = "print_transaction";
+ }
+ for (qw(acc_trans invoice_details)) { delete $form->{$_} }
+ }
+
+ for (qw(department employee language month partsgroup project years)) {
+ delete $form->{"all_$_"};
+ }
+
+ for ( keys %temp ) { $form->{$_} = $temp{$_} }
+
+ $form->{rowcount}++;
+ $form->{paidaccounts}++;
+
+ delete $form->{paid};
+
+ for ( 1 .. $form->{paidaccounts} ) {
+ $form->{"paid_$_"} =
+ $form->format_amount( \%myconfig, $form->{"paid_$_"}, 2 );
+ }
+
+ $form->{copies} = 1;
+
+ &$pf;
+
+ if ( $form->{media} eq 'email' ) {
+
+ # add email message
+ $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};
+
+ $form->{intnotes} .= qq|\n\n| if $form->{intnotes};
+ $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\n|
+ . $locale->text('Message: ');
+
+ $form->{intnotes} .=
+ ( $form->{message} ) ? $form->{message} : $locale->text('sent');
+
+ $form->save_intnotes( \%myconfig, $form->{module} );
+ }
+
+}
-sub continue { &{ $form->{nextsub} } };
-sub gl_transaction { &add };
-sub ar_transaction { &add_transaction(ar) };
-sub ap_transaction { &add_transaction(ap) };
-sub sales_invoice_ { &add_transaction(is) };
-sub vendor_invoice_ { &add_transaction(ir) };
+sub continue { &{ $form->{nextsub} } }
+sub gl_transaction { &add }
+sub ar_transaction { &add_transaction(ar) }
+sub ap_transaction { &add_transaction(ap) }
+sub sales_invoice_ { &add_transaction(is) }
+sub vendor_invoice_ { &add_transaction(ir) }
diff --git a/bin/arapprn.pl b/bin/arapprn.pl
index 9cd91e02..ceae64be 100644
--- a/bin/arapprn.pl
+++ b/bin/arapprn.pl
@@ -1,720 +1,815 @@
-#=====================================================================
-# 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
-#
-
-use Error qw(:try);
-use LedgerSMB::Template;
-
-# 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;
-
- if (($form->{'media'} eq 'screen') and ($form->{'format'} eq 'html')) {
- my $template = LedgerSMB::Template->new(\%myconfig, $form->{'formname'}, 'HTML');
- try {
- $template->render($form);
- $form->header;
- print $template->{'output'};
- exit;
- } catch Error::Simple with {
- my $E = shift;
- $form->error($E->stacktrace);
- };
- }
- $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;
-
- if (($form->{'media'} eq 'screen') and ($form->{'format'} eq 'html')) {
- my $template = LedgerSMB::Template->new(\%myconfig, $form->{'formname'}, 'HTML');
- try {
- $template->render($form);
- $form->header;
- print $template->{'output'};
- exit;
- } catch Error::Simple with {
- my $E = shift;
- $form->error($E->stacktrace);
- };
- }
- $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
+#
+
+use Error qw(:try);
+use LedgerSMB::Template;
+
+# 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;
+
+ if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
+ {
+ my $template =
+ LedgerSMB::Template->new( \%myconfig, $form->{'formname'}, 'HTML' );
+ try {
+ $template->render($form);
+ $form->header;
+ print $template->{'output'};
+ exit;
+ }
+ catch Error::Simple with {
+ my $E = shift;
+ $form->error( $E->stacktrace );
+ };
+ }
+ $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;
+
+ if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
+ {
+ my $template =
+ LedgerSMB::Template->new( \%myconfig, $form->{'formname'}, 'HTML' );
+ try {
+ $template->render($form);
+ $form->header;
+ print $template->{'output'};
+ exit;
+ }
+ catch Error::Simple with {
+ my $E = shift;
+ $form->error( $E->stacktrace );
+ };
+ }
+ $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 16fb2996..b6579805 100644
--- a/bin/bp.pl
+++ b/bin/bp.pl
@@ -1,547 +1,617 @@
-#=====================================================================
-# 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} } };
-
+#=====================================================================
+# 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/ca.pl b/bin/ca.pl
index 9554914d..ae2768e8 100644
--- a/bin/ca.pl
+++ b/bin/ca.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -43,12 +43,13 @@
#
# module for Chart of Accounts, Income Statement and Balance Sheet
# search and edit transactions posted by the GL, AR and AP
-#
+#
#======================================================================
use LedgerSMB::CA;
1;
+
# end of main
# this is for our long dates
@@ -79,27 +80,30 @@ use LedgerSMB::CA;
# $locale->text('Nov')
# $locale->text('Dec')
-
sub chart_of_accounts {
- CA->all_accounts(\%myconfig, \%$form);
+ CA->all_accounts( \%myconfig, \%$form );
- @column_index = qw(accno gifi_accno description debit credit);
+ @column_index = qw(accno gifi_accno description debit credit);
- $column_header{accno} = qq|<th class=listtop>|.$locale->text('Account').qq|</th>\n|;
- $column_header{gifi_accno} = qq|<th class=listtop>|.$locale->text('GIFI').qq|</th>\n|;
- $column_header{description} = qq|<th class=listtop>|.$locale->text('Description').qq|</th>\n|;
- $column_header{debit} = qq|<th class=listtop>|.$locale->text('Debit').qq|</th>\n|;
- $column_header{credit} = qq|<th class=listtop>|.$locale->text('Credit').qq|</th>\n|;
-
+ $column_header{accno} =
+ qq|<th class=listtop>| . $locale->text('Account') . qq|</th>\n|;
+ $column_header{gifi_accno} =
+ qq|<th class=listtop>| . $locale->text('GIFI') . qq|</th>\n|;
+ $column_header{description} =
+ qq|<th class=listtop>| . $locale->text('Description') . qq|</th>\n|;
+ $column_header{debit} =
+ qq|<th class=listtop>| . $locale->text('Debit') . qq|</th>\n|;
+ $column_header{credit} =
+ qq|<th class=listtop>| . $locale->text('Credit') . qq|</th>\n|;
- $form->{title} = $locale->text('Chart of Accounts');
+ $form->{title} = $locale->text('Chart of Accounts');
- $colspan = $#column_index + 1;
-
- $form->header;
+ $colspan = $#column_index + 1;
+
+ $form->header;
- print qq|
+ print qq|
<body>
<table border=0 width=100%>
@@ -107,55 +111,73 @@ sub chart_of_accounts {
<tr height="5"></tr>
<tr class=listheading>|;
- for (@column_index) { print $column_header{$_} }
+ for (@column_index) { print $column_header{$_} }
- print qq|
+ print qq|
</tr>
|;
-
- foreach $ca (@{ $form->{CA} }) {
-
- $description = $form->escape($ca->{description});
- $gifi_description = $form->escape($ca->{gifi_description});
-
- $href = qq|$form->{script}?path=$form->{path}&action=list&accno=$ca->{accno}&login=$form->{login}&sessionid=$form->{sessionid}&description=$description&gifi_accno=$ca->{gifi_accno}&gifi_description=$gifi_description|;
-
- if ($ca->{charttype} eq "H") {
- print qq|<tr class=listheading>|;
- for (qw(accno description)) { $column_data{$_} = "<th class=listheading>$ca->{$_}</th>" }
- $column_data{gifi_accno} = "<th class=listheading>$ca->{gifi_accno}&nbsp;</th>";
- } else {
- $i++; $i %= 2;
- print qq|<tr class=listrow$i>|;
- $column_data{accno} = "<td><a href=$href>$ca->{accno}</a></td>";
- $column_data{gifi_accno} = "<td><a href=$href&accounttype=gifi>$ca->{gifi_accno}</a>&nbsp;</td>";
- $column_data{description} = "<td>$ca->{description}</td>";
- }
-
- $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{debit}, 2, "&nbsp;")."</td>\n";
- $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{credit}, 2, "&nbsp;")."</td>\n";
-
- $totaldebit += $ca->{debit};
- $totalcredit += $ca->{credit};
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
+ foreach $ca ( @{ $form->{CA} } ) {
+
+ $description = $form->escape( $ca->{description} );
+ $gifi_description = $form->escape( $ca->{gifi_description} );
+
+ $href =
+qq|$form->{script}?path=$form->{path}&action=list&accno=$ca->{accno}&login=$form->{login}&sessionid=$form->{sessionid}&description=$description&gifi_accno=$ca->{gifi_accno}&gifi_description=$gifi_description|;
+
+ if ( $ca->{charttype} eq "H" ) {
+ print qq|<tr class=listheading>|;
+ for (qw(accno description)) {
+ $column_data{$_} = "<th class=listheading>$ca->{$_}</th>";
+ }
+ $column_data{gifi_accno} =
+ "<th class=listheading>$ca->{gifi_accno}&nbsp;</th>";
+ }
+ else {
+ $i++;
+ $i %= 2;
+ print qq|<tr class=listrow$i>|;
+ $column_data{accno} = "<td><a href=$href>$ca->{accno}</a></td>";
+ $column_data{gifi_accno} =
+"<td><a href=$href&accounttype=gifi>$ca->{gifi_accno}</a>&nbsp;</td>";
+ $column_data{description} = "<td>$ca->{description}</td>";
+ }
+
+ $column_data{debit} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ca->{debit}, 2, "&nbsp;" )
+ . "</td>\n";
+ $column_data{credit} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ca->{credit}, 2, "&nbsp;" )
+ . "</td>\n";
+
+ $totaldebit += $ca->{debit};
+ $totalcredit += $ca->{credit};
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
</tr>
|;
- }
+ }
+
+ for (qw(accno gifi_accno description)) {
+ $column_data{$_} = "<td>&nbsp;</td>";
+ }
- for (qw(accno gifi_accno description)) { $column_data{$_} = "<td>&nbsp;</td>" }
+ $column_data{debit} =
+ "<th align=right class=listtotal>"
+ . $form->format_amount( \%myconfig, $totaldebit, 2, 0 ) . "</th>";
+ $column_data{credit} =
+ "<th align=right class=listtotal>"
+ . $form->format_amount( \%myconfig, $totalcredit, 2, 0 ) . "</th>";
- $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, 0)."</th>";
- $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, 0)."</th>";
-
- print "<tr class=listtotal>";
+ print "<tr class=listtotal>";
- for (@column_index) { print "$column_data{$_}\n" }
+ for (@column_index) { print "$column_data{$_}\n" }
- print qq|
+ print qq|
</tr>
<tr>
<td colspan=$colspan><hr size=3 noshade></td>
@@ -168,57 +190,74 @@ sub chart_of_accounts {
}
-
sub list {
- $form->{title} = $locale->text('List Transactions');
- if ($form->{accounttype} eq 'gifi') {
- $form->{title} .= " - ".$locale->text('GIFI')." $form->{gifi_accno} - $form->{gifi_description}";
- } else {
- $form->{title} .= " - ".$locale->text('Account')." $form->{accno} - $form->{description}";
- }
+ $form->{title} = $locale->text('List Transactions');
+ if ( $form->{accounttype} eq 'gifi' ) {
+ $form->{title} .= " - "
+ . $locale->text('GIFI')
+ . " $form->{gifi_accno} - $form->{gifi_description}";
+ }
+ else {
+ $form->{title} .= " - "
+ . $locale->text('Account')
+ . " $form->{accno} - $form->{description}";
+ }
- # get departments
- $form->all_departments(\%myconfig);
- if (@{ $form->{all_department} }) {
- $form->{selectdepartment} = "<option>\n";
+ # get departments
+ $form->all_departments( \%myconfig );
+ if ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} = "<option>\n";
- for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
- }
+ for ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+ }
- $department = qq|
+ $department = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Department').qq|</th>
+ <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|
+ 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>
+ <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|
+ <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;
- $form->header;
-
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -241,17 +280,19 @@ sub list {
<table>
$department
<tr>
- <th align=right>|.$locale->text('From').qq|</th>
+ <th align=right>| . $locale->text('From') . qq|</th>
<td><input name=fromdate size=11 title="$myconfig{dateformat}"></td>
- <th align=right>|.$locale->text('To').qq|</th>
+ <th align=right>| . $locale->text('To') . qq|</th>
<td><input name=todate size=11 title="$myconfig{dateformat}"></td>
</tr>
$selectfrom
<tr>
- <th align=right>|.$locale->text('Include in Report').qq|</th>
+ <th align=right>| . $locale->text('Include in Report') . qq|</th>
<td colspan=3>
- <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('AR/AP').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('AR/AP') . qq|
+ <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('Subtotal') . qq|
</td>
</tr>
</table>
@@ -264,7 +305,9 @@ sub list {
<input type="hidden" name="path" value="$form->{path}">
<input type="hidden" name="sessionid" value="$form->{sessionid}">
-<br><button class="submit" type="submit" name="action" value="list_transactions">|.$locale->text('List Transactions').qq|</button>
+<br><button class="submit" type="submit" name="action" value="list_transactions">|
+ . $locale->text('List Transactions')
+ . qq|</button>
</form>
</body>
@@ -273,104 +316,133 @@ sub list {
}
-
sub list_transactions {
- CA->all_transactions(\%myconfig, \%$form);
-
- $department = $form->escape($form->{department});
- $projectnumber = $form->escape($form->{projectnumber});
- $title = $form->escape($form->{title});
+ CA->all_transactions( \%myconfig, \%$form );
- # construct href
- $href = "$form->{script}?action=list_transactions&department=$department&projectnumber=$projectnumber&title=$title";
- for (qw(path oldsort accno login sessionid fromdate todate accounttype gifi_accno l_heading l_subtotal l_accno)) { $href .= "&$_=$form->{$_}" }
+ $department = $form->escape( $form->{department} );
+ $projectnumber = $form->escape( $form->{projectnumber} );
+ $title = $form->escape( $form->{title} );
- $drilldown = $href;
- $drilldown .= "&sort=$form->{sort}";
+ # construct href
+ $href =
+"$form->{script}?action=list_transactions&department=$department&projectnumber=$projectnumber&title=$title";
+ for (
+ qw(path oldsort accno login sessionid fromdate todate accounttype gifi_accno l_heading l_subtotal l_accno)
+ )
+ {
+ $href .= "&$_=$form->{$_}";
+ }
- $href .= "&direction=$form->{direction}";
-
- $form->sort_order();
-
- $drilldown .= "&direction=$form->{direction}";
-
- $form->{prevreport} = $href unless $form->{prevreport};
- $href .= "&prevreport=".$form->escape($form->{prevreport});
- $drilldown .= "&prevreport=".$form->escape($form->{prevreport});
-
- # figure out which column comes first
- $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</a></th>|;
- $column_header{reference} = qq|<th><a class=listheading href=$href&sort=reference>|.$locale->text('Reference').qq|</a></th>|;
- $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
- $column_header{cleared} = qq|<th class=listheading>|.$locale->text('R').qq|</th>|;
- $column_header{source} = qq|<th class=listheading>|.$locale->text('Source').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{balance} = qq|<th class=listheading>|.$locale->text('Balance').qq|</th>|;
- $column_header{accno} = qq|<th class=listheading>|.$locale->text('AR/AP').qq|</th>|;
-
- @columns = qw(transdate reference description debit credit);
- if ($form->{link} =~ /_paid/) {
- @columns = qw(transdate reference description source cleared debit credit);
- }
- push @columns, "accno" if $form->{l_accno};
- @column_index = $form->sort_columns(@columns);
-
-
- if ($form->{accounttype} eq 'gifi') {
- for (qw(accno description)) { $form->{$_} = $form->{"gifi_$_"} }
- }
- if ($form->{accno}) {
- push @column_index, "balance";
- }
-
- $form->{title} = ($form->{accounttype} eq 'gifi') ? $locale->text('GIFI') : $locale->text('Account');
-
- $form->{title} .= " $form->{accno} - $form->{description}";
+ $drilldown = $href;
+ $drilldown .= "&sort=$form->{sort}";
+
+ $href .= "&direction=$form->{direction}";
+
+ $form->sort_order();
+
+ $drilldown .= "&direction=$form->{direction}";
+
+ $form->{prevreport} = $href unless $form->{prevreport};
+ $href .= "&prevreport=" . $form->escape( $form->{prevreport} );
+ $drilldown .= "&prevreport=" . $form->escape( $form->{prevreport} );
+
+ # figure out which column comes first
+ $column_header{transdate} =
+ qq|<th><a class=listheading href=$href&sort=transdate>|
+ . $locale->text('Date')
+ . qq|</a></th>|;
+ $column_header{reference} =
+ qq|<th><a class=listheading href=$href&sort=reference>|
+ . $locale->text('Reference')
+ . qq|</a></th>|;
+ $column_header{description} =
+ qq|<th><a class=listheading href=$href&sort=description>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
+ $column_header{cleared} =
+ qq|<th class=listheading>| . $locale->text('R') . qq|</th>|;
+ $column_header{source} =
+ qq|<th class=listheading>| . $locale->text('Source') . 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{balance} =
+ qq|<th class=listheading>| . $locale->text('Balance') . qq|</th>|;
+ $column_header{accno} =
+ qq|<th class=listheading>| . $locale->text('AR/AP') . qq|</th>|;
+
+ @columns = qw(transdate reference description debit credit);
+ if ( $form->{link} =~ /_paid/ ) {
+ @columns =
+ qw(transdate reference description source cleared debit credit);
+ }
+ push @columns, "accno" if $form->{l_accno};
+ @column_index = $form->sort_columns(@columns);
- if ($form->{department}) {
- ($department) = split /--/, $form->{department};
- $options = $locale->text('Department')." : $department<br>";
- }
- if ($form->{projectnumber}) {
- ($projectnumber) = split /--/, $form->{projectnumber};
- $options .= $locale->text('Project Number')." : $projectnumber<br>";
- }
+ if ( $form->{accounttype} eq 'gifi' ) {
+ for (qw(accno description)) { $form->{$_} = $form->{"gifi_$_"} }
+ }
+ if ( $form->{accno} ) {
+ push @column_index, "balance";
+ }
+ $form->{title} =
+ ( $form->{accounttype} eq 'gifi' )
+ ? $locale->text('GIFI')
+ : $locale->text('Account');
- if ($form->{fromdate} || $form->{todate}) {
+ $form->{title} .= " $form->{accno} - $form->{description}";
- if ($form->{fromdate}) {
- $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
+ if ( $form->{department} ) {
+ ($department) = split /--/, $form->{department};
+ $options = $locale->text('Department') . " : $department<br>";
}
- if ($form->{todate}) {
- $todate = $locale->date(\%myconfig, $form->{todate}, 1);
+ if ( $form->{projectnumber} ) {
+ ($projectnumber) = split /--/, $form->{projectnumber};
+ $options .= $locale->text('Project Number') . " : $projectnumber<br>";
}
-
- $form->{period} = "$fromdate - $todate";
- } else {
- $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
- }
- $form->{period} = "<a href=$form->{prevreport}>$form->{period}</a>" if $form->{prevreport};
-
- $options .= $form->{period};
-
-
- # construct callback
- $department = $form->escape($form->{department},1);
- $projectnumber = $form->escape($form->{projectnumber},1);
- $title = $form->escape($form->{title},1);
- $form->{prevreport} = $form->escape($form->{prevreport},1);
-
- $form->{callback} = "$form->{script}?action=list_transactions&department=$department&projectnumber=$projectnumber&title=$title";
- for (qw(path direction oldsort accno login sessionid fromdate todate accounttype gifi_accno l_heading l_subtotal l_accno prevreport)) { $form->{callback} .= "&$_=$form->{$_}" }
-
-
- $form->header;
+ 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 );
+ }
- print qq|
+ $form->{period} = "<a href=$form->{prevreport}>$form->{period}</a>"
+ if $form->{prevreport};
+
+ $options .= $form->{period};
+
+ # construct callback
+ $department = $form->escape( $form->{department}, 1 );
+ $projectnumber = $form->escape( $form->{projectnumber}, 1 );
+ $title = $form->escape( $form->{title}, 1 );
+ $form->{prevreport} = $form->escape( $form->{prevreport}, 1 );
+
+ $form->{callback} =
+"$form->{script}?action=list_transactions&department=$department&projectnumber=$projectnumber&title=$title";
+ for (
+ qw(path direction oldsort accno login sessionid fromdate todate accounttype gifi_accno l_heading l_subtotal l_accno prevreport)
+ )
+ {
+ $form->{callback} .= "&$_=$form->{$_}";
+ }
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -387,111 +459,134 @@ sub list_transactions {
<tr class=listheading>
|;
- for (@column_index) { print "$column_header{$_}\n" }
+ for (@column_index) { print "$column_header{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
- # add sort to callback
- $form->{callback} = $form->escape($form->{callback} . "&sort=$form->{sort}");
+ # add sort to callback
+ $form->{callback} =
+ $form->escape( $form->{callback} . "&sort=$form->{sort}" );
- if (@{ $form->{CA} }) {
- $sameitem = $form->{CA}->[0]->{$form->{sort}};
- }
+ if ( @{ $form->{CA} } ) {
+ $sameitem = $form->{CA}->[0]->{ $form->{sort} };
+ }
- $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
- $ml *= -1 if $form->{contra};
+ $ml = ( $form->{category} =~ /(A|E)/ ) ? -1 : 1;
+ $ml *= -1 if $form->{contra};
- if ($form->{accno} && $form->{balance}) {
-
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+ if ( $form->{accno} && $form->{balance} ) {
- $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
- $i++; $i %= 2;
-
- print qq|
+ $column_data{balance} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $form->{balance} * $ml, 2, 0 )
+ . "</td>";
+
+ $i++;
+ $i %= 2;
+
+ print qq|
<tr class=listrow$i>
|;
- for (@column_index) { print "$column_data{$_}\n" }
- print qq|
+ for (@column_index) { print "$column_data{$_}\n" }
+ print qq|
</tr>
|;
- }
-
- foreach $ca (@{ $form->{CA} }) {
-
- if ($form->{l_subtotal} eq 'Y') {
- if ($sameitem ne $ca->{$form->{sort}}) {
- &ca_subtotal;
- }
}
-
- # construct link to source
- $href = "<a href=$ca->{module}.pl?path=$form->{path}&action=edit&id=$ca->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$form->{callback}>$ca->{reference}</a>";
-
-
- $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{debit}, 2, "&nbsp;")."</td>";
- $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ca->{credit}, 2, "&nbsp;")."</td>";
-
- $form->{balance} += $ca->{amount};
- $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
-
- $subtotaldebit += $ca->{debit};
- $subtotalcredit += $ca->{credit};
-
- $totaldebit += $ca->{debit};
- $totalcredit += $ca->{credit};
-
- $column_data{transdate} = qq|<td>$ca->{transdate}</td>|;
- $column_data{reference} = qq|<td>$href</td>|;
- $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
-
- $column_data{cleared} = ($ca->{cleared}) ? qq|<td>*</td>| : qq|<td>&nbsp;</td>|;
- $column_data{source} = qq|<td>$ca->{source}&nbsp;</td>|;
-
- $column_data{accno} = qq|<td>|;
- for (@{ $ca->{accno} }) { $column_data{accno} .= "<a href=$drilldown&accno=$_>$_</a> " }
- $column_data{accno} .= qq|&nbsp;</td>|;
-
- if ($ca->{id} != $sameid) {
- $i++; $i %= 2;
- }
- $sameid = $ca->{id};
- print qq|
+ foreach $ca ( @{ $form->{CA} } ) {
+
+ if ( $form->{l_subtotal} eq 'Y' ) {
+ if ( $sameitem ne $ca->{ $form->{sort} } ) {
+ &ca_subtotal;
+ }
+ }
+
+ # construct link to source
+ $href =
+"<a href=$ca->{module}.pl?path=$form->{path}&action=edit&id=$ca->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$form->{callback}>$ca->{reference}</a>";
+
+ $column_data{debit} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ca->{debit}, 2, "&nbsp;" )
+ . "</td>";
+ $column_data{credit} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ca->{credit}, 2, "&nbsp;" )
+ . "</td>";
+
+ $form->{balance} += $ca->{amount};
+ $column_data{balance} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $form->{balance} * $ml, 2, 0 )
+ . "</td>";
+
+ $subtotaldebit += $ca->{debit};
+ $subtotalcredit += $ca->{credit};
+
+ $totaldebit += $ca->{debit};
+ $totalcredit += $ca->{credit};
+
+ $column_data{transdate} = qq|<td>$ca->{transdate}</td>|;
+ $column_data{reference} = qq|<td>$href</td>|;
+ $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
+
+ $column_data{cleared} =
+ ( $ca->{cleared} ) ? qq|<td>*</td>| : qq|<td>&nbsp;</td>|;
+ $column_data{source} = qq|<td>$ca->{source}&nbsp;</td>|;
+
+ $column_data{accno} = qq|<td>|;
+ for ( @{ $ca->{accno} } ) {
+ $column_data{accno} .= "<a href=$drilldown&accno=$_>$_</a> ";
+ }
+ $column_data{accno} .= qq|&nbsp;</td>|;
+
+ if ( $ca->{id} != $sameid ) {
+ $i++;
+ $i %= 2;
+ }
+ $sameid = $ca->{id};
+
+ print qq|
<tr class=listrow$i>
|;
- for (@column_index) { print "$column_data{$_}\n" }
+ for (@column_index) { print "$column_data{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
- }
-
+ }
- if ($form->{l_subtotal} eq 'Y') {
- &ca_subtotal;
- }
-
+ if ( $form->{l_subtotal} eq 'Y' ) {
+ &ca_subtotal;
+ }
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;")."</th>";
- $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;")."</th>";
- $column_data{balance} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</th>";
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{debit} =
+ "<th align=right class=listtotal>"
+ . $form->format_amount( \%myconfig, $totaldebit, 2, "&nbsp;" ) . "</th>";
+ $column_data{credit} =
+ "<th align=right class=listtotal>"
+ . $form->format_amount( \%myconfig, $totalcredit, 2, "&nbsp;" ) . "</th>";
+ $column_data{balance} =
+ "<th align=right class=listtotal>"
+ . $form->format_amount( \%myconfig, $form->{balance} * $ml, 2, 0 )
+ . "</th>";
- print qq|
+ print qq|
<tr class=listtotal>
|;
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
</tr>
</table>
</td>
@@ -504,29 +599,34 @@ sub list_transactions {
</body>
</html>
|;
-
-}
+}
sub ca_subtotal {
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $column_data{debit} = "<th align=right class=listsubtotal>".$form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;") . "</th>";
- $column_data{credit} = "<th align=right class=listsubtotal>".$form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;") . "</th>";
-
- $subtotaldebit = 0;
- $subtotalcredit = 0;
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
- $sameitem = $ca->{$form->{sort}};
+ $column_data{debit} =
+ "<th align=right class=listsubtotal>"
+ . $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{credit} =
+ "<th align=right class=listsubtotal>"
+ . $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" )
+ . "</th>";
- print qq|
+ $subtotaldebit = 0;
+ $subtotalcredit = 0;
+
+ $sameitem = $ca->{ $form->{sort} };
+
+ print qq|
<tr class=listsubtotal>
|;
- for (@column_index) { print "$column_data{$_}\n" }
+ for (@column_index) { print "$column_data{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
diff --git a/bin/cp.pl b/bin/cp.pl
index 8665fb29..c643b7d8 100644
--- a/bin/cp.pl
+++ b/bin/cp.pl
@@ -1,1440 +1,1648 @@
-#=====================================================================
-# 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
-#
-# Contributors:
-#
-#
-# Author: DWS Systems Inc.
-# Web: http://www.ledgersmb.org/
-#
-# Contributors:
-#
-# 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.
-#======================================================================
-#
-# Payment module
-#
-#======================================================================
-
-use Error qw(:try);
-
-use LedgerSMB::Template;
-use LedgerSMB::CP;
-use LedgerSMB::OP;
-use LedgerSMB::IS;
-use LedgerSMB::IR;
-
-require "bin/arap.pl";
-
-1;
-# end of main
-
-
-sub payment {
-
- if ($form->{type} eq 'receipt') {
- $form->{ARAP} = "AR";
- $form->{arap} = "ar";
- $form->{vc} = "customer";
- $form->{formname} = "receipt";
- }
- if ($form->{type} eq 'check') {
- $form->{ARAP} = "AP";
- $form->{arap} = "ap";
- $form->{vc} = "vendor";
- $form->{formname} = "check";
- }
-
- $form->{payment} = "payment";
-
- $form->{callback} = "$form->{script}?action=payment&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&all_vc=$form->{all_vc}&type=$form->{type}";
-
- # setup customer/vendor selection for open invoices
- if ($form->{all_vc}) {
- $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP}, undef, $form->{datepaid});
- } else {
- CP->get_openvc(\%myconfig, \%$form);
- if ($myconfig{vclimit} > 0) {
- $form->{"all_$form->{vc}"} = $form->{name_list};
- }
- }
-
- $form->{"select$form->{vc}"} = "";
- if (@{ $form->{"all_$form->{vc}"} }) {
- $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
- for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
-
- # departments
- if (@{ $form->{all_department} }) {
- $form->{selectdepartment} = "<option>\n";
- $form->{department} = "$form->{department}--$form->{department_id}" if $form->{department};
-
- for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
- }
-
- if (@{ $form->{all_language} }) {
- $form->{selectlanguage} = "<option>\n";
- for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
- }
-
- CP->paymentaccounts(\%myconfig, \%$form);
-
- $form->{selectaccount} = "";
- $form->{"select$form->{ARAP}"} = "";
-
- for (@{ $form->{PR}{"$form->{ARAP}_paid"} }) { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
- for (@{ $form->{PR}{$form->{ARAP}} }) { $form->{"select$form->{ARAP}"} .= "<option>$_->{accno}--$_->{description}\n" }
-
- # currencies
- @curr = split /:/, $form->{currencies};
- $form->{defaultcurrency} = $curr[0];
- chomp $form->{defaultcurrency};
-
- $form->{selectcurrency} = "";
- for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
-
- $form->{currency} = $form->{defaultcurrency};
- $form->{oldcurrency} = $form->{currency};
-
- if ($form->{currency} ne $form->{defaultcurrency}) {
- $form->{forex} = $form->{exchangerate} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{datepaid}, ($form->{vc} eq 'customer') ? "buy" : "sell");
- }
-
- $form->{olddatepaid} = $form->{datepaid};
-
- $form->{media} = $myconfig{printer};
- $form->{format} = "pdf" unless $myconfig{printer};
-
- &payment_header;
- &payment_footer;
-
-}
-
-
-sub payments {
-
- if ($form->{type} eq 'receipt') {
- $form->{ARAP} = "AR";
- $form->{arap} = "ar";
- $form->{vc} = "customer";
- $form->{formname} = "receipt";
- }
- if ($form->{type} eq 'check') {
- $form->{ARAP} = "AP";
- $form->{arap} = "ap";
- $form->{vc} = "vendor";
- $form->{formname} = "check";
- }
-
- $form->{payment} = "payments";
-
- $form->{callback} = "$form->{script}?action=$form->{action}";
- for (qw(path login sessionid type)) { $form->{callback} .= "&$_=$form->{$_}" }
-
- CP->paymentaccounts(\%myconfig, \%$form);
-
- if (@{ $form->{all_language} }) {
- $form->{selectlanguage} = "<option>\n";
- for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
- }
-
- # departments
- if (@{ $form->{all_department} }) {
- $form->{selectdepartment} = "<option>\n";
- $form->{department} = "$form->{department}--$form->{department_id}" if $form->{department};
-
- for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
- }
-
- $form->{selectaccount} = "";
- $form->{"select$form->{ARAP}"} = "";
-
- for (@{ $form->{PR}{"$form->{ARAP}_paid"} }) { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
- for (@{ $form->{PR}{$form->{ARAP}} }) { $form->{"select$form->{ARAP}"} .= "<option>$_->{accno}--$_->{description}\n" }
-
- # currencies
- @curr = split /:/, $form->{currencies};
- $form->{defaultcurrency} = $curr[0];
- chomp $form->{defaultcurrency};
-
- $form->{selectcurrency} = "";
- for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
-
- $form->{oldcurrency} = $form->{currency} = $form->{defaultcurrency};
- $form->{oldduedateto} = $form->{datepaid};
-
- $form->{media} = $myconfig{printer};
- $form->{format} = "pdf" unless $myconfig{printer};
-
- &payments_header;
- &invoices_due;
- &payments_footer;
-
-}
-
-
-sub payments_header {
-
- if ($form->{type} eq 'receipt') {
- $form->{title} = $locale->text('Receipts');
- }
- if ($form->{type} eq 'check') {
- $form->{title} = $locale->text('Payments');
- }
-
-
- for ("department") {
- $form->{"select$_"} = $form->unescape($form->{"select$_"});
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
- }
-
- for ("account", "currency", "$form->{ARAP}") {
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
- }
-
- if ($form->{defaultcurrency}) {
- $exchangerate = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Currency').qq|</th>
- <td><select name=currency>$form->{selectcurrency}</select></td>
- <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
- <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
- </tr>
-|;
- }
-
- if ($form->{currency} ne $form->{defaultcurrency}) {
- $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
-
- if ($form->{forex}) {
- $exchangerate .= qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th>
- <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
- </tr>
-|;
- } else {
- $exchangerate .= qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th>
- <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
- </tr>
-|;
- }
- }
-
- $department = qq|
- <tr>
- <th align="right" nowrap>|.$locale->text('Department').qq|</th>
- <td><select name=department>$form->{selectdepartment}</select>
- <input type=hidden name=selectdepartment value="|.$form->escape($form->{selectdepartment},1).qq|">
- </td>
- </tr>
-| if $form->{selectdepartment};
-
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-|;
-
- $form->hide_form(qw(defaultcurrency closedto vc type formname arap ARAP title oldduedatefrom oldduedateto payment olddepartment));
-
- print qq|
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>
- <table width=100%>
- <tr valign=top>
- <td>
- <table>
- <tr>
- <th align=right>|.$locale->text('Due Date').qq|&nbsp;|.$locale->text('From').qq|</th>
- <td><input name=duedatefrom value="$form->{duedatefrom}" title="$myconfig{dateformat}" size=11></td>
- <th align=right>|.$locale->text('To').qq|</th>
- <td><input name=duedateto value="$form->{duedateto}" title="$myconfig{dateformat}" size=11></td>
- </tr>
- </table>
- </td>
- </td>
- <td align=right>
- <table>
- $department
- <tr>
- <th align=right nowrap>|.$locale->text($form->{ARAP}).qq|</th>
- <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select>
- </td>
- <input type=hidden name="select$form->{ARAP}" value="$form->{"select$form->{ARAP}"}">
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Account').qq|</th>
- <td colspan=3><select name=account>$form->{selectaccount}</select>
- <input type=hidden name=selectaccount value="$form->{selectaccount}">
- </td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Date').qq|</th>
- <td><input name=datepaid value="$form->{datepaid}" title="$myconfig{dateformat}" size=11></td>
- </tr>
- $exchangerate
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
-|;
-
-}
-
-
-sub invoices_due {
-
- @column_index = qw(name invnumber transdate amount due checked paid memo source);
- push @column_index, "language" if $form->{selectlanguage};
-
- $colspan = $#column_index + 1;
-
- $invoice = $locale->text('Invoices');
- $vclabel = ucfirst $form->{vc};
- $vclabel = $locale->text($vclabel);
-
- print qq|
- <input type=hidden name=column_index value="id @column_index">
- <tr>
- <td>
- <table width=100%>
- <tr>
- <th class=listheading colspan=$colspan>$invoice</th>
- </tr>
-|;
-
- $column_data{name} = qq|<th nowrap>$vclabel</th>|;
- $column_data{invnumber} = qq|<th nowrap>|.$locale->text('Invoice')."</th>";
- $column_data{transdate} = qq|<th nowrap>|.$locale->text('Date')."</th>";
- $column_data{amount} = qq|<th nowrap>|.$locale->text('Amount')."</th>";
- $column_data{due} = qq|<th nowrap>|.$locale->text('Amount Due')."</th>";
- $column_data{paid} = qq|<th nowrap>|.$locale->text('Amount')."</th>";
- $column_data{checked} = qq|<th nowrap>|.$locale->text('Select')."</th>";
- $column_data{memo} = qq|<th nowrap>|.$locale->text('Memo')."</th>";
- $column_data{source} = qq|<th nowrap>|.$locale->text('Source')."</th>";
- $column_data{language} = qq|<th nowrap>|.$locale->text('Language')."</th>";
-
- print qq|
- <tr>
-|;
- for (@column_index) { print "$column_data{$_}\n" }
- print qq|
- </tr>
-|;
-
- $form->{selectlanguage} = $form->unescape($form->{selectlanguage});
-
- for $i (1 .. $form->{rowcount}) {
-
- for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- $totalamount += $form->{"amount_$i"};
- $totaldue += $form->{"due_$i"};
- if ($form->{"paid_$i"} !~ /NaN/){
- $totalpaid += $form->{"paid_$i"};
- } else {
- $form->{"paid_$i"} = '';
- }
- for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
-
- $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
- <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
- <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
- $column_data{transdate} = qq|<td>$form->{"transdate_$i"}</td>
- <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
- $column_data{amount} = qq|<td align=right>$form->{"amount_$i"}</td>
- <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
- $column_data{due} = qq|<td align=right>$form->{"due_$i"}</td>
- <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
-
- $column_data{paid} = qq|<td align=right><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
-
- if ($same_id eq $form->{"$form->{vc}_id_$i"}) {
- for (qw(name memo source language)) { $column_data{$_} = qq|<td>&nbsp;</td>| }
- } else {
- $column_data{name} = qq|<td>$form->{"name_$i"}</td>|;
- $column_data{memo} = qq|<td align=right><input name="memo_$i" size=10 value="$form->{"memo_$i"}"></td>|;
- $column_data{source} = qq|<td align=right><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|;
-
- if ($form->{selectlanguage}) {
- $selectlanguage = $form->{selectlanguage};
- $selectlanguage =~ s/(<option value="\Q$form->{"language_code_$i"}\E")/$1 selected/;
- $column_data{language} = qq|<td><select name="language_code_$i">$selectlanguage</select></td>|;
- }
-
- }
-
- $column_data{name} .= qq|
- <input type=hidden name="name_$i" value="$form->{"name_$i"}">
- <input type=hidden name="$form->{vc}_id_$i" value="$form->{"$form->{vc}_id_$i"}">|;
-
- $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
- $column_data{checked} = qq|<td align=center><input name="checked_$i" type=checkbox class=checkbox $form->{"checked_$i"}></td>|;
-
- $j++; $j %= 2;
- print qq|
- <tr class=listrow$j>
-|;
- for (@column_index) { print "$column_data{$_}\n" }
- print qq|
- </tr>
-|;
-
- $same_id = $form->{"$form->{vc}_id_$i"};
-
- }
-
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $column_data{amount} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totalamount, 2, "&nbsp;").qq|</th>|;
- $column_data{due} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totaldue, 2, "&nbsp;").qq|</th>|;
- $column_data{paid} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;").qq|</th>|;
-
- print qq|
- <tr class=listtotal>
-|;
- for (@column_index) { print "$column_data{$_}\n" }
- print qq|
- </tr>
- </table>
- </td>
- </tr>
-<input type=hidden name=selectlanguage value="|.$form->escape($form->{selectlanguage},1).qq|">
-|;
-
-}
-
-
-sub payments_footer {
-
- $form->{DF}{$form->{format}} = "selected";
-
- $transdate = $form->datetonum(\%myconfig, $form->{datepaid});
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
-
- if (${LedgerSMB::Sysconfig::latex}) {
-
- $media = qq|<select name=media>
- <option value=screen>|.$locale->text('Screen');
-
- if (%{LedgerSMB::Sysconfig::printer}) {
- for (sort keys %{LedgerSMB::Sysconfig::printer}) { $media .= qq|
- <option value="$_">$_| }
- }
-
- $media .= qq|</select>|;
- $format = qq|<select name=format>
- <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq|
- <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF').qq|</select>|;
- }
-
- print qq|
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-|;
-
-# type=submit $locale->text('Update')
-# type=submit $locale->text('Post')
-# type=submit $locale->text('Print')
-# type=submit $locale->text('Select all')
-
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- 'select_all' => { ndx => 2, key => 'A', value => $locale->text('Select all') },
- 'print' => { ndx => 3, key => 'P', value => $locale->text('Print') },
- 'post' => { ndx => 4, key => 'O', value => $locale->text('Post') },
- );
-
- if (! ${LedgerSMB::Sysconfig::latex}) {
- delete $button{'print'};
- }
-
- if ($transdate <= $closedto) {
- for ('post', 'print') { delete $button{$_} }
- $media = $format = "";
- }
-
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
-
- $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
-
- print qq|
- $format
- $media
-|;
-
- $form->hide_form(qw(callback rowcount path login sessionid));
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
- </form>
-
-</body>
-</html>
-|;
-
-}
-
-
-sub select_all {
-
- for (1 .. $form->{rowcount}) { $form->{"checked_$_"} = 1 }
- &{"update_$form->{payment}"}
-
-}
-
-
-sub update {
- my ($new_name_selected) = @_;
-
- &{"update_$form->{payment}"};
-
-}
-
-
-sub update_payments {
-
- if ($form->{ARAP} eq 'AR') {
- $buysell = "buy";
- } else {
- $buysell = "sell";
- }
-
- if (($form->{oldduedatefrom} ne $form->{duedatefrom}) || ($form->{oldduedateto} ne $form->{duedateto}) || ($form->{department} ne $form->{olddepartment})) {
- CP->get_openinvoices(\%myconfig, \%$form);
- $form->{redo} = 1;
- }
-
- if ($form->{currency} ne $form->{oldcurrency}) {
- $form->{oldcurrency} = $form->{currency};
- if (!$form->{redo}) {
- CP->get_openinvoices(\%myconfig, \%$form);
- $form->{redo} = 1;
- }
- }
-
- for (qw(duedatefrom duedateto department)) { $form->{"old$_"} = $form->{$_} }
-
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{datepaid}, $buysell)));
-
- if ($form->{redo}) {
- $form->{rowcount} = 0;
-
- $i = 0;
- foreach $ref (@{ $form->{PR} }) {
- $i++;
- for (qw(id name invnumber transdate)) { $form->{"${_}_$i"} = $ref->{$_} }
- $form->{"$form->{vc}_id_$i"} = $ref->{"$form->{vc}_id"};
- $ref->{exchangerate} = 1 unless $ref->{exchangerate};
- $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
- $form->{"due_$i"} = ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
- $form->{"checked_$i"} = "";
- $form->{"paid_$i"} = "";
-
- # need to format
- for (qw(amount due)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
- }
-
- $form->{rowcount} = $i;
- }
-
- $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
-
- # recalculate
- $amount = 0;
- for $i (1 .. $form->{rowcount}) {
-
- for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- if ($form->{"checked_$i"}) {
- # calculate paid_$i
- if (!$form->{"paid_$i"}) {
- $form->{"paid_$i"} = $form->{"due_$i"};
- }
-
- $amount += $form->{"paid_$i"};
- $form->{redo} = 1;
- } else {
- $form->{"paid_$i"} = "";
- }
-
- for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
- }
-
- $form->{amount} += ($amount - $form->{oldamount}) if $form->{redo};
-
- &payments_header;
- &invoices_due;
- &payments_footer;
-
-}
-
-
-sub update_payment {
-
- if ($form->{vc} eq 'customer') {
- $buysell = "buy";
- } else {
- $buysell = "sell";
- }
-
- $department = $form->{department};
-
- # get customer/vendor
- &check_openvc;
- $form->{department} = $department;
-
- if ($form->{datepaid} ne $form->{olddatepaid}) {
- $form->{olddatepaid} = $form->{datepaid};
- $form->{oldall_vc} = !$form->{oldall_vc} if $form->{all_vc};
- }
-
- if ($form->{department} ne $form->{olddepartment}) {
- $form->{olddepartment} = $form->{department};
- $form->{redo} = 1;
- }
-
- # if we switched to all_vc
- if ($form->{all_vc} ne $form->{oldall_vc}) {
-
- if ($form->{"select$form->{vc}"}) {
- $form->{redo} = ($form->{"old$name"} ne $form->{$name});
- } else {
- $form->{redo} = ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|);
- }
-
- $form->{"select$form->{vc}"} = "";
-
- if ($form->{all_vc}) {
- $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP}, undef, $form->{datepaid});
-
- if (@{ $form->{"all_$form->{vc}"} }) {
- for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
-
- } else {
- if (($myconfig{vclimit} * 1) > 0) {
- $form->{$form->{vc}} = "";
- }
-
- CP->get_openvc(\%myconfig, \%$form);
-
- if (($myconfig{vclimit} * 1) > 0) {
- $form->{"all_$form->{vc}"} = $form->{name_list};
- }
-
- if (@{ $form->{"all_$form->{vc}"} }) {
- $newvc = qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
- for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
-
-
- # if the name is not the same
- if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
- $form->{$form->{vc}} = $newvc;
- &check_openvc;
- }
- }
- }
-
- if (@{ $form->{all_language} }) {
- $form->{selectlanguage} = "<option>\n";
- for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
- }
-
- }
-
- if ($new_name_selected || $form->{redo}) {
- CP->get_openinvoices(\%myconfig, \%$form);
- ($newvc) = split /--/, $form->{$form->{vc}};
- $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;;
- $form->{redo} = 1;
- }
-
- if ($form->{currency} ne $form->{oldcurrency}) {
- $form->{oldcurrency} = $form->{currency};
- if (!$form->{redo}) {
- CP->get_openinvoices(\%myconfig, \%$form);
- $form->{redo} = 1;
- }
- }
-
-
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{datepaid}, $buysell)));
-
- if ($form->{redo}) {
- $form->{rowcount} = 0;
-
- $i = 0;
- foreach $ref (@{ $form->{PR} }) {
- $i++;
- $form->{"id_$i"} = $ref->{id};
- $form->{"invnumber_$i"} = $ref->{invnumber};
- $form->{"transdate_$i"} = $ref->{transdate};
- $ref->{exchangerate} = 1 unless $ref->{exchangerate};
- $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
- $form->{"due_$i"} = ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
- $form->{"checked_$i"} = "";
- $form->{"paid_$i"} = "";
-
- # need to format
- for (qw(amount due)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
- }
- $form->{rowcount} = $i;
- }
-
- $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
-
- # recalculate
- $amount = 0;
- for $i (1 .. $form->{rowcount}) {
-
- for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- if ($form->{"checked_$i"}) {
- # calculate paid_$i
- if (!$form->{"paid_$i"}) {
- $form->{"paid_$i"} = $form->{"due_$i"};
- }
-
- $amount += $form->{"paid_$i"};
- $form->{redo} = 1;
- } else {
- $form->{"paid_$i"} = "";
- }
-
- for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
- }
-
- $form->{amount} += ($amount - $form->{oldamount}) if $form->{redo};
-
- &payment_header;
- &list_invoices;
- &payment_footer;
-
-}
-
-
-
-
-sub payment_header {
-
- $vclabel = ucfirst $form->{vc};
- $vclabel = $locale->text($vclabel);
-
- if ($form->{type} eq 'receipt') {
- $form->{title} = $locale->text('Receipt');
- }
- if ($form->{type} eq 'check') {
- $form->{title} = $locale->text('Payment');
- }
-
-
-# $locale->text('Customer')
-# $locale->text('Vendor')
-
- if ($form->{$form->{vc}} eq "") {
- for (qw(address1 address2 city zipcode state country)) { $form->{$_} = "" }
- }
-
- for ("$form->{vc}", "department") {
- $form->{"select$_"} = $form->unescape($form->{"select$_"});
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
- }
-
- for ("account", "currency", "$form->{ARAP}") {
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
- }
-
- if ($form->{defaultcurrency}) {
- $exchangerate = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Currency').qq|</th>
- <td><select name=currency>$form->{selectcurrency}</select></td>
- <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
- <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
- </tr>
-|;
- }
-
- if ($form->{currency} ne $form->{defaultcurrency}) {
- $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
-
- if ($form->{forex}) {
- $exchangerate .= qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th>
- <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
- </tr>
-|;
- } else {
- $exchangerate .= qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th>
- <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
- </tr>
-|;
- }
- }
-
- $vc = ($form->{"select$form->{vc}"}) ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>| : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
-
- if ($form->{all_vc}) {
- $allvc = "checked";
- } else {
- $allvc = "";
- }
-
-# $locale->text('AR')
-# $locale->text('AP')
-
- $department = qq|
- <tr>
- <th align="right" nowrap>|.$locale->text('Department').qq|</th>
- <td><select name=department>$form->{selectdepartment}</select>
- <input type=hidden name=selectdepartment value="|.$form->escape($form->{selectdepartment},1).qq|">
- </td>
- </tr>
-| if $form->{selectdepartment};
-
- $form->header;
-
- print qq|
-<body>
-
-<form method=post action=$form->{script}>
-|;
-
- $form->hide_form(qw(defaultcurrency closedto vc type ARAP arap title formname payment olddepartment));
-
- print qq|
-
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>
- <table width=100%>
- <tr valign=top>
- <td>
- <table>
- <tr>
- <td align=right>
- <input name=all_vc type=checkbox class=checkbox value=Y $allvc>
- <input type=hidden name="oldall_vc" value="$form->{all_vc}"></td>
- <th align=left>|.$locale->text('All').qq|</th>
- </tr>
- <tr>
- <th align=right>$vclabel</th>
- <td>$vc</td>
- <input type=hidden name="select$form->{vc}" value="|.$form->escape($form->{"select$form->{vc}"},1).qq|">
- <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
- <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
- </tr>
- <tr valign=top>
- <th align=right nowrap>|.$locale->text('Address').qq|</th>
- <td colspan=2>
- <table>
- <tr>
- <td>$form->{address1}</td>
- </tr>
- <tr>
- <td>$form->{address2}</td>
- </tr>
- <td>$form->{city}</td>
- </tr>
- </tr>
- <td>$form->{state}</td>
- </tr>
- </tr>
- <td>$form->{zipcode}</td>
- </tr>
- <tr>
- <td>$form->{country}</td>
- </tr>
- </table>
- </td>
- <input type=hidden name=address1 value="$form->{address1}">
- <input type=hidden name=address2 value="$form->{address2}">
- <input type=hidden name=city value="$form->{city}">
- <input type=hidden name=state value="$form->{state}">
- <input type=hidden name=zipcode value="$form->{zipcode}">
- <input type=hidden name=country value="$form->{country}">
- </tr>
- <tr>
- <th align=right>|.$locale->text('Memo').qq|</th>
- <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
- </tr>
- </table>
- </td>
- <td align=right>
- <table>
- $department
- <tr>
- <th align=right nowrap>|.$locale->text($form->{ARAP}).qq|</th>
- <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select>
- </td>
- <input type=hidden name="select$form->{ARAP}" value="$form->{"select$form->{ARAP}"}">
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Account').qq|</th>
- <td colspan=3><select name=account>$form->{selectaccount}</select>
- <input type=hidden name=selectaccount value="$form->{selectaccount}">
- </td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Date').qq|</th>
- <td><input name=datepaid value="$form->{datepaid}" title="$myconfig{dateformat}" size=11></td>
- <input type=hidden name=olddatepaid value=$form->{olddatepaid}>
- </tr>
- $exchangerate
- <tr>
- <th align=right nowrap>|.$locale->text('Source').qq|</th>
- <td colspan=3><input name=source value="$form->{source}" size=10></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Amount').qq|</th>
- <td colspan=3><input name=amount size=10 value=|.$form->format_amount(\%myconfig, $form->{amount}, 2).qq|></td>
- <input type=hidden name=oldamount value=$form->{amount}>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
-|;
-
-}
-
-
-sub list_invoices {
-
- @column_index = qw(invnumber transdate amount due checked paid);
-
- $colspan = $#column_index + 1;
-
- $invoice = $locale->text('Invoices');
-
- print qq|
- <input type=hidden name=column_index value="id @column_index">
- <tr>
- <td>
- <table width=100%>
- <tr>
- <th class=listheading colspan=$colspan>$invoice</th>
- </tr>
-|;
-
- $column_data{invnumber} = qq|<th nowrap>|.$locale->text('Invoice')."</th>";
- $column_data{transdate} = qq|<th nowrap>|.$locale->text('Date')."</th>";
- $column_data{amount} = qq|<th nowrap>|.$locale->text('Amount')."</th>";
- $column_data{due} = qq|<th nowrap>|.$locale->text('Amount Due')."</th>";
- $column_data{paid} = qq|<th nowrap>|.$locale->text('Amount')."</th>";
- $column_data{checked} = qq|<th nowrap>|.$locale->text('Select')."</th>";
-
- print qq|
- <tr>
-|;
- for (@column_index) { print "$column_data{$_}\n" }
- print qq|
- </tr>
-|;
-
- for $i (1 .. $form->{rowcount}) {
-
- for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- $totalamount += $form->{"amount_$i"};
- $totaldue += $form->{"due_$i"};
- if ($form->{"paid_$i"} =~ /NaN/){
- $form->{"paid_$i"} = '';
- } else {
- $totalpaid += $form->{"paid_$i"};
- }
-
- for (qw(amount due paid)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
-
- $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
- <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
- <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
- $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
- <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
- $column_data{amount} = qq|<td align=right width=15%>$form->{"amount_$i"}</td>
- <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
- $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
- <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
-
- $column_data{paid} = qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
-
- $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
- $column_data{checked} = qq|<td align=center width=10%><input name="checked_$i" type=checkbox class=checkbox $form->{"checked_$i"}></td>|;
-
- $j++; $j %= 2;
- print qq|
- <tr class=listrow$j>
-|;
- for (@column_index) { print "$column_data{$_}\n" }
- print qq|
- </tr>
-|;
- }
-
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $column_data{amount} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totalamount, 2, "&nbsp;").qq|</th>|;
- $column_data{due} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totaldue, 2, "&nbsp;").qq|</th>|;
- $column_data{paid} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totalpaid, 2, "&nbsp;").qq|</th>|;
-
- print qq|
- <tr class=listtotal>
-|;
- for (@column_index) { print "$column_data{$_}\n" }
- print qq|
- </tr>
- </table>
- </td>
- </tr>
-|;
-
-}
-
-
-sub payment_footer {
-
- $form->{DF}{$form->{format}} = "selected";
-
- $transdate = $form->datetonum(\%myconfig, $form->{datepaid});
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
-
- if (${LedgerSMB::Sysconfig::latex}) {
- 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|">|;
- }
-
- $media = qq|<select name=media>
- <option value=screen>|.$locale->text('Screen');
-
- if (%{LedgerSMB::Sysconfig::printer}) {
- for (sort keys %{LedgerSMB::Sysconfig::printer}) { $media .= qq|
- <option value="$_">$_| }
- }
-
- $media .= qq|</select>|;
- $format = qq|<select name=format>
- <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq|
- <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF').qq|</select>|;
- }
-
- print qq|
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-|;
-
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- 'select_all' => { ndx => 2, key => 'A', value => $locale->text('Select all') },
- 'print' => { ndx => 3, key => 'P', value => $locale->text('Print') },
- 'post' => { ndx => 4, key => 'O', value => $locale->text('Post') },
- );
-
- if (! ${LedgerSMB::Sysconfig::latex}) {
- delete $button{'print'};
- }
-
- if ($transdate <= $closedto) {
- for ('post', 'print') { delete $button{$_} }
- $media = $format = "";
- }
-
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
-
- $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
-
- print qq|
- $lang
- $format
- $media
-|;
-
- $form->hide_form(qw(callback rowcount path login sessionid));
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
- </form>
-
-</body>
-</html>
-|;
-
-}
-
-
-sub post { &{"post_$form->{payment}"} }
-
-
-sub post_payments {
-
- if ($form->{currency} ne $form->{defaultcurrency}) {
- $form->error($locale->text('Exchange rate missing!')) unless $form->{exchangerate};
- }
-
- if (CP->post_payments(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Payments posted!'));
- } else {
- $form->error($locale->text('Posting failed!'));
- }
-
-}
-
-
-sub post_payment {
-
- &check_form;
-
- if ($form->{currency} ne $form->{defaultcurrency}) {
- $form->error($locale->text('Exchange rate missing!')) unless $form->{exchangerate};
- }
-
- $msg1 = "$form->{title} posted!";
- $msg2 = "Cannot post $form->{title}!";
-
-# $locale->text('Payment posted!')
-# $locale->text('Receipt posted!')
-# $locale->text('Cannot post Payment!')
-# $locale->text('Cannot post Receipt!')
-
-
- $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
-
- $source = $form->{source};
- $source =~ s/(\d+)/$1 + 1/e;
-
- if ($form->{callback}) {
- $form->{callback} .= "&source=$source";
- }
-
- if (CP->post_payment(\%myconfig, \%$form)) {
- $form->redirect($locale->text($msg1));
- } else {
- $form->error($locale->text($msg2));
- }
-
-}
-
-
-sub print {
-
- &{ "print_$form->{payment}" };
- &update if $form->{media} ne 'screen';
-
-}
-
-
-sub print_payments {
-
- $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/);
-
- $SIG{INT} = 'IGNORE';
-
- for (qw(company address)) { $form->{$_} = $myconfig{$_} }
- $form->{address} =~ s/\\n/\n/g;
-
- %oldform = ();
- for (keys %$form) { $oldform{$_} = $form->{$_} };
-
- @a = qw(name company address text_amount text_decimal address1 address2 city state zipcode country memo);
- for (@a) { $temp{$_} = $form->{$_} }
-
- $form->format_string(@a);
-
- $ok = 0;
- $j = 0;
- $temp{rowcount} = $form->{rowcount};
-
- for $i (1 .. $temp{rowcount}) {
-
- if ($form->{"$form->{vc}_id_$i"} ne $form->{"$form->{vc}_id"}) {
-
- $form->{rowcount} = $j;
- for (1 .. $j) { $form->{"id_$_"} = $temp{"id_$_"} }
- &print_form if $ok;
-
- $ok = 0;
- $j = 0;
- $form->{amount} = 0;
- for (qw(invnumber invdate due paid)) { @{ $form->{$_} } = () }
- for (qw(language_code source memo)) { $form->{$_} = $form->{"${_}_$i"} }
-
- }
-
- if ($form->{"checked_$i"}) {
- $j++;
- $ok = 1;
- $temp{"id_$j"} = $form->{"id_$i"};
- $form->{"invdate_$i"} = $form->{"transdate_$i"};
- for (qw(invnumber invdate due paid)) { push @{ $form->{$_} }, $form->{"${_}_$i"} }
- $form->{amount} += $form->parse_amount(\%myconfig, $form->{"paid_$i"});
- $form->{"$form->{vc}_id"} = $form->{"$form->{vc}_id_$i"};
- }
-
- }
-
- $form->{rowcount} = $j;
- for (1 .. $j) { $form->{"id_$_"} = $temp{"id_$_"} }
-
- &print_form if $ok;
-
- for (keys %oldform) { $form->{$_} = $oldform{$_} }
-
-}
-
-
-sub print_form {
-
- $c = CP->new(($form->{language_code}) ? $form->{language_code} : $myconfig{countrycode});
- $c->init;
-
- ($whole, $form->{decimal}) = split /\./, $form->{amount};
- $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
- $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);
-
- $datepaid = $form->datetonum(\%myconfig, $form->{datepaid});
- ($form->{yyyy}, $form->{mm}, $form->{dd}) = $datepaid =~ /(....)(..)(..)/;
-
- &{ "$form->{vc}_details" };
-
- $form->{templates} = "$myconfig{templates}";
- $form->{IN} = "$form->{formname}.tex";
-
- if ($form->{media} ne 'screen') {
- $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
- $form->{printmode} = '|-';
- }
-
- if (($form->{'media'} eq 'screen') and ($form->{'format'} eq 'html')) {
- my $template = LedgerSMB::Template->new(\%myconfig, $form->{'formname'}, 'HTML');
- try {
- $template->render($form);
- $form->header;
- print $template->{'output'};
- exit;
- } catch Error::Simple with {
- my $E = shift;
- $form->error($E->stacktrace);
- };
- }
- $form->parse_template(\%myconfig, ${LedgerSMB::Sysconfig::userspath});
-
-}
-
-
-sub print_payment {
-
- &check_form;
-
- for (qw(company address)) { $form->{$_} = $myconfig{$_} }
- $form->{address} =~ s/\\n/\n/g;
-
- @a = qw(rowcount name company address text_amount text_decimal address1 address2 city state zipcode country memo);
-
- %temp = ();
- for (@a) { $temp{$_} = $form->{$_} }
-
- if (scalar @{$form->{invnumber}} > ${LedgerSMB::Sysconfig::check_max_invoices}) {
- $#{$form->{invnumber}} = ${LedgerSMB::Sysconfig::check_max_invoices} - 1;
- $form->{invnumbers_maxed} = 1;
- $form->{message} = $locale->text("Please see attatched report for list of invoices paid.");
- }
-
- $form->format_string(@a);
-
- &print_form;
-
- for (keys %temp) { $form->{$_} = $temp{$_} }
-
-}
-
-
-sub customer_details { IS->customer_details(\%myconfig, \%$form) };
-sub vendor_details { IR->vendor_details(\%myconfig, \%$form) };
-
-
-sub check_form {
-
- &check_openvc;
-
- if ($form->{currency} ne $form->{oldcurrency}) {
- &update;
- exit;
- }
-
- $form->error($locale->text('Date missing!')) unless $form->{datepaid};
-
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
- $datepaid = $form->datetonum(\%myconfig, $form->{datepaid});
-
- $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
-
- # this is just to format the year
- $form->{datepaid} = $locale->date(\%myconfig, $form->{datepaid});
-
- $amount = $form->parse_amount(\%myconfig, $form->{amount});
- $form->{amount} = $amount;
-
- for $i (1 .. $form->{rowcount}) {
- if ($form->{"paid_$i"}) {
- $amount -= $form->parse_amount(\%myconfig, $form->{"paid_$i"});
-
- push(@{ $form->{paid} }, $form->{"paid_$i"});
- push(@{ $form->{due} }, $form->{"due_$i"});
- push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
- push(@{ $form->{invdate} }, $form->{"transdate_$i"});
- }
- }
-
- if ($form->round_amount($amount, 2) != 0) {
- push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
- push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
- push(@{ $form->{invnumber} }, ($form->{ARAP} eq 'AR') ? $locale->text('Deposit') : $locale->text('Prepayment'));
- push(@{ $form->{invdate} }, $form->{datepaid});
- }
-
-}
-
-
-sub check_openvc {
-
- $name = $form->{vc};
- ($new_name, $new_id) = split /--/, $form->{$name};
-
- if ($form->{all_vc}) {
- if ($form->{"select$name"}) {
- $ok = ($form->{"old$name"} ne $form->{$name});
- } else {
- $ok = ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|);
- }
-
- if ($ok) {
- $form->{redo} = 1;
- if ($form->{"select$name"}) {
- $form->{"${name}_id"} = $new_id;
- AA->get_name(\%myconfig, \%$form);
- $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
- } else {
- &check_name($form->{vc});
- }
- }
-
- } else {
-
- # if we use a selection
- if ($form->{"select$name"}) {
- if ($form->{"old$name"} ne $form->{$name}) {
-
- $form->{"${name}_id"} = $new_id;
- AA->get_name(\%myconfig, \%$form);
-
- $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
- $form->{redo} = 1;
- }
- } else {
-
- # check name, combine name and id
- if ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|) {
-
- # return one name or a list of names in $form->{name_list}
- if (($rv = CP->get_openvc(\%myconfig, \%$form)) > 1) {
- $form->{redo} = 1;
- &select_name($name);
- exit;
- }
-
- if ($rv == 1) {
- # we got one name
- $form->{"${name}_id"} = $form->{name_list}[0]->{id};
- $form->{$name} = $form->{name_list}[0]->{name};
- $form->{"old$name"} = qq|$form->{$name}--$form->{"${name}_id"}|;
-
- AA->get_name(\%myconfig, \%$form);
-
- } else {
- # nothing open
- $form->error($locale->text('Nothing open!'));
- }
-
- $form->{redo} = 1;
- }
- }
- }
-
-}
-
-
+#=====================================================================
+# 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
+#
+# Contributors:
+#
+#
+# Author: DWS Systems Inc.
+# Web: http://www.ledgersmb.org/
+#
+# Contributors:
+#
+# 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.
+#======================================================================
+#
+# Payment module
+#
+#======================================================================
+
+use Error qw(:try);
+
+use LedgerSMB::Template;
+use LedgerSMB::CP;
+use LedgerSMB::OP;
+use LedgerSMB::IS;
+use LedgerSMB::IR;
+
+require "bin/arap.pl";
+
+1;
+
+# end of main
+
+sub payment {
+
+ if ( $form->{type} eq 'receipt' ) {
+ $form->{ARAP} = "AR";
+ $form->{arap} = "ar";
+ $form->{vc} = "customer";
+ $form->{formname} = "receipt";
+ }
+ if ( $form->{type} eq 'check' ) {
+ $form->{ARAP} = "AP";
+ $form->{arap} = "ap";
+ $form->{vc} = "vendor";
+ $form->{formname} = "check";
+ }
+
+ $form->{payment} = "payment";
+
+ $form->{callback} =
+"$form->{script}?action=payment&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&all_vc=$form->{all_vc}&type=$form->{type}";
+
+ # setup customer/vendor selection for open invoices
+ if ( $form->{all_vc} ) {
+ $form->all_vc( \%myconfig, $form->{vc}, $form->{ARAP}, undef,
+ $form->{datepaid} );
+ }
+ else {
+ CP->get_openvc( \%myconfig, \%$form );
+ if ( $myconfig{vclimit} > 0 ) {
+ $form->{"all_$form->{vc}"} = $form->{name_list};
+ }
+ }
+
+ $form->{"select$form->{vc}"} = "";
+ if ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
+ for ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{"select$form->{vc}"} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
+
+ # departments
+ if ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} = "<option>\n";
+ $form->{department} = "$form->{department}--$form->{department_id}"
+ if $form->{department};
+
+ for ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+ }
+
+ if ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} = "<option>\n";
+ for ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} .=
+ qq|<option value="$_->{code}">$_->{description}\n|;
+ }
+ }
+
+ CP->paymentaccounts( \%myconfig, \%$form );
+
+ $form->{selectaccount} = "";
+ $form->{"select$form->{ARAP}"} = "";
+
+ for ( @{ $form->{PR}{"$form->{ARAP}_paid"} } ) {
+ $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n";
+ }
+ for ( @{ $form->{PR}{ $form->{ARAP} } } ) {
+ $form->{"select$form->{ARAP}"} .=
+ "<option>$_->{accno}--$_->{description}\n";
+ }
+
+ # currencies
+ @curr = split /:/, $form->{currencies};
+ $form->{defaultcurrency} = $curr[0];
+ chomp $form->{defaultcurrency};
+
+ $form->{selectcurrency} = "";
+ for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
+
+ $form->{currency} = $form->{defaultcurrency};
+ $form->{oldcurrency} = $form->{currency};
+
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ $form->{forex} = $form->{exchangerate} =
+ $form->check_exchangerate( \%myconfig, $form->{currency},
+ $form->{datepaid}, ( $form->{vc} eq 'customer' ) ? "buy" : "sell" );
+ }
+
+ $form->{olddatepaid} = $form->{datepaid};
+
+ $form->{media} = $myconfig{printer};
+ $form->{format} = "pdf" unless $myconfig{printer};
+
+ &payment_header;
+ &payment_footer;
+
+}
+
+sub payments {
+
+ if ( $form->{type} eq 'receipt' ) {
+ $form->{ARAP} = "AR";
+ $form->{arap} = "ar";
+ $form->{vc} = "customer";
+ $form->{formname} = "receipt";
+ }
+ if ( $form->{type} eq 'check' ) {
+ $form->{ARAP} = "AP";
+ $form->{arap} = "ap";
+ $form->{vc} = "vendor";
+ $form->{formname} = "check";
+ }
+
+ $form->{payment} = "payments";
+
+ $form->{callback} = "$form->{script}?action=$form->{action}";
+ for (qw(path login sessionid type)) {
+ $form->{callback} .= "&$_=$form->{$_}";
+ }
+
+ CP->paymentaccounts( \%myconfig, \%$form );
+
+ if ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} = "<option>\n";
+ for ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} .=
+ qq|<option value="$_->{code}">$_->{description}\n|;
+ }
+ }
+
+ # departments
+ if ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} = "<option>\n";
+ $form->{department} = "$form->{department}--$form->{department_id}"
+ if $form->{department};
+
+ for ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+ }
+
+ $form->{selectaccount} = "";
+ $form->{"select$form->{ARAP}"} = "";
+
+ for ( @{ $form->{PR}{"$form->{ARAP}_paid"} } ) {
+ $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n";
+ }
+ for ( @{ $form->{PR}{ $form->{ARAP} } } ) {
+ $form->{"select$form->{ARAP}"} .=
+ "<option>$_->{accno}--$_->{description}\n";
+ }
+
+ # currencies
+ @curr = split /:/, $form->{currencies};
+ $form->{defaultcurrency} = $curr[0];
+ chomp $form->{defaultcurrency};
+
+ $form->{selectcurrency} = "";
+ for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
+
+ $form->{oldcurrency} = $form->{currency} = $form->{defaultcurrency};
+ $form->{oldduedateto} = $form->{datepaid};
+
+ $form->{media} = $myconfig{printer};
+ $form->{format} = "pdf" unless $myconfig{printer};
+
+ &payments_header;
+ &invoices_due;
+ &payments_footer;
+
+}
+
+sub payments_header {
+
+ if ( $form->{type} eq 'receipt' ) {
+ $form->{title} = $locale->text('Receipts');
+ }
+ if ( $form->{type} eq 'check' ) {
+ $form->{title} = $locale->text('Payments');
+ }
+
+ for ("department") {
+ $form->{"select$_"} = $form->unescape( $form->{"select$_"} );
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
+ }
+
+ for ( "account", "currency", "$form->{ARAP}" ) {
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~
+ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
+ }
+
+ if ( $form->{defaultcurrency} ) {
+ $exchangerate = qq|
+ <tr>
+ <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
+ <td><select name=currency>$form->{selectcurrency}</select></td>
+ <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
+ <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
+ </tr>
+|;
+ }
+
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ $form->{exchangerate} =
+ $form->format_amount( \%myconfig, $form->{exchangerate} );
+
+ if ( $form->{forex} ) {
+ $exchangerate .= qq|
+ <tr>
+ <th align=right nowrap>| . $locale->text('Exchange Rate') . qq|</th>
+ <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
+ </tr>
+|;
+ }
+ else {
+ $exchangerate .= qq|
+ <tr>
+ <th align=right nowrap>| . $locale->text('Exchange Rate') . qq|</th>
+ <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
+ </tr>
+|;
+ }
+ }
+
+ $department = qq|
+ <tr>
+ <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
+ <td><select name=department>$form->{selectdepartment}</select>
+ <input type=hidden name=selectdepartment value="|
+ . $form->escape( $form->{selectdepartment}, 1 ) . qq|">
+ </td>
+ </tr>
+| if $form->{selectdepartment};
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+|;
+
+ $form->hide_form(
+ qw(defaultcurrency closedto vc type formname arap ARAP title oldduedatefrom oldduedateto payment olddepartment)
+ );
+
+ print qq|
+<table width=100%>
+ <tr>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr valign=top>
+ <td>
+ <table>
+ <tr>
+ <th align=right>|
+ . $locale->text('Due Date')
+ . qq|&nbsp;|
+ . $locale->text('From')
+ . qq|</th>
+ <td><input name=duedatefrom value="$form->{duedatefrom}" title="$myconfig{dateformat}" size=11></td>
+ <th align=right>| . $locale->text('To') . qq|</th>
+ <td><input name=duedateto value="$form->{duedateto}" title="$myconfig{dateformat}" size=11></td>
+ </tr>
+ </table>
+ </td>
+ </td>
+ <td align=right>
+ <table>
+ $department
+ <tr>
+ <th align=right nowrap>| . $locale->text( $form->{ARAP} ) . qq|</th>
+ <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select>
+ </td>
+ <input type=hidden name="select$form->{ARAP}" value="$form->{"select$form->{ARAP}"}">
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Account') . qq|</th>
+ <td colspan=3><select name=account>$form->{selectaccount}</select>
+ <input type=hidden name=selectaccount value="$form->{selectaccount}">
+ </td>
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Date') . qq|</th>
+ <td><input name=datepaid value="$form->{datepaid}" title="$myconfig{dateformat}" size=11></td>
+ </tr>
+ $exchangerate
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+|;
+
+}
+
+sub invoices_due {
+
+ @column_index =
+ qw(name invnumber transdate amount due checked paid memo source);
+ push @column_index, "language" if $form->{selectlanguage};
+
+ $colspan = $#column_index + 1;
+
+ $invoice = $locale->text('Invoices');
+ $vclabel = ucfirst $form->{vc};
+ $vclabel = $locale->text($vclabel);
+
+ print qq|
+ <input type=hidden name=column_index value="id @column_index">
+ <tr>
+ <td>
+ <table width=100%>
+ <tr>
+ <th class=listheading colspan=$colspan>$invoice</th>
+ </tr>
+|;
+
+ $column_data{name} = qq|<th nowrap>$vclabel</th>|;
+ $column_data{invnumber} =
+ qq|<th nowrap>| . $locale->text('Invoice') . "</th>";
+ $column_data{transdate} = qq|<th nowrap>| . $locale->text('Date') . "</th>";
+ $column_data{amount} = qq|<th nowrap>| . $locale->text('Amount') . "</th>";
+ $column_data{due} = qq|<th nowrap>| . $locale->text('Amount Due') . "</th>";
+ $column_data{paid} = qq|<th nowrap>| . $locale->text('Amount') . "</th>";
+ $column_data{checked} = qq|<th nowrap>| . $locale->text('Select') . "</th>";
+ $column_data{memo} = qq|<th nowrap>| . $locale->text('Memo') . "</th>";
+ $column_data{source} = qq|<th nowrap>| . $locale->text('Source') . "</th>";
+ $column_data{language} =
+ qq|<th nowrap>| . $locale->text('Language') . "</th>";
+
+ print qq|
+ <tr>
+|;
+ for (@column_index) { print "$column_data{$_}\n" }
+ print qq|
+ </tr>
+|;
+
+ $form->{selectlanguage} = $form->unescape( $form->{selectlanguage} );
+
+ for $i ( 1 .. $form->{rowcount} ) {
+
+ for (qw(amount due paid)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ $totalamount += $form->{"amount_$i"};
+ $totaldue += $form->{"due_$i"};
+ if ( $form->{"paid_$i"} !~ /NaN/ ) {
+ $totalpaid += $form->{"paid_$i"};
+ }
+ else {
+ $form->{"paid_$i"} = '';
+ }
+ for (qw(amount due paid)) {
+ $form->{"${_}_$i"} =
+ $form->format_amount( \%myconfig, $form->{"${_}_$i"}, 2 );
+ }
+
+ $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
+ <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
+ <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
+ $column_data{transdate} = qq|<td>$form->{"transdate_$i"}</td>
+ <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
+ $column_data{amount} = qq|<td align=right>$form->{"amount_$i"}</td>
+ <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
+ $column_data{due} = qq|<td align=right>$form->{"due_$i"}</td>
+ <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
+
+ $column_data{paid} =
+qq|<td align=right><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
+
+ if ( $same_id eq $form->{"$form->{vc}_id_$i"} ) {
+ for (qw(name memo source language)) {
+ $column_data{$_} = qq|<td>&nbsp;</td>|;
+ }
+ }
+ else {
+ $column_data{name} = qq|<td>$form->{"name_$i"}</td>|;
+ $column_data{memo} =
+qq|<td align=right><input name="memo_$i" size=10 value="$form->{"memo_$i"}"></td>|;
+ $column_data{source} =
+qq|<td align=right><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|;
+
+ if ( $form->{selectlanguage} ) {
+ $selectlanguage = $form->{selectlanguage};
+ $selectlanguage =~
+s/(<option value="\Q$form->{"language_code_$i"}\E")/$1 selected/;
+ $column_data{language} =
+qq|<td><select name="language_code_$i">$selectlanguage</select></td>|;
+ }
+
+ }
+
+ $column_data{name} .= qq|
+ <input type=hidden name="name_$i" value="$form->{"name_$i"}">
+ <input type=hidden name="$form->{vc}_id_$i" value="$form->{"$form->{vc}_id_$i"}">|;
+
+ $form->{"checked_$i"} = ( $form->{"checked_$i"} ) ? "checked" : "";
+ $column_data{checked} =
+qq|<td align=center><input name="checked_$i" type=checkbox class=checkbox $form->{"checked_$i"}></td>|;
+
+ $j++;
+ $j %= 2;
+ print qq|
+ <tr class=listrow$j>
+|;
+ for (@column_index) { print "$column_data{$_}\n" }
+ print qq|
+ </tr>
+|;
+
+ $same_id = $form->{"$form->{vc}_id_$i"};
+
+ }
+
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{amount} =
+ qq|<th class=listtotal align=right>|
+ . $form->format_amount( \%myconfig, $totalamount, 2, "&nbsp;" )
+ . qq|</th>|;
+ $column_data{due} =
+ qq|<th class=listtotal align=right>|
+ . $form->format_amount( \%myconfig, $totaldue, 2, "&nbsp;" )
+ . qq|</th>|;
+ $column_data{paid} =
+ qq|<th class=listtotal align=right>|
+ . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" )
+ . qq|</th>|;
+
+ print qq|
+ <tr class=listtotal>
+|;
+ for (@column_index) { print "$column_data{$_}\n" }
+ print qq|
+ </tr>
+ </table>
+ </td>
+ </tr>
+<input type=hidden name=selectlanguage value="|
+ . $form->escape( $form->{selectlanguage}, 1 ) . qq|">
+|;
+
+}
+
+sub payments_footer {
+
+ $form->{DF}{ $form->{format} } = "selected";
+
+ $transdate = $form->datetonum( \%myconfig, $form->{datepaid} );
+ $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
+
+ if ( ${LedgerSMB::Sysconfig::latex} ) {
+
+ $media = qq|<select name=media>
+ <option value=screen>| . $locale->text('Screen');
+
+ if ( %{LedgerSMB::Sysconfig::printer} ) {
+ for ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
+ $media .= qq|
+ <option value="$_">$_|;
+ }
+ }
+
+ $media .= qq|</select>|;
+ $format = qq|<select name=format>
+ <option value=postscript $form->{DF}{postscript}>|
+ . $locale->text('Postscript') . qq|
+ <option value=pdf $form->{DF}{pdf}>|
+ . $locale->text('PDF')
+ . qq|</select>|;
+ }
+
+ print qq|
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+|;
+
+ # type=submit $locale->text('Update')
+ # type=submit $locale->text('Post')
+ # type=submit $locale->text('Print')
+ # type=submit $locale->text('Select all')
+
+ %button = (
+ 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
+ 'select_all' =>
+ { ndx => 2, key => 'A', value => $locale->text('Select all') },
+ 'print' => { ndx => 3, key => 'P', value => $locale->text('Print') },
+ 'post' => { ndx => 4, key => 'O', value => $locale->text('Post') },
+ );
+
+ if ( !${LedgerSMB::Sysconfig::latex} ) {
+ delete $button{'print'};
+ }
+
+ if ( $transdate <= $closedto ) {
+ for ( 'post', 'print' ) { delete $button{$_} }
+ $media = $format = "";
+ }
+
+ for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
+ $form->print_button( \%button, $_ );
+ }
+
+ $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
+
+ print qq|
+ $format
+ $media
+|;
+
+ $form->hide_form(qw(callback rowcount path login sessionid));
+
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
+ </form>
+
+</body>
+</html>
+|;
+
+}
+
+sub select_all {
+
+ for ( 1 .. $form->{rowcount} ) { $form->{"checked_$_"} = 1 }
+ &{"update_$form->{payment}"}
+
+}
+
+sub update {
+ my ($new_name_selected) = @_;
+
+ &{"update_$form->{payment}"};
+
+}
+
+sub update_payments {
+
+ if ( $form->{ARAP} eq 'AR' ) {
+ $buysell = "buy";
+ }
+ else {
+ $buysell = "sell";
+ }
+
+ if ( ( $form->{oldduedatefrom} ne $form->{duedatefrom} )
+ || ( $form->{oldduedateto} ne $form->{duedateto} )
+ || ( $form->{department} ne $form->{olddepartment} ) )
+ {
+ CP->get_openinvoices( \%myconfig, \%$form );
+ $form->{redo} = 1;
+ }
+
+ if ( $form->{currency} ne $form->{oldcurrency} ) {
+ $form->{oldcurrency} = $form->{currency};
+ if ( !$form->{redo} ) {
+ CP->get_openinvoices( \%myconfig, \%$form );
+ $form->{redo} = 1;
+ }
+ }
+
+ for (qw(duedatefrom duedateto department)) {
+ $form->{"old$_"} = $form->{$_};
+ }
+
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate = $form->check_exchangerate(
+ \%myconfig, $form->{currency}, $form->{datepaid}, $buysell
+ )
+ )
+ );
+
+ if ( $form->{redo} ) {
+ $form->{rowcount} = 0;
+
+ $i = 0;
+ foreach $ref ( @{ $form->{PR} } ) {
+ $i++;
+ for (qw(id name invnumber transdate)) {
+ $form->{"${_}_$i"} = $ref->{$_};
+ }
+ $form->{"$form->{vc}_id_$i"} = $ref->{"$form->{vc}_id"};
+ $ref->{exchangerate} = 1 unless $ref->{exchangerate};
+ $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
+ $form->{"due_$i"} =
+ ( $ref->{amount} - $ref->{paid} ) / $ref->{exchangerate};
+ $form->{"checked_$i"} = "";
+ $form->{"paid_$i"} = "";
+
+ # need to format
+ for (qw(amount due)) {
+ $form->{"${_}_$i"} =
+ $form->format_amount( \%myconfig, $form->{"${_}_$i"}, 2 );
+ }
+ }
+
+ $form->{rowcount} = $i;
+ }
+
+ $form->{amount} = $form->parse_amount( \%myconfig, $form->{amount} );
+
+ # recalculate
+ $amount = 0;
+ for $i ( 1 .. $form->{rowcount} ) {
+
+ for (qw(amount due paid)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ if ( $form->{"checked_$i"} ) {
+
+ # calculate paid_$i
+ if ( !$form->{"paid_$i"} ) {
+ $form->{"paid_$i"} = $form->{"due_$i"};
+ }
+
+ $amount += $form->{"paid_$i"};
+ $form->{redo} = 1;
+ }
+ else {
+ $form->{"paid_$i"} = "";
+ }
+
+ for (qw(amount due paid)) {
+ $form->{"${_}_$i"} =
+ $form->format_amount( \%myconfig, $form->{"${_}_$i"}, 2 );
+ }
+ }
+
+ $form->{amount} += ( $amount - $form->{oldamount} ) if $form->{redo};
+
+ &payments_header;
+ &invoices_due;
+ &payments_footer;
+
+}
+
+sub update_payment {
+
+ if ( $form->{vc} eq 'customer' ) {
+ $buysell = "buy";
+ }
+ else {
+ $buysell = "sell";
+ }
+
+ $department = $form->{department};
+
+ # get customer/vendor
+ &check_openvc;
+ $form->{department} = $department;
+
+ if ( $form->{datepaid} ne $form->{olddatepaid} ) {
+ $form->{olddatepaid} = $form->{datepaid};
+ $form->{oldall_vc} = !$form->{oldall_vc} if $form->{all_vc};
+ }
+
+ if ( $form->{department} ne $form->{olddepartment} ) {
+ $form->{olddepartment} = $form->{department};
+ $form->{redo} = 1;
+ }
+
+ # if we switched to all_vc
+ if ( $form->{all_vc} ne $form->{oldall_vc} ) {
+
+ if ( $form->{"select$form->{vc}"} ) {
+ $form->{redo} = ( $form->{"old$name"} ne $form->{$name} );
+ }
+ else {
+ $form->{redo} =
+ ( $form->{"old$name"} ne
+ qq|$form->{$name}--$form->{"${name}_id"}| );
+ }
+
+ $form->{"select$form->{vc}"} = "";
+
+ if ( $form->{all_vc} ) {
+ $form->all_vc( \%myconfig, $form->{vc}, $form->{ARAP}, undef,
+ $form->{datepaid} );
+
+ if ( @{ $form->{"all_$form->{vc}"} } ) {
+ for ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{"select$form->{vc}"} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
+
+ }
+ else {
+ if ( ( $myconfig{vclimit} * 1 ) > 0 ) {
+ $form->{ $form->{vc} } = "";
+ }
+
+ CP->get_openvc( \%myconfig, \%$form );
+
+ if ( ( $myconfig{vclimit} * 1 ) > 0 ) {
+ $form->{"all_$form->{vc}"} = $form->{name_list};
+ }
+
+ if ( @{ $form->{"all_$form->{vc}"} } ) {
+ $newvc =
+qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
+ for ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{"select$form->{vc}"} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+
+ # if the name is not the same
+ if ( $form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/ ) {
+ $form->{ $form->{vc} } = $newvc;
+ &check_openvc;
+ }
+ }
+ }
+
+ if ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} = "<option>\n";
+ for ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} .=
+ qq|<option value="$_->{code}">$_->{description}\n|;
+ }
+ }
+
+ }
+
+ if ( $new_name_selected || $form->{redo} ) {
+ CP->get_openinvoices( \%myconfig, \%$form );
+ ($newvc) = split /--/, $form->{ $form->{vc} };
+ $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
+ $form->{redo} = 1;
+ }
+
+ if ( $form->{currency} ne $form->{oldcurrency} ) {
+ $form->{oldcurrency} = $form->{currency};
+ if ( !$form->{redo} ) {
+ CP->get_openinvoices( \%myconfig, \%$form );
+ $form->{redo} = 1;
+ }
+ }
+
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate = $form->check_exchangerate(
+ \%myconfig, $form->{currency}, $form->{datepaid}, $buysell
+ )
+ )
+ );
+
+ if ( $form->{redo} ) {
+ $form->{rowcount} = 0;
+
+ $i = 0;
+ foreach $ref ( @{ $form->{PR} } ) {
+ $i++;
+ $form->{"id_$i"} = $ref->{id};
+ $form->{"invnumber_$i"} = $ref->{invnumber};
+ $form->{"transdate_$i"} = $ref->{transdate};
+ $ref->{exchangerate} = 1 unless $ref->{exchangerate};
+ $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
+ $form->{"due_$i"} =
+ ( $ref->{amount} - $ref->{paid} ) / $ref->{exchangerate};
+ $form->{"checked_$i"} = "";
+ $form->{"paid_$i"} = "";
+
+ # need to format
+ for (qw(amount due)) {
+ $form->{"${_}_$i"} =
+ $form->format_amount( \%myconfig, $form->{"${_}_$i"}, 2 );
+ }
+ }
+ $form->{rowcount} = $i;
+ }
+
+ $form->{amount} = $form->parse_amount( \%myconfig, $form->{amount} );
+
+ # recalculate
+ $amount = 0;
+ for $i ( 1 .. $form->{rowcount} ) {
+
+ for (qw(amount due paid)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ if ( $form->{"checked_$i"} ) {
+
+ # calculate paid_$i
+ if ( !$form->{"paid_$i"} ) {
+ $form->{"paid_$i"} = $form->{"due_$i"};
+ }
+
+ $amount += $form->{"paid_$i"};
+ $form->{redo} = 1;
+ }
+ else {
+ $form->{"paid_$i"} = "";
+ }
+
+ for (qw(amount due paid)) {
+ $form->{"${_}_$i"} =
+ $form->format_amount( \%myconfig, $form->{"${_}_$i"}, 2 );
+ }
+ }
+
+ $form->{amount} += ( $amount - $form->{oldamount} ) if $form->{redo};
+
+ &payment_header;
+ &list_invoices;
+ &payment_footer;
+
+}
+
+sub payment_header {
+
+ $vclabel = ucfirst $form->{vc};
+ $vclabel = $locale->text($vclabel);
+
+ if ( $form->{type} eq 'receipt' ) {
+ $form->{title} = $locale->text('Receipt');
+ }
+ if ( $form->{type} eq 'check' ) {
+ $form->{title} = $locale->text('Payment');
+ }
+
+ # $locale->text('Customer')
+ # $locale->text('Vendor')
+
+ if ( $form->{ $form->{vc} } eq "" ) {
+ for (qw(address1 address2 city zipcode state country)) {
+ $form->{$_} = "";
+ }
+ }
+
+ for ( "$form->{vc}", "department" ) {
+ $form->{"select$_"} = $form->unescape( $form->{"select$_"} );
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
+ }
+
+ for ( "account", "currency", "$form->{ARAP}" ) {
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~
+ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
+ }
+
+ if ( $form->{defaultcurrency} ) {
+ $exchangerate = qq|
+ <tr>
+ <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
+ <td><select name=currency>$form->{selectcurrency}</select></td>
+ <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
+ <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
+ </tr>
+|;
+ }
+
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ $form->{exchangerate} =
+ $form->format_amount( \%myconfig, $form->{exchangerate} );
+
+ if ( $form->{forex} ) {
+ $exchangerate .= qq|
+ <tr>
+ <th align=right nowrap>| . $locale->text('Exchange Rate') . qq|</th>
+ <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
+ </tr>
+|;
+ }
+ else {
+ $exchangerate .= qq|
+ <tr>
+ <th align=right nowrap>| . $locale->text('Exchange Rate') . qq|</th>
+ <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
+ </tr>
+|;
+ }
+ }
+
+ $vc =
+ ( $form->{"select$form->{vc}"} )
+ ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
+ : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
+
+ if ( $form->{all_vc} ) {
+ $allvc = "checked";
+ }
+ else {
+ $allvc = "";
+ }
+
+ # $locale->text('AR')
+ # $locale->text('AP')
+
+ $department = qq|
+ <tr>
+ <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
+ <td><select name=department>$form->{selectdepartment}</select>
+ <input type=hidden name=selectdepartment value="|
+ . $form->escape( $form->{selectdepartment}, 1 ) . qq|">
+ </td>
+ </tr>
+| if $form->{selectdepartment};
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action=$form->{script}>
+|;
+
+ $form->hide_form(
+ qw(defaultcurrency closedto vc type ARAP arap title formname payment olddepartment)
+ );
+
+ print qq|
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>
+ <table width=100%>
+ <tr valign=top>
+ <td>
+ <table>
+ <tr>
+ <td align=right>
+ <input name=all_vc type=checkbox class=checkbox value=Y $allvc>
+ <input type=hidden name="oldall_vc" value="$form->{all_vc}"></td>
+ <th align=left>| . $locale->text('All') . qq|</th>
+ </tr>
+ <tr>
+ <th align=right>$vclabel</th>
+ <td>$vc</td>
+ <input type=hidden name="select$form->{vc}" value="|
+ . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|">
+ <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
+ <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
+ </tr>
+ <tr valign=top>
+ <th align=right nowrap>| . $locale->text('Address') . qq|</th>
+ <td colspan=2>
+ <table>
+ <tr>
+ <td>$form->{address1}</td>
+ </tr>
+ <tr>
+ <td>$form->{address2}</td>
+ </tr>
+ <td>$form->{city}</td>
+ </tr>
+ </tr>
+ <td>$form->{state}</td>
+ </tr>
+ </tr>
+ <td>$form->{zipcode}</td>
+ </tr>
+ <tr>
+ <td>$form->{country}</td>
+ </tr>
+ </table>
+ </td>
+ <input type=hidden name=address1 value="$form->{address1}">
+ <input type=hidden name=address2 value="$form->{address2}">
+ <input type=hidden name=city value="$form->{city}">
+ <input type=hidden name=state value="$form->{state}">
+ <input type=hidden name=zipcode value="$form->{zipcode}">
+ <input type=hidden name=country value="$form->{country}">
+ </tr>
+ <tr>
+ <th align=right>| . $locale->text('Memo') . qq|</th>
+ <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
+ </tr>
+ </table>
+ </td>
+ <td align=right>
+ <table>
+ $department
+ <tr>
+ <th align=right nowrap>| . $locale->text( $form->{ARAP} ) . qq|</th>
+ <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select>
+ </td>
+ <input type=hidden name="select$form->{ARAP}" value="$form->{"select$form->{ARAP}"}">
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Account') . qq|</th>
+ <td colspan=3><select name=account>$form->{selectaccount}</select>
+ <input type=hidden name=selectaccount value="$form->{selectaccount}">
+ </td>
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Date') . qq|</th>
+ <td><input name=datepaid value="$form->{datepaid}" title="$myconfig{dateformat}" size=11></td>
+ <input type=hidden name=olddatepaid value=$form->{olddatepaid}>
+ </tr>
+ $exchangerate
+ <tr>
+ <th align=right nowrap>| . $locale->text('Source') . qq|</th>
+ <td colspan=3><input name=source value="$form->{source}" size=10></td>
+ </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Amount') . qq|</th>
+ <td colspan=3><input name=amount size=10 value=|
+ . $form->format_amount( \%myconfig, $form->{amount}, 2 )
+ . qq|></td>
+ <input type=hidden name=oldamount value=$form->{amount}>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+|;
+
+}
+
+sub list_invoices {
+
+ @column_index = qw(invnumber transdate amount due checked paid);
+
+ $colspan = $#column_index + 1;
+
+ $invoice = $locale->text('Invoices');
+
+ print qq|
+ <input type=hidden name=column_index value="id @column_index">
+ <tr>
+ <td>
+ <table width=100%>
+ <tr>
+ <th class=listheading colspan=$colspan>$invoice</th>
+ </tr>
+|;
+
+ $column_data{invnumber} =
+ qq|<th nowrap>| . $locale->text('Invoice') . "</th>";
+ $column_data{transdate} = qq|<th nowrap>| . $locale->text('Date') . "</th>";
+ $column_data{amount} = qq|<th nowrap>| . $locale->text('Amount') . "</th>";
+ $column_data{due} = qq|<th nowrap>| . $locale->text('Amount Due') . "</th>";
+ $column_data{paid} = qq|<th nowrap>| . $locale->text('Amount') . "</th>";
+ $column_data{checked} = qq|<th nowrap>| . $locale->text('Select') . "</th>";
+
+ print qq|
+ <tr>
+|;
+ for (@column_index) { print "$column_data{$_}\n" }
+ print qq|
+ </tr>
+|;
+
+ for $i ( 1 .. $form->{rowcount} ) {
+
+ for (qw(amount due paid)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ $totalamount += $form->{"amount_$i"};
+ $totaldue += $form->{"due_$i"};
+ if ( $form->{"paid_$i"} =~ /NaN/ ) {
+ $form->{"paid_$i"} = '';
+ }
+ else {
+ $totalpaid += $form->{"paid_$i"};
+ }
+
+ for (qw(amount due paid)) {
+ $form->{"${_}_$i"} =
+ $form->format_amount( \%myconfig, $form->{"${_}_$i"}, 2 );
+ }
+
+ $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
+ <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
+ <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
+ $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
+ <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
+ $column_data{amount} =
+ qq|<td align=right width=15%>$form->{"amount_$i"}</td>
+ <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
+ $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
+ <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
+
+ $column_data{paid} =
+qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
+
+ $form->{"checked_$i"} = ( $form->{"checked_$i"} ) ? "checked" : "";
+ $column_data{checked} =
+qq|<td align=center width=10%><input name="checked_$i" type=checkbox class=checkbox $form->{"checked_$i"}></td>|;
+
+ $j++;
+ $j %= 2;
+ print qq|
+ <tr class=listrow$j>
+|;
+ for (@column_index) { print "$column_data{$_}\n" }
+ print qq|
+ </tr>
+|;
+ }
+
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{amount} =
+ qq|<th class=listtotal align=right>|
+ . $form->format_amount( \%myconfig, $totalamount, 2, "&nbsp;" )
+ . qq|</th>|;
+ $column_data{due} =
+ qq|<th class=listtotal align=right>|
+ . $form->format_amount( \%myconfig, $totaldue, 2, "&nbsp;" )
+ . qq|</th>|;
+ $column_data{paid} =
+ qq|<th class=listtotal align=right>|
+ . $form->format_amount( \%myconfig, $totalpaid, 2, "&nbsp;" )
+ . qq|</th>|;
+
+ print qq|
+ <tr class=listtotal>
+|;
+ for (@column_index) { print "$column_data{$_}\n" }
+ print qq|
+ </tr>
+ </table>
+ </td>
+ </tr>
+|;
+
+}
+
+sub payment_footer {
+
+ $form->{DF}{ $form->{format} } = "selected";
+
+ $transdate = $form->datetonum( \%myconfig, $form->{datepaid} );
+ $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
+
+ if ( ${LedgerSMB::Sysconfig::latex} ) {
+ 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|">|;
+ }
+
+ $media = qq|<select name=media>
+ <option value=screen>| . $locale->text('Screen');
+
+ if ( %{LedgerSMB::Sysconfig::printer} ) {
+ for ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
+ $media .= qq|
+ <option value="$_">$_|;
+ }
+ }
+
+ $media .= qq|</select>|;
+ $format = qq|<select name=format>
+ <option value=postscript $form->{DF}{postscript}>|
+ . $locale->text('Postscript') . qq|
+ <option value=pdf $form->{DF}{pdf}>|
+ . $locale->text('PDF')
+ . qq|</select>|;
+ }
+
+ print qq|
+ <tr>
+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+|;
+
+ %button = (
+ 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
+ 'select_all' =>
+ { ndx => 2, key => 'A', value => $locale->text('Select all') },
+ 'print' => { ndx => 3, key => 'P', value => $locale->text('Print') },
+ 'post' => { ndx => 4, key => 'O', value => $locale->text('Post') },
+ );
+
+ if ( !${LedgerSMB::Sysconfig::latex} ) {
+ delete $button{'print'};
+ }
+
+ if ( $transdate <= $closedto ) {
+ for ( 'post', 'print' ) { delete $button{$_} }
+ $media = $format = "";
+ }
+
+ for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
+ $form->print_button( \%button, $_ );
+ }
+
+ $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
+
+ print qq|
+ $lang
+ $format
+ $media
+|;
+
+ $form->hide_form(qw(callback rowcount path login sessionid));
+
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
+ </form>
+
+</body>
+</html>
+|;
+
+}
+
+sub post { &{"post_$form->{payment}"} }
+
+sub post_payments {
+
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ $form->error( $locale->text('Exchange rate missing!') )
+ unless $form->{exchangerate};
+ }
+
+ if ( CP->post_payments( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Payments posted!') );
+ }
+ else {
+ $form->error( $locale->text('Posting failed!') );
+ }
+
+}
+
+sub post_payment {
+
+ &check_form;
+
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ $form->error( $locale->text('Exchange rate missing!') )
+ unless $form->{exchangerate};
+ }
+
+ $msg1 = "$form->{title} posted!";
+ $msg2 = "Cannot post $form->{title}!";
+
+ # $locale->text('Payment posted!')
+ # $locale->text('Receipt posted!')
+ # $locale->text('Cannot post Payment!')
+ # $locale->text('Cannot post Receipt!')
+
+ $form->{amount} = $form->format_amount( \%myconfig, $form->{amount}, 2 );
+
+ $source = $form->{source};
+ $source =~ s/(\d+)/$1 + 1/e;
+
+ if ( $form->{callback} ) {
+ $form->{callback} .= "&source=$source";
+ }
+
+ if ( CP->post_payment( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text($msg1) );
+ }
+ else {
+ $form->error( $locale->text($msg2) );
+ }
+
+}
+
+sub print {
+
+ &{"print_$form->{payment}"};
+ &update if $form->{media} ne 'screen';
+
+}
+
+sub print_payments {
+
+ $form->error( $locale->text('Select postscript or PDF!') )
+ if ( $form->{format} !~ /(postscript|pdf)/ );
+
+ $SIG{INT} = 'IGNORE';
+
+ for (qw(company address)) { $form->{$_} = $myconfig{$_} }
+ $form->{address} =~ s/\\n/\n/g;
+
+ %oldform = ();
+ for ( keys %$form ) { $oldform{$_} = $form->{$_} }
+
+ @a =
+ qw(name company address text_amount text_decimal address1 address2 city state zipcode country memo);
+ for (@a) { $temp{$_} = $form->{$_} }
+
+ $form->format_string(@a);
+
+ $ok = 0;
+ $j = 0;
+ $temp{rowcount} = $form->{rowcount};
+
+ for $i ( 1 .. $temp{rowcount} ) {
+
+ if ( $form->{"$form->{vc}_id_$i"} ne $form->{"$form->{vc}_id"} ) {
+
+ $form->{rowcount} = $j;
+ for ( 1 .. $j ) { $form->{"id_$_"} = $temp{"id_$_"} }
+ &print_form if $ok;
+
+ $ok = 0;
+ $j = 0;
+ $form->{amount} = 0;
+ for (qw(invnumber invdate due paid)) { @{ $form->{$_} } = () }
+ for (qw(language_code source memo)) {
+ $form->{$_} = $form->{"${_}_$i"};
+ }
+
+ }
+
+ if ( $form->{"checked_$i"} ) {
+ $j++;
+ $ok = 1;
+ $temp{"id_$j"} = $form->{"id_$i"};
+ $form->{"invdate_$i"} = $form->{"transdate_$i"};
+ for (qw(invnumber invdate due paid)) {
+ push @{ $form->{$_} }, $form->{"${_}_$i"};
+ }
+ $form->{amount} +=
+ $form->parse_amount( \%myconfig, $form->{"paid_$i"} );
+ $form->{"$form->{vc}_id"} = $form->{"$form->{vc}_id_$i"};
+ }
+
+ }
+
+ $form->{rowcount} = $j;
+ for ( 1 .. $j ) { $form->{"id_$_"} = $temp{"id_$_"} }
+
+ &print_form if $ok;
+
+ for ( keys %oldform ) { $form->{$_} = $oldform{$_} }
+
+}
+
+sub print_form {
+
+ $c =
+ CP->new( ( $form->{language_code} )
+ ? $form->{language_code}
+ : $myconfig{countrycode} );
+ $c->init;
+
+ ( $whole, $form->{decimal} ) = split /\./, $form->{amount};
+ $form->{amount} = $form->format_amount( \%myconfig, $form->{amount}, 2 );
+ $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 );
+
+ $datepaid = $form->datetonum( \%myconfig, $form->{datepaid} );
+ ( $form->{yyyy}, $form->{mm}, $form->{dd} ) = $datepaid =~ /(....)(..)(..)/;
+
+ &{"$form->{vc}_details"};
+
+ $form->{templates} = "$myconfig{templates}";
+ $form->{IN} = "$form->{formname}.tex";
+
+ if ( $form->{media} ne 'screen' ) {
+ $form->{OUT} = "${LedgerSMB::Sysconfig::printer}{$form->{media}}";
+ $form->{printmode} = '|-';
+ }
+
+ if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
+ {
+ my $template =
+ LedgerSMB::Template->new( \%myconfig, $form->{'formname'}, 'HTML' );
+ try {
+ $template->render($form);
+ $form->header;
+ print $template->{'output'};
+ exit;
+ }
+ catch Error::Simple with {
+ my $E = shift;
+ $form->error( $E->stacktrace );
+ };
+ }
+ $form->parse_template( \%myconfig, ${LedgerSMB::Sysconfig::userspath} );
+
+}
+
+sub print_payment {
+
+ &check_form;
+
+ for (qw(company address)) { $form->{$_} = $myconfig{$_} }
+ $form->{address} =~ s/\\n/\n/g;
+
+ @a =
+ qw(rowcount name company address text_amount text_decimal address1 address2 city state zipcode country memo);
+
+ %temp = ();
+ for (@a) { $temp{$_} = $form->{$_} }
+
+ if (
+ scalar @{ $form->{invnumber} } >
+ ${LedgerSMB::Sysconfig::check_max_invoices} )
+ {
+ $#{ $form->{invnumber} } =
+ ${LedgerSMB::Sysconfig::check_max_invoices} - 1;
+ $form->{invnumbers_maxed} = 1;
+ $form->{message} =
+ $locale->text(
+ "Please see attatched report for list of invoices paid.");
+ }
+
+ $form->format_string(@a);
+
+ &print_form;
+
+ for ( keys %temp ) { $form->{$_} = $temp{$_} }
+
+}
+
+sub customer_details { IS->customer_details( \%myconfig, \%$form ) }
+sub vendor_details { IR->vendor_details( \%myconfig, \%$form ) }
+
+sub check_form {
+
+ &check_openvc;
+
+ if ( $form->{currency} ne $form->{oldcurrency} ) {
+ &update;
+ exit;
+ }
+
+ $form->error( $locale->text('Date missing!') ) unless $form->{datepaid};
+
+ $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
+ $datepaid = $form->datetonum( \%myconfig, $form->{datepaid} );
+
+ $form->error( $locale->text('Cannot post payment for a closed period!') )
+ if ( $datepaid <= $closedto );
+
+ # this is just to format the year
+ $form->{datepaid} = $locale->date( \%myconfig, $form->{datepaid} );
+
+ $amount = $form->parse_amount( \%myconfig, $form->{amount} );
+ $form->{amount} = $amount;
+
+ for $i ( 1 .. $form->{rowcount} ) {
+ if ( $form->{"paid_$i"} ) {
+ $amount -= $form->parse_amount( \%myconfig, $form->{"paid_$i"} );
+
+ push( @{ $form->{paid} }, $form->{"paid_$i"} );
+ push( @{ $form->{due} }, $form->{"due_$i"} );
+ push( @{ $form->{invnumber} }, $form->{"invnumber_$i"} );
+ push( @{ $form->{invdate} }, $form->{"transdate_$i"} );
+ }
+ }
+
+ if ( $form->round_amount( $amount, 2 ) != 0 ) {
+ push(
+ @{ $form->{paid} },
+ $form->format_amount( \%myconfig, $amount, 2 )
+ );
+ push( @{ $form->{due} }, $form->format_amount( \%myconfig, 0, "0" ) );
+ push(
+ @{ $form->{invnumber} },
+ ( $form->{ARAP} eq 'AR' )
+ ? $locale->text('Deposit')
+ : $locale->text('Prepayment')
+ );
+ push( @{ $form->{invdate} }, $form->{datepaid} );
+ }
+
+}
+
+sub check_openvc {
+
+ $name = $form->{vc};
+ ( $new_name, $new_id ) = split /--/, $form->{$name};
+
+ if ( $form->{all_vc} ) {
+ if ( $form->{"select$name"} ) {
+ $ok = ( $form->{"old$name"} ne $form->{$name} );
+ }
+ else {
+ $ok =
+ ( $form->{"old$name"} ne
+ qq|$form->{$name}--$form->{"${name}_id"}| );
+ }
+
+ if ($ok) {
+ $form->{redo} = 1;
+ if ( $form->{"select$name"} ) {
+ $form->{"${name}_id"} = $new_id;
+ AA->get_name( \%myconfig, \%$form );
+ $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
+ }
+ else {
+ &check_name( $form->{vc} );
+ }
+ }
+
+ }
+ else {
+
+ # if we use a selection
+ if ( $form->{"select$name"} ) {
+ if ( $form->{"old$name"} ne $form->{$name} ) {
+
+ $form->{"${name}_id"} = $new_id;
+ AA->get_name( \%myconfig, \%$form );
+
+ $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
+ $form->{redo} = 1;
+ }
+ }
+ else {
+
+ # check name, combine name and id
+ if ( $form->{"old$name"} ne
+ qq|$form->{$name}--$form->{"${name}_id"}| )
+ {
+
+ # return one name or a list of names in $form->{name_list}
+ if ( ( $rv = CP->get_openvc( \%myconfig, \%$form ) ) > 1 ) {
+ $form->{redo} = 1;
+ &select_name($name);
+ exit;
+ }
+
+ if ( $rv == 1 ) {
+
+ # we got one name
+ $form->{"${name}_id"} = $form->{name_list}[0]->{id};
+ $form->{$name} = $form->{name_list}[0]->{name};
+ $form->{"old$name"} =
+ qq|$form->{$name}--$form->{"${name}_id"}|;
+
+ AA->get_name( \%myconfig, \%$form );
+
+ }
+ else {
+
+ # nothing open
+ $form->error( $locale->text('Nothing open!') );
+ }
+
+ $form->{redo} = 1;
+ }
+ }
+ }
+
+}
+
diff --git a/bin/ct.pl b/bin/ct.pl
index 252c36be..1f90e63c 100644
--- a/bin/ct.pl
+++ b/bin/ct.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -44,50 +44,52 @@
use LedgerSMB::CT;
1;
+
# end of main
+sub add {
+ $form->{title} = "Add";
-sub add {
+ # $locale->text('Add Customer')
+ # $locale->text('Add Vendor')
- $form->{title} = "Add";
-# $locale->text('Add Customer')
-# $locale->text('Add Vendor')
+ $form->{callback} =
+"$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
- $form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
+ CT->create_links( \%myconfig, \%$form );
- CT->create_links(\%myconfig, \%$form);
-
- &form_header;
- &form_footer;
-
-}
+ &form_header;
+ &form_footer;
+}
sub history {
-# $locale->text('Customer History')
-# $locale->text('Vendor History')
-
- $history = 1;
- $label = ucfirst $form->{db};
- $label .= " History";
-
- if ($form->{db} eq 'customer') {
- $invlabel = $locale->text('Sales Invoices');
- $ordlabel = $locale->text('Sales Orders');
- $quolabel = $locale->text('Quotations');
- } else {
- $invlabel = $locale->text('Vendor Invoices');
- $ordlabel = $locale->text('Purchase Orders');
- $quolabel = $locale->text('Request for Quotations');
- }
-
- $form->{title} = $locale->text($label);
-
- $form->{nextsub} = "list_history";
-
- $transactions = qq|
+ # $locale->text('Customer History')
+ # $locale->text('Vendor History')
+
+ $history = 1;
+ $label = ucfirst $form->{db};
+ $label .= " History";
+
+ if ( $form->{db} eq 'customer' ) {
+ $invlabel = $locale->text('Sales Invoices');
+ $ordlabel = $locale->text('Sales Orders');
+ $quolabel = $locale->text('Quotations');
+ }
+ else {
+ $invlabel = $locale->text('Vendor Invoices');
+ $ordlabel = $locale->text('Purchase Orders');
+ $quolabel = $locale->text('Request for Quotations');
+ }
+
+ $form->{title} = $locale->text($label);
+
+ $form->{nextsub} = "list_history";
+
+ $transactions = qq|
<tr>
<td></td>
<td>
@@ -109,16 +111,18 @@ sub history {
<td>
<table>
<tr>
- <th>|.$locale->text('From').qq|</th>
+ <th>| . $locale->text('From') . qq|</th>
<td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
- <th>|.$locale->text('To').qq|</th>
+ <th>| . $locale->text('To') . qq|</th>
<td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
</tr>
<tr>
<td></td>
<td colspan=3>
- <input name="open" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Open').qq|
- <input name="closed" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Closed').qq|
+ <input name="open" type=checkbox class=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Open') . qq|
+ <input name="closed" type=checkbox class=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Closed') . qq|
</td>
</tr>
</table>
@@ -129,50 +133,63 @@ sub history {
</tr>
|;
- $include = qq|
+ $include = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
+ <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
<td>
<table>
<tr>
- <td><input name=history type=radio class=radio value=summary checked> |.$locale->text('Summary').qq|</td>
- <td><input name=history type=radio class=radio value=detail> |.$locale->text('Detail').qq|
+ <td><input name=history type=radio class=radio value=summary checked> |
+ . $locale->text('Summary')
+ . qq|</td>
+ <td><input name=history type=radio class=radio value=detail> |
+ . $locale->text('Detail') . qq|
</td>
</tr>
<tr>
<td>
- <input name="l_partnumber" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Part Number').qq|
+ <input name="l_partnumber" type=checkbox class=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Part Number') . qq|
</td>
<td>
- <input name="l_description" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Description').qq|
+ <input name="l_description" type=checkbox class=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Description') . qq|
</td>
<td>
- <input name="l_sellprice" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Sell Price').qq|
+ <input name="l_sellprice" type=checkbox class=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Sell Price') . qq|
</td>
<td>
- <input name="l_curr" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Currency').qq|
+ <input name="l_curr" type=checkbox class=checkbox value=Y>&nbsp;|
+ . $locale->text('Currency') . qq|
</td>
</tr>
<tr>
<td>
- <input name="l_qty" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Qty').qq|
+ <input name="l_qty" type=checkbox class=checkbox value=Y>&nbsp;|
+ . $locale->text('Qty') . qq|
</td>
<td>
- <input name="l_unit" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Unit').qq|
+ <input name="l_unit" type=checkbox class=checkbox value=Y>&nbsp;|
+ . $locale->text('Unit') . qq|
</td>
<td>
- <input name="l_discount" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Discount').qq|
+ <input name="l_discount" type=checkbox class=checkbox value=Y>&nbsp;|
+ . $locale->text('Discount') . qq|
</td>
<tr>
</tr>
<td>
- <input name="l_deliverydate" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Delivery Date').qq|
+ <input name="l_deliverydate" type=checkbox class=checkbox value=Y>&nbsp;|
+ . $locale->text('Delivery Date') . qq|
</td>
<td>
- <input name="l_projectnumber" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Project Number').qq|
+ <input name="l_projectnumber" type=checkbox class=checkbox value=Y>&nbsp;|
+ . $locale->text('Project Number') . qq|
</td>
<td>
- <input name="l_serialnumber" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Serial Number').qq|
+ <input name="l_serialnumber" type=checkbox class=checkbox value=Y>&nbsp;|
+ . $locale->text('Serial Number') . qq|
</td>
</tr>
</table>
@@ -180,37 +197,36 @@ sub history {
</tr>
|;
- &search_name;
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ &search_name;
- print qq|
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
</body>
</html>
|;
}
-
sub transactions {
- if ($form->{db} eq 'customer') {
- $translabel = $locale->text('AR Transactions');
- $invlabel = $locale->text('Sales Invoices');
- $ordlabel = $locale->text('Sales Orders');
- $quolabel = $locale->text('Quotations');
- } else {
- $translabel = $locale->text('AP Transactions');
- $invlabel = $locale->text('Vendor Invoices');
- $ordlabel = $locale->text('Purchase Orders');
- $quolabel = $locale->text('Request for Quotations');
- }
+ if ( $form->{db} eq 'customer' ) {
+ $translabel = $locale->text('AR Transactions');
+ $invlabel = $locale->text('Sales Invoices');
+ $ordlabel = $locale->text('Sales Orders');
+ $quolabel = $locale->text('Quotations');
+ }
+ else {
+ $translabel = $locale->text('AP Transactions');
+ $invlabel = $locale->text('Vendor Invoices');
+ $ordlabel = $locale->text('Purchase Orders');
+ $quolabel = $locale->text('Request for Quotations');
+ }
-
- $transactions = qq|
+ $transactions = qq|
<tr>
<td></td>
<td>
@@ -235,25 +251,31 @@ sub transactions {
<td>
<table>
<tr>
- <th>|.$locale->text('From').qq|</th>
+ <th>| . $locale->text('From') . qq|</th>
<td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
- <th>|.$locale->text('To').qq|</th>
+ <th>| . $locale->text('To') . qq|</th>
<td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
</tr>
<tr>
<td></td>
<td colspan=3>
- <input name="open" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Open').qq|
- <input name="closed" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Closed').qq|
+ <input name="open" type=checkbox class=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Open') . qq|
+ <input name="closed" type=checkbox class=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Closed') . qq|
</td>
</tr>
<tr>
<td></td>
<td colspan=3>
- <input name="l_amount" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Amount').qq|
- <input name="l_tax" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Tax').qq|
- <input name="l_total" type=checkbox class=checkbox value=Y checked>&nbsp;|.$locale->text('Total').qq|
- <input name="l_subtotal" type=checkbox class=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|
+ <input name="l_amount" type=checkbox class=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Amount') . qq|
+ <input name="l_tax" type=checkbox class=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Tax') . qq|
+ <input name="l_total" type=checkbox class=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Total') . qq|
+ <input name="l_subtotal" type=checkbox class=checkbox value=Y>&nbsp;|
+ . $locale->text('Subtotal') . qq|
</td>
</tr>
</table>
@@ -266,76 +288,122 @@ sub transactions {
}
-
sub include_in_report {
-
- $label = ucfirst $form->{db};
-
- @a = ();
-
- push @a, qq|<input name="l_ndx" type=checkbox class=checkbox value=Y> |.$locale->text('No.');
- push @a, qq|<input name="l_id" type=checkbox class=checkbox value=Y> |.$locale->text('ID');
- push @a, qq|<input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |.$locale->text($label . ' Number');
- push @a, qq|<input name="l_name" type=checkbox class=checkbox value=Y $form->{l_name}> |.$locale->text('Company Name');
- push @a, qq|<input name="l_contact" type=checkbox class=checkbox value=Y $form->{l_contact}> |.$locale->text('Contact');
- push @a, qq|<input name="l_email" type=checkbox class=checkbox value=Y $form->{l_email}> |.$locale->text('E-mail');
- push @a, qq|<input name="l_address" type=checkbox class=checkbox value=Y> |.$locale->text('Address');
- push @a, qq|<input name="l_city" type=checkbox class=checkbox value=Y> |.$locale->text('City');
- push @a, qq|<input name="l_state" type=checkbox class=checkbox value=Y> |.$locale->text('State/Province');
- push @a, qq|<input name="l_zipcode" type=checkbox class=checkbox value=Y> |.$locale->text('Zip/Postal Code');
- push @a, qq|<input name="l_country" type=checkbox class=checkbox value=Y> |.$locale->text('Country');
- push @a, qq|<input name="l_phone" type=checkbox class=checkbox value=Y $form->{l_phone}> |.$locale->text('Phone');
- push @a, qq|<input name="l_fax" type=checkbox class=checkbox value=Y> |.$locale->text('Fax');
- push @a, qq|<input name="l_cc" type=checkbox class=checkbox value=Y> |.$locale->text('Cc');
-
- if ($myconfig{role} =~ /(admin|manager)/) {
- push @a, qq|<input name="l_bcc" type=checkbox class=checkbox value=Y> |.$locale->text('Bcc');
- }
-
- push @a, qq|<input name="l_notes" type=checkbox class=checkbox value=Y> |.$locale->text('Notes');
- push @a, qq|<input name="l_discount" type=checkbox class=checkbox value=Y> |.$locale->text('Discount');
- push @a, qq|<input name="l_taxaccount" type=checkbox class=checkbox value=Y> |.$locale->text('Tax Account');
- push @a, qq|<input name="l_taxnumber" type=checkbox class=checkbox value=Y> |.$locale->text('Tax Number');
-
- if ($form->{db} eq 'customer') {
- push @a, qq|<input name="l_employee" type=checkbox class=checkbox value=Y> |.$locale->text('Salesperson');
- push @a, qq|<input name="l_manager" type=checkbox class=checkbox value=Y> |.$locale->text('Manager');
- push @a, qq|<input name="l_pricegroup" type=checkbox class=checkbox value=Y> |.$locale->text('Pricegroup');
-
- } else {
- push @a, qq|<input name="l_employee" type=checkbox class=checkbox value=Y> |.$locale->text('Employee');
- push @a, qq|<input name="l_manager" type=checkbox class=checkbox value=Y> |.$locale->text('Manager');
- push @a, qq|<input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |.$locale->text('GIFI');
-
- }
-
- push @a, qq|<input name="l_sic_code" type=checkbox class=checkbox value=Y> |.$locale->text('SIC');
- push @a, qq|<input name="l_iban" type=checkbox class=checkbox value=Y> |.$locale->text('IBAN');
- push @a, qq|<input name="l_bic" type=checkbox class=checkbox value=Y> |.$locale->text('BIC');
- push @a, qq|<input name="l_business" type=checkbox class=checkbox value=Y> |.$locale->text('Type of Business');
- push @a, qq|<input name="l_terms" type=checkbox class=checkbox value=Y> |.$locale->text('Terms');
- push @a, qq|<input name="l_language" type=checkbox class=checkbox value=Y> |.$locale->text('Language');
- push @a, qq|<input name="l_startdate" type=checkbox class=checkbox value=Y> |.$locale->text('Startdate');
- push @a, qq|<input name="l_enddate" type=checkbox class=checkbox value=Y> |.$locale->text('Enddate');
-
-
- $include = qq|
+
+ $label = ucfirst $form->{db};
+
+ @a = ();
+
+ push @a, qq|<input name="l_ndx" type=checkbox class=checkbox value=Y> |
+ . $locale->text('No.');
+ push @a, qq|<input name="l_id" type=checkbox class=checkbox value=Y> |
+ . $locale->text('ID');
+ push @a,
+qq|<input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |
+ . $locale->text( $label . ' Number' );
+ push @a,
+qq|<input name="l_name" type=checkbox class=checkbox value=Y $form->{l_name}> |
+ . $locale->text('Company Name');
+ push @a,
+qq|<input name="l_contact" type=checkbox class=checkbox value=Y $form->{l_contact}> |
+ . $locale->text('Contact');
+ push @a,
+qq|<input name="l_email" type=checkbox class=checkbox value=Y $form->{l_email}> |
+ . $locale->text('E-mail');
+ push @a, qq|<input name="l_address" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Address');
+ push @a, qq|<input name="l_city" type=checkbox class=checkbox value=Y> |
+ . $locale->text('City');
+ push @a, qq|<input name="l_state" type=checkbox class=checkbox value=Y> |
+ . $locale->text('State/Province');
+ push @a, qq|<input name="l_zipcode" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Zip/Postal Code');
+ push @a, qq|<input name="l_country" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Country');
+ push @a,
+qq|<input name="l_phone" type=checkbox class=checkbox value=Y $form->{l_phone}> |
+ . $locale->text('Phone');
+ push @a, qq|<input name="l_fax" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Fax');
+ push @a, qq|<input name="l_cc" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Cc');
+
+ if ( $myconfig{role} =~ /(admin|manager)/ ) {
+ push @a, qq|<input name="l_bcc" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Bcc');
+ }
+
+ push @a, qq|<input name="l_notes" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Notes');
+ push @a, qq|<input name="l_discount" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Discount');
+ push @a,
+ qq|<input name="l_taxaccount" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Tax Account');
+ push @a,
+ qq|<input name="l_taxnumber" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Tax Number');
+
+ if ( $form->{db} eq 'customer' ) {
+ push @a,
+ qq|<input name="l_employee" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Salesperson');
+ push @a,
+ qq|<input name="l_manager" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Manager');
+ push @a,
+ qq|<input name="l_pricegroup" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Pricegroup');
+
+ }
+ else {
+ push @a,
+ qq|<input name="l_employee" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Employee');
+ push @a,
+ qq|<input name="l_manager" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Manager');
+ push @a,
+ qq|<input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |
+ . $locale->text('GIFI');
+
+ }
+
+ push @a, qq|<input name="l_sic_code" type=checkbox class=checkbox value=Y> |
+ . $locale->text('SIC');
+ push @a, qq|<input name="l_iban" type=checkbox class=checkbox value=Y> |
+ . $locale->text('IBAN');
+ push @a, qq|<input name="l_bic" type=checkbox class=checkbox value=Y> |
+ . $locale->text('BIC');
+ push @a, qq|<input name="l_business" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Type of Business');
+ push @a, qq|<input name="l_terms" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Terms');
+ push @a, qq|<input name="l_language" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Language');
+ push @a,
+ qq|<input name="l_startdate" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Startdate');
+ push @a, qq|<input name="l_enddate" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Enddate');
+
+ $include = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
+ <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
<td>
<table>
|;
- while (@a) {
- $include .= qq|<tr>\n|;
- for (1 .. 5) {
- $include .= qq|<td nowrap>|. shift @a;
- $include .= qq|</td>\n|;
+ while (@a) {
+ $include .= qq|<tr>\n|;
+ for ( 1 .. 5 ) {
+ $include .= qq|<td nowrap>| . shift @a;
+ $include .= qq|</td>\n|;
+ }
+ $include .= qq|</tr>\n|;
}
- $include .= qq|</tr>\n|;
- }
- $include .= qq|
+ $include .= qq|
</table>
</td>
</tr>
@@ -343,39 +411,42 @@ sub include_in_report {
}
-
sub search {
-# $locale->text('Customers')
-# $locale->text('Vendors')
+ # $locale->text('Customers')
+ # $locale->text('Vendors')
+
+ $form->{title} = $locale->text('Search') unless $form->{title};
- $form->{title} = $locale->text('Search') unless $form->{title};
-
- for (qw(name contact phone email)) { $form->{"l_$_"} = 'checked' }
+ for (qw(name contact phone email)) { $form->{"l_$_"} = 'checked' }
- $form->{nextsub} = "list_names";
+ $form->{nextsub} = "list_names";
- $orphan = qq|
+ $orphan = qq|
<tr>
<td></td>
- <td><input name=status class=radio type=radio value=all checked>&nbsp;|.$locale->text('All').qq|
- <input name=status class=radio type=radio value=active>&nbsp;|.$locale->text('Active').qq|
- <input name=status class=radio type=radio value=inactive>&nbsp;|.$locale->text('Inactive').qq|
- <input name=status class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned').qq|</td>
+ <td><input name=status class=radio type=radio value=all checked>&nbsp;|
+ . $locale->text('All') . qq|
+ <input name=status class=radio type=radio value=active>&nbsp;|
+ . $locale->text('Active') . qq|
+ <input name=status class=radio type=radio value=inactive>&nbsp;|
+ . $locale->text('Inactive') . qq|
+ <input name=status class=radio type=radio value=orphaned>&nbsp;|
+ . $locale->text('Orphaned')
+ . qq|</td>
</tr>
|;
+ &transactions;
+ &include_in_report;
+ &search_name;
- &transactions;
- &include_in_report;
- &search_name;
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</body>
</html>
@@ -383,28 +454,26 @@ sub search {
}
-
sub search_name {
- $label = ucfirst $form->{db};
+ $label = ucfirst $form->{db};
- if ($form->{db} eq 'customer') {
- $employee = qq|
- <th align=right nowrap>|.$locale->text('Salesperson').qq|</th>
+ if ( $form->{db} eq 'customer' ) {
+ $employee = qq|
+ <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
<td><input name=employee size=32></td>
|;
- }
- if ($form->{db} eq 'vendor') {
- $employee = qq|
- <th align=right nowrap>|.$locale->text('Employee').qq|</th>
+ }
+ if ( $form->{db} eq 'vendor' ) {
+ $employee = qq|
+ <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
<td><input name=employee size=32></td>
|;
- }
-
-
- $form->header;
-
- print qq|
+ }
+
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -423,26 +492,26 @@ sub search_name {
<td>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Company Name').qq|</th>
+ <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
<td><input name=name size=32></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Contact').qq|</th>
+ <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
<td><input name=contact size=32></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
+ <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
<td><input name=email size=32></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Phone').qq|</th>
+ <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
<td><input name=phone size=20></td>
</tr>
<tr>
$employee
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Notes').qq|</th>
+ <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
<td colspan=3><textarea name=notes rows=3 cols=32></textarea></td>
</tr>
</table>
@@ -451,32 +520,36 @@ sub search_name {
<td>
<table>
<tr>
- <th align=right nowrap>|.$locale->text($label . ' Number').qq|</th>
+ <th align=right nowrap>| . $locale->text( $label . ' Number' ) . qq|</th>
<td><input name=$form->{db}number size=32></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Address').qq|</th>
+ <th align=right nowrap>| . $locale->text('Address') . qq|</th>
<td><input name=address size=32></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('City').qq|</th>
+ <th align=right nowrap>| . $locale->text('City') . qq|</th>
<td><input name=city size=32></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
+ <th align=right nowrap>| . $locale->text('State/Province') . qq|</th>
<td><input name=state size=32></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
+ <th align=right nowrap>| . $locale->text('Zip/Postal Code') . qq|</th>
<td><input name=zipcode size=10></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Country').qq|</th>
+ <th align=right nowrap>| . $locale->text('Country') . qq|</th>
<td><input name=country size=32></td>
</tr>
<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>
+ <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>
</table>
</td>
@@ -509,266 +582,369 @@ sub search_name {
<input type="hidden" name="sessionid" value="$form->{sessionid}">
<br>
-<button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+<button type="submit" class="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
|;
}
-
sub list_names {
- CT->search(\%myconfig, \%$form);
-
- $href = "$form->{script}?action=list_names&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&l_subtotal=$form->{l_subtotal}";
-
- $form->sort_order();
-
- $callback = "$form->{script}?action=list_names&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&l_subtotal=$form->{l_subtotal}";
-
- @columns = $form->sort_columns(id, name, "$form->{db}number", address,
- city, state, zipcode, country, contact,
- phone, fax, email, cc, bcc, employee,
- manager, notes, discount, terms,
- taxaccount, taxnumber, gifi_accno, sic_code, business,
- pricegroup, language, iban, bic,
- startdate, enddate,
- invnumber, invamount, invtax, invtotal,
- ordnumber, ordamount, ordtax, ordtotal,
- quonumber, quoamount, quotax, quototal);
- unshift @columns, "ndx";
-
- $form->{l_invnumber} = "Y" if $form->{l_transnumber};
- foreach $item (qw(inv ord quo)) {
- if ($form->{"l_${item}number"}) {
- for (qw(amount tax total)) { $form->{"l_$item$_"} = $form->{"l_$_"} }
- $removeemployee = 1;
- $openclosed = 1;
- }
- }
- $form->{open} = $form->{closed} = "" if !$openclosed;
-
-
- 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";
- }
- }
-
- foreach $item (qw(amount tax total transnumber)) {
- if ($form->{"l_$item"} eq "Y") {
- $callback .= "&l_$item=Y";
- $href .= "&l_$item=Y";
- }
- }
-
-
- if ($form->{status} eq 'all') {
- $option = $locale->text('All');
- }
- if ($form->{status} eq 'orphaned') {
- $option = $locale->text('Orphaned');
- }
- if ($form->{status} eq 'active') {
- $option = $locale->text('Active');
- }
- if ($form->{status} eq 'inactive') {
- $option = $locale->text('Inactive');
- }
-
- if ($form->{name}) {
- $callback .= "&name=".$form->escape($form->{name},1);
- $href .= "&name=".$form->escape($form->{name});
- $option .= "\n<br>".$locale->text('Name')." : $form->{name}";
- }
- if ($form->{address}) {
- $callback .= "&address=".$form->escape($form->{address},1);
- $href .= "&address=".$form->escape($form->{address});
- $option .= "\n<br>".$locale->text('Address')." : $form->{address}";
- }
- if ($form->{city}) {
- $callback .= "&city=".$form->escape($form->{city},1);
- $href .= "&city=".$form->escape($form->{city});
- $option .= "\n<br>".$locale->text('City')." : $form->{city}";
- }
- if ($form->{state}) {
- $callback .= "&state=".$form->escape($form->{state},1);
- $href .= "&state=".$form->escape($form->{state});
- $option .= "\n<br>".$locale->text('State')." : $form->{state}";
- }
- if ($form->{zipcode}) {
- $callback .= "&zipcode=".$form->escape($form->{zipcode},1);
- $href .= "&zipcode=".$form->escape($form->{zipcode});
- $option .= "\n<br>".$locale->text('Zip/Postal Code')." : $form->{zipcode}";
- }
- if ($form->{country}) {
- $callback .= "&country=".$form->escape($form->{country},1);
- $href .= "&country=".$form->escape($form->{country});
- $option .= "\n<br>".$locale->text('Country')." : $form->{country}";
- }
- if ($form->{contact}) {
- $callback .= "&contact=".$form->escape($form->{contact},1);
- $href .= "&contact=".$form->escape($form->{contact});
- $option .= "\n<br>".$locale->text('Contact')." : $form->{contact}";
- }
- if ($form->{employee}) {
- $callback .= "&employee=".$form->escape($form->{employee},1);
- $href .= "&employee=".$form->escape($form->{employee});
- $option .= "\n<br>";
- if ($form->{db} eq 'customer') {
- $option .= $locale->text('Salesperson');
- }
- if ($form->{db} eq 'vendor') {
- $option .= $locale->text('Employee');
- }
- $option .= " : $form->{employee}";
- }
-
- $fromdate = "";
- $todate = "";
- if ($form->{startdatefrom}) {
- $callback .= "&startdatefrom=$form->{startdatefrom}";
- $href .= "&startdatefrom=$form->{startdatefrom}";
- $fromdate = $locale->date(\%myconfig, $form->{startdatefrom}, 1);
- }
- if ($form->{startdateto}) {
- $callback .= "&startdateto=$form->{startdateto}";
- $href .= "&startdateto=$form->{startdateto}";
- $todate = $locale->date(\%myconfig, $form->{startdateto}, 1);
- }
- if ($fromdate || $todate) {
- $option .= "\n<br>".$locale->text('Startdate')." $fromdate - $todate";
- }
-
- if ($form->{notes}) {
- $callback .= "&notes=".$form->escape($form->{notes},1);
- $href .= "&notes=".$form->escape($form->{notes});
- $option .= "\n<br>".$locale->text('Notes')." : $form->{notes}";
- }
- if ($form->{"$form->{db}number"}) {
- $callback .= qq|&$form->{db}number=|.$form->escape($form->{"$form->{db}number"},1);
- $href .= "&$form->{db}number=".$form->escape($form->{"$form->{db}number"});
- $option .= "\n<br>".$locale->text('Number').qq| : $form->{"$form->{db}number"}|;
- }
- if ($form->{phone}) {
- $callback .= "&phone=".$form->escape($form->{phone},1);
- $href .= "&phone=".$form->escape($form->{phone});
- $option .= "\n<br>".$locale->text('Phone')." : $form->{phone}";
- }
- if ($form->{email}) {
- $callback .= "&email=".$form->escape($form->{email},1);
- $href .= "&email=".$form->escape($form->{email});
- $option .= "\n<br>".$locale->text('E-mail')." : $form->{email}";
- }
- 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}";
- if ($form->{transdatefrom}) {
- $option .= " ";
- } else {
- $option .= "\n<br>" if ($option);
- }
- $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 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');
- }
-
-
- $form->{callback} = "$callback&sort=$form->{sort}";
- $callback = $form->escape($form->{callback});
-
- $column_header{ndx} = qq|<th class=listheading>&nbsp;</th>|;
- $column_header{id} = qq|<th class=listheading>|.$locale->text('ID').qq|</th>|;
- $column_header{"$form->{db}number"} = qq|<th><a class=listheading href=$href&sort=$form->{db}number>|.$locale->text('Number').qq|</a></th>|;
- $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|;
- $column_header{address} = qq|<th class=listheading>|.$locale->text('Address').qq|</th>|;
- $column_header{city} = qq|<th><a class=listheading href=$href&sort=city>|.$locale->text('City').qq|</a></th>|;
- $column_header{state} = qq|<th><a class=listheading href=$href&sort=state>|.$locale->text('State/Province').qq|</a></th>|;
- $column_header{zipcode} = qq|<th><a class=listheading href=$href&sort=zipcode>|.$locale->text('Zip/Postal Code').qq|</a></th>|;
- $column_header{country} = qq|<th><a class=listheading href=$href&sort=country>|.$locale->text('Country').qq|</a></th>|;
- $column_header{contact} = qq|<th><a class=listheading href=$href&sort=contact>|.$locale->text('Contact').qq|</a></th>|;
- $column_header{phone} = qq|<th><a class=listheading href=$href&sort=phone>|.$locale->text('Phone').qq|</a></th>|;
- $column_header{fax} = qq|<th><a class=listheading href=$href&sort=fax>|.$locale->text('Fax').qq|</a></th>|;
- $column_header{email} = qq|<th><a class=listheading href=$href&sort=email>|.$locale->text('E-mail').qq|</a></th>|;
- $column_header{cc} = qq|<th><a class=listheading href=$href&sort=cc>|.$locale->text('Cc').qq|</a></th>|;
- $column_header{bcc} = qq|<th><a class=listheading href=$href&sort=cc>|.$locale->text('Bcc').qq|</a></th>|;
- $column_header{notes} = qq|<th><a class=listheading href=$href&sort=notes>|.$locale->text('Notes').qq|</a></th>|;
- $column_header{discount} = qq|<th class=listheading>%</th>|;
- $column_header{terms} = qq|<th class=listheading>|.$locale->text('Terms').qq|</th>|;
-
- $column_header{taxnumber} = qq|<th><a class=listheading href=$href&sort=taxnumber>|.$locale->text('Tax Number').qq|</a></th>|;
- $column_header{taxaccount} = qq|<th class=listheading>|.$locale->text('Tax Account').qq|</th>|;
- $column_header{gifi_accno} = qq|<th><a class=listheading href=$href&sort=gifi_accno>|.$locale->text('GIFI').qq|</a></th>|;
- $column_header{sic_code} = qq|<th><a class=listheading href=$href&sort=sic_code>|.$locale->text('SIC').qq|</a></th>|;
- $column_header{business} = qq|<th><a class=listheading href=$href&sort=business>|.$locale->text('Type of Business').qq|</a></th>|;
- $column_header{iban} = qq|<th class=listheading>|.$locale->text('IBAN').qq|</th>|;
- $column_header{bic} = qq|<th class=listheading>|.$locale->text('BIC').qq|</th>|;
- $column_header{startdate} = qq|<th><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|;
- $column_header{enddate} = qq|<th><a class=listheading href=$href&sort=enddate>|.$locale->text('Enddate').qq|</a></th>|;
-
- $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice').qq|</a></th>|;
- $column_header{ordnumber} = qq|<th><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order').qq|</a></th>|;
- $column_header{quonumber} = qq|<th><a class=listheading href=$href&sort=quonumber>|.$locale->text('Quotation').qq|</a></th>|;
-
- if ($form->{db} eq 'customer') {
- $column_header{employee} = qq|<th><a class=listheading href=$href&sort=employee>|.$locale->text('Salesperson').qq|</a></th>|;
- } else {
- $column_header{employee} = qq|<th><a class=listheading href=$href&sort=employee>|.$locale->text('Employee').qq|</a></th>|;
- }
- $column_header{manager} = qq|<th><a class=listheading href=$href&sort=manager>|.$locale->text('Manager').qq|</a></th>|;
-
- $column_header{pricegroup} = qq|<th><a class=listheading href=$href&sort=pricegroup>|.$locale->text('Pricegroup').qq|</a></th>|;
- $column_header{language} = qq|<th><a class=listheading href=$href&sort=language>|.$locale->text('Language').qq|</a></th>|;
-
-
- $amount = $locale->text('Amount');
- $tax = $locale->text('Tax');
- $total = $locale->text('Total');
-
- $column_header{invamount} = qq|<th class=listheading>$amount</th>|;
- $column_header{ordamount} = qq|<th class=listheading>$amount</th>|;
- $column_header{quoamount} = qq|<th class=listheading>$amount</th>|;
-
- $column_header{invtax} = qq|<th class=listheading>$tax</th>|;
- $column_header{ordtax} = qq|<th class=listheading>$tax</th>|;
- $column_header{quotax} = qq|<th class=listheading>$tax</th>|;
-
- $column_header{invtotal} = qq|<th class=listheading>$total</th>|;
- $column_header{ordtotal} = qq|<th class=listheading>$total</th>|;
- $column_header{quototal} = qq|<th class=listheading>$total</th>|;
-
+ CT->search( \%myconfig, \%$form );
+
+ $href =
+"$form->{script}?action=list_names&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&l_subtotal=$form->{l_subtotal}";
+
+ $form->sort_order();
+
+ $callback =
+"$form->{script}?action=list_names&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&l_subtotal=$form->{l_subtotal}";
+
+ @columns = $form->sort_columns( id, name, "$form->{db}number", address,
+ city, state, zipcode, country,
+ contact, phone, fax, email,
+ cc, bcc, employee, manager,
+ notes, discount, terms, taxaccount,
+ taxnumber, gifi_accno, sic_code, business,
+ pricegroup, language, iban, bic,
+ startdate, enddate, invnumber, invamount,
+ invtax, invtotal, ordnumber, ordamount,
+ ordtax, ordtotal, quonumber, quoamount,
+ quotax, quototal
+ );
+ unshift @columns, "ndx";
+
+ $form->{l_invnumber} = "Y" if $form->{l_transnumber};
+ foreach $item (qw(inv ord quo)) {
+ if ( $form->{"l_${item}number"} ) {
+ for (qw(amount tax total)) {
+ $form->{"l_$item$_"} = $form->{"l_$_"};
+ }
+ $removeemployee = 1;
+ $openclosed = 1;
+ }
+ }
+ $form->{open} = $form->{closed} = "" if !$openclosed;
- if ($form->{status}) {
- $label = ucfirst $form->{db}."s";
- $form->{title} = $locale->text($label);
- } else {
- $label = ucfirst $form->{db};
- $form->{title} = $locale->text($label ." Transactions");
- }
+ 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";
+ }
+ }
- $form->header;
+ foreach $item (qw(amount tax total transnumber)) {
+ if ( $form->{"l_$item"} eq "Y" ) {
+ $callback .= "&l_$item=Y";
+ $href .= "&l_$item=Y";
+ }
+ }
- print qq|
+ if ( $form->{status} eq 'all' ) {
+ $option = $locale->text('All');
+ }
+ if ( $form->{status} eq 'orphaned' ) {
+ $option = $locale->text('Orphaned');
+ }
+ if ( $form->{status} eq 'active' ) {
+ $option = $locale->text('Active');
+ }
+ if ( $form->{status} eq 'inactive' ) {
+ $option = $locale->text('Inactive');
+ }
+
+ if ( $form->{name} ) {
+ $callback .= "&name=" . $form->escape( $form->{name}, 1 );
+ $href .= "&name=" . $form->escape( $form->{name} );
+ $option .= "\n<br>" . $locale->text('Name') . " : $form->{name}";
+ }
+ if ( $form->{address} ) {
+ $callback .= "&address=" . $form->escape( $form->{address}, 1 );
+ $href .= "&address=" . $form->escape( $form->{address} );
+ $option .= "\n<br>" . $locale->text('Address') . " : $form->{address}";
+ }
+ if ( $form->{city} ) {
+ $callback .= "&city=" . $form->escape( $form->{city}, 1 );
+ $href .= "&city=" . $form->escape( $form->{city} );
+ $option .= "\n<br>" . $locale->text('City') . " : $form->{city}";
+ }
+ if ( $form->{state} ) {
+ $callback .= "&state=" . $form->escape( $form->{state}, 1 );
+ $href .= "&state=" . $form->escape( $form->{state} );
+ $option .= "\n<br>" . $locale->text('State') . " : $form->{state}";
+ }
+ if ( $form->{zipcode} ) {
+ $callback .= "&zipcode=" . $form->escape( $form->{zipcode}, 1 );
+ $href .= "&zipcode=" . $form->escape( $form->{zipcode} );
+ $option .=
+ "\n<br>" . $locale->text('Zip/Postal Code') . " : $form->{zipcode}";
+ }
+ if ( $form->{country} ) {
+ $callback .= "&country=" . $form->escape( $form->{country}, 1 );
+ $href .= "&country=" . $form->escape( $form->{country} );
+ $option .= "\n<br>" . $locale->text('Country') . " : $form->{country}";
+ }
+ if ( $form->{contact} ) {
+ $callback .= "&contact=" . $form->escape( $form->{contact}, 1 );
+ $href .= "&contact=" . $form->escape( $form->{contact} );
+ $option .= "\n<br>" . $locale->text('Contact') . " : $form->{contact}";
+ }
+ if ( $form->{employee} ) {
+ $callback .= "&employee=" . $form->escape( $form->{employee}, 1 );
+ $href .= "&employee=" . $form->escape( $form->{employee} );
+ $option .= "\n<br>";
+ if ( $form->{db} eq 'customer' ) {
+ $option .= $locale->text('Salesperson');
+ }
+ if ( $form->{db} eq 'vendor' ) {
+ $option .= $locale->text('Employee');
+ }
+ $option .= " : $form->{employee}";
+ }
+
+ $fromdate = "";
+ $todate = "";
+ if ( $form->{startdatefrom} ) {
+ $callback .= "&startdatefrom=$form->{startdatefrom}";
+ $href .= "&startdatefrom=$form->{startdatefrom}";
+ $fromdate = $locale->date( \%myconfig, $form->{startdatefrom}, 1 );
+ }
+ if ( $form->{startdateto} ) {
+ $callback .= "&startdateto=$form->{startdateto}";
+ $href .= "&startdateto=$form->{startdateto}";
+ $todate = $locale->date( \%myconfig, $form->{startdateto}, 1 );
+ }
+ if ( $fromdate || $todate ) {
+ $option .=
+ "\n<br>" . $locale->text('Startdate') . " $fromdate - $todate";
+ }
+
+ if ( $form->{notes} ) {
+ $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
+ $href .= "&notes=" . $form->escape( $form->{notes} );
+ $option .= "\n<br>" . $locale->text('Notes') . " : $form->{notes}";
+ }
+ if ( $form->{"$form->{db}number"} ) {
+ $callback .=
+ qq|&$form->{db}number=|
+ . $form->escape( $form->{"$form->{db}number"}, 1 );
+ $href .=
+ "&$form->{db}number=" . $form->escape( $form->{"$form->{db}number"} );
+ $option .= "\n<br>"
+ . $locale->text('Number')
+ . qq| : $form->{"$form->{db}number"}|;
+ }
+ if ( $form->{phone} ) {
+ $callback .= "&phone=" . $form->escape( $form->{phone}, 1 );
+ $href .= "&phone=" . $form->escape( $form->{phone} );
+ $option .= "\n<br>" . $locale->text('Phone') . " : $form->{phone}";
+ }
+ if ( $form->{email} ) {
+ $callback .= "&email=" . $form->escape( $form->{email}, 1 );
+ $href .= "&email=" . $form->escape( $form->{email} );
+ $option .= "\n<br>" . $locale->text('E-mail') . " : $form->{email}";
+ }
+ 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}";
+ if ( $form->{transdatefrom} ) {
+ $option .= " ";
+ }
+ else {
+ $option .= "\n<br>" if ($option);
+ }
+ $option .=
+ $locale->text('To') . "&nbsp;"
+ . $locale->date( \%myconfig, $form->{transdateto}, 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');
+ }
+
+ $form->{callback} = "$callback&sort=$form->{sort}";
+ $callback = $form->escape( $form->{callback} );
+
+ $column_header{ndx} = qq|<th class=listheading>&nbsp;</th>|;
+ $column_header{id} =
+ qq|<th class=listheading>| . $locale->text('ID') . qq|</th>|;
+ $column_header{"$form->{db}number"} =
+ qq|<th><a class=listheading href=$href&sort=$form->{db}number>|
+ . $locale->text('Number')
+ . qq|</a></th>|;
+ $column_header{name} =
+ qq|<th><a class=listheading href=$href&sort=name>|
+ . $locale->text('Name')
+ . qq|</a></th>|;
+ $column_header{address} =
+ qq|<th class=listheading>| . $locale->text('Address') . qq|</th>|;
+ $column_header{city} =
+ qq|<th><a class=listheading href=$href&sort=city>|
+ . $locale->text('City')
+ . qq|</a></th>|;
+ $column_header{state} =
+ qq|<th><a class=listheading href=$href&sort=state>|
+ . $locale->text('State/Province')
+ . qq|</a></th>|;
+ $column_header{zipcode} =
+ qq|<th><a class=listheading href=$href&sort=zipcode>|
+ . $locale->text('Zip/Postal Code')
+ . qq|</a></th>|;
+ $column_header{country} =
+ qq|<th><a class=listheading href=$href&sort=country>|
+ . $locale->text('Country')
+ . qq|</a></th>|;
+ $column_header{contact} =
+ qq|<th><a class=listheading href=$href&sort=contact>|
+ . $locale->text('Contact')
+ . qq|</a></th>|;
+ $column_header{phone} =
+ qq|<th><a class=listheading href=$href&sort=phone>|
+ . $locale->text('Phone')
+ . qq|</a></th>|;
+ $column_header{fax} =
+ qq|<th><a class=listheading href=$href&sort=fax>|
+ . $locale->text('Fax')
+ . qq|</a></th>|;
+ $column_header{email} =
+ qq|<th><a class=listheading href=$href&sort=email>|
+ . $locale->text('E-mail')
+ . qq|</a></th>|;
+ $column_header{cc} =
+ qq|<th><a class=listheading href=$href&sort=cc>|
+ . $locale->text('Cc')
+ . qq|</a></th>|;
+ $column_header{bcc} =
+ qq|<th><a class=listheading href=$href&sort=cc>|
+ . $locale->text('Bcc')
+ . qq|</a></th>|;
+ $column_header{notes} =
+ qq|<th><a class=listheading href=$href&sort=notes>|
+ . $locale->text('Notes')
+ . qq|</a></th>|;
+ $column_header{discount} = qq|<th class=listheading>%</th>|;
+ $column_header{terms} =
+ qq|<th class=listheading>| . $locale->text('Terms') . qq|</th>|;
+
+ $column_header{taxnumber} =
+ qq|<th><a class=listheading href=$href&sort=taxnumber>|
+ . $locale->text('Tax Number')
+ . qq|</a></th>|;
+ $column_header{taxaccount} =
+ qq|<th class=listheading>| . $locale->text('Tax Account') . qq|</th>|;
+ $column_header{gifi_accno} =
+ qq|<th><a class=listheading href=$href&sort=gifi_accno>|
+ . $locale->text('GIFI')
+ . qq|</a></th>|;
+ $column_header{sic_code} =
+ qq|<th><a class=listheading href=$href&sort=sic_code>|
+ . $locale->text('SIC')
+ . qq|</a></th>|;
+ $column_header{business} =
+ qq|<th><a class=listheading href=$href&sort=business>|
+ . $locale->text('Type of Business')
+ . qq|</a></th>|;
+ $column_header{iban} =
+ qq|<th class=listheading>| . $locale->text('IBAN') . qq|</th>|;
+ $column_header{bic} =
+ qq|<th class=listheading>| . $locale->text('BIC') . qq|</th>|;
+ $column_header{startdate} =
+ qq|<th><a class=listheading href=$href&sort=startdate>|
+ . $locale->text('Startdate')
+ . qq|</a></th>|;
+ $column_header{enddate} =
+ qq|<th><a class=listheading href=$href&sort=enddate>|
+ . $locale->text('Enddate')
+ . qq|</a></th>|;
+
+ $column_header{invnumber} =
+ qq|<th><a class=listheading href=$href&sort=invnumber>|
+ . $locale->text('Invoice')
+ . qq|</a></th>|;
+ $column_header{ordnumber} =
+ qq|<th><a class=listheading href=$href&sort=ordnumber>|
+ . $locale->text('Order')
+ . qq|</a></th>|;
+ $column_header{quonumber} =
+ qq|<th><a class=listheading href=$href&sort=quonumber>|
+ . $locale->text('Quotation')
+ . qq|</a></th>|;
+
+ if ( $form->{db} eq 'customer' ) {
+ $column_header{employee} =
+ qq|<th><a class=listheading href=$href&sort=employee>|
+ . $locale->text('Salesperson')
+ . qq|</a></th>|;
+ }
+ else {
+ $column_header{employee} =
+ qq|<th><a class=listheading href=$href&sort=employee>|
+ . $locale->text('Employee')
+ . qq|</a></th>|;
+ }
+ $column_header{manager} =
+ qq|<th><a class=listheading href=$href&sort=manager>|
+ . $locale->text('Manager')
+ . qq|</a></th>|;
+
+ $column_header{pricegroup} =
+ qq|<th><a class=listheading href=$href&sort=pricegroup>|
+ . $locale->text('Pricegroup')
+ . qq|</a></th>|;
+ $column_header{language} =
+ qq|<th><a class=listheading href=$href&sort=language>|
+ . $locale->text('Language')
+ . qq|</a></th>|;
+
+ $amount = $locale->text('Amount');
+ $tax = $locale->text('Tax');
+ $total = $locale->text('Total');
+
+ $column_header{invamount} = qq|<th class=listheading>$amount</th>|;
+ $column_header{ordamount} = qq|<th class=listheading>$amount</th>|;
+ $column_header{quoamount} = qq|<th class=listheading>$amount</th>|;
+
+ $column_header{invtax} = qq|<th class=listheading>$tax</th>|;
+ $column_header{ordtax} = qq|<th class=listheading>$tax</th>|;
+ $column_header{quotax} = qq|<th class=listheading>$tax</th>|;
+
+ $column_header{invtotal} = qq|<th class=listheading>$total</th>|;
+ $column_header{ordtotal} = qq|<th class=listheading>$total</th>|;
+ $column_header{quototal} = qq|<th class=listheading>$total</th>|;
+
+ if ( $form->{status} ) {
+ $label = ucfirst $form->{db} . "s";
+ $form->{title} = $locale->text($label);
+ }
+ else {
+ $label = ucfirst $form->{db};
+ $form->{title} = $locale->text( $label . " Transactions" );
+ }
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -785,155 +961,214 @@ sub list_names {
<tr class=listheading>
|;
- for (@column_index) { print "$column_header{$_}\n" }
+ for (@column_index) { print "$column_header{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
- $ordertype = ($form->{db} eq 'customer') ? 'sales_order' : 'purchase_order';
- $quotationtype = ($form->{db} eq 'customer') ? 'sales_quotation' : 'request_quotation';
- $subtotal = 0;
-
- $i = 0;
- foreach $ref (@{ $form->{CT} }) {
-
- if ($ref->{$form->{sort}} ne $sameitem && $form->{l_subtotal}) {
- # print subtotal
- if ($subtotal) {
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
- &list_subtotal;
- }
- }
-
- if ($ref->{id} eq $sameid) {
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
- } else {
-
- $i++;
-
- $ref->{notes} =~ s/\r?\n/<br>/g;
- for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
-
- $column_data{ndx} = "<td align=right>$i</td>";
-
- if ($ref->{$form->{sort}} eq $sameitem) {
- $column_data{$form->{sort}} = "<td>&nbsp;</td>";
- }
-
- $column_data{address} = "<td>$ref->{address1} $ref->{address2}&nbsp;</td>";
- $column_data{name} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&callback=$callback>$ref->{name}&nbsp;</td>";
-
- $email = "";
- if ($form->{sort} =~ /(email|cc)/) {
- if ($ref->{$form->{sort}} ne $sameitem) {
- $email = 1;
- }
- } else {
- $email = 1;
- }
-
- if ($email) {
- foreach $item (qw(email cc bcc)) {
- if ($ref->{$item}) {
- $email = $ref->{$item};
- $email =~ s/</\&lt;/;
- $email =~ s/>/\&gt;/;
-
- $column_data{$item} = qq|<td><a href="mailto:$ref->{$item}">$email</a></td>|;
- }
- }
- }
- }
-
- if ($ref->{formtype} eq 'invoice') {
- $column_data{invnumber} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}&nbsp;</td>";
-
- $column_data{invamount} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{netamount}, 2, "&nbsp;")."</td>";
- $column_data{invtax} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} - $ref->{netamount}, 2, "&nbsp;")."</td>";
- $column_data{invtotal} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")."</td>";
-
- $invamountsubtotal += $ref->{netamount};
- $invtaxsubtotal += ($ref->{amount} - $ref->{netamount});
- $invtotalsubtotal += $ref->{amount};
- $subtotal = 1;
- }
-
- if ($ref->{formtype} eq 'order') {
- $column_data{ordnumber} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{ordnumber}&nbsp;</td>";
-
- $column_data{ordamount} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{netamount}, 2, "&nbsp;")."</td>";
- $column_data{ordtax} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} - $ref->{netamount}, 2, "&nbsp;")."</td>";
- $column_data{ordtotal} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")."</td>";
-
- $ordamountsubtotal += $ref->{netamount};
- $ordtaxsubtotal += ($ref->{amount} - $ref->{netamount});
- $ordtotalsubtotal += $ref->{amount};
- $subtotal = 1;
- }
-
- if ($ref->{formtype} eq 'quotation') {
- $column_data{quonumber} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{quonumber}&nbsp;</td>";
-
- $column_data{quoamount} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{netamount}, 2, "&nbsp;")."</td>";
- $column_data{quotax} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} - $ref->{netamount}, 2, "&nbsp;")."</td>";
- $column_data{quototal} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")."</td>";
-
- $quoamountsubtotal += $ref->{netamount};
- $quotaxsubtotal += ($ref->{amount} - $ref->{netamount});
- $quototalsubtotal += $ref->{amount};
- $subtotal = 1;
- }
-
- if ($sameid ne "$ref->{id}") {
- if ($form->{l_discount}) {
- $column_data{discount} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{discount} * 100, "", "&nbsp;")."</td>";
- }
- if ($form->{l_terms}) {
- $column_data{terms} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{terms}, "", "&nbsp;")."</td>";
- }
- }
-
- $j++; $j %= 2;
- print "
+ $ordertype =
+ ( $form->{db} eq 'customer' ) ? 'sales_order' : 'purchase_order';
+ $quotationtype =
+ ( $form->{db} eq 'customer' ) ? 'sales_quotation' : 'request_quotation';
+ $subtotal = 0;
+
+ $i = 0;
+ foreach $ref ( @{ $form->{CT} } ) {
+
+ if ( $ref->{ $form->{sort} } ne $sameitem && $form->{l_subtotal} ) {
+
+ # print subtotal
+ if ($subtotal) {
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+ &list_subtotal;
+ }
+ }
+
+ if ( $ref->{id} eq $sameid ) {
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+ }
+ else {
+
+ $i++;
+
+ $ref->{notes} =~ s/\r?\n/<br>/g;
+ for (@column_index) {
+ $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
+ }
+
+ $column_data{ndx} = "<td align=right>$i</td>";
+
+ if ( $ref->{ $form->{sort} } eq $sameitem ) {
+ $column_data{ $form->{sort} } = "<td>&nbsp;</td>";
+ }
+
+ $column_data{address} =
+ "<td>$ref->{address1} $ref->{address2}&nbsp;</td>";
+ $column_data{name} =
+"<td><a href=$form->{script}?action=edit&id=$ref->{id}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&callback=$callback>$ref->{name}&nbsp;</td>";
+
+ $email = "";
+ if ( $form->{sort} =~ /(email|cc)/ ) {
+ if ( $ref->{ $form->{sort} } ne $sameitem ) {
+ $email = 1;
+ }
+ }
+ else {
+ $email = 1;
+ }
+
+ if ($email) {
+ foreach $item (qw(email cc bcc)) {
+ if ( $ref->{$item} ) {
+ $email = $ref->{$item};
+ $email =~ s/</\&lt;/;
+ $email =~ s/>/\&gt;/;
+
+ $column_data{$item} =
+qq|<td><a href="mailto:$ref->{$item}">$email</a></td>|;
+ }
+ }
+ }
+ }
+
+ if ( $ref->{formtype} eq 'invoice' ) {
+ $column_data{invnumber} =
+"<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}&nbsp;</td>";
+
+ $column_data{invamount} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{netamount}, 2,
+ "&nbsp;" )
+ . "</td>";
+ $column_data{invtax} = "<td align=right>"
+ . $form->format_amount( \%myconfig,
+ $ref->{amount} - $ref->{netamount},
+ 2, "&nbsp;" )
+ . "</td>";
+ $column_data{invtotal} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{amount}, 2, "&nbsp;" )
+ . "</td>";
+
+ $invamountsubtotal += $ref->{netamount};
+ $invtaxsubtotal += ( $ref->{amount} - $ref->{netamount} );
+ $invtotalsubtotal += $ref->{amount};
+ $subtotal = 1;
+ }
+
+ if ( $ref->{formtype} eq 'order' ) {
+ $column_data{ordnumber} =
+"<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{ordnumber}&nbsp;</td>";
+
+ $column_data{ordamount} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{netamount}, 2,
+ "&nbsp;" )
+ . "</td>";
+ $column_data{ordtax} = "<td align=right>"
+ . $form->format_amount( \%myconfig,
+ $ref->{amount} - $ref->{netamount},
+ 2, "&nbsp;" )
+ . "</td>";
+ $column_data{ordtotal} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{amount}, 2, "&nbsp;" )
+ . "</td>";
+
+ $ordamountsubtotal += $ref->{netamount};
+ $ordtaxsubtotal += ( $ref->{amount} - $ref->{netamount} );
+ $ordtotalsubtotal += $ref->{amount};
+ $subtotal = 1;
+ }
+
+ if ( $ref->{formtype} eq 'quotation' ) {
+ $column_data{quonumber} =
+"<td><a href=$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{quonumber}&nbsp;</td>";
+
+ $column_data{quoamount} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{netamount}, 2,
+ "&nbsp;" )
+ . "</td>";
+ $column_data{quotax} = "<td align=right>"
+ . $form->format_amount( \%myconfig,
+ $ref->{amount} - $ref->{netamount},
+ 2, "&nbsp;" )
+ . "</td>";
+ $column_data{quototal} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{amount}, 2, "&nbsp;" )
+ . "</td>";
+
+ $quoamountsubtotal += $ref->{netamount};
+ $quotaxsubtotal += ( $ref->{amount} - $ref->{netamount} );
+ $quototalsubtotal += $ref->{amount};
+ $subtotal = 1;
+ }
+
+ if ( $sameid ne "$ref->{id}" ) {
+ if ( $form->{l_discount} ) {
+ $column_data{discount} = "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{discount} * 100,
+ "", "&nbsp;" )
+ . "</td>";
+ }
+ if ( $form->{l_terms} ) {
+ $column_data{terms} = "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{terms}, "",
+ "&nbsp;" )
+ . "</td>";
+ }
+ }
+
+ $j++;
+ $j %= 2;
+ print "
<tr class=listrow$j>
";
- for (@column_index) { print "$column_data{$_}\n" }
+ for (@column_index) { print "$column_data{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
-
- $sameitem = "$ref->{$form->{sort}}";
- $sameid = $ref->{id};
-
- }
-
- if ($form->{l_subtotal} && $subtotal) {
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
- &list_subtotal;
- }
-
- $i = 1;
- if ($myconfig{acs} !~ /AR--AR/) {
- if ($form->{db} eq 'customer') {
- $button{'AR--Customers--Add Customer'}{code} = qq|<button class="submit" type="submit" name="action" value="add_customer">|.$locale->text('Add Customer').qq|</button> |;
- $button{'AR--Customers--Add Customer'}{order} = $i++;
- }
- }
- if ($myconfig{acs} !~ /AP--AP/) {
- if ($form->{db} eq 'vendor') {
- $button{'AP--Vendors--Add Vendor'}{code} = qq|<button class="submit" type="submit" name="action" value="add_vendor">|.$locale->text('Add Vendor').qq|</button> |;
- $button{'AP--Vendors--Add Vendor'}{order} = $i++;
- }
- }
-
- foreach $item (split /;/, $myconfig{acs}) {
- delete $button{$item};
- }
-
- print qq|
+
+ $sameitem = "$ref->{$form->{sort}}";
+ $sameid = $ref->{id};
+
+ }
+
+ if ( $form->{l_subtotal} && $subtotal ) {
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+ &list_subtotal;
+ }
+
+ $i = 1;
+ if ( $myconfig{acs} !~ /AR--AR/ ) {
+ if ( $form->{db} eq 'customer' ) {
+ $button{'AR--Customers--Add Customer'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add_customer">|
+ . $locale->text('Add Customer')
+ . qq|</button> |;
+ $button{'AR--Customers--Add Customer'}{order} = $i++;
+ }
+ }
+ if ( $myconfig{acs} !~ /AP--AP/ ) {
+ if ( $form->{db} eq 'vendor' ) {
+ $button{'AP--Vendors--Add Vendor'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add_vendor">|
+ . $locale->text('Add Vendor')
+ . qq|</button> |;
+ $button{'AP--Vendors--Add Vendor'}{order} = $i++;
+ }
+ }
+
+ foreach $item ( split /;/, $myconfig{acs} ) {
+ delete $button{$item};
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -946,184 +1181,245 @@ sub list_names {
<form method=post action=$form->{script}>
|;
- $form->hide_form(qw(callback db path login sessionid));
-
- if ($form->{status}) {
- foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
- print $item->{code};
+ $form->hide_form(qw(callback db path login sessionid));
+
+ if ( $form->{status} ) {
+ foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
+ print $item->{code};
+ }
}
- }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
</html>
|;
-
-}
+}
sub list_subtotal {
- $column_data{invamount} = "<td align=right>".$form->format_amount(\%myconfig, $invamountsubtotal, 2, "&nbsp;")."</td>";
- $column_data{invtax} = "<td align=right>".$form->format_amount(\%myconfig, $invtaxsubtotal, 2, "&nbsp;")."</td>";
- $column_data{invtotal} = "<td align=right>".$form->format_amount(\%myconfig, $invtotalsubtotal, 2, "&nbsp;")."</td>";
-
- $invamountsubtotal = 0;
- $invtaxsubtotal = 0;
- $invtotalsubtotal = 0;
+ $column_data{invamount} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $invamountsubtotal, 2, "&nbsp;" )
+ . "</td>";
+ $column_data{invtax} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $invtaxsubtotal, 2, "&nbsp;" )
+ . "</td>";
+ $column_data{invtotal} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $invtotalsubtotal, 2, "&nbsp;" )
+ . "</td>";
+
+ $invamountsubtotal = 0;
+ $invtaxsubtotal = 0;
+ $invtotalsubtotal = 0;
+
+ $column_data{ordamount} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ordamountsubtotal, 2, "&nbsp;" )
+ . "</td>";
+ $column_data{ordtax} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ordtaxsubtotal, 2, "&nbsp;" )
+ . "</td>";
+ $column_data{ordtotal} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ordtotalsubtotal, 2, "&nbsp;" )
+ . "</td>";
+
+ $ordamountsubtotal = 0;
+ $ordtaxsubtotal = 0;
+ $ordtotalsubtotal = 0;
+
+ $column_data{quoamount} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $quoamountsubtotal, 2, "&nbsp;" )
+ . "</td>";
+ $column_data{quotax} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $quotaxsubtotal, 2, "&nbsp;" )
+ . "</td>";
+ $column_data{quototal} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $quototalsubtotal, 2, "&nbsp;" )
+ . "</td>";
+
+ $quoamountsubtotal = 0;
+ $quotaxsubtotal = 0;
+ $quototalsubtotal = 0;
- $column_data{ordamount} = "<td align=right>".$form->format_amount(\%myconfig, $ordamountsubtotal, 2, "&nbsp;")."</td>";
- $column_data{ordtax} = "<td align=right>".$form->format_amount(\%myconfig, $ordtaxsubtotal, 2, "&nbsp;")."</td>";
- $column_data{ordtotal} = "<td align=right>".$form->format_amount(\%myconfig, $ordtotalsubtotal, 2, "&nbsp;")."</td>";
-
- $ordamountsubtotal = 0;
- $ordtaxsubtotal = 0;
- $ordtotalsubtotal = 0;
-
- $column_data{quoamount} = "<td align=right>".$form->format_amount(\%myconfig, $quoamountsubtotal, 2, "&nbsp;")."</td>";
- $column_data{quotax} = "<td align=right>".$form->format_amount(\%myconfig, $quotaxsubtotal, 2, "&nbsp;")."</td>";
- $column_data{quototal} = "<td align=right>".$form->format_amount(\%myconfig, $quototalsubtotal, 2, "&nbsp;")."</td>";
-
- $quoamountsubtotal = 0;
- $quotaxsubtotal = 0;
- $quototalsubtotal = 0;
-
- print "
+ print "
<tr class=listsubtotal>
";
- for (@column_index) { print "$column_data{$_}\n" }
+ for (@column_index) { print "$column_data{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
-
}
-
sub list_history {
-
- CT->get_history(\%myconfig, \%$form);
-
- $href = "$form->{script}?action=list_history&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&history=$form->{history}";
-
- $form->sort_order();
-
- $callback = "$form->{script}?action=list_history&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&history=$form->{history}";
-
- $form->{l_fxsellprice} = $form->{l_curr};
- @columns = $form->sort_columns(partnumber, description, qty, unit, sellprice, fxsellprice, curr, discount, deliverydate, projectnumber, serialnumber);
-
- if ($form->{history} eq 'summary') {
- @columns = $form->sort_columns(partnumber, description, qty, unit, sellprice, curr);
- }
-
- 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->{history} eq 'detail') {
- $option = $locale->text('Detail');
- }
- if ($form->{history} eq 'summary') {
- $option .= $locale->text('Summary');
- }
- if ($form->{name}) {
- $callback .= "&name=".$form->escape($form->{name},1);
- $href .= "&name=".$form->escape($form->{name});
- $option .= "\n<br>".$locale->text('Name')." : $form->{name}";
- }
- if ($form->{contact}) {
- $callback .= "&contact=".$form->escape($form->{contact},1);
- $href .= "&contact=".$form->escape($form->{contact});
- $option .= "\n<br>".$locale->text('Contact')." : $form->{contact}";
- }
- if ($form->{"$form->{db}number"}) {
- $callback .= qq|&$form->{db}number=|.$form->escape($form->{"$form->{db}number"},1);
- $href .= "&$form->{db}number=".$form->escape($form->{"$form->{db}number"});
- $option .= "\n<br>".$locale->text('Number').qq| : $form->{"$form->{db}number"}|;
- }
- if ($form->{email}) {
- $callback .= "&email=".$form->escape($form->{email},1);
- $href .= "&email=".$form->escape($form->{email});
- $option .= "\n<br>".$locale->text('E-mail')." : $form->{email}";
- }
- 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}";
- if ($form->{transdatefrom}) {
- $option .= " ";
- } else {
- $option .= "\n<br>" if ($option);
- }
- $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 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');
- }
-
-
- $form->{callback} = "$callback&sort=$form->{sort}";
- $callback = $form->escape($form->{callback});
-
- $column_header{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Part Number').qq|</a></th>|;
- $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
-
- if ($form->{history} eq 'summary') {
- $column_header{sellprice} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;
- } else {
- $column_header{sellprice} = qq|<th class=listheading>|.$locale->text('Sell Price').qq|</th>|;
- }
- $column_header{fxsellprice} = qq|<th>&nbsp;</th>|;
-
- $column_header{curr} = qq|<th class=listheading>|.$locale->text('Curr').qq|</th>|;
- $column_header{discount} = qq|<th class=listheading>|.$locale->text('Discount').qq|</th>|;
- $column_header{qty} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
- $column_header{unit} = qq|<th class=listheading>|.$locale->text('Unit').qq|</th>|;
- $column_header{deliverydate} = qq|<th><a class=listheading href=$href&sort=deliverydate>|.$locale->text('Delivery Date').qq|</a></th>|;
- $column_header{projectnumber} = qq|<th><a class=listheading href=$href&sort=projectnumber>|.$locale->text('Project Number').qq|</a></th>|;
- $column_header{serialnumber} = qq|<th><a class=listheading href=$href&sort=serialnumber>|.$locale->text('Serial Number').qq|</a></th>|;
-
-
-# $locale->text('Customer History')
-# $locale->text('Vendor History')
-
- $label = ucfirst $form->{db};
- $form->{title} = $locale->text($label." History");
-
- $colspan = $#column_index + 1;
-
- $form->header;
-
- print qq|
+
+ CT->get_history( \%myconfig, \%$form );
+
+ $href =
+"$form->{script}?action=list_history&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&history=$form->{history}";
+
+ $form->sort_order();
+
+ $callback =
+"$form->{script}?action=list_history&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&history=$form->{history}";
+
+ $form->{l_fxsellprice} = $form->{l_curr};
+ @columns = $form->sort_columns( partnumber, description, qty, unit,
+ sellprice, fxsellprice, curr, discount,
+ deliverydate, projectnumber, serialnumber
+ );
+
+ if ( $form->{history} eq 'summary' ) {
+ @columns =
+ $form->sort_columns( partnumber, description, qty, unit, sellprice,
+ curr );
+ }
+
+ 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->{history} eq 'detail' ) {
+ $option = $locale->text('Detail');
+ }
+ if ( $form->{history} eq 'summary' ) {
+ $option .= $locale->text('Summary');
+ }
+ if ( $form->{name} ) {
+ $callback .= "&name=" . $form->escape( $form->{name}, 1 );
+ $href .= "&name=" . $form->escape( $form->{name} );
+ $option .= "\n<br>" . $locale->text('Name') . " : $form->{name}";
+ }
+ if ( $form->{contact} ) {
+ $callback .= "&contact=" . $form->escape( $form->{contact}, 1 );
+ $href .= "&contact=" . $form->escape( $form->{contact} );
+ $option .= "\n<br>" . $locale->text('Contact') . " : $form->{contact}";
+ }
+ if ( $form->{"$form->{db}number"} ) {
+ $callback .=
+ qq|&$form->{db}number=|
+ . $form->escape( $form->{"$form->{db}number"}, 1 );
+ $href .=
+ "&$form->{db}number=" . $form->escape( $form->{"$form->{db}number"} );
+ $option .= "\n<br>"
+ . $locale->text('Number')
+ . qq| : $form->{"$form->{db}number"}|;
+ }
+ if ( $form->{email} ) {
+ $callback .= "&email=" . $form->escape( $form->{email}, 1 );
+ $href .= "&email=" . $form->escape( $form->{email} );
+ $option .= "\n<br>" . $locale->text('E-mail') . " : $form->{email}";
+ }
+ 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}";
+ if ( $form->{transdatefrom} ) {
+ $option .= " ";
+ }
+ else {
+ $option .= "\n<br>" if ($option);
+ }
+ $option .=
+ $locale->text('To') . "&nbsp;"
+ . $locale->date( \%myconfig, $form->{transdateto}, 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');
+ }
+
+ $form->{callback} = "$callback&sort=$form->{sort}";
+ $callback = $form->escape( $form->{callback} );
+
+ $column_header{partnumber} =
+ qq|<th><a class=listheading href=$href&sort=partnumber>|
+ . $locale->text('Part Number')
+ . qq|</a></th>|;
+ $column_header{description} =
+ qq|<th><a class=listheading href=$href&sort=description>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
+
+ if ( $form->{history} eq 'summary' ) {
+ $column_header{sellprice} =
+ qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
+ }
+ else {
+ $column_header{sellprice} =
+ qq|<th class=listheading>| . $locale->text('Sell Price') . qq|</th>|;
+ }
+ $column_header{fxsellprice} = qq|<th>&nbsp;</th>|;
+
+ $column_header{curr} =
+ qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
+ $column_header{discount} =
+ qq|<th class=listheading>| . $locale->text('Discount') . qq|</th>|;
+ $column_header{qty} =
+ qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
+ $column_header{unit} =
+ qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
+ $column_header{deliverydate} =
+ qq|<th><a class=listheading href=$href&sort=deliverydate>|
+ . $locale->text('Delivery Date')
+ . qq|</a></th>|;
+ $column_header{projectnumber} =
+ qq|<th><a class=listheading href=$href&sort=projectnumber>|
+ . $locale->text('Project Number')
+ . qq|</a></th>|;
+ $column_header{serialnumber} =
+ qq|<th><a class=listheading href=$href&sort=serialnumber>|
+ . $locale->text('Serial Number')
+ . qq|</a></th>|;
+
+ # $locale->text('Customer History')
+ # $locale->text('Vendor History')
+
+ $label = ucfirst $form->{db};
+ $form->{title} = $locale->text( $label . " History" );
+
+ $colspan = $#column_index + 1;
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -1140,109 +1436,125 @@ sub list_history {
<tr class=listheading>
|;
- for (@column_index) { print "$column_header{$_}\n" }
+ for (@column_index) { print "$column_header{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
+ $module = 'oe';
+ if ( $form->{db} eq 'customer' ) {
+ $invlabel = $locale->text('Sales Invoice');
+ $ordlabel = $locale->text('Sales Order');
+ $quolabel = $locale->text('Quotation');
+
+ $ordertype = 'sales_order';
+ $quotationtype = 'sales_quotation';
+ if ( $form->{type} eq 'invoice' ) {
+ $module = 'is';
+ }
+ }
+ else {
+ $invlabel = $locale->text('Vendor Invoice');
+ $ordlabel = $locale->text('Purchase Order');
+ $quolabel = $locale->text('RFQ');
+
+ $ordertype = 'purchase_order';
+ $quotationtype = 'request_quotation';
+ if ( $form->{type} eq 'invoice' ) {
+ $module = 'ir';
+ }
+ }
+
+ $ml = ( $form->{db} eq 'vendor' ) ? -1 : 1;
- $module = 'oe';
- if ($form->{db} eq 'customer') {
- $invlabel = $locale->text('Sales Invoice');
- $ordlabel = $locale->text('Sales Order');
- $quolabel = $locale->text('Quotation');
-
- $ordertype = 'sales_order';
- $quotationtype = 'sales_quotation';
- if ($form->{type} eq 'invoice') {
- $module = 'is';
- }
- } else {
- $invlabel = $locale->text('Vendor Invoice');
- $ordlabel = $locale->text('Purchase Order');
- $quolabel = $locale->text('RFQ');
-
- $ordertype = 'purchase_order';
- $quotationtype = 'request_quotation';
- if ($form->{type} eq 'invoice') {
- $module = 'ir';
- }
- }
-
- $ml = ($form->{db} eq 'vendor') ? -1 : 1;
-
- foreach $ref (@{ $form->{CT} }) {
-
- if ($ref->{id} ne $sameid) {
- # print the header
- print qq|
+ foreach $ref ( @{ $form->{CT} } ) {
+
+ if ( $ref->{id} ne $sameid ) {
+
+ # print the header
+ print qq|
<tr class=listheading>
<th colspan=$colspan><a class=listheading href=$form->{script}?action=edit&id=$ref->{ctid}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{name} $ref->{address}</a></th>
</tr>
|;
- }
+ }
- if ($form->{type} ne 'invoice') {
- $ref->{fxsellprice} = $ref->{sellprice};
- $ref->{sellprice} *= $ref->{exchangerate};
- }
-
- if ($form->{history} eq 'detail' and $ref->{invid} ne $sameinvid) {
- # print inv, ord, quo number
- $i++; $i %= 2;
-
- print qq|
+ if ( $form->{type} ne 'invoice' ) {
+ $ref->{fxsellprice} = $ref->{sellprice};
+ $ref->{sellprice} *= $ref->{exchangerate};
+ }
+
+ if ( $form->{history} eq 'detail' and $ref->{invid} ne $sameinvid ) {
+
+ # print inv, ord, quo number
+ $i++;
+ $i %= 2;
+
+ print qq|
<tr class=listrow$i>
|;
- if ($form->{type} eq 'invoice') {
- print qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$invlabel $ref->{invnumber} / $ref->{employee}</a></th>|;
- }
-
- if ($form->{type} eq 'order') {
- print qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ordlabel $ref->{ordnumber} / $ref->{employee}</a></th>|;
- }
+ if ( $form->{type} eq 'invoice' ) {
+ print
+qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$invlabel $ref->{invnumber} / $ref->{employee}</a></th>|;
+ }
+
+ if ( $form->{type} eq 'order' ) {
+ print
+qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ordlabel $ref->{ordnumber} / $ref->{employee}</a></th>|;
+ }
- if ($form->{type} eq 'quotation') {
- print qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$quolabel $ref->{quonumber} / $ref->{employee}</a></th>|;
- }
+ if ( $form->{type} eq 'quotation' ) {
+ print
+qq|<th align=left colspan=$colspan><a href=${module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$quolabel $ref->{quonumber} / $ref->{employee}</a></th>|;
+ }
- print qq|
+ print qq|
</tr>
|;
- }
-
- for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
-
- if ($form->{l_curr}) {
- $column_data{fxsellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{fxsellprice}, 2)."</td>";
- }
- $column_data{sellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{sellprice}, 2)."</td>";
-
- $column_data{qty} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{qty} * $ml)."</td>";
- $column_data{discount} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{discount} * 100, "", "&nbsp;")."</td>";
- $column_data{partnumber} = qq|<td><a href=ic.pl?action=edit&id=$ref->{pid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}</td>|;
-
-
- $i++; $i %= 2;
- print qq|
+ }
+
+ for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
+
+ if ( $form->{l_curr} ) {
+ $column_data{fxsellprice} =
+ qq|<td align=right>|
+ . $form->format_amount( \%myconfig, $ref->{fxsellprice}, 2 )
+ . "</td>";
+ }
+ $column_data{sellprice} =
+ qq|<td align=right>|
+ . $form->format_amount( \%myconfig, $ref->{sellprice}, 2 ) . "</td>";
+
+ $column_data{qty} =
+ qq|<td align=right>|
+ . $form->format_amount( \%myconfig, $ref->{qty} * $ml ) . "</td>";
+ $column_data{discount} = qq|<td align=right>|
+ . $form->format_amount( \%myconfig, $ref->{discount} * 100,
+ "", "&nbsp;" )
+ . "</td>";
+ $column_data{partnumber} =
+qq|<td><a href=ic.pl?action=edit&id=$ref->{pid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}</td>|;
+
+ $i++;
+ $i %= 2;
+ print qq|
<tr class=listrow$i>
|;
- for (@column_index) { print "$column_data{$_}\n" }
+ for (@column_index) { print "$column_data{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
-
- $sameid = $ref->{id};
- $sameinvid = $ref->{invid};
- }
+ $sameid = $ref->{id};
+ $sameinvid = $ref->{invid};
-
- print qq|
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -1253,187 +1565,206 @@ sub list_history {
|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
</html>
|;
-
-}
-
+}
sub edit {
-# $locale->text('Edit Customer')
-# $locale->text('Edit Vendor')
+ # $locale->text('Edit Customer')
+ # $locale->text('Edit Vendor')
- CT->create_links(\%myconfig, \%$form);
+ CT->create_links( \%myconfig, \%$form );
- for (keys %$form) { $form->{$_} = $form->quote($form->{$_}) }
+ for ( keys %$form ) { $form->{$_} = $form->quote( $form->{$_} ) }
- $form->{title} = "Edit";
+ $form->{title} = "Edit";
- # format discount
- $form->{discount} *= 100;
-
- &form_header;
- &form_footer;
+ # format discount
+ $form->{discount} *= 100;
-}
+ &form_header;
+ &form_footer;
+}
sub form_header {
- $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
- $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0);
- $form->{discount} = $form->format_amount(\%myconfig, $form->{discount}, "");
- $form->{terms} = $form->format_amount(\%myconfig, $form->{terms}, "");
-
- if ($myconfig{role} =~ /(admin|manager)/) {
- $bcc = qq|
+ $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
+ $form->{creditlimit} =
+ $form->format_amount( \%myconfig, $form->{creditlimit}, 0 );
+ $form->{discount} =
+ $form->format_amount( \%myconfig, $form->{discount}, "" );
+ $form->{terms} = $form->format_amount( \%myconfig, $form->{terms}, "" );
+
+ if ( $myconfig{role} =~ /(admin|manager)/ ) {
+ $bcc = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Bcc').qq|</th>
+ <th align=right nowrap>| . $locale->text('Bcc') . qq|</th>
<td><input name=bcc size=35 value="$form->{bcc}"></td>
</tr>
|;
- }
-
- if ($form->{currencies}) {
- # currencies
- for (split /:/, $form->{currencies}) { $form->{selectcurrency} .= "<option>$_\n" }
- $form->{selectcurrency} =~ s/option>($form->{curr})/option selected>$1/;
- $currency = qq|
- <th>|.$locale->text('Currency').qq|</th>
+ }
+
+ if ( $form->{currencies} ) {
+
+ # currencies
+ for ( split /:/, $form->{currencies} ) {
+ $form->{selectcurrency} .= "<option>$_\n";
+ }
+ $form->{selectcurrency} =~ s/option>($form->{curr})/option selected>$1/;
+ $currency = qq|
+ <th>| . $locale->text('Currency') . qq|</th>
<td><select name=curr>$form->{selectcurrency}</select></td>
|;
- }
-
- foreach $item (split / /, $form->{taxaccounts}) {
- if ($form->{tax}{$item}{taxable}) {
- $taxable .= qq| <input name="tax_$item" value=1 class=checkbox type=checkbox checked>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
- } else {
- $taxable .= qq| <input name="tax_$item" value=1 class=checkbox type=checkbox>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
}
- }
- if ($taxable) {
- $tax = qq|
+ foreach $item ( split / /, $form->{taxaccounts} ) {
+ if ( $form->{tax}{$item}{taxable} ) {
+ $taxable .=
+qq| <input name="tax_$item" value=1 class=checkbox type=checkbox checked>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
+ }
+ else {
+ $taxable .=
+qq| <input name="tax_$item" value=1 class=checkbox type=checkbox>&nbsp;<b>$form->{tax}{$item}{description}</b>|;
+ }
+ }
+
+ if ($taxable) {
+ $tax = qq|
<tr>
- <th align=right>|.$locale->text('Taxable').qq|</th>
+ <th align=right>| . $locale->text('Taxable') . qq|</th>
<td colspan=5>
<table>
<tr>
<td>$taxable</td>
<td><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
- <th align=left>|.$locale->text('Tax Included').qq|</th>
+ <th align=left>| . $locale->text('Tax Included') . qq|</th>
</tr>
</table>
</td>
</tr>
|;
- }
+ }
- $typeofbusiness = qq|
+ $typeofbusiness = qq|
<th></th>
<td></td>
|;
- if (@{ $form->{all_business} }) {
- $form->{selectbusiness} = qq|<option>\n|;
- for (@{ $form->{all_business} }) { $form->{selectbusiness} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
+ if ( @{ $form->{all_business} } ) {
+ $form->{selectbusiness} = qq|<option>\n|;
+ for ( @{ $form->{all_business} } ) {
+ $form->{selectbusiness} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
- $form->{selectbusiness} =~ s/(<option value="\Q$form->{business}--$form->{business_id}\E")>/$1 selected>/;
+ $form->{selectbusiness} =~
+s/(<option value="\Q$form->{business}--$form->{business_id}\E")>/$1 selected>/;
- $typeofbusiness = qq|
- <th align=right>|.$locale->text('Type of Business').qq|</th>
+ $typeofbusiness = qq|
+ <th align=right>| . $locale->text('Type of Business') . qq|</th>
<td><select name=business>$form->{selectbusiness}</select></td>
|;
+ }
- }
-
- $pricegroup = qq|
+ $pricegroup = qq|
<th></th>
<td></td>
|;
- if (@{ $form->{all_pricegroup} } && $form->{db} eq 'customer') {
- $form->{selectpricegroup} = qq|<option>\n|;
- for (@{ $form->{all_pricegroup} }) { $form->{selectpricegroup} .= qq|<option value="$_->{pricegroup}--$_->{id}">$_->{pricegroup}\n| }
-
- $form->{selectpricegroup} =~ s/(<option value="\Q$form->{pricegroup}--$form->{pricegroup_id}\E")/$1 selected/;
+ if ( @{ $form->{all_pricegroup} } && $form->{db} eq 'customer' ) {
+ $form->{selectpricegroup} = qq|<option>\n|;
+ for ( @{ $form->{all_pricegroup} } ) {
+ $form->{selectpricegroup} .=
+ qq|<option value="$_->{pricegroup}--$_->{id}">$_->{pricegroup}\n|;
+ }
- $pricegroup = qq|
- <th align=right>|.$locale->text('Pricegroup').qq|</th>
+ $form->{selectpricegroup} =~
+s/(<option value="\Q$form->{pricegroup}--$form->{pricegroup_id}\E")/$1 selected/;
+
+ $pricegroup = qq|
+ <th align=right>| . $locale->text('Pricegroup') . qq|</th>
<td><select name=pricegroup>$form->{selectpricegroup}</select></td>
|;
- }
-
- $lang = qq|
+ }
+
+ $lang = qq|
<th></th>
<td></td>
|;
- if (@{ $form->{all_language} }) {
- $form->{selectlanguage} = qq|<option>\n|;
- for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{description}--$_->{code}">$_->{description}\n| }
-
- $form->{selectlanguage} =~ s/(<option value="\Q$form->{language}--$form->{language_code}\E")/$1 selected/;
+ if ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} = qq|<option>\n|;
+ for ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} .=
+qq|<option value="$_->{description}--$_->{code}">$_->{description}\n|;
+ }
- $lang = qq|
- <th align=right>|.$locale->text('Language').qq|</th>
+ $form->{selectlanguage} =~
+s/(<option value="\Q$form->{language}--$form->{language_code}\E")/$1 selected/;
+
+ $lang = qq|
+ <th align=right>| . $locale->text('Language') . qq|</th>
<td><select name=language>$form->{selectlanguage}</select></td>
|;
- }
-
- $employeelabel = $locale->text('Salesperson');
-
- $form->{selectemployee} = qq|<option>\n|;
- for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
-
- $form->{selectemployee} =~ s/(<option value="\Q$form->{employee}--$form->{employee_id}\E")/$1 selected/;
-
- if ($form->{db} eq 'vendor') {
- $gifi = qq|
- <th align=right>|.$locale->text('Sub-contract GIFI').qq|</th>
+ }
+
+ $employeelabel = $locale->text('Salesperson');
+
+ $form->{selectemployee} = qq|<option>\n|;
+ for ( @{ $form->{all_employee} } ) {
+ $form->{selectemployee} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+
+ $form->{selectemployee} =~
+s/(<option value="\Q$form->{employee}--$form->{employee_id}\E")/$1 selected/;
+
+ if ( $form->{db} eq 'vendor' ) {
+ $gifi = qq|
+ <th align=right>| . $locale->text('Sub-contract GIFI') . qq|</th>
<td><input name=gifi_accno size=9 value="$form->{gifi_accno}"></td>
|;
- $employeelabel = $locale->text('Employee');
- }
-
+ $employeelabel = $locale->text('Employee');
+ }
- if (@{ $form->{all_employee} }) {
- $employee = qq|
+ if ( @{ $form->{all_employee} } ) {
+ $employee = qq|
<th align=right>$employeelabel</th>|;
-
- if ($myconfig{role} ne 'user' || !$form->{id}) {
- $employee .= qq|
+
+ if ( $myconfig{role} ne 'user' || !$form->{id} ) {
+ $employee .= qq|
<td><select name=employee>$form->{selectemployee}</select></td>
|;
- } else {
- $employee .= qq|
+ }
+ else {
+ $employee .= qq|
<td>$form->{employee}</td>
<input type=hidden name=employee value="$form->{employee}--$form->{employee_id}">|;
+ }
}
- }
+ # $locale->text('Customer Number')
+ # $locale->text('Vendor Number')
-# $locale->text('Customer Number')
-# $locale->text('Vendor Number')
+ $label = ucfirst $form->{db};
+ $form->{title} = $locale->text("$form->{title} $label");
- $label = ucfirst $form->{db};
- $form->{title} = $locale->text("$form->{title} $label");
-
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -1450,17 +1781,19 @@ sub form_header {
<td width=50%>
<table width=100%>
<tr class=listheading>
- <th class=listheading colspan=2 width=50%>|.$locale->text('Billing Address').qq|</th>
+ <th class=listheading colspan=2 width=50%>|
+ . $locale->text('Billing Address')
+ . qq|</th>
<tr>
- <th align=right nowrap>|.$locale->text($label .' Number').qq|</th>
+ <th align=right nowrap>| . $locale->text( $label . ' Number' ) . qq|</th>
<td><input name="$form->{db}number" size=35 maxlength=32 value="$form->{"$form->{db}number"}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Company Name').qq|</th>
+ <th align=right nowrap>| . $locale->text('Company Name') . qq|</th>
<td><input name=name size=35 maxlength=64 value="$form->{name}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Address').qq|</th>
+ <th align=right nowrap>| . $locale->text('Address') . qq|</th>
<td><input name=address1 size=35 maxlength=32 value="$form->{address1}"></td>
</tr>
<tr>
@@ -1468,39 +1801,39 @@ sub form_header {
<td><input name=address2 size=35 maxlength=32 value="$form->{address2}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('City').qq|</th>
+ <th align=right nowrap>| . $locale->text('City') . qq|</th>
<td><input name=city size=35 maxlength=32 value="$form->{city}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
+ <th align=right nowrap>| . $locale->text('State/Province') . qq|</th>
<td><input name=state size=35 maxlength=32 value="$form->{state}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
+ <th align=right nowrap>| . $locale->text('Zip/Postal Code') . qq|</th>
<td><input name=zipcode size=10 maxlength=10 value="$form->{zipcode}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Country').qq|</th>
+ <th align=right nowrap>| . $locale->text('Country') . qq|</th>
<td><input name=country size=35 maxlength=32 value="$form->{country}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Contact').qq|</th>
+ <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
<td><input name=contact size=35 maxlength=64 value="$form->{contact}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Phone').qq|</th>
+ <th align=right nowrap>| . $locale->text('Phone') . qq|</th>
<td><input name=phone size=20 maxlength=20 value="$form->{phone}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Fax').qq|</th>
+ <th align=right nowrap>| . $locale->text('Fax') . qq|</th>
<td><input name=fax size=20 maxlength=20 value="$form->{fax}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
+ <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
<td><input name=email size=35 value="$form->{email}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Cc').qq|</th>
+ <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
<td><input name=cc size=35 value="$form->{cc}"></td>
</tr>
$bcc
@@ -1509,10 +1842,12 @@ sub form_header {
<td width=50%>
<table width=100%>
<tr>
- <th class=listheading colspan=2>|.$locale->text('Shipping Address').qq|</th>
+ <th class=listheading colspan=2>|
+ . $locale->text('Shipping Address')
+ . qq|</th>
</tr>
<tr>
- <td><input name=none size=35 value=|. ("=" x 35) .qq|></td>
+ <td><input name=none size=35 value=| . ( "=" x 35 ) . qq|></td>
</tr>
<tr>
<td><input name=shiptoname size=35 maxlength=64 value="$form->{shiptoname}"></td>
@@ -1558,32 +1893,34 @@ sub form_header {
<table>
$tax
<tr>
- <th align=right>|.$locale->text('Startdate').qq|</th>
+ <th align=right>| . $locale->text('Startdate') . qq|</th>
<td><input name=startdate size=11 title="$myconfig{dateformat}" value=$form->{startdate}></td>
- <th align=right>|.$locale->text('Enddate').qq|</th>
+ <th align=right>| . $locale->text('Enddate') . qq|</th>
<td><input name=enddate size=11 title="$myconfig{dateformat}" value=$form->{enddate}></td>
</tr>
<tr>
- <th align=right>|.$locale->text('Credit Limit').qq|</th>
+ <th align=right>| . $locale->text('Credit Limit') . qq|</th>
<td><input name=creditlimit size=9 value="$form->{creditlimit}"></td>
- <th align=right>|.$locale->text('Terms').qq|</th>
- <td><input name=terms size=2 value="$form->{terms}"> <b>|.$locale->text('days').qq|</b></td>
- <th align=right>|.$locale->text('Discount').qq|</th>
+ <th align=right>| . $locale->text('Terms') . qq|</th>
+ <td><input name=terms size=2 value="$form->{terms}"> <b>|
+ . $locale->text('days')
+ . qq|</b></td>
+ <th align=right>| . $locale->text('Discount') . qq|</th>
<td><input name=discount size=4 value="$form->{discount}">
<b>%</b></td>
</tr>
<tr>
- <th align=right>|.$locale->text('Tax Number / SSN').qq|</th>
+ <th align=right>| . $locale->text('Tax Number / SSN') . qq|</th>
<td><input name=taxnumber size=20 value="$form->{taxnumber}"></td>
$gifi
- <th align=right>|.$locale->text('SIC').qq|</th>
+ <th align=right>| . $locale->text('SIC') . qq|</th>
<td><input name=sic_code size=6 maxlength=6 value="$form->{sic_code}"></td>
</tr>
<tr>
$typeofbusiness
- <th align=right>|.$locale->text('BIC').qq|</th>
+ <th align=right>| . $locale->text('BIC') . qq|</th>
<td><input name=bic size=11 maxlength=11 value="$form->{bic}"></td>
- <th align=right>|.$locale->text('IBAN').qq|</th>
+ <th align=right>| . $locale->text('IBAN') . qq|</th>
<td><input name=iban size=24 maxlength=34 value="$form->{iban}"></td>
</tr>
<tr>
@@ -1596,7 +1933,7 @@ sub form_header {
<td colspan=4>
<table>
<tr valign=top>
- <th align=left nowrap>|.$locale->text('Notes').qq|</th>
+ <th align=left nowrap>| . $locale->text('Notes') . qq|</th>
<td><textarea name=notes rows=3 cols=40 wrap=soft>$form->{notes}</textarea></td>
</tr>
</table>
@@ -1613,129 +1950,139 @@ sub form_header {
}
+sub form_footer {
+ # type=submit $locale->text('Save')
+ # type=submit $locale->text('Save as new')
+ # type=submit $locale->text('AR Transaction')
+ # type=submit $locale->text('Sales Invoice')
+ # type=submit $locale->text('Sales Order')
+ # type=submit $locale->text('Quotation')
+ # type=submit $locale->text('AP Transaction')
+ # type=submit $locale->text('Vendor Invoice')
+ # type=submit $locale->text('Purchase Order')
+ # type=submit $locale->text('RFQ')
+ # type=submit $locale->text('Pricelist')
+ # type=submit $locale->text('Delete')
+ # type=submit $locale->text('POS')
+
+ %button = (
+ 'save' => { ndx => 1, key => 'S', value => $locale->text('Save') },
+ 'save_as_new' =>
+ { ndx => 2, key => 'N', value => $locale->text('Save as new') },
+ 'ar_transaction' =>
+ { ndx => 7, key => 'A', value => $locale->text('AR Transaction') },
+ 'ap_transaction' =>
+ { ndx => 8, key => 'A', value => $locale->text('AP Transaction') },
+ 'sales_invoice' =>
+ { ndx => 9, key => 'I', value => $locale->text('Sales Invoice') },
+ 'pos' => { ndx => 10, key => 'C', value => $locale->text('POS') },
+ 'sales_order' =>
+ { ndx => 11, key => 'O', value => $locale->text('Sales Order') },
+ 'quotation' =>
+ { ndx => 12, key => 'Q', value => $locale->text('Quotation') },
+ 'vendor_invoice' =>
+ { ndx => 13, key => 'I', value => $locale->text('Vendor Invoice') },
+ 'purchase_order' =>
+ { ndx => 14, key => 'O', value => $locale->text('Purchase Order') },
+ 'rfq' => { ndx => 15, key => 'Q', value => $locale->text('RFQ') },
+ 'pricelist' =>
+ { ndx => 16, key => 'P', value => $locale->text('Pricelist') },
+ 'delete' => { ndx => 17, key => 'D', value => $locale->text('Delete') },
+ );
+
+ %a = ();
+
+ if ( $form->{db} eq 'customer' ) {
+ if ( $myconfig{acs} !~ /AR--Customers--Add Customer/ ) {
+ $a{'save'} = 1;
+
+ if ( $form->{id} ) {
+ $a{'save_as_new'} = 1;
+ if ( $form->{status} eq 'orphaned' ) {
+ $a{'delete'} = 1;
+ }
+ }
+ }
+
+ if ( $myconfig{acs} !~ /AR--AR/ ) {
+ if ( $myconfig{acs} !~ /AR--Add Transaction/ ) {
+ $a{'ar_transaction'} = 1;
+ }
+ if ( $myconfig{acs} !~ /AR--Sales Invoice/ ) {
+ $a{'sales_invoice'} = 1;
+ }
+ }
+ if ( $myconfig{acs} !~ /POS--POS/ ) {
+ if ( $myconfig{acs} !~ /POS--Sale/ ) {
+ $a{'pos'} = 1;
+ }
+ }
+ if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
+ if ( $myconfig{acs} !~ /Order Entry--Sales Order/ ) {
+ $a{'sales_order'} = 1;
+ }
+ }
+ if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
+ if ( $myconfig{acs} !~ /Quotations--Quotation/ ) {
+ $a{'quotation'} = 1;
+ }
+ }
+ }
-sub form_footer {
+ if ( $form->{db} eq 'vendor' ) {
+ if ( $myconfig{acs} !~ /AP--Vendors--Add Vendor/ ) {
+ $a{'save'} = 1;
+
+ if ( $form->{id} ) {
+ $a{'save_as_new'} = 1;
+ if ( $form->{status} eq 'orphaned' ) {
+ $a{'delete'} = 1;
+ }
+ }
+ }
+
+ if ( $myconfig{acs} !~ /AP--AP/ ) {
+ if ( $myconfig{acs} !~ /AP--Add Transaction/ ) {
+ $a{'ap_transaction'} = 1;
+ }
+ if ( $myconfig{acs} !~ /AP--Vendor Invoice/ ) {
+ $a{'vendor_invoice'} = 1;
+ }
+ }
+ if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
+ if ( $myconfig{acs} !~ /Order Entry--Purchase Order/ ) {
+ $a{'purchase_order'} = 1;
+ }
+ }
+ if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
+ if ( $myconfig{acs} !~ /Quotations--RFQ/ ) {
+ $a{'rfq'} = 1;
+ }
+ }
+ }
-# type=submit $locale->text('Save')
-# type=submit $locale->text('Save as new')
-# type=submit $locale->text('AR Transaction')
-# type=submit $locale->text('Sales Invoice')
-# type=submit $locale->text('Sales Order')
-# type=submit $locale->text('Quotation')
-# type=submit $locale->text('AP Transaction')
-# type=submit $locale->text('Vendor Invoice')
-# type=submit $locale->text('Purchase Order')
-# type=submit $locale->text('RFQ')
-# type=submit $locale->text('Pricelist')
-# type=submit $locale->text('Delete')
-# type=submit $locale->text('POS')
-
- %button = ('save' => { ndx => 1, key => 'S', value => $locale->text('Save') },
- 'save_as_new' => { ndx => 2, key => 'N', value => $locale->text('Save as new') },
- 'ar_transaction' => { ndx => 7, key => 'A', value => $locale->text('AR Transaction') },
- 'ap_transaction' => { ndx => 8, key => 'A', value => $locale->text('AP Transaction') },
- 'sales_invoice' => { ndx => 9, key => 'I', value => $locale->text('Sales Invoice') },
- 'pos' => { ndx => 10, key => 'C', value => $locale->text('POS') },
- 'sales_order' => { ndx => 11, key => 'O', value => $locale->text('Sales Order') },
- 'quotation' => { ndx => 12, key => 'Q', value => $locale->text('Quotation') },
- 'vendor_invoice' => { ndx => 13, key => 'I', value => $locale->text('Vendor Invoice') },
- 'purchase_order' => { ndx => 14, key => 'O', value => $locale->text('Purchase Order') },
- 'rfq' => { ndx => 15, key => 'Q', value => $locale->text('RFQ') },
- 'pricelist' => { ndx => 16, key => 'P', value => $locale->text('Pricelist') },
- 'delete' => { ndx => 17, key => 'D', value => $locale->text('Delete') },
- );
-
-
- %a = ();
-
- if ($form->{db} eq 'customer') {
- if ($myconfig{acs} !~ /AR--Customers--Add Customer/) {
- $a{'save'} = 1;
-
- if ($form->{id}) {
- $a{'save_as_new'} = 1;
- if ($form->{status} eq 'orphaned') {
- $a{'delete'} = 1;
- }
- }
- }
-
- if ($myconfig{acs} !~ /AR--AR/) {
- if ($myconfig{acs} !~ /AR--Add Transaction/) {
- $a{'ar_transaction'} = 1;
- }
- if ($myconfig{acs} !~ /AR--Sales Invoice/) {
- $a{'sales_invoice'} = 1;
- }
- }
- if ($myconfig{acs} !~ /POS--POS/) {
- if ($myconfig{acs} !~ /POS--Sale/) {
- $a{'pos'} = 1;
- }
- }
- if ($myconfig{acs} !~ /Order Entry--Order Entry/) {
- if ($myconfig{acs} !~ /Order Entry--Sales Order/) {
- $a{'sales_order'} = 1;
- }
- }
- if ($myconfig{acs} !~ /Quotations--Quotations/) {
- if ($myconfig{acs} !~ /Quotations--Quotation/) {
- $a{'quotation'} = 1;
- }
- }
- }
-
- if ($form->{db} eq 'vendor') {
- if ($myconfig{acs} !~ /AP--Vendors--Add Vendor/) {
- $a{'save'} = 1;
-
- if ($form->{id}) {
- $a{'save_as_new'} = 1;
- if ($form->{status} eq 'orphaned') {
- $a{'delete'} = 1;
- }
- }
+ if ( $myconfig{acs} !~ /Goods & Services--Goods & Services/ ) {
+ $myconfig{acs} =~
+ s/(Goods & Services--)Add (Service|Assembly).*;/$1--Add Part/g;
+ if ( $myconfig{acs} !~ /Goods & Services--Add Part/ ) {
+ $a{'pricelist'} = 1;
+ }
}
-
- if ($myconfig{acs} !~ /AP--AP/) {
- if ($myconfig{acs} !~ /AP--Add Transaction/) {
- $a{'ap_transaction'} = 1;
- }
- if ($myconfig{acs} !~ /AP--Vendor Invoice/) {
- $a{'vendor_invoice'} = 1;
- }
- }
- if ($myconfig{acs} !~ /Order Entry--Order Entry/) {
- if ($myconfig{acs} !~ /Order Entry--Purchase Order/) {
- $a{'purchase_order'} = 1;
- }
- }
- if ($myconfig{acs} !~ /Quotations--Quotations/) {
- if ($myconfig{acs} !~ /Quotations--RFQ/) {
- $a{'rfq'} = 1;
- }
- }
- }
-
- if ($myconfig{acs} !~ /Goods & Services--Goods & Services/) {
- $myconfig{acs} =~ s/(Goods & Services--)Add (Service|Assembly).*;/$1--Add Part/g;
- if ($myconfig{acs} !~ /Goods & Services--Add Part/) {
- $a{'pricelist'} = 1;
- }
- }
-
- $form->hide_form(qw(id taxaccounts path login sessionid callback db));
-
- 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;
- }
-
- print qq|
+
+ $form->hide_form(qw(id taxaccounts path login sessionid callback db));
+
+ 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;
+ }
+
+ print qq|
</form>
@@ -1745,183 +2092,197 @@ sub form_footer {
}
-
sub pricelist {
- $form->isblank("name", $locale->text('Name missing!'));
+ $form->isblank( "name", $locale->text('Name missing!') );
- $form->{display_form} ||= "display_pricelist";
+ $form->{display_form} ||= "display_pricelist";
- CT->pricelist(\%myconfig, \%$form);
+ CT->pricelist( \%myconfig, \%$form );
- foreach $ref (@{ $form->{"all_partspricelist"} }) {
- $i++;
- for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
- }
- $form->{rowcount} = $i;
+ foreach $ref ( @{ $form->{"all_partspricelist"} } ) {
+ $i++;
+ for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
+ }
+ $form->{rowcount} = $i;
+
+ # currencies
+ @curr = split /:/, $form->{currencies};
+ for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
+
+ if ( @{ $form->{all_partsgroup} } ) {
+ $form->{selectpartsgroup} = "";
+ foreach $ref ( @{ $form->{all_partsgroup} } ) {
+ $form->{selectpartsgroup} .= qq|$ref->{partsgroup}--$ref->{id}\n|;
+ }
+ }
- # currencies
- @curr = split /:/, $form->{currencies};
- for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
-
- if (@ { $form->{all_partsgroup} }) {
- $form->{selectpartsgroup} = "";
- foreach $ref (@ { $form->{all_partsgroup} }) {
- $form->{selectpartsgroup} .= qq|$ref->{partsgroup}--$ref->{id}\n|;
+ for (qw(currencies all_partsgroup all_partspricelist)) {
+ delete $form->{$_};
}
- }
- for (qw(currencies all_partsgroup all_partspricelist)) { delete $form->{$_} }
+ foreach $i ( 1 .. $form->{rowcount} ) {
- foreach $i (1 .. $form->{rowcount}) {
-
- if ($form->{db} eq 'customer') {
-
- $form->{"pricebreak_$i"} = $form->format_amount(\%myconfig, $form->{"pricebreak_$i"});
+ if ( $form->{db} eq 'customer' ) {
- $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, 2);
-
- }
-
- if ($form->{db} eq 'vendor') {
-
- $form->{"leadtime_$i"} = $form->format_amount(\%myconfig, $form->{"leadtime_$i"});
-
- $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2);
-
+ $form->{"pricebreak_$i"} =
+ $form->format_amount( \%myconfig, $form->{"pricebreak_$i"} );
+
+ $form->{"sellprice_$i"} =
+ $form->format_amount( \%myconfig, $form->{"sellprice_$i"}, 2 );
+
+ }
+
+ if ( $form->{db} eq 'vendor' ) {
+
+ $form->{"leadtime_$i"} =
+ $form->format_amount( \%myconfig, $form->{"leadtime_$i"} );
+
+ $form->{"lastcost_$i"} =
+ $form->format_amount( \%myconfig, $form->{"lastcost_$i"}, 2 );
+
+ }
}
- }
- $form->{rowcount}++;
- &{ "$form->{db}_pricelist" };
-
+ $form->{rowcount}++;
+ &{"$form->{db}_pricelist"};
+
}
-
sub customer_pricelist {
- @flds = qw(runningnumber id partnumber description sellprice unit partsgroup pricebreak curr validfrom validto);
+ @flds =
+ qw(runningnumber id partnumber description sellprice unit partsgroup pricebreak curr validfrom validto);
+
+ $form->{rowcount}--;
+
+ # remove empty rows
+ if ( $form->{rowcount} ) {
+
+ foreach $i ( 1 .. $form->{rowcount} ) {
+
+ for (qw(pricebreak sellprice)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ ( $a, $b ) = split /\./, $form->{"pricebreak_$i"};
+ $a = length $a;
+ $b = length $b;
+ $whole = ( $whole > $a ) ? $whole : $a;
+ $dec = ( $dec > $b ) ? $dec : $b;
+ }
+ $pad1 = '0' x $whole;
+ $pad2 = '0' x $dec;
- $form->{rowcount}--;
-
- # remove empty rows
- if ($form->{rowcount}) {
+ foreach $i ( 1 .. $form->{rowcount} ) {
+ ( $a, $b ) = split /\./, $form->{"pricebreak_$i"};
- foreach $i (1 .. $form->{rowcount}) {
+ $a = substr( "$pad1$a", -$whole );
+ $b = substr( "$b$pad2", 0, $dec );
+ $ndx{qq|$form->{"partnumber_$i"}_$form->{"id_$i"}_$a$b|} = $i;
+ }
+
+ $i = 1;
+ for ( sort keys %ndx ) { $form->{"runningnumber_$ndx{$_}"} = $i++ }
+
+ foreach $i ( 1 .. $form->{rowcount} ) {
+ if ( $form->{"partnumber_$i"} && $form->{"sellprice_$i"} ) {
+ if ( $form->{"id_$i"} eq $sameid ) {
+ $j = $i + 1;
+ next
+ if ( $form->{"id_$j"} eq $sameid
+ && !$form->{"pricebreak_$i"} );
+ }
+
+ push @a, {};
+ $j = $#a;
+
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
+ $sameid = $form->{"id_$i"};
+ }
+
+ $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
+ $form->{rowcount} = $count;
- for (qw(pricebreak sellprice)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- ($a, $b) = split /\./, $form->{"pricebreak_$i"};
- $a = length $a;
- $b = length $b;
- $whole = ($whole > $a) ? $whole : $a;
- $dec = ($dec > $b) ? $dec : $b;
}
- $pad1 = '0' x $whole;
- $pad2 = '0' x $dec;
- foreach $i (1 .. $form->{rowcount}) {
- ($a, $b) = split /\./, $form->{"pricebreak_$i"};
-
- $a = substr("$pad1$a", -$whole);
- $b = substr("$b$pad2", 0, $dec);
- $ndx{qq|$form->{"partnumber_$i"}_$form->{"id_$i"}_$a$b|} = $i;
+ $form->{rowcount}++;
+
+ if ( $form->{display_form} ) {
+ &{"$form->{display_form}"};
}
-
- $i = 1;
- for (sort keys %ndx) { $form->{"runningnumber_$ndx{$_}"} = $i++ }
-
- foreach $i (1 .. $form->{rowcount}) {
- if ($form->{"partnumber_$i"} && $form->{"sellprice_$i"}) {
- if ($form->{"id_$i"} eq $sameid) {
- $j = $i + 1;
- next if ($form->{"id_$j"} eq $sameid && !$form->{"pricebreak_$i"});
- }
-
- push @a, {};
- $j = $#a;
-
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
- }
- $sameid = $form->{"id_$i"};
- }
-
- $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
- $form->{rowcount} = $count;
-
- }
-
- $form->{rowcount}++;
-
- if ($form->{display_form}) {
- &{ "$form->{display_form}" };
- }
}
-
sub vendor_pricelist {
- @flds = qw(runningnumber id sku partnumber description lastcost unit partsgroup curr leadtime);
+ @flds =
+ qw(runningnumber id sku partnumber description lastcost unit partsgroup curr leadtime);
- $form->{rowcount}--;
-
- # remove empty rows
- if ($form->{rowcount}) {
+ $form->{rowcount}--;
- foreach $i (1 .. $form->{rowcount}) {
+ # remove empty rows
+ if ( $form->{rowcount} ) {
- for (qw(leadtime lastcost)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
- $var = ($form->{"partnumber_$i"}) ? $form->{"sku_$i"} : qq|_$form->{"sku_$i"}|;
- $ndx{$var} = $i;
-
- }
+ foreach $i ( 1 .. $form->{rowcount} ) {
- $i = 1;
- for (sort keys %ndx) { $form->{"runningnumber_$ndx{$_}"} = $i++ }
+ for (qw(leadtime lastcost)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+ $var =
+ ( $form->{"partnumber_$i"} )
+ ? $form->{"sku_$i"}
+ : qq|_$form->{"sku_$i"}|;
+ $ndx{$var} = $i;
- foreach $i (1 .. $form->{rowcount}) {
- if ($form->{"sku_$i"}) {
- push @a, {};
- $j = $#a;
+ }
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
- }
- }
-
- $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
- $form->{rowcount} = $count;
+ $i = 1;
+ for ( sort keys %ndx ) { $form->{"runningnumber_$ndx{$_}"} = $i++ }
- }
+ foreach $i ( 1 .. $form->{rowcount} ) {
+ if ( $form->{"sku_$i"} ) {
+ push @a, {};
+ $j = $#a;
- $form->{rowcount}++;
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
+ }
- if ($form->{display_form}) {
- &{ "$form->{display_form}" };
- }
+ $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
+ $form->{rowcount} = $count;
-}
+ }
+ $form->{rowcount}++;
+
+ if ( $form->{display_form} ) {
+ &{"$form->{display_form}"};
+ }
-sub display_pricelist {
-
- &pricelist_header;
- delete $form->{action};
- $form->hide_form;
- &pricelist_footer;
-
}
+sub display_pricelist {
+
+ &pricelist_header;
+ delete $form->{action};
+ $form->hide_form;
+ &pricelist_footer;
+
+}
sub pricelist_header {
-
- $form->{title} = $form->{name};
-
- $form->header;
- print qq|
+ $form->{title} = $form->{name};
+
+ $form->header;
+
+ print qq|
<body>
<form method=post action="$form->{script}">
@@ -1933,133 +2294,181 @@ sub pricelist_header {
<tr height="5"></tr>
|;
- if ($form->{db} eq 'customer') {
- @column_index = qw(partnumber description);
- push @column_index, "partsgroup" if $form->{selectpartsgroup};
- push @column_index, qw(pricebreak sellprice curr validfrom validto);
-
- $column_header{pricebreak} = qq|<th class=listheading nowrap>|.$locale->text('Break').qq|</th>|;
- $column_header{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Sell Price').qq|</th>|;
- $column_header{validfrom} = qq|<th class=listheading nowrap>|.$locale->text('From').qq|</th>|;
- $column_header{validto} = qq|<th class=listheading nowrap>|.$locale->text('To').qq|</th>|;
- }
-
- if ($form->{db} eq 'vendor') {
- @column_index = qw(sku partnumber description);
- push @column_index, "partsgroup" if $form->{selectpartsgroup};
- push @column_index, qw(lastcost curr leadtime);
-
+ if ( $form->{db} eq 'customer' ) {
+ @column_index = qw(partnumber description);
+ push @column_index, "partsgroup" if $form->{selectpartsgroup};
+ push @column_index, qw(pricebreak sellprice curr validfrom validto);
+
+ $column_header{pricebreak} =
+ qq|<th class=listheading nowrap>|
+ . $locale->text('Break')
+ . qq|</th>|;
+ $column_header{sellprice} =
+ qq|<th class=listheading nowrap>|
+ . $locale->text('Sell Price')
+ . qq|</th>|;
+ $column_header{validfrom} =
+ qq|<th class=listheading nowrap>| . $locale->text('From') . qq|</th>|;
+ $column_header{validto} =
+ qq|<th class=listheading nowrap>| . $locale->text('To') . qq|</th>|;
+ }
- $column_header{sku} = qq|<th class=listheading nowrap>|.$locale->text('SKU').qq|</th>|;
- $column_header{leadtime} = qq|<th class=listheading nowrap>|.$locale->text('Leadtime').qq|</th>|;
- $column_header{lastcost} = qq|<th class=listheading nowrap>|.$locale->text('Cost').qq|</th>|;
- }
+ if ( $form->{db} eq 'vendor' ) {
+ @column_index = qw(sku partnumber description);
+ push @column_index, "partsgroup" if $form->{selectpartsgroup};
+ push @column_index, qw(lastcost curr leadtime);
+
+ $column_header{sku} =
+ qq|<th class=listheading nowrap>| . $locale->text('SKU') . qq|</th>|;
+ $column_header{leadtime} =
+ qq|<th class=listheading nowrap>|
+ . $locale->text('Leadtime')
+ . qq|</th>|;
+ $column_header{lastcost} =
+ qq|<th class=listheading nowrap>| . $locale->text('Cost') . qq|</th>|;
+ }
- $column_header{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
- $column_header{description} = qq|<th class=listheading nowrap width=80%>|.$locale->text('Description').qq|</th>|;
- $column_header{partsgroup} = qq|<th class=listheading nowrap>|.$locale->text('Group').qq|</th>|;
- $column_header{curr} = qq|<th class=listheading nowrap>|.$locale->text('Curr').qq|</th>|;
+ $column_header{partnumber} =
+ qq|<th class=listheading nowrap>| . $locale->text('Number') . qq|</th>|;
+ $column_header{description} =
+ qq|<th class=listheading nowrap width=80%>|
+ . $locale->text('Description')
+ . qq|</th>|;
+ $column_header{partsgroup} =
+ qq|<th class=listheading nowrap>| . $locale->text('Group') . qq|</th>|;
+ $column_header{curr} =
+ qq|<th class=listheading nowrap>| . $locale->text('Curr') . qq|</th>|;
- print qq|
+ print qq|
<tr>
<td>
<table width=100%>
<tr class=listheading>
|;
- for (@column_index) { print "\n$column_header{$_}" }
-
- print qq|
+ for (@column_index) { print "\n$column_header{$_}" }
+
+ print qq|
</tr>
|;
- $sameid = "";
- foreach $i (1 .. $form->{rowcount}) {
-
- $selectcurrency = $form->{selectcurrency};
- $selectcurrency =~ s/option>\Q$form->{"curr_$i"}\E/option selected>$form->{"curr_$i"}/;
-
- if ($form->{selectpartsgroup}) {
- if ($i < $form->{rowcount}) {
- ($partsgroup) = split /--/, $form->{"partsgroup_$i"};
- $column_data{partsgroup} = qq|<td>$partsgroup</td>
- <input type=hidden name="partsgroup_$i" value="|.$form->quote($form->{"partsgroup_$i"}).qq|">|;
- }
- }
-
-
- if ($i < $form->{rowcount}) {
-
- if ($form->{"id_$i"} eq $sameid) {
- for (qw(partnumber description partsgroup)) { $column_data{$_} = qq|<td>&nbsp;</td>
- <input type=hidden name="${_}_$i" value="|.$form->quote($form->{"${_}_$i"}).qq|">| }
- } else {
-
- $column_data{sku} = qq|<td><input name="sku_$i" value="$form->{"sku_$i"}"></td>|;
- $column_data{partnumber} = qq|<td><input name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
-
- $column_data{description} = qq|<td>$form->{"description_$i"}&nbsp;</td>
- <input type=hidden name="description_$i" value="|.$form->quote($form->{"description_$i"}).qq|">|;
-
- }
-
- $column_data{partnumber} .= qq|
+ $sameid = "";
+ foreach $i ( 1 .. $form->{rowcount} ) {
+
+ $selectcurrency = $form->{selectcurrency};
+ $selectcurrency =~
+ s/option>\Q$form->{"curr_$i"}\E/option selected>$form->{"curr_$i"}/;
+
+ if ( $form->{selectpartsgroup} ) {
+ if ( $i < $form->{rowcount} ) {
+ ($partsgroup) = split /--/, $form->{"partsgroup_$i"};
+ $column_data{partsgroup} = qq|<td>$partsgroup</td>
+ <input type=hidden name="partsgroup_$i" value="|
+ . $form->quote( $form->{"partsgroup_$i"} ) . qq|">|;
+ }
+ }
+
+ if ( $i < $form->{rowcount} ) {
+
+ if ( $form->{"id_$i"} eq $sameid ) {
+ for (qw(partnumber description partsgroup)) {
+ $column_data{$_} = qq|<td>&nbsp;</td>
+ <input type=hidden name="${_}_$i" value="|
+ . $form->quote( $form->{"${_}_$i"} ) . qq|">|;
+ }
+ }
+ else {
+
+ $column_data{sku} =
+ qq|<td><input name="sku_$i" value="$form->{"sku_$i"}"></td>|;
+ $column_data{partnumber} =
+qq|<td><input name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
+
+ $column_data{description} =
+ qq|<td>$form->{"description_$i"}&nbsp;</td>
+ <input type=hidden name="description_$i" value="|
+ . $form->quote( $form->{"description_$i"} ) . qq|">|;
+
+ }
+
+ $column_data{partnumber} .= qq|
<input type=hidden name="id_$i" value="$form->{"id_$i"}">|;
-
- } else {
-
- if ($form->{db} eq 'customer') {
- $column_data{partnumber} = qq|<td><input name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
- } else {
- $column_data{partnumber} = qq|<td>&nbsp;</td>|;
- }
-
- $column_data{partnumber} .= qq|
+
+ }
+ else {
+
+ if ( $form->{db} eq 'customer' ) {
+ $column_data{partnumber} =
+qq|<td><input name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
+ }
+ else {
+ $column_data{partnumber} = qq|<td>&nbsp;</td>|;
+ }
+
+ $column_data{partnumber} .= qq|
<input type=hidden name="id_$i" value="$form->{"id_$i"}">|;
-
- $column_data{sku} = qq|<td><input name="sku_$i" value="$form->{"sku_$i"}"></td>|;
- $column_data{description} = qq|<td><input name="description_$i" value="$form->{"description_$i"}"></td>|;
-
- if ($form->{selectpartsgroup}) {
- $selectpartsgroup = "<option>";
- foreach $line (split /\n/, $form->{selectpartsgroup}) {
- $selectpartsgroup .= qq|\n<option value="|.$form->quote($line).qq|">| .(split /--/, $line)[0];
- }
- $column_data{partsgroup} = qq|<td><select name="partsgroup_$i">$selectpartsgroup</select></td>|;
- }
-
- }
-
-
- if ($form->{db} eq 'customer') {
-
- $column_data{pricebreak} = qq|<td align=right><input name="pricebreak_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"pricebreak_$i"}).qq|></td>|;
- $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, 2).qq|></td>|;
-
- $column_data{validfrom} = qq|<td><input name="validfrom_$i" size=11 value=$form->{"validfrom_$i"}></td>|;
- $column_data{validto} = qq|<td><input name="validto_$i" size=11 value=$form->{"validto_$i"}></td>|;
- }
-
- if ($form->{db} eq 'vendor') {
- $column_data{leadtime} = qq|<td align=right><input name="leadtime_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"leadtime_$i"}).qq|></td>|;
- $column_data{lastcost} = qq|<td align=right><input name="lastcost_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2).qq|></td>|;
- }
-
-
- $column_data{curr} = qq|<td><select name="curr_$i">$selectcurrency</select></td>|;
-
-
- print qq|<tr valign=top>|;
-
- for (@column_index) { print "\n$column_data{$_}" }
- print qq|</tr>|;
+ $column_data{sku} =
+ qq|<td><input name="sku_$i" value="$form->{"sku_$i"}"></td>|;
+ $column_data{description} =
+qq|<td><input name="description_$i" value="$form->{"description_$i"}"></td>|;
+
+ if ( $form->{selectpartsgroup} ) {
+ $selectpartsgroup = "<option>";
+ foreach $line ( split /\n/, $form->{selectpartsgroup} ) {
+ $selectpartsgroup .=
+ qq|\n<option value="|
+ . $form->quote($line) . qq|">|
+ . ( split /--/, $line )[0];
+ }
+ $column_data{partsgroup} =
+qq|<td><select name="partsgroup_$i">$selectpartsgroup</select></td>|;
+ }
+
+ }
+
+ if ( $form->{db} eq 'customer' ) {
+
+ $column_data{pricebreak} =
+ qq|<td align=right><input name="pricebreak_$i" size=5 value=|
+ . $form->format_amount( \%myconfig, $form->{"pricebreak_$i"} )
+ . qq|></td>|;
+ $column_data{sellprice} =
+ qq|<td align=right><input name="sellprice_$i" size=10 value=|
+ . $form->format_amount( \%myconfig, $form->{"sellprice_$i"}, 2 )
+ . qq|></td>|;
+
+ $column_data{validfrom} =
+qq|<td><input name="validfrom_$i" size=11 value=$form->{"validfrom_$i"}></td>|;
+ $column_data{validto} =
+qq|<td><input name="validto_$i" size=11 value=$form->{"validto_$i"}></td>|;
+ }
+
+ if ( $form->{db} eq 'vendor' ) {
+ $column_data{leadtime} =
+ qq|<td align=right><input name="leadtime_$i" size=5 value=|
+ . $form->format_amount( \%myconfig, $form->{"leadtime_$i"} )
+ . qq|></td>|;
+ $column_data{lastcost} =
+ qq|<td align=right><input name="lastcost_$i" size=10 value=|
+ . $form->format_amount( \%myconfig, $form->{"lastcost_$i"}, 2 )
+ . qq|></td>|;
+ }
+
+ $column_data{curr} =
+ qq|<td><select name="curr_$i">$selectcurrency</select></td>|;
+
+ print qq|<tr valign=top>|;
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|</tr>|;
+
+ $sameid = $form->{"id_$i"};
- $sameid = $form->{"id_$i"};
+ }
- }
-
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -2069,136 +2478,167 @@ sub pricelist_header {
</table>
|;
- # delete variables
- foreach $i (1 .. $form->{rowcount}) {
- for (@column_index, "id") { delete $form->{"${_}_$i"} }
- }
- for (qw(title titlebar script none)) { delete $form->{$_} }
+ # delete variables
+ foreach $i ( 1 .. $form->{rowcount} ) {
+ for ( @column_index, "id" ) { delete $form->{"${_}_$i"} }
+ }
+ for (qw(title titlebar script none)) { delete $form->{$_} }
}
-
sub pricelist_footer {
-# type=submit $locale->text('Update')
-# type=submit $locale->text('Save Pricelist')
+ # type=submit $locale->text('Update')
+ # type=submit $locale->text('Save Pricelist')
+
+ %button = (
+ 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
+ 'save_pricelist' =>
+ { ndx => 3, key => 'S', value => $locale->text('Save Pricelist') },
+ );
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- 'save_pricelist' => { ndx => 3, key => 'S', value => $locale->text('Save Pricelist') },
- );
-
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
-
- print qq|
+ for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
+ $form->print_button( \%button, $_ );
+ }
+
+ print qq|
</form>
</body>
</html>
-|;
+|;
}
-
sub update {
-
- $i = $form->{rowcount};
- $additem = 0;
-
- if ($form->{db} eq 'customer') {
- $additem = 1 if ! (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq ""));
- }
- if ($form->{db} eq 'vendor') {
- if (! (($form->{"sku_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq ""))) {
- $additem = 1;
- $form->{"partnumber_$i"} = $form->{"sku_$i"};
- }
- }
-
- if ($additem) {
-
- CT->retrieve_item(\%myconfig, \%$form);
-
- $rows = scalar @{ $form->{item_list} };
-
- if ($rows > 0) {
-
- if ($rows > 1) {
-
- &select_item;
- exit;
-
- } else {
-
- $sellprice = $form->{"sellprice_$i"};
- $pricebreak = $form->{"pricebreak_$i"};
- $lastcost = $form->{"lastcost_$i"};
-
- for (qw(partnumber description)) { $form->{item_list}[0]{$_} = $form->quote($form->{item_list}[0]{$_}) }
- for (keys %{ $form->{item_list}[0] }) { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
-
- if ($form->{db} eq 'customer') {
-
- if ($sellprice) {
- $form->{"sellprice_$i"} = $sellprice;
- }
-
- $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, 2);
-
- $form->{"pricebreak_$i"} = $pricebreak;
-
- } else {
-
- foreach $j (1 .. $form->{rowcount} - 1) {
- if ($form->{"sku_$j"} eq $form->{"partnumber_$i"}) {
- $form->error($locale->text('Item already on pricelist!'));
- }
- }
-
- if ($lastcost) {
- $form->{"lastcost_$i"} = $lastcost;
- }
-
- $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2);
-
- $form->{"sku_$i"} = $form->{"partnumber_$i"};
-# delete $form->{"partnumber_$i"};
-
- }
-
- $form->{rowcount}++;
-
- }
-
- } else {
-
- $form->error($locale->text('Item not on file!'));
-
- }
- }
-
- &{ "$form->{db}_pricelist" };
-
-}
+ $i = $form->{rowcount};
+ $additem = 0;
+ if ( $form->{db} eq 'customer' ) {
+ $additem = 1
+ if !(( $form->{"partnumber_$i"} eq "" )
+ && ( $form->{"description_$i"} eq "" )
+ && ( $form->{"partsgroup_$i"} eq "" ) );
+ }
+ if ( $form->{db} eq 'vendor' ) {
+ if (
+ !(
+ ( $form->{"sku_$i"} eq "" )
+ && ( $form->{"description_$i"} eq "" )
+ && ( $form->{"partsgroup_$i"} eq "" )
+ )
+ )
+ {
+ $additem = 1;
+ $form->{"partnumber_$i"} = $form->{"sku_$i"};
+ }
+ }
+
+ if ($additem) {
+
+ CT->retrieve_item( \%myconfig, \%$form );
+
+ $rows = scalar @{ $form->{item_list} };
+
+ if ( $rows > 0 ) {
+
+ if ( $rows > 1 ) {
+
+ &select_item;
+ exit;
+
+ }
+ else {
+
+ $sellprice = $form->{"sellprice_$i"};
+ $pricebreak = $form->{"pricebreak_$i"};
+ $lastcost = $form->{"lastcost_$i"};
+
+ for (qw(partnumber description)) {
+ $form->{item_list}[0]{$_} =
+ $form->quote( $form->{item_list}[0]{$_} );
+ }
+ for ( keys %{ $form->{item_list}[0] } ) {
+ $form->{"${_}_$i"} = $form->{item_list}[0]{$_};
+ }
+
+ if ( $form->{db} eq 'customer' ) {
+
+ if ($sellprice) {
+ $form->{"sellprice_$i"} = $sellprice;
+ }
+
+ $form->{"sellprice_$i"} =
+ $form->format_amount( \%myconfig, $form->{"sellprice_$i"},
+ 2 );
+
+ $form->{"pricebreak_$i"} = $pricebreak;
+
+ }
+ else {
+
+ foreach $j ( 1 .. $form->{rowcount} - 1 ) {
+ if ( $form->{"sku_$j"} eq $form->{"partnumber_$i"} ) {
+ $form->error(
+ $locale->text('Item already on pricelist!') );
+ }
+ }
+
+ if ($lastcost) {
+ $form->{"lastcost_$i"} = $lastcost;
+ }
+
+ $form->{"lastcost_$i"} =
+ $form->format_amount( \%myconfig, $form->{"lastcost_$i"},
+ 2 );
+
+ $form->{"sku_$i"} = $form->{"partnumber_$i"};
+
+ # delete $form->{"partnumber_$i"};
+
+ }
+
+ $form->{rowcount}++;
+
+ }
+
+ }
+ else {
+
+ $form->error( $locale->text('Item not on file!') );
+
+ }
+ }
+
+ &{"$form->{db}_pricelist"};
+
+}
sub select_item {
- @column_index = qw(ndx partnumber description partsgroup unit sellprice lastcost);
-
- $column_data{ndx} = qq|<th>&nbsp;</th>|;
- $column_data{partnumber} = qq|<th class=listheading>|.$locale->text('Number').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{unit} = qq|<th class=listheading>|.$locale->text('Unit').qq|</th>|;
- $column_data{sellprice} = qq|<th class=listheading>|.$locale->text('Sell Price').qq|</th>|;
- $column_data{lastcost} = qq|<th class=listheading>|.$locale->text('Cost').qq|</th>|;
-
- $form->header;
-
- $title = $locale->text('Select items');
-
- print qq|
+ @column_index =
+ qw(ndx partnumber description partsgroup unit sellprice lastcost);
+
+ $column_data{ndx} = qq|<th>&nbsp;</th>|;
+ $column_data{partnumber} =
+ qq|<th class=listheading>| . $locale->text('Number') . 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{unit} =
+ qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
+ $column_data{sellprice} =
+ qq|<th class=listheading>| . $locale->text('Sell Price') . qq|</th>|;
+ $column_data{lastcost} =
+ qq|<th class=listheading>| . $locale->text('Cost') . qq|</th>|;
+
+ $form->header;
+
+ $title = $locale->text('Select items');
+
+ print qq|
<body>
<form method=post action="$form->{script}">
@@ -2216,42 +2656,58 @@ sub select_item {
<table width=100%>
<tr class=listheading>|;
- for (@column_index) { print "\n$column_data{$_}" }
+ for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ print qq|
</tr>
|;
- my $i = 0;
- foreach $ref (@{ $form->{item_list} }) {
- $i++;
+ my $i = 0;
+ foreach $ref ( @{ $form->{item_list} } ) {
+ $i++;
- for (qw(partnumber description unit)) { $ref->{$_} = $form->quote($ref->{$_}) }
-
- $column_data{ndx} = qq|<td><input name="ndx_$i" class=checkbox type=checkbox value=$i></td>|;
+ for (qw(partnumber description unit)) {
+ $ref->{$_} = $form->quote( $ref->{$_} );
+ }
- for (qw(partnumber description partsgroup unit)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
+ $column_data{ndx} =
+qq|<td><input name="ndx_$i" class=checkbox type=checkbox value=$i></td>|;
- $column_data{sellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{sellprice}, 2, "&nbsp;").qq|</td>|;
- $column_data{lastcost} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{lastcost}, 2, "&nbsp;").qq|</td>|;
+ for (qw(partnumber description partsgroup unit)) {
+ $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>|;
+ }
- $j++; $j %= 2;
+ $column_data{sellprice} =
+ qq|<td align=right>|
+ . $form->format_amount( \%myconfig, $ref->{sellprice}, 2, "&nbsp;" )
+ . qq|</td>|;
+ $column_data{lastcost} =
+ qq|<td align=right>|
+ . $form->format_amount( \%myconfig, $ref->{lastcost}, 2, "&nbsp;" )
+ . qq|</td>|;
- print qq|
+ $j++;
+ $j %= 2;
+
+ print qq|
<tr class=listrow$j>|;
- for (@column_index) { print "\n$column_data{$_}" }
+ for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ print qq|
</tr>
|;
- for (qw(partnumber description partsgroup partsgroup_id sellprice lastcost unit id)) {
- print qq|<input type=hidden name="new_${_}_$i" value="$ref->{$_}">\n|;
+ for (
+ qw(partnumber description partsgroup partsgroup_id sellprice lastcost unit id)
+ )
+ {
+ print
+ qq|<input type=hidden name="new_${_}_$i" value="$ref->{$_}">\n|;
+ }
}
- }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -2264,18 +2720,20 @@ sub select_item {
|;
- # delete action variable
- for (qw(nextsub item_list)) { delete $form->{$_} }
-
- $form->{action} = "item_selected";
+ # delete action variable
+ for (qw(nextsub item_list)) { delete $form->{$_} }
- $form->hide_form;
+ $form->{action} = "item_selected";
- print qq|
+ $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>
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
</body>
@@ -2283,212 +2741,203 @@ sub select_item {
|;
}
+sub item_selected {
+ # add rows
+ $i = $form->{rowcount};
-sub item_selected {
+ %id = ();
+ for $i ( 1 .. $form->{rowcount} - 1 ) {
+ $id{ $form->{"id_$i"} } = 1;
+ }
- # add rows
- $i = $form->{rowcount};
+ for $j ( 1 .. $form->{lastndx} ) {
- %id = ();
- for $i (1 .. $form->{rowcount} - 1) {
- $id{$form->{"id_$i"}} = 1;
- }
-
- for $j (1 .. $form->{lastndx}) {
-
- if ($form->{"ndx_$j"}) {
-
- if ($id{$form->{"new_id_$j"}}) {
- next if $form->{db} eq 'vendor';
- }
-
- for (qw(id partnumber description unit sellprice lastcost)) {
- $form->{"${_}_$i"} = $form->{"new_${_}_$j"};
- }
-
- $form->{"partsgroup_$i"} = qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|;
- $form->{"sku_$i"} = $form->{"new_partnumber_$j"};
-
- $i++;
-
+ if ( $form->{"ndx_$j"} ) {
+
+ if ( $id{ $form->{"new_id_$j"} } ) {
+ next if $form->{db} eq 'vendor';
+ }
+
+ for (qw(id partnumber description unit sellprice lastcost)) {
+ $form->{"${_}_$i"} = $form->{"new_${_}_$j"};
+ }
+
+ $form->{"partsgroup_$i"} =
+ qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|;
+ $form->{"sku_$i"} = $form->{"new_partnumber_$j"};
+
+ $i++;
+
+ }
}
- }
- $form->{rowcount} = $i;
-
- # delete all the new_ variables
- for $i (1 .. $form->{lastndx}) {
- for (qw(id partnumber description unit sellprice lastcost partsgroup partsgroup_id)) { delete $form->{"new_${_}_$i"} }
- delete $form->{"ndx_$i"};
- }
-
- for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
+ $form->{rowcount} = $i;
+
+ # delete all the new_ variables
+ for $i ( 1 .. $form->{lastndx} ) {
+ for (
+ qw(id partnumber description unit sellprice lastcost partsgroup partsgroup_id)
+ )
+ {
+ delete $form->{"new_${_}_$i"};
+ }
+ delete $form->{"ndx_$i"};
+ }
+
+ for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
- &{ "$form->{db}_pricelist" };
+ &{"$form->{db}_pricelist"};
}
+sub save_pricelist {
+ &{"CT::save_$form->{db}"}( "", \%myconfig, \%$form );
-
-sub save_pricelist {
-
- &{ "CT::save_$form->{db}" }("", \%myconfig, \%$form);
-
- $callback = $form->{callback};
- $form->{callback} = "$form->{script}?action=edit";
- for (qw(db id login path sessionid)) { $form->{callback} .= "&$_=$form->{$_}" }
- $form->{callback} .= "&callback=".$form->escape($callback,1);
-
- if (CT->save_pricelist(\%myconfig, \%$form)) {
- $form->redirect;
- } else {
- $form->error($locale->text('Could not save pricelist!'));
- }
+ $callback = $form->{callback};
+ $form->{callback} = "$form->{script}?action=edit";
+ for (qw(db id login path sessionid)) {
+ $form->{callback} .= "&$_=$form->{$_}";
+ }
+ $form->{callback} .= "&callback=" . $form->escape( $callback, 1 );
+
+ if ( CT->save_pricelist( \%myconfig, \%$form ) ) {
+ $form->redirect;
+ }
+ else {
+ $form->error( $locale->text('Could not save pricelist!') );
+ }
}
+sub add_transaction {
+
+ $form->isblank( "name", $locale->text("Name missing!") );
+ &{"CT::save_$form->{db}"}( "", \%myconfig, \%$form );
-sub add_transaction {
-
- $form->isblank("name", $locale->text("Name missing!"));
+ $form->{callback} = $form->escape( $form->{callback}, 1 );
+ $name = $form->escape( $form->{name}, 1 );
- &{ "CT::save_$form->{db}" }("", \%myconfig, \%$form);
-
- $form->{callback} = $form->escape($form->{callback},1);
- $name = $form->escape($form->{name},1);
+ $form->{callback} =
+"$form->{script}?login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}";
- $form->{callback} = "$form->{script}?login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}";
+ $form->redirect;
- $form->redirect;
-
}
sub ap_transaction {
- $form->{script} = "ap.pl";
- $form->{type} = "ap_transaction";
- &add_transaction;
+ $form->{script} = "ap.pl";
+ $form->{type} = "ap_transaction";
+ &add_transaction;
}
-
sub ar_transaction {
- $form->{script} = "ar.pl";
- $form->{type} = "ar_transaction";
- &add_transaction;
+ $form->{script} = "ar.pl";
+ $form->{type} = "ar_transaction";
+ &add_transaction;
}
-
sub sales_invoice {
- $form->{script} = "is.pl";
- $form->{type} = "invoice";
- &add_transaction;
-
-}
+ $form->{script} = "is.pl";
+ $form->{type} = "invoice";
+ &add_transaction;
+}
sub pos {
-
- $form->{script} = "ps.pl";
- $form->{type} = "pos_invoice";
- &add_transaction;
-}
+ $form->{script} = "ps.pl";
+ $form->{type} = "pos_invoice";
+ &add_transaction;
+}
sub vendor_invoice {
- $form->{script} = "ir.pl";
- $form->{type} = "invoice";
- &add_transaction;
-
-}
+ $form->{script} = "ir.pl";
+ $form->{type} = "invoice";
+ &add_transaction;
+}
sub rfq {
- $form->{script} = "oe.pl";
- $form->{type} = "request_quotation";
- &add_transaction;
+ $form->{script} = "oe.pl";
+ $form->{type} = "request_quotation";
+ &add_transaction;
}
-
sub quotation {
-
- $form->{script} = "oe.pl";
- $form->{type} = "sales_quotation";
- &add_transaction;
-}
+ $form->{script} = "oe.pl";
+ $form->{type} = "sales_quotation";
+ &add_transaction;
+}
sub sales_order {
-
- $form->{script} = "oe.pl";
- $form->{type} = "sales_order";
- &add_transaction;
-}
+ $form->{script} = "oe.pl";
+ $form->{type} = "sales_order";
+ &add_transaction;
+}
sub purchase_order {
- $form->{script} = "oe.pl";
- $form->{type} = "purchase_order";
- &add_transaction;
-
-}
+ $form->{script} = "oe.pl";
+ $form->{type} = "purchase_order";
+ &add_transaction;
+}
sub save_as_new {
-
- delete $form->{id};
- &save;
-
-}
+ delete $form->{id};
+ &save;
+
+}
sub save {
-# $locale->text('Customer saved!')
-# $locale->text('Vendor saved!')
-
- $msg = ucfirst $form->{db};
- $msg .= " saved!";
-
- $form->isblank("name", $locale->text("Name missing!"));
- &{ "CT::save_$form->{db}" }("", \%myconfig, \%$form);
-
- $form->redirect($locale->text($msg));
-
-}
+ # $locale->text('Customer saved!')
+ # $locale->text('Vendor saved!')
+ $msg = ucfirst $form->{db};
+ $msg .= " saved!";
-sub delete {
+ $form->isblank( "name", $locale->text("Name missing!") );
+ &{"CT::save_$form->{db}"}( "", \%myconfig, \%$form );
+
+ $form->redirect( $locale->text($msg) );
-# $locale->text('Customer deleted!')
-# $locale->text('Cannot delete customer!')
-# $locale->text('Vendor deleted!')
-# $locale->text('Cannot delete vendor!')
-
- CT->delete(\%myconfig, \%$form);
-
- $msg = ucfirst $form->{db};
- $msg .= " deleted!";
- $form->redirect($locale->text($msg));
-
}
+sub delete {
+
+ # $locale->text('Customer deleted!')
+ # $locale->text('Cannot delete customer!')
+ # $locale->text('Vendor deleted!')
+ # $locale->text('Cannot delete vendor!')
+
+ CT->delete( \%myconfig, \%$form );
+
+ $msg = ucfirst $form->{db};
+ $msg .= " deleted!";
+ $form->redirect( $locale->text($msg) );
+
+}
-sub continue { &{ $form->{nextsub} } };
+sub continue { &{ $form->{nextsub} } }
-sub add_customer { &add };
-sub add_vendor { &add };
+sub add_customer { &add }
+sub add_vendor { &add }
diff --git a/bin/gl.pl b/bin/gl.pl
index 2db8611d..fc1c9669 100644
--- a/bin/gl.pl
+++ b/bin/gl.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -45,15 +45,14 @@
#
#======================================================================
-
use LedgerSMB::GL;
use LedgerSMB::PE;
require "bin/arap.pl";
1;
-# end of main
+# end of main
# this is for our long dates
# $locale->text('January')
@@ -84,174 +83,228 @@ require "bin/arap.pl";
# $locale->text('Dec')
sub pos_adjust {
- $form->{rowcount} = 3;
- require "pos.conf.pl";
- $form->{accno_1} = $pos_config{'close_cash_accno'};
- $form->{accno_2} = $pos_config{'coa_prefix'};
- $form->{accno_3} = $pos_config{'coa_prefix'};
+ $form->{rowcount} = 3;
+ require "pos.conf.pl";
+ $form->{accno_1} = $pos_config{'close_cash_accno'};
+ $form->{accno_2} = $pos_config{'coa_prefix'};
+ $form->{accno_3} = $pos_config{'coa_prefix'};
}
sub add_pos_adjust {
- $form->{pos_adjust} = 1;
- $form->{reference} = $locale->text("Adjusting Till: (till) Source: (source)");
- $form->{description} =
- $locale->text("Adjusting till due to data entry error.");
- $form->{callback} = "$form->{script}?action=add_pos_adjust&transfer=$form->{transfer}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
- &add;
+ $form->{pos_adjust} = 1;
+ $form->{reference} =
+ $locale->text("Adjusting Till: (till) Source: (source)");
+ $form->{description} =
+ $locale->text("Adjusting till due to data entry error.");
+ $form->{callback} =
+"$form->{script}?action=add_pos_adjust&transfer=$form->{transfer}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
+ &add;
}
-
+
sub add {
- $form->{title} = "Add";
-
- $form->{callback} = "$form->{script}?action=add&transfer=$form->{transfer}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
+ $form->{title} = "Add";
+
+ $form->{callback} =
+"$form->{script}?action=add&transfer=$form->{transfer}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
+
+ &create_links;
- &create_links;
+ $form->{rowcount} = ( $form->{transfer} ) ? 3 : 9;
+ if ( $form->{pos_adjust} ) {
+ &pos_adjust;
+ }
+ $form->{oldtransdate} = $form->{transdate};
+ $form->{focus} = "reference";
+
+ # departments
+ if ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} = "<option>\n";
- $form->{rowcount} = ($form->{transfer}) ? 3 : 9;
- if ($form->{pos_adjust}){
- &pos_adjust;
- }
- $form->{oldtransdate} = $form->{transdate};
- $form->{focus} = "reference";
+ for ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+ }
- # departments
- if (@{ $form->{all_department} }) {
- $form->{selectdepartment} = "<option>\n";
+ &display_form(1);
- for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
- }
-
- &display_form(1);
-
}
-
sub edit {
- &create_links;
-
- $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
-
- # readonly
- if (! $form->{readonly}) {
- $form->{readonly} = 1 if $myconfig{acs} =~ /General Ledger--Add Transaction/;
- }
-
- $form->{title} = "Edit";
-
- $i = 1;
- foreach $ref (@{ $form->{GL} }) {
- $form->{"accno_$i"} = "$ref->{accno}--$ref->{description}";
-
- $form->{"projectnumber_$i"} = "$ref->{projectnumber}--$ref->{project_id}";
- for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
-
- if ($ref->{amount} < 0) {
- $form->{totaldebit} -= $ref->{amount};
- $form->{"debit_$i"} = $ref->{amount} * -1;
- } else {
- $form->{totalcredit} += $ref->{amount};
- $form->{"credit_$i"} = $ref->{amount};
+ &create_links;
+
+ $form->{locked} =
+ ( $form->{revtrans} )
+ ? '1'
+ : ( $form->datetonum( \%myconfig, $form->{transdate} ) <=
+ $form->datetonum( \%myconfig, $form->{closedto} ) );
+
+ # readonly
+ if ( !$form->{readonly} ) {
+ $form->{readonly} = 1
+ if $myconfig{acs} =~ /General Ledger--Add Transaction/;
}
- $i++;
- }
+ $form->{title} = "Edit";
- $form->{rowcount} = $i;
- $form->{focus} = "debit_$i";
-
- &form_header;
- &display_rows;
- &form_footer;
-
-}
+ $i = 1;
+ foreach $ref ( @{ $form->{GL} } ) {
+ $form->{"accno_$i"} = "$ref->{accno}--$ref->{description}";
+ $form->{"projectnumber_$i"} =
+ "$ref->{projectnumber}--$ref->{project_id}";
+ for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
+ if ( $ref->{amount} < 0 ) {
+ $form->{totaldebit} -= $ref->{amount};
+ $form->{"debit_$i"} = $ref->{amount} * -1;
+ }
+ else {
+ $form->{totalcredit} += $ref->{amount};
+ $form->{"credit_$i"} = $ref->{amount};
+ }
+
+ $i++;
+ }
+
+ $form->{rowcount} = $i;
+ $form->{focus} = "debit_$i";
+
+ &form_header;
+ &display_rows;
+ &form_footer;
-sub create_links {
-
- GL->transaction(\%myconfig, \%$form);
-
- for (@{ $form->{all_accno} }) { $form->{selectaccno} .= "<option>$_->{accno}--$_->{description}\n" }
-
- # projects
- if (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} = "<option>\n";
- for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
- }
-
- # departments
- if (@{ $form->{all_department} }) {
- $form->{department} = "$form->{department}--$form->{department_id}";
- $form->{selectdepartment} = "<option>\n";
- for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
- }
-
}
+sub create_links {
+
+ GL->transaction( \%myconfig, \%$form );
+
+ for ( @{ $form->{all_accno} } ) {
+ $form->{selectaccno} .= "<option>$_->{accno}--$_->{description}\n";
+ }
+
+ # projects
+ if ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} = "<option>\n";
+ for ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} .=
+qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
+ }
+ }
+
+ # departments
+ if ( @{ $form->{all_department} } ) {
+ $form->{department} = "$form->{department}--$form->{department_id}";
+ $form->{selectdepartment} = "<option>\n";
+ for ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+ }
+
+}
sub search {
- $form->{title} = $locale->text('General Ledger Reports');
-
- $colspan = 5;
- $form->all_departments(\%myconfig);
- # departments
- if (@{ $form->{all_department} }) {
- $form->{selectdepartment} = "<option>\n";
- for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
+ $form->{title} = $locale->text('General Ledger Reports');
- $l_department = qq|<input name="l_department" class=checkbox type=checkbox value=Y> |.$locale->text('Department');
+ $colspan = 5;
+ $form->all_departments( \%myconfig );
- $department = qq|
+ # departments
+ if ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} = "<option>\n";
+ for ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+
+ $l_department =
+ qq|<input name="l_department" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Department');
+
+ $department = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Department').qq|</th>
+ <th align=right nowrap>| . $locale->text('Department') . qq|</th>
<td colspan=$colspan><select name=department>$form->{selectdepartment}</select></td>
</tr>
|;
- }
-
- 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|
+ 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>
+ <th align=right>| . $locale->text('Period') . qq|</th>
<td colspan=$colspan>
<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|
+ <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>
|;
- }
-
- @a = ();
- push @a, qq|<input name="l_id" class=checkbox type=checkbox value=Y> |.$locale->text('ID');
- push @a, qq|<input name="l_transdate" class=checkbox type=checkbox value=Y checked> |.$locale->text('Date');
- push @a, qq|<input name="l_reference" class=checkbox type=checkbox value=Y checked> |.$locale->text('Reference');
- push @a, qq|<input name="l_description" class=checkbox type=checkbox value=Y checked> |.$locale->text('Description');
- push @a, qq|<input name="l_notes" class=checkbox type=checkbox value=Y> |.$locale->text('Notes');
- push @a, $l_department if $l_department;
- push @a, qq|<input name="l_debit" class=checkbox type=checkbox value=Y checked> |.$locale->text('Debit');
- push @a, qq|<input name="l_credit" class=checkbox type=checkbox value=Y checked> |.$locale->text('Credit');
- push @a, qq|<input name="l_source" class=checkbox type=checkbox value=Y checked> |.$locale->text('Source');
- push @a, qq|<input name="l_memo" class=checkbox type=checkbox value=Y> |.$locale->text('Memo');
- push @a, qq|<input name="l_accno" class=checkbox type=checkbox value=Y checked> |.$locale->text('Account');
- push @a, qq|<input name="l_gifi_accno" class=checkbox type=checkbox value=Y> |.$locale->text('GIFI');
-
-
- $form->header;
-
- print qq|
+ }
+
+ @a = ();
+ push @a, qq|<input name="l_id" class=checkbox type=checkbox value=Y> |
+ . $locale->text('ID');
+ push @a,
+qq|<input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Date');
+ push @a,
+qq|<input name="l_reference" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Reference');
+ push @a,
+qq|<input name="l_description" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Description');
+ push @a, qq|<input name="l_notes" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Notes');
+ push @a, $l_department if $l_department;
+ push @a,
+ qq|<input name="l_debit" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Debit');
+ push @a,
+ qq|<input name="l_credit" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Credit');
+ push @a,
+ qq|<input name="l_source" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Source');
+ push @a, qq|<input name="l_memo" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Memo');
+ push @a,
+ qq|<input name="l_accno" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Account');
+ push @a,
+ qq|<input name="l_gifi_accno" class=checkbox type=checkbox value=Y> |
+ . $locale->text('GIFI');
+
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -267,68 +320,76 @@ sub search {
<td>
<table>
<tr>
- <th align=right>|.$locale->text('Reference').qq|</th>
+ <th align=right>| . $locale->text('Reference') . qq|</th>
<td><input name=reference size=20></td>
</tr>
<tr>
- <th align=right>|.$locale->text('Source').qq|</th>
+ <th align=right>| . $locale->text('Source') . qq|</th>
<td><input name=source size=20></td>
- <th align=right>|.$locale->text('Memo').qq|</th>
+ <th align=right>| . $locale->text('Memo') . qq|</th>
<td><input name=memo size=20></td>
</tr>
$department
<tr>
- <th align=right>|.$locale->text('Description').qq|</th>
+ <th align=right>| . $locale->text('Description') . qq|</th>
<td colspan=$colspan><input name=description size=60></td>
</tr>
<tr>
- <th align=right>|.$locale->text('Notes').qq|</th>
+ <th align=right>| . $locale->text('Notes') . qq|</th>
<td colspan=$colspan><input name=notes size=60></td>
</tr>
<tr>
- <th align=right>|.$locale->text('From').qq|</th>
+ <th align=right>| . $locale->text('From') . qq|</th>
<td><input name=datefrom size=11 title="$myconfig{dateformat}"></td>
- <th align=right>|.$locale->text('To').qq|</th>
+ <th align=right>| . $locale->text('To') . qq|</th>
<td><input name=dateto size=11 title="$myconfig{dateformat}"></td>
</tr>
$selectfrom
<tr>
- <th align=right>|.$locale->text('Amount').qq| >=</th>
+ <th align=right>| . $locale->text('Amount') . qq| >=</th>
<td><input name=amountfrom size=11></td>
- <th align=right>|.$locale->text('Amount').qq| <=</th>
+ <th align=right>| . $locale->text('Amount') . qq| <=</th>
<td><input name=amountto size=11></td>
</tr>
<tr>
- <th align=right>|.$locale->text('Include in Report').qq|</th>
+ <th align=right>| . $locale->text('Include in Report') . qq|</th>
<td colspan=$colspan>
<table>
<tr>
<td>
- <input name="category" class=radio type=radio value=X checked>&nbsp;|.$locale->text('All').qq|
- <input name="category" class=radio type=radio value=A>&nbsp;|.$locale->text('Asset').qq|
- <input name="category" class=radio type=radio value=L>&nbsp;|.$locale->text('Liability').qq|
- <input name="category" class=radio type=radio value=Q>&nbsp;|.$locale->text('Equity').qq|
- <input name="category" class=radio type=radio value=I>&nbsp;|.$locale->text('Income').qq|
- <input name="category" class=radio type=radio value=E>&nbsp;|.$locale->text('Expense').qq|
+ <input name="category" class=radio type=radio value=X checked>&nbsp;|
+ . $locale->text('All') . qq|
+ <input name="category" class=radio type=radio value=A>&nbsp;|
+ . $locale->text('Asset') . qq|
+ <input name="category" class=radio type=radio value=L>&nbsp;|
+ . $locale->text('Liability') . qq|
+ <input name="category" class=radio type=radio value=Q>&nbsp;|
+ . $locale->text('Equity') . qq|
+ <input name="category" class=radio type=radio value=I>&nbsp;|
+ . $locale->text('Income') . qq|
+ <input name="category" class=radio type=radio value=E>&nbsp;|
+ . $locale->text('Expense') . qq|
</td>
</tr>
<tr>
<table>
|;
- while (@a) {
- print qq|<tr>\n|;
- for (1 .. 5) {
- print qq|<td nowrap>|. shift @a;
- print qq|</td>\n|;
+ while (@a) {
+ print qq|<tr>\n|;
+ for ( 1 .. 5 ) {
+ print qq|<td nowrap>| . shift @a;
+ print qq|</td>\n|;
+ }
+ print qq|</tr>\n|;
}
- print qq|</tr>\n|;
- }
- print qq|
+ print qq|
<tr>
- <td nowrap><input name="l_subtotal" class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
+ <td nowrap><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Subtotal')
+ . qq|</td>
</tr>
</table>
</tr>
@@ -345,190 +406,241 @@ sub search {
<input type=hidden name=nextsub value=generate_report>
|;
- $form->hide_form(qw(path login sessionid));
-
- print qq|
+ $form->hide_form(qw(path login sessionid));
+
+ print qq|
<br>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</body>
</html>
|;
}
-
sub generate_report {
- $form->{sort} = "transdate" unless $form->{sort};
-
- GL->all_transactions(\%myconfig, \%$form);
-
- $href = "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- $form->sort_order();
-
- $callback = "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- %acctype = ( 'A' => $locale->text('Asset'),
- 'L' => $locale->text('Liability'),
- 'Q' => $locale->text('Equity'),
- 'I' => $locale->text('Income'),
- 'E' => $locale->text('Expense'),
- );
-
- $form->{title} = $locale->text('General Ledger');
-
- $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
-
- unless ($form->{category} eq 'X') {
- $form->{title} .= " : ".$locale->text($acctype{$form->{category}});
- }
- if ($form->{accno}) {
- $href .= "&accno=".$form->escape($form->{accno});
- $callback .= "&accno=".$form->escape($form->{accno},1);
- $option = $locale->text('Account')." : $form->{accno} $form->{account_description}";
- }
- if ($form->{gifi_accno}) {
- $href .= "&gifi_accno=".$form->escape($form->{gifi_accno});
- $callback .= "&gifi_accno=".$form->escape($form->{gifi_accno},1);
- $option .= "\n<br>" if $option;
- $option .= $locale->text('GIFI')." : $form->{gifi_accno} $form->{gifi_account_description}";
- }
- if ($form->{source}) {
- $href .= "&source=".$form->escape($form->{source});
- $callback .= "&source=".$form->escape($form->{source},1);
- $option .= "\n<br>" if $option;
- $option .= $locale->text('Source')." : $form->{source}";
- }
- if ($form->{memo}) {
- $href .= "&memo=".$form->escape($form->{memo});
- $callback .= "&memo=".$form->escape($form->{memo},1);
- $option .= "\n<br>" if $option;
- $option .= $locale->text('Memo')." : $form->{memo}";
- }
- if ($form->{reference}) {
- $href .= "&reference=".$form->escape($form->{reference});
- $callback .= "&reference=".$form->escape($form->{reference},1);
- $option .= "\n<br>" if $option;
- $option .= $locale->text('Reference')." : $form->{reference}";
- }
- if ($form->{department}) {
- $href .= "&department=".$form->escape($form->{department});
- $callback .= "&department=".$form->escape($form->{department},1);
- ($department) = split /--/, $form->{department};
- $option .= "\n<br>" if $option;
- $option .= $locale->text('Department')." : $department";
- }
-
- if ($form->{description}) {
- $href .= "&description=".$form->escape($form->{description});
- $callback .= "&description=".$form->escape($form->{description},1);
- $option .= "\n<br>" if $option;
- $option .= $locale->text('Description')." : $form->{description}";
- }
- if ($form->{notes}) {
- $href .= "&notes=".$form->escape($form->{notes});
- $callback .= "&notes=".$form->escape($form->{notes},1);
- $option .= "\n<br>" if $option;
- $option .= $locale->text('Notes')." : $form->{notes}";
- }
-
- if ($form->{datefrom}) {
- $href .= "&datefrom=$form->{datefrom}";
- $callback .= "&datefrom=$form->{datefrom}";
- $option .= "\n<br>" if $option;
- $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{datefrom}, 1);
- }
- if ($form->{dateto}) {
- $href .= "&dateto=$form->{dateto}";
- $callback .= "&dateto=$form->{dateto}";
- if ($form->{datefrom}) {
- $option .= " ";
- } else {
- $option .= "\n<br>" if $option;
+ $form->{sort} = "transdate" unless $form->{sort};
+
+ GL->all_transactions( \%myconfig, \%$form );
+
+ $href =
+"$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+
+ $form->sort_order();
+
+ $callback =
+"$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+
+ %acctype = (
+ 'A' => $locale->text('Asset'),
+ 'L' => $locale->text('Liability'),
+ 'Q' => $locale->text('Equity'),
+ 'I' => $locale->text('Income'),
+ 'E' => $locale->text('Expense'),
+ );
+
+ $form->{title} = $locale->text('General Ledger');
+
+ $ml = ( $form->{category} =~ /(A|E)/ ) ? -1 : 1;
+
+ unless ( $form->{category} eq 'X' ) {
+ $form->{title} .=
+ " : " . $locale->text( $acctype{ $form->{category} } );
+ }
+ if ( $form->{accno} ) {
+ $href .= "&accno=" . $form->escape( $form->{accno} );
+ $callback .= "&accno=" . $form->escape( $form->{accno}, 1 );
+ $option =
+ $locale->text('Account')
+ . " : $form->{accno} $form->{account_description}";
+ }
+ if ( $form->{gifi_accno} ) {
+ $href .= "&gifi_accno=" . $form->escape( $form->{gifi_accno} );
+ $callback .= "&gifi_accno=" . $form->escape( $form->{gifi_accno}, 1 );
+ $option .= "\n<br>" if $option;
+ $option .=
+ $locale->text('GIFI')
+ . " : $form->{gifi_accno} $form->{gifi_account_description}";
+ }
+ if ( $form->{source} ) {
+ $href .= "&source=" . $form->escape( $form->{source} );
+ $callback .= "&source=" . $form->escape( $form->{source}, 1 );
+ $option .= "\n<br>" if $option;
+ $option .= $locale->text('Source') . " : $form->{source}";
+ }
+ if ( $form->{memo} ) {
+ $href .= "&memo=" . $form->escape( $form->{memo} );
+ $callback .= "&memo=" . $form->escape( $form->{memo}, 1 );
+ $option .= "\n<br>" if $option;
+ $option .= $locale->text('Memo') . " : $form->{memo}";
+ }
+ if ( $form->{reference} ) {
+ $href .= "&reference=" . $form->escape( $form->{reference} );
+ $callback .= "&reference=" . $form->escape( $form->{reference}, 1 );
+ $option .= "\n<br>" if $option;
+ $option .= $locale->text('Reference') . " : $form->{reference}";
+ }
+ if ( $form->{department} ) {
+ $href .= "&department=" . $form->escape( $form->{department} );
+ $callback .= "&department=" . $form->escape( $form->{department}, 1 );
+ ($department) = split /--/, $form->{department};
+ $option .= "\n<br>" if $option;
+ $option .= $locale->text('Department') . " : $department";
+ }
+
+ if ( $form->{description} ) {
+ $href .= "&description=" . $form->escape( $form->{description} );
+ $callback .= "&description=" . $form->escape( $form->{description}, 1 );
+ $option .= "\n<br>" if $option;
+ $option .= $locale->text('Description') . " : $form->{description}";
}
- $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{dateto}, 1);
- }
-
- if ($form->{amountfrom}) {
- $href .= "&amountfrom=$form->{amountfrom}";
- $callback .= "&amountfrom=$form->{amountfrom}";
- $option .= "\n<br>" if $option;
- $option .= $locale->text('Amount')." >= ".$form->format_amount(\%myconfig, $form->{amountfrom}, 2);
- }
- if ($form->{amountto}) {
- $href .= "&amountto=$form->{amountto}";
- $callback .= "&amountto=$form->{amountto}";
- if ($form->{amountfrom}) {
- $option .= " <= ";
- } else {
- $option .= "\n<br>" if $option;
- $option .= $locale->text('Amount')." <= ";
+ if ( $form->{notes} ) {
+ $href .= "&notes=" . $form->escape( $form->{notes} );
+ $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
+ $option .= "\n<br>" if $option;
+ $option .= $locale->text('Notes') . " : $form->{notes}";
+ }
+
+ if ( $form->{datefrom} ) {
+ $href .= "&datefrom=$form->{datefrom}";
+ $callback .= "&datefrom=$form->{datefrom}";
+ $option .= "\n<br>" if $option;
+ $option .=
+ $locale->text('From') . " "
+ . $locale->date( \%myconfig, $form->{datefrom}, 1 );
+ }
+ if ( $form->{dateto} ) {
+ $href .= "&dateto=$form->{dateto}";
+ $callback .= "&dateto=$form->{dateto}";
+ if ( $form->{datefrom} ) {
+ $option .= " ";
+ }
+ else {
+ $option .= "\n<br>" if $option;
+ }
+ $option .=
+ $locale->text('To') . " "
+ . $locale->date( \%myconfig, $form->{dateto}, 1 );
+ }
+
+ if ( $form->{amountfrom} ) {
+ $href .= "&amountfrom=$form->{amountfrom}";
+ $callback .= "&amountfrom=$form->{amountfrom}";
+ $option .= "\n<br>" if $option;
+ $option .=
+ $locale->text('Amount') . " >= "
+ . $form->format_amount( \%myconfig, $form->{amountfrom}, 2 );
+ }
+ if ( $form->{amountto} ) {
+ $href .= "&amountto=$form->{amountto}";
+ $callback .= "&amountto=$form->{amountto}";
+ if ( $form->{amountfrom} ) {
+ $option .= " <= ";
+ }
+ else {
+ $option .= "\n<br>" if $option;
+ $option .= $locale->text('Amount') . " <= ";
+ }
+ $option .= $form->format_amount( \%myconfig, $form->{amountto}, 2 );
+ }
+
+ @columns =
+ $form->sort_columns(
+ qw(transdate id reference description notes source memo debit credit accno gifi_accno department)
+ );
+ pop @columns if $form->{department};
+
+ if ( $form->{link} =~ /_paid/ ) {
+ @columns =
+ $form->sort_columns(
+ qw(transdate id reference description notes source memo cleared debit credit accno gifi_accno)
+ );
+ $form->{l_cleared} = "Y";
+ }
+
+ if ( $form->{accno} || $form->{gifi_accno} ) {
+ @columns = grep !/(accno|gifi_accno)/, @columns;
+ push @columns, "balance";
+ $form->{l_balance} = "Y";
+ }
+
+ 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";
+ }
}
- $option .= $form->format_amount(\%myconfig, $form->{amountto}, 2);
- }
-
-
- @columns = $form->sort_columns(qw(transdate id reference description notes source memo debit credit accno gifi_accno department));
- pop @columns if $form->{department};
-
- if ($form->{link} =~ /_paid/) {
- @columns = $form->sort_columns(qw(transdate id reference description notes source memo cleared debit credit accno gifi_accno));
- $form->{l_cleared} = "Y";
- }
-
- if ($form->{accno} || $form->{gifi_accno}) {
- @columns = grep !/(accno|gifi_accno)/, @columns;
- push @columns, "balance";
- $form->{l_balance} = "Y";
- }
-
-
- 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->{l_subtotal} eq 'Y') {
- $callback .= "&l_subtotal=Y";
- $href .= "&l_subtotal=Y";
- }
-
- $callback .= "&category=$form->{category}";
- $href .= "&category=$form->{category}";
-
- $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{reference} = "<th><a class=listheading href=$href&sort=reference>".$locale->text('Reference')."</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{description} = "<th><a class=listheading href=$href&sort=description>".$locale->text('Description')."</a></th>";
- $column_header{department} = "<th><a class=listheading href=$href&sort=department>".$locale->text('Department')."</a></th>";
- $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>";
- $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</th>";
- $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</th>";
- $column_header{accno} = "<th><a class=listheading href=$href&sort=accno>".$locale->text('Account')."</a></th>";
- $column_header{gifi_accno} = "<th><a class=listheading href=$href&sort=gifi_accno>".$locale->text('GIFI')."</a></th>";
- $column_header{balance} = "<th>".$locale->text('Balance')."</th>";
- $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;
-
- $form->header;
-
- print qq|
+
+ $callback .= "&category=$form->{category}";
+ $href .= "&category=$form->{category}";
+
+ $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{reference} =
+ "<th><a class=listheading href=$href&sort=reference>"
+ . $locale->text('Reference')
+ . "</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{description} =
+ "<th><a class=listheading href=$href&sort=description>"
+ . $locale->text('Description')
+ . "</a></th>";
+ $column_header{department} =
+ "<th><a class=listheading href=$href&sort=department>"
+ . $locale->text('Department')
+ . "</a></th>";
+ $column_header{notes} =
+ "<th class=listheading>" . $locale->text('Notes') . "</th>";
+ $column_header{debit} =
+ "<th class=listheading>" . $locale->text('Debit') . "</th>";
+ $column_header{credit} =
+ "<th class=listheading>" . $locale->text('Credit') . "</th>";
+ $column_header{accno} =
+ "<th><a class=listheading href=$href&sort=accno>"
+ . $locale->text('Account')
+ . "</a></th>";
+ $column_header{gifi_accno} =
+ "<th><a class=listheading href=$href&sort=gifi_accno>"
+ . $locale->text('GIFI')
+ . "</a></th>";
+ $column_header{balance} = "<th>" . $locale->text('Balance') . "</th>";
+ $column_header{cleared} = qq|<th>| . $locale->text('R') . qq|</th>|;
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -545,130 +657,167 @@ sub generate_report {
<tr class=listheading>
|;
- for (@column_index) { print "$column_header{$_}\n" }
+ for (@column_index) { print "$column_header{$_}\n" }
- print "
+ print "
</tr>
";
-
- # add sort to callback
- $form->{callback} = "$callback&sort=$form->{sort}";
- $callback = $form->escape($form->{callback});
-
- $cml = 1;
- # initial item for subtotals
- if (@{ $form->{GL} }) {
- $sameitem = $form->{GL}->[0]->{$form->{sort}};
- $cml = -1 if $form->{contra};
- }
-
- if (($form->{accno} || $form->{gifi_accno}) && $form->{balance}) {
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
- $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml * $cml, 2, 0)."</td>";
-
- $i++; $i %= 2;
- print qq|
+ # add sort to callback
+ $form->{callback} = "$callback&sort=$form->{sort}";
+ $callback = $form->escape( $form->{callback} );
+
+ $cml = 1;
+
+ # initial item for subtotals
+ if ( @{ $form->{GL} } ) {
+ $sameitem = $form->{GL}->[0]->{ $form->{sort} };
+ $cml = -1 if $form->{contra};
+ }
+
+ if ( ( $form->{accno} || $form->{gifi_accno} ) && $form->{balance} ) {
+
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+ $column_data{balance} = "<td align=right>"
+ . $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml,
+ 2, 0 )
+ . "</td>";
+
+ $i++;
+ $i %= 2;
+ print qq|
<tr class=listrow$i>
|;
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print qq|
</tr>
|;
- }
-
- # reverse href
- $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
- $form->sort_order();
- $href =~ s/direction=$form->{direction}/direction=$direction/;
+ }
- $i = 0;
- foreach $ref (@{ $form->{GL} }) {
+ # reverse href
+ $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
+ $form->sort_order();
+ $href =~ s/direction=$form->{direction}/direction=$direction/;
+
+ $i = 0;
+ foreach $ref ( @{ $form->{GL} } ) {
+
+ # if item ne sort print subtotal
+ if ( $form->{l_subtotal} eq 'Y' ) {
+ if ( $sameitem ne $ref->{ $form->{sort} } ) {
+ &gl_subtotal;
+ }
+ }
+
+ $form->{balance} += $ref->{amount};
+
+ $subtotaldebit += $ref->{debit};
+ $subtotalcredit += $ref->{credit};
+
+ $totaldebit += $ref->{debit};
+ $totalcredit += $ref->{credit};
+
+ $ref->{debit} =
+ $form->format_amount( \%myconfig, $ref->{debit}, 2, "&nbsp;" );
+ $ref->{credit} =
+ $form->format_amount( \%myconfig, $ref->{credit}, 2, "&nbsp;" );
+
+ for (qw(id transdate)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
+
+ $column_data{reference} =
+"<td><a href=$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{reference}</td>";
+
+ $ref->{notes} =~ s/\r?\n/<br>/g;
+ for (qw(description source memo notes department)) {
+ $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
+ }
+
+ $column_data{debit} = "<td align=right>$ref->{debit}</td>";
+ $column_data{credit} = "<td align=right>$ref->{credit}</td>";
+
+ $column_data{accno} =
+"<td><a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{accno}</a></td>";
+ $column_data{gifi_accno} =
+"<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a>&nbsp;</td>";
+ $column_data{balance} = "<td align=right>"
+ . $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml,
+ 2, 0 )
+ . "</td>";
+ $column_data{cleared} =
+ ( $ref->{cleared} ) ? "<td>*</td>" : "<td>&nbsp;</td>";
+
+ if ( $ref->{id} != $sameid ) {
+ $i++;
+ $i %= 2;
+ }
+ print "
+ <tr class=listrow$i>";
+ for (@column_index) { print "$column_data{$_}\n" }
+ print "</tr>";
- # if item ne sort print subtotal
- if ($form->{l_subtotal} eq 'Y') {
- if ($sameitem ne $ref->{$form->{sort}}) {
- &gl_subtotal;
- }
- }
-
- $form->{balance} += $ref->{amount};
-
- $subtotaldebit += $ref->{debit};
- $subtotalcredit += $ref->{credit};
-
- $totaldebit += $ref->{debit};
- $totalcredit += $ref->{credit};
-
- $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
- $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
-
- for (qw(id transdate)) { $column_data{$_} = "<td>$ref->{$_}</td>" }
-
- $column_data{reference} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{reference}</td>";
-
- $ref->{notes} =~ s/\r?\n/<br>/g;
- for (qw(description source memo notes department)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
-
- $column_data{debit} = "<td align=right>$ref->{debit}</td>";
- $column_data{credit} = "<td align=right>$ref->{credit}</td>";
-
- $column_data{accno} = "<td><a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{accno}</a></td>";
- $column_data{gifi_accno} = "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a>&nbsp;</td>";
- $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml * $cml, 2, 0)."</td>";
- $column_data{cleared} = ($ref->{cleared}) ? "<td>*</td>" : "<td>&nbsp;</td>";
-
- if ($ref->{id} != $sameid) {
- $i++; $i %= 2;
+ $sameid = $ref->{id};
}
- print "
- <tr class=listrow$i>";
- for (@column_index) { print "$column_data{$_}\n" }
- print "</tr>";
-
- $sameid = $ref->{id};
- }
+ &gl_subtotal if ( $form->{l_subtotal} eq 'Y' );
- &gl_subtotal if ($form->{l_subtotal} eq 'Y');
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+ $column_data{debit} =
+ "<th align=right class=listtotal>"
+ . $form->format_amount( \%myconfig, $totaldebit, 2, "&nbsp;" ) . "</th>";
+ $column_data{credit} =
+ "<th align=right class=listtotal>"
+ . $form->format_amount( \%myconfig, $totalcredit, 2, "&nbsp;" ) . "</th>";
+ $column_data{balance} =
+ "<th align=right class=listtotal>"
+ . $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml, 2, 0 )
+ . "</th>";
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;")."</th>";
- $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;")."</th>";
- $column_data{balance} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $form->{balance} * $ml * $cml, 2, 0)."</th>";
-
- print qq|
+ print qq|
<tr class=listtotal>
|;
- for (@column_index) { print "$column_data{$_}\n" }
-
- $i = 1;
- if ($myconfig{acs} !~ /General Ledger--General Ledger/) {
- $button{'General Ledger--Add Transaction'}{code} = qq|<button class="submit" type="submit" name="action" value="gl_transaction">|.$locale->text('GL Transaction').qq|</button> |;
- $button{'General Ledger--Add Transaction'}{order} = $i++;
- }
- if ($myconfig{acs} !~ /AR--AR/) {
- $button{'AR--Add Transaction'}{code} = qq|<button class="submit" type="submit" name="action" value="ar_transaction">|.$locale->text('AR Transaction').qq|</button> |;
- $button{'AR--Add Transaction'}{order} = $i++;
- $button{'AR--Sales Invoice'}{code} = qq|<button class="submit" type="submit" name="action" value="sales_invoice_">|.$locale->text('Sales Invoice').qq|</button> |;
- $button{'AR--Sales Invoice'}{order} = $i++;
- }
- if ($myconfig{acs} !~ /AP--AP/) {
- $button{'AP--Add Transaction'}{code} = qq|<button class="submit" type="submit" name="action" value="ap_transaction">|.$locale->text('AP Transaction').qq|</button> |;
- $button{'AP--Add Transaction'}{order} = $i++;
- $button{'AP--Vendor Invoice'}{code} = qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|.$locale->text('Vendor Invoice').qq|</button> |;
- $button{'AP--Vendor Invoice'}{order} = $i++;
- }
-
- foreach $item (split /;/, $myconfig{acs}) {
- delete $button{$item};
- }
-
- print qq|
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ $i = 1;
+ if ( $myconfig{acs} !~ /General Ledger--General Ledger/ ) {
+ $button{'General Ledger--Add Transaction'}{code} =
+qq|<button class="submit" type="submit" name="action" value="gl_transaction">|
+ . $locale->text('GL Transaction')
+ . qq|</button> |;
+ $button{'General Ledger--Add Transaction'}{order} = $i++;
+ }
+ if ( $myconfig{acs} !~ /AR--AR/ ) {
+ $button{'AR--Add Transaction'}{code} =
+qq|<button class="submit" type="submit" name="action" value="ar_transaction">|
+ . $locale->text('AR Transaction')
+ . qq|</button> |;
+ $button{'AR--Add Transaction'}{order} = $i++;
+ $button{'AR--Sales Invoice'}{code} =
+qq|<button class="submit" type="submit" name="action" value="sales_invoice_">|
+ . $locale->text('Sales Invoice')
+ . qq|</button> |;
+ $button{'AR--Sales Invoice'}{order} = $i++;
+ }
+ if ( $myconfig{acs} !~ /AP--AP/ ) {
+ $button{'AP--Add Transaction'}{code} =
+qq|<button class="submit" type="submit" name="action" value="ap_transaction">|
+ . $locale->text('AP Transaction')
+ . qq|</button> |;
+ $button{'AP--Add Transaction'}{order} = $i++;
+ $button{'AP--Vendor Invoice'}{code} =
+qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|
+ . $locale->text('Vendor Invoice')
+ . qq|</button> |;
+ $button{'AP--Vendor Invoice'}{order} = $i++;
+ }
+
+ foreach $item ( split /;/, $myconfig{acs} ) {
+ delete $button{$item};
+ }
+
+ print qq|
</tr>
</table>
</td>
@@ -683,18 +832,18 @@ sub generate_report {
<form method=post action=$form->{script}>
|;
- $form->hide_form(qw(callback path login sessionid));
-
- foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
- print $item->{code};
- }
+ $form->hide_form(qw(callback path login sessionid));
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
+ print $item->{code};
+ }
+
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
@@ -704,165 +853,183 @@ sub generate_report {
}
-
sub gl_subtotal {
-
- $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
- $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
-
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
- $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</td>";
- $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</td>";
+ $subtotaldebit =
+ $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" );
+ $subtotalcredit =
+ $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" );
+
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{debit} =
+ "<th align=right class=listsubtotal>$subtotaldebit</td>";
+ $column_data{credit} =
+ "<th align=right class=listsubtotal>$subtotalcredit</td>";
-
- print "<tr class=listsubtotal>";
- for (@column_index) { print "$column_data{$_}\n" }
- print "</tr>";
+ print "<tr class=listsubtotal>";
+ for (@column_index) { print "$column_data{$_}\n" }
+ print "</tr>";
- $subtotaldebit = 0;
- $subtotalcredit = 0;
+ $subtotaldebit = 0;
+ $subtotalcredit = 0;
- $sameitem = $ref->{$form->{sort}};
+ $sameitem = $ref->{ $form->{sort} };
}
-
sub update {
- if ($form->{transdate} ne $form->{oldtransdate}) {
- if ($form->{selectprojectnumber}) {
- $form->all_projects(\%myconfig, undef, $form->{transdate});
- if (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} = "<option>\n";
- for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
- $form->{selectprojectnumber} = $form->escape($form->{selectprojectnumber},1);
- }
+ if ( $form->{transdate} ne $form->{oldtransdate} ) {
+ if ( $form->{selectprojectnumber} ) {
+ $form->all_projects( \%myconfig, undef, $form->{transdate} );
+ if ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} = "<option>\n";
+ for ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} .=
+qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
+ }
+ $form->{selectprojectnumber} =
+ $form->escape( $form->{selectprojectnumber}, 1 );
+ }
+ }
+ $form->{oldtransdate} = $form->{transdate};
}
- $form->{oldtransdate} = $form->{transdate};
- }
-
- @a = ();
- $count = 0;
- @flds = qw(accno debit credit projectnumber fx_transaction source memo);
-
- for $i (1 .. $form->{rowcount}) {
- unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
- for (qw(debit credit)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- push @a, {};
- $j = $#a;
-
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
+
+ @a = ();
+ $count = 0;
+ @flds = qw(accno debit credit projectnumber fx_transaction source memo);
+
+ for $i ( 1 .. $form->{rowcount} ) {
+ unless ( ( $form->{"debit_$i"} eq "" )
+ && ( $form->{"credit_$i"} eq "" ) )
+ {
+ for (qw(debit credit)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ push @a, {};
+ $j = $#a;
+
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
}
- }
+ for $i ( 1 .. $count ) {
+ $j = $i - 1;
+ for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
+ }
- for $i (1 .. $count) {
- $j = $i - 1;
- for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
- }
+ for $i ( $count + 1 .. $form->{rowcount} ) {
+ for (@flds) { delete $form->{"${_}_$i"} }
+ }
- for $i ($count + 1 .. $form->{rowcount}) {
- for (@flds) { delete $form->{"${_}_$i"} }
- }
+ $form->{rowcount} = $count + 1;
- $form->{rowcount} = $count + 1;
+ &display_form;
- &display_form;
-
}
-
sub display_form {
- my ($init) = @_;
+ my ($init) = @_;
- &form_header;
- &display_rows($init);
- &form_footer;
+ &form_header;
+ &display_rows($init);
+ &form_footer;
}
-
sub display_rows {
- my ($init) = @_;
+ my ($init) = @_;
+
+ $form->{selectprojectnumber} =
+ $form->unescape( $form->{selectprojectnumber} )
+ if $form->{selectprojectnumber};
- $form->{selectprojectnumber} = $form->unescape($form->{selectprojectnumber}) if $form->{selectprojectnumber};
-
- $form->{totaldebit} = 0;
- $form->{totalcredit} = 0;
+ $form->{totaldebit} = 0;
+ $form->{totalcredit} = 0;
- for $i (1 .. $form->{rowcount}) {
+ for $i ( 1 .. $form->{rowcount} ) {
- $source = qq|
+ $source = qq|
<td><input name="source_$i" size=10 value="$form->{"source_$i"}"></td>|;
- $memo = qq|
+ $memo = qq|
<td><input name="memo_$i" value="$form->{"memo_$i"}"></td>|;
- if ($init) {
- $accno = qq|
+ if ($init) {
+ $accno = qq|
<td><select name="accno_$i">$form->{selectaccno}</select></td>|;
-
- if ($form->{selectprojectnumber}) {
- $project = qq|
+
+ if ( $form->{selectprojectnumber} ) {
+ $project = qq|
<td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
- }
-
- if ($form->{transfer}) {
- $fx_transaction = qq|
+ }
+
+ if ( $form->{transfer} ) {
+ $fx_transaction = qq|
<td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
|;
- }
-
- } else {
-
- $form->{totaldebit} += $form->{"debit_$i"};
- $form->{totalcredit} += $form->{"credit_$i"};
-
- for (qw(debit credit)) { $form->{"${_}_$i"} = ($form->{"${_}_$i"}) ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) : "" }
-
- if ($i < $form->{rowcount}) {
-
- $accno = qq|<td>$form->{"accno_$i"}</td>|;
-
- if ($form->{selectprojectnumber}) {
- $form->{"projectnumber_$i"} = "" if $form->{selectprojectnumber} !~ /$form->{"projectnumber_$i"}/;
-
- $project = $form->{"projectnumber_$i"};
- $project =~ s/--.*//;
- $project = qq|<td>$project</td>|;
- }
-
- if ($form->{transfer}) {
- $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
- $x = ($checked) ? "x" : "";
- $fx_transaction = qq|
+ }
+
+ }
+ else {
+
+ $form->{totaldebit} += $form->{"debit_$i"};
+ $form->{totalcredit} += $form->{"credit_$i"};
+
+ for (qw(debit credit)) {
+ $form->{"${_}_$i"} =
+ ( $form->{"${_}_$i"} )
+ ? $form->format_amount( \%myconfig, $form->{"${_}_$i"}, 2 )
+ : "";
+ }
+
+ if ( $i < $form->{rowcount} ) {
+
+ $accno = qq|<td>$form->{"accno_$i"}</td>|;
+
+ if ( $form->{selectprojectnumber} ) {
+ $form->{"projectnumber_$i"} = ""
+ if $form->{selectprojectnumber} !~
+ /$form->{"projectnumber_$i"}/;
+
+ $project = $form->{"projectnumber_$i"};
+ $project =~ s/--.*//;
+ $project = qq|<td>$project</td>|;
+ }
+
+ if ( $form->{transfer} ) {
+ $checked = ( $form->{"fx_transaction_$i"} ) ? "1" : "";
+ $x = ($checked) ? "x" : "";
+ $fx_transaction = qq|
<td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
|;
- }
-
- $form->hide_form("accno_$i", "projectnumber_$i");
-
- } else {
-
- $accno = qq|
+ }
+
+ $form->hide_form( "accno_$i", "projectnumber_$i" );
+
+ }
+ else {
+
+ $accno = qq|
<td><select name="accno_$i">$form->{selectaccno}</select></td>|;
- if ($form->{selectprojectnumber}) {
- $project = qq|
+ if ( $form->{selectprojectnumber} ) {
+ $project = qq|
<td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
- }
-
- if ($form->{transfer}) {
- $fx_transaction = qq|
+ }
+
+ if ( $form->{transfer} ) {
+ $fx_transaction = qq|
<td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
|;
- }
- }
- }
-
- print qq|<tr valign=top>
+ }
+ }
+ }
+
+ print qq|<tr valign=top>
$accno
$fx_transaction
<td><input name="debit_$i" size=12 value="$form->{"debit_$i"}" accesskey=$i></td>
@@ -873,80 +1040,90 @@ sub display_rows {
</tr>
|;
- }
+ }
- $form->hide_form(qw(rowcount selectaccno pos_adjust));
-
- print qq|
-<input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">|;
+ $form->hide_form(qw(rowcount selectaccno pos_adjust));
-}
+ print qq|
+<input type=hidden name=selectprojectnumber value="|
+ . $form->escape( $form->{selectprojectnumber}, 1 ) . qq|">|;
+}
sub form_header {
- $title = $form->{title};
- if ($form->{transfer}) {
- $form->{title} = $locale->text("$title Cash Transfer Transaction");
- } else {
- $form->{title} = $locale->text("$title General Ledger Transaction");
- }
-
-# $locale->text('Add Cash Transfer Transaction')
-# $locale->text('Edit Cash Transfer Transaction')
-# $locale->text('Add General Ledger Transaction')
-# $locale->text('Edit General Ledger Transaction')
-
-
- $form->{selectdepartment} = $form->unescape($form->{selectdepartment});
- $form->{selectdepartment} =~ s/ selected//;
- $form->{selectdepartment} =~ s/(<option value="\Q$form->{department}\E")/$1 selected/;
-
- for (qw(reference description notes)) { $form->{$_} = $form->quote($form->{$_}) }
-
- if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
- $description = qq|<textarea name=description rows=$rows cols=50 wrap=soft>$form->{description}</textarea>|;
- } else {
- $description = qq|<input name=description size=50 value="$form->{description}">|;
- }
-
- if (($rows = $form->numtextrows($form->{notes}, 50)) > 1) {
- $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
- } else {
- $notes = qq|<input name=notes size=50 value="$form->{notes}">|;
- }
-
- $department = qq|
+ $title = $form->{title};
+ if ( $form->{transfer} ) {
+ $form->{title} = $locale->text("$title Cash Transfer Transaction");
+ }
+ else {
+ $form->{title} = $locale->text("$title General Ledger Transaction");
+ }
+
+ # $locale->text('Add Cash Transfer Transaction')
+ # $locale->text('Edit Cash Transfer Transaction')
+ # $locale->text('Add General Ledger Transaction')
+ # $locale->text('Edit General Ledger Transaction')
+
+ $form->{selectdepartment} = $form->unescape( $form->{selectdepartment} );
+ $form->{selectdepartment} =~ s/ selected//;
+ $form->{selectdepartment} =~
+ s/(<option value="\Q$form->{department}\E")/$1 selected/;
+
+ for (qw(reference description notes)) {
+ $form->{$_} = $form->quote( $form->{$_} );
+ }
+
+ if ( ( $rows = $form->numtextrows( $form->{description}, 50 ) ) > 1 ) {
+ $description =
+qq|<textarea name=description rows=$rows cols=50 wrap=soft>$form->{description}</textarea>|;
+ }
+ else {
+ $description =
+ qq|<input name=description size=50 value="$form->{description}">|;
+ }
+
+ if ( ( $rows = $form->numtextrows( $form->{notes}, 50 ) ) > 1 ) {
+ $notes =
+qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
+ }
+ else {
+ $notes = qq|<input name=notes size=50 value="$form->{notes}">|;
+ }
+
+ $department = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Department').qq|</th>
+ <th align=right nowrap>| . $locale->text('Department') . qq|</th>
<td><select name=department>$form->{selectdepartment}</select></td>
- <input type=hidden name=selectdepartment value="|.$form->escape($form->{selectdepartment},1).qq|">
+ <input type=hidden name=selectdepartment value="|
+ . $form->escape( $form->{selectdepartment}, 1 ) . qq|">
</tr>
| if $form->{selectdepartment};
- $project = qq|
- <th class=listheading>|.$locale->text('Project').qq|</th>
+ $project = qq|
+ <th class=listheading>| . $locale->text('Project') . qq|</th>
| if $form->{selectprojectnumber};
- if ($form->{transfer}) {
- $fx_transaction = qq|
- <th class=listheading>|.$locale->text('FX').qq|</th>
+ if ( $form->{transfer} ) {
+ $fx_transaction = qq|
+ <th class=listheading>| . $locale->text('FX') . qq|</th>
|;
- }
+ }
+
+ $focus = ( $form->{focus} ) ? $form->{focus} : "debit_$form->{rowcount}";
- $focus = ($form->{focus}) ? $form->{focus} : "debit_$form->{rowcount}";
-
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body onload="document.forms[0].${focus}.focus()" />
<form method=post action=$form->{script}>
|;
- $form->hide_form(qw(id transfer selectaccno closedto locked oldtransdate recurring));
-
- print qq|
+ $form->hide_form(
+ qw(id transfer selectaccno closedto locked oldtransdate recurring));
+
+ print qq|
<input type=hidden name=title value="$title">
<table width=100%>
@@ -958,18 +1135,18 @@ sub form_header {
<td>
<table>
<tr>
- <th align=right>|.$locale->text('Reference').qq|</th>
+ <th align=right>| . $locale->text('Reference') . qq|</th>
<td><input name=reference size=20 value="$form->{reference}"></td>
- <th align=right>|.$locale->text('Date').qq|</th>
+ <th align=right>| . $locale->text('Date') . qq|</th>
<td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
</tr>
$department
<tr>
- <th align=right>|.$locale->text('Description').qq|</th>
+ <th align=right>| . $locale->text('Description') . qq|</th>
<td colspan=3>$description</td>
</tr>
<tr>
- <th align=right>|.$locale->text('Notes').qq|</th>
+ <th align=right>| . $locale->text('Notes') . qq|</th>
<td colspan=3>$notes</td>
</tr>
</table>
@@ -979,35 +1156,36 @@ sub form_header {
<td>
<table width=100%>
<tr class=listheading>
- <th class=listheading>|.$locale->text('Account').qq|</th>
+ <th class=listheading>| . $locale->text('Account') . qq|</th>
$fx_transaction
- <th class=listheading>|.$locale->text('Debit').qq|</th>
- <th class=listheading>|.$locale->text('Credit').qq|</th>
- <th class=listheading>|.$locale->text('Source').qq|</th>
- <th class=listheading>|.$locale->text('Memo').qq|</th>
+ <th class=listheading>| . $locale->text('Debit') . qq|</th>
+ <th class=listheading>| . $locale->text('Credit') . qq|</th>
+ <th class=listheading>| . $locale->text('Source') . qq|</th>
+ <th class=listheading>| . $locale->text('Memo') . qq|</th>
$project
</tr>
|;
}
-
sub form_footer {
- for (qw(totaldebit totalcredit)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, "&nbsp;") }
-
+ for (qw(totaldebit totalcredit)) {
+ $form->{$_} =
+ $form->format_amount( \%myconfig, $form->{$_}, 2, "&nbsp;" );
+ }
- $project = qq|
+ $project = qq|
<th>&nbsp;</th>
| if $form->{selectprojectnumber};
- if ($form->{transfer}) {
- $fx_transaction = qq|
+ if ( $form->{transfer} ) {
+ $fx_transaction = qq|
<th>&nbsp;</th>
|;
- }
-
- print qq|
+ }
+
+ print qq|
<tr class=listtotal>
<th>&nbsp;</th>
$fx_transaction
@@ -1026,142 +1204,161 @@ sub form_footer {
</table>
|;
- $form->hide_form(qw(path login sessionid callback));
-
- $transdate = $form->datetonum(\%myconfig, $form->{transdate});
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
-
-# type=submit $locale->text('Update')
-# type=submit $locale->text('Post')
-# type=submit $locale->text('Schedule')
-# type=submit $locale->text('Post as new')
-# type=submit $locale->text('Delete')
-
- if (! $form->{readonly}) {
-
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- 'post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
- 'post_as_new' => { ndx => 6, key => 'N', value => $locale->text('Post as new') },
- 'schedule' => { ndx => 7, key => 'H', value => $locale->text('Schedule') },
- 'delete' => { ndx => 8, key => 'D', value => $locale->text('Delete') },
- );
-
- %a = ();
-
- if ($form->{id}) {
- for ('update', 'post_as_new', 'schedule') { $a{$_} = 1 }
-
- if (! $form->{locked}) {
- if ($transdate > $closedto) {
- for ('post', 'delete') { $a{$_} = 1 }
- }
- }
-
- } else {
- if ($transdate > $closedto) {
- for ("update", "post", "schedule") { $a{$_} = 1 }
- }
+ $form->hide_form(qw(path login sessionid callback));
+
+ $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
+ $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
+
+ # type=submit $locale->text('Update')
+ # type=submit $locale->text('Post')
+ # type=submit $locale->text('Schedule')
+ # type=submit $locale->text('Post as new')
+ # type=submit $locale->text('Delete')
+
+ if ( !$form->{readonly} ) {
+
+ %button = (
+ 'update' =>
+ { ndx => 1, key => 'U', value => $locale->text('Update') },
+ 'post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
+ 'post_as_new' =>
+ { ndx => 6, key => 'N', value => $locale->text('Post as new') },
+ 'schedule' =>
+ { ndx => 7, key => 'H', value => $locale->text('Schedule') },
+ 'delete' =>
+ { ndx => 8, key => 'D', value => $locale->text('Delete') },
+ );
+
+ %a = ();
+
+ if ( $form->{id} ) {
+ for ( 'update', 'post_as_new', 'schedule' ) { $a{$_} = 1 }
+
+ if ( !$form->{locked} ) {
+ if ( $transdate > $closedto ) {
+ for ( 'post', 'delete' ) { $a{$_} = 1 }
+ }
+ }
+
+ }
+ else {
+ if ( $transdate > $closedto ) {
+ for ( "update", "post", "schedule" ) { $a{$_} = 1 }
+ }
+ }
+
+ for ( keys %button ) { delete $button{$_} if !$a{$_} }
+ for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
+ {
+ $form->print_button( \%button, $_ );
+ }
+
+ }
+
+ if ( $form->{recurring} ) {
+ print qq|<div align=right>| . $locale->text('Scheduled') . qq|</div>|;
}
- for (keys %button) { delete $button{$_} if ! $a{$_} }
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
-
- }
-
- if ($form->{recurring}) {
- print qq|<div align=right>|.$locale->text('Scheduled').qq|</div>|;
- }
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
</form>
</body>
</html>
|;
-
-}
+}
sub delete {
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
|;
- delete $form->{action};
+ delete $form->{action};
- $form->hide_form;
-
- print qq|
-<h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
+ $form->hide_form;
-<h4>|.$locale->text('Are you sure you want to delete Transaction [_1]', $form->{reference}).qq|</h4>
+ print qq|
+<h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
+
+<h4>|
+ . $locale->text( 'Are you sure you want to delete Transaction [_1]',
+ $form->{reference} )
+ . qq|</h4>
-<button name="action" class="submit" type="submit" value="yes">|.$locale->text('Yes').qq|</button>
+<button name="action" class="submit" type="submit" value="yes">|
+ . $locale->text('Yes')
+ . qq|</button>
</form>
|;
}
-
sub yes {
- if (GL->delete_transaction(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Transaction deleted!'));
- } else {
- $form->error($locale->text('Cannot delete transaction!'));
- }
-
-}
+ if ( GL->delete_transaction( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Transaction deleted!') );
+ }
+ else {
+ $form->error( $locale->text('Cannot delete transaction!') );
+ }
+}
sub post {
- $form->isblank("transdate", $locale->text('Transaction Date missing!'));
+ $form->isblank( "transdate", $locale->text('Transaction Date missing!') );
+
+ $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
+ $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
+
+ $form->error(
+ $locale->text('Cannot post transaction for a closed period!') )
+ if ( $transdate <= $closedto );
+
+ # add up debits and credits
+ for $i ( 1 .. $form->{rowcount} ) {
+ $dr = $form->parse_amount( \%myconfig, $form->{"debit_$i"} );
+ $cr = $form->parse_amount( \%myconfig, $form->{"credit_$i"} );
+
+ if ( $dr && $cr ) {
+ $form->error(
+ $locale->text(
+'Cannot post transaction with a debit and credit entry for the same account!'
+ )
+ );
+ }
+ $debit += $dr;
+ $credit += $cr;
+ }
- $transdate = $form->datetonum(\%myconfig, $form->{transdate});
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
+ if ( $form->round_amount( $debit, 2 ) != $form->round_amount( $credit, 2 ) )
+ {
+ $form->error( $locale->text('Out of balance transaction!') );
+ }
- $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
+ if ( !$form->{repost} ) {
+ if ( $form->{id} ) {
+ &repost;
+ exit;
+ }
+ }
- # add up debits and credits
- for $i (1 .. $form->{rowcount}) {
- $dr = $form->parse_amount(\%myconfig, $form->{"debit_$i"});
- $cr = $form->parse_amount(\%myconfig, $form->{"credit_$i"});
-
- if ($dr && $cr) {
- $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
+ if ( GL->post_transaction( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Transaction posted!') );
}
- $debit += $dr;
- $credit += $cr;
- }
-
- if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
- $form->error($locale->text('Out of balance transaction!'));
- }
-
- if (! $form->{repost}) {
- if ($form->{id}) {
- &repost;
- exit;
+ else {
+ $form->error( $locale->text('Cannot post transaction!') );
}
- }
-
- if (GL->post_transaction(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Transaction posted!'));
- } else {
- $form->error($locale->text('Cannot post transaction!'));
- }
-
-}
+}
diff --git a/bin/hr.pl b/bin/hr.pl
index 160b4c87..78b098c0 100644
--- a/bin/hr.pl
+++ b/bin/hr.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -43,59 +43,88 @@ use LedgerSMB::HR;
use LedgerSMB::User;
1;
-# end of main
-
+# end of main
sub add {
- $label = "Add ".ucfirst $form->{db};
- $form->{title} = $locale->text($label);
+ $label = "Add " . ucfirst $form->{db};
+ $form->{title} = $locale->text($label);
- $form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
+ $form->{callback} =
+"$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
- &{ "$form->{db}_links" };
-
-}
+ &{"$form->{db}_links"};
+}
-sub search { &{ "search_$form->{db}" } };
-
+sub search { &{"search_$form->{db}"} }
sub search_employee {
- $form->{title} = $locale->text('Employees');
-
- @a = ();
-
- push @a, qq|<input name="l_ndx" type=checkbox class=checkbox value=Y> |.$locale->text('Pos');
- push @a, qq|<input name="l_id" type=checkbox class=checkbox value=Y> |.$locale->text('ID');
- push @a, qq|<input name="l_employeenumber" type=checkbox class=checkbox value=Y checked> |.$locale->text('Employee Number');
- push @a, qq|<input name="l_name" type=checkbox class=checkbox value=Y checked> |.$locale->text('Employee Name');
- push @a, qq|<input name="l_address" type=checkbox class=checkbox value=Y> |.$locale->text('Address');
- push @a, qq|<input name="l_city" type=checkbox class=checkbox value=Y> |.$locale->text('City');
- push @a, qq|<input name="l_state" type=checkbox class=checkbox value=Y> |.$locale->text('State/Province');
- push @a, qq|<input name="l_zipcode" type=checkbox class=checkbox value=Y> |.$locale->text('Zip/Postal Code');
- push @a, qq|<input name="l_country" type=checkbox class=checkbox value=Y> |.$locale->text('Country');
- push @a, qq|<input name="l_workphone" type=checkbox class=checkbox value=Y checked> |.$locale->text('Work Phone');
- push @a, qq|<input name="l_homephone" type=checkbox class=checkbox value=Y checked> |.$locale->text('Home Phone');
- push @a, qq|<input name="l_startdate" type=checkbox class=checkbox value=Y checked> |.$locale->text('Startdate');
- push @a, qq|<input name="l_enddate" type=checkbox class=checkbox value=Y checked> |.$locale->text('Enddate');
- push @a, qq|<input name="l_sales" type=checkbox class=checkbox value=Y> |.$locale->text('Sales');
- push @a, qq|<input name="l_manager" type=checkbox class=checkbox value=Y> |.$locale->text('Manager');
- push @a, qq|<input name="l_role" type=checkbox class=checkbox value=Y checked> |.$locale->text('Role');
- push @a, qq|<input name="l_login" type=checkbox class=checkbox value=Y checked> |.$locale->text('Login');
- push @a, qq|<input name="l_email" type=checkbox class=checkbox value=Y> |.$locale->text('E-mail');
- push @a, qq|<input name="l_ssn" type=checkbox class=checkbox value=Y> |.$locale->text('SSN');
- push @a, qq|<input name="l_dob" type=checkbox class=checkbox value=Y> |.$locale->text('DOB');
- push @a, qq|<input name="l_iban" type=checkbox class=checkbox value=Y> |.$locale->text('IBAN');
- push @a, qq|<input name="l_bic" type=checkbox class=checkbox value=Y> |.$locale->text('BIC');
- push @a, qq|<input name="l_notes" type=checkbox class=checkbox value=Y> |.$locale->text('Notes');
-
+ $form->{title} = $locale->text('Employees');
+
+ @a = ();
+
+ push @a, qq|<input name="l_ndx" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Pos');
+ push @a, qq|<input name="l_id" type=checkbox class=checkbox value=Y> |
+ . $locale->text('ID');
+ push @a,
+qq|<input name="l_employeenumber" type=checkbox class=checkbox value=Y checked> |
+ . $locale->text('Employee Number');
+ push @a,
+ qq|<input name="l_name" type=checkbox class=checkbox value=Y checked> |
+ . $locale->text('Employee Name');
+ push @a, qq|<input name="l_address" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Address');
+ push @a, qq|<input name="l_city" type=checkbox class=checkbox value=Y> |
+ . $locale->text('City');
+ push @a, qq|<input name="l_state" type=checkbox class=checkbox value=Y> |
+ . $locale->text('State/Province');
+ push @a, qq|<input name="l_zipcode" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Zip/Postal Code');
+ push @a, qq|<input name="l_country" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Country');
+ push @a,
+qq|<input name="l_workphone" type=checkbox class=checkbox value=Y checked> |
+ . $locale->text('Work Phone');
+ push @a,
+qq|<input name="l_homephone" type=checkbox class=checkbox value=Y checked> |
+ . $locale->text('Home Phone');
+ push @a,
+qq|<input name="l_startdate" type=checkbox class=checkbox value=Y checked> |
+ . $locale->text('Startdate');
+ push @a,
+ qq|<input name="l_enddate" type=checkbox class=checkbox value=Y checked> |
+ . $locale->text('Enddate');
+ push @a, qq|<input name="l_sales" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Sales');
+ push @a, qq|<input name="l_manager" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Manager');
+ push @a,
+ qq|<input name="l_role" type=checkbox class=checkbox value=Y checked> |
+ . $locale->text('Role');
+ push @a,
+ qq|<input name="l_login" type=checkbox class=checkbox value=Y checked> |
+ . $locale->text('Login');
+ push @a, qq|<input name="l_email" type=checkbox class=checkbox value=Y> |
+ . $locale->text('E-mail');
+ push @a, qq|<input name="l_ssn" type=checkbox class=checkbox value=Y> |
+ . $locale->text('SSN');
+ push @a, qq|<input name="l_dob" type=checkbox class=checkbox value=Y> |
+ . $locale->text('DOB');
+ push @a, qq|<input name="l_iban" type=checkbox class=checkbox value=Y> |
+ . $locale->text('IBAN');
+ push @a, qq|<input name="l_bic" type=checkbox class=checkbox value=Y> |
+ . $locale->text('BIC');
+ push @a, qq|<input name="l_notes" type=checkbox class=checkbox value=Y> |
+ . $locale->text('Notes');
+
+ $form->header;
- $form->header;
-
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -109,45 +138,54 @@ sub search_employee {
<td>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Employee Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('Employee Number') . qq|</th>
<td colspan=3><input name=employeenumber size=20></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Employee Name').qq|</th>
+ <th align=right nowrap>| . $locale->text('Employee Name') . qq|</th>
<td colspan=3><input name=name size=35></td>
</tr>
<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>
+ <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>
<tr valign=top>
- <th align=right nowrap>|.$locale->text('Notes').qq|</th>
+ <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
<td colspan=3><input name=notes size=40></td>
</tr>
<tr>
<td></td>
- <td colspan=3><input name=status class=radio type=radio value=all checked>&nbsp;|.$locale->text('All').qq|
- <input name=status class=radio type=radio value=active>&nbsp;|.$locale->text('Active').qq|
- <input name=status class=radio type=radio value=inactive>&nbsp;|.$locale->text('Inactive').qq|
- <input name=status class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned').qq|
- <input name=sales class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Sales').qq|
+ <td colspan=3><input name=status class=radio type=radio value=all checked>&nbsp;|
+ . $locale->text('All') . qq|
+ <input name=status class=radio type=radio value=active>&nbsp;|
+ . $locale->text('Active') . qq|
+ <input name=status class=radio type=radio value=inactive>&nbsp;|
+ . $locale->text('Inactive') . qq|
+ <input name=status class=radio type=radio value=orphaned>&nbsp;|
+ . $locale->text('Orphaned') . qq|
+ <input name=sales class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('Sales') . qq|
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
+ <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
<td colspan=3>
<table>
|;
- while (@a) {
- print qq|<tr>\n|;
- for (1 .. 5) {
- print qq|<td nowrap>|. shift @a;
- print qq|</td>\n|;
+ while (@a) {
+ print qq|<tr>\n|;
+ for ( 1 .. 5 ) {
+ print qq|<td nowrap>| . shift @a;
+ print qq|</td>\n|;
+ }
+ print qq|</tr>\n|;
}
- print qq|</tr>\n|;
- }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -162,136 +200,208 @@ sub search_employee {
<input type=hidden name=nextsub value=list_employees>
|;
- $form->hide_form(qw(db path login sessionid));
+ $form->hide_form(qw(db path login sessionid));
- print qq|
+ print qq|
<br>
-<button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+<button type="submit" class="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</body>
</html>
|;
}
-
sub list_employees {
- HR->employees(\%myconfig, \%$form);
-
- $href = "$form->{script}?action=list_employees&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
-
- $form->sort_order();
+ HR->employees( \%myconfig, \%$form );
+
+ $href =
+"$form->{script}?action=list_employees&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
+
+ $form->sort_order();
+
+ $callback =
+"$form->{script}?action=list_employees&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
- $callback = "$form->{script}?action=list_employees&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
-
- @columns = $form->sort_columns(qw(id employeenumber name address city state zipcode country workphone homephone email startdate enddate ssn dob iban bic sales role manager login notes));
- unshift @columns, "ndx";
+ @columns =
+ $form->sort_columns(
+ qw(id employeenumber name address city state zipcode country workphone homephone email startdate enddate ssn dob iban bic sales role manager login notes)
+ );
+ unshift @columns, "ndx";
- foreach $item (@columns) {
- if ($form->{"l_$item"} eq "Y") {
- push @column_index, $item;
+ 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";
+ # add column to href and callback
+ $callback .= "&l_$item=Y";
+ $href .= "&l_$item=Y";
+ }
+ }
+
+ %role = (
+ user => $locale->text('User'),
+ supervisor => $locale->text('Supervisor'),
+ manager => $locale->text('Manager'),
+ admin => $locale->text('Administrator')
+ );
+
+ $option = $locale->text('All');
+
+ if ( $form->{status} eq 'sales' ) {
+ $option = $locale->text('Sales');
+ }
+ if ( $form->{status} eq 'orphaned' ) {
+ $option = $locale->text('Orphaned');
}
- }
-
- %role = ( user => $locale->text('User'),
- supervisor => $locale->text('Supervisor'),
- manager => $locale->text('Manager'),
- admin => $locale->text('Administrator')
- );
-
- $option = $locale->text('All');
-
- if ($form->{status} eq 'sales') {
- $option = $locale->text('Sales');
- }
- if ($form->{status} eq 'orphaned') {
- $option = $locale->text('Orphaned');
- }
- if ($form->{status} eq 'active') {
- $option = $locale->text('Active');
- }
- if ($form->{status} eq 'inactive') {
- $option = $locale->text('Inactive');
- }
-
- if ($form->{employeenumber}) {
- $callback .= "&employeenumber=".$form->escape($form->{employeenumber},1);
- $href .= "&employeenumber=".$form->escape($form->{employeenumber});
- $option .= "\n<br>".$locale->text('Employee Number')." : $form->{employeenumber}";
- }
- if ($form->{name}) {
- $callback .= "&name=".$form->escape($form->{name},1);
- $href .= "&name=".$form->escape($form->{name});
- $option .= "\n<br>".$locale->text('Employee Name')." : $form->{name}";
- }
- if ($form->{startdatefrom}) {
- $callback .= "&startdatefrom=$form->{startdatefrom}";
- $href .= "&startdatefrom=$form->{startdatefrom}";
- $fromdate = $locale->date(\%myconfig, $form->{startdatefrom}, 1);
- }
- if ($form->{startdateto}) {
- $callback .= "&startdateto=$form->{startdateto}";
- $href .= "&startdateto=$form->{startdateto}";
- $todate = $locale->date(\%myconfig, $form->{startdateto}, 1);
- }
- if ($fromdate || $todate) {
- $option .= "\n<br>".$locale->text('Startdate')." $fromdate - $todate";
- }
-
- if ($form->{notes}) {
- $callback .= "&notes=".$form->escape($form->{notes},1);
- $href .= "&notes=".$form->escape($form->{notes});
- $option .= "\n<br>" if $option;
- $option .= $locale->text('Notes')." : $form->{notes}";
- }
-
- $form->{callback} = "$callback&sort=$form->{sort}";
- $callback = $form->escape($form->{callback});
-
- $column_header{ndx} = qq|<th class=listheading>&nbsp;</th>|;
- $column_header{id} = qq|<th class=listheading>|.$locale->text('ID').qq|</th>|;
- $column_header{employeenumber} = qq|<th><a class=listheading href=$href&sort=employeenumber>|.$locale->text('Number').qq|</a></th>|;
- $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|;
- $column_header{manager} = qq|<th><a class=listheading href=$href&sort=manager>|.$locale->text('Manager').qq|</a></th>|;
- $column_header{address} = qq|<th class=listheading>|.$locale->text('Address').qq|</a></th>|;
- $column_header{city} = qq|<th><a class=listheading href=$href&sort=city>|.$locale->text('City').qq|</a></th>|;
- $column_header{state} = qq|<th><a class=listheading href=$href&sort=state>|.$locale->text('State/Province').qq|</a></th>|;
- $column_header{zipcode} = qq|<th><a class=listheading href=$href&sort=zipcode>|.$locale->text('Zip/Postal Code').qq|</a></th>|;
- $column_header{country} = qq|<th><a class=listheading href=$href&sort=country>|.$locale->text('Country').qq|</a></th>|;
- $column_header{workphone} = qq|<th><a class=listheading href=$href&sort=workphone>|.$locale->text('Work Phone').qq|</a></th>|;
- $column_header{homephone} = qq|<th><a class=listheading href=$href&sort=homephone>|.$locale->text('Home Phone').qq|</a></th>|;
-
- $column_header{startdate} = qq|<th><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|;
- $column_header{enddate} = qq|<th><a class=listheading href=$href&sort=enddate>|.$locale->text('Enddate').qq|</a></th>|;
- $column_header{notes} = qq|<th><a class=listheading href=$href&sort=notes>|.$locale->text('Notes').qq|</a></th>|;
- $column_header{role} = qq|<th><a class=listheading href=$href&sort=role>|.$locale->text('Role').qq|</a></th>|;
- $column_header{login} = qq|<th><a class=listheading href=$href&sort=login>|.$locale->text('Login').qq|</a></th>|;
-
- $column_header{sales} = qq|<th class=listheading>|.$locale->text('S').qq|</th>|;
- $column_header{email} = qq|<th><a class=listheading href=$href&sort=email>|.$locale->text('E-mail').qq|</a></th>|;
- $column_header{ssn} = qq|<th><a class=listheading href=$href&sort=ssn>|.$locale->text('SSN').qq|</a></th>|;
- $column_header{dob} = qq|<th><a class=listheading href=$href&sort=dob>|.$locale->text('DOB').qq|</a></th>|;
- $column_header{iban} = qq|<th><a class=listheading href=$href&sort=iban>|.$locale->text('IBAN').qq|</a></th>|;
- $column_header{bic} = qq|<th><a class=listheading href=$href&sort=bic>|.$locale->text('BIC').qq|</a></th>|;
-
- $form->{title} = $locale->text('Employees');
-
- $form->header;
-
- print qq|
+ if ( $form->{status} eq 'active' ) {
+ $option = $locale->text('Active');
+ }
+ if ( $form->{status} eq 'inactive' ) {
+ $option = $locale->text('Inactive');
+ }
+
+ if ( $form->{employeenumber} ) {
+ $callback .=
+ "&employeenumber=" . $form->escape( $form->{employeenumber}, 1 );
+ $href .= "&employeenumber=" . $form->escape( $form->{employeenumber} );
+ $option .= "\n<br>"
+ . $locale->text('Employee Number')
+ . " : $form->{employeenumber}";
+ }
+ if ( $form->{name} ) {
+ $callback .= "&name=" . $form->escape( $form->{name}, 1 );
+ $href .= "&name=" . $form->escape( $form->{name} );
+ $option .=
+ "\n<br>" . $locale->text('Employee Name') . " : $form->{name}";
+ }
+ if ( $form->{startdatefrom} ) {
+ $callback .= "&startdatefrom=$form->{startdatefrom}";
+ $href .= "&startdatefrom=$form->{startdatefrom}";
+ $fromdate = $locale->date( \%myconfig, $form->{startdatefrom}, 1 );
+ }
+ if ( $form->{startdateto} ) {
+ $callback .= "&startdateto=$form->{startdateto}";
+ $href .= "&startdateto=$form->{startdateto}";
+ $todate = $locale->date( \%myconfig, $form->{startdateto}, 1 );
+ }
+ if ( $fromdate || $todate ) {
+ $option .=
+ "\n<br>" . $locale->text('Startdate') . " $fromdate - $todate";
+ }
+
+ if ( $form->{notes} ) {
+ $callback .= "&notes=" . $form->escape( $form->{notes}, 1 );
+ $href .= "&notes=" . $form->escape( $form->{notes} );
+ $option .= "\n<br>" if $option;
+ $option .= $locale->text('Notes') . " : $form->{notes}";
+ }
+
+ $form->{callback} = "$callback&sort=$form->{sort}";
+ $callback = $form->escape( $form->{callback} );
+
+ $column_header{ndx} = qq|<th class=listheading>&nbsp;</th>|;
+ $column_header{id} =
+ qq|<th class=listheading>| . $locale->text('ID') . qq|</th>|;
+ $column_header{employeenumber} =
+ qq|<th><a class=listheading href=$href&sort=employeenumber>|
+ . $locale->text('Number')
+ . qq|</a></th>|;
+ $column_header{name} =
+ qq|<th><a class=listheading href=$href&sort=name>|
+ . $locale->text('Name')
+ . qq|</a></th>|;
+ $column_header{manager} =
+ qq|<th><a class=listheading href=$href&sort=manager>|
+ . $locale->text('Manager')
+ . qq|</a></th>|;
+ $column_header{address} =
+ qq|<th class=listheading>| . $locale->text('Address') . qq|</a></th>|;
+ $column_header{city} =
+ qq|<th><a class=listheading href=$href&sort=city>|
+ . $locale->text('City')
+ . qq|</a></th>|;
+ $column_header{state} =
+ qq|<th><a class=listheading href=$href&sort=state>|
+ . $locale->text('State/Province')
+ . qq|</a></th>|;
+ $column_header{zipcode} =
+ qq|<th><a class=listheading href=$href&sort=zipcode>|
+ . $locale->text('Zip/Postal Code')
+ . qq|</a></th>|;
+ $column_header{country} =
+ qq|<th><a class=listheading href=$href&sort=country>|
+ . $locale->text('Country')
+ . qq|</a></th>|;
+ $column_header{workphone} =
+ qq|<th><a class=listheading href=$href&sort=workphone>|
+ . $locale->text('Work Phone')
+ . qq|</a></th>|;
+ $column_header{homephone} =
+ qq|<th><a class=listheading href=$href&sort=homephone>|
+ . $locale->text('Home Phone')
+ . qq|</a></th>|;
+
+ $column_header{startdate} =
+ qq|<th><a class=listheading href=$href&sort=startdate>|
+ . $locale->text('Startdate')
+ . qq|</a></th>|;
+ $column_header{enddate} =
+ qq|<th><a class=listheading href=$href&sort=enddate>|
+ . $locale->text('Enddate')
+ . qq|</a></th>|;
+ $column_header{notes} =
+ qq|<th><a class=listheading href=$href&sort=notes>|
+ . $locale->text('Notes')
+ . qq|</a></th>|;
+ $column_header{role} =
+ qq|<th><a class=listheading href=$href&sort=role>|
+ . $locale->text('Role')
+ . qq|</a></th>|;
+ $column_header{login} =
+ qq|<th><a class=listheading href=$href&sort=login>|
+ . $locale->text('Login')
+ . qq|</a></th>|;
+
+ $column_header{sales} =
+ qq|<th class=listheading>| . $locale->text('S') . qq|</th>|;
+ $column_header{email} =
+ qq|<th><a class=listheading href=$href&sort=email>|
+ . $locale->text('E-mail')
+ . qq|</a></th>|;
+ $column_header{ssn} =
+ qq|<th><a class=listheading href=$href&sort=ssn>|
+ . $locale->text('SSN')
+ . qq|</a></th>|;
+ $column_header{dob} =
+ qq|<th><a class=listheading href=$href&sort=dob>|
+ . $locale->text('DOB')
+ . qq|</a></th>|;
+ $column_header{iban} =
+ qq|<th><a class=listheading href=$href&sort=iban>|
+ . $locale->text('IBAN')
+ . qq|</a></th>|;
+ $column_header{bic} =
+ qq|<th><a class=listheading href=$href&sort=bic>|
+ . $locale->text('BIC')
+ . qq|</a></th>|;
+
+ $form->{title} = $locale->text('Employees');
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -308,58 +418,65 @@ sub list_employees {
<tr class=listheading>
|;
- for (@column_index) { print "$column_header{$_}\n" }
-
- print qq|
+ for (@column_index) { print "$column_header{$_}\n" }
+
+ print qq|
</tr>
|;
- $i = 0;
- foreach $ref (@{ $form->{all_employee} }) {
+ $i = 0;
+ foreach $ref ( @{ $form->{all_employee} } ) {
- $i++;
-
- $ref->{notes} =~ s/\r?\n/<br>/g;
- for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
+ $i++;
- $column_data{ndx} = "<td align=right>$i</td>";
-
- $column_data{sales} = ($ref->{sales}) ? "<td>x</td>" : "<td>&nbsp;</td>";
- $column_data{role} = qq|<td>$role{"$ref->{role}"}&nbsp;</td>|;
- $column_date{address} = qq|$ref->{address1} $ref->{address2}|;
+ $ref->{notes} =~ s/\r?\n/<br>/g;
+ for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
- $column_data{name} = "<td><a href=$form->{script}?action=edit&db=employee&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&callback=$callback>$ref->{name}&nbsp;</td>";
+ $column_data{ndx} = "<td align=right>$i</td>";
- if ($ref->{email}) {
- $email = $ref->{email};
- $email =~ s/</\&lt;/;
- $email =~ s/>/\&gt;/;
-
- $column_data{email} = qq|<td><a href="mailto:$ref->{email}">$email</a></td>|;
- }
+ $column_data{sales} =
+ ( $ref->{sales} ) ? "<td>x</td>" : "<td>&nbsp;</td>";
+ $column_data{role} = qq|<td>$role{"$ref->{role}"}&nbsp;</td>|;
+ $column_date{address} = qq|$ref->{address1} $ref->{address2}|;
+
+ $column_data{name} =
+"<td><a href=$form->{script}?action=edit&db=employee&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&callback=$callback>$ref->{name}&nbsp;</td>";
+
+ if ( $ref->{email} ) {
+ $email = $ref->{email};
+ $email =~ s/</\&lt;/;
+ $email =~ s/>/\&gt;/;
+
+ $column_data{email} =
+ qq|<td><a href="mailto:$ref->{email}">$email</a></td>|;
+ }
- $j++; $j %= 2;
- print "
+ $j++;
+ $j %= 2;
+ print "
<tr class=listrow$j>
";
- for (@column_index) { print "$column_data{$_}\n" }
+ for (@column_index) { print "$column_data{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
-
- }
-
- $i = 1;
- $button{'HR--Employees--Add Employee'}{code} = qq|<button class="submit" type="submit" name="action" value="add_employee">|.$locale->text('Add Employee').qq|</button> |;
- $button{'HR--Employees--Add Employee'}{order} = $i++;
-
- foreach $item (split /;/, $myconfig{acs}) {
- delete $button{$item};
- }
-
- print qq|
+
+ }
+
+ $i = 1;
+ $button{'HR--Employees--Add Employee'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add_employee">|
+ . $locale->text('Add Employee')
+ . qq|</button> |;
+ $button{'HR--Employees--Add Employee'}{order} = $i++;
+
+ foreach $item ( split /;/, $myconfig{acs} ) {
+ delete $button{$item};
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -372,138 +489,148 @@ sub list_employees {
<form method=post action=$form->{script}>
|;
- $form->hide_form(qw(callback db path login sessionid));
-
- foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
- print $item->{code};
- }
+ $form->hide_form(qw(callback db path login sessionid));
+
+ foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
+ print $item->{code};
+ }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
</html>
|;
-
-}
+}
sub edit {
-# $locale->text('Edit Employee')
-# $locale->text('Edit Deduction')
+ # $locale->text('Edit Employee')
+ # $locale->text('Edit Deduction')
- $label = ucfirst $form->{db};
- $form->{title} = "Edit $label";
+ $label = ucfirst $form->{db};
+ $form->{title} = "Edit $label";
- &{ "$form->{db}_links" };
-
-}
+ &{"$form->{db}_links"};
+}
sub employee_links {
-#$form->{deductions} = 1;
- HR->get_employee(\%myconfig, \%$form);
+ #$form->{deductions} = 1;
+ HR->get_employee( \%myconfig, \%$form );
- for (keys %$form) { $form->{$_} = $form->quote($form->{$_}) }
+ for ( keys %$form ) { $form->{$_} = $form->quote( $form->{$_} ) }
- if (@{ $form->{all_deduction} }) {
- $form->{selectdeduction} = "<option>\n";
- for (@{ $form->{all_deduction} }) { $form->{selectdeduction} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
- }
+ if ( @{ $form->{all_deduction} } ) {
+ $form->{selectdeduction} = "<option>\n";
+ for ( @{ $form->{all_deduction} } ) {
+ $form->{selectdeduction} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+ }
- $form->{manager} = "$form->{manager}--$form->{managerid}";
+ $form->{manager} = "$form->{manager}--$form->{managerid}";
- if (@{ $form->{all_manager} }) {
- $form->{selectmanager} = "<option>\n";
- for (@{ $form->{all_manager} }) { $form->{selectmanager} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
+ if ( @{ $form->{all_manager} } ) {
+ $form->{selectmanager} = "<option>\n";
+ for ( @{ $form->{all_manager} } ) {
+ $form->{selectmanager} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
- %role = ( user => $locale->text('User'),
- supervisor => $locale->text('Supervisor'),
- manager => $locale->text('Manager'),
- admin => $locale->text('Administrator')
- );
-
- $form->{selectrole} = "<option>\n";
- for (qw(user supervisor manager admin)) { $form->{selectrole} .= "<option value=$_>$role{$_}\n" }
+ %role = (
+ user => $locale->text('User'),
+ supervisor => $locale->text('Supervisor'),
+ manager => $locale->text('Manager'),
+ admin => $locale->text('Administrator')
+ );
- $i = 1;
- foreach $ref (@{ $form->{all_employeededuction} }) {
- $form->{"deduction_$i"} = "$ref->{description}--$ref->{id}" if $ref->{id};
- for (qw(before after rate)) { $form->{"${_}_$i"} = $ref->{$_} }
- $i++;
- }
- $form->{deduction_rows} = $i - 1;
+ $form->{selectrole} = "<option>\n";
+ for (qw(user supervisor manager admin)) {
+ $form->{selectrole} .= "<option value=$_>$role{$_}\n";
+ }
- &employee_header;
- &employee_footer;
+ $i = 1;
+ foreach $ref ( @{ $form->{all_employeededuction} } ) {
+ $form->{"deduction_$i"} = "$ref->{description}--$ref->{id}"
+ if $ref->{id};
+ for (qw(before after rate)) { $form->{"${_}_$i"} = $ref->{$_} }
+ $i++;
+ }
+ $form->{deduction_rows} = $i - 1;
-}
+ &employee_header;
+ &employee_footer;
+}
sub employee_header {
- $sales = qq|<input type=hidden name=sales value=$form->{sales}>|;
- $form->{sales} = ($form->{sales}) ? "checked" : "";
+ $sales = qq|<input type=hidden name=sales value=$form->{sales}>|;
+ $form->{sales} = ( $form->{sales} ) ? "checked" : "";
- $form->{selectrole} =~ s/ selected//;
- $form->{selectrole} =~ s/option value=\Q$form->{role}\E>/option value=$form->{role} selected>/;
+ $form->{selectrole} =~ s/ selected//;
+ $form->{selectrole} =~
+ s/option value=\Q$form->{role}\E>/option value=$form->{role} selected>/;
- $form->{selectdeduction} = $form->unescape($form->{selectdeduction});
-
- $form->{selectmanager} = $form->unescape($form->{selectmanager});
- $form->{selectmanager} =~ s/ selected//;
- $form->{selectmanager} =~ s/(<option value="\Q$form->{manager}\E")/$1 selected/;
+ $form->{selectdeduction} = $form->unescape( $form->{selectdeduction} );
- $sales .= qq|
+ $form->{selectmanager} = $form->unescape( $form->{selectmanager} );
+ $form->{selectmanager} =~ s/ selected//;
+ $form->{selectmanager} =~
+ s/(<option value="\Q$form->{manager}\E")/$1 selected/;
+
+ $sales .= qq|
<input type=hidden name=role value=$form->{role}>
<input type=hidden name=manager value=$form->{manager}>
|;
- if ($myconfig{role} ne 'user') {
- $sales = qq|
+ if ( $myconfig{role} ne 'user' ) {
+ $sales = qq|
<tr>
- <th align=right>|.$locale->text('Sales').qq|</th>
+ <th align=right>| . $locale->text('Sales') . qq|</th>
<td><input name=sales class=checkbox type=checkbox value=1 $form->{sales}></td>
</tr>
<tr>
- <th align=right>|.$locale->text('Role').qq|</th>
+ <th align=right>| . $locale->text('Role') . qq|</th>
<td><select name=role>$form->{selectrole}</select></td>
</tr>
|;
- if ($form->{selectmanager}) {
- $sales .= qq|
+ if ( $form->{selectmanager} ) {
+ $sales .= qq|
<tr>
- <th align=right>|.$locale->text('Manager').qq|</th>
+ <th align=right>| . $locale->text('Manager') . qq|</th>
<td><select name=manager>$form->{selectmanager}</select></td>
</tr>
|;
+ }
}
- }
-
- $form->{deduction_rows}++;
-
- for $i (1 .. $form->{deduction_rows}) {
- $form->{"selectdeduction_$i"} = $form->{selectdeduction};
- if ($form->{"deduction_$i"}) {
- $form->{"selectdeduction_$i"} =~ s/(<option value="\Q$form->{"deduction_$i"}\E")/$1 selected/;
+
+ $form->{deduction_rows}++;
+
+ for $i ( 1 .. $form->{deduction_rows} ) {
+ $form->{"selectdeduction_$i"} = $form->{selectdeduction};
+ if ( $form->{"deduction_$i"} ) {
+ $form->{"selectdeduction_$i"} =~
+ s/(<option value="\Q$form->{"deduction_$i"}\E")/$1 selected/;
+ }
}
- }
- $form->{selectdeduction} = $form->escape($form->{selectdeduction},1);
- $form->{selectmanager} = $form->escape($form->{selectmanager},1);
+ $form->{selectdeduction} = $form->escape( $form->{selectdeduction}, 1 );
+ $form->{selectmanager} = $form->escape( $form->{selectmanager}, 1 );
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -530,15 +657,15 @@ sub employee_header {
<td>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('Number') . qq|</th>
<td><input name=employeenumber size=32 maxlength=32 value="$form->{employeenumber}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Name').qq|</th>
+ <th align=right nowrap>| . $locale->text('Name') . qq|</th>
<td><input name=name size=35 maxlength=64 value="$form->{name}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Address').qq|</th>
+ <th align=right nowrap>| . $locale->text('Address') . qq|</th>
<td><input name=address1 size=35 maxlength=32 value="$form->{address1}"></td>
</tr>
<tr>
@@ -546,23 +673,23 @@ sub employee_header {
<td><input name=address2 size=35 maxlength=32 value="$form->{address2}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('City').qq|</th>
+ <th align=right nowrap>| . $locale->text('City') . qq|</th>
<td><input name=city size=35 maxlength=32 value="$form->{city}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('State/Province').qq|</th>
+ <th align=right nowrap>| . $locale->text('State/Province') . qq|</th>
<td><input name=state size=35 maxlength=32 value="$form->{state}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Zip/Postal Code').qq|</th>
+ <th align=right nowrap>| . $locale->text('Zip/Postal Code') . qq|</th>
<td><input name=zipcode size=10 maxlength=10 value="$form->{zipcode}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Country').qq|</th>
+ <th align=right nowrap>| . $locale->text('Country') . qq|</th>
<td><input name=country size=35 maxlength=32 value="$form->{country}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('E-mail').qq|</th>
+ <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
<td><input name=email size=35 value="$form->{email}"></td>
</tr>
<tr>
@@ -572,36 +699,36 @@ sub employee_header {
<td>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Work Phone').qq|</th>
+ <th align=right nowrap>| . $locale->text('Work Phone') . qq|</th>
<td><input name=workphone size=20 maxlength=20 value="$form->{workphone}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Home Phone').qq|</th>
+ <th align=right nowrap>| . $locale->text('Home Phone') . qq|</th>
<td><input name=homephone size=20 maxlength=20 value="$form->{homephone}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Startdate').qq|</th>
+ <th align=right nowrap>| . $locale->text('Startdate') . qq|</th>
<td><input name=startdate size=11 title="$myconfig{dateformat}" value=$form->{startdate}></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Enddate').qq|</th>
+ <th align=right nowrap>| . $locale->text('Enddate') . qq|</th>
<td><input name=enddate size=11 title="$myconfig{dateformat}" value=$form->{enddate}></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('SSN').qq|</th>
+ <th align=right nowrap>| . $locale->text('SSN') . qq|</th>
<td><input name=ssn size=20 maxlength=20 value="$form->{ssn}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('DOB').qq|</th>
+ <th align=right nowrap>| . $locale->text('DOB') . qq|</th>
<td><input name=dob size=11 title="$myconfig{dateformat}" value=$form->{dob}></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('IBAN').qq|</th>
+ <th align=right nowrap>| . $locale->text('IBAN') . qq|</th>
<td><input name=iban size=34 maxlength=34 value="$form->{iban}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('BIC').qq|</th>
+ <th align=right nowrap>| . $locale->text('BIC') . qq|</th>
<td><input name=bic size=11 maxlength=11 value="$form->{bic}"></td>
</tr>
</table>
@@ -611,45 +738,51 @@ sub employee_header {
</td>
</tr>
<tr>
- <th align=left nowrap>|.$locale->text('Notes').qq|</th>
+ <th align=left nowrap>| . $locale->text('Notes') . qq|</th>
</tr>
<tr>
<td><textarea name=notes rows=3 cols=60 wrap=soft>$form->{notes}</textarea></td>
</tr>
|;
- if ($form->{selectdeduction}) {
+ if ( $form->{selectdeduction} ) {
- print qq|
+ print qq|
<tr>
<td>
<table width=100%>
<tr class=listheading>
- <th class=listheading>|.$locale->text('Payroll Deduction').qq|</th>
- <th class=listheading colspan=3>|.$locale->text('Allowances').qq|</th>
+ <th class=listheading>| . $locale->text('Payroll Deduction') . qq|</th>
+ <th class=listheading colspan=3>| . $locale->text('Allowances') . qq|</th>
</tr>
<tr class=listheading>
<th></th>
- <th class=listheading>|.$locale->text('Before Deduction').qq|</th>
- <th class=listheading>|.$locale->text('After Deduction').qq|</th>
- <th class=listheading>|.$locale->text('Rate').qq|</th>
+ <th class=listheading>| . $locale->text('Before Deduction') . qq|</th>
+ <th class=listheading>| . $locale->text('After Deduction') . qq|</th>
+ <th class=listheading>| . $locale->text('Rate') . qq|</th>
</tr>
|;
- for $i (1 .. $form->{deduction_rows}) {
- print qq|
+ for $i ( 1 .. $form->{deduction_rows} ) {
+ print qq|
<tr>
<td><select name="deduction_$i">$form->{"selectdeduction_$i"}</select></td>
- <td><input name="before_$i" value=|.$form->format_amount(\%myconfig, $form->{"before_$i"}, 2).qq|></td>
- <td><input name="after_$i" value=|.$form->format_amount(\%myconfig, $form->{"after_$i"}, 2).qq|></td>
- <td><input name="rate_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"rate_$i"}).qq|></td>
+ <td><input name="before_$i" value=|
+ . $form->format_amount( \%myconfig, $form->{"before_$i"}, 2 )
+ . qq|></td>
+ <td><input name="after_$i" value=|
+ . $form->format_amount( \%myconfig, $form->{"after_$i"}, 2 )
+ . qq|></td>
+ <td><input name="rate_$i" size=5 value=|
+ . $form->format_amount( \%myconfig, $form->{"rate_$i"} )
+ . qq|></td>
</tr>
|;
+ }
}
- }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -661,11 +794,9 @@ sub employee_header {
}
-
-
sub employee_footer {
- print qq|
+ print qq|
<input name=id type=hidden value=$form->{id}>
<input type=hidden name=db value=$form->{db}>
@@ -679,23 +810,33 @@ sub employee_footer {
<br>
-<button class="submit" type="submit" name="action" value="update">|.$locale->text('Update').qq|</button>
-<button class="submit" type="submit" name="action" value="save">|.$locale->text('Save').qq|</button>
+<button class="submit" type="submit" name="action" value="update">|
+ . $locale->text('Update')
+ . qq|</button>
+<button class="submit" type="submit" name="action" value="save">|
+ . $locale->text('Save')
+ . qq|</button>
|;
- if ($form->{id}) {
- print qq|<button class="submit" type="submit" name="action" value="save_as_new">|.$locale->text('Save as new').qq|</button>\n|;
- if ($form->{status} eq 'orphaned') {
- print qq|<button class="submit" type="submit" name="action" value="delete">|.$locale->text('Delete').qq|</button>\n|;
+ if ( $form->{id} ) {
+ print
+qq|<button class="submit" type="submit" name="action" value="save_as_new">|
+ . $locale->text('Save as new')
+ . qq|</button>\n|;
+ if ( $form->{status} eq 'orphaned' ) {
+ print
+qq|<button class="submit" type="submit" name="action" value="delete">|
+ . $locale->text('Delete')
+ . qq|</button>\n|;
+ }
}
- }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
@@ -705,84 +846,97 @@ sub employee_footer {
}
-
-sub save { &{ "save_$form->{db}" } };
-
+sub save { &{"save_$form->{db}"} }
sub save_employee {
- $form->isblank("name", $locale->text("Name missing!"));
- HR->save_employee(\%myconfig, \%$form);
+ $form->isblank( "name", $locale->text("Name missing!") );
+ HR->save_employee( \%myconfig, \%$form );
- # if it is a login change memberfile and .conf
- if ($form->{employeelogin}) {
- $user = LedgerSMB::User->new($form->{employeelogin});
+ # if it is a login change memberfile and .conf
+ if ( $form->{employeelogin} ) {
+ $user = LedgerSMB::User->new( $form->{employeelogin} );
- for (qw(name email role)) { $user->{$_} = $form->{$_} }
+ for (qw(name email role)) { $user->{$_} = $form->{$_} }
- # assign $myconfig for db
- for (qw(dbconnect dbhost dbport dbpasswd)) { $user->{$_} = $myconfig{$_} }
-
- for (qw(dbpasswd password)) { $user->{"old_$_"} = $user->{$_} }
- $user->{packpw} = 1;
+ # assign $myconfig for db
+ for (qw(dbconnect dbhost dbport dbpasswd)) {
+ $user->{$_} = $myconfig{$_};
+ }
- $user->save_member() if $user->{login};
- }
-
- $form->redirect($locale->text('Employee saved!'));
-
-}
+ for (qw(dbpasswd password)) { $user->{"old_$_"} = $user->{$_} }
+ $user->{packpw} = 1;
+
+ $user->save_member() if $user->{login};
+ }
+ $form->redirect( $locale->text('Employee saved!') );
-sub delete { &{ "delete_$form->{db}" } };
+}
+sub delete { &{"delete_$form->{db}"} }
sub delete_employee {
- HR->delete_employee(\%myconfig, \%$form);
- $form->redirect($locale->text('Employee deleted!'));
-
+ HR->delete_employee( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Employee deleted!') );
+
}
+sub continue { &{ $form->{nextsub} } }
-sub continue { &{ $form->{nextsub} } };
+sub add_employee { &add }
+sub add_deduction { &add }
-sub add_employee { &add };
-sub add_deduction { &add };
+sub search_deduction {
+ HR->deductions( \%myconfig, \%$form );
-sub search_deduction {
+ $href =
+"$form->{script}?action=search_deduction&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- HR->deductions(\%myconfig, \%$form);
-
- $href = "$form->{script}?action=search_deduction&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+ $form->sort_order();
- $form->sort_order();
+ $callback =
+"$form->{script}?action=search_deduction&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
- $callback = "$form->{script}?action=search_deduction&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- @column_index = $form->sort_columns(qw(description rate amount above below employeepays employerpays ap_accno expense_accno));
+ @column_index =
+ $form->sort_columns(
+ qw(description rate amount above below employeepays employerpays ap_accno expense_accno)
+ );
-
- $form->{callback} = $callback;
- $callback = $form->escape($form->{callback});
-
- $column_header{description} = qq|<th class=listheading href=$href>|.$locale->text('Description').qq|</th>|;
- $column_header{rate} = qq|<th class=listheading nowrap>|.$locale->text('Rate').qq|<br>%</th>|;
- $column_header{amount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
- $column_header{above} = qq|<th class=listheading>|.$locale->text('Above').qq|</th>|;
- $column_header{below} = qq|<th class=listheading>|.$locale->text('Below').qq|</th>|;
- $column_header{employerpays} = qq|<th class=listheading>|.$locale->text('Employer').qq|</th>|;
- $column_header{employeepays} = qq|<th class=listheading>|.$locale->text('Employee').qq|</th>|;
-
- $column_header{ap_accno} = qq|<th class=listheading>|.$locale->text('AP').qq|</th>|;
- $column_header{expense_accno} = qq|<th class=listheading>|.$locale->text('Expense').qq|</th>|;
-
- $form->{title} = $locale->text('Deductions');
-
- $form->header;
-
- print qq|
+ $form->{callback} = $callback;
+ $callback = $form->escape( $form->{callback} );
+
+ $column_header{description} =
+ qq|<th class=listheading href=$href>|
+ . $locale->text('Description')
+ . qq|</th>|;
+ $column_header{rate} =
+ qq|<th class=listheading nowrap>|
+ . $locale->text('Rate')
+ . qq|<br>%</th>|;
+ $column_header{amount} =
+ qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
+ $column_header{above} =
+ qq|<th class=listheading>| . $locale->text('Above') . qq|</th>|;
+ $column_header{below} =
+ qq|<th class=listheading>| . $locale->text('Below') . qq|</th>|;
+ $column_header{employerpays} =
+ qq|<th class=listheading>| . $locale->text('Employer') . qq|</th>|;
+ $column_header{employeepays} =
+ qq|<th class=listheading>| . $locale->text('Employee') . qq|</th>|;
+
+ $column_header{ap_accno} =
+ qq|<th class=listheading>| . $locale->text('AP') . qq|</th>|;
+ $column_header{expense_accno} =
+ qq|<th class=listheading>| . $locale->text('Expense') . qq|</th>|;
+
+ $form->{title} = $locale->text('Deductions');
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -799,55 +953,73 @@ sub search_deduction {
<tr class=listheading>
|;
- for (@column_index) { print "$column_header{$_}\n" }
-
- print qq|
+ for (@column_index) { print "$column_header{$_}\n" }
+
+ print qq|
</tr>
|;
-
- foreach $ref (@{ $form->{all_deduction} }) {
-
- $rate = $form->format_amount(\%myconfig, $ref->{rate} * 100, "", "&nbsp;");
-
- $column_data{rate} = "<td align=right>$rate</td>";
-
- for (qw(amount below above)) { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;")."</td>" }
-
- for (qw(ap_accno expense_accno)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
-
- for (qw(employerpays employeepays)) { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, "", "&nbsp;")."</td>" }
-
- if ($ref->{description} ne $sameitem) {
- $column_data{description} = "<td><a href=$form->{script}?action=edit&db=$form->{db}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</a></td>";
- } else {
- $column_data{description} = "<td>&nbsp;</td>";
- }
-
- $i++; $i %= 2;
- print "
+ foreach $ref ( @{ $form->{all_deduction} } ) {
+
+ $rate =
+ $form->format_amount( \%myconfig, $ref->{rate} * 100, "", "&nbsp;" );
+
+ $column_data{rate} = "<td align=right>$rate</td>";
+
+ for (qw(amount below above)) {
+ $column_data{$_} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" )
+ . "</td>";
+ }
+
+ for (qw(ap_accno expense_accno)) {
+ $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
+ }
+
+ for (qw(employerpays employeepays)) {
+ $column_data{$_} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{$_}, "", "&nbsp;" )
+ . "</td>";
+ }
+
+ if ( $ref->{description} ne $sameitem ) {
+ $column_data{description} =
+"<td><a href=$form->{script}?action=edit&db=$form->{db}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}</a></td>";
+ }
+ else {
+ $column_data{description} = "<td>&nbsp;</td>";
+ }
+
+ $i++;
+ $i %= 2;
+ print "
<tr class=listrow$i>
";
- for (@column_index) { print "$column_data{$_}\n" }
+ for (@column_index) { print "$column_data{$_}\n" }
- print qq|
+ print qq|
</tr>
|;
- $sameitem = $ref->{description};
-
- }
+ $sameitem = $ref->{description};
- $i = 1;
- $button{'HR--Deductions--Add Deduction'}{code} = qq|<button class="submit" type="submit" name="action" value="add_deduction">|.$locale->text('Add Deduction').qq|</button> |;
- $button{'HR--Deductions--Add Deduction'}{order} = $i++;
+ }
+
+ $i = 1;
+ $button{'HR--Deductions--Add Deduction'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add_deduction">|
+ . $locale->text('Add Deduction')
+ . qq|</button> |;
+ $button{'HR--Deductions--Add Deduction'}{order} = $i++;
- foreach $item (split /;/, $myconfig{acs}) {
- delete $button{$item};
- }
-
- print qq|
+ foreach $item ( split /;/, $myconfig{acs} ) {
+ delete $button{$item};
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -868,108 +1040,115 @@ sub search_deduction {
<input type=hidden name=sessionid value=$form->{sessionid}>
|;
- foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
- print $item->{code};
- }
+ foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
+ print $item->{code};
+ }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
</html>
|;
-
-}
+}
sub deduction_links {
-
- HR->get_deduction(\%myconfig, \%$form);
-
- $i = 1;
- foreach $ref (@{ $form->{deductionrate} }) {
- for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
- $i++;
- }
- $form->{rate_rows} = $i - 1;
-
- $i = 1;
- foreach $ref (@{ $form->{deductionbase} }) {
- $form->{"base_$i"} = "$ref->{description}--$ref->{id}" if $ref->{id};
- $form->{"maximum_$i"} = $ref->{maximum};
- $i++;
- }
- $form->{base_rows} = $i - 1;
-
- $i = 1;
- foreach $ref (@{ $form->{deductionafter} }) {
- $form->{"after_$i"} = "$ref->{description}--$ref->{id}" if $ref->{id};
- $i++;
- }
- $form->{after_rows} = $i - 1;
-
- $form->{employeepays} = 1;
-
- $selectaccount = "<option>\n";
- for (@{ $form->{ap_accounts} }) { $selectaccount .= "<option>$_->{accno}--$_->{description}\n" }
-
- $form->{ap_accno} = qq|$form->{ap_accno}--$form->{ap_description}|;
- $form->{selectap} = $selectaccount;
-
- $selectaccount = "<option>\n";
- for (@{ $form->{expense_accounts} }) { $selectaccount .= "<option>$_->{accno}--$_->{description}\n" }
-
- $form->{expense_accno} = qq|$form->{expense_accno}--$form->{expense_description}|;
- $form->{selectexpense} = $selectaccount;
-
- for (1 .. $form->{rate_rows}) { $form->{"rate_$_"} *= 100 }
-
- $form->{selectbase} = "<option>\n";
- for (@{ $form->{all_deduction} }) { $form->{selectbase} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
-
- &deduction_header;
- &deduction_footer;
-
-}
+ HR->get_deduction( \%myconfig, \%$form );
-sub deduction_header {
+ $i = 1;
+ foreach $ref ( @{ $form->{deductionrate} } ) {
+ for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
+ $i++;
+ }
+ $form->{rate_rows} = $i - 1;
- $selectap = $form->{selectap};
- $selectap =~ s/option>\Q$form->{ap_accno}\E/option selected>$form->{ap_accno}/;
- $selectexpense = $form->{selectexpense};
- $selectexpense =~ s/option>\Q$form->{expense_accno}\E/option selected>$form->{expense_accno}/;
+ $i = 1;
+ foreach $ref ( @{ $form->{deductionbase} } ) {
+ $form->{"base_$i"} = "$ref->{description}--$ref->{id}" if $ref->{id};
+ $form->{"maximum_$i"} = $ref->{maximum};
+ $i++;
+ }
+ $form->{base_rows} = $i - 1;
+ $i = 1;
+ foreach $ref ( @{ $form->{deductionafter} } ) {
+ $form->{"after_$i"} = "$ref->{description}--$ref->{id}" if $ref->{id};
+ $i++;
+ }
+ $form->{after_rows} = $i - 1;
- $form->{rate_rows}++;
- $form->{base_rows}++;
- $form->{after_rows}++;
+ $form->{employeepays} = 1;
- $form->{selectbase} = $form->unescape($form->{selectbase});
-
- for $i (1 .. $form->{base_rows}) {
- $form->{"selectbase_$i"} = $form->{selectbase};
- if ($form->{"base_$i"}) {
- $form->{"selectbase_$i"} =~ s/(<option value="\Q$form->{"base_$i"}\E")/$1 selected/;
+ $selectaccount = "<option>\n";
+ for ( @{ $form->{ap_accounts} } ) {
+ $selectaccount .= "<option>$_->{accno}--$_->{description}\n";
}
- }
- for $i (1 .. $form->{after_rows}) {
- $form->{"selectafter_$i"} = $form->{selectbase};
- if ($form->{"after_$i"}) {
- $form->{"selectafter_$i"} =~ s/(<option value="\Q$form->{"after_$i"}\E")/$1 selected/;
+
+ $form->{ap_accno} = qq|$form->{ap_accno}--$form->{ap_description}|;
+ $form->{selectap} = $selectaccount;
+
+ $selectaccount = "<option>\n";
+ for ( @{ $form->{expense_accounts} } ) {
+ $selectaccount .= "<option>$_->{accno}--$_->{description}\n";
}
- }
-
- $form->header;
+ $form->{expense_accno} =
+ qq|$form->{expense_accno}--$form->{expense_description}|;
+ $form->{selectexpense} = $selectaccount;
+
+ for ( 1 .. $form->{rate_rows} ) { $form->{"rate_$_"} *= 100 }
+
+ $form->{selectbase} = "<option>\n";
+ for ( @{ $form->{all_deduction} } ) {
+ $form->{selectbase} .=
+ qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+
+ &deduction_header;
+ &deduction_footer;
+
+}
+
+sub deduction_header {
+
+ $selectap = $form->{selectap};
+ $selectap =~
+ s/option>\Q$form->{ap_accno}\E/option selected>$form->{ap_accno}/;
+ $selectexpense = $form->{selectexpense};
+ $selectexpense =~
+s/option>\Q$form->{expense_accno}\E/option selected>$form->{expense_accno}/;
+
+ $form->{rate_rows}++;
+ $form->{base_rows}++;
+ $form->{after_rows}++;
+
+ $form->{selectbase} = $form->unescape( $form->{selectbase} );
+
+ for $i ( 1 .. $form->{base_rows} ) {
+ $form->{"selectbase_$i"} = $form->{selectbase};
+ if ( $form->{"base_$i"} ) {
+ $form->{"selectbase_$i"} =~
+ s/(<option value="\Q$form->{"base_$i"}\E")/$1 selected/;
+ }
+ }
+ for $i ( 1 .. $form->{after_rows} ) {
+ $form->{"selectafter_$i"} = $form->{selectbase};
+ if ( $form->{"after_$i"} ) {
+ $form->{"selectafter_$i"} =~
+ s/(<option value="\Q$form->{"after_$i"}\E")/$1 selected/;
+ }
+ }
+
+ $form->header;
-
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -978,7 +1157,8 @@ sub deduction_header {
<input type=hidden name=selectap value="$form->{selectap}">
<input type=hidden name=selectexpense value="$form->{selectexpense}">
-<input type=hidden name=selectbase value="|.$form->escape($form->{selectbase},1).qq|">
+<input type=hidden name=selectbase value="|
+ . $form->escape( $form->{selectbase}, 1 ) . qq|">
<input type=hidden name=rate_rows value=$form->{rate_rows}>
<input type=hidden name=base_rows value=$form->{base_rows}>
@@ -993,53 +1173,68 @@ sub deduction_header {
<td>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Description').qq|</th>
+ <th align=right nowrap>| . $locale->text('Description') . qq|</th>
<td><input name=description size=35 value="$form->{description}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('AP').qq|</th>
+ <th align=right nowrap>| . $locale->text('AP') . qq|</th>
<td><select name=ap_accno>$selectap</select></td>
- <th align=right nowrap>|.$locale->text('Employee pays').qq| x</th>
- <td><input name=employeepays size=4 value=|.$form->format_amount(\%myconfig, $form->{employeepays}).qq|></td>
+ <th align=right nowrap>| . $locale->text('Employee pays') . qq| x</th>
+ <td><input name=employeepays size=4 value=|
+ . $form->format_amount( \%myconfig, $form->{employeepays} )
+ . qq|></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Expense').qq|</th>
+ <th align=right nowrap>| . $locale->text('Expense') . qq|</th>
<td><select name=expense_accno>$selectexpense</select></td>
- <th align=right nowrap>|.$locale->text('Employer pays').qq| x</th>
- <td><input name=employerpays size=4 value=|.$form->format_amount(\%myconfig, $form->{employerpays}).qq|></td>
+ <th align=right nowrap>| . $locale->text('Employer pays') . qq| x</th>
+ <td><input name=employerpays size=4 value=|
+ . $form->format_amount( \%myconfig, $form->{employerpays} )
+ . qq|></td>
</tr>
<tr>
<td></td>
<td></td>
- <th align=right nowrap>|.$locale->text('Exempt age <').qq|</th>
- <td><input name=fromage size=4 value=|.$form->format_amount(\%myconfig, $form->{fromage}).qq|></td>
+ <th align=right nowrap>| . $locale->text('Exempt age <') . qq|</th>
+ <td><input name=fromage size=4 value=|
+ . $form->format_amount( \%myconfig, $form->{fromage} )
+ . qq|></td>
<th align=right nowrap>&gt;</th>
- <td><input name=toage size=4 value=|.$form->format_amount(\%myconfig, $form->{toage}).qq|>
+ <td><input name=toage size=4 value=|
+ . $form->format_amount( \%myconfig, $form->{toage} ) . qq|>
</tr>
<tr>
<td></td>
<td>
<table>
<tr class=listheading>
- <th class=listheading>|.$locale->text('Rate').qq| %</th>
- <th class=listheading>|.$locale->text('Amount').qq|</th>
- <th class=listheading>|.$locale->text('Above').qq|</th>
- <th class=listheading>|.$locale->text('Below').qq|</th>
+ <th class=listheading>| . $locale->text('Rate') . qq| %</th>
+ <th class=listheading>| . $locale->text('Amount') . qq|</th>
+ <th class=listheading>| . $locale->text('Above') . qq|</th>
+ <th class=listheading>| . $locale->text('Below') . qq|</th>
</tr>
|;
- for $i (1 .. $form->{rate_rows}) {
- print qq|
+ for $i ( 1 .. $form->{rate_rows} ) {
+ print qq|
<tr>
- <td><input name="rate_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"rate_$i"}).qq|></td>
- <td><input name="amount_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"amount_$i"}, 2).qq|></td>
- <td><input name="above_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"above_$i"}, 2).qq|></td>
- <td><input name="below_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"below_$i"}, 2).qq|></td>
+ <td><input name="rate_$i" size=10 value=|
+ . $form->format_amount( \%myconfig, $form->{"rate_$i"} )
+ . qq|></td>
+ <td><input name="amount_$i" size=10 value=|
+ . $form->format_amount( \%myconfig, $form->{"amount_$i"}, 2 )
+ . qq|></td>
+ <td><input name="above_$i" size=10 value=|
+ . $form->format_amount( \%myconfig, $form->{"above_$i"}, 2 )
+ . qq|></td>
+ <td><input name="below_$i" size=10 value=|
+ . $form->format_amount( \%myconfig, $form->{"below_$i"}, 2 )
+ . qq|></td>
</tr>
|;
- }
+ }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -1047,42 +1242,44 @@ sub deduction_header {
</td>
</tr>
|;
-
- print qq|
+
+ print qq|
<tr>
<td>
<table>
|;
- $basedon = $locale->text('Based on');
- $maximum = $locale->text('Maximum');
-
- for $i (1 .. $form->{base_rows}) {
- print qq|
+ $basedon = $locale->text('Based on');
+ $maximum = $locale->text('Maximum');
+
+ for $i ( 1 .. $form->{base_rows} ) {
+ print qq|
<tr>
<th>$basedon</th>
<td><select name="base_$i">$form->{"selectbase_$i"}</select></td>
<th>$maximum</th>
- <td><input name="maximum_$i" value=|.$form->format_amount(\%myconfig, $form->{"maximum_$i"}, 2).qq|></td>
+ <td><input name="maximum_$i" value=|
+ . $form->format_amount( \%myconfig, $form->{"maximum_$i"}, 2 )
+ . qq|></td>
</tr>
|;
- $basedon = "";
- $maximum = "";
- }
+ $basedon = "";
+ $maximum = "";
+ }
- $deductafter = $locale->text('Deduct after');
-
- for $i (1 .. $form->{after_rows}) {
- print qq|
+ $deductafter = $locale->text('Deduct after');
+
+ for $i ( 1 .. $form->{after_rows} ) {
+ print qq|
<tr>
<th>$deductafter</th>
<td><select name="after_$i">$form->{"selectafter_$i"}</select></td>
</tr>
|;
- $deductafter = "";
- }
+ $deductafter = "";
+ }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -1094,11 +1291,9 @@ sub deduction_header {
}
-
-
sub deduction_footer {
- print qq|
+ print qq|
<input name="id" type="hidden" value="$form->{id}">
<input type="hidden" name="db" value="$form->{db}">
@@ -1111,24 +1306,34 @@ sub deduction_footer {
<br>
-<button class="submit" type="submit" name="action" value="update">|.$locale->text("Update").qq|</button>
-<button class="submit" type="submit" name="action" value="save">|.$locale->text("Save").qq|</button>
+<button class="submit" type="submit" name="action" value="update">|
+ . $locale->text("Update")
+ . qq|</button>
+<button class="submit" type="submit" name="action" value="save">|
+ . $locale->text("Save")
+ . qq|</button>
|;
- if ($form->{id}) {
- print qq|<button class="submit" type="submit" name="action" value="save_as_new">|.$locale->text('Save as new').qq|</button>\n|;
-
- if ($form->{status} eq 'orphaned') {
- print qq|<button class="submit" type="submit" name="action" value="delete">|.$locale->text('Delete').qq|</button>\n|;
+ if ( $form->{id} ) {
+ print
+qq|<button class="submit" type="submit" name="action" value="save_as_new">|
+ . $locale->text('Save as new')
+ . qq|</button>\n|;
+
+ if ( $form->{status} eq 'orphaned' ) {
+ print
+qq|<button class="submit" type="submit" name="action" value="delete">|
+ . $locale->text('Delete')
+ . qq|</button>\n|;
+ }
}
- }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
@@ -1138,124 +1343,123 @@ sub deduction_footer {
}
-
-sub update { &{ "update_$form->{db}" }; }
-sub save { &{ "save_$form->{db}" } };
-
+sub update { &{"update_$form->{db}"}; }
+sub save { &{"save_$form->{db}"} }
sub update_deduction {
- # if rate or amount is blank remove row
- @flds = qw(rate amount above below);
- $count = 0;
- @a = ();
- for $i (1 .. $form->{rate_rows}) {
- for (@flds) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
- if ($form->{"rate_$i"} || $form->{"amount_$i"}) {
- push @a, {};
- $j = $#a;
-
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
+ # if rate or amount is blank remove row
+ @flds = qw(rate amount above below);
+ $count = 0;
+ @a = ();
+ for $i ( 1 .. $form->{rate_rows} ) {
+ for (@flds) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+ if ( $form->{"rate_$i"} || $form->{"amount_$i"} ) {
+ push @a, {};
+ $j = $#a;
+
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
}
- }
- $form->redo_rows(\@flds, \@a, $count, $form->{rate_rows});
- $form->{rate_rows} = $count;
-
-
- @flds = qw(base maximum);
- $count = 0;
- @a = ();
- for $i (1 .. $form->{"base_rows"}) {
- $form->{"maximum_$i"} = $form->parse_amount(\%myconfig, $form->{"maximum_$i"});
- if ($form->{"base_$i"}) {
- push @a, {};
- $j = $#a;
-
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
+ $form->redo_rows( \@flds, \@a, $count, $form->{rate_rows} );
+ $form->{rate_rows} = $count;
+
+ @flds = qw(base maximum);
+ $count = 0;
+ @a = ();
+ for $i ( 1 .. $form->{"base_rows"} ) {
+ $form->{"maximum_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"maximum_$i"} );
+ if ( $form->{"base_$i"} ) {
+ push @a, {};
+ $j = $#a;
+
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
}
- }
- $form->redo_rows(\@flds, \@a, $count, $form->{"base_rows"});
- $form->{"base_rows"} = $count;
-
-
- @flds = qw(after);
- $count = 0;
- @a = ();
- for $i (1 .. $form->{"after_rows"}) {
- if ($form->{"after_$i"}) {
- push @a, {};
- $j = $#a;
-
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
+ $form->redo_rows( \@flds, \@a, $count, $form->{"base_rows"} );
+ $form->{"base_rows"} = $count;
+
+ @flds = qw(after);
+ $count = 0;
+ @a = ();
+ for $i ( 1 .. $form->{"after_rows"} ) {
+ if ( $form->{"after_$i"} ) {
+ push @a, {};
+ $j = $#a;
+
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
}
- }
- $form->redo_rows(\@flds, \@a, $count, $form->{"after_rows"});
- $form->{"after_rows"} = $count;
+ $form->redo_rows( \@flds, \@a, $count, $form->{"after_rows"} );
+ $form->{"after_rows"} = $count;
- &deduction_header;
- &deduction_footer;
+ &deduction_header;
+ &deduction_footer;
}
-
sub update_employee {
- # if rate or amount is blank remove row
- @flds = qw(before after);
- $count = 0;
- @a = ();
- for $i (1 .. $form->{deduction_rows}) {
- for (@flds) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
- if ($form->{"deduction_$i"}) {
- push @a, {};
- $j = $#a;
-
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
+ # if rate or amount is blank remove row
+ @flds = qw(before after);
+ $count = 0;
+ @a = ();
+ for $i ( 1 .. $form->{deduction_rows} ) {
+ for (@flds) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+ if ( $form->{"deduction_$i"} ) {
+ push @a, {};
+ $j = $#a;
+
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
}
- }
- $form->redo_rows(\@flds, \@a, $count, $form->{deduction_rows});
- $form->{deduction_rows} = $count;
+ $form->redo_rows( \@flds, \@a, $count, $form->{deduction_rows} );
+ $form->{deduction_rows} = $count;
- &employee_header;
- &employee_footer;
+ &employee_header;
+ &employee_footer;
}
-
sub save_as_new {
- $form->{id} = 0;
- delete $form->{employeelogin};
+ $form->{id} = 0;
+ delete $form->{employeelogin};
- &save;
+ &save;
}
-
sub save_deduction {
- $form->isblank("description", $locale->text("Description missing!"));
+ $form->isblank( "description", $locale->text("Description missing!") );
- unless ($form->{"rate_1"} || $form->{"amount_1"}) {
- $form->isblank("rate_1", $locale->text("Rate missing!")) unless $form->{"amount_1"};
- $form->isblank("amount_1", $locale->text("Amount missing!"));
- }
-
- HR->save_deduction(\%myconfig, \%$form);
- $form->redirect($locale->text('Deduction saved!'));
-
-}
+ unless ( $form->{"rate_1"} || $form->{"amount_1"} ) {
+ $form->isblank( "rate_1", $locale->text("Rate missing!") )
+ unless $form->{"amount_1"};
+ $form->isblank( "amount_1", $locale->text("Amount missing!") );
+ }
+ HR->save_deduction( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Deduction saved!') );
+
+}
sub delete_deduction {
- HR->delete_deduction(\%myconfig, \%$form);
- $form->redirect($locale->text('Deduction deleted!'));
-
-}
+ HR->delete_deduction( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Deduction deleted!') );
+}
diff --git a/bin/ic.pl b/bin/ic.pl
index c1a5b27d..50de73fd 100644
--- a/bin/ic.pl
+++ b/bin/ic.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -40,424 +40,513 @@
#
#======================================================================
-
use LedgerSMB::IC;
use LedgerSMB::Tax;
require "bin/io.pl";
1;
-# end of main
-
+# end of main
sub add {
- %label = ( part => 'Part',
- service => 'Service',
- assembly => 'Assembly',
- labor => 'Labor/Overhead', );
+ %label = (
+ part => 'Part',
+ service => 'Service',
+ assembly => 'Assembly',
+ labor => 'Labor/Overhead',
+ );
+
+ # $locale->text('Add Part')
+ # $locale->text('Add Service')
+ # $locale->text('Add Assembly')
+ # $locale->text('Add Labor/Overhead')
-# $locale->text('Add Part')
-# $locale->text('Add Service')
-# $locale->text('Add Assembly')
-# $locale->text('Add Labor/Overhead')
+ $label = "Add $label{$form->{item}}";
+ $form->{title} = $locale->text($label);
- $label = "Add $label{$form->{item}}";
- $form->{title} = $locale->text($label);
+ $form->{callback} =
+"$form->{script}?action=add&item=$form->{item}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
- $form->{callback} = "$form->{script}?action=add&item=$form->{item}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
+ $form->{orphaned} = 1;
- $form->{orphaned} = 1;
+ if ( $form->{previousform} ) {
+ $form->{callback} = "";
+ }
- if ($form->{previousform}) {
- $form->{callback} = "";
- }
+ &link_part;
- &link_part;
-
- &display_form;
+ &display_form;
}
-
sub edit {
-
- %label = ( part => 'Part',
- service => 'Service',
- assembly => 'Assembly',
- labor => 'Labor/Overhead', );
-# $locale->text('Edit Part')
-# $locale->text('Edit Service')
-# $locale->text('Edit Assembly')
-# $locale->text('Edit Labor/Overhead')
+ %label = (
+ part => 'Part',
+ service => 'Service',
+ assembly => 'Assembly',
+ labor => 'Labor/Overhead',
+ );
+
+ # $locale->text('Edit Part')
+ # $locale->text('Edit Service')
+ # $locale->text('Edit Assembly')
+ # $locale->text('Edit Labor/Overhead')
- IC->get_part(\%myconfig, \%$form);
+ IC->get_part( \%myconfig, \%$form );
- $label = "Edit $label{$form->{item}}";
- $form->{title} = $locale->text($label);
+ $label = "Edit $label{$form->{item}}";
+ $form->{title} = $locale->text($label);
- $form->{previousform} = $form->escape($form->{previousform}, 1) if $form->{previousform};
+ $form->{previousform} = $form->escape( $form->{previousform}, 1 )
+ if $form->{previousform};
- &link_part;
+ &link_part;
- &display_form;
+ &display_form;
}
+sub link_part {
+ IC->create_links( "IC", \%myconfig, \%$form );
-sub link_part {
+ # currencies
+ $form->{selectcurrency} = "";
+ for ( split /:/, $form->{currencies} ) {
+ $form->{selectcurrency} .= "<option>$_\n";
+ }
- IC->create_links("IC", \%myconfig, \%$form);
+ # readonly
+ if ( $form->{item} eq 'part' ) {
+ $form->{readonly} = 1
+ if $myconfig{acs} =~ /Goods \& Services--Add Part/;
+ $form->error(
+ $locale->text(
+ 'Cannot create Part; Inventory account does not exist!')
+ ) if !@{ $form->{IC_links}{IC} };
+ $form->error(
+ $locale->text('Cannot create Part; Income account does not exist!')
+ ) if !@{ $form->{IC_links}{IC_sale} };
+ $form->error(
+ $locale->text('Cannot create Part; COGS account does not exist!') )
+ if !@{ $form->{IC_links}{IC_cogs} };
+ }
- # currencies
- $form->{selectcurrency} = "";
- for (split /:/, $form->{currencies}) { $form->{selectcurrency} .= "<option>$_\n" }
+ if ( $form->{item} eq 'service' ) {
+ $form->{readonly} = 1
+ if $myconfig{acs} =~ /Goods \& Services--Add Service/;
+ $form->error(
+ $locale->text(
+ 'Cannot create Service; Income account does not exist!')
+ ) if !@{ $form->{IC_links}{IC_income} };
+ $form->error(
+ $locale->text(
+ 'Cannot create Service; Expense account does not exist!')
+ ) if !@{ $form->{IC_links}{IC_expense} };
+ }
- # readonly
- if ($form->{item} eq 'part') {
- $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Part/;
- $form->error($locale->text('Cannot create Part; Inventory account does not exist!')) if ! @{ $form->{IC_links}{IC} };
- $form->error($locale->text('Cannot create Part; Income account does not exist!')) if ! @{ $form->{IC_links}{IC_sale} };
- $form->error($locale->text('Cannot create Part; COGS account does not exist!')) if ! @{ $form->{IC_links}{IC_cogs} };
- }
-
- if ($form->{item} eq 'service') {
- $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Service/;
- $form->error($locale->text('Cannot create Service; Income account does not exist!')) if ! @{ $form->{IC_links}{IC_income} };
- $form->error($locale->text('Cannot create Service; Expense account does not exist!')) if ! @{ $form->{IC_links}{IC_expense} };
- }
-
- if ($form->{item} eq 'assembly') {
- $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Assembly/;
- $form->error($locale->text('Cannot create Assembly; Income account does not exist!')) if ! @{ $form->{IC_links}{IC_income} };
- }
- if ($form->{item} eq 'labor') {
- $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Labor\/Overhead/;
- $form->error($locale->text('Cannot create Labor; Inventory account does not exist!')) if ! @{ $form->{IC_links}{IC} };
- $form->error($locale->text('Cannot create Labor; COGS account does not exist!')) if ! @{ $form->{IC_links}{IC_cogs} };
- }
+ if ( $form->{item} eq 'assembly' ) {
+ $form->{readonly} = 1
+ if $myconfig{acs} =~ /Goods \& Services--Add Assembly/;
+ $form->error(
+ $locale->text(
+ 'Cannot create Assembly; Income account does not exist!')
+ ) if !@{ $form->{IC_links}{IC_income} };
+ }
+ if ( $form->{item} eq 'labor' ) {
+ $form->{readonly} = 1
+ if $myconfig{acs} =~ /Goods \& Services--Add Labor\/Overhead/;
+ $form->error(
+ $locale->text(
+ 'Cannot create Labor; Inventory account does not exist!')
+ ) if !@{ $form->{IC_links}{IC} };
+ $form->error(
+ $locale->text('Cannot create Labor; COGS account does not exist!') )
+ if !@{ $form->{IC_links}{IC_cogs} };
+ }
-
- # parts, assemblies , labor and overhead have the same links
- $taxpart = ($form->{item} eq 'service') ? "service" : "part";
-
- # build the popup menus
- $form->{taxaccounts} = "";
- foreach $key (keys %{ $form->{IC_links} }) {
-
- $form->{"select$key"} = "";
- foreach $ref (@{ $form->{IC_links}{$key} }) {
- # if this is a tax field
- if ($key =~ /IC_tax/) {
- if ($key =~ /$taxpart/) {
-
- $form->{taxaccounts} .= "$ref->{accno} ";
- $form->{"IC_tax_$ref->{accno}_description"} = "$ref->{accno}--$ref->{description}";
-
- if ($form->{id}) {
- if ($form->{amount}{$ref->{accno}}) {
- $form->{"IC_tax_$ref->{accno}"} = "checked";
- }
- } else {
- $form->{"IC_tax_$ref->{accno}"} = "checked";
- }
-
- }
- } else {
-
- $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
-
- }
- }
- }
- chop $form->{taxaccounts};
-
- if ($form->{item} !~ /service/) {
- $form->{selectIC_inventory} = $form->{selectIC};
- $form->{selectIC_income} = $form->{selectIC_sale};
- $form->{selectIC_expense} = $form->{selectIC_cogs};
- $form->{IC_income} = $form->{IC_sale};
- $form->{IC_expense} = $form->{IC_cogs};
- }
-
- # set option
- for (qw(IC_inventory IC_income IC_expense)) { $form->{$_} = "$form->{amount}{$_}{accno}--$form->{amount}{$_}{description}" if $form->{amount}{$_}{accno} }
-
- delete $form->{IC_links};
- delete $form->{amount};
-
- $form->get_partsgroup(\%myconfig, {all => 1});
- if ($form->{partsgroup}) {
- $form->{partsgroup} = $form->quote($form->{partsgroup})."--$form->{partsgroup_id}";
- }
-
- if (@{ $form->{all_partsgroup} }) {
- $form->{selectpartsgroup} = qq|<option>\n|;
+ # parts, assemblies , labor and overhead have the same links
+ $taxpart = ( $form->{item} eq 'service' ) ? "service" : "part";
+
+ # build the popup menus
+ $form->{taxaccounts} = "";
+ foreach $key ( keys %{ $form->{IC_links} } ) {
- for (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} .= qq|<option value="|.$form->quote($_->{partsgroup}).qq|--$_->{id}">$_->{partsgroup}\n| }
- delete $form->{all_partsgroup};
- }
+ $form->{"select$key"} = "";
+ foreach $ref ( @{ $form->{IC_links}{$key} } ) {
- if ($form->{item} eq 'assembly') {
+ # if this is a tax field
+ if ( $key =~ /IC_tax/ ) {
+ if ( $key =~ /$taxpart/ ) {
- for (1 .. $form->{assembly_rows}) {
- if ($form->{"partsgroup_id_$_"}) {
- $form->{"partsgroup_$_"} = qq|$form->{"partsgroup_$_"}--$form->{"partsgroup_id_$_"}|;
- }
+ $form->{taxaccounts} .= "$ref->{accno} ";
+ $form->{"IC_tax_$ref->{accno}_description"} =
+ "$ref->{accno}--$ref->{description}";
+
+ if ( $form->{id} ) {
+ if ( $form->{amount}{ $ref->{accno} } ) {
+ $form->{"IC_tax_$ref->{accno}"} = "checked";
+ }
+ }
+ else {
+ $form->{"IC_tax_$ref->{accno}"} = "checked";
+ }
+
+ }
+ }
+ else {
+
+ $form->{"select$key"} .=
+ "<option>$ref->{accno}--$ref->{description}\n";
+
+ }
+ }
+ }
+ chop $form->{taxaccounts};
+
+ if ( $form->{item} !~ /service/ ) {
+ $form->{selectIC_inventory} = $form->{selectIC};
+ $form->{selectIC_income} = $form->{selectIC_sale};
+ $form->{selectIC_expense} = $form->{selectIC_cogs};
+ $form->{IC_income} = $form->{IC_sale};
+ $form->{IC_expense} = $form->{IC_cogs};
}
-
- $form->get_partsgroup(\%myconfig);
- if (@{ $form->{all_partsgroup} }) {
- $form->{selectassemblypartsgroup} = qq|<option>\n|;
+ # set option
+ for (qw(IC_inventory IC_income IC_expense)) {
+ $form->{$_} =
+ "$form->{amount}{$_}{accno}--$form->{amount}{$_}{description}"
+ if $form->{amount}{$_}{accno};
+ }
+
+ delete $form->{IC_links};
+ delete $form->{amount};
- for (@{ $form->{all_partsgroup} }) { $form->{selectassemblypartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| }
- delete $form->{all_partsgroup};
+ $form->get_partsgroup( \%myconfig, { all => 1 } );
+ if ( $form->{partsgroup} ) {
+ $form->{partsgroup} =
+ $form->quote( $form->{partsgroup} ) . "--$form->{partsgroup_id}";
}
- }
-
- # setup make and models
- $i = 1;
- foreach $ref (@{ $form->{makemodels} }) {
- for (qw(make model)) { $form->{"${_}_$i"} = $ref->{$_} }
- $i++;
- }
- $form->{makemodel_rows} = $i - 1;
- delete $form->{makemodels};
-
- # setup vendors
- if (@{ $form->{all_vendor} }) {
- $form->{selectvendor} = "<option>\n";
- for (@{ $form->{all_vendor} }) { $form->{selectvendor} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- delete $form->{all_vendor};
- }
-
- # vendor matrix
- $i = 1;
- foreach $ref (@{ $form->{vendormatrix} }) {
- $form->{"vendor_$i"} = qq|$ref->{name}--$ref->{id}|;
-
- for (qw(partnumber lastcost leadtime vendorcurr)) { $form->{"${_}_$i"} = $ref->{$_} }
- $i++;
- }
- $form->{vendor_rows} = $i - 1;
- delete $form->{vendormatrix};
-
- # setup customers and groups
- if (@{ $form->{all_customer} }) {
- $form->{selectcustomer} = "<option>\n";
- for (@{ $form->{all_customer} }) { $form->{selectcustomer} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- delete $form->{all_customer};
- }
-
- if (@{ $form->{all_pricegroup} }) {
- $form->{selectpricegroup} = "<option>\n";
- for (@{ $form->{all_pricegroup} }) { $form->{selectpricegroup} .= qq|<option value="$_->{pricegroup}--$_->{id}">$_->{pricegroup}\n| }
- delete $form->{all_pricegroup};
- }
-
- $i = 1;
- # customer matrix
- foreach $ref (@{ $form->{customermatrix} }) {
-
- $form->{"customer_$i"} = "$ref->{name}--$ref->{cid}" if $ref->{cid};
- $form->{"pricegroup_$i"} = "$ref->{pricegroup}--$ref->{gid}" if $ref->{gid};
-
- for (qw(validfrom validto pricebreak customerprice customercurr)) { $form->{"${_}_$i"} = $ref->{$_} }
-
- $i++;
-
- }
- $form->{customer_rows} = $i - 1;
- delete $form->{customermatrix};
+ if ( @{ $form->{all_partsgroup} } ) {
+ $form->{selectpartsgroup} = qq|<option>\n|;
-}
+ for ( @{ $form->{all_partsgroup} } ) {
+ $form->{selectpartsgroup} .=
+ qq|<option value="|
+ . $form->quote( $_->{partsgroup} )
+ . qq|--$_->{id}">$_->{partsgroup}\n|;
+ }
+ delete $form->{all_partsgroup};
+ }
+
+ if ( $form->{item} eq 'assembly' ) {
+
+ for ( 1 .. $form->{assembly_rows} ) {
+ if ( $form->{"partsgroup_id_$_"} ) {
+ $form->{"partsgroup_$_"} =
+ qq|$form->{"partsgroup_$_"}--$form->{"partsgroup_id_$_"}|;
+ }
+ }
+ $form->get_partsgroup( \%myconfig );
+ if ( @{ $form->{all_partsgroup} } ) {
+ $form->{selectassemblypartsgroup} = qq|<option>\n|;
+
+ for ( @{ $form->{all_partsgroup} } ) {
+ $form->{selectassemblypartsgroup} .=
+qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|;
+ }
+ delete $form->{all_partsgroup};
+ }
+ }
+
+ # setup make and models
+ $i = 1;
+ foreach $ref ( @{ $form->{makemodels} } ) {
+ for (qw(make model)) { $form->{"${_}_$i"} = $ref->{$_} }
+ $i++;
+ }
+ $form->{makemodel_rows} = $i - 1;
+ delete $form->{makemodels};
+
+ # setup vendors
+ if ( @{ $form->{all_vendor} } ) {
+ $form->{selectvendor} = "<option>\n";
+ for ( @{ $form->{all_vendor} } ) {
+ $form->{selectvendor} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ delete $form->{all_vendor};
+ }
+
+ # vendor matrix
+ $i = 1;
+ foreach $ref ( @{ $form->{vendormatrix} } ) {
+ $form->{"vendor_$i"} = qq|$ref->{name}--$ref->{id}|;
+
+ for (qw(partnumber lastcost leadtime vendorcurr)) {
+ $form->{"${_}_$i"} = $ref->{$_};
+ }
+ $i++;
+ }
+ $form->{vendor_rows} = $i - 1;
+ delete $form->{vendormatrix};
+
+ # setup customers and groups
+ if ( @{ $form->{all_customer} } ) {
+ $form->{selectcustomer} = "<option>\n";
+ for ( @{ $form->{all_customer} } ) {
+ $form->{selectcustomer} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ delete $form->{all_customer};
+ }
+
+ if ( @{ $form->{all_pricegroup} } ) {
+ $form->{selectpricegroup} = "<option>\n";
+ for ( @{ $form->{all_pricegroup} } ) {
+ $form->{selectpricegroup} .=
+ qq|<option value="$_->{pricegroup}--$_->{id}">$_->{pricegroup}\n|;
+ }
+ delete $form->{all_pricegroup};
+ }
+
+ $i = 1;
+
+ # customer matrix
+ foreach $ref ( @{ $form->{customermatrix} } ) {
+
+ $form->{"customer_$i"} = "$ref->{name}--$ref->{cid}" if $ref->{cid};
+ $form->{"pricegroup_$i"} = "$ref->{pricegroup}--$ref->{gid}"
+ if $ref->{gid};
+
+ for (qw(validfrom validto pricebreak customerprice customercurr)) {
+ $form->{"${_}_$i"} = $ref->{$_};
+ }
+
+ $i++;
+
+ }
+ $form->{customer_rows} = $i - 1;
+ delete $form->{customermatrix};
+
+}
sub form_header {
- if ($form->{lastcost} > 0) {
- $markup = $form->round_amount((($form->{sellprice}/$form->{lastcost} - 1) * 100), 1);
- $form->{markup} = $form->format_amount(\%myconfig, $markup, 1);
- }
-
- ($dec) = ($form->{sellprice} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
-
- for (qw(listprice sellprice)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces) }
-
- ($dec) = ($form->{lastcost} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
-
- for (qw(lastcost avgcost)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces) }
-
- for (qw(weight rop stock)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) }
-
- for (qw(partnumber description unit notes)) { $form->{$_} = $form->quote($form->{$_}) }
+ if ( $form->{lastcost} > 0 ) {
+ $markup =
+ $form->round_amount(
+ ( ( $form->{sellprice} / $form->{lastcost} - 1 ) * 100 ), 1 );
+ $form->{markup} = $form->format_amount( \%myconfig, $markup, 1 );
+ }
- if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
- $rows = 2;
- }
-
- $notes = qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|;
+ ($dec) = ( $form->{sellprice} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces = ( $dec > 2 ) ? $dec : 2;
- if (($rows = $form->numtextrows($form->{description}, 40)) > 1) {
- $description = qq|<textarea name="description" rows=$rows cols=40 wrap=soft>$form->{description}</textarea>|;
- } else {
- $description = qq|<input name=description size=40 value="$form->{description}">|;
- }
-
- for (split / /, $form->{taxaccounts}) { $form->{"IC_tax_$_"} = ($form->{"IC_tax_$_"}) ? "checked" : "" }
+ for (qw(listprice sellprice)) {
+ $form->{$_} =
+ $form->format_amount( \%myconfig, $form->{$_}, $decimalplaces );
+ }
- $form->{selectIC_inventory} = $form->{selectIC};
-
- # set option
- for (qw(IC_inventory IC_income IC_expense)) {
- if ($form->{$_}) {
- if ($form->{orphaned}) {
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
- } else {
- $form->{"select$_"} = qq|<option selected>$form->{$_}|;
- }
- }
- }
-
- if ($form->{selectpartsgroup}) {
- $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup});
-
- $partsgroup = qq|<input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|">|;
-
- $form->{partsgroup} = $form->quote($form->{partsgroup});
- $form->{selectpartsgroup} =~ s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
-
- $partsgroup .= qq|\n<select name=partsgroup>$form->{selectpartsgroup}</select>|;
- $group = $locale->text('Group');
- }
-
- # tax fields
- foreach $item (split / /, $form->{taxaccounts}) {
- $tax .= qq|
+ ($dec) = ( $form->{lastcost} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ for (qw(lastcost avgcost)) {
+ $form->{$_} =
+ $form->format_amount( \%myconfig, $form->{$_}, $decimalplaces );
+ }
+
+ for (qw(weight rop stock)) {
+ $form->{$_} = $form->format_amount( \%myconfig, $form->{$_} );
+ }
+
+ for (qw(partnumber description unit notes)) {
+ $form->{$_} = $form->quote( $form->{$_} );
+ }
+
+ if ( ( $rows = $form->numtextrows( $form->{notes}, 40 ) ) < 2 ) {
+ $rows = 2;
+ }
+
+ $notes =
+qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|;
+
+ if ( ( $rows = $form->numtextrows( $form->{description}, 40 ) ) > 1 ) {
+ $description =
+qq|<textarea name="description" rows=$rows cols=40 wrap=soft>$form->{description}</textarea>|;
+ }
+ else {
+ $description =
+ qq|<input name=description size=40 value="$form->{description}">|;
+ }
+
+ for ( split / /, $form->{taxaccounts} ) {
+ $form->{"IC_tax_$_"} = ( $form->{"IC_tax_$_"} ) ? "checked" : "";
+ }
+
+ $form->{selectIC_inventory} = $form->{selectIC};
+
+ # set option
+ for (qw(IC_inventory IC_income IC_expense)) {
+ if ( $form->{$_} ) {
+ if ( $form->{orphaned} ) {
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~
+ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
+ }
+ else {
+ $form->{"select$_"} = qq|<option selected>$form->{$_}|;
+ }
+ }
+ }
+
+ if ( $form->{selectpartsgroup} ) {
+ $form->{selectpartsgroup} =
+ $form->unescape( $form->{selectpartsgroup} );
+
+ $partsgroup =
+ qq|<input type=hidden name=selectpartsgroup value="|
+ . $form->escape( $form->{selectpartsgroup}, 1 ) . qq|">|;
+
+ $form->{partsgroup} = $form->quote( $form->{partsgroup} );
+ $form->{selectpartsgroup} =~
+ s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
+
+ $partsgroup .=
+ qq|\n<select name=partsgroup>$form->{selectpartsgroup}</select>|;
+ $group = $locale->text('Group');
+ }
+
+ # tax fields
+ foreach $item ( split / /, $form->{taxaccounts} ) {
+ $tax .= qq|
<input class=checkbox type=checkbox name="IC_tax_$item" value=1 $form->{"IC_tax_$item"}>&nbsp;<b>$form->{"IC_tax_${item}_description"}</b>
<br><input type=hidden name=IC_tax_${item}_description value="$form->{"IC_tax_${item}_description"}">
|;
- }
+ }
-
- $sellprice = qq|
+ $sellprice = qq|
<tr>
- <th align="right" nowrap="true">|.$locale->text('Sell Price').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Sell Price') . qq|</th>
<td><input name=sellprice size=11 value=$form->{sellprice}></td>
</tr>
<tr>
- <th align="right" nowrap="true">|.$locale->text('List Price').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('List Price') . qq|</th>
<td><input name=listprice size=11 value=$form->{listprice}></td>
</tr>
|;
- $avgcost = qq|
+ $avgcost = qq|
<tr>
- <th align="right" nowrap="true">|.$locale->text('Average Cost').qq|</th>
+ <th align="right" nowrap="true">|
+ . $locale->text('Average Cost')
+ . qq|</th>
<td><input type=hidden name=avgcost value=$form->{avgcost}>$form->{avgcost}</td>
</tr>
|;
- $lastcost = qq|
+ $lastcost = qq|
<tr>
- <th align="right" nowrap="true">|.$locale->text('Last Cost').qq|</th>
+ <th align="right" nowrap="true">|
+ . $locale->text('Last Cost')
+ . qq|</th>
<td><input name=lastcost size=11 value=$form->{lastcost}></td>
</tr>
<tr>
- <th align="right" nowrap="true">|.$locale->text('Markup').qq| %</th>
+ <th align="right" nowrap="true">|
+ . $locale->text('Markup')
+ . qq| %</th>
<td><input name=markup size=5 value=$form->{markup}></td>
<input type=hidden name=oldmarkup value=$markup>
</tr>
|;
-
- if ($form->{item} =~ /(part|assembly)/) {
- $n = ($form->{onhand} > 0) ? "1" : "0";
- $onhand = qq|
+ if ( $form->{item} =~ /(part|assembly)/ ) {
+ $n = ( $form->{onhand} > 0 ) ? "1" : "0";
+ $onhand = qq|
<tr>
- <th align="right" nowrap>|.$locale->text('On Hand').qq|</th>
- <th align=left nowrap class="plus$n">&nbsp;|.$form->format_amount(\%myconfig, $form->{onhand}).qq|</th>
+ <th align="right" nowrap>| . $locale->text('On Hand') . qq|</th>
+ <th align=left nowrap class="plus$n">&nbsp;|
+ . $form->format_amount( \%myconfig, $form->{onhand} )
+ . qq|</th>
</tr>
|;
- $rop = qq|
+ $rop = qq|
<tr>
- <th align="right" nowrap="true">|.$locale->text('ROP').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('ROP') . qq|</th>
<td><input name=rop size=10 value=$form->{rop}></td>
</tr>
|;
-
- $bin = qq|
+
+ $bin = qq|
<tr>
- <th align="right" nowrap="true">|.$locale->text('Bin').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Bin') . qq|</th>
<td><input name=bin size=10 value="$form->{bin}"></td>
</tr>
|;
-
- $imagelinks = qq|
+
+ $imagelinks = qq|
<tr>
<td>
<table width=100%>
<tr>
- <th align=right nowrap>|.$locale->text('Image').qq|</th>
+ <th align=right nowrap>| . $locale->text('Image') . qq|</th>
<td><input name=image size=40 value="$form->{image}"></td>
- <th align=right nowrap>|.$locale->text('Microfiche').qq|</th>
+ <th align=right nowrap>| . $locale->text('Microfiche') . qq|</th>
<td><input name=microfiche size=20 value="$form->{microfiche}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Drawing').qq|</th>
+ <th align=right nowrap>| . $locale->text('Drawing') . qq|</th>
<td><input name=drawing size=40 value="$form->{drawing}"></td>
</tr>
</table>
</td>
</tr>
|;
- }
-
+ }
- if ($form->{item} eq "part") {
+ if ( $form->{item} eq "part" ) {
- $linkaccounts = qq|
+ $linkaccounts = qq|
<tr>
- <th align=right>|.$locale->text('Inventory').qq|</th>
+ <th align=right>| . $locale->text('Inventory') . qq|</th>
<td><select name=IC_inventory>$form->{selectIC_inventory}</select></td>
<input name=selectIC type=hidden value="$form->{selectIC}">
</tr>
<tr>
- <th align=right>|.$locale->text('Income').qq|</th>
+ <th align=right>| . $locale->text('Income') . qq|</th>
<td><select name=IC_income>$form->{selectIC_income}</select></td>
<input name=selectIC_income type=hidden value="$form->{selectIC_income}">
</tr>
<tr>
- <th align=right>|.$locale->text('COGS').qq|</th>
+ <th align=right>| . $locale->text('COGS') . qq|</th>
<td><select name=IC_expense>$form->{selectIC_expense}</select></td>
<input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
</tr>
|;
-
- if ($tax) {
- $linkaccounts .= qq|
+
+ if ($tax) {
+ $linkaccounts .= qq|
<tr>
- <th align=right>|.$locale->text('Tax').qq|</th>
+ <th align=right>| . $locale->text('Tax') . qq|</th>
<td>$tax</td>
</tr>
|;
- }
-
- $weight = qq|
+ }
+
+ $weight = qq|
<tr>
- <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
<td>
<table>
<tr>
@@ -474,18 +563,17 @@ sub form_header {
</td>
</tr>
|;
-
- }
+ }
+
+ if ( $form->{item} eq "assembly" ) {
- if ($form->{item} eq "assembly") {
+ $avgcost = "";
- $avgcost = "";
-
- if ($form->{project_id}) {
- $weight = qq|
+ if ( $form->{project_id} ) {
+ $weight = qq|
<tr>
- <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
<td>
<table>
<tr>
@@ -502,11 +590,12 @@ sub form_header {
</td>
</tr>
|;
- } else {
-
- $weight = qq|
+ }
+ else {
+
+ $weight = qq|
<tr>
- <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
<td>
<table>
<tr>
@@ -524,139 +613,145 @@ sub form_header {
</td>
</tr>
|;
- }
-
+ }
- if ($form->{project_id}) {
- $lastcost = "";
- $avgcost = "";
- $onhand = "";
- $rop = "";
- $form->{isassemblyitem} = 1;
+ if ( $form->{project_id} ) {
+ $lastcost = "";
+ $avgcost = "";
+ $onhand = "";
+ $rop = "";
+ $form->{isassemblyitem} = 1;
- } else {
- $stock = qq|
+ }
+ else {
+ $stock = qq|
<tr>
- <th align="right" nowrap>|.$locale->text('Stock').qq|</th>
+ <th align="right" nowrap>| . $locale->text('Stock') . qq|</th>
<td><input name=stock size=10 value=$form->{stock}></td>
</tr>
|;
- $lastcost = qq|
+ $lastcost = qq|
<tr>
- <th align="right" nowrap="true">|.$locale->text('Last Cost').qq|</th>
+ <th align="right" nowrap="true">|
+ . $locale->text('Last Cost')
+ . qq|</th>
<td><input type=hidden name=lastcost value=$form->{lastcost}>$form->{lastcost}</td>
</tr>
<tr>
- <th align="right" nowrap="true">|.$locale->text('Markup').qq| %</th>
+ <th align="right" nowrap="true">|
+ . $locale->text('Markup')
+ . qq| %</th>
<td><input name=markup size=5 value=$form->{markup}></td>
<input type=hidden name=oldmarkup value=$markup>
</tr>
|;
- }
+ }
- $linkaccounts = qq|
+ $linkaccounts = qq|
<tr>
- <th align=right>|.$locale->text('Income').qq|</th>
+ <th align=right>| . $locale->text('Income') . qq|</th>
<td><select name=IC_income>$form->{selectIC_income}</select></td>
<input name=selectIC_income type=hidden value="$form->{selectIC_income}">
</tr>
|;
-
- if ($tax) {
- $linkaccounts .= qq|
+
+ if ($tax) {
+ $linkaccounts .= qq|
<tr>
- <th align=right>|.$locale->text('Tax').qq|</th>
+ <th align=right>| . $locale->text('Tax') . qq|</th>
<td>$tax</td>
</tr>
|;
+ }
+
}
-
- }
-
- if ($form->{item} eq "service") {
- $avgcost = "";
- $linkaccounts = qq|
+ if ( $form->{item} eq "service" ) {
+ $avgcost = "";
+ $linkaccounts = qq|
<tr>
- <th align=right>|.$locale->text('Income').qq|</th>
+ <th align=right>| . $locale->text('Income') . qq|</th>
<td><select name=IC_income>$form->{selectIC_income}</select></td>
<input name=selectIC_income type=hidden value="$form->{selectIC_income}">
</tr>
<tr>
- <th align=right>|.$locale->text('Expense').qq|</th>
+ <th align=right>| . $locale->text('Expense') . qq|</th>
<td><select name=IC_expense>$form->{selectIC_expense}</select></td>
<input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
</tr>
|;
-
- if ($tax) {
- $linkaccounts .= qq|
+
+ if ($tax) {
+ $linkaccounts .= qq|
<tr>
- <th align=right>|.$locale->text('Tax').qq|</th>
+ <th align=right>| . $locale->text('Tax') . qq|</th>
<td>$tax</td>
</tr>
|;
- }
+ }
- }
+ }
- if ($form->{item} eq 'labor') {
- $avgcost = "";
+ if ( $form->{item} eq 'labor' ) {
+ $avgcost = "";
- $n = ($form->{onhand} > 0) ? "1" : "0";
- $onhand = qq|
+ $n = ( $form->{onhand} > 0 ) ? "1" : "0";
+ $onhand = qq|
<tr>
- <th align="right" nowrap>|.$locale->text('On Hand').qq|</th>
- <th align=left nowrap class="plus$n">&nbsp;|.$form->format_amount(\%myconfig, $form->{onhand}).qq|</th>
+ <th align="right" nowrap>| . $locale->text('On Hand') . qq|</th>
+ <th align=left nowrap class="plus$n">&nbsp;|
+ . $form->format_amount( \%myconfig, $form->{onhand} )
+ . qq|</th>
</tr>
|;
-
- $linkaccounts = qq|
+
+ $linkaccounts = qq|
<tr>
- <th align=right>|.$locale->text('Labor/Overhead').qq|</th>
+ <th align=right>| . $locale->text('Labor/Overhead') . qq|</th>
<td><select name=IC_inventory>$form->{selectIC_inventory}</select></td>
<input name=selectIC type=hidden value="$form->{selectIC}">
</tr>
<tr>
- <th align=right>|.$locale->text('COGS').qq|</th>
+ <th align=right>| . $locale->text('COGS') . qq|</th>
<td><select name=IC_expense>$form->{selectIC_expense}</select></td>
<input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
</tr>
|;
-
- }
- if ($form->{id}) {
- $checked = ($form->{obsolete}) ? "checked" : "";
- $obsolete = qq|
+ }
+
+ if ( $form->{id} ) {
+ $checked = ( $form->{obsolete} ) ? "checked" : "";
+ $obsolete = qq|
<tr>
- <th align="right" nowrap="true">|.$locale->text('Obsolete').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Obsolete') . qq|</th>
<td><input name=obsolete type=checkbox class=checkbox value=1 $checked></td>
</tr>
|;
- $obsolete = "<input type=hidden name=obsolete value=$form->{obsolete}>" if $form->{project_id};
- }
-
-
-# type=submit $locale->text('Edit Part')
-# type=submit $locale->text('Edit Service')
-# type=submit $locale->text('Edit Assembly')
+ $obsolete = "<input type=hidden name=obsolete value=$form->{obsolete}>"
+ if $form->{project_id};
+ }
+ # type=submit $locale->text('Edit Part')
+ # type=submit $locale->text('Edit Service')
+ # type=submit $locale->text('Edit Assembly')
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action="$form->{script}">
|;
- $form->hide_form(qw(id item title makemodel alternate onhand orphaned taxaccounts rowcount baseassembly project_id));
-
- print qq|
+ $form->hide_form(
+ qw(id item title makemodel alternate onhand orphaned taxaccounts rowcount baseassembly project_id)
+ );
+
+ print qq|
<table width="100%">
<tr>
<th class=listtop>$form->{title}</th>
@@ -666,8 +761,8 @@ sub form_header {
<td>
<table width="100%">
<tr valign=top>
- <th align=left>|.$locale->text('Number').qq|</th>
- <th align=left>|.$locale->text('Description').qq|</th>
+ <th align=left>| . $locale->text('Number') . qq|</th>
+ <th align=left>| . $locale->text('Description') . qq|</th>
<th align=left>$group</th>
</tr>
<tr valign=top>
@@ -685,11 +780,13 @@ sub form_header {
<td width=70%>
<table width="100%" height="100%">
<tr class="listheading">
- <th class="listheading" align="center" colspan=2>|.$locale->text('Link Accounts').qq|</th>
+ <th class="listheading" align="center" colspan=2>|
+ . $locale->text('Link Accounts')
+ . qq|</th>
</tr>
$linkaccounts
<tr>
- <th align="left">|.$locale->text('Notes').qq|</th>
+ <th align="left">| . $locale->text('Notes') . qq|</th>
</tr>
<tr>
<td colspan=2>
@@ -701,14 +798,14 @@ sub form_header {
<td width="30%">
<table width="100%">
<tr>
- <th align="right" nowrap="true">|.$locale->text('Updated').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Updated') . qq|</th>
<td><input name=priceupdate size=11 title="$myconfig{dateformat}" value=$form->{priceupdate}></td>
</tr>
$sellprice
$lastcost
$avgcost
<tr>
- <th align="right" nowrap="true">|.$locale->text('Unit').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Unit') . qq|</th>
<td><input name=unit size=5 value="$form->{unit}"></td>
</tr>
$weight
@@ -727,63 +824,73 @@ sub form_header {
|;
}
-
sub form_footer {
- print qq|
+ print qq|
<tr>
<td><hr size=3 noshade></td>
</tr>
</table>
|;
- $form->hide_form(qw(customer_rows));
+ $form->hide_form(qw(customer_rows));
- if ($form->{item} =~ /(part|assembly)/) {
- $form->hide_form(qw(makemodel_rows));
- }
-
- if ($form->{item} =~ /(part|service)/) {
- $form->hide_form(qw(vendor_rows));
- }
-
-# type=submit $locale->text('Update')
-# type=submit $locale->text('Save')
-# type=submit $locale->text('Save as new')
-# type=submit $locale->text('Delete')
-
- if (! $form->{readonly}) {
-
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
- );
-
- if ($form->{id}) {
-
- if (!$form->{isassemblyitem}) {
- $button{'save_as_new'} = { ndx => 7, key => 'N', value => $locale->text('Save as new') };
- }
-
- if ($form->{orphaned}) {
- $button{'delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') };
- }
- }
- %button = () if $form->{isassemblyitem} && $form->{item} eq 'assembly';
-
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
-
- }
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- &assembly_row(++$form->{assembly_rows}) if $form->{item} eq 'assembly';
-
- $form->hide_form(qw(login path sessionid callback previousform isassemblyitem));
-
- print qq|
+ if ( $form->{item} =~ /(part|assembly)/ ) {
+ $form->hide_form(qw(makemodel_rows));
+ }
+
+ if ( $form->{item} =~ /(part|service)/ ) {
+ $form->hide_form(qw(vendor_rows));
+ }
+
+ # type=submit $locale->text('Update')
+ # type=submit $locale->text('Save')
+ # type=submit $locale->text('Save as new')
+ # type=submit $locale->text('Delete')
+
+ if ( !$form->{readonly} ) {
+
+ %button = (
+ 'update' =>
+ { ndx => 1, key => 'U', value => $locale->text('Update') },
+ 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
+ );
+
+ if ( $form->{id} ) {
+
+ if ( !$form->{isassemblyitem} ) {
+ $button{'save_as_new'} = {
+ ndx => 7,
+ key => 'N',
+ value => $locale->text('Save as new')
+ };
+ }
+
+ if ( $form->{orphaned} ) {
+ $button{'delete'} =
+ { ndx => 16, key => 'D', value => $locale->text('Delete') };
+ }
+ }
+ %button = () if $form->{isassemblyitem} && $form->{item} eq 'assembly';
+
+ for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
+ {
+ $form->print_button( \%button, $_ );
+ }
+
+ }
+
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ &assembly_row( ++$form->{assembly_rows} ) if $form->{item} eq 'assembly';
+
+ $form->hide_form(
+ qw(login path sessionid callback previousform isassemblyitem));
+
+ print qq|
</form>
</body>
@@ -792,266 +899,345 @@ sub form_footer {
}
-
sub search {
- $form->get_partsgroup(\%myconfig, { searchitems => $form->{searchitems}});
+ $form->get_partsgroup( \%myconfig,
+ { searchitems => $form->{searchitems} } );
- IC->get_warehouses(\%myconfig, \%$form) unless $form->{searchitems} =~ /(service|labor)/;
+ IC->get_warehouses( \%myconfig, \%$form )
+ unless $form->{searchitems} =~ /(service|labor)/;
- if (@{ $form->{all_partsgroup} }) {
- $partsgroup = qq|<option>\n|;
+ if ( @{ $form->{all_partsgroup} } ) {
+ $partsgroup = qq|<option>\n|;
- for (@{ $form->{all_partsgroup} }) { $partsgroup .= qq|<option value="|.$form->quote($_->{partsgroup}).qq|--$_->{id}">$_->{partsgroup}\n| }
+ for ( @{ $form->{all_partsgroup} } ) {
+ $partsgroup .=
+ qq|<option value="|
+ . $form->quote( $_->{partsgroup} )
+ . qq|--$_->{id}">$_->{partsgroup}\n|;
+ }
- $partsgroup = qq|
- <th align=right nowrap>|.$locale->text('Group').qq|</th>
+ $partsgroup = qq|
+ <th align=right nowrap>| . $locale->text('Group') . qq|</th>
<td><select name=partsgroup>$partsgroup</select></td>
|;
- $l_partsgroup = qq|<input name=l_partsgroup class=checkbox type=checkbox value=Y> |.$locale->text('Group');
- }
+ $l_partsgroup =
+ qq|<input name=l_partsgroup class=checkbox type=checkbox value=Y> |
+ . $locale->text('Group');
+ }
- $l_listprice = qq|<input name=l_listprice class=checkbox type=checkbox value=Y> |.$locale->text('List Price');
- $l_sellprice = qq|<input name=l_sellprice class=checkbox type=checkbox value=Y checked> |.$locale->text('Sell Price');
- $l_lastcost = qq|<input name=l_lastcost class=checkbox type=checkbox value=Y checked> |.$locale->text('Last Cost');
- $l_avgcost = qq|<input name=l_avgcost class=checkbox type=checkbox value=Y checked> |.$locale->text('Average Cost');
- $l_linetotal = qq|<input name=l_linetotal class=checkbox type=checkbox value=Y> |.$locale->text('Line Total');
- $l_markup = qq|<input name=l_markup class=checkbox type=checkbox value=Y> |.$locale->text('Markup');
- $l_account = qq|<input name=l_account class=checkbox type=checkbox value=Y> |.$locale->text('Accounts');
-
- $bought = qq|
+ $l_listprice =
+ qq|<input name=l_listprice class=checkbox type=checkbox value=Y> |
+ . $locale->text('List Price');
+ $l_sellprice =
+ qq|<input name=l_sellprice class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Sell Price');
+ $l_lastcost =
+ qq|<input name=l_lastcost class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Last Cost');
+ $l_avgcost =
+ qq|<input name=l_avgcost class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Average Cost');
+ $l_linetotal =
+ qq|<input name=l_linetotal class=checkbox type=checkbox value=Y> |
+ . $locale->text('Line Total');
+ $l_markup =
+ qq|<input name=l_markup class=checkbox type=checkbox value=Y> |
+ . $locale->text('Markup');
+ $l_account =
+ qq|<input name=l_account class=checkbox type=checkbox value=Y> |
+ . $locale->text('Accounts');
+
+ $bought = qq|
<td>
<table>
<tr>
<td><input name=bought class=checkbox type=checkbox value=1></td>
- <td nowrap>|.$locale->text('Vendor Invoices').qq|</td>
+ <td nowrap>| . $locale->text('Vendor Invoices') . qq|</td>
</tr>
<tr>
<td><input name=onorder class=checkbox type=checkbox value=1></td>
- <td nowrap>|.$locale->text('Purchase Orders').qq|</td>
+ <td nowrap>| . $locale->text('Purchase Orders') . qq|</td>
</tr>
<tr>
<td><input name=rfq class=checkbox type=checkbox value=1></td>
- <td nowrap>|.$locale->text('RFQ').qq|</td>
+ <td nowrap>| . $locale->text('RFQ') . qq|</td>
</tr>
</table>
</td>
|;
- $sold = qq|
+ $sold = qq|
<td>
<table>
<tr>
<td><input name=sold class=checkbox type=checkbox value=1></td>
- <td nowrap>|.$locale->text('Sales Invoices').qq|</td>
+ <td nowrap>| . $locale->text('Sales Invoices') . qq|</td>
</tr>
<tr>
<td><input name=ordered class=checkbox type=checkbox value=1></td>
- <td nowrap>|.$locale->text('Sales Orders').qq|</td>
+ <td nowrap>| . $locale->text('Sales Orders') . qq|</td>
</tr>
<tr>
<td><input name=quoted class=checkbox type=checkbox value=1></td>
- <td nowrap>|.$locale->text('Quotations').qq|</td>
+ <td nowrap>| . $locale->text('Quotations') . qq|</td>
</tr>
</table>
</td>
|;
- $fromto = qq|
+ $fromto = qq|
<td>
<table>
<tr>
- <td nowrap><b>|.$locale->text('From').qq|</b>
+ <td nowrap><b>| . $locale->text('From') . qq|</b>
<input name=transdatefrom size=11 title="$myconfig{dateformat}">
- <b>|.$locale->text('To').qq|</b>
+ <b>| . $locale->text('To') . qq|</b>
<input name=transdateto size=11 title="$myconfig{dateformat}"></td>
</tr>
<tr>
- <td nowrap><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
- <input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
+ <td nowrap><input name=method class=radio type=radio value=accrual checked>|
+ . $locale->text('Accrual') . qq|
+ <input name=method class=radio type=radio value=cash>|
+ . $locale->text('Cash')
+ . qq|</td>
</tr>
<tr>
<td nowrap>
- <input name=open class=checkbox type=checkbox value=1 checked> |.$locale->text('Open').qq|
- <input name=closed class=checkbox type=checkbox> |.$locale->text('Closed').qq|
- <input name=summary type=radio class=radio value=1> |.$locale->text('Summary').qq|
- <input name=summary type=radio class=radio value=0 checked> |.$locale->text('Detail').qq|
+ <input name=open class=checkbox type=checkbox value=1 checked> |
+ . $locale->text('Open') . qq|
+ <input name=closed class=checkbox type=checkbox> |
+ . $locale->text('Closed') . qq|
+ <input name=summary type=radio class=radio value=1> |
+ . $locale->text('Summary') . qq|
+ <input name=summary type=radio class=radio value=0 checked> |
+ . $locale->text('Detail') . qq|
</td>
</tr>
</table>
</td>
|;
- $l_name = qq|<input name=l_name class=checkbox type=checkbox value=Y> |.$locale->text('Name');
- $l_curr = qq|<input name=l_curr class=checkbox type=checkbox value=Y> |.$locale->text('Currency');
- $l_employee = qq|<input name=l_employee class=checkbox type=checkbox value=Y> |.$locale->text('Employee');
- $l_serialnumber = qq|<input name=l_serialnumber class=checkbox type=checkbox value=Y> |.$locale->text('Serial Number');
-
- $serialnumber = qq|
- <th align=right nowrap>|.$locale->text('Serial Number').qq|</th>
+ $l_name =
+ qq|<input name=l_name class=checkbox type=checkbox value=Y> |
+ . $locale->text('Name');
+ $l_curr =
+ qq|<input name=l_curr class=checkbox type=checkbox value=Y> |
+ . $locale->text('Currency');
+ $l_employee =
+ qq|<input name=l_employee class=checkbox type=checkbox value=Y> |
+ . $locale->text('Employee');
+ $l_serialnumber =
+ qq|<input name=l_serialnumber class=checkbox type=checkbox value=Y> |
+ . $locale->text('Serial Number');
+
+ $serialnumber = qq|
+ <th align=right nowrap>| . $locale->text('Serial Number') . qq|</th>
<td><input name=serialnumber size=20></td>
|;
- $orphaned = qq|
- <input name=itemstatus class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned');
+ $orphaned = qq|
+ <input name=itemstatus class=radio type=radio value=orphaned>&nbsp;|
+ . $locale->text('Orphaned');
- if ($form->{searchitems} =~ /(all|part|assembly)/) {
-
- $onhand = qq|
- <input name=itemstatus class=radio type=radio value=onhand>&nbsp;|.$locale->text('On Hand').qq|
- <input name=itemstatus class=radio type=radio value=short>&nbsp;|.$locale->text('Short').qq|
+ if ( $form->{searchitems} =~ /(all|part|assembly)/ ) {
+
+ $onhand = qq|
+ <input name=itemstatus class=radio type=radio value=onhand>&nbsp;|
+ . $locale->text('On Hand') . qq|
+ <input name=itemstatus class=radio type=radio value=short>&nbsp;|
+ . $locale->text('Short') . qq|
|;
- $makemodel = qq|
+ $makemodel = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Make').qq|</th>
+ <th align=right nowrap>| . $locale->text('Make') . qq|</th>
<td><input name=make size=20></td>
- <th align=right nowrap>|.$locale->text('Model').qq|</th>
+ <th align=right nowrap>| . $locale->text('Model') . qq|</th>
<td><input name=model size=20></td>
</tr>
|;
- $l_make = qq|<input name=l_make class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Make');
- $l_model = qq|<input name=l_model class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Model');
+ $l_make =
+ qq|<input name=l_make class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('Make');
+ $l_model =
+ qq|<input name=l_model class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('Model');
- $l_bin = qq|<input name=l_bin class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Bin');
+ $l_bin =
+ qq|<input name=l_bin class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('Bin');
- $l_rop = qq|<input name=l_rop class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('ROP');
+ $l_rop =
+ qq|<input name=l_rop class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('ROP');
- $l_weight = qq|<input name=l_weight class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Weight');
+ $l_weight =
+ qq|<input name=l_weight class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('Weight');
+ if ( @{ $form->{all_warehouse} } ) {
+ $selectwarehouse = "<option>\n";
- if (@{ $form->{all_warehouse} }) {
- $selectwarehouse = "<option>\n";
+ for ( @{ $form->{all_warehouse} } ) {
+ $selectwarehouse .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
- for (@{ $form->{all_warehouse} }) { $selectwarehouse .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
-
- $warehouse = qq|
- <th align=right nowrap>|.$locale->text('Warehouse').qq|</th>
+ $warehouse = qq|
+ <th align=right nowrap>| . $locale->text('Warehouse') . qq|</th>
<td><select name=warehouse>$selectwarehouse</select></td>
|;
- $l_warehouse = qq|<input name=l_warehouse class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Warehouse');
+ $l_warehouse =
+qq|<input name=l_warehouse class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('Warehouse');
- }
+ }
- $drawing = qq|
+ $drawing = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Drawing').qq|</th>
+ <th align=right nowrap>| . $locale->text('Drawing') . qq|</th>
<td><input name=drawing size=20></td>
- <th align=right nowrap>|.$locale->text('Microfiche').qq|</th>
+ <th align=right nowrap>| . $locale->text('Microfiche') . qq|</th>
<td><input name=microfiche size=20></td>
</tr>
|;
- $l_image = qq|<input name=l_image class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Image');
-
- $l_drawing = qq|<input name=l_drawing class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Drawing');
- $l_microfiche = qq|<input name=l_microfiche class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Microfiche');
+ $l_image =
+ qq|<input name=l_image class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('Image');
- }
+ $l_drawing =
+ qq|<input name=l_drawing class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('Drawing');
+ $l_microfiche =
+qq|<input name=l_microfiche class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('Microfiche');
- if ($form->{searchitems} eq 'assembly') {
+ }
- $bought = "";
-
- $toplevel = qq|
+ if ( $form->{searchitems} eq 'assembly' ) {
+
+ $bought = "";
+
+ $toplevel = qq|
<tr>
<td></td>
<td colspan=3>
- <input name=null class=radio type=radio checked>&nbsp;|.$locale->text('Top Level').qq|
- <input name=individual class=checkbox type=checkbox value=1>&nbsp;|.$locale->text('Individual Items').qq|
+ <input name=null class=radio type=radio checked>&nbsp;|
+ . $locale->text('Top Level') . qq|
+ <input name=individual class=checkbox type=checkbox value=1>&nbsp;|
+ . $locale->text('Individual Items') . qq|
</td>
</tr>
|;
- $bom = qq|<input name=itemstatus type=radio value=bom>&nbsp;|.$locale->text('BOM');
-
- } elsif ($form->{searchitems} eq 'component') {
-
- $bought = "";
- $sold = "";
- $fromto = "";
- $l_name = "";
- $l_curr = "";
- $l_employee = "";
- $l_serialnumber = "";
-
- $warehouse = "";
- $serialnumber = "";
- $orphaned = "";
- $l_warehouse = "";
- $l_account = "";
-
- } elsif ($form->{searchitems} eq 'labor') {
+ $bom =
+ qq|<input name=itemstatus type=radio value=bom>&nbsp;|
+ . $locale->text('BOM');
- $sold = "";
+ }
+ elsif ( $form->{searchitems} eq 'component' ) {
+
+ $bought = "";
+ $sold = "";
+ $fromto = "";
+ $l_name = "";
+ $l_curr = "";
+ $l_employee = "";
+ $l_serialnumber = "";
+
+ $warehouse = "";
+ $serialnumber = "";
+ $orphaned = "";
+ $l_warehouse = "";
+ $l_account = "";
- $warehouse = "";
- $serialnumber = "";
- $l_avgcost = "";
-
- }
-
+ }
+ elsif ( $form->{searchitems} eq 'labor' ) {
- @a = ();
- push @a, qq|<input name=l_runningnumber class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('No.');
- push @a, qq|<input name=l_partnumber class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Number');
- push @a, qq|<input name=l_description class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Description');
- push @a, qq|<input name=l_qty class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Qty');
- push @a, qq|<input name=l_unit class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Unit');
- push @a, qq|<input name=l_priceupdate class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Updated');
- push @a, $l_partsgroup if $l_partsgroup;
- push @a, $l_listprice if $l_listprice;
- push @a, $l_sellprice if $l_sellprice;
- push @a, $l_lastcost if $l_lastcost;
- push @a, $l_avgcost if $l_avgcost;
- push @a, $l_linetotal if $l_linetotal;
- push @a, $l_markup if $l_markup;
- push @a, $l_bin if $l_bin;
- push @a, $l_rop if $l_rop;
- push @a, $l_weight if $l_weight;
- push @a, qq|<input name=l_notes class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Notes');
- push @a, $l_image if $l_image;
- push @a, $l_drawing if $l_drawing;
- push @a, $l_microfiche if $l_microfiche;
- push @a, $l_make if $l_make;
- push @a, $l_model if $l_model;
- push @a, $l_warehouse if $l_warehouse;
- push @a, $l_account if $l_account;
- push @a, $l_name if $l_name;
- push @a, $l_curr if $l_curr;
- push @a, $l_employee if $l_employee;
- push @a, $l_serialnumber if $l_serialnumber;
-
- %title = ( all => 'Items',
- part => 'Parts',
- labor => 'Labor/Overhead',
- service => 'Services',
- assembly => 'Assemblies',
- component => 'Components'
- );
-
-# $locale->text('Items')
-# $locale->text('Parts')
-# $locale->text('Labor/Overhead')
-# $locale->text('Services')
-# $locale->text('Assemblies')
-# $locale->text('Components')
-
- $form->{title} = $locale->text($title{$form->{searchitems}});
-
- $form->header;
-
- print qq|
+ $sold = "";
+
+ $warehouse = "";
+ $serialnumber = "";
+ $l_avgcost = "";
+
+ }
+
+ @a = ();
+ push @a,
+qq|<input name=l_runningnumber class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('No.');
+ push @a,
+qq|<input name=l_partnumber class=checkbox type=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Number');
+ push @a,
+qq|<input name=l_description class=checkbox type=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Description');
+ push @a,
+ qq|<input name=l_qty class=checkbox type=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Qty');
+ push @a,
+ qq|<input name=l_unit class=checkbox type=checkbox value=Y checked>&nbsp;|
+ . $locale->text('Unit');
+ push @a,
+ qq|<input name=l_priceupdate class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('Updated');
+ push @a, $l_partsgroup if $l_partsgroup;
+ push @a, $l_listprice if $l_listprice;
+ push @a, $l_sellprice if $l_sellprice;
+ push @a, $l_lastcost if $l_lastcost;
+ push @a, $l_avgcost if $l_avgcost;
+ push @a, $l_linetotal if $l_linetotal;
+ push @a, $l_markup if $l_markup;
+ push @a, $l_bin if $l_bin;
+ push @a, $l_rop if $l_rop;
+ push @a, $l_weight if $l_weight;
+ push @a, qq|<input name=l_notes class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('Notes');
+ push @a, $l_image if $l_image;
+ push @a, $l_drawing if $l_drawing;
+ push @a, $l_microfiche if $l_microfiche;
+ push @a, $l_make if $l_make;
+ push @a, $l_model if $l_model;
+ push @a, $l_warehouse if $l_warehouse;
+ push @a, $l_account if $l_account;
+ push @a, $l_name if $l_name;
+ push @a, $l_curr if $l_curr;
+ push @a, $l_employee if $l_employee;
+ push @a, $l_serialnumber if $l_serialnumber;
+
+ %title = (
+ all => 'Items',
+ part => 'Parts',
+ labor => 'Labor/Overhead',
+ service => 'Services',
+ assembly => 'Assemblies',
+ component => 'Components'
+ );
+
+ # $locale->text('Items')
+ # $locale->text('Parts')
+ # $locale->text('Labor/Overhead')
+ # $locale->text('Services')
+ # $locale->text('Assemblies')
+ # $locale->text('Components')
+
+ $form->{title} = $locale->text( $title{ $form->{searchitems} } );
+
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
|;
- $form->hide_form(qw(searchitems title));
+ $form->hide_form(qw(searchitems title));
- print qq|
+ print qq|
<table width="100%">
<tr><th class=listtop>$form->{title}</th></tr>
@@ -1060,11 +1246,11 @@ sub search {
<td>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('Number') . qq|</th>
<td><input name=partnumber size=20></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Description').qq|</th>
+ <th align=right nowrap>| . $locale->text('Description') . qq|</th>
<td colspan=3><input name=description size=40></td>
</tr>
<tr>
@@ -1080,9 +1266,11 @@ sub search {
<tr>
<td></td>
<td colspan=3>
- <input name=itemstatus class=radio type=radio value=active checked>&nbsp;|.$locale->text('Active').qq|
+ <input name=itemstatus class=radio type=radio value=active checked>&nbsp;|
+ . $locale->text('Active') . qq|
$onhand
- <input name=itemstatus class=radio type=radio value=obsolete>&nbsp;|.$locale->text('Obsolete').qq|
+ <input name=itemstatus class=radio type=radio value=obsolete>&nbsp;|
+ . $locale->text('Obsolete') . qq|
$orphaned
$bom
</td>
@@ -1105,24 +1293,28 @@ sub search {
</td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
+ <th align=right nowrap>|
+ . $locale->text('Include in Report')
+ . qq|</th>
<td colspan=3>
<table>
<tr>
|;
- while (@a) {
- for (1 .. 5) {
- print qq|<td nowrap>|. shift @a;
- print qq|</td>\n|;
+ while (@a) {
+ for ( 1 .. 5 ) {
+ print qq|<td nowrap>| . shift @a;
+ print qq|</td>\n|;
+ }
+ print qq|</tr>\n|;
}
- print qq|</tr>\n|;
- }
- print qq|
+ print qq|
</tr>
<tr>
- <td><input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|</td>
+ <td><input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text('Subtotal')
+ . qq|</td>
</tr>
</table>
</td>
@@ -1136,20 +1328,22 @@ sub search {
<input type="hidden" name="nextsub" value="generate_report">
<br>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>|;
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>|;
- $form->hide_form(qw(path login sessionid));
-
- print qq|
+ $form->hide_form(qw(path login sessionid));
+
+ print qq|
</form>
|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</body>
</html>
@@ -1157,395 +1351,539 @@ sub search {
}
+sub generate_report {
+ # setup $form->{sort}
+ unless ( $form->{sort} ) {
+ if ( $form->{description} && !( $form->{partnumber} ) ) {
+ $form->{sort} = "description";
+ }
+ else {
+ $form->{sort} = "partnumber";
+ }
+ }
-sub generate_report {
+ if ( $form->{itemstatus} eq 'bom' ) {
+ $form->{l_perassembly} = "Y" if $form->{l_qty} eq "Y";
+ $form->{individual} = 1;
+ $form->{title} = $locale->text('BOM');
+ }
- # setup $form->{sort}
- unless ($form->{sort}) {
- if ($form->{description} && !($form->{partnumber})) {
- $form->{sort} = "description";
- } else {
- $form->{sort} = "partnumber";
+ $callback = "$form->{script}?action=generate_report";
+ for (
+ qw(path login sessionid searchitems itemstatus individual bom l_linetotal method)
+ )
+ {
+ $callback .= qq|&$_=$form->{$_}|;
+ }
+ for (qw(warehouse partsgroup title)) {
+ $callback .= qq|&$_=| . $form->escape( $form->{$_}, 1 );
}
- }
-
- if ($form->{itemstatus} eq 'bom') {
- $form->{l_perassembly} = "Y" if $form->{l_qty} eq "Y";
- $form->{individual} = 1;
- $form->{title} = $locale->text('BOM');
- }
-
- $callback = "$form->{script}?action=generate_report";
- for (qw(path login sessionid searchitems itemstatus individual bom l_linetotal method)) { $callback .= qq|&$_=$form->{$_}| }
- for (qw(warehouse partsgroup title)) { $callback .= qq|&$_=|.$form->escape($form->{$_},1) }
-
- # if we have a serialnumber limit search
- if ($form->{serialnumber} || $form->{l_serialnumber}) {
- $form->{l_serialnumber} = "Y";
- unless ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered}) {
- if ($form->{searchitems} eq 'assembly') {
- $form->{sold} = $form->{ordered} = 1;
- } else {
- $form->{bought} = $form->{sold} = $form->{onorder} = $form->{ordered} = 1;
- }
- }
- }
-
- if ($form->{itemstatus} eq 'active') {
- $option .= $locale->text('Active')." : ";
- }
- if ($form->{itemstatus} eq 'obsolete') {
- $form->{onhand} = $form->{short} = 0;
-
- $form->{l_qty} = 0;
- $form->{warehouse} = "";
- $form->{l_warehouse} = 0;
-
- $option .= $locale->text('Obsolete')." : ";
- }
- if ($form->{itemstatus} eq 'orphaned') {
- $form->{onhand} = $form->{short} = 0;
- $form->{bought} = $form->{sold} = 0;
- $form->{onorder} = $form->{ordered} = 0;
- $form->{rfq} = $form->{quoted} = 0;
-
- $form->{l_qty} = 0;
- $form->{warehouse} = "";
- $form->{l_warehouse} = 0;
-
- $form->{transdatefrom} = $form->{transdateto} = "";
-
- $option .= $locale->text('Orphaned')." : ";
- }
- if ($form->{itemstatus} eq 'onhand') {
- $option .= $locale->text('On Hand')." : ";
- $form->{l_onhand} = "Y";
- }
- if ($form->{itemstatus} eq 'short') {
- $option .= $locale->text('Short')." : ";
- $form->{l_onhand} = "Y";
- $form->{l_rop} = "Y" unless $form->{searchitems} eq 'labor';
-
- $form->{warehouse} = "";
- $form->{l_warehouse} = 0;
- }
-
- if ($form->{l_account}) {
- for (qw(l_name l_curr l_employee)) { delete $form->{$_} }
- } else {
- $ok = 0;
- foreach $l (qw(l_name l_curr l_employee)) {
- if ($form->{$l}) {
- foreach $v (qw(onorder ordered rfq quoted bought sold)) {
- if ($form->{$v}) {
- $ok = 1;
- last;
- }
- }
- if (!$ok) {
- for (qw(onorder ordered rfq quoted bought sold)) { $form->{$_} = 1 }
- }
- last;
- }
- }
- }
-
- if ($form->{onorder}) {
- $form->{l_ordnumber} = "Y";
- $callback .= "&onorder=$form->{onorder}";
- $option .= $locale->text('Purchase Order')." : ";
- }
- if ($form->{ordered}) {
- $form->{l_ordnumber} = "Y";
- $callback .= "&ordered=$form->{ordered}";
- $option .= $locale->text('Sales Order')." : ";
- }
- if ($form->{rfq}) {
- $form->{l_quonumber} = "Y";
- $callback .= "&rfq=$form->{rfq}";
- $option .= $locale->text('RFQ')." : ";
- }
- if ($form->{quoted}) {
- $form->{l_quonumber} = "Y";
- $callback .= "&quoted=$form->{quoted}";
- $option .= $locale->text('Quotation')." : ";
- }
- if ($form->{bought}) {
- $form->{l_invnumber} = "Y";
- $callback .= "&bought=$form->{bought}";
- $option .= $locale->text('Vendor Invoice')." : ";
- }
- if ($form->{sold}) {
- $form->{l_invnumber} = "Y";
- $callback .= "&sold=$form->{sold}";
- $option .= $locale->text('Sales Invoice')." : ";
- }
- if ($form->{sold} || $form->{bought}) {
- $label = ucfirst $form->{method};
- $option .= $locale->text($label) ." : ";
- }
-
- if ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered} || $form->{rfq} || $form->{quoted}) {
-
- # warehouse stuff is meaningless
- $form->{warehouse} = "";
- $form->{l_warehouse} = 0;
-
- $form->{l_account} = "";
-
- if ($form->{open}) {
- $callback .= "&open=$form->{open}";
- $option .= $locale->text('Open');
- }
- if ($form->{closed}) {
- $callback .= "&closed=$form->{closed}";
- if ($form->{open}) {
- $option .= " : ".$locale->text('Closed');
- } else {
- $option .= $locale->text('Closed');
- }
- }
- if ($form->{summary}) {
- $callback .= "&summary=$form->{summary}";
- $option .= " : ".$locale->text('Summary');
- $form->{l_ordnumber} = "";
- $form->{l_quonumber} = "";
- $form->{l_invnumber} = "";
- } else {
- $option .= " : ".$locale->text('Detail');
+ # if we have a serialnumber limit search
+ if ( $form->{serialnumber} || $form->{l_serialnumber} ) {
+ $form->{l_serialnumber} = "Y";
+ unless ( $form->{bought}
+ || $form->{sold}
+ || $form->{onorder}
+ || $form->{ordered} )
+ {
+ if ( $form->{searchitems} eq 'assembly' ) {
+ $form->{sold} = $form->{ordered} = 1;
+ }
+ else {
+ $form->{bought} = $form->{sold} = $form->{onorder} =
+ $form->{ordered} = 1;
+ }
+ }
}
-
- if ($form->{transdatefrom}) {
- $callback .= "&transdatefrom=$form->{transdatefrom}";
- $option .= "\n<br>".$locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
+
+ if ( $form->{itemstatus} eq 'active' ) {
+ $option .= $locale->text('Active') . " : ";
}
- if ($form->{transdateto}) {
- $callback .= "&transdateto=$form->{transdateto}";
- $option .= "\n<br>".$locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 1);
+ if ( $form->{itemstatus} eq 'obsolete' ) {
+ $form->{onhand} = $form->{short} = 0;
+
+ $form->{l_qty} = 0;
+ $form->{warehouse} = "";
+ $form->{l_warehouse} = 0;
+
+ $option .= $locale->text('Obsolete') . " : ";
}
- }
-
- if ($form->{warehouse}) {
- ($warehouse) = split /--/, $form->{warehouse};
- $option .= "<br>".$locale->text('Warehouse')." : $warehouse";
- $form->{l_warehouse} = 0;
- }
-
- $option .= "<br>";
-
- if ($form->{partnumber}) {
- $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
- $option .= $locale->text('Number').qq| : $form->{partnumber}<br>|;
- }
- if ($form->{partsgroup}) {
- ($partsgroup) = split /--/, $form->{partsgroup};
- $option .= $locale->text('Group').qq| : $partsgroup<br>|;
- }
- if ($form->{serialnumber}) {
- $callback .= "&serialnumber=".$form->escape($form->{serialnumber},1);
- $option .= $locale->text('Serial Number').qq| : $form->{serialnumber}<br>|;
- }
- if ($form->{description}) {
- $callback .= "&description=".$form->escape($form->{description},1);
- $description = $form->{description};
- $description =~ s/\r?\n/<br>/g;
- $option .= $locale->text('Description').qq| : $form->{description}<br>|;
- }
- if ($form->{make}) {
- $callback .= "&make=".$form->escape($form->{make},1);
- $option .= $locale->text('Make').qq| : $form->{make}<br>|;
- }
- if ($form->{model}) {
- $callback .= "&model=".$form->escape($form->{model},1);
- $option .= $locale->text('Model').qq| : $form->{model}<br>|;
- }
- if ($form->{drawing}) {
- $callback .= "&drawing=".$form->escape($form->{drawing},1);
- $option .= $locale->text('Drawing').qq| : $form->{drawing}<br>|;
- }
- if ($form->{microfiche}) {
- $callback .= "&microfiche=".$form->escape($form->{microfiche},1);
- $option .= $locale->text('Microfiche').qq| : $form->{microfiche}<br>|;
- }
-
- if ($form->{l_markup}) {
- $form->{l_sellprice} = "Y";
- $form->{l_lastcostmarkup} = "Y" if $form->{l_lastcost};
- $form->{l_avgcostmarkup} = "Y" if $form->{l_avgcost};
- }
+ if ( $form->{itemstatus} eq 'orphaned' ) {
+ $form->{onhand} = $form->{short} = 0;
+ $form->{bought} = $form->{sold} = 0;
+ $form->{onorder} = $form->{ordered} = 0;
+ $form->{rfq} = $form->{quoted} = 0;
-
- @columns = $form->sort_columns(qw(partnumber description notes assemblypartnumber partsgroup make model bin onhand perassembly rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost lastcostmarkup avgcost linetotalavgcost avgcostmarkup curr priceupdate weight image drawing microfiche invnumber ordnumber quonumber name employee serialnumber warehouse));
- unshift @columns, "runningnumber";
-
- if ($form->{l_linetotal}) {
- $form->{l_onhand} = "Y";
- $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
- $form->{l_linetotallastcost} = "Y" if $form->{l_lastcost};
- $form->{l_linetotalavgcost} = "Y" if $form->{l_avgcost};
- $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
- }
-
- if ($form->{searchitems} eq 'service') {
- # remove bin, weight and rop from list
- for (qw(bin weight rop)) { $form->{"l_$_"} = "" }
-
- $form->{l_onhand} = "";
- # qty is irrelevant unless bought or sold
- if ($form->{bought} || $form->{sold} || $form->{onorder} ||
- $form->{ordered} || $form->{rfq} || $form->{quoted}) {
- $form->{l_onhand} = "Y";
- } else {
- for (qw(sellprice lastcost avgcost listprice)) { $form->{"l_linetotal$_"} = "" }
- }
- } else {
- $form->{l_onhand} = "Y" if $form->{l_qty};
- }
-
- foreach $item (@columns) {
- if ($form->{"l_$item"} eq "Y") {
- push @column_index, $item;
+ $form->{l_qty} = 0;
+ $form->{warehouse} = "";
+ $form->{l_warehouse} = 0;
+
+ $form->{transdatefrom} = $form->{transdateto} = "";
- # add column to callback
- $callback .= "&l_$item=Y";
+ $option .= $locale->text('Orphaned') . " : ";
+ }
+ if ( $form->{itemstatus} eq 'onhand' ) {
+ $option .= $locale->text('On Hand') . " : ";
+ $form->{l_onhand} = "Y";
}
- }
+ if ( $form->{itemstatus} eq 'short' ) {
+ $option .= $locale->text('Short') . " : ";
+ $form->{l_onhand} = "Y";
+ $form->{l_rop} = "Y" unless $form->{searchitems} eq 'labor';
- if ($form->{l_account} eq 'Y') {
- if ($form->{searchitems} eq 'all' || $form->{searchitems} eq 'part') {
- push @column_index, (qw(inventory income expense tax));
- } elsif ($form->{searchitems} eq 'service') {
- push @column_index, (qw(income expense tax));
- } elsif ($form->{searchitems} eq 'assembly') {
- push @column_index, (qw(income tax));
- } else {
- push @column_index, (qw(inventory expense));
+ $form->{warehouse} = "";
+ $form->{l_warehouse} = 0;
}
- $callback .= "&l_account=Y";
- }
-
- if ($form->{l_subtotal} eq 'Y') {
- $callback .= "&l_subtotal=Y";
- }
+ if ( $form->{l_account} ) {
+ for (qw(l_name l_curr l_employee)) { delete $form->{$_} }
+ }
+ else {
+ $ok = 0;
+ foreach $l (qw(l_name l_curr l_employee)) {
+ if ( $form->{$l} ) {
+ foreach $v (qw(onorder ordered rfq quoted bought sold)) {
+ if ( $form->{$v} ) {
+ $ok = 1;
+ last;
+ }
+ }
+ if ( !$ok ) {
+ for (qw(onorder ordered rfq quoted bought sold)) {
+ $form->{$_} = 1;
+ }
+ }
+ last;
+ }
+ }
+ }
- IC->all_parts(\%myconfig, \%$form);
+ if ( $form->{onorder} ) {
+ $form->{l_ordnumber} = "Y";
+ $callback .= "&onorder=$form->{onorder}";
+ $option .= $locale->text('Purchase Order') . " : ";
+ }
+ if ( $form->{ordered} ) {
+ $form->{l_ordnumber} = "Y";
+ $callback .= "&ordered=$form->{ordered}";
+ $option .= $locale->text('Sales Order') . " : ";
+ }
+ if ( $form->{rfq} ) {
+ $form->{l_quonumber} = "Y";
+ $callback .= "&rfq=$form->{rfq}";
+ $option .= $locale->text('RFQ') . " : ";
+ }
+ if ( $form->{quoted} ) {
+ $form->{l_quonumber} = "Y";
+ $callback .= "&quoted=$form->{quoted}";
+ $option .= $locale->text('Quotation') . " : ";
+ }
+ if ( $form->{bought} ) {
+ $form->{l_invnumber} = "Y";
+ $callback .= "&bought=$form->{bought}";
+ $option .= $locale->text('Vendor Invoice') . " : ";
+ }
+ if ( $form->{sold} ) {
+ $form->{l_invnumber} = "Y";
+ $callback .= "&sold=$form->{sold}";
+ $option .= $locale->text('Sales Invoice') . " : ";
+ }
+ if ( $form->{sold} || $form->{bought} ) {
+ $label = ucfirst $form->{method};
+ $option .= $locale->text($label) . " : ";
+ }
- $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
-
- $href = $callback;
-
- $form->sort_order();
-
- $callback =~ s/(direction=).*?\&/$1$form->{direction}\&/;
-
- if ($form->{searchitems} eq 'assembly') {
- if ($form->{l_partnumber}) {
- # replace partnumber with partnumber_
- $ndx = 0;
- foreach $item (@column_index) {
- $ndx++;
- last if $item eq 'partnumber';
- }
-
- splice @column_index, $ndx, 0, map { "partnumber_$_" } (1 .. $form->{pncol});
- $colspan = $form->{pncol} + 1;
- }
- }
-
- if ($form->{searchitems} eq 'component') {
- if ($form->{l_partnumber}) {
- # splice it in after the partnumber
- $ndx = 0;
- foreach $item (@column_index) {
- $ndx++;
- last if $item eq 'partnumber';
- }
-
- @a = splice @column_index, 0, $ndx;
- unshift @column_index, "assemblypartnumber";
- unshift @column_index, @a;
- }
- }
-
-
- $column_header{runningnumber} = qq|<th a class=listheading>&nbsp;</th>|;
- $column_header{partnumber} = qq|<th nowrap colspan=$colspan><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</a></th>|;
- $column_header{description} = qq|<th nowrap><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
- $column_header{notes} = qq|<th nowrap class=listheading>|.$locale->text('Notes').qq|</th>|;
- $column_header{partsgroup} = qq|<th nowrap><a class=listheading href=$href&sort=partsgroup>|.$locale->text('Group').qq|</a></th>|;
- $column_header{bin} = qq|<th><a class=listheading href=$href&sort=bin>|.$locale->text('Bin').qq|</a></th>|;
- $column_header{priceupdate} = qq|<th nowrap><a class=listheading href=$href&sort=priceupdate>|.$locale->text('Updated').qq|</a></th>|;
- $column_header{onhand} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
- $column_header{perassembly} = qq|<th>&nbsp;</th>|;
- $column_header{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
- $column_header{listprice} = qq|<th class=listheading nowrap>|.$locale->text('List Price').qq|</th>|;
- $column_header{lastcost} = qq|<th class=listheading nowrap>|.$locale->text('Last Cost').qq|</th>|;
- $column_header{avgcost} = qq|<th class=listheading nowrap>|.$locale->text('Avg Cost').qq|</th>|;
- $column_header{rop} = qq|<th class=listheading nowrap>|.$locale->text('ROP').qq|</th>|;
- $column_header{weight} = qq|<th class=listheading nowrap>|.$locale->text('Weight').qq|</th>|;
- $column_header{avgcostmarkup} = qq|<th class=listheading nowrap>%</th>|;
- $column_header{lastcostmarkup} = qq|<th class=listheading nowrap>%</th>|;
-
- $column_header{make} = qq|<th nowrap><a class=listheading href=$href&sort=make>|.$locale->text('Make').qq|</a></th>|;
- $column_header{model} = qq|<th nowrap><a class=listheading href=$href&sort=model>|.$locale->text('Model').qq|</a></th>|;
-
- $column_header{invnumber} = qq|<th nowrap><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice Number').qq|</a></th>|;
- $column_header{ordnumber} = qq|<th nowrap><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order Number').qq|</a></th>|;
- $column_header{quonumber} = qq|<th nowrap><a class=listheading href=$href&sort=quonumber>|.$locale->text('Quotation').qq|</a></th>|;
-
- $column_header{name} = qq|<th nowrap><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|;
-
- $column_header{employee} = qq|<th nowrap><a class=listheading href=$href&sort=employee>|.$locale->text('Employee').qq|</a></th>|;
-
- $column_header{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Sell Price').qq|</th>|;
-
- for (qw(sellprice lastcost avgcost listprice)) { $column_header{"linetotal$_"} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>| }
-
- $column_header{curr} = qq|<th nowrap><a class=listheading href=$href&sort=curr>|.$locale->text('Curr').qq|</a></th>|;
-
- $column_header{image} = qq|<th class=listheading nowrap>|.$locale->text('Image').qq|</a></th>|;
- $column_header{drawing} = qq|<th nowrap><a class=listheading href=$href&sort=drawing>|.$locale->text('Drawing').qq|</a></th>|;
- $column_header{microfiche} = qq|<th nowrap><a class=listheading href=$href&sort=microfiche>|.$locale->text('Microfiche').qq|</a></th>|;
-
- $column_header{serialnumber} = qq|<th nowrap><a class=listheading href=$href&sort=serialnumber>|.$locale->text('Serial Number').qq|</a></th>|;
-
- $column_header{assemblypartnumber} = qq|<th nowrap><a class=listheading href=$href&sort=assemblypartnumber>|.$locale->text('Assembly').qq|</a></th>|;
-
- $column_header{warehouse} = qq|<th nowrap class=listheading>|.$locale->text('Warehouse').qq|</th>|;
+ if ( $form->{bought}
+ || $form->{sold}
+ || $form->{onorder}
+ || $form->{ordered}
+ || $form->{rfq}
+ || $form->{quoted} )
+ {
+
+ # warehouse stuff is meaningless
+ $form->{warehouse} = "";
+ $form->{l_warehouse} = 0;
+
+ $form->{l_account} = "";
+
+ if ( $form->{open} ) {
+ $callback .= "&open=$form->{open}";
+ $option .= $locale->text('Open');
+ }
+ if ( $form->{closed} ) {
+ $callback .= "&closed=$form->{closed}";
+ if ( $form->{open} ) {
+ $option .= " : " . $locale->text('Closed');
+ }
+ else {
+ $option .= $locale->text('Closed');
+ }
+ }
+ if ( $form->{summary} ) {
+ $callback .= "&summary=$form->{summary}";
+ $option .= " : " . $locale->text('Summary');
+ $form->{l_ordnumber} = "";
+ $form->{l_quonumber} = "";
+ $form->{l_invnumber} = "";
+ }
+ else {
+ $option .= " : " . $locale->text('Detail');
+ }
+
+ if ( $form->{transdatefrom} ) {
+ $callback .= "&transdatefrom=$form->{transdatefrom}";
+ $option .= "\n<br>"
+ . $locale->text('From')
+ . "&nbsp;"
+ . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
+ }
+ if ( $form->{transdateto} ) {
+ $callback .= "&transdateto=$form->{transdateto}";
+ $option .= "\n<br>"
+ . $locale->text('To')
+ . "&nbsp;"
+ . $locale->date( \%myconfig, $form->{transdateto}, 1 );
+ }
+ }
- $column_header{inventory} = qq|<th nowrap class=listheading>|.$locale->text('Inventory').qq|</th>|;
- $column_header{income} = qq|<th nowrap class=listheading>|.$locale->text('Income').qq|</th>|;
- $column_header{expense} = qq|<th nowrap class=listheading>|.$locale->text('Expense').qq|</th>|;
- $column_header{tax} = qq|<th nowrap class=listheading>|.$locale->text('Tax').qq|</th>|;
-
- $form->header;
-
- $i = 1;
- if ($form->{searchitems} eq 'part') {
- $button{'Goods & Services--Add Part'}{code} = qq|<button class="submit" type="submit" name="action" value="add_part">|.$locale->text('Add Part').qq|</button> |;
- $button{'Goods & Services--Add Part'}{order} = $i++;
- }
- if ($form->{searchitems} eq 'service') {
- $button{'Goods & Services--Add Service'}{code} = qq|<button class="submit" type="submit" name="action" value="add_service">|.$locale->text('Add Service').qq|</button> |;
- $button{'Goods & Services--Add Service'}{order} = $i++;
- }
- if ($form->{searchitems} eq 'assembly') {
- $button{'Goods & Services--Add Assembly'}{code} = qq|<button class="submit" type="submit" name="action" value="add_assembly">|.$locale->text('Add Assembly').qq|</button> |;
- $button{'Goods & Services--Add Assembly'}{order} = $i++;
- }
- if ($form->{searchitems} eq 'labor') {
- $button{'Goods & Services--Add Labor/Overhead'}{code} = qq|<button class="submit" type="submit" name="action" value="add_labor_overhead">|.$locale->text('Add Labor/Overhead').qq|</button> |;
- $button{'Goods & Services--Add Labor/Overhead'}{order} = $i++;
- }
-
- foreach $item (split /;/, $myconfig{acs}) {
- delete $button{$item};
- }
-
- print qq|
+ if ( $form->{warehouse} ) {
+ ($warehouse) = split /--/, $form->{warehouse};
+ $option .= "<br>" . $locale->text('Warehouse') . " : $warehouse";
+ $form->{l_warehouse} = 0;
+ }
+
+ $option .= "<br>";
+
+ if ( $form->{partnumber} ) {
+ $callback .= "&partnumber=" . $form->escape( $form->{partnumber}, 1 );
+ $option .= $locale->text('Number') . qq| : $form->{partnumber}<br>|;
+ }
+ if ( $form->{partsgroup} ) {
+ ($partsgroup) = split /--/, $form->{partsgroup};
+ $option .= $locale->text('Group') . qq| : $partsgroup<br>|;
+ }
+ if ( $form->{serialnumber} ) {
+ $callback .=
+ "&serialnumber=" . $form->escape( $form->{serialnumber}, 1 );
+ $option .=
+ $locale->text('Serial Number') . qq| : $form->{serialnumber}<br>|;
+ }
+ if ( $form->{description} ) {
+ $callback .= "&description=" . $form->escape( $form->{description}, 1 );
+ $description = $form->{description};
+ $description =~ s/\r?\n/<br>/g;
+ $option .=
+ $locale->text('Description') . qq| : $form->{description}<br>|;
+ }
+ if ( $form->{make} ) {
+ $callback .= "&make=" . $form->escape( $form->{make}, 1 );
+ $option .= $locale->text('Make') . qq| : $form->{make}<br>|;
+ }
+ if ( $form->{model} ) {
+ $callback .= "&model=" . $form->escape( $form->{model}, 1 );
+ $option .= $locale->text('Model') . qq| : $form->{model}<br>|;
+ }
+ if ( $form->{drawing} ) {
+ $callback .= "&drawing=" . $form->escape( $form->{drawing}, 1 );
+ $option .= $locale->text('Drawing') . qq| : $form->{drawing}<br>|;
+ }
+ if ( $form->{microfiche} ) {
+ $callback .= "&microfiche=" . $form->escape( $form->{microfiche}, 1 );
+ $option .= $locale->text('Microfiche') . qq| : $form->{microfiche}<br>|;
+ }
+
+ if ( $form->{l_markup} ) {
+ $form->{l_sellprice} = "Y";
+ $form->{l_lastcostmarkup} = "Y" if $form->{l_lastcost};
+ $form->{l_avgcostmarkup} = "Y" if $form->{l_avgcost};
+ }
+
+ @columns =
+ $form->sort_columns(
+ qw(partnumber description notes assemblypartnumber partsgroup make model bin onhand perassembly rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost lastcostmarkup avgcost linetotalavgcost avgcostmarkup curr priceupdate weight image drawing microfiche invnumber ordnumber quonumber name employee serialnumber warehouse)
+ );
+ unshift @columns, "runningnumber";
+
+ if ( $form->{l_linetotal} ) {
+ $form->{l_onhand} = "Y";
+ $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
+ $form->{l_linetotallastcost} = "Y" if $form->{l_lastcost};
+ $form->{l_linetotalavgcost} = "Y" if $form->{l_avgcost};
+ $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
+ }
+
+ if ( $form->{searchitems} eq 'service' ) {
+
+ # remove bin, weight and rop from list
+ for (qw(bin weight rop)) { $form->{"l_$_"} = "" }
+
+ $form->{l_onhand} = "";
+
+ # qty is irrelevant unless bought or sold
+ if ( $form->{bought}
+ || $form->{sold}
+ || $form->{onorder}
+ || $form->{ordered}
+ || $form->{rfq}
+ || $form->{quoted} )
+ {
+ $form->{l_onhand} = "Y";
+ }
+ else {
+ for (qw(sellprice lastcost avgcost listprice)) {
+ $form->{"l_linetotal$_"} = "";
+ }
+ }
+ }
+ else {
+ $form->{l_onhand} = "Y" if $form->{l_qty};
+ }
+
+ foreach $item (@columns) {
+ if ( $form->{"l_$item"} eq "Y" ) {
+ push @column_index, $item;
+
+ # add column to callback
+ $callback .= "&l_$item=Y";
+ }
+ }
+
+ if ( $form->{l_account} eq 'Y' ) {
+ if ( $form->{searchitems} eq 'all' || $form->{searchitems} eq 'part' ) {
+ push @column_index, (qw(inventory income expense tax));
+ }
+ elsif ( $form->{searchitems} eq 'service' ) {
+ push @column_index, (qw(income expense tax));
+ }
+ elsif ( $form->{searchitems} eq 'assembly' ) {
+ push @column_index, (qw(income tax));
+ }
+ else {
+ push @column_index, (qw(inventory expense));
+ }
+
+ $callback .= "&l_account=Y";
+ }
+
+ if ( $form->{l_subtotal} eq 'Y' ) {
+ $callback .= "&l_subtotal=Y";
+ }
+
+ IC->all_parts( \%myconfig, \%$form );
+
+ $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
+
+ $href = $callback;
+
+ $form->sort_order();
+
+ $callback =~ s/(direction=).*?\&/$1$form->{direction}\&/;
+
+ if ( $form->{searchitems} eq 'assembly' ) {
+ if ( $form->{l_partnumber} ) {
+
+ # replace partnumber with partnumber_
+ $ndx = 0;
+ foreach $item (@column_index) {
+ $ndx++;
+ last if $item eq 'partnumber';
+ }
+
+ splice @column_index, $ndx, 0,
+ map { "partnumber_$_" } ( 1 .. $form->{pncol} );
+ $colspan = $form->{pncol} + 1;
+ }
+ }
+
+ if ( $form->{searchitems} eq 'component' ) {
+ if ( $form->{l_partnumber} ) {
+
+ # splice it in after the partnumber
+ $ndx = 0;
+ foreach $item (@column_index) {
+ $ndx++;
+ last if $item eq 'partnumber';
+ }
+
+ @a = splice @column_index, 0, $ndx;
+ unshift @column_index, "assemblypartnumber";
+ unshift @column_index, @a;
+ }
+ }
+
+ $column_header{runningnumber} = qq|<th a class=listheading>&nbsp;</th>|;
+ $column_header{partnumber} =
+qq|<th nowrap colspan=$colspan><a class=listheading href=$href&sort=partnumber>|
+ . $locale->text('Number')
+ . qq|</a></th>|;
+ $column_header{description} =
+ qq|<th nowrap><a class=listheading href=$href&sort=description>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
+ $column_header{notes} =
+ qq|<th nowrap class=listheading>| . $locale->text('Notes') . qq|</th>|;
+ $column_header{partsgroup} =
+ qq|<th nowrap><a class=listheading href=$href&sort=partsgroup>|
+ . $locale->text('Group')
+ . qq|</a></th>|;
+ $column_header{bin} =
+ qq|<th><a class=listheading href=$href&sort=bin>|
+ . $locale->text('Bin')
+ . qq|</a></th>|;
+ $column_header{priceupdate} =
+ qq|<th nowrap><a class=listheading href=$href&sort=priceupdate>|
+ . $locale->text('Updated')
+ . qq|</a></th>|;
+ $column_header{onhand} =
+ qq|<th class=listheading nowrap>| . $locale->text('Qty') . qq|</th>|;
+ $column_header{perassembly} = qq|<th>&nbsp;</th>|;
+ $column_header{unit} =
+ qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
+ $column_header{listprice} =
+ qq|<th class=listheading nowrap>|
+ . $locale->text('List Price')
+ . qq|</th>|;
+ $column_header{lastcost} =
+ qq|<th class=listheading nowrap>|
+ . $locale->text('Last Cost')
+ . qq|</th>|;
+ $column_header{avgcost} =
+ qq|<th class=listheading nowrap>| . $locale->text('Avg Cost') . qq|</th>|;
+ $column_header{rop} =
+ qq|<th class=listheading nowrap>| . $locale->text('ROP') . qq|</th>|;
+ $column_header{weight} =
+ qq|<th class=listheading nowrap>| . $locale->text('Weight') . qq|</th>|;
+ $column_header{avgcostmarkup} = qq|<th class=listheading nowrap>%</th>|;
+ $column_header{lastcostmarkup} = qq|<th class=listheading nowrap>%</th>|;
+
+ $column_header{make} =
+ qq|<th nowrap><a class=listheading href=$href&sort=make>|
+ . $locale->text('Make')
+ . qq|</a></th>|;
+ $column_header{model} =
+ qq|<th nowrap><a class=listheading href=$href&sort=model>|
+ . $locale->text('Model')
+ . qq|</a></th>|;
+
+ $column_header{invnumber} =
+ qq|<th nowrap><a class=listheading href=$href&sort=invnumber>|
+ . $locale->text('Invoice Number')
+ . qq|</a></th>|;
+ $column_header{ordnumber} =
+ qq|<th nowrap><a class=listheading href=$href&sort=ordnumber>|
+ . $locale->text('Order Number')
+ . qq|</a></th>|;
+ $column_header{quonumber} =
+ qq|<th nowrap><a class=listheading href=$href&sort=quonumber>|
+ . $locale->text('Quotation')
+ . qq|</a></th>|;
+
+ $column_header{name} =
+ qq|<th nowrap><a class=listheading href=$href&sort=name>|
+ . $locale->text('Name')
+ . qq|</a></th>|;
+
+ $column_header{employee} =
+ qq|<th nowrap><a class=listheading href=$href&sort=employee>|
+ . $locale->text('Employee')
+ . qq|</a></th>|;
+
+ $column_header{sellprice} =
+ qq|<th class=listheading nowrap>|
+ . $locale->text('Sell Price')
+ . qq|</th>|;
+
+ for (qw(sellprice lastcost avgcost listprice)) {
+ $column_header{"linetotal$_"} =
+ qq|<th class=listheading nowrap>|
+ . $locale->text('Extended')
+ . qq|</th>|;
+ }
+
+ $column_header{curr} =
+ qq|<th nowrap><a class=listheading href=$href&sort=curr>|
+ . $locale->text('Curr')
+ . qq|</a></th>|;
+
+ $column_header{image} =
+ qq|<th class=listheading nowrap>|
+ . $locale->text('Image')
+ . qq|</a></th>|;
+ $column_header{drawing} =
+ qq|<th nowrap><a class=listheading href=$href&sort=drawing>|
+ . $locale->text('Drawing')
+ . qq|</a></th>|;
+ $column_header{microfiche} =
+ qq|<th nowrap><a class=listheading href=$href&sort=microfiche>|
+ . $locale->text('Microfiche')
+ . qq|</a></th>|;
+
+ $column_header{serialnumber} =
+ qq|<th nowrap><a class=listheading href=$href&sort=serialnumber>|
+ . $locale->text('Serial Number')
+ . qq|</a></th>|;
+
+ $column_header{assemblypartnumber} =
+ qq|<th nowrap><a class=listheading href=$href&sort=assemblypartnumber>|
+ . $locale->text('Assembly')
+ . qq|</a></th>|;
+
+ $column_header{warehouse} =
+ qq|<th nowrap class=listheading>|
+ . $locale->text('Warehouse')
+ . qq|</th>|;
+
+ $column_header{inventory} =
+ qq|<th nowrap class=listheading>|
+ . $locale->text('Inventory')
+ . qq|</th>|;
+ $column_header{income} =
+ qq|<th nowrap class=listheading>| . $locale->text('Income') . qq|</th>|;
+ $column_header{expense} =
+ qq|<th nowrap class=listheading>| . $locale->text('Expense') . qq|</th>|;
+ $column_header{tax} =
+ qq|<th nowrap class=listheading>| . $locale->text('Tax') . qq|</th>|;
+
+ $form->header;
+
+ $i = 1;
+ if ( $form->{searchitems} eq 'part' ) {
+ $button{'Goods & Services--Add Part'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add_part">|
+ . $locale->text('Add Part')
+ . qq|</button> |;
+ $button{'Goods & Services--Add Part'}{order} = $i++;
+ }
+ if ( $form->{searchitems} eq 'service' ) {
+ $button{'Goods & Services--Add Service'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add_service">|
+ . $locale->text('Add Service')
+ . qq|</button> |;
+ $button{'Goods & Services--Add Service'}{order} = $i++;
+ }
+ if ( $form->{searchitems} eq 'assembly' ) {
+ $button{'Goods & Services--Add Assembly'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add_assembly">|
+ . $locale->text('Add Assembly')
+ . qq|</button> |;
+ $button{'Goods & Services--Add Assembly'}{order} = $i++;
+ }
+ if ( $form->{searchitems} eq 'labor' ) {
+ $button{'Goods & Services--Add Labor/Overhead'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add_labor_overhead">|
+ . $locale->text('Add Labor/Overhead')
+ . qq|</button> |;
+ $button{'Goods & Services--Add Labor/Overhead'}{order} = $i++;
+ }
+
+ foreach $item ( split /;/, $myconfig{acs} ) {
+ delete $button{$item};
+ }
+
+ print qq|
<body>
<table width=100%>
@@ -1562,224 +1900,333 @@ sub generate_report {
<tr class=listheading>
|;
- for (@column_index) { print "\n$column_header{$_}" }
-
- print qq|
+ for (@column_index) { print "\n$column_header{$_}" }
+
+ print qq|
</tr>
|;
+ # add order to callback
+ $form->{callback} = $callback .= "&sort=$form->{sort}";
+
+ # escape callback for href
+ $callback = $form->escape($callback);
+
+ $k = $#{ @{ $form->{parts} } };
+ @groupby = ( $form->{sort} );
+
+ if ( $form->{summary} ) {
+ @groupby = ();
+ for (
+ qw(partnumber description notes partsgroup make model bin curr priceupdate image drawing microfiche invnumber ordnumber quonumber name employee serialnumber warehouse)
+ )
+ {
+ $a{$_} = 1;
+ }
+
+ for (@column_index) {
+ if ( $a{$_} ) {
+ push @groupby, $_;
+ }
+ }
+ push @groupby, "id";
+ }
- # add order to callback
- $form->{callback} = $callback .= "&sort=$form->{sort}";
-
- # escape callback for href
- $callback = $form->escape($callback);
-
-
- $k = $#{@{ $form->{parts} }};
- @groupby = ($form->{sort});
-
- if ($form->{summary}) {
- @groupby = ();
- for (qw(partnumber description notes partsgroup make model bin curr priceupdate image drawing microfiche invnumber ordnumber quonumber name employee serialnumber warehouse)) { $a{$_} = 1 };
-
- for (@column_index) {
- if ($a{$_}) {
- push @groupby, $_;
- }
- }
- push @groupby, "id";
- }
-
- if ($k > 0) {
- $samegroup = "";
- for (@groupby) { $samegroup .= $form->{parts}->[0]->{$_} }
- }
-
- $i = 0;
- $n = 0;
-
- foreach $ref (@{ $form->{parts} }) {
-
- $ref->{exchangerate} ||= 1;
- $ref->{discount} *= 1;
-
- if ($form->{summary}) {
-
- $summary{$ref->{id}}{total} += $ref->{sellprice} * $ref->{onhand};
- $summary{$ref->{id}}{onhand} += $ref->{onhand};
-
- if ($n < $k) {
- $nextgroup = "";
- for (@groupby) { $nextgroup .= $form->{parts}->[$n+1]->{$_} }
- $n++;
-
- $form->{parts}->[$n]->{exchangerate} ||= 1;
-
- if ($samegroup eq $nextgroup) {
- for (qw(exchangerate discount)) { $form->{parts}->[$n]->{$_} = ($ref->{$_} + $form->{parts}->[$n]->{$_}) / 2 }
- next;
- }
- $samegroup = $nextgroup;
- }
-
- $ref->{onhand} = $summary{$ref->{id}}{onhand};
- $ref->{sellprice} = ($ref->{onhand}) ? $summary{$ref->{id}}{total} / $ref->{onhand} : 0;
-
- $summary{$ref->{id}}{total} = 0;
- $summary{$ref->{id}}{onhand} = 0;
-
- }
-
- if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
- if ($sameitem ne $ref->{$form->{sort}}) {
- &parts_subtotal;
- $sameitem = $ref->{$form->{sort}};
- }
- }
-
- $i++;
-
- if ($form->{l_curr}) {
- if ($ref->{module} eq 'oe') {
- $ref->{sellprice} = $ref->{sellprice} * (1 - $ref->{discount});
- } else {
- for (qw(sellprice listprice lastcost avgcost)) { $ref->{$_} /= $ref->{exchangerate} }
- }
- } else {
- if ($ref->{module} eq 'oe') {
- $ref->{sellprice} = $ref->{sellprice} * (1 - $ref->{discount});
- for (qw(sellprice listprice lastcost avgcost)) { $ref->{$_} *= $ref->{exchangerate} }
- }
- }
-
- if (!$form->{summary}) {
- for (qw(sellprice listprice lastcost avgcost)) { $ref->{$_} = $form->round_amount($ref->{$_}, 2) }
- }
-
- if ($form->{l_markup}) {
- $ref->{lastcostmarkup} = (($ref->{sellprice} / $ref->{lastcost}) - 1) * 100 if $ref->{lastcost} != 0;
- $ref->{avgcostmarkup} = (($ref->{sellprice} / $ref->{avgcost}) - 1) * 100 if $ref->{avgcost} != 0;
- }
-
- # use this for assemblies
- $onhand = $ref->{onhand};
-
- for (qw(description notes)) { $ref->{$_} =~ s/\r?\n/<br>/g }
-
- for (1 .. $form->{pncol}) { $column_data{"partnumber_$_"} = "<td>&nbsp;</td>" }
-
- $column_data{runningnumber} = "<td align=right>$i</td>";
- $column_data{partnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
-
- if ($ref->{assemblypartnumber}) {
- if ($sameid eq $ref->{id}) {
- $i--;
- for (qw(runningnumber partnumber)) { $column_data{$_} = "<td>&nbsp;</td>" }
- }
- }
-
- $column_data{assemblypartnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{assembly_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{assemblypartnumber}&nbsp;</a></td>";
-
- if ($ref->{assemblyitem}) {
- $onhand = 0 if $form->{sold};
- $ref->{income} = "";
-
- for (qw(runningnumber partnumber)) { $column_data{$_} = "<td>&nbsp;</td>" }
- $i--;
-
- $column_data{"partnumber_$ref->{stagger}"} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
-
- }
-
- for (qw(description notes partsgroup employee curr)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
-
- $column_data{onhand} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;")."</td>";
- $column_data{perassembly} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{perassembly}, '', "&nbsp;")."</td>";
-
- if ($form->{summary}) {
- $column_data{sellprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{sellprice}, 4, "&nbsp;") . "</td>";
- } else {
- $column_data{sellprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{sellprice}, 2, "&nbsp;") . "</td>";
- }
- for (qw(listprice lastcost avgcost)) { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;") . "</td>" }
-
- for (qw(lastcost avgcost)) { $column_data{"${_}markup"} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{"${_}markup"}, 1, "&nbsp;")."</td>" }
-
- if ($form->{l_linetotal}) {
- for (qw(sellprice lastcost avgcost listprice)) { $column_data{"linetotal$_"} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2, "&nbsp;")."</td>" }
- }
-
- if ($ref->{assemblyitem} && $ref->{stagger} > 1) {
- for (qw(sellprice lastcost avgcost listprice)) { $column_data{"linetotal$_"} = "<td>&nbsp;</td>" }
- }
-
- if (!$ref->{assemblyitem}) {
- $totalsellprice += $onhand * $ref->{sellprice};
- $totallastcost += $onhand * $ref->{lastcost};
- $totalavgcost += $onhand * $ref->{avgcost};
- $totallistprice += $onhand * $ref->{listprice};
-
- $subtotalonhand += $onhand;
- $subtotalsellprice += $onhand * $ref->{sellprice};
- $subtotallastcost += $onhand * $ref->{lastcost};
- $subtotalavgcost += $onhand * $ref->{avgcost};
- $subtotallistprice += $onhand * $ref->{listprice};
- }
-
- $column_data{rop} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{rop}, '', "&nbsp;")."</td>";
- $column_data{weight} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{weight}, '', "&nbsp;")."</td>";
- $column_data{unit} = "<td>$ref->{unit}&nbsp;</td>";
- $column_data{bin} = "<td>$ref->{bin}&nbsp;</td>";
- $column_data{priceupdate} = "<td>$ref->{priceupdate}&nbsp;</td>";
-
- $ref->{module} = 'ps' if $ref->{till};
- $column_data{invnumber} = ($ref->{module} ne 'oe') ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}&nbsp;</a></td>" : "<td>$ref->{invnumber}&nbsp;</td>";
- $column_data{ordnumber} = ($ref->{module} eq 'oe') ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{ordnumber}&nbsp;</a></td>" : "<td>$ref->{ordnumber}&nbsp;</td>";
- $column_data{quonumber} = ($ref->{module} eq 'oe' && !$ref->{ordnumber}) ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{quonumber}&nbsp;</a></td>" : "<td>$ref->{quonumber}&nbsp;</td>";
-
- $column_data{name} = "<td>$ref->{name}&nbsp;</td>";
-
- $column_data{image} = ($ref->{image}) ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>" : "<td>&nbsp;</td>";
- $column_data{drawing} = ($ref->{drawing}) ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>" : "<td>&nbsp;</td>";
- $column_data{microfiche} = ($ref->{microfiche}) ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>" : "<td>&nbsp;</td>";
-
- for (qw(make model serialnumber warehouse inventory income expense tax)) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
-
- $j++; $j %= 2;
- print "<tr class=listrow$j>";
-
- for (@column_index) { print "\n$column_data{$_}" }
+ if ( $k > 0 ) {
+ $samegroup = "";
+ for (@groupby) { $samegroup .= $form->{parts}->[0]->{$_} }
+ }
- print qq|
+ $i = 0;
+ $n = 0;
+
+ foreach $ref ( @{ $form->{parts} } ) {
+
+ $ref->{exchangerate} ||= 1;
+ $ref->{discount} *= 1;
+
+ if ( $form->{summary} ) {
+
+ $summary{ $ref->{id} }{total} += $ref->{sellprice} * $ref->{onhand};
+ $summary{ $ref->{id} }{onhand} += $ref->{onhand};
+
+ if ( $n < $k ) {
+ $nextgroup = "";
+ for (@groupby) {
+ $nextgroup .= $form->{parts}->[ $n + 1 ]->{$_};
+ }
+ $n++;
+
+ $form->{parts}->[$n]->{exchangerate} ||= 1;
+
+ if ( $samegroup eq $nextgroup ) {
+ for (qw(exchangerate discount)) {
+ $form->{parts}->[$n]->{$_} =
+ ( $ref->{$_} + $form->{parts}->[$n]->{$_} ) / 2;
+ }
+ next;
+ }
+ $samegroup = $nextgroup;
+ }
+
+ $ref->{onhand} = $summary{ $ref->{id} }{onhand};
+ $ref->{sellprice} =
+ ( $ref->{onhand} )
+ ? $summary{ $ref->{id} }{total} / $ref->{onhand}
+ : 0;
+
+ $summary{ $ref->{id} }{total} = 0;
+ $summary{ $ref->{id} }{onhand} = 0;
+
+ }
+
+ if ( $form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem} ) {
+ if ( $sameitem ne $ref->{ $form->{sort} } ) {
+ &parts_subtotal;
+ $sameitem = $ref->{ $form->{sort} };
+ }
+ }
+
+ $i++;
+
+ if ( $form->{l_curr} ) {
+ if ( $ref->{module} eq 'oe' ) {
+ $ref->{sellprice} =
+ $ref->{sellprice} * ( 1 - $ref->{discount} );
+ }
+ else {
+ for (qw(sellprice listprice lastcost avgcost)) {
+ $ref->{$_} /= $ref->{exchangerate};
+ }
+ }
+ }
+ else {
+ if ( $ref->{module} eq 'oe' ) {
+ $ref->{sellprice} =
+ $ref->{sellprice} * ( 1 - $ref->{discount} );
+ for (qw(sellprice listprice lastcost avgcost)) {
+ $ref->{$_} *= $ref->{exchangerate};
+ }
+ }
+ }
+
+ if ( !$form->{summary} ) {
+ for (qw(sellprice listprice lastcost avgcost)) {
+ $ref->{$_} = $form->round_amount( $ref->{$_}, 2 );
+ }
+ }
+
+ if ( $form->{l_markup} ) {
+ $ref->{lastcostmarkup} =
+ ( ( $ref->{sellprice} / $ref->{lastcost} ) - 1 ) * 100
+ if $ref->{lastcost} != 0;
+ $ref->{avgcostmarkup} =
+ ( ( $ref->{sellprice} / $ref->{avgcost} ) - 1 ) * 100
+ if $ref->{avgcost} != 0;
+ }
+
+ # use this for assemblies
+ $onhand = $ref->{onhand};
+
+ for (qw(description notes)) { $ref->{$_} =~ s/\r?\n/<br>/g }
+
+ for ( 1 .. $form->{pncol} ) {
+ $column_data{"partnumber_$_"} = "<td>&nbsp;</td>";
+ }
+
+ $column_data{runningnumber} = "<td align=right>$i</td>";
+ $column_data{partnumber} =
+"<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
+
+ if ( $ref->{assemblypartnumber} ) {
+ if ( $sameid eq $ref->{id} ) {
+ $i--;
+ for (qw(runningnumber partnumber)) {
+ $column_data{$_} = "<td>&nbsp;</td>";
+ }
+ }
+ }
+
+ $column_data{assemblypartnumber} =
+"<td><a href=$form->{script}?action=edit&id=$ref->{assembly_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{assemblypartnumber}&nbsp;</a></td>";
+
+ if ( $ref->{assemblyitem} ) {
+ $onhand = 0 if $form->{sold};
+ $ref->{income} = "";
+
+ for (qw(runningnumber partnumber)) {
+ $column_data{$_} = "<td>&nbsp;</td>";
+ }
+ $i--;
+
+ $column_data{"partnumber_$ref->{stagger}"} =
+"<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
+
+ }
+
+ for (qw(description notes partsgroup employee curr)) {
+ $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
+ }
+
+ $column_data{onhand} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{onhand}, '', "&nbsp;" )
+ . "</td>";
+ $column_data{perassembly} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{perassembly}, '',
+ "&nbsp;" )
+ . "</td>";
+
+ if ( $form->{summary} ) {
+ $column_data{sellprice} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{sellprice}, 4,
+ "&nbsp;" )
+ . "</td>";
+ }
+ else {
+ $column_data{sellprice} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{sellprice}, 2,
+ "&nbsp;" )
+ . "</td>";
+ }
+ for (qw(listprice lastcost avgcost)) {
+ $column_data{$_} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{$_}, 2, "&nbsp;" )
+ . "</td>";
+ }
+
+ for (qw(lastcost avgcost)) {
+ $column_data{"${_}markup"} = "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{"${_}markup"}, 1,
+ "&nbsp;" )
+ . "</td>";
+ }
+
+ if ( $form->{l_linetotal} ) {
+ for (qw(sellprice lastcost avgcost listprice)) {
+ $column_data{"linetotal$_"} = "<td align=right>"
+ . $form->format_amount( \%myconfig,
+ $ref->{onhand} * $ref->{$_},
+ 2, "&nbsp;" )
+ . "</td>";
+ }
+ }
+
+ if ( $ref->{assemblyitem} && $ref->{stagger} > 1 ) {
+ for (qw(sellprice lastcost avgcost listprice)) {
+ $column_data{"linetotal$_"} = "<td>&nbsp;</td>";
+ }
+ }
+
+ if ( !$ref->{assemblyitem} ) {
+ $totalsellprice += $onhand * $ref->{sellprice};
+ $totallastcost += $onhand * $ref->{lastcost};
+ $totalavgcost += $onhand * $ref->{avgcost};
+ $totallistprice += $onhand * $ref->{listprice};
+
+ $subtotalonhand += $onhand;
+ $subtotalsellprice += $onhand * $ref->{sellprice};
+ $subtotallastcost += $onhand * $ref->{lastcost};
+ $subtotalavgcost += $onhand * $ref->{avgcost};
+ $subtotallistprice += $onhand * $ref->{listprice};
+ }
+
+ $column_data{rop} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{rop}, '', "&nbsp;" )
+ . "</td>";
+ $column_data{weight} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{weight}, '', "&nbsp;" )
+ . "</td>";
+ $column_data{unit} = "<td>$ref->{unit}&nbsp;</td>";
+ $column_data{bin} = "<td>$ref->{bin}&nbsp;</td>";
+ $column_data{priceupdate} = "<td>$ref->{priceupdate}&nbsp;</td>";
+
+ $ref->{module} = 'ps' if $ref->{till};
+ $column_data{invnumber} =
+ ( $ref->{module} ne 'oe' )
+ ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}&nbsp;</a></td>"
+ : "<td>$ref->{invnumber}&nbsp;</td>";
+ $column_data{ordnumber} =
+ ( $ref->{module} eq 'oe' )
+ ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{ordnumber}&nbsp;</a></td>"
+ : "<td>$ref->{ordnumber}&nbsp;</td>";
+ $column_data{quonumber} =
+ ( $ref->{module} eq 'oe' && !$ref->{ordnumber} )
+ ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{quonumber}&nbsp;</a></td>"
+ : "<td>$ref->{quonumber}&nbsp;</td>";
+
+ $column_data{name} = "<td>$ref->{name}&nbsp;</td>";
+
+ $column_data{image} =
+ ( $ref->{image} )
+ ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>"
+ : "<td>&nbsp;</td>";
+ $column_data{drawing} =
+ ( $ref->{drawing} )
+ ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>"
+ : "<td>&nbsp;</td>";
+ $column_data{microfiche} =
+ ( $ref->{microfiche} )
+ ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>"
+ : "<td>&nbsp;</td>";
+
+ for (qw(make model serialnumber warehouse inventory income expense tax))
+ {
+ $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>";
+ }
+
+ $j++;
+ $j %= 2;
+ print "<tr class=listrow$j>";
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
</tr>
|;
- $sameid = $ref->{id};
-
- }
-
-
- if ($form->{l_subtotal} eq 'Y') {
- &parts_subtotal;
- }
-
- if ($form->{"l_linetotal"}) {
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
- $column_data{linetotalsellprice} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalsellprice, 2, "&nbsp;")."</th>";
- $column_data{linetotallastcost} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totallastcost, 2, "&nbsp;")."</th>";
- $column_data{linetotalavgcost} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalavgcost, 2, "&nbsp;")."</th>";
- $column_data{linetotallistprice} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totallistprice, 2, "&nbsp;")."</th>";
+ $sameid = $ref->{id};
- print "<tr class=listtotal>";
+ }
- for (@column_index) { print "\n$column_data{$_}" }
+ if ( $form->{l_subtotal} eq 'Y' ) {
+ &parts_subtotal;
+ }
- print qq|</tr>
+ if ( $form->{"l_linetotal"} ) {
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+ $column_data{linetotalsellprice} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalsellprice, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{linetotallastcost} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totallastcost, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{linetotalavgcost} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalavgcost, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{linetotallistprice} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totallistprice, 2, "&nbsp;" )
+ . "</th>";
+
+ print "<tr class=listtotal>";
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|</tr>
|;
- }
+ }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -1787,8 +2234,8 @@ sub generate_report {
</table>
|;
-
- print qq|
+
+ print qq|
<br>
@@ -1797,18 +2244,18 @@ sub generate_report {
<input type=hidden name=item value=$form->{searchitems}>
|;
- $form->hide_form(qw(callback path login sessionid));
+ $form->hide_form(qw(callback path login sessionid));
- foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
- print $item->{code};
- }
+ foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
+ print $item->{code};
+ }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -1817,63 +2264,86 @@ sub generate_report {
}
-
sub parts_subtotal {
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
- $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{individual});
-
- $column_data{onhand} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalonhand, '', "&nbsp;")."</th>";
-
- $column_data{linetotalsellprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalsellprice, 2, "&nbsp;")."</th>";
- $column_data{linetotallistprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallistprice, 2, "&nbsp;")."</th>";
- $column_data{linetotallastcost} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallastcost, 2, "&nbsp;")."</th>";
- $column_data{linetotalavgcost} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalavgcost, 2, "&nbsp;")."</th>";
-
- $subtotalonhand = 0;
- $subtotalsellprice = 0;
- $subtotallistprice = 0;
- $subtotallastcost = 0;
- $subtotalavgcost = 0;
-
- print "<tr class=listsubtotal>";
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+ $subtotalonhand = 0
+ if ( $form->{searchitems} eq 'assembly' && $form->{individual} );
+
+ $column_data{onhand} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalonhand, '', "&nbsp;" )
+ . "</th>";
+
+ $column_data{linetotalsellprice} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalsellprice, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{linetotallistprice} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotallistprice, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{linetotallastcost} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotallastcost, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{linetotalavgcost} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalavgcost, 2, "&nbsp;" )
+ . "</th>";
+
+ $subtotalonhand = 0;
+ $subtotalsellprice = 0;
+ $subtotallistprice = 0;
+ $subtotallastcost = 0;
+ $subtotalavgcost = 0;
+
+ print "<tr class=listsubtotal>";
- for (@column_index) { print "\n$column_data{$_}" }
+ for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ print qq|
</tr>
|;
}
-
sub requirements {
- $form->get_partsgroup(\%myconfig, { searchitems => 'parts'});
- $form->all_years(\%myconfig);
+ $form->get_partsgroup( \%myconfig, { searchitems => 'parts' } );
+ $form->all_years( \%myconfig );
- if (@{ $form->{all_partsgroup} }) {
- $partsgroup = qq|<option>\n|;
+ if ( @{ $form->{all_partsgroup} } ) {
+ $partsgroup = qq|<option>\n|;
- for (@{ $form->{all_partsgroup} }) { $partsgroup .= qq|<option value="|.$form->quote($_->{partsgroup}).qq|--$_->{id}">$_->{partsgroup}\n| }
+ for ( @{ $form->{all_partsgroup} } ) {
+ $partsgroup .=
+ qq|<option value="|
+ . $form->quote( $_->{partsgroup} )
+ . qq|--$_->{id}">$_->{partsgroup}\n|;
+ }
- $partsgroup = qq|
- <th align=right nowrap>|.$locale->text('Group').qq|</th>
+ $partsgroup = qq|
+ <th align=right nowrap>| . $locale->text('Group') . qq|</th>
<td><select name=partsgroup>$partsgroup</select></td>
|;
- $l_partsgroup = qq|<input name=l_partsgroup class=checkbox type=checkbox value=Y> |.$locale->text('Group');
- }
+ $l_partsgroup =
+ qq|<input name=l_partsgroup class=checkbox type=checkbox value=Y> |
+ . $locale->text('Group');
+ }
+
+ if ( @{ $form->{all_years} } ) {
- if (@{ $form->{all_years} }) {
- # accounting years
- $form->{selectaccountingyear} = qq|<option>\n|;
- for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
-
-
- $selectfrom = qq|
+ # accounting years
+ $form->{selectaccountingyear} = qq|<option>\n|;
+ for ( @{ $form->{all_years} } ) {
+ $form->{selectaccountingyear} .= qq|<option>$_\n|;
+ }
+
+ $selectfrom = qq|
<tr>
- <th align=right>|.$locale->text('Period').qq|</th>
+ <th align=right>| . $locale->text('Period') . qq|</th>
<td colspan=3>
<table>
<tr>
@@ -1883,27 +2353,29 @@ sub requirements {
<td>
|;
- $selectfrom .= qq|
+ $selectfrom .= qq|
<table>
<tr>
|;
- for (sort keys %{ $form->{all_month} }) {
- $i = ($_ * 1) - 1;
- if (($i % 3) == 0) {
- $selectfrom .= qq|
+ for ( sort keys %{ $form->{all_month} } ) {
+ $i = ( $_ * 1 ) - 1;
+ if ( ( $i % 3 ) == 0 ) {
+ $selectfrom .= qq|
</tr>
<tr>
|;
- }
+ }
- $i = $_ * 1;
-
- $selectfrom .= qq|
- <td nowrap><input name="l_month_$i" class checkbox type=checkbox value=Y>&nbsp;|.$locale->text($form->{all_month}{$_}).qq|</td>\n|;
- }
-
- $selectfrom .= qq|
+ $i = $_ * 1;
+
+ $selectfrom .= qq|
+ <td nowrap><input name="l_month_$i" class checkbox type=checkbox value=Y>&nbsp;|
+ . $locale->text( $form->{all_month}{$_} )
+ . qq|</td>\n|;
+ }
+
+ $selectfrom .= qq|
</tr>
</table>
</td>
@@ -1912,22 +2384,23 @@ sub requirements {
</td>
</tr>
|;
- } else {
- $form->error($locale->text('No History!'));
- }
+ }
+ else {
+ $form->error( $locale->text('No History!') );
+ }
- $form->{title} = $locale->text('Parts Requirements');
-
- $form->header;
-
- print qq|
+ $form->{title} = $locale->text('Parts Requirements');
+
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
|;
- print qq|
+ print qq|
<table width="100%">
@@ -1937,11 +2410,11 @@ sub requirements {
<td>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('Number') . qq|</th>
<td><input name=partnumber size=20></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Description').qq|</th>
+ <th align=right nowrap>| . $locale->text('Description') . qq|</th>
<td colspan=3><input name=description size=40></td>
</tr>
<tr>
@@ -1960,20 +2433,22 @@ sub requirements {
<input type="hidden" name="sort" value="partnumber">
<br>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>|;
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>|;
- $form->hide_form(qw(path login sessionid));
-
- print qq|
+ $form->hide_form(qw(path login sessionid));
+
+ print qq|
</form>
|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</body>
</html>
@@ -1981,75 +2456,89 @@ sub requirements {
}
+sub requirements_report {
+ $callback = "$form->{script}?action=requirements_report";
+ for (qw(path login sessionid year)) { $callback .= qq|&$_=$form->{$_}| }
+ for (qw(partsgroup)) {
+ $callback .= qq|&$_=| . $form->escape( $form->{$_}, 1 );
+ }
-sub requirements_report {
+ if ( $form->{partnumber} ) {
+ $callback .= "&partnumber=" . $form->escape( $form->{partnumber}, 1 );
+ $option .= $locale->text('Number') . qq| : $form->{partnumber}<br>|;
+ }
+ if ( $form->{partsgroup} ) {
+ ($partsgroup) = split /--/, $form->{partsgroup};
+ $option .= $locale->text('Group') . qq| : $partsgroup<br>|;
+ }
+ if ( $form->{description} ) {
+ $callback .= "&description=" . $form->escape( $form->{description}, 1 );
+ $description = $form->{description};
+ $description =~ s/\r?\n/<br>/g;
+ $option .=
+ $locale->text('Description') . qq| : $form->{description}<br>|;
+ }
- $callback = "$form->{script}?action=requirements_report";
- for (qw(path login sessionid year)) { $callback .= qq|&$_=$form->{$_}| }
- for (qw(partsgroup)) { $callback .= qq|&$_=|.$form->escape($form->{$_},1) }
-
- if ($form->{partnumber}) {
- $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
- $option .= $locale->text('Number').qq| : $form->{partnumber}<br>|;
- }
- if ($form->{partsgroup}) {
- ($partsgroup) = split /--/, $form->{partsgroup};
- $option .= $locale->text('Group').qq| : $partsgroup<br>|;
- }
- if ($form->{description}) {
- $callback .= "&description=".$form->escape($form->{description},1);
- $description = $form->{description};
- $description =~ s/\r?\n/<br>/g;
- $option .= $locale->text('Description').qq| : $form->{description}<br>|;
- }
-
-
- @column_index = $form->sort_columns(qw(partnumber description));
- unshift @column_index, "runningnumber";
-
- for (1 .. 12) {
- if ($form->{"l_month_$_"}) {
- $callback .= qq|&l_month_$_=$form->{"l_month_$_"}|;
- push @column_index, $_;
- $month{$_} = 1;
+ @column_index = $form->sort_columns(qw(partnumber description));
+ unshift @column_index, "runningnumber";
+
+ for ( 1 .. 12 ) {
+ if ( $form->{"l_month_$_"} ) {
+ $callback .= qq|&l_month_$_=$form->{"l_month_$_"}|;
+ push @column_index, $_;
+ $month{$_} = 1;
+ }
}
- }
-
- push @column_index, "year" unless %month;
- push @column_index, qw(onhand so po order);
- IC->requirements(\%myconfig, \%$form);
+ push @column_index, "year" unless %month;
+ push @column_index, qw(onhand so po order);
- $form->sort_order();
-
- $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
-
- $href = $callback;
-
- $callback =~ s/(direction=).*?\&/$1$form->{direction}\&/;
-
- if (%month) {
- $option .= $locale->text('Year').qq| : $form->{year}<br>|;
- }
-
-
- $column_header{runningnumber} = qq|<th a class=listheading>&nbsp;</th>|;
- $column_header{partnumber} = qq|<th nowrap colspan=$colspan><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</a></th>|;
- $column_header{description} = qq|<th nowrap><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
- $column_header{onhand} = qq|<th class=listheading nowrap>|.$locale->text('Onhand').qq|</th>|;
- $column_header{so} = qq|<th class=listheading nowrap>|.$locale->text('SO').qq|</th>|;
- $column_header{po} = qq|<th class=listheading nowrap>|.$locale->text('PO').qq|</th>|;
- $column_header{order} = qq|<th class=listheading nowrap>|.$locale->text('Order').qq|</th>|;
- $column_header{year} = qq|<th class=listheading nowrap>$form->{year}</th>|;
-
- for (sort { $a <=> $b } keys %month) { $column_header{$_} = qq|<th class=listheading nowrap>|.$locale->text($locale->{SHORT_MONTH}[$_-1]).qq|</th>| }
-
- $form->{title} = $locale->text('Parts Requirements');
-
- $form->header;
+ IC->requirements( \%myconfig, \%$form );
- print qq|
+ $form->sort_order();
+
+ $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
+
+ $href = $callback;
+
+ $callback =~ s/(direction=).*?\&/$1$form->{direction}\&/;
+
+ if (%month) {
+ $option .= $locale->text('Year') . qq| : $form->{year}<br>|;
+ }
+
+ $column_header{runningnumber} = qq|<th a class=listheading>&nbsp;</th>|;
+ $column_header{partnumber} =
+qq|<th nowrap colspan=$colspan><a class=listheading href=$href&sort=partnumber>|
+ . $locale->text('Number')
+ . qq|</a></th>|;
+ $column_header{description} =
+ qq|<th nowrap><a class=listheading href=$href&sort=description>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
+ $column_header{onhand} =
+ qq|<th class=listheading nowrap>| . $locale->text('Onhand') . qq|</th>|;
+ $column_header{so} =
+ qq|<th class=listheading nowrap>| . $locale->text('SO') . qq|</th>|;
+ $column_header{po} =
+ qq|<th class=listheading nowrap>| . $locale->text('PO') . qq|</th>|;
+ $column_header{order} =
+ qq|<th class=listheading nowrap>| . $locale->text('Order') . qq|</th>|;
+ $column_header{year} = qq|<th class=listheading nowrap>$form->{year}</th>|;
+
+ for ( sort { $a <=> $b } keys %month ) {
+ $column_header{$_} =
+ qq|<th class=listheading nowrap>|
+ . $locale->text( $locale->{SHORT_MONTH}[ $_ - 1 ] )
+ . qq|</th>|;
+ }
+
+ $form->{title} = $locale->text('Parts Requirements');
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -2066,93 +2555,113 @@ sub requirements_report {
<tr class=listheading>
|;
- for (@column_index) { print "\n$column_header{$_}" }
-
- print qq|
+ for (@column_index) { print "\n$column_header{$_}" }
+
+ print qq|
</tr>
|;
+ # add order to callback
+ $form->{callback} = $callback .= "&sort=$form->{sort}";
- # add order to callback
- $form->{callback} = $callback .= "&sort=$form->{sort}";
+ # escape callback for href
+ $callback = $form->escape($callback);
- # escape callback for href
- $callback = $form->escape($callback);
+ if ( @{ $form->{parts} } ) {
+ $sameid = $form->{parts}->[0]->{id};
+ }
- if (@{ $form->{parts} }) {
- $sameid = $form->{parts}->[0]->{id};
- }
+ for ( keys %month ) { $column_data{$_} = "<td>&nbsp;</td>" }
- for (keys %month) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $i = 0;
- $qty = 0;
- foreach $ref (@{ $form->{parts} }) {
-
- if ($ref->{id} != $sameid) {
-
- $i++;
- $column_data{runningnumber} = "<td align=right>$i</td>";
-
- $order = 0 if $order < 0;
- $column_data{order} = "<td align=right>".$form->format_amount(\%myconfig, $order, '', "-")."</td>";
- $j++; $j %= 2;
- print "<tr class=listrow$j>";
-
- for (@column_index) {
- print "\n$column_data{$_}";
- $column_data{$_} = "<td>&nbsp;</td>";
- }
-
- print qq|
+ $i = 0;
+ $qty = 0;
+ foreach $ref ( @{ $form->{parts} } ) {
+
+ if ( $ref->{id} != $sameid ) {
+
+ $i++;
+ $column_data{runningnumber} = "<td align=right>$i</td>";
+
+ $order = 0 if $order < 0;
+ $column_data{order} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $order, '', "-" ) . "</td>";
+ $j++;
+ $j %= 2;
+ print "<tr class=listrow$j>";
+
+ for (@column_index) {
+ print "\n$column_data{$_}";
+ $column_data{$_} = "<td>&nbsp;</td>";
+ }
+
+ print qq|
</tr>
|;
- $qty = 0;
- }
+ $qty = 0;
+ }
-
- $ref->{description} =~ s/\r?\n/<br>/g;
-
- $column_data{partnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
+ $ref->{description} =~ s/\r?\n/<br>/g;
- $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
+ $column_data{partnumber} =
+"<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
- $column_data{onhand} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;")."</td>";
- $column_data{so} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{so}, '', "&nbsp;")."</td>";
- $column_data{po} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{po}, '', "&nbsp;")."</td>";
+ $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
- $column_data{$ref->{month}} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{qty}, '', "&nbsp;")."</td>";
- if (%month) {
- $qty += $ref->{qty} if exists $month{$ref->{month}};
- } else {
- $qty += $ref->{qty};
- }
-
- $column_data{year} = "<td align=right>".$form->format_amount(\%myconfig, $qty, '', "&nbsp;")."</td>";
+ $column_data{onhand} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{onhand}, '', "&nbsp;" )
+ . "</td>";
+ $column_data{so} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{so}, '', "&nbsp;" )
+ . "</td>";
+ $column_data{po} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{po}, '', "&nbsp;" )
+ . "</td>";
- $order = $qty + $ref->{so} - $ref->{po} - $ref->{onhand};
+ $column_data{ $ref->{month} } =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{qty}, '', "&nbsp;" )
+ . "</td>";
+ if (%month) {
+ $qty += $ref->{qty} if exists $month{ $ref->{month} };
+ }
+ else {
+ $qty += $ref->{qty};
+ }
- $sameid = $ref->{id};
+ $column_data{year} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $qty, '', "&nbsp;" ) . "</td>";
- }
-
- if (@{ $form->{parts} }) {
- $i++;
- $column_data{runningnumber} = "<td align=right>$i</td>";
+ $order = $qty + $ref->{so} - $ref->{po} - $ref->{onhand};
- $order = 0 if $order < 0;
- $column_data{order} = "<td align=right>".$form->format_amount(\%myconfig, $order, '', "-")."</td>";
- $j++; $j %= 2;
- print "<tr class=listrow$j>";
+ $sameid = $ref->{id};
- for (@column_index) { print "\n$column_data{$_}" }
+ }
- print qq|
+ if ( @{ $form->{parts} } ) {
+ $i++;
+ $column_data{runningnumber} = "<td align=right>$i</td>";
+
+ $order = 0 if $order < 0;
+ $column_data{order} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $order, '', "-" ) . "</td>";
+ $j++;
+ $j %= 2;
+ print "<tr class=listrow$j>";
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
</tr>
|;
- }
-
- print qq|
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -2160,8 +2669,8 @@ sub requirements_report {
</table>
|;
-
- print qq|
+
+ print qq|
<br>
@@ -2169,14 +2678,14 @@ sub requirements_report {
|;
- $form->hide_form(qw(callback path login sessionid));
+ $form->hide_form(qw(callback path login sessionid));
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -2185,32 +2694,33 @@ sub requirements_report {
}
-
sub makemodel_row {
- my ($numrows) = @_;
+ my ($numrows) = @_;
- for (qw(make model)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
+ for (qw(make model)) {
+ $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} );
+ }
- print qq|
+ print qq|
<tr>
<td>
<table width=100%>
<tr>
- <th class="listheading">|.$locale->text('Make').qq|</th>
- <th class="listheading">|.$locale->text('Model').qq|</th>
+ <th class="listheading">| . $locale->text('Make') . qq|</th>
+ <th class="listheading">| . $locale->text('Model') . qq|</th>
</tr>
|;
- for $i (1 .. $numrows) {
- print qq|
+ for $i ( 1 .. $numrows ) {
+ print qq|
<tr>
<td><input name="make_$i" size=30 value="$form->{"make_$i"}"></td>
<td><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>
</tr>
|;
- }
+ }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -2218,75 +2728,84 @@ sub makemodel_row {
}
-
sub vendor_row {
- my ($numrows) = @_;
+ my ($numrows) = @_;
- $form->{selectvendor} = $form->unescape($form->{selectvendor});
+ $form->{selectvendor} = $form->unescape( $form->{selectvendor} );
- $currency = qq|
- <th class="listheading">|.$locale->text('Curr').qq|</th>| if $form->{selectcurrency};
-
- print qq|
- <input type=hidden name=selectvendor value="|.$form->escape($form->{selectvendor},1).qq|">
+ $currency = qq|
+ <th class="listheading">| . $locale->text('Curr') . qq|</th>|
+ if $form->{selectcurrency};
+
+ print qq|
+ <input type=hidden name=selectvendor value="|
+ . $form->escape( $form->{selectvendor}, 1 ) . qq|">
<tr>
<td>
<table width=100%>
<tr>
- <th class="listheading">|.$locale->text('Vendor').qq|</th>
- <th class="listheading">|.$locale->text('Number').qq|</th>
- <th class="listheading">|.$locale->text('Cost').qq|</th>
+ <th class="listheading">| . $locale->text('Vendor') . qq|</th>
+ <th class="listheading">| . $locale->text('Number') . qq|</th>
+ <th class="listheading">| . $locale->text('Cost') . qq|</th>
$currency
- <th class="listheading">|.$locale->text('Leadtime').qq|</th>
+ <th class="listheading">| . $locale->text('Leadtime') . qq|</th>
</tr>
|;
- for $i (1 .. $numrows) {
-
- if ($form->{selectcurrency}) {
- $form->{selectcurrency} =~ s/ selected//;
- $form->{selectcurrency} =~ s/option>$form->{"vendorcurr_$i"}/option selected>$form->{"vendorcurr_$i"}/;
- $currency = qq|
+ for $i ( 1 .. $numrows ) {
+
+ if ( $form->{selectcurrency} ) {
+ $form->{selectcurrency} =~ s/ selected//;
+ $form->{selectcurrency} =~
+s/option>$form->{"vendorcurr_$i"}/option selected>$form->{"vendorcurr_$i"}/;
+ $currency = qq|
<td><select name="vendorcurr_$i">$form->{selectcurrency}</select></td>|;
- }
-
- if ($i == $numrows) {
-
- $vendor = qq|
+ }
+
+ if ( $i == $numrows ) {
+
+ $vendor = qq|
<td><input name="vendor_$i" size=35 value="$form->{"vendor_$i"}"></td>
|;
-
- if ($form->{selectvendor}) {
- $vendor = qq|
+
+ if ( $form->{selectvendor} ) {
+ $vendor = qq|
<td width=99%><select name="vendor_$i">$form->{selectvendor}</select></td>
|;
- }
-
- } else {
-
- ($vendor) = split /--/, $form->{"vendor_$i"};
- $vendor = qq|
+ }
+
+ }
+ else {
+
+ ($vendor) = split /--/, $form->{"vendor_$i"};
+ $vendor = qq|
<td>$vendor
<input type=hidden name="vendor_$i" value="$form->{"vendor_$i"}">
</td>
|;
- }
-
- $form->{"partnumber_$i"} = $form->quote($form->{"partnumber_$i"});
- print qq|
+ }
+
+ $form->{"partnumber_$i"} = $form->quote( $form->{"partnumber_$i"} );
+ print qq|
<tr>
$vendor
<td><input name="partnumber_$i" size=20 value="$form->{"partnumber_$i"}"></td>
- <td><input name="lastcost_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2).qq|></td>
+ <td><input name="lastcost_$i" size=10 value=|
+ . $form->format_amount( \%myconfig, $form->{"lastcost_$i"}, 2 )
+ . qq|></td>
$currency
- <td nowrap><input name="leadtime_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"leadtime_$i"}).qq|> <b>|.$locale->text('days').qq|</b></td>
+ <td nowrap><input name="leadtime_$i" size=5 value=|
+ . $form->format_amount( \%myconfig, $form->{"leadtime_$i"} )
+ . qq|> <b>|
+ . $locale->text('days')
+ . qq|</b></td>
</tr>
|;
-
- }
- print qq|
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -2294,100 +2813,107 @@ sub vendor_row {
}
-
sub customer_row {
- my ($numrows) = @_;
+ my ($numrows) = @_;
- if ($form->{selectpricegroup}) {
- $pricegroup = qq|
- <th class="listheading">|.$locale->text('Pricegroup').qq|
+ if ( $form->{selectpricegroup} ) {
+ $pricegroup = qq|
+ <th class="listheading">| . $locale->text('Pricegroup') . qq|
</th>
|;
- }
+ }
- $form->{selectcustomer} = $form->unescape($form->{selectcustomer});
- $form->{selectpricegroup} = $form->unescape($form->{selectpricegroup});
-
- $form->hide_form(qw(selectcurrency));
+ $form->{selectcustomer} = $form->unescape( $form->{selectcustomer} );
+ $form->{selectpricegroup} = $form->unescape( $form->{selectpricegroup} );
+
+ $form->hide_form(qw(selectcurrency));
+
+ $currency = qq|<th class="listheading">| . $locale->text('Curr') . qq|</th>|
+ if $form->{selectcurrency};
- $currency = qq|<th class="listheading">|.$locale->text('Curr').qq|</th>| if $form->{selectcurrency};
-
- print qq|
- <input type=hidden name=selectcustomer value="|.$form->escape($form->{selectcustomer},1).qq|">
- <input type=hidden name=selectpricegroup value="|.$form->escape($form->{selectpricegroup},1).qq|">
+ print qq|
+ <input type=hidden name=selectcustomer value="|
+ . $form->escape( $form->{selectcustomer}, 1 ) . qq|">
+ <input type=hidden name=selectpricegroup value="|
+ . $form->escape( $form->{selectpricegroup}, 1 ) . qq|">
<tr>
<td>
<table width=100%>
<tr>
- <th class="listheading">|.$locale->text('Customer').qq|</th>
+ <th class="listheading">| . $locale->text('Customer') . qq|</th>
$pricegroup
- <th class="listheading">|.$locale->text('Break').qq|</th>
- <th class="listheading">|.$locale->text('Sell Price').qq|</th>
+ <th class="listheading">| . $locale->text('Break') . qq|</th>
+ <th class="listheading">| . $locale->text('Sell Price') . qq|</th>
$currency
- <th class="listheading">|.$locale->text('From').qq|</th>
- <th class="listheading">|.$locale->text('To').qq|</th>
+ <th class="listheading">| . $locale->text('From') . qq|</th>
+ <th class="listheading">| . $locale->text('To') . qq|</th>
</tr>
|;
- for $i (1 .. $numrows) {
+ for $i ( 1 .. $numrows ) {
- if ($form->{selectcurrency}) {
- $form->{selectcurrency} =~ s/ selected//;
- $form->{selectcurrency} =~ s/option>$form->{"customercurr_$i"}/option selected>$form->{"customercurr_$i"}/;
- $currency = qq|
+ if ( $form->{selectcurrency} ) {
+ $form->{selectcurrency} =~ s/ selected//;
+ $form->{selectcurrency} =~
+s/option>$form->{"customercurr_$i"}/option selected>$form->{"customercurr_$i"}/;
+ $currency = qq|
<td><select name="customercurr_$i">$form->{selectcurrency}</select></td>|;
- }
-
- if ($i == $numrows) {
- $customer = qq|
+ }
+
+ if ( $i == $numrows ) {
+ $customer = qq|
<td><input name="customer_$i" size=35 value="$form->{"customer_$i"}"></td>
|;
-
- if ($form->{selectcustomer}) {
- $customer = qq|
+
+ if ( $form->{selectcustomer} ) {
+ $customer = qq|
<td><select name="customer_$i">$form->{selectcustomer}</select></td>
|;
- }
+ }
- if ($form->{selectpricegroup}) {
- $pricegroup = qq|
+ if ( $form->{selectpricegroup} ) {
+ $pricegroup = qq|
<td><select name="pricegroup_$i">$form->{selectpricegroup}</select></td>
|;
- }
+ }
- } else {
- ($customer) = split /--/, $form->{"customer_$i"};
- $customer = qq|
+ }
+ else {
+ ($customer) = split /--/, $form->{"customer_$i"};
+ $customer = qq|
<td>$customer</td>
<input type=hidden name="customer_$i" value="$form->{"customer_$i"}">
|;
- if ($form->{selectpricegroup}) {
- ($pricegroup) = split /--/, $form->{"pricegroup_$i"};
- $pricegroup = qq|
+ if ( $form->{selectpricegroup} ) {
+ ($pricegroup) = split /--/, $form->{"pricegroup_$i"};
+ $pricegroup = qq|
<td>$pricegroup</td>
<input type=hidden name="pricegroup_$i" value="$form->{"pricegroup_$i"}">
|;
- }
- }
-
-
- print qq|
+ }
+ }
+
+ print qq|
<tr>
$customer
$pricegroup
- <td><input name="pricebreak_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"pricebreak_$i"}).qq|></td>
- <td><input name="customerprice_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"customerprice_$i"}, 2).qq|></td>
+ <td><input name="pricebreak_$i" size=5 value=|
+ . $form->format_amount( \%myconfig, $form->{"pricebreak_$i"} )
+ . qq|></td>
+ <td><input name="customerprice_$i" size=10 value=|
+ . $form->format_amount( \%myconfig, $form->{"customerprice_$i"}, 2 )
+ . qq|></td>
$currency
<td><input name="validfrom_$i" size=11 title="$myconfig{dateformat}" value="$form->{"validfrom_$i"}"></td>
<td><input name="validto_$i" size=11 title="$myconfig{dateformat}" value="$form->{"validto_$i"}"></td>
</tr>
|;
- }
+ }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -2395,66 +2921,78 @@ sub customer_row {
}
+sub assembly_row {
+ my ($numrows) = @_;
+
+ @column_index =
+ qw(runningnumber qty unit bom adj partnumber description sellprice listprice lastcost);
+ if ( $form->{selectassemblypartsgroup} ) {
+ $form->{selectassemblypartsgroup} =
+ $form->unescape( $form->{selectassemblypartsgroup} );
+ @column_index =
+ qw(runningnumber qty unit bom adj partnumber description partsgroup sellprice listprice lastcost);
+ }
-sub assembly_row {
- my ($numrows) = @_;
+ delete $form->{previousform};
- @column_index = qw(runningnumber qty unit bom adj partnumber description sellprice listprice lastcost);
-
- if ($form->{selectassemblypartsgroup}) {
- $form->{selectassemblypartsgroup} = $form->unescape($form->{selectassemblypartsgroup});
- @column_index = qw(runningnumber qty unit bom adj partnumber description partsgroup sellprice listprice lastcost);
- }
-
- delete $form->{previousform};
-
- # change callback
- $form->{old_callback} = $form->{callback};
- $callback = $form->{callback};
- $form->{callback} = "$form->{script}?action=display_form";
-
- # delete action
- for (qw(action header)) { delete $form->{$_} }
-
- $form->{baseassembly} = 0;
- $previousform = "";
- # save form variables in a previousform variable
- $form->{selectcustomer} = ""; # we seem to have run into a 40kb limit
- foreach $key (sort keys %$form) {
- # escape ampersands
- $form->{$key} =~ s/&/%26/g;
- $previousform .= qq|$key=$form->{$key}&| if $form->{$key};
- }
- chop $previousform;
- $form->{previousform} = $form->escape($previousform, 1);
-
- $form->{sellprice} = 0;
- $form->{listprice} = 0;
- $form->{lastcost} = 0;
- $form->{weight} = 0;
-
- $form->{callback} = $callback;
-
-
- $column_header{runningnumber} = qq|<th nowrap width=5%>|.$locale->text('Item').qq|</th>|;
- $column_header{qty} = qq|<th align=left nowrap width=10%>|.$locale->text('Qty').qq|</th>|;
- $column_header{unit} = qq|<th align=left nowrap width=5%>|.$locale->text('Unit').qq|</th>|;
- $column_header{partnumber} = qq|<th align=left nowrap width=20%>|.$locale->text('Number').qq|</th>|;
- $column_header{description} = qq|<th nowrap width=50%>|.$locale->text('Description').qq|</th>|;
- $column_header{sellprice} = qq|<th align=right nowrap>|.$locale->text('Sell').qq|</th>|;
- $column_header{listprice} = qq|<th align=right nowrap>|.$locale->text('List').qq|</th>|;
- $column_header{lastcost} = qq|<th align=right nowrap>|.$locale->text('Cost').qq|</th>|;
- $column_header{bom} = qq|<th>|.$locale->text('BOM').qq|</th>|;
- $column_header{adj} = qq|<th>|.$locale->text('A').qq|</th>|;
- $column_header{partsgroup} = qq|<th>|.$locale->text('Group').qq|</th>|;
-
- print qq|
+ # change callback
+ $form->{old_callback} = $form->{callback};
+ $callback = $form->{callback};
+ $form->{callback} = "$form->{script}?action=display_form";
+
+ # delete action
+ for (qw(action header)) { delete $form->{$_} }
+
+ $form->{baseassembly} = 0;
+ $previousform = "";
+
+ # save form variables in a previousform variable
+ $form->{selectcustomer} = ""; # we seem to have run into a 40kb limit
+ foreach $key ( sort keys %$form ) {
+
+ # escape ampersands
+ $form->{$key} =~ s/&/%26/g;
+ $previousform .= qq|$key=$form->{$key}&| if $form->{$key};
+ }
+ chop $previousform;
+ $form->{previousform} = $form->escape( $previousform, 1 );
+
+ $form->{sellprice} = 0;
+ $form->{listprice} = 0;
+ $form->{lastcost} = 0;
+ $form->{weight} = 0;
+
+ $form->{callback} = $callback;
+
+ $column_header{runningnumber} =
+ qq|<th nowrap width=5%>| . $locale->text('Item') . qq|</th>|;
+ $column_header{qty} =
+ qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
+ $column_header{unit} =
+ qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
+ $column_header{partnumber} =
+ qq|<th align=left nowrap width=20%>|
+ . $locale->text('Number')
+ . qq|</th>|;
+ $column_header{description} =
+ qq|<th nowrap width=50%>| . $locale->text('Description') . qq|</th>|;
+ $column_header{sellprice} =
+ qq|<th align=right nowrap>| . $locale->text('Sell') . qq|</th>|;
+ $column_header{listprice} =
+ qq|<th align=right nowrap>| . $locale->text('List') . qq|</th>|;
+ $column_header{lastcost} =
+ qq|<th align=right nowrap>| . $locale->text('Cost') . qq|</th>|;
+ $column_header{bom} = qq|<th>| . $locale->text('BOM') . qq|</th>|;
+ $column_header{adj} = qq|<th>| . $locale->text('A') . qq|</th>|;
+ $column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
+
+ print qq|
<p>
<table width=100%>
<tr class=listheading>
- <th class=listheading>|.$locale->text('Individual Items').qq|</th>
+ <th class=listheading>| . $locale->text('Individual Items') . qq|</th>
</tr>
<tr>
<td>
@@ -2462,91 +3000,125 @@ sub assembly_row {
<tr>
|;
- for (@column_index) { print "\n$column_header{$_}" }
-
- print qq|
+ for (@column_index) { print "\n$column_header{$_}" }
+
+ print qq|
</tr>
|;
- $spc = ($form->{path} =~ /lynx/) ? "." : " ";
- $numrows-- if $form->{project_id};
+ $spc = ( $form->{path} =~ /lynx/ ) ? "." : " ";
+ $numrows-- if $form->{project_id};
- for $i (1 .. $numrows) {
- for (qw(partnumber description)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
+ for $i ( 1 .. $numrows ) {
+ for (qw(partnumber description)) {
+ $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} );
+ }
- $linetotalsellprice = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
- $form->{sellprice} += $linetotalsellprice;
-
- $linetotallistprice = $form->round_amount($form->{"listprice_$i"} * $form->{"qty_$i"}, 2);
- $form->{listprice} += $linetotallistprice;
+ $linetotalsellprice =
+ $form->round_amount( $form->{"sellprice_$i"} * $form->{"qty_$i"}, 2 );
+ $form->{sellprice} += $linetotalsellprice;
- $linetotallastcost = $form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"}, 2);
- $form->{lastcost} += $linetotallastcost;
+ $linetotallistprice =
+ $form->round_amount( $form->{"listprice_$i"} * $form->{"qty_$i"}, 2 );
+ $form->{listprice} += $linetotallistprice;
+ $linetotallastcost =
+ $form->round_amount( $form->{"lastcost_$i"} * $form->{"qty_$i"}, 2 );
+ $form->{lastcost} += $linetotallastcost;
- $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
+ $form->{"qty_$i"} =
+ $form->format_amount( \%myconfig, $form->{"qty_$i"} );
- $linetotalsellprice = $form->format_amount(\%myconfig, $linetotalsellprice, 2);
- $linetotallistprice = $form->format_amount(\%myconfig, $linetotallistprice, 2);
- $linetotallastcost = $form->format_amount(\%myconfig, $linetotallastcost, 2);
+ $linetotalsellprice =
+ $form->format_amount( \%myconfig, $linetotalsellprice, 2 );
+ $linetotallistprice =
+ $form->format_amount( \%myconfig, $linetotallistprice, 2 );
+ $linetotallastcost =
+ $form->format_amount( \%myconfig, $linetotallastcost, 2 );
- if ($i == $numrows && !$form->{project_id}) {
+ if ( $i == $numrows && !$form->{project_id} ) {
- for (qw(runningnumber unit bom adj)) { $column_data{$_} = qq|<td></td>| }
+ for (qw(runningnumber unit bom adj)) {
+ $column_data{$_} = qq|<td></td>|;
+ }
- $column_data{qty} = qq|<td><input name="qty_$i" size=6 value="$form->{"qty_$i"}" accesskey="$i" title="[Alt-$i]"></td>|;
- $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
- $column_data{description} = qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"></td>|;
- $column_data{partsgroup} = qq|<td><select name="partsgroup_$i">$form->{selectassemblypartsgroup}</select></td>|;
+ $column_data{qty} =
+qq|<td><input name="qty_$i" size=6 value="$form->{"qty_$i"}" accesskey="$i" title="[Alt-$i]"></td>|;
+ $column_data{partnumber} =
+qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
+ $column_data{description} =
+qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"></td>|;
+ $column_data{partsgroup} =
+qq|<td><select name="partsgroup_$i">$form->{selectassemblypartsgroup}</select></td>|;
- } else {
-
- $column_data{partnumber} = qq|<td><button class="submit" type="submit" name="action" value="$spc$form->{"partnumber_$i"}">$spc$form->{"partnumber_$i"}</button></td>
+ }
+ else {
+
+ $column_data{partnumber} =
+qq|<td><button class="submit" type="submit" name="action" value="$spc$form->{"partnumber_$i"}">$spc$form->{"partnumber_$i"}</button></td>
<input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">|;
-
- $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
- $column_data{qty} = qq|<td><input name="qty_$i" size=6 value="$form->{"qty_$i"}" accesskey="$i" title="[Alt-$i]"></td>|;
-
- for (qw(bom adj)) { $form->{"${_}_$i"} = ($form->{"${_}_$i"}) ? "checked" : "" }
- $column_data{bom} = qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
- $column_data{adj} = qq|<td align=center><input name="adj_$i" type=checkbox class=checkbox value=1 $form->{"adj_$i"}></td>|;
-
- ($partsgroup) = split /--/, $form->{"partsgroup_$i"};
- $column_data{partsgroup} = qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$partsgroup</td>|;
-
- $column_data{unit} = qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
- $column_data{description} = qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
-
- }
-
- $column_data{sellprice} = qq|<td align=right>$linetotalsellprice</td>|;
- $column_data{listprice} = qq|<td align=right>$linetotallistprice</td>|;
- $column_data{lastcost} = qq|<td align=right>$linetotallastcost</td>|;
-
- print qq|
+
+ $column_data{runningnumber} =
+ qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
+ $column_data{qty} =
+qq|<td><input name="qty_$i" size=6 value="$form->{"qty_$i"}" accesskey="$i" title="[Alt-$i]"></td>|;
+
+ for (qw(bom adj)) {
+ $form->{"${_}_$i"} = ( $form->{"${_}_$i"} ) ? "checked" : "";
+ }
+ $column_data{bom} =
+qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
+ $column_data{adj} =
+qq|<td align=center><input name="adj_$i" type=checkbox class=checkbox value=1 $form->{"adj_$i"}></td>|;
+
+ ($partsgroup) = split /--/, $form->{"partsgroup_$i"};
+ $column_data{partsgroup} =
+qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$partsgroup</td>|;
+
+ $column_data{unit} =
+qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
+ $column_data{description} =
+qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
+
+ }
+
+ $column_data{sellprice} = qq|<td align=right>$linetotalsellprice</td>|;
+ $column_data{listprice} = qq|<td align=right>$linetotallistprice</td>|;
+ $column_data{lastcost} = qq|<td align=right>$linetotallastcost</td>|;
+
+ print qq|
<tr>|;
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
</tr>
|;
- $form->hide_form("id_$i","sellprice_$i","listprice_$i","lastcost_$i","weight_$i","assembly_$i");
-
- }
+ $form->hide_form(
+ "id_$i", "sellprice_$i", "listprice_$i", "lastcost_$i",
+ "weight_$i", "assembly_$i"
+ );
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+ }
- $column_data{sellprice} = "<th align=right>".$form->format_amount(\%myconfig, $form->{sellprice}, 2)."</th>";
- $column_data{listprice} = "<th align=right>".$form->format_amount(\%myconfig, $form->{listprice}, 2)."</th>";
- $column_data{lastcost} = "<th align=right>".$form->format_amount(\%myconfig, $form->{lastcost}, 2)."</th>";
-
- print qq|
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{sellprice} =
+ "<th align=right>"
+ . $form->format_amount( \%myconfig, $form->{sellprice}, 2 ) . "</th>";
+ $column_data{listprice} =
+ "<th align=right>"
+ . $form->format_amount( \%myconfig, $form->{listprice}, 2 ) . "</th>";
+ $column_data{lastcost} =
+ "<th align=right>"
+ . $form->format_amount( \%myconfig, $form->{lastcost}, 2 ) . "</th>";
+
+ print qq|
<tr>|;
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
</tr>
</table>
</td>
@@ -2557,227 +3129,282 @@ sub assembly_row {
</table>
<input type=hidden name=assembly_rows value=$form->{assembly_rows}>
<input type=hidden name=nextsub value=edit_assemblyitem>
- <input type=hidden name=selectassemblypartsgroup value="|.$form->escape($form->{selectassemblypartsgroup},1).qq|">
+ <input type=hidden name=selectassemblypartsgroup value="|
+ . $form->escape( $form->{selectassemblypartsgroup}, 1 ) . qq|">
|;
-
-}
+}
sub edit_assemblyitem {
- $pn = substr($form->{action}, 1);
+ $pn = substr( $form->{action}, 1 );
- $i = 0;
- for (1 .. $form->{assembly_rows} - 1) {
- $i++;
- last if $form->{"partnumber_$_"} eq $pn;
- }
+ $i = 0;
+ for ( 1 .. $form->{assembly_rows} - 1 ) {
+ $i++;
+ last if $form->{"partnumber_$_"} eq $pn;
+ }
- $form->error($locale->text('unexpected error!')) unless $i;
-
- $form->{baseassembly} = ($form->{baseassembly}) ? $form->{baseassembly} : $form->{"assembly_$i"};
+ $form->error( $locale->text('unexpected error!') ) unless $i;
- $form->{callback} = qq|$form->{script}?action=edit&id=$form->{"id_$i"}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&rowcount=$i&baseassembly=$form->{baseassembly}&isassemblyitem=1&previousform=$form->{previousform}|;
+ $form->{baseassembly} =
+ ( $form->{baseassembly} )
+ ? $form->{baseassembly}
+ : $form->{"assembly_$i"};
- $form->redirect;
-
-}
+ $form->{callback} =
+qq|$form->{script}?action=edit&id=$form->{"id_$i"}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&rowcount=$i&baseassembly=$form->{baseassembly}&isassemblyitem=1&previousform=$form->{previousform}|;
+ $form->redirect;
+
+}
sub update {
- if ($form->{item} eq "assembly") {
-
- $i = $form->{assembly_rows};
- $i = $form->{assembly_rows} + 1 if $form->{project_id};
-
- # if last row is empty check the form otherwise retrieve item
- if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {
-
- &check_form;
-
- } else {
-
- IC->assembly_item(\%myconfig, \%$form);
-
- $rows = scalar @{ $form->{item_list} };
-
- if ($rows) {
- $form->{"adj_$i"} = 1;
-
- if ($rows > 1) {
- $form->{makemodel_rows}--;
- $form->{customer_rows}--;
- &select_item;
- exit;
- } else {
- $form->{"qty_$i"} = 1;
- $form->{"adj_$i"} = 1;
- for (qw(partnumber description unit)) { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) }
- for (keys %{ $form->{item_list}[0] }) { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
-
- if ($form->{item_list}[0]{partsgroup_id}) {
- $form->{"partsgroup_$i"} = qq|$form->{item_list}[0]{partsgroup}--$form->{item_list}[0]{partsgroup_id}|;
- }
-
- $form->{"runningnumber_$i"} = $form->{assembly_rows};
- $form->{assembly_rows}++;
-
- &check_form;
-
- }
-
- } else {
-
- $form->{rowcount} = $i;
- $form->{assembly_rows}++;
-
- &new_item;
-
- }
- }
-
- } else {
-
- &check_form;
+ if ( $form->{item} eq "assembly" ) {
- }
+ $i = $form->{assembly_rows};
+ $i = $form->{assembly_rows} + 1 if $form->{project_id};
-}
+ # if last row is empty check the form otherwise retrieve item
+ if ( ( $form->{"partnumber_$i"} eq "" )
+ && ( $form->{"description_$i"} eq "" )
+ && ( $form->{"partsgroup_$i"} eq "" ) )
+ {
+ &check_form;
-sub check_vendor {
-
- @flds = qw(vendor partnumber lastcost leadtime vendorcurr);
- @a = ();
- $count = 0;
+ }
+ else {
- for (qw(lastcost leadtime)) { $form->{"${_}_$form->{vendor_rows}"} = $form->parse_amount(\%myconfig, $form->{"${_}_$form->{vendor_rows}"}) }
-
- for $i (1 .. $form->{vendor_rows} - 1) {
-
- for (qw(lastcost leadtime)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- if ($form->{"lastcost_$i"} || $form->{"partnumber_$i"}) {
-
- push @a, {};
- $j = $#a;
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
-
- }
- }
-
- $i = $form->{vendor_rows};
-
- if (!$form->{selectvendor}) {
-
- if ($form->{"vendor_$i"} && !$form->{"vendor_id_$i"}) {
- ($form->{vendor}) = split /--/, $form->{"vendor_$i"};
- if (($j = $form->get_name(\%myconfig, vendor)) > 1) {
- &select_name(vendor, $i);
- exit;
- }
-
- if ($j == 1) {
- # we got one name
- $form->{"vendor_$i"} = qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|;
- } else {
- # name is not on file
- $form->error($locale->text('[_1]: Vendor not on file!', $form->{"vendor_$i"}));
- }
- }
- }
-
- if ($form->{"vendor_$i"}) {
- push @a, {};
- $j = $#a;
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
- }
-
- $form->redo_rows(\@flds, \@a, $count, $form->{vendor_rows});
- $form->{vendor_rows} = $count;
+ IC->assembly_item( \%myconfig, \%$form );
+
+ $rows = scalar @{ $form->{item_list} };
+
+ if ($rows) {
+ $form->{"adj_$i"} = 1;
+
+ if ( $rows > 1 ) {
+ $form->{makemodel_rows}--;
+ $form->{customer_rows}--;
+ &select_item;
+ exit;
+ }
+ else {
+ $form->{"qty_$i"} = 1;
+ $form->{"adj_$i"} = 1;
+ for (qw(partnumber description unit)) {
+ $form->{item_list}[$i]{$_} =
+ $form->quote( $form->{item_list}[$i]{$_} );
+ }
+ for ( keys %{ $form->{item_list}[0] } ) {
+ $form->{"${_}_$i"} = $form->{item_list}[0]{$_};
+ }
+
+ if ( $form->{item_list}[0]{partsgroup_id} ) {
+ $form->{"partsgroup_$i"} =
+qq|$form->{item_list}[0]{partsgroup}--$form->{item_list}[0]{partsgroup_id}|;
+ }
+
+ $form->{"runningnumber_$i"} = $form->{assembly_rows};
+ $form->{assembly_rows}++;
+
+ &check_form;
+
+ }
+
+ }
+ else {
+
+ $form->{rowcount} = $i;
+ $form->{assembly_rows}++;
+
+ &new_item;
+
+ }
+ }
+
+ }
+ else {
+
+ &check_form;
+
+ }
}
+sub check_vendor {
+
+ @flds = qw(vendor partnumber lastcost leadtime vendorcurr);
+ @a = ();
+ $count = 0;
+
+ for (qw(lastcost leadtime)) {
+ $form->{"${_}_$form->{vendor_rows}"} =
+ $form->parse_amount( \%myconfig,
+ $form->{"${_}_$form->{vendor_rows}"} );
+ }
+
+ for $i ( 1 .. $form->{vendor_rows} - 1 ) {
+
+ for (qw(lastcost leadtime)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ if ( $form->{"lastcost_$i"} || $form->{"partnumber_$i"} ) {
+
+ push @a, {};
+ $j = $#a;
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+
+ }
+ }
+
+ $i = $form->{vendor_rows};
+
+ if ( !$form->{selectvendor} ) {
+
+ if ( $form->{"vendor_$i"} && !$form->{"vendor_id_$i"} ) {
+ ( $form->{vendor} ) = split /--/, $form->{"vendor_$i"};
+ if ( ( $j = $form->get_name( \%myconfig, vendor ) ) > 1 ) {
+ &select_name( vendor, $i );
+ exit;
+ }
+
+ if ( $j == 1 ) {
+
+ # we got one name
+ $form->{"vendor_$i"} =
+qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|;
+ }
+ else {
+
+ # name is not on file
+ $form->error(
+ $locale->text(
+ '[_1]: Vendor not on file!',
+ $form->{"vendor_$i"}
+ )
+ );
+ }
+ }
+ }
+
+ if ( $form->{"vendor_$i"} ) {
+ push @a, {};
+ $j = $#a;
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
+
+ $form->redo_rows( \@flds, \@a, $count, $form->{vendor_rows} );
+ $form->{vendor_rows} = $count;
+
+}
sub check_customer {
-
- @flds = qw(customer validfrom validto pricebreak customerprice pricegroup customercurr);
- @a = ();
- $count = 0;
- for (qw(customerprice pricebreak)) { $form->{"${_}_$form->{customer_rows}"} = $form->parse_amount(\%myconfig, $form->{"${_}_$form->{customer_rows}"}) }
+ @flds =
+ qw(customer validfrom validto pricebreak customerprice pricegroup customercurr);
+ @a = ();
+ $count = 0;
- for $i (1 .. $form->{customer_rows} - 1) {
+ for (qw(customerprice pricebreak)) {
+ $form->{"${_}_$form->{customer_rows}"} =
+ $form->parse_amount( \%myconfig,
+ $form->{"${_}_$form->{customer_rows}"} );
+ }
+
+ for $i ( 1 .. $form->{customer_rows} - 1 ) {
+
+ for (qw(customerprice pricebreak)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ if ( $form->{"customerprice_$i"} ) {
+ if ( $form->{"pricebreak_$i"}
+ || $form->{"customer_$i"}
+ || $form->{"pricegroup_$i"} )
+ {
+
+ push @a, {};
+ $j = $#a;
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
- for (qw(customerprice pricebreak)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- if ($form->{"customerprice_$i"}) {
- if ($form->{"pricebreak_$i"} || $form->{"customer_$i"} || $form->{"pricegroup_$i"}) {
-
- push @a, {};
- $j = $#a;
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
-
- }
+ }
+ }
}
- }
- $i = $form->{customer_rows};
+ $i = $form->{customer_rows};
- if (!$form->{selectcustomer}) {
+ if ( !$form->{selectcustomer} ) {
- if ($form->{"customer_$i"} && !$form->{"customer_id_$i"}) {
- ($form->{customer}) = split /--/, $form->{"customer_$i"};
+ if ( $form->{"customer_$i"} && !$form->{"customer_id_$i"} ) {
+ ( $form->{customer} ) = split /--/, $form->{"customer_$i"};
- if (($j = $form->get_name(\%myconfig, customer)) > 1) {
- &select_name(customer, $i);
- exit;
- }
+ if ( ( $j = $form->get_name( \%myconfig, customer ) ) > 1 ) {
+ &select_name( customer, $i );
+ exit;
+ }
- if ($j == 1) {
- # we got one name
- $form->{"customer_$i"} = qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|;
- } else {
- # name is not on file
- $form->error($locale->text('[_1]: Customer not on file!', $form->{customer}));
- }
+ if ( $j == 1 ) {
+
+ # we got one name
+ $form->{"customer_$i"} =
+qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|;
+ }
+ else {
+
+ # name is not on file
+ $form->error(
+ $locale->text(
+ '[_1]: Customer not on file!',
+ $form->{customer}
+ )
+ );
+ }
+ }
}
- }
- if ($form->{"customer_$i"} || $form->{"pricegroup_$i"} || ($form->{"customerprice_$i"} || $form->{"pricebreak_$i"})) {
- push @a, {};
- $j = $#a;
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
- }
+ if ( $form->{"customer_$i"}
+ || $form->{"pricegroup_$i"}
+ || ( $form->{"customerprice_$i"} || $form->{"pricebreak_$i"} ) )
+ {
+ push @a, {};
+ $j = $#a;
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
- $form->redo_rows(\@flds, \@a, $count, $form->{customer_rows});
- $form->{customer_rows} = $count;
+ $form->redo_rows( \@flds, \@a, $count, $form->{customer_rows} );
+ $form->{customer_rows} = $count;
}
+sub select_name {
+ my ( $table, $vr ) = @_;
+ @column_index = qw(ndx name address);
-sub select_name {
- my ($table, $vr) = @_;
-
- @column_index = qw(ndx name address);
+ $label = ucfirst $table;
+ $column_data{ndx} = qq|<th>&nbsp;</th>|;
+ $column_data{name} =
+ qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
+ $column_data{address} =
+ qq|<th class=listheading colspan=5>|
+ . $locale->text('Address')
+ . qq|</th>|;
- $label = ucfirst $table;
- $column_data{ndx} = qq|<th>&nbsp;</th>|;
- $column_data{name} = qq|<th class=listheading>|.$locale->text($label).qq|</th>|;
- $column_data{address} = qq|<th class=listheading colspan=5>|.$locale->text('Address').qq|</th>|;
-
- # list items with radio button on a form
- $form->header;
+ # list items with radio button on a form
+ $form->header;
- $title = $locale->text('Select from one of the names below');
+ $title = $locale->text('Select from one of the names below');
- print qq|
+ print qq|
<body>
<form method=post action="$form->{script}">
@@ -2794,41 +3421,46 @@ sub select_name {
<table width=100%>
<tr class=listheading>|;
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
</tr>
|;
- @column_index = qw(ndx name address city state zipcode country);
-
- my $i = 0;
- foreach $ref (@{ $form->{name_list} }) {
- $checked = ($i++) ? "" : "checked";
-
- $ref->{name} = $form->quote($ref->{name});
-
- $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
- $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
- $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}|;
- for (qw(city state zipcode country)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
-
- $j++; $j %= 2;
- print qq|
+ @column_index = qw(ndx name address city state zipcode country);
+
+ my $i = 0;
+ foreach $ref ( @{ $form->{name_list} } ) {
+ $checked = ( $i++ ) ? "" : "checked";
+
+ $ref->{name} = $form->quote( $ref->{name} );
+
+ $column_data{ndx} =
+qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
+ $column_data{name} =
+qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
+ $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}|;
+ for (qw(city state zipcode country)) {
+ $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>|;
+ }
+
+ $j++;
+ $j %= 2;
+ print qq|
<tr class=listrow$j>|;
- for (@column_index) { print "\n$column_data{$_}" }
+ for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ print qq|
</tr>
<input name="new_id_$i" type=hidden value=$ref->{id}>
|;
- }
-
- print qq|
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -2841,16 +3473,18 @@ sub select_name {
|;
- # delete variables
- for (qw(action nextsub name_list)) { delete $form->{$_} }
+ # delete variables
+ for (qw(action nextsub name_list)) { delete $form->{$_} }
- $form->hide_form;
-
- print qq|
+ $form->hide_form;
+
+ print qq|
<input type=hidden name=nextsub value=name_selected>
<input type=hidden name=vc value=$table>
<br>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
</body>
@@ -2859,198 +3493,225 @@ sub select_name {
}
+sub name_selected {
+ # replace the variable with the one checked
-sub name_selected {
+ # index for new item
+ $i = $form->{ndx};
- # replace the variable with the one checked
+ $form->{"$form->{vc}_$form->{vr}"} =
+ qq|$form->{"new_name_$i"}--$form->{"new_id_$i"}|;
+ $form->{"$form->{vc}_id_$form->{vr}"} = $form->{"new_id_$i"};
- # index for new item
- $i = $form->{ndx};
-
- $form->{"$form->{vc}_$form->{vr}"} = qq|$form->{"new_name_$i"}--$form->{"new_id_$i"}|;
- $form->{"$form->{vc}_id_$form->{vr}"} = $form->{"new_id_$i"};
+ # delete all the new_ variables
+ for $i ( 1 .. $form->{lastndx} ) {
+ for (qw(id name)) { delete $form->{"new_${_}_$i"} }
+ }
- # delete all the new_ variables
- for $i (1 .. $form->{lastndx}) {
- for (qw(id name)) { delete $form->{"new_${_}_$i"} }
- }
-
- for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
+ for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
- &update;
+ &update;
}
-
sub save {
- if ($form->{obsolete}) {
- $form->error($locale->text("Inventory quantity must be zero before you can set this $form->{item} obsolete!")) if ($form->{onhand});
- }
+ if ( $form->{obsolete} ) {
+ $form->error(
+ $locale->text(
+"Inventory quantity must be zero before you can set this $form->{item} obsolete!"
+ )
+ ) if ( $form->{onhand} );
+ }
# expand dynamic strings
# $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
# $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
- $olditem = $form->{id};
-
- # save part
- $rc = IC->save(\%myconfig, \%$form);
-
- $parts_id = $form->{id};
-
- # load previous variables
- if ($form->{previousform} && !$form->{callback}) {
- # save the new form variables before splitting previousform
- for (keys %$form) { $newform{$_} = $form->{$_} }
-
- $previousform = $form->unescape($form->{previousform});
- $baseassembly = $form->{baseassembly};
-
- # don't trample on previous variables
- for (keys %newform) { delete $form->{$_} if $_ ne 'dbh'}
-
- # now take it apart and restore original values
- foreach $item (split /&/, $previousform) {
- ($key, $value) = split /=/, $item, 2;
- $value =~ s/%26/&/g;
- $form->{$key} = $value if $key ne 'dbh';
- }
-
-
- if ($form->{item} eq 'assembly') {
-
- if ($baseassembly) {
- #redo the assembly
- $previousform =~ /\&id=(\d+)/;
- $form->{id} = $1;
-
- # restore original callback
- $form->{callback} = $form->unescape($form->{old_callback});
-
- &edit;
- exit;
- }
-
- # undo number formatting
- for (qw(weight listprice sellprice lastcost rop)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-
- $form->{assembly_rows}-- if $olditem;
- $i = $newform{rowcount};
- $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
-
- $form->{listprice} -= $form->{"listprice_$i"} * $form->{"qty_$i"};
- $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
- $form->{lastcost} -= $form->{"lastcost_$i"} * $form->{"qty_$i"};
- $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
-
- # change/add values for assembly item
- for (qw(partnumber description bin unit weight listprice sellprice lastcost)) { $form->{"${_}_$i"} = $newform{$_} }
-
- foreach $item (qw(listprice sellprice lastcost)) {
- $form->{$item} += $form->{"${item}_$i"} * $form->{"qty_$i"};
- $form->{$item} = $form->round_amount($form->{$item}, 2);
- }
-
- $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
-
- $form->{"adj_$i"} = 1 if !$olditem;
-
- $form->{customer_rows}--;
-
- } else {
- # set values for last invoice/order item
- $i = $form->{rowcount};
- $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
-
- for (qw(partnumber description bin unit listprice sellprice partsgroup)) { $form->{"${_}_$i"} = $newform{$_} }
- for (qw(inventory income expense)) {
- $form->{"${_}_accno_id_$i"} = $newform{"IC_$_"};
- $form->{"${_}_accno_id_$i"} =~ s/--.*//;
- }
- $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
-
- if ($form->{exchangerate} != 0) {
- $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"} / $form->{exchangerate}, 2);
- }
-
- for (split / /, $newform{taxaccounts}) { $form->{"taxaccounts_$i"} .= "$_ " if ($newform{"IC_tax_$_"}) }
- chop $form->{"taxaccounts_$i"};
-
- # credit remaining calculation
- $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);
- }
-
- $ml = 1;
- if ($form->{type} =~ /invoice/) {
- $ml = -1 if $form->{type} =~ /_invoice/;
- }
- $form->{creditremaining} -= ($amount * $ml);
-
- }
-
- $form->{"id_$i"} = $parts_id;
- delete $form->{action};
-
- # restore original callback
- $callback = $form->unescape($form->{callback});
- $form->{callback} = $form->unescape($form->{old_callback});
- delete $form->{old_callback};
-
- $form->{makemodel_rows}--;
-
- # put callback together
- foreach $key (keys %$form) {
- # do single escape for Apache 2.0
- $value = $form->escape($form->{$key}, 1);
- $callback .= qq|&$key=$value|;
+ $olditem = $form->{id};
+
+ # save part
+ $rc = IC->save( \%myconfig, \%$form );
+
+ $parts_id = $form->{id};
+
+ # load previous variables
+ if ( $form->{previousform} && !$form->{callback} ) {
+
+ # save the new form variables before splitting previousform
+ for ( keys %$form ) { $newform{$_} = $form->{$_} }
+
+ $previousform = $form->unescape( $form->{previousform} );
+ $baseassembly = $form->{baseassembly};
+
+ # don't trample on previous variables
+ for ( keys %newform ) { delete $form->{$_} if $_ ne 'dbh' }
+
+ # now take it apart and restore original values
+ foreach $item ( split /&/, $previousform ) {
+ ( $key, $value ) = split /=/, $item, 2;
+ $value =~ s/%26/&/g;
+ $form->{$key} = $value if $key ne 'dbh';
+ }
+
+ if ( $form->{item} eq 'assembly' ) {
+
+ if ($baseassembly) {
+
+ #redo the assembly
+ $previousform =~ /\&id=(\d+)/;
+ $form->{id} = $1;
+
+ # restore original callback
+ $form->{callback} = $form->unescape( $form->{old_callback} );
+
+ &edit;
+ exit;
+ }
+
+ # undo number formatting
+ for (qw(weight listprice sellprice lastcost rop)) {
+ $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} );
+ }
+
+ $form->{assembly_rows}-- if $olditem;
+ $i = $newform{rowcount};
+ $form->{"qty_$i"} = 1 unless ( $form->{"qty_$i"} );
+
+ $form->{listprice} -= $form->{"listprice_$i"} * $form->{"qty_$i"};
+ $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
+ $form->{lastcost} -= $form->{"lastcost_$i"} * $form->{"qty_$i"};
+ $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
+
+ # change/add values for assembly item
+ for (
+ qw(partnumber description bin unit weight listprice sellprice lastcost)
+ )
+ {
+ $form->{"${_}_$i"} = $newform{$_};
+ }
+
+ foreach $item (qw(listprice sellprice lastcost)) {
+ $form->{$item} += $form->{"${item}_$i"} * $form->{"qty_$i"};
+ $form->{$item} = $form->round_amount( $form->{$item}, 2 );
+ }
+
+ $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
+
+ $form->{"adj_$i"} = 1 if !$olditem;
+
+ $form->{customer_rows}--;
+
+ }
+ else {
+
+ # set values for last invoice/order item
+ $i = $form->{rowcount};
+ $form->{"qty_$i"} = 1 unless ( $form->{"qty_$i"} );
+
+ for (
+ qw(partnumber description bin unit listprice sellprice partsgroup)
+ )
+ {
+ $form->{"${_}_$i"} = $newform{$_};
+ }
+ for (qw(inventory income expense)) {
+ $form->{"${_}_accno_id_$i"} = $newform{"IC_$_"};
+ $form->{"${_}_accno_id_$i"} =~ s/--.*//;
+ }
+ $form->{"sellprice_$i"} = $newform{lastcost}
+ if ( $form->{vendor_id} );
+
+ if ( $form->{exchangerate} != 0 ) {
+ $form->{"sellprice_$i"} =
+ $form->round_amount(
+ $form->{"sellprice_$i"} / $form->{exchangerate}, 2 );
+ }
+
+ for ( split / /, $newform{taxaccounts} ) {
+ $form->{"taxaccounts_$i"} .= "$_ " if ( $newform{"IC_tax_$_"} );
+ }
+ chop $form->{"taxaccounts_$i"};
+
+ # credit remaining calculation
+ $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 );
+ }
+
+ $ml = 1;
+ if ( $form->{type} =~ /invoice/ ) {
+ $ml = -1 if $form->{type} =~ /_invoice/;
+ }
+ $form->{creditremaining} -= ( $amount * $ml );
+
+ }
+
+ $form->{"id_$i"} = $parts_id;
+ delete $form->{action};
+
+ # restore original callback
+ $callback = $form->unescape( $form->{callback} );
+ $form->{callback} = $form->unescape( $form->{old_callback} );
+ delete $form->{old_callback};
+
+ $form->{makemodel_rows}--;
+
+ # put callback together
+ foreach $key ( keys %$form ) {
+
+ # do single escape for Apache 2.0
+ $value = $form->escape( $form->{$key}, 1 );
+ $callback .= qq|&$key=$value|;
+ }
+ $form->{callback} = $callback;
}
- $form->{callback} = $callback;
- }
- if ($rc){
- # redirect
- $form->redirect("Part Saved");
- } else {
- $form->error;
- }
+ if ($rc) {
-}
+ # redirect
+ $form->redirect("Part Saved");
+ }
+ else {
+ $form->error;
+ }
+}
sub save_as_new {
- $form->{id} = 0;
- &save;
+ $form->{id} = 0;
+ &save;
}
-
sub delete {
- # redirect
- if (IC->delete(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Item deleted!'));
- } else {
- $form->error($locale->text('Cannot delete item!'));
- }
+ # redirect
+ if ( IC->delete( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Item deleted!') );
+ }
+ else {
+ $form->error( $locale->text('Cannot delete item!') );
+ }
}
+sub stock_assembly {
+ $form->{title} = $locale->text('Stock Assembly');
-sub stock_assembly {
+ $form->header;
- $form->{title} = $locale->text('Stock Assembly');
-
- $form->header;
-
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -3064,17 +3725,21 @@ sub stock_assembly {
<td>
<table>
<tr>
- <th align="right" nowrap="true">|.$locale->text('Number').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Number') . qq|</th>
<td><input name=partnumber size=20></td>
<td>&nbsp;</td>
</tr>
<tr>
- <th align="right" nowrap="true">|.$locale->text('Description').qq|</th>
+ <th align="right" nowrap="true">|
+ . $locale->text('Description')
+ . qq|</th>
<td><input name=description size=40></td>
</tr>
<tr>
<td></td>
- <td><input name=checkinventory class=checkbox type=checkbox value=1>&nbsp;|.$locale->text('Check Inventory').qq|</td>
+ <td><input name=checkinventory class=checkbox type=checkbox value=1>&nbsp;|
+ . $locale->text('Check Inventory')
+ . qq|</td>
</tr>
</table>
</td>
@@ -3085,22 +3750,24 @@ sub stock_assembly {
<input type=hidden name=sort value=partnumber>
|;
- $form->hide_form(qw(path login sessionid));
+ $form->hide_form(qw(path login sessionid));
- print qq|
+ print qq|
<input type="hidden" name="nextsub" value="list_assemblies">
<br>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</body>
</html>
@@ -3108,45 +3775,55 @@ sub stock_assembly {
}
+sub list_assemblies {
+ IC->retrieve_assemblies( \%myconfig, \%$form );
+ $callback =
+"$form->{script}?action=list_assemblies&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&checkinventory=$form->{checkinventory}";
-sub list_assemblies {
-
- IC->retrieve_assemblies(\%myconfig, \%$form);
+ $form->sort_order();
+ $href =
+"$form->{script}?action=list_assemblies&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&checkinventory=$form->{checkinventory}";
- $callback = "$form->{script}?action=list_assemblies&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&checkinventory=$form->{checkinventory}";
-
- $form->sort_order();
- $href = "$form->{script}?action=list_assemblies&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&checkinventory=$form->{checkinventory}";
-
- if ($form->{partnumber}) {
- $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
- $href .= "&partnumber=".$form->escape($form->{partnumber});
- $form->{sort} = "partnumber" unless $form->{sort};
- }
- if ($form->{description}) {
- $callback .= "&description=".$form->escape($form->{description},1);
- $href .= "&description=".$form->escape($form->{description});
- $form->{sort} = "description" unless $form->{sort};
- }
-
- $column_header{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</th>|;
- $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</th>|;
- $column_header{bin} = qq|<th><a class=listheading href=$href&sort=bin>|.$locale->text('Bin').qq|</th>|;
- $column_header{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
- $column_header{rop} = qq|<th class=listheading>|.$locale->text('ROP').qq|</th>|;
- $column_header{stock} = qq|<th class=listheading>|.$locale->text('Add').qq|</th>|;
-
- @column_index = $form->sort_columns(qw(partnumber description bin onhand rop stock));
-
- $form->{title} = $locale->text('Stock Assembly');
+ if ( $form->{partnumber} ) {
+ $callback .= "&partnumber=" . $form->escape( $form->{partnumber}, 1 );
+ $href .= "&partnumber=" . $form->escape( $form->{partnumber} );
+ $form->{sort} = "partnumber" unless $form->{sort};
+ }
+ if ( $form->{description} ) {
+ $callback .= "&description=" . $form->escape( $form->{description}, 1 );
+ $href .= "&description=" . $form->escape( $form->{description} );
+ $form->{sort} = "description" unless $form->{sort};
+ }
-
- $form->header;
-
+ $column_header{partnumber} =
+ qq|<th><a class=listheading href=$href&sort=partnumber>|
+ . $locale->text('Number')
+ . qq|</th>|;
+ $column_header{description} =
+ qq|<th><a class=listheading href=$href&sort=description>|
+ . $locale->text('Description')
+ . qq|</th>|;
+ $column_header{bin} =
+ qq|<th><a class=listheading href=$href&sort=bin>|
+ . $locale->text('Bin')
+ . qq|</th>|;
+ $column_header{onhand} =
+ qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
+ $column_header{rop} =
+ qq|<th class=listheading>| . $locale->text('ROP') . qq|</th>|;
+ $column_header{stock} =
+ qq|<th class=listheading>| . $locale->text('Add') . qq|</th>|;
+
+ @column_index =
+ $form->sort_columns(qw(partnumber description bin onhand rop stock));
+
+ $form->{title} = $locale->text('Stock Assembly');
+
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -3162,48 +3839,62 @@ sub list_assemblies {
<tr class=listheading>
|;
- for (@column_index) { print "\n$column_header{$_}" }
+ for (@column_index) { print "\n$column_header{$_}" }
- print qq|
+ print qq|
</tr>
|;
- # add sort and escape callback
- $form->{callback} = $callback .= "&sort=$form->{sort}";
-
- # escape callback for href
- $callback = $form->escape($callback);
-
+ # add sort and escape callback
+ $form->{callback} = $callback .= "&sort=$form->{sort}";
+
+ # escape callback for href
+ $callback = $form->escape($callback);
+
+ $i = 1;
+ foreach $ref ( @{ $form->{assembly_items} } ) {
+
+ for (qw(partnumber description)) {
+ $ref->{$_} = $form->quote( $ref->{$_} );
+ }
+
+ $column_data{partnumber} =
+"<td width=20%><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
+
+ $column_data{description} =
+ qq|<td width=50%>$ref->{description}&nbsp;</td>|;
+ $column_data{bin} = qq|<td>$ref->{bin}&nbsp;</td>|;
+ $column_data{onhand} =
+ qq|<td align=right>|
+ . $form->format_amount( \%myconfig, $ref->{onhand}, "", "&nbsp;" )
+ . qq|</td>|;
+ $column_data{rop} =
+ qq|<td align=right>|
+ . $form->format_amount( \%myconfig, $ref->{rop}, '', "&nbsp;" )
+ . qq|</td>|;
+ $column_data{stock} =
+ qq|<td width=10%><input name="qty_$i" size=10 value=|
+ . $form->format_amount( \%myconfig, $ref->{stock} )
+ . qq|></td>
+ <input type=hidden name="stock_$i" value=$ref->{stock}>|;
- $i = 1;
- foreach $ref (@{ $form->{assembly_items} }) {
+ $j++;
+ $j %= 2;
+ print
+qq|<tr class=listrow$j><input name="id_$i" type=hidden value=$ref->{id}>\n|;
- for (qw(partnumber description)) { $ref->{$_} = $form->quote($ref->{$_}) }
-
- $column_data{partnumber} = "<td width=20%><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
-
- $column_data{description} = qq|<td width=50%>$ref->{description}&nbsp;</td>|;
- $column_data{bin} = qq|<td>$ref->{bin}&nbsp;</td>|;
- $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, "", "&nbsp;").qq|</td>|;
- $column_data{rop} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{rop}, '', "&nbsp;").qq|</td>|;
- $column_data{stock} = qq|<td width=10%><input name="qty_$i" size=10 value=|.$form->format_amount(\%myconfig, $ref->{stock}).qq|></td>
- <input type=hidden name="stock_$i" value=$ref->{stock}>|;
+ for (@column_index) { print "\n$column_data{$_}" }
- $j++; $j %= 2;
- print qq|<tr class=listrow$j><input name="id_$i" type=hidden value=$ref->{id}>\n|;
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
+ print qq|
</tr>
|;
- $i++;
+ $i++;
- }
-
- $i--;
- print qq|
+ }
+
+ $i--;
+ print qq|
</td>
</table>
<tr>
@@ -3212,49 +3903,53 @@ sub list_assemblies {
</table>
|;
- $form->hide_form(qw(checkinventory path login sessionid callback));
+ $form->hide_form(qw(checkinventory path login sessionid callback));
- print qq|
+ print qq|
<input type="hidden" name="rowcount" value="$i">
<input type="hidden" name="nextsub" value="restock_assemblies">
<br>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
</body>
</html>
|;
-
-}
+}
sub restock_assemblies {
-
- if ($form->{checkinventory}) {
- for (1 .. $form->{rowcount}) { $form->error($locale->text('Quantity exceeds available units to stock!')) if $form->parse_amount($myconfig, $form->{"qty_$_"}) > $form->{"stock_$_"} }
- }
-
- if (IC->restock_assemblies(\%myconfig, \%$form)) {
- if ($form->{callback} =~ /(direction=)(.*?)\&/) {
- $direction = ($2 eq 'ASC') ? 'DESC' : 'ASC';
+ if ( $form->{checkinventory} ) {
+ for ( 1 .. $form->{rowcount} ) {
+ $form->error(
+ $locale->text('Quantity exceeds available units to stock!') )
+ if $form->parse_amount( $myconfig, $form->{"qty_$_"} ) >
+ $form->{"stock_$_"};
+ }
}
- $form->{callback} =~ s/direction=(.*?)\&/direction=$direction\&/;
- $form->redirect($locale->text('Assemblies restocked!'));
- } else {
- $form->error($locale->text('Cannot stock assemblies!'));
- }
-
-}
+ if ( IC->restock_assemblies( \%myconfig, \%$form ) ) {
+ if ( $form->{callback} =~ /(direction=)(.*?)\&/ ) {
+ $direction = ( $2 eq 'ASC' ) ? 'DESC' : 'ASC';
+ }
+ $form->{callback} =~ s/direction=(.*?)\&/direction=$direction\&/;
+ $form->redirect( $locale->text('Assemblies restocked!') );
+ }
+ else {
+ $form->error( $locale->text('Cannot stock assemblies!') );
+ }
-sub continue { &{ $form->{nextsub} } };
+}
-sub add_part { &add };
-sub add_service { &add };
-sub add_assembly { &add };
-sub add_labor_overhead { &add };
+sub continue { &{ $form->{nextsub} } }
+sub add_part { &add }
+sub add_service { &add }
+sub add_assembly { &add }
+sub add_labor_overhead { &add }
diff --git a/bin/io.pl b/bin/io.pl
index 16e6f1c3..48c2caa0 100644
--- a/bin/io.pl
+++ b/bin/io.pl
@@ -1,1724 +1,1971 @@
-######################################################################
-# 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 Error qw(:try);
-
-use LedgerSMB::Tax;
-use LedgerSMB::Template;
-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 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->{"sellprice_$i"} = $form->{"new_sellprice_$j"} unless $form->{"sellprice_$i"};
-
- $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 sellprice unit)) { $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=6>|.$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>
-
- </tr>
- <tr>
- <td colspan=6>|.$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;
-
- if (($form->{'media'} eq 'screen') and ($form->{'format'} eq 'html')) {
- my $template = LedgerSMB::Template->new(\%myconfig, $form->{'formname'}, 'HTML');
- try {
- $template->render($form);
- $form->header;
- print $template->{'output'};
- exit;
- } catch Error::Simple with {
- my $E = shift;
- $form->error($E->stacktrace);
- };
- }
-
- $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 Error qw(:try);
+
+use LedgerSMB::Tax;
+use LedgerSMB::Template;
+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 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->{"sellprice_$i"} = $form->{"new_sellprice_$j"}
+ unless $form->{"sellprice_$i"};
+
+ $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 sellprice unit)) {
+ $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=6>| . $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>
+
+ </tr>
+ <tr>
+ <td colspan=6>| . $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;
+
+ if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
+ {
+ my $template =
+ LedgerSMB::Template->new( \%myconfig, $form->{'formname'}, 'HTML' );
+ try {
+ $template->render($form);
+ $form->header;
+ print $template->{'output'};
+ exit;
+ }
+ catch Error::Simple with {
+ my $E = shift;
+ $form->error( $E->stacktrace );
+ };
+ }
+
+ $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/ir.pl b/bin/ir.pl
index f05fb764..87866777 100644
--- a/bin/ir.pl
+++ b/bin/ir.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -38,7 +38,6 @@
#
#======================================================================
-
use LedgerSMB::IR;
use LedgerSMB::PE;
use LedgerSMB::Tax;
@@ -47,277 +46,331 @@ require "bin/io.pl";
require "bin/arap.pl";
1;
-# end of main
-
+# end of main
sub add {
- $form->{title} = $locale->text('Add Vendor Invoice');
+ $form->{title} = $locale->text('Add Vendor Invoice');
- $form->{callback} = "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}" unless $form->{callback};
- &invoice_links;
- &prepare_invoice;
- &display_form;
-
-}
+ $form->{callback} =
+"$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
+ &invoice_links;
+ &prepare_invoice;
+ &display_form;
+}
sub edit {
- $form->{title} = $locale->text('Edit Vendor Invoice');
+ $form->{title} = $locale->text('Edit Vendor Invoice');
- &invoice_links;
- &prepare_invoice;
- &display_form;
-
-}
+ &invoice_links;
+ &prepare_invoice;
+ &display_form;
+}
sub invoice_links {
-
- $form->{vc} = "vendor";
- $form->{type} = "invoice";
-
- # create links
- $form->create_links("AP", \%myconfig, "vendor", 1);
-
- # currencies
- @curr = split /:/, $form->{currencies};
- $form->{defaultcurrency} = $curr[0];
- chomp $form->{defaultcurrency};
-
- for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
-
- if (@{ $form->{all_vendor} }) {
- unless ($form->{vendor_id}) {
- $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
- }
- }
-
- AA->get_name(\%myconfig, \%$form);
- delete $form->{notes};
- IR->retrieve_invoice(\%myconfig, \%$form);
-
- $form->{oldlanguage_code} = $form->{language_code};
-
- $form->get_partsgroup(\%myconfig, { language_code => $form->{language_code} });
- 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|;
- }
- }
- }
-
- if (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} = "<option>\n";
- for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
- }
-
- $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
- $form->{oldtransdate} = $form->{transdate};
-
- # vendors
- $form->{selectvendor} = "";
- if (@{ $form->{all_vendor} }) {
- $form->{vendor} = "$form->{vendor}--$form->{vendor_id}";
- for (@{ $form->{all_vendor} }) { $form->{selectvendor} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
-
- # departments
- if (@{ $form->{all_department} }) {
- $form->{selectdepartment} = "<option>\n";
- $form->{department} = "$form->{department}--$form->{department_id}" if $form->{department_id};
-
- for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
- }
-
- if (@{ $form->{all_language} }) {
- $form->{selectlanguage} = "<option>\n";
- for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
- }
-
- # forex
- $form->{forex} = $form->{exchangerate};
- $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
-
- foreach $key (keys %{ $form->{AP_links} }) {
-
- $form->{"select$key"} = "";
- foreach $ref (@{ $form->{AP_links}{$key} }) {
- $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
- }
-
- if ($key eq "AP_paid") {
- for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
- $form->{"AP_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
- # reverse paid
- $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount};
- $form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};
- $form->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate};
- $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i-1]->{source};
- $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i-1]->{memo};
- $form->{"cleared_$i"} = $form->{acc_trans}{$key}->[$i-1]->{cleared};
-
- $form->{paidaccounts} = $i;
- }
- } else {
- $form->{$key} = "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}" if $form->{acc_trans}{$key}->[0]->{accno};
- }
-
- }
-
- $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
-
- $form->{AP} = $form->{AP_1} unless $form->{id};
-
- $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
-
- if (! $form->{readonly}) {
- $form->{readonly} = 1 if $myconfig{acs} =~ /AP--Vendor Invoice/;
- }
-
-}
+ $form->{vc} = "vendor";
+ $form->{type} = "invoice";
+ # create links
+ $form->create_links( "AP", \%myconfig, "vendor", 1 );
-sub prepare_invoice {
+ # currencies
+ @curr = split /:/, $form->{currencies};
+ $form->{defaultcurrency} = $curr[0];
+ chomp $form->{defaultcurrency};
- $form->{type} = "invoice";
- $form->{currency} =~ s/ //g;
- $form->{oldcurrency} = $form->{currency};
+ for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
- if ($form->{id}) {
-
- for (qw(invnumber ordnumber ponumber quonumber)) { $form->{$_} = $form->quote($form->{$_}) }
+ if ( @{ $form->{all_vendor} } ) {
+ unless ( $form->{vendor_id} ) {
+ $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
+ }
+ }
+
+ AA->get_name( \%myconfig, \%$form );
+ delete $form->{notes};
+ IR->retrieve_invoice( \%myconfig, \%$form );
+
+ $form->{oldlanguage_code} = $form->{language_code};
+
+ $form->get_partsgroup( \%myconfig,
+ { language_code => $form->{language_code} } );
+ 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|;
+ }
+ }
+ }
+
+ if ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} = "<option>\n";
+ for ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} .=
+qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
+ }
+ }
- foreach $ref (@{ $form->{invoice_details} }) {
- $i++;
- for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
+ $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
+ $form->{oldtransdate} = $form->{transdate};
- $form->{"projectnumber_$i"} = qq|$ref->{projectnumber}--$ref->{project_id}| if $ref->{project_id};
- $form->{"partsgroup_$i"} = qq|$ref->{partsgroup}--$ref->{partsgroup_id}| if $ref->{partsgroup_id};
+ # vendors
+ $form->{selectvendor} = "";
+ if ( @{ $form->{all_vendor} } ) {
+ $form->{vendor} = "$form->{vendor}--$form->{vendor_id}";
+ for ( @{ $form->{all_vendor} } ) {
+ $form->{selectvendor} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
- $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
-
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
-
- $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
- $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
- $form->{"oldqty_$i"} = $form->{"qty_$i"};
+ # departments
+ if ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} = "<option>\n";
+ $form->{department} = "$form->{department}--$form->{department_id}"
+ if $form->{department_id};
- for (qw(partnumber sku description unit)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
+ for ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+ }
- $form->{rowcount} = $i;
+ if ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} = "<option>\n";
+ for ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} .=
+ qq|<option value="$_->{code}">$_->{description}\n|;
+ }
}
- }
-
+
+ # forex
+ $form->{forex} = $form->{exchangerate};
+ $exchangerate = ( $form->{exchangerate} ) ? $form->{exchangerate} : 1;
+
+ foreach $key ( keys %{ $form->{AP_links} } ) {
+
+ $form->{"select$key"} = "";
+ foreach $ref ( @{ $form->{AP_links}{$key} } ) {
+ $form->{"select$key"} .=
+ "<option>$ref->{accno}--$ref->{description}\n";
+ }
+
+ if ( $key eq "AP_paid" ) {
+ for $i ( 1 .. scalar @{ $form->{acc_trans}{$key} } ) {
+ $form->{"AP_paid_$i"} =
+"$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
+
+ # reverse paid
+ $form->{"paid_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{amount};
+ $form->{"datepaid_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{transdate};
+ $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{exchangerate};
+ $form->{"source_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{source};
+ $form->{"memo_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{memo};
+ $form->{"cleared_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{cleared};
+
+ $form->{paidaccounts} = $i;
+ }
+ }
+ else {
+ $form->{$key} =
+"$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}"
+ if $form->{acc_trans}{$key}->[0]->{accno};
+ }
+
+ }
+
+ $form->{paidaccounts} = 1 unless ( exists $form->{paidaccounts} );
+
+ $form->{AP} = $form->{AP_1} unless $form->{id};
+
+ $form->{locked} =
+ ( $form->{revtrans} )
+ ? '1'
+ : ( $form->datetonum( \%myconfig, $form->{transdate} ) <=
+ $form->datetonum( \%myconfig, $form->{closedto} ) );
+
+ if ( !$form->{readonly} ) {
+ $form->{readonly} = 1 if $myconfig{acs} =~ /AP--Vendor Invoice/;
+ }
+
}
+sub prepare_invoice {
+
+ $form->{type} = "invoice";
+ $form->{currency} =~ s/ //g;
+ $form->{oldcurrency} = $form->{currency};
+
+ if ( $form->{id} ) {
+
+ for (qw(invnumber ordnumber ponumber quonumber)) {
+ $form->{$_} = $form->quote( $form->{$_} );
+ }
+
+ foreach $ref ( @{ $form->{invoice_details} } ) {
+ $i++;
+ for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
+
+ $form->{"projectnumber_$i"} =
+ qq|$ref->{projectnumber}--$ref->{project_id}|
+ if $ref->{project_id};
+ $form->{"partsgroup_$i"} =
+ qq|$ref->{partsgroup}--$ref->{partsgroup_id}|
+ if $ref->{partsgroup_id};
+
+ $form->{"discount_$i"} =
+ $form->format_amount( \%myconfig, $form->{"discount_$i"} * 100 );
+
+ ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ $form->{"sellprice_$i"} =
+ $form->format_amount( \%myconfig, $form->{"sellprice_$i"},
+ $decimalplaces );
+ $form->{"qty_$i"} =
+ $form->format_amount( \%myconfig, $form->{"qty_$i"} );
+ $form->{"oldqty_$i"} = $form->{"qty_$i"};
+
+ for (qw(partnumber sku description unit)) {
+ $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} );
+ }
+
+ $form->{rowcount} = $i;
+ }
+ }
+}
sub form_header {
- # set option selected
- for (qw(AP currency)) {
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
- }
-
- for (qw(vendor department)) {
- $form->{"select$_"} = $form->unescape($form->{"select$_"});
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 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|
+ # set option selected
+ for (qw(AP currency)) {
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~
+ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
+ }
+
+ for (qw(vendor department)) {
+ $form->{"select$_"} = $form->unescape( $form->{"select$_"} );
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 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|
<tr>
- <th align=right nowrap>|.$locale->text('Language').qq|</th>
+ <th align=right nowrap>| . $locale->text('Language') . qq|</th>
<td><select name=language_code>$form->{selectlanguage}</select></td>
<input type=hidden name=oldlanguage_code value=$form->{oldlanguage_code}>
- <input type=hidden name="selectlanguage" value="|.
- $form->escape($form->{selectlanguage},1).qq|">
+ <input type=hidden name="selectlanguage" value="|
+ . $form->escape( $form->{selectlanguage}, 1 ) . qq|">
</tr>
|;
- }
-
+ }
- $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
+ $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|
+ $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 nowrap>|.$locale->text('Exchange Rate').qq|</th>
+ if ( $form->{defaultcurrency}
+ && $form->{currency} ne $form->{defaultcurrency} )
+ {
+ if ( $form->{forex} ) {
+ $exchangerate .= qq|
+ <th align=right nowrap>|
+ . $locale->text('Exchange Rate')
+ . qq|</th>
<td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
|;
- } else {
- $exchangerate .= qq|
- <th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th>
+ }
+ else {
+ $exchangerate .= qq|
+ <th align=right nowrap>|
+ . $locale->text('Exchange Rate')
+ . qq|</th>
<td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
|;
+ }
}
- }
- $exchangerate .= qq|
+ $exchangerate .= qq|
<input type=hidden name=forex value=$form->{forex}>
</tr>
|;
-
- if ($form->{selectvendor}) {
- $vendor = qq|<select name=vendor>$form->{selectvendor}</select>
- <input type=hidden name="selectvendor" value="|.
- $form->escape($form->{selectvendor},1).qq|">|;
- } else {
- $vendor = qq|<input name=vendor value="$form->{vendor}" size=35>|;
- }
-
- $department = qq|
+
+ if ( $form->{selectvendor} ) {
+ $vendor = qq|<select name=vendor>$form->{selectvendor}</select>
+ <input type=hidden name="selectvendor" value="|
+ . $form->escape( $form->{selectvendor}, 1 ) . qq|">|;
+ }
+ else {
+ $vendor = qq|<input name=vendor value="$form->{vendor}" size=35>|;
+ }
+
+ $department = qq|
<tr>
- <th align="right" nowrap>|.$locale->text('Department').qq|</th>
+ <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|">
+ <input type=hidden name=selectdepartment value="|
+ . $form->escape( $form->{selectdepartment}, 1 ) . qq|">
</td>
</tr>
| if $form->{selectdepartment};
- $n = ($form->{creditremaining} < 0) ? "0" : "1";
+ $n = ( $form->{creditremaining} < 0 ) ? "0" : "1";
+
+ $i = $form->{rowcount} + 1;
+ $focus = "partnumber_$i";
- $i = $form->{rowcount} + 1;
- $focus = "partnumber_$i";
-
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body onLoad="document.forms[0].${focus}.focus()" />
<form method=post action="$form->{script}">
|;
- $form->{vc} = "vendor";
- $form->hide_form(qw(id title vc type terms creditlimit creditremaining closedto locked shipped oldtransdate recurring));
-
- print qq|
+ $form->{vc} = "vendor";
+ $form->hide_form(
+ qw(id title vc type terms creditlimit creditremaining closedto locked shipped oldtransdate recurring)
+ );
+
+ print qq|
<table width=100%>
<tr class=listtop>
<th>$form->{title}</th>
@@ -330,7 +383,7 @@ sub form_header {
<td>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Vendor').qq|</th>
+ <th align=right nowrap>| . $locale->text('Vendor') . qq|</th>
<td colspan=3>$vendor</td>
<input type=hidden name=vendor_id value=$form->{vendor_id}>
@@ -342,16 +395,20 @@ sub form_header {
<td colspan=3>
<table>
<tr>
- <th nowrap>|.$locale->text('Credit Limit').qq|</th>
- <td>|.$form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0").qq|</td>
+ <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
+ <td>|
+ . $form->format_amount( \%myconfig, $form->{creditlimit}, 0, "0" )
+ . qq|</td>
<td width=20%></td>
- <th nowrap>|.$locale->text('Remaining').qq|</th>
- <td class="plus$n" nowrap>|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</td>
+ <th nowrap>| . $locale->text('Remaining') . qq|</th>
+ <td class="plus$n" nowrap>|
+ . $form->format_amount( \%myconfig, $form->{creditremaining}, 0, "0" )
+ . qq|</td>
</tr>
</table>
</td>
<tr>
- <th align=right>|.$locale->text('Record in').qq|</th>
+ <th align=right>| . $locale->text('Record in') . qq|</th>
<td colspan=3><select name=AP>$form->{selectAP}</select></td>
<input type=hidden name=selectAP value="$form->{selectAP}">
</tr>
@@ -362,24 +419,24 @@ sub form_header {
<td align=right>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
<td><input name=invnumber size=20 value="$form->{invnumber}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
<td><input name=ordnumber size=20 value="$form->{ordnumber}"></td>
<input type=hidden name=quonumber value="$form->{quonumber}">
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Invoice Date').qq|</th>
+ <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
<td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Due Date').qq|</th>
+ <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
<td><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('PO Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('PO Number') . qq|</th>
<td><input name=ponumber size=20 value="$form->{ponumber}"></td>
</tr>
$lang
@@ -391,71 +448,79 @@ sub form_header {
</tr>
|;
- $form->hide_form(qw(selectcurrency defaultcurrency taxaccounts));
-
- for (split / /, $form->{taxaccounts}) { $form->hide_form("${_}_rate", "${_}_description") }
-
-}
+ $form->hide_form(qw(selectcurrency defaultcurrency taxaccounts));
+ for ( split / /, $form->{taxaccounts} ) {
+ $form->hide_form( "${_}_rate", "${_}_description" );
+ }
+}
sub form_footer {
- $form->{invtotal} = $form->{invsubtotal};
-
- if (($rows = $form->numtextrows($form->{notes}, 35, 8)) < 2) {
- $rows = 2;
- }
- if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
- $introws = 2;
- }
- $rows = ($rows > $introws) ? $rows : $introws;
- $notes = qq|<textarea name=notes rows=$rows cols=35 wrap=soft>$form->{notes}</textarea>|;
- $intnotes = qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
-
- $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
-
- $taxincluded = "";
- if ($form->{taxaccounts}) {
- $taxincluded = qq|
- <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|.$locale->text('Tax Included').qq|</b>
+ $form->{invtotal} = $form->{invsubtotal};
+
+ if ( ( $rows = $form->numtextrows( $form->{notes}, 35, 8 ) ) < 2 ) {
+ $rows = 2;
+ }
+ if ( ( $introws = $form->numtextrows( $form->{intnotes}, 35, 8 ) ) < 2 ) {
+ $introws = 2;
+ }
+ $rows = ( $rows > $introws ) ? $rows : $introws;
+ $notes =
+qq|<textarea name=notes rows=$rows cols=35 wrap=soft>$form->{notes}</textarea>|;
+ $intnotes =
+qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
+
+ $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
+
+ $taxincluded = "";
+ if ( $form->{taxaccounts} ) {
+ $taxincluded = qq|
+ <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
+ . $locale->text('Tax Included') . qq|</b>
|;
- }
-
- if (!$form->{taxincluded}) {
- my @taxset = Tax::init_taxes($form, $form->{taxaccounts});
- $form->{invtotal} += $form->round_amount(
- Tax::calculate_taxes(\@taxset, $form, $form->{invsubtotal}, 0), 2);
- foreach $taxobj (@taxset) {
- $item = $taxobj->account;
- if ($form->{"${item}_base"}) {
- $form->{"${item}_total"} = $form->format_amount(\%myconfig,
- $form->round_amount($taxobj->value, 2), 2);
-
- $tax .= qq|
+ }
+
+ if ( !$form->{taxincluded} ) {
+ my @taxset = Tax::init_taxes( $form, $form->{taxaccounts} );
+ $form->{invtotal} +=
+ $form->round_amount(
+ Tax::calculate_taxes( \@taxset, $form, $form->{invsubtotal}, 0 ),
+ 2 );
+ foreach $taxobj (@taxset) {
+ $item = $taxobj->account;
+ if ( $form->{"${item}_base"} ) {
+ $form->{"${item}_total"} =
+ $form->format_amount( \%myconfig,
+ $form->round_amount( $taxobj->value, 2 ), 2 );
+
+ $tax .= qq|
<tr>
<th align=right>$form->{"${item}_description"}</th>
<td align=right>$form->{"${item}_total"}</td>
</tr>
|;
- }
- }
+ }
+ }
+
+ $form->{invsubtotal} =
+ $form->format_amount( \%myconfig, $form->{invsubtotal}, 2, 0 );
- $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
-
- $subtotal = qq|
+ $subtotal = qq|
<tr>
- <th align=right>|.$locale->text('Subtotal').qq|</th>
+ <th align=right>| . $locale->text('Subtotal') . qq|</th>
<td align=right>$form->{invsubtotal}</td>
</tr>
|;
- }
+ }
- $form->{oldinvtotal} = $form->{invtotal};
- $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
+ $form->{oldinvtotal} = $form->{invtotal};
+ $form->{invtotal} =
+ $form->format_amount( \%myconfig, $form->{invtotal}, 2, 0 );
- print qq|
+ print qq|
<tr>
<td>
<table width=100%>
@@ -463,9 +528,9 @@ sub form_footer {
<td>
<table>
<tr>
- <th align=left>|.$locale->text('Notes').qq|</th>
- <th align=left>|.$locale->text('Internal Notes').qq|</th>
- <th align=left>|.$locale->text('Import Text').qq|</th>
+ <th align=left>| . $locale->text('Notes') . qq|</th>
+ <th align=left>| . $locale->text('Internal Notes') . qq|</th>
+ <th align=left>| . $locale->text('Import Text') . qq|</th>
</tr>
<tr valign=top>
<td>$notes</td>
@@ -481,7 +546,7 @@ sub form_footer {
$subtotal
$tax
<tr>
- <th align=right>|.$locale->text('Total').qq|</th>
+ <th align=right>| . $locale->text('Total') . qq|</th>
<td align=right>$form->{invtotal}</td>
</tr>
</table>
@@ -494,22 +559,23 @@ sub form_footer {
<td>
<table width=100%>
<tr>
- <th colspan=6 class=listheading>|.$locale->text('Payments').qq|</th>
+ <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
</tr>
|;
- if ($form->{currency} eq $form->{defaultcurrency}) {
- @column_index = qw(datepaid source memo paid AP_paid);
- } else {
- @column_index = qw(datepaid source memo paid exchangerate AP_paid);
+ if ( $form->{currency} eq $form->{defaultcurrency} ) {
+ @column_index = qw(datepaid source memo paid AP_paid);
+ }
+ else {
+ @column_index = qw(datepaid source memo paid exchangerate AP_paid);
}
- $column_data{datepaid} = "<th>".$locale->text('Date')."</th>";
- $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
- $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";
- $column_data{AP_paid} = "<th>".$locale->text('Account')."</th>";
- $column_data{source} = "<th>".$locale->text('Source')."</th>";
- $column_data{memo} = "<th>".$locale->text('Memo')."</th>";
+ $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
+ $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
+ $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
+ $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
+ $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
+ $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
print qq|
<tr>
@@ -519,52 +585,64 @@ sub form_footer {
</tr>
|;
- $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
- for $i (1 .. $form->{paidaccounts}) {
+ $form->{paidaccounts}++ if ( $form->{"paid_$form->{paidaccounts}"} );
+ for $i ( 1 .. $form->{paidaccounts} ) {
+
+ $form->hide_form("cleared_$i");
- $form->hide_form("cleared_$i");
-
- print qq|
+ print qq|
<tr>
|;
- $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
- $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_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"});
-
- $exchangerate = qq|&nbsp;|;
- if ($form->{currency} ne $form->{defaultcurrency}) {
- if ($form->{"forex_$i"}) {
- $exchangerate = qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
- } else {
- $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
- }
- }
- $exchangerate .= qq|
+ $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
+ $form->{"selectAP_paid_$i"} =~
+s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_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"} );
+
+ $exchangerate = qq|&nbsp;|;
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ if ( $form->{"forex_$i"} ) {
+ $exchangerate =
+qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
+ }
+ else {
+ $exchangerate =
+qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
+ }
+ }
+ $exchangerate .= qq|
<input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
|;
- $column_data{"paid_$i"} = qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
- $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
- $column_data{"AP_paid_$i"} = qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
- $column_data{"datepaid_$i"} = qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
- $column_data{"source_$i"} = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
- $column_data{"memo_$i"} = qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
-
- for (@column_index) { print qq|$column_data{"${_}_$i"}\n| }
-
- print qq|
+ $column_data{"paid_$i"} =
+qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
+ $column_data{"exchangerate_$i"} =
+ qq|<td align=center>$exchangerate</td>|;
+ $column_data{"AP_paid_$i"} =
+qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
+ $column_data{"datepaid_$i"} =
+qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
+ $column_data{"source_$i"} =
+qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
+ $column_data{"memo_$i"} =
+qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
+
+ for (@column_index) { print qq|$column_data{"${_}_$i"}\n| }
+
+ print qq|
</tr>
|;
}
$form->{oldtotalpaid} = $totalpaid;
$form->hide_form(qw(paidaccounts selectAP_paid oldinvtotal oldtotalpaid));
-
+
print qq|
</table>
</td>
@@ -576,51 +654,64 @@ sub form_footer {
<br>
|;
- $transdate = $form->datetonum(\%myconfig, $form->{transdate});
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
-
-# type=submit $locale->text('Update')
-# type=submit $locale->text('Post')
-# type=submit $locale->text('Post as new')
-# type=submit $locale->text('Schedule')
-# type=submit $locale->text('Purchase Order')
-# type=submit $locale->text('Delete')
-
- if (! $form->{readonly}) {
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- 'post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
- 'post_as_new' => { ndx => 5, key => 'N', value => $locale->text('Post as new') },
- 'purchase_order' => { ndx => 6, key => 'L', value => $locale->text('Purchase Order') },
- 'schedule' => { ndx => 7, key => 'H', value => $locale->text('Schedule') },
- 'delete' => { ndx => 8, key => 'D', value => $locale->text('Delete') },
- );
-
- if ($form->{id}) {
-
- if ($form->{locked}) {
- for ("post", "delete") { delete $button{$_} }
- }
-
- } else {
-
- if ($transdate > $closedto) {
- for ('update', 'post', 'schedule') { $a{$_} = 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(rowcount callback path login sessionid));
-
-print qq|
+ $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
+ $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
+
+ # type=submit $locale->text('Update')
+ # type=submit $locale->text('Post')
+ # type=submit $locale->text('Post as new')
+ # type=submit $locale->text('Schedule')
+ # type=submit $locale->text('Purchase Order')
+ # type=submit $locale->text('Delete')
+
+ if ( !$form->{readonly} ) {
+ %button = (
+ 'update' =>
+ { ndx => 1, key => 'U', value => $locale->text('Update') },
+ 'post' => { ndx => 3, key => 'O', value => $locale->text('Post') },
+ 'post_as_new' =>
+ { ndx => 5, key => 'N', value => $locale->text('Post as new') },
+ 'purchase_order' => {
+ ndx => 6,
+ key => 'L',
+ value => $locale->text('Purchase Order')
+ },
+ 'schedule' =>
+ { ndx => 7, key => 'H', value => $locale->text('Schedule') },
+ 'delete' =>
+ { ndx => 8, key => 'D', value => $locale->text('Delete') },
+ );
+
+ if ( $form->{id} ) {
+
+ if ( $form->{locked} ) {
+ for ( "post", "delete" ) { delete $button{$_} }
+ }
+
+ }
+ else {
+
+ if ( $transdate > $closedto ) {
+ for ( 'update', 'post', 'schedule' ) { $a{$_} = 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(rowcount callback path login sessionid));
+
+ print qq|
</form>
</body>
@@ -629,304 +720,395 @@ print qq|
}
-
sub import_text {
- my @o_list;
- my @i_lines = split(/(\n|\r|\r\n)/, $form->{import_text});
- foreach $i (@i_lines){
- chomp($i);
- if ($i ne ""){ # Strip out blank lines
- push @o_list, $i;
- }
- }
- my $c = 1;
- my $linenumber = 0;
- foreach $l (@o_list){
- if ($c % 2){
- $linenumber += 1;
- $form->{"partnumber_$linenumber"} = $l;
+ my @o_list;
+ my @i_lines = split( /(\n|\r|\r\n)/, $form->{import_text} );
+ foreach $i (@i_lines) {
+ chomp($i);
+ if ( $i ne "" ) { # Strip out blank lines
+ push @o_list, $i;
+ }
}
- else {
- $form->{"qty_$linenumber"} = $l;
+ my $c = 1;
+ my $linenumber = 0;
+ foreach $l (@o_list) {
+ if ( $c % 2 ) {
+ $linenumber += 1;
+ $form->{"partnumber_$linenumber"} = $l;
+ }
+ else {
+ $form->{"qty_$linenumber"} = $l;
+ }
+ $c += 1;
+ $form->{rowcount} = $linenumber;
+ IR->retrieve_item( \%myconfig, \%$form );
+ $rows = scalar @{ $form->{item_list} };
+ $rows = 0 unless $rows;
+ $i = $form->{rowcount};
+ if ( $rows = 0 ) {
+ $form->{"id_$i"} = 0;
+ $form->{"unit_$i"} = $locale->text('ea');
+
+ &new_item;
+ }
+ elsif ( $rows > 1 ) {
+ &select_item;
+ exit;
+ }
+ else {
+ map {
+ $form->{item_list}[$i]{$_} =
+ $form->quote( $form->{item_list}[$i]{$_} )
+ } qw(partnumber description unit);
+
+ map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
+ keys %{ $form->{item_list}[0] };
+
+ $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
+
+ ($dec) = ( $s =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ $amount =
+ $form->{"sellprice_$i"} * $form->{"qty_$i"} *
+ ( 1 - $form->{"discount_$i"} / 100 );
+ map { $form->{"${_}_base"} = 0 }
+ ( split / /, $form->{taxaccounts} );
+ map { $form->{"${_}_base"} += $amount }
+ ( split / /, $form->{"taxaccounts_$i"} );
+ if ( !$form->{taxincluded} ) {
+ my @taxes = Tax::init_taxes( $form, $form->{taxaccounts} );
+ $amount +=
+ ( Tax::calculate_taxes( \@taxes, $form, $amount, 0 ) );
+ }
+
+ $form->{creditremaining} -= $amount;
+
+ $form->{"sellprice_$i"} =
+ $form->format_amount( \%myconfig, $form->{"sellprice_$i"},
+ $decimalplaces );
+ $form->{"qty_$i"} =
+ $form->format_amount( \%myconfig, $form->{"qty_$i"} );
+
+ }
+ $form->{item_list} = [];
}
- $c += 1;
- $form->{rowcount}=$linenumber;
- IR->retrieve_item(\%myconfig, \%$form);
- $rows = scalar @{ $form->{item_list} };
- $rows = 0 unless $rows;
- $i = $form->{rowcount};
- if ($rows = 0){
- $form->{"id_$i"} = 0;
- $form->{"unit_$i"} = $locale->text('ea');
-
- &new_item;
- } elsif ($rows > 1){
- &select_item;
- exit;
- } else {
- map { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) } qw(partnumber description unit);
-
- map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
-
- $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
-
- ($dec) = ($s =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
-
- $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
- map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
- map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
- if (!$form->{taxincluded}) {
- my @taxes = Tax::init_taxes($form, $form->{taxaccounts});
- $amount += (Tax::calculate_taxes(\@taxes, $form, $amount, 0));
- }
-
- $form->{creditremaining} -= $amount;
-
- $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
- $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
-
- }
- $form->{item_list} = [];
- }
- ++$form->{rowcount}
+ ++$form->{rowcount};
}
sub update {
- if($form->{import_text}){
- &import_text;
- }
-
-
- $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
-
- if ($newname = &check_name(vendor)) {
- &rebuild_vc(vendor, AP, $form->{transdate}, 1);
- }
- if ($form->{transdate} ne $form->{oldtransdate}) {
- $form->{duedate} = ($form->{terms}) ? $form->current_date(\%myconfig, $form->{transdate}, $form->{terms} * 1) : $form->{duedate};
- $form->{oldtransdate} = $form->{transdate};
- &rebuild_vc(vendor, AP, $form->{transdate}, 1) if ! $newname;
-
- if ($form->{currency} ne $form->{defaultcurrency}) {
- delete $form->{exchangerate};
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'sell')));
- $form->{oldcurrency} = $form->{currency};
- }
- }
-
- if ($form->{currency} ne $form->{oldcurrency}) {
- delete $form->{exchangerate};
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'sell')));
- }
-
-
- $j = 1;
- for $i (1 .. $form->{paidaccounts}) {
- if ($form->{"paid_$i"}) {
- for (qw(datepaid source memo cleared)) { $form->{"${_}_$j"} = $form->{"${_}_$i"} }
- for (qw(paid exchangerate)) { $form->{"${_}_$j"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- $form->{"exchangerate_$j"} = $exchangerate if ($form->{"forex_$j"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$j"}, 'sell')));
- if ($j++ != $i) {
- for (qw(datepaid source memo cleared paid exchangerate forex)) { delete $form->{"${_}_$i"} }
- }
- } else {
- for (qw(datepaid source memo cleared paid exchangerate forex)) { delete $form->{"${_}_$i"} }
- }
- $form->{paidaccounts} = $j;
- }
-
- $i = $form->{rowcount};
- $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
-
- for (qw(partsgroup projectnumber)) {
- $form->{"select$_"} = $form->unescape($form->{"select$_"}) if $form->{"select$_"};
- }
-
- if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {
-
- $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
- &check_form;
-
- } else {
-
- IR->retrieve_item(\%myconfig, \%$form);
-
- my $rows = scalar @{ $form->{item_list} };
-
- if ($form->{language_code} && $rows == 0) {
- $language_code = $form->{language_code};
- $form->{language_code} = "";
- IR->retrieve_item(\%myconfig, \%$form);
- $form->{language_code} = $language_code;
- $rows = scalar @{ $form->{item_list} };
- }
-
- if ($rows) {
-
- if ($rows > 1) {
-
- &select_item;
- exit;
-
- } else {
-
- $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
-
- $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
-
- for (qw(partnumber description unit)) { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) }
-
- for (keys %{ $form->{item_list}[0] }) { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
-
- $form->{"discount_$i"} = $form->{discount} * 100;
-
- if ($sellprice) {
- $form->{"sellprice_$i"} = $sellprice;
-
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
- } else {
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
-
- $form->{"sellprice_$i"} /= $exchangerate;
- }
-
- $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
- for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
- for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
- if (!$form->{taxincluded}) {
- my @taxes = Tax::init_taxes($form, $form->{"taxaccounts_$i"});
- $amount += (Tax::calculate_taxes(\@taxes, $form, $amount, 0));
- }
-
- $form->{creditremaining} -= $amount;
-
- $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
-
- $form->{"oldqty_$i"} = $form->{"qty_$i"};
- for (qw(qty discount)) { $form->{"{_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- }
-
- &display_form;
-
- } else {
- # ok, so this is a new part
- # ask if it is a part or service item
-
- if ($form->{"partsgroup_$i"} && ($form->{"partsnumber_$i"} eq "") && ($form->{"description_$i"} eq "")) {
- $form->{"discount_$i"} = "";
- &display_form;
- } else {
-
- $form->{"id_$i"} = 0;
- $form->{"unit_$i"} = $locale->text('ea');
-
- &new_item;
-
- }
- }
- }
-}
+ if ( $form->{import_text} ) {
+ &import_text;
+ }
+
+ $form->{exchangerate} =
+ $form->parse_amount( \%myconfig, $form->{exchangerate} );
+ if ( $newname = &check_name(vendor) ) {
+ &rebuild_vc( vendor, AP, $form->{transdate}, 1 );
+ }
+ if ( $form->{transdate} ne $form->{oldtransdate} ) {
+ $form->{duedate} =
+ ( $form->{terms} )
+ ? $form->current_date( \%myconfig, $form->{transdate},
+ $form->{terms} * 1 )
+ : $form->{duedate};
+ $form->{oldtransdate} = $form->{transdate};
+ &rebuild_vc( vendor, AP, $form->{transdate}, 1 ) if !$newname;
+
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ delete $form->{exchangerate};
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate = $form->check_exchangerate(
+ \%myconfig, $form->{currency},
+ $form->{transdate}, 'sell'
+ )
+ )
+ );
+ $form->{oldcurrency} = $form->{currency};
+ }
+ }
+ if ( $form->{currency} ne $form->{oldcurrency} ) {
+ delete $form->{exchangerate};
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate = $form->check_exchangerate(
+ \%myconfig, $form->{currency},
+ $form->{transdate}, 'sell'
+ )
+ )
+ );
+ }
-sub post {
+ $j = 1;
+ for $i ( 1 .. $form->{paidaccounts} ) {
+ if ( $form->{"paid_$i"} ) {
+ for (qw(datepaid source memo cleared)) {
+ $form->{"${_}_$j"} = $form->{"${_}_$i"};
+ }
+ for (qw(paid exchangerate)) {
+ $form->{"${_}_$j"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ $form->{"exchangerate_$j"} = $exchangerate
+ if (
+ $form->{"forex_$j"} = (
+ $exchangerate = $form->check_exchangerate(
+ \%myconfig, $form->{currency},
+ $form->{"datepaid_$j"}, 'sell'
+ )
+ )
+ );
+ if ( $j++ != $i ) {
+ for (qw(datepaid source memo cleared paid exchangerate forex)) {
+ delete $form->{"${_}_$i"};
+ }
+ }
+ }
+ else {
+ for (qw(datepaid source memo cleared paid exchangerate forex)) {
+ delete $form->{"${_}_$i"};
+ }
+ }
+ $form->{paidaccounts} = $j;
+ }
+
+ $i = $form->{rowcount};
+ $exchangerate = ( $form->{exchangerate} ) ? $form->{exchangerate} : 1;
+
+ for (qw(partsgroup projectnumber)) {
+ $form->{"select$_"} = $form->unescape( $form->{"select$_"} )
+ if $form->{"select$_"};
+ }
+
+ if ( ( $form->{"partnumber_$i"} eq "" )
+ && ( $form->{"description_$i"} eq "" )
+ && ( $form->{"partsgroup_$i"} eq "" ) )
+ {
+
+ $form->{creditremaining} +=
+ ( $form->{oldinvtotal} - $form->{oldtotalpaid} );
+ &check_form;
+
+ }
+ else {
+
+ IR->retrieve_item( \%myconfig, \%$form );
+
+ my $rows = scalar @{ $form->{item_list} };
+
+ if ( $form->{language_code} && $rows == 0 ) {
+ $language_code = $form->{language_code};
+ $form->{language_code} = "";
+ IR->retrieve_item( \%myconfig, \%$form );
+ $form->{language_code} = $language_code;
+ $rows = scalar @{ $form->{item_list} };
+ }
+
+ if ($rows) {
+
+ if ( $rows > 1 ) {
+
+ &select_item;
+ exit;
+
+ }
+ else {
+
+ $form->{"qty_$i"} =
+ ( $form->{"qty_$i"} * 1 ) ? $form->{"qty_$i"} : 1;
+
+ $sellprice =
+ $form->parse_amount( \%myconfig, $form->{"sellprice_$i"} );
+
+ for (qw(partnumber description unit)) {
+ $form->{item_list}[$i]{$_} =
+ $form->quote( $form->{item_list}[$i]{$_} );
+ }
+
+ for ( keys %{ $form->{item_list}[0] } ) {
+ $form->{"${_}_$i"} = $form->{item_list}[0]{$_};
+ }
+
+ $form->{"discount_$i"} = $form->{discount} * 100;
+
+ if ($sellprice) {
+ $form->{"sellprice_$i"} = $sellprice;
+
+ ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+ }
+ else {
+ ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ $form->{"sellprice_$i"} /= $exchangerate;
+ }
- $form->isblank("transdate", $locale->text('Invoice Date missing!'));
- $form->isblank("vendor", $locale->text('Vendor missing!'));
-
- # if the vendor changed get new values
- if (&check_name(vendor)) {
- &update;
- exit;
- }
-
- &validate_items;
-
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
- $transdate = $form->datetonum(\%myconfig, $form->{transdate});
-
- $form->error($locale->text('Cannot post invoice for a closed period!')) if ($transdate <= $closedto);
-
- $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
-
- for $i (1 .. $form->{paidaccounts}) {
- if ($form->{"paid_$i"}) {
- $datepaid = $form->datetonum(\%myconfig, $form->{"datepaid_$i"});
-
- $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
-
- $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
-
- if ($form->{currency} ne $form->{defaultcurrency}) {
- $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
- $form->isblank("exchangerate_$i", $locale->text('Exchange rate for payment missing!'));
- }
- }
- }
-
- if (! $form->{repost}) {
- if ($form->{id}) {
- &repost;
- exit;
- }
- }
-
- ($form->{AP}) = split /--/, $form->{AP};
- ($form->{AP_paid}) = split /--/, $form->{AP_paid};
-
- if (IR->post_invoice(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Invoice [_1] posted!', $form->{invnumber}));
- } else {
- $form->error($locale->text('Cannot post invoice!'));
- }
-
+ $amount =
+ $form->{"sellprice_$i"} * $form->{"qty_$i"} *
+ ( 1 - $form->{"discount_$i"} / 100 );
+ for ( split / /, $form->{taxaccounts} ) {
+ $form->{"${_}_base"} = 0;
+ }
+ for ( split / /, $form->{"taxaccounts_$i"} ) {
+ $form->{"${_}_base"} += $amount;
+ }
+ if ( !$form->{taxincluded} ) {
+ my @taxes =
+ Tax::init_taxes( $form, $form->{"taxaccounts_$i"} );
+ $amount +=
+ ( Tax::calculate_taxes( \@taxes, $form, $amount, 0 ) );
+ }
+
+ $form->{creditremaining} -= $amount;
+
+ $form->{"sellprice_$i"} =
+ $form->format_amount( \%myconfig, $form->{"sellprice_$i"},
+ $decimalplaces );
+
+ $form->{"oldqty_$i"} = $form->{"qty_$i"};
+ for (qw(qty discount)) {
+ $form->{"{_}_$i"} =
+ $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ }
+
+ &display_form;
+
+ }
+ else {
+
+ # ok, so this is a new part
+ # ask if it is a part or service item
+
+ if ( $form->{"partsgroup_$i"}
+ && ( $form->{"partsnumber_$i"} eq "" )
+ && ( $form->{"description_$i"} eq "" ) )
+ {
+ $form->{"discount_$i"} = "";
+ &display_form;
+ }
+ else {
+
+ $form->{"id_$i"} = 0;
+ $form->{"unit_$i"} = $locale->text('ea');
+
+ &new_item;
+
+ }
+ }
+ }
}
+sub post {
+
+ $form->isblank( "transdate", $locale->text('Invoice Date missing!') );
+ $form->isblank( "vendor", $locale->text('Vendor missing!') );
+
+ # if the vendor changed get new values
+ if ( &check_name(vendor) ) {
+ &update;
+ exit;
+ }
+
+ &validate_items;
+
+ $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
+ $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
+ $form->error( $locale->text('Cannot post invoice for a closed period!') )
+ if ( $transdate <= $closedto );
+
+ $form->isblank( "exchangerate", $locale->text('Exchange rate missing!') )
+ if ( $form->{currency} ne $form->{defaultcurrency} );
+
+ for $i ( 1 .. $form->{paidaccounts} ) {
+ if ( $form->{"paid_$i"} ) {
+ $datepaid = $form->datetonum( \%myconfig, $form->{"datepaid_$i"} );
+
+ $form->isblank( "datepaid_$i",
+ $locale->text('Payment date missing!') );
+
+ $form->error(
+ $locale->text('Cannot post payment for a closed period!') )
+ if ( $datepaid <= $closedto );
+
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ $form->{"exchangerate_$i"} = $form->{exchangerate}
+ if ( $transdate == $datepaid );
+ $form->isblank( "exchangerate_$i",
+ $locale->text('Exchange rate for payment missing!') );
+ }
+ }
+ }
+
+ if ( !$form->{repost} ) {
+ if ( $form->{id} ) {
+ &repost;
+ exit;
+ }
+ }
+
+ ( $form->{AP} ) = split /--/, $form->{AP};
+ ( $form->{AP_paid} ) = split /--/, $form->{AP_paid};
+
+ if ( IR->post_invoice( \%myconfig, \%$form ) ) {
+ $form->redirect(
+ $locale->text( 'Invoice [_1] posted!', $form->{invnumber} ) );
+ }
+ else {
+ $form->error( $locale->text('Cannot post invoice!') );
+ }
+
+}
sub delete {
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
|;
- $form->{action} = "yes";
- $form->hide_form;
+ $form->{action} = "yes";
+ $form->hide_form;
- print qq|
-<h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
+ print qq|
+<h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
-<h4>|.$locale->text('Are you sure you want to delete Invoice Number [_1]?', $form->{invnumber}).qq|</h4>
+<h4>|
+ . $locale->text( 'Are you sure you want to delete Invoice Number [_1]?',
+ $form->{invnumber} )
+ . qq|</h4>
<p>
-<button name="action" class="submit" type="submit" value="yes">|.$locale->text('Yes').qq|</button>
+<button name="action" class="submit" type="submit" value="yes">|
+ . $locale->text('Yes')
+ . qq|</button>
</form>
|;
-
}
-
-
sub yes {
- if (IR->delete_invoice(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Invoice deleted!'));
- } else {
- $form->error($locale->text('Cannot delete invoice!'));
- }
+ if ( IR->delete_invoice( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Invoice deleted!') );
+ }
+ else {
+ $form->error( $locale->text('Cannot delete invoice!') );
+ }
}
-
diff --git a/bin/is.pl b/bin/is.pl
index d34419d7..5d5c880f 100644
--- a/bin/is.pl
+++ b/bin/is.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -43,7 +43,6 @@
#
#======================================================================
-
use LedgerSMB::IS;
use LedgerSMB::PE;
use LedgerSMB::Tax;
@@ -51,302 +50,363 @@ use LedgerSMB::Tax;
require "bin/arap.pl";
require "bin/io.pl";
-
1;
-# end of main
-
+# end of main
sub add {
- $form->{title} = $locale->text('Add Sales Invoice');
+ $form->{title} = $locale->text('Add Sales Invoice');
- $form->{callback} = "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}" unless $form->{callback};
+ $form->{callback} =
+"$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
- &invoice_links;
- &prepare_invoice;
- &display_form;
-
-}
+ &invoice_links;
+ &prepare_invoice;
+ &display_form;
+}
sub edit {
- $form->{title} = $locale->text('Edit Sales Invoice');
+ $form->{title} = $locale->text('Edit Sales Invoice');
- &invoice_links;
- &prepare_invoice;
- &display_form;
-
-}
+ &invoice_links;
+ &prepare_invoice;
+ &display_form;
+}
sub invoice_links {
- $form->{vc} = "customer";
- $form->{type} = "invoice";
-
- # create links
- $form->create_links("AR", \%myconfig, "customer", 1);
-
- # currencies
- @curr = split /:/, $form->{currencies};
- $form->{defaultcurrency} = $curr[0];
- chomp $form->{defaultcurrency};
-
- for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
-
- if (@{ $form->{all_customer} }) {
- unless ($form->{customer_id}) {
- $form->{customer_id} = $form->{all_customer}->[0]->{id};
- }
- }
-
- AA->get_name(\%myconfig, \%$form);
- delete $form->{notes};
- IS->retrieve_invoice(\%myconfig, \%$form);
-
- $form->{oldlanguage_code} = $form->{language_code};
-
- $form->get_partsgroup(\%myconfig, { language_code => $form->{language_code}, searchitems => 'nolabor' });
-
- 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|;
- }
- }
- }
-
- if (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} = "<option>\n";
- for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
- }
-
- $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
- $form->{oldtransdate} = $form->{transdate};
-
- $form->{selectcustomer} = "";
- if (@{ $form->{all_customer} }) {
- $form->{customer} = "$form->{customer}--$form->{customer_id}";
- for (@{ $form->{all_customer} }) { $form->{selectcustomer} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
-
- # departments
- if (@{ $form->{all_department} }) {
- $form->{selectdepartment} = "<option>\n";
- $form->{department} = "$form->{department}--$form->{department_id}" if $form->{department_id};
-
- for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
- }
-
- $form->{employee} = "$form->{employee}--$form->{employee_id}";
- # sales staff
- if (@{ $form->{all_employee} }) {
- $form->{selectemployee} = "";
- for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
-
- if (@{ $form->{all_language} }) {
- $form->{selectlanguage} = "<option>\n";
- for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
- }
-
- # forex
- $form->{forex} = $form->{exchangerate};
- $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
-
- foreach $key (keys %{ $form->{AR_links} }) {
-
- $form->{"select$key"} = "";
- foreach $ref (@{ $form->{AR_links}{$key} }) {
- $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
- }
-
- if ($key eq "AR_paid") {
- for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
- $form->{"AR_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
- # reverse paid
- $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount} * -1;
- $form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};
- $form->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate};
- $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i-1]->{source};
- $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i-1]->{memo};
- $form->{"cleared_$i"} = $form->{acc_trans}{$key}->[$i-1]->{cleared};
-
- $form->{paidaccounts} = $i;
- }
- } else {
- $form->{$key} = "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}" if $form->{acc_trans}{$key}->[0]->{accno};
- }
-
- }
-
- for (qw(AR_links acc_trans)) { delete $form->{$_} }
-
- $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
-
- $form->{AR} = $form->{AR_1} unless $form->{id};
-
- $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
-
- if (! $form->{readonly}) {
- $form->{readonly} = 1 if $myconfig{acs} =~ /AR--Sales Invoice/;
- }
+ $form->{vc} = "customer";
+ $form->{type} = "invoice";
-}
+ # create links
+ $form->create_links( "AR", \%myconfig, "customer", 1 );
+ # currencies
+ @curr = split /:/, $form->{currencies};
+ $form->{defaultcurrency} = $curr[0];
+ chomp $form->{defaultcurrency};
-sub prepare_invoice {
+ for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
+
+ if ( @{ $form->{all_customer} } ) {
+ unless ( $form->{customer_id} ) {
+ $form->{customer_id} = $form->{all_customer}->[0]->{id};
+ }
+ }
+
+ AA->get_name( \%myconfig, \%$form );
+ delete $form->{notes};
+ IS->retrieve_invoice( \%myconfig, \%$form );
+
+ $form->{oldlanguage_code} = $form->{language_code};
+
+ $form->get_partsgroup( \%myconfig,
+ { language_code => $form->{language_code}, searchitems => 'nolabor' } );
+
+ 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|;
+ }
+ }
+ }
+
+ if ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} = "<option>\n";
+ for ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} .=
+qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
+ }
+ }
+
+ $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
+ $form->{oldtransdate} = $form->{transdate};
+
+ $form->{selectcustomer} = "";
+ if ( @{ $form->{all_customer} } ) {
+ $form->{customer} = "$form->{customer}--$form->{customer_id}";
+ for ( @{ $form->{all_customer} } ) {
+ $form->{selectcustomer} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
+
+ # departments
+ if ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} = "<option>\n";
+ $form->{department} = "$form->{department}--$form->{department_id}"
+ if $form->{department_id};
+
+ for ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+ }
+
+ $form->{employee} = "$form->{employee}--$form->{employee_id}";
+
+ # sales staff
+ if ( @{ $form->{all_employee} } ) {
+ $form->{selectemployee} = "";
+ for ( @{ $form->{all_employee} } ) {
+ $form->{selectemployee} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
+
+ if ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} = "<option>\n";
+ for ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} .=
+ qq|<option value="$_->{code}">$_->{description}\n|;
+ }
+ }
+
+ # forex
+ $form->{forex} = $form->{exchangerate};
+ $exchangerate = ( $form->{exchangerate} ) ? $form->{exchangerate} : 1;
+
+ foreach $key ( keys %{ $form->{AR_links} } ) {
+
+ $form->{"select$key"} = "";
+ foreach $ref ( @{ $form->{AR_links}{$key} } ) {
+ $form->{"select$key"} .=
+ "<option>$ref->{accno}--$ref->{description}\n";
+ }
+
+ if ( $key eq "AR_paid" ) {
+ for $i ( 1 .. scalar @{ $form->{acc_trans}{$key} } ) {
+ $form->{"AR_paid_$i"} =
+"$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
+
+ # reverse paid
+ $form->{"paid_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{amount} * -1;
+ $form->{"datepaid_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{transdate};
+ $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{exchangerate};
+ $form->{"source_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{source};
+ $form->{"memo_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{memo};
+ $form->{"cleared_$i"} =
+ $form->{acc_trans}{$key}->[ $i - 1 ]->{cleared};
+
+ $form->{paidaccounts} = $i;
+ }
+ }
+ else {
+ $form->{$key} =
+"$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}"
+ if $form->{acc_trans}{$key}->[0]->{accno};
+ }
+
+ }
+
+ for (qw(AR_links acc_trans)) { delete $form->{$_} }
+
+ $form->{paidaccounts} = 1 unless ( exists $form->{paidaccounts} );
+
+ $form->{AR} = $form->{AR_1} unless $form->{id};
+
+ $form->{locked} =
+ ( $form->{revtrans} )
+ ? '1'
+ : ( $form->datetonum( \%myconfig, $form->{transdate} ) <=
+ $form->datetonum( \%myconfig, $form->{closedto} ) );
+
+ if ( !$form->{readonly} ) {
+ $form->{readonly} = 1 if $myconfig{acs} =~ /AR--Sales Invoice/;
+ }
- $form->{type} = "invoice";
- $form->{formname} = "invoice";
- $form->{sortby} ||= "runningnumber";
- $form->{format} = "postscript" if $myconfig{printer};
- $form->{media} = $myconfig{printer};
-
- $form->{selectformname} = qq|<option value="invoice">|.$locale->text('Invoice').qq|
-<option value="pick_list">|.$locale->text('Pick List').qq|
-<option value="packing_list">|.$locale->text('Packing List');
-
- $i = 0;
- $form->{currency} =~ s/ //g;
- $form->{oldcurrency} = $form->{currency};
-
- if ($form->{id}) {
-
- for (qw(invnumber ordnumber ponumber quonumber shippingpoint shipvia notes intnotes)) { $form->{$_} = $form->quote($form->{$_}) }
-
- foreach $ref (@{ $form->{invoice_details} } ) {
- $i++;
- for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
-
- $form->{"projectnumber_$i"} = qq|$ref->{projectnumber}--$ref->{project_id}| if $ref->{project_id};
- $form->{"partsgroup_$i"} = qq|$ref->{partsgroup}--$ref->{partsgroup_id}| if $ref->{partsgroup_id};
-
- $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
-
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
-
- $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
- $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
- $form->{"oldqty_$i"} = $form->{"qty_$i"};
-
- for (qw(partnumber sku description unit)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
- $form->{rowcount} = $i;
- }
- }
-
}
+sub prepare_invoice {
+ $form->{type} = "invoice";
+ $form->{formname} = "invoice";
+ $form->{sortby} ||= "runningnumber";
+ $form->{format} = "postscript" if $myconfig{printer};
+ $form->{media} = $myconfig{printer};
+
+ $form->{selectformname} =
+ qq|<option value="invoice">|
+ . $locale->text('Invoice') . qq|
+<option value="pick_list">| . $locale->text('Pick List') . qq|
+<option value="packing_list">| . $locale->text('Packing List');
+
+ $i = 0;
+ $form->{currency} =~ s/ //g;
+ $form->{oldcurrency} = $form->{currency};
+
+ if ( $form->{id} ) {
+
+ for (
+ qw(invnumber ordnumber ponumber quonumber shippingpoint shipvia notes intnotes)
+ )
+ {
+ $form->{$_} = $form->quote( $form->{$_} );
+ }
+
+ foreach $ref ( @{ $form->{invoice_details} } ) {
+ $i++;
+ for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
+
+ $form->{"projectnumber_$i"} =
+ qq|$ref->{projectnumber}--$ref->{project_id}|
+ if $ref->{project_id};
+ $form->{"partsgroup_$i"} =
+ qq|$ref->{partsgroup}--$ref->{partsgroup_id}|
+ if $ref->{partsgroup_id};
+
+ $form->{"discount_$i"} =
+ $form->format_amount( \%myconfig, $form->{"discount_$i"} * 100 );
+
+ ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ $form->{"sellprice_$i"} =
+ $form->format_amount( \%myconfig, $form->{"sellprice_$i"},
+ $decimalplaces );
+ $form->{"qty_$i"} =
+ $form->format_amount( \%myconfig, $form->{"qty_$i"} );
+ $form->{"oldqty_$i"} = $form->{"qty_$i"};
+
+ for (qw(partnumber sku description unit)) {
+ $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} );
+ }
+ $form->{rowcount} = $i;
+ }
+ }
+
+}
sub form_header {
- # 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>
+ # 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|
+ $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>|;
+ 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|
+ $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|
+ 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>
+ <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|">
+ <input type=hidden name=selectdepartment value="|
+ . $form->escape( $form->{selectdepartment}, 1 ) . qq|">
</td>
</tr>
| if $form->{selectdepartment};
+ $n = ( $form->{creditremaining} < 0 ) ? "0" : "1";
- $n = ($form->{creditremaining} < 0) ? "0" : "1";
-
-
- if ($form->{business}) {
- $business = qq|
+ if ( $form->{business} ) {
+ $business = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Business').qq|</th>
+ <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>
+ <th align=right nowrap>| . $locale->text('Trade Discount') . qq|</th>
+ <td>|
+ . $form->format_amount( \%myconfig, $form->{tradediscount} * 100 )
+ . qq| %</td>
</tr>
|;
- }
+ }
- $employee = qq|
+ $employee = qq|
<input type=hidden name=employee value="$form->{employee}">
|;
-
- $employee = qq|
+ $employee = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Salesperson').qq|</th>
+ <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
<td><select name=employee>$form->{selectemployee}</select></td>
- <input type=hidden name=selectemployee value="|.
- $form->escape($form->{selectemployee},1).qq|">
+ <input type=hidden name=selectemployee value="|
+ . $form->escape( $form->{selectemployee}, 1 ) . qq|">
</tr>
| if $form->{selectemployee};
- $i = $form->{rowcount} + 1;
- $focus = "partnumber_$i";
-
- $form->header;
+ $i = $form->{rowcount} + 1;
+ $focus = "partnumber_$i";
+
+ $form->header;
- print qq|
+ print qq|
<body onLoad="document.forms[0].${focus}.focus()" />
<form method=post action="$form->{script}">
|;
- $form->hide_form(qw(id type media format printed emailed queued title vc terms discount creditlimit creditremaining tradediscount business closedto locked shipped oldtransdate recurring));
-
- print qq|
+ $form->hide_form(
+ qw(id type media format printed emailed queued title vc terms discount creditlimit creditremaining tradediscount business closedto locked shipped oldtransdate recurring)
+ );
+
+ print qq|
<table width=100%>
<tr class=listtop>
<th class=listtop>$form->{title}</th>
@@ -359,7 +419,7 @@ sub form_header {
<td>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Customer').qq|</th>
+ <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
<td colspan=3>$customer</td>
<input type=hidden name=customer_id value=$form->{customer_id}>
<input type=hidden name=oldcustomer value="$form->{oldcustomer}">
@@ -369,29 +429,33 @@ sub form_header {
<td colspan=3>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Credit Limit').qq|</th>
- <td>|.$form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0").qq|</td>
+ <th align=right nowrap>| . $locale->text('Credit Limit') . qq|</th>
+ <td>|
+ . $form->format_amount( \%myconfig, $form->{creditlimit}, 0, "0" )
+ . qq|</td>
<td width=10></td>
- <th align=right nowrap>|.$locale->text('Remaining').qq|</th>
- <td class="plus$n" nowrap>|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</td>
+ <th align=right nowrap>| . $locale->text('Remaining') . qq|</th>
+ <td class="plus$n" nowrap>|
+ . $form->format_amount( \%myconfig, $form->{creditremaining}, 0, "0" )
+ . qq|</td>
</tr>
$business
</table>
</td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Record in').qq|</th>
+ <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
$exchangerate
<tr>
- <th align=right nowrap>|.$locale->text('Shipping Point').qq|</th>
+ <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
<td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Ship via').qq|</th>
+ <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
<td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
</tr>
</table>
@@ -400,24 +464,24 @@ sub form_header {
<table>
$employee
<tr>
- <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
<td><input name=invnumber size=20 value="$form->{invnumber}"></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
<td><input name=ordnumber size=20 value="$form->{ordnumber}"></td>
<input type=hidden name=quonumber value="$form->{quonumber}">
</tr>
<tr>
- <th align=right>|.$locale->text('Invoice Date').qq|</th>
+ <th align=right>| . $locale->text('Invoice Date') . qq|</th>
<td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
</tr>
<tr>
- <th align=right>|.$locale->text('Due Date').qq|</th>
+ <th align=right>| . $locale->text('Due Date') . qq|</th>
<td><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('PO Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('PO Number') . qq|</th>
<td><input name=ponumber size=20 value="$form->{ponumber}"></td>
</tr>
</table>
@@ -432,75 +496,82 @@ sub form_header {
</tr>
|;
- $form->hide_form(qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail message email subject cc bcc taxaccounts));
-
- foreach $item (split / /, $form->{taxaccounts}) {
- $form->hide_form("${item}_rate", "${item}_description", "${item}_taxnumber");
- }
-
-}
+ $form->hide_form(
+ qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail message email subject cc bcc taxaccounts)
+ );
+ foreach $item ( split / /, $form->{taxaccounts} ) {
+ $form->hide_form( "${item}_rate", "${item}_description",
+ "${item}_taxnumber" );
+ }
+}
sub form_footer {
- $form->{invtotal} = $form->{invsubtotal};
+ $form->{invtotal} = $form->{invsubtotal};
- if (($rows = $form->numtextrows($form->{notes}, 35, 8)) < 2) {
- $rows = 2;
- }
- if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
- $introws = 2;
- }
- $rows = ($rows > $introws) ? $rows : $introws;
- $notes = qq|<textarea name=notes rows=$rows cols=35 wrap=soft>$form->{notes}</textarea>|;
- $intnotes = qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
+ if ( ( $rows = $form->numtextrows( $form->{notes}, 35, 8 ) ) < 2 ) {
+ $rows = 2;
+ }
+ if ( ( $introws = $form->numtextrows( $form->{intnotes}, 35, 8 ) ) < 2 ) {
+ $introws = 2;
+ }
+ $rows = ( $rows > $introws ) ? $rows : $introws;
+ $notes =
+qq|<textarea name=notes rows=$rows cols=35 wrap=soft>$form->{notes}</textarea>|;
+ $intnotes =
+qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
- $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
+ $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
- $taxincluded = "";
- if ($form->{taxaccounts}) {
- $taxincluded = qq|
+ $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>
+ <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 $item (@taxes) {
- my $taccno = $item->account;
- $form->{"${taccno}_total"} = $form->format_amount(\%myconfig,
- $item->value, 2);
- $tax .= qq|
+ }
+
+ if ( !$form->{taxincluded} ) {
+
+ my @taxes = Tax::init_taxes( $form, $form->{taxaccounts} );
+ $form->{invtotal} +=
+ Tax::calculate_taxes( \@taxes, $form, $form->{invsubtotal}, 0 );
+ foreach $item (@taxes) {
+ my $taccno = $item->account;
+ $form->{"${taccno}_total"} =
+ $form->format_amount( \%myconfig, $item->value, 2 );
+ $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 );
- $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
-
- $subtotal = qq|
+ $subtotal = qq|
<tr>
- <th align=right>|.$locale->text('Subtotal').qq|</th>
+ <th align=right>| . $locale->text('Subtotal') . qq|</th>
<td align=right>$form->{invsubtotal}</td>
</tr>
|;
- }
+ }
- $form->{oldinvtotal} = $form->{invtotal};
- $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
-
- print qq|
+ $form->{oldinvtotal} = $form->{invtotal};
+ $form->{invtotal} =
+ $form->format_amount( \%myconfig, $form->{invtotal}, 2, 0 );
+
+ print qq|
<tr>
<td>
<table width=100%>
@@ -508,8 +579,8 @@ sub form_footer {
<td>
<table>
<tr>
- <th align=left>|.$locale->text('Notes').qq|</th>
- <th align=left>|.$locale->text('Internal Notes').qq|</th>
+ <th align=left>| . $locale->text('Notes') . qq|</th>
+ <th align=left>| . $locale->text('Internal Notes') . qq|</th>
</tr>
<tr valign=top>
<td>$notes</td>
@@ -522,7 +593,7 @@ sub form_footer {
$subtotal
$tax
<tr>
- <th align=right>|.$locale->text('Total').qq|</th>
+ <th align=right>| . $locale->text('Total') . qq|</th>
<td align=right>$form->{invtotal}</td>
</tr>
$taxincluded
@@ -536,77 +607,88 @@ sub form_footer {
<td>
<table width=100%>
<tr class=listheading>
- <th colspan=6 class=listheading>|.$locale->text('Payments')
- .qq|</th>
+ <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
</tr>
|;
- if ($form->{currency} eq $form->{defaultcurrency}) {
- @column_index = qw(datepaid source memo paid AR_paid);
- } else {
- @column_index = qw(datepaid source memo paid exchangerate AR_paid);
- }
-
- $column_data{datepaid} = "<th>".$locale->text('Date')."</th>";
- $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
- $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";
- $column_data{AR_paid} = "<th>".$locale->text('Account')."</th>";
- $column_data{source} = "<th>".$locale->text('Source')."</th>";
- $column_data{memo} = "<th>".$locale->text('Memo')."</th>";
-
- print "
+ if ( $form->{currency} eq $form->{defaultcurrency} ) {
+ @column_index = qw(datepaid source memo paid AR_paid);
+ }
+ else {
+ @column_index = qw(datepaid source memo paid exchangerate AR_paid);
+ }
+
+ $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
+ $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
+ $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
+ $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
+ $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
+ $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
+
+ print "
<tr>
";
- for (@column_index) { print "$column_data{$_}\n" }
- print "
+ for (@column_index) { print "$column_data{$_}\n" }
+ print "
</tr>
";
-
- $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
- for $i (1 .. $form->{paidaccounts}) {
-
- $form->hide_form("cleared_$i");
- print "
- <tr>\n";
+ $form->{paidaccounts}++ if ( $form->{"paid_$form->{paidaccounts}"} );
+ 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"});
+ $form->hide_form("cleared_$i");
- $exchangerate = qq|&nbsp;|;
- if ($form->{currency} ne $form->{defaultcurrency}) {
- if ($form->{"forex_$i"}) {
- $exchangerate = qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
- } else {
- $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
- }
- }
+ print "
+ <tr>\n";
- $exchangerate .= qq|
+ $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"} );
+
+ $exchangerate = qq|&nbsp;|;
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ if ( $form->{"forex_$i"} ) {
+ $exchangerate =
+qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
+ }
+ else {
+ $exchangerate =
+qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
+ }
+ }
+
+ $exchangerate .= qq|
<input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
|;
- $column_data{paid} = qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
- $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
- $column_data{AR_paid} = qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
- $column_data{datepaid} = qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
- $column_data{source} = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
- $column_data{memo} = qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
-
- for (@column_index) { print qq|$column_data{$_}\n| }
- print "
+ $column_data{paid} =
+qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
+ $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
+ $column_data{AR_paid} =
+qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
+ $column_data{datepaid} =
+qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
+ $column_data{source} =
+qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
+ $column_data{memo} =
+qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
+
+ for (@column_index) { print qq|$column_data{$_}\n| }
+ print "
</tr>\n";
- }
+ }
+
+ $form->{oldtotalpaid} = $totalpaid;
+ $form->hide_form(qw(paidaccounts selectAR_paid oldinvtotal oldtotalpaid));
- $form->{oldtotalpaid} = $totalpaid;
- $form->hide_form(qw(paidaccounts selectAR_paid oldinvtotal oldtotalpaid));
-
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -617,79 +699,107 @@ sub form_footer {
<td>
|;
- &print_options;
+ &print_options;
- print qq|
+ 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('Post')
+ # type=submit $locale->text('Print and Post')
+ # type=submit $locale->text('Schedule')
+ # type=submit $locale->text('Ship to')
+ # type=submit $locale->text('Post as new')
+ # type=submit $locale->text('Print and Post as new')
+ # type=submit $locale->text('E-mail')
+ # type=submit $locale->text('Delete')
+ # type=submit $locale->text('Sales Order')
+
+ 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') },
+ 'ship_to' =>
+ { ndx => 4, key => 'T', value => $locale->text('Ship to') },
+ 'e_mail' =>
+ { ndx => 5, key => 'E', value => $locale->text('E-mail') },
+ 'print_and_post' => {
+ ndx => 6,
+ key => 'R',
+ value => $locale->text('Print and Post')
+ },
+ 'post_as_new' =>
+ { ndx => 7, key => 'N', value => $locale->text('Post as new') },
+ 'print_and_post_as_new' => {
+ ndx => 8,
+ key => 'W',
+ value => $locale->text('Print and Post as new')
+ },
+ 'sales_order' =>
+ { ndx => 9, key => 'L', value => $locale->text('Sales Order') },
+ 'schedule' =>
+ { ndx => 10, key => 'H', value => $locale->text('Schedule') },
+ 'delete' =>
+ { ndx => 11, key => 'D', value => $locale->text('Delete') },
+ );
+
+ if ( $form->{id} ) {
+
+ if ( $form->{locked} || $transdate <= $closedto ) {
+ for ( "post", "print_and_post", "delete" ) {
+ delete $button{$_};
+ }
+ }
+
+ if ( !${LedgerSMB::Sysconfig::latex} ) {
+ for ( "print_and_post", "print_and_post_as_new" ) {
+ delete $button{$_};
+ }
+ }
+
+ }
+ else {
+
+ if ( $transdate > $closedto ) {
+
+ for ( "update", "ship_to", "print", "e_mail", "post",
+ "schedule" )
+ {
+ $a{$_} = 1;
+ }
+ $a{'print_and_post'} = 1 if ${LedgerSMB::Sysconfig::latex};
+
+ }
+ for ( keys %button ) { delete $button{$_} if !$a{$_} }
+ }
+
+ for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
+ {
+ $form->print_button( \%button, $_ );
+ }
+
+ }
- $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('Schedule')
-# type=submit $locale->text('Ship to')
-# type=submit $locale->text('Post as new')
-# type=submit $locale->text('Print and Post as new')
-# type=submit $locale->text('E-mail')
-# type=submit $locale->text('Delete')
-# type=submit $locale->text('Sales Order')
-
- 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') },
- 'ship_to' => { ndx => 4, key => 'T', value => $locale->text('Ship to') },
- 'e_mail' => { ndx => 5, key => 'E', value => $locale->text('E-mail') },
- 'print_and_post' => { ndx => 6, key => 'R', value => $locale->text('Print and Post') },
- 'post_as_new' => { ndx => 7, key => 'N', value => $locale->text('Post as new') },
- 'print_and_post_as_new' => { ndx => 8, key => 'W', value => $locale->text('Print and Post as new') },
- 'sales_order' => { ndx => 9, key => 'L', value => $locale->text('Sales Order') },
- 'schedule' => { ndx => 10, key => 'H', value => $locale->text('Schedule') },
- 'delete' => { ndx => 11, key => 'D', value => $locale->text('Delete') },
- );
-
- if ($form->{id}) {
-
- if ($form->{locked} || $transdate <= $closedto) {
- for ("post", "print_and_post", "delete") { delete $button{$_} }
- }
-
- if (!${LedgerSMB::Sysconfig::latex}) {
- for ("print_and_post", "print_and_post_as_new") { delete $button{$_} }
- }
-
- } else {
-
- if ($transdate > $closedto) {
-
- for ("update", "ship_to", "print", "e_mail", "post", "schedule") { $a{$_} = 1 }
- $a{'print_and_post'} = 1 if ${LedgerSMB::Sysconfig::latex};
-
- }
- 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(rowcount callback path login sessionid));
-
- print qq|
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ $form->hide_form(qw(rowcount callback path login sessionid));
+
+ print qq|
</form>
</body>
@@ -698,276 +808,369 @@ sub form_footer {
}
-
sub update {
- $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
-
- if ($newname = &check_name(customer)) {
- &rebuild_vc(customer, AR, $form->{transdate}, 1);
- }
- if ($form->{transdate} ne $form->{oldtransdate}) {
- $form->{duedate} = ($form->{terms}) ? $form->current_date(\%myconfig, $form->{transdate}, $form->{terms} * 1) : $form->{duedate};
- $form->{oldtransdate} = $form->{transdate};
- &rebuild_vc(customer, AR, $form->{transdate}, 1) if ! $newname;
-
- if ($form->{currency} ne $form->{defaultcurrency}) {
- delete $form->{exchangerate};
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'buy')));
- }
-
- $form->{selectemployee} = "";
- if (@{ $form->{all_employee} }) {
- for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
- }
-
- if ($form->{currency} ne $form->{oldcurrency}) {
- delete $form->{exchangerate};
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'buy')));
- }
-
-
- $j = 1;
- for $i (1 .. $form->{paidaccounts}) {
- if ($form->{"paid_$i"}) {
- for (qw(datepaid source memo cleared)) { $form->{"${_}_$j"} = $form->{"${_}_$i"} }
- for (qw(paid exchangerate)) { $form->{"${_}_$j"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- $form->{"exchangerate_$j"} = $exchangerate if ($form->{"forex_$j"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$j"}, 'buy')));
- if ($j++ != $i) {
- for (qw(datepaid source memo cleared paid exchangerate forex)) { delete $form->{"${_}_$i"} }
- }
- } else {
- for (qw(datepaid source memo cleared paid exchangerate forex)) { delete $form->{"${_}_$i"} }
- }
- }
- $form->{paidaccounts} = $j;
-
- $i = $form->{rowcount};
- $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
-
- for (qw(partsgroup projectnumber)) {
- $form->{"select$_"} = $form->unescape($form->{"select$_"}) if $form->{"select$_"};
- }
-
- # if last row empty, check the form otherwise retrieve new item
- if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {
-
- $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
- &check_form;
-
- } else {
-
- IS->retrieve_item(\%myconfig, \%$form);
-
- $rows = scalar @{ $form->{item_list} };
-
- if ($form->{language_code} && $rows == 0) {
- $language_code = $form->{language_code};
- $form->{language_code} = "";
- IS->retrieve_item(\%myconfig, \%$form);
- $form->{language_code} = $language_code;
- $rows = scalar @{ $form->{item_list} };
- }
-
- if ($rows) {
-
- if ($rows > 1) {
-
- &select_item;
- exit;
-
- } else {
-
- $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
-
- $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
-
- for (qw(partnumber description unit)) { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) }
- for (keys %{ $form->{item_list}[0] }) { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
-
- $form->{"discount_$i"} = $form->{discount} * 100;
-
- if ($sellprice) {
- $form->{"sellprice_$i"} = $sellprice;
-
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces1 = ($dec > 2) ? $dec : 2;
- } else {
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces1 = ($dec > 2) ? $dec : 2;
-
- $form->{"sellprice_$i"} /= $exchangerate;
- }
-
- ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces2 = ($dec > 2) ? $dec : 2;
-
- # if there is an exchange rate adjust sellprice
- for (qw(listprice lastcost)) { $form->{"${_}_$i"} /= $exchangerate }
-
- $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
- for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
- for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
- if (!$form->{taxincluded}) {
- my @taxes = Tax::init_taxes($form, $form->{"taxaccounts_$i"});
- $amount += Tax::calculate_taxes(\@taxes, $form, $amount, 0);
- }
-
- $form->{creditremaining} -= $amount;
-
- 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->{"oldqty_$i"} = $form->{"qty_$i"};
- for (qw(qty discount)) { $form->{"{_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- }
-
- &display_form;
-
- } else {
- # ok, so this is a new part
- # ask if it is a part or service item
-
- if ($form->{"partsgroup_$i"} && ($form->{"partsnumber_$i"} eq "") && ($form->{"description_$i"} eq "")) {
- $form->{rowcount}--;
- &display_form;
- } else {
-
- $form->{"id_$i"} = 0;
- $form->{"unit_$i"} = $locale->text('ea');
-
- &new_item;
-
- }
- }
- }
-}
+ $form->{exchangerate} =
+ $form->parse_amount( \%myconfig, $form->{exchangerate} );
+
+ if ( $newname = &check_name(customer) ) {
+ &rebuild_vc( customer, AR, $form->{transdate}, 1 );
+ }
+ if ( $form->{transdate} ne $form->{oldtransdate} ) {
+ $form->{duedate} =
+ ( $form->{terms} )
+ ? $form->current_date( \%myconfig, $form->{transdate},
+ $form->{terms} * 1 )
+ : $form->{duedate};
+ $form->{oldtransdate} = $form->{transdate};
+ &rebuild_vc( customer, AR, $form->{transdate}, 1 ) if !$newname;
+
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ delete $form->{exchangerate};
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate = $form->check_exchangerate(
+ \%myconfig, $form->{currency},
+ $form->{transdate}, 'buy'
+ )
+ )
+ );
+ }
+
+ $form->{selectemployee} = "";
+ if ( @{ $form->{all_employee} } ) {
+ for ( @{ $form->{all_employee} } ) {
+ $form->{selectemployee} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
+ }
+ if ( $form->{currency} ne $form->{oldcurrency} ) {
+ delete $form->{exchangerate};
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate = $form->check_exchangerate(
+ \%myconfig, $form->{currency},
+ $form->{transdate}, 'buy'
+ )
+ )
+ );
+ }
+ $j = 1;
+ for $i ( 1 .. $form->{paidaccounts} ) {
+ if ( $form->{"paid_$i"} ) {
+ for (qw(datepaid source memo cleared)) {
+ $form->{"${_}_$j"} = $form->{"${_}_$i"};
+ }
+ for (qw(paid exchangerate)) {
+ $form->{"${_}_$j"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ $form->{"exchangerate_$j"} = $exchangerate
+ if (
+ $form->{"forex_$j"} = (
+ $exchangerate = $form->check_exchangerate(
+ \%myconfig, $form->{currency},
+ $form->{"datepaid_$j"}, 'buy'
+ )
+ )
+ );
+ if ( $j++ != $i ) {
+ for (qw(datepaid source memo cleared paid exchangerate forex)) {
+ delete $form->{"${_}_$i"};
+ }
+ }
+ }
+ else {
+ for (qw(datepaid source memo cleared paid exchangerate forex)) {
+ delete $form->{"${_}_$i"};
+ }
+ }
+ }
+ $form->{paidaccounts} = $j;
-sub post {
+ $i = $form->{rowcount};
+ $exchangerate = ( $form->{exchangerate} ) ? $form->{exchangerate} : 1;
- $form->isblank("transdate", $locale->text('Invoice Date missing!'));
- $form->isblank("customer", $locale->text('Customer missing!'));
-
- # if oldcustomer ne customer redo form
- if (&check_name(customer)) {
- &update;
- exit;
- }
-
- &validate_items;
-
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
- $transdate = $form->datetonum(\%myconfig, $form->{transdate});
-
- $form->error($locale->text('Cannot post invoice for a closed period!')) if ($transdate <= $closedto);
-
- $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
-
- for $i (1 .. $form->{paidaccounts}) {
- if ($form->{"paid_$i"}) {
- $datepaid = $form->datetonum(\%myconfig, $form->{"datepaid_$i"});
-
- $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
-
- $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
-
- if ($form->{currency} ne $form->{defaultcurrency}) {
- $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
- $form->isblank("exchangerate_$i", $locale->text('Exchange rate for payment missing!'));
- }
- }
- }
-
-
- $form->{label} = $locale->text('Invoice');
-
- if (! $form->{repost}) {
- if ($form->{id}) {
- &repost;
- exit;
- }
- }
-
- ($form->{AR}) = split /--/, $form->{AR};
- ($form->{AR_paid}) = split /--/, $form->{AR_paid};
-
- if (IS->post_invoice(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Invoice [_1] posted!', $form->{invnumber}));
- } else {
- $form->error($locale->text('Cannot post invoice!'));
- }
-
+ for (qw(partsgroup projectnumber)) {
+ $form->{"select$_"} = $form->unescape( $form->{"select$_"} )
+ if $form->{"select$_"};
+ }
+
+ # if last row empty, check the form otherwise retrieve new item
+ if ( ( $form->{"partnumber_$i"} eq "" )
+ && ( $form->{"description_$i"} eq "" )
+ && ( $form->{"partsgroup_$i"} eq "" ) )
+ {
+
+ $form->{creditremaining} +=
+ ( $form->{oldinvtotal} - $form->{oldtotalpaid} );
+ &check_form;
+
+ }
+ else {
+
+ IS->retrieve_item( \%myconfig, \%$form );
+
+ $rows = scalar @{ $form->{item_list} };
+
+ if ( $form->{language_code} && $rows == 0 ) {
+ $language_code = $form->{language_code};
+ $form->{language_code} = "";
+ IS->retrieve_item( \%myconfig, \%$form );
+ $form->{language_code} = $language_code;
+ $rows = scalar @{ $form->{item_list} };
+ }
+
+ if ($rows) {
+
+ if ( $rows > 1 ) {
+
+ &select_item;
+ exit;
+
+ }
+ else {
+
+ $form->{"qty_$i"} =
+ ( $form->{"qty_$i"} * 1 ) ? $form->{"qty_$i"} : 1;
+
+ $sellprice =
+ $form->parse_amount( \%myconfig, $form->{"sellprice_$i"} );
+
+ for (qw(partnumber description unit)) {
+ $form->{item_list}[$i]{$_} =
+ $form->quote( $form->{item_list}[$i]{$_} );
+ }
+ for ( keys %{ $form->{item_list}[0] } ) {
+ $form->{"${_}_$i"} = $form->{item_list}[0]{$_};
+ }
+
+ $form->{"discount_$i"} = $form->{discount} * 100;
+
+ if ($sellprice) {
+ $form->{"sellprice_$i"} = $sellprice;
+
+ ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces1 = ( $dec > 2 ) ? $dec : 2;
+ }
+ else {
+ ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces1 = ( $dec > 2 ) ? $dec : 2;
+
+ $form->{"sellprice_$i"} /= $exchangerate;
+ }
+
+ ($dec) = ( $form->{"lastcost_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces2 = ( $dec > 2 ) ? $dec : 2;
+
+ # if there is an exchange rate adjust sellprice
+ for (qw(listprice lastcost)) {
+ $form->{"${_}_$i"} /= $exchangerate;
+ }
+
+ $amount =
+ $form->{"sellprice_$i"} * $form->{"qty_$i"} *
+ ( 1 - $form->{"discount_$i"} / 100 );
+ for ( split / /, $form->{taxaccounts} ) {
+ $form->{"${_}_base"} = 0;
+ }
+ for ( split / /, $form->{"taxaccounts_$i"} ) {
+ $form->{"${_}_base"} += $amount;
+ }
+ if ( !$form->{taxincluded} ) {
+ my @taxes =
+ Tax::init_taxes( $form, $form->{"taxaccounts_$i"} );
+ $amount +=
+ Tax::calculate_taxes( \@taxes, $form, $amount, 0 );
+ }
+
+ $form->{creditremaining} -= $amount;
+
+ 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->{"oldqty_$i"} = $form->{"qty_$i"};
+ for (qw(qty discount)) {
+ $form->{"{_}_$i"} =
+ $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ }
+
+ &display_form;
+
+ }
+ else {
+
+ # ok, so this is a new part
+ # ask if it is a part or service item
+
+ if ( $form->{"partsgroup_$i"}
+ && ( $form->{"partsnumber_$i"} eq "" )
+ && ( $form->{"description_$i"} eq "" ) )
+ {
+ $form->{rowcount}--;
+ &display_form;
+ }
+ else {
+
+ $form->{"id_$i"} = 0;
+ $form->{"unit_$i"} = $locale->text('ea');
+
+ &new_item;
+
+ }
+ }
+ }
}
+sub post {
+
+ $form->isblank( "transdate", $locale->text('Invoice Date missing!') );
+ $form->isblank( "customer", $locale->text('Customer missing!') );
-sub print_and_post {
+ # if oldcustomer ne customer redo form
+ if ( &check_name(customer) ) {
+ &update;
+ exit;
+ }
+
+ &validate_items;
+
+ $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
+ $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
+
+ $form->error( $locale->text('Cannot post invoice for a closed period!') )
+ if ( $transdate <= $closedto );
+
+ $form->isblank( "exchangerate", $locale->text('Exchange rate missing!') )
+ if ( $form->{currency} ne $form->{defaultcurrency} );
+
+ for $i ( 1 .. $form->{paidaccounts} ) {
+ if ( $form->{"paid_$i"} ) {
+ $datepaid = $form->datetonum( \%myconfig, $form->{"datepaid_$i"} );
+
+ $form->isblank( "datepaid_$i",
+ $locale->text('Payment date missing!') );
+
+ $form->error(
+ $locale->text('Cannot post payment for a closed period!') )
+ if ( $datepaid <= $closedto );
- $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->{currency} ne $form->{defaultcurrency} ) {
+ $form->{"exchangerate_$i"} = $form->{exchangerate}
+ if ( $transdate == $datepaid );
+ $form->isblank( "exchangerate_$i",
+ $locale->text('Exchange rate for payment missing!') );
+ }
+ }
+ }
+
+ $form->{label} = $locale->text('Invoice');
- if (! $form->{repost}) {
- if ($form->{id}) {
- $form->{print_and_post} = 1;
- &repost;
- exit;
+ if ( !$form->{repost} ) {
+ if ( $form->{id} ) {
+ &repost;
+ exit;
+ }
}
- }
- $old_form = new Form;
- $form->{display_form} = "post";
- for (keys %$form) { $old_form->{$_} = $form->{$_} }
- $old_form->{rowcount}++;
+ ( $form->{AR} ) = split /--/, $form->{AR};
+ ( $form->{AR_paid} ) = split /--/, $form->{AR_paid};
- &print_form($old_form);
+ if ( IS->post_invoice( \%myconfig, \%$form ) ) {
+ $form->redirect(
+ $locale->text( 'Invoice [_1] posted!', $form->{invnumber} ) );
+ }
+ else {
+ $form->error( $locale->text('Cannot post invoice!') );
+ }
}
+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';
+
+ if ( !$form->{repost} ) {
+ if ( $form->{id} ) {
+ $form->{print_and_post} = 1;
+ &repost;
+ exit;
+ }
+ }
+
+ $old_form = new Form;
+ $form->{display_form} = "post";
+ for ( keys %$form ) { $old_form->{$_} = $form->{$_} }
+ $old_form->{rowcount}++;
+
+ &print_form($old_form);
+
+}
sub delete {
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
|;
- $form->{action} = "yes";
- $form->hide_form;
+ $form->{action} = "yes";
+ $form->hide_form;
- print qq|
-<h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
+ print qq|
+<h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
-<h4>|.$locale->text('Are you sure you want to delete Invoice Number [_1]?', $form->{invnumber}).qq|
+<h4>|
+ . $locale->text( 'Are you sure you want to delete Invoice Number [_1]?',
+ $form->{invnumber} )
+ . qq|
</h4>
<p>
-<button name="action" class="submit" type="submit" value="yes">|.$locale->text('Yes').qq|</button>
+<button name="action" class="submit" type="submit" value="yes">|
+ . $locale->text('Yes')
+ . qq|</button>
</form>
|;
-
}
-
-
sub yes {
- if (IS->delete_invoice(\%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool})) {
- $form->redirect($locale->text('Invoice deleted!'));
- } else {
- $form->error($locale->text('Cannot delete invoice!'));
- }
+ if (
+ IS->delete_invoice(
+ \%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool}
+ )
+ )
+ {
+ $form->redirect( $locale->text('Invoice deleted!') );
+ }
+ else {
+ $form->error( $locale->text('Cannot delete invoice!') );
+ }
}
-
diff --git a/bin/jc.pl b/bin/jc.pl
index 18153885..a5889c19 100644
--- a/bin/jc.pl
+++ b/bin/jc.pl
@@ -1,1944 +1,2235 @@
-#=====================================================================
-# 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 Error qw(:try);
-
-use LedgerSMB::Template;
-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->{description} ($ref->{description})</option>\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);
- }
-
- if (($form->{'media'} eq 'screen') and ($form->{'format'} eq 'html')) {
- my $template = LedgerSMB::Template->new(\%myconfig, $form->{'formname'}, 'HTML');
- try {
- $template->render($form);
- $form->header;
- print $template->{'output'};
- exit;
- } catch Error::Simple with {
- my $E = shift;
- $form->error($E->stacktrace);
- };
- }
- $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 Error qw(:try);
+
+use LedgerSMB::Template;
+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->{description} ($ref->{description})</option>\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 );
+ }
+
+ if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
+ {
+ my $template =
+ LedgerSMB::Template->new( \%myconfig, $form->{'formname'}, 'HTML' );
+ try {
+ $template->render($form);
+ $form->header;
+ print $template->{'output'};
+ exit;
+ }
+ catch Error::Simple with {
+ my $E = shift;
+ $form->error( $E->stacktrace );
+ };
+ }
+ $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/login.pl b/bin/login.pl
index 1df03b42..b9cfd65c 100644
--- a/bin/login.pl
+++ b/bin/login.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -34,7 +34,6 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#======================================================================
-
1;
use DBI;
use LedgerSMB::User;
@@ -45,56 +44,57 @@ use LedgerSMB::Session;
## will need this later when session_destroy will be used
#use LedgerSMB::Session;
-
$form = new Form;
-$locale = LedgerSMB::Locale->get_handle(${LedgerSMB::Sysconfig::language}) or
- $form->error(__FILE__.':'.__LINE__.": Locale not loaded: $!\n");
+$locale = LedgerSMB::Locale->get_handle( ${LedgerSMB::Sysconfig::language} )
+ or $form->error( __FILE__ . ':' . __LINE__ . ": Locale not loaded: $!\n" );
$locale->encoding('UTF-8');
$form->{charset} = 'UTF-8';
+
#$form->{charset} = $locale->encoding;
# customization
-if (-f "bin/custom/$form->{script}") {
- eval { require "bin/custom/$form->{script}"; };
- $form->error(__FILE__.':'.__LINE__.': '.$@) if ($@);
+if ( -f "bin/custom/$form->{script}" ) {
+ eval { require "bin/custom/$form->{script}"; };
+ $form->error( __FILE__ . ':' . __LINE__ . ': ' . $@ ) if ($@);
}
# per login customization
-if (-f "bin/custom/$form->{login}_$form->{script}") {
- eval { require "bin/custom/$form->{login}_$form->{script}"; };
- $form->error(__FILE__.':'.__LINE__.': '.$@) if ($@);
+if ( -f "bin/custom/$form->{login}_$form->{script}" ) {
+ eval { require "bin/custom/$form->{login}_$form->{script}"; };
+ $form->error( __FILE__ . ':' . __LINE__ . ': ' . $@ ) if ($@);
}
# window title bar, user info
-$form->{titlebar} = "LedgerSMB ".$locale->text('Version'). " $form->{version}";
+$form->{titlebar} =
+ "LedgerSMB " . $locale->text('Version') . " $form->{version}";
-if ($form->{action}) {
- $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}";
- &{ $form->{action} };
+if ( $form->{action} ) {
+ $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}";
+ &{ $form->{action} };
-} else {
- &login_screen;
}
-
+else {
+ &login_screen;
+}
1;
-
sub login_screen {
- $form->{stylesheet} = "ledgersmb.css";
- $form->{favicon} = "favicon.ico";
+ $form->{stylesheet} = "ledgersmb.css";
+ $form->{favicon} = "favicon.ico";
- $form->{endsession} = 1;
+ $form->{endsession} = 1;
- if ($form->{login}) {
- $sf = q|function sf() { document.login.password.focus(); }|;
- } else {
- $sf = q|function sf() { document.login.login.focus(); }|;
- }
+ if ( $form->{login} ) {
+ $sf = q|function sf() { document.login.password.focus(); }|;
+ }
+ else {
+ $sf = q|function sf() { document.login.login.focus(); }|;
+ }
- my $headeradd = qq|
+ my $headeradd = qq|
<script language="JavaScript" type="text/javascript">
<!--
var agt = navigator.userAgent.toLowerCase();
@@ -116,9 +116,9 @@ sub login_screen {
// End -->
</script>|;
- $form->header(1, $headeradd);
+ $form->header( 1, $headeradd );
- print qq|
+ print qq|
<body class="login" onload="jsp(); sf();">
<br /><br />
@@ -127,7 +127,9 @@ sub login_screen {
<tr>
<td class="login" align="center">
<a href="http://www.ledgersmb.org/" target="_top"><img src="images/ledgersmb.png" width="200" heith="100" border="0" alt="LedgerSMB Logo" /></a>
- <h1 class="login" align="center">|.$locale->text('Version').qq| $form->{version}</h1>
+ <h1 class="login" align="center">|
+ . $locale->text('Version')
+ . qq| $form->{version}</h1>
<p>
<form method="post" action="$form->{script}" name="login">
<table width="100%">
@@ -135,11 +137,11 @@ sub login_screen {
<td align="center">
<table>
<tr>
- <th align="right">|.$locale->text('Name').qq|</th>
+ <th align="right">| . $locale->text('Name') . qq|</th>
<td><input class="login" name="login" size="30" value="$form->{login}" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Password').qq|</th>
+ <th align="right">| . $locale->text('Password') . qq|</th>
<td><input class="login" type="password" name="password" size="30" /></td>
</tr>
</table>
@@ -149,31 +151,32 @@ sub login_screen {
</table>
<input type="hidden" name="path" value="$form->{path}" />
<input type="hidden" name="js" value="$form->{js}" />
- <button type="submit" name="action" value="login">|.$locale->text('Login').qq|</button>
+ <button type="submit" name="action" value="login">|
+ . $locale->text('Login')
+ . qq|</button>
</form>
</p>
</td>
</tr>
</table>
<p><a href="admin.pl"
- >|.$locale->text("Administrative login").qq|</a></p>
+ >| . $locale->text("Administrative login") . qq|</a></p>
</center>
</body>
</html>|;
}
-
sub selectdataset {
- my ($login) = @_;
+ my ($login) = @_;
- if (-f "css/ledgersmb.css") {
- $form->{stylesheet} = "ledgersmb.css";
- }
+ if ( -f "css/ledgersmb.css" ) {
+ $form->{stylesheet} = "ledgersmb.css";
+ }
- $form->header(1);
+ $form->header(1);
- print qq|
+ print qq|
<body class="login" onload="document.forms[0].password.focus()" />
<br /><br />
<center>
@@ -181,7 +184,9 @@ sub selectdataset {
<tr>
<td class="login" align="center">
<a href="http://www.ledgersmb.org/" target="_top"><img src="images/ledgersmb.png" width="100" heith="100" border="0" alt="LedgerSMB Logo" /></a>
- <h1 class="login" align="center">|.$locale->text('Version').qq| $form->{version}</h1>
+ <h1 class="login" align="center">|
+ . $locale->text('Version')
+ . qq| $form->{version}</h1>
<p>
<form method="post" action="$form->{script}">
<input type="hidden" name="beenthere" value="1" />
@@ -192,29 +197,32 @@ sub selectdataset {
<td align="center">
<table>
<tr>
- <th align="right">|.$locale->text('Name').qq|</th>
+ <th align="right">| . $locale->text('Name') . qq|</th>
<td>$form->{login}</td>
</tr>
<tr>
- <th align="right">|.$locale->text('Password').qq|</th>
+ <th align="right">| . $locale->text('Password') . qq|</th>
<td><input class="login" type="password" name="password" size="30" value="$form->{password}" /></td>
</tr>
<tr>
- <th align="right">|.$locale->text('Company').qq|</th>
+ <th align="right">| . $locale->text('Company') . qq|</th>
<td>|;
- $checked = "checked";
- foreach $login (sort { $login{$a} cmp $login{$b} } keys %{ $login }) {
- print qq| <br /><input class="login" type="radio" name="login" value="$login" $checked>$login{$login} |;
- $checked = "";
- }
+ $checked = "checked";
+ foreach $login ( sort { $login{$a} cmp $login{$b} } keys %{$login} ) {
+ print
+qq| <br /><input class="login" type="radio" name="login" value="$login" $checked>$login{$login} |;
+ $checked = "";
+ }
- print qq|
+ print qq|
</td>
</tr>
</table>
<br />
- <button type="submit" name="action" value="login">|.$locale->text('Login').qq|</button>
+ <button type="submit" name="action" value="login">|
+ . $locale->text('Login')
+ . qq|</button>
</td>
</tr>
</table>
@@ -228,101 +236,105 @@ sub selectdataset {
}
-
sub login {
- $form->{stylesheet} = "ledgersmb.css";
- $form->{favicon} = "favicon.ico";
-
- $form->error(__FILE__.':'.__LINE__.': '.$locale->text('You did not enter a name!')) unless ($form->{login});
+ $form->{stylesheet} = "ledgersmb.css";
+ $form->{favicon} = "favicon.ico";
+ $form->error( __FILE__ . ':' . __LINE__ . ': '
+ . $locale->text('You did not enter a name!') )
+ unless ( $form->{login} );
- if (!${LedgerSMB::Sysconfig::GLOBALDBH}){
- $locale->text("No GlobalDBH Configured or Could not Connect");
- }
- $user = LedgerSMB::User->new($form->{login});
+ if ( !${LedgerSMB::Sysconfig::GLOBALDBH} ) {
+ $locale->text("No GlobalDBH Configured or Could not Connect");
+ }
+ $user = LedgerSMB::User->new( $form->{login} );
- if (($errno = $user->login(\%$form)) <= -1) {
+ if ( ( $errno = $user->login( \%$form ) ) <= -1 ) {
- $errno *= -1;
- $err[1] = $locale->text('Access Denied!');
- $err[2] = $locale->text('Incorrect Dataset version!');
- $err[3] = $locale->text('Dataset is newer than version!');
+ $errno *= -1;
+ $err[1] = $locale->text('Access Denied!');
+ $err[2] = $locale->text('Incorrect Dataset version!');
+ $err[3] = $locale->text('Dataset is newer than version!');
- if ($errno == 4) {
- # upgrade dataset and log in again
- if (!$LedgerSMB::Sysconfig::db_autoupdate){
- $form->error(
- $locale->text("Dabase Version too Old")
- );
- }
+ if ( $errno == 4 ) {
- for (qw(dbname dbhost dbport dbdriver dbuser dbpasswd)) { $form->{$_} = $user->{$_} }
+ # upgrade dataset and log in again
+ if ( !$LedgerSMB::Sysconfig::db_autoupdate ) {
+ $form->error( $locale->text("Dabase Version too Old") );
+ }
- $form->{dbpasswd} = unpack 'u', $form->{dbpasswd};
+ for (qw(dbname dbhost dbport dbdriver dbuser dbpasswd)) {
+ $form->{$_} = $user->{$_};
+ }
- $form->{dbupdate} = "db$user->{dbname}";
- $form->{$form->{dbupdate}} = 1;
+ $form->{dbpasswd} = unpack 'u', $form->{dbpasswd};
- $form->header;
- print qq|<body>|;
- print $locale->text('Upgrading to Version [_1] ...', $form->{version});
+ $form->{dbupdate} = "db$user->{dbname}";
+ $form->{ $form->{dbupdate} } = 1;
+ $form->header;
+ print qq|<body>|;
+ print $locale->text( 'Upgrading to Version [_1] ...',
+ $form->{version} );
- $user->dbupdate(\%$form);
+ $user->dbupdate( \%$form );
- # remove lock
- #unlink "${LedgerSMB::Sysconfig::userspath}/nologin";
+ # remove lock
+ #unlink "${LedgerSMB::Sysconfig::userspath}/nologin";
- print $locale->text('done');
+ print $locale->text('done');
- print "<p><a href=\"menu.pl?login=$form->{login}&amp;sessionid=$form->{sessionid}&amp;path=$form->{path}&amp;action=display&amp;main=company_logo&amp;js=$form->{js}>\">".$locale->text('Continue')."</a>";
- print qq|</body>|;
- exit;
- }
+ print
+"<p><a href=\"menu.pl?login=$form->{login}&amp;sessionid=$form->{sessionid}&amp;path=$form->{path}&amp;action=display&amp;main=company_logo&amp;js=$form->{js}>\">"
+ . $locale->text('Continue') . "</a>";
+ print qq|</body>|;
+ exit;
+ }
- $form->error(__FILE__.':'.__LINE__.': '.$err[$errno]);
- }
+ $form->error( __FILE__ . ':' . __LINE__ . ': ' . $err[$errno] );
+ }
- # made it this far, setup callback for the menu
- $form->{callback} = "menu.pl?action=display&password=$form->{password}";
- for (qw(login path js)) { $form->{callback} .= "&$_=$form->{$_}" }
+ # made it this far, setup callback for the menu
+ $form->{callback} = "menu.pl?action=display&password=$form->{password}";
+ for (qw(login path js)) { $form->{callback} .= "&$_=$form->{$_}" }
- # check for recurring transactions
- if ($user->{acs} !~ /Recurring Transactions/) {
+ # check for recurring transactions
+ if ( $user->{acs} !~ /Recurring Transactions/ ) {
- if ($user->check_recurring(\%$form)) {
- $form->{callback} .= "&main=recurring_transactions";
- } else {
- $form->{callback} .= "&main=company_logo";
- }
+ if ( $user->check_recurring( \%$form ) ) {
+ $form->{callback} .= "&main=recurring_transactions";
+ }
+ else {
+ $form->{callback} .= "&main=company_logo";
+ }
- } else {
+ }
+ else {
- if ($user->{role} eq 'user') {
- $form->{callback} .= "&main=company_logo";
- } else {
+ if ( $user->{role} eq 'user' ) {
+ $form->{callback} .= "&main=company_logo";
+ }
+ else {
- if ($user->check_recurring(\%$form)) {
- $form->{callback} .= "&main=recurring_transactions";
- } else {
- $form->{callback} .= "&main=company_logo";
- }
- }
- }
+ if ( $user->check_recurring( \%$form ) ) {
+ $form->{callback} .= "&main=recurring_transactions";
+ }
+ else {
+ $form->{callback} .= "&main=company_logo";
+ }
+ }
+ }
- Session::session_create($form);
- $form->redirect;
+ Session::session_create($form);
+ $form->redirect;
}
-
-
sub logout {
- $form->{callback} = "";
- $form->{endsession} = 1;
- Session::session_destroy($form);
+ $form->{callback} = "";
+ $form->{endsession} = 1;
+ Session::session_destroy($form);
$form->redirect;
}
-
diff --git a/bin/menu.pl b/bin/menu.pl
index 9b426b5f..1d44caaf 100644
--- a/bin/menu.pl
+++ b/bin/menu.pl
@@ -1,9 +1,9 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
#
-#
+#
# See COPYRIGHT file for copyright information
#======================================================================
#
@@ -19,42 +19,48 @@ $menufile = "menu.ini";
use LedgerSMB::Menu;
1;
-# end of main
+# end of main
sub display {
- if($form->{lynx}){
-
- $menu = new Menu "$menufile";
- $menu->add_file("custom_$menufile") if -f "custom_$menufile";
- $menu->add_file("$form->{login}_$menufile") if -f "$form->{login}_$menufile";
+ if ( $form->{lynx} ) {
- @menuorder = $menu->access_control(\%myconfig);
+ $menu = new Menu "$menufile";
+ $menu->add_file("custom_$menufile") if -f "custom_$menufile";
+ $menu->add_file("$form->{login}_$menufile")
+ if -f "$form->{login}_$menufile";
- $form->{title} = "LedgerSMB $form->{version}";
- $form->header(1);
+ @menuorder = $menu->access_control( \%myconfig );
- $offset = int (21 - $#menuorder)/2;
+ $form->{title} = "LedgerSMB $form->{version}";
+ $form->header(1);
- print "<pre>";
- print "\n" x $offset;
- print "</pre>";
- print qq|<center><table>|;
+ $offset = int( 21 - $#menuorder ) / 2;
- map { print "<tr><td>".$menu->menuitem(\%myconfig, \%$form, $_).$locale->text($_).qq|</a></td></tr>|; } @menuorder;
+ print "<pre>";
+ print "\n" x $offset;
+ print "</pre>";
+ print qq|<center><table>|;
- print qq'</table></body></html>';
+ map {
+ print "<tr><td>"
+ . $menu->menuitem( \%myconfig, \%$form, $_ )
+ . $locale->text($_)
+ . qq|</a></td></tr>|;
+ } @menuorder;
+ print qq'</table></body></html>';
- } else {
+ }
+ else {
- $menuwidth = ($ENV{HTTP_USER_AGENT} =~ /links/i) ? "240" : "155";
- $menuwidth = $myconfig{menuwidth} if $myconfig{menuwidth};
+ $menuwidth = ( $ENV{HTTP_USER_AGENT} =~ /links/i ) ? "240" : "155";
+ $menuwidth = $myconfig{menuwidth} if $myconfig{menuwidth};
- $form->header(!$form->{duplicate});
+ $form->header( !$form->{duplicate} );
- print qq|
+ print qq|
<frameset cols="$menuwidth,*" border="1">
<frame name="acc_menu" src="menu.pl?login=$form->{login}&amp;sessionid=$form->{sessionid}&amp;action=acc_menu&amp;path=$form->{path}&amp;js=$form->{js}" />
<frame name="main_window" src="locale/html/splash.html" />
@@ -62,27 +68,27 @@ sub display {
</html>
|;
- }
+ }
}
-
-
sub acc_menu {
- if($form->{lynx}){
+ if ( $form->{lynx} ) {
- &section_menu;
+ &section_menu;
- } else {
+ }
+ else {
- my $menu = new Menu "$menufile";
- $menu->add_file("custom_$menufile") if -f "custom_$menufile";
- $menu->add_file("$form->{login}_$menufile") if -f "$form->{login}_$menufile";
+ my $menu = new Menu "$menufile";
+ $menu->add_file("custom_$menufile") if -f "custom_$menufile";
+ $menu->add_file("$form->{login}_$menufile")
+ if -f "$form->{login}_$menufile";
- $form->{title} = $locale->text('Accounting Menu');
+ $form->{title} = $locale->text('Accounting Menu');
- my $headeradd = q|
+ my $headeradd = q|
<script type="text/javascript">
function SwitchMenu(obj) {
@@ -105,247 +111,268 @@ sub acc_menu {
document.onselectstart = new Function("return false");
</script>|;
- $form->header(undef, $headeradd);
- print q|
+ $form->header( undef, $headeradd );
+ print q|
<body class="menu">
<img class="cornerlogo" src="images/ledgersmb_small.png" width="100" height="50" border="1" alt="LedgerSMB" />
|;
- if ($form->{js}) {
- &js_menu($menu);
- } else {
- &section_menu($menu);
- }
+ if ( $form->{js} ) {
+ &js_menu($menu);
+ }
+ else {
+ &section_menu($menu);
+ }
- print q|
+ print q|
</body>
</html>
|;
- }
+ }
}
-
sub section_menu {
- if($form->{lynx}){
+ if ( $form->{lynx} ) {
- $menu = new Menu "$menufile", $form->{level};
+ $menu = new Menu "$menufile", $form->{level};
- $menu->add_file("custom_$menufile") if -f "custom_$menufile";
- $menu->add_file("$form->{login}_$menufile") if -f "$form->{login}_$menufile";
+ $menu->add_file("custom_$menufile") if -f "custom_$menufile";
+ $menu->add_file("$form->{login}_$menufile")
+ if -f "$form->{login}_$menufile";
- # build tiered menus
- @menuorder = $menu->access_control(\%myconfig, $form->{level});
+ # build tiered menus
+ @menuorder = $menu->access_control( \%myconfig, $form->{level} );
- foreach $item (@menuorder) {
- $a = $item;
- $item =~ s/^$form->{level}--//;
- push @neworder, $a unless ($item =~ /--/);
- }
+ foreach $item (@menuorder) {
+ $a = $item;
+ $item =~ s/^$form->{level}--//;
+ push @neworder, $a unless ( $item =~ /--/ );
+ }
- @menuorder = @neworder;
+ @menuorder = @neworder;
- $level = $form->{level};
- $level =~ s/--/ /g;
+ $level = $form->{level};
+ $level =~ s/--/ /g;
- $form->{title} = $locale->text($level);
- $form->header;
+ $form->{title} = $locale->text($level);
+ $form->header;
- $offset = int (21 - $#menuorder)/2;
+ $offset = int( 21 - $#menuorder ) / 2;
- print "<pre>";
- print "\n" x $offset;
- print "</pre>";
- print qq|<center><table>|;
+ print "<pre>";
+ print "\n" x $offset;
+ print "</pre>";
+ print qq|<center><table>|;
- foreach $item (@menuorder) {
- $label = $item;
- $label =~ s/$form->{level}--//g;
+ foreach $item (@menuorder) {
+ $label = $item;
+ $label =~ s/$form->{level}--//g;
- # remove target
- $menu->{$item}{target} = "";
+ # remove target
+ $menu->{$item}{target} = "";
- print "<tr><td>".$menu->menuitem(\%myconfig, \%$form, $item, $form->{level}).$locale->text($label)."</a></td></tr>";
- }
+ print "<tr><td>"
+ . $menu->menuitem( \%myconfig, \%$form, $item, $form->{level} )
+ . $locale->text($label)
+ . "</a></td></tr>";
+ }
- print qq'</table></body></html>';
+ print qq'</table></body></html>';
- } else {
+ }
+ else {
- my ($menu, $level) = @_;
+ my ( $menu, $level ) = @_;
- # build tiered menus
- my @menuorder = $menu->access_control(\%myconfig, $level);
+ # build tiered menus
+ my @menuorder = $menu->access_control( \%myconfig, $level );
- while (@menuorder) {
- $item = shift @menuorder;
- $label = $item;
- $label =~ s/$level--//g;
+ while (@menuorder) {
+ $item = shift @menuorder;
+ $label = $item;
+ $label =~ s/$level--//g;
- my $spacer = "&nbsp;" x (($item =~ s/--/--/g) * 2);
+ my $spacer = "&nbsp;" x ( ( $item =~ s/--/--/g ) * 2 );
- $label =~ s/.*--//g;
- $label = $locale->text($label);
- $label =~ s/ /&nbsp;/g if $label !~ /<img /i;
+ $label =~ s/.*--//g;
+ $label = $locale->text($label);
+ $label =~ s/ /&nbsp;/g if $label !~ /<img /i;
- $menu->{$item}{target} = "main_window" unless $menu->{$item}{target};
+ $menu->{$item}{target} = "main_window"
+ unless $menu->{$item}{target};
- if ($menu->{$item}{submenu}) {
+ if ( $menu->{$item}{submenu} ) {
- $menu->{$item}{$item} = !$form->{$item};
+ $menu->{$item}{$item} = !$form->{$item};
- if ($form->{level} && $item =~ $form->{level}) {
+ if ( $form->{level} && $item =~ $form->{level} ) {
- # expand menu
- print qq|<br />\n$spacer|.$menu->menuitem(\%myconfig, \%$form, $item, $level).qq|$label</a>|;
+ # expand menu
+ print qq|<br />\n$spacer|
+ . $menu->menuitem( \%myconfig, \%$form, $item, $level )
+ . qq|$label</a>|;
- # remove same level items
- map { shift @menuorder } grep /^$item/, @menuorder;
+ # remove same level items
+ map { shift @menuorder } grep /^$item/, @menuorder;
- &section_menu($menu, $item);
+ &section_menu( $menu, $item );
- print qq|<br />\n|;
+ print qq|<br />\n|;
- } else {
+ }
+ else {
- print qq|<br />\n$spacer|.$menu->menuitem(\%myconfig, \%$form, $item, $level).qq|$label&nbsp;...</a>|;
+ print qq|<br />\n$spacer|
+ . $menu->menuitem( \%myconfig, \%$form, $item, $level )
+ . qq|$label&nbsp;...</a>|;
- # remove same level items
- map { shift @menuorder } grep /^$item/, @menuorder;
+ # remove same level items
+ map { shift @menuorder } grep /^$item/, @menuorder;
- }
+ }
- } else {
+ }
+ else {
- if ($menu->{$item}{module}) {
+ if ( $menu->{$item}{module} ) {
- print qq|<br />\n$spacer|.$menu->menuitem(\%myconfig, \%$form, $item, $level).qq|$label</a>|;
+ print qq|<br />\n$spacer|
+ . $menu->menuitem( \%myconfig, \%$form, $item, $level )
+ . qq|$label</a>|;
- } else {
+ }
+ else {
- $form->{tag}++;
- print qq|<a name="id$form->{tag}"></a><p><b>$label</b></p>|;
+ $form->{tag}++;
+ print qq|<a name="id$form->{tag}"></a><p><b>$label</b></p>|;
- &section_menu($menu, $item);
+ &section_menu( $menu, $item );
- print qq|<br />\n|;
+ print qq|<br />\n|;
- }
- }
- }
- }
+ }
+ }
+ }
+ }
}
-
sub js_menu {
- my ($menu, $level) = @_;
+ my ( $menu, $level ) = @_;
- print qq| <div id="div_$menu_$level"> |;
+ print qq| <div id="div_$menu_$level"> |;
- # build tiered menus
- my @menuorder = $menu->access_control(\%myconfig, $level);
+ # build tiered menus
+ my @menuorder = $menu->access_control( \%myconfig, $level );
- while (@menuorder){
- $i++;
- $item = shift @menuorder;
- $label = $item;
- $label =~ s/.*--//g;
- $label = $locale->text($label);
+ while (@menuorder) {
+ $i++;
+ $item = shift @menuorder;
+ $label = $item;
+ $label =~ s/.*--//g;
+ $label = $locale->text($label);
- $menu->{$item}{target} = "main_window" unless $menu->{$item}{target};
+ $menu->{$item}{target} = "main_window" unless $menu->{$item}{target};
- if ($menu->{$item}{submenu}) {
+ if ( $menu->{$item}{submenu} ) {
- $display = "display: none;" unless $level eq ' ';
+ $display = "display: none;" unless $level eq ' ';
- print qq|
+ print qq|
<div id="menu$i" class="menuOut" onclick="SwitchMenu('sub$i')" onmouseover="ChangeClass('menu$i','menuOver')" onmouseout="ChangeClass('menu$i','menuOut')">$label</div>
<div class="submenu" id="sub$i" style="$display">|;
- # remove same level items
- map { shift @menuorder } grep /^$item/, @menuorder;
+ # remove same level items
+ map { shift @menuorder } grep /^$item/, @menuorder;
- &js_menu($menu, $item);
+ &js_menu( $menu, $item );
- print qq|
+ print qq|
</div>
|;
- } else {
+ }
+ else {
- if ($menu->{$item}{module}) {
+ if ( $menu->{$item}{module} ) {
- if ($level eq "") {
- print qq|<div id="menu$i" class="menuOut" onmouseover="ChangeClass('menu$i','menuOver')" onmouseout="ChangeClass('menu$i','menuOut')"> |.
- $menu->menuitem(\%myconfig, \%$form, $item, $level).qq|$label</a></div>|;
+ if ( $level eq "" ) {
+ print
+qq|<div id="menu$i" class="menuOut" onmouseover="ChangeClass('menu$i','menuOver')" onmouseout="ChangeClass('menu$i','menuOut')"> |
+ . $menu->menuitem( \%myconfig, \%$form, $item, $level )
+ . qq|$label</a></div>|;
- # remove same level items
- map { shift @menuorder } grep /^$item/, @menuorder;
+ # remove same level items
+ map { shift @menuorder } grep /^$item/, @menuorder;
- &js_menu($menu, $item);
+ &js_menu( $menu, $item );
- } else {
+ }
+ else {
- print qq|<div class="submenu"> |.
- $menu->menuitem(\%myconfig, \%$form, $item, $level).qq|$label</a></div>|;
- }
+ print qq|<div class="submenu"> |
+ . $menu->menuitem( \%myconfig, \%$form, $item, $level )
+ . qq|$label</a></div>|;
+ }
- } else {
+ }
+ else {
- $display = "display: none;" unless $item eq ' ';
+ $display = "display: none;" unless $item eq ' ';
- print qq|
+ print qq|
<div id="menu$i" class="menuOut" onclick="SwitchMenu('sub$i')" onmouseover="ChangeClass('menu$i','menuOver')" onmouseout="ChangeClass('menu$i','menuOut')">$label</div>
<div class="submenu" id="sub$i" style="$display">|;
- &js_menu($menu, $item);
+ &js_menu( $menu, $item );
- print qq| </div> |;
+ print qq| </div> |;
- }
+ }
- }
+ }
- }
+ }
- print qq| </div> |;
+ print qq| </div> |;
}
-
sub menubar {
- if($form->{lynx}){
+ if ( $form->{lynx} ) {
- $menu = new Menu "$menufile", "";
+ $menu = new Menu "$menufile", "";
- # build menubar
- @menuorder = $menu->access_control(\%myconfig, "");
+ # build menubar
+ @menuorder = $menu->access_control( \%myconfig, "" );
- @neworder = ();
- map { push @neworder, $_ unless ($_ =~ /--/) } @menuorder;
- @menuorder = @neworder;
+ @neworder = ();
+ map { push @neworder, $_ unless ( $_ =~ /--/ ) } @menuorder;
+ @menuorder = @neworder;
- print "<p>";
- $form->{script} = "menu.pl";
+ print "<p>";
+ $form->{script} = "menu.pl";
- print "| ";
+ print "| ";
- foreach $item (@menuorder) {
- $label = $item;
+ foreach $item (@menuorder) {
+ $label = $item;
- # remove target
- $menu->{$item}{target} = "";
+ # remove target
+ $menu->{$item}{target} = "";
- print $menu->menuitem(\%myconfig, \%$form, $item, "").$locale->text($label)."</a> | ";
- }
+ print $menu->menuitem( \%myconfig, \%$form, $item, "" )
+ . $locale->text($label)
+ . "</a> | ";
+ }
- } else {
+ }
+ else {
- 1;
- }
+ 1;
+ }
}
-
diff --git a/bin/oe.pl b/bin/oe.pl
index 320a7fa8..75309ec7 100644
--- a/bin/oe.pl
+++ b/bin/oe.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -39,7 +39,6 @@
#
#======================================================================
-
use LedgerSMB::OE;
use LedgerSMB::IR;
use LedgerSMB::IS;
@@ -50,396 +49,470 @@ use LedgerSMB::Locale;
require "bin/arap.pl";
require "bin/io.pl";
-
1;
-# end of main
+# end of main
sub add {
- if ($form->{type} eq 'purchase_order') {
- $form->{title} = $locale->text('Add Purchase Order');
- $form->{vc} = 'vendor';
- }
- if ($form->{type} eq 'sales_order') {
- $form->{title} = $locale->text('Add Sales Order');
- $form->{vc} = 'customer';
- }
- if ($form->{type} eq 'request_quotation') {
- $form->{title} = $locale->text('Add Request for Quotation');
- $form->{vc} = 'vendor';
- }
- if ($form->{type} eq 'sales_quotation') {
- $form->{title} = $locale->text('Add Quotation');
- $form->{vc} = 'customer';
- }
-
- $form->{callback} = "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}" unless $form->{callback};
-
- $form->{rowcount} = 0;
-
- &order_links;
- &prepare_order;
- &display_form;
+ if ( $form->{type} eq 'purchase_order' ) {
+ $form->{title} = $locale->text('Add Purchase Order');
+ $form->{vc} = 'vendor';
+ }
+ if ( $form->{type} eq 'sales_order' ) {
+ $form->{title} = $locale->text('Add Sales Order');
+ $form->{vc} = 'customer';
+ }
+ if ( $form->{type} eq 'request_quotation' ) {
+ $form->{title} = $locale->text('Add Request for Quotation');
+ $form->{vc} = 'vendor';
+ }
+ if ( $form->{type} eq 'sales_quotation' ) {
+ $form->{title} = $locale->text('Add Quotation');
+ $form->{vc} = 'customer';
+ }
-}
+ $form->{callback} =
+"$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
+ $form->{rowcount} = 0;
+
+ &order_links;
+ &prepare_order;
+ &display_form;
-sub edit {
-
- if ($form->{type} =~ /(purchase_order|bin_list)/) {
- $form->{title} = $locale->text('Edit Purchase Order');
- $form->{vc} = 'vendor';
- $form->{type} = 'purchase_order';
- }
- if ($form->{type} =~ /((sales|work)_order|(packing|pick)_list)/) {
- $form->{title} = $locale->text('Edit Sales Order');
- $form->{vc} = 'customer';
- $form->{type} = 'sales_order';
- }
- if ($form->{type} eq 'request_quotation') {
- $form->{title} = $locale->text('Edit Request for Quotation');
- $form->{vc} = 'vendor';
- }
- if ($form->{type} eq 'sales_quotation') {
- $form->{title} = $locale->text('Edit Quotation');
- $form->{vc} = 'customer';
- }
-
- &order_links;
- &prepare_order;
- &display_form;
-
}
+sub edit {
+
+ if ( $form->{type} =~ /(purchase_order|bin_list)/ ) {
+ $form->{title} = $locale->text('Edit Purchase Order');
+ $form->{vc} = 'vendor';
+ $form->{type} = 'purchase_order';
+ }
+ if ( $form->{type} =~ /((sales|work)_order|(packing|pick)_list)/ ) {
+ $form->{title} = $locale->text('Edit Sales Order');
+ $form->{vc} = 'customer';
+ $form->{type} = 'sales_order';
+ }
+ if ( $form->{type} eq 'request_quotation' ) {
+ $form->{title} = $locale->text('Edit Request for Quotation');
+ $form->{vc} = 'vendor';
+ }
+ if ( $form->{type} eq 'sales_quotation' ) {
+ $form->{title} = $locale->text('Edit Quotation');
+ $form->{vc} = 'customer';
+ }
+
+ &order_links;
+ &prepare_order;
+ &display_form;
+}
sub order_links {
- # retrieve order/quotation
- OE->retrieve(\%myconfig, \%$form);
+ # retrieve order/quotation
+ OE->retrieve( \%myconfig, \%$form );
+
+ # get customer/vendor
+ $form->all_vc( \%myconfig, $form->{vc},
+ ( $form->{vc} eq 'customer' ) ? "AR" : "AP",
+ undef, $form->{transdate}, 1 );
+
+ # currencies
+ @curr = split /:/, $form->{currencies};
+ $form->{defaultcurrency} = $curr[0];
+ chomp $form->{defaultcurrency};
+ $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
+
+ for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
+
+ $form->{oldlanguage_code} = $form->{language_code};
+
+ $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|;
+ }
+ }
+ }
- # get customer/vendor
- $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP", undef, $form->{transdate}, 1);
-
- # currencies
- @curr = split /:/, $form->{currencies};
- $form->{defaultcurrency} = $curr[0];
- chomp $form->{defaultcurrency};
- $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
-
- for (@curr) { $form->{selectcurrency} .= "<option>$_\n" }
+ if ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} = "<option>\n";
+ for ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} .=
+qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
+ }
+ }
- $form->{oldlanguage_code} = $form->{language_code};
-
- $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|;
- }
- }
- }
-
- if (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} = "<option>\n";
- for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
- }
-
- if (@{ $form->{"all_$form->{vc}"} }) {
- unless ($form->{"$form->{vc}_id"}) {
- $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
- }
- }
-
- for (qw(terms taxincluded)) { $temp{$_} = $form->{$_} }
- $form->{shipto} = 1 if $form->{id};
-
- # get customer / vendor
- AA->get_name(\%myconfig, \%$form);
-
- if ($form->{id}) {
- for (qw(terms taxincluded)) { $form->{$_} = $temp{$_} }
- }
-
- ($form->{$form->{vc}}) = split /--/, $form->{$form->{vc}};
- $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
-
- # build selection list
- $form->{"select$form->{vc}"} = "";
- if (@{ $form->{"all_$form->{vc}"} }) {
- $form->{$form->{vc}} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
- for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
-
- # departments
- if (@{ $form->{all_department} }) {
- $form->{selectdepartment} = "<option>\n";
- $form->{department} = "$form->{department}--$form->{department_id}" if $form->{department_id};
-
- for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
- }
-
- $form->{employee} = "$form->{employee}--$form->{employee_id}";
-
- # sales staff
- if (@{ $form->{all_employee} }) {
- $form->{selectemployee} = "";
- for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
-
- if (@{ $form->{all_language} }) {
- $form->{selectlanguage} = "<option>\n";
- for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
- }
-
- # forex
- $form->{forex} = $form->{exchangerate};
-
-}
+ if ( @{ $form->{"all_$form->{vc}"} } ) {
+ unless ( $form->{"$form->{vc}_id"} ) {
+ $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
+ }
+ }
+ for (qw(terms taxincluded)) { $temp{$_} = $form->{$_} }
+ $form->{shipto} = 1 if $form->{id};
-sub prepare_order {
+ # get customer / vendor
+ AA->get_name( \%myconfig, \%$form );
- $form->{format} = "postscript" if $myconfig{printer};
- $form->{media} = $myconfig{printer};
- $form->{formname} = $form->{type};
- $form->{sortby} ||= "runningnumber";
- $form->{currency} =~ s/ //g;
- $form->{oldcurrency} = $form->{currency};
-
- if ($form->{id}) {
-
- for (qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact)) { $form->{$_} = $form->quote($form->{$_}) }
-
- foreach $ref (@{ $form->{form_details} } ) {
- $i++;
- for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
-
- $form->{"projectnumber_$i"} = qq|$ref->{projectnumber}--$ref->{project_id}| if $ref->{project_id};
- $form->{"partsgroup_$i"} = qq|$ref->{partsgroup}--$ref->{partsgroup_id}| if $ref->{partsgroup_id};
-
- $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
-
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
-
- for (map { "${_}_$i" } qw(sellprice listprice)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces) }
-
- ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
-
- $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces);
-
- $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
- $form->{"oldqty_$i"} = $form->{"qty_$i"};
-
- for (qw(partnumber sku description unit)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
- $form->{rowcount} = $i;
- }
- }
-
- $form->{oldtransdate} = $form->{transdate};
-
- if ($form->{type} eq 'sales_quotation') {
- if (! $form->{readonly}) {
- $form->{readonly} = 1 if $myconfig{acs} =~ /Quotations--Quotation/;
- }
-
- $form->{selectformname} = qq|<option value="sales_quotation">|.$locale->text('Quotation');
- }
-
- if ($form->{type} eq 'request_quotation') {
- if (! $form->{readonly}) {
- $form->{readonly} = 1 if $myconfig{acs} =~ /Quotations--RFQ/;
+ if ( $form->{id} ) {
+ for (qw(terms taxincluded)) { $form->{$_} = $temp{$_} }
+ }
+
+ ( $form->{ $form->{vc} } ) = split /--/, $form->{ $form->{vc} };
+ $form->{"old$form->{vc}"} =
+ qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
+
+ # build selection list
+ $form->{"select$form->{vc}"} = "";
+ if ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{ $form->{vc} } =
+ qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
+ for ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{"select$form->{vc}"} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
}
-
- $form->{selectformname} = qq|<option value="request_quotation">|.$locale->text('RFQ');
- }
-
- if ($form->{type} eq 'sales_order') {
- if (! $form->{readonly}) {
- $form->{readonly} = 1 if $myconfig{acs} =~ /Order Entry--Sales Order/;
- }
-
- $form->{selectformname} = qq|<option value="sales_order">|.$locale->text('Sales Order').qq|
- <option value="work_order">|.$locale->text('Work Order').qq|
- <option value="pick_list">|.$locale->text('Pick List').qq|
- <option value="packing_list">|.$locale->text('Packing List');
- }
-
- if ($form->{type} eq 'purchase_order') {
- if (! $form->{readonly}) {
- $form->{readonly} = 1 if $myconfig{acs} =~ /Order Entry--Purchase Order/;
- }
-
- $form->{selectformname} = qq|<option value="purchase_order">|.$locale->text('Purchase Order').qq|
- <option value="bin_list">|.$locale->text('Bin List');
- }
-
- if ($form->{type} eq 'ship_order') {
- $form->{selectformname} = qq|<option value="pick_list">|.$locale->text('Pick List').qq|
- <option value="packing_list">|.$locale->text('Packing List');
- }
-
- if ($form->{type} eq 'receive_order') {
- $form->{selectformname} = qq|<option value="bin_list">|.$locale->text('Bin List');
- }
+
+ # departments
+ if ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} = "<option>\n";
+ $form->{department} = "$form->{department}--$form->{department_id}"
+ if $form->{department_id};
+
+ for ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+ }
+
+ $form->{employee} = "$form->{employee}--$form->{employee_id}";
+
+ # sales staff
+ if ( @{ $form->{all_employee} } ) {
+ $form->{selectemployee} = "";
+ for ( @{ $form->{all_employee} } ) {
+ $form->{selectemployee} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
+
+ if ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} = "<option>\n";
+ for ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} .=
+ qq|<option value="$_->{code}">$_->{description}\n|;
+ }
+ }
+
+ # forex
+ $form->{forex} = $form->{exchangerate};
}
+sub prepare_order {
+
+ $form->{format} = "postscript" if $myconfig{printer};
+ $form->{media} = $myconfig{printer};
+ $form->{formname} = $form->{type};
+ $form->{sortby} ||= "runningnumber";
+ $form->{currency} =~ s/ //g;
+ $form->{oldcurrency} = $form->{currency};
+
+ if ( $form->{id} ) {
+
+ for (
+ qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact)
+ )
+ {
+ $form->{$_} = $form->quote( $form->{$_} );
+ }
+
+ foreach $ref ( @{ $form->{form_details} } ) {
+ $i++;
+ for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
+
+ $form->{"projectnumber_$i"} =
+ qq|$ref->{projectnumber}--$ref->{project_id}|
+ if $ref->{project_id};
+ $form->{"partsgroup_$i"} =
+ qq|$ref->{partsgroup}--$ref->{partsgroup_id}|
+ if $ref->{partsgroup_id};
+
+ $form->{"discount_$i"} =
+ $form->format_amount( \%myconfig, $form->{"discount_$i"} * 100 );
+
+ ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ for ( map { "${_}_$i" } qw(sellprice listprice) ) {
+ $form->{$_} =
+ $form->format_amount( \%myconfig, $form->{$_},
+ $decimalplaces );
+ }
+
+ ($dec) = ( $form->{"lastcost_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+
+ $form->{"lastcost_$i"} =
+ $form->format_amount( \%myconfig, $form->{"lastcost_$i"},
+ $decimalplaces );
+
+ $form->{"qty_$i"} =
+ $form->format_amount( \%myconfig, $form->{"qty_$i"} );
+ $form->{"oldqty_$i"} = $form->{"qty_$i"};
+
+ for (qw(partnumber sku description unit)) {
+ $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} );
+ }
+ $form->{rowcount} = $i;
+ }
+ }
+
+ $form->{oldtransdate} = $form->{transdate};
+
+ if ( $form->{type} eq 'sales_quotation' ) {
+ if ( !$form->{readonly} ) {
+ $form->{readonly} = 1 if $myconfig{acs} =~ /Quotations--Quotation/;
+ }
+
+ $form->{selectformname} =
+ qq|<option value="sales_quotation">| . $locale->text('Quotation');
+ }
+
+ if ( $form->{type} eq 'request_quotation' ) {
+ if ( !$form->{readonly} ) {
+ $form->{readonly} = 1 if $myconfig{acs} =~ /Quotations--RFQ/;
+ }
+
+ $form->{selectformname} =
+ qq|<option value="request_quotation">| . $locale->text('RFQ');
+ }
+
+ if ( $form->{type} eq 'sales_order' ) {
+ if ( !$form->{readonly} ) {
+ $form->{readonly} = 1
+ if $myconfig{acs} =~ /Order Entry--Sales Order/;
+ }
+
+ $form->{selectformname} =
+ qq|<option value="sales_order">|
+ . $locale->text('Sales Order') . qq|
+ <option value="work_order">| . $locale->text('Work Order') . qq|
+ <option value="pick_list">| . $locale->text('Pick List') . qq|
+ <option value="packing_list">| . $locale->text('Packing List');
+ }
+
+ if ( $form->{type} eq 'purchase_order' ) {
+ if ( !$form->{readonly} ) {
+ $form->{readonly} = 1
+ if $myconfig{acs} =~ /Order Entry--Purchase Order/;
+ }
+
+ $form->{selectformname} =
+ qq|<option value="purchase_order">|
+ . $locale->text('Purchase Order') . qq|
+ <option value="bin_list">| . $locale->text('Bin List');
+ }
+
+ if ( $form->{type} eq 'ship_order' ) {
+ $form->{selectformname} =
+ qq|<option value="pick_list">|
+ . $locale->text('Pick List') . qq|
+ <option value="packing_list">| . $locale->text('Packing List');
+ }
+
+ if ( $form->{type} eq 'receive_order' ) {
+ $form->{selectformname} =
+ qq|<option value="bin_list">| . $locale->text('Bin List');
+ }
+
+}
sub form_header {
- $checkedopen = ($form->{closed}) ? "" : "checked";
- $checkedclosed = ($form->{closed}) ? "checked" : "";
+ $checkedopen = ( $form->{closed} ) ? "" : "checked";
+ $checkedclosed = ( $form->{closed} ) ? "checked" : "";
- if ($form->{id}) {
- $openclosed = qq|
+ if ( $form->{id} ) {
+ $openclosed = qq|
<tr>
- <th nowrap align=right><input name=closed type=radio class=radio value=0 $checkedopen> |.$locale->text('Open').qq|</th>
- <th nowrap align=left><input name=closed type=radio class=radio value=1 $checkedclosed> |.$locale->text('Closed').qq|</th>
+ <th nowrap align=right><input name=closed type=radio class=radio value=0 $checkedopen> |
+ . $locale->text('Open')
+ . qq|</th>
+ <th nowrap align=left><input name=closed type=radio class=radio value=1 $checkedclosed> |
+ . $locale->text('Closed')
+ . qq|</th>
</tr>
|;
- }
+ }
- # set option selected
- $form->{selectcurrency} =~ s/ selected//;
- $form->{selectcurrency} =~ s/option>\Q$form->{currency}\E/option selected>$form->{currency}/;
-
- for ("$form->{vc}", "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|
+ # set option selected
+ $form->{selectcurrency} =~ s/ selected//;
+ $form->{selectcurrency} =~
+ s/option>\Q$form->{currency}\E/option selected>$form->{currency}/;
+
+ for ( "$form->{vc}", "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}</td>
+ 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}</td>
<input type=hidden name=exchangerate value=$form->{exchangerate}>
|;
- } else {
- $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td><input name=exchangerate size=10 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|
+ $exchangerate .= qq|
<input type=hidden name=forex value=$form->{forex}>
</tr>
|;
+ $vclabel = ucfirst $form->{vc};
+ $vclabel = $locale->text($vclabel);
-
- $vclabel = ucfirst $form->{vc};
- $vclabel = $locale->text($vclabel);
-
- $terms = qq|
+ $terms = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Terms').qq|</th>
- <td nowrap><input name=terms size="3" maxlength="3" value=$form->{terms}> |.$locale->text('days').qq|</td>
+ <th align=right nowrap>| . $locale->text('Terms') . qq|</th>
+ <td nowrap><input name=terms size="3" maxlength="3" value=$form->{terms}> |
+ . $locale->text('days')
+ . qq|</td>
</tr>
|;
-
- if ($form->{business}) {
- $business = qq|
+ if ( $form->{business} ) {
+ $business = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Business').qq|</th>
+ <th align=right nowrap>| . $locale->text('Business') . qq|</th>
<td colspan=3>$form->{business}
&nbsp;&nbsp;&nbsp;|;
- $business .= qq|
- <b>|.$locale->text('Trade Discount').qq|</b>
- |.$form->format_amount(\%myconfig, $form->{tradediscount} * 100).qq| %| if $form->{vc} eq 'customer';
- $business .= qq|</td>
+ $business .= qq|
+ <b>| . $locale->text('Trade Discount') . qq|</b>
+ | . $form->format_amount( \%myconfig, $form->{tradediscount} * 100 ) . qq| %|
+ if $form->{vc} eq 'customer';
+ $business .= qq|</td>
</tr>
|;
- }
+ }
- if ($form->{type} !~ /_quotation$/) {
- $ordnumber = qq|
+ if ( $form->{type} !~ /_quotation$/ ) {
+ $ordnumber = qq|
<tr>
- <th width=70% align=right nowrap>|.$locale->text('Order Number').qq|</th>
+ <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
<td><input name=ordnumber size=20 value="$form->{ordnumber}"></td>
<input type=hidden name=quonumber value="$form->{quonumber}">
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Order Date').qq|</th>
+ <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
<td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
</tr>
<tr>
- <th align=right nowrap=true>|.$locale->text('Required by').qq|</th>
+ <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
<td><input name=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('PO Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('PO Number') . qq|</th>
<td><input name=ponumber size=20 value="$form->{ponumber}"></td>
</tr>
|;
-
- $n = ($form->{creditremaining} < 0) ? "0" : "1";
-
- $creditremaining = qq|
+
+ $n = ( $form->{creditremaining} < 0 ) ? "0" : "1";
+
+ $creditremaining = qq|
<tr>
<td></td>
<td colspan=3>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Credit Limit').qq|</th>
- <td>|.$form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0").qq|</td>
+ <th align=right nowrap>| . $locale->text('Credit Limit') . qq|</th>
+ <td>|
+ . $form->format_amount( \%myconfig, $form->{creditlimit}, 0, "0" )
+ . qq|</td>
<td width=10></td>
- <th align=right nowrap>|.$locale->text('Remaining').qq|</th>
- <td class="plus$n" nowrap>|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</td>
+ <th align=right nowrap>| . $locale->text('Remaining') . qq|</th>
+ <td class="plus$n" nowrap>|
+ . $form->format_amount( \%myconfig, $form->{creditremaining}, 0, "0" )
+ . qq|</td>
</tr>
</table>
</td>
</tr>
|;
- } else {
- $reqlabel = ($form->{type} eq 'sales_quotation') ? $locale->text('Valid until') : $locale->text('Required by');
- if ($form->{type} eq 'sales_quotation') {
- $ordnumber = qq|
+ }
+ else {
+ $reqlabel =
+ ( $form->{type} eq 'sales_quotation' )
+ ? $locale->text('Valid until')
+ : $locale->text('Required by');
+ if ( $form->{type} eq 'sales_quotation' ) {
+ $ordnumber = qq|
<tr>
- <th width=70% align=right nowrap>|.$locale->text('Quotation Number').qq|</th>
+ <th width=70% align=right nowrap>|
+ . $locale->text('Quotation Number')
+ . qq|</th>
<td><input name=quonumber size=20 value="$form->{quonumber}"></td>
<input type=hidden name=ordnumber value="$form->{ordnumber}">
</tr>
|;
- } else {
- $ordnumber = qq|
+ }
+ else {
+ $ordnumber = qq|
<tr>
- <th width=70% align=right nowrap>|.$locale->text('RFQ Number').qq|</th>
+ <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
<td><input name=quonumber size=20 value="$form->{quonumber}"></td>
<input type=hidden name=ordnumber value="$form->{ordnumber}">
</tr>
|;
- $terms = "";
- }
-
+ $terms = "";
+ }
- $ordnumber .= qq|
+ $ordnumber .= qq|
<tr>
- <th align=right nowrap>|.$locale->text('Quotation Date').qq|</th>
+ <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
<td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
</tr>
<tr>
@@ -448,71 +521,75 @@ sub form_header {
</tr>
|;
- }
+ }
- $ordnumber .= qq|
+ $ordnumber .= qq|
<input type=hidden name=oldtransdate value=$form->{oldtransdate}>|;
- if ($form->{"select$form->{vc}"}) {
- $vc = qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}</select>
+ if ( $form->{"select$form->{vc}"} ) {
+ $vc = qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}</select>
<input type=hidden name="select$form->{vc}" value="|
- .$form->escape($form->{"select$form->{vc}"},1).qq|">|;
- } else {
- $vc = qq|<input name=$form->{vc} value="$form->{$form->{vc}}" size=35>|;
- }
+ . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|">|;
+ }
+ else {
+ $vc = qq|<input name=$form->{vc} value="$form->{$form->{vc}}" size=35>|;
+ }
- $department = qq|
+ $department = qq|
<tr>
- <th align="right" nowrap>|.$locale->text('Department').qq|</th>
+ <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|">
+ . $form->escape( $form->{selectdepartment}, 1 ) . qq|">
</td>
</tr>
| if $form->{selectdepartment};
- $employee = qq|
+ $employee = qq|
<input type=hidden name=employee value="$form->{employee}">
|;
- if ($form->{type} eq 'sales_order') {
- if ($form->{selectemployee}) {
- $employee = qq|
+ if ( $form->{type} eq 'sales_order' ) {
+ if ( $form->{selectemployee} ) {
+ $employee = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Salesperson').qq|</th>
+ <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
<td><select name=employee>$form->{selectemployee}</select></td>
- <input type=hidden name=selectemployee value="|.
- $form->escape($form->{selectemployee},1).qq|"
+ <input type=hidden name=selectemployee value="|
+ . $form->escape( $form->{selectemployee}, 1 ) . qq|"
</tr>
|;
+ }
}
- } else {
- if ($form->{selectemployee}) {
- $employee = qq|
+ else {
+ if ( $form->{selectemployee} ) {
+ $employee = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Employee').qq|</th>
+ <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
<td><select name=employee>$form->{selectemployee}</select></td>
- <input type=hidden name=selectemployee value="|.
- $form->escape($form->{selectemployee},1).qq|"
+ <input type=hidden name=selectemployee value="|
+ . $form->escape( $form->{selectemployee}, 1 ) . qq|"
</tr>
|;
+ }
}
- }
- $i = $form->{rowcount} + 1;
- $focus = "partnumber_$i";
-
- $form->header;
-
- print 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 type formname media format printed emailed queued vc title discount creditlimit creditremaining tradediscount business recurring));
+ $form->hide_form(
+ qw(id type formname media format printed emailed queued vc title discount creditlimit creditremaining tradediscount business recurring)
+ );
- print qq|
+ print qq|
<table width=100%>
<tr class=listtop>
<th class=listtop>$form->{title}</th>
@@ -535,11 +612,11 @@ sub form_header {
$department
$exchangerate
<tr>
- <th align=right>|.$locale->text('Shipping Point').qq|</th>
+ <th align=right>| . $locale->text('Shipping Point') . qq|</th>
<td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
</tr>
<tr>
- <th align=right>|.$locale->text('Ship via').qq|</th>
+ <th align=right>| . $locale->text('Ship via') . qq|</th>
<td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
</tr>
</table>
@@ -559,81 +636,84 @@ sub form_header {
|;
- $form->hide_form(qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail message email subject cc bcc taxaccounts));
+ $form->hide_form(
+ qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail message email subject cc bcc taxaccounts)
+ );
- for (split / /, $form->{taxaccounts}) {
- print qq|
+ for ( split / /, $form->{taxaccounts} ) {
+ print qq|
<input type=hidden name="${_}_rate" value=$form->{"${_}_rate"}>
<input type=hidden name="${_}_description" value="$form->{"${_}_description"}">
|;
- }
+ }
}
-
sub form_footer {
- $form->{invtotal} = $form->{invsubtotal};
-
- if (($rows = $form->numtextrows($form->{notes}, 35, 8)) < 2) {
- $rows = 2;
- }
- if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
- $introws = 2;
- }
- $rows = ($rows > $introws) ? $rows : $introws;
- $notes = qq|<textarea name=notes rows=$rows cols=35 wrap=soft>$form->{notes}</textarea>|;
- $intnotes = qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
+ $form->{invtotal} = $form->{invsubtotal};
+ if ( ( $rows = $form->numtextrows( $form->{notes}, 35, 8 ) ) < 2 ) {
+ $rows = 2;
+ }
+ if ( ( $introws = $form->numtextrows( $form->{intnotes}, 35, 8 ) ) < 2 ) {
+ $introws = 2;
+ }
+ $rows = ( $rows > $introws ) ? $rows : $introws;
+ $notes =
+qq|<textarea name=notes rows=$rows cols=35 wrap=soft>$form->{notes}</textarea>|;
+ $intnotes =
+qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
- $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
+ $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
- $taxincluded = "";
- if ($form->{taxaccounts}) {
- $taxincluded = qq|
+ $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>
+ <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);
-
- $tax .= qq|
+ }
+
+ 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 );
+
+ $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|
+ $form->{invsubtotal} =
+ $form->format_amount( \%myconfig, $form->{invsubtotal}, 2, 0 );
+
+ $subtotal = qq|
<tr>
- <th align=right>|.$locale->text('Subtotal').qq|</th>
+ <th align=right>| . $locale->text('Subtotal') . qq|</th>
<td align=right>$form->{invsubtotal}</td>
</tr>
|;
- }
-
- $form->{oldinvtotal} = $form->{invtotal};
- $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
+ }
+ $form->{oldinvtotal} = $form->{invtotal};
+ $form->{invtotal} =
+ $form->format_amount( \%myconfig, $form->{invtotal}, 2, 0 );
- print qq|
+ print qq|
<tr>
<td>
<table width=100%>
@@ -641,8 +721,8 @@ sub form_footer {
<td>
<table>
<tr>
- <th align=left>|.$locale->text('Notes').qq|</th>
- <th align=left>|.$locale->text('Internal Notes').qq|</th>
+ <th align=left>| . $locale->text('Notes') . qq|</th>
+ <th align=left>| . $locale->text('Internal Notes') . qq|</th>
</tr>
<tr valign=top>
<td>$notes</td>
@@ -655,7 +735,7 @@ sub form_footer {
$subtotal
$tax
<tr>
- <th align=right>|.$locale->text('Total').qq|</th>
+ <th align=right>| . $locale->text('Total') . qq|</th>
<td align=right>$form->{invtotal}</td>
</tr>
$taxincluded
@@ -674,9 +754,9 @@ sub form_footer {
<td>
|;
- &print_options;
+ &print_options;
- print qq|
+ print qq|
</td>
</tr>
</table>
@@ -684,105 +764,134 @@ sub form_footer {
<br>
|;
-# type=submit $locale->text('Update')
-# type=submit $locale->text('Print')
-# type=submit $locale->text('Schedule')
-# type=submit $locale->text('Save')
-# type=submit $locale->text('Print and Save')
-# type=submit $locale->text('Ship to')
-# type=submit $locale->text('Save as new')
-# type=submit $locale->text('Print and Save as new')
-# type=submit $locale->text('E-mail')
-# type=submit $locale->text('Delete')
-# type=submit $locale->text('Sales Invoice')
-# type=submit $locale->text('Vendor Invoice')
-# type=submit $locale->text('Quotation')
-# type=submit $locale->text('RFQ')
-# type=submit $locale->text('Sales Order')
-# type=submit $locale->text('Purchase Order')
-
- 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') },
- 'ship_to' => { ndx => 4, key => 'T', value => $locale->text('Ship to') },
- 'e_mail' => { ndx => 5, key => 'E', value => $locale->text('E-mail') },
- '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') },
- 'sales_invoice' => { ndx => 9, key => 'I', value => $locale->text('Sales Invoice') },
- 'sales_order' => { ndx => 10, key => 'O', value => $locale->text('Sales Order') },
- 'quotation' => { ndx => 11, key => 'Q', value => $locale->text('Quotation') },
- 'vendor_invoice' => { ndx => 12, key => 'I', value => $locale->text('Vendor Invoice') },
- 'purchase_order' => { ndx => 13, key => 'O', value => $locale->text('Purchase Order') },
- 'rfq' => { ndx => 14, key => 'Q', value => $locale->text('RFQ') },
- 'schedule' => { ndx => 15, key => 'H', value => $locale->text('Schedule') },
- 'delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') },
- );
-
-
- %a = ();
- for ("update", "ship_to", "print", "e_mail", "save") { $a{$_} = 1 }
- $a{'print_and_save'} = 1 if ${LedgerSMB::Sysconfig::latex};
-
- if ($form->{id}) {
-
- $a{'delete'} = 1;
- $a{'save_as_new'} = 1;
- $a{'print_and_save_as_new'} = 1 if ${LedgerSMB::Sysconfig::latex};
-
- if ($form->{type} =~ /sales_/) {
- if ($myconfig{acs} !~ /AR--Sales Invoice/) {
- $a{'sales_invoice'} = 1;
- }
- } else {
- if ($myconfig{acs} !~ /AP--Vendor Invoice/) {
- $a{'vendor_invoice'} = 1;
- }
- }
-
- if ($form->{type} eq 'sales_order') {
- if ($myconfig{acs} !~ /Quotations--RFQ/) {
- $a{'quotation'} = 1;
- }
- }
-
- if ($form->{type} eq 'purchase_order') {
- if ($myconfig{acs} !~ /Quotations--RFQ/) {
- $a{'rfq'} = 1;
- }
- }
-
- if ($form->{type} eq 'sales_quotation') {
- if ($myconfig{acs} !~ /Order Entry--Sales Order/) {
- $a{'sales_order'} = 1;
- }
- }
-
- if ($myconfig{acs} !~ /Order Entry--Purchase Order/) {
- if ($form->{type} eq 'request_quotation') {
- $a{'purchase_order'} = 1;
- }
- }
- }
-
- if ($form->{type} =~ /_order/) {
- $a{'schedule'} = 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(rowcount callback path login sessionid));
-
- print qq|
+ # type=submit $locale->text('Update')
+ # type=submit $locale->text('Print')
+ # type=submit $locale->text('Schedule')
+ # type=submit $locale->text('Save')
+ # type=submit $locale->text('Print and Save')
+ # type=submit $locale->text('Ship to')
+ # type=submit $locale->text('Save as new')
+ # type=submit $locale->text('Print and Save as new')
+ # type=submit $locale->text('E-mail')
+ # type=submit $locale->text('Delete')
+ # type=submit $locale->text('Sales Invoice')
+ # type=submit $locale->text('Vendor Invoice')
+ # type=submit $locale->text('Quotation')
+ # type=submit $locale->text('RFQ')
+ # type=submit $locale->text('Sales Order')
+ # type=submit $locale->text('Purchase Order')
+
+ 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') },
+ 'ship_to' =>
+ { ndx => 4, key => 'T', value => $locale->text('Ship to') },
+ 'e_mail' =>
+ { ndx => 5, key => 'E', value => $locale->text('E-mail') },
+ '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')
+ },
+ 'sales_invoice' =>
+ { ndx => 9, key => 'I', value => $locale->text('Sales Invoice') },
+ 'sales_order' =>
+ { ndx => 10, key => 'O', value => $locale->text('Sales Order') },
+ 'quotation' =>
+ { ndx => 11, key => 'Q', value => $locale->text('Quotation') },
+ 'vendor_invoice' => {
+ ndx => 12,
+ key => 'I',
+ value => $locale->text('Vendor Invoice')
+ },
+ 'purchase_order' => {
+ ndx => 13,
+ key => 'O',
+ value => $locale->text('Purchase Order')
+ },
+ 'rfq' => { ndx => 14, key => 'Q', value => $locale->text('RFQ') },
+ 'schedule' =>
+ { ndx => 15, key => 'H', value => $locale->text('Schedule') },
+ 'delete' =>
+ { ndx => 16, key => 'D', value => $locale->text('Delete') },
+ );
+
+ %a = ();
+ for ( "update", "ship_to", "print", "e_mail", "save" ) { $a{$_} = 1 }
+ $a{'print_and_save'} = 1 if ${LedgerSMB::Sysconfig::latex};
+
+ if ( $form->{id} ) {
+
+ $a{'delete'} = 1;
+ $a{'save_as_new'} = 1;
+ $a{'print_and_save_as_new'} = 1 if ${LedgerSMB::Sysconfig::latex};
+
+ if ( $form->{type} =~ /sales_/ ) {
+ if ( $myconfig{acs} !~ /AR--Sales Invoice/ ) {
+ $a{'sales_invoice'} = 1;
+ }
+ }
+ else {
+ if ( $myconfig{acs} !~ /AP--Vendor Invoice/ ) {
+ $a{'vendor_invoice'} = 1;
+ }
+ }
+
+ if ( $form->{type} eq 'sales_order' ) {
+ if ( $myconfig{acs} !~ /Quotations--RFQ/ ) {
+ $a{'quotation'} = 1;
+ }
+ }
+
+ if ( $form->{type} eq 'purchase_order' ) {
+ if ( $myconfig{acs} !~ /Quotations--RFQ/ ) {
+ $a{'rfq'} = 1;
+ }
+ }
+
+ if ( $form->{type} eq 'sales_quotation' ) {
+ if ( $myconfig{acs} !~ /Order Entry--Sales Order/ ) {
+ $a{'sales_order'} = 1;
+ }
+ }
+
+ if ( $myconfig{acs} !~ /Order Entry--Purchase Order/ ) {
+ if ( $form->{type} eq 'request_quotation' ) {
+ $a{'purchase_order'} = 1;
+ }
+ }
+ }
+
+ if ( $form->{type} =~ /_order/ ) {
+ $a{'schedule'} = 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(rowcount callback path login sessionid));
+
+ print qq|
</form>
</body>
@@ -791,397 +900,516 @@ sub form_footer {
}
-
sub update {
- if ($form->{type} eq 'generate_purchase_order') {
-
- for (1 .. $form->{rowcount}) {
- if ($form->{"ndx_$_"}) {
- $form->{"$form->{vc}_id_$_"} = $form->{"$form->{vc}_id"};
- $form->{"$form->{vc}_$_"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
- }
+ if ( $form->{type} eq 'generate_purchase_order' ) {
+
+ for ( 1 .. $form->{rowcount} ) {
+ if ( $form->{"ndx_$_"} ) {
+ $form->{"$form->{vc}_id_$_"} = $form->{"$form->{vc}_id"};
+ $form->{"$form->{vc}_$_"} =
+ qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
+ }
+ }
+
+ &po_orderitems;
+ exit;
}
-
- &po_orderitems;
- exit;
- }
-
- $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
-
- if ($form->{vc} eq 'customer') {
- $buysell = "buy";
- $ARAP = "AR";
- } else {
- $buysell = "sell";
- $ARAP = "AP";
- }
-
- if ($newname = &check_name($form->{vc})) {
- &rebuild_vc($form->{vc}, $ARAP, $form->{transdate}, 1);
- }
-
- if ($form->{transdate} ne $form->{oldtransdate}) {
- $form->{reqdate} = ($form->{terms}) ? $form->current_date(\%myconfig, $form->{transdate}, $form->{terms} * 1) : $form->{reqdate};
- $form->{oldtransdate} = $form->{transdate};
- &rebuild_vc($form->{vc}, $ARAP, $form->{transdate}, 1) if ! $newname;
-
- if ($form->{currency} ne $form->{defaultcurrency}) {
- delete $form->{exchangerate};
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell)));
- }
-
- $form->{selectemployee} = "";
- if (@{ $form->{all_employee} }) {
- for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
- }
-
-
- if ($form->{currency} ne $form->{oldcurrency}) {
- delete $form->{exchangerate};
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell)));
- }
-
- my $i = $form->{rowcount};
- $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
-
- for (qw(partsgroup projectnumber)) {
- $form->{"select$_"} = $form->unescape($form->{"select$_"}) if $form->{"select$_"};
- }
-
- if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {
-
- $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
- &check_form;
-
- } else {
-
- $retrieve_item = "";
- if ($form->{type} eq 'purchase_order' || $form->{type} eq 'request_quotation') {
- $retrieve_item = "IR::retrieve_item";
- }
- if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
- $retrieve_item = "IS::retrieve_item";
- }
-
- &{ "$retrieve_item" }("", \%myconfig, \%$form);
-
- $rows = scalar @{ $form->{item_list} };
-
- if ($form->{language_code} && $rows == 0) {
- $language_code = $form->{language_code};
- $form->{language_code} = "";
- if ($retrieve_item) {
- &{ "$retrieve_item" }("", \%myconfig, \%$form);
- }
- $form->{language_code} = $language_code;
- $rows = scalar @{ $form->{item_list} };
- }
-
- if ($rows) {
-
- if ($rows > 1) {
-
- &select_item;
- exit;
-
- } else {
-
- $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
- $form->{"reqdate_$i"} = $form->{reqdate} if $form->{type} ne 'sales_quotation';
- $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
-
- for (qw(partnumber description unit)) { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) }
- for (keys %{ $form->{item_list}[0] }) { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
-
- $form->{"discount_$i"} = $form->{discount} * 100;
-
- if ($sellprice) {
- $form->{"sellprice_$i"} = $sellprice;
-
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces1 = ($dec > 2) ? $dec : 2;
- } else {
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces1 = ($dec > 2) ? $dec : 2;
-
- $form->{"sellprice_$i"} /= $exchangerate;
- }
-
- ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces2 = ($dec > 2) ? $dec : 2;
-
- for (qw(listprice lastcost)) { $form->{"${_}_$i"} /= $exchangerate }
-
- $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
- for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
- for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
- if (!$form->{taxincluded}) {
- my @taxes = Tax::init_taxes($form, $form->{taxaccounts});
- $amount += Tax::calculate_taxes(\@taxes, $form, $amount, 0);
- }
-
- $form->{creditremaining} -= $amount;
-
- 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->{"oldqty_$i"} = $form->{"qty_$i"};
- for (qw(qty discount)) { $form->{"{_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- }
-
- &display_form;
-
- } else {
- # ok, so this is a new part
- # ask if it is a part or service item
-
- if ($form->{"partsgroup_$i"} && ($form->{"partsnumber_$i"} eq "") && ($form->{"description_$i"} eq "")) {
- $form->{rowcount}--;
- &display_form;
- } else {
-
- $form->{"id_$i"} = 0;
- $form->{"unit_$i"} = $locale->text('ea');
- &new_item;
-
- }
- }
- }
-}
+ $form->{exchangerate} =
+ $form->parse_amount( \%myconfig, $form->{exchangerate} );
+ if ( $form->{vc} eq 'customer' ) {
+ $buysell = "buy";
+ $ARAP = "AR";
+ }
+ else {
+ $buysell = "sell";
+ $ARAP = "AP";
+ }
+
+ if ( $newname = &check_name( $form->{vc} ) ) {
+ &rebuild_vc( $form->{vc}, $ARAP, $form->{transdate}, 1 );
+ }
+
+ if ( $form->{transdate} ne $form->{oldtransdate} ) {
+ $form->{reqdate} =
+ ( $form->{terms} )
+ ? $form->current_date( \%myconfig, $form->{transdate},
+ $form->{terms} * 1 )
+ : $form->{reqdate};
+ $form->{oldtransdate} = $form->{transdate};
+ &rebuild_vc( $form->{vc}, $ARAP, $form->{transdate}, 1 ) if !$newname;
+
+ if ( $form->{currency} ne $form->{defaultcurrency} ) {
+ delete $form->{exchangerate};
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate = $form->check_exchangerate(
+ \%myconfig, $form->{currency},
+ $form->{transdate}, $buysell
+ )
+ )
+ );
+ }
+
+ $form->{selectemployee} = "";
+ if ( @{ $form->{all_employee} } ) {
+ for ( @{ $form->{all_employee} } ) {
+ $form->{selectemployee} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
+ }
+
+ if ( $form->{currency} ne $form->{oldcurrency} ) {
+ delete $form->{exchangerate};
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate = $form->check_exchangerate(
+ \%myconfig, $form->{currency},
+ $form->{transdate}, $buysell
+ )
+ )
+ );
+ }
+
+ my $i = $form->{rowcount};
+ $exchangerate = ( $form->{exchangerate} ) ? $form->{exchangerate} : 1;
+ for (qw(partsgroup projectnumber)) {
+ $form->{"select$_"} = $form->unescape( $form->{"select$_"} )
+ if $form->{"select$_"};
+ }
+
+ if ( ( $form->{"partnumber_$i"} eq "" )
+ && ( $form->{"description_$i"} eq "" )
+ && ( $form->{"partsgroup_$i"} eq "" ) )
+ {
+
+ $form->{creditremaining} +=
+ ( $form->{oldinvtotal} - $form->{oldtotalpaid} );
+ &check_form;
+
+ }
+ else {
+
+ $retrieve_item = "";
+ if ( $form->{type} eq 'purchase_order'
+ || $form->{type} eq 'request_quotation' )
+ {
+ $retrieve_item = "IR::retrieve_item";
+ }
+ if ( $form->{type} eq 'sales_order'
+ || $form->{type} eq 'sales_quotation' )
+ {
+ $retrieve_item = "IS::retrieve_item";
+ }
+
+ &{"$retrieve_item"}( "", \%myconfig, \%$form );
+
+ $rows = scalar @{ $form->{item_list} };
+
+ if ( $form->{language_code} && $rows == 0 ) {
+ $language_code = $form->{language_code};
+ $form->{language_code} = "";
+ if ($retrieve_item) {
+ &{"$retrieve_item"}( "", \%myconfig, \%$form );
+ }
+ $form->{language_code} = $language_code;
+ $rows = scalar @{ $form->{item_list} };
+ }
+
+ if ($rows) {
+
+ if ( $rows > 1 ) {
+
+ &select_item;
+ exit;
+
+ }
+ else {
+
+ $form->{"qty_$i"} =
+ ( $form->{"qty_$i"} * 1 ) ? $form->{"qty_$i"} : 1;
+ $form->{"reqdate_$i"} = $form->{reqdate}
+ if $form->{type} ne 'sales_quotation';
+ $sellprice =
+ $form->parse_amount( \%myconfig, $form->{"sellprice_$i"} );
+
+ for (qw(partnumber description unit)) {
+ $form->{item_list}[$i]{$_} =
+ $form->quote( $form->{item_list}[$i]{$_} );
+ }
+ for ( keys %{ $form->{item_list}[0] } ) {
+ $form->{"${_}_$i"} = $form->{item_list}[0]{$_};
+ }
+
+ $form->{"discount_$i"} = $form->{discount} * 100;
+
+ if ($sellprice) {
+ $form->{"sellprice_$i"} = $sellprice;
+
+ ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces1 = ( $dec > 2 ) ? $dec : 2;
+ }
+ else {
+ ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces1 = ( $dec > 2 ) ? $dec : 2;
+
+ $form->{"sellprice_$i"} /= $exchangerate;
+ }
+
+ ($dec) = ( $form->{"lastcost_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $decimalplaces2 = ( $dec > 2 ) ? $dec : 2;
+
+ for (qw(listprice lastcost)) {
+ $form->{"${_}_$i"} /= $exchangerate;
+ }
+
+ $amount =
+ $form->{"sellprice_$i"} * $form->{"qty_$i"} *
+ ( 1 - $form->{"discount_$i"} / 100 );
+ for ( split / /, $form->{taxaccounts} ) {
+ $form->{"${_}_base"} = 0;
+ }
+ for ( split / /, $form->{"taxaccounts_$i"} ) {
+ $form->{"${_}_base"} += $amount;
+ }
+ if ( !$form->{taxincluded} ) {
+ my @taxes = Tax::init_taxes( $form, $form->{taxaccounts} );
+ $amount +=
+ Tax::calculate_taxes( \@taxes, $form, $amount, 0 );
+ }
+
+ $form->{creditremaining} -= $amount;
+
+ 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->{"oldqty_$i"} = $form->{"qty_$i"};
+ for (qw(qty discount)) {
+ $form->{"{_}_$i"} =
+ $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ }
+
+ &display_form;
+
+ }
+ else {
+
+ # ok, so this is a new part
+ # ask if it is a part or service item
+
+ if ( $form->{"partsgroup_$i"}
+ && ( $form->{"partsnumber_$i"} eq "" )
+ && ( $form->{"description_$i"} eq "" ) )
+ {
+ $form->{rowcount}--;
+ &display_form;
+ }
+ else {
+
+ $form->{"id_$i"} = 0;
+ $form->{"unit_$i"} = $locale->text('ea');
+ &new_item;
+
+ }
+ }
+ }
+
+}
sub search {
- $requiredby = $locale->text('Required by');
+ $requiredby = $locale->text('Required by');
- if ($form->{type} eq 'purchase_order') {
- $form->{title} = $locale->text('Purchase Orders');
- $form->{vc} = 'vendor';
- $ordlabel = $locale->text('Order Number');
- $ordnumber = 'ordnumber';
- $employee = $locale->text('Employee');
- }
-
- if ($form->{type} eq 'receive_order') {
- $form->{title} = $locale->text('Receive Merchandise');
- $form->{vc} = 'vendor';
- $ordlabel = $locale->text('Order Number');
- $ordnumber = 'ordnumber';
- $employee = $locale->text('Employee');
- }
-
- if ($form->{type} eq 'generate_sales_order') {
- $form->{title} = $locale->text('Generate Sales Order from Purchase Orders');
- $form->{vc} = 'vendor';
- $ordlabel = $locale->text('Order Number');
- $ordnumber = 'ordnumber';
- $employee = $locale->text('Employee');
- }
-
- if ($form->{type} eq 'consolidate_sales_order') {
- $form->{title} = $locale->text('Consolidate Sales Orders');
- $form->{vc} = 'customer';
- $ordlabel = $locale->text('Order Number');
- $ordnumber = 'ordnumber';
- $employee = $locale->text('Salesperson');
- }
-
- if ($form->{type} eq 'request_quotation') {
- $form->{title} = $locale->text('Request for Quotations');
- $form->{vc} = 'vendor';
- $ordlabel = $locale->text('RFQ Number');
- $ordnumber = 'quonumber';
- $employee = $locale->text('Employee');
- }
-
- if ($form->{type} eq 'sales_order') {
- $form->{title} = $locale->text('Sales Orders');
- $form->{vc} = 'customer';
- $ordlabel = $locale->text('Order Number');
- $ordnumber = 'ordnumber';
- $employee = $locale->text('Salesperson');
- }
-
- if ($form->{type} eq 'ship_order') {
- $form->{title} = $locale->text('Ship Merchandise');
- $form->{vc} = 'customer';
- $ordlabel = $locale->text('Order Number');
- $ordnumber = 'ordnumber';
- $employee = $locale->text('Salesperson');
- }
-
- if ($form->{type} eq 'sales_quotation') {
- $form->{title} = $locale->text('Quotations');
- $form->{vc} = 'customer';
- $ordlabel = $locale->text('Quotation Number');
- $ordnumber = 'quonumber';
- $employee = $locale->text('Employee');
- $requiredby = $locale->text('Valid until');
- }
-
- if ($form->{type} eq 'generate_purchase_order') {
- $form->{title} = $locale->text('Generate Purchase Orders from Sales Order');
- $form->{vc} = 'customer';
- $ordlabel = $locale->text('Order Number');
- $ordnumber = 'ordnumber';
- $employee = $locale->text('Salesperson');
- }
-
- if ($form->{type} eq 'consolidate_purchase_order') {
- $form->{title} = $locale->text('Consolidate Purchase Orders');
- $form->{vc} = 'vendor';
- $ordlabel = $locale->text('Order Number');
- $ordnumber = 'ordnumber';
- $employee = $locale->text('Employee');
- }
-
- $l_employee = qq|<input name="l_employee" class=checkbox type=checkbox value=Y> $employee|;
- $l_manager = qq|<input name="l_manager" class=checkbox type=checkbox value=Y> |.$locale->text('Manager');
-
- if ($form->{type} =~ /(ship|receive)_order/) {
- OE->get_warehouses(\%myconfig, \%$form);
-
- $l_manager = "";
+ if ( $form->{type} eq 'purchase_order' ) {
+ $form->{title} = $locale->text('Purchase Orders');
+ $form->{vc} = 'vendor';
+ $ordlabel = $locale->text('Order Number');
+ $ordnumber = 'ordnumber';
+ $employee = $locale->text('Employee');
+ }
- # warehouse
- if (@{ $form->{all_warehouse} }) {
- $form->{selectwarehouse} = "<option>\n";
- $form->{warehouse} = qq|$form->{warehouse}--$form->{warehouse_id}|;
+ if ( $form->{type} eq 'receive_order' ) {
+ $form->{title} = $locale->text('Receive Merchandise');
+ $form->{vc} = 'vendor';
+ $ordlabel = $locale->text('Order Number');
+ $ordnumber = 'ordnumber';
+ $employee = $locale->text('Employee');
+ }
- for (@{ $form->{all_warehouse} }) { $form->{selectwarehouse} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
+ if ( $form->{type} eq 'generate_sales_order' ) {
+ $form->{title} =
+ $locale->text('Generate Sales Order from Purchase Orders');
+ $form->{vc} = 'vendor';
+ $ordlabel = $locale->text('Order Number');
+ $ordnumber = 'ordnumber';
+ $employee = $locale->text('Employee');
+ }
- $warehouse = qq|
+ if ( $form->{type} eq 'consolidate_sales_order' ) {
+ $form->{title} = $locale->text('Consolidate Sales Orders');
+ $form->{vc} = 'customer';
+ $ordlabel = $locale->text('Order Number');
+ $ordnumber = 'ordnumber';
+ $employee = $locale->text('Salesperson');
+ }
+
+ if ( $form->{type} eq 'request_quotation' ) {
+ $form->{title} = $locale->text('Request for Quotations');
+ $form->{vc} = 'vendor';
+ $ordlabel = $locale->text('RFQ Number');
+ $ordnumber = 'quonumber';
+ $employee = $locale->text('Employee');
+ }
+
+ if ( $form->{type} eq 'sales_order' ) {
+ $form->{title} = $locale->text('Sales Orders');
+ $form->{vc} = 'customer';
+ $ordlabel = $locale->text('Order Number');
+ $ordnumber = 'ordnumber';
+ $employee = $locale->text('Salesperson');
+ }
+
+ if ( $form->{type} eq 'ship_order' ) {
+ $form->{title} = $locale->text('Ship Merchandise');
+ $form->{vc} = 'customer';
+ $ordlabel = $locale->text('Order Number');
+ $ordnumber = 'ordnumber';
+ $employee = $locale->text('Salesperson');
+ }
+
+ if ( $form->{type} eq 'sales_quotation' ) {
+ $form->{title} = $locale->text('Quotations');
+ $form->{vc} = 'customer';
+ $ordlabel = $locale->text('Quotation Number');
+ $ordnumber = 'quonumber';
+ $employee = $locale->text('Employee');
+ $requiredby = $locale->text('Valid until');
+ }
+
+ if ( $form->{type} eq 'generate_purchase_order' ) {
+ $form->{title} =
+ $locale->text('Generate Purchase Orders from Sales Order');
+ $form->{vc} = 'customer';
+ $ordlabel = $locale->text('Order Number');
+ $ordnumber = 'ordnumber';
+ $employee = $locale->text('Salesperson');
+ }
+
+ if ( $form->{type} eq 'consolidate_purchase_order' ) {
+ $form->{title} = $locale->text('Consolidate Purchase Orders');
+ $form->{vc} = 'vendor';
+ $ordlabel = $locale->text('Order Number');
+ $ordnumber = 'ordnumber';
+ $employee = $locale->text('Employee');
+ }
+
+ $l_employee =
+qq|<input name="l_employee" class=checkbox type=checkbox value=Y> $employee|;
+ $l_manager =
+ qq|<input name="l_manager" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Manager');
+
+ if ( $form->{type} =~ /(ship|receive)_order/ ) {
+ OE->get_warehouses( \%myconfig, \%$form );
+
+ $l_manager = "";
+
+ # warehouse
+ if ( @{ $form->{all_warehouse} } ) {
+ $form->{selectwarehouse} = "<option>\n";
+ $form->{warehouse} = qq|$form->{warehouse}--$form->{warehouse_id}|;
+
+ for ( @{ $form->{all_warehouse} } ) {
+ $form->{selectwarehouse} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+
+ $warehouse = qq|
<tr>
- <th align=right>|.$locale->text('Warehouse').qq|</th>
+ <th align=right>| . $locale->text('Warehouse') . qq|</th>
<td><select name=warehouse>$form->{selectwarehouse}</select></td>
- <input type=hidden name=selectwarehouse value="|.
- $form->escape($form->{selectwarehouse},1).qq|">
+ <input type=hidden name=selectwarehouse value="|
+ . $form->escape( $form->{selectwarehouse}, 1 ) . qq|">
</tr>
|;
+ }
}
- }
- # setup vendor / customer selection
- $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
+ # setup vendor / customer 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| }
+ for ( @{ $form->{"all_$form->{vc}"} } ) {
+ $vc .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
- $selectemployee = "";
- if (@{ $form->{all_employee} }) {
- $selectemployee = "<option>\n";
- for (@{ $form->{all_employee} }) { $selectemployee .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
+ $selectemployee = "";
+ if ( @{ $form->{all_employee} } ) {
+ $selectemployee = "<option>\n";
+ for ( @{ $form->{all_employee} } ) {
+ $selectemployee .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
- $selectemployee = qq|
+ $selectemployee = qq|
<tr>
<th align=right>$employee</th>
<td colspan=3><select name=employee>$selectemployee</select></td>
</tr>
|;
- } else {
- $l_employee = $l_manager = "";
- }
+ }
+ else {
+ $l_employee = $l_manager = "";
+ }
- $vclabel = ucfirst $form->{vc};
- $vclabel = $locale->text($vclabel);
-
-# $locale->text('Vendor')
-# $locale->text('Customer')
-
- $vc = ($vc) ? qq|<select name=$form->{vc}><option>\n$vc</select>| : qq|<input name=$form->{vc} size=35>|;
+ $vclabel = ucfirst $form->{vc};
+ $vclabel = $locale->text($vclabel);
+
+ # $locale->text('Vendor')
+ # $locale->text('Customer')
- # departments
- if (@{ $form->{all_department} }) {
- $form->{selectdepartment} = "<option>\n";
+ $vc =
+ ($vc)
+ ? qq|<select name=$form->{vc}><option>\n$vc</select>|
+ : qq|<input name=$form->{vc} size=35>|;
- for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
- }
+ # departments
+ if ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} = "<option>\n";
+
+ for ( @{ $form->{all_department} } ) {
+ $form->{selectdepartment} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+ }
- $department = qq|
+ $department = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Department').qq|</th>
+ <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->{selectdepartment};
+
+ if ( $form->{type} =~ /(consolidate.*|generate.*|ship|receive)_order/ ) {
- if ($form->{type} =~ /(consolidate.*|generate.*|ship|receive)_order/) {
-
- $openclosed = qq|
+ $openclosed = qq|
<input type=hidden name="open" value=1>
|;
- } else {
-
- $openclosed = qq|
+ }
+ else {
+
+ $openclosed = qq|
<tr>
- <td nowrap><input name="open" class=checkbox type=checkbox value=1 checked> |.$locale->text('Open').qq|</td>
- <td nowrap><input name="closed" class=checkbox type=checkbox value=1 $form->{closed}> |.$locale->text('Closed').qq|</td>
+ <td nowrap><input name="open" class=checkbox type=checkbox value=1 checked> |
+ . $locale->text('Open')
+ . qq|</td>
+ <td nowrap><input name="closed" class=checkbox type=checkbox value=1 $form->{closed}> |
+ . $locale->text('Closed')
+ . qq|</td>
</tr>
|;
- }
-
- 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|
+ 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>
+ <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|
+ <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>
|;
- }
+ }
- if ($form->{type} =~ /_order/) {
- $ponumber = qq|
+ if ( $form->{type} =~ /_order/ ) {
+ $ponumber = qq|
<tr>
- <th align=right>|.$locale->text('PO Number').qq|</th>
+ <th align=right>| . $locale->text('PO Number') . qq|</th>
<td colspan=3><input name="ponumber" size=20></td>
</tr>
|;
+ $l_ponumber =
+ qq|<input name="l_ponumber" class=checkbox type=checkbox value=Y> |
+ . $locale->text('PO Number');
+ }
- $l_ponumber = qq|<input name="l_ponumber" class=checkbox type=checkbox value=Y> |.$locale->text('PO Number');
- }
-
- @a = ();
- push @a, qq|<input name="l_runningnumber" class=checkbox type=checkbox value=Y> |.$locale->text('No.');
- push @a, qq|<input name="l_id" class=checkbox type=checkbox value=Y> |.$locale->text('ID');
- push @a, qq|<input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel|;
- push @a, qq|<input name="l_transdate" class=checkbox type=checkbox value=Y checked> |.$locale->text('Date');
- push @a, $l_ponumber if $l_ponumber;
- push @a, qq|<input name="l_reqdate" class=checkbox type=checkbox value=Y checked> $requiredby|;
- push @a, qq|<input name="l_name" class=checkbox type=checkbox value=Y checked> $vclabel|;
- push @a, $l_employee if $l_employee;
- push @a, $l_manager if $l_manager;
- push @a, qq|<input name="l_shipvia" class=checkbox type=checkbox value=Y> |.$locale->text('Ship via');
- push @a, qq|<input name="l_netamount" class=checkbox type=checkbox value=Y> |.$locale->text('Amount');
- push @a, qq|<input name="l_tax" class=checkbox type=checkbox value=Y> |.$locale->text('Tax');
- push @a, qq|<input name="l_amount" class=checkbox type=checkbox value=Y checked> |.$locale->text('Total');
- push @a, qq|<input name="l_curr" class=checkbox type=checkbox value=Y checked> |.$locale->text('Currency');
-
-
- $form->header;
+ @a = ();
+ push @a,
+ qq|<input name="l_runningnumber" class=checkbox type=checkbox value=Y> |
+ . $locale->text('No.');
+ push @a, qq|<input name="l_id" class=checkbox type=checkbox value=Y> |
+ . $locale->text('ID');
+ push @a,
+qq|<input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel|;
+ push @a,
+qq|<input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Date');
+ push @a, $l_ponumber if $l_ponumber;
+ push @a,
+qq|<input name="l_reqdate" class=checkbox type=checkbox value=Y checked> $requiredby|;
+ push @a,
+qq|<input name="l_name" class=checkbox type=checkbox value=Y checked> $vclabel|;
+ push @a, $l_employee if $l_employee;
+ push @a, $l_manager if $l_manager;
+ push @a, qq|<input name="l_shipvia" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Ship via');
+ push @a,
+ qq|<input name="l_netamount" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Amount');
+ push @a, qq|<input name="l_tax" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Tax');
+ push @a,
+ qq|<input name="l_amount" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Total');
+ push @a,
+ qq|<input name="l_curr" class=checkbox type=checkbox value=Y checked> |
+ . $locale->text('Currency');
+
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -1207,39 +1435,41 @@ sub search {
</tr>
$ponumber
<tr>
- <th align=right>|.$locale->text('Ship via').qq|</th>
+ <th align=right>| . $locale->text('Ship via') . qq|</th>
<td colspan=3><input name="shipvia" size=40></td>
</tr>
<tr>
- <th align=right>|.$locale->text('Description').qq|</th>
+ <th align=right>| . $locale->text('Description') . qq|</th>
<td colspan=3><input name="description" size=40></td>
</tr>
<tr>
- <th align=right>|.$locale->text('From').qq|</th>
+ <th align=right>| . $locale->text('From') . qq|</th>
<td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
- <th align=right>|.$locale->text('To').qq|</th>
+ <th align=right>| . $locale->text('To') . qq|</th>
<td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
</tr>
<input type=hidden name=sort value=transdate>
$selectfrom
<tr>
- <th align=right>|.$locale->text('Include in Report').qq|</th>
+ <th align=right>| . $locale->text('Include in Report') . qq|</th>
<td colspan=3>
<table>
$openclosed
|;
- while (@a) {
- for (1 .. 5) {
- print qq|<td nowrap>|. shift @a;
- print qq|</td>\n|;
+ while (@a) {
+ for ( 1 .. 5 ) {
+ print qq|<td nowrap>| . shift @a;
+ print qq|</td>\n|;
+ }
+ print qq|</tr>\n|;
}
- print qq|</tr>\n|;
- }
- print qq|
+ print qq|
<tr>
- <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
+ <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
+ . $locale->text('Subtotal')
+ . qq|</td>
</tr>
</table>
</td>
@@ -1254,19 +1484,21 @@ sub search {
<input type=hidden name=nextsub value=transactions>
|;
- $form->hide_form(qw(path login sessionid vc type));
-
- print qq|
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+ $form->hide_form(qw(path login sessionid vc type));
+
+ print qq|
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</body>
</html>
@@ -1274,244 +1506,336 @@ sub search {
}
-
sub transactions {
-
- # split vendor / customer
- ($form->{$form->{vc}}, $form->{"$form->{vc}_id"}) = split(/--/, $form->{$form->{vc}});
-
- OE->transactions(\%myconfig, \%$form);
-
- $ordnumber = ($form->{type} =~ /_order/) ? 'ordnumber' : 'quonumber';
- $name = $form->escape($form->{$form->{vc}});
- $name .= qq|--$form->{"$form->{vc}_id"}| if $form->{"$form->{vc}_id"};
-
- # construct href
- $href = qq|$form->{script}?action=transactions|;
- for ("oldsort", "direction", "path", "type", "vc", "login", "sessionid", "transdatefrom", "transdateto", "open", "closed") { $href .= qq|&$_=$form->{$_}| }
- for ("$ordnumber", "department", "warehouse", "shipvia", "ponumber", "description", "employee") { $href .= qq|&$_=|.$form->escape($form->{$_}) }
- $href .= "&$form->{vc}=$name";
-
- # construct callback
- $name = $form->escape($form->{$form->{vc}},1);
- $name .= qq|--$form->{"$form->{vc}_id"}| if $form->{"$form->{vc}_id"};
-
- # flip direction
- $form->sort_order();
-
- $callback = qq|$form->{script}?action=transactions|;
- for ("oldsort", "direction", "path", "type", "vc", "login", "sessionid", "transdatefrom", "transdateto", "open", "closed") { $callback .= qq|&$_=$form->{$_}| }
- for ("$ordnumber", "department", "warehouse", "shipvia", "ponumber", "description", "employee") { $callback .= qq|&$_=|.$form->escape($form->{$_},1) }
- $callback .= "&$form->{vc}=$name";
+ # split vendor / customer
+ ( $form->{ $form->{vc} }, $form->{"$form->{vc}_id"} ) =
+ split( /--/, $form->{ $form->{vc} } );
+
+ OE->transactions( \%myconfig, \%$form );
+
+ $ordnumber = ( $form->{type} =~ /_order/ ) ? 'ordnumber' : 'quonumber';
+ $name = $form->escape( $form->{ $form->{vc} } );
+ $name .= qq|--$form->{"$form->{vc}_id"}| if $form->{"$form->{vc}_id"};
+
+ # construct href
+ $href = qq|$form->{script}?action=transactions|;
+ for (
+ "oldsort", "direction", "path", "type",
+ "vc", "login", "sessionid", "transdatefrom",
+ "transdateto", "open", "closed"
+ )
+ {
+ $href .= qq|&$_=$form->{$_}|;
+ }
+ for (
+ "$ordnumber", "department", "warehouse", "shipvia",
+ "ponumber", "description", "employee"
+ )
+ {
+ $href .= qq|&$_=| . $form->escape( $form->{$_} );
+ }
+ $href .= "&$form->{vc}=$name";
+
+ # construct callback
+ $name = $form->escape( $form->{ $form->{vc} }, 1 );
+ $name .= qq|--$form->{"$form->{vc}_id"}| if $form->{"$form->{vc}_id"};
+
+ # flip direction
+ $form->sort_order();
+
+ $callback = qq|$form->{script}?action=transactions|;
+ for (
+ "oldsort", "direction", "path", "type",
+ "vc", "login", "sessionid", "transdatefrom",
+ "transdateto", "open", "closed"
+ )
+ {
+ $callback .= qq|&$_=$form->{$_}|;
+ }
+ for (
+ "$ordnumber", "department", "warehouse", "shipvia",
+ "ponumber", "description", "employee"
+ )
+ {
+ $callback .= qq|&$_=| . $form->escape( $form->{$_}, 1 );
+ }
+ $callback .= "&$form->{vc}=$name";
+
+ @columns = $form->sort_columns(
+ "transdate", "reqdate", "id", "$ordnumber",
+ "ponumber", "name", "netamount", "tax",
+ "amount", "curr", "employee", "manager",
+ "shipvia", "open", "closed"
+ );
+ unshift @columns, "runningnumber";
+
+ $form->{l_open} = $form->{l_closed} = "Y"
+ if ( $form->{open} && $form->{closed} );
+
+ for (@columns) {
+ if ( $form->{"l_$_"} eq "Y" ) {
+ push @column_index, $_;
+
+ if ( $form->{l_curr} && $_ =~ /(amount|tax)/ ) {
+ push @column_index, "fx_$_";
+ }
+
+ # add column to href and callback
+ $callback .= "&l_$_=Y";
+ $href .= "&l_$_=Y";
+ }
+ }
- @columns = $form->sort_columns("transdate", "reqdate", "id", "$ordnumber", "ponumber", "name", "netamount", "tax", "amount", "curr", "employee", "manager", "shipvia", "open", "closed");
- unshift @columns, "runningnumber";
+ if ( $form->{l_subtotal} eq 'Y' ) {
+ $callback .= "&l_subtotal=Y";
+ $href .= "&l_subtotal=Y";
+ }
- $form->{l_open} = $form->{l_closed} = "Y" if ($form->{open} && $form->{closed}) ;
+ $requiredby = $locale->text('Required by');
+
+ $i = 1;
+ if ( $form->{vc} eq 'vendor' ) {
+ if ( $form->{type} eq 'receive_order' ) {
+ $form->{title} = $locale->text('Receive Merchandise');
+ }
+ if ( $form->{type} eq 'purchase_order' ) {
+ $form->{title} = $locale->text('Purchase Orders');
+ if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
+ $button{'Order Entry--Purchase Order'}{code} =
+qq|<button class="submit" type="submit" name="action" value="purchase_order">|
+ . $locale->text('Purchase Order')
+ . qq|</button> |;
+ $button{'Order Entry--Purchase Order'}{order} = $i++;
+ }
+ }
+ if ( $form->{type} eq 'generate_sales_order' ) {
+ $form->{title} = $locale->text('Purchase Orders');
+ $form->{type} = "purchase_order";
+ unshift @column_index, "ndx";
+ if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
+ $button{'Order Entry--Sales Order'}{code} =
+qq|<button class="submit" type="submit" name="action" value="generate_sales_order">|
+ . $locale->text('Generate Sales Order')
+ . qq|</button> |;
+ $button{'Order Entry--Sales Order'}{order} = $i++;
+ }
+ }
+ if ( $form->{type} eq 'consolidate_purchase_order' ) {
+ $form->{title} = $locale->text('Purchase Orders');
+ $form->{type} = "purchase_order";
+ unshift @column_index, "ndx";
+ if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
+ $button{'Order Entry--Purchase Order'}{code} =
+qq|<button class="submit" type="submit" name="action" value="consolidate_orders">|
+ . $locale->text('Consolidate Orders')
+ . qq|</button> |;
+ $button{'Order Entry--Purchase Order'}{order} = $i++;
+ }
+ }
+
+ if ( $form->{type} eq 'request_quotation' ) {
+ $form->{title} = $locale->text('Request for Quotations');
+ $quotation = $locale->text('RFQ');
+
+ if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
+ $button{'Quotations--RFQ'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add">|
+ . $locale->text('RFQ')
+ . qq|</button> |;
+ $button{'Quotations--RFQ'}{order} = $i++;
+ }
+
+ }
+ $name = $locale->text('Vendor');
+ $employee = $locale->text('Employee');
+ }
+ if ( $form->{vc} eq 'customer' ) {
+ if ( $form->{type} eq 'sales_order' ) {
+ $form->{title} = $locale->text('Sales Orders');
+ $employee = $locale->text('Salesperson');
+
+ if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
+ $button{'Order Entry--Sales Order'}{code} =
+qq|<button class="submit" type="submit" name="action" value="sales_order">|
+ . $locale->text('Sales Order')
+ . qq|</button> |;
+ $button{'Order Entry--Sales Order'}{order} = $i++;
+ }
+
+ }
+ if ( $form->{type} eq 'generate_purchase_order' ) {
+ $form->{title} = $locale->text('Sales Orders');
+ $form->{type} = "sales_order";
+ $employee = $locale->text('Salesperson');
+ unshift @column_index, "ndx";
+ if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
+ $button{'Order Entry--Purchase Order'}{code} =
+qq|<button class="submit" type="submit" name="action" value="generate_purchase_orders">|
+ . $locale->text('Generate Purchase Orders')
+ . qq|</button> |;
+ $button{'Order Entry--Purchase Order'}{order} = $i++;
+ }
+ }
+ if ( $form->{type} eq 'consolidate_sales_order' ) {
+ $form->{title} = $locale->text('Sales Orders');
+ $form->{type} = "sales_order";
+ unshift @column_index, "ndx";
+ if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) {
+ $button{'Order Entry--Sales Order'}{code} =
+qq|<button class="submit" type="submit" name="action" value="consolidate_orders">|
+ . $locale->text('Consolidate Orders')
+ . qq|</button> |;
+ $button{'Order Entry--Sales Order'}{order} = $i++;
+ }
+ }
+
+ if ( $form->{type} eq 'ship_order' ) {
+ $form->{title} = $locale->text('Ship Merchandise');
+ $employee = $locale->text('Salesperson');
+ }
+ if ( $form->{type} eq 'sales_quotation' ) {
+ $form->{title} = $locale->text('Quotations');
+ $employee = $locale->text('Employee');
+ $requiredby = $locale->text('Valid until');
+ $quotation = $locale->text('Quotation');
+
+ if ( $myconfig{acs} !~ /Quotations--Quotations/ ) {
+ $button{'Quotations--Quotation'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add">|
+ . $locale->text('Quotation')
+ . qq|</button> |;
+ $button{'Quotations--Quotation'}{order} = $i++;
+ }
+
+ }
+ $name = $locale->text('Customer');
+ }
- for (@columns) {
- if ($form->{"l_$_"} eq "Y") {
- push @column_index, $_;
+ for ( split /;/, $myconfig{acs} ) { delete $button{$_} }
+
+ $column_header{ndx} = qq|<th class=listheading>&nbsp;</th>|;
+ $column_header{runningnumber} = qq|<th class=listheading>&nbsp;</th>|;
+ $column_header{id} =
+ qq|<th><a class=listheading href=$href&sort=id>|
+ . $locale->text('ID')
+ . qq|</a></th>|;
+ $column_header{transdate} =
+ qq|<th><a class=listheading href=$href&sort=transdate>|
+ . $locale->text('Date')
+ . qq|</a></th>|;
+ $column_header{reqdate} =
+ qq|<th><a class=listheading href=$href&sort=reqdate>$requiredby</a></th>|;
+ $column_header{ordnumber} =
+ qq|<th><a class=listheading href=$href&sort=ordnumber>|
+ . $locale->text('Order')
+ . qq|</a></th>|;
+ $column_header{ponumber} =
+ qq|<th><a class=listheading href=$href&sort=ponumber>|
+ . $locale->text('PO Number')
+ . qq|</a></th>|;
+ $column_header{quonumber} =
+qq|<th><a class=listheading href=$href&sort=quonumber>$quotation</a></th>|;
+ $column_header{name} =
+ qq|<th><a class=listheading href=$href&sort=name>$name</a></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{amount} =
+ qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
+ $column_header{curr} =
+ qq|<th><a class=listheading href=$href&sort=curr>|
+ . $locale->text('Curr')
+ . qq|</a></th>|;
+ $column_header{shipvia} =
+ qq|<th><a class=listheading href=$href&sort=shipvia>|
+ . $locale->text('Ship via')
+ . qq|</a></th>|;
+ $column_header{open} =
+ qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
+ $column_header{closed} =
+ qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
+
+ $column_header{employee} =
+ qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
+ $column_header{manager} =
+ qq|<th><a class=listheading href=$href&sort=manager>|
+ . $locale->text('Manager')
+ . qq|</a></th>|;
+
+ for (qw(amount tax netamount)) {
+ $column_header{"fx_$_"} = "<th>&nbsp;</th>";
+ }
- if ($form->{l_curr} && $_ =~ /(amount|tax)/) {
- push @column_index, "fx_$_";
- }
-
- # add column to href and callback
- $callback .= "&l_$_=Y";
- $href .= "&l_$_=Y";
+ if ( $form->{ $form->{vc} } ) {
+ $option = $locale->text( ucfirst $form->{vc} );
+ $option .= " : $form->{$form->{vc}}";
}
- }
-
- if ($form->{l_subtotal} eq 'Y') {
- $callback .= "&l_subtotal=Y";
- $href .= "&l_subtotal=Y";
- }
-
- $requiredby = $locale->text('Required by');
-
- $i = 1;
- if ($form->{vc} eq 'vendor') {
- if ($form->{type} eq 'receive_order') {
- $form->{title} = $locale->text('Receive Merchandise');
- }
- if ($form->{type} eq 'purchase_order') {
- $form->{title} = $locale->text('Purchase Orders');
- if ($myconfig{acs} !~ /Order Entry--Order Entry/) {
- $button{'Order Entry--Purchase Order'}{code} = qq|<button class="submit" type="submit" name="action" value="purchase_order">|.$locale->text('Purchase Order').qq|</button> |;
- $button{'Order Entry--Purchase Order'}{order} = $i++;
- }
- }
- if ($form->{type} eq 'generate_sales_order') {
- $form->{title} = $locale->text('Purchase Orders');
- $form->{type} = "purchase_order";
- unshift @column_index, "ndx";
- if ($myconfig{acs} !~ /Order Entry--Order Entry/) {
- $button{'Order Entry--Sales Order'}{code} = qq|<button class="submit" type="submit" name="action" value="generate_sales_order">|.$locale->text('Generate Sales Order').qq|</button> |;
- $button{'Order Entry--Sales Order'}{order} = $i++;
- }
- }
- if ($form->{type} eq 'consolidate_purchase_order') {
- $form->{title} = $locale->text('Purchase Orders');
- $form->{type} = "purchase_order";
- unshift @column_index, "ndx";
- if ($myconfig{acs} !~ /Order Entry--Order Entry/) {
- $button{'Order Entry--Purchase Order'}{code} = qq|<button class="submit" type="submit" name="action" value="consolidate_orders">|.$locale->text('Consolidate Orders').qq|</button> |;
- $button{'Order Entry--Purchase Order'}{order} = $i++;
- }
- }
-
- if ($form->{type} eq 'request_quotation') {
- $form->{title} = $locale->text('Request for Quotations');
- $quotation = $locale->text('RFQ');
-
- if ($myconfig{acs} !~ /Quotations--Quotations/) {
- $button{'Quotations--RFQ'}{code} = qq|<button class="submit" type="submit" name="action" value="add">|.$locale->text('RFQ').qq|</button> |;
- $button{'Quotations--RFQ'}{order} = $i++;
- }
-
- }
- $name = $locale->text('Vendor');
- $employee = $locale->text('Employee');
- }
- if ($form->{vc} eq 'customer') {
- if ($form->{type} eq 'sales_order') {
- $form->{title} = $locale->text('Sales Orders');
- $employee = $locale->text('Salesperson');
-
- if ($myconfig{acs} !~ /Order Entry--Order Entry/) {
- $button{'Order Entry--Sales Order'}{code} = qq|<button class="submit" type="submit" name="action" value="sales_order">|.$locale->text('Sales Order').qq|</button> |;
- $button{'Order Entry--Sales Order'}{order} = $i++;
- }
-
- }
- if ($form->{type} eq 'generate_purchase_order') {
- $form->{title} = $locale->text('Sales Orders');
- $form->{type} = "sales_order";
- $employee = $locale->text('Salesperson');
- unshift @column_index, "ndx";
- if ($myconfig{acs} !~ /Order Entry--Order Entry/) {
- $button{'Order Entry--Purchase Order'}{code} = qq|<button class="submit" type="submit" name="action" value="generate_purchase_orders">|.$locale->text('Generate Purchase Orders').qq|</button> |;
- $button{'Order Entry--Purchase Order'}{order} = $i++;
- }
- }
- if ($form->{type} eq 'consolidate_sales_order') {
- $form->{title} = $locale->text('Sales Orders');
- $form->{type} = "sales_order";
- unshift @column_index, "ndx";
- if ($myconfig{acs} !~ /Order Entry--Order Entry/) {
- $button{'Order Entry--Sales Order'}{code} = qq|<button class="submit" type="submit" name="action" value="consolidate_orders">|.$locale->text('Consolidate Orders').qq|</button> |;
- $button{'Order Entry--Sales Order'}{order} = $i++;
- }
- }
-
- if ($form->{type} eq 'ship_order') {
- $form->{title} = $locale->text('Ship Merchandise');
- $employee = $locale->text('Salesperson');
- }
- if ($form->{type} eq 'sales_quotation') {
- $form->{title} = $locale->text('Quotations');
- $employee = $locale->text('Employee');
- $requiredby = $locale->text('Valid until');
- $quotation = $locale->text('Quotation');
-
- if ($myconfig{acs} !~ /Quotations--Quotations/) {
- $button{'Quotations--Quotation'}{code} = qq|<button class="submit" type="submit" name="action" value="add">|.$locale->text('Quotation').qq|</button> |;
- $button{'Quotations--Quotation'}{order} = $i++;
- }
-
- }
- $name = $locale->text('Customer');
- }
-
- for (split /;/, $myconfig{acs}) { delete $button{$_} }
-
- $column_header{ndx} = qq|<th class=listheading>&nbsp;</th>|;
- $column_header{runningnumber} = qq|<th class=listheading>&nbsp;</th>|;
- $column_header{id} = qq|<th><a class=listheading href=$href&sort=id>|.$locale->text('ID').qq|</a></th>|;
- $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>|.$locale->text('Date').qq|</a></th>|;
- $column_header{reqdate} = qq|<th><a class=listheading href=$href&sort=reqdate>$requiredby</a></th>|;
- $column_header{ordnumber} = qq|<th><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order').qq|</a></th>|;
- $column_header{ponumber} = qq|<th><a class=listheading href=$href&sort=ponumber>|.$locale->text('PO Number').qq|</a></th>|;
- $column_header{quonumber} = qq|<th><a class=listheading href=$href&sort=quonumber>$quotation</a></th>|;
- $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>$name</a></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{amount} = qq|<th class=listheading>|.$locale->text('Total').qq|</th>|;
- $column_header{curr} = qq|<th><a class=listheading href=$href&sort=curr>|.$locale->text('Curr').qq|</a></th>|;
- $column_header{shipvia} = qq|<th><a class=listheading href=$href&sort=shipvia>|.$locale->text('Ship via').qq|</a></th>|;
- $column_header{open} = qq|<th class=listheading>|.$locale->text('O').qq|</th>|;
- $column_header{closed} = qq|<th class=listheading>|.$locale->text('C').qq|</th>|;
-
- $column_header{employee} = qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
- $column_header{manager} = qq|<th><a class=listheading href=$href&sort=manager>|.$locale->text('Manager').qq|</a></th>|;
-
- for (qw(amount tax netamount)) { $column_header{"fx_$_"} = "<th>&nbsp;</th>" }
-
- if ($form->{$form->{vc}}) {
- $option = $locale->text(ucfirst $form->{vc});
- $option .= " : $form->{$form->{vc}}";
- }
- if ($form->{warehouse}) {
- ($warehouse) = split /--/, $form->{warehouse};
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Warehouse');
- $option .= " : $warehouse";
- }
- if ($form->{department}) {
- $option .= "\n<br>" if ($option);
- ($department) = split /--/, $form->{department};
- $option .= $locale->text('Department')." : $department";
- }
- if ($form->{employee}) {
- ($employee) = split /--/, $form->{employee};
- $option .= "\n<br>" if ($option);
- if ($form->{vc} eq 'customer') {
- $option .= $locale->text('Salesperson');
- } else {
- $option .= $locale->text('Employee');
- }
- $option .= " : $employee";
- }
- if ($form->{ordnumber}) {
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Order Number')." : $form->{ordnumber}";
- }
- if ($form->{quonumber}) {
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Quotation Number')." : $form->{quonumber}";
- }
- if ($form->{ponumber}) {
- $option = $locale->text('PO Number');
- $option .= " : $form->{ponumber}";
- }
- if ($form->{shipvia}) {
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Ship via')." : $form->{shipvia}";
- }
- if ($form->{description}) {
- $option .= "\n<br>" if $option;
- $option .= $locale->text('Description')." : $form->{description}";
- }
- if ($form->{transdatefrom}) {
- $option .= "\n<br>".$locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
- }
- if ($form->{transdateto}) {
- $option .= "\n<br>".$locale->text('To')." ".$locale->date(\%myconfig, $form->{transdateto}, 1);
- }
- if ($form->{open}) {
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Open');
- }
- if ($form->{closed}) {
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Closed');
- }
-
- $form->header;
+ if ( $form->{warehouse} ) {
+ ($warehouse) = split /--/, $form->{warehouse};
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Warehouse');
+ $option .= " : $warehouse";
+ }
+ if ( $form->{department} ) {
+ $option .= "\n<br>" if ($option);
+ ($department) = split /--/, $form->{department};
+ $option .= $locale->text('Department') . " : $department";
+ }
+ if ( $form->{employee} ) {
+ ($employee) = split /--/, $form->{employee};
+ $option .= "\n<br>" if ($option);
+ if ( $form->{vc} eq 'customer' ) {
+ $option .= $locale->text('Salesperson');
+ }
+ else {
+ $option .= $locale->text('Employee');
+ }
+ $option .= " : $employee";
+ }
+ if ( $form->{ordnumber} ) {
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Order Number') . " : $form->{ordnumber}";
+ }
+ if ( $form->{quonumber} ) {
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Quotation Number') . " : $form->{quonumber}";
+ }
+ if ( $form->{ponumber} ) {
+ $option = $locale->text('PO Number');
+ $option .= " : $form->{ponumber}";
+ }
+ if ( $form->{shipvia} ) {
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Ship via') . " : $form->{shipvia}";
+ }
+ if ( $form->{description} ) {
+ $option .= "\n<br>" if $option;
+ $option .= $locale->text('Description') . " : $form->{description}";
+ }
+ if ( $form->{transdatefrom} ) {
+ $option .= "\n<br>"
+ . $locale->text('From') . " "
+ . $locale->date( \%myconfig, $form->{transdatefrom}, 1 );
+ }
+ if ( $form->{transdateto} ) {
+ $option .= "\n<br>"
+ . $locale->text('To') . " "
+ . $locale->date( \%myconfig, $form->{transdateto}, 1 );
+ }
+ if ( $form->{open} ) {
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Open');
+ }
+ if ( $form->{closed} ) {
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Closed');
+ }
+
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -1529,123 +1853,164 @@ sub transactions {
<table width=100%>
<tr class=listheading>|;
- for (@column_index) { print "\n$column_header{$_}" }
+ for (@column_index) { print "\n$column_header{$_}" }
- print qq|
+ print qq|
</tr>
|;
- # add sort and escape callback
- $callback .= "&sort=$form->{sort}";
- $form->{callback} = $callback;
- $callback = $form->escape($callback);
+ # add sort and escape callback
+ $callback .= "&sort=$form->{sort}";
+ $form->{callback} = $callback;
+ $callback = $form->escape($callback);
- # flip direction
- $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
- $href =~ s/&direction=(\w+)&/&direction=$direction&/;
+ # flip direction
+ $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
+ $href =~ s/&direction=(\w+)&/&direction=$direction&/;
- if (@{ $form->{OE} }) {
- $sameitem = $form->{OE}->[0]->{$form->{sort}};
- }
-
- $action = "edit";
- $action = "ship_receive" if ($form->{type} =~ /(ship|receive)_order/);
+ if ( @{ $form->{OE} } ) {
+ $sameitem = $form->{OE}->[0]->{ $form->{sort} };
+ }
- $warehouse = $form->escape($form->{warehouse});
+ $action = "edit";
+ $action = "ship_receive" if ( $form->{type} =~ /(ship|receive)_order/ );
+
+ $warehouse = $form->escape( $form->{warehouse} );
+
+ $i = 0;
+ foreach $oe ( @{ $form->{OE} } ) {
+
+ $i++;
+
+ if ( $form->{l_subtotal} eq 'Y' ) {
+ if ( $sameitem ne $oe->{ $form->{sort} } ) {
+ &subtotal;
+ $sameitem = $oe->{ $form->{sort} };
+ }
+ }
+
+ if ( $form->{l_curr} ) {
+ for (qw(netamount amount)) { $oe->{"fx_$_"} = $oe->{$_} }
+ $oe->{fx_tax} = $oe->{fx_amount} - $oe->{fx_netamount};
+ for (qw(netamount amount)) { $oe->{$_} *= $oe->{exchangerate} }
+
+ for (qw(netamount amount)) {
+ $column_data{"fx_$_"} = "<td align=right>"
+ . $form->format_amount( \%myconfig, $oe->{"fx_$_"}, 2,
+ "&nbsp;" )
+ . "</td>";
+ }
+ $column_data{fx_tax} = "<td align=right>"
+ . $form->format_amount( \%myconfig,
+ $oe->{fx_amount} - $oe->{fx_netamount},
+ 2, "&nbsp;" )
+ . "</td>";
+
+ $totalfxnetamount += $oe->{fx_netamount};
+ $totalfxamount += $oe->{fx_amount};
+
+ $subtotalfxnetamount += $oe->{fx_netamount};
+ $subtotalfxamount += $oe->{fx_amount};
+ }
+
+ for (qw(netamount amount)) {
+ $column_data{$_} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $oe->{$_}, 2, "&nbsp;" )
+ . "</td>";
+ }
+ $column_data{tax} = "<td align=right>"
+ . $form->format_amount( \%myconfig, $oe->{amount} - $oe->{netamount},
+ 2, "&nbsp;" )
+ . "</td>";
+
+ $totalnetamount += $oe->{netamount};
+ $totalamount += $oe->{amount};
+
+ $subtotalnetamount += $oe->{netamount};
+ $subtotalamount += $oe->{amount};
+
+ $column_data{id} = "<td>$oe->{id}</td>";
+ $column_data{transdate} = "<td>$oe->{transdate}&nbsp;</td>";
+ $column_data{reqdate} = "<td>$oe->{reqdate}&nbsp;</td>";
+
+ $column_data{runningnumber} = qq|<td align=right>$i</td>|;
+ $column_data{ndx} =
+qq|<td><input name="ndx_$i" class=checkbox type=checkbox value=$oe->{id} checked></td>|;
+ $column_data{$ordnumber} =
+"<td><a href=$form->{script}?path=$form->{path}&action=$action&type=$form->{type}&id=$oe->{id}&warehouse=$warehouse&vc=$form->{vc}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$oe->{$ordnumber}</a></td>";
+
+ $name = $form->escape( $oe->{name} );
+ $column_data{name} =
+qq|<td><a href=ct.pl?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&action=edit&id=$oe->{"$form->{vc}_id"}&db=$form->{vc}&callback=$callback>$oe->{name}</a></td>|;
+
+ for (qw(employee manager shipvia curr ponumber)) {
+ $column_data{$_} = "<td>$oe->{$_}&nbsp;</td>";
+ }
+
+ if ( $oe->{closed} ) {
+ $column_data{closed} = "<td align=center>*</td>";
+ $column_data{open} = "<td>&nbsp;</td>";
+ }
+ else {
+ $column_data{closed} = "<td>&nbsp;</td>";
+ $column_data{open} = "<td align=center>*</td>";
+ }
+
+ $j++;
+ $j %= 2;
+ print "
+ <tr class=listrow$j>";
- $i = 0;
- foreach $oe (@{ $form->{OE} }) {
+ for (@column_index) { print "\n$column_data{$_}" }
- $i++;
+ print qq|
+ </tr>
+|;
- if ($form->{l_subtotal} eq 'Y') {
- if ($sameitem ne $oe->{$form->{sort}}) {
- &subtotal;
- $sameitem = $oe->{$form->{sort}};
- }
}
-
- if ($form->{l_curr}) {
- for (qw(netamount amount)) { $oe->{"fx_$_"} = $oe->{$_} }
- $oe->{fx_tax} = $oe->{fx_amount} - $oe->{fx_netamount};
- for (qw(netamount amount)) { $oe->{$_} *= $oe->{exchangerate} }
-
- for (qw(netamount amount)) { $column_data{"fx_$_"} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{"fx_$_"}, 2, "&nbsp;")."</td>" }
- $column_data{fx_tax} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{fx_amount} - $oe->{fx_netamount}, 2, "&nbsp;")."</td>";
-
- $totalfxnetamount += $oe->{fx_netamount};
- $totalfxamount += $oe->{fx_amount};
- $subtotalfxnetamount += $oe->{fx_netamount};
- $subtotalfxamount += $oe->{fx_amount};
+ if ( $form->{l_subtotal} eq 'Y' ) {
+ &subtotal;
}
-
- for (qw(netamount amount)) { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{$_}, 2, "&nbsp;")."</td>" }
- $column_data{tax} = "<td align=right>".$form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount}, 2, "&nbsp;")."</td>";
-
- $totalnetamount += $oe->{netamount};
- $totalamount += $oe->{amount};
-
- $subtotalnetamount += $oe->{netamount};
- $subtotalamount += $oe->{amount};
-
- $column_data{id} = "<td>$oe->{id}</td>";
- $column_data{transdate} = "<td>$oe->{transdate}&nbsp;</td>";
- $column_data{reqdate} = "<td>$oe->{reqdate}&nbsp;</td>";
-
- $column_data{runningnumber} = qq|<td align=right>$i</td>|;
- $column_data{ndx} = qq|<td><input name="ndx_$i" class=checkbox type=checkbox value=$oe->{id} checked></td>|;
- $column_data{$ordnumber} = "<td><a href=$form->{script}?path=$form->{path}&action=$action&type=$form->{type}&id=$oe->{id}&warehouse=$warehouse&vc=$form->{vc}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$oe->{$ordnumber}</a></td>";
-
- $name = $form->escape($oe->{name});
- $column_data{name} = qq|<td><a href=ct.pl?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&action=edit&id=$oe->{"$form->{vc}_id"}&db=$form->{vc}&callback=$callback>$oe->{name}</a></td>|;
-
- for (qw(employee manager shipvia curr ponumber)) { $column_data{$_} = "<td>$oe->{$_}&nbsp;</td>" }
+ # print totals
+ print qq|
+ <tr class=listtotal>|;
- if ($oe->{closed}) {
- $column_data{closed} = "<td align=center>*</td>";
- $column_data{open} = "<td>&nbsp;</td>";
- } else {
- $column_data{closed} = "<td>&nbsp;</td>";
- $column_data{open} = "<td align=center>*</td>";
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{netamount} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalnetamount, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{tax} = "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalamount - $totalnetamount,
+ 2, "&nbsp;" )
+ . "</th>";
+ $column_data{amount} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalamount, 2, "&nbsp;" ) . "</th>";
+
+ if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
+ $column_data{fx_netamount} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalfxnetamount, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{fx_tax} = "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig,
+ $totalfxamount - $totalfxnetamount,
+ 2, "&nbsp;" )
+ . "</th>";
+ $column_data{fx_amount} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalfxamount, 2, "&nbsp;" )
+ . "</th>";
}
- $j++; $j %= 2;
- print "
- <tr class=listrow$j>";
-
for (@column_index) { print "\n$column_data{$_}" }
print qq|
- </tr>
-|;
-
- }
-
- if ($form->{l_subtotal} eq 'Y') {
- &subtotal;
- }
-
- # print totals
- print qq|
- <tr class=listtotal>|;
-
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $column_data{netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;")."</th>";
- $column_data{tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount - $totalnetamount, 2, "&nbsp;")."</th>";
- $column_data{amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalamount, 2, "&nbsp;")."</th>";
-
- if ($form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal}) {
- $column_data{fx_netamount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxnetamount, 2, "&nbsp;")."</th>";
- $column_data{fx_tax} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount - $totalfxnetamount, 2, "&nbsp;")."</th>";
- $column_data{fx_amount} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalfxamount, 2, "&nbsp;")."</th>";
- }
-
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
</tr>
</td>
</table>
@@ -1658,9 +2023,11 @@ sub transactions {
<br>
|;
- $form->hide_form(qw(callback type vc path login sessionid department ordnumber ponumber shipvia));
-
- print qq|
+ $form->hide_form(
+ qw(callback type vc path login sessionid department ordnumber ponumber shipvia)
+ );
+
+ print qq|
<input type=hidden name=rowcount value=$i>
@@ -1669,16 +2036,18 @@ sub transactions {
|;
- if ($form->{type} !~ /(ship|receive)_order/) {
- for (sort { $a->{order} <=> $b->{order} } %button) { print $_->{code} }
- }
+ if ( $form->{type} !~ /(ship|receive)_order/ ) {
+ for ( sort { $a->{order} <=> $b->{order} } %button ) {
+ print $_->{code};
+ }
+ }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -1687,329 +2056,375 @@ sub transactions {
}
+sub subtotal {
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{netamount} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalnetamount, 2, "&nbsp;" )
+ . "</th>";
+ $column_data{tax} = "<td class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalamount - $subtotalnetamount,
+ 2, "&nbsp;" )
+ . "</th>";
+ $column_data{amount} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalamount, 2, "&nbsp;" )
+ . "</th>";
+
+ if ( $form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal} ) {
+ $column_data{fx_netamount} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalfxnetamount, 2,
+ "&nbsp;" )
+ . "</th>";
+ $column_data{fx_tax} = "<td class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig,
+ $subtotalfxamount - $subtotalfxnetamount,
+ 2, "&nbsp;" )
+ . "</th>";
+ $column_data{fx_amount} =
+ "<th class=listsubtotal align=right>"
+ . $form->format_amount( \%myconfig, $subtotalfxamount, 2, "&nbsp;" )
+ . "</th>";
+ }
-sub subtotal {
+ $subtotalnetamount = 0;
+ $subtotalamount = 0;
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- $column_data{netamount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;")."</th>";
- $column_data{tax} = "<td class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, 2, "&nbsp;")."</th>";
- $column_data{amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalamount, 2, "&nbsp;")."</th>";
-
- if ($form->{l_curr} && $form->{sort} eq 'curr' && $form->{l_subtotal}) {
- $column_data{fx_netamount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxnetamount, 2, "&nbsp;")."</th>";
- $column_data{fx_tax} = "<td class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxamount - $subtotalfxnetamount, 2, "&nbsp;")."</th>";
- $column_data{fx_amount} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalfxamount, 2, "&nbsp;")."</th>";
- }
-
- $subtotalnetamount = 0;
- $subtotalamount = 0;
-
- $subtotalfxnetamount = 0;
- $subtotalfxamount = 0;
+ $subtotalfxnetamount = 0;
+ $subtotalfxamount = 0;
- print "
+ print "
<tr class=listsubtotal>
";
-
- for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
</tr>
|;
}
-
sub save {
- if ($form->{type} =~ /_order$/) {
- $msg = $locale->text('Order Date missing!');
- } else {
- $msg = $locale->text('Quotation Date missing!');
- }
-
- $form->isblank("transdate", $msg);
+ if ( $form->{type} =~ /_order$/ ) {
+ $msg = $locale->text('Order Date missing!');
+ }
+ else {
+ $msg = $locale->text('Quotation Date missing!');
+ }
- $msg = ucfirst $form->{vc};
- $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
+ $form->isblank( "transdate", $msg );
-# $locale->text('Customer missing!');
-# $locale->text('Vendor missing!');
-
- $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
-
- &validate_items;
-
- # if the name changed get new values
- if (&check_name($form->{vc})) {
- &update;
- exit;
- }
-
-
- # this is for the internal notes section for the [email] Subject
- if ($form->{type} =~ /_order$/) {
- if ($form->{type} eq 'sales_order') {
- $form->{label} = $locale->text('Sales Order');
-
- $numberfld = "sonumber";
- $ordnumber = "ordnumber";
- } else {
- $form->{label} = $locale->text('Purchase Order');
-
- $numberfld = "ponumber";
- $ordnumber = "ordnumber";
- }
-
- $err = $locale->text('Cannot save order!');
-
- } else {
- if ($form->{type} eq 'sales_quotation') {
- $form->{label} = $locale->text('Quotation');
-
- $numberfld = "sqnumber";
- $ordnumber = "quonumber";
- } else {
- $form->{label} = $locale->text('Request for Quotation');
-
- $numberfld = "rfqnumber";
- $ordnumber = "quonumber";
- }
-
- $err = $locale->text('Cannot save quotation!');
-
- }
-
- if (! $form->{repost}) {
- if ($form->{id}) {
- &repost("Save");
- exit;
- }
- }
-
- if (OE->save(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Order saved!'));
- } else {
- $form->error($err);
- }
+ $msg = ucfirst $form->{vc};
+ $form->isblank( $form->{vc}, $locale->text( $msg . " missing!" ) );
-}
+ # $locale->text('Customer missing!');
+ # $locale->text('Vendor missing!');
+ $form->isblank( "exchangerate", $locale->text('Exchange rate missing!') )
+ if ( $form->{currency} ne $form->{defaultcurrency} );
-sub print_and_save {
+ &validate_items;
+
+ # if the name changed get new values
+ if ( &check_name( $form->{vc} ) ) {
+ &update;
+ exit;
+ }
+
+ # this is for the internal notes section for the [email] Subject
+ if ( $form->{type} =~ /_order$/ ) {
+ if ( $form->{type} eq 'sales_order' ) {
+ $form->{label} = $locale->text('Sales Order');
+
+ $numberfld = "sonumber";
+ $ordnumber = "ordnumber";
+ }
+ else {
+ $form->{label} = $locale->text('Purchase Order');
- $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';
+ $numberfld = "ponumber";
+ $ordnumber = "ordnumber";
+ }
- $old_form = new Form;
- $form->{display_form} = "save";
- for (keys %$form) { $old_form->{$_} = $form->{$_} }
- $old_form->{rowcount}++;
+ $err = $locale->text('Cannot save order!');
+
+ }
+ else {
+ if ( $form->{type} eq 'sales_quotation' ) {
+ $form->{label} = $locale->text('Quotation');
- &print_form($old_form);
+ $numberfld = "sqnumber";
+ $ordnumber = "quonumber";
+ }
+ else {
+ $form->{label} = $locale->text('Request for Quotation');
+
+ $numberfld = "rfqnumber";
+ $ordnumber = "quonumber";
+ }
+
+ $err = $locale->text('Cannot save quotation!');
+
+ }
+
+ if ( !$form->{repost} ) {
+ if ( $form->{id} ) {
+ &repost("Save");
+ exit;
+ }
+ }
+
+ if ( OE->save( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Order saved!') );
+ }
+ else {
+ $form->error($err);
+ }
}
+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';
+
+ $old_form = new Form;
+ $form->{display_form} = "save";
+ for ( keys %$form ) { $old_form->{$_} = $form->{$_} }
+ $old_form->{rowcount}++;
+
+ &print_form($old_form);
+
+}
sub delete {
- $form->header;
+ $form->header;
- if ($form->{type} =~ /_order$/) {
- $msg = $locale->text('Are you sure you want to delete Order Number');
- $ordnumber = 'ordnumber';
- } else {
- $msg = $locale->text('Are you sure you want to delete Quotation Number');
- $ordnumber = 'quonumber';
- }
-
- print qq|
+ if ( $form->{type} =~ /_order$/ ) {
+ $msg = $locale->text('Are you sure you want to delete Order Number');
+ $ordnumber = 'ordnumber';
+ }
+ else {
+ $msg =
+ $locale->text('Are you sure you want to delete Quotation Number');
+ $ordnumber = 'quonumber';
+ }
+
+ print qq|
<body>
<form method=post action=$form->{script}>
|;
- $form->{action} = "yes";
- $form->hide_form;
+ $form->{action} = "yes";
+ $form->hide_form;
- print qq|
-<h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
+ print qq|
+<h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
<h4>$msg $form->{$ordnumber}</h4>
<p>
-<button name="action" class="submit" type="submit" value="yes">|.$locale->text('Yes').qq|</button>
+<button name="action" class="submit" type="submit" value="yes">|
+ . $locale->text('Yes')
+ . qq|</button>
</form>
</body>
</html>
|;
+}
+
+sub yes {
+
+ if ( $form->{type} =~ /_order$/ ) {
+ $msg = $locale->text('Order deleted!');
+ $err = $locale->text('Cannot delete order!');
+ }
+ else {
+ $msg = $locale->text('Quotation deleted!');
+ $err = $locale->text('Cannot delete quotation!');
+ }
+
+ if ( OE->delete( \%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool} ) ) {
+ $form->redirect($msg);
+ }
+ else {
+ $form->error($err);
+ }
}
+sub vendor_invoice { &invoice }
+sub sales_invoice { &invoice }
+sub invoice {
-sub yes {
+ if ( $form->{type} =~ /_order$/ ) {
+ $form->isblank( "ordnumber", $locale->text('Order Number missing!') );
+ $form->isblank( "transdate", $locale->text('Order Date missing!') );
- if ($form->{type} =~ /_order$/) {
- $msg = $locale->text('Order deleted!');
- $err = $locale->text('Cannot delete order!');
- } else {
- $msg = $locale->text('Quotation deleted!');
- $err = $locale->text('Cannot delete quotation!');
- }
-
- if (OE->delete(\%myconfig, \%$form, ${LedgerSMB::Sysconfig::spool})) {
- $form->redirect($msg);
- } else {
- $form->error($err);
- }
+ }
+ else {
+ $form->isblank( "quonumber",
+ $locale->text('Quotation Number missing!') );
+ $form->isblank( "transdate", $locale->text('Quotation Date missing!') );
+ $form->{ordnumber} = "";
+ }
-}
+ # if the name changed get new values
+ if ( &check_name( $form->{vc} ) ) {
+ &update;
+ exit;
+ }
+ if ( $form->{type} =~ /_order/
+ && $form->{currency} ne $form->{defaultcurrency} )
+ {
-sub vendor_invoice { &invoice };
-sub sales_invoice { &invoice };
+ # check if we need a new exchangerate
+ $buysell = ( $form->{type} eq 'sales_order' ) ? "buy" : "sell";
-sub invoice {
-
- if ($form->{type} =~ /_order$/) {
- $form->isblank("ordnumber", $locale->text('Order Number missing!'));
- $form->isblank("transdate", $locale->text('Order Date missing!'));
+ $orddate = $form->current_date( \%myconfig );
+ $exchangerate =
+ $form->check_exchangerate( \%myconfig, $form->{currency}, $orddate,
+ $buysell );
+
+ if ( !$exchangerate ) {
+ &backorder_exchangerate( $orddate, $buysell );
+ exit;
+ }
+ }
- } else {
- $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
- $form->isblank("transdate", $locale->text('Quotation Date missing!'));
- $form->{ordnumber} = "";
- }
+ # close orders/quotations
+ $form->{closed} = 1;
- # if the name changed get new values
- if (&check_name($form->{vc})) {
- &update;
- exit;
- }
+ OE->save( \%myconfig, \%$form );
+ $form->{transdate} = $form->current_date( \%myconfig );
+ $form->{duedate} =
+ $form->current_date( \%myconfig, $form->{transdate}, $form->{terms} * 1 );
- if ($form->{type} =~ /_order/ && $form->{currency} ne $form->{defaultcurrency}) {
- # check if we need a new exchangerate
- $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
-
- $orddate = $form->current_date(\%myconfig);
- $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate, $buysell);
+ $form->{id} = '';
+ $form->{closed} = 0;
+ $form->{rowcount}--;
+ $form->{shipto} = 1;
- if (!$exchangerate) {
- &backorder_exchangerate($orddate, $buysell);
- exit;
+ if ( $form->{type} =~ /_order$/ ) {
+ $form->{exchangerate} = $exchangerate;
+ &create_backorder;
}
- }
+ if ( $form->{type} eq 'purchase_order'
+ || $form->{type} eq 'request_quotation' )
+ {
+ $form->{title} = $locale->text('Add Vendor Invoice');
+ $form->{script} = 'ir.pl';
- # close orders/quotations
- $form->{closed} = 1;
+ $script = "ir";
+ $buysell = 'sell';
+ }
+ if ( $form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation' )
+ {
+ $form->{title} = $locale->text('Add Sales Invoice');
+ $form->{script} = 'is.pl';
+ $script = "is";
+ $buysell = 'buy';
+ }
- OE->save(\%myconfig, \%$form);
-
- $form->{transdate} = $form->current_date(\%myconfig);
- $form->{duedate} = $form->current_date(\%myconfig, $form->{transdate}, $form->{terms} * 1);
-
- $form->{id} = '';
- $form->{closed} = 0;
- $form->{rowcount}--;
- $form->{shipto} = 1;
-
-
- if ($form->{type} =~ /_order$/) {
- $form->{exchangerate} = $exchangerate;
- &create_backorder;
- }
-
-
- if ($form->{type} eq 'purchase_order' || $form->{type} eq 'request_quotation') {
- $form->{title} = $locale->text('Add Vendor Invoice');
- $form->{script} = 'ir.pl';
-
- $script = "ir";
- $buysell = 'sell';
- }
- if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
- $form->{title} = $locale->text('Add Sales Invoice');
- $form->{script} = 'is.pl';
- $script = "is";
- $buysell = 'buy';
- }
-
- for (qw(id subject message printed emailed queued)) { delete $form->{$_} }
- $form->{$form->{vc}} =~ s/--.*//g;
- $form->{type} = "invoice";
-
- # locale messages
- $locale = LedgerSMB::Locale->get_handle($myconfig{countrycode}) or
- $form->error("Locale not loaded: $!\n");
- #$form->{charset} = $locale->encoding;
- $form->{charset} = 'UTF-8';
- $locale->encoding('UTF-8');
-
- require "bin/$form->{script}";
-
- # customized scripts
- if (-f "bin/custom/$form->{script}") {
- eval { require "bin/custom/$form->{script}"; };
- }
-
- # customized scripts for login
- if (-f "bin/custom/$form->{login}_$form->{script}") {
- eval { require "bin/custom/$form->{login}_$form->{script}"; };
- }
-
- for ("$form->{vc}", "currency") { $form->{"select$_"} = "" }
- for (qw(currency oldcurrency employee department intnotes notes taxincluded)) { $temp{$_} = $form->{$_} }
-
- &invoice_links;
-
- $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
-
- &prepare_invoice;
-
- for (keys %temp) { $form->{$_} = $temp{$_} }
-
- $form->{exchangerate} = "";
- $form->{forex} = "";
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell)));
-
- for $i (1 .. $form->{rowcount}) {
- $form->{"deliverydate_$i"} = $form->{"reqdate_$i"};
- for (qw(qty sellprice discount)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) }
- }
+ for (qw(id subject message printed emailed queued)) { delete $form->{$_} }
+ $form->{ $form->{vc} } =~ s/--.*//g;
+ $form->{type} = "invoice";
- for (qw(id subject message printed emailed queued audittrail)) { delete $form->{$_} }
+ # locale messages
+ $locale = LedgerSMB::Locale->get_handle( $myconfig{countrycode} )
+ or $form->error("Locale not loaded: $!\n");
- &display_form;
+ #$form->{charset} = $locale->encoding;
+ $form->{charset} = 'UTF-8';
+ $locale->encoding('UTF-8');
-}
+ require "bin/$form->{script}";
+ # customized scripts
+ if ( -f "bin/custom/$form->{script}" ) {
+ eval { require "bin/custom/$form->{script}"; };
+ }
+ # customized scripts for login
+ if ( -f "bin/custom/$form->{login}_$form->{script}" ) {
+ eval { require "bin/custom/$form->{login}_$form->{script}"; };
+ }
+
+ for ( "$form->{vc}", "currency" ) { $form->{"select$_"} = "" }
+ for (
+ qw(currency oldcurrency employee department intnotes notes taxincluded))
+ {
+ $temp{$_} = $form->{$_};
+ }
+
+ &invoice_links;
+
+ $form->{creditremaining} -= ( $form->{oldinvtotal} - $form->{ordtotal} );
+
+ &prepare_invoice;
+
+ for ( keys %temp ) { $form->{$_} = $temp{$_} }
+
+ $form->{exchangerate} = "";
+ $form->{forex} = "";
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate = $form->check_exchangerate(
+ \%myconfig, $form->{currency}, $form->{transdate}, $buysell
+ )
+ )
+ );
+
+ for $i ( 1 .. $form->{rowcount} ) {
+ $form->{"deliverydate_$i"} = $form->{"reqdate_$i"};
+ for (qw(qty sellprice discount)) {
+ $form->{"${_}_$i"} =
+ $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+ }
+
+ for (qw(id subject message printed emailed queued audittrail)) {
+ delete $form->{$_};
+ }
+
+ &display_form;
+
+}
sub backorder_exchangerate {
- my ($orddate, $buysell) = @_;
+ my ( $orddate, $buysell ) = @_;
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
|;
- # delete action variable
- for (qw(action nextsub exchangerate)) { delete $form->{$_} }
+ # delete action variable
+ for (qw(action nextsub exchangerate)) { delete $form->{$_} }
- $form->hide_form;
+ $form->hide_form;
- $form->{title} = $locale->text('Add Exchange Rate');
-
- print qq|
+ $form->{title} = $locale->text('Add Exchange Rate');
+
+ print qq|
<input type=hidden name=exchangeratedate value=$orddate>
<input type=hidden name=buysell value=$buysell>
@@ -2021,15 +2436,15 @@ sub backorder_exchangerate {
<td>
<table>
<tr>
- <th align=right>|.$locale->text('Currency').qq|</th>
+ <th align=right>| . $locale->text('Currency') . qq|</th>
<td>$form->{currency}</td>
</tr>
<tr>
- <th align=right>|.$locale->text('Date').qq|</th>
+ <th align=right>| . $locale->text('Date') . qq|</th>
<td>$orddate</td>
</tr>
<tr>
- <th align=right>|.$locale->text('Exchange Rate').qq|</th>
+ <th align=right>| . $locale->text('Exchange Rate') . qq|</th>
<td><input name=exchangerate size=11></td>
</tr>
</table>
@@ -2042,7 +2457,9 @@ sub backorder_exchangerate {
<br>
<input type=hidden name=nextsub value=save_exchangerate>
-<button name="action" class="submit" type="submit" value="continue">|.$locale->text('Continue').qq|</button>
+<button name="action" class="submit" type="submit" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
@@ -2050,219 +2467,231 @@ sub backorder_exchangerate {
</html>
|;
-
}
-
sub save_exchangerate {
- $form->isblank("exchangerate", $locale->text('Exchange rate missing!'));
- $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
- $form->save_exchangerate(\%myconfig, $form->{currency}, $form->{exchangeratedate}, $form->{exchangerate}, $form->{buysell});
-
- &invoice;
+ $form->isblank( "exchangerate", $locale->text('Exchange rate missing!') );
+ $form->{exchangerate} =
+ $form->parse_amount( \%myconfig, $form->{exchangerate} );
+ $form->save_exchangerate( \%myconfig, $form->{currency},
+ $form->{exchangeratedate},
+ $form->{exchangerate}, $form->{buysell} );
-}
+ &invoice;
+}
sub create_backorder {
-
- $form->{shipped} = 1;
-
- # figure out if we need to create a backorder
- # items aren't saved if qty != 0
-
- $dec1 = $dec2 = 0;
- for $i (1 .. $form->{rowcount}) {
- ($dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $dec1 = ($dec > $dec1) ? $dec : $dec1;
-
- ($dec) = ($form->{"ship_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $dec2 = ($dec > $dec2) ? $dec : $dec2;
-
- $totalqty += $qty = $form->{"qty_$i"};
- $totalship += $ship = $form->{"ship_$i"};
-
- $form->{"qty_$i"} = $qty - $ship;
- }
-
- $totalqty = $form->round_amount($totalqty, $dec1);
- $totalship = $form->round_amount($totalship, $dec2);
-
- if ($totalship == 0) {
- for (1 .. $form->{rowcount}) { $form->{"ship_$_"} = $form->{"qty_$_"} }
- $form->{ordtotal} = 0;
- $form->{shipped} = 0;
- return;
- }
-
- if ($totalqty == $totalship) {
- for (1 .. $form->{rowcount}) { $form->{"qty_$_"} = $form->{"ship_$_"} }
- $form->{ordtotal} = 0;
- return;
- }
-
- @flds = qw(partnumber description qty ship unit sellprice discount oldqty orderitems_id id bin weight listprice lastcost taxaccounts pricematrix sku onhand deliverydate reqdate projectnumber partsgroup assembly);
-
- for $i (1 .. $form->{rowcount}) {
- for (qw(qty sellprice discount)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) }
-
- $form->{"oldship_$i"} = $form->{"ship_$i"};
- $form->{"ship_$i"} = 0;
- }
-
- # clear flags
- for (qw(id subject message cc bcc printed emailed queued audittrail)) { delete $form->{$_} }
-
- OE->save(\%myconfig, \%$form);
-
- # rebuild rows for invoice
- @a = ();
- $count = 0;
-
- for $i (1 .. $form->{rowcount}) {
- $form->{"qty_$i"} = $form->{"oldship_$i"};
- $form->{"oldqty_$i"} = $form->{"qty_$i"};
-
- $form->{"orderitems_id_$i"} = "";
-
- if ($form->{"qty_$i"}) {
- push @a, {};
- $j = $#a;
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
- }
- }
-
- $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
- $form->{rowcount} = $count;
-}
+ $form->{shipped} = 1;
+ # figure out if we need to create a backorder
+ # items aren't saved if qty != 0
+ $dec1 = $dec2 = 0;
+ for $i ( 1 .. $form->{rowcount} ) {
+ ($dec) = ( $form->{"qty_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $dec1 = ( $dec > $dec1 ) ? $dec : $dec1;
-sub save_as_new {
+ ($dec) = ( $form->{"ship_$i"} =~ /\.(\d+)/ );
+ $dec = length $dec;
+ $dec2 = ( $dec > $dec2 ) ? $dec : $dec2;
+
+ $totalqty += $qty = $form->{"qty_$i"};
+ $totalship += $ship = $form->{"ship_$i"};
+
+ $form->{"qty_$i"} = $qty - $ship;
+ }
- for (qw(closed id printed emailed queued)) { delete $form->{$_} }
- &save;
+ $totalqty = $form->round_amount( $totalqty, $dec1 );
+ $totalship = $form->round_amount( $totalship, $dec2 );
+
+ if ( $totalship == 0 ) {
+ for ( 1 .. $form->{rowcount} ) {
+ $form->{"ship_$_"} = $form->{"qty_$_"};
+ }
+ $form->{ordtotal} = 0;
+ $form->{shipped} = 0;
+ return;
+ }
+
+ if ( $totalqty == $totalship ) {
+ for ( 1 .. $form->{rowcount} ) {
+ $form->{"qty_$_"} = $form->{"ship_$_"};
+ }
+ $form->{ordtotal} = 0;
+ return;
+ }
+
+ @flds =
+ qw(partnumber description qty ship unit sellprice discount oldqty orderitems_id id bin weight listprice lastcost taxaccounts pricematrix sku onhand deliverydate reqdate projectnumber partsgroup assembly);
+
+ for $i ( 1 .. $form->{rowcount} ) {
+ for (qw(qty sellprice discount)) {
+ $form->{"${_}_$i"} =
+ $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+
+ $form->{"oldship_$i"} = $form->{"ship_$i"};
+ $form->{"ship_$i"} = 0;
+ }
+
+ # clear flags
+ for (qw(id subject message cc bcc printed emailed queued audittrail)) {
+ delete $form->{$_};
+ }
+
+ OE->save( \%myconfig, \%$form );
+
+ # rebuild rows for invoice
+ @a = ();
+ $count = 0;
+
+ for $i ( 1 .. $form->{rowcount} ) {
+ $form->{"qty_$i"} = $form->{"oldship_$i"};
+ $form->{"oldqty_$i"} = $form->{"qty_$i"};
+
+ $form->{"orderitems_id_$i"} = "";
+
+ if ( $form->{"qty_$i"} ) {
+ push @a, {};
+ $j = $#a;
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
+ }
+
+ $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
+ $form->{rowcount} = $count;
}
+sub save_as_new {
+
+ for (qw(closed id printed emailed queued)) { delete $form->{$_} }
+ &save;
+
+}
sub print_and_save_as_new {
- for (qw(closed id printed emailed queued)) { delete $form->{$_} }
- &print_and_save;
+ for (qw(closed id printed emailed queued)) { delete $form->{$_} }
+ &print_and_save;
}
-
sub ship_receive {
- &order_links;
-
- &prepare_order;
+ &order_links;
- OE->get_warehouses(\%myconfig, \%$form);
+ &prepare_order;
- # warehouse
- if (@{ $form->{all_warehouse} }) {
- $form->{selectwarehouse} = "<option>\n";
+ OE->get_warehouses( \%myconfig, \%$form );
- for (@{ $form->{all_warehouse} }) { $form->{selectwarehouse} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
+ # warehouse
+ if ( @{ $form->{all_warehouse} } ) {
+ $form->{selectwarehouse} = "<option>\n";
+
+ for ( @{ $form->{all_warehouse} } ) {
+ $form->{selectwarehouse} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+
+ if ( $form->{warehouse} ) {
+ $form->{selectwarehouse} = qq|<option value="$form->{warehouse}">|;
+ $form->{warehouse} =~ s/--.*//;
+ $form->{selectwarehouse} .= $form->{warehouse};
+ }
+ }
- if ($form->{warehouse}) {
- $form->{selectwarehouse} = qq|<option value="$form->{warehouse}">|;
- $form->{warehouse} =~ s/--.*//;
- $form->{selectwarehouse} .= $form->{warehouse};
+ $form->{shippingdate} = $form->current_date( \%myconfig );
+ $form->{"$form->{vc}"} =~ s/--.*//;
+ $form->{"old$form->{vc}"} =
+ qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
+
+ @flds = ();
+ @a = ();
+ $count = 0;
+ foreach $key ( keys %$form ) {
+ if ( $key =~ /_1$/ ) {
+ $key =~ s/_1//;
+ push @flds, $key;
+ }
}
- }
- $form->{shippingdate} = $form->current_date(\%myconfig);
- $form->{"$form->{vc}"} =~ s/--.*//;
- $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
+ for $i ( 1 .. $form->{rowcount} ) {
- @flds = ();
- @a = ();
- $count = 0;
- foreach $key (keys %$form) {
- if ($key =~ /_1$/) {
- $key =~ s/_1//;
- push @flds, $key;
- }
- }
-
- for $i (1 .. $form->{rowcount}) {
- # undo formatting from prepare_order
- for (qw(qty ship)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
- $n = ($form->{"qty_$i"} -= $form->{"ship_$i"});
- if (abs($n) > 0) {
- $form->{"ship_$i"} = "";
- $form->{"serialnumber_$i"} = "";
+ # undo formatting from prepare_order
+ for (qw(qty ship)) {
+ $form->{"${_}_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+ $n = ( $form->{"qty_$i"} -= $form->{"ship_$i"} );
+ if ( abs($n) > 0 ) {
+ $form->{"ship_$i"} = "";
+ $form->{"serialnumber_$i"} = "";
- push @a, {};
- $j = $#a;
+ push @a, {};
+ $j = $#a;
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
}
- }
-
- $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
- $form->{rowcount} = $count;
-
- &display_ship_receive;
-
-}
+ $form->redo_rows( \@flds, \@a, $count, $form->{rowcount} );
+ $form->{rowcount} = $count;
+
+ &display_ship_receive;
+
+}
sub display_ship_receive {
-
- $vclabel = ucfirst $form->{vc};
- $vclabel = $locale->text($vclabel);
-
- $form->{rowcount}++;
-
- if ($form->{vc} eq 'customer') {
- $form->{title} = $locale->text('Ship Merchandise');
- $shipped = $locale->text('Shipping Date');
- } else {
- $form->{title} = $locale->text('Receive Merchandise');
- $shipped = $locale->text('Date Received');
- }
-
- # set option selected
- for (qw(warehouse employee)) {
- $form->{"select$_"} = $form->unescape($form->{"select$_"});
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
- }
+ $vclabel = ucfirst $form->{vc};
+ $vclabel = $locale->text($vclabel);
+
+ $form->{rowcount}++;
- $warehouse = qq|
+ if ( $form->{vc} eq 'customer' ) {
+ $form->{title} = $locale->text('Ship Merchandise');
+ $shipped = $locale->text('Shipping Date');
+ }
+ else {
+ $form->{title} = $locale->text('Receive Merchandise');
+ $shipped = $locale->text('Date Received');
+ }
+
+ # set option selected
+ for (qw(warehouse employee)) {
+ $form->{"select$_"} = $form->unescape( $form->{"select$_"} );
+ $form->{"select$_"} =~ s/ selected//;
+ $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
+ }
+
+ $warehouse = qq|
<tr>
- <th align=right>|.$locale->text('Warehouse').qq|</th>
+ <th align=right>| . $locale->text('Warehouse') . qq|</th>
<td><select name=warehouse>$form->{selectwarehouse}</select></td>
- <input type=hidden name=selectwarehouse value="|.
- $form->escape($form->{selectwarehouse},1).qq|">
+ <input type=hidden name=selectwarehouse value="|
+ . $form->escape( $form->{selectwarehouse}, 1 ) . qq|">
</tr>
| if $form->{selectwarehouse};
- $employee = qq|
+ $employee = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Contact').qq|</th>
+ <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
<td><select name=employee>$form->{selectemployee}</select></td>
- <input type=hidden name=selectemployee value="|.
- $form->escape($form->{selectemployee},1).qq|">
+ <input type=hidden name=selectemployee value="|
+ . $form->escape( $form->{selectemployee}, 1 ) . qq|">
</tr>
|;
+ $form->header;
- $form->header;
-
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -2270,9 +2699,9 @@ sub display_ship_receive {
<input type=hidden name=display_form value=display_ship_receive>
|;
- $form->hide_form(qw(id type media format printed emailed queued vc));
+ $form->hide_form(qw(id type media format printed emailed queued vc));
- print qq|
+ print qq|
<input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
<table width=100%>
@@ -2294,12 +2723,12 @@ sub display_ship_receive {
</tr>
$department
<tr>
- <th align=right>|.$locale->text('Shipping Point').qq|</th>
+ <th align=right>| . $locale->text('Shipping Point') . qq|</th>
<td colspan=3>
<input name=shippingpoint size=35 value="$form->{shippingpoint}">
</tr>
<tr>
- <th align=right>|.$locale->text('Ship via').qq|</th>
+ <th align=right>| . $locale->text('Ship via') . qq|</th>
<td colspan=3>
<input name=shipvia size=35 value="$form->{shipvia}">
</tr>
@@ -2310,17 +2739,17 @@ sub display_ship_receive {
<table>
$employee
<tr>
- <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
<td>$form->{ordnumber}</td>
<input type=hidden name=ordnumber value="$form->{ordnumber}">
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Order Date').qq|</th>
+ <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
<td>$form->{transdate}</td>
<input type=hidden name=transdate value=$form->{transdate}>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('PO Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('PO Number') . qq|</th>
<td>$form->{ponumber}</td>
<input type=hidden name=ponumber value="$form->{ponumber}">
</tr>
@@ -2337,75 +2766,104 @@ sub display_ship_receive {
|;
- $form->hide_form(qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail message email subject cc bcc));
+ $form->hide_form(
+ qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail message email subject cc bcc)
+ );
- @column_index = qw(partnumber);
-
- if ($form->{type} eq "ship_order") {
- $column_data{ship} = qq|<th class=listheading>|.$locale->text('Ship').qq|</th>|;
- }
- if ($form->{type} eq "receive_order") {
- $column_data{ship} = qq|<th class=listheading>|.$locale->text('Recd').qq|</th>|;
- $column_data{sku} = qq|<th class=listheading>|.$locale->text('SKU').qq|</th>|;
- push @column_index, "sku";
- }
- push @column_index, qw(description qty ship unit bin serialnumber);
-
- my $colspan = $#column_index + 1;
-
- $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{bin} = qq|<th class=listheading nowrap>|.$locale->text('Bin').qq|</th>|;
- $column_data{serialnumber} = qq|<th class=listheading nowrap>|.$locale->text('Serial No.').qq|</th>|;
-
- print qq|
+ @column_index = qw(partnumber);
+
+ if ( $form->{type} eq "ship_order" ) {
+ $column_data{ship} =
+ qq|<th class=listheading>| . $locale->text('Ship') . qq|</th>|;
+ }
+ if ( $form->{type} eq "receive_order" ) {
+ $column_data{ship} =
+ qq|<th class=listheading>| . $locale->text('Recd') . qq|</th>|;
+ $column_data{sku} =
+ qq|<th class=listheading>| . $locale->text('SKU') . qq|</th>|;
+ push @column_index, "sku";
+ }
+ push @column_index, qw(description qty ship unit bin serialnumber);
+
+ my $colspan = $#column_index + 1;
+
+ $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{bin} =
+ qq|<th class=listheading nowrap>| . $locale->text('Bin') . qq|</th>|;
+ $column_data{serialnumber} =
+ qq|<th class=listheading nowrap>|
+ . $locale->text('Serial No.')
+ . qq|</th>|;
+
+ print qq|
<tr>
<td>
<table width=100%>
<tr class=listheading>|;
- for (@column_index) { print "\n$column_data{$_}" }
+ for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ print qq|
</tr>
|;
-
-
- for $i (1 .. $form->{rowcount} - 1) {
-
- # undo formatting
- $form->{"ship_$i"} = $form->parse_amount(\%myconfig, $form->{"ship_$i"});
-
- for (qw(partnumber sku description unit bin serialnumber)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
-
- $description = $form->{"description_$i"};
- $description =~ s/\r?\n/<br>/g;
-
- $column_data{partnumber} = qq|<td>$form->{"partnumber_$i"}<input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
- $column_data{sku} = qq|<td>$form->{"sku_$i"}<input type=hidden name="sku_$i" value="$form->{"sku_$i"}"></td>|;
- $column_data{description} = qq|<td>$description<input type=hidden name="description_$i" value="$form->{"description_$i"}"></td>|;
- $column_data{qty} = qq|<td align=right>|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|<input type=hidden name="qty_$i" value="$form->{"qty_$i"}"></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>$form->{"unit_$i"}<input type=hidden name="unit_$i" value="$form->{"unit_$i"}"></td>|;
- $column_data{bin} = qq|<td>$form->{"bin_$i"}<input type=hidden name="bin_$i" value="$form->{"bin_$i"}"></td>|;
-
- $column_data{serialnumber} = qq|<td><input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}"></td>|;
-
- print qq|
+
+ for $i ( 1 .. $form->{rowcount} - 1 ) {
+
+ # undo formatting
+ $form->{"ship_$i"} =
+ $form->parse_amount( \%myconfig, $form->{"ship_$i"} );
+
+ for (qw(partnumber sku description unit bin serialnumber)) {
+ $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} );
+ }
+
+ $description = $form->{"description_$i"};
+ $description =~ s/\r?\n/<br>/g;
+
+ $column_data{partnumber} =
+qq|<td>$form->{"partnumber_$i"}<input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
+ $column_data{sku} =
+qq|<td>$form->{"sku_$i"}<input type=hidden name="sku_$i" value="$form->{"sku_$i"}"></td>|;
+ $column_data{description} =
+qq|<td>$description<input type=hidden name="description_$i" value="$form->{"description_$i"}"></td>|;
+ $column_data{qty} =
+ qq|<td align=right>|
+ . $form->format_amount( \%myconfig, $form->{"qty_$i"} )
+ . qq|<input type=hidden name="qty_$i" value="$form->{"qty_$i"}"></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>$form->{"unit_$i"}<input type=hidden name="unit_$i" value="$form->{"unit_$i"}"></td>|;
+ $column_data{bin} =
+qq|<td>$form->{"bin_$i"}<input type=hidden name="bin_$i" value="$form->{"bin_$i"}"></td>|;
+
+ $column_data{serialnumber} =
+qq|<td><input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}"></td>|;
+
+ print qq|
<tr valign=top>|;
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
</tr>
|;
- $form->hide_form("orderitems_id_$i","id_$i","partsgroup_$i");
+ $form->hide_form( "orderitems_id_$i", "id_$i", "partsgroup_$i" );
+
+ }
- }
-
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -2416,42 +2874,44 @@ sub display_ship_receive {
<td>
|;
- $form->{copies} = 1;
-
- &print_options;
-
- print qq|
+ $form->{copies} = 1;
+
+ &print_options;
+
+ print qq|
</td>
</tr>
</table>
<br>
|;
-# type=submit $locale->text('Done')
+ # type=submit $locale->text('Done')
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
- 'ship_to' => { ndx => 4, key => 'T', value => $locale->text('Ship to') },
- 'e_mail' => { ndx => 5, key => 'E', value => $locale->text('E-mail') },
- 'done' => { ndx => 11, key => 'D', value => $locale->text('Done') },
- );
-
- for ("update", "print") { $form->print_button(\%button, $_) }
-
- if ($form->{type} eq 'ship_order') {
- for ('ship_to', 'e_mail') { $form->print_button(\%button, $_) }
- }
-
- $form->print_button(\%button, 'done');
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ %button = (
+ 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
+ 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
+ 'ship_to' =>
+ { ndx => 4, key => 'T', value => $locale->text('Ship to') },
+ 'e_mail' => { ndx => 5, key => 'E', value => $locale->text('E-mail') },
+ 'done' => { ndx => 11, key => 'D', value => $locale->text('Done') },
+ );
- $form->hide_form(qw(rowcount callback path login sessionid));
-
- print qq|
+ for ( "update", "print" ) { $form->print_button( \%button, $_ ) }
+
+ if ( $form->{type} eq 'ship_order' ) {
+ for ( 'ship_to', 'e_mail' ) { $form->print_button( \%button, $_ ) }
+ }
+
+ $form->print_button( \%button, 'done' );
+
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ $form->hide_form(qw(rowcount callback path login sessionid));
+
+ print qq|
</form>
@@ -2459,57 +2919,69 @@ sub display_ship_receive {
</html>
|;
-
}
-
sub done {
- if ($form->{type} eq 'ship_order') {
- $form->isblank("shippingdate", $locale->text('Shipping Date missing!'));
- } else {
- $form->isblank("shippingdate", $locale->text('Date received missing!'));
- }
-
- $total = 0;
- for (1 .. $form->{rowcount} - 1) { $total += $form->{"ship_$_"} = $form->parse_amount(\%myconfig, $form->{"ship_$_"}) }
-
- $form->error($locale->text('Nothing entered!')) unless $total;
+ if ( $form->{type} eq 'ship_order' ) {
+ $form->isblank( "shippingdate",
+ $locale->text('Shipping Date missing!') );
+ }
+ else {
+ $form->isblank( "shippingdate",
+ $locale->text('Date received missing!') );
+ }
- if (OE->save_inventory(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Inventory saved!'));
- } else {
- $form->error($locale->text('Could not save!'));
- }
+ $total = 0;
+ for ( 1 .. $form->{rowcount} - 1 ) {
+ $total += $form->{"ship_$_"} =
+ $form->parse_amount( \%myconfig, $form->{"ship_$_"} );
+ }
-}
+ $form->error( $locale->text('Nothing entered!') ) unless $total;
+ if ( OE->save_inventory( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Inventory saved!') );
+ }
+ else {
+ $form->error( $locale->text('Could not save!') );
+ }
+
+}
sub search_transfer {
-
- OE->get_warehouses(\%myconfig, \%$form);
- # warehouse
- if (@{ $form->{all_warehouse} }) {
- $form->{selectwarehouse} = "<option>\n";
- $form->{warehouse} = qq|$form->{warehouse}--$form->{warehouse_id}| if $form->{warehouse_id};
+ OE->get_warehouses( \%myconfig, \%$form );
- for (@{ $form->{all_warehouse} }) { $form->{selectwarehouse} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| }
- } else {
- $form->error($locale->text('Nothing to transfer!'));
- }
-
- $form->get_partsgroup(\%myconfig, { searchitems => 'part'});
- if (@{ $form->{all_partsgroup} }) {
- $form->{selectpartsgroup} = "<option>\n";
- for (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| }
- }
-
- $form->{title} = $locale->text('Transfer Inventory');
-
- $form->header;
+ # warehouse
+ if ( @{ $form->{all_warehouse} } ) {
+ $form->{selectwarehouse} = "<option>\n";
+ $form->{warehouse} = qq|$form->{warehouse}--$form->{warehouse_id}|
+ if $form->{warehouse_id};
+
+ for ( @{ $form->{all_warehouse} } ) {
+ $form->{selectwarehouse} .=
+qq|<option value="$_->{description}--$_->{id}">$_->{description}\n|;
+ }
+ }
+ else {
+ $form->error( $locale->text('Nothing to transfer!') );
+ }
+
+ $form->get_partsgroup( \%myconfig, { searchitems => 'part' } );
+ if ( @{ $form->{all_partsgroup} } ) {
+ $form->{selectpartsgroup} = "<option>\n";
+ for ( @{ $form->{all_partsgroup} } ) {
+ $form->{selectpartsgroup} .=
+ qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|;
+ }
+ }
+
+ $form->{title} = $locale->text('Transfer Inventory');
+
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -2523,23 +2995,23 @@ sub search_transfer {
<td>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Transfer from').qq|</th>
+ <th align=right nowrap>| . $locale->text('Transfer from') . qq|</th>
<td><select name=fromwarehouse>$form->{selectwarehouse}</select></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Transfer to').qq|</th>
+ <th align=right nowrap>| . $locale->text('Transfer to') . qq|</th>
<td><select name=towarehouse>$form->{selectwarehouse}</select></td>
</tr>
<tr>
- <th align="right" nowrap="true">|.$locale->text('Part Number').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Part Number') . qq|</th>
<td><input name=partnumber size=20></td>
</tr>
<tr>
- <th align="right" nowrap="true">|.$locale->text('Description').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Description') . qq|</th>
<td><input name=description size=40></td>
</tr>
<tr>
- <th align=right nowrap>|.$locale->text('Group').qq|</th>
+ <th align=right nowrap>| . $locale->text('Group') . qq|</th>
<td><select name=partsgroup>$form->{selectpartsgroup}</select></td>
</tr>
</table>
@@ -2553,20 +3025,22 @@ sub search_transfer {
<br>
<input type=hidden name=nextsub value=list_transfer>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>|;
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>|;
- $form->hide_form(qw(path login sessionid));
+ $form->hide_form(qw(path login sessionid));
- print qq|
+ print qq|
</form>
|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</body>
</html>
@@ -2574,68 +3048,92 @@ sub search_transfer {
}
-
sub list_transfer {
- $form->{sort} = "partnumber" unless $form->{sort};
+ $form->{sort} = "partnumber" unless $form->{sort};
- OE->get_inventory(\%myconfig, \%$form);
-
- # construct href
- $href = "$form->{script}?action=list_transfer";
- for (qw(direction oldsort path login sessionid)) { $href .= "&$_=$form->{$_}" }
- for (qw(partnumber fromwarehouse towarehouse description partsgroup)) { $href .= "&$_=".$form->escape($form->{$_}) }
+ OE->get_inventory( \%myconfig, \%$form );
- $form->sort_order();
-
- # construct callback
- $callback = "$form->{script}?action=list_transfer";
- for (qw(direction oldsort path login sessionid)) { $callback .= "&$_=$form->{$_}" }
- for (qw(partnumber fromwarehouse towarehouse description partsgroup)) { $callback .= "&$_=".$form->escape($form->{$_},1) }
+ # construct href
+ $href = "$form->{script}?action=list_transfer";
+ for (qw(direction oldsort path login sessionid)) {
+ $href .= "&$_=$form->{$_}";
+ }
+ for (qw(partnumber fromwarehouse towarehouse description partsgroup)) {
+ $href .= "&$_=" . $form->escape( $form->{$_} );
+ }
- @column_index = $form->sort_columns(qw(partnumber description partsgroup make model fromwarehouse qty towarehouse transfer));
+ $form->sort_order();
- $column_header{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Part Number').qq|</a></th>|;
- $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
- $column_header{partsgroup} = qq|<th><a class=listheading href=$href&sort=partsgroup>|.$locale->text('Group').qq|</a></th>|;
- $column_header{fromwarehouse} = qq|<th><a class=listheading href=$href&sort=warehouse>|.$locale->text('From').qq|</a></th>|;
- $column_header{towarehouse} = qq|<th class=listheading>|.$locale->text('To').qq|</th>|;
- $column_header{qty} = qq|<th class=listheading>|.$locale->text('Qty').qq|</a></th>|;
- $column_header{transfer} = qq|<th class=listheading>|.$locale->text('Transfer').qq|</a></th>|;
+ # construct callback
+ $callback = "$form->{script}?action=list_transfer";
+ for (qw(direction oldsort path login sessionid)) {
+ $callback .= "&$_=$form->{$_}";
+ }
+ for (qw(partnumber fromwarehouse towarehouse description partsgroup)) {
+ $callback .= "&$_=" . $form->escape( $form->{$_}, 1 );
+ }
-
- ($warehouse, $warehouse_id) = split /--/, $form->{fromwarehouse};
-
- if ($form->{fromwarehouse}) {
- $option .= "\n<br>";
- $option .= $locale->text('From Warehouse')." : $warehouse";
- }
- ($warehouse, $warehouse_id) = split /--/, $form->{towarehouse};
- if ($form->{towarehouse}) {
- $option .= "\n<br>";
- $option .= $locale->text('To Warehouse')." : $warehouse";
- }
- if ($form->{partnumber}) {
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Part Number')." : $form->{partnumber}";
- }
- if ($form->{description}) {
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Description')." : $form->{description}";
- }
- if ($form->{partsgroup}) {
- ($partsgroup) = split /--/, $form->{partsgroup};
- $option .= "\n<br>" if ($option);
- $option .= $locale->text('Group')." : $partsgroup";
- }
-
- $form->{title} = $locale->text('Transfer Inventory');
-
- $callback .= "&sort=$form->{sort}";
-
- $form->header;
+ @column_index =
+ $form->sort_columns(
+ qw(partnumber description partsgroup make model fromwarehouse qty towarehouse transfer)
+ );
+
+ $column_header{partnumber} =
+ qq|<th><a class=listheading href=$href&sort=partnumber>|
+ . $locale->text('Part Number')
+ . qq|</a></th>|;
+ $column_header{description} =
+ qq|<th><a class=listheading href=$href&sort=description>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
+ $column_header{partsgroup} =
+ qq|<th><a class=listheading href=$href&sort=partsgroup>|
+ . $locale->text('Group')
+ . qq|</a></th>|;
+ $column_header{fromwarehouse} =
+ qq|<th><a class=listheading href=$href&sort=warehouse>|
+ . $locale->text('From')
+ . qq|</a></th>|;
+ $column_header{towarehouse} =
+ qq|<th class=listheading>| . $locale->text('To') . qq|</th>|;
+ $column_header{qty} =
+ qq|<th class=listheading>| . $locale->text('Qty') . qq|</a></th>|;
+ $column_header{transfer} =
+ qq|<th class=listheading>| . $locale->text('Transfer') . qq|</a></th>|;
+
+ ( $warehouse, $warehouse_id ) = split /--/, $form->{fromwarehouse};
+
+ if ( $form->{fromwarehouse} ) {
+ $option .= "\n<br>";
+ $option .= $locale->text('From Warehouse') . " : $warehouse";
+ }
+ ( $warehouse, $warehouse_id ) = split /--/, $form->{towarehouse};
+ if ( $form->{towarehouse} ) {
+ $option .= "\n<br>";
+ $option .= $locale->text('To Warehouse') . " : $warehouse";
+ }
+ if ( $form->{partnumber} ) {
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Part Number') . " : $form->{partnumber}";
+ }
+ if ( $form->{description} ) {
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Description') . " : $form->{description}";
+ }
+ if ( $form->{partsgroup} ) {
+ ($partsgroup) = split /--/, $form->{partsgroup};
+ $option .= "\n<br>" if ($option);
+ $option .= $locale->text('Group') . " : $partsgroup";
+ }
+
+ $form->{title} = $locale->text('Transfer Inventory');
+
+ $callback .= "&sort=$form->{sort}";
- print qq|
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -2655,42 +3153,48 @@ sub list_transfer {
<table width=100%>
<tr class=listheading>|;
-for (@column_index) { print "\n$column_header{$_}" }
+ for (@column_index) { print "\n$column_header{$_}" }
-print qq|
+ print qq|
</tr>
|;
- if (@{ $form->{all_inventory} }) {
- $sameitem = $form->{all_inventory}->[0]->{$form->{sort}};
- }
-
- $i = 0;
- foreach $ref (@{ $form->{all_inventory} }) {
-
- $i++;
-
- $column_data{partnumber} = qq|<td><input type=hidden name="id_$i" value=$ref->{id}>$ref->{partnumber}</td>|;
- $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
- $column_data{partsgroup} = "<td>$ref->{partsgroup}&nbsp;</td>";
- $column_data{fromwarehouse} = qq|<td><input type=hidden name="warehouse_id_$i" value=$ref->{warehouse_id}>$ref->{warehouse}&nbsp;</td>|;
- $column_data{towarehouse} = qq|<td>$warehouse&nbsp;</td>|;
- $column_data{qty} = qq|<td><input type=hidden name="qty_$i" value=$ref->{qty}>|.$form->format_amount(\%myconfig, $ref->{qty}).qq|</td>|;
- $column_data{transfer} = qq|<td><input name="transfer_$i" size=4></td>|;
+ if ( @{ $form->{all_inventory} } ) {
+ $sameitem = $form->{all_inventory}->[0]->{ $form->{sort} };
+ }
- $j++; $j %= 2;
- print "
+ $i = 0;
+ foreach $ref ( @{ $form->{all_inventory} } ) {
+
+ $i++;
+
+ $column_data{partnumber} =
+qq|<td><input type=hidden name="id_$i" value=$ref->{id}>$ref->{partnumber}</td>|;
+ $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
+ $column_data{partsgroup} = "<td>$ref->{partsgroup}&nbsp;</td>";
+ $column_data{fromwarehouse} =
+qq|<td><input type=hidden name="warehouse_id_$i" value=$ref->{warehouse_id}>$ref->{warehouse}&nbsp;</td>|;
+ $column_data{towarehouse} = qq|<td>$warehouse&nbsp;</td>|;
+ $column_data{qty} =
+ qq|<td><input type=hidden name="qty_$i" value=$ref->{qty}>|
+ . $form->format_amount( \%myconfig, $ref->{qty} )
+ . qq|</td>|;
+ $column_data{transfer} = qq|<td><input name="transfer_$i" size=4></td>|;
+
+ $j++;
+ $j %= 2;
+ print "
<tr class=listrow$j>";
-
- for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
</tr>
|;
- }
-
- print qq|
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -2707,135 +3211,182 @@ print qq|
<input type=hidden name=rowcount value=$i>
|;
- $form->{action} = "transfer";
- $form->hide_form(qw(path login sessionid action));
+ $form->{action} = "transfer";
+ $form->hide_form(qw(path login sessionid action));
- print qq|
-<button class="submit" type="submit" name="action" value="transfer">|.$locale->text('Transfer').qq|</button>|;
+ print qq|
+<button class="submit" type="submit" name="action" value="transfer">|
+ . $locale->text('Transfer')
+ . qq|</button>|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
</html>
|;
-
}
-
sub transfer {
- if (OE->transfer(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Inventory transferred!'));
- } else {
- $form->error($locale->text('Could not transfer Inventory!'));
- }
+ if ( OE->transfer( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Inventory transferred!') );
+ }
+ else {
+ $form->error( $locale->text('Could not transfer Inventory!') );
+ }
}
-
sub generate_purchase_orders {
- for (1 .. $form->{rowcount}) {
- if ($form->{"ndx_$_"}) {
- $ok = 1;
- last;
+ for ( 1 .. $form->{rowcount} ) {
+ if ( $form->{"ndx_$_"} ) {
+ $ok = 1;
+ last;
+ }
}
- }
-
- $form->error($locale->text('Nothing selected!')) unless $ok;
-
- ($null, $argv) = split /\?/, $form->{callback};
-
- for (split /\&/, $argv) {
- ($key, $value) = split /=/, $_;
- $form->{$key} = $value;
- }
-
- $form->{vc} = "vendor";
-
- OE->get_soparts(\%myconfig, \%$form);
-
- # flatten array
- $i = 0;
- foreach $parts_id (sort { $form->{orderitems}{$a}{partnumber} cmp $form->{orderitems}{$b}{partnumber} } keys %{ $form->{orderitems} }) {
-
- $required = $form->{orderitems}{$parts_id}{required};
- next if $required <= 0;
-
- $i++;
-
- $form->{"required_$i"} = $form->format_amount(\%myconfig, $required);
- $form->{"id_$i"} = $parts_id;
- $form->{"sku_$i"} = $form->{orderitems}{$parts_id}{partnumber};
-
- $form->{"curr_$i"} = $form->{defaultcurrency};
- $form->{"description_$i"} = $form->{orderitems}{$parts_id}{description};
- $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{orderitems}{$parts_id}{lastcost}, 2);
+ $form->error( $locale->text('Nothing selected!') ) unless $ok;
- $form->{"qty_$i"} = $required;
-
- if (exists $form->{orderitems}{$parts_id}{"parts$form->{vc}"}) {
- $form->{"qty_$i"} = "";
+ ( $null, $argv ) = split /\?/, $form->{callback};
- foreach $id (sort { $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$a}{lastcost} * $form->{$form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$a}{curr}} <=> $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$b}{lastcost} * $form->{$form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$b}{curr}} } keys %{ $form->{orderitems}{$parts_id}{"parts$form->{vc}"} }) {
- $i++;
-
- $form->{"qty_$i"} = $form->format_amount(\%myconfig, $required);
-
- $form->{"description_$i"} = "";
- for (qw(partnumber curr)) { $form->{"${_}_$i"} = $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}{$_} }
-
- $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}{lastcost}, 2);
- $form->{"leadtime_$i"} = $form->format_amount(\%myconfig, $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}{leadtime});
- $form->{"fx_$i"} = $form->format_amount(\%myconfig, $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}{lastcost} * $form->{$form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}{curr}}, 2);
-
- $form->{"id_$i"} = $parts_id;
-
- $form->{"$form->{vc}_$i"} = qq|$form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}{name}--$id|;
- $form->{"$form->{vc}_id_$i"} = $id;
+ for ( split /\&/, $argv ) {
+ ( $key, $value ) = split /=/, $_;
+ $form->{$key} = $value;
+ }
- $required = "";
- }
+ $form->{vc} = "vendor";
+
+ OE->get_soparts( \%myconfig, \%$form );
+
+ # flatten array
+ $i = 0;
+ foreach $parts_id (
+ sort {
+ $form->{orderitems}{$a}{partnumber}
+ cmp $form->{orderitems}{$b}{partnumber}
+ } keys %{ $form->{orderitems} }
+ )
+ {
+
+ $required = $form->{orderitems}{$parts_id}{required};
+ next if $required <= 0;
+
+ $i++;
+
+ $form->{"required_$i"} = $form->format_amount( \%myconfig, $required );
+ $form->{"id_$i"} = $parts_id;
+ $form->{"sku_$i"} = $form->{orderitems}{$parts_id}{partnumber};
+
+ $form->{"curr_$i"} = $form->{defaultcurrency};
+ $form->{"description_$i"} = $form->{orderitems}{$parts_id}{description};
+
+ $form->{"lastcost_$i"} =
+ $form->format_amount( \%myconfig,
+ $form->{orderitems}{$parts_id}{lastcost}, 2 );
+
+ $form->{"qty_$i"} = $required;
+
+ if ( exists $form->{orderitems}{$parts_id}{"parts$form->{vc}"} ) {
+ $form->{"qty_$i"} = "";
+
+ foreach $id (
+ sort {
+ $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$a}
+ {lastcost} * $form->{ $form->{orderitems}{$parts_id}
+ {"parts$form->{vc}"}{$a}{curr} } <=>
+ $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$b}
+ {lastcost} * $form->{ $form->{orderitems}{$parts_id}
+ {"parts$form->{vc}"}{$b}{curr} }
+ } keys %{ $form->{orderitems}{$parts_id}{"parts$form->{vc}"} }
+ )
+ {
+ $i++;
+
+ $form->{"qty_$i"} =
+ $form->format_amount( \%myconfig, $required );
+
+ $form->{"description_$i"} = "";
+ for (qw(partnumber curr)) {
+ $form->{"${_}_$i"} =
+ $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
+ {$_};
+ }
+
+ $form->{"lastcost_$i"} = $form->format_amount(
+ \%myconfig,
+ $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
+ {lastcost},
+ 2
+ );
+ $form->{"leadtime_$i"} = $form->format_amount( \%myconfig,
+ $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
+ {leadtime} );
+ $form->{"fx_$i"} = $form->format_amount(
+ \%myconfig,
+ $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
+ {lastcost} * $form->{
+ $form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}
+ {curr}
+ },
+ 2
+ );
+
+ $form->{"id_$i"} = $parts_id;
+
+ $form->{"$form->{vc}_$i"} =
+qq|$form->{orderitems}{$parts_id}{"parts$form->{vc}"}{$id}{name}--$id|;
+ $form->{"$form->{vc}_id_$i"} = $id;
+
+ $required = "";
+ }
+ }
+ $form->{"blankrow_$i"} = 1;
}
- $form->{"blankrow_$i"} = 1;
- }
- $form->{rowcount} = $i;
+ $form->{rowcount} = $i;
- &po_orderitems;
+ &po_orderitems;
}
-
sub po_orderitems {
- @column_index = qw(sku description partnumber leadtime fx lastcost curr required qty name);
-
- $column_header{sku} = qq|<th class=listheading>|.$locale->text('SKU').qq|</th>|;
- $column_header{partnumber} = qq|<th class=listheading>|.$locale->text('Part Number').qq|</th>|;
- $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
- $column_header{name} = qq|<th class=listheading>|.$locale->text('Vendor').qq|</th>|;
- $column_header{qty} = qq|<th class=listheading>|.$locale->text('Order').qq|</th>|;
- $column_header{required} = qq|<th class=listheading>|.$locale->text('Req').qq|</th>|;
- $column_header{lastcost} = qq|<th class=listheading>|.$locale->text('Cost').qq|</th>|;
- $column_header{fx} = qq|<th class=listheading>&nbsp;</th>|;
- $column_header{leadtime} = qq|<th class=listheading>|.$locale->text('Lead').qq|</th>|;
- $column_header{curr} = qq|<th class=listheading>|.$locale->text('Curr').qq|</th>|;
-
-
- $form->{title} = $locale->text('Generate Purchase Orders');
-
- $form->header;
+ @column_index =
+ qw(sku description partnumber leadtime fx lastcost curr required qty name);
+
+ $column_header{sku} =
+ qq|<th class=listheading>| . $locale->text('SKU') . qq|</th>|;
+ $column_header{partnumber} =
+ qq|<th class=listheading>| . $locale->text('Part Number') . qq|</th>|;
+ $column_header{description} =
+ qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
+ $column_header{name} =
+ qq|<th class=listheading>| . $locale->text('Vendor') . qq|</th>|;
+ $column_header{qty} =
+ qq|<th class=listheading>| . $locale->text('Order') . qq|</th>|;
+ $column_header{required} =
+ qq|<th class=listheading>| . $locale->text('Req') . qq|</th>|;
+ $column_header{lastcost} =
+ qq|<th class=listheading>| . $locale->text('Cost') . qq|</th>|;
+ $column_header{fx} = qq|<th class=listheading>&nbsp;</th>|;
+ $column_header{leadtime} =
+ qq|<th class=listheading>| . $locale->text('Lead') . qq|</th>|;
+ $column_header{curr} =
+ qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
+
+ $form->{title} = $locale->text('Generate Purchase Orders');
+
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -2850,54 +3401,64 @@ sub po_orderitems {
<table width=100%>
<tr class=listheading>|;
- for (@column_index) { print "\n$column_header{$_}" }
+ for (@column_index) { print "\n$column_header{$_}" }
- print qq|
+ print qq|
</tr>
|;
- for $i (1 .. $form->{rowcount}) {
+ for $i ( 1 .. $form->{rowcount} ) {
- for (qw(sku partnumber description curr)) { $column_data{$_} = qq|<td>$form->{"${_}_$i"}&nbsp;</td>| }
+ for (qw(sku partnumber description curr)) {
+ $column_data{$_} = qq|<td>$form->{"${_}_$i"}&nbsp;</td>|;
+ }
- for (qw(required leadtime lastcost fx)) { $column_data{$_} = qq|<td align=right>$form->{"${_}_$i"}</td>| }
-
- $column_data{qty} = qq|<td align=right><input name="qty_$i" size=6 value=$form->{"qty_$i"}></td>|;
-
- if ($form->{"$form->{vc}_id_$i"}) {
- $name = $form->{"$form->{vc}_$i"};
- $name =~ s/--.*//;
- $column_data{name} = qq|<td>$name</td>|;
- $form->hide_form("$form->{vc}_id_$i", "$form->{vc}_$i");
- } else {
- $column_data{name} = qq|<td><input name="ndx_$i" class=checkbox type=checkbox value="1"></td>|;
- }
+ for (qw(required leadtime lastcost fx)) {
+ $column_data{$_} = qq|<td align=right>$form->{"${_}_$i"}</td>|;
+ }
- $form->hide_form(map { "${_}_$i" } qw(id sku partnumber description curr required leadtime lastcost fx name blankrow));
-
- $blankrow = $form->{"blankrow_$i"};
+ $column_data{qty} =
+qq|<td align=right><input name="qty_$i" size=6 value=$form->{"qty_$i"}></td>|;
-BLANKROW:
- $j++; $j %= 2;
- print "
+ if ( $form->{"$form->{vc}_id_$i"} ) {
+ $name = $form->{"$form->{vc}_$i"};
+ $name =~ s/--.*//;
+ $column_data{name} = qq|<td>$name</td>|;
+ $form->hide_form( "$form->{vc}_id_$i", "$form->{vc}_$i" );
+ }
+ else {
+ $column_data{name} =
+qq|<td><input name="ndx_$i" class=checkbox type=checkbox value="1"></td>|;
+ }
+
+ $form->hide_form( map { "${_}_$i" }
+ qw(id sku partnumber description curr required leadtime lastcost fx name blankrow)
+ );
+
+ $blankrow = $form->{"blankrow_$i"};
+
+ BLANKROW:
+ $j++;
+ $j %= 2;
+ print "
<tr class=listrow$j>";
-
- for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
</tr>
|;
- if ($blankrow) {
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
- $blankrow = 0;
+ if ($blankrow) {
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+ $blankrow = 0;
+
+ goto BLANKROW;
+ }
- goto BLANKROW;
}
-
- }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -2910,20 +3471,26 @@ BLANKROW:
<br>
|;
- $form->hide_form(qw(callback department ponumber path login sessionid employee_id vc nextsub rowcount type));
-
- print qq|
-<button class="submit" type="submit" name="action" value="generate_orders">|.$locale->text('Generate Orders').qq|</button>|;
-
- print qq|
-<button class="submit" type="submit" name="action" value="select_vendor">|.$locale->text('Select Vendor').qq|</button>|;
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
-
- print qq|
+ $form->hide_form(
+ qw(callback department ponumber path login sessionid employee_id vc nextsub rowcount type)
+ );
+
+ print qq|
+<button class="submit" type="submit" name="action" value="generate_orders">|
+ . $locale->text('Generate Orders')
+ . qq|</button>|;
+
+ print qq|
+<button class="submit" type="submit" name="action" value="select_vendor">|
+ . $locale->text('Select Vendor')
+ . qq|</button>|;
+
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
</form>
</body>
@@ -2932,82 +3499,82 @@ BLANKROW:
}
-
sub generate_orders {
- if (OE->generate_orders(\%myconfig, \%$form)) {
- $form->redirect;
- } else {
- $form->error($locale->text('Order generation failed!'));
- }
-
-}
-
+ if ( OE->generate_orders( \%myconfig, \%$form ) ) {
+ $form->redirect;
+ }
+ else {
+ $form->error( $locale->text('Order generation failed!') );
+ }
+}
sub consolidate_orders {
- for (1 .. $form->{rowcount}) {
- if ($form->{"ndx_$_"}) {
- $ok = 1;
- last;
+ for ( 1 .. $form->{rowcount} ) {
+ if ( $form->{"ndx_$_"} ) {
+ $ok = 1;
+ last;
+ }
}
- }
- $form->error($locale->text('Nothing selected!')) unless $ok;
-
- ($null, $argv) = split /\?/, $form->{callback};
-
- for (split /\&/, $argv) {
- ($key, $value) = split /=/, $_;
- $form->{$key} = $value;
- }
+ $form->error( $locale->text('Nothing selected!') ) unless $ok;
- if (OE->consolidate_orders(\%myconfig, \%$form)) {
- $form->redirect;
- } else {
- $form->error($locale->text('Order generation failed!'));
- }
+ ( $null, $argv ) = split /\?/, $form->{callback};
-}
+ for ( split /\&/, $argv ) {
+ ( $key, $value ) = split /=/, $_;
+ $form->{$key} = $value;
+ }
+ if ( OE->consolidate_orders( \%myconfig, \%$form ) ) {
+ $form->redirect;
+ }
+ else {
+ $form->error( $locale->text('Order generation failed!') );
+ }
+
+}
sub select_vendor {
- for (1 .. $form->{rowcount}) {
- last if ($ok = $form->{"ndx_$_"});
- }
+ for ( 1 .. $form->{rowcount} ) {
+ last if ( $ok = $form->{"ndx_$_"} );
+ }
- $form->error($locale->text('Nothing selected!')) unless $ok;
-
- $form->header;
-
- print qq|
+ $form->error( $locale->text('Nothing selected!') ) unless $ok;
+
+ $form->header;
+
+ print qq|
<body onload="document.forms[0].vendor.focus()" />
<form method=post action=$form->{script}>
-<b>|.$locale->text('Vendor').qq|</b> <input name=vendor size=40>
+<b>| . $locale->text('Vendor') . qq|</b> <input name=vendor size=40>
|;
- $form->{nextsub} = "vendor_selected";
- $form->{action} = "vendor_selected";
-
- $form->hide_form;
-
- print qq|
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+ $form->{nextsub} = "vendor_selected";
+ $form->{action} = "vendor_selected";
+
+ $form->hide_form;
+
+ print qq|
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</body>
</html>
@@ -3015,28 +3582,33 @@ sub select_vendor {
}
-
sub vendor_selected {
- if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{transdate})) > 1) {
- &select_name($form->{vc});
- exit;
- }
+ if (
+ (
+ $rv = $form->get_name( \%myconfig, $form->{vc}, $form->{transdate} )
+ ) > 1
+ )
+ {
+ &select_name( $form->{vc} );
+ exit;
+ }
- if ($rv == 1) {
- for (1 .. $form->{rowcount}) {
- if ($form->{"ndx_$_"}) {
- $form->{"$form->{vc}_id_$_"} = $form->{name_list}[0]->{id};
- $form->{"$form->{vc}_$_"} = "$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}";
- }
+ if ( $rv == 1 ) {
+ for ( 1 .. $form->{rowcount} ) {
+ if ( $form->{"ndx_$_"} ) {
+ $form->{"$form->{vc}_id_$_"} = $form->{name_list}[0]->{id};
+ $form->{"$form->{vc}_$_"} =
+ "$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}";
+ }
+ }
+ }
+ else {
+ $msg = ucfirst $form->{vc} . " not on file!" unless $msg;
+ $form->error( $locale->text($msg) );
}
- } else {
- $msg = ucfirst $form->{vc} . " not on file!" unless $msg;
- $form->error($locale->text($msg));
- }
- &po_orderitems;
-
-}
+ &po_orderitems;
+}
diff --git a/bin/pe.pl b/bin/pe.pl
index acfaa784..189a1cb0 100644
--- a/bin/pe.pl
+++ b/bin/pe.pl
@@ -1,9 +1,9 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
#
-#
+#
# See COPYRIGHT file for copyright information
#======================================================================
#
@@ -17,228 +17,274 @@
#
#======================================================================
-
use LedgerSMB::PE;
use LedgerSMB::AA;
use LedgerSMB::OE;
-
+
1;
+
# end of main
+sub add {
+ # construct callback
+ $form->{callback} =
+"$form->{script}?action=add&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
+ unless $form->{callback};
-sub add {
-
- # construct callback
- $form->{callback} = "$form->{script}?action=add&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
+ &{"prepare_$form->{type}"};
- &{ "prepare_$form->{type}" };
-
- $form->{orphaned} = 1;
- &display_form;
-
-}
+ $form->{orphaned} = 1;
+ &display_form;
+}
sub edit {
-
- &{ "prepare_$form->{type}" };
- &display_form;
-
-}
+ &{"prepare_$form->{type}"};
+ &display_form;
+
+}
-sub prepare_partsgroup { PE->get_partsgroup(\%myconfig, \%$form) if $form->{id} }
-sub prepare_pricegroup { PE->get_pricegroup(\%myconfig, \%$form) if $form->{id} }
+sub prepare_partsgroup {
+ PE->get_partsgroup( \%myconfig, \%$form )
+ if $form->{id};
+}
+sub prepare_pricegroup {
+ PE->get_pricegroup( \%myconfig, \%$form )
+ if $form->{id};
+}
sub prepare_job {
-
-# $locale->text('Add Job')
-# $locale->text('Edit Job')
- $form->{vc} = 'customer';
-
- PE->get_job(\%myconfig, \%$form);
-
- $form->{taxaccounts} = "";
- for (keys %{ $form->{IC_links} }) {
-
- $form->{"select$_"} = "";
- foreach $ref (@{ $form->{IC_links}{$_} }) {
- if (/IC_tax/) {
- if (/taxpart/) {
- $form->{taxaccounts} .= "$ref->{accno} ";
- $form->{"IC_tax_$ref->{accno}_description"} = "$ref->{accno}--$ref->{description}";
- if ($form->{id}) {
- if ($form->{amount}{$ref->{accno}}) {
- $form->{"IC_tax_$ref->{accno}"} = "checked";
- }
- } else {
- $form->{"IC_tax_$ref->{accno}"} = "checked";
- }
- }
- } else {
- $form->{"select$_"} .= "<option>$ref->{accno}--$ref->{description}\n";
- }
- }
- }
- chop $form->{taxaccounts};
-
- $form->{selectIC_income} = $form->{selectIC_sale};
- $form->{IC_income} = $form->{IC_sale};
-
- $form->{IC_income} = qq|$form->{income_accno}--$form->{income_description}|;
+ # $locale->text('Add Job')
+ # $locale->text('Edit Job')
+
+ $form->{vc} = 'customer';
+
+ PE->get_job( \%myconfig, \%$form );
+
+ $form->{taxaccounts} = "";
+ for ( keys %{ $form->{IC_links} } ) {
+
+ $form->{"select$_"} = "";
+ foreach $ref ( @{ $form->{IC_links}{$_} } ) {
+ if (/IC_tax/) {
+ if (/taxpart/) {
+ $form->{taxaccounts} .= "$ref->{accno} ";
+ $form->{"IC_tax_$ref->{accno}_description"} =
+ "$ref->{accno}--$ref->{description}";
+ if ( $form->{id} ) {
+ if ( $form->{amount}{ $ref->{accno} } ) {
+ $form->{"IC_tax_$ref->{accno}"} = "checked";
+ }
+ }
+ else {
+ $form->{"IC_tax_$ref->{accno}"} = "checked";
+ }
+ }
+ }
+ else {
+ $form->{"select$_"} .=
+ "<option>$ref->{accno}--$ref->{description}\n";
+ }
+ }
+ }
+ chop $form->{taxaccounts};
- delete $form->{IC_links};
-
- $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
-
- if (@{ $form->{"all_$form->{vc}"} }) {
- $form->{"$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
- $form->{"select$form->{vc}"} = qq|<option>\n|;
- for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
-
- $form->get_partsgroup(\%myconfig, {all => 1});
- $form->{partsgroup} = $form->quote($form->{partsgroup})."--$form->{partsgroup_id}";
- if (@{ $form->{all_partsgroup} }) {
- $form->{selectpartsgroup} = qq|<option>\n|;
- for (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} .= qq|<option value="|.$form->quote($_->{partsgroup}).qq|--$_->{id}">$_->{partsgroup}\n| }
- }
-
- $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
+ $form->{selectIC_income} = $form->{selectIC_sale};
+ $form->{IC_income} = $form->{IC_sale};
- $form->{readonly} = 1 if $myconfig{acs} =~ /Job Costing--Add Job/;
-
-}
+ $form->{IC_income} = qq|$form->{income_accno}--$form->{income_description}|;
+ delete $form->{IC_links};
+
+ $form->{"old$form->{vc}"} =
+ qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
+
+ if ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{"$form->{vc}"} =
+ qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
+ $form->{"select$form->{vc}"} = qq|<option>\n|;
+ for ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{"select$form->{vc}"} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
+
+ $form->get_partsgroup( \%myconfig, { all => 1 } );
+ $form->{partsgroup} =
+ $form->quote( $form->{partsgroup} ) . "--$form->{partsgroup_id}";
+ if ( @{ $form->{all_partsgroup} } ) {
+ $form->{selectpartsgroup} = qq|<option>\n|;
+ for ( @{ $form->{all_partsgroup} } ) {
+ $form->{selectpartsgroup} .=
+ qq|<option value="|
+ . $form->quote( $_->{partsgroup} )
+ . qq|--$_->{id}">$_->{partsgroup}\n|;
+ }
+ }
+
+ $form->{locked} =
+ ( $form->{revtrans} )
+ ? '1'
+ : ( $form->datetonum( \%myconfig, $form->{transdate} ) <=
+ $form->datetonum( \%myconfig, $form->{closedto} ) );
+
+ $form->{readonly} = 1 if $myconfig{acs} =~ /Job Costing--Add Job/;
+
+}
sub job_header {
- for (qw(partnumber partdescription description notes unit)) { $form->{$_} = $form->quote($form->{$_}) }
+ for (qw(partnumber partdescription description notes unit)) {
+ $form->{$_} = $form->quote( $form->{$_} );
+ }
- for (qw(production weight)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) }
- for (qw(listprice sellprice)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
-
- if (($rows = $form->numtextrows($form->{partdescription}, 60)) > 1) {
- $partdescription = qq|<textarea name="partdescription" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{partdescription}</textarea>|;
- } else {
- $partdescription = qq|<input name=partdescription size=60 value="$form->{partdescription}">|;
- }
-
- if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
- $description = qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
- } else {
- $description = qq|<input name=description size=60 value="$form->{description}">|;
- }
-
- if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
- $rows = 2;
- }
+ for (qw(production weight)) {
+ $form->{$_} = $form->format_amount( \%myconfig, $form->{$_} );
+ }
+ for (qw(listprice sellprice)) {
+ $form->{$_} = $form->format_amount( \%myconfig, $form->{$_}, 2 );
+ }
+
+ if ( ( $rows = $form->numtextrows( $form->{partdescription}, 60 ) ) > 1 ) {
+ $partdescription =
+qq|<textarea name="partdescription" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{partdescription}</textarea>|;
+ }
+ else {
+ $partdescription =
+qq|<input name=partdescription size=60 value="$form->{partdescription}">|;
+ }
- $notes = qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|;
+ if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) {
+ $description =
+qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
+ }
+ else {
+ $description =
+ qq|<input name=description size=60 value="$form->{description}">|;
+ }
- $form->{selectIC_income} = $form->unescape($form->{selectIC_income});
- $form->{"select$form->{vc}"} = $form->unescape($form->{"select$form->{vc}"});
- $form->{"select$form->{vc}"} =~ s/ selected//;
- $form->{"select$form->{vc}"} =~ s/(<option value="\Q$form->{"$form->{vc}"}\E")/$1 selected/;
+ if ( ( $rows = $form->numtextrows( $form->{notes}, 40 ) ) < 2 ) {
+ $rows = 2;
+ }
+ $notes =
+qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|;
- $label = ucfirst $form->{vc};
- if ($form->{"select$form->{vc}"}) {
- $name = qq|
+ $form->{selectIC_income} = $form->unescape( $form->{selectIC_income} );
+ $form->{"select$form->{vc}"} =
+ $form->unescape( $form->{"select$form->{vc}"} );
+ $form->{"select$form->{vc}"} =~ s/ selected//;
+ $form->{"select$form->{vc}"} =~
+ s/(<option value="\Q$form->{"$form->{vc}"}\E")/$1 selected/;
+
+ $label = ucfirst $form->{vc};
+ if ( $form->{"select$form->{vc}"} ) {
+ $name = qq|
<tr>
- <th align=right nowrap>|.$locale->text($label).qq|</th>
+ <th align=right nowrap>| . $locale->text($label) . qq|</th>
<td colspan=3><select name="$form->{vc}">$form->{"select$form->{vc}"}</select></td>
- <input type=hidden name="select$form->{vc}" value="|.
- $form->escape($form->{"select$form->{vc}"},1).qq|">
+ <input type=hidden name="select$form->{vc}" value="|
+ . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|">
</tr>
|;
- } else {
- $name = qq|
+ }
+ else {
+ $name = qq|
<tr>
- <th align=right nowrap>|.$locale->text($label).qq|</th>
+ <th align=right nowrap>| . $locale->text($label) . qq|</th>
<td colspan=3><input name="$form->{vc}" value="$form->{"$form->{vc}"}" size=35></td>
- <input type=hidden name="select$form->{vc}" value="|.
- $form->escape($form->{"select$form->{vc}"},1).qq|">
+ <input type=hidden name="select$form->{vc}" value="|
+ . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|">
</tr>
|;
- }
-
- if ($form->{orphaned}) {
-
- for (qw(income)) {
- $form->{"selectIC_$_"} =~ s/ selected//;
- $form->{"selectIC_$_"} =~ s/option>\Q$form->{"IC_$_"}\E/option selected>$form->{"IC_$_"}/;
}
-
- $production = qq|
+
+ if ( $form->{orphaned} ) {
+
+ for (qw(income)) {
+ $form->{"selectIC_$_"} =~ s/ selected//;
+ $form->{"selectIC_$_"} =~
+ s/option>\Q$form->{"IC_$_"}\E/option selected>$form->{"IC_$_"}/;
+ }
+
+ $production = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Production').qq|</th>
+ <th align=right nowrap>| . $locale->text('Production') . qq|</th>
<td><input name=production size=10 value="$form->{production}"></td>
- <th align=right nowrap>|.$locale->text('Completed').qq|</th>
+ <th align=right nowrap>| . $locale->text('Completed') . qq|</th>
<td>$form->{completed}</td>
</tr>
|;
- } else {
-
- $form->{selectIC_income} = qq|<option selected>$form->{IC_income}|;
+ }
+ else {
+
+ $form->{selectIC_income} = qq|<option selected>$form->{IC_income}|;
- $production = qq|
+ $production = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Production').qq|</th>
+ <th align=right nowrap>| . $locale->text('Production') . qq|</th>
<td><input type=hidden name=production value="$form->{production}">$form->{production}</td>
- <th align=right nowrap>|.$locale->text('Completed').qq|</th>
+ <th align=right nowrap>| . $locale->text('Completed') . qq|</th>
<td>$form->{completed}</td>
</tr>
|;
- }
-
- for (split / /, $form->{taxaccounts}) { $form->{"IC_tax_$_"} = ($form->{"IC_tax_$_"}) ? "checked" : "" }
-
- if ($form->{selectpartsgroup}) {
- $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup});
+ }
+
+ for ( split / /, $form->{taxaccounts} ) {
+ $form->{"IC_tax_$_"} = ( $form->{"IC_tax_$_"} ) ? "checked" : "";
+ }
+
+ if ( $form->{selectpartsgroup} ) {
+ $form->{selectpartsgroup} =
+ $form->unescape( $form->{selectpartsgroup} );
- $partsgroup = qq|<input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|">|;
- $form->{partsgroup} = $form->quote($form->{partsgroup});
- $form->{selectpartsgroup} =~ s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
+ $partsgroup =
+ qq|<input type=hidden name=selectpartsgroup value="|
+ . $form->escape( $form->{selectpartsgroup}, 1 ) . qq|">|;
+ $form->{partsgroup} = $form->quote( $form->{partsgroup} );
+ $form->{selectpartsgroup} =~
+ s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
- $partsgroup .= qq|\n<select name=partsgroup>$form->{selectpartsgroup}</select>|;
- $group = $locale->text('Group');
+ $partsgroup .=
+ qq|\n<select name=partsgroup>$form->{selectpartsgroup}</select>|;
+ $group = $locale->text('Group');
}
$linkaccounts = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Income').qq|</th>
+ <th align=right nowrap>| . $locale->text('Income') . qq|</th>
<td><select name=IC_income>$form->{selectIC_income}</select></td>
</tr>
|;
- for (split / /, $form->{taxaccounts}) {
- $tax .= qq|
+ for ( split / /, $form->{taxaccounts} ) {
+ $tax .= qq|
<input class=checkbox type=checkbox name="IC_tax_$_" value=1 $form->{"IC_tax_$_"}>&nbsp;<b>$form->{"IC_tax_${_}_description"}</b>
<br><input type=hidden name=IC_tax_${_}_description value="$form->{"IC_tax_${_}_description"}">
|;
}
if ($tax) {
- $linkaccounts .= qq|
+ $linkaccounts .= qq|
<tr>
- <th align=right>|.$locale->text('Tax').qq|</th>
+ <th align=right>| . $locale->text('Tax') . qq|</th>
<td>$tax</td>
</tr>
|;
}
-
+
$partnumber = qq|
<tr>
<td>
<table>
<tr valign=top>
- <th align=left>|.$locale->text('Number').qq|</th>
- <th align=left>|.$locale->text('Description').qq|</th>
+ <th align=left>| . $locale->text('Number') . qq|</th>
+ <th align=left>| . $locale->text('Description') . qq|</th>
<th align=left>$group</th>
</tr>
<tr valign=top>
@@ -251,23 +297,31 @@ sub job_header {
</tr>
|;
- $form->{title} = ($form->{id}) ? $locale->text('Edit Job') : $locale->text('Add Job');
+ $form->{title} =
+ ( $form->{id} ) ? $locale->text('Edit Job') : $locale->text('Add Job');
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
|;
- for (qw(partnumber startdate enddate)) { $form->{"old$_"} = $form->{$_} }
-
- print qq|<input type=hidden name="selectIC_income" value="|.$form->escape($form->{"selectIC_income"},1).qq|">\n|;
-
- $form->hide_form("id", "type", "old$form->{vc}", "$form->{vc}_id", "orphaned", "taxaccounts", "vc", "project");
-
- print qq|
+ for (qw(partnumber startdate enddate)) { $form->{"old$_"} = $form->{$_} }
+
+ print qq|<input type=hidden name="selectIC_income" value="|
+ . $form->escape( $form->{"selectIC_income"}, 1 )
+ . qq|">\n|;
+
+ $form->hide_form(
+ "id", "type",
+ "old$form->{vc}", "$form->{vc}_id",
+ "orphaned", "taxaccounts",
+ "vc", "project"
+ );
+
+ print qq|
<table width=100%>
<tr>
@@ -278,16 +332,16 @@ sub job_header {
<td>
<table>
<tr>
- <th align=right>|.$locale->text('Number').qq|</th>
+ <th align=right>| . $locale->text('Number') . qq|</th>
<td><input name=projectnumber size=20 value="$form->{projectnumber}"></td>
- <th align=right>|.$locale->text('Description').qq|</th>
+ <th align=right>| . $locale->text('Description') . qq|</th>
<td>$description</td>
</tr>
$name
<tr>
- <th align=right>|.$locale->text('Startdate').qq|</th>
+ <th align=right>| . $locale->text('Startdate') . qq|</th>
<td><input name=startdate size=11 title="($myconfig{dateformat})" value=$form->{startdate}></td>
- <th align=right>|.$locale->text('Enddate').qq|</th>
+ <th align=right>| . $locale->text('Enddate') . qq|</th>
<td><input name=enddate size=11 title="($myconfig{dateformat})" value=$form->{enddate}></td>
</tr>
$production
@@ -295,7 +349,9 @@ sub job_header {
</td>
</tr>
<tr class="listheading">
- <th class="listheading" align="center">|.$locale->text('Assembly').qq|</th>
+ <th class="listheading" align="center">|
+ . $locale->text('Assembly')
+ . qq|</th>
</tr>
<tr>
<td>
@@ -308,11 +364,13 @@ sub job_header {
<td width=70%>
<table width=100%>
<tr class="listheading">
- <th class="listheading" align="center" colspan=2>|.$locale->text('Link Accounts').qq|</th>
+ <th class="listheading" align="center" colspan=2>|
+ . $locale->text('Link Accounts')
+ . qq|</th>
</tr>
$linkaccounts
<tr>
- <th align="left">|.$locale->text('Notes').qq|</th>
+ <th align="left">| . $locale->text('Notes') . qq|</th>
</tr>
<tr>
<td colspan=2>
@@ -324,19 +382,23 @@ sub job_header {
<td align=right>
<table>
<tr>
- <th align="right" nowrap="true">|.$locale->text('Updated').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Updated') . qq|</th>
<td><input name=priceupdate size=11 title="$myconfig{dateformat}" value=$form->{priceupdate}></td>
</tr>
<tr>
- <th align="right" nowrap="true">|.$locale->text('List Price').qq|</th>
+ <th align="right" nowrap="true">|
+ . $locale->text('List Price')
+ . qq|</th>
<td><input name=listprice size=11 value=$form->{listprice}></td>
</tr>
<tr>
- <th align="right" nowrap="true">|.$locale->text('Sell Price').qq|</th>
+ <th align="right" nowrap="true">|
+ . $locale->text('Sell Price')
+ . qq|</th>
<td><input name=sellprice size=11 value=$form->{sellprice}></td>
</tr>
<tr>
- <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
<td>
<table>
<tr>
@@ -352,11 +414,11 @@ sub job_header {
</table>
</td>
<tr>
- <th align="right" nowrap="true">|.$locale->text('Bin').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Bin') . qq|</th>
<td><input name=bin size=10 value="$form->{bin}"></td>
</tr>
<tr>
- <th align="right" nowrap="true">|.$locale->text('Unit').qq|</th>
+ <th align="right" nowrap="true">| . $locale->text('Unit') . qq|</th>
<td><input name=unit size=5 value="$form->{unit}"></td>
</tr>
</table>
@@ -376,34 +438,38 @@ sub job_header {
}
-
sub job_footer {
- $form->hide_form(qw(callback path login sessionid));
-
-# type=submit $locale->text('Update')
-# type=submit $locale->text('Save')
-# type=submit $locale->text('Delete')
-
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- );
-
- if ($myconfig{acs} !~ /Job Costing--Add Job/) {
- $button{'save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
+ $form->hide_form(qw(callback path login sessionid));
+
+ # type=submit $locale->text('Update')
+ # type=submit $locale->text('Save')
+ # type=submit $locale->text('Delete')
+
+ %button =
+ ( 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
+ );
- if ($form->{id} && $form->{orphaned}) {
- $button{'delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') };
+ if ( $myconfig{acs} !~ /Job Costing--Add Job/ ) {
+ $button{'save'} =
+ { ndx => 3, key => 'S', value => $locale->text('Save') };
+
+ if ( $form->{id} && $form->{orphaned} ) {
+ $button{'delete'} =
+ { ndx => 16, key => 'D', value => $locale->text('Delete') };
+ }
}
- }
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
+ $form->print_button( \%button, $_ );
+ }
+
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -412,51 +478,73 @@ sub job_footer {
}
-
sub list_stock {
- PE->list_stock(\%myconfig, \%$form);
+ PE->list_stock( \%myconfig, \%$form );
- $form->{title} = $locale->text('Stock Finished Goods');
- $form->{action} = "list_stock";
+ $form->{title} = $locale->text('Stock Finished Goods');
+ $form->{action} = "list_stock";
- $href = "$form->{script}?";
- for (qw(action direction oldsort type path login sessionid status)) { $href .= "$_=$form->{$_}&" }
+ $href = "$form->{script}?";
+ for (qw(action direction oldsort type path login sessionid status)) {
+ $href .= "$_=$form->{$_}&";
+ }
- $form->sort_order();
-
- $callback = "$form->{script}?";
- for (qw(action direction oldsort type path login sessionid status)) { $callback .= "$_=$form->{$_}&" }
-
- @column_index = $form->sort_columns(qw(projectnumber description startdate partnumber production completed stock));
-
- if ($form->{projectnumber}) {
- $href .= "&projectnumber=".$form->escape($form->{projectnumber});
- $callback .= "&projectnumber=$form->{projectnumber}";
- ($var) = split /--/, $form->{projectnumber};
- $option .= "\n<br>".$locale->text('Job Number')." : $var";
- }
- if ($form->{stockingdate}) {
- $href .= "&stockingdate=$form->{stockingdate}";
- $option .= "\n<br>".$locale->text('As of')." : ".$locale->date(\%myconfig, $form->{stockingdate}, 1);
- }
-
- $column_header{projectnumber} = qq|<th width=30%><a class=listheading href=$href&sort=projectnumber>|.$locale->text('Number').qq|</a></th>|;
- $column_header{description} = qq|<th width=50%><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
- $column_header{startdate} = qq|<th width=10%><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|;
- $column_header{partnumber} = "<th><a class=listheading href=$href&sort=partnumber>" . $locale->text('Assembly') . "</a></th>";
- $column_header{production} = "<th class=listheading>" . $locale->text('Production') . "</a></th>";
- $column_header{completed} = "<th class=listheading>" . $locale->text('Completed') . "</a></th>";
- $column_header{stock} = "<th class=listheading>" . $locale->text('Add') . "</a></th>";
-
-
- $form->header;
-
- if (@{ $form->{all_project} }) {
- $sameitem = $form->{all_project}->[0]->{$form->{sort}};
- }
-
- print qq|
+ $form->sort_order();
+
+ $callback = "$form->{script}?";
+ for (qw(action direction oldsort type path login sessionid status)) {
+ $callback .= "$_=$form->{$_}&";
+ }
+
+ @column_index =
+ $form->sort_columns(
+ qw(projectnumber description startdate partnumber production completed stock)
+ );
+
+ if ( $form->{projectnumber} ) {
+ $href .= "&projectnumber=" . $form->escape( $form->{projectnumber} );
+ $callback .= "&projectnumber=$form->{projectnumber}";
+ ($var) = split /--/, $form->{projectnumber};
+ $option .= "\n<br>" . $locale->text('Job Number') . " : $var";
+ }
+ if ( $form->{stockingdate} ) {
+ $href .= "&stockingdate=$form->{stockingdate}";
+ $option .= "\n<br>"
+ . $locale->text('As of') . " : "
+ . $locale->date( \%myconfig, $form->{stockingdate}, 1 );
+ }
+
+ $column_header{projectnumber} =
+ qq|<th width=30%><a class=listheading href=$href&sort=projectnumber>|
+ . $locale->text('Number')
+ . qq|</a></th>|;
+ $column_header{description} =
+ qq|<th width=50%><a class=listheading href=$href&sort=description>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
+ $column_header{startdate} =
+ qq|<th width=10%><a class=listheading href=$href&sort=startdate>|
+ . $locale->text('Startdate')
+ . qq|</a></th>|;
+ $column_header{partnumber} =
+ "<th><a class=listheading href=$href&sort=partnumber>"
+ . $locale->text('Assembly')
+ . "</a></th>";
+ $column_header{production} =
+ "<th class=listheading>" . $locale->text('Production') . "</a></th>";
+ $column_header{completed} =
+ "<th class=listheading>" . $locale->text('Completed') . "</a></th>";
+ $column_header{stock} =
+ "<th class=listheading>" . $locale->text('Add') . "</a></th>";
+
+ $form->header;
+
+ if ( @{ $form->{all_project} } ) {
+ $sameitem = $form->{all_project}->[0]->{ $form->{sort} };
+ }
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -475,46 +563,54 @@ sub list_stock {
<tr class=listheading>
|;
- for (@column_index) { print "$column_header{$_}\n" }
-
- print qq|
+ for (@column_index) { print "$column_header{$_}\n" }
+
+ print qq|
</tr>
|;
- # escape callback
- $form->{callback} = $callback .= "&sort=$form->{sort}";
+ # escape callback
+ $form->{callback} = $callback .= "&sort=$form->{sort}";
- # escape callback for href
- $callback = $form->escape($callback);
+ # escape callback for href
+ $callback = $form->escape($callback);
- # flip direction
- $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
- $href =~ s/&direction=(\w+)&/&direction=$direction&/;
+ # flip direction
+ $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
+ $href =~ s/&direction=(\w+)&/&direction=$direction&/;
- $i = 0;
- foreach $ref (@{ $form->{all_project} }) {
+ $i = 0;
+ foreach $ref ( @{ $form->{all_project} } ) {
- $i++;
-
- for (qw(projectnumber description startdate enddate partnumber)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
- for (qw(production completed)) { $column_data{$_} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{$_}).qq|</td>| }
- $column_data{stock} = qq|<td><input name="stock_$i" size=6></td>|;
-
- $j++; $j %= 2;
-
- print qq|
+ $i++;
+
+ for (qw(projectnumber description startdate enddate partnumber)) {
+ $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>|;
+ }
+ for (qw(production completed)) {
+ $column_data{$_} =
+ qq|<td align=right>|
+ . $form->format_amount( \%myconfig, $ref->{$_} )
+ . qq|</td>|;
+ }
+ $column_data{stock} = qq|<td><input name="stock_$i" size=6></td>|;
+
+ $j++;
+ $j %= 2;
+
+ print qq|
<tr valign=top class=listrow$j>
<input type=hidden name="id_$i" value=$ref->{id}>
|;
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print "
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print "
</tr>
";
- }
-
- print qq|
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -524,12 +620,14 @@ sub list_stock {
</table>
|;
- $form->hide_form(qw(callback type path login sessionid status));
+ $form->hide_form(qw(callback type path login sessionid status));
- print qq|
+ print qq|
<input type="hidden" name="nextsub" value="stock">
<br>
-<button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+<button type="submit" class="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
</body>
@@ -538,170 +636,188 @@ sub list_stock {
}
-
sub stock {
- if (PE->stock_assembly(\%myconfig, \%$form)) {
- $form->redirect($locale->text('Assembly stocked!'));
- } else {
- $form->error($locale->text('Cannot stock Assembly!'));
- }
+ if ( PE->stock_assembly( \%myconfig, \%$form ) ) {
+ $form->redirect( $locale->text('Assembly stocked!') );
+ }
+ else {
+ $form->error( $locale->text('Cannot stock Assembly!') );
+ }
}
-
sub prepare_project {
- $form->{vc} = 'customer';
+ $form->{vc} = 'customer';
- PE->get_project(\%myconfig, \%$form);
+ PE->get_project( \%myconfig, \%$form );
- $form->{title} = ($form->{id}) ? $locale->text('Edit Project') : $locale->text('Add Project');
-
- $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
+ $form->{title} =
+ ( $form->{id} )
+ ? $locale->text('Edit Project')
+ : $locale->text('Add Project');
- if (@{ $form->{"all_$form->{vc}"} }) {
- $form->{"$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
- $form->{"select$form->{vc}"} = qq|<option>\n|;
- for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
+ $form->{"old$form->{vc}"} =
+ qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
-}
+ if ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{"$form->{vc}"} =
+ qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
+ $form->{"select$form->{vc}"} = qq|<option>\n|;
+ for ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{"select$form->{vc}"} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
+}
sub search {
- # accounting years
- $form->all_years(\%myconfig);
+ # accounting years
+ $form->all_years( \%myconfig );
- if (@{ $form->{all_years} }) {
- $form->{selectaccountingyear} = "<option>\n";
- for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
+ 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| }
+ $form->{selectaccountingmonth} = "<option>\n";
+ for ( sort keys %{ $form->{all_month} } ) {
+ $form->{selectaccountingmonth} .=
+ qq|<option value=$_>|
+ . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
+ }
- $fromto = qq|
+ $fromto = qq|
<tr>
- <th align=right>|.$locale->text('Startdate').qq|</th>
- <td>|.$locale->text('From').qq| <input name=startdatefrom size=11 title="($myconfig{'dateformat'})">|.$locale->text('To').qq|
+ <th align=right>| . $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>
|;
- $selectperiod = qq|
+ $selectperiod = qq|
<tr>
- <th align=right>|.$locale->text('Period').qq|</th>
+ <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|
+ <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>
|;
- }
+ }
+ $orphaned = qq|
+ <input name=status class=radio type=radio value=orphaned>&nbsp;|
+ . $locale->text('Orphaned');
- $orphaned = qq|
- <input name=status class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned');
-
- if ($form->{type} eq 'project') {
- $report = "project_report";
- $sort = "projectnumber";
- $form->{title} = $locale->text('Projects');
+ if ( $form->{type} eq 'project' ) {
+ $report = "project_report";
+ $sort = "projectnumber";
+ $form->{title} = $locale->text('Projects');
- $number = qq|
+ $number = qq|
<tr>
- <th align=right width=1%>|.$locale->text('Number').qq|</th>
+ <th align=right width=1%>| . $locale->text('Number') . qq|</th>
<td><input name=projectnumber size=20></td>
</tr>
<tr>
- <th align=right>|.$locale->text('Description').qq|</th>
+ <th align=right>| . $locale->text('Description') . qq|</th>
<td><input name=description size=60></td>
</tr>
|;
- }
-
- if ($form->{type} eq 'stock') {
- $report = "list_stock";
- $form->{title} = $locale->text('Stock Finished Goods');
- PE->list_stock(\%myconfig, \%$form);
+ }
- $selectperiod = "";
- $orphaned = "";
- $fromto = qq|
+ if ( $form->{type} eq 'stock' ) {
+ $report = "list_stock";
+ $form->{title} = $locale->text('Stock Finished Goods');
+ PE->list_stock( \%myconfig, \%$form );
+
+ $selectperiod = "";
+ $orphaned = "";
+ $fromto = qq|
<tr>
- <th align=right nowrap>|.$locale->text('As of').qq|</th>
+ <th align=right nowrap>| . $locale->text('As of') . qq|</th>
<td><input name=stockingdate size=11 title="$myconfig{dateformat}"></td>
</tr>
|;
- $number = qq|
+ $number = qq|
<tr>
- <th align=right width=1%>|.$locale->text('Job Number').qq|</th>
+ <th align=right width=1%>| . $locale->text('Job Number') . qq|</th>
<td><input name=projectnumber size=20></td>
</tr>
<tr>
- <th align=right>|.$locale->text('Description').qq|</th>
+ <th align=right>| . $locale->text('Description') . qq|</th>
<td><input name=description size=60></td>
</tr>
|;
- }
-
- if ($form->{type} eq 'job') {
- $report = "job_report";
- $sort = "projectnumber";
- $form->{title} = $locale->text('Jobs');
+ }
+
+ if ( $form->{type} eq 'job' ) {
+ $report = "job_report";
+ $sort = "projectnumber";
+ $form->{title} = $locale->text('Jobs');
- $number = qq|
+ $number = qq|
<tr>
- <th align=right width=1%>|.$locale->text('Number').qq|</th>
+ <th align=right width=1%>| . $locale->text('Number') . qq|</th>
<td><input name=projectnumber size=20></td>
</tr>
<tr>
- <th align=right>|.$locale->text('Description').qq|</th>
+ <th align=right>| . $locale->text('Description') . qq|</th>
<td><input name=description size=60></td>
</tr>
|;
- }
+ }
- if ($form->{type} eq 'partsgroup') {
- $report = "partsgroup_report";
- $sort = 'partsgroup';
- $form->{title} = $locale->text('Groups');
-
- $fromto = "";
- $selectperiod = "";
- $number = qq|
+ if ( $form->{type} eq 'partsgroup' ) {
+ $report = "partsgroup_report";
+ $sort = 'partsgroup';
+ $form->{title} = $locale->text('Groups');
+
+ $fromto = "";
+ $selectperiod = "";
+ $number = qq|
<tr>
- <th align=right width=1%>|.$locale->text('Group').qq|</th>
+ <th align=right width=1%>| . $locale->text('Group') . qq|</th>
<td><input name=partsgroup size=20></td>
</tr>
|;
- }
+ }
- if ($form->{type} eq 'pricegroup') {
- $report = "pricegroup_report";
- $sort = 'pricegroup';
- $form->{title} = $locale->text('Pricegroups');
-
- $fromto = "";
- $selectperiod = "";
- $number = qq|
+ if ( $form->{type} eq 'pricegroup' ) {
+ $report = "pricegroup_report";
+ $sort = 'pricegroup';
+ $form->{title} = $locale->text('Pricegroups');
+
+ $fromto = "";
+ $selectperiod = "";
+ $number = qq|
<tr>
- <th align=right width=1%>|.$locale->text('Pricegroup').qq|</th>
+ <th align=right width=1%>| . $locale->text('Pricegroup') . qq|</th>
<td><input name=pricegroup size=20></td>
</tr>
|;
- }
-
+ }
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -722,9 +838,12 @@ sub search {
$selectperiod
<tr>
<td></td>
- <td><input name=status class=radio type=radio value=all checked>&nbsp;|.$locale->text('All').qq|
- <input name=status class=radio type=radio value=active>&nbsp;|.$locale->text('Active').qq|
- <input name=status class=radio type=radio value=inactive>&nbsp;|.$locale->text('Inactive').qq|
+ <td><input name=status class=radio type=radio value=all checked>&nbsp;|
+ . $locale->text('All') . qq|
+ <input name=status class=radio type=radio value=active>&nbsp;|
+ . $locale->text('Active') . qq|
+ <input name=status class=radio type=radio value=inactive>&nbsp;|
+ . $locale->text('Inactive') . qq|
$orphaned</td>
</tr>
</table>
@@ -738,19 +857,21 @@ sub search {
<input type=hidden name=nextsub value=$report>
|;
- $form->hide_form(qw(path login sessionid title));
+ $form->hide_form(qw(path login sessionid title));
- print qq|
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+ print qq|
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</body>
</html>
@@ -758,107 +879,144 @@ sub search {
}
-
sub job_report {
- for (qw(projectnumber description)) { $form->{$_} = $form->unescape($form->{$_}) }
- PE->jobs(\%myconfig, \%$form);
+ for (qw(projectnumber description)) {
+ $form->{$_} = $form->unescape( $form->{$_} );
+ }
+ PE->jobs( \%myconfig, \%$form );
- $form->{action} = "job_report";
- &list_projects;
+ $form->{action} = "job_report";
+ &list_projects;
}
-
sub project_report {
- for (qw(projectnumber description)) { $form->{$_} = $form->unescape($form->{$_}) }
- PE->projects(\%myconfig, \%$form);
+ for (qw(projectnumber description)) {
+ $form->{$_} = $form->unescape( $form->{$_} );
+ }
+ PE->projects( \%myconfig, \%$form );
- $form->{action} = "project_report";
- &list_projects;
+ $form->{action} = "project_report";
+ &list_projects;
}
-
sub list_projects {
- $href = "$form->{script}?";
- for (qw(action direction oldsort type path login sessionid status startdatefrom startdateto)) { $href .= "$_=$form->{$_}&" }
-
- $form->sort_order();
-
- $callback = "$form->{script}?";
- for (qw(action direction oldsort type path login sessionid status startdatefrom startdateto)) { $callback .= "$_=$form->{$_}&" }
-
- @column_index = $form->sort_columns(qw(projectnumber description name startdate enddate));
-
- if ($form->{status} eq 'all') {
- $option = $locale->text('All');
- }
- if ($form->{status} eq 'orphaned') {
- $option .= $locale->text('Orphaned');
- }
- if ($form->{status} eq 'active') {
- $option = $locale->text('Active');
- @column_index = $form->sort_columns(qw(projectnumber description name startdate));
- }
- if ($form->{status} eq 'inactive') {
- $option = $locale->text('Inactive');
- }
-
- if ($form->{type} eq 'project') {
- $label = $locale->text('Project');
- $form->{title} = $locale->text('Projects');
- } else {
- $label = $locale->text('Job');
- push @column_index, qw(partnumber production completed);
- $form->{title} = $locale->text('Jobs');
- }
-
- if ($form->{projectnumber}) {
- $href .= "&projectnumber=".$form->escape($form->{projectnumber});
- $callback .= "&projectnumber=$form->{projectnumber}";
- $option .= "\n<br>$label : $form->{projectnumber}";
- }
- if ($form->{description}) {
- $href .= "&description=".$form->escape($form->{description});
- $callback .= "&description=$form->{description}";
- $option .= "\n<br>".$locale->text('Description')." : $form->{description}";
- }
- if ($form->{startdatefrom}) {
- $href .= "&startdatefrom=$form->{startdatefrom}";
- $option .= "\n<br>".$locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{startdatefrom}, 1);
- }
- if ($form->{startdateto}) {
- $href .= "&startdateto=$form->{startdateto}";
- if ($form->{startdatefrom}) {
- $option .= " ";
- } else {
- $option .= "\n<br>" if ($option);
- }
- $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{startdateto}, 1);
- }
-
-
- $column_header{projectnumber} = qq|<th><a class=listheading href=$href&sort=projectnumber>|.$locale->text('Number').qq|</a></th>|;
- $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
- $column_header{startdate} = qq|<th width=10><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|;
- $column_header{enddate} = qq|<th width=10><a class=listheading href=$href&sort=enddate>|.$locale->text('Enddate').qq|</a></th>|;
-
- $column_header{partnumber} = "<th><a class=listheading href=$href&sort=partnumber>" . $locale->text('Assembly') . "</a></th>";
- $column_header{production} = "<th width=10 class=listheading>" . $locale->text('Production') . "</th>";
- $column_header{completed} = "<th width=10 class=listheading>" . $locale->text('Completed') . "</th>";
- $column_header{name} = "<th class=listheading>" . $locale->text('Customer') . "</th>";
-
-
- $form->header;
-
- if (@{ $form->{all_project} }) {
- $sameitem = $form->{all_project}->[0]->{$form->{sort}};
- }
-
- print qq|
+ $href = "$form->{script}?";
+ for (
+ qw(action direction oldsort type path login sessionid status startdatefrom startdateto)
+ )
+ {
+ $href .= "$_=$form->{$_}&";
+ }
+
+ $form->sort_order();
+
+ $callback = "$form->{script}?";
+ for (
+ qw(action direction oldsort type path login sessionid status startdatefrom startdateto)
+ )
+ {
+ $callback .= "$_=$form->{$_}&";
+ }
+
+ @column_index =
+ $form->sort_columns(qw(projectnumber description name startdate enddate));
+
+ if ( $form->{status} eq 'all' ) {
+ $option = $locale->text('All');
+ }
+ if ( $form->{status} eq 'orphaned' ) {
+ $option .= $locale->text('Orphaned');
+ }
+ if ( $form->{status} eq 'active' ) {
+ $option = $locale->text('Active');
+ @column_index =
+ $form->sort_columns(qw(projectnumber description name startdate));
+ }
+ if ( $form->{status} eq 'inactive' ) {
+ $option = $locale->text('Inactive');
+ }
+
+ if ( $form->{type} eq 'project' ) {
+ $label = $locale->text('Project');
+ $form->{title} = $locale->text('Projects');
+ }
+ else {
+ $label = $locale->text('Job');
+ push @column_index, qw(partnumber production completed);
+ $form->{title} = $locale->text('Jobs');
+ }
+
+ if ( $form->{projectnumber} ) {
+ $href .= "&projectnumber=" . $form->escape( $form->{projectnumber} );
+ $callback .= "&projectnumber=$form->{projectnumber}";
+ $option .= "\n<br>$label : $form->{projectnumber}";
+ }
+ if ( $form->{description} ) {
+ $href .= "&description=" . $form->escape( $form->{description} );
+ $callback .= "&description=$form->{description}";
+ $option .=
+ "\n<br>" . $locale->text('Description') . " : $form->{description}";
+ }
+ if ( $form->{startdatefrom} ) {
+ $href .= "&startdatefrom=$form->{startdatefrom}";
+ $option .= "\n<br>"
+ . $locale->text('From')
+ . "&nbsp;"
+ . $locale->date( \%myconfig, $form->{startdatefrom}, 1 );
+ }
+ if ( $form->{startdateto} ) {
+ $href .= "&startdateto=$form->{startdateto}";
+ if ( $form->{startdatefrom} ) {
+ $option .= " ";
+ }
+ else {
+ $option .= "\n<br>" if ($option);
+ }
+ $option .=
+ $locale->text('To') . "&nbsp;"
+ . $locale->date( \%myconfig, $form->{startdateto}, 1 );
+ }
+
+ $column_header{projectnumber} =
+ qq|<th><a class=listheading href=$href&sort=projectnumber>|
+ . $locale->text('Number')
+ . qq|</a></th>|;
+ $column_header{description} =
+ qq|<th><a class=listheading href=$href&sort=description>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
+ $column_header{startdate} =
+ qq|<th width=10><a class=listheading href=$href&sort=startdate>|
+ . $locale->text('Startdate')
+ . qq|</a></th>|;
+ $column_header{enddate} =
+ qq|<th width=10><a class=listheading href=$href&sort=enddate>|
+ . $locale->text('Enddate')
+ . qq|</a></th>|;
+
+ $column_header{partnumber} =
+ "<th><a class=listheading href=$href&sort=partnumber>"
+ . $locale->text('Assembly')
+ . "</a></th>";
+ $column_header{production} =
+ "<th width=10 class=listheading>" . $locale->text('Production') . "</th>";
+ $column_header{completed} =
+ "<th width=10 class=listheading>" . $locale->text('Completed') . "</th>";
+ $column_header{name} =
+ "<th class=listheading>" . $locale->text('Customer') . "</th>";
+
+ $form->header;
+
+ if ( @{ $form->{all_project} } ) {
+ $sameitem = $form->{all_project}->[0]->{ $form->{sort} };
+ }
+
+ print qq|
<body>
<table width=100%>
@@ -875,66 +1033,82 @@ sub list_projects {
<tr class=listheading>
|;
- for (@column_index) { print "$column_header{$_}\n" }
-
- print qq|
+ for (@column_index) { print "$column_header{$_}\n" }
+
+ print qq|
</tr>
|;
- # escape callback
- $form->{callback} = $callback .= "&sort=$form->{sort}";
+ # escape callback
+ $form->{callback} = $callback .= "&sort=$form->{sort}";
- # escape callback for href
- $callback = $form->escape($callback);
+ # escape callback for href
+ $callback = $form->escape($callback);
- # flip direction
- $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
- $href =~ s/&direction=(\w+)&/&direction=$direction&/;
+ # flip direction
+ $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
+ $href =~ s/&direction=(\w+)&/&direction=$direction&/;
- foreach $ref (@{ $form->{all_project} }) {
-
- for (qw(description startdate enddate name)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
+ foreach $ref ( @{ $form->{all_project} } ) {
- for (qw(production completed)) { $column_data{$_} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{$_}) }
+ for (qw(description startdate enddate name)) {
+ $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>|;
+ }
- $column_data{projectnumber} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&project=$form->{project}&callback=$callback>$ref->{projectnumber}</td>|;
- $column_data{partnumber} = qq|<td><a href=ic.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}</td>|;
-
- $j++; $j %= 2;
-
- print qq|
+ for (qw(production completed)) {
+ $column_data{$_} =
+ qq|<td align=right>|
+ . $form->format_amount( \%myconfig, $ref->{$_} );
+ }
+
+ $column_data{projectnumber} =
+qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&project=$form->{project}&callback=$callback>$ref->{projectnumber}</td>|;
+ $column_data{partnumber} =
+qq|<td><a href=ic.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}</td>|;
+
+ $j++;
+ $j %= 2;
+
+ print qq|
<tr valign=top class=listrow$j>
|;
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print "
+
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print "
</tr>
";
- }
-
- $i = 1;
- if ($form->{type} eq 'project') {
- if ($myconfig{acs} !~ /Projects--Projects/) {
- $button{'Projects--Add Project'}{code} = qq|<button class="submit" type="submit" name="action" value="add_project">|.$locale->text('Add Project').qq|</button> |;
- $button{'Projects--Add Project'}{order} = $i++;
-
- for (split /;/, $myconfig{acs}) {
- delete $button{$_};
- }
- }
- } else {
- if ($myconfig{acs} !~ /Job Costing--Job Costing/) {
- $button{'Job Costing--Add Job'}{code} = qq|<button class="submit" type="submit" name="action" value="add_job">|.$locale->text('Add Job').qq|</button> |;
- $button{'Job Costing--Add Job'}{order} = $i++;
-
- for (split /;/, $myconfig{acs}) {
- delete $button{$_};
- }
- }
- }
-
- print qq|
+ }
+
+ $i = 1;
+ if ( $form->{type} eq 'project' ) {
+ if ( $myconfig{acs} !~ /Projects--Projects/ ) {
+ $button{'Projects--Add Project'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add_project">|
+ . $locale->text('Add Project')
+ . qq|</button> |;
+ $button{'Projects--Add Project'}{order} = $i++;
+
+ for ( split /;/, $myconfig{acs} ) {
+ delete $button{$_};
+ }
+ }
+ }
+ else {
+ if ( $myconfig{acs} !~ /Job Costing--Job Costing/ ) {
+ $button{'Job Costing--Add Job'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add_job">|
+ . $locale->text('Add Job')
+ . qq|</button> |;
+ $button{'Job Costing--Add Job'}{order} = $i++;
+
+ for ( split /;/, $myconfig{acs} ) {
+ delete $button{$_};
+ }
+ }
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -947,18 +1121,18 @@ sub list_projects {
<form method=post action=$form->{script}>
|;
- $form->hide_form(qw(callback type path login sessionid));
+ $form->hide_form(qw(callback type path login sessionid));
- foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
- print $item->{code};
- }
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
+ print $item->{code};
+ }
- print qq|
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
</form>
</body>
@@ -967,54 +1141,63 @@ sub list_projects {
}
-
sub project_header {
- $form->{description} = $form->quote($form->{description});
-
- if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
- $description = qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
- } else {
- $description = qq|<input name=description size=60 value="$form->{description}">|;
- }
-
- $form->{"select$form->{vc}"} = $form->unescape($form->{"select$form->{vc}"});
- $form->{"select$form->{vc}"} =~ s/ selected//;
- $form->{"select$form->{vc}"} =~ s/(<option value="\Q$form->{"$form->{vc}"}\E")/$1 selected/;
+ $form->{description} = $form->quote( $form->{description} );
+
+ if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) {
+ $description =
+qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
+ }
+ else {
+ $description =
+ qq|<input name=description size=60 value="$form->{description}">|;
+ }
- $label = ucfirst $form->{vc};
- if ($form->{"select$form->{vc}"}) {
- $name = qq|
+ $form->{"select$form->{vc}"} =
+ $form->unescape( $form->{"select$form->{vc}"} );
+ $form->{"select$form->{vc}"} =~ s/ selected//;
+ $form->{"select$form->{vc}"} =~
+ s/(<option value="\Q$form->{"$form->{vc}"}\E")/$1 selected/;
+
+ $label = ucfirst $form->{vc};
+ if ( $form->{"select$form->{vc}"} ) {
+ $name = qq|
<tr>
- <th align=right nowrap>|.$locale->text($label).qq|</th>
+ <th align=right nowrap>| . $locale->text($label) . qq|</th>
<td colspan=3><select name="$form->{vc}">$form->{"select$form->{vc}"}</select></td>
- <input type=hidden name="select$form->{vc}" value="|.
- $form->escape($form->{"select$form->{vc}"},1).qq|">
+ <input type=hidden name="select$form->{vc}" value="|
+ . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|">
</tr>
|;
- } else {
- $name = qq|
+ }
+ else {
+ $name = qq|
<tr>
- <th align=right nowrap>|.$locale->text($label).qq|</th>
+ <th align=right nowrap>| . $locale->text($label) . qq|</th>
<td colspan=3><input name="$form->{vc}" value="$form->{"$form->{vc}"}" size=35></td>
- <input type=hidden name="select$form->{vc}" value="|.
- $form->escape($form->{"select$form->{vc}"},1).qq|">
+ <input type=hidden name="select$form->{vc}" value="|
+ . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|">
</tr>
|;
- }
-
+ }
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
|;
- $form->hide_form("id", "type", "old$form->{vc}", "$form->{vc}_id", "orphaned","vc", "title");
+ $form->hide_form(
+ "id", "type",
+ "old$form->{vc}", "$form->{vc}_id",
+ "orphaned", "vc",
+ "title"
+ );
- print qq|
+ print qq|
<table width=100%>
<tr>
<th class=listtop>$form->{title}</th>
@@ -1024,16 +1207,16 @@ sub project_header {
<td>
<table>
<tr>
- <th align=right>|.$locale->text('Number').qq|</th>
+ <th align=right>| . $locale->text('Number') . qq|</th>
<td><input name=projectnumber size=20 value="$form->{projectnumber}"></td>
- <th align=right>|.$locale->text('Description').qq|</th>
+ <th align=right>| . $locale->text('Description') . qq|</th>
<td>$description</td>
</tr>
$name
<tr>
- <th align=right>|.$locale->text('Startdate').qq|</th>
+ <th align=right>| . $locale->text('Startdate') . qq|</th>
<td><input name=startdate size=11 title="($myconfig{dateformat})" value=$form->{startdate}></td>
- <th align=right>|.$locale->text('Enddate').qq|</th>
+ <th align=right>| . $locale->text('Enddate') . qq|</th>
<td><input name=enddate size=11 title="($myconfig{dateformat})" value=$form->{enddate}></td>
</tr>
</table>
@@ -1047,30 +1230,34 @@ sub project_header {
}
-
sub project_footer {
- $form->hide_form(qw(callback path login sessionid));
-
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- );
-
- if ($myconfig{acs} !~ /Projects--Add Project/) {
- $button{'save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
+ $form->hide_form(qw(callback path login sessionid));
- if ($form->{id} && $form->{orphaned}) {
- $button{'delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') };
+ %button =
+ ( 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
+ );
+
+ if ( $myconfig{acs} !~ /Projects--Add Project/ ) {
+ $button{'save'} =
+ { ndx => 3, key => 'S', value => $locale->text('Save') };
+
+ if ( $form->{id} && $form->{orphaned} ) {
+ $button{'delete'} =
+ { ndx => 16, key => 'D', value => $locale->text('Delete') };
+ }
}
- }
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
+ for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
+ $form->print_button( \%button, $_ );
+ }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -1079,138 +1266,163 @@ sub project_footer {
}
-
sub save {
-
- if ($form->{translation}) {
- PE->save_translation(\%myconfig, \%$form);
- $form->redirect($locale->text('Translations saved!'));
- exit;
- }
-
- if ($form->{type} eq 'project') {
- if ($form->{"select$form->{vc}"}) {
- ($null, $form->{"$form->{vc}_id"}) = split /--/, $form->{"$form->{vc}"};
- } else {
- if ($form->{"old$form->{vc}"} ne qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|) {
-
- if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{startdate})) > 1) {
- &select_name;
- exit;
- }
-
- if ($rv == 1) {
- $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
- $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
- $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
- }
- }
- }
-
- PE->save_project(\%myconfig, \%$form);
- $form->redirect($locale->text('Project saved!'));
- }
-
- if ($form->{type} eq 'partsgroup') {
- $form->isblank("partsgroup", $locale->text('Group missing!'));
- PE->save_partsgroup(\%myconfig, \%$form);
- $form->redirect($locale->text('Group saved!'));
- }
-
- if ($form->{type} eq 'pricegroup') {
- $form->isblank("pricegroup", $locale->text('Pricegroup missing!'));
- PE->save_pricegroup(\%myconfig, \%$form);
- $form->redirect($locale->text('Pricegroup saved!'));
- }
-
- if ($form->{type} eq 'job') {
- if ($form->{"select$form->{vc}"}) {
- ($null, $form->{"$form->{vc}_id"}) = split /--/, $form->{"$form->{vc}"};
- } else {
- if ($form->{"old$form->{vc}"} ne qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|) {
-
- if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{startdate})) > 1) {
- &select_name;
- exit;
- }
-
- if ($rv == 1) {
- $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
- $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
- $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
- }
- }
- }
-
- PE->save_job(\%myconfig, \%$form);
- $form->redirect($locale->text('Job saved!'));
- }
+ if ( $form->{translation} ) {
+ PE->save_translation( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Translations saved!') );
+ exit;
+ }
+
+ if ( $form->{type} eq 'project' ) {
+ if ( $form->{"select$form->{vc}"} ) {
+ ( $null, $form->{"$form->{vc}_id"} ) = split /--/,
+ $form->{"$form->{vc}"};
+ }
+ else {
+ if ( $form->{"old$form->{vc}"} ne
+ qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}| )
+ {
+
+ if (
+ (
+ $rv = $form->get_name(
+ \%myconfig, $form->{vc}, $form->{startdate}
+ )
+ ) > 1
+ )
+ {
+ &select_name;
+ exit;
+ }
+
+ if ( $rv == 1 ) {
+ $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
+ $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
+ $form->{"old$form->{vc}"} =
+ qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
+ }
+ }
+ }
+
+ PE->save_project( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Project saved!') );
+ }
-}
+ if ( $form->{type} eq 'partsgroup' ) {
+ $form->isblank( "partsgroup", $locale->text('Group missing!') );
+ PE->save_partsgroup( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Group saved!') );
+ }
+ if ( $form->{type} eq 'pricegroup' ) {
+ $form->isblank( "pricegroup", $locale->text('Pricegroup missing!') );
+ PE->save_pricegroup( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Pricegroup saved!') );
+ }
+
+ if ( $form->{type} eq 'job' ) {
+ if ( $form->{"select$form->{vc}"} ) {
+ ( $null, $form->{"$form->{vc}_id"} ) = split /--/,
+ $form->{"$form->{vc}"};
+ }
+ else {
+ if ( $form->{"old$form->{vc}"} ne
+ qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}| )
+ {
+
+ if (
+ (
+ $rv = $form->get_name(
+ \%myconfig, $form->{vc}, $form->{startdate}
+ )
+ ) > 1
+ )
+ {
+ &select_name;
+ exit;
+ }
+
+ if ( $rv == 1 ) {
+ $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
+ $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
+ $form->{"old$form->{vc}"} =
+ qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
+ }
+ }
+ }
+
+ PE->save_job( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Job saved!') );
+ }
+
+}
sub delete {
- if ($form->{translation}) {
- PE->delete_translation(\%myconfig, \%$form);
- $form->redirect($locale->text('Translation deleted!'));
+ if ( $form->{translation} ) {
+ PE->delete_translation( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Translation deleted!') );
- } else {
-
- if ($form->{type} eq 'project') {
- PE->delete_project(\%myconfig, \%$form);
- $form->redirect($locale->text('Project deleted!'));
- }
- if ($form->{type} eq 'job') {
- PE->delete_job(\%myconfig, \%$form);
- $form->redirect($locale->text('Job deleted!'));
- }
- if ($form->{type} eq 'partsgroup') {
- PE->delete_partsgroup(\%myconfig, \%$form);
- $form->redirect($locale->text('Group deleted!'));
}
- if ($form->{type} eq 'pricegroup') {
- PE->delete_pricegroup(\%myconfig, \%$form);
- $form->redirect($locale->text('Pricegroup deleted!'));
+ else {
+
+ if ( $form->{type} eq 'project' ) {
+ PE->delete_project( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Project deleted!') );
+ }
+ if ( $form->{type} eq 'job' ) {
+ PE->delete_job( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Job deleted!') );
+ }
+ if ( $form->{type} eq 'partsgroup' ) {
+ PE->delete_partsgroup( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Group deleted!') );
+ }
+ if ( $form->{type} eq 'pricegroup' ) {
+ PE->delete_pricegroup( \%myconfig, \%$form );
+ $form->redirect( $locale->text('Pricegroup deleted!') );
+ }
}
- }
}
-
sub partsgroup_report {
- $form->{partsgroup} = $form->unescape($form->{partsgroup});
- PE->partsgroups(\%myconfig, \%$form);
+ $form->{partsgroup} = $form->unescape( $form->{partsgroup} );
+ PE->partsgroups( \%myconfig, \%$form );
- $href = "$form->{script}?action=partsgroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
-
- $form->sort_order();
+ $href =
+"$form->{script}?action=partsgroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
- $callback = "$form->{script}?action=partsgroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
-
- if ($form->{status} eq 'all') {
- $option = $locale->text('All');
- }
- if ($form->{status} eq 'orphaned') {
- $option .= $locale->text('Orphaned');
- }
- if ($form->{partsgroup}) {
- $callback .= "&partsgroup=$form->{partsgroup}";
- $option .= "\n<br>".$locale->text('Group')." : $form->{partsgroup}";
- }
-
+ $form->sort_order();
+
+ $callback =
+"$form->{script}?action=partsgroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
+
+ if ( $form->{status} eq 'all' ) {
+ $option = $locale->text('All');
+ }
+ if ( $form->{status} eq 'orphaned' ) {
+ $option .= $locale->text('Orphaned');
+ }
+ if ( $form->{partsgroup} ) {
+ $callback .= "&partsgroup=$form->{partsgroup}";
+ $option .= "\n<br>" . $locale->text('Group') . " : $form->{partsgroup}";
+ }
- @column_index = $form->sort_columns(qw(partsgroup));
+ @column_index = $form->sort_columns(qw(partsgroup));
- $column_header{partsgroup} = qq|<th><a class=listheading href=$href&sort=partsgroup width=90%>|.$locale->text('Group').qq|</a></th>|;
+ $column_header{partsgroup} =
+ qq|<th><a class=listheading href=$href&sort=partsgroup width=90%>|
+ . $locale->text('Group')
+ . qq|</a></th>|;
- $form->{title} = $locale->text('Groups');
+ $form->{title} = $locale->text('Groups');
- $form->header;
-
- print qq|
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -1227,45 +1439,50 @@ sub partsgroup_report {
<tr class=listheading>
|;
- for (@column_index) { print "$column_header{$_}\n" }
-
- print qq|
+ for (@column_index) { print "$column_header{$_}\n" }
+
+ print qq|
</tr>
|;
- # escape callback
- $form->{callback} = $callback;
+ # escape callback
+ $form->{callback} = $callback;
- # escape callback for href
- $callback = $form->escape($callback);
-
- foreach $ref (@{ $form->{item_list} }) {
-
- $i++; $i %= 2;
-
- print qq|
+ # escape callback for href
+ $callback = $form->escape($callback);
+
+ foreach $ref ( @{ $form->{item_list} } ) {
+
+ $i++;
+ $i %= 2;
+
+ print qq|
<tr valign=top class=listrow$i>
|;
-
- $column_data{partsgroup} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partsgroup}</td>|;
- for (@column_index) { print "$column_data{$_}\n" }
-
- print "
+
+ $column_data{partsgroup} =
+qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partsgroup}</td>|;
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print "
</tr>
";
- }
-
- $i = 1;
- if ($myconfig{acs} !~ /Goods \& Services--Goods \& Services/) {
- $button{'Goods & Services--Add Group'}{code} = qq|<button class="submit" type="submit" name="action" value="add_group">|.$locale->text('Add Group').qq|</button> |;
- $button{'Goods & Services--Add Group'}{order} = $i++;
+ }
- foreach $item (split /;/, $myconfig{acs}) {
- delete $button{$item};
+ $i = 1;
+ if ( $myconfig{acs} !~ /Goods \& Services--Goods \& Services/ ) {
+ $button{'Goods & Services--Add Group'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add_group">|
+ . $locale->text('Add Group')
+ . qq|</button> |;
+ $button{'Goods & Services--Add Group'}{order} = $i++;
+
+ foreach $item ( split /;/, $myconfig{acs} ) {
+ delete $button{$item};
+ }
}
- }
-
- print qq|
+
+ print qq|
</table>
</td>
</tr>
@@ -1278,18 +1495,18 @@ sub partsgroup_report {
<form method=post action=$form->{script}>
|;
- $form->hide_form(qw(callback type path login sessionid));
+ $form->hide_form(qw(callback type path login sessionid));
- foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
- print $item->{code};
- }
+ foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
+ print $item->{code};
+ }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -1298,21 +1515,19 @@ sub partsgroup_report {
}
-
sub partsgroup_header {
- $form->{action} =~ s/_.*//;
- $form->{title} = $locale->text(ucfirst $form->{action} . " Group");
+ $form->{action} =~ s/_.*//;
+ $form->{title} = $locale->text( ucfirst $form->{action} . " Group" );
-# $locale->text('Add Group')
-# $locale->text('Edit Group')
+ # $locale->text('Add Group')
+ # $locale->text('Edit Group')
- $form->{partsgroup} = $form->quote($form->{partsgroup});
+ $form->{partsgroup} = $form->quote( $form->{partsgroup} );
-
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -1329,7 +1544,7 @@ sub partsgroup_header {
<td>
<table width=100%>
<tr>
- <th align=right>|.$locale->text('Group').qq|</th>
+ <th align=right>| . $locale->text('Group') . qq|</th>
<td><input name=partsgroup size=30 value="$form->{partsgroup}"></td>
</tr>
@@ -1344,28 +1559,31 @@ sub partsgroup_header {
}
-
sub partsgroup_footer {
- $form->hide_form(qw(callback path login sessionid));
+ $form->hide_form(qw(callback path login sessionid));
- if ($myconfig{acs} !~ /Goods \& Services--Add Group/) {
- print qq|
-<button type="submit" class="submit" name="action" value="save">|.$locale->text('Save').qq|</button>
+ if ( $myconfig{acs} !~ /Goods \& Services--Add Group/ ) {
+ print qq|
+<button type="submit" class="submit" name="action" value="save">|
+ . $locale->text('Save')
+ . qq|</button>
|;
- if ($form->{id} && $form->{orphaned}) {
- print qq|
-<button type="submit" class="submit" name="action" value="delete">|.$locale->text('Delete').qq|</button>|;
+ if ( $form->{id} && $form->{orphaned} ) {
+ print qq|
+<button type="submit" class="submit" name="action" value="delete">|
+ . $locale->text('Delete')
+ . qq|</button>|;
+ }
}
- }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -1374,39 +1592,43 @@ sub partsgroup_footer {
}
-
sub pricegroup_report {
- $form->{pricegroup} = $form->unescape($form->{pricegroup});
- PE->pricegroups(\%myconfig, \%$form);
+ $form->{pricegroup} = $form->unescape( $form->{pricegroup} );
+ PE->pricegroups( \%myconfig, \%$form );
- $href = "$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
-
- $form->sort_order();
+ $href =
+"$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
- $callback = "$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
-
- if ($form->{status} eq 'all') {
- $option = $locale->text('All');
- }
- if ($form->{status} eq 'orphaned') {
- $option .= $locale->text('Orphaned');
- }
- if ($form->{pricegroup}) {
- $callback .= "&pricegroup=$form->{pricegroup}";
- $option .= "\n<br>".$locale->text('Pricegroup')." : $form->{pricegroup}";
- }
-
+ $form->sort_order();
- @column_index = $form->sort_columns(qw(pricegroup));
+ $callback =
+"$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
- $column_header{pricegroup} = qq|<th><a class=listheading href=$href&sort=pricegroup width=90%>|.$locale->text('Pricegroup').qq|</th>|;
+ if ( $form->{status} eq 'all' ) {
+ $option = $locale->text('All');
+ }
+ if ( $form->{status} eq 'orphaned' ) {
+ $option .= $locale->text('Orphaned');
+ }
+ if ( $form->{pricegroup} ) {
+ $callback .= "&pricegroup=$form->{pricegroup}";
+ $option .=
+ "\n<br>" . $locale->text('Pricegroup') . " : $form->{pricegroup}";
+ }
- $form->{title} = $locale->text('Pricegroups');
+ @column_index = $form->sort_columns(qw(pricegroup));
- $form->header;
-
- print qq|
+ $column_header{pricegroup} =
+ qq|<th><a class=listheading href=$href&sort=pricegroup width=90%>|
+ . $locale->text('Pricegroup')
+ . qq|</th>|;
+
+ $form->{title} = $locale->text('Pricegroups');
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -1423,45 +1645,50 @@ sub pricegroup_report {
<tr class=listheading>
|;
- for (@column_index) { print "$column_header{$_}\n" }
-
- print qq|
+ for (@column_index) { print "$column_header{$_}\n" }
+
+ print qq|
</tr>
|;
- # escape callback
- $form->{callback} = $callback;
+ # escape callback
+ $form->{callback} = $callback;
- # escape callback for href
- $callback = $form->escape($callback);
-
- foreach $ref (@{ $form->{item_list} }) {
-
- $i++; $i %= 2;
-
- print qq|
+ # escape callback for href
+ $callback = $form->escape($callback);
+
+ foreach $ref ( @{ $form->{item_list} } ) {
+
+ $i++;
+ $i %= 2;
+
+ print qq|
<tr valign=top class=listrow$i>
|;
-
- $column_data{pricegroup} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{pricegroup}</td>|;
- for (@column_index) { print "$column_data{$_}\n" }
-
- print "
+
+ $column_data{pricegroup} =
+qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{pricegroup}</td>|;
+ for (@column_index) { print "$column_data{$_}\n" }
+
+ print "
</tr>
";
- }
-
- $i = 1;
- if ($myconfig{acs} !~ /Goods \& Services--Goods \& Services/) {
- $button{'Goods & Services--Add Pricegroup'}{code} = qq|<button class="submit" type="submit" name="action" value="add_pricegroup">|.$locale->text('Add Pricegroup').qq|</button> |;
- $button{'Goods & Services--Add Pricegroup'}{order} = $i++;
+ }
- foreach $item (split /;/, $myconfig{acs}) {
- delete $button{$item};
+ $i = 1;
+ if ( $myconfig{acs} !~ /Goods \& Services--Goods \& Services/ ) {
+ $button{'Goods & Services--Add Pricegroup'}{code} =
+qq|<button class="submit" type="submit" name="action" value="add_pricegroup">|
+ . $locale->text('Add Pricegroup')
+ . qq|</button> |;
+ $button{'Goods & Services--Add Pricegroup'}{order} = $i++;
+
+ foreach $item ( split /;/, $myconfig{acs} ) {
+ delete $button{$item};
+ }
}
- }
-
- print qq|
+
+ print qq|
</table>
</td>
</tr>
@@ -1474,18 +1701,18 @@ sub pricegroup_report {
<form method=post action=$form->{script}>
|;
- $form->hide_form(qw(callback type path login sessionid));
-
- foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
- print $item->{code};
- }
+ $form->hide_form(qw(callback type path login sessionid));
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
+ print $item->{code};
+ }
+
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -1494,19 +1721,18 @@ sub pricegroup_report {
}
-
sub pricegroup_header {
- $form->{title} = $locale->text(ucfirst $form->{action} ." Pricegroup");
+ $form->{title} = $locale->text( ucfirst $form->{action} . " Pricegroup" );
-# $locale->text('Add Pricegroup')
-# $locale->text('Edit Pricegroup')
+ # $locale->text('Add Pricegroup')
+ # $locale->text('Edit Pricegroup')
- $form->{pricegroup} = $form->quote($form->{pricegroup});
+ $form->{pricegroup} = $form->quote( $form->{pricegroup} );
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -1523,7 +1749,7 @@ sub pricegroup_header {
<td>
<table width=100%>
<tr>
- <th align=right>|.$locale->text('Pricegroup').qq|</th>
+ <th align=right>| . $locale->text('Pricegroup') . qq|</th>
<td><input name=pricegroup size=30 value="$form->{pricegroup}"></td>
</tr>
@@ -1538,28 +1764,31 @@ sub pricegroup_header {
}
-
sub pricegroup_footer {
- $form->hide_form(qw(callback path login sessionid));
-
- if ($myconfig{acs} !~ /Goods \& Services--Add Pricegroup/) {
- print qq|
-<button type="submit" class="submit" name="action" value="save">|.$locale->text('Save').qq|</button>
+ $form->hide_form(qw(callback path login sessionid));
+
+ if ( $myconfig{acs} !~ /Goods \& Services--Add Pricegroup/ ) {
+ print qq|
+<button type="submit" class="submit" name="action" value="save">|
+ . $locale->text('Save')
+ . qq|</button>
|;
- if ($form->{id} && $form->{orphaned}) {
- print qq|
-<button type="submit" class="submit" name="action" value="delete">|.$locale->text('Delete').qq|</button>|;
+ if ( $form->{id} && $form->{orphaned} ) {
+ print qq|
+<button type="submit" class="submit" name="action" value="delete">|
+ . $locale->text('Delete')
+ . qq|</button>|;
+ }
}
- }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -1568,50 +1797,48 @@ sub pricegroup_footer {
}
-
sub translation {
- if ($form->{translation} eq 'description') {
- $form->{title} = $locale->text('Description Translations');
- $sort = qq|<input type=hidden name=sort value=partnumber>|;
- $form->{number} = "partnumber";
- $number = qq|
+ if ( $form->{translation} eq 'description' ) {
+ $form->{title} = $locale->text('Description Translations');
+ $sort = qq|<input type=hidden name=sort value=partnumber>|;
+ $form->{number} = "partnumber";
+ $number = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('Number') . qq|</th>
<td><input name=partnumber size=20></td>
</tr>
|;
- }
+ }
- if ($form->{translation} eq 'partsgroup') {
- $form->{title} = $locale->text('Group Translations');
- $sort = qq|<input type=hidden name=sort value=partsgroup>|;
- }
-
- if ($form->{translation} eq 'project') {
- $form->{title} = $locale->text('Project Description Translations');
- $form->{number} = "projectnumber";
- $sort = qq|<input type=hidden name=sort value=projectnumber>|;
- $number = qq|
+ if ( $form->{translation} eq 'partsgroup' ) {
+ $form->{title} = $locale->text('Group Translations');
+ $sort = qq|<input type=hidden name=sort value=partsgroup>|;
+ }
+
+ if ( $form->{translation} eq 'project' ) {
+ $form->{title} = $locale->text('Project Description Translations');
+ $form->{number} = "projectnumber";
+ $sort = qq|<input type=hidden name=sort value=projectnumber>|;
+ $number = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Project Number').qq|</th>
+ <th align=right nowrap>| . $locale->text('Project Number') . qq|</th>
<td><input name=projectnumber size=20></td>
</tr>
|;
- }
+ }
+ $form->header;
- $form->header;
-
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
|;
- $form->hide_form(qw(translation title number));
-
- print qq|
+ $form->hide_form(qw(translation title number));
+
+ print qq|
<table width="100%">
<tr><th class=listtop>$form->{title}</th></tr>
@@ -1621,7 +1848,7 @@ sub translation {
<table>
$number
<tr>
- <th align=right nowrap>|.$locale->text('Description').qq|</th>
+ <th align=right nowrap>| . $locale->text('Description') . qq|</th>
<td colspan=3><input name=description size=40></td>
</tr>
</table>
@@ -1634,12 +1861,14 @@ sub translation {
$sort
|;
- $form->hide_form(qw(path login sessionid));
+ $form->hide_form(qw(path login sessionid));
- print qq|
+ print qq|
<br>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
</body>
@@ -1648,49 +1877,66 @@ $sort
}
-
sub list_translations {
- $title = $form->escape($form->{title},1);
-
- $callback = "$form->{script}?action=list_translations&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&translation=$form->{translation}&number=$form->{number}&title=$title";
-
- if ($form->{"$form->{number}"}) {
- $callback .= qq|&$form->{number}=$form->{"$form->{number}"}|;
- $option .= $locale->text('Number').qq| : $form->{"$form->{number}"}<br>|;
- }
- if ($form->{description}) {
- $callback .= "&description=$form->{description}";
- $description = $form->{description};
- $description =~ s/\r?\n/<br>/g;
- $option .= $locale->text('Description').qq| : $form->{description}<br>|;
- }
-
- if ($form->{translation} eq 'partsgroup') {
- @column_index = qw(description language translation);
- $form->{sort} = "";
- } else {
- @column_index = $form->sort_columns("$form->{number}", "description", "language", "translation");
- }
-
- &{ "PE::$form->{translation}_translations" }("", \%myconfig, \%$form);
-
- $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
-
- $href = $callback;
-
- $form->sort_order();
-
- $callback =~ s/(direction=).*\&{1}/$1$form->{direction}\&/;
+ $title = $form->escape( $form->{title}, 1 );
- $column_header{"$form->{number}"} = qq|<th nowrap><a class=listheading href=$href&sort=$form->{number}>|.$locale->text('Number').qq|</a></th>|;
- $column_header{description} = qq|<th nowrap width=40%><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
- $column_header{language} = qq|<th nowrap class=listheading>|.$locale->text('Language').qq|</a></th>|;
- $column_header{translation} = qq|<th nowrap width=40% class=listheading>|.$locale->text('Translation').qq|</a></th>|;
+ $callback =
+"$form->{script}?action=list_translations&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&translation=$form->{translation}&number=$form->{number}&title=$title";
- $form->header;
+ if ( $form->{"$form->{number}"} ) {
+ $callback .= qq|&$form->{number}=$form->{"$form->{number}"}|;
+ $option .=
+ $locale->text('Number') . qq| : $form->{"$form->{number}"}<br>|;
+ }
+ if ( $form->{description} ) {
+ $callback .= "&description=$form->{description}";
+ $description = $form->{description};
+ $description =~ s/\r?\n/<br>/g;
+ $option .=
+ $locale->text('Description') . qq| : $form->{description}<br>|;
+ }
- print qq|
+ if ( $form->{translation} eq 'partsgroup' ) {
+ @column_index = qw(description language translation);
+ $form->{sort} = "";
+ }
+ else {
+ @column_index =
+ $form->sort_columns( "$form->{number}", "description", "language",
+ "translation" );
+ }
+
+ &{"PE::$form->{translation}_translations"}( "", \%myconfig, \%$form );
+
+ $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
+
+ $href = $callback;
+
+ $form->sort_order();
+
+ $callback =~ s/(direction=).*\&{1}/$1$form->{direction}\&/;
+
+ $column_header{"$form->{number}"} =
+ qq|<th nowrap><a class=listheading href=$href&sort=$form->{number}>|
+ . $locale->text('Number')
+ . qq|</a></th>|;
+ $column_header{description} =
+ qq|<th nowrap width=40%><a class=listheading href=$href&sort=description>|
+ . $locale->text('Description')
+ . qq|</a></th>|;
+ $column_header{language} =
+ qq|<th nowrap class=listheading>|
+ . $locale->text('Language')
+ . qq|</a></th>|;
+ $column_header{translation} =
+ qq|<th nowrap width=40% class=listheading>|
+ . $locale->text('Translation')
+ . qq|</a></th>|;
+
+ $form->header;
+
+ print qq|
<body>
<table width=100%>
@@ -1707,43 +1953,44 @@ sub list_translations {
<tr class=listheading>
|;
- for (@column_index) { print "\n$column_header{$_}" }
-
- print qq|
+ for (@column_index) { print "\n$column_header{$_}" }
+
+ print qq|
</tr>
|;
+ # add order to callback
+ $form->{callback} = $callback .= "&sort=$form->{sort}";
- # add order to callback
- $form->{callback} = $callback .= "&sort=$form->{sort}";
+ # escape callback for href
+ $callback = $form->escape($callback);
- # escape callback for href
- $callback = $form->escape($callback);
+ if ( @{ $form->{translations} } ) {
+ $sameitem = $form->{translations}->[0]->{ $form->{sort} };
+ }
- if (@{ $form->{translations} }) {
- $sameitem = $form->{translations}->[0]->{$form->{sort}};
- }
+ foreach $ref ( @{ $form->{translations} } ) {
- foreach $ref (@{ $form->{translations} }) {
-
- $ref->{description} =~ s/\r?\n/<br>/g;
-
- for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
-
- $column_data{description} = "<td><a href=$form->{script}?action=edit_translation&translation=$form->{translation}&number=$form->{number}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}&nbsp;</a></td>";
-
- $i++; $i %= 2;
- print "<tr class=listrow$i>";
+ $ref->{description} =~ s/\r?\n/<br>/g;
- for (@column_index) { print "\n$column_data{$_}" }
+ for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
- print qq|
+ $column_data{description} =
+"<td><a href=$form->{script}?action=edit_translation&translation=$form->{translation}&number=$form->{number}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}&nbsp;</a></td>";
+
+ $i++;
+ $i %= 2;
+ print "<tr class=listrow$i>";
+
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
</tr>
|;
- }
-
- print qq|
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -1751,8 +1998,8 @@ sub list_translations {
</table>
|;
-
- print qq|
+
+ print qq|
<br>
@@ -1761,14 +2008,14 @@ sub list_translations {
<input name=callback type=hidden value="$form->{callback}">
|;
- $form->hide_form(qw(path login sessionid));
+ $form->hide_form(qw(path login sessionid));
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -1777,66 +2024,74 @@ sub list_translations {
}
-
sub edit_translation {
- &{ "PE::$form->{translation}_translations" }("", \%myconfig, \%$form);
+ &{"PE::$form->{translation}_translations"}( "", \%myconfig, \%$form );
- $form->error($locale->text('Languages not defined!')) unless @{ $form->{all_language} };
+ $form->error( $locale->text('Languages not defined!') )
+ unless @{ $form->{all_language} };
- $form->{selectlanguage} = qq|<option>\n|;
- for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
+ $form->{selectlanguage} = qq|<option>\n|;
+ for ( @{ $form->{all_language} } ) {
+ $form->{selectlanguage} .=
+ qq|<option value="$_->{code}">$_->{description}\n|;
+ }
- $form->{"$form->{number}"} = $form->{translations}->[0]->{"$form->{number}"};
- $form->{description} = $form->{translations}->[0]->{description};
- $form->{description} =~ s/\r?\n/<br>/g;
+ $form->{"$form->{number}"} =
+ $form->{translations}->[0]->{"$form->{number}"};
+ $form->{description} = $form->{translations}->[0]->{description};
+ $form->{description} =~ s/\r?\n/<br>/g;
- shift @{ $form->{translations} };
+ shift @{ $form->{translations} };
- $i = 1;
- foreach $row (@{ $form->{translations} }) {
- $form->{"language_code_$i"} = $row->{code};
- $form->{"translation_$i"} = $row->{translation};
- $i++;
- }
- $form->{translation_rows} = $i - 1;
-
- $form->{title} = $locale->text('Edit Description Translations');
-
- &translation_header;
- &translation_footer;
+ $i = 1;
+ foreach $row ( @{ $form->{translations} } ) {
+ $form->{"language_code_$i"} = $row->{code};
+ $form->{"translation_$i"} = $row->{translation};
+ $i++;
+ }
+ $form->{translation_rows} = $i - 1;
-}
+ $form->{title} = $locale->text('Edit Description Translations');
+ &translation_header;
+ &translation_footer;
+
+}
sub translation_header {
- $form->{translation_rows}++;
+ $form->{translation_rows}++;
- $form->{selectlanguage} = $form->unescape($form->{selectlanguage});
- for $i (1 .. $form->{translation_rows}) {
- $form->{"selectlanguage_$i"} = $form->{selectlanguage};
- if ($form->{"language_code_$i"}) {
- $form->{"selectlanguage_$i"} =~ s/(<option value="\Q$form->{"language_code_$i"}\E")/$1 selected/;
+ $form->{selectlanguage} = $form->unescape( $form->{selectlanguage} );
+ for $i ( 1 .. $form->{translation_rows} ) {
+ $form->{"selectlanguage_$i"} = $form->{selectlanguage};
+ if ( $form->{"language_code_$i"} ) {
+ $form->{"selectlanguage_$i"} =~
+ s/(<option value="\Q$form->{"language_code_$i"}\E")/$1 selected/;
+ }
}
- }
-
- $form->{selectlanguage} = $form->escape($form->{selectlanguage},1);
- $form->header;
-
- print qq|
+ $form->{selectlanguage} = $form->escape( $form->{selectlanguage}, 1 );
+
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
-<input type=hidden name=$form->{number} value="|.$form->quote($form->{"$form->{number}"}).qq|">
-<input type=hidden name=description value="|.$form->quote($form->{description}).qq|">
+<input type=hidden name=$form->{number} value="|
+ . $form->quote( $form->{"$form->{number}"} ) . qq|">
+<input type=hidden name=description value="|
+ . $form->quote( $form->{description} ) . qq|">
|;
- $form->hide_form(qw(id trans_id selectlanguage translation_rows number translation title));
+ $form->hide_form(
+ qw(id trans_id selectlanguage translation_rows number translation title)
+ );
- print qq|
+ print qq|
<table width="100%">
<tr><th class=listtop>$form->{title}</th></tr>
@@ -1850,28 +2105,33 @@ sub translation_header {
</tr>
<tr>
<tr>
- <th class=listheading>|.$locale->text('Language').qq|</th>
- <th class=listheading>|.$locale->text('Translation').qq|</th>
+ <th class=listheading>| . $locale->text('Language') . qq|</th>
+ <th class=listheading>| . $locale->text('Translation') . qq|</th>
</tr>
|;
- for $i (1 .. $form->{translation_rows}) {
-
- if (($rows = $form->numtextrows($form->{"translation_$i"}, 40)) > 1) {
- $translation = qq|<textarea name="translation_$i" rows=$rows cols=40 wrap=soft>$form->{"translation_$i"}</textarea>|;
- } else {
- $translation = qq|<input name="translation_$i" size=40 value="$form->{"translation_$i"}">|;
- }
-
- print qq|
+ for $i ( 1 .. $form->{translation_rows} ) {
+
+ if ( ( $rows = $form->numtextrows( $form->{"translation_$i"}, 40 ) ) >
+ 1 )
+ {
+ $translation =
+qq|<textarea name="translation_$i" rows=$rows cols=40 wrap=soft>$form->{"translation_$i"}</textarea>|;
+ }
+ else {
+ $translation =
+qq|<input name="translation_$i" size=40 value="$form->{"translation_$i"}">|;
+ }
+
+ print qq|
<tr valign=top>
<td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td>
<td>$translation</td>
</tr>
|;
- }
+ }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -1883,28 +2143,30 @@ sub translation_header {
}
-
sub translation_footer {
- $form->hide_form(qw(path login sessionid callback));
-
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
- 'delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') },
- );
-
- if (! $form->{trans_id}) {
- delete $button{'delete'};
- }
+ $form->hide_form(qw(path login sessionid callback));
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
+ %button = (
+ 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
+ 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
+ 'delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') },
+ );
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( !$form->{trans_id} ) {
+ delete $button{'delete'};
+ }
+
+ for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
+ $form->print_button( \%button, $_ );
+ }
- print qq|
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
+
+ print qq|
</form>
@@ -1914,93 +2176,117 @@ sub translation_footer {
}
-
sub update {
- if ($form->{translation}) {
- @flds = qw(language translation);
- $count = 0;
- @a = ();
- for $i (1 .. $form->{translation_rows}) {
- if ($form->{"language_code_$i"} ne "") {
- push @a, {};
- $j = $#a;
+ if ( $form->{translation} ) {
+ @flds = qw(language translation);
+ $count = 0;
+ @a = ();
+ for $i ( 1 .. $form->{translation_rows} ) {
+ if ( $form->{"language_code_$i"} ne "" ) {
+ push @a, {};
+ $j = $#a;
- for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
- $count++;
- }
- }
- $form->redo_rows(\@flds, \@a, $count, $form->{translation_rows});
- $form->{translation_rows} = $count;
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
+ }
+ }
+ $form->redo_rows( \@flds, \@a, $count, $form->{translation_rows} );
+ $form->{translation_rows} = $count;
- &translation_header;
- &translation_footer;
+ &translation_header;
+ &translation_footer;
- exit;
-
- }
+ exit;
- if ($form->{type} =~ /(job|project)/) {
+ }
-# $locale->text('Customer not on file!')
-# $locale->text('Vendor not on file!')
+ if ( $form->{type} =~ /(job|project)/ ) {
+
+ # $locale->text('Customer not on file!')
+ # $locale->text('Vendor not on file!')
+
+ for (qw(production listprice sellprice weight)) {
+ $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} );
+ }
+
+ $form->{projectnumber} =
+ $form->update_defaults( \%myconfig, "projectnumber" )
+ unless $form->{projectnumber};
+
+ if ( $form->{"select$form->{vc}"} ) {
+ if ( $form->{startdate} ne $form->{oldstartdate}
+ || $form->{enddate} ne $form->{oldenddate} )
+ {
+
+ PE->get_customer( \%myconfig, \%$form );
+
+ if ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{"select$form->{vc}"} = qq|<option>\n|;
+ for ( @{ $form->{"all_$form->{vc}"} } ) {
+ $form->{"select$form->{vc}"} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
+ }
+ }
+
+ $form->{"old$form->{vc}"} = $form->{"$form->{vc}"};
+ ( $null, $form->{"$form->{vc}_id"} ) = split /--/,
+ $form->{"$form->{vc}"};
+
+ }
+ else {
+
+ if ( $form->{"old$form->{vc}"} ne
+ qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}| )
+ {
+
+ if (
+ (
+ $rv = $form->get_name(
+ \%myconfig, $form->{vc}, $form->{startdate}
+ )
+ ) > 1
+ )
+ {
+ &select_name;
+ exit;
+ }
+
+ if ( $rv == 1 ) {
+ $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
+ $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
+ $form->{"old$form->{vc}"} =
+ qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
+ }
+ else {
+ $msg = ucfirst $form->{vc} . " not on file!";
+ $form->error( $locale->text($msg) );
+ }
+ }
+ }
+ }
- for (qw(production listprice sellprice weight)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+ &display_form;
- $form->{projectnumber} = $form->update_defaults(\%myconfig, "projectnumber") unless $form->{projectnumber};
-
- if ($form->{"select$form->{vc}"}) {
- if ($form->{startdate} ne $form->{oldstartdate} || $form->{enddate} ne $form->{oldenddate}) {
-
- PE->get_customer(\%myconfig, \%$form);
-
- if (@{ $form->{"all_$form->{vc}"} }) {
- $form->{"select$form->{vc}"} = qq|<option>\n|;
- for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- }
- }
-
- $form->{"old$form->{vc}"} = $form->{"$form->{vc}"};
- ($null, $form->{"$form->{vc}_id"}) = split /--/, $form->{"$form->{vc}"};
-
- } else {
-
- if ($form->{"old$form->{vc}"} ne qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|) {
-
- if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{startdate})) > 1) {
- &select_name;
- exit;
- }
-
- if ($rv == 1) {
- $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
- $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
- $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
- } else {
- $msg = ucfirst $form->{vc} ." not on file!";
- $form->error($locale->text($msg));
- }
- }
- }
- }
-
- &display_form;
-
}
-
sub select_name {
- $label = ucfirst $form->{vc};
-
- @column_index = qw(ndx name address);
- $column_data{ndx} = qq|<th>&nbsp;</th>|;
- $column_data{name} = qq|<th class=listheading>|.$locale->text($label).qq|</th>|;
- $column_data{address} = qq|<th class=listheading colspan=5>|.$locale->text('Address').qq|</th>|;
-
- $form->header;
- $title = $locale->text('Select from one of the names below');
- print qq|
+ $label = ucfirst $form->{vc};
+
+ @column_index = qw(ndx name address);
+ $column_data{ndx} = qq|<th>&nbsp;</th>|;
+ $column_data{name} =
+ qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
+ $column_data{address} =
+ qq|<th class=listheading colspan=5>|
+ . $locale->text('Address')
+ . qq|</th>|;
+
+ $form->header;
+ $title = $locale->text('Select from one of the names below');
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -2015,41 +2301,46 @@ sub select_name {
<table width=100%>
<tr class=listheading>|;
- for (@column_index) { print "\n$column_data{$_}" }
-
- print qq|
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ print qq|
</tr>
|;
- @column_index = qw(ndx name address city state zipcode country);
-
- my $i = 0;
- foreach $ref (@{ $form->{name_list} }) {
- $checked = ($i++) ? "" : "checked";
+ @column_index = qw(ndx name address city state zipcode country);
- $ref->{name} = $form->quote($ref->{name});
-
- $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
- $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
- $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}</td>|;
- for (qw(city state zipcode country)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
-
- $j++; $j %= 2;
- print qq|
+ my $i = 0;
+ foreach $ref ( @{ $form->{name_list} } ) {
+ $checked = ( $i++ ) ? "" : "checked";
+
+ $ref->{name} = $form->quote( $ref->{name} );
+
+ $column_data{ndx} =
+qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
+ $column_data{name} =
+qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
+ $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}</td>|;
+ for (qw(city state zipcode country)) {
+ $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>|;
+ }
+
+ $j++;
+ $j %= 2;
+ print qq|
<tr class=listrow$j>|;
- for (@column_index) { print "\n$column_data{$_}" }
+ for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ print qq|
</tr>
<input name="new_id_$i" type=hidden value=$ref->{id}>
|;
- }
-
- print qq|
+ }
+
+ print qq|
</table>
</td>
</tr>
@@ -2062,15 +2353,17 @@ sub select_name {
|;
- # delete variables
- for (qw(action nextsub name_list)) { delete $form->{$_} }
-
- $form->hide_form;
+ # delete variables
+ for (qw(action nextsub name_list)) { delete $form->{$_} }
+
+ $form->hide_form;
- print qq|
+ print qq|
<input type="hidden" name="nextsub" value="name_selected">
<br>
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
</body>
@@ -2079,107 +2372,125 @@ sub select_name {
}
-
sub name_selected {
- # replace the variable with the one checked
+ # replace the variable with the one checked
- # index for new item
- $i = $form->{ndx};
-
- $form->{$form->{vc}} = $form->{"new_name_$i"};
- $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
- $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
-
- # delete all the new_ variables
- for $i (1 .. $form->{lastndx}) {
- for (qw(id name)) { delete $form->{"new_${_}_$i"} }
- }
-
- for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
+ # index for new item
+ $i = $form->{ndx};
- &display_form;
+ $form->{ $form->{vc} } = $form->{"new_name_$i"};
+ $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
+ $form->{"old$form->{vc}"} =
+ qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
-}
+ # delete all the new_ variables
+ for $i ( 1 .. $form->{lastndx} ) {
+ for (qw(id name)) { delete $form->{"new_${_}_$i"} }
+ }
+
+ for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
+ &display_form;
+
+}
sub display_form {
- &{ "$form->{type}_header" };
- &{ "$form->{type}_footer" };
+ &{"$form->{type}_header"};
+ &{"$form->{type}_footer"};
}
-sub continue { &{ $form->{nextsub} } };
+sub continue { &{ $form->{nextsub} } }
-sub add_group { &add }
-sub add_project { &add }
-sub add_job { &add }
+sub add_group { &add }
+sub add_project { &add }
+sub add_job { &add }
sub add_pricegroup { &add }
-
-
sub project_sales_order {
- PE->project_sales_order(\%myconfig, \%$form);
-
- if (@{ $form->{all_years} }) {
- $form->{selectaccountingyear} = "<option>\n";
- for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
+ PE->project_sales_order( \%myconfig, \%$form );
- $form->{selectaccountingmonth} = "<option>\n";
- for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
+ if ( @{ $form->{all_years} } ) {
+ $form->{selectaccountingyear} = "<option>\n";
+ for ( @{ $form->{all_years} } ) {
+ $form->{selectaccountingyear} .= qq|<option>$_\n|;
+ }
- $selectfrom = qq|
+ $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>
+ <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|
+ <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|
+ $fromto = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Transaction Dates').qq|</th>
- <td>|.$locale->text('From').qq| <input name=transdatefrom size=11 title="$myconfig{dateformat}">
- |.$locale->text('To').qq| <input name=transdateto size=11 title="$myconfig{dateformat}"></td>
+ <th align=right nowrap>| . $locale->text('Transaction Dates') . qq|</th>
+ <td>|
+ . $locale->text('From')
+ . qq| <input name=transdatefrom size=11 title="$myconfig{dateformat}">
+ |
+ . $locale->text('To')
+ . qq| <input name=transdateto size=11 title="$myconfig{dateformat}"></td>
</tr>
$selectfrom
|;
- if (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} = "<option>\n";
- for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
- } else {
- $form->error($locale->text('No open Projects!'));
- }
+ if ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} = "<option>\n";
+ for ( @{ $form->{all_project} } ) {
+ $form->{selectprojectnumber} .=
+qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
+ }
+ }
+ else {
+ $form->error( $locale->text('No open Projects!') );
+ }
- if (@{ $form->{all_employee} }) {
- $form->{selectemployee} = "<option>\n";
- for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
+ if ( @{ $form->{all_employee} } ) {
+ $form->{selectemployee} = "<option>\n";
+ for ( @{ $form->{all_employee} } ) {
+ $form->{selectemployee} .=
+ qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
+ }
- $employee = qq|
+ $employee = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Employee').qq|</th>
+ <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
<td><select name=employee>$form->{selectemployee}</select></td>
</tr>
|;
- }
-
- $form->{title} = $locale->text('Generate Sales Orders');
- $form->{vc} = "customer";
- $form->{type} = "sales_order";
+ }
+
+ $form->{title} = $locale->text('Generate Sales Orders');
+ $form->{vc} = "customer";
+ $form->{type} = "sales_order";
- $form->header;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -2193,15 +2504,17 @@ sub project_sales_order {
<td>
<table>
<tr>
- <th align=right>|.$locale->text('Project').qq|</th>
+ <th align=right>| . $locale->text('Project') . qq|</th>
<td colspan=3><select name=projectnumber>$form->{selectprojectnumber}</select></td>
</tr>
$employee
$fromto
<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><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>
</table>
@@ -2213,22 +2526,24 @@ sub project_sales_order {
</table>
|;
-
- $form->{nextsub} = "project_jcitems_list";
- $form->hide_form(qw(path login sessionid nextsub type vc));
- print qq|
-<button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+ $form->{nextsub} = "project_jcitems_list";
+ $form->hide_form(qw(path login sessionid nextsub type vc));
+
+ print qq|
+<button type="submit" class="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</body>
</html>
@@ -2236,100 +2551,126 @@ sub project_sales_order {
}
-
sub project_jcitems_list {
- $form->{projectnumber} = $form->unescape($form->{projectnumber});
- $form->{employee} = $form->unescape($form->{employee});
- $form->{callback} = "$form->{script}?action=project_jcitems_list";
- for (qw(month year interval summary transdatefrom transdateto login path sessionid nextsub type vc)) { $form->{callback} .= "&$_=$form->{$_}" }
- for (qw(employe projectnumber)) { $form->{callback} .= "&$_=".$form->escape($form->{$_},1) }
-
- PE->get_jcitems(\%myconfig, \%$form);
+ $form->{projectnumber} = $form->unescape( $form->{projectnumber} );
+ $form->{employee} = $form->unescape( $form->{employee} );
+ $form->{callback} = "$form->{script}?action=project_jcitems_list";
+ for (
+ qw(month year interval summary transdatefrom transdateto login path sessionid nextsub type vc)
+ )
+ {
+ $form->{callback} .= "&$_=$form->{$_}";
+ }
+ for (qw(employe projectnumber)) {
+ $form->{callback} .= "&$_=" . $form->escape( $form->{$_}, 1 );
+ }
- # flatten array
- $i = 1;
- foreach $ref (@{ $form->{jcitems} }) {
-
- if ($form->{summary}) {
-
- $thisitem = qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|;
-
- if ($thisitem eq $sameitem) {
-
- $i--;
- for (qw(qty amount)) { $form->{"${_}_$i"} += $ref->{$_} }
- $form->{"id_$i"} .= " $ref->{id}:$ref->{qty}";
- if ($form->{"notes_$i"}) {
- $form->{"notes_$i"} .= qq|\n\n$ref->{notes}|;
- } else {
- $form->{"notes_$i"} = $ref->{notes};
- }
-
- } else {
-
- for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
-
- $form->{"checked_$i"} = 1;
- $form->{"$form->{vc}_$i"} = $ref->{$form->{vc}};
- $form->{"id_$i"} = "$ref->{id}:$ref->{qty}";
-
- }
-
- $sameitem = qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|;
- } else {
-
- for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
- $form->{"checked_$i"} = 1;
- $form->{"id_$i"} = "$ref->{id}:$ref->{qty}";
-
- }
-
- $i++;
-
- }
+ PE->get_jcitems( \%myconfig, \%$form );
- $form->{rowcount} = $i - 1;
+ # flatten array
+ $i = 1;
+ foreach $ref ( @{ $form->{jcitems} } ) {
- for $i (1 .. $form->{rowcount}) {
- for (qw(qty allocated)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) }
- for (qw(amount sellprice)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
- }
+ if ( $form->{summary} ) {
- &jcitems;
-
-}
+ $thisitem =
+ qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|;
+
+ if ( $thisitem eq $sameitem ) {
+ $i--;
+ for (qw(qty amount)) { $form->{"${_}_$i"} += $ref->{$_} }
+ $form->{"id_$i"} .= " $ref->{id}:$ref->{qty}";
+ if ( $form->{"notes_$i"} ) {
+ $form->{"notes_$i"} .= qq|\n\n$ref->{notes}|;
+ }
+ else {
+ $form->{"notes_$i"} = $ref->{notes};
+ }
+
+ }
+ else {
+
+ for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
+
+ $form->{"checked_$i"} = 1;
+ $form->{"$form->{vc}_$i"} = $ref->{ $form->{vc} };
+ $form->{"id_$i"} = "$ref->{id}:$ref->{qty}";
+
+ }
+
+ $sameitem =
+ qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|;
+ }
+ else {
+
+ for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
+ $form->{"checked_$i"} = 1;
+ $form->{"id_$i"} = "$ref->{id}:$ref->{qty}";
+
+ }
+
+ $i++;
+
+ }
+
+ $form->{rowcount} = $i - 1;
+
+ for $i ( 1 .. $form->{rowcount} ) {
+ for (qw(qty allocated)) {
+ $form->{"${_}_$i"} =
+ $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
+ }
+ for (qw(amount sellprice)) {
+ $form->{"${_}_$i"} =
+ $form->format_amount( \%myconfig, $form->{"${_}_$i"}, 2 );
+ }
+ }
+
+ &jcitems;
+
+}
sub jcitems {
-# $locale->text('Customer')
-# $locale->text('Vendor')
+ # $locale->text('Customer')
+ # $locale->text('Vendor')
- $vc = ucfirst $form->{vc};
-
- @column_index = qw(id projectnumber name);
- if (!$form->{summary}) {
- push @column_index, qw(transdate);
- }
- push @column_index, qw(partnumber description qty amount);
-
- $column_header{id} = qq|<th>&nbsp;</th>|;
- $column_header{transdate} = qq|<th class=listheading>|.$locale->text('Date').qq|</th>|;
- $column_header{partnumber} = qq|<th class=listheading>|.$locale->text('Service Code').qq|<br>|.$locale->text('Part Number').qq|</th>|;
- $column_header{projectnumber} = qq|<th class=listheading>|.$locale->text('Project Number').qq|</th>|;
- $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
- $column_header{name} = qq|<th class=listheading>$vc</th>|;
- $column_header{qty} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
- $column_header{amount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
-
- if ($form->{type} eq 'sales_order') {
- $form->{title} = $locale->text('Generate Sales Orders');
- }
+ $vc = ucfirst $form->{vc};
- $form->header;
+ @column_index = qw(id projectnumber name);
+ if ( !$form->{summary} ) {
+ push @column_index, qw(transdate);
+ }
+ push @column_index, qw(partnumber description qty amount);
+
+ $column_header{id} = qq|<th>&nbsp;</th>|;
+ $column_header{transdate} =
+ qq|<th class=listheading>| . $locale->text('Date') . qq|</th>|;
+ $column_header{partnumber} =
+ qq|<th class=listheading>|
+ . $locale->text('Service Code')
+ . qq|<br>|
+ . $locale->text('Part Number')
+ . qq|</th>|;
+ $column_header{projectnumber} =
+ qq|<th class=listheading>| . $locale->text('Project Number') . qq|</th>|;
+ $column_header{description} =
+ qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
+ $column_header{name} = qq|<th class=listheading>$vc</th>|;
+ $column_header{qty} =
+ qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
+ $column_header{amount} =
+ qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
+
+ if ( $form->{type} eq 'sales_order' ) {
+ $form->{title} = $locale->text('Generate Sales Orders');
+ }
+
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -2344,43 +2685,55 @@ sub jcitems {
<table width=100%>
<tr class=listheading>|;
- for (@column_index) { print "\n$column_header{$_}" }
+ for (@column_index) { print "\n$column_header{$_}" }
- print qq|
+ print qq|
</tr>
|;
- for $i (1 .. $form->{rowcount}) {
-
- for (@column_index) { $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>| }
- for (qw(qty amount)) { $column_data{$_} = qq|<td align=right>$form->{"${_}_$i"}</td>| }
-
- $checked = ($form->{"checked_$i"}) ? "checked" : "";
- $column_data{id} = qq|<td><input name="checked_$i" class=checkbox type=checkbox value="1" $checked></td>|;
-
- if ($form->{"$form->{vc}_id_$i"}) {
- $column_data{name} = qq|<td>$form->{"$form->{vc}_$i"}</td>|;
- $form->hide_form("$form->{vc}_id_$i", "$form->{vc}_$i");
- } else {
- $column_data{name} = qq|<td><input name="ndx_$i" class=checkbox type=checkbox value="1"></td>|;
- }
-
- for (qw(projectnumber partnumber description notes)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
- $form->hide_form(map {"${_}_$i"} qw(id project_id parts_id projectnumber transdate partnumber description notes qty amount taxaccounts sellprice));
-
- $j++; $j %= 2;
- print "
+ for $i ( 1 .. $form->{rowcount} ) {
+
+ for (@column_index) {
+ $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>|;
+ }
+ for (qw(qty amount)) {
+ $column_data{$_} = qq|<td align=right>$form->{"${_}_$i"}</td>|;
+ }
+
+ $checked = ( $form->{"checked_$i"} ) ? "checked" : "";
+ $column_data{id} =
+qq|<td><input name="checked_$i" class=checkbox type=checkbox value="1" $checked></td>|;
+
+ if ( $form->{"$form->{vc}_id_$i"} ) {
+ $column_data{name} = qq|<td>$form->{"$form->{vc}_$i"}</td>|;
+ $form->hide_form( "$form->{vc}_id_$i", "$form->{vc}_$i" );
+ }
+ else {
+ $column_data{name} =
+qq|<td><input name="ndx_$i" class=checkbox type=checkbox value="1"></td>|;
+ }
+
+ for (qw(projectnumber partnumber description notes)) {
+ $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} );
+ }
+ $form->hide_form( map { "${_}_$i" }
+ qw(id project_id parts_id projectnumber transdate partnumber description notes qty amount taxaccounts sellprice)
+ );
+
+ $j++;
+ $j %= 2;
+ print "
<tr class=listrow$j>";
- for (@column_index) { print "\n$column_data{$_}" }
+ for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ print qq|
</tr>
|;
- }
+ }
- print qq|
+ print qq|
</table>
</td>
</tr>
@@ -2393,25 +2746,31 @@ sub jcitems {
<br>
|;
- $form->hide_form(qw(path login sessionid vc nextsub rowcount type currency defaultcurrency taxaccounts summary callback));
+ $form->hide_form(
+ qw(path login sessionid vc nextsub rowcount type currency defaultcurrency taxaccounts summary callback)
+ );
- for (split / /, $form->{taxaccounts}) { $form->hide_form("${_}_rate") }
+ for ( split / /, $form->{taxaccounts} ) { $form->hide_form("${_}_rate") }
- if ($form->{rowcount}) {
- print qq|
-<button class="submit" type="submit" name="action" value="generate_sales_orders">|.$locale->text('Generate Sales Orders').qq|</button>|;
+ if ( $form->{rowcount} ) {
+ print qq|
+<button class="submit" type="submit" name="action" value="generate_sales_orders">|
+ . $locale->text('Generate Sales Orders')
+ . qq|</button>|;
- print qq|
-<button class="submit" type="submit" name="action" value="select_customer">|.$locale->text('Select Customer').qq|</button>|;
+ print qq|
+<button class="submit" type="submit" name="action" value="select_customer">|
+ . $locale->text('Select Customer')
+ . qq|</button>|;
- }
+ }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -2420,20 +2779,22 @@ sub jcitems {
}
-
sub select_customer {
- for (1 .. $form->{rowcount}) {
- last if ($ok = $form->{"ndx_$_"});
- }
+ for ( 1 .. $form->{rowcount} ) {
+ last if ( $ok = $form->{"ndx_$_"} );
+ }
- $form->error($locale->text('Nothing selected!')) unless $ok;
+ $form->error( $locale->text('Nothing selected!') ) unless $ok;
- $label = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor');
-
- $form->header;
+ $label =
+ ( $form->{vc} eq 'customer' )
+ ? $locale->text('Customer')
+ : $locale->text('Vendor');
- print qq|
+ $form->header;
+
+ print qq|
<body onLoad="document.forms[0].$form->{vc}.focus()" />
<form method=post action=$form->{script}>
@@ -2442,18 +2803,20 @@ sub select_customer {
|;
- $form->{nextsub} = "$form->{vc}_selected";
- $form->{action} = "$form->{vc}_selected";
+ $form->{nextsub} = "$form->{vc}_selected";
+ $form->{action} = "$form->{vc}_selected";
- $form->hide_form;
+ $form->hide_form;
- print qq|
-<button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+ print qq|
+<button class="submit" type="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
|;
- print qq|
+ print qq|
</body>
</html>
@@ -2461,112 +2824,126 @@ sub select_customer {
}
-
sub customer_selected {
- if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{startdate})) > 1) {
- &select_name($form->{vc});
- exit;
- }
+ if (
+ (
+ $rv = $form->get_name( \%myconfig, $form->{vc}, $form->{startdate} )
+ ) > 1
+ )
+ {
+ &select_name( $form->{vc} );
+ exit;
+ }
- if ($rv == 1) {
- $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
- $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
- } else {
- $msg = ($form->{vc} eq 'customer') ? $locale->text('Customer not on file!') : $locale->text('Vendor not on file!');
- $form->error($locale->text($msg));
- }
+ if ( $rv == 1 ) {
+ $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
+ $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
+ }
+ else {
+ $msg =
+ ( $form->{vc} eq 'customer' )
+ ? $locale->text('Customer not on file!')
+ : $locale->text('Vendor not on file!');
+ $form->error( $locale->text($msg) );
+ }
- &display_form;
-
-}
+ &display_form;
+}
sub sales_order_header {
-
- for (1 .. $form->{rowcount}) {
- if ($form->{"ndx_$_"}) {
- $form->{"$form->{vc}_id_$_"} = $form->{"$form->{vc}_id"};
- $form->{"$form->{vc}_$_"} = $form->{"$form->{vc}"};
+
+ for ( 1 .. $form->{rowcount} ) {
+ if ( $form->{"ndx_$_"} ) {
+ $form->{"$form->{vc}_id_$_"} = $form->{"$form->{vc}_id"};
+ $form->{"$form->{vc}_$_"} = $form->{"$form->{vc}"};
+ }
}
- }
-
+
}
sub sales_order_footer { &jcitems }
-
sub generate_sales_orders {
- for $i (1 .. $form->{rowcount}) {
- $form->error($locale->text('Customer missing!')) if ($form->{"checked_$i"} && !$form->{"customer_$i"});
- }
-
- for $i (1 .. $form->{rowcount}) {
- if ($form->{"checked_$i"}) {
- push @{ $form->{order}{qq|$form->{"customer_id_$i"}|} }, {
- partnumber => $form->{"partnumber_$i"},
- id => $form->{"parts_id_$i"},
- description => $form->{"description_$i"},
- qty => $form->{"qty_$i"},
- sellprice => $form->{"sellprice_$i"},
- projectnumber => qq|--$form->{"project_id_$i"}|,
- reqdate => $form->{"transdate_$i"},
- taxaccounts => $form->{"taxaccounts_$i"},
- jcitems => $form->{"id_$i"},
- notes => $form->{"notes_$i"},
- }
- }
- }
-
- $order = new Form;
- $order->{dbh} = $form->{dbh};
- for (keys %{ $form->{order} }) {
-
- for (qw(type vc defaultcurrency login)) { $order->{$_} = $form->{$_} }
- for (split / /, $form->{taxaccounts}) { $order->{"${_}_rate"} = $form->{"${_}_rate"} }
+ for $i ( 1 .. $form->{rowcount} ) {
+ $form->error( $locale->text('Customer missing!') )
+ if ( $form->{"checked_$i"} && !$form->{"customer_$i"} );
+ }
- $i = 0;
- $order->{"$order->{vc}_id"} = $_;
-
- AA->get_name(\%myconfig, \%$order);
-
- foreach $ref (@ {$form->{order}{$_} }) {
- $i++;
-
- for (keys %$ref) { $order->{"${_}_$i"} = $ref->{$_} }
-
- $taxaccounts = "";
- for (split / /, $order->{taxaccounts}) { $taxaccounts .= qq|$_ | if ($_ =~ /$order->{"taxaccounts_$i"}/) }
- $order->{"taxaccounts_$i"} = $taxaccounts;
-
- }
- $order->{rowcount} = $i;
-
- for (qw(currency)) { $order->{$_} = $form->{$_} }
+ for $i ( 1 .. $form->{rowcount} ) {
+ if ( $form->{"checked_$i"} ) {
+ push @{ $form->{order}{qq|$form->{"customer_id_$i"}|} },
+ {
+ partnumber => $form->{"partnumber_$i"},
+ id => $form->{"parts_id_$i"},
+ description => $form->{"description_$i"},
+ qty => $form->{"qty_$i"},
+ sellprice => $form->{"sellprice_$i"},
+ projectnumber => qq|--$form->{"project_id_$i"}|,
+ reqdate => $form->{"transdate_$i"},
+ taxaccounts => $form->{"taxaccounts_$i"},
+ jcitems => $form->{"id_$i"},
+ notes => $form->{"notes_$i"},
+ };
+ }
+ }
- $order->{ordnumber} = $order->update_defaults(\%myconfig, 'sonumber');
- $order->{transdate} = $order->current_date(\%myconfig);
- $order->{reqdate} = $order->{transdate};
-
- for (qw(intnotes employee employee_id)) { delete $order->{$_} }
+ $order = new Form;
+ $order->{dbh} = $form->{dbh};
+ for ( keys %{ $form->{order} } ) {
- PE->timecard_get_currency(\%$order);
-
- if (OE->save(\%myconfig, \%$order)) {
- if (! PE->allocate_projectitems(\%myconfig, \%$order)) {
- OE->delete(\%myconfig, \%$order, ${LedgerSMB::Sysconfig::spool});
- }
- } else {
- $order->error($locale->text('Failed to save order!'));
- }
+ for (qw(type vc defaultcurrency login)) { $order->{$_} = $form->{$_} }
+ for ( split / /, $form->{taxaccounts} ) {
+ $order->{"${_}_rate"} = $form->{"${_}_rate"};
+ }
- for (keys %$order) { delete $order->{$_} }
+ $i = 0;
+ $order->{"$order->{vc}_id"} = $_;
- }
+ AA->get_name( \%myconfig, \%$order );
- $form->redirect($locale->text('Orders generated!'));
+ foreach $ref ( @{ $form->{order}{$_} } ) {
+ $i++;
-}
+ for ( keys %$ref ) { $order->{"${_}_$i"} = $ref->{$_} }
+
+ $taxaccounts = "";
+ for ( split / /, $order->{taxaccounts} ) {
+ $taxaccounts .= qq|$_ |
+ if ( $_ =~ /$order->{"taxaccounts_$i"}/ );
+ }
+ $order->{"taxaccounts_$i"} = $taxaccounts;
+
+ }
+ $order->{rowcount} = $i;
+
+ for (qw(currency)) { $order->{$_} = $form->{$_} }
+
+ $order->{ordnumber} = $order->update_defaults( \%myconfig, 'sonumber' );
+ $order->{transdate} = $order->current_date( \%myconfig );
+ $order->{reqdate} = $order->{transdate};
+ for (qw(intnotes employee employee_id)) { delete $order->{$_} }
+
+ PE->timecard_get_currency( \%$order );
+
+ if ( OE->save( \%myconfig, \%$order ) ) {
+ if ( !PE->allocate_projectitems( \%myconfig, \%$order ) ) {
+ OE->delete( \%myconfig, \%$order,
+ ${LedgerSMB::Sysconfig::spool} );
+ }
+ }
+ else {
+ $order->error( $locale->text('Failed to save order!') );
+ }
+
+ for ( keys %$order ) { delete $order->{$_} }
+
+ }
+
+ $form->redirect( $locale->text('Orders generated!') );
+
+}
diff --git a/bin/pos.pl b/bin/pos.pl
index 8c28bf41..6492ad35 100644
--- a/bin/pos.pl
+++ b/bin/pos.pl
@@ -1,1096 +1,1245 @@
-#=====================================================================
-# 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 Error qw(:try);
-
-use LedgerSMB::Template;
-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, $_) }
-
-
- 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};
-
- if (($form->{'media'} eq 'screen') and ($form->{'format'} eq 'html')) {
- my $template = LedgerSMB::Template->new(\%myconfig, $form->{'formname'}, 'HTML');
- try {
- $template->render($form);
- $form->header;
- print $template->{'output'};
- exit;
- } catch Error::Simple with {
- my $E = shift;
- $form->error($E->stacktrace);
- };
- }
- $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->{my_partsgroup} =~ s/\r//;
- $form->{action} = $form->{my_partsgroup};
-
- 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 Error qw(:try);
+
+use LedgerSMB::Template;
+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, $_ );
+ }
+
+ 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};
+
+ if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
+ {
+ my $template =
+ LedgerSMB::Template->new( \%myconfig, $form->{'formname'}, 'HTML' );
+ try {
+ $template->render($form);
+ $form->header;
+ print $template->{'output'};
+ exit;
+ }
+ catch Error::Simple with {
+ my $E = shift;
+ $form->error( $E->stacktrace );
+ };
+ }
+ $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->{my_partsgroup} =~ s/\r//;
+ $form->{action} = $form->{my_partsgroup};
+
+ 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/ps.pl b/bin/ps.pl
index c9ba0c5c..1d6eec1c 100644
--- a/bin/ps.pl
+++ b/bin/ps.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -53,18 +53,19 @@ require "bin/pos.pl";
require "pos.conf.pl";
# customizations
-if (-f "bin/custom/pos.pl") {
- eval { require "bin/custom/pos.pl"; };
+if ( -f "bin/custom/pos.pl" ) {
+ eval { require "bin/custom/pos.pl"; };
}
-if (-f "bin/custom/$form->{login}_pos.pl") {
- eval { require "bin/custom/$form->{login}_pos.pl"; };
+if ( -f "bin/custom/$form->{login}_pos.pl" ) {
+ eval { require "bin/custom/$form->{login}_pos.pl"; };
}
# Necessary for Partsgroup lookups
-if ($form->{action} =~ s/^\s//){
- $form->{my_partsgroup} = $form->{action};
- $form->{action} = "lookup_partsgroup";
+if ( $form->{action} =~ s/^\s// ) {
+ $form->{my_partsgroup} = $form->{action};
+ $form->{action} = "lookup_partsgroup";
}
1;
+
# end
diff --git a/bin/pw.pl b/bin/pw.pl
index 9bb2c3ba..f03ed240 100644
--- a/bin/pw.pl
+++ b/bin/pw.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -35,17 +35,21 @@
#======================================================================
1;
-# end of main
+# end of main
sub getpassword {
- my ($s) = @_;
+ my ($s) = @_;
+
+ $form->{endsession} = 1;
- $form->{endsession} = 1;
+ $sessionexpired =
+ qq|<p><span style="font-weight:bold; color:red;">|
+ . $locale->text('Session expired!')
+ . qq|</span></p>|
+ if $s;
- $sessionexpired = qq|<p><span style="font-weight:bold; color:red;">|.$locale->text('Session expired!').qq|</span></p>| if $s;
-
- my $headeradd = qq|
+ my $headeradd = qq|
<script language="JavaScript" type="text/javascript">
<!--
function sf(){
@@ -54,8 +58,8 @@ function sf(){
// End -->
</script>|;
- $form->header(undef, $headeradd);
- print qq|
+ $form->header( undef, $headeradd );
+ print qq|
<body onload="sf()">
$sessionexpired
@@ -64,18 +68,20 @@ function sf(){
<table>
<tr>
- <th align=right>|.$locale->text('Password').qq|</th>
+ <th align=right>| . $locale->text('Password') . qq|</th>
<td><input type="password" name="password" size="30"></td>
- <td><button type="submit" value="continue">|.$locale->text('Continue').qq|</button></td>
+ <td><button type="submit" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button></td>
</tr>
</table>
|;
- for (qw(script endsession password)) { delete $form->{$_} }
- $form->hide_form;
-
- print qq|
+ for (qw(script endsession password)) { delete $form->{$_} }
+ $form->hide_form;
+
+ print qq|
</form>
</body>
@@ -84,4 +90,3 @@ function sf(){
}
-
diff --git a/bin/rc.pl b/bin/rc.pl
index 05d1f2f6..6428ff63 100644
--- a/bin/rc.pl
+++ b/bin/rc.pl
@@ -8,9 +8,9 @@
# 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,
+# 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):
@@ -41,6 +41,7 @@
use LedgerSMB::RC;
1;
+
# end of main
# this is for our long dates
@@ -71,56 +72,67 @@ use LedgerSMB::RC;
# $locale->text('Nov')
# $locale->text('Dec')
-
sub reconciliation {
-
- RC->paymentaccounts(\%myconfig, \%$form);
- $selection = "";
- for (@{ $form->{PR} }) { $selection .= "<option>$_->{accno}--$_->{description}\n" }
+ RC->paymentaccounts( \%myconfig, \%$form );
+
+ $selection = "";
+ for ( @{ $form->{PR} } ) {
+ $selection .= "<option>$_->{accno}--$_->{description}\n";
+ }
- $form->{title} = $locale->text('Reconciliation');
+ $form->{title} = $locale->text('Reconciliation');
- if ($form->{report}) {
- $form->{title} = $locale->text('Reconciliation Report');
- $cleared = qq|
+ if ( $form->{report} ) {
+ $form->{title} = $locale->text('Reconciliation Report');
+ $cleared = qq|
<input type=hidden name=report value=1>
<tr>
<td align=right><input type=checkbox class=checkbox name=outstanding value=1 checked></td>
- <td>|.$locale->text('Outstanding').qq|</td>
+ <td>| . $locale->text('Outstanding') . qq|</td>
<td align=right><input type=checkbox class=checkbox name=cleared value=1></td>
- <td>|.$locale->text('Cleared').qq|</td>
+ <td>| . $locale->text('Cleared') . qq|</td>
</tr>
|;
- }
-
- 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|
+ 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>
+ <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|
+ <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;
+ $form->header;
- print qq|
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -134,23 +146,30 @@ sub reconciliation {
<td>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Account').qq|</th>
+ <th align=right nowrap>| . $locale->text('Account') . qq|</th>
<td colspan=3><select name=accno>$selection</select></td>
</tr>
<tr>
- <th align=right>|.$locale->text('From').qq|</th>
- <td colspan=3><input name=fromdate size=11 title="$myconfig{dateformat}"> <b>|.$locale->text('To').qq|</b> <input name=todate size=11 title="$myconfig{dateformat}"></td>
+ <th align=right>| . $locale->text('From') . qq|</th>
+ <td colspan=3><input name=fromdate size=11 title="$myconfig{dateformat}"> <b>|
+ . $locale->text('To')
+ . qq|</b> <input name=todate size=11 title="$myconfig{dateformat}"></td>
</tr>
$selectfrom
$cleared
<tr>
<td></td>
- <td colspan=3><input type=radio style=radio name=summary value=1 checked> |.$locale->text('Summary').qq|
- <input type=radio style=radio name=summary value=0> |.$locale->text('Detail').qq|</td>
+ <td colspan=3><input type=radio style=radio name=summary value=1 checked> |
+ . $locale->text('Summary') . qq|
+ <input type=radio style=radio name=summary value=0> |
+ . $locale->text('Detail')
+ . qq|</td>
</tr>
<tr>
<td></td>
- <td colspan=3><input type=checkbox class=checkbox name=fx_transaction value=1 checked> |.$locale->text('Include Exchange Rate Difference').qq|</td>
+ <td colspan=3><input type=checkbox class=checkbox name=fx_transaction value=1 checked> |
+ . $locale->text('Include Exchange Rate Difference')
+ . qq|</td>
</tr>
</table>
</td>
@@ -164,20 +183,22 @@ sub reconciliation {
<input type=hidden name=nextsub value=get_payments>
|;
- $form->hide_form(qw(path login sessionid));
+ $form->hide_form(qw(path login sessionid));
- print qq|
-<button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
+ print qq|
+<button type="submit" class="submit" name="action" value="continue">|
+ . $locale->text('Continue')
+ . qq|</button>
</form>
|;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</body>
</html>
@@ -185,24 +206,24 @@ sub reconciliation {
}
-
-sub continue { &{ $form->{nextsub} } };
+sub continue { &{ $form->{nextsub} } }
sub till_closing {
- $form->{callback} = "$form->{script}?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
-
- # $locale->text("Source");
- # $locale->text("Actual");
- # $locale->text("Expected");
- # $locale->text("Error");
- @colheadings = qw(Source Actual Expected Error);
- my $curren = $pos_config{'curren'};
-
- $form->{title} = $locale->text("Closing Till For [_1]", $form->{login});
- require "pos.conf.pl";
- RC->getposlines(\%myconfig, \%$form);
- $form->header;
- print qq|
+ $form->{callback} =
+"$form->{script}?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+
+ # $locale->text("Source");
+ # $locale->text("Actual");
+ # $locale->text("Expected");
+ # $locale->text("Error");
+ @colheadings = qw(Source Actual Expected Error);
+ my $curren = $pos_config{'curren'};
+
+ $form->{title} = $locale->text( "Closing Till For [_1]", $form->{login} );
+ require "pos.conf.pl";
+ RC->getposlines( \%myconfig, \%$form );
+ $form->header;
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -211,7 +232,7 @@ sub till_closing {
<input type=hidden name=sessionid value=$form->{sessionid}>
<input type=hidden name=callback value="$form->{callback}">
-<input type=hidden name=sum value="|.$form->{sum} * -1 .qq|">
+<input type=hidden name=sum value="| . $form->{sum} * -1 . qq|">
<table width=100%>
<tr>
<th class=listtop>$form->{title}</th>
@@ -220,29 +241,30 @@ sub till_closing {
<table width=100%>
|;
- print "<tr>";
- map {print "<td class=listheading>".$locale->text($_)."</td>";} @colheadings;
- print "</tr>";
- my $j;
- my $source;
- foreach $source (sort keys %pos_sources){
- $amount = 0;
- foreach $ref (@{$form->{TB}}){
- if ($ref->{source} eq $source){
- $amount = $ref->{amount} * -1;
- last;
- }
- }
- ++$j;
- $j = $j % 2;
- print qq|<tr class=listrow$j><td>|.$pos_sources{$source}.qq|</td>
+ print "<tr>";
+ map { print "<td class=listheading>" . $locale->text($_) . "</td>"; }
+ @colheadings;
+ print "</tr>";
+ my $j;
+ my $source;
+ foreach $source ( sort keys %pos_sources ) {
+ $amount = 0;
+ foreach $ref ( @{ $form->{TB} } ) {
+ if ( $ref->{source} eq $source ) {
+ $amount = $ref->{amount} * -1;
+ last;
+ }
+ }
+ ++$j;
+ $j = $j % 2;
+ print qq|<tr class=listrow$j><td>| . $pos_sources{$source} . qq|</td>
<td><input name="amount_$source">
<input type=hidden name="expected_$source"
value="$amount"></td>
<td>${curren}$amount</td>
<td id="error_$source">&nbsp;</td></tr>|;
- }
- print qq|
+ }
+ print qq|
<script type='text/javascript'>
function money_round(m){
@@ -253,26 +275,27 @@ function money_round(m){
function custom_calc_total(){
|;
- my $subgen = 'document.forms[0].sub_sub.value = ';
- my $toround = '';
- foreach my $unit (@{$pos_config{'breakdown'}}) {
- # XXX Needs to take into account currencies that don't use 2 dp
- my $parsed = $form->parse_amount(\%pos_config, $unit);
- my $calcval = $parsed;
- $calcval = sprintf('%03d', $calcval * 100) if $calcval < 1;
- my $subval = 'sub_' . $calcval;
- $calcval = 'calc_' . $calcval;
- print qq|
+ my $subgen = 'document.forms[0].sub_sub.value = ';
+ my $toround = '';
+ foreach my $unit ( @{ $pos_config{'breakdown'} } ) {
+
+ # XXX Needs to take into account currencies that don't use 2 dp
+ my $parsed = $form->parse_amount( \%pos_config, $unit );
+ my $calcval = $parsed;
+ $calcval = sprintf( '%03d', $calcval * 100 ) if $calcval < 1;
+ my $subval = 'sub_' . $calcval;
+ $calcval = 'calc_' . $calcval;
+ print qq|
document.forms[0].${subval}.value = document.forms[0].${calcval}.value * $parsed;
|;
- $subgen .= "document.forms[0].${subval}.value * 1 + ";
- $toround .= qq|
+ $subgen .= "document.forms[0].${subval}.value * 1 + ";
+ $toround .= qq|
document.forms[0].${subval}.value =
money_round(document.forms[0].${subval}.value); |;
- }
- print $subgen . "0;";
- print $toround;
- print qq|document.forms[0].sub_sub.value =
+ }
+ print $subgen . "0;";
+ print $toround;
+ print qq|document.forms[0].sub_sub.value =
money_round(document.forms[0].sub_sub.value);
document.forms[0].amount_cash.value = money_round(
document.forms[0].sub_sub.value - $pos_config{till_cash});
@@ -283,45 +306,49 @@ function check_errors(){
var source_error = 0;
var err_cell;
|;
- map {
- print " source_error = money_round(
+ map {
+ print " source_error = money_round(
document.forms[0].amount_$_.value -
document.forms[0].expected_$_.value);
cumulative_error = cumulative_error + source_error;
err_cell = document.getElementById('error_$_');
- err_cell.innerHTML = '$curren' + source_error;\n";
- } (keys %pos_sources);
- print qq|
- alert('|.$locale->text('Cumulative Error:').qq| $curren' + money_round(cumulative_error));
+ err_cell.innerHTML = '$curren' + source_error;\n";
+ } ( keys %pos_sources );
+ print qq|
+ alert('|
+ . $locale->text('Cumulative Error:')
+ . qq| $curren' + money_round(cumulative_error));
}
</script>
<table>
<col><col><col>|;
- foreach my $unit (@{$pos_config{'breakdown'}}) {
- # XXX Needs to take into account currencies that don't use 2 dp
- my $calcval = $form->parse_amount(\%pos_config, $unit);
- $calcval = sprintf('%03d', $calcval * 100) if $calcval < 1;
- my $subval = 'sub_' . $calcval;
- $calcval = 'calc_' . $calcval;
- print qq|<tr>
+ foreach my $unit ( @{ $pos_config{'breakdown'} } ) {
+
+ # XXX Needs to take into account currencies that don't use 2 dp
+ my $calcval = $form->parse_amount( \%pos_config, $unit );
+ $calcval = sprintf( '%03d', $calcval * 100 ) if $calcval < 1;
+ my $subval = 'sub_' . $calcval;
+ $calcval = 'calc_' . $calcval;
+ print qq|<tr>
<td><input type=text name=$calcval value="$form->{$calcval}"></td>
<th>X ${curren}${unit} = </th>
<td><input type="text" name="$subval" value="$form->{$subval}"></td>
</tr>|;
- }
- print qq|<tr>
+ }
+ print qq|<tr>
<td>&nbsp;</td>
- <th>|.$locale->text("Subtotal").qq|:</th>
+ <th>| . $locale->text("Subtotal") . qq|:</th>
<td><input type=text name=sub_sub value="$form->{sub_sub}"></td>
</tr>
</table>
<input type=button name=calculate class=submit onClick="custom_calc_total()"
- value='|.$locale->text('Calculate').qq|'>
+ value='| . $locale->text('Calculate') . qq|'>
|;
- print qq|</table><button type="submit" name="action" value="close_till">|.
- $locale->text("Close Till").qq|</button>|;
- print qq|
+ print qq|</table><button type="submit" name="action" value="close_till">|
+ . $locale->text("Close Till")
+ . qq|</button>|;
+ print qq|
</form>
</body>
@@ -329,166 +356,187 @@ function check_errors(){
|;
}
-
sub close_till {
- use LedgerSMB::GL;
- require 'pos.conf.pl';
- RC->clear_till(\%myconfig, \%$form);
- my $amount = 0;
- my $expected = 0;
- my $difference = 0;
- my $lines = '';
- $form->{rowcount} = 2;
- foreach $key (keys %pos_sources){
- $amount = 0;
- $expected = 0;
- $amount = $form->parse_amount(\%myconfig, $form->{"amount_$key"});
- $expected = $form->parse_amount(\%myconfig, $form->{"expected_$key"});
- $gl_entry = "Closing Till $pos_config{till} source = $key";
- $accno1 = $pos_config{till_accno};
- if (${$pos_config{'source_accno_override'}{$key}}){
- $accno2 = ${$pos_config{'source_accno_override'}{$key}};
- } else {
- $accno2 = $pos_config{'close_cash_accno'};
- }
- $form->{reference} = $gl_entry;
- $form->{accno_1} = $accno1;
- $form->{credit_1} = $amount;
- $form->{accno_2} = $accno2;
- $form->{debit_2} = $amount;
- $form->{transdate} = $form->current_date(\%myconfig);
- GL->post_transaction(\%myconfig, \%$form);
- delete $form->{id};
- $error = $amount - $expected;
- $difference += $error;
- $lines .= "Source: $key, Amount: $amount\nExpected: $expected. Error= $error\n\n";
- }
- $gl_entry = "Closing Till: $pos_config{till} Over/Under";
- $amount = $difference * -1;
- $form->{reference} = $gl_entry;
- $form->{accno_1} = $accno1;
- $form->{credit_1} = $amount;
- $form->{accno_2} = $pos_config{coa_prefix};
- $form->{debit_2} = $amount;
- $form->{transdate} = $form->current_date(\%myconfig);
- GL->post_transaction(\%myconfig, \%$form);
- delete $form->{id};
- $lines .= "Cumulative Error: $amount";
- $form->{accno} = $form->{accno_1};
- RC->getbalance(\%myconfig, \%$form);
- $amount = $form->{balance} * -1;
- $gl_entry = "Resetting Till: $pos_config{till}";
- $form->{reference} = $gl_entry;
- $form->{accno_1} = $accno1;
- $form->{credit_1} = $amount;
- $form->{accno_2} = $pos_config{coa_prefix};
- $form->{debit_2} = $amount;
- $form->{transdate} = $form->current_date(\%myconfig);
- GL->post_transaction(\%myconfig, \%$form);
- delete $form->{id};
-
- $head = "Closing Till $pos_config{till} for $form->{login}\n".
- "Date: $form->{transdate}\n\n\n";
- my @cashlines = [$locale->text("Cash Breakdown:")];
- foreach my $unit (@{$pos_config{'breakdown'}}) {
- # XXX Needs to take into account currencies that don't use 2 dp
- my $parsed = $form->parse_amount(\%pos_config, $unit);
- my $calcval = $parsed;
- $calcval = sprintf('%03d', $calcval * 100) if $calcval < 1;
- my $subval = 'sub_' . $calcval;
- $calcval = 'calc_' . $calcval;
- push @cashlines, "$form->{$calcval} x $parseval = $form->{$subval}";
- }
- push @cashlines, $locale->text("Total Cash in Drawer: [_1]",
- $form->{sub_sub});
- push @cashlines, $locale->text("Less Cash in Till At Start: [_1]",
- $form->{till_cash});
- push @cashlines, "\n";
- $cash = join ("\n", @cashlines);
- $foot = $locale->text("Cumulative Error: [_1]", $difference)."\n";
- $foot .= $locale->text('Reset Till By [_1]', $amount)."\n\n\n\n\n\n\n\n\n\n";
- open (PRN, "|-", ${LedgerSMB::Sysconfig::printer}{Printer});
- print PRN $head;
- print PRN $lines;
- print PRN $cash;
- print PRN $cash;
- print PRN $foot;
- close PRN;
- if ($difference > 0){
- $message = $locale->text("You are over by [_1]", $difference);
- } elsif ($difference < 0){
- $message = $locale->text("You are under by [_1]", $difference * -1);
- }
- else {
- $message = $local->text("Congratulations! Your till is exactly balanced.");
- }
- $form->info($message);
+ use LedgerSMB::GL;
+ require 'pos.conf.pl';
+ RC->clear_till( \%myconfig, \%$form );
+ my $amount = 0;
+ my $expected = 0;
+ my $difference = 0;
+ my $lines = '';
+ $form->{rowcount} = 2;
+
+ foreach $key ( keys %pos_sources ) {
+ $amount = 0;
+ $expected = 0;
+ $amount = $form->parse_amount( \%myconfig, $form->{"amount_$key"} );
+ $expected = $form->parse_amount( \%myconfig, $form->{"expected_$key"} );
+ $gl_entry = "Closing Till $pos_config{till} source = $key";
+ $accno1 = $pos_config{till_accno};
+ if ( ${ $pos_config{'source_accno_override'}{$key} } ) {
+ $accno2 = ${ $pos_config{'source_accno_override'}{$key} };
+ }
+ else {
+ $accno2 = $pos_config{'close_cash_accno'};
+ }
+ $form->{reference} = $gl_entry;
+ $form->{accno_1} = $accno1;
+ $form->{credit_1} = $amount;
+ $form->{accno_2} = $accno2;
+ $form->{debit_2} = $amount;
+ $form->{transdate} = $form->current_date( \%myconfig );
+ GL->post_transaction( \%myconfig, \%$form );
+ delete $form->{id};
+ $error = $amount - $expected;
+ $difference += $error;
+ $lines .=
+"Source: $key, Amount: $amount\nExpected: $expected. Error= $error\n\n";
+ }
+ $gl_entry = "Closing Till: $pos_config{till} Over/Under";
+ $amount = $difference * -1;
+ $form->{reference} = $gl_entry;
+ $form->{accno_1} = $accno1;
+ $form->{credit_1} = $amount;
+ $form->{accno_2} = $pos_config{coa_prefix};
+ $form->{debit_2} = $amount;
+ $form->{transdate} = $form->current_date( \%myconfig );
+ GL->post_transaction( \%myconfig, \%$form );
+ delete $form->{id};
+ $lines .= "Cumulative Error: $amount";
+ $form->{accno} = $form->{accno_1};
+ RC->getbalance( \%myconfig, \%$form );
+ $amount = $form->{balance} * -1;
+ $gl_entry = "Resetting Till: $pos_config{till}";
+ $form->{reference} = $gl_entry;
+ $form->{accno_1} = $accno1;
+ $form->{credit_1} = $amount;
+ $form->{accno_2} = $pos_config{coa_prefix};
+ $form->{debit_2} = $amount;
+ $form->{transdate} = $form->current_date( \%myconfig );
+ GL->post_transaction( \%myconfig, \%$form );
+ delete $form->{id};
+
+ $head =
+ "Closing Till $pos_config{till} for $form->{login}\n"
+ . "Date: $form->{transdate}\n\n\n";
+ my @cashlines = [ $locale->text("Cash Breakdown:") ];
+ foreach my $unit ( @{ $pos_config{'breakdown'} } ) {
+
+ # XXX Needs to take into account currencies that don't use 2 dp
+ my $parsed = $form->parse_amount( \%pos_config, $unit );
+ my $calcval = $parsed;
+ $calcval = sprintf( '%03d', $calcval * 100 ) if $calcval < 1;
+ my $subval = 'sub_' . $calcval;
+ $calcval = 'calc_' . $calcval;
+ push @cashlines, "$form->{$calcval} x $parseval = $form->{$subval}";
+ }
+ push @cashlines,
+ $locale->text( "Total Cash in Drawer: [_1]", $form->{sub_sub} );
+ push @cashlines,
+ $locale->text( "Less Cash in Till At Start: [_1]", $form->{till_cash} );
+ push @cashlines, "\n";
+ $cash = join( "\n", @cashlines );
+ $foot = $locale->text( "Cumulative Error: [_1]", $difference ) . "\n";
+ $foot .=
+ $locale->text( 'Reset Till By [_1]', $amount ) . "\n\n\n\n\n\n\n\n\n\n";
+ open( PRN, "|-", ${LedgerSMB::Sysconfig::printer}{Printer} );
+ print PRN $head;
+ print PRN $lines;
+ print PRN $cash;
+ print PRN $cash;
+ print PRN $foot;
+ close PRN;
+
+ if ( $difference > 0 ) {
+ $message = $locale->text( "You are over by [_1]", $difference );
+ }
+ elsif ( $difference < 0 ) {
+ $message = $locale->text( "You are under by [_1]", $difference * -1 );
+ }
+ else {
+ $message =
+ $local->text("Congratulations! Your till is exactly balanced.");
+ }
+ $form->info($message);
}
sub get_payments {
- ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
- if ($form->{'pos'}){
- require "pos.conf.pl";
- $form->{fromdate} = $form->current_date(\%myconfig);
- unless ($form->{source}){
- $form->{source} = (sort keys(%pos_sources))[0];
+ ( $form->{accno}, $form->{account} ) = split /--/, $form->{accno};
+ if ( $form->{'pos'} ) {
+ require "pos.conf.pl";
+ $form->{fromdate} = $form->current_date( \%myconfig );
+ unless ( $form->{source} ) {
+ $form->{source} = ( sort keys(%pos_sources) )[0];
+ }
+ if ( $form->{source} eq 'cash' ) {
+ $form->{summary} = "true";
+ }
+ else {
+ $form->{summary} = "";
+ }
+ $form->{accno} = $pos_config{'coa_prefix'} . "." . $pos_config{'till'};
+ $form->{account} = $form->{source};
}
- if ($form->{source} eq 'cash'){
- $form->{summary} = "true";
- } else {
- $form->{summary} = "";
+
+ RC->payment_transactions( \%myconfig, \%$form );
+
+ $ml = ( $form->{category} eq 'A' ) ? -1 : 1;
+ $form->{statementbalance} = $form->{endingbalance} * $ml;
+ if ( !$form->{fx_transaction} ) {
+ $form->{statementbalance} =
+ ( $form->{endingbalance} - $form->{fx_endingbalance} ) * $ml;
}
- $form->{accno} = $pos_config{'coa_prefix'} . "." . $pos_config{'till'};
- $form->{account} = $form->{source};
- }
-
- RC->payment_transactions(\%myconfig, \%$form);
-
- $ml = ($form->{category} eq 'A') ? -1 : 1;
- $form->{statementbalance} = $form->{endingbalance} * $ml;
- if (! $form->{fx_transaction}) {
- $form->{statementbalance} = ($form->{endingbalance} - $form->{fx_endingbalance}) * $ml;
- }
-
- $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
-
- &display_form;
-}
+ $form->{statementbalance} =
+ $form->format_amount( \%myconfig, $form->{statementbalance}, 2, 0 );
+ &display_form;
+
+}
sub display_form {
-
- if ($form->{report}) {
- @column_index = qw(transdate source name cleared debit credit);
- } else {
- @column_index = qw(transdate source name cleared debit credit balance);
- }
-
- $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;
- $column_header{source} = "<th class=listheading>".$locale->text('Source')."</a></th>";
- $column_header{name} = "<th class=listheading>".$locale->text('Description')."</a></th>";
- $column_header{transdate} = "<th class=listheading>".$locale->text('Date')."</a></th>";
-
- $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</a></th>";
- $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</a></th>";
- $column_header{balance} = "<th class=listheading>".$locale->text('Balance')."</a></th>";
-
- 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);
- }
-
- $form->{title} = "$form->{accno}--$form->{account}";
-
- $form->header;
-
- print qq|
+
+ if ( $form->{report} ) {
+ @column_index = qw(transdate source name cleared debit credit);
+ }
+ else {
+ @column_index = qw(transdate source name cleared debit credit balance);
+ }
+
+ $column_header{cleared} = qq|<th>| . $locale->text('R') . qq|</th>|;
+ $column_header{source} =
+ "<th class=listheading>" . $locale->text('Source') . "</a></th>";
+ $column_header{name} =
+ "<th class=listheading>" . $locale->text('Description') . "</a></th>";
+ $column_header{transdate} =
+ "<th class=listheading>" . $locale->text('Date') . "</a></th>";
+
+ $column_header{debit} =
+ "<th class=listheading>" . $locale->text('Debit') . "</a></th>";
+ $column_header{credit} =
+ "<th class=listheading>" . $locale->text('Credit') . "</a></th>";
+ $column_header{balance} =
+ "<th class=listheading>" . $locale->text('Balance') . "</a></th>";
+
+ 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 );
+ }
+
+ $form->{title} = "$form->{accno}--$form->{account}";
+
+ $form->header;
+
+ print qq|
<body>
<form method=post action=$form->{script}>
@@ -509,216 +557,249 @@ sub display_form {
<tr class=listheading>
|;
- for (@column_index) { print "\n$column_header{$_}" }
+ for (@column_index) { print "\n$column_header{$_}" }
- print qq|
+ print qq|
</tr>
|;
- $ml = ($form->{category} eq 'A') ? -1 : 1;
- $form->{beginningbalance} *= $ml;
- $form->{fx_balance} *= $ml;
-
- if (! $form->{fx_transaction}) {
- $form->{beginningbalance} -= $form->{fx_balance};
- }
- $balance = $form->{beginningbalance};
-
- $i = 0;
- $j = 0;
-
- for (qw(cleared transdate source debit credit)) { $column_data{$_} = "<td>&nbsp;</td>" }
-
- if (! $form->{report}) {
- $column_data{name} = qq|<td>|.$locale->text('Beginning Balance').qq|</td>|;
- $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
- print qq|
+ $ml = ( $form->{category} eq 'A' ) ? -1 : 1;
+ $form->{beginningbalance} *= $ml;
+ $form->{fx_balance} *= $ml;
+
+ if ( !$form->{fx_transaction} ) {
+ $form->{beginningbalance} -= $form->{fx_balance};
+ }
+ $balance = $form->{beginningbalance};
+
+ $i = 0;
+ $j = 0;
+
+ for (qw(cleared transdate source debit credit)) {
+ $column_data{$_} = "<td>&nbsp;</td>";
+ }
+
+ if ( !$form->{report} ) {
+ $column_data{name} =
+ qq|<td>| . $locale->text('Beginning Balance') . qq|</td>|;
+ $column_data{balance} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $balance, 2, 0 ) . "</td>";
+ print qq|
<tr class=listrow$j>
|;
- for (@column_index) { print "\n$column_data{$_}" }
+ for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ print qq|
</tr>
|;
- }
+ }
+ foreach $ref ( @{ $form->{PR} } ) {
- foreach $ref (@{ $form->{PR} }) {
+ $i++;
- $i++;
+ if ( !$form->{fx_transaction} ) {
+ next if $ref->{fx_transaction};
+ }
- if (! $form->{fx_transaction}) {
- next if $ref->{fx_transaction};
- }
+ $checked = ( $ref->{cleared} ) ? "checked" : "";
- $checked = ($ref->{cleared}) ? "checked" : "";
-
- %temp = ();
- if (!$ref->{fx_transaction}) {
- for (qw(name source transdate)) { $temp{$_} = $ref->{$_} }
- }
-
- $column_data{name} = "<td>";
- for (@{ $temp{name} }) { $column_data{name} .= "$_<br>" }
- $column_data{name} .= "</td>";
- $column_data{source} = qq|<td>$temp{source}&nbsp;</td>
+ %temp = ();
+ if ( !$ref->{fx_transaction} ) {
+ for (qw(name source transdate)) { $temp{$_} = $ref->{$_} }
+ }
+
+ $column_data{name} = "<td>";
+ for ( @{ $temp{name} } ) { $column_data{name} .= "$_<br>" }
+ $column_data{name} .= "</td>";
+ $column_data{source} = qq|<td>$temp{source}&nbsp;</td>
<input type=hidden name="id_$i" value=$ref->{id}>|;
-
- $column_data{debit} = "<td>&nbsp;</td>";
- $column_data{credit} = "<td>&nbsp;</td>";
-
- $balance += $ref->{amount} * $ml;
-
- if ($ref->{amount} < 0) {
-
- $totaldebits += $ref->{amount} * -1;
-
- $column_data{debit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount} * -1, 2, "&nbsp;")."</td>";
-
- } else {
-
- $totalcredits += $ref->{amount};
-
- $column_data{credit} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{amount}, 2, "&nbsp;")."</td>";
-
- }
-
- $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $balance, 2, 0)."</td>";
-
- if ($ref->{fx_transaction}) {
-
- $column_data{cleared} = ($clearfx) ? qq|<td align=center>*</td>| : qq|<td>&nbsp;</td>|;
- $cleared += $ref->{amount} * $ml if $clearfx;
-
- } else {
-
- if ($form->{report}) {
-
- if ($ref->{cleared}) {
- $column_data{cleared} = qq|<td align=center>*</td>|;
- $clearfx = 1;
- } else {
- $column_data{cleared} = qq|<td>&nbsp;</td>|;
- $clearfx = 0;
- }
-
- } else {
-
- if ($ref->{oldcleared}) {
- $cleared += $ref->{amount} * $ml;
- $clearfx = 1;
- $column_data{cleared} = qq|<td align=center>*</td>
+
+ $column_data{debit} = "<td>&nbsp;</td>";
+ $column_data{credit} = "<td>&nbsp;</td>";
+
+ $balance += $ref->{amount} * $ml;
+
+ if ( $ref->{amount} < 0 ) {
+
+ $totaldebits += $ref->{amount} * -1;
+
+ $column_data{debit} = "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{amount} * -1,
+ 2, "&nbsp;" )
+ . "</td>";
+
+ }
+ else {
+
+ $totalcredits += $ref->{amount};
+
+ $column_data{credit} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $ref->{amount}, 2, "&nbsp;" )
+ . "</td>";
+
+ }
+
+ $column_data{balance} =
+ "<td align=right>"
+ . $form->format_amount( \%myconfig, $balance, 2, 0 ) . "</td>";
+
+ if ( $ref->{fx_transaction} ) {
+
+ $column_data{cleared} =
+ ($clearfx) ? qq|<td align=center>*</td>| : qq|<td>&nbsp;</td>|;
+ $cleared += $ref->{amount} * $ml if $clearfx;
+
+ }
+ else {
+
+ if ( $form->{report} ) {
+
+ if ( $ref->{cleared} ) {
+ $column_data{cleared} = qq|<td align=center>*</td>|;
+ $clearfx = 1;
+ }
+ else {
+ $column_data{cleared} = qq|<td>&nbsp;</td>|;
+ $clearfx = 0;
+ }
+
+ }
+ else {
+
+ if ( $ref->{oldcleared} ) {
+ $cleared += $ref->{amount} * $ml;
+ $clearfx = 1;
+ $column_data{cleared} = qq|<td align=center>*</td>
<input type=hidden name="cleared_$i" value=$ref->{cleared}>
<input type=hidden name="oldcleared_$i" value=$ref->{oldcleared}>
<input type=hidden name="source_$i" value="$ref->{source}">
<input type=hidden name="amount_$1" value="$ref->{amount}">|;
- } else {
- $cleared += $ref->{amount} * $ml if $checked;
- $clearfx = ($checked) ? 1 : 0;
- $column_data{cleared} = qq|<td align=center><input name="cleared_$i" type=checkbox class=checkbox value=1 $checked>
+ }
+ else {
+ $cleared += $ref->{amount} * $ml if $checked;
+ $clearfx = ($checked) ? 1 : 0;
+ $column_data{cleared} =
+qq|<td align=center><input name="cleared_$i" type=checkbox class=checkbox value=1 $checked>
<input type=hidden name="source_$i" value="$ref->{source}">
<input type=hidden name="amount_$i" value="$ref->{amount}">
</td>|;
- }
-
- }
- }
-
- $column_data{transdate} = qq|<td>$temp{transdate}&nbsp;</td>
+ }
+
+ }
+ }
+
+ $column_data{transdate} = qq|<td>$temp{transdate}&nbsp;</td>
<input type=hidden name="transdate_$i" value=$ref->{transdate}>|;
- $j++; $j %= 2;
- print qq|
+ $j++;
+ $j %= 2;
+ print qq|
<tr class=listrow$j>
|;
- for (@column_index) { print "\n$column_data{$_}" }
+ for (@column_index) { print "\n$column_data{$_}" }
- print qq|
+ print qq|
</tr>
|;
- }
+ }
- $form->{rowcount} = $i;
-
- # print totals
- for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+ $form->{rowcount} = $i;
- $column_data{debit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totaldebits, 2, "&nbsp;")."</th>";
- $column_data{credit} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalcredits, 2, "&nbsp;")."</th>";
-
- print qq|
+ # print totals
+ for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
+
+ $column_data{debit} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totaldebits, 2, "&nbsp;" ) . "</th>";
+ $column_data{credit} =
+ "<th class=listtotal align=right>"
+ . $form->format_amount( \%myconfig, $totalcredits, 2, "&nbsp;" )
+ . "</th>";
+
+ print qq|
<tr class=listtotal>
|;
- for (@column_index) { print "\n$column_data{$_}" }
-
- $form->{statementbalance} = $form->parse_amount(\%myconfig, $form->{statementbalance});
- $difference = $form->format_amount(\%myconfig, $form->{beginningbalance} + $cleared - $form->{statementbalance}, 2, 0);
- if ($form->{source}){
- $difference = 0;
- }
- $form->{statementbalance} = $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
-
- print qq|
+ for (@column_index) { print "\n$column_data{$_}" }
+
+ $form->{statementbalance} =
+ $form->parse_amount( \%myconfig, $form->{statementbalance} );
+ $difference =
+ $form->format_amount( \%myconfig,
+ $form->{beginningbalance} + $cleared - $form->{statementbalance},
+ 2, 0 );
+ if ( $form->{source} ) {
+ $difference = 0;
+ }
+ $form->{statementbalance} =
+ $form->format_amount( \%myconfig, $form->{statementbalance}, 2, 0 );
+
+ print qq|
</tr>
</table>
</td>
</tr>
|;
- if ($form->{'pos'}){
- $close_next = qq|<button type="submit" class="submit" name="action"
- value="close_next">|.$locale->text('Close Next').qq|</button>|;
- $done = "";
- }
- else {
- $close_next = "";
- $done = qq|<button type="submit" class="submit" name="action"
- value="done">|.$locale->text('Done').qq|</button>|;
- }
- if ($form->{'pos'}){
- $difference = qq|
+ if ( $form->{'pos'} ) {
+ $close_next = qq|<button type="submit" class="submit" name="action"
+ value="close_next">| . $locale->text('Close Next') . qq|</button>|;
+ $done = "";
+ }
+ else {
+ $close_next = "";
+ $done = qq|<button type="submit" class="submit" name="action"
+ value="done">| . $locale->text('Done') . qq|</button>|;
+ }
+ if ( $form->{'pos'} ) {
+ $difference = qq|
<tr>
<th align=right><select name=over_under>
- <option value=under>|.$locale->text('Under').qq|</option>
- <option value=over>|.$locale->text('Over').qq|</option>
+ <option value=under>|
+ . $locale->text('Under')
+ . qq|</option>
+ <option value=over>| . $locale->text('Over') . qq|</option>
</select><input type=hidden name=pos value='true'>
</th>
<td width=10%></td>
<td align=right><input name=null size=11
- value='|.$form->{null2}.qq|'></td>
+ value='| . $form->{null2} . qq|'></td>
<input type=hidden name=difference
value=$difference>
|;
- if ($form->{'over_under'}){
- $o_u = $form->{'over_under'};
- $difference =~ s/(value=$o_u)/SELECTED $1/g;
+ if ( $form->{'over_under'} ) {
+ $o_u = $form->{'over_under'};
+ $difference =~ s/(value=$o_u)/SELECTED $1/g;
+ }
}
- } else {
- $difference = qq|
+ else {
+ $difference = qq|
<tr>
- <th align=right nowrap>|.$locale->text('Difference').qq|</th>
+ <th align=right nowrap>| . $locale->text('Difference') . qq|</th>
<td width=10%></td>
<td align=right><input name=null size=11 value=$difference></td>
<input type=hidden name=difference value=$difference>
</tr>|;
- }
-
-
- if ($form->{report}) {
+ }
- print qq|
+ if ( $form->{report} ) {
+
+ print qq|
</tr>
</table>
|;
- } else {
-
- print qq|
+ }
+ else {
+
+ print qq|
<tr>
<td>
@@ -727,7 +808,7 @@ sub display_form {
<td align=right>
<table>
<tr>
- <th align=right nowrap>|.$locale->text('Statement Balance').qq|</th>
+ <th align=right nowrap>| . $locale->text('Statement Balance') . qq|</th>
<td width=10%></td>
<td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
</tr>
@@ -744,22 +825,28 @@ sub display_form {
</table>
|;
- $form->hide_form(qw(fx_transaction summary rowcount accno account fromdate todate path login sessionid));
-
- print qq|
+ $form->hide_form(
+ qw(fx_transaction summary rowcount accno account fromdate todate path login sessionid)
+ );
+
+ print qq|
<br>
-<button type="submit" class="submit" name="action" value="update">|.$locale->text('Update').qq|</button>
-<button type="submit" class="submit" name="action" value="select_all">|.$locale->text('Select all').qq|</button>
+<button type="submit" class="submit" name="action" value="update">|
+ . $locale->text('Update')
+ . qq|</button>
+<button type="submit" class="submit" name="action" value="select_all">|
+ . $locale->text('Select all')
+ . qq|</button>
$done
$close_next |;
- }
+ }
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
+ if ( $form->{lynx} ) {
+ require "bin/menu.pl";
+ &menubar;
+ }
- print qq|
+ print qq|
</form>
</body>
@@ -768,43 +855,41 @@ sub display_form {
}
-
sub update {
- $form->{null2} = $form->{null};
-
- RC->payment_transactions(\%myconfig, \%$form);
-
- $i = 0;
- foreach $ref (@{ $form->{PR} }) {
- $i++;
- $ref->{cleared} = ($form->{"cleared_$i"}) ? 1 : 0;
- }
-
- &display_form;
-
-}
+ $form->{null2} = $form->{null};
+ RC->payment_transactions( \%myconfig, \%$form );
-sub select_all {
-
- RC->payment_transactions(\%myconfig, \%$form);
+ $i = 0;
+ foreach $ref ( @{ $form->{PR} } ) {
+ $i++;
+ $ref->{cleared} = ( $form->{"cleared_$i"} ) ? 1 : 0;
+ }
- for (@{ $form->{PR} }) { $_->{cleared} = 1 }
+ &display_form;
- &display_form;
-
}
+sub select_all {
-sub done {
+ RC->payment_transactions( \%myconfig, \%$form );
- $form->{callback} = "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&sessionid=$form->{sessionid}";
+ for ( @{ $form->{PR} } ) { $_->{cleared} = 1 }
- $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
+ &display_form;
- RC->reconcile(\%myconfig, \%$form);
- $form->redirect;
-
}
+sub done {
+
+ $form->{callback} =
+"$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&sessionid=$form->{sessionid}";
+
+ $form->error( $locale->text('Out of balance!') )
+ if ( $form->{difference} *= 1 );
+
+ RC->reconcile( \%myconfig, \%$form );
+ $form->redirect;
+
+}
diff --git a/bin/rp.pl b/bin/rp.pl
index 26f55dcf..a962ada1 100644
--- a/bin/rp.pl
+++ b/bin/rp.pl
@@ -1,2584 +1,2904 @@
-#=====================================================================
-# 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
-#
-#======================================================================
-
-use Error qw(:try);
-
-require "bin/arap.pl";
-
-use LedgerSMB::Template;
-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";
-
- if (($form->{'media'} eq 'screen') and ($form->{'format'} eq 'html')) {
- my $template = LedgerSMB::Template->new(\%myconfig, $form->{'formname'}, 'HTML');
- try {
- $template->render($form);
- $form->header;
- print $template->{'output'};
- exit;
- } catch Error::Simple with {
- my $E = shift;
- $form->error($E->stacktrace);
- };
- }
- $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};
-
- if (($form->{'media'} eq 'screen') and ($form->{'format'} eq 'html')) {
- my $template = LedgerSMB::Template->new(\%myconfig, $form->{'formname'}, 'HTML');
- try {
- $template->render($form);
- $form->header;
- print $template->{'output'};
- exit;
- } catch Error::Simple with {
- my $E = shift;
- $form->error($E->stacktrace);
- };
- }
- $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) }
-
- if (($form->{'media'} eq 'screen') and ($form->{'format'} eq 'html')) {
- my $template = LedgerSMB::Template->new(\%myconfig, $form->{'formname'}, 'HTML');
- try {
- $template->render($form);
- $form->header;
- print $template->{'output'};
- exit;
- } catch Error::Simple with {
- my $E = shift;
- $form->error($E->stacktrace);
- };
- }
- $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
+#
+#======================================================================
+
+use Error qw(:try);
+
+require "bin/arap.pl";
+
+use LedgerSMB::Template;
+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";
+
+ if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
+ {
+ my $template =
+ LedgerSMB::Template->new( \%myconfig, $form->{'formname'}, 'HTML' );
+ try {
+ $template->render($form);
+ $form->header;
+ print $template->{'output'};
+ exit;
+ }
+ catch Error::Simple with {
+ my $E = shift;
+ $form->error( $E->stacktrace );
+ };
+ }
+ $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};
+
+ if ( ( $form->{'media'} eq 'screen' ) and ( $form->{'format'} eq 'html' ) )
+ {
+ my $template =
+ LedgerSMB::Template->new( \%myconfig, $form->{'formname'}, 'HTML' );
+ try {
+ $template->render($form);
+ $form->header;
+ print $template->{'output'};
+ exit;
+ }
+ catch Error::Simple with {
+ my $E = shift;
+ $form->error( $E->stacktrace );
+ };
+ }
+ $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 );
+ }
+
+ if ( ( $form->{'media'} eq 'screen' )
+ and ( $form->{'format'} eq 'html' ) )
+ {
+ my $template =
+ LedgerSMB::Template->new( \%myconfig, $form->{'formname'},
+ 'HTML' );
+ try {
+ $template->render($form);
+ $form->header;
+ print $template->{'output'};
+ exit;
+ }
+ catch Error::Simple with {
+ my $E = shift;
+ $form->error( $E->stacktrace );
+ };
+ }
+ $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;
+
+}
+
diff --git a/common.pl b/common.pl
index 54dcb246..71026b0a 100644
--- a/common.pl
+++ b/common.pl
@@ -9,9 +9,9 @@
# 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,
+# 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.
#
#####################################################################
@@ -23,44 +23,47 @@
use LedgerSMB::Sysconfig;
sub redirect {
- use List::Util qw(first);
- my ($script, $argv) = split(/\?/, $form->{callback});
+ use List::Util qw(first);
+ my ( $script, $argv ) = split( /\?/, $form->{callback} );
- my @common_attrs = qw(
- dbh login favicon stylesheet titlebar password custom_db_fields
- );
+ my @common_attrs = qw(
+ dbh login favicon stylesheet titlebar password custom_db_fields
+ );
- if (!$script){ # http redirect to login.pl if called w/no args
- print "Location: login.pl\n";
- print "Content-type: text/html\n\n";
- exit;
- }
+ if ( !$script ) { # http redirect to login.pl if called w/no args
+ print "Location: login.pl\n";
+ print "Content-type: text/html\n\n";
+ exit;
+ }
- $form->error($locale->text(__FILE__.':'.__LINE__.':'.$script.':'."Invalid Redirect"))
- unless first {$_ eq $script} @{LedgerSMB::Sysconfig::scripts};
+ $form->error(
+ $locale->text(
+ __FILE__ . ':' . __LINE__ . ':' . $script . ':' . "Invalid Redirect"
+ )
+ ) unless first { $_ eq $script } @{LedgerSMB::Sysconfig::scripts};
- my %temphash;
- for (@common_attrs){
- $temphash{$_} = $form->{$_};
- }
+ my %temphash;
+ for (@common_attrs) {
+ $temphash{$_} = $form->{$_};
+ }
- undef $form;
- $form = new Form($argv);
- require "bin/$script";
+ undef $form;
+ $form = new Form($argv);
+ require "bin/$script";
- for (@common_attrs){
- $form->{$_} = $temphash{$_};
- }
- $form->{script} = $script;
+ for (@common_attrs) {
+ $form->{$_} = $temphash{$_};
+ }
+ $form->{script} = $script;
- if (!$myconfig){ # needed for login
- %myconfig = %{LedgerSMB::User->fetch_config($form->{login})};
- }
- if (!$form->{dbh} and ($script ne 'admin.pl')){
- $form->db_init(\%myconfig);
- }
+ if ( !$myconfig ) { # needed for login
+ %myconfig = %{ LedgerSMB::User->fetch_config( $form->{login} ) };
+ }
+ if ( !$form->{dbh} and ( $script ne 'admin.pl' ) ) {
+ $form->db_init( \%myconfig );
+ }
- &{$form->{action}};
+ &{ $form->{action} };
}
1;
diff --git a/custom.pl b/custom.pl
index 5f5cc799..18314c76 100644
--- a/custom.pl
+++ b/custom.pl
@@ -1,3 +1,3 @@
#Custom logic goes here.
-1; # End
+1; # End
diff --git a/dists/win32/shebang-activeperl.pl b/dists/win32/shebang-activeperl.pl
index a0621839..b3c6ac14 100644
--- a/dists/win32/shebang-activeperl.pl
+++ b/dists/win32/shebang-activeperl.pl
@@ -1,18 +1,18 @@
#!c:\perl\bin\perl
-# Use this script to convert the beginnings of files to the path to ActivePerl
+# Use this script to convert the beginnings of files to the path to ActivePerl
# if you are installing with ActivePerl.
- opendir DIR, ".";
- @perlfiles = grep /\.pl/, readdir DIR;
- closedir DIR;
+opendir DIR, ".";
+@perlfiles = grep /\.pl/, readdir DIR;
+closedir DIR;
- foreach $file (@perlfiles) {
+foreach $file (@perlfiles) {
open FH, '+<', "$file";
-
+
@file = <FH>;
- seek(FH, 0, 0);
- truncate(FH, 0);
+ seek( FH, 0, 0 );
+ truncate( FH, 0 );
$line = shift @file;
@@ -20,5 +20,5 @@
print FH @file;
close(FH);
-
- }
+
+}
diff --git a/dists/win32/shebang-vanilla.pl b/dists/win32/shebang-vanilla.pl
index 9921a723..6c8a5c95 100644
--- a/dists/win32/shebang-vanilla.pl
+++ b/dists/win32/shebang-vanilla.pl
@@ -1,18 +1,18 @@
#!c:\vanilla-perl\perl\bin\perl
-# Use this script to convert the beginnings of files to the path to ActivePerl
+# Use this script to convert the beginnings of files to the path to ActivePerl
# if you are installing with Vanilla Perl.
- opendir DIR, ".";
- @perlfiles = grep /\.pl/, readdir DIR;
- closedir DIR;
+opendir DIR, ".";
+@perlfiles = grep /\.pl/, readdir DIR;
+closedir DIR;
- foreach $file (@perlfiles) {
+foreach $file (@perlfiles) {
open FH, '+<', "$file";
-
+
@file = <FH>;
- seek(FH, 0, 0);
- truncate(FH, 0);
+ seek( FH, 0, 0 );
+ truncate( FH, 0 );
$line = shift @file;
@@ -20,5 +20,5 @@
print FH @file;
close(FH);
-
- }
+
+}
diff --git a/dists/win32/wix/uuidgen.pl b/dists/win32/wix/uuidgen.pl
index 3713739f..fceb004f 100644
--- a/dists/win32/wix/uuidgen.pl
+++ b/dists/win32/wix/uuidgen.pl
@@ -1,5 +1,5 @@
-use Data::UUID;
-$ug = new Data::UUID;
-$uuid = $ug->create();
-print $ug->to_string($uuid);
-print "\n"; \ No newline at end of file
+use Data::UUID;
+$ug = new Data::UUID;
+$uuid = $ug->create();
+print $ug->to_string($uuid);
+print "\n";
diff --git a/doc/samples/lsmb02-cli-example.pl b/doc/samples/lsmb02-cli-example.pl
index e0084c01..2aa2657e 100644
--- a/doc/samples/lsmb02-cli-example.pl
+++ b/doc/samples/lsmb02-cli-example.pl
@@ -28,12 +28,10 @@
use File::chdir;
use HTML::Entities;
-
print "\n\nLedger-SMB login: ";
my $login = <STDIN>;
chomp($login);
-
print "\nLedger-SMB password: ";
system("stty -echo");
my $pwd = <STDIN>;
@@ -43,56 +41,68 @@ print "\n\n";
$cmd = "login=" . $login . '&password=' . $pwd . '&path=bin&action=login';
-$signin = runLScmd("./login.pl",$cmd);
+$signin = runLScmd( "./login.pl", $cmd );
if ( $signin =~ m/Error:/ ) {
- print "\nLogin error\n";
- exit;
+ print "\nLogin error\n";
+ exit;
}
-
while (<main::DATA>) {
- chomp;
- @rec = split(/\|/);
-
- $arg = 'path=bin/mozilla&login=' . $login . '&password=' . $pwd .
- '&action=' . escape(substr($rec[0],0,35)) .
- '&db=' . $rec[1] .
- '&name=' . escape(substr($rec[2],0,35)) .
- '&vendornumber=' . $rec[3] .
- '&address1=' . escape(substr($rec[4],0,35)) .
- '&address2=' . escape(substr($rec[5],0,35)) .
- '&city=' . escape(substr($rec[6],0,35)) .
- '&state=' . escape(substr($rec[7],0,35)) .
- '&zipcode=' . escape(substr($rec[8],0,35)) .
- '&country=' . escape(substr($rec[9],0,35)) .
- '&phone=' . escape(substr($rec[10],0,20)) .
- '&tax_2150=1' .
- '&taxaccounts=2150' .
- '&taxincluded=0' .
- '&terms=0';
-
- $rc=runLScmd("./ct.pl",$arg);
-
- if ($rc =~ m/Vendor saved!/) {
-
- print "$rec[2] SAVED\n";
+ chomp;
+ @rec = split(/\|/);
+
+ $arg =
+ 'path=bin/mozilla&login=' . $login
+ . '&password='
+ . $pwd
+ . '&action='
+ . escape( substr( $rec[0], 0, 35 ) ) . '&db='
+ . $rec[1]
+ . '&name='
+ . escape( substr( $rec[2], 0, 35 ) )
+ . '&vendornumber='
+ . $rec[3]
+ . '&address1='
+ . escape( substr( $rec[4], 0, 35 ) )
+ . '&address2='
+ . escape( substr( $rec[5], 0, 35 ) )
+ . '&city='
+ . escape( substr( $rec[6], 0, 35 ) )
+ . '&state='
+ . escape( substr( $rec[7], 0, 35 ) )
+ . '&zipcode='
+ . escape( substr( $rec[8], 0, 35 ) )
+ . '&country='
+ . escape( substr( $rec[9], 0, 35 ) )
+ . '&phone='
+ . escape( substr( $rec[10], 0, 20 ) )
+ . '&tax_2150=1'
+ . '&taxaccounts=2150'
+ . '&taxincluded=0'
+ . '&terms=0';
+
+ $rc = runLScmd( "./ct.pl", $arg );
+
+ if ( $rc =~ m/Vendor saved!/ ) {
+
+ print "$rec[2] SAVED\n";
- } else {
+ }
+ else {
- print "$rec[2] ERROR\n";
+ print "$rec[2] ERROR\n";
- }
+ }
}
-
$cmd = "login=" . $login . '&password=' . $pwd . '&path=bin&action=logout';
-$signin = runLScmd("./login.pl",$cmd);
+$signin = runLScmd( "./login.pl", $cmd );
if ( $signin =~ m/Error:/ ) {
@@ -102,12 +112,10 @@ if ( $signin =~ m/Error:/ ) {
exit;
-
#*******************************************************
# Subroutines
#*******************************************************
-
sub runLScmd {
my $cmd = shift;
@@ -131,15 +139,14 @@ sub escape {
if ($str) {
- decode_entities($str);
- $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
+ decode_entities($str);
+ $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
}
return $str;
}
-
#*******************************************************
# Record Format
#*******************************************************
diff --git a/drivers/pd3000.pl b/drivers/pd3000.pl
index a73ae932..a621a3ac 100644
--- a/drivers/pd3000.pl
+++ b/drivers/pd3000.pl
@@ -8,16 +8,16 @@
# 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,
+# 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.
# Driver for Logic Controls PD-3000 Pole Display.
# As with all pole display drivers, the control codes are contained in a hash
# array called $pd_control.
# THis pole display uses separate meanings for LF and CR. Both are included.
-# LF moves the cursor to the other line (same position), while CR moves the
+# LF moves the cursor to the other line (same position), while CR moves the
# cursor to the left-most spot (same line). Assume most PD's do this.
# Most of this is simple ASCII, but what to make things clear.
@@ -25,23 +25,23 @@
# Not including the bit about installing fonts.
%pd_control = (
- 'mode_vscroll' => pack('C', 18),
- 'mode_normal' => pack('C', 17),
- 'bright_full' => pack('CC', 4, 0xFF),
- 'bright_high' => pack('CC', 4, 0x60),
- 'bright_med' => pack('CC', 4, 0x40),
- 'bright_low' => pack('CC', 4, 0x20),
- 'backspace' => pack('C', 8),
- 'htab' => pack('C', 9), # Functions like cursor movement
- 'lf' => pack('C', 0x0A),
- 'cr' => pack('C', 0x0D),
- 'digit_select' => pack('C', 0x10), # Pack followed by a number 0-39
- 'cursor_on' => pack('C', 0x13),
- 'cursor_off' => pack('C', 0x14),
- 'reset' => pack('C', 0x1F),
- 'scroll_message' => pack ('C', 0x05), # Followed by up to 45 chars.
+ 'mode_vscroll' => pack( 'C', 18 ),
+ 'mode_normal' => pack( 'C', 17 ),
+ 'bright_full' => pack( 'CC', 4, 0xFF ),
+ 'bright_high' => pack( 'CC', 4, 0x60 ),
+ 'bright_med' => pack( 'CC', 4, 0x40 ),
+ 'bright_low' => pack( 'CC', 4, 0x20 ),
+ 'backspace' => pack( 'C', 8 ),
+ 'htab' => pack( 'C', 9 ), # Functions like cursor movement
+ 'lf' => pack( 'C', 0x0A ),
+ 'cr' => pack( 'C', 0x0D ),
+ 'digit_select' => pack( 'C', 0x10 ), # Pack followed by a number 0-39
+ 'cursor_on' => pack( 'C', 0x13 ),
+ 'cursor_off' => pack( 'C', 0x14 ),
+ 'reset' => pack( 'C', 0x1F ),
+ 'scroll_message' => pack( 'C', 0x05 ), # Followed by up to 45 chars.
);
# A few more useful control sequences:
-$pd_control{'new_line'} = $pd_control{'cr'}.$pd_control{'lf'};
+$pd_control{'new_line'} = $pd_control{'cr'} . $pd_control{'lf'};
diff --git a/import_members.pl b/import_members.pl
index d9eb87ae..ba135d25 100755
--- a/import_members.pl
+++ b/import_members.pl
@@ -20,7 +20,7 @@
#
# http://lists.sourceforge.net/mailman/listinfo/ledger-smb-users
#
-# Other info on how to get help, including commercial support
+# Other info on how to get help, including commercial support
# can be found at:
#
# http://www.ledgersmb.org/help/
@@ -29,116 +29,127 @@ use LedgerSMB::User;
use LedgerSMB::Form;
use LedgerSMB::Sysconfig;
-if($ENV{HTTP_HOST}){
- print "Content-type: text/html\n\n";
- print "<html>\n";
- print "<strong>This script cannot be executed via http. You must run it via the command line.</strong>\n";
- print "</html>\n";
- exit;
+if ( $ENV{HTTP_HOST} ) {
+ print "Content-type: text/html\n\n";
+ print "<html>\n";
+ print
+"<strong>This script cannot be executed via http. You must run it via the command line.</strong>\n";
+ print "</html>\n";
+ exit;
}
my $membersfile = $ARGV[0];
-if (length($membersfile) < 2){
+if ( length($membersfile) < 2 ) {
print "\nUsage: import_members.pl path/to/members\n\n";
- print "You must supply the path to the members file. Default location\n";
- print "is users/members. In this case do this:\n\n";
- print " ./import_members.pl users/members\n\n";
- exit;
+ print "You must supply the path to the members file. Default location\n";
+ print "is users/members. In this case do this:\n\n";
+ print " ./import_members.pl users/members\n\n";
+ exit;
}
my @users = ();
-open(FH, '<', "$membersfile") || die ("Couldn't open members file!");
+open( FH, '<', "$membersfile" ) || die("Couldn't open members file!");
while (<FH>) {
- chop;
-
- if (/^\[.*\]/) {
- $login = $_;
- $login =~ s/(\[|\])//g;
-
- if($login eq 'admin'){
-
- print "\nIMPORT FAILED: User 'admin' was found.\n\n";
- print "Please change this user's name to something else. In LedgerSMB version 1.2, \n";
- print "'admin' is a reserved user for the administration of the entire system.\n";
- print "To change the user's name, find the line in the members file that looks \n";
- print "like [admin] and change 'admin' to something else (keep the '[' and ']').\n";
- print "Save the file and run this script again.\n\n";
- exit;
-
- } elsif($login ne 'root login'){
- push @users, $login;
- $member{$login}{'login'} = $login;
- }
- next;
- }
-
- if($login ne 'root login'){
- if( ($key, $value) = split /=/, $_, 2){
- if($key eq 'dbpasswd'){
- $member{$login}{$key} = unpack 'u', $value;
- } elsif($key eq 'password') {
- $member{$login}{'crypted_password'} = $value;
- } else {
- $member{$login}{$key} = $value;
- }
- }
- }
+ chop;
+
+ if (/^\[.*\]/) {
+ $login = $_;
+ $login =~ s/(\[|\])//g;
+
+ if ( $login eq 'admin' ) {
+
+ print "\nIMPORT FAILED: User 'admin' was found.\n\n";
+ print
+"Please change this user's name to something else. In LedgerSMB version 1.2, \n";
+ print
+"'admin' is a reserved user for the administration of the entire system.\n";
+ print
+"To change the user's name, find the line in the members file that looks \n";
+ print
+"like [admin] and change 'admin' to something else (keep the '[' and ']').\n";
+ print "Save the file and run this script again.\n\n";
+ exit;
+
+ }
+ elsif ( $login ne 'root login' ) {
+ push @users, $login;
+ $member{$login}{'login'} = $login;
+ }
+ next;
+ }
+
+ if ( $login ne 'root login' ) {
+ if ( ( $key, $value ) = split /=/, $_, 2 ) {
+ if ( $key eq 'dbpasswd' ) {
+ $member{$login}{$key} = unpack 'u', $value;
+ }
+ elsif ( $key eq 'password' ) {
+ $member{$login}{'crypted_password'} = $value;
+ }
+ else {
+ $member{$login}{$key} = $value;
+ }
+ }
+ }
}
close(FH);
print "\n\nParsing members file completed. Now trying to import user data.\n\n";
-
foreach (@users) {
- $myUser = $member{$_};
- &save_member($myUser);
- print "Import of user '$_' seems to have succeeded.\n";
+ $myUser = $member{$_};
+ &save_member($myUser);
+ print "Import of user '$_' seems to have succeeded.\n";
}
-print "\nSUCCESS! It seems that every user in the members file was imported!\n\n";
+print
+ "\nSUCCESS! It seems that every user in the members file was imported!\n\n";
sub save_member {
- # a slightly modified version of LegerSBM::User::save_member
- # with special handling of the password -> crypted_password
+ # a slightly modified version of LegerSBM::User::save_member
+ # with special handling of the password -> crypted_password
+
+ my ($self) = @_;
- my ($self) = @_;
+ # replace \r\n with \n
+ for (qw(address signature)) { $self->{$_} =~ s/\r?\n/\\n/g }
- # replace \r\n with \n
- for (qw(address signature)) { $self->{$_} =~ s/\r?\n/\\n/g }
+ # use central db
+ my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
- # use central db
- my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH};
+ #check to see if the user exists already
+ my $userCheck = $dbh->prepare("SELECT id FROM users WHERE username = ?");
+ $userCheck->execute( $self->{login} );
+ my ($userID) = $userCheck->fetchrow_array;
- #check to see if the user exists already
- my $userCheck = $dbh->prepare("SELECT id FROM users WHERE username = ?");
- $userCheck->execute($self->{login});
- my ($userID) = $userCheck->fetchrow_array;
+ if ($userID) {
- if($userID){
- #got an id, check to see if it's in the users_conf table
- my $userConfCheck = $dbh->prepare("SELECT count(*) FROM users_conf WHERE id = ?");
- $userConfCheck->execute($userID);
+ #got an id, check to see if it's in the users_conf table
+ my $userConfCheck =
+ $dbh->prepare("SELECT count(*) FROM users_conf WHERE id = ?");
+ $userConfCheck->execute($userID);
- ($userConfExists) = $userConfCheck->fetchrow_array;
- }
- else{
- my $userConfAdd = $dbh->prepare("SELECT create_user(?);");
- $userConfAdd->execute($self->{login});
- ($userID) = $userConfAdd->fetchrow_array;
- }
+ ($userConfExists) = $userConfCheck->fetchrow_array;
+ }
+ else {
+ my $userConfAdd = $dbh->prepare("SELECT create_user(?);");
+ $userConfAdd->execute( $self->{login} );
+ ($userID) = $userConfAdd->fetchrow_array;
+ }
- if($userConfExists){
+ if ($userConfExists) {
- my $userConfUpdate = $dbh->prepare("UPDATE users_conf
+ my $userConfUpdate = $dbh->prepare(
+ "UPDATE users_conf
SET acs = ?, address = ?, businessnumber = ?,
company = ?, countrycode = ?, currency = ?,
dateformat = ?, dbdriver = ?,
@@ -150,25 +161,33 @@ sub save_member {
sid = ?, signature = ?, stylesheet = ?,
tel = ?, templates = ?, timeout = ?,
vclimit = ?
- WHERE id = ?;");
-
- $userConfUpdate->execute($self->{acs}, $self->{address}, $self->{businessnumber},
- $self->{company}, $self->{countrycode}, $self->{currency},
- $self->{dateformat}, $self->{dbdriver},
- $self->{dbhost}, $self->{dbname}, $self->{dboptions},
- $self->{dbpasswd}, $self->{dbport}, $self->{dbuser},
- $self->{email}, $self->{fax}, $self->{menuwidth},
- $self->{name}, $self->{numberformat}, $self->{crypted_password},
- $self->{print}, $self->{printer}, $self->{role},
- $self->{sid}, $self->{signature}, $self->{stylesheet},
- $self->{tel}, $self->{templates}, $self->{timeout},
- $self->{vclimit}, $userID);
-
-
- }
- else{
-
- my $userConfInsert = $dbh->prepare("INSERT INTO users_conf(acs, address, businessnumber,
+ WHERE id = ?;"
+ );
+
+ $userConfUpdate->execute(
+ $self->{acs}, $self->{address},
+ $self->{businessnumber}, $self->{company},
+ $self->{countrycode}, $self->{currency},
+ $self->{dateformat}, $self->{dbdriver},
+ $self->{dbhost}, $self->{dbname},
+ $self->{dboptions}, $self->{dbpasswd},
+ $self->{dbport}, $self->{dbuser},
+ $self->{email}, $self->{fax},
+ $self->{menuwidth}, $self->{name},
+ $self->{numberformat}, $self->{crypted_password},
+ $self->{print}, $self->{printer},
+ $self->{role}, $self->{sid},
+ $self->{signature}, $self->{stylesheet},
+ $self->{tel}, $self->{templates},
+ $self->{timeout}, $self->{vclimit},
+ $userID
+ );
+
+ }
+ else {
+
+ my $userConfInsert = $dbh->prepare(
+ "INSERT INTO users_conf(acs, address, businessnumber,
company, countrycode, currency,
dateformat, dbdriver,
dbhost, dbname, dboptions, dbpasswd,
@@ -178,74 +197,85 @@ sub save_member {
timeout, vclimit, id, crypted_password)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
- ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
-
- $userConfInsert->execute($self->{acs}, $self->{address}, $self->{businessnumber},
- $self->{company}, $self->{countrycode}, $self->{currency},
- $self->{dateformat}, $self->{dbdriver},
- $self->{dbhost}, $self->{dbname}, $self->{dboptions},
- $self->{dbpasswd}, $self->{dbport}, $self->{dbuser},
- $self->{email}, $self->{fax}, $self->{menuwidth},
- $self->{name}, $self->{numberformat},
- $self->{print}, $self->{printer}, $self->{role},
- $self->{sid}, $self->{signature}, $self->{stylesheet},
- $self->{tel}, $self->{templates}, $self->{timeout},
- $self->{vclimit}, $userID, $self->{crypted_password});
-
- }
-
- if (! $self->{'admin'}) {
-
- $self->{dbpasswd} =~ s/\\'/'/g;
- $self->{dbpasswd} =~ s/\\\\/\\/g;
-
- # format dbconnect and dboptions string
- LedgerSMB::User::dbconnect_vars($self, $self->{dbname});
-
- # check if login is in database
- my $dbh = DBI->connect(
- $self->{dbconnect}, $self->{dbuser}, $self->{dbpasswd},
- {AutoCommit => 0})
- or $self->error($DBI::errstr);
-
- # add login to employee table if it does not exist
- my $login = $self->{login};
- $login =~ s/@.*//;
- my $sth = $dbh->prepare("SELECT id FROM employee WHERE login = ?;");
- $sth->execute($login);
-
- my ($id) = $sth->fetchrow_array;
- $sth->finish;
- my $employeenumber;
- my @values;
- if ($id) {
-
- $query = qq|UPDATE employee SET
+ ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"
+ );
+
+ $userConfInsert->execute(
+ $self->{acs}, $self->{address},
+ $self->{businessnumber}, $self->{company},
+ $self->{countrycode}, $self->{currency},
+ $self->{dateformat}, $self->{dbdriver},
+ $self->{dbhost}, $self->{dbname},
+ $self->{dboptions}, $self->{dbpasswd},
+ $self->{dbport}, $self->{dbuser},
+ $self->{email}, $self->{fax},
+ $self->{menuwidth}, $self->{name},
+ $self->{numberformat}, $self->{print},
+ $self->{printer}, $self->{role},
+ $self->{sid}, $self->{signature},
+ $self->{stylesheet}, $self->{tel},
+ $self->{templates}, $self->{timeout},
+ $self->{vclimit}, $userID,
+ $self->{crypted_password}
+ );
+
+ }
+
+ if ( !$self->{'admin'} ) {
+
+ $self->{dbpasswd} =~ s/\\'/'/g;
+ $self->{dbpasswd} =~ s/\\\\/\\/g;
+
+ # format dbconnect and dboptions string
+ LedgerSMB::User::dbconnect_vars( $self, $self->{dbname} );
+
+ # check if login is in database
+ my $dbh = DBI->connect(
+ $self->{dbconnect}, $self->{dbuser},
+ $self->{dbpasswd}, { AutoCommit => 0 }
+ ) or $self->error($DBI::errstr);
+
+ # add login to employee table if it does not exist
+ my $login = $self->{login};
+ $login =~ s/@.*//;
+ my $sth = $dbh->prepare("SELECT id FROM employee WHERE login = ?;");
+ $sth->execute($login);
+
+ my ($id) = $sth->fetchrow_array;
+ $sth->finish;
+ my $employeenumber;
+ my @values;
+ if ($id) {
+
+ $query = qq|UPDATE employee SET
role = ?,
email = ?,
name = ?
WHERE login = ?|;
- @values = ($self->{role}, $self->{email}, $self->{name}, $login);
+ @values = ( $self->{role}, $self->{email}, $self->{name}, $login );
- } else {
+ }
+ else {
- my ($employeenumber) = Form::update_defaults(
- "", \%$self, "employeenumber", $dbh);
- $query = qq|
+ my ($employeenumber) =
+ Form::update_defaults( "", \%$self, "employeenumber", $dbh );
+ $query = qq|
INSERT INTO employee
(login, employeenumber, name,
workphone, role, email, sales)
VALUES (?, ?, ?, ?, ?, ?, '1')|;
-
- @values = ($login, $employeenumber, $self->{name}, $self->{tel},
- $self->{role}, $self->{email})
- }
- $sth = $dbh->prepare($query);
- $sth->execute(@values);
- $dbh->commit;
- $dbh->disconnect;
+ @values = (
+ $login, $employeenumber, $self->{name},
+ $self->{tel}, $self->{role}, $self->{email}
+ );
+ }
+
+ $sth = $dbh->prepare($query);
+ $sth->execute(@values);
+ $dbh->commit;
+ $dbh->disconnect;
- }
+ }
}
diff --git a/login.pl b/login.pl
index a9608a18..c7c3b8e2 100755
--- a/login.pl
+++ b/login.pl
@@ -10,9 +10,9 @@
# 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,
+# 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):
@@ -54,19 +54,18 @@ require "common.pl";
$| = 1;
-if ($ENV{CONTENT_LENGTH}) {
- read(STDIN, $_, $ENV{CONTENT_LENGTH});
+if ( $ENV{CONTENT_LENGTH} ) {
+ read( STDIN, $_, $ENV{CONTENT_LENGTH} );
}
-if ($ENV{QUERY_STRING}) {
- $_ = $ENV{QUERY_STRING};
+if ( $ENV{QUERY_STRING} ) {
+ $_ = $ENV{QUERY_STRING};
}
-if ($ARGV[0]) {
- $_ = $ARGV[0];
+if ( $ARGV[0] ) {
+ $_ = $ARGV[0];
}
-
%form = split /[&=]/;
# fix for apache 2.0 bug
@@ -75,8 +74,7 @@ map { $form{$_} =~ s/\\$// } keys %form;
# name of this script
$0 =~ tr/\\/\//;
$pos = rindex $0, '/';
-$script = substr($0, $pos + 1);
-
+$script = substr( $0, $pos + 1 );
#This needs to be a db query
#if (-e "${LedgerSMB::Sysconfig::userspath}/nologin" && $script ne 'admin.pl') {
@@ -89,6 +87,5 @@ $script = substr($0, $pos + 1);
$ARGV[0] = $_;
require "bin/$script";
-
# end of main
diff --git a/lsmb.pl b/lsmb.pl
index cdc4737c..d74f714d 100755
--- a/lsmb.pl
+++ b/lsmb.pl
@@ -10,37 +10,41 @@ use warnings;
use strict;
use CGI::Carp qw(fatalsToBrowser);
-sub cgi_handle {
- my $self = shift;
-
- my $script = $ENV{PATH_INFO};
-
- $script =~ s/^\///;
- # TODO: we can parse out other information, such as
- # Company Identifier, and what not here.
-
- #return $self->debug();
-
- if($script =~ /\.pl$/) {
- # perl scripts should be directly executed.
- warn "[LedgerSMB::Handler] running $script";
- exec("./$script") or croak $!;
- } else {
- # redirect them back to the original url
-
- # infer the base URI, this fails unless the script is named lsmb.pl
- my ($base_uri) = $ENV{SCRIPT_NAME} =~ m#^(.*?)/lsmb.pl#;
- print "Status: 301\nLocation: $base_uri/$script\n\n";
- }
+sub cgi_handle {
+ my $self = shift;
+
+ my $script = $ENV{PATH_INFO};
+
+ $script =~ s/^\///;
+
+ # TODO: we can parse out other information, such as
+ # Company Identifier, and what not here.
+
+ #return $self->debug();
+
+ if ( $script =~ /\.pl$/ ) {
+
+ # perl scripts should be directly executed.
+ warn "[LedgerSMB::Handler] running $script";
+ exec("./$script") or croak $!;
+ }
+ else {
+
+ # redirect them back to the original url
+
+ # infer the base URI, this fails unless the script is named lsmb.pl
+ my ($base_uri) = $ENV{SCRIPT_NAME} =~ m#^(.*?)/lsmb.pl#;
+ print "Status: 301\nLocation: $base_uri/$script\n\n";
+ }
}
-sub debug {
- my $self = shift;
+sub debug {
+ my $self = shift;
- use Data::Dumper;
- print "Content-type: text/plain\n\n";
- print "\$0 is $0\n";
- print Dumper(\%ENV);
+ use Data::Dumper;
+ print "Content-type: text/plain\n\n";
+ print "\$0 is $0\n";
+ print Dumper( \%ENV );
}
diff --git a/menu.pl b/menu.pl
index 4a8cacbe..fbbcb575 100755
--- a/menu.pl
+++ b/menu.pl
@@ -10,9 +10,9 @@
# 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,
+# 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):
@@ -59,128 +59,149 @@ use LedgerSMB::Session;
use Data::Dumper;
require "common.pl";
-
# for custom preprocessing logic
eval { require "custom.pl"; };
$form = new Form;
-
+
# name of this script
$0 =~ tr/\\/\//;
$pos = rindex $0, '/';
-$script = substr($0, $pos + 1);
+$script = substr( $0, $pos + 1 );
# we use $script for the language module
$form->{script} = $script;
+
# strip .pl for translation files
$script =~ s/\.pl//;
# pull in DBI
use DBI qw(:sql_types);
-# grab user config. This is ugly and unecessary if/when
-# we get rid of myconfig and use User as a real object
-%myconfig = %{LedgerSMB::User->fetch_config($form->{login})};
+# grab user config. This is ugly and unecessary if/when
+# we get rid of myconfig and use User as a real object
+%myconfig = %{ LedgerSMB::User->fetch_config( $form->{login} ) };
if ($@) {
- $locale = LedgerSMB::Locale->get_handle($myconfig{countrycode}) or
- $form->error(__FILE__.':'.__LINE__.": Locale not loaded: $!\n");
- $form->{charset} = $locale->encoding;
- $form->{charset} = 'UTF-8';
- $locale->encoding('UTF-8');
-
- $form->{callback} = "";
- $msg1 = $locale->text('You are logged out!');
- $msg2 = $locale->text('Login');
- $form->redirect("$msg1 <p><a href=\"login.pl\" target=\"_top\">$msg2</a></p>");
+ $locale = LedgerSMB::Locale->get_handle( $myconfig{countrycode} )
+ or
+ $form->error( __FILE__ . ':' . __LINE__ . ": Locale not loaded: $!\n" );
+ $form->{charset} = $locale->encoding;
+ $form->{charset} = 'UTF-8';
+ $locale->encoding('UTF-8');
+
+ $form->{callback} = "";
+ $msg1 = $locale->text('You are logged out!');
+ $msg2 = $locale->text('Login');
+ $form->redirect(
+ "$msg1 <p><a href=\"login.pl\" target=\"_top\">$msg2</a></p>");
}
# locale messages
-$locale = LedgerSMB::Locale->get_handle($myconfig{countrycode}) or
- $form->error(__FILE__.':'.__LINE__.": Locale not loaded: $!\n");
+$locale = LedgerSMB::Locale->get_handle( $myconfig{countrycode} )
+ or $form->error( __FILE__ . ':' . __LINE__ . ": Locale not loaded: $!\n" );
+
#$form->{charset} = $locale->encoding;
$form->{charset} = 'UTF-8';
$locale->encoding('UTF-8');
# send warnings to browser
-$SIG{__WARN__} = sub { $form->info($_[0]) };
+$SIG{__WARN__} = sub { $form->info( $_[0] ) };
# send errors to browser
-$SIG{__DIE__} = sub { $form->error(__FILE__.':'.__LINE__.': '.$_[0]) };
+$SIG{__DIE__} =
+ sub { $form->error( __FILE__ . ':' . __LINE__ . ': ' . $_[0] ) };
-map { $form->{$_} = $myconfig{$_} } qw(stylesheet timeout) unless ($form->{type} eq 'preferences');
-$form->db_init(\%myconfig);
+map { $form->{$_} = $myconfig{$_} } qw(stylesheet timeout)
+ unless ( $form->{type} eq 'preferences' );
+$form->db_init( \%myconfig );
-if ($form->{path} ne 'bin/lynx'){ $form->{path} = 'bin/mozilla';}
+if ( $form->{path} ne 'bin/lynx' ) { $form->{path} = 'bin/mozilla'; }
# did sysadmin lock us out
-if (-f "${LedgerSMB::Sysconfig::userspath}/nologin") {
- $form->error(__FILE__.':'.__LINE__.': '.$locale->text('System currently down for maintenance!'));
+if ( -f "${LedgerSMB::Sysconfig::userspath}/nologin" ) {
+ $form->error( __FILE__ . ':' . __LINE__ . ': '
+ . $locale->text('System currently down for maintenance!') );
}
# pull in the main code
require "bin/$form->{script}";
# customized scripts
-if (-f "bin/custom/$form->{script}") {
- eval { require "bin/custom/$form->{script}"; };
+if ( -f "bin/custom/$form->{script}" ) {
+ eval { require "bin/custom/$form->{script}"; };
}
# customized scripts for login
-if (-f "bin/custom/$form->{login}_$form->{script}") {
- eval { require "bin/custom/$form->{login}_$form->{script}"; };
+if ( -f "bin/custom/$form->{login}_$form->{script}" ) {
+ eval { require "bin/custom/$form->{login}_$form->{script}"; };
}
-
-if ($form->{action}) {
- # window title bar, user info
- $form->{titlebar} = "LedgerSMB ".$locale->text('Version'). " $form->{version} - $myconfig{name} - $myconfig{dbname}";
+if ( $form->{action} ) {
+
+ # window title bar, user info
+ $form->{titlebar} =
+ "LedgerSMB "
+ . $locale->text('Version')
+ . " $form->{version} - $myconfig{name} - $myconfig{dbname}";
- &check_password;
+ &check_password;
- &{ $form->{action} };
+ &{ $form->{action} };
-} else {
- $form->error(__FILE__.':'.__LINE__.': '.$locale->text('action= not defined!'));
+}
+else {
+ $form->error( __FILE__ . ':' . __LINE__ . ': '
+ . $locale->text('action= not defined!') );
}
1;
+
# end
sub check_password {
-
- require "bin/pw.pl";
-
- if ($form->{password}) {
- if (! Session::password_check($form, $form->{login}, $form->{password})) {
- if ($ENV{GATEWAY_INTERFACE}) {
- &getpassword;
- } else {
- $form->error(__FILE__.':'.__LINE__.': '.$locale->text('Access Denied!'));
- }
- exit;
- } else {
- Session::session_create($form);
- }
-
- } else {
- if ($ENV{GATEWAY_INTERFACE}) {
- $ENV{HTTP_COOKIE} =~ s/;\s*/;/g;
- @cookies = split /;/, $ENV{HTTP_COOKIE};
- foreach (@cookies) {
- ($name,$value) = split /=/, $_, 2;
- $cookie{$name} = $value;
- }
-
- #check for valid session
- if(!Session::session_check($cookie{"LedgerSMB"}, $form)){
- &getpassword(1);
- exit;
- }
- } else {
- exit;
- }
- }
-}
+ require "bin/pw.pl";
+
+ if ( $form->{password} ) {
+ if (
+ !Session::password_check(
+ $form, $form->{login}, $form->{password}
+ )
+ )
+ {
+ if ( $ENV{GATEWAY_INTERFACE} ) {
+ &getpassword;
+ }
+ else {
+ $form->error( __FILE__ . ':' . __LINE__ . ': '
+ . $locale->text('Access Denied!') );
+ }
+ exit;
+ }
+ else {
+ Session::session_create($form);
+ }
+
+ }
+ else {
+ if ( $ENV{GATEWAY_INTERFACE} ) {
+ $ENV{HTTP_COOKIE} =~ s/;\s*/;/g;
+ @cookies = split /;/, $ENV{HTTP_COOKIE};
+ foreach (@cookies) {
+ ( $name, $value ) = split /=/, $_, 2;
+ $cookie{$name} = $value;
+ }
+
+ #check for valid session
+ if ( !Session::session_check( $cookie{"LedgerSMB"}, $form ) ) {
+ &getpassword(1);
+ exit;
+ }
+ }
+ else {
+ exit;
+ }
+ }
+}
diff --git a/net-setup.pl b/net-setup.pl
index 594847e8..a9fc3341 100755
--- a/net-setup.pl
+++ b/net-setup.pl
@@ -10,9 +10,9 @@
# 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,
+# 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):
@@ -23,80 +23,131 @@
#######################################################################
# Next bunch of lines are to check to see if they have the cpan module installed.
-my $cpan=0;
-eval {
- use CPAN;
-};
-if (!$@){
- $cpan = 1;
+my $cpan = 0;
+eval { use CPAN; };
+if ( !$@ ) {
+ $cpan = 1;
}
$| = 1;
#not sure how safe this is. If the browser sends a blank GATEWAY_INTERFACE
-#will this script destroy part of the install?
+#will this script destroy part of the install?
#This script should probably be made inaccessible via HTTP until this feature is working
-if (($ENV{GATEWAY_INTERFACE})||($ENV{HTTP_HOST})) {
- print "Content-type: text/html\n\nThis does not work yet! use $0 from the command line";
- exit;
+if ( ( $ENV{GATEWAY_INTERFACE} ) || ( $ENV{HTTP_HOST} ) ) {
+ print
+"Content-type: text/html\n\nThis does not work yet! use $0 from the command line";
+ exit;
}
# Make sure they have the required perl modules installed.
# bin/mozilla/admin.pl needs Digest::MD5 for session handling
# HTML:LinkExtor is used by the setup program.
-my @req_modules=(qw(DBI DBD::Pg Digest::MD5 HTML::LinkExtor));
-
-foreach my $module(@req_modules){
- print "Checking for: $module ...\t";
- my @results=&check_module($module);
- print "$results[1]\n";
- next if($results[0]); # Passed, no need to continue..
- if ($cpan == 1){
- # Can try to install the module..
- print "\n\nWould you like to try and install this package ($module) through CPAN? (Y/N) [Y]:";
- my $response=<STDIN>;
- if(($response=~/y/i) or ($response eq "\n")){
- my $inst_obj = CPAN::Shell->install($module);
- @results=&check_module($module);
- if(!$results[0]){
- print "\n\nCould not install $module using CPAN.\n";
- die "Please try to install this module manually\n";
- }
- } else {
- die "Please install the $module perl module and retry the setup.\n";
- }
- } else {
- # Can't try to install the module..
- die "Please install the $module perl module and retry the setup.\n";
- }
+my @req_modules = (qw(DBI DBD::Pg Digest::MD5 HTML::LinkExtor));
+
+foreach my $module (@req_modules) {
+ print "Checking for: $module ...\t";
+ my @results = &check_module($module);
+ print "$results[1]\n";
+ next if ( $results[0] ); # Passed, no need to continue..
+ if ( $cpan == 1 ) {
+
+ # Can try to install the module..
+ print
+"\n\nWould you like to try and install this package ($module) through CPAN? (Y/N) [Y]:";
+ my $response = <STDIN>;
+ if ( ( $response =~ /y/i ) or ( $response eq "\n" ) ) {
+ my $inst_obj = CPAN::Shell->install($module);
+ @results = &check_module($module);
+ if ( !$results[0] ) {
+ print "\n\nCould not install $module using CPAN.\n";
+ die "Please try to install this module manually\n";
+ }
+ }
+ else {
+ die "Please install the $module perl module and retry the setup.\n";
+ }
+ }
+ else {
+
+ # Can't try to install the module..
+ die "Please install the $module perl module and retry the setup.\n";
+ }
}
use HTML::LinkExtor;
-
-my $lynx = `lynx -version`; # if LWP is not installed use lynx
-my $gzip = `gzip -V 2>&1`; # gz decompression utility
-my $tar = `tar --version 2>&1`; # tar archiver
+my $lynx = `lynx -version`; # if LWP is not installed use lynx
+my $gzip = `gzip -V 2>&1`; # gz decompression utility
+my $tar = `tar --version 2>&1`; # tar archiver
my $latex = `latex -version`;
-my $versionurl ='http://prdownloads.sourceforge.net/ledger-smb';
+my $versionurl = 'http://prdownloads.sourceforge.net/ledger-smb';
my %source = (
- 1 => { url => "http://voxel.dl.sourceforge.net/sourceforge/ledger-smb", site => "New York, U.S.A", locale => 'us' },
- 2 => { url => "http://easynews.dl.sourceforge.net/sourceforge/ledger-smb", site => "Arizona, U.S.A", locale => 'us' },
- 3 => { url => "http://ufpr.dl.sourceforge.net/sourceforge/ledger-smb", site =>"Brazil", locale => 'br' },
- 4 => { url => "http://surfnet.dl.sourceforge.net/sourceforge/ledger-smb", site => "The Netherlands", locale => 'nl' },
- 5 => { url => "http://http://kent.dl.sourceforge.net/sourceforge/ledger-smb", site => "U.K", locale => 'uk' },
- 6 => { url => "http://ovh.dl.sourceforge.net/sourceforge/ledger-smb", site => "France", locale => 'fr' },
- 7 => { url => "http://mesh.dl.sourceforge.net/sourceforge/ledger-smb", site => "Germany", locale => 'de' },
- 8 => { url => "http://citkit.dl.sourceforge.net/sourceforge/ledger-smb", site => "Russia", locale => 'ru' },
- 9 => { url => "http://optusnet.dl.sourceforge.net/sourceforge/ledger-smb", site => "Sydney, Australia", locale => 'au' },
- 10 => { url => "http://nchc.dl.sourceforge.net/sourceforge/ledger-smb", site => "Taiwan", locale => 'tw' },
- 11 => { url => "http://jaist.dl.sourceforge.net/sourceforge/ledger-smb", site => "Japan", locale => 'jp' },
- 12 => { url => "http://heanet.dl.sourceforge.net/sourceforge/ledger-smb", site => "Ireland", locale => 'ie' }
- );
-
-my $userspath = "users"; # default for new installation
+ 1 => {
+ url => "http://voxel.dl.sourceforge.net/sourceforge/ledger-smb",
+ site => "New York, U.S.A",
+ locale => 'us'
+ },
+ 2 => {
+ url => "http://easynews.dl.sourceforge.net/sourceforge/ledger-smb",
+ site => "Arizona, U.S.A",
+ locale => 'us'
+ },
+ 3 => {
+ url => "http://ufpr.dl.sourceforge.net/sourceforge/ledger-smb",
+ site => "Brazil",
+ locale => 'br'
+ },
+ 4 => {
+ url => "http://surfnet.dl.sourceforge.net/sourceforge/ledger-smb",
+ site => "The Netherlands",
+ locale => 'nl'
+ },
+ 5 => {
+ url => "http://http://kent.dl.sourceforge.net/sourceforge/ledger-smb",
+ site => "U.K",
+ locale => 'uk'
+ },
+ 6 => {
+ url => "http://ovh.dl.sourceforge.net/sourceforge/ledger-smb",
+ site => "France",
+ locale => 'fr'
+ },
+ 7 => {
+ url => "http://mesh.dl.sourceforge.net/sourceforge/ledger-smb",
+ site => "Germany",
+ locale => 'de'
+ },
+ 8 => {
+ url => "http://citkit.dl.sourceforge.net/sourceforge/ledger-smb",
+ site => "Russia",
+ locale => 'ru'
+ },
+ 9 => {
+ url => "http://optusnet.dl.sourceforge.net/sourceforge/ledger-smb",
+ site => "Sydney, Australia",
+ locale => 'au'
+ },
+ 10 => {
+ url => "http://nchc.dl.sourceforge.net/sourceforge/ledger-smb",
+ site => "Taiwan",
+ locale => 'tw'
+ },
+ 11 => {
+ url => "http://jaist.dl.sourceforge.net/sourceforge/ledger-smb",
+ site => "Japan",
+ locale => 'jp'
+ },
+ 12 => {
+ url => "http://heanet.dl.sourceforge.net/sourceforge/ledger-smb",
+ site => "Ireland",
+ locale => 'ie'
+ }
+);
+
+my $userspath = "users"; # default for new installation
eval { require "ledger-smb.conf"; };
@@ -109,30 +160,32 @@ my $newinstall = 1;
eval { require LWP::Simple; };
$lwp = !($@);
-unless ($lwp || $lynx || $filename) {
- die "You must have either lynx or LWP installed or specify a filename.
+unless ( $lwp || $lynx || $filename ) {
+ die "You must have either lynx or LWP installed or specify a filename.
perl $0 <filename>\n";
}
if ($filename) {
- # extract version
- die "Not a Ledger-SMB archive\n" if ($filename !~ /^ledger-smb/);
- $version = $filename;
- $version =~ s/ledger-smb-(\d+\.\d+\.\d+).*$/$1/;
+
+ # extract version
+ die "Not a Ledger-SMB archive\n" if ( $filename !~ /^ledger-smb/ );
+ $version = $filename;
+ $version =~ s/ledger-smb-(\d+\.\d+\.\d+).*$/$1/;
}
-
-if (-f "VERSION") {
- # get installed version from VERSION file
- open(FH, '<', "VERSION");
- @a = <FH>;
- close(FH);
- $version = $a[0];
- chomp $version;
- $newinstall = !$version;
- if (! -f "ledger-smb.conf") {
- $newinstall = 1;
- }
+
+if ( -f "VERSION" ) {
+
+ # get installed version from VERSION file
+ open( FH, '<', "VERSION" );
+ @a = <FH>;
+ close(FH);
+ $version = $a[0];
+ chomp $version;
+ $newinstall = !$version;
+ if ( !-f "ledger-smb.conf" ) {
+ $newinstall = 1;
+ }
}
# Try to determine web user and group..
@@ -141,84 +194,89 @@ $webowner = "nobody";
$webgroup = "nogroup";
# Check for apache2.conf
-if ($httpd = `find /etc /usr/local/etc -type f -name 'apache2.conf'`) {
- chomp $httpd;
- $webowner = `grep "^User " $httpd`;
- $webgroup = `grep "^Group " $httpd`;
- chomp $webowner;
- chomp $webgroup;
- (undef, $webowner) = split / /, $webowner;
- (undef, $webgroup) = split / /, $webgroup;
-
-} elsif ($httpd = `find /etc /usr/local/etc -type f -name 'httpd.conf'`) {
- # Else check for httpd.conf
- chomp $httpd;
- $webowner = `grep "^User " $httpd`;
- $webgroup = `grep "^Group " $httpd`;
- chomp $webowner;
- chomp $webgroup;
- (undef, $webowner) = split / /, $webowner;
- (undef, $webgroup) = split / /, $webgroup;
-}
+if ( $httpd = `find /etc /usr/local/etc -type f -name 'apache2.conf'` ) {
+ chomp $httpd;
+ $webowner = `grep "^User " $httpd`;
+ $webgroup = `grep "^Group " $httpd`;
+ chomp $webowner;
+ chomp $webgroup;
+ ( undef, $webowner ) = split / /, $webowner;
+ ( undef, $webgroup ) = split / /, $webgroup;
-if ($confd = `find /etc /usr/local/etc -type d -name 'apache*/conf.d'`) {
- chomp $confd;
}
-# If we are doing a new install.. check the postgresql installation..
-if ($newinstall == 1){
- # Check the postgresql version before we even check for a connection if local
- system("tput clear"); # Clear the screen..
- our ($pghost, $pgport, $pguser, $pgpassword);
- print "\n\nIs PostgreSQL installed [L]ocally,\n or will you be connecting to a [R]emote server? (L/R) [L]:";
- my $localremote=<STDIN>;
- if(($localremote=~/L/i) or ($localremote eq "\n")){
- $pghost = 'localhost';
- # If local, check the local postgresql version..
- my $pgversion = `psql --version`;
- ($pgversionnum) = $pgversion =~ m/(\d\.\d\.\d)/;
- unless ($pgversionnum gt '8.0.0'){
- # Die, cannot continue..
- print "LedgerSMB requires postgres version 8.0 or higher. You have version $pgversionnum installed\n";
- die;
- }
- }
- if (!&check_pgconnect){
- print "\n\n\nInstallation was not successful\n Exiting....\n";
- exit;
- }
-
+elsif ( $httpd = `find /etc /usr/local/etc -type f -name 'httpd.conf'` ) {
+
+ # Else check for httpd.conf
+ chomp $httpd;
+ $webowner = `grep "^User " $httpd`;
+ $webgroup = `grep "^Group " $httpd`;
+ chomp $webowner;
+ chomp $webgroup;
+ ( undef, $webowner ) = split / /, $webowner;
+ ( undef, $webgroup ) = split / /, $webgroup;
+}
+
+if ( $confd = `find /etc /usr/local/etc -type d -name 'apache*/conf.d'` ) {
+ chomp $confd;
}
+# If we are doing a new install.. check the postgresql installation..
+if ( $newinstall == 1 ) {
+
+ # Check the postgresql version before we even check for a connection if local
+ system("tput clear"); # Clear the screen..
+ our ( $pghost, $pgport, $pguser, $pgpassword );
+ print
+"\n\nIs PostgreSQL installed [L]ocally,\n or will you be connecting to a [R]emote server? (L/R) [L]:";
+ my $localremote = <STDIN>;
+ if ( ( $localremote =~ /L/i ) or ( $localremote eq "\n" ) ) {
+ $pghost = 'localhost';
+
+ # If local, check the local postgresql version..
+ my $pgversion = `psql --version`;
+ ($pgversionnum) = $pgversion =~ m/(\d\.\d\.\d)/;
+ unless ( $pgversionnum gt '8.0.0' ) {
+
+ # Die, cannot continue..
+ print
+"LedgerSMB requires postgres version 8.0 or higher. You have version $pgversionnum installed\n";
+ die;
+ }
+ }
+ if ( !&check_pgconnect ) {
+ print "\n\n\nInstallation was not successful\n Exiting....\n";
+ exit;
+ }
+}
system("tput clear");
if ($filename) {
- $install = "\ninstall $version from (f)ile\n";
+ $install = "\ninstall $version from (f)ile\n";
}
# check for latest version
&get_latest_version;
chomp $latest_version;
-if (!$newinstall) {
+if ( !$newinstall ) {
- $install .= "\n(r)einstall $version\n";
-
-}
+ $install .= "\n(r)einstall $version\n";
-if ($version && $latest_version) {
- if ($version ne $latest_version) {
- $install .= "\n(u)pgrade to $latest_version\n";
- }
}
+if ( $version && $latest_version ) {
+ if ( $version ne $latest_version ) {
+ $install .= "\n(u)pgrade to $latest_version\n";
+ }
+}
$install .= "\n(i)nstall $latest_version (from Internet)\n" if $latest_version;
$install .= "\n(d)ownload $latest_version (no installation)" unless $filename;
- print qq|
+print qq|
LedgerSMB Accounting and ERP Installation
@@ -236,256 +294,277 @@ chomp $a;
exit unless $a;
$a = lc $a;
-if ($a !~ /d/) {
+if ( $a !~ /d/ ) {
- print qq|\nEnter httpd owner [$webowner] : |;
- $web = <STDIN>;
- chomp $web;
- $webowner = $web if $web;
+ print qq|\nEnter httpd owner [$webowner] : |;
+ $web = <STDIN>;
+ chomp $web;
+ $webowner = $web if $web;
+
+ print qq|\nEnter httpd group [$webgroup] : |;
+ $web = <STDIN>;
+ chomp $web;
+ $webgroup = $web if $web;
- print qq|\nEnter httpd group [$webgroup] : |;
- $web = <STDIN>;
- chomp $web;
- $webgroup = $web if $web;
-
}
-if ($a ne 'f') {
- system("tput clear");
+if ( $a ne 'f' ) {
+ system("tput clear");
- # choose site
- foreach $item (sort { $a <=> $b } keys %source) {
- $i++;
- print qq|$i. $source{$item}{site}\n|;
- }
+ # choose site
+ foreach $item ( sort { $a <=> $b } keys %source ) {
+ $i++;
+ print qq|$i. $source{$item}{site}\n|;
+ }
- $site = "1";
+ $site = "1";
- print qq|\nChoose Location [$site] : |;
- $b = <STDIN>;
- chomp $b;
- $site = $b if $b;
+ print qq|\nChoose Location [$site] : |;
+ $b = <STDIN>;
+ chomp $b;
+ $site = $b if $b;
}
-if ($a eq 'd') {
- &download;
+if ( $a eq 'd' ) {
+ &download;
}
-if ($a =~ /(i|u)/) {
- &install_smb;
+if ( $a =~ /(i|u)/ ) {
+ &install_smb;
}
-if ($a eq 'r') {
- $latest_version = $version;
- &install_smb;
+if ( $a eq 'r' ) {
+ $latest_version = $version;
+ &install_smb;
}
-if ($a eq 'f') {
- &install_smb;
+if ( $a eq 'f' ) {
+ &install_smb;
}
exit;
+
# end main
-sub check_module{
- my($module)=@_;
- eval "use $module";
- if(!$@){
- return 1, "Ok";
- }else{
- return 0, "FAILED",$@;
- }
+sub check_module {
+ my ($module) = @_;
+ eval "use $module";
+ if ( !$@ ) {
+ return 1, "Ok";
+ }
+ else {
+ return 0, "FAILED", $@;
+ }
}
sub download {
- &get_source_code;
+ &get_source_code;
}
-
sub get_latest_version {
-
- print "Checking for latest version number .... ";
-
- if ($filename) {
- print "skipping, filename supplied\n";
- return;
- }
- my $urlresult = '';
- if ($lwp) {
- if ($urlresult = LWP::Simple::get("$versionurl")){
- $latest_version = parse_links($urlresult);
- } else {
- print "not found";
- }
- } else {
- if (!$lynx) {
- print "\nYou must have either lynx or LWP installed";
- exit 1;
- }
- $ok = `lynx -dump -head $versionurl`;
- if ($ok = ($ok =~ s/HTTP.*?200 //)) {
- $urlresult = `lynx -dump $versionurl`;
- $latest_version = parse_links($urlresult);
- } else {
- print "not found";
- }
- die unless $ok;
- }
-
- if ($latest_version) {
- print "ok\n";
- 1;
- }
+
+ print "Checking for latest version number .... ";
+
+ if ($filename) {
+ print "skipping, filename supplied\n";
+ return;
+ }
+ my $urlresult = '';
+ if ($lwp) {
+ if ( $urlresult = LWP::Simple::get("$versionurl") ) {
+ $latest_version = parse_links($urlresult);
+ }
+ else {
+ print "not found";
+ }
+ }
+ else {
+ if ( !$lynx ) {
+ print "\nYou must have either lynx or LWP installed";
+ exit 1;
+ }
+ $ok = `lynx -dump -head $versionurl`;
+ if ( $ok = ( $ok =~ s/HTTP.*?200 // ) ) {
+ $urlresult = `lynx -dump $versionurl`;
+ $latest_version = parse_links($urlresult);
+ }
+ else {
+ print "not found";
+ }
+ die unless $ok;
+ }
+
+ if ($latest_version) {
+ print "ok\n";
+ 1;
+ }
}
my @versions = ();
-sub parse_links{
+
+sub parse_links {
+
# Take the html retrieved by lwp or lynx and look for the version numbers.
- my $text = shift;
+ my $text = shift;
my $version = '';
- my $p = HTML::LinkExtor->new(\&cb);
+ my $p = HTML::LinkExtor->new( \&cb );
$p->parse($text) or die;
- foreach (@versions){
- my ($chkversion) = $_ =~ /^\/ledger-smb\/ledger-smb-(\d{1,3}\.\d{1,3}\.\d{1,3}\w*)\.tar\.gz$/;
- $version = $chkversion if ($chkversion gt $version);
+ foreach (@versions) {
+ my ($chkversion) =
+ $_ =~
+ /^\/ledger-smb\/ledger-smb-(\d{1,3}\.\d{1,3}\.\d{1,3}\w*)\.tar\.gz$/;
+ $version = $chkversion if ( $chkversion gt $version );
}
return $version;
}
sub cb {
+
# Callback function for LinkExtor
- my($tag, %attr) = @_;
+ my ( $tag, %attr ) = @_;
return if $tag ne 'a';
- return unless $attr{href} =~ /^\/ledger-smb\/ledger-smb-\d{1,3}\.\d{1,3}\.\d{1,3}\w*\.tar\.gz$/;
- push(@versions, values %attr);
+ return
+ unless $attr{href} =~
+ /^\/ledger-smb\/ledger-smb-\d{1,3}\.\d{1,3}\.\d{1,3}\w*\.tar\.gz$/;
+ push( @versions, values %attr );
}
sub get_source_code {
- $err = 0;
+ $err = 0;
- @order = ();
- push @order, $site;
-
- for (sort { $a <=> $b } keys %source) {
- push @order, $_;
- }
-
- if ($latest_version) {
- # download it
- chomp $latest_version;
- $latest_version = "ledger-smb-${latest_version}.tar.gz";
-
- print "\nStatus\n";
- print "Downloading $latest_version .... ";
-
- foreach $key (@order) {
- print "\n$source{$key}{site} .... ";
+ @order = ();
+ push @order, $site;
- if ($lwp) {
- $err = LWP::Simple::getstore("$source{$key}{url}/$latest_version", "$latest_version");
- $err -= 200;
- } else {
- $ok = `lynx -dump -head $source{$key}{url}/$latest_version`;
- $err = !($ok =~ s/HTTP.*?200 //);
+ for ( sort { $a <=> $b } keys %source ) {
+ push @order, $_;
+ }
- if (!$err) {
- $err = system("lynx -dump $source{$key}{url}/$latest_version > $latest_version");
- }
- }
+ if ($latest_version) {
+
+ # download it
+ chomp $latest_version;
+ $latest_version = "ledger-smb-${latest_version}.tar.gz";
+
+ print "\nStatus\n";
+ print "Downloading $latest_version .... ";
+
+ foreach $key (@order) {
+ print "\n$source{$key}{site} .... ";
+
+ if ($lwp) {
+ $err =
+ LWP::Simple::getstore( "$source{$key}{url}/$latest_version",
+ "$latest_version" );
+ $err -= 200;
+ }
+ else {
+ $ok = `lynx -dump -head $source{$key}{url}/$latest_version`;
+ $err = !( $ok =~ s/HTTP.*?200 // );
+
+ if ( !$err ) {
+ $err =
+ system(
+"lynx -dump $source{$key}{url}/$latest_version > $latest_version"
+ );
+ }
+ }
+
+ if ($err) {
+ print "failed!";
+ }
+ else {
+ last;
+ }
+
+ }
- if ($err) {
- print "failed!";
- } else {
- last;
- }
+ }
+ else {
+ $err = -1;
+ }
+ if ($err) {
+ die "Cannot get $latest_version";
+ }
+ else {
+ print "ok!\n";
}
-
- } else {
- $err = -1;
- }
-
- if ($err) {
- die "Cannot get $latest_version";
- } else {
- print "ok!\n";
- }
- $latest_version;
+ $latest_version;
}
-
sub install_smb {
- if ($filename) {
- $latest_version = $filename;
- } else {
- $latest_version = &get_source_code;
- }
-
- &decompress;
-
- if ($newinstall) {
- open(FH, '<', "ledger-smb.conf.default");
- @f = <FH>;
- close(FH);
- unless ($latex) {
- grep { s/^\$latex.*/\$latex = 0;/ } @f;
- }
- open(FH, '>', "ledger-smb.conf");
- print FH @f;
- close(FH);
-
- $alias = $absolutealias = $ENV{'PWD'};
- $alias =~ s/.*\///g;
-
- $httpddir = `dirname $httpd`;
- if ($confd) {
- $httpddir = $confd;
+ if ($filename) {
+ $latest_version = $filename;
}
- chomp $httpddir;
- $filename = "ledger-smb-httpd.conf";
-
- # do we have write permission?
- if (!open(FH, '>>', "$httpddir/$filename")) {
- open(FH, '>', "$filename");
- $norw = 1;
+ else {
+ $latest_version = &get_source_code;
}
- open (HTTPD, '<', 'sql-ledger-httpd.conf');
- while ($line = <HTTPD>){
- print FH $line;
- }
- close(FH);
-
- print qq|
+ &decompress;
+
+ if ($newinstall) {
+ open( FH, '<', "ledger-smb.conf.default" );
+ @f = <FH>;
+ close(FH);
+ unless ($latex) {
+ grep { s/^\$latex.*/\$latex = 0;/ } @f;
+ }
+ open( FH, '>', "ledger-smb.conf" );
+ print FH @f;
+ close(FH);
+
+ $alias = $absolutealias = $ENV{'PWD'};
+ $alias =~ s/.*\///g;
+
+ $httpddir = `dirname $httpd`;
+ if ($confd) {
+ $httpddir = $confd;
+ }
+ chomp $httpddir;
+ $filename = "ledger-smb-httpd.conf";
+
+ # do we have write permission?
+ if ( !open( FH, '>>', "$httpddir/$filename" ) ) {
+ open( FH, '>', "$filename" );
+ $norw = 1;
+ }
+
+ open( HTTPD, '<', 'sql-ledger-httpd.conf' );
+ while ( $line = <HTTPD> ) {
+ print FH $line;
+ }
+ close(FH);
+
+ print qq|
This is a new installation.
|;
- if ($norw) {
- print qq|
+ if ($norw) {
+ print qq|
Webserver directives were written to $filename
Copy $filename to $httpddir
|;
- if (!$confd) {
- print qq| and add
+ if ( !$confd ) {
+ print qq| and add
# Ledger-SMB
Include $httpddir/$filename
to $httpd
|;
- }
+ }
- print qq| and restart your webserver!\n|;
+ print qq| and restart your webserver!\n|;
- if (!$permset) {
- print qq|
+ if ( !$permset ) {
+ print qq|
WARNING: permissions for templates, users, css and spool directory
could not be set. Login as root and set permissions
@@ -493,223 +572,238 @@ could not be set. Login as root and set permissions
# chmod 771 users templates css spool
|;
- }
+ }
- } else {
-
- print qq|
+ }
+ else {
+
+ print qq|
Webserver directives were written to
$httpddir/$filename
|;
-
- if (!$confd) {
- if (!(`grep "^# LedgerSMB" $httpd`)) {
- open(FH, '>>', "$httpd");
+ if ( !$confd ) {
+ if ( !(`grep "^# LedgerSMB" $httpd`) ) {
+
+ open( FH, '>>', "$httpd" );
- print FH qq|
+ print FH qq|
# LedgerSMB
Include $httpddir/$filename
|;
- close(FH);
-
- }
- }
-
- if (!$>) {
- # send SIGHUP to httpd
- if ($f = `find /var -type f -name 'httpd.pid'`) {
- $pid = `cat $f`;
- chomp $pid;
- if ($pid) {
- system("kill -s HUP $pid");
- }
- }
- }
- }
- }
-
- # if this is not root, check if user is part of $webgroup
- if ($>) {
- if ($permset = ($) =~ getgrnam $webgroup)) {
- `chown -hR :$webgroup users templates css spool`;
- chmod 0771, 'users', 'templates', 'css', 'spool';
- `chown :$webgroup ledger-smb.conf`;
- }
- } else {
- # root
- `chown -hR 0:0 *`;
- `chown -hR $webowner:$webgroup users templates css spool`;
- chmod 0771, 'users', 'templates', 'css', 'spool';
- `chown $webowner:$webgroup ledger-smb.conf`;
- }
-
- chmod 0644, 'ledger-smb.conf';
- unlink "ledger-smb.conf.default";
+ close(FH);
+
+ }
+ }
+
+ if ( !$> ) {
+
+ # send SIGHUP to httpd
+ if ( $f = `find /var -type f -name 'httpd.pid'` ) {
+ $pid = `cat $f`;
+ chomp $pid;
+ if ($pid) {
+ system("kill -s HUP $pid");
+ }
+ }
+ }
+ }
+ }
- &cleanup;
+ # if this is not root, check if user is part of $webgroup
+ if ($>) {
+ if ( $permset = ( $) =~ getgrnam $webgroup ) ) {
+ `chown -hR :$webgroup users templates css spool`;
+ chmod 0771, 'users', 'templates', 'css', 'spool';
+ `chown :$webgroup ledger-smb.conf`;
+ }
+ }
+ else {
- while ($a !~ /(Y|N)/) {
- print qq|\nDisplay README (Y/n) : |;
- $a = <STDIN>;
- chomp $a;
- $a = ($a) ? uc $a : 'Y';
-
- if ($a eq 'Y') {
- @args = ("more", "doc/README");
- system(@args);
+ # root
+ `chown -hR 0:0 *`;
+ `chown -hR $webowner:$webgroup users templates css spool`;
+ chmod 0771, 'users', 'templates', 'css', 'spool';
+ `chown $webowner:$webgroup ledger-smb.conf`;
}
- }
-
-}
+ chmod 0644, 'ledger-smb.conf';
+ unlink "ledger-smb.conf.default";
+
+ &cleanup;
+
+ while ( $a !~ /(Y|N)/ ) {
+ print qq|\nDisplay README (Y/n) : |;
+ $a = <STDIN>;
+ chomp $a;
+ $a = ($a) ? uc $a : 'Y';
+
+ if ( $a eq 'Y' ) {
+ @args = ( "more", "doc/README" );
+ system(@args);
+ }
+ }
+
+}
sub decompress {
-
- die "Error: gzip not installed\n" unless ($gzip);
- die "Error: tar not installed\n" unless ($tar);
-
- &create_lockfile;
- # ungzip and extract source code
- print "Decompressing $latest_version ... ";
-
- if (system("gzip -df $latest_version")) {
- print "Error: Could not decompress $latest_version\n";
- &remove_lockfile;
- exit;
- } else {
- print "done\n";
- }
+ die "Error: gzip not installed\n" unless ($gzip);
+ die "Error: tar not installed\n" unless ($tar);
- # strip gz from latest_version
- $latest_version =~ s/\.gz//;
-
- # now untar it
- print "Unpacking $latest_version ... ";
- if (system("tar -xf $latest_version")) {
- print "Error: Could not unpack $latest_version\n";
- &remove_lockfile;
- exit;
- } else {
- # now we have a copy in ledger-smb
- if (system("tar -cf $latest_version -C ledger-smb .")) {
- print "Error: Could not create archive for $latest_version\n";
- &remove_lockfile;
- exit;
- } else {
- if (system("tar -xf $latest_version")) {
- print "Error: Could not unpack $latest_version\n";
- &remove_lockfile;
- exit;
- } else {
- print "done\n";
- print "cleaning up ... ";
- `rm -rf ledger-smb`;
+ &create_lockfile;
+
+ # ungzip and extract source code
+ print "Decompressing $latest_version ... ";
+
+ if ( system("gzip -df $latest_version") ) {
+ print "Error: Could not decompress $latest_version\n";
+ &remove_lockfile;
+ exit;
+ }
+ else {
print "done\n";
- }
}
- }
-}
+ # strip gz from latest_version
+ $latest_version =~ s/\.gz//;
+
+ # now untar it
+ print "Unpacking $latest_version ... ";
+ if ( system("tar -xf $latest_version") ) {
+ print "Error: Could not unpack $latest_version\n";
+ &remove_lockfile;
+ exit;
+ }
+ else {
+
+ # now we have a copy in ledger-smb
+ if ( system("tar -cf $latest_version -C ledger-smb .") ) {
+ print "Error: Could not create archive for $latest_version\n";
+ &remove_lockfile;
+ exit;
+ }
+ else {
+ if ( system("tar -xf $latest_version") ) {
+ print "Error: Could not unpack $latest_version\n";
+ &remove_lockfile;
+ exit;
+ }
+ else {
+ print "done\n";
+ print "cleaning up ... ";
+ `rm -rf ledger-smb`;
+ print "done\n";
+ }
+ }
+ }
+}
sub create_lockfile {
- if (-d "$userspath") {
- open(FH, '>', "$userspath/nologin");
- close(FH);
- }
-
-}
+ if ( -d "$userspath" ) {
+ open( FH, '>', "$userspath/nologin" );
+ close(FH);
+ }
+}
sub cleanup {
- unlink "$latest_version";
- unlink "$userspath/members.default" if (-f "$userspath/members.default");
+ unlink "$latest_version";
+ unlink "$userspath/members.default" if ( -f "$userspath/members.default" );
+
+ &remove_lockfile;
- &remove_lockfile;
-
}
+sub remove_lockfile {
+ unlink "$userspath/nologin"
+ if ( -f "$userspath/nologin" );
+}
-sub remove_lockfile { unlink "$userspath/nologin" if (-f "$userspath/nologin") };
-
-sub check_pgconnect{
- print "We will now attempt to validate that we are able to \nconnect to your postgres database.\n";
- my $cnx = 0;
- while (!$cnx){
- print "\nPlease enter the host name of the postgresql database? ".
- "(ie localhost)\n [$pghost]:";
- my $response=<STDIN>;
- $response =~ s/\s*//g;
- chomp($response);
- # Should probably try to validate the hostname here.. but for now, we'll leave it.
- $response = $pghost if ($response eq '');
- while (!$pgport){
- print "\nPlease enter the port postgres is listening on.\n[5432]:";
- $pgport=<STDIN>;
- chomp($pgport);
- $pgport = 5432 if ($pgport eq '');
- if (($pgport =~ /\D/)||($pgport > 65535)){
- print "\nThe port must be a number between 0 and 65535, ".
- "postgres default is 5432\n";
- undef $pgport;
- }
- }
- while (!$pguser){
- print "\nPlease enter a valid postgres user name ".
- "to validate the connection.:";
- $pguser=<STDIN>;
- chomp($pguser);
- if ($pguser eq ''){
- print "\nYou must enter a username\n";
- }
- }
- while (!$pgpass){
- print "\nPlease enter a valid postgres password ".
- "to validate the connection.:";
- $pgpass=<STDIN>;
- chomp($pgpass);
- if ($pgpass eq ''){
- print "\nYou must enter a password\n";
- }
+sub check_pgconnect {
+ print
+"We will now attempt to validate that we are able to \nconnect to your postgres database.\n";
+ my $cnx = 0;
+ while ( !$cnx ) {
+ print "\nPlease enter the host name of the postgresql database? "
+ . "(ie localhost)\n [$pghost]:";
+ my $response = <STDIN>;
+ $response =~ s/\s*//g;
+ chomp($response);
+
+# Should probably try to validate the hostname here.. but for now, we'll leave it.
+ $response = $pghost if ( $response eq '' );
+ while ( !$pgport ) {
+ print "\nPlease enter the port postgres is listening on.\n[5432]:";
+ $pgport = <STDIN>;
+ chomp($pgport);
+ $pgport = 5432 if ( $pgport eq '' );
+ if ( ( $pgport =~ /\D/ ) || ( $pgport > 65535 ) ) {
+ print "\nThe port must be a number between 0 and 65535, "
+ . "postgres default is 5432\n";
+ undef $pgport;
+ }
+ }
+ while ( !$pguser ) {
+ print "\nPlease enter a valid postgres user name "
+ . "to validate the connection.:";
+ $pguser = <STDIN>;
+ chomp($pguser);
+ if ( $pguser eq '' ) {
+ print "\nYou must enter a username\n";
+ }
+ }
+ while ( !$pgpass ) {
+ print "\nPlease enter a valid postgres password "
+ . "to validate the connection.:";
+ $pgpass = <STDIN>;
+ chomp($pgpass);
+ if ( $pgpass eq '' ) {
+ print "\nYou must enter a password\n";
+ }
+ }
+
+ # Try to connect;
+ eval {
+ my $dbh =
+ DBI->connect(
+ "dbi:Pg:dbname=template1;host=$response;" . "port=$pgport;",
+ $pguser, $pgpass )
+ or die $DBI::errstr;
+ my $version = $dbh->get_info(18);
+ if ( $version =~ /^07/ ) {
+ die "You have postgres version $version installed, "
+ . "we require a minimum of 8.0\n";
+ }
+ };
+ if ($@) {
+ system("tput clear");
+ print "Connection to the database was unsucessful\n"
+ . "The error we received was this:\n$@\n"
+ . "Would you like to try to enter the authentication "
+ . "information again? (Y/N)[N]:";
+ $answer = <STDIN>;
+ chomp($answer);
+ if ( $answer =~ /n/i ) {
+ $cnx = 1;
+ }
+ }
+ else {
+ $cnx = 1;
+ }
}
-
- # Try to connect;
- eval {
- my $dbh = DBI->connect("dbi:Pg:dbname=template1;host=$response;".
- "port=$pgport;", $pguser, $pgpass) or die $DBI::errstr;
- my $version = $dbh->get_info( 18 );
- if ($version =~ /^07/){
- die "You have postgres version $version installed, ".
- "we require a minimum of 8.0\n";
- }
- };
- if ($@){
- system("tput clear");
- print "Connection to the database was unsucessful\n".
- "The error we received was this:\n$@\n".
- "Would you like to try to enter the authentication ".
- "information again? (Y/N)[N]:";
- $answer=<STDIN>;
- chomp($answer);
- if($answer=~/n/i){
- $cnx = 1;
- }
- } else {
- $cnx = 1;
- }
- }
+
# Try to guide the user to an answer to the connection problems.
- system("tput clear"); # Clear the screen..
+ system("tput clear"); # Clear the screen..
print "Have you already set up a database user for LedgerSMB? (Y/N) [N]:";
$answer = <STDIN>;
chomp($answer);
- if(($answer=~/n/i) or ($answer eq "")){
- print q|
+ if ( ( $answer =~ /n/i ) or ( $answer eq "" ) ) {
+ print q|
If you have not set up a database user yet, you can use the following command:
@@ -721,8 +815,9 @@ Shall the new user be allowed to create more new users? (y/n) n
if you use passwords to access postgres use this command
$ createuser -d -P ledger-smb
|;
- return 0;
+ return 0;
}
+
# Maybe they did not change pg_hba.conf?
print qq|Did you modify pg_hba.conf to allow access?
@@ -741,14 +836,15 @@ $ createuser -d -P ledger-smb
Did you allow access to the postgres database from the web server?
(Y/N) [Y]:|;
$answer = <STDIN>;
- if(($response=~/n/i) or ($response eq "\n")){
- return 0;
- }
+ if ( ( $response =~ /n/i ) or ( $response eq "\n" ) ) {
+ return 0;
+ }
+
# Add other checks here..
-
+
return 0;
}
- print "\nConnection Successful, Press enter to continue\n";
- $answer=<STDIN>;
- return 1;
-
+print "\nConnection Successful, Press enter to continue\n";
+$answer = <STDIN>;
+return 1;
+
diff --git a/pos.conf.pl b/pos.conf.pl
index e89e69ce..da0ca6e2 100644
--- a/pos.conf.pl
+++ b/pos.conf.pl
@@ -1,4 +1,5 @@
use LedgerSMB::Sysconfig;
+
# This sets up the settings for the POS hardware. You can use it to override
# printing commands etc. as well.
@@ -8,36 +9,37 @@ use LedgerSMB::Sysconfig;
# Begin Editing Here
-$pos_config{'rem_host'}=$ENV{'REMOTE_ADDR'};
+$pos_config{'rem_host'} = $ENV{'REMOTE_ADDR'};
-$pos_config{'pd_host'} = $pos_config{'rem_host'};
-$pos_config{'pd_port'} = 6601;
+$pos_config{'pd_host'} = $pos_config{'rem_host'};
+$pos_config{'pd_port'} = 6601;
$pos_config{'pd_proto'} = 'tcp';
-require "drivers/pd3000.pl"; # Use the PD3000 driver
+require "drivers/pd3000.pl"; # Use the PD3000 driver
# Some businesses may want to Override this for custom apps
-$pos_config{'pd_host'} = $pos_config{'rem_host'};
+$pos_config{'pd_host'} = $pos_config{'rem_host'};
-$pos_config{'rp_port'} = 6602;
+$pos_config{'rp_port'} = 6602;
$pos_config{'rp_proto'} = 'tcp';
$pos_config{'rp_netdirect'} = 'yes';
# Some businesses may want to Override this for custom apps
-$pos_config{'rp_host'} = $pos_config{'rem_host'};
-$pos_config{'rp_cash_open'} = pack("CCCCC",27,112,0,25,250);
+$pos_config{'rp_host'} = $pos_config{'rem_host'};
+$pos_config{'rp_cash_open'} = pack( "CCCCC", 27, 112, 0, 25, 250 );
$pos_config{'coa_prefix'} = 1300;
$pos_config{'close_cash_accno'} = 1060;
$pos_config{till_cash} = 200;
+
# Add your sources here.
-$pos_sources{'visa'} = $locale->text("Visa/MC");
-$pos_sources{'disc'} = $locale->text("Discover");
+$pos_sources{'visa'} = $locale->text("Visa/MC");
+$pos_sources{'disc'} = $locale->text("Discover");
$pos_sources{'check'} = $locale->text('Check');
-$pos_sources{'cash'} = $locale->text('Cash');
+$pos_sources{'cash'} = $locale->text('Cash');
$pos_sources{'gcert'} = $locale->text('Gift Cert');
$pos_source_default = 'cash';
@@ -45,13 +47,14 @@ $pos_source_default = 'cash';
# 1 for source = memo
# 2 for credit card handling
%pos_source_type = {
- visa => 2,
- cash => 1,
- check => 1,
- disc => 2
+ visa => 2,
+ cash => 1,
+ check => 1,
+ disc => 2
};
-${$pos_config{'source_accno_override'}{'gcert'}} = '2105';
+${ $pos_config{'source_accno_override'}{'gcert'} } = '2105';
+
# Define your till accno scheme here. Current supported values are 'terminal'
# and 'cashier'
@@ -68,33 +71,33 @@ $pos_config{'numberformat'} = '1,000.00';
# Units of currency to use in the till closing cash breakdown relative to
# your base unit of currency, formatted in your chosen format
-@{$pos_config{'breakdown'}} = (
- '100', '50', '20', '10', '5', '2', '1', '0.25', '0.10', '0.05', '0.01');
+@{ $pos_config{'breakdown'} } =
+ ( '100', '50', '20', '10', '5', '2', '1', '0.25', '0.10', '0.05', '0.01' );
# Stop Editing Here
-if (lc($pos_config{'till_type'}) eq 'terminal'){
- $pos_config{'till'} = (split(/\./, $pos_config{'rem_host'}))[3];
+if ( lc( $pos_config{'till_type'} ) eq 'terminal' ) {
+ $pos_config{'till'} = ( split( /\./, $pos_config{'rem_host'} ) )[3];
}
-elsif (lc($pos_config{'till_type'}) eq 'cashier'){
- use LedgerSMB::User;
- $pos_config{'till'} = $form->get_my_emp_num(\%myconfig, \%$form);
+elsif ( lc( $pos_config{'till_type'} ) eq 'cashier' ) {
+ use LedgerSMB::User;
+ $pos_config{'till'} = $form->get_my_emp_num( \%myconfig, \%$form );
}
-else {
- $form->error("No till type defined in pos.conf.pl!");
+else {
+ $form->error("No till type defined in pos.conf.pl!");
}
$pos_config{till_accno} = "$pos_config{coa_prefix}.$pos_config{till}";
-$pos_config{'pd_dest'}=pack(
- 's n a4 x8', 2, $pos_config{'pd_port'},
- pack('CCCC', split(/\./, $pos_config{'pd_host'}))
-);
+$pos_config{'pd_dest'} = pack( 's n a4 x8',
+ 2, $pos_config{'pd_port'},
+ pack( 'CCCC', split( /\./, $pos_config{'pd_host'} ) ) );
-$form->{pos_config} = \%pos_config;
+$form->{pos_config} = \%pos_config;
$form->{pos_sources} = \%pos_sources;
# Due to the architecture of SL, we need to use netcat to print.
# Otherwise the document gets spooled twice and this interferes with timeliness.
-${LedgerSMB::Sysconfig::printer}{'Printer'} = "utils/pos/directnet.pl $pos_config{rp_host} $pos_config{rp_proto} $pos_config{rp_port}";
+${LedgerSMB::Sysconfig::printer}{'Printer'} =
+"utils/pos/directnet.pl $pos_config{rp_host} $pos_config{rp_proto} $pos_config{rp_port}";
1;
diff --git a/rest.pl b/rest.pl
index 27618202..9b1330de 100755
--- a/rest.pl
+++ b/rest.pl
@@ -4,8 +4,10 @@ use LedgerSMB::RESTXML::Handler;
# To Enable the REST API, Delete these 5 lines.
print "Content-type: text/plain\n\n";
-print "REST API disabled by default until authentication is working correctly\n";
-print "If you understand the security implications of this, and wish to enable the REST api\n";
+print
+ "REST API disabled by default until authentication is working correctly\n";
+print
+"If you understand the security implications of this, and wish to enable the REST api\n";
print "Then open rest.pl, and remove these 5 lines";
exit;
diff --git a/utils/cli/ledgersmb_cli.pl b/utils/cli/ledgersmb_cli.pl
index a8fbaa98..606cfac0 100644
--- a/utils/cli/ledgersmb_cli.pl
+++ b/utils/cli/ledgersmb_cli.pl
@@ -4,15 +4,15 @@
# LedgerSMB Command-line script host
#
#
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
-# with permission. It is released under the GNU General Public License
-# Version 2 or, at your option, any later version. See COPYRIGHT file for
+# with permission. It is released under the GNU General Public License
+# Version 2 or, at your option, any later version. See COPYRIGHT file for
# details.
#
# This is a simple wrapper that allows you to write simple scripts with LSMB
@@ -83,9 +83,10 @@ $syntax = << '_END_SYNTAX_';
_END_SYNTAX_
- $::RD_HINT = 1;
- $::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error
- $::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c.`
+$::RD_HINT = 1;
+$::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error
+$::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c.`
+
#$::RD_TRACE = 1;
my @loopstack;
my $loopindex;
@@ -95,97 +96,100 @@ my @control_stack;
push @loopstack, $form;
sub assignval {
- my ($key, $value) = @_;
- if ($key =~ /^ENV:/i){
- $ENV{$key} = $value;
- } else {
- %{$loopstack[$#loopstack - 1]}->{$key} = $value;
- }
+ my ( $key, $value ) = @_;
+ if ( $key =~ /^ENV:/i ) {
+ $ENV{$key} = $value;
+ }
+ else {
+ %{ $loopstack[ $#loopstack - 1 ] }->{$key} = $value;
+ }
}
sub expression {
- shift;
- my ($lhs,$op,$rhs) = @_;
- $lhs = $VARIABLE{$lhs} if $lhs=~/[^-+0-9]/;
- return eval "$lhs $op $rhs";
+ shift;
+ my ( $lhs, $op, $rhs ) = @_;
+ $lhs = $VARIABLE{$lhs} if $lhs =~ /[^-+0-9]/;
+ return eval "$lhs $op $rhs";
}
sub call {
- my ($call, $argstr) = @_;
- $argstr =~ s/form/\\\%\$form/;
- $argstr =~ s/user/\\\%myconfig/;
- my @args = split /,\s/, $argstr;
- eval "$call($argstr);\n" || print STDERR $@ . "\n";
+ my ( $call, $argstr ) = @_;
+ $argstr =~ s/form/\\\%\$form/;
+ $argstr =~ s/user/\\\%myconfig/;
+ my @args = split /,\s/, $argstr;
+ eval "$call($argstr);\n" || print STDERR $@ . "\n";
}
sub call_and_assign {
- my $key = pop;
- $stackref->{key} = call(@_);
+ my $key = pop;
+ $stackref->{key} = call(@_);
}
sub push_loop {
- my $key = shift;
- my $is_hash = 0;
- if (ref($stackref->{$key}) =~ /HASH/){
- $is_hash = 1;
- } elsif (ref ($stackref->{$key}) !~ /ARRAY/){
- print STDERR "Warning: Must loop through array or hash.";
- }
- push @loopstack, \$stackref->{$key};
- push @controlstack,
- { "key" => $key,
- 'index' => 0,
- 'linenum' => $#linestack,
- is_hash => $is_hash };
+ my $key = shift;
+ my $is_hash = 0;
+ if ( ref( $stackref->{$key} ) =~ /HASH/ ) {
+ $is_hash = 1;
+ }
+ elsif ( ref( $stackref->{$key} ) !~ /ARRAY/ ) {
+ print STDERR "Warning: Must loop through array or hash.";
+ }
+ push @loopstack, \$stackref->{$key};
+ push @controlstack,
+ {
+ "key" => $key,
+ 'index' => 0,
+ 'linenum' => $#linestack,
+ is_hash => $is_hash
+ };
}
sub pop_loop {
- pop @loopstack;
- $stackref = \$loopstack[$#loopstack];
+ pop @loopstack;
+ $stackref = \$loopstack[$#loopstack];
}
sub if_handler {
- my $key = shift;
- if (!$stackref->{$key}){
- $if_count = 1;
- }
+ my $key = shift;
+ if ( !$stackref->{$key} ) {
+ $if_count = 1;
+ }
}
sub login {
- $myconfig = new LedgerSMB::User
- "${LedgerSMB::Sysconfig::memberfile}", "$form->{login}";
- $form->db_init($myconfig);
+ $myconfig = new LedgerSMB::User "${LedgerSMB::Sysconfig::memberfile}",
+ "$form->{login}";
+ $form->db_init($myconfig);
}
sub load_mod {
- my $mod = shift;
- $mod =~ s/::/\//;
- require "$mod.pm";;
+ my $mod = shift;
+ $mod =~ s/::/\//;
+ require "$mod.pm";
}
my $scriptparse = new Parse::RecDescent($syntax);
-
$loopindex = 0;
my @linestack;
-while ($line = <>){
- push @linestack, $line;
- if ($if_count){
- if ($line =~ /^\s*IF\s/){
- ++$if_count;
- }
- if ($line =~ /^(\s*FI\s*|\s*END\s+IF\s*)$/){
- --$if_count;
- }
- }
- next if ($if_count);
- $line =~ s/#.*$//; # strip comments
- $scriptparse->startrule($line);
+while ( $line = <> ) {
+ push @linestack, $line;
+ if ($if_count) {
+ if ( $line =~ /^\s*IF\s/ ) {
+ ++$if_count;
+ }
+ if ( $line =~ /^(\s*FI\s*|\s*END\s+IF\s*)$/ ) {
+ --$if_count;
+ }
+ }
+ next if ($if_count);
+ $line =~ s/#.*$//; # strip comments
+ $scriptparse->startrule($line);
}
delete $form->{password};
-for (keys %$form){
- print "$_ = $form->{$_}\n";
+for ( keys %$form ) {
+ print "$_ = $form->{$_}\n";
}
diff --git a/utils/notify_short/config.pl b/utils/notify_short/config.pl
index bd37bed1..cddda1e0 100644
--- a/utils/notify_short/config.pl
+++ b/utils/notify_short/config.pl
@@ -1,13 +1,12 @@
#!/usr/bin/perl
-use vars qw($email_to $cc_to $email_from $sendmail $database $db_user
- $db_passwd $template_head $template_foot);
+use vars qw($email_to $cc_to $email_from $sendmail $database $db_user
+ $db_passwd $template_head $template_foot);
# The address to send the mail to. On UNIX systems, multiple addresses can be
# separated by a space.
$email_to = 'manager@example';
-
# The email address this email is from:
$email_from = 'noreply@example';
@@ -28,8 +27,7 @@ $cycle_delay = 60;
# The password for the db user:
$db_passwd = "mypasswd";
-$template_top =
-"From: $email_from
+$template_top = "From: $email_from
Subject: Parts Short Notice
Hi. This is the SL-Short listener. You are receiving this message because
diff --git a/utils/notify_short/listener.pl b/utils/notify_short/listener.pl
index a9286795..acbb7c91 100644
--- a/utils/notify_short/listener.pl
+++ b/utils/notify_short/listener.pl
@@ -7,40 +7,46 @@
# By Chris Travers, Metatron Technology Consulting
# chris@metatrontech.com
#
-# Released under the GNU GPL v2.0 or later. See included GPL.txt for more
+# Released under the GNU GPL v2.0 or later. See included GPL.txt for more
# information.
require "config.pl";
use DBI;
my $dsn = "dbi:Pg:dbname=$database";
-my $dbh = DBI->connect($dsn, $db_user, $db_passwd,
- { AutoCommit => 1,
- PrintError => 0,
- RaiseError => 1, }
+my $dbh = DBI->connect(
+ $dsn, $db_user,
+ $db_passwd,
+ {
+ AutoCommit => 1,
+ PrintError => 0,
+ RaiseError => 1,
+ }
);
my $sth;
$dbh->do("LISTEN parts_short");
-while (1){ # loop infinitely
- if ($dbh->func ('pg_notifies')){
- &on_notify;
- }
- sleep $cycle_delay;
+while (1) { # loop infinitely
+ if ( $dbh->func('pg_notifies') ) {
+ &on_notify;
+ }
+ sleep $cycle_delay;
}
+
sub on_notify {
- open (MAIL, '|-', "$sendmail");
- $sth = $dbh->prepare("
+ open( MAIL, '|-', "$sendmail" );
+ $sth = $dbh->prepare( "
SELECT partnumber, description, onhand, rop FROM parts
WHERE onhand <= rop
- ");
- $sth->execute;
- print MAIL $template_top;
- while (($partnumber, $description, $avail, $rop) = $sth->fetchrow_array){
- write MAIL;
- }
- print MAIL $template_foot;
- close MAIL;
+ " );
+ $sth->execute;
+ print MAIL $template_top;
+ while ( ( $partnumber, $description, $avail, $rop ) = $sth->fetchrow_array )
+ {
+ write MAIL;
+ }
+ print MAIL $template_foot;
+ close MAIL;
}
diff --git a/utils/pos/directnet.pl b/utils/pos/directnet.pl
index 3bdd2e51..efe4de0a 100755
--- a/utils/pos/directnet.pl
+++ b/utils/pos/directnet.pl
@@ -1,19 +1,16 @@
#!/usr/bin/perl
-($host, $proto, $port) = @ARGV;
+( $host, $proto, $port ) = @ARGV;
-socket(SOCK, 2, 1, getprotobynumber($proto));
+socket( SOCK, 2, 1, getprotobynumber($proto) );
-$dest=pack(
- 's n a4 x8', 2, $port,
- pack('CCCC', split(/\./, $host))
-);
+$dest = pack( 's n a4 x8', 2, $port, pack( 'CCCC', split( /\./, $host ) ) );
-connect (SOCK, $dest);
+connect( SOCK, $dest );
-open ('STD', '-');
-while ($line = <STD>){
- print SOCK $line;
+open( 'STD', '-' );
+while ( $line = <STD> ) {
+ print SOCK $line;
}
close STD;
close SOCK;