Go to the documentation of this file.00001 <?php
00002
00008 class oxPriceList
00009 {
00015 protected $_aList = array();
00016
00022 public function __construct()
00023 {
00024 }
00025
00031 public function getBruttoSum()
00032 {
00033 $dSum = 0;
00034 foreach ( $this->_aList as $oPrice ) {
00035 $dSum += $oPrice->getBruttoPrice();
00036 }
00037
00038 return $dSum;
00039 }
00040
00046 public function getNettoSum()
00047 {
00048 $dSum = 0;
00049 foreach ( $this->_aList as $oPrice ) {
00050 $dSum += $oPrice->getNettoPrice();
00051 }
00052
00053 return $dSum;
00054 }
00055
00063 public function getSum( $isNettoMode = true )
00064 {
00065 if ( $isNettoMode ) {
00066 return $this->getNettoSum();
00067 } else {
00068 return $this->getBruttoSum();
00069 }
00070 }
00071
00079 public function getVatInfo( $isNettoMode = true )
00080 {
00081 $aVatValues = array();
00082 $aPrices = array();
00083 foreach ( $this->_aList as $oPrice ) {
00084 $sKey = ( string ) $oPrice->getVat();
00085 if ( !isset( $aPrices[$sKey] )) {
00086 $aPrices[$sKey]['sum'] = 0;
00087 $aPrices[$sKey]['vat'] = $oPrice->getVat();
00088 }
00089 $aPrices[$sKey]['sum'] += $oPrice->getPrice();
00090 }
00091
00092 foreach ( $aPrices as $sKey => $aPrice ) {
00093 if ( $isNettoMode ) {
00094 $dPrice = $aPrice['sum'] * $aPrice['vat'] / 100;
00095 } else {
00096 $dPrice = $aPrice['sum'] * $aPrice['vat'] / ( 100 + $aPrice['vat'] );
00097 }
00098 $aVatValues[$sKey] = $dPrice;
00099 }
00100
00101 return $aVatValues;
00102 }
00103
00104
00110 public function getPriceInfo()
00111 {
00112 $aPrices = array();
00113 foreach ( $this->_aList as $oPrice ) {
00114 $sVat = ( string ) $oPrice->getVat();
00115 if ( !isset( $aPrices[$sVat] )) {
00116 $aPrices[$sVat] = 0;
00117 }
00118 $aPrices[$sVat] += $oPrice->getBruttoPrice();
00119 }
00120
00121 return $aPrices;
00122 }
00123
00130 public function getMostUsedVatPercent()
00131 {
00132 $aPrices = $this->getPriceInfo();
00133 if ( count( $aPrices ) == 0 ) {
00134 return;
00135 }
00136
00137 $aVats = array_keys( $aPrices, max( $aPrices ) );
00138 return max( $aVats );
00139 }
00140
00146 public function getProportionalVatPercent()
00147 {
00148 $dTotalSum = 0;
00149
00150 foreach ( $this->_aList as $oPrice ) {
00151 $dTotalSum += $oPrice->getNettoPrice();
00152 }
00153
00154 $dProportionalVat = 0;
00155
00156 foreach ( $this->_aList as $oPrice ) {
00157 if ( $dTotalSum > 0 ) {
00158 $dProportionalVat += $oPrice->getNettoPrice() / $dTotalSum * $oPrice->getVat();
00159 }
00160 }
00161
00162 return $dProportionalVat;
00163 }
00164
00165
00166
00174 public function addToPriceList( $oPrice )
00175 {
00176 $this->_aList[] = $oPrice;
00177 }
00178
00184 public function calculateToPrice()
00185 {
00186 if ( count($this->_aList) == 0 ) {
00187 return;
00188 }
00189
00190 $dNetoTotal = 0;
00191 $dVatTotal = 0;
00192 $dVat = 0;
00193
00194 foreach ( $this->_aList as $oPrice ) {
00195 $dNetoTotal += $oPrice->getNettoPrice();
00196 $dVatTotal += $oPrice->getVatValue();
00197 }
00198
00199 $oPrice = oxNew('oxPrice');
00200
00201 if ( $dNetoTotal ) {
00202 $dVat = $dVatTotal*100/$dNetoTotal;
00203
00204 $oPrice->setNettoPriceMode();
00205 $oPrice->setPrice($dNetoTotal);
00206 $oPrice->setVat($dVat);
00207 }
00208
00209 return $oPrice;
00210 }
00211
00217 public function getCount()
00218 {
00219 return count($this->_aList);
00220 }
00221
00222 }