2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 06:44:06 +00:00

fix: minor fixes

This commit is contained in:
akshayitzme 2023-09-06 16:29:38 +05:30 committed by akshayitzme
parent 7e7e3ed3cd
commit ffbce23f03
7 changed files with 55 additions and 73 deletions

View File

@ -394,7 +394,8 @@ export class BespokeQueries {
static async getPOSTransactedAmount(
db: DatabaseCore,
fromDate: Date
fromDate: Date,
toDate: Date
): Promise<Record<string, Money> | undefined> {
const sinvNames = (
await db.knex!(ModelNameEnum.SalesInvoice)
@ -403,7 +404,9 @@ export class BespokeQueries {
.andWhereRaw('datetime(date) > datetime(?)', [
new Date(fromDate.setHours(0, 0, 0)).toISOString(),
])
.andWhereRaw('datetime(date) < datetime(?)', [new Date().toISOString()])
.andWhereRaw('datetime(date) < datetime(?)', [
new Date(toDate.setHours(0, 0, 0)).toISOString(),
])
).map((row: { name: string }) => row.name);
if (!sinvNames.length) {

View File

@ -344,11 +344,13 @@ export class DatabaseHandler extends DatabaseBase {
}
async getPOSTransactedAmount(
fromDate: Date
fromDate: Date,
toDate: Date
): Promise<Record<string, Money> | undefined> {
return (await this.#demux.callBespoke(
'getPOSTransactedAmount',
fromDate
fromDate,
toDate
)) as Promise<Record<string, Money> | undefined>;
}

View File

@ -31,14 +31,15 @@ let sinvDocOne: SalesInvoice | undefined;
test('check pos transacted amount', async (t) => {
const transactedAmountBeforeTxn = await fyo.db.getPOSTransactedAmount(
new Date('2022-01-01')
new Date('2023-01-01'),
new Date('2023-01-02')
);
t.equals(transactedAmountBeforeTxn, undefined);
sinvDocOne = fyo.doc.getNewDoc(ModelNameEnum.SalesInvoice, {
isPOS: true,
date: new Date('2022-01-02'),
date: new Date('2023-01-01'),
account: 'Debtors',
party: customer.name,
}) as SalesInvoice;
@ -56,7 +57,7 @@ test('check pos transacted amount', async (t) => {
const sinvDocTwo = fyo.doc.getNewDoc(ModelNameEnum.SalesInvoice, {
isPOS: true,
date: new Date('2022-01-02'),
date: new Date('2023-01-01'),
account: 'Debtors',
party: customer.name,
}) as SalesInvoice;
@ -72,14 +73,17 @@ test('check pos transacted amount', async (t) => {
await paymentDocTwo.setMultiple({
paymentMethod: 'Transfer',
clearanceDate: new Date(),
clearanceDate: new Date('2023-01-01'),
referenceId: 'xxxxxxxx',
});
await paymentDocTwo.sync();
const transactedAmountAfterTxn: Record<string, Money> | undefined =
await fyo.db.getPOSTransactedAmount(new Date('2022-01-02'));
await fyo.db.getPOSTransactedAmount(
new Date('2023-01-01'),
new Date('2023-01-02')
);
t.true(transactedAmountAfterTxn);

View File

@ -194,7 +194,7 @@
<div class=""></div>
<div
v-if="row.links && row.links?.item.hasBatch"
v-if="row.links?.item && row.links?.item.hasBatch"
class="pl-6 px-4 pt-6 col-span-2"
>
<Link
@ -213,7 +213,7 @@
</div>
<div
v-if="row.links && row.links?.item.hasBatch"
v-if="row.links?.item && row.links?.item.hasBatch"
class="px-2 pt-6 col-span-2"
>
<Float
@ -233,7 +233,7 @@
</div>
<div
v-if="row.links && row.links?.item.hasSerialNumber"
v-if="row.links?.item && row.links?.item.hasSerialNumber"
class="px-2 pt-8 col-span-2"
>
<Text

View File

@ -109,7 +109,10 @@ export default defineComponent({
return;
}
const fromDate = fyo.singles.POSShift?.openingDate;
this.transactedAmount = await fyo.db.getPOSTransactedAmount(fromDate);
this.transactedAmount = await fyo.db.getPOSTransactedAmount(
fromDate,
new Date()
);
},
seedClosingCash() {
if (!this.posShiftDoc) {

View File

@ -26,6 +26,7 @@
@set-cash-amount="setCashAmount"
@set-transfer-amount="setTransferAmount"
@set-transfer-ref-no="setTransferRefNo"
@set-transfer-clearance-date="setTransferClearanceDate"
/>
<div
@ -58,8 +59,8 @@
<div class="flex flex-col gap-3" style="height: calc(100vh - 6rem)">
<div class="bg-white border grow h-full p-4 rounded-md">
<!-- Customer Search -->
<Link
v-if="sinvDoc.fieldMap"
class="flex-shrink-0"
:border="true"
:value="sinvDoc.party"
@ -116,11 +117,8 @@
:text-right="true"
/>
<FloatingLabelCurrencyInput
:df="{
label: t`Total`,
fieldtype: 'Currency',
fieldname: 'total',
}"
v-if="sinvDoc.fieldMap"
:df="sinvDoc.fieldMap.grandTotal"
size="large"
:value="sinvDoc.grandTotal"
:read-only="true"
@ -212,8 +210,8 @@ export default defineComponent({
},
provide() {
return {
doc: computed(() => this.sinvDoc),
cashAmount: computed(() => this.cashAmount),
doc: computed(() => this.sinvDoc),
isDiscountingEnabled: computed(() => this.isDiscountingEnabled),
itemDiscounts: computed(() => this.itemDiscounts),
itemQtyMap: computed(() => this.itemQtyMap),
@ -221,6 +219,7 @@ export default defineComponent({
sinvDoc: computed(() => this.sinvDoc),
totalTaxedAmount: computed(() => this.totalTaxedAmount),
transferAmount: computed(() => this.transferAmount),
transferClearanceDate: computed(() => this.transferClearanceDate),
transferRefNo: computed(() => this.transferRefNo),
};
},

View File

@ -1,13 +1,9 @@
<template>
<Modal class="w-2/6 ml-auto mr-3.5" :set-close-listener="false">
<div class="px-4 py-6 grid" style="height: 95vh">
<div v-if="sinvDoc.fieldMap" class="px-4 py-6 grid" style="height: 95vh">
<div class="grid grid-cols-2 gap-6">
<Currency
:df="{
label: t`Cash`,
fieldtype: 'Currency',
fieldname: 'cash',
}"
:df="fyo.fieldMap.PaymentFor.amount"
:read-only="!transferAmount.isZero()"
:border="true"
:text-right="true"
@ -27,11 +23,7 @@
</Button>
<Currency
:df="{
label: t`Transfer`,
fieldtype: 'Currency',
fieldname: 'transfer',
}"
:df="fyo.fieldMap.PaymentFor.amount"
:read-only="!cashAmount.isZero()"
:border="true"
:text-right="true"
@ -54,11 +46,7 @@
<div class="mt-8 grid grid-cols-2 gap-6">
<Data
v-show="!transferAmount.isZero()"
:df="{
label: t`Transfer Ref No.`,
fieldtype: 'Data',
fieldname: 'transferRefNo',
}"
:df="fyo.fieldMap.Payment.referenceId"
:show-label="true"
:border="true"
:required="!transferAmount.isZero()"
@ -68,14 +56,11 @@
<Date
v-show="!transferAmount.isZero()"
:df="{
label: t`Clearance Date`,
fieldtype: 'Date',
fieldname: 'transferClearanceDate',
}"
:df="fyo.fieldMap.Payment.clearanceDate"
:show-label="true"
:border="true"
:required="!transferAmount.isZero()"
:value="transferClearanceDate"
@change="(value:Date) => $emit('setTransferClearanceDate', value)"
/>
</div>
@ -114,11 +99,7 @@
class="mb-14 row-start-4 row-span-2 grid grid-cols-2 gap-x-6 gap-y-11"
>
<Currency
:df="{
label: t`Net Total`,
fieldtype: 'Currency',
fieldname: 'netTotal',
}"
:df="sinvDoc.fieldMap.netTotal"
:read-only="true"
:show-label="true"
:border="true"
@ -140,11 +121,7 @@
/>
<Currency
:df="{
label: t`Total Amount`,
fieldtype: 'Currency',
fieldname: 'totalAmount',
}"
:df="sinvDoc.fieldMap.baseGrandTotal"
:read-only="true"
:show-label="true"
:border="true"
@ -154,11 +131,7 @@
<Currency
v-if="isDiscountingEnabled"
:df="{
label: t`Discount Amount`,
fieldtype: 'Currency',
fieldname: 'discountAmount',
}"
:df="sinvDoc.fieldMap.discountAmount"
:read-only="true"
:show-label="true"
:border="true"
@ -167,11 +140,7 @@
/>
<Currency
:df="{
label: t`Grand Total`,
fieldtype: 'Currency',
fieldname: 'grandTotal',
}"
:df="sinvDoc.fieldMap.grandTotal"
:read-only="true"
:show-label="true"
:border="true"
@ -262,6 +231,7 @@ export default defineComponent({
transferAmount: inject('transferAmount') as Money,
sinvDoc: inject('sinvDoc') as SalesInvoice,
transferRefNo: inject('transferRefNo') as string,
transferClearanceDate: inject('transferClearanceDate') as Date,
totalTaxedAmount: inject('totalTaxedAmount') as Money,
};
},
@ -273,15 +243,16 @@ export default defineComponent({
return grandTotal.sub(this.transferAmount);
}
if (this.transferAmount.isZero()) {
return grandTotal.sub(this.cashAmount);
}
const totalPaidAmount = this.cashAmount.add(this.transferAmount);
return grandTotal.sub(totalPaidAmount);
return grandTotal.sub(this.cashAmount);
},
paidChange(): Money {
return this.cashAmount.sub(this.sinvDoc?.grandTotal ?? fyo.pesa(0));
const grandTotal = this.sinvDoc?.grandTotal ?? fyo.pesa(0);
if (this.cashAmount.isZero()) {
return this.transferAmount.sub(grandTotal);
}
return this.cashAmount.sub(grandTotal);
},
showBalanceAmount(): boolean {
if (
@ -309,15 +280,15 @@ export default defineComponent({
return false;
}
if (this.cashAmount.lt(this.sinvDoc?.grandTotal ?? fyo.pesa(0))) {
return false;
if (this.cashAmount.gt(this.sinvDoc?.grandTotal ?? fyo.pesa(0))) {
return true;
}
if (this.transferAmount.gte(this.sinvDoc?.grandTotal ?? fyo.pesa(0))) {
return false;
if (this.transferAmount.gt(this.sinvDoc?.grandTotal ?? fyo.pesa(0))) {
return true;
}
return true;
return false;
},
},
methods: {