Location: PHPKode > scripts > Price Calculator > price-calculator/pricecalc.class.php
<?php
#################################################################
### Calcul Price v06-02-07 is class for calculate price params ##
### Author : Martin Sadera, www.e-d-a.info                     ##
### © 2006 All rights reserved for EDACMS system               ##
#################################################################
/*
functions list
DPH()                       - Get DPH value of price
DPH_f()                     - Get formated DPH value of price
WithDph()                   - Get price with Dph
WithDph_f()                 - Get formated price with Dph
WithoutDph()                - Get price without Dph
WithoutDph_f()              - Get formated price without Dph
QuantityWithDPH($quantity)  - Get price with Dph * quantity
QuantityWithDPH_f($quantity)- Get formated price with Dph * quantity
SavedMoneyWithoutDph()      - Get price without Dph - reduced price
SavedMoneyWithoutDph_f()    - Get formated price without Dph - reduced price without Dph
SavedMoneyWithDph()         - Get price with Dph - reduced price with Dph
SavedMoneyWithDph_f()       - Get formated price with Dph - reduced price with Dph
OldWithDph()                - Get old price with Dph
OldWithDph_f()              - Get formated old price with Dph
OldWithoutDph()             - Get old price without Dph
OldWithoutDph_f()           - Get formated old price without Dph
*/
class PriceCalc {
  var $price_with_dph=0;
  var $price_without_dph=0;
  var $price_dph=0;
  var $old_price_without_dph=0;
  var $old_price_with_dph=0;
  var $price_signature='';
  
  #calculate basic price types
  function PriceCalc ($price,$dph,$reduction=0,$price_signature='') {
    $this->price_signature=$price_signature;
    #reduce price if is set %
    if ($reduction>0) {
      $this->old_price_without_dph=$price;
      $this->old_price_with_dph=round($price+($price*($dph/100)),0);
      $price=$price-($price/$reduction);
      }
    
    #basic types
    $this->price_without_dph=$price;
    $this->price_with_dph=round($price+($price*($dph/100)),0);
    $this->price_dph=$this->price_with_dph-$this->price_without_dph;
    }
  
  #formating clasic float numbers (without Dph)
  function FormatNumber($value) {
    if ($this->price_signature!='') {
      //return number_format($value, 2, ',', '#')."&nbsp;".$this->price_signature;
      return str_replace("#","&nbsp;",number_format($value, 2, ',', '#')."&nbsp;".$this->price_signature);
      } else {
      //return number_format($value, 2, ',', '#');
      return str_replace("#","&nbsp;",number_format($value, 2, ',', '#'));
      }
    }
  
  #format rounded numbers (with Dph)
  function FormatNumberWithDPH($value) {
    if ($this->price_signature!='') {
      //return number_format($value, 0, ',', '#').",-&nbsp;".$this->price_signature
      return str_replace("#","&nbsp;",number_format($value, 0, ',', '#').",-&nbsp;".$this->price_signature);
      } else {
      //return number_format($value, 0, ',', '#').",-";
      return str_replace("#","&nbsp;",number_format($value, 0, ',', '#').",-");
      }
    }


  #old price without Dph formated
  function OldWithoutDph() {
    return $this->old_price_without_dph;
    }

  #old price without Dph formated
  function OldWithoutDph_f() {
    return $this->FormatNumber($this->old_price_without_dph);
    }
  
  #old price with Dph formated
  function OldWithDph_f() {
    return $this->FormatNumberWithDPH($this->old_price_with_dph);
    }
    
  #old price with Dph
  function OldWithDph() {
    return ($this->price_with_dph);
    }
  
  
  #quantity * price with DPH
  function QuantityWithDPH($quantity) {
    return ($this->price_with_dph*($quantity*1));  
    }
  
  #quantity * price with DPH
  function QuantityWithDPH_f($quantity) {
    return $this->FormatNumberWithDPH($this->price_with_dph*($quantity*1));  
    }
  
  #quantity * price without DPH
  function QuantityWithoutDPH($quantity) {
    return ($this->price_without_dph*($quantity*1));  
    }

  #quantity * price without DPH
  function QuantityWithoutDPH_f($quantity) {
    return $this->FormatNumberWithDPH($this->price_without_dph*($quantity*1));  
    }
  
  #get price with DPH formated
  function WithDPH_f() {
    return $this->FormatNumberWithDPH($this->price_with_dph);
    }
    
  #get price without DPH formated  
  function WithoutDPH_f() {
    return $this->FormatNumber($this->price_without_dph);
    }
  
  #get only DPH value formated
  function DPH_f() {
    return $this->FormatNumber($this->price_dph);
    }
  
  #get price with DPH
  function WithDPH() {
    return $this->price_with_dph;
    }
    
  #get price without DPH  
  function WithoutDPH() {
    return $this->price_without_dph;
    }
    
  #get only DPH value
  function DPH() {
    return $this->price_dph;
    }
  
  #money saved with DPH
  function SavedMoneyWithDPH_f() {
    if ($this->old_price_with_dph>0) {
      return $this->FormatNumberWithDPH($this->old_price_with_dph-$this->price_with_dph);
      } else {
      return 0;
      }
    }
    
  #money saved without DPH
  function SavedMoneyWithoutDPH_f() {
    if ($this->old_price_without_dph>0) {
      return $this->FormatNumber($this->old_price_without_dph-$this->price_without_dph);
      } else {
      return 0;
      }
    }
    
  #money saved without DPH
  function SavedMoneyWithoutDPH() {
    if ($this->old_price_without_dph>0) {
      return ($this->price_without_dph-$this->old_price_without_dph);
      } else {
      return 0;
      }
    }
    
  #money saved with DPH
  function SavedMoneyWithDPH() {
    if ($this->old_price_with_dph>0) {
      return ($this->price_with_dph-$this->old_price_with_dph);
      } else {
      return 0;
      }
    }
    

}
?>
Return current item: Price Calculator