ConsoleTVs/Invoices

large figures upset the total

mbuk opened this issue · 5 comments

mbuk commented

The total price calculation breaks in here
(it's something to do with bcmul)
If the inputs to the method are:

$name = 'blah';
$price = '8,333.325';
$ammount = 1; 
$id = '';
$this->decimals is the default (2)

The output will return 0.00

public function addItem($name, $price, $ammount = 1, $id = '-')
  {
      $price = number_format($price, $this->decimals);

      $this->items->push(Collection::make([
          'name'       => $name,
          'price'      => $price,
          'ammount'    => $ammount,
          'totalPrice' => number_format(bcmul($price, $ammount, $this->decimals), $this->decimals),
          'id'         => $id,
      ]));

      return $this;
  }

BTW amount is mispelt here 😄

You can't have a coma in the price input.

I will work on fancier outputs but talking about php floats, the value must be:

$price = 8333.325;

Not:

$price = '8,333.325';
$price = '8333.325';
$price = '8.333,325';
mbuk commented

Yes indeed, that's already possible:

php artisan vendor:publish

location: at the vendor folder in resources/views/vendor/invoices

PS; Sorry for the poor docs, I will work on them

mbuk commented

You're welcome ^^