2
0
mirror of https://github.com/frappe/books.git synced 2025-01-25 16:18:33 +00:00

257 lines
5.7 KiB
JavaScript
Raw Normal View History

2022-02-16 11:49:16 +05:30
import frappe, { t } from 'frappe';
import utils from '../../../accounting/utils';
2022-03-08 12:14:05 +05:30
import { DEFAULT_NUMBER_SERIES } from '../../../frappe/utils/consts';
2018-03-27 19:22:59 +05:30
const paymentTypeMap = {
Receive: t`Receive`,
Pay: t`Pay`,
};
2022-03-30 16:27:45 +05:30
const paymentMethodMap = {
Cash: t`Cash`,
Cheque: t`Cheque`,
Transfer: t`Transfer`,
};
export default {
name: 'Payment',
2022-02-16 11:49:16 +05:30
label: t`Payment`,
isSingle: 0,
isChild: 0,
isSubmittable: 1,
keywordFields: [],
settings: 'PaymentSettings',
fields: [
2022-02-28 14:20:50 +05:30
{
label: t`Payment No`,
fieldname: 'name',
fieldtype: 'Data',
required: 1,
readOnly: 1,
},
{
fieldname: 'party',
2022-02-16 11:49:16 +05:30
label: t`Party`,
fieldtype: 'Link',
target: 'Party',
required: 1,
},
2019-08-14 13:13:49 +05:30
{
fieldname: 'date',
2022-02-16 11:49:16 +05:30
label: t`Posting Date`,
2019-08-14 13:13:49 +05:30
fieldtype: 'Date',
default: () => new Date().toISOString(),
2019-08-14 13:13:49 +05:30
},
{
fieldname: 'account',
2022-02-16 11:49:16 +05:30
label: t`From Account`,
fieldtype: 'Link',
target: 'Account',
required: 1,
getFilters: (query, doc) => {
if (doc.paymentType === 'Pay') {
if (doc.paymentMethod === 'Cash') {
return { accountType: 'Cash', isGroup: 0 };
} else {
return { accountType: ['in', ['Bank', 'Cash']], isGroup: 0 };
}
}
},
formula: (doc) => {
if (doc.paymentMethod === 'Cash' && doc.paymentType === 'Pay') {
return 'Cash';
}
},
},
2019-07-19 18:54:31 +05:30
{
fieldname: 'paymentType',
2022-02-16 11:49:16 +05:30
label: t`Payment Type`,
2019-07-19 18:54:31 +05:30
fieldtype: 'Select',
2022-03-30 16:27:45 +05:30
placeholder: t`Payment Type`,
options: Object.keys(paymentTypeMap),
map: paymentTypeMap,
required: 1,
2019-07-19 18:54:31 +05:30
},
{
fieldname: 'paymentAccount',
2022-02-16 11:49:16 +05:30
label: t`To Account`,
2022-03-30 16:27:45 +05:30
placeholder: t`To Account`,
fieldtype: 'Link',
target: 'Account',
required: 1,
getFilters: (query, doc) => {
if (doc.paymentType === 'Receive') {
if (doc.paymentMethod === 'Cash') {
return { accountType: 'Cash', isGroup: 0 };
} else {
return { accountType: ['in', ['Bank', 'Cash']], isGroup: 0 };
}
}
},
formula: (doc) => {
if (doc.paymentMethod === 'Cash' && doc.paymentType === 'Receive') {
return 'Cash';
}
},
},
2022-03-08 12:14:05 +05:30
{
fieldname: 'numberSeries',
label: t`Number Series`,
fieldtype: 'Link',
target: 'NumberSeries',
required: 1,
getFilters: () => {
return { referenceType: 'Payment' };
},
default: DEFAULT_NUMBER_SERIES['Payment'],
},
2019-07-19 18:54:31 +05:30
{
fieldname: 'paymentMethod',
2022-02-16 11:49:16 +05:30
label: t`Payment Method`,
2022-03-30 16:27:45 +05:30
placeholder: t`Payment Method`,
2019-07-19 18:54:31 +05:30
fieldtype: 'Select',
2022-03-30 16:27:45 +05:30
options: Object.keys(paymentMethodMap),
map: paymentMethodMap,
default: 'Cash',
required: 1,
2019-07-19 18:54:31 +05:30
},
{
fieldname: 'referenceId',
2022-02-16 11:49:16 +05:30
label: t`Ref. / Cheque No.`,
2022-03-30 16:27:45 +05:30
placeholder: t`Ref. / Cheque No.`,
fieldtype: 'Data',
required: (doc) => doc.paymentMethod !== 'Cash', // TODO: UNIQUE
hidden: (doc) => doc.paymentMethod === 'Cash',
},
{
fieldname: 'referenceDate',
2022-02-16 11:49:16 +05:30
label: t`Ref. Date`,
2022-03-30 16:27:45 +05:30
placeholder: t`Ref. Date`,
fieldtype: 'Date',
},
{
fieldname: 'clearanceDate',
2022-02-16 11:49:16 +05:30
label: t`Clearance Date`,
2022-03-30 16:27:45 +05:30
placeholder: t`Clearance Date`,
2019-07-19 18:54:31 +05:30
fieldtype: 'Date',
hidden: (doc) => doc.paymentMethod === 'Cash',
},
{
fieldname: 'amount',
2022-02-16 11:49:16 +05:30
label: t`Amount`,
fieldtype: 'Currency',
required: 1,
2021-12-29 11:59:26 +05:30
formula: (doc) => doc.getSum('for', 'amount', false),
validate(value, doc) {
2021-12-29 11:59:26 +05:30
if (value.isNegative()) {
throw new frappe.errors.ValidationError(
frappe.t`Payment amount cannot be less than zero.`
);
}
if (doc.for.length === 0) return;
2021-12-29 11:59:26 +05:30
const amount = doc.getSum('for', 'amount', false);
2021-12-29 11:59:26 +05:30
if (value.gt(amount)) {
2021-10-29 23:12:10 +05:30
throw new frappe.errors.ValidationError(
frappe.t`Payment amount cannot
exceed ${frappe.format(amount, 'Currency')}.`
);
2021-12-29 11:59:26 +05:30
} else if (value.isZero()) {
throw new frappe.errors.ValidationError(
frappe.t`Payment amount cannot
be ${frappe.format(value, 'Currency')}.`
2021-10-29 23:12:10 +05:30
);
}
},
},
{
fieldname: 'writeoff',
2022-02-16 11:49:16 +05:30
label: t`Write Off / Refund`,
fieldtype: 'Currency',
},
{
fieldname: 'for',
2022-02-16 11:49:16 +05:30
label: t`Payment Reference`,
fieldtype: 'Table',
childtype: 'PaymentFor',
required: 0,
},
2021-11-21 19:08:04 +05:30
{
fieldname: 'cancelled',
2022-02-16 11:49:16 +05:30
label: t`Cancelled`,
2021-11-21 19:08:04 +05:30
fieldtype: 'Check',
default: 0,
2022-02-23 12:52:14 +05:30
readOnly: 1,
2021-11-21 19:08:04 +05:30
},
],
quickEditFields: [
2022-03-08 12:14:05 +05:30
'numberSeries',
'party',
'date',
'paymentMethod',
'account',
'paymentType',
'paymentAccount',
'referenceId',
'referenceDate',
'clearanceDate',
'amount',
'writeoff',
'for',
],
layout: [
{
columns: [
Winter Sprint: Work (#79) * init() * Country-wise Chart of accounts on setup * Add a sample invoice template * Some error fixes * [fix] missing COA - move importCOA.js from models/doctype/account to models/doctype/Account * All Account initial balance zero * setup Bank Reconciliation * New chart of accounts tree component * GST taxes added. initialized gst reports. * [chore] add *.db to .gitignore * [fix] importCOA path error * fix error + bank reconciliation fields * [feat] add gst taxes * GST report initialized * GST report finalized * GST report finalized * Complete min. reconciliation * [feat] auto select tax in invoice based on states * [chore] fix merge changes * Fix date issue - Make Payment * Add invoice templates and invoice customizer panel * Restructure invoice vue components * update file with fiscal year * Fix issues in invoice designs * Add company settings. Dynamic addresses in invoice * Move invoice styles to different file and add separate components for addresses * [feat] add export-filtered-data-to-csv to reports * [feat] add Export Wizard component for customizing export * Fix invoice customizer position while scrolling. Fix address displayed as undefined in invoice if not found in db * [chore] change markup for select all chkbox * Setup config as doctype * GSTIN bug fix * Add custom google fonts * Add Send email footer * Fix DateTime * Complete Merge + Resolve * Complete Merge + Resolve * [chore] change layout of Export Wizard * [enh] optimize checkNoneSelected, style export modal footer divider * Add Tax to SideBar * Remove extra logs * [fix] db name section in sidebar showing absolute path instead of dbname in windows i.e. platform=win32 * Country-wise Chart of accounts on setup (#78) * Country-wise Chart of accounts on setup * Some error fixes * All Account initial balance zero * Update README.md - updated installation instructions with more detail * Merge #79 Winter Sprint: Work https://github.com/frappe/accounting/pull/79 * Revert "Merge #79 Winter Sprint: Work" This reverts commit 171511666817caa430af672791c8d452e3b4b680.
2019-02-18 11:12:04 +05:30
{
fields: ['party', 'account'],
Winter Sprint: Work (#79) * init() * Country-wise Chart of accounts on setup * Add a sample invoice template * Some error fixes * [fix] missing COA - move importCOA.js from models/doctype/account to models/doctype/Account * All Account initial balance zero * setup Bank Reconciliation * New chart of accounts tree component * GST taxes added. initialized gst reports. * [chore] add *.db to .gitignore * [fix] importCOA path error * fix error + bank reconciliation fields * [feat] add gst taxes * GST report initialized * GST report finalized * GST report finalized * Complete min. reconciliation * [feat] auto select tax in invoice based on states * [chore] fix merge changes * Fix date issue - Make Payment * Add invoice templates and invoice customizer panel * Restructure invoice vue components * update file with fiscal year * Fix issues in invoice designs * Add company settings. Dynamic addresses in invoice * Move invoice styles to different file and add separate components for addresses * [feat] add export-filtered-data-to-csv to reports * [feat] add Export Wizard component for customizing export * Fix invoice customizer position while scrolling. Fix address displayed as undefined in invoice if not found in db * [chore] change markup for select all chkbox * Setup config as doctype * GSTIN bug fix * Add custom google fonts * Add Send email footer * Fix DateTime * Complete Merge + Resolve * Complete Merge + Resolve * [chore] change layout of Export Wizard * [enh] optimize checkNoneSelected, style export modal footer divider * Add Tax to SideBar * Remove extra logs * [fix] db name section in sidebar showing absolute path instead of dbname in windows i.e. platform=win32 * Country-wise Chart of accounts on setup (#78) * Country-wise Chart of accounts on setup * Some error fixes * All Account initial balance zero * Update README.md - updated installation instructions with more detail * Merge #79 Winter Sprint: Work https://github.com/frappe/accounting/pull/79 * Revert "Merge #79 Winter Sprint: Work" This reverts commit 171511666817caa430af672791c8d452e3b4b680.
2019-02-18 11:12:04 +05:30
},
{
fields: ['date', 'paymentAccount'],
},
],
},
{
columns: [
2018-03-27 09:50:58 +05:30
{
fields: ['paymentMethod'],
2018-03-27 09:50:58 +05:30
},
2019-07-19 18:54:31 +05:30
{
fields: ['paymentType'],
2019-07-19 18:54:31 +05:30
},
{
fields: ['referenceId'],
},
],
2019-07-19 18:54:31 +05:30
},
{
columns: [
2018-03-27 09:50:58 +05:30
{
fields: ['referenceDate'],
2018-03-27 09:50:58 +05:30
},
{
fields: ['clearanceDate'],
},
],
},
{
columns: [
{
fields: ['for'],
},
],
},
{
columns: [
2018-03-27 09:50:58 +05:30
{
fields: ['amount', 'writeoff'],
},
],
},
],
2021-11-21 19:08:04 +05:30
actions: [utils.ledgerLink],
links: [utils.ledgerLink],
};