Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Fix and adds
  • Loading branch information
Helkyd committed Jan 21, 2021
2 parents ef9808a + 853f3f6 commit 85a8f50
Show file tree
Hide file tree
Showing 24 changed files with 1,033 additions and 239 deletions.
146 changes: 17 additions & 129 deletions models/doctype/Payment/Payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,26 @@ module.exports = {
printTemplate: PaymentTemplate,
settings: 'PaymentSettings',
fields: [
{
label: 'Doc AGT', //HELKyds 18-01-2021
fieldname: 'docAgt',
fieldtype: 'Data',
required: 0,
readOnly: 1
},

{
fieldname: 'party',
label: 'Party',
fieldtype: 'Link',
target: 'Party',
required: 1,
readOnly: async doc => {
if (
doc.submitted === 1 &&
(doc.clearanceDate !== null || doc.paymentMethod === 'Cash')
) {
return 1;
} else {
return 0;
}
}
required: 1
},
{
fieldname: 'date',
label: 'Posting Date',
fieldtype: 'Date',
default: new Date().toISOString(),
readOnly: async doc => {
if (
doc.submitted === 1 &&
(doc.clearanceDate !== null || doc.paymentMethod === 'Cash')
) {
return 1;
} else {
return 0;
}
}
default: new Date().toISOString()
},
{
fieldname: 'account',
Expand All @@ -62,34 +50,14 @@ module.exports = {
return { accountType: ['in', ['Bank', 'Cash']], isGroup: 0 };
}
}
},
readOnly: async doc => {
if (
doc.submitted === 1 &&
(doc.clearanceDate !== null || doc.paymentMethod === 'Cash')
) {
return 1;
} else {
return 0;
}
}
},
{
fieldname: 'paymentType',
label: 'Payment Type',
fieldtype: 'Select',
options: ['', 'Receive', 'Pay'],
required: 1,
readOnly: async doc => {
if (
doc.submitted === 1 &&
(doc.clearanceDate !== null || doc.paymentMethod === 'Cash')
) {
return 1;
} else {
return 0;
}
}
required: 1
},
{
fieldname: 'paymentAccount',
Expand Down Expand Up @@ -118,16 +86,6 @@ module.exports = {
console.log(conta[0].name);
return conta[0].name;
}
},
readOnly: async doc => {
if (
doc.submitted === 1 &&
(doc.clearanceDate !== null || doc.paymentMethod === 'Cash')
) {
return 1;
} else {
return 0;
}
}
},
{
Expand All @@ -136,50 +94,20 @@ module.exports = {
placeholder: 'Payment Method',
fieldtype: 'Select',
options: ['', 'Cash', 'Cheque', 'Transfer'],
required: 1,
readOnly: async doc => {
if (
doc.submitted === 1 &&
(doc.clearanceDate !== null || doc.paymentMethod === 'Cash')
) {
return 1;
} else {
return 0;
}
}
required: 1
},
{
fieldname: 'referenceId',
label: 'Ref. / Cheque No.',
placeholder: 'Ref. / Cheque No.',
fieldtype: 'Data',
required: 1, // TODO: UNIQUE
readOnly: async doc => {
if (
doc.submitted === 1 &&
(doc.clearanceDate !== null || doc.paymentMethod === 'Cash')
) {
return 1;
} else {
return 0;
}
}
required: 1 // TODO: UNIQUE
},
{
fieldname: 'referenceDate',
label: 'Ref. Date',
placeholder: 'Ref. Date',
fieldtype: 'Date',
readOnly: async doc => {
if (
doc.submitted === 1 &&
(doc.clearanceDate !== null || doc.paymentMethod === 'Cash')
) {
return 1;
} else {
return 0;
}
}
fieldtype: 'Date'
},
{
fieldname: 'clearanceDate',
Expand All @@ -188,66 +116,26 @@ module.exports = {
fieldtype: 'Date',
hidden: doc => {
return doc.paymentMethod === 'Cash' ? 1 : 0;
},
readOnly: async doc => {
if (
doc.submitted === 1 &&
(doc.clearanceDate !== null || doc.paymentMethod === 'Cash')
) {
return 1;
} else {
return 0;
}
}
},
{
fieldname: 'amount',
label: 'Amount',
fieldtype: 'Currency',
required: 1, //Helkyds 29-11-2020 Removed Defaults causing error
readOnly: async doc => {
if (
doc.submitted === 1 &&
(doc.clearanceDate !== null || doc.paymentMethod === 'Cash')
) {
return 1;
} else {
return 0;
}
}
required: 1 //Helkyds 29-11-2020 Removed Defaults causing error
},
{
fieldname: 'writeoff',
label: 'Write Off / Refund',
fieldtype: 'Currency',
default: 0,
readOnly: async doc => {
if (
doc.submitted === 1 &&
(doc.clearanceDate !== null || doc.paymentMethod === 'Cash')
) {
return 1;
} else {
return 0;
}
}
default: 0
},
{
fieldname: 'payfor', //Helkyds 29-11-2020 Renamed from for to payfor
label: 'Payment For',
fieldtype: 'Table',
childtype: 'PaymentFor',
required: 1,
readOnly: async doc => {
if (
doc.submitted === 1 &&
(doc.clearanceDate !== null || doc.paymentMethod === 'Cash')
) {
return 1;
} else {
return 0;
}
}
required: 1
}
],

Expand Down
8 changes: 8 additions & 0 deletions models/doctype/Payment/PaymentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ export default {
render(doc) {
let status = 'Draft';
let color = 'gray';
if (!doc.submitted) {
status = 'Draft';
color = 'gray';
}

if (
doc.submitted === 1 &&
(doc.clearanceDate !== null || doc.paymentMethod === 'Cash')
) {
color = 'green';
status = 'Submitted';
} else if (doc.submitted === 2) {
color = 'red';
status = 'Canceled';
}

return {
Expand Down
62 changes: 62 additions & 0 deletions models/doctype/Payment/PaymentServer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const BaseDocument = require('frappejs/model/document');
const frappe = require('frappejs');
const LedgerPosting = require('../../../accounting/ledgerPosting');
const naming = require('frappejs/model/naming');

//HELKYds 30-11-2020; Changed For to payfor
module.exports = class PaymentServer extends BaseDocument {
Expand Down Expand Up @@ -41,6 +42,14 @@ module.exports = class PaymentServer extends BaseDocument {
return entries;
}

async validate() {
console.log('Antes de salvar');
console.log(this.submitted);
if (this.submitted === null) {
this.submitted = 0;
}
}

async beforeSubmit() {
if (!this.payfor.length) {
throw new Error(`No reference for the payment.`);
Expand All @@ -58,6 +67,9 @@ module.exports = class PaymentServer extends BaseDocument {
outstandingAmount = baseGrandTotal;
}
if (this.amount <= 0 || this.amount > outstandingAmount) {
//Disable Print button
this.submitted = 0;
//$0.getElementsByClassName('focus:outline-none rounded-md shadow-button flex-center text-gray-900 text-xs ml-2')[0].style['display'] = 'none'
throw new Error(
`Payment amount (${this.amount}) should be greater than 0 and less than Outstanding amount (${outstandingAmount})`
);
Expand All @@ -68,6 +80,56 @@ module.exports = class PaymentServer extends BaseDocument {
await referenceDoc.update();
let party = await frappe.getDoc('Party', this.party);
await party.updateOutstandingAmount();
//docAGT

let seriedocumento = 'RC-';
if (this.name.search('RC') != -1) {
seriedocumento = 'RC%';
}

let numeroserie = await frappe.db.getAll({
doctype: 'NumberSeries',
fields: ['name', 'current'],
filters: { name: ['like', seriedocumento] }
});
console.log(numeroserie);
console.log(numeroserie[0].name);
console.log('naming');
this.docAgt = await naming.getSeriesNext(numeroserie[0].name);
console.log('naming ', this.docAgt);
console.log('Series replace');
console.log(
this.docAgt
.substr(
this.docAgt.search(new Date().toISOString().slice(0, 4)),
this.docAgt.length
)
.search('-')
);
if (
this.docAgt
.substr(
this.docAgt.search(new Date().toISOString().slice(0, 4)),
this.docAgt.length
)
.search('-') != -1
) {
let novodocAGT = this.docAgt.replace(
this.docAgt.substr(
this.docAgt.search(new Date().toISOString().slice(0, 4)),
this.docAgt.length
),
this.docAgt
.substr(
this.docAgt.search(new Date().toISOString().slice(0, 4)),
this.docAgt.length
)
.replace('-', '/')
);
console.log('aqui ', novodocAGT);
this.docAgt = novodocAGT;
console.log(this.docAgt);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion models/doctype/Payment/PaymentTemplate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default {
let type = this.printSettings.template;
let templates = {
Basic
//Minimal,
//Minimal.
//Business
};
if (!(type in templates)) {
Expand Down
Loading

0 comments on commit 85a8f50

Please sign in to comment.