2019-12-26 13:45:41 +00:00
|
|
|
<template>
|
2019-12-26 14:01:28 +00:00
|
|
|
<div class="py-4" v-if="pendingInvoices.length">
|
2019-12-26 13:45:41 +00:00
|
|
|
<div class="px-4 text-sm text-gray-600 mb-1">
|
2022-02-14 05:15:26 +00:00
|
|
|
{{ t`Recent Invoices` }}
|
2019-12-26 13:45:41 +00:00
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
class="px-4 py-3 border-b hover:bg-gray-100 cursor-pointer"
|
|
|
|
v-for="invoice in pendingInvoices"
|
|
|
|
:key="invoice.name"
|
|
|
|
@click="routeToForm(invoice)"
|
|
|
|
>
|
|
|
|
<div class="text-base">
|
|
|
|
<div class="flex justify-between items-center mb-1">
|
|
|
|
<span class="font-medium">
|
|
|
|
{{ invoice.name }}
|
|
|
|
</span>
|
|
|
|
<span>
|
|
|
|
<component :is="getStatusBadge(invoice)" />
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div class="flex justify-between">
|
|
|
|
<span>
|
|
|
|
{{ frappe.format(invoice.date, invoiceMeta.getField('date')) }}
|
|
|
|
</span>
|
|
|
|
<div>
|
|
|
|
<span
|
|
|
|
class="font-medium text-gray-900"
|
|
|
|
>
|
|
|
|
{{
|
|
|
|
frappe.format(
|
2022-02-07 11:45:58 +00:00
|
|
|
amountPaid(invoice),
|
2019-12-26 13:45:41 +00:00
|
|
|
invoiceMeta.getField('baseGrandTotal')
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</span>
|
2022-02-07 11:45:58 +00:00
|
|
|
<span class="text-gray-600" v-if="!fullyPaid(invoice)">
|
2019-12-26 13:45:41 +00:00
|
|
|
({{
|
|
|
|
frappe.format(
|
2022-02-28 07:23:38 +00:00
|
|
|
invoice.outstandingAmount,
|
|
|
|
invoiceMeta.getField('outstandingAmount')
|
2019-12-26 13:45:41 +00:00
|
|
|
)
|
|
|
|
}})
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-02-28 07:23:38 +00:00
|
|
|
import { routeTo } from '@/utils';
|
2022-01-20 20:57:29 +00:00
|
|
|
import frappe from 'frappe';
|
2019-12-26 13:45:41 +00:00
|
|
|
import { getStatusColumn } from '../Transaction/Transaction';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'PartyWidget',
|
|
|
|
props: ['doc'],
|
|
|
|
data() {
|
|
|
|
return {
|
2022-02-07 11:45:58 +00:00
|
|
|
pendingInvoices: [],
|
2019-12-26 13:45:41 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
invoiceDoctype() {
|
|
|
|
let isCustomer = this.doc.doctype === 'Customer';
|
|
|
|
return isCustomer ? 'SalesInvoice' : 'PurchaseInvoice';
|
|
|
|
},
|
|
|
|
invoiceMeta() {
|
|
|
|
return frappe.getMeta(this.invoiceDoctype);
|
2022-02-07 11:45:58 +00:00
|
|
|
},
|
2019-12-26 13:45:41 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.fetchPendingInvoices();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async fetchPendingInvoices() {
|
|
|
|
let isCustomer = this.doc.doctype === 'Customer';
|
|
|
|
let doctype = this.invoiceDoctype;
|
|
|
|
let partyField = isCustomer ? 'customer' : 'supplier';
|
|
|
|
this.pendingInvoices = await frappe.db.getAll({
|
|
|
|
doctype,
|
|
|
|
fields: [
|
|
|
|
'name',
|
|
|
|
'date',
|
|
|
|
'outstandingAmount',
|
|
|
|
'baseGrandTotal',
|
2022-02-07 11:45:58 +00:00
|
|
|
'submitted',
|
2019-12-26 13:45:41 +00:00
|
|
|
],
|
|
|
|
filters: {
|
2022-02-07 11:45:58 +00:00
|
|
|
[partyField]: this.doc.name,
|
2019-12-26 13:45:41 +00:00
|
|
|
},
|
|
|
|
limit: 3,
|
2022-02-07 11:45:58 +00:00
|
|
|
orderBy: 'creation',
|
2019-12-26 13:45:41 +00:00
|
|
|
});
|
2022-02-07 11:45:58 +00:00
|
|
|
window.pendingInvoices = this.pendingInvoices;
|
2019-12-26 13:45:41 +00:00
|
|
|
},
|
|
|
|
getStatusBadge(doc) {
|
|
|
|
let statusColumn = getStatusColumn();
|
|
|
|
return statusColumn.render(doc);
|
|
|
|
},
|
|
|
|
routeToForm(doc) {
|
2021-11-21 16:15:27 +00:00
|
|
|
routeTo(`/edit/${this.invoiceDoctype}/${doc.name}`);
|
2019-12-26 13:45:41 +00:00
|
|
|
},
|
|
|
|
fullyPaid(invoice) {
|
2022-02-07 11:45:58 +00:00
|
|
|
return invoice.outstandingAmount.isZero();
|
2019-12-26 13:45:41 +00:00
|
|
|
},
|
2022-02-07 11:45:58 +00:00
|
|
|
amountPaid(invoice) {
|
|
|
|
return invoice.baseGrandTotal.sub(invoice.outstandingAmount);
|
2019-12-26 13:45:41 +00:00
|
|
|
},
|
2022-02-07 11:45:58 +00:00
|
|
|
},
|
2019-12-26 13:45:41 +00:00
|
|
|
};
|
|
|
|
</script>
|