[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[2270] branches/1.2
- Subject: SF.net SVN: ledger-smb:[2270] branches/1.2
- From: ..hidden..
- Date: Sat, 16 Aug 2008 20:56:11 +0000
Revision: 2270
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2270&view=rev
Author: einhverfr
Date: 2008-08-16 20:56:10 +0000 (Sat, 16 Aug 2008)
Log Message:
-----------
* Fixing price matrix logic (1897245)
Modified Paths:
--------------
branches/1.2/LedgerSMB/IC.pm
branches/1.2/LedgerSMB/IR.pm
branches/1.2/LedgerSMB/IS.pm
branches/1.2/LedgerSMB/PriceMatrix.pm
branches/1.2/LedgerSMB/Sysconfig.pm
branches/1.2/bin/ic.pl
Modified: branches/1.2/LedgerSMB/IC.pm
===================================================================
--- branches/1.2/LedgerSMB/IC.pm 2008-08-16 18:30:10 UTC (rev 2269)
+++ branches/1.2/LedgerSMB/IC.pm 2008-08-16 20:56:10 UTC (rev 2270)
@@ -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: branches/1.2/LedgerSMB/IR.pm
===================================================================
--- branches/1.2/LedgerSMB/IR.pm 2008-08-16 18:30:10 UTC (rev 2269)
+++ branches/1.2/LedgerSMB/IR.pm 2008-08-16 20:56:10 UTC (rev 2270)
@@ -1165,6 +1165,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->{fxsellprice} =~ /\.(\d+)/ );
@@ -1189,8 +1191,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;
@@ -1289,6 +1289,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+)/ );
@@ -1306,8 +1308,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: branches/1.2/LedgerSMB/IS.pm
===================================================================
--- branches/1.2/LedgerSMB/IS.pm 2008-08-16 18:30:10 UTC (rev 2269)
+++ branches/1.2/LedgerSMB/IS.pm 2008-08-16 20:56:10 UTC (rev 2270)
@@ -1977,6 +1977,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);
my ($dec) = ( $ref->{fxsellprice} =~ /\.(\d+)/ );
$dec = length $dec;
@@ -1997,8 +1999,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}
@@ -2104,6 +2104,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+)/ );
@@ -2122,8 +2124,6 @@
chop $ref->{taxaccounts};
# get matrix
- PriceMatrix::price_matrix( $pmh, $ref, $transdate, $decimalplaces,
- $form, $myconfig );
$ref->{description} = $ref->{translation}
if $ref->{translation};
Modified: branches/1.2/LedgerSMB/PriceMatrix.pm
===================================================================
--- branches/1.2/LedgerSMB/PriceMatrix.pm 2008-08-16 18:30:10 UTC (rev 2269)
+++ branches/1.2/LedgerSMB/PriceMatrix.pm 2008-08-16 20:56:10 UTC (rev 2270)
@@ -41,54 +41,55 @@
my $sth;
my @queryargs;
+ my $transdate = $form->{dbh}->quote( $form->{transdate} );
if ( $form->{customer_id} ) {
my $defaultcurrency = $form->{dbh}->quote( $form->{defaultcurrency} );
my $customer_id = $form->{dbh}->quote( $form->{customer_id} );
$query = qq|
- SELECT p.id AS parts_id, 0 AS customer_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, p.pricegroup_id,
+ SELECT p.parts_id, p.customer_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 = $customer_id
+ AND coalesce(p.validfrom, $transdate) <=
+ $transdate
+ AND coalesce(p.validto, $transdate) >=
+ $transdate
+ AND p.customer_id = $customer_id
UNION
SELECT p.parts_id, p.customer_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 pricegroup g ON (g.id = p.pricegroup_id)
JOIN customer c ON (c.pricegroup_id = g.id)
WHERE p.parts_id = ?
- AND c.id = $customer_id
+ AND coalesce(p.validfrom, $transdate) <=
+ $transdate
+ AND coalesce(p.validto, $transdate) >=
+ $transdate
+ AND c.id = $customer_id
UNION
SELECT p.parts_id, p.customer_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 customer_id DESC, pricegroup_id DESC,
- pricebreak
+ ORDER BY priority LIMIT 1;
|;
$sth = $dbh->prepare($query) || $form->dberror($query);
}
@@ -97,10 +98,10 @@
# price matrix and vendor's partnumber
$query = qq|
- SELECT partnumber
+ SELECT partnumber, lastcost
FROM partsvendor
WHERE parts_id = ?
- AND vendor_id = $vendor_id|;
+ AND vendor_id = $vendor_id|;
$sth = $dbh->prepare($query) || $form->dberror($query);
}
@@ -109,7 +110,6 @@
sub price_matrix {
my ( $pmh, $ref, $transdate, $decimalplaces, $form, $myconfig ) = @_;
- $ref->{pricematrix} = "";
my $customerprice;
my $pricegroupprice;
my $sellprice;
@@ -118,103 +118,29 @@
# depends if this is a customer or vendor
if ( $form->{customer_id} ) {
- $pmh->execute( $ref->{id}, $ref->{id}, $ref->{id}, $ref->{id} );
+ $pmh->execute( $ref->{id}, $ref->{id}, $ref->{id} );
+ } elsif ( $form->{vendor_id} ) {
+ $pmh->execute( $ref->{id} );
+ } else {
+ $form->debug();
+ $form->error();
+ return;
+ }
- while ( $mref = $pmh->fetchrow_hashref(NAME_lc) ) {
-
+ if ( $mref = $pmh->fetchrow_hashref(NAME_lc) ) {
+ if ($form->{customer_id}){
$form->db_parse_numeric(sth=>$sth, hashref=>$mref);
- # check date
- if ( $mref->{validfrom} ) {
- next
- if $transdate <
- $form->datetonum( $myconfig, $mref->{validfrom} );
+ $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=>$sth, 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: branches/1.2/LedgerSMB/Sysconfig.pm
===================================================================
--- branches/1.2/LedgerSMB/Sysconfig.pm 2008-08-16 18:30:10 UTC (rev 2269)
+++ branches/1.2/LedgerSMB/Sysconfig.pm 2008-08-16 20:56:10 UTC (rev 2270)
@@ -15,7 +15,7 @@
$session = 'DB';
$logging = 0; # No logging on by default
-
+$max_post_size = 1024 * 1024; # Default to 1MB
@io_lineitem_columns = qw(unit onhand sellprice discount linetotal);
# Whitelist for redirect destination
Modified: branches/1.2/bin/ic.pl
===================================================================
--- branches/1.2/bin/ic.pl 2008-08-16 18:30:10 UTC (rev 2269)
+++ branches/1.2/bin/ic.pl 2008-08-16 20:56:10 UTC (rev 2270)
@@ -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.