summaryrefslogtreecommitdiff
path: root/LedgerSMB/PriceMatrix.pm
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-04-12 20:46:20 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-04-12 20:46:20 +0000
commitdf073d6e09c0f87fb2e88cc215ace843a5851d4a (patch)
tree1c15ce909d3e0353b21bbd909e6720fd485a3a53 /LedgerSMB/PriceMatrix.pm
parent65458125b8f3814fd6ef4d07b55ab69f62f5a528 (diff)
Formatting with Perltidy
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/branches/1.2@1068 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/PriceMatrix.pm')
-rw-r--r--LedgerSMB/PriceMatrix.pm254
1 files changed, 130 insertions, 124 deletions
diff --git a/LedgerSMB/PriceMatrix.pm b/LedgerSMB/PriceMatrix.pm
index c604e982..68fa5b12 100644
--- a/LedgerSMB/PriceMatrix.pm
+++ b/LedgerSMB/PriceMatrix.pm
@@ -1,8 +1,8 @@
#=====================================================================
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
# with permission.
@@ -14,7 +14,7 @@
# maintainers, and copyright holders, see the CONTRIBUTORS file.
#
# Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
-# Copyright (C) 2001
+# Copyright (C) 2001
#
# Author: DWS Systems Inc.
# Web: http://www.sql-ledger.org
@@ -23,30 +23,29 @@
#
#======================================================================
#
-# This file has undergone whitespace cleanup
-#
+# This file has undergone whitespace cleanup
+#
#======================================================================
#
# Price Matrix module
-#
+#
#
#======================================================================
package PriceMatrix;
sub price_matrix_query {
- my ($dbh, $form) = @_;
+ my ( $dbh, $form ) = @_;
- my $query;
- my $sth;
+ my $query;
+ my $sth;
- my @queryargs;
+ my @queryargs;
- if ($form->{customer_id}) {
- my $defaultcurrency = $form->{dbh}->quote(
- $form->{defaultcurrency});
- my $customer_id = $form->{dbh}->quote($form->{customer_id});
- $query = qq|
+ 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,
@@ -91,122 +90,129 @@ sub price_matrix_query {
ORDER BY customer_id DESC, pricegroup_id DESC,
pricebreak
|;
- $sth = $dbh->prepare($query) || $form->dberror($query);
- } elsif ($form->{vendor_id}) {
- my $vendor_id = $form->{dbh}->quote($form->{vendor_id});
- # price matrix and vendor's partnumber
- $query = qq|
+ $sth = $dbh->prepare($query) || $form->dberror($query);
+ }
+ elsif ( $form->{vendor_id} ) {
+ my $vendor_id = $form->{dbh}->quote( $form->{vendor_id} );
+
+ # price matrix and vendor's partnumber
+ $query = qq|
SELECT partnumber
FROM partsvendor
WHERE parts_id = ?
AND vendor_id = $vendor_id|;
- $sth = $dbh->prepare($query) || $form->dberror($query);
- }
-
- $sth;
-}
+ $sth = $dbh->prepare($query) || $form->dberror($query);
+ }
+ $sth;
+}
sub price_matrix {
- my ($pmh, $ref, $transdate, $decimalplaces, $form, $myconfig) = @_;
- $ref->{pricematrix} = "";
- my $customerprice;
- my $pricegroupprice;
- my $sellprice;
- my $mref;
- my %p = ();
-
- # 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)) {
-
- # check date
- if ($mref->{validfrom}) {
- next if $transdate < $form->datetonum(
- $myconfig, $mref->{validfrom});
- }
- 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};
-
- }
-
-
- if ($form->{vendor_id}) {
- $pmh->execute($ref->{id});
-
- $mref = $pmh->fetchrow_hashref(NAME_lc);
-
- 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}";
-
- }
+ my ( $pmh, $ref, $transdate, $decimalplaces, $form, $myconfig ) = @_;
+ $ref->{pricematrix} = "";
+ my $customerprice;
+ my $pricegroupprice;
+ my $sellprice;
+ my $mref;
+ my %p = ();
+
+ # 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) ) {
+
+ # check date
+ if ( $mref->{validfrom} ) {
+ next
+ if $transdate <
+ $form->datetonum( $myconfig, $mref->{validfrom} );
+ }
+ 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};
+
+ }
+
+ if ( $form->{vendor_id} ) {
+ $pmh->execute( $ref->{id} );
+
+ $mref = $pmh->fetchrow_hashref(NAME_lc);
+
+ 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;