summaryrefslogtreecommitdiff
path: root/LedgerSMB
diff options
context:
space:
mode:
authoraurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46>2007-07-05 18:44:24 +0000
committeraurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46>2007-07-05 18:44:24 +0000
commit94903b12ecba837d8717bcf91b7bcc25556a996a (patch)
tree8e8185200c5a72e3cef0d7edf3391f38409a50ea /LedgerSMB
parent9aec614fb5c2470d3bb60e88bb6a71429d50b790 (diff)
Modifications to support toggling of the On-Hold field in the ar and ap tables;
An On-Hold toggle button was added to the Invoice Edit page, as well as a selector for All Invoices (default), Active Invoices, and Held Invoices to the AR and AP search pages. Modifications as needed to bring the code in line with linuxpoet's entity patches. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1350 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB')
-rw-r--r--LedgerSMB/AA.pm21
-rw-r--r--LedgerSMB/CT.pm38
-rw-r--r--LedgerSMB/Form.pm9
-rw-r--r--LedgerSMB/IR.pm39
-rw-r--r--LedgerSMB/IS.pm42
5 files changed, 124 insertions, 25 deletions
diff --git a/LedgerSMB/AA.pm b/LedgerSMB/AA.pm
index 8c4c4ad9..5a523cd0 100644
--- a/LedgerSMB/AA.pm
+++ b/LedgerSMB/AA.pm
@@ -886,6 +886,25 @@ sub transactions {
WHERE lower(description)
LIKE '$var'))|;
}
+
+ if ($form->{invoice_type}) {
+
+ if ( $form->{invoice_type} == 2 ) {
+
+ $where .= qq|
+ AND a.on_hold = 'f'
+ |;
+ }
+
+ if ($form->{invoice_type} == 3) {
+
+ $where .= qq|
+ AND a.on_hold = 't'
+ |;
+ }
+ }
+
+ # the third state, all invoices, sets no explicit toggles. It just selects them all, as normal.
$query .= "WHERE $where
ORDER BY $sortorder";
@@ -972,7 +991,7 @@ sub get_name {
FROM $form->{vc} c
JOIN entity ON (entity.id = c.entity_id)
LEFT JOIN business b ON (b.id = c.business_id)
- WHERE c.id = ?|;
+ WHERE c.entity_id = ?|;
# TODO: Add location join
@queryargs = ( $form->{"$form->{vc}_id"} );
diff --git a/LedgerSMB/CT.pm b/LedgerSMB/CT.pm
index 785d2dc3..6aa07459 100644
--- a/LedgerSMB/CT.pm
+++ b/LedgerSMB/CT.pm
@@ -264,42 +264,46 @@ sub _save_vc {
}
if (!$updated){
# Creating Entity
- $query = qq|INSERT INTO entity (name, entity_class) VALUES (?, ?)|;
+ ($form->{entity_id}) = $dbh->selectrow_array("SELECT nextval('entity_id_seq')");
+ $query = qq|INSERT INTO entity (id, name, entity_class) VALUES (?, ?)|;
$sth = $dbh->prepare($query);
- $sth->execute($form->{name}, $form->{entity_class});
+ $sth->execute($form->{entity_id}, $form->{name}, $form->{entity_class});
$sth->finish;
- ($form->{entity_id}) =
- $dbh->selectrow_array("SELECT currval('entity_id_seq')");
+
# Creating LOCATION
+ ($form->{location_id}) =
+ $dbh->selectrow_array("SELECT nextval('location_id_seq')");
$query = qq|
INSERT INTO location
- (line_one, line_two, city_province, mail_code,
- country_id)
+ (id, line_one, line_two, city_province, mail_code,
+ country_id, location_class,created)
VALUES
(?, ?, ?, ?,
(SELECT id FROM country
- WHERE short_name = ? OR name = ?))
- |;
+ WHERE short_name = ? OR name = ?),
+ 1, current_date)
+ |; # location class 1 is Billing. This is a sensible default.
$sth = $dbh->prepare($query);
- $sth->execute($form->{address1}, $form->{address2},
+ $sth->execute($form->{location_id}, $form->{address1}, $form->{address2},
"$form->{city}, $form->{state}", $form->{zipcode},
$form->{country}, $form->{country}
) || $form->dberror($query);
- ($form->{location_id}) =
- $dbh->selectrow_array("SELECT currval('location_id_seq')");
+
#Creating company
+ # Removed entity_class_id ~Aurynn
+ # removed primary_location_id ~Aurynn
$query = qq|
INSERT INTO company
- (entity_id, entity_class_id, legal_name,
- primary_location_id, tax_id)
+ (entity_id, legal_name, tax_id)
VALUES
- (?, ?, ?, ?, ?)
+ (?, ?, ?)
|;
$sth = $dbh->prepare($query) || $form->dberror($query);
- $sth->execute($form->{entity_id}, $form->{entity_class},
+ $sth->execute($form->{entity_id}, # $form->{entity_class}, # removed entity_class_id ~Aurynn
$form->{name},
- $form->{location_id}, $form->{taxnumber});
+ # $form->{location_id}, # removed by ~aurynn
+ $form->{taxnumber});
#Creating customer record
$query = qq|
INSERT INTO customer
@@ -331,7 +335,7 @@ sub save_customer {
my ( $self, $myconfig, $form ) = @_;
- # connect to database
+ # connect to databaseĀµ
my $dbh = $form->{dbh};
my $query;
my $sth;
diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm
index 4a2d0a65..7d263fdd 100644
--- a/LedgerSMB/Form.pm
+++ b/LedgerSMB/Form.pm
@@ -1201,10 +1201,11 @@ sub get_name {
my $name = $self->like( lc $self->{$table} );
my $query = qq|
- SELECT * FROM $table
- WHERE (lower(name) LIKE ? OR ${table}number LIKE ?)
+ SELECT * FROM $table t
+ JOIN entity e ON t.entity_id = e.id
+ WHERE (lower(e.name) LIKE ? OR t.${table}number LIKE ?)
$where
- ORDER BY name|;
+ ORDER BY e.name|;
unshift( @queryargs, $name, $name );
my $sth = $self->{dbh}->prepare($query);
@@ -1726,7 +1727,7 @@ sub lastname_used {
$where = "AND $where " if $where;
$inv_notes = "ct.invoice_notes," if $vc eq 'customer';
my $query = qq|
- SELECT entity.name, ct.curr AS currency, ct.id AS ${vc}_id,
+ SELECT entity.name, ct.curr AS currency, entity_id AS ${vc}_id,
current_date + ct.terms AS duedate,
$inv_notes
ct.curr AS currency
diff --git a/LedgerSMB/IR.pm b/LedgerSMB/IR.pm
index d651a520..ff0b2704 100644
--- a/LedgerSMB/IR.pm
+++ b/LedgerSMB/IR.pm
@@ -1044,7 +1044,8 @@ sub retrieve_invoice {
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
+ a.vendor_id, a.language_code, a.ponumber,
+ a.on_hold
FROM ap a
WHERE id = ?|;
$sth = $dbh->prepare($query);
@@ -1375,5 +1376,39 @@ sub item_links {
$sth->finish;
}
-1;
+sub toggle_on_hold {
+
+ my $self = shift @_;
+ my $form = shift @_;
+
+ if ($form->{id}) { # it's an existing (.. probably) invoice.
+
+ my $dbh = $form->{dbh};
+ my $sth = $dbh->prepare("SELECT on_hold from ar where ar.id = ?");
+ $sth->execute($form->{id});
+ my $state = $sth->fetchrow_array;
+ my $sth;
+ my $n_s; # new state
+ if ($state[0] == 't') {
+
+ # Turn it off
+ $n_s = 'f';
+
+ } else {
+ $n_s = 't';
+ }
+
+ my $sth = $dbh->prepare("update ar set on_hold = ?::boolean where ar.id = ?");
+ my $code = $dbh->execute($ns, $form->{id});
+
+ return 1;
+
+ } else { # This shouldn't even be possible, but check for it anyway.
+
+ # Definitely, DEFINITELY check it.
+ # happily return 0. Find out about proper error states.
+ return 0;
+ }
+}
+1; \ No newline at end of file
diff --git a/LedgerSMB/IS.pm b/LedgerSMB/IS.pm
index 42fb5a2b..3ffbc1ed 100644
--- a/LedgerSMB/IS.pm
+++ b/LedgerSMB/IS.pm
@@ -1759,7 +1759,8 @@ sub retrieve_invoice {
a.duedate, a.taxincluded, a.curr AS currency,
a.employee_id, e.name AS employee, a.till,
a.entity_id,
- a.language_code, a.ponumber
+ a.language_code, a.ponumber,
+ a.on_hold
FROM ar a
LEFT JOIN employee e ON (e.entity_id = a.employee_id)
WHERE a.id = ?|;
@@ -2039,5 +2040,44 @@ sub exchangerate_defaults {
}
+=pod
+
+=cut
+
+sub toggle_on_hold {
+
+ my $self = shift @_;
+ my $form = shift @_;
+
+ if ($form->{id}) { # it's an existing (.. probably) invoice.
+
+ my $dbh = $form->{dbh};
+ my $sth = $dbh->prepare("SELECT on_hold from ar where ar.id = ?");
+ $sth->execute($form->{id});
+ my $state = $sth->fetchrow_array;
+ my $sth;
+ my $n_s; # new state
+ if ($state[0] == 't') {
+
+ # Turn it off
+ $n_s = 'f';
+
+ } else {
+ $n_s = 't';
+ }
+
+ my $sth = $dbh->prepare("update ar set on_hold = ?::boolean where ar.id = ?");
+ my $code = $dbh->execute($ns, $form->{id});
+
+ return 1;
+
+ } else { # This shouldn't even be possible, but check for it anyway.
+
+ # Definitely, DEFINITELY check it.
+ # happily return 0. Find out about proper error states.
+ return 0;
+ }
+}
+
1;