Merge pull request #1372 from burakcakirel/discount-per-item
Discount per Item
This commit is contained in:
commit
ea195221a9
@ -64,7 +64,7 @@ class CreateBill extends Job
|
||||
protected function createItemsAndTotals()
|
||||
{
|
||||
// Create items
|
||||
list($sub_total, $taxes) = $this->createItems();
|
||||
list($sub_total, $discount_amount_total, $taxes) = $this->createItems();
|
||||
|
||||
$sort_order = 1;
|
||||
|
||||
@ -83,8 +83,23 @@ class CreateBill extends Job
|
||||
$sort_order++;
|
||||
|
||||
// Add discount
|
||||
if ($discount_amount_total > 0) {
|
||||
BillTotal::create([
|
||||
'company_id' => $this->bill->company_id,
|
||||
'bill_id' => $this->bill->id,
|
||||
'code' => 'item_discount',
|
||||
'name' => 'bills.item_discount',
|
||||
'amount' => $discount_amount_total,
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$this->request['amount'] -= $discount_amount_total;
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
|
||||
if (!empty($this->request['discount'])) {
|
||||
$discount_total = $sub_total * ($this->request['discount'] / 100);
|
||||
$discount_total = ($sub_total - $discount_amount_total) * ($this->request['discount'] / 100);
|
||||
|
||||
BillTotal::create([
|
||||
'company_id' => $this->bill->company_id,
|
||||
@ -155,7 +170,7 @@ class CreateBill extends Job
|
||||
|
||||
protected function createItems()
|
||||
{
|
||||
$sub_total = 0;
|
||||
$sub_total = $discount_amount = $discount_amount_total = 0;
|
||||
|
||||
$taxes = [];
|
||||
|
||||
@ -170,8 +185,14 @@ class CreateBill extends Job
|
||||
|
||||
$bill_item = $this->dispatch(new CreateBillItem($item, $this->bill));
|
||||
|
||||
$item_amount = (double) $item['price'] * (double) $item['quantity'];
|
||||
|
||||
$discount_amount = ($item_amount * ($item['discount'] / 100));
|
||||
|
||||
// Calculate totals
|
||||
$sub_total += $bill_item->total;
|
||||
$sub_total += $bill_item->total + $discount_amount;
|
||||
|
||||
$discount_amount_total += $discount_amount;
|
||||
|
||||
if (!$bill_item->item_taxes) {
|
||||
continue;
|
||||
@ -190,6 +211,6 @@ class CreateBill extends Job
|
||||
}
|
||||
}
|
||||
|
||||
return [$sub_total, $taxes];
|
||||
return [$sub_total, $discount_amount_total, $taxes];
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class CreateBillItem extends Job
|
||||
|
||||
// Apply discount to amount
|
||||
if (!empty($this->request['discount'])) {
|
||||
$item_discounted_amount = $item_amount - ($item_amount * ($this->request['discount'] / 100));
|
||||
$item_discounted_amount = $item_amount -= ($item_amount * ($this->request['discount'] / 100));
|
||||
}
|
||||
|
||||
$tax_amount = 0;
|
||||
@ -138,6 +138,7 @@ class CreateBillItem extends Job
|
||||
'quantity' => (double) $this->request['quantity'],
|
||||
'price' => (double) $this->request['price'],
|
||||
'tax' => $item_tax_total,
|
||||
'discount_rate' => $this->request['discount'],
|
||||
'total' => $item_amount,
|
||||
]);
|
||||
|
||||
|
@ -72,7 +72,7 @@ class UpdateBill extends Job
|
||||
protected function createItemsAndTotals()
|
||||
{
|
||||
// Create items
|
||||
list($sub_total, $taxes) = $this->createItems();
|
||||
list($sub_total, $discount_amount_total, $taxes) = $this->createItems();
|
||||
|
||||
// Delete current totals
|
||||
$this->deleteRelationships($this->bill, 'totals');
|
||||
@ -94,8 +94,23 @@ class UpdateBill extends Job
|
||||
$sort_order++;
|
||||
|
||||
// Add discount
|
||||
if ($discount_amount_total > 0) {
|
||||
BillTotal::create([
|
||||
'company_id' => $this->bill->company_id,
|
||||
'bill_id' => $this->bill->id,
|
||||
'code' => 'item_discount',
|
||||
'name' => 'bills.item_discount',
|
||||
'amount' => $discount_amount_total,
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$this->request['amount'] -= $discount_amount_total;
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
|
||||
if (!empty($this->request['discount'])) {
|
||||
$discount_total = $sub_total * ($this->request['discount'] / 100);
|
||||
$discount_total = ($sub_total - $discount_amount_total) * ($this->request['discount'] / 100);
|
||||
|
||||
BillTotal::create([
|
||||
'company_id' => $this->bill->company_id,
|
||||
@ -166,7 +181,7 @@ class UpdateBill extends Job
|
||||
|
||||
protected function createItems()
|
||||
{
|
||||
$sub_total = 0;
|
||||
$sub_total = $discount_amount = $discount_amount_total = 0;
|
||||
|
||||
$taxes = [];
|
||||
|
||||
@ -184,8 +199,14 @@ class UpdateBill extends Job
|
||||
|
||||
$bill_item = $this->dispatch(new CreateBillItem($item, $this->bill));
|
||||
|
||||
$item_amount = (double) $item['price'] * (double) $item['quantity'];
|
||||
|
||||
$discount_amount = ($item_amount * ($item['discount'] / 100));
|
||||
|
||||
// Calculate totals
|
||||
$sub_total += $bill_item->total;
|
||||
$sub_total += $bill_item->total + $discount_amount;
|
||||
|
||||
$discount_amount_total += $discount_amount;
|
||||
|
||||
if (!$bill_item->item_taxes) {
|
||||
continue;
|
||||
@ -204,6 +225,6 @@ class UpdateBill extends Job
|
||||
}
|
||||
}
|
||||
|
||||
return [$sub_total, $taxes];
|
||||
return [$sub_total, $discount_amount_total, $taxes];
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ class CreateInvoice extends Job
|
||||
protected function createItemsAndTotals()
|
||||
{
|
||||
// Create items
|
||||
list($sub_total, $taxes) = $this->createItems();
|
||||
list($sub_total, $discount_amount_total, $taxes) = $this->createItems();
|
||||
|
||||
$sort_order = 1;
|
||||
|
||||
@ -83,8 +83,23 @@ class CreateInvoice extends Job
|
||||
$sort_order++;
|
||||
|
||||
// Add discount
|
||||
if ($discount_amount_total > 0) {
|
||||
InvoiceTotal::create([
|
||||
'company_id' => $this->invoice->company_id,
|
||||
'invoice_id' => $this->invoice->id,
|
||||
'code' => 'item_discount',
|
||||
'name' => 'invoices.item_discount',
|
||||
'amount' => $discount_amount_total,
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$this->request['amount'] -= $discount_amount_total;
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
|
||||
if (!empty($this->request['discount'])) {
|
||||
$discount_total = $sub_total * ($this->request['discount'] / 100);
|
||||
$discount_total = ($sub_total - $discount_amount_total) * ($this->request['discount'] / 100);
|
||||
|
||||
InvoiceTotal::create([
|
||||
'company_id' => $this->invoice->company_id,
|
||||
@ -155,7 +170,7 @@ class CreateInvoice extends Job
|
||||
|
||||
protected function createItems()
|
||||
{
|
||||
$sub_total = 0;
|
||||
$sub_total = $discount_amount = $discount_amount_total = 0;
|
||||
|
||||
$taxes = [];
|
||||
|
||||
@ -170,8 +185,14 @@ class CreateInvoice extends Job
|
||||
|
||||
$invoice_item = $this->dispatch(new CreateInvoiceItem($item, $this->invoice));
|
||||
|
||||
$item_amount = (double) $item['price'] * (double) $item['quantity'];
|
||||
|
||||
$discount_amount = ($item_amount * ($item['discount'] / 100));
|
||||
|
||||
// Calculate totals
|
||||
$sub_total += $invoice_item->total;
|
||||
$sub_total += $invoice_item->total + $discount_amount;
|
||||
|
||||
$discount_amount_total += $discount_amount;
|
||||
|
||||
if (!$invoice_item->item_taxes) {
|
||||
continue;
|
||||
@ -190,6 +211,6 @@ class CreateInvoice extends Job
|
||||
}
|
||||
}
|
||||
|
||||
return [$sub_total, $taxes];
|
||||
return [$sub_total, $discount_amount_total, $taxes];
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class CreateInvoiceItem extends Job
|
||||
|
||||
// Apply discount to amount
|
||||
if (!empty($this->request['discount'])) {
|
||||
$item_discounted_amount = $item_amount - ($item_amount * ($this->request['discount'] / 100));
|
||||
$item_discounted_amount = $item_amount -= ($item_amount * ($this->request['discount'] / 100));
|
||||
}
|
||||
|
||||
$tax_amount = 0;
|
||||
@ -138,6 +138,7 @@ class CreateInvoiceItem extends Job
|
||||
'quantity' => (double) $this->request['quantity'],
|
||||
'price' => (double) $this->request['price'],
|
||||
'tax' => $item_tax_total,
|
||||
'discount_rate' => $this->request['discount'],
|
||||
'total' => $item_amount,
|
||||
]);
|
||||
|
||||
|
@ -72,7 +72,7 @@ class UpdateInvoice extends Job
|
||||
protected function createItemsAndTotals()
|
||||
{
|
||||
// Create items
|
||||
list($sub_total, $taxes) = $this->createItems();
|
||||
list($sub_total, $discount_amount_total, $taxes) = $this->createItems();
|
||||
|
||||
// Delete current totals
|
||||
$this->deleteRelationships($this->invoice, 'totals');
|
||||
@ -94,8 +94,23 @@ class UpdateInvoice extends Job
|
||||
$sort_order++;
|
||||
|
||||
// Add discount
|
||||
if ($discount_amount_total > 0) {
|
||||
InvoiceTotal::create([
|
||||
'company_id' => $this->invoice->company_id,
|
||||
'invoice_id' => $this->invoice->id,
|
||||
'code' => 'item_discount',
|
||||
'name' => 'invoices.item_discount',
|
||||
'amount' => $discount_amount_total,
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$this->request['amount'] -= $discount_amount_total;
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
|
||||
if (!empty($this->request['discount'])) {
|
||||
$discount_total = $sub_total * ($this->request['discount'] / 100);
|
||||
$discount_total = ($sub_total - $discount_amount_total) * ($this->request['discount'] / 100);
|
||||
|
||||
InvoiceTotal::create([
|
||||
'company_id' => $this->invoice->company_id,
|
||||
@ -166,7 +181,7 @@ class UpdateInvoice extends Job
|
||||
|
||||
protected function createItems()
|
||||
{
|
||||
$sub_total = 0;
|
||||
$sub_total = $discount_amount = $discount_amount_total = 0;
|
||||
|
||||
$taxes = [];
|
||||
|
||||
@ -184,8 +199,14 @@ class UpdateInvoice extends Job
|
||||
|
||||
$invoice_item = $this->dispatch(new CreateInvoiceItem($item, $this->invoice));
|
||||
|
||||
$item_amount = (double) $item['price'] * (double) $item['quantity'];
|
||||
|
||||
$discount_amount = ($item_amount * ($item['discount'] / 100));
|
||||
|
||||
// Calculate totals
|
||||
$sub_total += $invoice_item->total;
|
||||
$sub_total += $invoice_item->total + $discount_amount;
|
||||
|
||||
$discount_amount_total += $discount_amount;
|
||||
|
||||
if (!$invoice_item->item_taxes) {
|
||||
continue;
|
||||
@ -204,6 +225,6 @@ class UpdateInvoice extends Job
|
||||
}
|
||||
}
|
||||
|
||||
return [$sub_total, $taxes];
|
||||
return [$sub_total, $discount_amount_total, $taxes];
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,18 @@ class BillItem extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'bill_id', 'item_id', 'name', 'quantity', 'price', 'total', 'tax'];
|
||||
protected $fillable = [
|
||||
'company_id',
|
||||
'bill_id',
|
||||
'item_id',
|
||||
'name',
|
||||
'quantity',
|
||||
'price',
|
||||
'total',
|
||||
'tax',
|
||||
'discount_rate',
|
||||
'discount_type',
|
||||
];
|
||||
|
||||
/**
|
||||
* Clonable relationships.
|
||||
@ -84,6 +95,22 @@ class BillItem extends Model
|
||||
$this->attributes['tax'] = (double) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the formatted discount.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDiscountRateAttribute($value)
|
||||
{
|
||||
if (setting('localisation.percent_position', 'after') === 'after') {
|
||||
$text = ($this->discount_type === 'normal') ? $value . '%' : $value;
|
||||
} else {
|
||||
$text = ($this->discount_type === 'normal') ? '%' . $value : $value;
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert tax to Array.
|
||||
*
|
||||
|
@ -17,7 +17,18 @@ class InvoiceItem extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'invoice_id', 'item_id', 'name', 'quantity', 'price', 'total', 'tax'];
|
||||
protected $fillable = [
|
||||
'company_id',
|
||||
'invoice_id',
|
||||
'item_id',
|
||||
'name',
|
||||
'quantity',
|
||||
'price',
|
||||
'total',
|
||||
'tax',
|
||||
'discount_rate',
|
||||
'discount_type',
|
||||
];
|
||||
|
||||
/**
|
||||
* Clonable relationships.
|
||||
@ -83,6 +94,22 @@ class InvoiceItem extends Model
|
||||
$this->attributes['tax'] = (double) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the formatted discount.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDiscountRateAttribute($value)
|
||||
{
|
||||
if (setting('localisation.percent_position', 'after') === 'after') {
|
||||
$text = ($this->discount_type === 'normal') ? $value . '%' : $value;
|
||||
} else {
|
||||
$text = ($this->discount_type === 'normal') ? '%' . $value : $value;
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert tax to Array.
|
||||
*
|
||||
|
54
database/migrations/2020_03_20_183732_core_v208.php
Normal file
54
database/migrations/2020_03_20_183732_core_v208.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CoreV208 extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table(
|
||||
'invoice_items',
|
||||
function (Blueprint $table) {
|
||||
$table->double('discount_rate', 15, 4)->default('0.0000')->after('tax');
|
||||
$table->string('discount_type')->default('normal')->after('discount_rate');
|
||||
}
|
||||
);
|
||||
|
||||
Schema::table(
|
||||
'bill_items',
|
||||
function (Blueprint $table) {
|
||||
$table->double('discount_rate', 15, 4)->default('0.0000')->after('tax');
|
||||
$table->string('discount_type')->default('normal')->after('discount_rate');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table(
|
||||
'invoice_items',
|
||||
function (Blueprint $table) {
|
||||
$table->dropColumn(['discount_rate', 'discount_type']);
|
||||
}
|
||||
);
|
||||
|
||||
Schema::table(
|
||||
'bill_items',
|
||||
function (Blueprint $table) {
|
||||
$table->dropColumn(['discount_rate', 'discount_type']);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
8
public/css/custom.css
vendored
8
public/css/custom.css
vendored
@ -740,6 +740,14 @@ table .align-items-center td span.badge
|
||||
/*--Quantity Width Finish--*/
|
||||
|
||||
|
||||
/*--Discount Width--*/
|
||||
.w-12
|
||||
{
|
||||
width: 12%;
|
||||
}
|
||||
/*--Discount Width Finish--*/
|
||||
|
||||
|
||||
/*--------Responsive--------*/
|
||||
/*--Xs Breakpoint--*/
|
||||
@media (max-width: 575.98px)
|
||||
|
45
resources/assets/js/views/purchases/bills.js
vendored
45
resources/assets/js/views/purchases/bills.js
vendored
@ -32,6 +32,7 @@ const app = new Vue({
|
||||
bulk_action: new BulkAction('bills'),
|
||||
totals: {
|
||||
sub: 0,
|
||||
item_discount: '',
|
||||
discount: '',
|
||||
discount_text: false,
|
||||
tax: 0,
|
||||
@ -50,7 +51,7 @@ const app = new Vue({
|
||||
items: '',
|
||||
discount: false,
|
||||
taxes: null,
|
||||
colspan: 5,
|
||||
colspan: 6,
|
||||
}
|
||||
},
|
||||
|
||||
@ -75,6 +76,7 @@ const app = new Vue({
|
||||
price: (item.price).toFixed(2),
|
||||
quantity: item.quantity,
|
||||
tax_id: item.tax_id,
|
||||
discount: item.discount_rate,
|
||||
total: (item.total).toFixed(2)
|
||||
});
|
||||
});
|
||||
@ -106,10 +108,12 @@ const app = new Vue({
|
||||
onCalculateTotal() {
|
||||
let sub_total = 0;
|
||||
let discount_total = 0;
|
||||
let item_discount_total = 0;
|
||||
let tax_total = 0;
|
||||
let grand_total = 0;
|
||||
let items = this.form.items;
|
||||
let discount = this.form.discount;
|
||||
let discount_in_totals = this.form.discount;
|
||||
let discount = '';
|
||||
|
||||
if (items.length) {
|
||||
let index = 0;
|
||||
@ -120,13 +124,22 @@ const app = new Vue({
|
||||
let item = items[index];
|
||||
|
||||
// item sub total calcute.
|
||||
let item_sub_total = item.price * item.quantity;
|
||||
let item_total = item.price * item.quantity;
|
||||
|
||||
// item discount calculate.
|
||||
let item_discounted_total = item_sub_total;
|
||||
let item_discounted_total = item_total;
|
||||
|
||||
if (discount) {
|
||||
item_discounted_total = item_sub_total - (item_sub_total * (discount / 100));
|
||||
if (discount_in_totals) {
|
||||
item_discounted_total = item_total - (item_total * (discount_in_totals / 100));
|
||||
discount = discount_in_totals;
|
||||
}
|
||||
|
||||
let discount_amount = 0;
|
||||
|
||||
if (item.discount) {
|
||||
discount_amount = item_total * (item.discount / 100);
|
||||
item_discounted_total = item_total - discount_amount;
|
||||
discount = item.discount;
|
||||
}
|
||||
|
||||
// item tax calculate.
|
||||
@ -178,7 +191,7 @@ const app = new Vue({
|
||||
|
||||
item_tax_total = item_sub_and_tax_total - item_base_rate;
|
||||
|
||||
item_sub_total = item_base_rate + discount;
|
||||
item_total = item_base_rate + discount;
|
||||
}
|
||||
|
||||
if (compounds.length) {
|
||||
@ -189,10 +202,15 @@ const app = new Vue({
|
||||
}
|
||||
|
||||
// set item total
|
||||
items[index].total = item_sub_total;
|
||||
if (item.discount) {
|
||||
items[index].total = item_discounted_total;
|
||||
} else {
|
||||
items[index].total = item_total;
|
||||
}
|
||||
|
||||
// calculate sub, tax, discount all items.
|
||||
sub_total += item_sub_total;
|
||||
item_discount_total += discount_amount;
|
||||
sub_total += item_total;
|
||||
tax_total += item_tax_total;
|
||||
}
|
||||
}
|
||||
@ -200,14 +218,17 @@ const app = new Vue({
|
||||
// set global total variable.
|
||||
this.totals.sub = sub_total;
|
||||
this.totals.tax = tax_total;
|
||||
this.totals.item_discount = item_discount_total;
|
||||
|
||||
sub_total -= item_discount_total;
|
||||
|
||||
// Apply discount to total
|
||||
if (discount) {
|
||||
discount_total = sub_total * (discount / 100);
|
||||
if (discount_in_totals) {
|
||||
discount_total = sub_total * (discount_in_totals / 100);
|
||||
|
||||
this.totals.discount = discount_total;
|
||||
|
||||
sub_total = sub_total - (sub_total * (discount / 100));
|
||||
sub_total = sub_total - (sub_total * (discount_in_totals / 100));
|
||||
}
|
||||
|
||||
// set all item grand total.
|
||||
|
45
resources/assets/js/views/sales/invoices.js
vendored
45
resources/assets/js/views/sales/invoices.js
vendored
@ -32,6 +32,7 @@ const app = new Vue({
|
||||
bulk_action: new BulkAction('invoices'),
|
||||
totals: {
|
||||
sub: 0,
|
||||
item_discount: '',
|
||||
discount: '',
|
||||
discount_text: false,
|
||||
tax: 0,
|
||||
@ -50,7 +51,7 @@ const app = new Vue({
|
||||
items: '',
|
||||
discount: false,
|
||||
taxes: null,
|
||||
colspan: 5,
|
||||
colspan: 6,
|
||||
}
|
||||
},
|
||||
|
||||
@ -75,6 +76,7 @@ const app = new Vue({
|
||||
price: (item.price).toFixed(2),
|
||||
quantity: item.quantity,
|
||||
tax_id: item.tax_id,
|
||||
discount: item.discount_rate,
|
||||
total: (item.total).toFixed(2)
|
||||
});
|
||||
});
|
||||
@ -106,10 +108,12 @@ const app = new Vue({
|
||||
onCalculateTotal() {
|
||||
let sub_total = 0;
|
||||
let discount_total = 0;
|
||||
let item_discount_total = 0;
|
||||
let tax_total = 0;
|
||||
let grand_total = 0;
|
||||
let items = this.form.items;
|
||||
let discount = this.form.discount;
|
||||
let discount_in_totals = this.form.discount;
|
||||
let discount = '';
|
||||
|
||||
if (items.length) {
|
||||
let index = 0;
|
||||
@ -120,13 +124,22 @@ const app = new Vue({
|
||||
let item = items[index];
|
||||
|
||||
// item sub total calcute.
|
||||
let item_sub_total = item.price * item.quantity;
|
||||
let item_total = item.price * item.quantity;
|
||||
|
||||
// item discount calculate.
|
||||
let item_discounted_total = item_sub_total;
|
||||
let item_discounted_total = item_total;
|
||||
|
||||
if (discount) {
|
||||
item_discounted_total = item_sub_total - (item_sub_total * (discount / 100));
|
||||
if (discount_in_totals) {
|
||||
item_discounted_total = item_total - (item_total * (discount_in_totals / 100));
|
||||
discount = discount_in_totals;
|
||||
}
|
||||
|
||||
let discount_amount = 0;
|
||||
|
||||
if (item.discount) {
|
||||
discount_amount = item_total * (item.discount / 100);
|
||||
item_discounted_total = item_total - discount_amount;
|
||||
discount = item.discount;
|
||||
}
|
||||
|
||||
// item tax calculate.
|
||||
@ -178,7 +191,7 @@ const app = new Vue({
|
||||
|
||||
item_tax_total = item_sub_and_tax_total - item_base_rate;
|
||||
|
||||
item_sub_total = item_base_rate + discount;
|
||||
item_total = item_base_rate + discount;
|
||||
}
|
||||
|
||||
if (compounds.length) {
|
||||
@ -189,10 +202,15 @@ const app = new Vue({
|
||||
}
|
||||
|
||||
// set item total
|
||||
items[index].total = item_sub_total;
|
||||
if (item.discount) {
|
||||
items[index].total = item_discounted_total;
|
||||
} else {
|
||||
items[index].total = item_total;
|
||||
}
|
||||
|
||||
// calculate sub, tax, discount all items.
|
||||
sub_total += item_sub_total;
|
||||
item_discount_total += discount_amount;
|
||||
sub_total += item_total;
|
||||
tax_total += item_tax_total;
|
||||
}
|
||||
}
|
||||
@ -200,14 +218,17 @@ const app = new Vue({
|
||||
// set global total variable.
|
||||
this.totals.sub = sub_total;
|
||||
this.totals.tax = tax_total;
|
||||
this.totals.item_discount = item_discount_total;
|
||||
|
||||
sub_total -= item_discount_total;
|
||||
|
||||
// Apply discount to total
|
||||
if (discount) {
|
||||
discount_total = sub_total * (discount / 100);
|
||||
if (discount_in_totals) {
|
||||
discount_total = sub_total * (discount_in_totals / 100);
|
||||
|
||||
this.totals.discount = discount_total;
|
||||
|
||||
sub_total = sub_total - (sub_total * (discount / 100));
|
||||
sub_total = sub_total - (sub_total * (discount_in_totals / 100));
|
||||
}
|
||||
|
||||
// set all item grand total.
|
||||
|
@ -13,6 +13,7 @@ return [
|
||||
'price' => 'Price',
|
||||
'sub_total' => 'Subtotal',
|
||||
'discount' => 'Discount',
|
||||
'item_discount' => 'Item Discount',
|
||||
'tax_total' => 'Tax Total',
|
||||
'total' => 'Total',
|
||||
|
||||
|
@ -13,6 +13,7 @@ return [
|
||||
'price' => 'Price',
|
||||
'sub_total' => 'Subtotal',
|
||||
'discount' => 'Discount',
|
||||
'item_discount' => 'Item Discount',
|
||||
'tax_total' => 'Tax Total',
|
||||
'total' => 'Total',
|
||||
|
||||
|
@ -51,6 +51,10 @@
|
||||
<th class="text-right border-right-0 border-bottom-0">{{ trans('bills.price') }}</th>
|
||||
@stack('price_th_end')
|
||||
|
||||
@stack('discount_th_start')
|
||||
<th class="text-right border-right-0 border-bottom-0">{{ trans('bills.discount') }}</th>
|
||||
@stack('discount_th_end')
|
||||
|
||||
@stack('taxes_th_start')
|
||||
<th class="text-right border-right-0 border-bottom-0">{{ trans_choice('general.taxes', 1) }}</th>
|
||||
@stack('taxes_th_end')
|
||||
@ -69,13 +73,13 @@
|
||||
<button type="button" @click="onAddItem" id="button-add-item" data-toggle="tooltip" title="{{ trans('general.add') }}" class="btn btn-icon btn-outline-success btn-lg" data-original-title="{{ trans('general.add') }}"><i class="fa fa-plus"></i>
|
||||
</button>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0" colspan="5" :colspan="colspan"></td>
|
||||
<td class="text-right border-bottom-0" colspan="6" :colspan="colspan"></td>
|
||||
</tr>
|
||||
@stack('add_item_td_end')
|
||||
|
||||
@stack('sub_total_td_start')
|
||||
<tr id="tr-subtotal">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans('bills.sub_total') }}</strong>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0 long-texts">
|
||||
@ -86,9 +90,22 @@
|
||||
</tr>
|
||||
@stack('sub_total_td_end')
|
||||
|
||||
@stack('item_discount_td_start')
|
||||
<tr id="tr-subtotal">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans('bills.item_discount') }}</strong>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0 long-texts">
|
||||
{{ Form::moneyGroup('item_discount', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.item_discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }}
|
||||
<span id="item-discount" v-if="totals.item_discount" v-html="totals.item_discount"></span>
|
||||
<span v-else>@money(0, $currency->code, true)</span>
|
||||
</td>
|
||||
</tr>
|
||||
@stack('item_discount_td_end')
|
||||
|
||||
@stack('add_discount_td_start')
|
||||
<tr id="tr-discount">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<el-popover
|
||||
popper-class="p-0 h-0"
|
||||
placement="bottom"
|
||||
@ -140,7 +157,7 @@
|
||||
|
||||
@stack('tax_total_td_start')
|
||||
<tr id="tr-tax">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans_choice('general.taxes', 1) }}</strong>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0 long-texts">
|
||||
@ -153,7 +170,7 @@
|
||||
|
||||
@stack('grand_total_td_start')
|
||||
<tr id="tr-total">
|
||||
<td class="text-right border-right-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans('bills.total') }}</strong>
|
||||
</td>
|
||||
<td class="text-right long-texts">
|
||||
|
@ -52,6 +52,10 @@
|
||||
<th class="text-right border-right-0 border-bottom-0">{{ trans('bills.price') }}</th>
|
||||
@stack('price_th_end')
|
||||
|
||||
@stack('discount_th_start')
|
||||
<th class="text-right border-right-0 border-bottom-0">{{ trans('bills.discount') }}</th>
|
||||
@stack('discount_th_end')
|
||||
|
||||
@stack('taxes_th_start')
|
||||
<th class="text-right border-right-0 border-bottom-0">{{ trans_choice('general.taxes', 1) }}</th>
|
||||
@stack('taxes_th_end')
|
||||
@ -70,13 +74,13 @@
|
||||
<button type="button" @click="onAddItem" id="button-add-item" data-toggle="tooltip" title="{{ trans('general.add') }}" class="btn btn-icon btn-outline-success btn-lg" data-original-title="{{ trans('general.add') }}"><i class="fa fa-plus"></i>
|
||||
</button>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0" colspan="5" :colspan="colspan"></td>
|
||||
<td class="text-right border-bottom-0" colspan="6" :colspan="colspan"></td>
|
||||
</tr>
|
||||
@stack('add_item_td_end')
|
||||
|
||||
@stack('sub_total_td_start')
|
||||
<tr id="tr-subtotal">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans('bills.sub_total') }}</strong>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0 long-texts">
|
||||
@ -89,7 +93,7 @@
|
||||
|
||||
@stack('add_discount_td_start')
|
||||
<tr id="tr-discount">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<el-popover
|
||||
popper-class="p-0 h-0"
|
||||
placement="bottom"
|
||||
@ -141,7 +145,7 @@
|
||||
|
||||
@stack('tax_total_td_start')
|
||||
<tr id="tr-tax">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans_choice('general.taxes', 1) }}</strong>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0 long-texts">
|
||||
@ -154,7 +158,7 @@
|
||||
|
||||
@stack('grand_total_td_start')
|
||||
<tr id="tr-total">
|
||||
<td class="text-right border-right-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans('bills.total') }}</strong>
|
||||
</td>
|
||||
<td class="text-right long-texts">
|
||||
|
@ -98,6 +98,37 @@
|
||||
</td>
|
||||
@stack('price_td_end')
|
||||
|
||||
@stack('discount_td_start')
|
||||
<td class="border-right-0 border-bottom-0 w-12"
|
||||
:class="[{'has-error': form.errors.has('items.' + index + '.discount') }]">
|
||||
@stack('discount_input_start')
|
||||
<div class="input-group input-group-merge">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="input-discount">
|
||||
<i class="fa fa-percent"></i>
|
||||
</span>
|
||||
</div>
|
||||
<input type="number"
|
||||
max="100"
|
||||
min="0"
|
||||
class="form-control text-center"
|
||||
:name="'items.' + index + '.discount'"
|
||||
autocomplete="off"
|
||||
required="required"
|
||||
data-item="quantity"
|
||||
v-model="row.discount"
|
||||
@input="onCalculateTotal"
|
||||
@change="form.errors.clear('items.' + index + '.discount')">
|
||||
|
||||
<div class="invalid-feedback d-block"
|
||||
v-if="form.errors.has('items.' + index + '.discount')"
|
||||
v-html="form.errors.get('items.' + index + '.discount')">
|
||||
</div>
|
||||
</div>
|
||||
@stack('discount_input_end')
|
||||
</td>
|
||||
@stack('discount_td_end')
|
||||
|
||||
@stack('taxes_td_start')
|
||||
<td class="border-right-0 border-bottom-0"
|
||||
:class="[{'has-error': form.errors.has('items.' + index + '.tax_id') }]">
|
||||
|
@ -339,6 +339,10 @@
|
||||
<th class="col-sm-3 text-right d-none d-sm-block">{{ trans('bills.price') }}</th>
|
||||
@stack('price_th_end')
|
||||
|
||||
@stack('discount_th_start')
|
||||
<th class="col-sm-1 text-center d-none d-sm-block">{{ trans('bills.discount') }}</th>
|
||||
@stack('discount_th_end')
|
||||
|
||||
@stack('total_th_start')
|
||||
<th class="col-xs-4 col-sm-3 text-right pr-5">{{ trans('bills.total') }}</th>
|
||||
@stack('total_th_end')
|
||||
@ -362,6 +366,10 @@
|
||||
<td class="col-sm-3 text-right d-none d-sm-block">@money($bill_item->price, $bill->currency_code, true)</td>
|
||||
@stack('price_td_end')
|
||||
|
||||
@stack('discount_td_start')
|
||||
<td class="col-sm-1 text-center d-none d-sm-block">{{ $bill_item->discount_rate }}</td>
|
||||
@stack('discount_td_end')
|
||||
|
||||
@stack('total_td_start')
|
||||
<td class="col-xs-4 col-sm-3 text-right pr-5">@money($bill_item->total, $bill->currency_code, true)</td>
|
||||
@stack('total_td_end')
|
||||
|
@ -51,6 +51,10 @@
|
||||
<th class="text-right border-right-0 border-bottom-0">{{ trans($text_override['price']) }}</th>
|
||||
@stack('price_th_end')
|
||||
|
||||
@stack('discount_th_start')
|
||||
<th class="text-right border-right-0 border-bottom-0">{{ trans('invoices.discount') }}</th>
|
||||
@stack('discount_th_end')
|
||||
|
||||
@stack('taxes_th_start')
|
||||
<th class="text-right border-right-0 border-bottom-0">{{ trans_choice('general.taxes', 1) }}</th>
|
||||
@stack('taxes_th_end')
|
||||
@ -69,13 +73,13 @@
|
||||
<button type="button" @click="onAddItem" id="button-add-item" data-toggle="tooltip" title="{{ trans('general.add') }}" class="btn btn-icon btn-outline-success btn-lg" data-original-title="{{ trans('general.add') }}"><i class="fa fa-plus"></i>
|
||||
</button>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0" colspan="5" :colspan="colspan"></td>
|
||||
<td class="text-right border-bottom-0" colspan="6" :colspan="colspan"></td>
|
||||
</tr>
|
||||
@stack('add_item_td_end')
|
||||
|
||||
@stack('sub_total_td_start')
|
||||
<tr id="tr-subtotal">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans('invoices.sub_total') }}</strong>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0 long-texts">
|
||||
@ -86,9 +90,22 @@
|
||||
</tr>
|
||||
@stack('sub_total_td_end')
|
||||
|
||||
@stack('item_discount_td_start')
|
||||
<tr id="tr-subtotal">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans('invoices.item_discount') }}</strong>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0 long-texts">
|
||||
{{ Form::moneyGroup('item_discount', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.item_discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }}
|
||||
<span id="item-discount" v-if="totals.item_discount" v-html="totals.item_discount"></span>
|
||||
<span v-else>@money(0, $currency->code, true)</span>
|
||||
</td>
|
||||
</tr>
|
||||
@stack('item_discount_td_end')
|
||||
|
||||
@stack('add_discount_td_start')
|
||||
<tr id="tr-discount">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<el-popover
|
||||
popper-class="p-0 h-0"
|
||||
placement="bottom"
|
||||
@ -140,7 +157,7 @@
|
||||
|
||||
@stack('tax_total_td_start')
|
||||
<tr id="tr-tax">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans_choice('general.taxes', 1) }}</strong>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0 long-texts">
|
||||
@ -153,7 +170,7 @@
|
||||
|
||||
@stack('grand_total_td_start')
|
||||
<tr id="tr-total">
|
||||
<td class="text-right border-right-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans('invoices.total') }}</strong>
|
||||
</td>
|
||||
<td class="text-right long-texts">
|
||||
|
@ -52,6 +52,10 @@
|
||||
<th class="text-right border-right-0 border-bottom-0">{{ trans($text_override['price']) }}</th>
|
||||
@stack('price_th_end')
|
||||
|
||||
@stack('discount_th_start')
|
||||
<th class="text-right border-right-0 border-bottom-0">{{ trans('invoices.discount') }}</th>
|
||||
@stack('discount_th_end')
|
||||
|
||||
@stack('taxes_th_start')
|
||||
<th class="text-right border-right-0 border-bottom-0">{{ trans_choice('general.taxes', 1) }}</th>
|
||||
@stack('taxes_th_end')
|
||||
@ -70,13 +74,13 @@
|
||||
<button type="button" @click="onAddItem" id="button-add-item" data-toggle="tooltip" title="{{ trans('general.add') }}" class="btn btn-icon btn-outline-success btn-lg" data-original-title="{{ trans('general.add') }}"><i class="fa fa-plus"></i>
|
||||
</button>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0" colspan="5" :colspan="colspan"></td>
|
||||
<td class="text-right border-bottom-0" colspan="6" :colspan="colspan"></td>
|
||||
</tr>
|
||||
@stack('add_item_td_end')
|
||||
|
||||
@stack('sub_total_td_start')
|
||||
<tr id="tr-subtotal">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans('invoices.sub_total') }}</strong>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0 long-texts">
|
||||
@ -89,7 +93,7 @@
|
||||
|
||||
@stack('add_discount_td_start')
|
||||
<tr id="tr-discount">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<el-popover
|
||||
popper-class="p-0 h-0"
|
||||
placement="bottom"
|
||||
@ -141,7 +145,7 @@
|
||||
|
||||
@stack('tax_total_td_start')
|
||||
<tr id="tr-tax">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans_choice('general.taxes', 1) }}</strong>
|
||||
</td>
|
||||
<td class="text-right border-bottom-0 long-texts">
|
||||
@ -154,7 +158,7 @@
|
||||
|
||||
@stack('grand_total_td_start')
|
||||
<tr id="tr-total">
|
||||
<td class="text-right border-right-0" colspan="5" :colspan="colspan">
|
||||
<td class="text-right border-right-0" colspan="6" :colspan="colspan">
|
||||
<strong>{{ trans('invoices.total') }}</strong>
|
||||
</td>
|
||||
<td class="text-right long-texts">
|
||||
|
@ -98,6 +98,37 @@
|
||||
</td>
|
||||
@stack('price_td_end')
|
||||
|
||||
@stack('discount_td_start')
|
||||
<td class="border-right-0 border-bottom-0 w-12"
|
||||
:class="[{'has-error': form.errors.has('items.' + index + '.discount') }]">
|
||||
@stack('discount_input_start')
|
||||
<div class="input-group input-group-merge">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="input-discount">
|
||||
<i class="fa fa-percent"></i>
|
||||
</span>
|
||||
</div>
|
||||
<input type="number"
|
||||
max="100"
|
||||
min="0"
|
||||
class="form-control text-center"
|
||||
:name="'items.' + index + '.discount'"
|
||||
autocomplete="off"
|
||||
required="required"
|
||||
data-item="quantity"
|
||||
v-model="row.discount"
|
||||
@input="onCalculateTotal"
|
||||
@change="form.errors.clear('items.' + index + '.discount')">
|
||||
|
||||
<div class="invalid-feedback d-block"
|
||||
v-if="form.errors.has('items.' + index + '.discount')"
|
||||
v-html="form.errors.get('items.' + index + '.discount')">
|
||||
</div>
|
||||
</div>
|
||||
@stack('discount_input_end')
|
||||
</td>
|
||||
@stack('discount_td_end')
|
||||
|
||||
@stack('taxes_td_start')
|
||||
<td class="border-right-0 border-bottom-0"
|
||||
:class="[{'has-error': form.errors.has('items.' + index + '.tax_id') }]">
|
||||
|
@ -356,6 +356,10 @@
|
||||
<th class="col-sm-3 text-right d-none d-sm-block">{{ trans($text_override['price']) }}</th>
|
||||
@stack('price_th_end')
|
||||
|
||||
@stack('discount_th_start')
|
||||
<th class="col-sm-1 text-center d-none d-sm-block">{{ trans('invoices.discount') }}</th>
|
||||
@stack('discount_th_end')
|
||||
|
||||
@stack('total_th_start')
|
||||
<th class="col-xs-4 col-sm-3 text-right pr-5">{{ trans('invoices.total') }}</th>
|
||||
@stack('total_th_end')
|
||||
@ -379,6 +383,10 @@
|
||||
<td class="col-sm-3 text-right d-none d-sm-block">@money($invoice_item->price, $invoice->currency_code, true)</td>
|
||||
@stack('price_td_end')
|
||||
|
||||
@stack('discount_td_start')
|
||||
<td class="col-sm-1 text-center d-none d-sm-block">{{ $invoice_item->discount_rate }}</td>
|
||||
@stack('discount_td_end')
|
||||
|
||||
@stack('total_td_start')
|
||||
<td class="col-xs-4 col-sm-3 text-right pr-5">@money($invoice_item->total, $invoice->currency_code, true)</td>
|
||||
@stack('total_td_end')
|
||||
|
Loading…
x
Reference in New Issue
Block a user