mirror of
https://github.com/frappe/books.git
synced 2025-01-08 17:24:05 +00:00
incr: display discount input on the form
This commit is contained in:
parent
bab18dc8f7
commit
877cc0b8d4
@ -178,8 +178,8 @@ export abstract class Invoice extends Transactional {
|
|||||||
|
|
||||||
async getGrandTotal() {
|
async getGrandTotal() {
|
||||||
const itemDiscountAmount = this.getItemDiscountAmount();
|
const itemDiscountAmount = this.getItemDiscountAmount();
|
||||||
const discountAmount = this.discountAmount ?? this.fyo.pesa(0);
|
const invoiceDiscountAmount = this.getInvoiceDiscountAmount();
|
||||||
const totalDiscount = itemDiscountAmount.add(discountAmount);
|
const totalDiscount = itemDiscountAmount.add(invoiceDiscountAmount);
|
||||||
|
|
||||||
return ((this.taxes ?? []) as Doc[])
|
return ((this.taxes ?? []) as Doc[])
|
||||||
.map((doc) => doc.amount as Money)
|
.map((doc) => doc.amount as Money)
|
||||||
@ -187,6 +187,23 @@ export abstract class Invoice extends Transactional {
|
|||||||
.sub(totalDiscount);
|
.sub(totalDiscount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getInvoiceDiscountAmount() {
|
||||||
|
if (this.setDiscountAmount) {
|
||||||
|
return this.discountAmount ?? this.fyo.pesa(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
let totalItemAmounts = this.fyo.pesa(0);
|
||||||
|
for (const item of this.items ?? []) {
|
||||||
|
if (this.discountAfterTax) {
|
||||||
|
totalItemAmounts = totalItemAmounts.add(item.itemTaxedTotal!);
|
||||||
|
} else {
|
||||||
|
totalItemAmounts = totalItemAmounts.add(item.itemDiscountedTotal!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalItemAmounts.percent(this.discountPercent ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
getItemDiscountAmount() {
|
getItemDiscountAmount() {
|
||||||
if (!this?.items?.length) {
|
if (!this?.items?.length) {
|
||||||
return this.fyo.pesa(0);
|
return this.fyo.pesa(0);
|
||||||
@ -248,24 +265,6 @@ export abstract class Invoice extends Transactional {
|
|||||||
formula: async () => this.netTotal!.mul(this.exchangeRate!),
|
formula: async () => this.netTotal!.mul(this.exchangeRate!),
|
||||||
},
|
},
|
||||||
taxes: { formula: async () => await this.getTaxSummary() },
|
taxes: { formula: async () => await this.getTaxSummary() },
|
||||||
discountAmount: {
|
|
||||||
formula: async (fieldname) => {
|
|
||||||
if (fieldname !== 'discountPercent') {
|
|
||||||
return this.discountAmount!;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.getDiscountAmountFromPercent();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
discountPercent: {
|
|
||||||
formula: async (fieldname) => {
|
|
||||||
if (fieldname === 'discountAmount') {
|
|
||||||
return this.getDiscountPercentFromAmount();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.discountPercent!;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
grandTotal: { formula: async () => await this.getGrandTotal() },
|
grandTotal: { formula: async () => await this.getGrandTotal() },
|
||||||
baseGrandTotal: {
|
baseGrandTotal: {
|
||||||
formula: async () => (this.grandTotal as Money).mul(this.exchangeRate!),
|
formula: async () => (this.grandTotal as Money).mul(this.exchangeRate!),
|
||||||
@ -281,18 +280,6 @@ export abstract class Invoice extends Transactional {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
getDiscountPercentFromAmount() {
|
|
||||||
const discountAmount = this.discountAmount ?? this.fyo.pesa(0);
|
|
||||||
const itemDiscountedAmounts = this.getItemDiscountedAmounts();
|
|
||||||
return discountAmount.mul(100).div(itemDiscountedAmounts).float;
|
|
||||||
}
|
|
||||||
|
|
||||||
getDiscountAmountFromPercent() {
|
|
||||||
const discountPercent = this.discountPercent ?? 0;
|
|
||||||
const itemDiscountedAmounts = this.getItemDiscountedAmounts();
|
|
||||||
return itemDiscountedAmounts.percent(discountPercent);
|
|
||||||
}
|
|
||||||
|
|
||||||
getItemDiscountedAmounts() {
|
getItemDiscountedAmounts() {
|
||||||
let itemDiscountedAmounts = this.fyo.pesa(0);
|
let itemDiscountedAmounts = this.fyo.pesa(0);
|
||||||
for (const item of this.items ?? []) {
|
for (const item of this.items ?? []) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<label class="flex items-center">
|
<label class="flex items-center">
|
||||||
<div class="mr-3 text-gray-900 text-sm" v-if="showLabel && !labelRight">
|
<div class="mr-3 text-gray-600 text-sm" v-if="showLabel && !labelRight">
|
||||||
{{ df.label }}
|
{{ df.label }}
|
||||||
</div>
|
</div>
|
||||||
<div style="width: 14px; height: 14px; overflow: hidden; cursor: pointer">
|
<div style="width: 14px; height: 14px; overflow: hidden; cursor: pointer">
|
||||||
@ -61,7 +61,7 @@
|
|||||||
@focus="(e) => $emit('focus', e)"
|
@focus="(e) => $emit('focus', e)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-3 text-gray-900 text-sm" v-if="showLabel && labelRight">
|
<div class="ml-3 text-gray-600 text-sm" v-if="showLabel && labelRight">
|
||||||
{{ df.label }}
|
{{ df.label }}
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
@ -95,7 +95,26 @@
|
|||||||
:read-only="doc?.submitted"
|
:read-only="doc?.submitted"
|
||||||
/>
|
/>
|
||||||
<FormControl
|
<FormControl
|
||||||
v-if="doc.discountPercent > 0 && !doc.setDiscountAmount"
|
v-if="doc.enableDiscounting"
|
||||||
|
:show-label="true"
|
||||||
|
:label-right="false"
|
||||||
|
class="
|
||||||
|
text-base
|
||||||
|
bg-gray-100
|
||||||
|
rounded
|
||||||
|
flex
|
||||||
|
items-center
|
||||||
|
justify-center
|
||||||
|
w-ful
|
||||||
|
"
|
||||||
|
input-class="px-3 py-2 text-base bg-transparent text-right"
|
||||||
|
:df="getField('setDiscountAmount')"
|
||||||
|
:value="doc.setDiscountAmount"
|
||||||
|
@change="(value) => doc.set('setDiscountAmount', value)"
|
||||||
|
:read-only="doc?.submitted"
|
||||||
|
/>
|
||||||
|
<FormControl
|
||||||
|
v-if="doc.enableDiscounting && !doc.setDiscountAmount"
|
||||||
class="text-base bg-gray-100 rounded"
|
class="text-base bg-gray-100 rounded"
|
||||||
input-class="px-3 py-2 text-base bg-transparent text-right"
|
input-class="px-3 py-2 text-base bg-transparent text-right"
|
||||||
:df="getField('discountPercent')"
|
:df="getField('discountPercent')"
|
||||||
@ -104,7 +123,7 @@
|
|||||||
:read-only="doc?.submitted"
|
:read-only="doc?.submitted"
|
||||||
/>
|
/>
|
||||||
<FormControl
|
<FormControl
|
||||||
v-if="doc.discountAmount.float > 0 && doc.setDiscountAmount"
|
v-if="doc.enableDiscounting && doc.setDiscountAmount"
|
||||||
class="text-base bg-gray-100 rounded"
|
class="text-base bg-gray-100 rounded"
|
||||||
input-class="px-3 py-2 text-base bg-transparent text-right"
|
input-class="px-3 py-2 text-base bg-transparent text-right"
|
||||||
:df="getField('discountAmount')"
|
:df="getField('discountAmount')"
|
||||||
@ -352,11 +371,10 @@ export default {
|
|||||||
return text;
|
return text;
|
||||||
},
|
},
|
||||||
totalDiscount() {
|
totalDiscount() {
|
||||||
const discountAmount = this.doc?.discountAmount ?? fyo.pesa(0);
|
return this.discountAmount.add(this.itemDiscountAmount);
|
||||||
return discountAmount.add(this.itemDiscountAmount);
|
|
||||||
},
|
},
|
||||||
discountAmount() {
|
discountAmount() {
|
||||||
return this.doc?.discountAmount ?? fyo.pesa(0);
|
return this.doc?.getInvoiceDiscountAmount();
|
||||||
},
|
},
|
||||||
itemDiscountAmount() {
|
itemDiscountAmount() {
|
||||||
return this.doc.getItemDiscountAmount();
|
return this.doc.getItemDiscountAmount();
|
||||||
@ -397,12 +415,9 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fields = [
|
const fields = ['discountAfterTax'].map((fn) =>
|
||||||
'discountAfterTax',
|
fyo.getField(this.schemaName, fn)
|
||||||
'setDiscountAmount',
|
);
|
||||||
'discountAmount',
|
|
||||||
'discountPercent',
|
|
||||||
].map((fn) => fyo.getField(this.schemaName, fn));
|
|
||||||
|
|
||||||
this.toggleQuickEditDoc(this.doc, fields);
|
this.toggleQuickEditDoc(this.doc, fields);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user