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