Skip to content

Commit 685a71e

Browse files
committed
Makes validate() and calculate() methods public. resolves #173
1 parent 4b77d98 commit 685a71e

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/Traits/InvoiceHelpers.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public function totalTaxes(float $amount, bool $byPercent = false)
5858
throw new Exception('Invoice: unable to set tax twice.');
5959
}
6060

61-
$this->total_taxes = $amount;
62-
!$byPercent ?: $this->tax_rate = $amount;
61+
$this->total_taxes = $amount;
62+
! $byPercent ?: $this->tax_rate = $amount;
6363

6464
return $this;
6565
}
@@ -107,8 +107,8 @@ public function totalDiscount(float $total_discount, bool $byPercent = false)
107107
throw new Exception('Invoice: unable to set discount twice.');
108108
}
109109

110-
$this->total_discount = $total_discount;
111-
!$byPercent ?: $this->discount_percentage = $total_discount;
110+
$this->total_discount = $total_discount;
111+
! $byPercent ?: $this->discount_percentage = $total_discount;
112112

113113
return $this;
114114
}
@@ -213,31 +213,31 @@ public function getLogo()
213213
*/
214214
public function hasTax()
215215
{
216-
return !is_null($this->total_taxes);
216+
return ! is_null($this->total_taxes);
217217
}
218218

219219
/**
220220
* @return bool
221221
*/
222222
public function hasDiscount()
223223
{
224-
return !is_null($this->total_discount);
224+
return ! is_null($this->total_discount);
225225
}
226226

227227
/**
228228
* @return bool
229229
*/
230230
public function hasShipping()
231231
{
232-
return !is_null($this->shipping_amount);
232+
return ! is_null($this->shipping_amount);
233233
}
234234

235235
/**
236236
* @return bool
237237
*/
238238
public function hasTotalAmount()
239239
{
240-
return !is_null($this->total_amount);
240+
return ! is_null($this->total_amount);
241241
}
242242

243243
/**
@@ -258,9 +258,9 @@ public function hasItemOrInvoiceDiscount()
258258

259259
public function applyColspan(): void
260260
{
261-
(!$this->hasItemUnits) ?: $this->table_columns++;
262-
(!$this->hasItemDiscount) ?: $this->table_columns++;
263-
(!$this->hasItemTax) ?: $this->table_columns++;
261+
(! $this->hasItemUnits) ?: $this->table_columns++;
262+
(! $this->hasItemDiscount) ?: $this->table_columns++;
263+
(! $this->hasItemTax) ?: $this->table_columns++;
264264
}
265265

266266
public function calculateDiscount(): void
@@ -325,25 +325,25 @@ protected function beforeRender(): void
325325
/**
326326
* @throws Exception
327327
*/
328-
protected function validate()
328+
public function validate()
329329
{
330-
if (!$this->buyer) {
330+
if (! $this->buyer) {
331331
throw new Exception('Buyer not defined.');
332332
}
333333

334-
if (!$this->seller) {
334+
if (! $this->seller) {
335335
throw new Exception('Seller not defined.');
336336
}
337337

338-
if (!count($this->items)) {
338+
if (! count($this->items)) {
339339
throw new Exception('No items to invoice defined.');
340340
}
341341
}
342342

343343
/**
344344
* @return $this
345345
*/
346-
protected function calculate()
346+
public function calculate()
347347
{
348348
$total_amount = null;
349349
$total_discount = null;
@@ -362,7 +362,7 @@ function ($item) use (&$total_amount, &$total_discount, &$total_taxes) {
362362

363363
$item->calculate($this->currency_decimals);
364364

365-
(!$item->hasUnits()) ?: $this->hasItemUnits = true;
365+
(! $item->hasUnits()) ?: $this->hasItemUnits = true;
366366

367367
if ($item->hasDiscount()) {
368368
$total_discount += $item->discount;
@@ -389,7 +389,7 @@ function ($item) use (&$total_amount, &$total_discount, &$total_taxes) {
389389
$this->hasTotalAmount() ?: $this->total_amount = $total_amount;
390390
$this->hasDiscount() ? $this->calculateDiscount() : $this->total_discount = $total_discount;
391391
$this->hasTax() ? $this->calculateTax() : $this->total_taxes = $total_taxes;
392-
!$this->hasShipping() ?: $this->calculateShipping();
392+
! $this->hasShipping() ?: $this->calculateShipping();
393393

394394
return $this;
395395
}

0 commit comments

Comments
 (0)