Invoice create invocie item multible tax
This commit is contained in:
@ -323,22 +323,25 @@ class Items extends Controller
|
||||
$price = (double) $item['price'];
|
||||
$quantity = (double) $item['quantity'];
|
||||
|
||||
$item_tax_total= 0;
|
||||
$item_tax_total = 0;
|
||||
$item_sub_total = ($price * $quantity);
|
||||
|
||||
if (!empty($item['tax_id'])) {
|
||||
$tax = Tax::find($item['tax_id']);
|
||||
foreach ($item['tax_id'] as $tax_id) {
|
||||
$tax = Tax::find($tax_id);
|
||||
|
||||
$item_tax_total = (($price * $quantity) / 100) * $tax->rate;
|
||||
$item_tax = (($price * $quantity) / 100) * $tax->rate;
|
||||
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$item_tax = $item_tax - ($item_tax * ($discount / 100));
|
||||
}
|
||||
|
||||
$item_tax_total += $item_tax;
|
||||
}
|
||||
}
|
||||
|
||||
$sub_total += $item_sub_total;
|
||||
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$item_tax_total = $item_tax_total - ($item_tax_total * ($discount / 100));
|
||||
}
|
||||
|
||||
$tax_total += $item_tax_total;
|
||||
|
||||
$items[$key] = money($item_sub_total, $currency_code, true)->format();
|
||||
|
@ -14,6 +14,7 @@ use App\Models\Income\Customer;
|
||||
use App\Models\Income\Invoice;
|
||||
use App\Models\Income\InvoiceHistory;
|
||||
use App\Models\Income\InvoiceItem;
|
||||
use App\Models\Income\InvoiceItemTax;
|
||||
use App\Models\Income\InvoiceTotal;
|
||||
use App\Models\Income\InvoicePayment;
|
||||
use App\Models\Income\InvoiceStatus;
|
||||
@ -218,18 +219,32 @@ class Invoices extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$tax = $tax_id = 0;
|
||||
$item_tax = 0;
|
||||
$item_taxes = [];
|
||||
$invoice_item_taxes = [];
|
||||
|
||||
if (!empty($item['tax_id'])) {
|
||||
$tax_object = Tax::find($item['tax_id']);
|
||||
foreach ($item['tax_id'] as $tax_id) {
|
||||
$tax_object = Tax::find($tax_id);
|
||||
|
||||
$tax_id = $item['tax_id'];
|
||||
$item_taxes[] = $tax_id;
|
||||
|
||||
$tax = (((double) $item['price'] * (double) $item['quantity']) / 100) * $tax_object->rate;
|
||||
$tax = (((double) $item['price'] * (double) $item['quantity']) / 100) * $tax_object->rate;
|
||||
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$tax = $tax - ($tax * ($discount / 100));
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$tax = $tax - ($tax * ($discount / 100));
|
||||
}
|
||||
|
||||
$invoice_item_taxes[] = [
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'tax_id' => $tax_id,
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax,
|
||||
];
|
||||
|
||||
$item_tax += $tax;
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,29 +253,33 @@ class Invoices extends Controller
|
||||
$invoice_item['sku'] = $item_sku;
|
||||
$invoice_item['quantity'] = (double) $item['quantity'];
|
||||
$invoice_item['price'] = (double) $item['price'];
|
||||
$invoice_item['tax'] = $tax;
|
||||
$invoice_item['tax_id'] = $tax_id;
|
||||
$invoice_item['tax'] = $item_tax;
|
||||
$invoice_item['tax_id'] = 0;//(int) $item_taxes;
|
||||
$invoice_item['total'] = (double) $item['price'] * (double) $item['quantity'];
|
||||
|
||||
InvoiceItem::create($invoice_item);
|
||||
$invoice_item_created = InvoiceItem::create($invoice_item);
|
||||
|
||||
// Set taxes
|
||||
if (isset($tax_object)) {
|
||||
if (isset($taxes) && array_key_exists($tax_object->id, $taxes)) {
|
||||
$taxes[$tax_object->id]['amount'] += $tax;
|
||||
} else {
|
||||
$taxes[$tax_object->id] = [
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax
|
||||
];
|
||||
if ($invoice_item_taxes) {
|
||||
foreach ($invoice_item_taxes as $invoice_item_tax) {
|
||||
$invoice_item_tax['invoice_item_id'] = $invoice_item_created->id;
|
||||
|
||||
InvoiceItemTax::create($invoice_item_tax);
|
||||
|
||||
// Set taxes
|
||||
if (isset($taxes) && array_key_exists($invoice_item_tax['tax_id'], $taxes)) {
|
||||
$taxes[$invoice_item_tax['tax_id']]['amount'] += $invoice_item_tax['amount'];
|
||||
} else {
|
||||
$taxes[$invoice_item_tax['tax_id']] = [
|
||||
'name' => $invoice_item_tax['name'],
|
||||
'amount' => $invoice_item_tax['amount']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate totals
|
||||
$tax_total += $tax;
|
||||
$tax_total += $item_tax;
|
||||
$sub_total += $invoice_item['total'];
|
||||
|
||||
unset($tax_object);
|
||||
}
|
||||
}
|
||||
|
||||
@ -439,18 +458,32 @@ class Invoices extends Controller
|
||||
$item_sku = $item_object->sku;
|
||||
}
|
||||
|
||||
$tax = $tax_id = 0;
|
||||
$item_tax = 0;
|
||||
$item_taxes = [];
|
||||
$invoice_item_taxes = [];
|
||||
|
||||
if (!empty($item['tax_id'])) {
|
||||
$tax_object = Tax::find($item['tax_id']);
|
||||
foreach ($item['tax_id'] as $tax_id) {
|
||||
$tax_object = Tax::find($tax_id);
|
||||
|
||||
$tax_id = $item['tax_id'];
|
||||
$item_taxes[] = $tax_id;
|
||||
|
||||
$tax = (((double) $item['price'] * (double) $item['quantity']) / 100) * $tax_object->rate;
|
||||
$tax = (((double) $item['price'] * (double) $item['quantity']) / 100) * $tax_object->rate;
|
||||
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$tax = $tax - ($tax * ($discount / 100));
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$tax = $tax - ($tax * ($discount / 100));
|
||||
}
|
||||
|
||||
$invoice_item_taxes[] = [
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'tax_id' => $tax_id,
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax,
|
||||
];
|
||||
|
||||
$item_tax += $tax;
|
||||
}
|
||||
}
|
||||
|
||||
@ -460,24 +493,31 @@ class Invoices extends Controller
|
||||
$invoice_item['quantity'] = (double) $item['quantity'];
|
||||
$invoice_item['price'] = (double) $item['price'];
|
||||
$invoice_item['tax'] = $tax;
|
||||
$invoice_item['tax_id'] = $tax_id;
|
||||
$invoice_item['tax_id'] = 0;//$tax_id;
|
||||
$invoice_item['total'] = (double) $item['price'] * (double) $item['quantity'];
|
||||
|
||||
if (isset($tax_object)) {
|
||||
if (isset($taxes) && array_key_exists($tax_object->id, $taxes)) {
|
||||
$taxes[$tax_object->id]['amount'] += $tax;
|
||||
} else {
|
||||
$taxes[$tax_object->id] = [
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax
|
||||
];
|
||||
$invoice_item_created = InvoiceItem::create($invoice_item);
|
||||
|
||||
if ($invoice_item_taxes) {
|
||||
foreach ($invoice_item_taxes as $invoice_item_tax) {
|
||||
$invoice_item_tax['invoice_item_id'] = $invoice_item_created->id;
|
||||
|
||||
InvoiceItemTax::create($invoice_item_tax);
|
||||
|
||||
// Set taxes
|
||||
if (isset($taxes) && array_key_exists($invoice_item_tax['tax_id'], $taxes)) {
|
||||
$taxes[$invoice_item_tax['tax_id']]['amount'] += $invoice_item_tax['amount'];
|
||||
} else {
|
||||
$taxes[$invoice_item_tax['tax_id']] = [
|
||||
'name' => $invoice_item_tax['name'],
|
||||
'amount' => $invoice_item_tax['amount']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tax_total += $tax;
|
||||
$tax_total += $item_tax;
|
||||
$sub_total += $invoice_item['total'];
|
||||
|
||||
InvoiceItem::create($invoice_item);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user