2019-11-20 00:40:01 +05:30
|
|
|
<template>
|
|
|
|
<div class="flex flex-col">
|
2022-04-30 00:34:08 +05:30
|
|
|
<!-- Page Header (Title, Buttons, etc) -->
|
2022-04-27 17:32:43 +05:30
|
|
|
<PageHeader :backLink="true">
|
2022-05-01 13:09:03 +05:30
|
|
|
<template v-if="doc">
|
2021-11-11 15:05:34 +05:30
|
|
|
<StatusBadge :status="status" />
|
2022-05-01 13:09:03 +05:30
|
|
|
<DropdownWithActions :actions="actions" />
|
2019-11-20 00:40:01 +05:30
|
|
|
<Button
|
2022-04-30 00:34:08 +05:30
|
|
|
v-if="doc.notInserted || doc.dirty"
|
2019-11-20 00:40:01 +05:30
|
|
|
type="primary"
|
2022-05-01 13:09:03 +05:30
|
|
|
class="text-white text-xs"
|
2022-04-30 00:34:08 +05:30
|
|
|
@click="sync"
|
2019-11-20 00:40:01 +05:30
|
|
|
>
|
2022-02-14 10:45:26 +05:30
|
|
|
{{ t`Save` }}
|
2019-12-20 12:14:31 +05:30
|
|
|
</Button>
|
2019-11-20 00:40:01 +05:30
|
|
|
<Button
|
2022-04-30 00:34:08 +05:30
|
|
|
v-else-if="!doc.dirty && !doc.notInserted && !doc.submitted"
|
2019-11-20 00:40:01 +05:30
|
|
|
type="primary"
|
2022-05-01 13:09:03 +05:30
|
|
|
class="text-white text-xs"
|
2022-04-30 00:34:08 +05:30
|
|
|
@click="submit"
|
2019-11-20 00:40:01 +05:30
|
|
|
>
|
2022-02-14 10:45:26 +05:30
|
|
|
{{ t`Submit` }}
|
2019-12-20 12:14:31 +05:30
|
|
|
</Button>
|
2019-11-20 00:40:01 +05:30
|
|
|
</template>
|
|
|
|
</PageHeader>
|
2022-04-30 00:34:08 +05:30
|
|
|
|
|
|
|
<!-- Journal Entry Form -->
|
2021-09-16 17:54:22 +05:30
|
|
|
<div v-if="doc" class="flex justify-center flex-1 mb-8 mt-2">
|
2019-11-20 00:40:01 +05:30
|
|
|
<div
|
2022-05-01 13:09:03 +05:30
|
|
|
class="
|
|
|
|
border
|
|
|
|
rounded-lg
|
|
|
|
shadow
|
|
|
|
h-full
|
|
|
|
flex flex-col
|
|
|
|
justify-between
|
|
|
|
w-600
|
|
|
|
"
|
2019-11-20 00:40:01 +05:30
|
|
|
>
|
|
|
|
<div>
|
2022-05-01 13:09:03 +05:30
|
|
|
<div class="m-6 flex flex-col gap-2">
|
2019-11-20 00:40:01 +05:30
|
|
|
<h1 class="text-2xl font-semibold">
|
2022-04-30 00:34:08 +05:30
|
|
|
{{ doc.notInserted ? t`New Journal Entry` : doc.name }}
|
2019-11-20 00:40:01 +05:30
|
|
|
</h1>
|
2022-04-30 00:34:08 +05:30
|
|
|
|
|
|
|
<!-- First Column of Fields -->
|
2022-05-01 13:09:03 +05:30
|
|
|
<div class="flex flex-row justify-between gap-2">
|
|
|
|
<FormControl
|
|
|
|
class="w-1/3"
|
|
|
|
:df="getField('entryType')"
|
|
|
|
:value="doc.entryType"
|
|
|
|
placeholder="Entry Type"
|
|
|
|
@change="(value) => doc.set('entryType', value)"
|
|
|
|
input-class="bg-gray-100 px-3 py-2 text-base"
|
|
|
|
:read-only="doc.submitted"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
|
|
|
/>
|
|
|
|
<FormControl
|
|
|
|
class="w-1/3"
|
|
|
|
:df="getField('referenceNumber')"
|
|
|
|
:value="doc.referenceNumber"
|
|
|
|
:placeholder="'Reference Number'"
|
|
|
|
@change="(value) => doc.set('referenceNumber', value)"
|
|
|
|
input-class="bg-gray-100 p-2 text-base"
|
|
|
|
:read-only="doc.submitted"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
|
|
|
/>
|
|
|
|
<FormControl
|
|
|
|
:df="getField('numberSeries')"
|
|
|
|
:value="doc.numberSeries"
|
|
|
|
@change="(value) => doc.set('numberSeries', value)"
|
|
|
|
class="bg-gray-100 rounded w-1/3"
|
|
|
|
input-class="p-2 text-base bg-transparent"
|
|
|
|
:read-only="!doc.notInserted || doc.submitted"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
|
|
|
/>
|
|
|
|
</div>
|
2022-04-30 00:34:08 +05:30
|
|
|
|
2022-05-01 13:09:03 +05:30
|
|
|
<!-- Second Row of Fields -->
|
|
|
|
<div class="flex flex-row justify-between gap-2">
|
|
|
|
<FormControl
|
|
|
|
class="w-1/3"
|
|
|
|
:df="getField('date')"
|
|
|
|
:value="doc.date"
|
|
|
|
:placeholder="'Date'"
|
|
|
|
@change="(value) => doc.set('date', value)"
|
|
|
|
input-class="bg-gray-100 px-3 py-2 text-base"
|
|
|
|
:read-only="doc.submitted"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
|
|
|
/>
|
|
|
|
<div class="w-1/3" />
|
|
|
|
<FormControl
|
|
|
|
class="w-1/3"
|
|
|
|
:df="getField('referenceDate')"
|
|
|
|
:value="doc.referenceDate"
|
|
|
|
:placeholder="'Reference Date'"
|
|
|
|
@change="(value) => doc.set('referenceDate', value)"
|
|
|
|
input-class="bg-gray-100 px-3 py-2 text-base"
|
|
|
|
:read-only="doc.submitted"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
|
|
|
/>
|
2019-11-20 00:40:01 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
2022-05-01 13:09:03 +05:30
|
|
|
<hr />
|
2022-04-30 00:34:08 +05:30
|
|
|
|
|
|
|
<!-- Account Entries Table -->
|
2022-05-01 13:09:03 +05:30
|
|
|
<Table
|
2022-04-30 00:34:08 +05:30
|
|
|
class="mt-2 px-6 text-base"
|
|
|
|
:df="getField('accounts')"
|
|
|
|
:value="doc.accounts"
|
|
|
|
:showHeader="true"
|
2022-05-01 13:09:03 +05:30
|
|
|
:max-rows-before-overflow="6"
|
2022-04-30 00:34:08 +05:30
|
|
|
:read-only="doc.submitted"
|
|
|
|
/>
|
2019-11-20 00:40:01 +05:30
|
|
|
</div>
|
2022-04-30 00:34:08 +05:30
|
|
|
|
|
|
|
<!-- Footer -->
|
2022-05-01 13:09:03 +05:30
|
|
|
<div v-if="doc.accounts?.length ?? 0">
|
|
|
|
<hr />
|
|
|
|
<div class="flex justify-between text-base m-6 gap-12">
|
2022-04-30 00:34:08 +05:30
|
|
|
<!-- User Remark -->
|
2022-05-01 13:09:03 +05:30
|
|
|
<FormControl
|
|
|
|
class="w-1/2 self-end"
|
|
|
|
input-class="bg-gray-100"
|
|
|
|
:df="getField('userRemark')"
|
|
|
|
:value="doc.userRemark"
|
|
|
|
@change="(value) => doc.set('userRemark', value)"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
|
|
|
:read-only="doc.submitted"
|
|
|
|
/>
|
2022-04-30 00:34:08 +05:30
|
|
|
|
|
|
|
<!-- Debit and Credit -->
|
2022-05-01 13:09:03 +05:30
|
|
|
<div class="w-1/2 gap-2 flex flex-col self-end font-semibold">
|
|
|
|
<div class="flex justify-between text-green-600">
|
|
|
|
<div>{{ t`Total Debit` }}</div>
|
|
|
|
<div>{{ totalDebit }}</div>
|
|
|
|
</div>
|
|
|
|
<hr />
|
|
|
|
<div class="flex justify-between text-red-600">
|
|
|
|
<div>{{ t`Total Credit` }}</div>
|
|
|
|
<div>{{ totalCredit }}</div>
|
|
|
|
</div>
|
2019-11-20 00:40:01 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2022-04-30 00:34:08 +05:30
|
|
|
import { computed } from '@vue/reactivity';
|
|
|
|
import { ModelNameEnum } from 'models/types';
|
2022-04-20 12:08:47 +05:30
|
|
|
import Button from 'src/components/Button';
|
2022-04-22 16:32:03 +05:30
|
|
|
import FormControl from 'src/components/Controls/FormControl.vue';
|
2022-05-01 13:09:03 +05:30
|
|
|
import Table from 'src/components/Controls/Table.vue';
|
2022-04-20 12:08:47 +05:30
|
|
|
import DropdownWithActions from 'src/components/DropdownWithActions';
|
|
|
|
import PageHeader from 'src/components/PageHeader';
|
|
|
|
import StatusBadge from 'src/components/StatusBadge';
|
2022-04-21 18:38:36 +05:30
|
|
|
import { fyo } from 'src/initFyo';
|
2022-04-30 00:34:08 +05:30
|
|
|
import {
|
|
|
|
getActionsForDocument,
|
|
|
|
routeTo,
|
|
|
|
showMessageDialog
|
|
|
|
} from 'src/utils/ui';
|
2022-01-19 13:09:39 +05:30
|
|
|
import { handleErrorWithDialog } from '../errorHandling';
|
2019-11-20 00:40:01 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'JournalEntryForm',
|
|
|
|
props: ['name'],
|
|
|
|
components: {
|
|
|
|
PageHeader,
|
|
|
|
Button,
|
2019-12-20 12:14:31 +05:30
|
|
|
DropdownWithActions,
|
2021-11-11 15:05:34 +05:30
|
|
|
StatusBadge,
|
2019-11-20 00:40:01 +05:30
|
|
|
FormControl,
|
2022-05-01 13:09:03 +05:30
|
|
|
Table
|
|
|
|
},
|
2019-11-20 00:40:01 +05:30
|
|
|
provide() {
|
|
|
|
return {
|
2022-04-30 00:34:08 +05:30
|
|
|
schemaName: this.schemaName,
|
2021-11-11 15:05:34 +05:30
|
|
|
name: this.name,
|
2022-04-30 00:34:08 +05:30
|
|
|
doc: computed(() => this.doc),
|
2019-11-20 00:40:01 +05:30
|
|
|
};
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2022-04-30 00:34:08 +05:30
|
|
|
schemaName: ModelNameEnum.JournalEntry,
|
2021-11-11 15:05:34 +05:30
|
|
|
doc: null,
|
2019-11-20 00:40:01 +05:30
|
|
|
};
|
|
|
|
},
|
2022-04-30 00:34:08 +05:30
|
|
|
async mounted() {
|
|
|
|
try {
|
|
|
|
this.doc = await fyo.doc.getDoc(this.schemaName, this.name);
|
|
|
|
} catch (error) {
|
|
|
|
if (error instanceof fyo.errors.NotFoundError) {
|
|
|
|
routeTo(`/list/${this.schemaName}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.handleError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fyo.store.isDevelopment) {
|
|
|
|
window.je = this;
|
|
|
|
}
|
|
|
|
},
|
2019-11-20 00:40:01 +05:30
|
|
|
computed: {
|
2021-11-11 15:05:34 +05:30
|
|
|
status() {
|
2022-04-30 00:34:08 +05:30
|
|
|
if (this.doc.notInserted || !this.doc.submitted) {
|
2021-11-11 15:05:34 +05:30
|
|
|
return 'Draft';
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
},
|
2019-11-20 00:40:01 +05:30
|
|
|
totalDebit() {
|
|
|
|
let value = 0;
|
|
|
|
if (this.doc.accounts) {
|
|
|
|
value = this.doc.getSum('accounts', 'debit');
|
|
|
|
}
|
2022-04-21 18:38:36 +05:30
|
|
|
return fyo.format(value, 'Currency');
|
2019-11-20 00:40:01 +05:30
|
|
|
},
|
|
|
|
totalCredit() {
|
|
|
|
let value = 0;
|
|
|
|
if (this.doc.accounts) {
|
|
|
|
value = this.doc.getSum('accounts', 'credit');
|
|
|
|
}
|
2022-04-21 18:38:36 +05:30
|
|
|
return fyo.format(value, 'Currency');
|
2019-12-20 12:14:31 +05:30
|
|
|
},
|
|
|
|
actions() {
|
|
|
|
return getActionsForDocument(this.doc);
|
2021-11-11 15:05:34 +05:30
|
|
|
},
|
2019-11-20 00:40:01 +05:30
|
|
|
},
|
|
|
|
methods: {
|
2022-04-30 00:34:08 +05:30
|
|
|
getField(fieldname) {
|
|
|
|
return fyo.getField(ModelNameEnum.JournalEntry, fieldname);
|
|
|
|
},
|
|
|
|
async sync() {
|
2022-04-24 12:18:44 +05:30
|
|
|
return this.doc.sync().catch(this.handleError);
|
2019-11-20 00:40:01 +05:30
|
|
|
},
|
2022-04-30 00:34:08 +05:30
|
|
|
async submit() {
|
2021-12-16 17:22:23 +05:30
|
|
|
showMessageDialog({
|
2022-02-09 12:47:54 +05:30
|
|
|
message: this.t`Are you sure you want to submit this Journal Entry?`,
|
2021-12-16 17:22:23 +05:30
|
|
|
buttons: [
|
|
|
|
{
|
2022-02-09 12:47:54 +05:30
|
|
|
label: this.t`Yes`,
|
2021-12-16 17:22:23 +05:30
|
|
|
action: () => {
|
|
|
|
this.doc.submit().catch(this.handleError);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-02-09 12:47:54 +05:30
|
|
|
label: this.t`No`,
|
2021-12-16 17:22:23 +05:30
|
|
|
action() {},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2019-11-20 00:40:01 +05:30
|
|
|
},
|
2019-12-20 12:14:31 +05:30
|
|
|
handleError(e) {
|
|
|
|
handleErrorWithDialog(e, this.doc);
|
2021-11-11 15:05:34 +05:30
|
|
|
},
|
|
|
|
},
|
2019-11-20 00:40:01 +05:30
|
|
|
};
|
|
|
|
</script>
|