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-02-10 13:12:43 +05:30
|
|
|
<template #actions v-if="doc">
|
2021-11-11 15:05:34 +05:30
|
|
|
<StatusBadge :status="status" />
|
2019-12-20 12:14:31 +05:30
|
|
|
<DropdownWithActions class="ml-2" :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"
|
|
|
|
class="text-white text-xs ml-2"
|
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"
|
|
|
|
class="text-white text-xs ml-2"
|
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
|
|
|
|
class="border rounded-lg shadow h-full flex flex-col justify-between"
|
|
|
|
style="width: 600px"
|
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<div class="mt-8 px-6">
|
|
|
|
<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-03-08 13:13:04 +05:30
|
|
|
<div class="flex justify-between mt-2 gap-2">
|
2019-11-20 00:40:01 +05:30
|
|
|
<div class="w-1/3">
|
|
|
|
<FormControl
|
2022-04-30 00:34:08 +05:30
|
|
|
:df="getField('entryType')"
|
2019-11-20 00:40:01 +05:30
|
|
|
:value="doc.entryType"
|
|
|
|
placeholder="Entry Type"
|
2021-11-11 15:05:34 +05:30
|
|
|
@change="(value) => doc.set('entryType', value)"
|
2019-12-11 15:08:20 +05:30
|
|
|
input-class="bg-gray-100 px-3 py-2 text-base"
|
2021-09-16 17:54:22 +05:30
|
|
|
:read-only="doc.submitted"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
2019-11-20 00:40:01 +05:30
|
|
|
/>
|
|
|
|
<FormControl
|
|
|
|
class="mt-2"
|
2022-04-30 00:34:08 +05:30
|
|
|
:df="getField('date')"
|
2019-11-20 00:40:01 +05:30
|
|
|
:value="doc.date"
|
|
|
|
:placeholder="'Date'"
|
2021-11-11 15:05:34 +05:30
|
|
|
@change="(value) => doc.set('date', value)"
|
2019-12-11 15:08:20 +05:30
|
|
|
input-class="bg-gray-100 px-3 py-2 text-base"
|
2021-09-16 17:54:22 +05:30
|
|
|
:read-only="doc.submitted"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
2019-11-20 00:40:01 +05:30
|
|
|
/>
|
|
|
|
</div>
|
2022-04-30 00:34:08 +05:30
|
|
|
|
|
|
|
<!-- Second Column of Fields -->
|
2019-11-20 00:40:01 +05:30
|
|
|
<div class="w-1/3">
|
|
|
|
<FormControl
|
2022-04-30 00:34:08 +05:30
|
|
|
:df="getField('referenceNumber')"
|
2019-11-20 00:40:01 +05:30
|
|
|
:value="doc.referenceNumber"
|
|
|
|
:placeholder="'Reference Number'"
|
2021-11-11 15:05:34 +05:30
|
|
|
@change="(value) => doc.set('referenceNumber', value)"
|
2019-12-11 15:08:20 +05:30
|
|
|
input-class="bg-gray-100 p-2 text-base"
|
2021-09-16 17:54:22 +05:30
|
|
|
:read-only="doc.submitted"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
2019-11-20 00:40:01 +05:30
|
|
|
/>
|
|
|
|
<FormControl
|
|
|
|
class="mt-2"
|
2022-04-30 00:34:08 +05:30
|
|
|
:df="getField('referenceDate')"
|
2021-12-16 15:54:01 +05:30
|
|
|
:value="doc.referenceDate"
|
2019-11-20 00:40:01 +05:30
|
|
|
:placeholder="'Reference Date'"
|
2021-11-11 15:05:34 +05:30
|
|
|
@change="(value) => doc.set('referenceDate', value)"
|
2019-12-11 15:08:20 +05:30
|
|
|
input-class="bg-gray-100 px-3 py-2 text-base"
|
2021-09-16 17:54:22 +05:30
|
|
|
:read-only="doc.submitted"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
2019-11-20 00:40:01 +05:30
|
|
|
/>
|
|
|
|
</div>
|
2022-04-30 00:34:08 +05:30
|
|
|
|
|
|
|
<!-- Third Column of Fields -->
|
2022-03-08 13:13:04 +05:30
|
|
|
<div class="w-1/3">
|
|
|
|
<FormControl
|
2022-04-30 00:34:08 +05:30
|
|
|
:df="getField('numberSeries')"
|
2022-03-08 13:13:04 +05:30
|
|
|
:value="doc.numberSeries"
|
|
|
|
@change="(value) => doc.set('numberSeries', value)"
|
2022-04-30 00:34:08 +05:30
|
|
|
class="bg-gray-100 rounded"
|
|
|
|
input-class="p-2 text-base bg-transparent"
|
|
|
|
:read-only="!doc.notInserted || doc.submitted"
|
2022-03-08 13:13:04 +05:30
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
|
|
|
/>
|
2022-04-21 18:38:36 +05:30
|
|
|
</div>
|
2019-11-20 00:40:01 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-30 00:34:08 +05:30
|
|
|
|
|
|
|
<!-- Account Entries Table -->
|
|
|
|
<FormControl
|
|
|
|
class="mt-2 px-6 text-base"
|
|
|
|
:df="getField('accounts')"
|
|
|
|
:value="doc.accounts"
|
|
|
|
:showHeader="true"
|
|
|
|
:max-rows-before-overflow="4"
|
|
|
|
@change="(value) => doc.set('accounts', value)"
|
|
|
|
:read-only="doc.submitted"
|
|
|
|
/>
|
2019-11-20 00:40:01 +05:30
|
|
|
</div>
|
2022-04-30 00:34:08 +05:30
|
|
|
|
|
|
|
<!-- Footer -->
|
2019-11-20 00:40:01 +05:30
|
|
|
<div class="px-6 mb-6">
|
|
|
|
<div
|
|
|
|
class="grid items-center border-t pt-3 pr-2"
|
|
|
|
style="grid-template-columns: 1.3fr 1fr 1fr"
|
|
|
|
>
|
2022-04-30 00:34:08 +05:30
|
|
|
<!-- User Remark -->
|
2019-11-20 00:40:01 +05:30
|
|
|
<div class="text-sm">
|
|
|
|
<FormControl
|
2022-04-30 00:34:08 +05:30
|
|
|
:df="getField('userRemark')"
|
2019-11-20 00:40:01 +05:30
|
|
|
:value="doc.userRemark"
|
2021-11-11 15:05:34 +05:30
|
|
|
@change="(value) => doc.set('userRemark', value)"
|
2021-09-16 17:54:22 +05:30
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
|
|
|
:read-only="doc.submitted"
|
2019-11-20 00:40:01 +05:30
|
|
|
/>
|
|
|
|
</div>
|
2022-04-30 00:34:08 +05:30
|
|
|
|
|
|
|
<!-- Debit and Credit -->
|
2021-11-22 11:25:09 +05:30
|
|
|
<div class="text-right font-semibold text-green-600 px-3">
|
2019-11-20 00:40:01 +05:30
|
|
|
{{ totalDebit }}
|
|
|
|
</div>
|
2021-11-22 11:25:09 +05:30
|
|
|
<div class="text-right font-semibold text-red-600 px-3">
|
2019-11-20 00:40:01 +05:30
|
|
|
{{ totalCredit }}
|
|
|
|
</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-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,
|
|
|
|
},
|
|
|
|
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>
|