2
0
mirror of https://github.com/frappe/books.git synced 2025-02-04 04:58:30 +00:00
books/src/pages/JournalEntryForm.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

263 lines
7.6 KiB
Vue
Raw Normal View History

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">
<template v-if="doc">
<StatusBadge :status="status" />
<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"
class="text-white text-xs"
2022-04-30 00:34:08 +05:30
@click="sync"
2019-11-20 00:40:01 +05:30
>
{{ t`Save` }}
</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"
2022-04-30 00:34:08 +05:30
@click="submit"
2019-11-20 00:40:01 +05:30
>
{{ t`Submit` }}
</Button>
2019-11-20 00:40:01 +05:30
</template>
</PageHeader>
2022-04-30 00:34:08 +05:30
<!-- Journal Entry Form -->
<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
w-600
"
2019-11-20 00:40:01 +05:30
>
<div>
<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 -->
<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
<!-- 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>
<hr />
2022-04-30 00:34:08 +05:30
<!-- Account Entries Table -->
<Table
2022-04-30 00:34:08 +05:30
class="mt-2 px-6 text-base"
:df="getField('accounts')"
:value="doc.accounts"
:showHeader="true"
: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 -->
<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 -->
<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 -->
<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';
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';
import { fyo } from 'src/initFyo';
2022-04-30 00:34:08 +05:30
import {
getActionsForDocument,
routeTo,
showMessageDialog
} from 'src/utils/ui';
import { handleErrorWithDialog } from '../errorHandling';
2019-11-20 00:40:01 +05:30
export default {
name: 'JournalEntryForm',
props: ['name'],
components: {
PageHeader,
Button,
DropdownWithActions,
StatusBadge,
2019-11-20 00:40:01 +05:30
FormControl,
Table
},
2019-11-20 00:40:01 +05:30
provide() {
return {
2022-04-30 00:34:08 +05:30
schemaName: this.schemaName,
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,
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: {
status() {
2022-04-30 00:34:08 +05:30
if (this.doc.notInserted || !this.doc.submitted) {
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');
}
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');
}
return fyo.format(value, 'Currency');
},
actions() {
return getActionsForDocument(this.doc);
},
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() {
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() {
showMessageDialog({
2022-02-09 12:47:54 +05:30
message: this.t`Are you sure you want to submit this Journal Entry?`,
buttons: [
{
2022-02-09 12:47:54 +05:30
label: this.t`Yes`,
action: () => {
this.doc.submit().catch(this.handleError);
},
},
{
2022-02-09 12:47:54 +05:30
label: this.t`No`,
action() {},
},
],
});
2019-11-20 00:40:01 +05:30
},
handleError(e) {
handleErrorWithDialog(e, this.doc);
},
},
2019-11-20 00:40:01 +05:30
};
</script>