summaryrefslogtreecommitdiff
path: root/LedgerSMB/BP.pm
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-04-26 18:00:56 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-04-26 18:00:56 +0000
commit666fd833584fe2e3618a397fe9d9a9bdf4c5b94b (patch)
tree19c4444705fd7f7803e0d7b597659c11d7e85b73 /LedgerSMB/BP.pm
parent2edd2e4de0f08a0a5f23647ea715f279671a0b89 (diff)
Doing a simple Perltidy commit so that I can evaluate differences between the branches and make sure patches are up to date
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1103 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/BP.pm')
-rw-r--r--LedgerSMB/BP.pm516
1 files changed, 260 insertions, 256 deletions
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;
+ }
+ }
}