[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[4035] trunk
- Subject: SF.net SVN: ledger-smb:[4035] trunk
- From: ..hidden..
- Date: Wed, 23 Nov 2011 08:23:12 +0000
Revision: 4035
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4035&view=rev
Author: einhverfr
Date: 2011-11-23 08:23:11 +0000 (Wed, 23 Nov 2011)
Log Message:
-----------
Merging from 1.3
Modified Paths:
--------------
trunk/LedgerSMB/DBObject/Company.pm
trunk/sql/modules/Company.sql
Property Changed:
----------------
trunk/
trunk/LedgerSMB/Scripts/admin.pm
trunk/LedgerSMB/Scripts/employee.pm
trunk/LedgerSMB/Scripts/payment.pm
trunk/LedgerSMB/Scripts/setup.pm
trunk/sql/upgrade/1.2-1.3-manual.sql
Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/1.3:3711-4030
+ /branches/1.3:3711-4034
Modified: trunk/LedgerSMB/DBObject/Company.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Company.pm 2011-11-23 08:19:32 UTC (rev 4034)
+++ trunk/LedgerSMB/DBObject/Company.pm 2011-11-23 08:23:11 UTC (rev 4035)
@@ -700,6 +700,61 @@
funcname => 'company__list_bank_account');
};
+=item get_pricematrix
+
+This routine gets the price matrix for the customer or vendor. The pricematrix
+info is stored in the pricematrix hash entry. If a customer (account_class=1),
+it also populates a pricematrix_pricegroup entry.
+
+=cut
+
+sub get_pricematrix {
+ my $self = shift @_;
+ @{$self->{pricematrix}} = $self->exec_method(
+ funcname => 'eca__get_pricematrix'
+ );
+ if ($self->{account_class} == 1){
+ @{$self->{pricematrix_pricegroup}}= $self->exec_method(
+ funcname => 'eca__get_pricematrix_by_pricegroup'
+ );
+ }
+}
+
+=item delete_pricematrix($entry_id)
+
+This deletes a pricematrix line identified by $entry_id
+
+=cut
+
+sub delete_pricematrix {
+ my $self = shift @_;
+ my ($entry_id) = @_;
+ my ($retval) = $self->exec_method(funcname => 'eca__delete_pricematrix',
+ args => [$self->{credit_id}, $entry_id]
+ );
+ return $retval;
+}
+
+
+=item save_pricematrix
+
+Updates or inserts the price matrix.
+
+=cut
+
+sub save_pricematrix {
+ my $self = shift @_;
+ for my $count (1 .. $self->{pm_rowcount}){
+ my $entry_id = $self->{"pm_$count"};
+ my @args = ();
+ for my $prop (qw()){
+ push @args, $self->{"${prop}_$entry_id"};
+ $self->execute_method(funcname => 'eca__save_pricematrix',
+ args => ..hidden..);
+ }
+ }
+}
+
=back
=head1 COPYRIGHT
Property changes on: trunk/LedgerSMB/Scripts/admin.pm
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/1.3/LedgerSMB/Scripts/admin.pm:3901-4030
/branches/1.3/scripts/admin.pl:3711-3903
+ /branches/1.3/LedgerSMB/Scripts/admin.pm:3901-4034
/branches/1.3/scripts/admin.pl:3711-3903
Property changes on: trunk/LedgerSMB/Scripts/employee.pm
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/1.3/LedgerSMB/Scripts/employee.pm:3712-4030
/branches/1.3/scripts/employee.pl:3842-3843
+ /branches/1.3/LedgerSMB/Scripts/employee.pm:3712-4034
/branches/1.3/scripts/employee.pl:3842-3843
Property changes on: trunk/LedgerSMB/Scripts/payment.pm
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/1.3/LedgerSMB/Scripts/payment.pm:4010-4030
/branches/1.3/scripts/payment.pl:3711-4011
+ /branches/1.3/LedgerSMB/Scripts/payment.pm:4010-4034
/branches/1.3/scripts/payment.pl:3711-4011
Property changes on: trunk/LedgerSMB/Scripts/setup.pm
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/1.3/LedgerSMB/Scripts/setup.pm:3937-4030
/branches/1.3/scripts/setup.pl:3711-3967
+ /branches/1.3/LedgerSMB/Scripts/setup.pm:3937-4034
/branches/1.3/scripts/setup.pl:3711-3967
Modified: trunk/sql/modules/Company.sql
===================================================================
--- trunk/sql/modules/Company.sql 2011-11-23 08:19:32 UTC (rev 4034)
+++ trunk/sql/modules/Company.sql 2011-11-23 08:23:11 UTC (rev 4035)
@@ -1332,7 +1332,20 @@
) IS
$$ Returns a list of all entity credit accounts attached to that entity.$$;
+-- pricematrix
+CREATE OR REPLACE FUNCTION eca__get_pricematrix_by_pricegroup(in_id int)
+RETURNS SETOF eca__pricematrix AS
+$$
+SELECT pc.parts_id, p.partnumber, p.description, pc.credit_id, pc.pricebreak,
+ pc.sellprice, NULL::numeric, NULL::int, NULL::text, pc.validfrom,
+ pc.validto, pc.curr, pc.entry_id
+ FROM partscustomer pc
+ JOIN parts p on pc.parts_id = p.id
+ JOIN entity_credit_account eca ON pc.pricegroup_id = eca.pricegroup_id
+ WHERE eca.id = $1 AND eca.entity_class = 2
+$$ LANGUAGE SQL;
+
CREATE OR REPLACE FUNCTION eca__get_pricematrix(in_id int)
RETURNS SETOF eca__pricematrix AS
$$
@@ -1356,4 +1369,232 @@
$$ language sql;
+COMMENT ON FUNCTION eca__get_pricematrix(in_id int) IS
+$$ This returns the pricematrix for the customer or vendor
+(entity_credit_account identified by in_id), orderd by partnumber, validfrom
+$$;
+
+CREATE OR REPLACE FUNCTION eca__delete_pricematrix
+(in_credit_id int, in_entry_id int)
+RETURNS BOOL AS
+$$
+DECLARE retval bool;
+
+BEGIN
+
+retval := false;
+
+DELETE FROM partsvendor
+ WHERE entry_id = in_entry_id
+ AND credit_id = in_credit_id;
+
+retval := FOUND;
+
+DELETE FROM partscustomer
+ WHERE entry_id = in_entry_id
+ AND credit_id = in_credit_id;
+
+RETURN FOUND or retval;
+
+END;
+$$ language plpgsql;
+
+CREATE OR REPLACE FUNCTION eca__save_pricematrix
+(in_parts_id int, in_credit_id int, in_pricebreak numeric, in_price numeric,
+ in_lead_time int2, in_partnumber text, in_validfrom date, in_validto date,
+ in_curr char(3), in_entry_id int)
+RETURNS eca__pricematrix AS
+$$
+DECLARE
+ retval eca__pricematrix;
+ t_insert bool;
+
+BEGIN
+
+t_insert := false;
+
+PERFORM * FROM entity_credit_account
+ WHERE id = in_credit_id AND entity_class = 1;
+
+IF FOUND THEN -- VENDOR
+ UPDATE partsvendor
+ SET lastcost = in_price,
+ leadtime = in_lead_time,
+ partnumber = in_partnumber,
+ curr = in_curr
+ WHERE credit_id = in_credit_id AND entry_id = in_entry_id;
+
+ IF NOT FOUND THEN
+ INSERT INTO partsvendor
+ (parts_id, credit_id, lastcost, leadtime, partnumber, curr)
+ VALUES (in_parts_id, in_credit_id, in_price, in_leadtime::int2,
+ in_partnumber, in_curr);
+ END IF;
+
+ SELECT pv.parts_id, p.partnumber, p.description, pv.credit_id, NULL, NULL,
+ pv.lastcost, pv.leadtime::int, pv.partnumber, NULL, NULL, pv.curr,
+ pv.entry_id
+ INTO retval
+ FROM partsvendor pv
+ JOIN parts p ON p.id = pv.parts_id
+ WHERE parts_id = in_parts_id and credit_id = in_credit_id;
+
+ RETURN retval;
+END IF;
+
+PERFORM * FROM entity_credit_account
+ WHERE id = in_credit_id AND entity_class = 2;
+
+IF FOUND THEN -- CUSTOMER
+ UPDATE partscustomer
+ SET pricebreak = in_pricebreak,
+ sellprice = in_price,
+ validfrom = in_validfrom,
+ validto = in_validto,
+ curr = in_curr
+ WHERE entry_id = in_entry_id and credit_id = in_credit_id;
+
+ IF NOT FOUND THEN
+ INSERT INTO partscustomer
+ (parts_id, credit_id, sellprice, validfrom, validto, curr)
+ VALUES (in_parts_id, in_credit_id, in_price, in_validfrom, in_validto,
+ in_curr);
+
+ t_insert := true;
+ END IF;
+
+ SELECT pc.parts_id, p.partnumber, p.description, pc.credit_id,
+ pc.pricebreak, pc.sellprice, NULL, NULL, NULL, pc.validfrom,
+ pc.validto, pc.curr, pc.entry_id
+ INTO retval
+ FROM partscustomer pc
+ JOIN parts p on pc.parts_id = p.id
+ WHERE entry_id = CASE WHEN t_insert
+ THEN currval('partscustomer_entry_id_seq')
+ ELSE in_entry_id
+ END;
+
+ RETURN retval;
+
+END IF;
+
+RAISE EXCEPTION 'No valid entity credit account found';
+
+END;
+$$ LANGUAGE PLPGSQL;
+
+COMMENT ON FUNCTION eca__get_pricematrix(in_id int) IS
+$$ This returns the pricematrix for the customer or vendor
+(entity_credit_account identified by in_id), orderd by partnumber, validfrom
+$$;
+
+CREATE OR REPLACE FUNCTION eca__delete_pricematrix
+(in_credit_id int, in_entry_id int)
+RETURNS BOOL AS
+$$
+DECLARE retval bool;
+
+BEGIN
+
+retval := false;
+
+DELETE FROM partsvendor
+ WHERE entry_id = in_entry_id
+ AND credit_id = in_credit_id;
+
+retval := FOUND;
+
+DELETE FROM partscustomer
+ WHERE entry_id = in_entry_id
+ AND credit_id = in_credit_id;
+
+RETURN FOUND or retval;
+
+END;
+$$ language plpgsql;
+
+CREATE OR REPLACE FUNCTION eca__save_pricematrix
+(in_parts_id int, in_credit_id int, in_pricebreak numeric, in_price numeric,
+ in_lead_time int2, in_partnumber text, in_validfrom date, in_validto date,
+ in_curr char(3), in_entry_id int)
+RETURNS eca__pricematrix AS
+$$
+DECLARE
+ retval eca__pricematrix;
+ t_insert bool;
+
+BEGIN
+
+t_insert := false;
+
+PERFORM * FROM entity_credit_account
+ WHERE id = in_credit_id AND entity_class = 1;
+
+IF FOUND THEN -- VENDOR
+ UPDATE partsvendor
+ SET lastcost = in_price,
+ leadtime = in_lead_time,
+ partnumber = in_partnumber,
+ curr = in_curr
+ WHERE credit_id = in_credit_id AND entry_id = in_entry_id;
+
+ IF NOT FOUND THEN
+ INSERT INTO partsvendor
+ (parts_id, credit_id, lastcost, leadtime, partnumber, curr)
+ VALUES (in_parts_id, in_credit_id, in_price, in_leadtime::int2,
+ in_partnumber, in_curr);
+ END IF;
+
+ SELECT pv.parts_id, p.partnumber, p.description, pv.credit_id, NULL, NULL,
+ pv.lastcost, pv.leadtime::int, pv.partnumber, NULL, NULL, pv.curr,
+ pv.entry_id
+ INTO retval
+ FROM partsvendor pv
+ JOIN parts p ON p.id = pv.parts_id
+ WHERE parts_id = in_parts_id and credit_id = in_credit_id;
+
+ RETURN retval;
+END IF;
+
+PERFORM * FROM entity_credit_account
+ WHERE id = in_credit_id AND entity_class = 2;
+
+IF FOUND THEN -- CUSTOMER
+ UPDATE partscustomer
+ SET pricebreak = in_pricebreak,
+ sellprice = in_price,
+ validfrom = in_validfrom,
+ validto = in_validto,
+ curr = in_curr
+ WHERE entry_id = in_entry_id and credit_id = in_credit_id;
+
+ IF NOT FOUND THEN
+ INSERT INTO partscustomer
+ (parts_id, credit_id, sellprice, validfrom, validto, curr)
+ VALUES (in_parts_id, in_credit_id, in_price, in_validfrom, in_validto,
+ in_curr);
+
+ t_insert := true;
+ END IF;
+
+ SELECT pc.parts_id, p.partnumber, p.description, pc.credit_id,
+ pc.pricebreak, pc.sellprice, NULL, NULL, NULL, pc.validfrom,
+ pc.validto, pc.curr, pc.entry_id
+ INTO retval
+ FROM partscustomer pc
+ JOIN parts p on pc.parts_id = p.id
+ WHERE entry_id = CASE WHEN t_insert
+ THEN currval('partscustomer_entry_id_seq')
+ ELSE in_entry_id
+ END;
+
+ RETURN retval;
+
+END IF;
+
+RAISE EXCEPTION 'No valid entity credit account found';
+
+END;
+$$ LANGUAGE PLPGSQL;
+
COMMIT;
Property changes on: trunk/sql/upgrade/1.2-1.3-manual.sql
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/1.3/sql/upgrade/1.2-1.3-manual.sql:3712-4030
/branches/1.3/sql/upgrade/1.2-1.3.sql:3711-3851
/trunk/sql/upgrade/1.2-1.3.sql:858-3710
+ /branches/1.3/sql/upgrade/1.2-1.3-manual.sql:3712-4034
/branches/1.3/sql/upgrade/1.2-1.3.sql:3711-3851
/trunk/sql/upgrade/1.2-1.3.sql:858-3710
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.