This topic is locked
[SOLVED]

 Once again about Total

7/5/2010 3:54:46 AM
PHPRunner General questions
B
bangke author

How i calculate ExtendedPrice with this formula:

*UnitPrice = UnitPrice Quantity - Discount*, where discount field is percentage
I have tried to add this code to
Before record Added and before record updated* bi it was not works :

$values["ExtendedPrice"] = $values["UnitPrice"] * $values["Quantity"] - ($values["Discount"];


For example :

UnitPrice : 1000

Quantity : 10

Discount :10%
ExtendedPrice should be : 9000

A
ann 7/5/2010

Hi,
try this code:

$values["ExtendedPrice"] = $values["UnitPrice"] * $values["Quantity"] - $values["Discount"];



Also make sure you use correct field names.

B
bangke author 7/5/2010



Hi,
try this code:

$values["ExtendedPrice"] = $values["UnitPrice"] * $values["Quantity"] - $values["Discount"];



Also make sure you use correct field names.


Thanks Ann but it seems i have problem with MySQL Datatype for percentage :

I use decimal(4,3) for Discount Datatype.

I also tried to use VIEW AS % PERCENT in the visual editor for the field Percentage but it not works.
Can you suggest another solution?

A
ann 7/5/2010

Hi,
it's difficult to tell you what's happening without seeing actual files.

Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error. 'Demo Account' button can be found on the last screen in the program.

S
swanside 7/5/2010



Hi,
it's difficult to tell you what's happening without seeing actual files.

Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error. 'Demo Account' button can be found on the last screen in the program.


I use a similar formular in my Invoiceing table. Try something like this in your SQL editor.
It might not work due to the select sum, as mine goes across different tables, so you may have to play around with it.
SELECT

UnitPrice,

Quantity,

Discount,

IFNULL((select sum(QuantityUnitPrice-(QuantityUnitPrice-Discount/100))), 0) AS ExtendedPrice,
Or
SELECT

UnitPrice,

Quantity,

Discount,

IFNULL((select Quantity
UnitPrice-(QuantityUnitPrice-Discount/100)), 0) AS ExtendedPrice,
This should give something like this, The first part should come to;

QuantityUnitPrice = 1010=100
The second part should come to;

QuantityUnitPrice-Discount/100 = 1010-10/100=10

So this should show the discount as 10 and the Extended Price = 90

I think, I have not tried it,but can try tomorrow on a database.

S
swanside 7/6/2010



I use a similar formular in my Invoiceing table. Try something like this in your SQL editor.
It might not work due to the select sum, as mine goes across different tables, so you may have to play around with it.
SELECT

UnitPrice,

Quantity,

Discount,

IFNULL((select sum(QuantityUnitPrice-(QuantityUnitPrice-Discount/100))), 0) AS ExtendedPrice,
Or
SELECT

UnitPrice,

Quantity,

Discount,

IFNULL((select Quantity
UnitPrice-(QuantityUnitPrice-Discount/100)), 0) AS ExtendedPrice,
This should give something like this, The first part should come to;

QuantityUnitPrice = 1010=100
The second part should come to;

QuantityUnitPrice-Discount/100 = 1010-10/100=10

So this should show the discount as 10 and the Extended Price = 90

I think, I have not tried it,but can try tomorrow on a database.


Just tried this and found it works OK
SELECT

Quantity,

UnitPrice,

Discount,

IFNULL((SELECT ROUND(sum(QuantityUnitPrice+(QuantityUnitPrice-Discount/100)),2)), 0) AS ExtendedPrice

FROM test
Here is the table
-- phpMyAdmin SQL Dump

-- version 3.2.5

-- http://www.phpmyadmin.net

--

-- Host: localhost

-- Generation Time: Jul 06, 2010 at 01:54 PM

-- Server version: 5.1.34

-- PHP Version: 5.2.9-2
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/
!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;

/
!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;

/
!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;

/
!40101 SET NAMES utf8 */;
--

-- Database: test

--
-- --------------------------------------------------------
--

-- Table structure for table test

--
CREATE TABLE IF NOT EXISTS test (

Quantity varchar(10) NOT NULL,

UnitPrice varchar(10) NOT NULL,

Discount varchar(10) NOT NULL,

PRIMARY KEY (Quantity)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--

-- Dumping data for table test

--
INSERT INTO test (Quantity, UnitPrice, Discount) VALUES

('10', '10', '10');

romaldus 7/6/2010



How i calculate ExtendedPrice with this formula:

*UnitPrice = UnitPrice Quantity - Discount*, where discount field is percentage
I have tried to add this code to
Before record Added and before record updated* bi it was not works :

$values["ExtendedPrice"] = $values["UnitPrice"] * $values["Quantity"] - ($values["Discount"];


For example :

UnitPrice : 1000

Quantity : 10

Discount :10%
ExtendedPrice should be : 9000


I have tested this one and it works :

$values["ExtendedPrice"] = ($values["UnitPrice"] * $values["Quantity"]) - (($values["Discount"]/100)*($values["UnitPrice"] * $values["Quantity"]));
B
bangke author 7/6/2010

Thanks, both swanside's and Romaldus' solvied the problem <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=51028&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=51028&image=2&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=51028&image=3&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />

romaldus 7/7/2010



I have tested this one and it works :

$values["ExtendedPrice"] = ($values["UnitPrice"] * $values["Quantity"]) - (($values["Discount"]/100)*($values["UnitPrice"] * $values["Quantity"]));



BTW, anyone can simplify the code above? it's too long <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=51042&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

S
swanside 7/7/2010

Just do it in the edit SQL query.
You can see if it works in there by clicking on results.