OXID eShop CE  4.9.5
 All Classes Files Functions Variables Pages
oxpricelist.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
16  protected $_aList = array();
17 
23  public function __construct()
24  {
25  }
26 
32  public function getBruttoSum()
33  {
34  $dSum = 0;
35  foreach ($this->_aList as $oPrice) {
36  $dSum += $oPrice->getBruttoPrice();
37  }
38 
39  return $dSum;
40  }
41 
47  public function getNettoSum()
48  {
49  $dSum = 0;
50  foreach ($this->_aList as $oPrice) {
51  $dSum += $oPrice->getNettoPrice();
52  }
53 
54  return $dSum;
55  }
56 
64  public function getSum($isNettoMode = true)
65  {
66  if ($isNettoMode) {
67  return $this->getNettoSum();
68  } else {
69  return $this->getBruttoSum();
70  }
71  }
72 
80  public function getVatInfo($isNettoMode = true)
81  {
82  $aVatValues = array();
83  $aPrices = array();
84  foreach ($this->_aList as $oPrice) {
85  $sKey = ( string ) $oPrice->getVat();
86  if (!isset($aPrices[$sKey])) {
87  $aPrices[$sKey]['sum'] = 0;
88  $aPrices[$sKey]['vat'] = $oPrice->getVat();
89  }
90  $aPrices[$sKey]['sum'] += $oPrice->getPrice();
91  }
92 
93  foreach ($aPrices as $sKey => $aPrice) {
94  if ($isNettoMode) {
95  $dPrice = $aPrice['sum'] * $aPrice['vat'] / 100;
96  } else {
97  $dPrice = $aPrice['sum'] * $aPrice['vat'] / (100 + $aPrice['vat']);
98  }
99  $aVatValues[$sKey] = $dPrice;
100  }
101 
102  return $aVatValues;
103  }
104 
105 
111  public function getPriceInfo()
112  {
113  $aPrices = array();
114  foreach ($this->_aList as $oPrice) {
115  $sVat = ( string ) $oPrice->getVat();
116  if (!isset($aPrices[$sVat])) {
117  $aPrices[$sVat] = 0;
118  }
119  $aPrices[$sVat] += $oPrice->getBruttoPrice();
120  }
121 
122  return $aPrices;
123  }
124 
131  public function getMostUsedVatPercent()
132  {
133  $aPrices = $this->getPriceInfo();
134  if (count($aPrices) == 0) {
135  return;
136  }
137 
138  $aVats = array_keys($aPrices, max($aPrices));
139 
140  return max($aVats);
141  }
142 
148  public function getProportionalVatPercent()
149  {
150  $dTotalSum = 0;
151 
152  foreach ($this->_aList as $oPrice) {
153  $dTotalSum += $oPrice->getNettoPrice();
154  }
155 
156  $dProportionalVat = 0;
157 
158  foreach ($this->_aList as $oPrice) {
159  if ($dTotalSum > 0) {
160  $dProportionalVat += $oPrice->getNettoPrice() / $dTotalSum * $oPrice->getVat();
161  }
162  }
163 
164  return $dProportionalVat;
165  }
166 
167 
173  public function addToPriceList($oPrice)
174  {
175  $this->_aList[] = $oPrice;
176  }
177 
183  public function calculateToPrice()
184  {
185  if (count($this->_aList) == 0) {
186  return;
187  }
188 
189  $dNetoTotal = 0;
190  $dVatTotal = 0;
191  $dVat = 0;
192 
193  foreach ($this->_aList as $oPrice) {
194  $dNetoTotal += $oPrice->getNettoPrice();
195  $dVatTotal += $oPrice->getVatValue();
196  }
197 
198  $oPrice = oxNew('oxPrice');
199 
200  if ($dNetoTotal) {
201  $dVat = $dVatTotal * 100 / $dNetoTotal;
202 
203  $oPrice->setNettoPriceMode();
204  $oPrice->setPrice($dNetoTotal);
205  $oPrice->setVat($dVat);
206  }
207 
208  return $oPrice;
209  }
210 
216  public function getCount()
217  {
218  return count($this->_aList);
219  }
220 }