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