Add more work on InvoiceCreator

This commit is contained in:
Kendrick Chan 2018-02-01 23:12:50 +08:00
parent 85a0f972c7
commit 687f1b0ff9

View file

@ -8,6 +8,8 @@ use App\Entity\Invoice;
use App\Entity\InvoiceItem; use App\Entity\InvoiceItem;
use App\Entity\User; use App\Entity\User;
use Doctrine\Common\Util\Debug;
class InvoiceCreator class InvoiceCreator
{ {
const VAT_RATE = 0.12; const VAT_RATE = 0.12;
@ -65,6 +67,13 @@ class InvoiceCreator
$total['vat_ex_price'] += $vat_ex_price; $total['vat_ex_price'] += $vat_ex_price;
$total['total_price'] += $sell_price; $total['total_price'] += $sell_price;
// add item
$item = new InvoiceItem();
$item->setInvoice($invoice)
->setTitle($batt->getModel() . ' ' . $batt->getSize())
->setQuantity(1)
->setPrice($sell_price);
} }
// get trade-ins // get trade-ins
@ -76,6 +85,13 @@ class InvoiceCreator
$total['ti_rate'] += $ti_rate; $total['ti_rate'] += $ti_rate;
$total['total_price'] -= $ti_rate; $total['total_price'] -= $ti_rate;
// add item
$item = new InvoiceItem();
$item->setInvoice($invoice)
->setTitle('Trade-in battery')
->setQuantity(1)
->setPrice($ti_rate);
} }
// TODO: check if any promo is applied // TODO: check if any promo is applied
@ -86,6 +102,10 @@ class InvoiceCreator
->setVAT($total['vat']) ->setVAT($total['vat'])
->setDiscount($total['ti_rate']); ->setDiscount($total['ti_rate']);
// dump
Debug::dump($invoice, 1);
return $invoice; return $invoice;
} }
} }