summaryrefslogtreecommitdiff
path: root/LedgerSMB/Form.pm
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-12-20 01:25:01 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-12-20 01:25:01 +0000
commitb119931d2f74d3d0a6a2d3292154c175f534acf4 (patch)
tree8fd925dd21320f39156991bfd10bbed267a79b01 /LedgerSMB/Form.pm
parent0f9d68697da12477342cc41825737b282a215f32 (diff)
Fixing flawed invoice behavior
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1985 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/Form.pm')
-rw-r--r--LedgerSMB/Form.pm56
1 files changed, 28 insertions, 28 deletions
diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm
index 39648086..cb31c8e9 100644
--- a/LedgerSMB/Form.pm
+++ b/LedgerSMB/Form.pm
@@ -1653,8 +1653,8 @@ sub get_name {
my $where;
if ($transdate) {
$where = qq|
- AND (startdate IS NULL OR startdate <= ?)
- AND (enddate IS NULL OR enddate >= ?)|;
+ AND (c.startdate IS NULL OR c.startdate <= ?)
+ AND (c.enddate IS NULL OR c.enddate >= ?)|;
@queryargs = ( $transdate, $transdate );
}
@@ -1664,15 +1664,19 @@ sub get_name {
$self->error('Invalid name source');
}
# Company name is stored in $self->{vendor} or $self->{customer}
+ if ($self->{"${table}number"} eq ''){
+ $self->{"${table}number"} = $self->{$table};
+ }
my $name = $self->like( lc $self->{$table} );
# Vendor and Customer are now views into entity_credit_account.
- my $query = qq|
- SELECT * FROM $table t
- JOIN entity e ON t.entity_id = e.id
- WHERE (lower(e.name) LIKE ? OR t.${table}number LIKE ?)
+ my $query = qq/
+ SELECT c.*, e.name FROM entity_credit_account c
+ JOIN entity e ON c.entity_id = e.id
+ WHERE (lower(e.name) LIKE ?
+ AND c.meta_number LIKE ?)
$where
- ORDER BY e.name|;
+ ORDER BY e.name/;
unshift( @queryargs, $name, $self->like($self->{"${table}number"}) );
my $sth = $self->{dbh}->prepare($query);
@@ -1726,16 +1730,17 @@ sub all_vc {
$self->{vc_class} = 2;
$vc = 'vendor';
}
- my $query = qq|SELECT count(*) FROM entity_credit_account where entity_class = ?|;
+ my $query = qq|SELECT count(*) FROM entity_credit_account ec
+ where ec.entity_class = ?|;
my $where;
my @queryargs2 = ($self->{vc_class});
my @queryargs;
if ($transdate) {
- $query .= qq| AND (startdate IS NULL OR startdate <= ?)
- AND (enddate IS NULL OR enddate >= ?)|;
- $where = qq| (startdate IS NULL OR startdate <= ?)
- AND (enddate IS NULL OR enddate >= ?)
- AND entity_class = ?|;
+ $query .= qq| AND (ec.startdate IS NULL OR ec.startdate <= ?)
+ AND (ec.enddate IS NULL OR ec.enddate >= ?)|;
+ $where = qq| (ec.startdate IS NULL OR ec.startdate <= ?)
+ AND (ec.enddate IS NULL OR ec.enddate >= ?)
+ AND ec.entity_class = ?|;
push (@queryargs, $transdate, $transdate, $self->{vc_class});
push (@queryargs2, $transdate, $transdate);
} else {
@@ -1755,20 +1760,14 @@ sub all_vc {
$self->{"${vc}_id"} *= 1;
- $query = qq|SELECT id, name
- FROM entity
- WHERE id IN (select entity_id
- FROM
- entity_credit_account
- WHERE
- $where)
-
- UNION
-
- SELECT id,name
- FROM entity
- WHERE id = ?
- ORDER BY name|;
+ # TODO: Alter this so that it pulls up the entity_credit_account
+ # instead of the entity_id. --CT
+ $query = qq|
+ SELECT ec.id, e.name
+ FROM entity e
+ JOIN entity_credit_account ec ON (ec.entity_id = e.id)
+ WHERE ec.id = ? OR $where
+ ORDER BY name|;
push( @queryargs, $self->{"${vc}_id"} );
@@ -2192,7 +2191,8 @@ sub create_links {
$query = qq|
SELECT a.invnumber, a.transdate,
- a.entity_id, a.datepaid, a.duedate, a.ordnumber,
+ a.entity_credit_account AS entity_id,
+ a.datepaid, a.duedate, a.ordnumber,
a.taxincluded, a.curr AS currency, a.notes,
a.intnotes, ce.name AS $vc, a.department_id,
d.description AS department,