Merge branch 'akaunting:master' into invoice-form-enhancements
This commit is contained in:
189
resources/assets/js/views/common/documents.js
vendored
189
resources/assets/js/views/common/documents.js
vendored
@ -27,70 +27,74 @@ const app = new Vue({
|
||||
],
|
||||
|
||||
data: function () {
|
||||
return {
|
||||
form: new Form('document'),
|
||||
bulk_action: new BulkAction('documents'),
|
||||
totals: {
|
||||
sub: 0,
|
||||
item_discount: '',
|
||||
discount: '',
|
||||
discount_text: false,
|
||||
taxes: [],
|
||||
total: 0
|
||||
},
|
||||
transaction: [],
|
||||
edit: {
|
||||
status: false,
|
||||
currency: false,
|
||||
items: 0,
|
||||
},
|
||||
colspan: 6,
|
||||
discount: false,
|
||||
tax: false,
|
||||
discounts: [],
|
||||
tax_id: [],
|
||||
|
||||
items: [],
|
||||
taxes: [],
|
||||
page_loaded: false,
|
||||
currencies: [],
|
||||
min_due_date: false,
|
||||
currency_symbol: {
|
||||
"name":"US Dollar",
|
||||
"code":"USD",
|
||||
"rate":1,
|
||||
"precision":2,
|
||||
"symbol":"$",
|
||||
"symbol_first":1,
|
||||
"decimal_mark":".",
|
||||
"thousands_separator":","
|
||||
},
|
||||
dropdown_visible: true
|
||||
}
|
||||
return {
|
||||
form: new Form('document'),
|
||||
bulk_action: new BulkAction('documents'),
|
||||
totals: {
|
||||
sub: 0,
|
||||
item_discount: '',
|
||||
discount: '',
|
||||
discount_text: false,
|
||||
taxes: [],
|
||||
total: 0
|
||||
},
|
||||
transaction: [],
|
||||
edit: {
|
||||
status: false,
|
||||
currency: false,
|
||||
items: 0,
|
||||
},
|
||||
colspan: 6,
|
||||
discount: false,
|
||||
tax: false,
|
||||
discounts: [],
|
||||
tax_id: [],
|
||||
|
||||
items: [],
|
||||
taxes: [],
|
||||
page_loaded: false,
|
||||
currencies: [],
|
||||
min_due_date: false,
|
||||
currency_symbol: {
|
||||
"name":"US Dollar",
|
||||
"code":"USD",
|
||||
"rate":1,
|
||||
"precision":2,
|
||||
"symbol":"$",
|
||||
"symbol_first":1,
|
||||
"decimal_mark":".",
|
||||
"thousands_separator":","
|
||||
},
|
||||
dropdown_visible: true,
|
||||
dynamic_taxes: [],
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
if ((document.getElementById('items') != null) && (document.getElementById('items').rows)) {
|
||||
this.colspan = document.getElementById("items").rows[0].cells.length - 1;
|
||||
}
|
||||
|
||||
if (!this.edit.status) {
|
||||
this.dropdown_visible = false;
|
||||
}
|
||||
|
||||
this.currency_symbol.rate = this.form.currency_rate;
|
||||
this.form.discount_type = 'percentage';
|
||||
|
||||
if (company_currency_code) {
|
||||
let default_currency_symbol = null;
|
||||
if ((document.getElementById('items') != null) && (document.getElementById('items').rows)) {
|
||||
this.colspan = document.getElementById("items").rows[0].cells.length - 1;
|
||||
}
|
||||
|
||||
if (!this.edit.status) {
|
||||
this.dropdown_visible = false;
|
||||
}
|
||||
|
||||
this.currency_symbol.rate = this.form.currency_rate;
|
||||
|
||||
if (company_currency_code) {
|
||||
let default_currency_symbol = null;
|
||||
|
||||
for (let symbol of this.currencies) {
|
||||
if(symbol.code == company_currency_code) {
|
||||
default_currency_symbol = symbol.symbol;
|
||||
}
|
||||
}
|
||||
|
||||
this.currency_symbol.symbol = default_currency_symbol;
|
||||
}
|
||||
|
||||
for (let symbol of this.currencies) {
|
||||
if(symbol.code == company_currency_code) {
|
||||
default_currency_symbol = symbol.symbol;
|
||||
}
|
||||
}
|
||||
this.currency_symbol.symbol = default_currency_symbol;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
methods: {
|
||||
@ -98,7 +102,7 @@ const app = new Vue({
|
||||
let global_discount = parseFloat(this.form.discount);
|
||||
let discount_total = 0;
|
||||
let line_item_discount_total = 0;
|
||||
let taxes = document_taxes;
|
||||
let taxes = this.dynamic_taxes;
|
||||
let sub_total = 0;
|
||||
let totals_taxes = [];
|
||||
let grand_total = 0;
|
||||
@ -115,7 +119,19 @@ const app = new Vue({
|
||||
let line_discount_amount = 0;
|
||||
|
||||
if (item.discount) {
|
||||
line_discount_amount = item.total * (item.discount / 100);
|
||||
if (item.discount_type === 'percentage') {
|
||||
if (item.discount > 100) {
|
||||
item.discount = 100;
|
||||
}
|
||||
|
||||
line_discount_amount = item.total * (item.discount / 100);
|
||||
} else {
|
||||
if (parseInt(item.discount) > item.price) {
|
||||
item.discount = item.price;
|
||||
}
|
||||
line_discount_amount = parseFloat(item.discount);
|
||||
}
|
||||
|
||||
item.discount_amount = line_discount_amount
|
||||
|
||||
item_discounted_total = item.total -= line_discount_amount;
|
||||
@ -124,12 +140,6 @@ const app = new Vue({
|
||||
|
||||
let item_discounted_total = item.total;
|
||||
|
||||
if (global_discount) {
|
||||
item_discounted_total = item.total - (item.total * (global_discount / 100));
|
||||
|
||||
item_discount = global_discount;
|
||||
}
|
||||
|
||||
// item tax calculate.
|
||||
if (item.tax_ids) {
|
||||
let inclusives = [];
|
||||
@ -240,7 +250,11 @@ const app = new Vue({
|
||||
|
||||
// Apply discount to total
|
||||
if (global_discount) {
|
||||
discount_total = parseFloat(sub_total + inclusive_tax_total) * (global_discount / 100);
|
||||
if (this.form.discount_type === 'percentage') {
|
||||
discount_total = parseFloat(sub_total + inclusive_tax_total) * (global_discount / 100);
|
||||
} else {
|
||||
discount_total = global_discount;
|
||||
}
|
||||
|
||||
this.totals.discount = discount_total;
|
||||
|
||||
@ -254,7 +268,7 @@ const app = new Vue({
|
||||
|
||||
this.form.items.forEach(function(form_item, form_index) {
|
||||
let item = this.items[form_index];
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(item)) {
|
||||
if (key == 'add_tax' || key == 'tax_ids' || key == 'add_discount') {
|
||||
continue
|
||||
@ -352,7 +366,7 @@ const app = new Vue({
|
||||
|
||||
let selected_tax;
|
||||
|
||||
document_taxes.forEach(function(tax) {
|
||||
this.dynamic_taxes.forEach(function(tax) {
|
||||
if (tax.id == this.tax_id) {
|
||||
selected_tax = tax;
|
||||
}
|
||||
@ -387,16 +401,35 @@ const app = new Vue({
|
||||
},
|
||||
|
||||
onAddLineDiscount(item_index) {
|
||||
this.items[item_index].discount_type = 'percentage';
|
||||
this.items[item_index].add_discount = true;
|
||||
},
|
||||
|
||||
onChangeDiscountType(type) {
|
||||
this.form.discount_type = type;
|
||||
this.onCalculateTotal();
|
||||
},
|
||||
|
||||
onChangeLineDiscountType(item_index, type) {
|
||||
this.items[item_index].discount_type = type;
|
||||
this.onCalculateTotal();
|
||||
},
|
||||
|
||||
onAddTotalDiscount() {
|
||||
let discount = document.getElementById('pre-discount').value;
|
||||
|
||||
if (discount < 0) {
|
||||
discount = 0;
|
||||
} else if (discount > 100) {
|
||||
discount = 100;
|
||||
if (this.form.discount_type === 'percentage') {
|
||||
if (discount < 0) {
|
||||
discount = 0;
|
||||
} else if (discount > 100) {
|
||||
discount = 100;
|
||||
}
|
||||
} else {
|
||||
if (discount < 0) {
|
||||
discount = 0;
|
||||
} else if (discount > this.totals.sub) {
|
||||
discount = this.totals.sub;
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('pre-discount').value = discount;
|
||||
@ -620,6 +653,7 @@ const app = new Vue({
|
||||
price: (item.price).toFixed(2),
|
||||
tax_ids: item.tax_ids,
|
||||
discount: item.discount_rate,
|
||||
discount_type: item.discount_type,
|
||||
total: (item.total).toFixed(2)
|
||||
});
|
||||
|
||||
@ -657,6 +691,7 @@ const app = new Vue({
|
||||
tax_ids: item_taxes,
|
||||
add_discount: (item.discount_rate) ? true : false,
|
||||
discount: item.discount_rate,
|
||||
discount_type: item.discount_type,
|
||||
total: (item.total).toFixed(2),
|
||||
// @todo
|
||||
// invoice_item_checkbox_sample: [],
|
||||
@ -686,7 +721,7 @@ const app = new Vue({
|
||||
|
||||
this.page_loaded = true;
|
||||
|
||||
if (document_currencies) {
|
||||
if (typeof document_currencies !== 'undefined' && document_currencies) {
|
||||
this.currencies = document_currencies;
|
||||
|
||||
this.currencies.forEach(function (currency, index) {
|
||||
@ -697,5 +732,9 @@ const app = new Vue({
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
|
||||
if (typeof document_taxes !== 'undefined' && document_taxes) {
|
||||
this.dynamic_taxes = document_taxes;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user