2019-10-11 15:25:50 +05:30
|
|
|
<template>
|
2019-11-20 00:25:32 +05:30
|
|
|
<div class="flex flex-col" v-if="doc">
|
2019-10-11 15:25:50 +05:30
|
|
|
<PageHeader>
|
2019-12-04 22:56:40 +05:30
|
|
|
<BackLink slot="title" @click="routeToList" />
|
2019-10-11 15:25:50 +05:30
|
|
|
<template slot="actions">
|
2019-11-20 00:25:32 +05:30
|
|
|
<Button class="text-gray-900 text-xs" @click="openInvoiceSettings">
|
|
|
|
{{ _('Customise') }}
|
|
|
|
</Button>
|
2019-12-03 13:49:58 +05:30
|
|
|
<Button
|
|
|
|
v-if="doc.submitted"
|
|
|
|
class="text-gray-900 text-xs ml-2"
|
|
|
|
:icon="true"
|
|
|
|
@click="$router.push(`/print/${doc.doctype}/${doc.name}`)"
|
|
|
|
>
|
|
|
|
<feather-icon name="printer" class="w-4 h-4" />
|
|
|
|
</Button>
|
2019-10-30 01:03:26 +05:30
|
|
|
<Dropdown
|
2019-11-27 12:16:15 +05:30
|
|
|
v-if="actions && actions.length"
|
2019-11-20 00:25:32 +05:30
|
|
|
class="text-xs"
|
2019-11-27 12:16:15 +05:30
|
|
|
:items="actions"
|
2019-10-30 01:03:26 +05:30
|
|
|
right
|
|
|
|
>
|
|
|
|
<template v-slot="{ toggleDropdown }">
|
2019-11-20 00:25:32 +05:30
|
|
|
<Button
|
|
|
|
class="text-gray-900 text-xs ml-2"
|
|
|
|
:icon="true"
|
|
|
|
@click="toggleDropdown()"
|
|
|
|
>
|
|
|
|
<feather-icon name="more-horizontal" class="w-4 h-4" />
|
2019-10-30 01:03:26 +05:30
|
|
|
</Button>
|
|
|
|
</template>
|
|
|
|
</Dropdown>
|
2019-10-14 02:49:28 +05:30
|
|
|
<Button
|
2019-11-20 00:25:32 +05:30
|
|
|
v-if="showSave"
|
2019-10-14 02:49:28 +05:30
|
|
|
type="primary"
|
|
|
|
class="text-white text-xs ml-2"
|
|
|
|
@click="onSaveClick"
|
2019-11-20 00:25:32 +05:30
|
|
|
>
|
2019-12-04 22:56:40 +05:30
|
|
|
{{ _('Save') }}
|
|
|
|
</Button>
|
2019-10-14 02:49:28 +05:30
|
|
|
<Button
|
|
|
|
v-if="!doc._dirty && !doc._notInserted && !doc.submitted"
|
|
|
|
type="primary"
|
|
|
|
class="text-white text-xs ml-2"
|
|
|
|
@click="onSubmitClick"
|
2019-11-20 00:25:32 +05:30
|
|
|
>{{ _('Submit') }}</Button
|
|
|
|
>
|
2019-10-11 15:25:50 +05:30
|
|
|
</template>
|
|
|
|
</PageHeader>
|
2019-10-14 02:49:28 +05:30
|
|
|
<div
|
|
|
|
class="flex justify-center flex-1 mb-8 mt-6"
|
|
|
|
v-if="meta"
|
|
|
|
:class="doc.submitted && 'pointer-events-none'"
|
|
|
|
>
|
2019-11-20 00:25:32 +05:30
|
|
|
<div
|
|
|
|
class="border rounded-lg shadow h-full flex flex-col justify-between"
|
|
|
|
style="width: 600px"
|
|
|
|
>
|
2019-10-11 15:25:50 +05:30
|
|
|
<div>
|
2019-11-20 00:25:32 +05:30
|
|
|
<div class="px-6 pt-6" v-if="printSettings">
|
|
|
|
<div class="flex text-sm text-gray-900 border-b pb-4">
|
2019-10-11 15:25:50 +05:30
|
|
|
<div class="w-1/3">
|
2019-11-20 00:25:32 +05:30
|
|
|
<div v-if="printSettings.displayLogo">
|
|
|
|
<img
|
|
|
|
class="h-12 max-w-32 object-contain"
|
|
|
|
:src="printSettings.logo"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="text-xl text-gray-700 font-semibold" v-else>
|
|
|
|
{{ companyName }}
|
|
|
|
</div>
|
2019-10-11 15:25:50 +05:30
|
|
|
</div>
|
|
|
|
<div class="w-1/3">
|
2019-11-20 00:25:32 +05:30
|
|
|
<div>{{ printSettings.email }}</div>
|
|
|
|
<div class="mt-1">{{ printSettings.phone }}</div>
|
2019-10-11 15:25:50 +05:30
|
|
|
</div>
|
|
|
|
<div class="w-1/3">
|
2019-11-20 00:25:32 +05:30
|
|
|
<div v-if="address">{{ address.addressDisplay }}</div>
|
2019-10-11 15:25:50 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="mt-8 px-6">
|
2019-12-11 14:40:27 +05:30
|
|
|
<h1 class="text-2xl font-semibold">
|
2019-12-13 01:04:37 +05:30
|
|
|
{{
|
|
|
|
doc._notInserted
|
|
|
|
? doc.doctype === 'SalesInvoice'
|
|
|
|
? _('New Invoice')
|
|
|
|
: _('New Bill')
|
|
|
|
: doc.name
|
|
|
|
}}
|
2019-12-11 14:40:27 +05:30
|
|
|
</h1>
|
|
|
|
<div class="flex justify-between mt-2">
|
2019-10-11 15:25:50 +05:30
|
|
|
<div class="w-1/3">
|
|
|
|
<FormControl
|
2019-12-11 14:40:27 +05:30
|
|
|
class="text-base"
|
|
|
|
input-class="bg-gray-100 p-2 text-lg font-semibold"
|
|
|
|
:df="meta.getField(partyField.fieldname)"
|
|
|
|
:value="doc[partyField.fieldname]"
|
|
|
|
:placeholder="partyField.label"
|
|
|
|
@change="value => doc.set(partyField.fieldname, value)"
|
|
|
|
@new-doc="party => doc.set(partyField.fieldname, party.name)"
|
2019-11-20 00:25:32 +05:30
|
|
|
:read-only="doc.submitted"
|
2019-10-11 15:25:50 +05:30
|
|
|
/>
|
|
|
|
<FormControl
|
2019-11-27 12:16:15 +05:30
|
|
|
class="mt-2 text-base"
|
2019-12-11 14:40:27 +05:30
|
|
|
input-class="bg-gray-100 px-3 py-2 text-base"
|
2019-10-11 15:25:50 +05:30
|
|
|
:df="meta.getField('account')"
|
|
|
|
:value="doc.account"
|
|
|
|
:placeholder="'Account'"
|
|
|
|
@change="value => doc.set('account', value)"
|
2019-11-20 00:25:32 +05:30
|
|
|
:read-only="doc.submitted"
|
2019-10-11 15:25:50 +05:30
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="w-1/3">
|
|
|
|
<FormControl
|
2019-12-11 14:40:27 +05:30
|
|
|
input-class="bg-gray-100 px-3 py-2 text-base text-right"
|
|
|
|
:df="meta.getField('date')"
|
|
|
|
:value="doc.date"
|
|
|
|
:placeholder="'Date'"
|
|
|
|
@change="value => doc.set('date', value)"
|
2019-11-20 00:25:32 +05:30
|
|
|
:read-only="doc.submitted"
|
2019-10-11 15:25:50 +05:30
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-11-20 00:25:32 +05:30
|
|
|
<div class="px-6 text-base">
|
2019-10-13 17:33:01 +05:30
|
|
|
<FormControl
|
|
|
|
:df="meta.getField('items')"
|
|
|
|
:value="doc.items"
|
|
|
|
:showHeader="true"
|
|
|
|
@change="value => doc.set('items', value)"
|
2019-11-20 00:25:32 +05:30
|
|
|
:read-only="doc.submitted"
|
2019-10-13 17:33:01 +05:30
|
|
|
/>
|
2019-10-11 15:25:50 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
2019-11-20 00:25:32 +05:30
|
|
|
<div class="px-6 mb-6 flex justify-end text-base">
|
2019-10-11 15:25:50 +05:30
|
|
|
<div class="w-64">
|
|
|
|
<div class="flex pl-2 justify-between py-3 border-b">
|
2019-11-27 12:16:15 +05:30
|
|
|
<div>{{ _('Subtotal') }}</div>
|
2019-12-03 13:49:58 +05:30
|
|
|
<div>{{ formattedValue('netTotal') }}</div>
|
2019-10-11 15:25:50 +05:30
|
|
|
</div>
|
2019-11-20 00:25:32 +05:30
|
|
|
<div
|
|
|
|
class="flex pl-2 justify-between py-3"
|
|
|
|
v-for="tax in doc.taxes"
|
|
|
|
:key="tax.name"
|
|
|
|
>
|
2019-10-11 15:25:50 +05:30
|
|
|
<div>{{ tax.account }} ({{ tax.rate }}%)</div>
|
2019-12-03 13:49:58 +05:30
|
|
|
<div>
|
|
|
|
{{
|
|
|
|
frappe.format(tax.amount, {
|
|
|
|
fieldtype: 'Currency',
|
|
|
|
currency: doc.currency
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
</div>
|
2019-10-11 15:25:50 +05:30
|
|
|
</div>
|
2019-10-14 02:49:28 +05:30
|
|
|
<div
|
|
|
|
class="flex pl-2 justify-between py-3 border-t text-green-600 font-semibold text-base"
|
|
|
|
>
|
2019-11-27 12:16:15 +05:30
|
|
|
<div>{{ _('Grand Total') }}</div>
|
2019-12-03 13:49:58 +05:30
|
|
|
<div>{{ formattedValue('grandTotal') }}</div>
|
2019-10-11 15:25:50 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2019-12-03 13:49:58 +05:30
|
|
|
import frappe from 'frappejs';
|
2019-10-11 15:25:50 +05:30
|
|
|
import PageHeader from '@/components/PageHeader';
|
|
|
|
import Button from '@/components/Button';
|
|
|
|
import FormControl from '@/components/Controls/FormControl';
|
2019-10-30 01:03:26 +05:30
|
|
|
import Dropdown from '@/components/Dropdown';
|
2019-12-04 22:56:40 +05:30
|
|
|
import BackLink from '@/components/BackLink';
|
2019-11-20 00:25:32 +05:30
|
|
|
import { openSettings } from '@/pages/Settings/utils';
|
2019-12-10 14:55:11 +05:30
|
|
|
import { deleteDocWithPrompt, handleErrorWithDialog } from '@/utils';
|
2019-10-11 15:25:50 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'InvoiceForm',
|
2019-10-14 02:49:28 +05:30
|
|
|
props: ['doctype', 'name'],
|
2019-10-11 15:25:50 +05:30
|
|
|
components: {
|
|
|
|
PageHeader,
|
|
|
|
Button,
|
|
|
|
FormControl,
|
2019-12-04 22:56:40 +05:30
|
|
|
Dropdown,
|
|
|
|
BackLink
|
2019-10-11 15:25:50 +05:30
|
|
|
},
|
|
|
|
provide() {
|
|
|
|
return {
|
2019-10-14 02:49:28 +05:30
|
|
|
doctype: this.doctype,
|
2019-10-11 15:25:50 +05:30
|
|
|
name: this.name
|
|
|
|
};
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2019-11-20 00:25:32 +05:30
|
|
|
doc: null,
|
|
|
|
printSettings: null,
|
|
|
|
companyName: null
|
2019-10-11 15:25:50 +05:30
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2019-11-28 00:09:16 +05:30
|
|
|
meta() {
|
|
|
|
return frappe.getMeta(this.doctype);
|
|
|
|
},
|
|
|
|
itemsMeta() {
|
|
|
|
return frappe.getMeta(`${this.doctype}Item`);
|
|
|
|
},
|
2019-10-11 15:25:50 +05:30
|
|
|
itemTableFields() {
|
2019-10-13 17:33:01 +05:30
|
|
|
return this.itemsMeta.tableFields.map(fieldname =>
|
2019-10-11 15:25:50 +05:30
|
|
|
this.itemsMeta.getField(fieldname)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
itemTableColumnRatio() {
|
2019-12-13 01:04:37 +05:30
|
|
|
return [0.3].concat(this.itemTableFields.map(() => 1));
|
2019-10-14 02:49:28 +05:30
|
|
|
},
|
|
|
|
partyField() {
|
|
|
|
let fieldname = {
|
|
|
|
SalesInvoice: 'customer',
|
|
|
|
PurchaseInvoice: 'supplier'
|
|
|
|
}[this.doctype];
|
|
|
|
return this.meta.getField(fieldname);
|
2019-11-20 00:25:32 +05:30
|
|
|
},
|
|
|
|
address() {
|
|
|
|
return this.printSettings && this.printSettings.getLink('address');
|
|
|
|
},
|
|
|
|
showSave() {
|
|
|
|
return this.doc && (this.doc._notInserted || this.doc._dirty);
|
2019-11-27 12:16:15 +05:30
|
|
|
},
|
|
|
|
actions() {
|
|
|
|
if (!this.doc) return null;
|
|
|
|
let deleteAction = {
|
|
|
|
component: {
|
|
|
|
template: `<span class="text-red-700">{{ _('Delete') }}</span>`
|
|
|
|
},
|
|
|
|
condition: doc => !doc.isNew() && !doc.submitted,
|
2019-12-13 01:04:37 +05:30
|
|
|
action: this.deleteAction
|
2019-11-27 12:16:15 +05:30
|
|
|
};
|
|
|
|
let actions = [...(this.meta.actions || []), deleteAction]
|
|
|
|
.filter(d => (d.condition ? d.condition(this.doc) : true))
|
|
|
|
.map(d => {
|
|
|
|
return {
|
|
|
|
label: d.label,
|
|
|
|
component: d.component,
|
2019-12-04 22:56:40 +05:30
|
|
|
action: d.action.bind(this, this.doc, this.$router)
|
2019-11-27 12:16:15 +05:30
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
return actions;
|
2019-10-30 01:03:26 +05:30
|
|
|
}
|
2019-10-11 15:25:50 +05:30
|
|
|
},
|
|
|
|
async mounted() {
|
2019-12-03 13:49:58 +05:30
|
|
|
try {
|
|
|
|
this.doc = await frappe.getDoc(this.doctype, this.name);
|
|
|
|
window.d = this.doc;
|
|
|
|
} catch (error) {
|
|
|
|
if (error instanceof frappe.errors.NotFoundError) {
|
|
|
|
this.routeToList();
|
|
|
|
return;
|
|
|
|
}
|
2019-12-10 14:55:11 +05:30
|
|
|
throw error;
|
2019-12-03 13:49:58 +05:30
|
|
|
}
|
2019-11-20 00:25:32 +05:30
|
|
|
this.printSettings = await frappe.getSingle('PrintSettings');
|
|
|
|
this.companyName = (
|
|
|
|
await frappe.getSingle('AccountingSettings')
|
|
|
|
).companyName;
|
|
|
|
|
2019-11-27 12:16:15 +05:30
|
|
|
let query = this.$route.query;
|
|
|
|
if (query.values && query.doctype === this.doctype) {
|
2019-11-20 00:25:32 +05:30
|
|
|
this.doc.set(this.$router.currentRoute.query.values);
|
|
|
|
}
|
2019-10-11 15:25:50 +05:30
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async addNewItem() {
|
|
|
|
this.doc.append('items');
|
|
|
|
},
|
|
|
|
async onSaveClick() {
|
2019-11-20 00:25:32 +05:30
|
|
|
await this.doc.set(
|
|
|
|
'items',
|
|
|
|
this.doc.items.filter(row => row.item)
|
|
|
|
);
|
2019-12-10 14:55:11 +05:30
|
|
|
return this.doc.insertOrUpdate().catch(this.handleError);
|
2019-10-14 02:49:28 +05:30
|
|
|
},
|
2019-12-13 01:04:37 +05:30
|
|
|
deleteAction() {
|
|
|
|
return deleteDocWithPrompt(this.doc).then(res => {
|
|
|
|
if (res) {
|
|
|
|
this.routeToList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2019-12-10 14:55:11 +05:30
|
|
|
onSubmitClick() {
|
|
|
|
return this.doc.submit().catch(this.handleError);
|
|
|
|
},
|
|
|
|
handleError(e) {
|
|
|
|
handleErrorWithDialog(e, this.doc);
|
2019-10-30 01:03:26 +05:30
|
|
|
},
|
2019-11-20 00:25:32 +05:30
|
|
|
openInvoiceSettings() {
|
|
|
|
openSettings('Invoice');
|
|
|
|
},
|
|
|
|
routeToList() {
|
|
|
|
this.$router.push(`/list/${this.doctype}`);
|
2019-12-03 13:49:58 +05:30
|
|
|
},
|
|
|
|
formattedValue(fieldname, doc) {
|
|
|
|
if (!doc) {
|
|
|
|
doc = this.doc;
|
|
|
|
}
|
|
|
|
let df = doc.meta.getField(fieldname);
|
|
|
|
return frappe.format(doc[fieldname], df, doc);
|
2019-10-11 15:25:50 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|