Ubuntu
3 years ago
8 changed files with 807 additions and 35 deletions
File diff suppressed because one or more lines are too long
@ -1,10 +1,689 @@ |
|||
// Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
frappe.ui.form.on('System Mapping', { |
|||
//refresh: function(frm) {
|
|||
//}
|
|||
// frappe.ui.form.on('System Mapping', {
|
|||
// //refresh: function(frm) {
|
|||
// //}
|
|||
// after_save: function(frm){
|
|||
// cur_frm.reload_doc();
|
|||
// }
|
|||
// });
|
|||
|
|||
|
|||
var dusted = false; |
|||
|
|||
var sub_system_idx = []; |
|||
var mat_array = []; |
|||
|
|||
cur_frm.fields_dict['variant_mapping'].get_query = function(doc, cdt, cdn) { |
|||
return {query:"smart_service.transactions.doctype.procedure.procedure.variant",}; |
|||
}; |
|||
|
|||
cur_frm.fields_dict['system_sub_systems'].grid.get_field('systems').get_query = function(doc, cdt, cdn){ |
|||
return {query:"smart_service.transactions.doctype.system_mapping.system_mapping.systems",}; |
|||
}; |
|||
|
|||
cur_frm.fields_dict['system_sub_systems'].grid.get_field('procedure').get_query = function(doc, cdt, cdn){ |
|||
return {query:"smart_service.transactions.doctype.system_mapping.system_mapping.procedure",}; |
|||
}; |
|||
|
|||
frappe.ui.form.on('System Mapping', { |
|||
onload: function(frm) { |
|||
frm.set_query("systems", "system_sub_systems", function(doc , cdt, cdn) { |
|||
return { |
|||
"query": "smart_service.transactions.doctype.system_mapping.system_mapping.system_filter", |
|||
filters:{ |
|||
"system_filter": frm.doc.system_filter |
|||
} |
|||
}; |
|||
}); |
|||
frm.set_query("systems", "systems_assets", function(doc , cdt, cdn) { |
|||
var system = []; |
|||
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { |
|||
let value = row.doc.systems; |
|||
system.push(value); |
|||
}); |
|||
return { |
|||
filters: {'system_name': ['in',system], |
|||
} |
|||
}; |
|||
}); |
|||
|
|||
frm.trigger('fnLoadmat_initial_values'); |
|||
if (frm.doc.kilometer_mapping !== undefined){ |
|||
frappe.db.get_doc('Kilometer Mapping', frm.doc.kilometer_mapping) |
|||
.then(doc => { |
|||
// frm.set_value("km_active_status",doc.active_status);
|
|||
refresh_field("km_active_status"); |
|||
}); |
|||
|
|||
} |
|||
}, |
|||
validate: function(frm){ |
|||
if (frm.is_new()) { |
|||
if(frm.doc.variant_mapping) |
|||
var km_doc_name = frm.doc.variant_mapping + "-" + frm.doc.language + "-KM"; |
|||
frappe.db.exists('System Mapping', frm.doc.variant_mapping + "-" + frm.doc.language + "-SM") |
|||
.then(smexists => { |
|||
if (smexists){ |
|||
frappe.throw(__('System Mapping already Exists!!!')); |
|||
} else { |
|||
frappe.db.exists('Kilometer Mapping', km_doc_name) |
|||
.then(exists => { |
|||
if (exists) { |
|||
frm.trigger('fnSave_caller'); |
|||
} else { |
|||
// frappe.call({
|
|||
// "method": "smart_service.transactions.doctype.system_mapping.system_mapping.create_kilometer",
|
|||
// "args": {
|
|||
// "doc": cur_frm.doc.name,
|
|||
// "doctype": 'Kilometer Mapping',
|
|||
// "variant_mapping": frm.doc.variant_mapping,
|
|||
// "language":frm.doc.language
|
|||
// },
|
|||
// })
|
|||
// frappe.db.insert({
|
|||
// doctype: 'Kilometer Mapping',
|
|||
// variant_mapping: frm.doc.variant_mapping,
|
|||
// language:frm.doc.language
|
|||
// }).then(doc => {
|
|||
// frm.set_value("kilometer_mapping",doc.name);
|
|||
// refresh_field("kilometer_mapping");
|
|||
// frm.trigger('fnSave_caller');
|
|||
// });
|
|||
} |
|||
}); |
|||
} |
|||
}); |
|||
} else { |
|||
frm.trigger('fnSave_caller'); |
|||
} |
|||
}, |
|||
after_save: function(frm){ |
|||
cur_frm.reload_doc(); |
|||
cur_frm.reload_doc(); |
|||
}, |
|||
refresh: function(frm) { |
|||
cur_frm.doc.system_filter = "All"; |
|||
if(frm.doc.system_filter == "All"){ |
|||
frm.get_field('system_sub_systems').grid.static_rows = false; |
|||
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
}); |
|||
} |
|||
|
|||
// frm.disable_save(); //*** Check Refresh for Save Function
|
|||
|
|||
// frm.add_custom_button(__('Save'), function(){
|
|||
// // frm.trigger('fnSave');
|
|||
// }).addClass("btn-warning").css({'background-color':'#e31a37', 'color':'white'});
|
|||
|
|||
frm.fields_dict.system_sub_systems.grid.get_field('procedure').get_query = function(doc, cdt, cdn) { |
|||
return { |
|||
filters:[ |
|||
['language', '=', frm.doc.language] |
|||
] |
|||
}; |
|||
}; |
|||
frm.trigger('fnsetsystemsfilter'); |
|||
// Make a Copy of Rows Data for Move Function
|
|||
sub_system_idx.length = 0; |
|||
frm.fields_dict.system_sub_systems.grid.data.forEach((row) => { |
|||
sub_system_idx.push(row); |
|||
}); |
|||
}, |
|||
onload_post_render: function(frm) { |
|||
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { |
|||
if (row.doc.procedure_is_published == 1){ |
|||
// row.doc.procedure_status = "Published";
|
|||
} |
|||
if (row.doc.procedure_status == "Publish Ready"){ |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'}); |
|||
}else if (row.doc.procedure_status == "Published"){ |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#93f163'}); |
|||
} else { |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffffff'}); |
|||
} |
|||
}); |
|||
refresh_field("system_sub_systems"); |
|||
}, |
|||
variant_mapping: function(frm) { |
|||
frm.trigger('fnSet_SM_KM_4_VM'); |
|||
}, |
|||
language: function(frm) { |
|||
frm.trigger('fnSet_SM_KM_4_VM'); |
|||
}, |
|||
system_filter: function(frm) { |
|||
if (frm.doc.system_filter == "All"){ |
|||
frm.get_field('system_sub_systems').grid.static_rows = false; |
|||
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
}); |
|||
|
|||
frm.get_field('systems_assets').grid.static_rows = false; |
|||
frm.fields_dict.systems_assets.grid.grid_rows.forEach((row) => { |
|||
$("div[data-fieldname=systems_assets]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
}); |
|||
|
|||
} else { |
|||
frm.get_field('system_sub_systems').grid.static_rows = false; |
|||
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { |
|||
if (row.doc.systems != frm.doc.system_filter){ |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide(); |
|||
} else { |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
} |
|||
}); |
|||
|
|||
frm.get_field('systems_assets').grid.static_rows = false; |
|||
frm.fields_dict.systems_assets.grid.grid_rows.forEach((row) => { |
|||
if (row.doc.systems != frm.doc.system_filter){ |
|||
$("div[data-fieldname=systems_assets]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').hide(); |
|||
} else { |
|||
$("div[data-fieldname=systems_assets]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').show(); |
|||
} |
|||
}); |
|||
} |
|||
}, |
|||
fnsetsystemsfilter: function(frm){ |
|||
var filtered_systems = frm.doc.system_filter; |
|||
$("select[data-fieldname='system_filter']").empty(); |
|||
$("select[data-fieldname='system_filter']").append(new Option("All", "All")); |
|||
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { |
|||
let value = row.doc.systems; |
|||
if (value) |
|||
if ($("select[data-fieldname='system_filter'] option[value='" + value + "']").length === 0){ |
|||
$("select[data-fieldname='system_filter']").append(new Option(value, value)); |
|||
} |
|||
|
|||
}); |
|||
frm.doc.system_filter = filtered_systems; |
|||
//refresh_field("system_sub_systems");
|
|||
}, |
|||
fnLoadmat_initial_values: function(frm){ |
|||
if (frm.doc.system_sub_systems !== undefined){ |
|||
mat_array.length = 0; |
|||
frm.doc.system_sub_systems.forEach(row => { |
|||
// ***Update the Current Procedure Status
|
|||
if (row.procedure){ |
|||
frappe.db.get_doc('Procedure', row.procedure) |
|||
.then(doc => { |
|||
row.procedure_status = doc.workflow_state; |
|||
refresh_field("system_sub_systems"); |
|||
}); |
|||
} |
|||
// ***Store the Initial MAT values
|
|||
var valueToPush = {}; |
|||
valueToPush.name = row.name; |
|||
valueToPush.type = (frm.is_new() ? "New":"Initial"); |
|||
valueToPush.mat_initial = (row.mat === undefined ? null:row.mat); |
|||
valueToPush.mat_update = (frm.is_new() ? row.mat:null); |
|||
valueToPush.idx = row.idx; |
|||
valueToPush.sub_systems = row.sub_systems; |
|||
valueToPush.procedure_status = row.procedure_status; |
|||
valueToPush.procedure_is_published = row.procedure_is_published; |
|||
mat_array.push(valueToPush); |
|||
}); |
|||
} |
|||
}, |
|||
fnSave1: function(frm){ |
|||
//*** Check the respective Kilometer Mapping Document exisits
|
|||
if (frm.is_new()) { |
|||
if(frm.doc.variant_mapping) |
|||
var km_doc_name = frm.doc.variant_mapping + "-" + frm.doc.language + "-KM"; |
|||
frappe.db.exists('System Mapping', frm.doc.variant_mapping + "-" + frm.doc.language + "-SM") |
|||
.then(smexists => { |
|||
if (smexists){ |
|||
frappe.throw(__('System Mapping already Exists!!!')); |
|||
} else { |
|||
frappe.db.exists('Kilometer Mapping', km_doc_name) |
|||
.then(exists => { |
|||
if (exists) { |
|||
frm.trigger('fnSave_caller'); |
|||
} else { |
|||
// frappe.call({
|
|||
// "method": "smart_service.transactions.doctype.system_mapping.system_mapping.create_kilometer",
|
|||
// "args": {
|
|||
// "doc": cur_frm.doc.name,
|
|||
// "doctype": 'Kilometer Mapping',
|
|||
// "variant_mapping": frm.doc.variant_mapping,
|
|||
// "language":frm.doc.language
|
|||
// },
|
|||
// })
|
|||
// frappe.db.insert({
|
|||
// doctype: 'Kilometer Mapping',
|
|||
// variant_mapping: frm.doc.variant_mapping,
|
|||
// language:frm.doc.language
|
|||
// }).then(doc => {
|
|||
// frm.set_value("kilometer_mapping",doc.name);
|
|||
// refresh_field("kilometer_mapping");
|
|||
// frm.trigger('fnSave_caller');
|
|||
// });
|
|||
} |
|||
}); |
|||
} |
|||
}); |
|||
} else { |
|||
frm.trigger('fnSave_caller'); |
|||
} |
|||
}, |
|||
fnSave_caller: function(frm){ |
|||
// frappe.validated = false
|
|||
//*** Construct the change point as HTML
|
|||
var html = "<html><head><style>table, th, td {border: 1px solid #DFDFDF; border-collapse: collapse;}table {border-radius: 10px;}th, td {text-align:left;padding: 5px;}</style></head><body><table>"; |
|||
$.each(mat_array, function(index, row){ |
|||
if (row.type !== "Initial"){ |
|||
html = html + "<tr><td>" + row.sub_systems + "</td><td> MAT " + row.type + ": <b>" + row.mat_update + "</b></td></tr>" ; |
|||
dusted = true; |
|||
} |
|||
}); |
|||
html = html + "</table></body>"; |
|||
|
|||
if (dusted){ |
|||
// frappe.msgprint('Changes will impact KM Mapping')
|
|||
// frappe.msgprint('Changes will impact KM Mapping - <b>'+ frm.doc.kilometer_mapping + '</b><br>This Document status will be set to: <b>Draft</b><br><br>Following are the changes updated: <br>' + html,
|
|||
// () => {
|
|||
//*** Change the State to Draft for KM
|
|||
//console.log("Dusted:" + dusted);
|
|||
//console.log("Is Dirty:" + frm.is_dirty());
|
|||
frappe.db.set_value('Kilometer Mapping', frm.doc.kilometer_mapping, 'workflow_state', 'Draft') |
|||
.then(r => { |
|||
dusted = false;//frm.save();
|
|||
// MOVE THIS CODE TO PY FILE ********* START
|
|||
mat_array.forEach((array_row) => { |
|||
|
|||
//*** Add Edit Delete the respective Kiolmeter with Updated/Deleted MAT
|
|||
|
|||
if (array_row.type !== "Initial"){ |
|||
frappe.call({ |
|||
"method": "smart_service.transactions.doctype.system_mapping.system_mapping.update_mat", |
|||
"args": { |
|||
"doc": cur_frm.doc.name, |
|||
"km": frm.doc.kilometer_mapping, |
|||
"vehicle": frm.doc.vehicle, |
|||
"type": array_row.type, |
|||
"idx": array_row.idx, |
|||
"systems": array_row.systems, |
|||
"sub_systems": array_row.sub_systems, |
|||
"mat_initial": array_row.mat_initial, //*** for Deleted
|
|||
"mat_update": array_row.mat_update, //*** for New, Added & Edited
|
|||
"km_applicable": 0 |
|||
}, |
|||
//freeze: true,
|
|||
//async:false,
|
|||
callback:function(r){ |
|||
frappe.msgprint('Changes will impact KM Mapping - <b>'+ frm.doc.kilometer_mapping + '</b><br>This Document status will be set to: <b>Draft</b><br><br>Following are the changes updated: <br>' + html) |
|||
} |
|||
}); |
|||
} |
|||
// });
|
|||
// MOVE THIS CODE TO PY FILE ********* END
|
|||
// frappe.show_alert({
|
|||
// message:__('Inserted Rows in KM Doc: ' + frm.doc.kilometer_mapping),
|
|||
// indicator:'green'
|
|||
// }, 5);
|
|||
frm.trigger('fnLoadmat_initial_values'); |
|||
//frappe.validated = true
|
|||
// frm.save()
|
|||
}); |
|||
}, () => { |
|||
// action to perform if No is selected
|
|||
}); |
|||
} else if(frm.is_dirty()){ |
|||
dusted = false;//frm.save();
|
|||
frm.trigger('fnLoadmat_initial_values'); |
|||
// } else {
|
|||
// frappe.show_alert({
|
|||
// message:__('No updates for Kilometer Mapping... '),
|
|||
// indicator:'yellow'
|
|||
// }, 5);
|
|||
} |
|||
}, |
|||
fnSet_SM_KM_4_VM: function (frm) { |
|||
if (frm.doc.variant_mapping === undefined) return; |
|||
frappe.db.exists('System Mapping', frm.doc.variant_mapping + "-" + frm.doc.language + "-SM") |
|||
.then(smexists => { |
|||
if (smexists){ |
|||
frappe.throw(__('System Mapping already Exists!!!')); |
|||
//frm.set_value("variant_mapping",null);
|
|||
//refresh_field("variant_mapping");
|
|||
} else { |
|||
frappe.db.exists('Kilometer Mapping', frm.doc.variant_mapping + "-" + frm.doc.language + "-KM") |
|||
.then(exists => { |
|||
if (exists){ |
|||
frm.set_value("kilometer_mapping",frm.doc.variant_mapping + "-" + frm.doc.language + "-KM"); |
|||
} else { |
|||
frm.set_value("kilometer_mapping",null); |
|||
frm.set_value("km_active_status","Not Configured!"); |
|||
} |
|||
}); |
|||
} |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
frappe.ui.form.on('System Mapping_Sub System', { |
|||
before_system_sub_systems_remove: function(frm,cdt,cdn) { |
|||
var d = locals[cdt][cdn]; |
|||
|
|||
var id = d.idx; |
|||
id = id-1; |
|||
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id]; |
|||
let index = mat_array.findIndex(o => o.name === row.doc.name); |
|||
if (index >= 0){ |
|||
|
|||
if (row.doc.mat !== ""){ |
|||
mat_array[index].type = "Deleted"; |
|||
mat_array[index].systems = row.doc.systems; |
|||
mat_array[index].sub_systems = row.doc.sub_systems; |
|||
mat_array[index].idx = row.doc.idx; |
|||
mat_array[index].mat_update = row.doc.mat === '' ? null : row.doc.mat; |
|||
} |
|||
} |
|||
}, |
|||
system_sub_systems_move: function(frm,cdt,cdn) { |
|||
var d = locals[cdt][cdn]; |
|||
|
|||
var id = d.idx; |
|||
var from = id; |
|||
id = id-1; |
|||
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id]; |
|||
|
|||
let index = sub_system_idx.findIndex(o => o.name === d.name); |
|||
var to = index + 1; |
|||
|
|||
if(from > to) {to = [from, from = to][0];} |
|||
|
|||
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { |
|||
if (row.doc.procedure_status == "Publish Ready"){ |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'}); |
|||
}else if (row.doc.procedure_status == "Published"){ |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#93f163'}); |
|||
} else { |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffffff'}); |
|||
} |
|||
if (row.doc.idx >= from && row.doc.idx <= to) { |
|||
if (row.doc.procedure_is_published == 1){ |
|||
// row.doc.procedure_status = "Publish Ready";
|
|||
row.doc.procedure_is_published = 0; |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'}); |
|||
} |
|||
} |
|||
}); |
|||
refresh_field("system_sub_systems"); |
|||
}, |
|||
system_sub_systems_add: function(frm,cdt,cdn) { |
|||
var d = locals[cdt][cdn]; |
|||
var id = d.idx; |
|||
id = id-1; |
|||
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id]; |
|||
var prevrow = frm.fields_dict.system_sub_systems.grid.grid_rows[id-1]; |
|||
if (frm.doc.system_filter == "All"){ |
|||
if (prevrow !== undefined) row.doc.systems = prevrow.doc.systems; |
|||
}else{ |
|||
row.doc.systems = frm.doc.system_filter; |
|||
} |
|||
|
|||
}, |
|||
systems: function (frm,cdt,cdn) { |
|||
frm.trigger('fnsetsystemsfilter'); |
|||
}, |
|||
system_sub_systems_remove: function(frm,cdt,cdn) { |
|||
let index = sub_system_idx.findIndex(o => o.name === cdn); |
|||
frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { |
|||
if (row.doc.procedure_status == "Publish Ready"){ |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'}); |
|||
}else if (row.doc.procedure_status == "Published"){ |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#93f163'}); |
|||
} else { |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffffff'}); |
|||
} |
|||
if (row.doc.idx >= index) { |
|||
if (row.doc.procedure_is_published == 1){ |
|||
// row.doc.procedure_status = "Publish Ready";
|
|||
row.doc.procedure_is_published = 0; |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'}); |
|||
} |
|||
} |
|||
}); |
|||
frm.refresh(); |
|||
frm.doc.system_filter = "All"; |
|||
}, |
|||
systems: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)}, |
|||
sub_systems: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)}, |
|||
procedure: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)}, |
|||
active_status: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)}, |
|||
symptom: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)}, |
|||
component: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)}, |
|||
estimate_time: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)}, |
|||
rts: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)}, |
|||
cover_image: function(frm,cdt,cdn) {fn_updateProceduteStatus(frm,cdt,cdn)}, |
|||
mat: function(frm,cdt,cdn) { |
|||
var res_mat = []; |
|||
var d = locals[cdt][cdn]; |
|||
var id = d.idx; |
|||
for (var i = 0; i < cur_frm.doc.system_sub_systems.length; i++) { |
|||
for (var j = 0; j < res_mat.length; j++) { |
|||
var list_mat = res_mat[j]; |
|||
var cur_mat = cur_frm.doc.system_sub_systems[i].mat; |
|||
if((list_mat) && (cur_mat)){ |
|||
var dup_mat = list_mat.toUpperCase(); |
|||
var another_dup_mat = cur_mat.toUpperCase() |
|||
if(dup_mat == another_dup_mat){ |
|||
// cur_frm.doc.system_sub_systems[i].mat = '';
|
|||
//cur_frm.refresh_field('mat')
|
|||
// cur_frm.refresh_fields();
|
|||
frappe.throw('You Cannot Select Same MAT ' + cur_mat + ' Multiple Times' + ' in Row no ' + id) |
|||
// }
|
|||
} |
|||
} |
|||
// if (res_mat[j] == cur_frm.doc.system_sub_systems[i].mat) {
|
|||
// cur_frm.doc.system_sub_systems[i].mat = '';
|
|||
// cur_frm.refresh_field('mat')
|
|||
// cur_frm.refresh_fields();
|
|||
// frappe.throw('You Cannot Select Same MAT ' + cur_frm.doc.system_sub_systems[i].mat + ' Multiple Times');
|
|||
// }
|
|||
} |
|||
if (cur_frm.doc.system_sub_systems[i].mat) { |
|||
res_mat.push(frm.doc.system_sub_systems[i].mat) |
|||
} |
|||
} |
|||
cur_frm.refresh_fields(); |
|||
frm.refresh_field("system_sub_systems") |
|||
fn_mat_updated(frm,cdt,cdn) |
|||
}, |
|||
sub_systems: function(frm,cdt,cdn) { |
|||
var d = locals[cdt][cdn]; |
|||
var id = d.idx; |
|||
id = id-1; |
|||
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id]; |
|||
var procedurename = frm.doc.variant_mapping+"-"+d.sub_systems+"-"+frm.doc.language; |
|||
frappe.db.exists('Procedure', procedurename) |
|||
.then(exists => { |
|||
if (exists){ |
|||
frappe.db.get_doc('Procedure', procedurename) |
|||
.then(doc => { |
|||
row.doc.procedure = doc.name; |
|||
row.doc.procedure_status = doc.workflow_state; |
|||
if (row.doc.estimate_time === undefined) row.doc.estimate_time = doc.estimate_time; |
|||
if (row.doc.rts === undefined) row.doc.rts = doc.rts; |
|||
if (row.doc.mat === undefined) {row.doc.mat = doc.mat; fn_mat_updated(frm,cdt,cdn)} |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure"]').css({'background-color': '#ffc3c3'}); |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'}); |
|||
row.toggle_editable_row(false); |
|||
refresh_field("system_sub_systems"); |
|||
}); |
|||
}else{ |
|||
row.doc.procedure = ""; |
|||
row.doc.procedure_status = ""; |
|||
if(row.doc.mat){ |
|||
row.doc.mat = ''; |
|||
fn_mat_updated(frm,cdt,cdn)} |
|||
row.toggle_editable_row(false); |
|||
refresh_field("system_sub_systems"); |
|||
frappe.msgprint(__('Procedure to be created or sub-system renamed')); |
|||
} |
|||
}); |
|||
var res_system = []; |
|||
for (var i = 0; i < frm.doc.system_sub_systems.length; i++) { |
|||
for (var j = 0; j < res_system.length; j++) { |
|||
var sys = frm.doc.system_sub_systems[i].sub_systems; |
|||
if(frm.doc.system_sub_systems[i].sub_systems == res_system[j]){ |
|||
frm.doc.system_sub_systems[i].sub_systems = ''; |
|||
frm.refresh_field('sub_Systems') |
|||
frm.refresh_fields(); |
|||
frappe.msgprint('You Cannot Select Same Sub Systems ' + sys + ' Multiple Times'); |
|||
} |
|||
} |
|||
if (frm.doc.system_sub_systems[i].sub_systems) { |
|||
res_system.push(frm.doc.system_sub_systems[i].sub_systems) |
|||
} |
|||
} |
|||
}, |
|||
procedure: function(frm,cdt,cdn) { |
|||
var d = locals[cdt][cdn]; |
|||
var id = d.idx; |
|||
id = id-1; |
|||
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id]; |
|||
var procedurename = frm.doc.variant_mapping+"-"+d.sub_systems+"-"+frm.doc.language; |
|||
if (d.procedure){ |
|||
frappe.db.exists('Procedure', d.procedure) |
|||
.then(exists => { |
|||
if (exists){ |
|||
frappe.db.get_doc('Procedure', d.procedure) |
|||
.then(doc => { |
|||
row.doc.procedure = doc.name; |
|||
row.doc.procedure_status = doc.workflow_state; |
|||
row.doc.procedure_is_published = 0; |
|||
//if (row.doc.estimated_time === undefined) row.doc.estimated_time = doc.estimated_time;
|
|||
//if (row.doc.rts === undefined) row.doc.rts = doc.rts;
|
|||
//if (row.doc.mat === undefined) row.doc.mat = doc.mat;
|
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure"]').css({'background-color': '#ffc3c3'}); |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'}); |
|||
row.toggle_editable_row(false); |
|||
refresh_field("system_sub_systems"); |
|||
}); |
|||
}else{ |
|||
row.doc.procedure = ""; |
|||
row.doc.procedure_status = ""; |
|||
row.toggle_editable_row(false); |
|||
refresh_field("system_sub_systems"); |
|||
frappe.throw(__('Procedure to be created or sub-system renamed')); |
|||
} |
|||
}); |
|||
} else { |
|||
row.doc.procedure_status = ""; |
|||
row.toggle_editable_row(false); |
|||
refresh_field("system_sub_systems"); |
|||
} |
|||
}, |
|||
}); |
|||
|
|||
function fn_updateProceduteStatus(frm,cdt,cdn){ |
|||
var d = locals[cdt][cdn]; |
|||
var id = d.idx; |
|||
id = id-1; |
|||
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id]; |
|||
if (row.doc.procedure_is_published == 1){ |
|||
// row.doc.procedure_status = "Publish Ready";
|
|||
row.doc.procedure_is_published = 0; |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#ffc3c3'}); |
|||
row.toggle_editable_row(false); |
|||
} |
|||
refresh_field("system_sub_systems"); |
|||
|
|||
} |
|||
function fn_mat_updated(frm,cdt,cdn){ |
|||
fn_updateProceduteStatus(frm,cdt,cdn); |
|||
var d = locals[cdt][cdn]; |
|||
var id = d.idx; |
|||
id = id-1; |
|||
var row = frm.fields_dict.system_sub_systems.grid.grid_rows[id]; |
|||
let index = mat_array.findIndex(o => o.name === row.doc.name); |
|||
if (index >= 0){ |
|||
mat_array[index].mat_update = row.doc.mat === '' ? null : row.doc.mat; |
|||
if (row.doc.mat === ""){ |
|||
if (mat_array[index].mat_initial === null){ |
|||
mat_array[index].type = "Initial"; |
|||
if (mat_array[index].procedure_is_published){ |
|||
row.doc.procedure_status = "Published"; |
|||
row.doc.procedure_is_published = 1; |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#93f163'}); |
|||
row.toggle_editable_row(false); |
|||
} |
|||
} else {mat_array[index].type = "Deleted"; |
|||
mat_array[index].systems = row.doc.systems; |
|||
mat_array[index].sub_systems = row.doc.sub_systems; |
|||
mat_array[index].idx = row.doc.idx; |
|||
} |
|||
} else { |
|||
if (mat_array[index].mat_initial === null || mat_array[index].mat_initial == ''){ |
|||
mat_array[index].type = "Added"; |
|||
mat_array[index].systems = row.doc.systems; |
|||
mat_array[index].sub_systems = row.doc.sub_systems; |
|||
mat_array[index].idx = row.doc.idx; |
|||
} else { |
|||
if (mat_array[index].mat_initial == row.doc.mat){ |
|||
mat_array[index].type = "Initial"; |
|||
mat_array[index].systems = row.doc.systems; |
|||
mat_array[index].sub_systems = row.doc.sub_systems; |
|||
mat_array[index].idx = row.doc.idx; |
|||
if (mat_array[index].procedure_is_published){ |
|||
row.doc.procedure_status = "Published"; |
|||
row.doc.procedure_is_published = 1; |
|||
$("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="'+ row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({'background-color': '#93f163'}); |
|||
row.toggle_editable_row(false); |
|||
} |
|||
} else { |
|||
mat_array[index].type = "Edited"; |
|||
mat_array[index].systems = row.doc.systems; |
|||
mat_array[index].sub_systems = row.doc.sub_systems; |
|||
mat_array[index].idx = row.doc.idx; |
|||
} |
|||
} |
|||
} |
|||
} else { |
|||
var valueToPush = {}; |
|||
valueToPush.name = row.doc.name; |
|||
valueToPush.type = "New"; |
|||
valueToPush.mat_initial = null; |
|||
valueToPush.mat_update = row.doc.mat; |
|||
valueToPush.idx = row.doc.idx; |
|||
valueToPush.systems = row.doc.systems; |
|||
valueToPush.sub_systems = row.doc.sub_systems; |
|||
valueToPush.procedure_status = row.doc.procedure_status; |
|||
valueToPush.procedure_is_published = row.doc.procedure_is_published; |
|||
mat_array.push(valueToPush); |
|||
} |
|||
refresh_field("system_sub_systems"); |
|||
} |
|||
|
|||
frappe.ui.form.on('System Mapping_System Assets', { |
|||
remarks: function(frm,cdt,cdn){ |
|||
var child = locals[cdt][cdn]; |
|||
if(child.active_status == "Active"){ |
|||
child.remarks = ''; |
|||
cur_frm.refresh_fields(); |
|||
frappe.throw("Remarks should not allow for Active status") |
|||
} |
|||
}, |
|||
active_status: function(frm,cdt,cdn){ |
|||
var child = locals[cdt][cdn]; |
|||
child.remarks = ''; |
|||
cur_frm.refresh_fields(); |
|||
|
|||
}, |
|||
systems_assets_add: function(frm,cdt,cdn){ |
|||
var d = locals[cdt][cdn]; |
|||
var id = d.idx; |
|||
id = id-1; |
|||
var row = frm.fields_dict.systems_assets.grid.grid_rows[id]; |
|||
var prevrow = frm.fields_dict.systems_assets.grid.grid_rows[id-1]; |
|||
if (frm.doc.system_filter == "All"){ |
|||
if (prevrow !== undefined) row.doc.systems = prevrow.doc.systems; |
|||
}else{ |
|||
row.doc.systems = frm.doc.system_filter; |
|||
} |
|||
row.doc.language = frm.doc.language; |
|||
cur_frm.refresh_fields(); |
|||
} |
|||
}); |
Loading…
Reference in new issue