Permalink
Browse files

also link to ir/is from payment

  • Loading branch information...
1 parent a739d15 commit e7104e67e53c358588684b30b34ff23ed984f5f1 tshvr committed Dec 29, 2011
Showing with 41 additions and 9 deletions.
  1. +1 −1 LedgerSMB/DBObject/Customer.pm
  2. +1 −1 LedgerSMB/DBObject/Vendor.pm
  3. +34 −3 scripts/payment.pl
  4. +5 −4 sql/modules/Payment.sql
@@ -28,7 +28,7 @@ package LedgerSMB::DBObject::Customer;
use base qw(LedgerSMB::DBObject::Company);
use strict;
-my $ENTITY_CLASS = 2;
+our $ENTITY_CLASS = 2;
sub set_entity_class {
@@ -29,7 +29,7 @@ package LedgerSMB::DBObject::Vendor;
use base qw(LedgerSMB::DBObject::Company);
use strict;
-my $ENTITY_CLASS = 1;
+our $ENTITY_CLASS = 1;
sub set_entity_class {
my $self = shift @_;
View
@@ -51,6 +51,8 @@ package LedgerSMB::Scripts::payment;
use LedgerSMB::Sysconfig;
use LedgerSMB::DBObject::Payment;
use LedgerSMB::DBObject::Date;
+use LedgerSMB::DBObject::Customer;
+use LedgerSMB::DBObject::Vendor;
use LedgerSMB::CancelFurtherProcessing;
use Error::Simple;
use Error;
@@ -975,9 +977,38 @@ sub payment2 {
}
#print STDERR localtime()." payment.pl array=".Data::Dumper::Dumper($array_options[$ref])."\n";
my $paid_formatted=$Payment->format_amount(amount=>($array_options[$ref]->{amount} - $array_options[$ref]->{due} - $array_options[$ref]->{discount}));
-#Now its time to build the link to the invoice :)
-my $uri = $Payment->{account_class} == 1 ? 'ap' : 'ar';
-$uri .= '.pl?action=edit&id='.$array_options[$ref]->{invoice_id}.'&path=bin/mozilla&login='.$request->{login};
+ #Now its time to build the link to the invoice :)
+ my $uri_module;
+ #TODO move following code to sub getModuleForUri() ?
+ if($Payment->{account_class} == $LedgerSMB::DBObject::Vendor::ENTITY_CLASS)
+ {
+ if($array_options[$ref]->{invoice})
+ {
+ $uri_module='ir';
+ }
+ else
+ {
+ $uri_module='ap';
+ }
+ }#account_class 1
+ elsif($Payment->{account_class} == $LedgerSMB::DBObject::Customer::ENTITY_CLASS)
+ {
+ if($array_options[$ref]->{invoice})
+ {
+ $uri_module='is';
+ }
+ else
+ {
+ $uri_module='ar';
+ }
+ }#account_class 2
+ else
+ {
+ #TODO
+ $uri_module='??';
+ }
+#my $uri = $Payment->{account_class} == 1 ? 'ap' : 'ar';
+ my $uri =$uri_module.'.pl?action=edit&id='.$array_options[$ref]->{invoice_id}.'&path=bin/mozilla&login='.$request->{login};
push @invoice_data, { invoice => { number => $array_options[$ref]->{invnumber},
id => $array_options[$ref]->{invoice_id},
View
@@ -125,6 +125,7 @@ DROP TYPE IF EXISTS payment_invoice CASCADE;
CREATE TYPE payment_invoice AS (
invoice_id int,
invnumber text,
+ invoice bool,
invoice_date date,
amount numeric,
amount_fx numeric,
@@ -149,7 +150,7 @@ $$
DECLARE payment_inv payment_invoice;
BEGIN
FOR payment_inv IN
- SELECT a.id AS invoice_id, a.invnumber AS invnumber,
+ SELECT a.id AS invoice_id, a.invnumber AS invnumber,a.invoice AS invoice,
a.transdate AS invoice_date, a.amount AS amount,
a.amount/
(CASE WHEN a.curr = (SELECT * from defaults_get_defaultcurrency())
@@ -198,13 +199,13 @@ BEGIN
END) AS exchangerate
--TODO HV prepare drop entity_id from ap,ar
--FROM (SELECT id, invnumber, transdate, amount, entity_id,
- FROM (SELECT id, invnumber, transdate, amount,
+ FROM (SELECT id, invnumber, invoice, transdate, amount,
1 as invoice_class, paid, curr,
entity_credit_account, department_id, approved
FROM ap
UNION
--SELECT id, invnumber, transdate, amount, entity_id,
- SELECT id, invnumber, transdate, amount,
+ SELECT id, invnumber, invoice, transdate, amount,
2 AS invoice_class, paid, curr,
entity_credit_account, department_id, approved
FROM ar
@@ -239,7 +240,7 @@ BEGIN
OR in_department_id IS NULL)
AND due <> 0
AND a.approved = true
- GROUP BY a.invnumber, a.transdate, a.amount, amount_fx, discount, discount_fx, ac.due, a.id, c.discount_terms, ex.buy, ex.sell, a.curr
+ GROUP BY a.invnumber, a.transdate, a.amount, amount_fx, discount, discount_fx, ac.due, a.id, c.discount_terms, ex.buy, ex.sell, a.curr, a.invoice
LOOP
RETURN NEXT payment_inv;
END LOOP;

0 comments on commit e7104e6

Please sign in to comment.