Skip to content

Commit

Permalink
fix: add missing code
Browse files Browse the repository at this point in the history
Add code that was lost during version 13 to version 14 upgrade
  • Loading branch information
Lucky-Tsuma committed Feb 1, 2023
1 parent 98a410c commit 545a1d0
Show file tree
Hide file tree
Showing 13 changed files with 716 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,49 @@
// For license information, please see license.txt

frappe.ui.form.on('Grant Application Activity', {
// refresh: function(frm) {

// }
//Get grant budget_template items
grant_budget_template: function (frm) {
if (frm.doc.grant_budget_template) {
frm.clear_table('grant_application_activity_budget_item');
frappe.model.with_doc('Grant Budget Template', frm.doc.grant_budget_template, function () {
let source_doc = frappe.model.get_doc('Grant Budget Template', frm.doc.grant_budget_template);
$.each(source_doc.budget_items, function (index, source_row) {
const target_row = frm.add_child('grant_application_activity_budget_item');
target_row.budget_item = source_row.budget_item;
target_row.budget_category = source_row.budget_category;
frm.refresh_field('grant_application_activity_budget_item');
});
});
}
},
//Calculate total budget
validate: function (frm) {
//Budget
let total_budget_amt = 0;
$.each(frm.doc.grant_application_activity_budget_item, function (j, bitem) {
total_budget_amt += flt(bitem.amount);
});
frm.doc.activity_budget = total_budget_amt;
}
});

//Budget Amount Calculation
var amount_calculation = function (frm, cdt, cdn) {
var row = locals[cdt][cdn];
if ((row.qty) && (row.rate)) {
frappe.model.set_value(cdt, cdn, 'amount', (row.qty * row.rate));
frm.refresh_field("amount");
}
}

//Budget child table amount calculation on qty change
frappe.ui.form.on("Grant Application Activity Budget Item", "qty", function (frm, cdt, cdn) {
//amount on qty change
amount_calculation(frm, cdt, cdn);
})

//Budget child table amount calculation on rate change
frappe.ui.form.on("Grant Application Activity Budget Item", "rate", function (frm, cdt, cdn) {
//amount on rate change
amount_calculation(frm, cdt, cdn);
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,64 @@
// For license information, please see license.txt

frappe.ui.form.on('Grant Application Budget Review', {
// refresh: function(frm) {

// }
grant_application: function (frm) {
if (frm.doc.grant_application) {
frm.clear_table('grant_application_budget_review_item');
frappe.model.with_doc('Grant Application', frm.doc.grant_application, function () {
let source_doc = frappe.model.get_doc('Grant Application', frm.doc.grant_application);
$.each(source_doc.grant_application_budget_item, function (index, source_row) {
const target_row = frm.add_child('grant_application_budget_review_item');
target_row.budget_item = source_row.budget_item;
target_row.unit_of_measure = source_row.unit_of_measure;
target_row.qty = source_row.qty;
target_row.rate = source_row.rate;
target_row.amount = source_row.amount;
target_row.item_description = source_row.item_description;
target_row.reviewed_rate = source_row.rate;
target_row.reviewed_amount = source_row.amount;
frm.refresh_field('grant_application_budget_review_item');
});
});
}
},
//Calculate total score
validate: function (frm) {
// calculate total budget amount for each line budget item
let total_requested_amount = 0;
let total_reviewed_amount = 0;
$.each(frm.doc.grant_application_budget_review_item, function (i, d) {
total_requested_amount += flt(d.amount);
total_reviewed_amount += flt(d.reviewed_amount);
});
frm.doc.requested_amount = total_requested_amount;
frm.doc.reviewed_amount = total_reviewed_amount;
},
setup: function (frm) {
frm.set_indicator_formatter('budget_item',
function (doc) {
return (doc.amount != doc.reviewed_amount) ? "green" : "white"
})
},
on_submit: function (frm) {
update_grant_app_average_reviewed_budget_amount(frm);
},
after_cancel: function (frm) {
update_grant_app_average_reviewed_budget_amount(frm);
}
});

//Update grant application
var update_grant_app_average_reviewed_budget_amount = function (frm) {

let count_of_reviews = frappe.db.count('Grant Application Budget Review',
{'grant_application': frm.doc.grant_application, 'docstatus': 1});

let sum_of_reviews = frappe.db.get_list('Grant Application Budget Review',
filters = {'grant_application': frm.doc.grant_application, 'docstatus': 1},
fields = ['sum(reviewed_amount) as sum_rev_amt','grant_application'],
group_by = 'grant_application');

let average_reviewed_budget_amount = flt(sum_of_reviews / count_of_reviews, 2);

frappe.db.set_value('Grant Application', frm.doc.grant_application, 'average_reviewed_budget_amount', average_reviewed_budget_amount);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,62 @@
// For license information, please see license.txt

frappe.ui.form.on('Grant Application Endorsement', {
// refresh: function(frm) {

// }
email_id: function (frm) {
get_user_details(frm);
},
validate: function (frm) {
get_user_details(frm);
},
send_sms: function (frm) {
send_sms(frm);
}
});

//Begin of Functions
//Get user details
var get_user_details = function (frm) {
if (frm.doc.email_id) {
frappe.model.with_doc('User', frm.doc.email_id, function () {
let user = frappe.model.get_doc('User', frm.doc.email_id);
if (user['name']) {
frm.set_value('user', user['name']);
frm.set_value('mobile_no', user['mobile_no']);
frm.set_value('first_name', user['first_name']);
frm.set_value('middle_name', user['middle_name']);
frm.set_value('last_name', user['last_name']);
} else{
frm.set_value('user', null);
frm.set_value('mobile_no', null);
frm.set_value('first_name', null);
frm.set_value('middle_name', null);
frm.set_value('last_name', null);
}

refresh_field('user');
refresh_field('mobile_no');
refresh_field('first_name');
refresh_field('middle_name');
refresh_field('last_name');
});
}
};

//Send SMS
var send_sms = function (frm) {
if (frm.doc.first_name && frm.doc.send_sms === 1 && frm.doc.mobile_no) {
var message = 'Dear, ' + frm.doc.first_name + ', Requesting for a Grant Application Endorsement at: ' + frm.doc.company + ', Sincerely: ' + frm.doc.applicant_name;
frappe.call({
method: "frappe.core.doctype.sms_settings.sms_settings.send_sms",
args: {
receiver_list: [frm.doc.mobile_no],
msg: message,
},
callback: function (r) {
if (r.exc) {
msgprint(r.exc);
return;
}
}
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,64 @@
// For license information, please see license.txt

frappe.ui.form.on('Grant Application Review', {
// refresh: function(frm) {

// }
grant_application: function (frm) {
if (frm.doc.grant_application) {
frm.clear_table('grant_application_review_item');
frappe.model.with_doc('Grant Application', frm.doc.grant_application, function () {
let source_doc = frappe.model.get_doc('Grant Application', frm.doc.grant_application);
$.each(source_doc.details, function (index, source_row) {
const target_row = frm.add_child('grant_application_review_item');
target_row.parameter = source_row.parameter;
target_row.item_description = source_row.item_description;
target_row.response = source_row.response;
target_row.response_description = source_row.response_description;
target_row.maximum_score = source_row.maximum_score;
frm.refresh_field('grant_application_review_item');
});
});
}
},
//Calculate total score
validate: function (frm) {
// calculate total budget amount for each line budget item
let total_maximum_score = 0;
let total_score = 0;
$.each(frm.doc.grant_application_review_item, function (i, d) {
total_maximum_score += flt(d.maximum_score);
if (d.score >= 0) {
total_score += flt(d.score);
}
});
frm.doc.maximum_score = total_maximum_score;
frm.doc.score = total_score;
},
setup: function (frm) {
frm.set_indicator_formatter('parameter',
function (doc) {
if (doc.score >= 0){
return "green"
} else if(doc.skip){
return "orange"
}else{
return "white"
}
}
)
}
});

//Score Validation against Maximum Score
var maximum_score_validation = function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
if (d.score && d.maximum_score) {
if (d.score > d.maximum_score) {
msgprint('Score is greater than Maximum Score for the Parameter, please amend to continue');
frappe.validated = false;
}
}
}

frappe.ui.form.on("Grant Application Review Item", "score", function (frm, cdt, cdn) {
//Score Validation against Maximum Score
maximum_score_validation(frm, cdt, cdn);
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@
// For license information, please see license.txt

frappe.ui.form.on('Grant Call', {
// refresh: function(frm) {

// }
});
grant_application_template: function (frm) {
frappe.call({
method: "copy_grant_application_parameters_from_template",
doc: frm.doc,
callback: function (r) {
refresh_field("grant_application_parameters");
}
});
},
grant_reporting_template: function (frm) {
frappe.call({
method: "copy_grant_application_report_parameters_from_template",
doc: frm.doc,
callback: function (r) {
refresh_field("grant_reporting_parameters");
}
});
}
});
Loading

0 comments on commit 545a1d0

Please sign in to comment.