2019-11-19 19:10:01 +00:00
|
|
|
<template>
|
|
|
|
<div class="flex flex-col">
|
|
|
|
<PageHeader>
|
2019-12-26 13:44:27 +00:00
|
|
|
<BackLink slot="title" />
|
2019-12-20 06:44:31 +00:00
|
|
|
<template slot="actions" v-if="doc">
|
2021-11-11 09:35:34 +00:00
|
|
|
<StatusBadge :status="status" />
|
2019-12-20 06:44:31 +00:00
|
|
|
<DropdownWithActions class="ml-2" :actions="actions" />
|
2019-11-19 19:10:01 +00:00
|
|
|
<Button
|
|
|
|
v-if="doc._notInserted || doc._dirty"
|
|
|
|
type="primary"
|
|
|
|
class="text-white text-xs ml-2"
|
|
|
|
@click="onSaveClick"
|
|
|
|
>
|
2019-12-20 06:44:31 +00:00
|
|
|
{{ _('Save') }}
|
|
|
|
</Button>
|
2019-11-19 19:10:01 +00:00
|
|
|
<Button
|
|
|
|
v-if="!doc._dirty && !doc._notInserted && !doc.submitted"
|
|
|
|
type="primary"
|
|
|
|
class="text-white text-xs ml-2"
|
|
|
|
@click="onSubmitClick"
|
|
|
|
>
|
2019-12-20 06:44:31 +00:00
|
|
|
{{ _('Submit') }}
|
|
|
|
</Button>
|
2019-11-19 19:10:01 +00:00
|
|
|
</template>
|
|
|
|
</PageHeader>
|
2021-09-16 12:24:22 +00:00
|
|
|
<div v-if="doc" class="flex justify-center flex-1 mb-8 mt-2">
|
2019-11-19 19:10:01 +00:00
|
|
|
<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">
|
|
|
|
{{ doc._notInserted ? _('New Journal Entry') : doc.name }}
|
|
|
|
</h1>
|
|
|
|
<div class="flex justify-between mt-2">
|
|
|
|
<div class="w-1/3">
|
|
|
|
<FormControl
|
|
|
|
:df="meta.getField('entryType')"
|
|
|
|
:value="doc.entryType"
|
|
|
|
placeholder="Entry Type"
|
2021-11-11 09:35:34 +00:00
|
|
|
@change="(value) => doc.set('entryType', value)"
|
2019-12-11 09:38:20 +00:00
|
|
|
input-class="bg-gray-100 px-3 py-2 text-base"
|
2019-11-19 19:10:01 +00:00
|
|
|
:show-label="true"
|
2021-09-16 12:24:22 +00:00
|
|
|
:read-only="doc.submitted"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
2019-11-19 19:10:01 +00:00
|
|
|
/>
|
|
|
|
<FormControl
|
|
|
|
class="mt-2"
|
|
|
|
:df="meta.getField('date')"
|
|
|
|
:value="doc.date"
|
|
|
|
:placeholder="'Date'"
|
2021-11-11 09:35:34 +00:00
|
|
|
@change="(value) => doc.set('date', value)"
|
2019-12-11 09:38:20 +00:00
|
|
|
input-class="bg-gray-100 px-3 py-2 text-base"
|
2019-11-19 19:10:01 +00:00
|
|
|
:show-label="true"
|
2021-09-16 12:24:22 +00:00
|
|
|
:read-only="doc.submitted"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
2019-11-19 19:10:01 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="w-1/3">
|
|
|
|
<FormControl
|
|
|
|
:df="meta.getField('referenceNumber')"
|
|
|
|
:value="doc.referenceNumber"
|
|
|
|
:placeholder="'Reference Number'"
|
2021-11-11 09:35:34 +00:00
|
|
|
@change="(value) => doc.set('referenceNumber', value)"
|
2019-12-11 09:38:20 +00:00
|
|
|
input-class="bg-gray-100 p-2 text-base"
|
2019-11-19 19:10:01 +00:00
|
|
|
:show-label="true"
|
2021-09-16 12:24:22 +00:00
|
|
|
:read-only="doc.submitted"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
2019-11-19 19:10:01 +00:00
|
|
|
/>
|
|
|
|
<FormControl
|
|
|
|
class="mt-2"
|
|
|
|
:df="meta.getField('referenceDate')"
|
|
|
|
:value="doc.date"
|
|
|
|
:placeholder="'Reference Date'"
|
2021-11-11 09:35:34 +00:00
|
|
|
@change="(value) => doc.set('referenceDate', value)"
|
2019-12-11 09:38:20 +00:00
|
|
|
input-class="bg-gray-100 px-3 py-2 text-base"
|
2019-11-19 19:10:01 +00:00
|
|
|
:show-label="true"
|
2021-09-16 12:24:22 +00:00
|
|
|
:read-only="doc.submitted"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
2019-11-19 19:10:01 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="mt-2 px-6 text-base">
|
|
|
|
<FormControl
|
|
|
|
:df="meta.getField('accounts')"
|
|
|
|
:value="doc.accounts"
|
|
|
|
:showHeader="true"
|
2021-09-16 12:24:22 +00:00
|
|
|
:max-rows-before-overflow="4"
|
2021-11-11 09:35:34 +00:00
|
|
|
@change="(value) => doc.set('accounts', value)"
|
2019-11-19 19:10:01 +00:00
|
|
|
:read-only="doc.submitted"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<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"
|
|
|
|
>
|
|
|
|
<div class="text-sm">
|
|
|
|
<FormControl
|
|
|
|
:df="meta.getField('userRemark')"
|
|
|
|
:value="doc.userRemark"
|
2021-11-11 09:35:34 +00:00
|
|
|
@change="(value) => doc.set('userRemark', value)"
|
2021-09-16 12:24:22 +00:00
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
|
|
|
:read-only="doc.submitted"
|
2019-11-19 19:10:01 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="text-right font-semibold text-green-700 px-3">
|
|
|
|
{{ totalDebit }}
|
|
|
|
</div>
|
|
|
|
<div class="text-right font-semibold text-red-700 px-3">
|
|
|
|
{{ totalCredit }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2019-12-20 06:44:31 +00:00
|
|
|
import frappe from 'frappejs';
|
2019-11-19 19:10:01 +00:00
|
|
|
import PageHeader from '@/components/PageHeader';
|
|
|
|
import Button from '@/components/Button';
|
2019-12-20 06:44:31 +00:00
|
|
|
import DropdownWithActions from '@/components/DropdownWithActions';
|
2019-11-19 19:10:01 +00:00
|
|
|
import FormControl from '@/components/Controls/FormControl';
|
2019-12-04 17:26:40 +00:00
|
|
|
import BackLink from '@/components/BackLink';
|
2021-11-11 09:35:34 +00:00
|
|
|
import StatusBadge from '@/components/StatusBadge';
|
2019-12-20 06:44:31 +00:00
|
|
|
import { handleErrorWithDialog, getActionsForDocument } from '@/utils';
|
2019-11-19 19:10:01 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'JournalEntryForm',
|
|
|
|
props: ['name'],
|
|
|
|
components: {
|
|
|
|
PageHeader,
|
|
|
|
Button,
|
2019-12-20 06:44:31 +00:00
|
|
|
DropdownWithActions,
|
2021-11-11 09:35:34 +00:00
|
|
|
StatusBadge,
|
2019-11-19 19:10:01 +00:00
|
|
|
FormControl,
|
2021-11-11 09:35:34 +00:00
|
|
|
BackLink,
|
2019-11-19 19:10:01 +00:00
|
|
|
},
|
|
|
|
provide() {
|
|
|
|
return {
|
|
|
|
doctype: 'JournalEntry',
|
2021-11-11 09:35:34 +00:00
|
|
|
name: this.name,
|
2019-11-19 19:10:01 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
doctype: 'JournalEntry',
|
2021-11-11 09:35:34 +00:00
|
|
|
doc: null,
|
2019-11-19 19:10:01 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2019-12-20 06:44:31 +00:00
|
|
|
meta() {
|
|
|
|
return frappe.getMeta(this.doctype);
|
|
|
|
},
|
2021-11-11 09:35:34 +00:00
|
|
|
status() {
|
|
|
|
if (this.doc._notInserted || !this.doc.submitted) {
|
|
|
|
return 'Draft';
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
},
|
2019-11-19 19:10:01 +00:00
|
|
|
totalDebit() {
|
|
|
|
let value = 0;
|
|
|
|
if (this.doc.accounts) {
|
|
|
|
value = this.doc.getSum('accounts', 'debit');
|
|
|
|
}
|
|
|
|
return frappe.format(value, 'Currency');
|
|
|
|
},
|
|
|
|
totalCredit() {
|
|
|
|
let value = 0;
|
|
|
|
if (this.doc.accounts) {
|
|
|
|
value = this.doc.getSum('accounts', 'credit');
|
|
|
|
}
|
|
|
|
return frappe.format(value, 'Currency');
|
2019-12-20 06:44:31 +00:00
|
|
|
},
|
|
|
|
actions() {
|
|
|
|
return getActionsForDocument(this.doc);
|
2021-11-11 09:35:34 +00:00
|
|
|
},
|
2019-11-19 19:10:01 +00:00
|
|
|
},
|
|
|
|
async mounted() {
|
2019-12-20 06:44:31 +00:00
|
|
|
try {
|
|
|
|
this.doc = await frappe.getDoc(this.doctype, this.name);
|
|
|
|
window.je = this.doc;
|
|
|
|
} catch (error) {
|
|
|
|
if (error instanceof frappe.errors.NotFoundError) {
|
|
|
|
this.$router.push(`/list/${this.doctype}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.handleError(error);
|
|
|
|
}
|
2019-11-19 19:10:01 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async onSaveClick() {
|
2019-12-20 06:44:31 +00:00
|
|
|
return this.doc.insertOrUpdate().catch(this.handleError);
|
2019-11-19 19:10:01 +00:00
|
|
|
},
|
|
|
|
async onSubmitClick() {
|
2019-12-20 06:44:31 +00:00
|
|
|
await this.doc.submit().catch(this.handleError);
|
2019-11-19 19:10:01 +00:00
|
|
|
},
|
2019-12-20 06:44:31 +00:00
|
|
|
handleError(e) {
|
|
|
|
handleErrorWithDialog(e, this.doc);
|
2021-11-11 09:35:34 +00:00
|
|
|
},
|
|
|
|
},
|
2019-11-19 19:10:01 +00:00
|
|
|
};
|
|
|
|
</script>
|