[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[2271] trunk
- Subject: SF.net SVN: ledger-smb:[2271] trunk
- From: ..hidden..
- Date: Sat, 16 Aug 2008 21:12:35 +0000
Revision: 2271
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2271&view=rev
Author: einhverfr
Date: 2008-08-16 21:12:34 +0000 (Sat, 16 Aug 2008)
Log Message:
-----------
Manually merging in pricematrix changes for ticket 1897245 because codebase is too far off for automatic merge
Modified Paths:
--------------
trunk/LedgerSMB/IC.pm
trunk/LedgerSMB/IR.pm
trunk/LedgerSMB/IS.pm
trunk/LedgerSMB/PriceMatrix.pm
trunk/bin/ic.pl
Modified: trunk/LedgerSMB/IC.pm
===================================================================
--- trunk/LedgerSMB/IC.pm 2008-08-16 20:56:10 UTC (rev 2270)
+++ trunk/LedgerSMB/IC.pm 2008-08-16 21:12:34 UTC (rev 2271)
@@ -543,7 +543,7 @@
$form->parse_amount( $myconfig, $form->{"${_}_$i"} );
}
- if ( $form->{"customerprice_$i"} ) {
+ if ( $form->{"customerprice_$i"} || $form->{"pricebreak_$i"} ) {
( $null, $customer_id ) = split /--/, $form->{"customer_$i"};
$customer_id *= 1;
Modified: trunk/LedgerSMB/IR.pm
===================================================================
--- trunk/LedgerSMB/IR.pm 2008-08-16 20:56:10 UTC (rev 2270)
+++ trunk/LedgerSMB/IR.pm 2008-08-16 21:12:34 UTC (rev 2271)
@@ -1180,6 +1180,8 @@
my $ptref;
while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ PriceMatrix::price_matrix( $pmh, $ref, '', $decimalplaces, $form,
+ $myconfig );
$form->db_parse_numeric(sth=>$sth, hashref=>$ref);
$ref->{qty} *= -1 if $form->{reverse};
my ($dec) = ( $ref->{fxsellprice} =~ /\.(\d+)/ );
@@ -1204,8 +1206,6 @@
$form->round_amount(
$ref->{fxsellprice} * $form->{ $form->{currency} },
$decimalplaces );
- PriceMatrix::price_matrix( $pmh, $ref, $decimalplaces, $form,
- $myconfig );
$ref->{sellprice} = $ref->{fxsellprice};
$ref->{qty} *= -1;
@@ -1304,6 +1304,8 @@
my $ptref;
while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ PriceMatrix::price_matrix( $pmh, $ref, '', $decimalplaces, $form,
+ $myconfig );
$form->db_parse_numeric(sth=>$sth, hashref=>$ref);
my ($dec) = ( $ref->{sellprice} =~ /\.(\d+)/ );
@@ -1321,8 +1323,6 @@
chop $ref->{taxaccounts};
# get vendor price and partnumber
- PriceMatrix::price_matrix( $pmh, $ref, $decimalplaces, $form,
- $myconfig );
$ref->{description} = $ref->{translation}
if $ref->{translation};
Modified: trunk/LedgerSMB/IS.pm
===================================================================
--- trunk/LedgerSMB/IS.pm 2008-08-16 20:56:10 UTC (rev 2270)
+++ trunk/LedgerSMB/IS.pm 2008-08-16 21:12:34 UTC (rev 2271)
@@ -1996,6 +1996,8 @@
my $ptref;
while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ PriceMatrix::price_matrix( $pmh, $ref, $form->{transdate},
+ $decimalplaces, $form, $myconfig );
$form->db_parse_numeric(sth=>$sth, hashref => $ref);
$ref->{qty} *= -1 if $form->{reverse};
my ($dec) = ( $ref->{fxsellprice} =~ /\.(\d+)/ );
@@ -2017,8 +2019,6 @@
# price matrix
$ref->{sellprice} =
( $ref->{fxsellprice} * $form->{ $form->{currency} } );
- PriceMatrix::price_matrix( $pmh, $ref, $form->{transdate},
- $decimalplaces, $form, $myconfig );
$ref->{sellprice} = $ref->{fxsellprice};
$ref->{partsgroup} = $ref->{partsgrouptranslation}
@@ -2124,6 +2124,8 @@
my $transdate = $form->datetonum( $myconfig, $form->{transdate} );
while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) {
+ PriceMatrix::price_matrix( $pmh, $ref, $transdate, $decimalplaces,
+ $form, $myconfig );
$form->db_parse_numeric(sth => $sth, hashref => $ref);
my ($dec) = ( $ref->{sellprice} =~ /\.(\d+)/ );
@@ -2142,8 +2144,6 @@
chop $ref->{taxaccounts};
# get matrix
- PriceMatrix::price_matrix( $pmh, $ref, $transdate, $decimalplaces,
- $form, $myconfig );
$ref->{description} = $ref->{translation}
if $ref->{translation};
Modified: trunk/LedgerSMB/PriceMatrix.pm
===================================================================
--- trunk/LedgerSMB/PriceMatrix.pm 2008-08-16 20:56:10 UTC (rev 2270)
+++ trunk/LedgerSMB/PriceMatrix.pm 2008-08-16 21:12:34 UTC (rev 2271)
@@ -46,52 +46,52 @@
if ( $form->{customer_id} ) {
my $defaultcurrency = $form->{dbh}->quote( $form->{defaultcurrency} );
$query = qq|
- SELECT p.id AS parts_id, 0 AS entity_id,
- 0 AS pricegroup_id, 0 AS pricebreak,
- p.sellprice, NULL AS validfrom, NULL AS validto,
- (SELECT substr(value,1,3) FROM defaults WHERE
- setting_key = 'curr') AS curr,
- '' AS pricegroup
- FROM parts p
- WHERE p.id = ?
-
- UNION
-
SELECT p.parts_id, p.customer_id AS entity_id,
- p.pricegroup_id,
+ NULL AS pricegroup_id,
p.pricebreak, p.sellprice, p.validfrom,
- p.validto, p.curr, g.pricegroup
+ p.validto, p.curr, NULL AS pricegroup,
+ 1 as priority
FROM partscustomer p
- LEFT JOIN pricegroup g ON (g.id = p.pricegroup_id)
WHERE p.parts_id = ?
- AND p.customer_id = $entity_id
+ AND coalesce(p.validfrom, $transdate) <=
+ $transdate
+ AND coalesce(p.validto, $transdate) >=
+ $transdate
+ AND p.customer_id = $entity_id
UNION
- SELECT p.parts_id, p.customer_id AS entity_id,
+ SELECT p.parts_id, p.customer_id AS entity_id,
p.pricegroup_id,
p.pricebreak, p.sellprice, p.validfrom,
- p.validto, p.curr, g.pricegroup
+ p.validto, p.curr, g.pricegroup, 2 AS priority
FROM partscustomer p
- LEFT JOIN pricegroup g ON (g.id = p.pricegroup_id)
- JOIN entity_credit_account c ON (c.pricegroup_id = g.id)
+ JOIN pricegroup g ON (g.id = p.pricegroup_id)
+ JOIN customer c ON (c.pricegroup_id = g.id)
WHERE p.parts_id = ?
- AND c.entity_id = $entity_id
+ AND coalesce(p.validfrom, $transdate) <=
+ $transdate
+ AND coalesce(p.validto, $transdate) >=
+ $transdate
+ AND c.id = $entity_id
UNION
- SELECT p.parts_id, p.customer_id AS entity_id,
+ SELECT p.parts_id, p.customer_id AS entity_id,
p.pricegroup_id,
p.pricebreak, p.sellprice, p.validfrom,
- p.validto, p.curr, g.pricegroup
+ p.validto, p.curr, g.pricegroup, 3 AS priority
FROM partscustomer p
LEFT JOIN pricegroup g ON (g.id = p.pricegroup_id)
WHERE p.customer_id = 0
- AND p.pricegroup_id = 0
- AND p.parts_id = ?
+ AND p.pricegroup_id = 0
+ AND coalesce(p.validfrom, $transdate) <=
+ $transdate
+ AND coalesce(p.validto, $transdate) >=
+ $transdate
+ AND p.parts_id = ?
- ORDER BY entity_id DESC, pricegroup_id DESC,
- pricebreak
+ ORDER BY priority LIMIT 1;
|;
$sth = $dbh->prepare($query) || $form->dberror($query);
}
@@ -99,7 +99,7 @@
# price matrix and vendor's partnumber
$query = qq|
- SELECT partnumber
+ SELECT partnumber, lastcost
FROM partsvendor
WHERE parts_id = ?
AND entity_id = $entity_id|;
@@ -111,7 +111,6 @@
sub price_matrix {
my ( $pmh, $ref, $transdate, $decimalplaces, $form, $myconfig ) = @_;
- $ref->{pricematrix} = "";
my $customerprice;
my $pricegroupprice;
my $sellprice;
@@ -120,103 +119,27 @@
# depends if this is a customer or vendor
if ( $form->{customer_id} ) {
- $pmh->execute( $ref->{id}, $ref->{id}, $ref->{id}, $ref->{id} );
-
- while ( $mref = $pmh->fetchrow_hashref('NAME_lc') ) {
-
- $form->db_parse_numeric(sth=>$pmh, hashref=>$mref);
- # check date
- if ( $mref->{validfrom} ) {
- next
- if $transdate <
- $form->datetonum( $myconfig, $mref->{validfrom} );
+ $pmh->execute( $ref->{id}, $ref->{id}, $ref->{id} );
+ } elsif ( $form->{vendor_id} ) {
+ $pmh->execute( $ref->{id} );
+ } else {
+ $form->error('Invalid Form');
+ return;
+ }
+ if ( $mref = $pmh->fetchrow_hashref(NAME_lc) ) {
+ if ($form->{customer_id}){
+ $form->db_parse_numeric(sth=>$sth, hashref=>$mref);
+ $sellprice = $mref->{sellprice} || $ref->{sellprice};
+ if ($mref->{pricebreak}){
+ $sellprice = $sellprice
+ - ($sellprice * ($mref->{pricebreak} / 100));
}
- if ( $mref->{validto} ) {
- next
- if $transdate >
- $form->datetonum( $myconfig, $mref->{validto} );
- }
-
- # convert price
- $sellprice =
- $form->round_amount(
- $mref->{sellprice} * $form->{ $mref->{curr} },
- $decimalplaces );
-
- if ( $mref->{customer_id} ) {
- $ref->{sellprice} = $sellprice
- if !$mref->{pricebreak};
- $p{ $mref->{pricebreak} } = $sellprice;
- $customerprice = 1;
- }
-
- if ( $mref->{pricegroup_id} ) {
- if ( !$customerprice ) {
- $ref->{sellprice} = $sellprice
- if !$mref->{pricebreak};
- $p{ $mref->{pricebreak} } = $sellprice;
- }
- $pricegroupprice = 1;
- }
-
- if ( !$customerprice && !$pricegroupprice ) {
- $p{ $mref->{pricebreak} } = $sellprice;
- }
-
- }
- $pmh->finish;
-
- if (%p) {
- if ( $ref->{sellprice} ) {
- $p{0} = $ref->{sellprice};
- }
- for ( sort { $a <=> $b } keys %p ) {
- $ref->{pricematrix} .= "${_}:$p{$_} ";
- }
- }
- else {
- if ($init) {
- $ref->{sellprice} =
- $form->round_amount( $ref->{sellprice}, $decimalplaces );
- }
- else {
- $ref->{sellprice} =
- $form->round_amount(
- $ref->{sellprice} * ( 1 - $form->{tradediscount} ),
- $decimalplaces );
- }
- $ref->{pricematrix} = "0:$ref->{sellprice} "
- if $ref->{sellprice};
- }
- chop $ref->{pricematrix};
-
+ $ref->{sellprice} = $sellprice;
+ } elsif ($form->{vendor_id}){
+ $sellprice = $mref->{lastcost} || $ref->{sellprice};
+ $ref->{sellprice} = $sellprice;
+ }
}
- if ( $form->{vendor_id} ) {
- $pmh->execute( $ref->{id} );
-
- $mref = $pmh->fetchrow_hashref('NAME_lc');
- $form->db_parse_numeric(sth=>$pmh, hashref=>$mref);
-
- if ( $mref->{partnumber} ne "" ) {
- $ref->{partnumber} = $mref->{partnumber};
- }
-
- if ( $mref->{lastcost} ) {
-
- # do a conversion
- $ref->{sellprice} =
- $form->round_amount( $mref->{lastcost} * $form->{ $mref->{curr} },
- $decimalplaces );
- }
- $pmh->finish;
-
- $ref->{sellprice} *= 1;
-
- # add 0:price to matrix
- $ref->{pricematrix} = "0:$ref->{sellprice}";
-
- }
-
}
1;
Modified: trunk/bin/ic.pl
===================================================================
--- trunk/bin/ic.pl 2008-08-16 20:56:10 UTC (rev 2270)
+++ trunk/bin/ic.pl 2008-08-16 21:12:34 UTC (rev 2271)
@@ -3324,7 +3324,7 @@
$form->parse_amount( \%myconfig, $form->{"${_}_$i"} );
}
- if ( $form->{"customerprice_$i"} ) {
+ if ( $form->{"customerprice_$i"} || $form->{"pricebreak_$i"} ) {
if ( $form->{"pricebreak_$i"}
|| $form->{"customer_$i"}
|| $form->{"pricegroup_$i"} )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.