refs #1408 Fixed invoice total discount feature..
This commit is contained in:
parent
024c70da84
commit
e3240fa43b
@ -179,6 +179,11 @@ class CreateInvoice extends Job
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ((array) $this->request['items'] as $item) {
|
foreach ((array) $this->request['items'] as $item) {
|
||||||
|
$item['global_discount'] = 0;
|
||||||
|
|
||||||
|
if (!empty($this->request['discount'])) {
|
||||||
|
$item['global_discount'] = $this->request['discount'];
|
||||||
|
}
|
||||||
|
|
||||||
$invoice_item = $this->dispatch(new CreateInvoiceItem($item, $this->invoice));
|
$invoice_item = $this->dispatch(new CreateInvoiceItem($item, $this->invoice));
|
||||||
|
|
||||||
|
@ -38,11 +38,16 @@ class CreateInvoiceItem extends Job
|
|||||||
|
|
||||||
$item_discounted_amount = $item_amount;
|
$item_discounted_amount = $item_amount;
|
||||||
|
|
||||||
// Apply discount to amount
|
// Apply line discount to amount
|
||||||
if (!empty($this->request['discount'])) {
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply global discount to amount
|
||||||
|
if (!empty($this->request['global_discount'])) {
|
||||||
|
$item_discounted_amount = $item_amount - ($item_amount * ($this->request['global_discount'] / 100));
|
||||||
|
}
|
||||||
|
|
||||||
$tax_amount = 0;
|
$tax_amount = 0;
|
||||||
$item_taxes = [];
|
$item_taxes = [];
|
||||||
$item_tax_total = 0;
|
$item_tax_total = 0;
|
||||||
|
@ -193,6 +193,11 @@ class UpdateInvoice extends Job
|
|||||||
$this->deleteRelationships($this->invoice, ['items', 'item_taxes']);
|
$this->deleteRelationships($this->invoice, ['items', 'item_taxes']);
|
||||||
|
|
||||||
foreach ((array) $this->request['items'] as $item) {
|
foreach ((array) $this->request['items'] as $item) {
|
||||||
|
$item['global_discount'] = 0;
|
||||||
|
|
||||||
|
if (!empty($this->request['discount'])) {
|
||||||
|
$item['global_discount'] = $this->request['discount'];
|
||||||
|
}
|
||||||
|
|
||||||
$invoice_item = $this->dispatch(new CreateInvoiceItem($item, $this->invoice));
|
$invoice_item = $this->dispatch(new CreateInvoiceItem($item, $this->invoice));
|
||||||
|
|
||||||
|
@ -117,6 +117,31 @@ class InvoiceItem extends Model
|
|||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the formatted discount.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDiscountRateAttribute($value = 0)
|
||||||
|
{
|
||||||
|
$discount_rate = 0;
|
||||||
|
|
||||||
|
switch (setting('localisation.discount_location', 'total')) {
|
||||||
|
case 'no':
|
||||||
|
case 'total':
|
||||||
|
$discount_rate = 0;
|
||||||
|
break;
|
||||||
|
case 'item':
|
||||||
|
$discount_rate = $value;
|
||||||
|
break;
|
||||||
|
case 'both':
|
||||||
|
$discount_rate = $value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $discount_rate;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert tax to Array.
|
* Convert tax to Array.
|
||||||
*
|
*
|
||||||
|
2
resources/assets/js/views/sales/invoices.js
vendored
2
resources/assets/js/views/sales/invoices.js
vendored
@ -83,7 +83,7 @@ const app = new Vue({
|
|||||||
price: (item.price).toFixed(2),
|
price: (item.price).toFixed(2),
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
tax_id: item.tax_id,
|
tax_id: item.tax_id,
|
||||||
discount: (typeof item_backup.discount !== 'undefined') ? item.discount_rate : 0,
|
discount: item.discount_rate,
|
||||||
total: (item.total).toFixed(2)
|
total: (item.total).toFixed(2)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -127,7 +127,7 @@
|
|||||||
<i class="fa fa-percent"></i>
|
<i class="fa fa-percent"></i>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control']) !!}
|
{!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control', 'v-model' => 'form.discount']) !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
|
@ -128,7 +128,7 @@
|
|||||||
<i class="fa fa-percent"></i>
|
<i class="fa fa-percent"></i>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control']) !!}
|
{!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control', 'v-model' => 'form.discount']) !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user