From dc8913e13218540791215049a39264d051baf845 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 9 Jan 2013 12:35:24 +0530 Subject: [PATCH] toggle display of contact info based on customer and conatct, address query based on customer --- .../doctype/sales_invoice/sales_invoice.js | 29 +++------------ selling/doctype/opportunity/opportunity.js | 22 +++++++++--- selling/doctype/quotation/quotation.js | 24 ++----------- selling/doctype/sales_common/sales_common.js | 20 +++++++++++ selling/doctype/sales_order/sales_order.js | 31 ++++------------ stock/doctype/delivery_note/delivery_note.js | 35 +++++++------------ 6 files changed, 65 insertions(+), 96 deletions(-) diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js index 86dc3a5c14..eab1d4744d 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.js +++ b/accounts/doctype/sales_invoice/sales_invoice.js @@ -94,8 +94,7 @@ cur_frm.cscript.hide_fields = function(doc, cdt, cdn) { for(f in item_flds_pos) cur_frm.fields_dict['entries'].grid.set_column_disp(item_flds_pos[f], false); } - if(doc.customer) unhide_field('contact_section'); - else hide_field('contact_section'); + cur_frm.toggle_display("contact_section", doc.customer); // India related fields var cp = wn.control_panel; @@ -173,6 +172,8 @@ cur_frm.cscript.warehouse = function(doc, cdt , cdn) { //Customer cur_frm.cscript.customer = function(doc,dt,dn,onload) { + cur_frm.toggle_display("contact_section", doc.customer); + var pl = doc.price_list_name; var callback = function(r,rt) { var callback2 = function(doc, dt, dn) { @@ -191,8 +192,6 @@ cur_frm.cscript.customer = function(doc,dt,dn,onload) { } var args = onload ? 'onload':'' if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name), 'get_default_customer_address', args, callback); - - if(doc.customer) unhide_field('contact_section'); } @@ -202,25 +201,6 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1); } -cur_frm.fields_dict.customer_address.on_new = function(dn) { - locals['Address'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Address'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Contact'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; -} - -cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; -} - - // Set Due Date = posting date + credit days cur_frm.cscript.debit_to = function(doc,dt,dn) { @@ -232,7 +212,8 @@ cur_frm.cscript.debit_to = function(doc,dt,dn) { var callback = function(r,rt) { var doc = locals[cur_frm.doctype][cur_frm.docname]; if(doc.customer) $c_obj(make_doclist(dt,dn), 'get_default_customer_address', '', callback2); - if(doc.customer) unhide_field('contact_section'); + cur_frm.toggle_display("contact_section", doc.customer); + cur_frm.refresh(); } diff --git a/selling/doctype/opportunity/opportunity.js b/selling/doctype/opportunity/opportunity.js index d5c665a70c..664b88d8cf 100644 --- a/selling/doctype/opportunity/opportunity.js +++ b/selling/doctype/opportunity/opportunity.js @@ -25,6 +25,9 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn){ cur_frm.add_custom_button('Opportunity Lost', cur_frm.cscript['Declare Opportunity Lost']); cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms); } + + cur_frm.toggle_display("contact_info", doc.customer || doc.lead); + } // ONLOAD @@ -79,7 +82,7 @@ cur_frm.cscript.enquiry_from = function(doc,cdt,cdn){ } // hide - unhide fields based on lead or customer -cur_frm.cscript.lead_cust_show = function(doc,cdt,cdn){ +cur_frm.cscript.lead_cust_show = function(doc,cdt,cdn){ if(doc.enquiry_from == 'Lead'){ unhide_field(['lead']); hide_field(['lead_name','customer','customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']); @@ -87,13 +90,15 @@ cur_frm.cscript.lead_cust_show = function(doc,cdt,cdn){ } else if(doc.enquiry_from == 'Customer'){ unhide_field(['customer']); - hide_field(['lead','lead_name','address_display','contact_display','contact_mobile','contact_email','territory']); + hide_field(['lead','lead_name','address_display','contact_display','contact_mobile','contact_email','territory', 'customer_group']); doc.lead = doc.lead_name = doc.customer = doc.customer_address = doc.contact_person = doc.address_display = doc.contact_display = doc.contact_mobile = doc.contact_email = doc.territory = doc.customer_group = ""; } } // customer cur_frm.cscript.customer = function(doc,dt,dn) { + cur_frm.toggle_display("contact_info", doc.customer || doc.lead); + if(doc.customer) { cur_frm.call({ doc: cur_frm.doc, @@ -127,11 +132,18 @@ cur_frm.fields_dict.contact_person.on_new = function(dn) { } cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; + return 'SELECT name, address_line1, city FROM tabAddress \ + WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND \ + %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; } cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; + if (!doc.customer) msgprint("Please select customer first"); + else { + return 'SELECT name, CONCAT(first_name," ",ifnull(last_name,"")) As FullName, \ + department, designation FROM tabContact WHERE customer = "'+ doc.customer + + '" AND docstatus != 2 AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; + } } // lead @@ -140,6 +152,8 @@ cur_frm.fields_dict['lead'].get_query = function(doc,cdt,cdn){ } cur_frm.cscript.lead = function(doc, cdt, cdn) { + cur_frm.toggle_display("contact_info", doc.customer || doc.lead); + if(doc.lead) get_server_fields('get_lead_details', doc.lead,'', doc, cdt, cdn, 1); if(doc.lead) unhide_field(['lead_name','address_display','contact_mobile','contact_email','territory']); } diff --git a/selling/doctype/quotation/quotation.js b/selling/doctype/quotation/quotation.js index 3673b07d9a..532cecc866 100644 --- a/selling/doctype/quotation/quotation.js +++ b/selling/doctype/quotation/quotation.js @@ -94,8 +94,7 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { erpnext.hide_naming_series(); - if(doc.customer || doc.lead) $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true); - else $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(false); + cur_frm.toggle_display("contact_section", doc.customer || doc.lead); if (!doc.__islocal) { cur_frm.communication_view = new wn.views.CommunicationList({ @@ -119,7 +118,8 @@ cur_frm.cscript.customer = function(doc,dt,dn) { if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name), 'get_default_customer_address', '', callback); - if(doc.customer) unhide_field(['customer_address','contact_person','territory', 'customer_group']); + + cur_frm.toggle_display("contact_section", doc.customer); } cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) { @@ -130,24 +130,6 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc }),'', doc, dt, dn, 1); } -cur_frm.fields_dict.customer_address.on_new = function(dn) { - locals['Address'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Address'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Contact'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; -} - -cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; -} - cur_frm.fields_dict.lead.get_query = erpnext.utils.lead_query; cur_frm.cscript.lead = function(doc, cdt, cdn) { diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js index c1435bd3b3..4ceac9e41d 100644 --- a/selling/doctype/sales_common/sales_common.js +++ b/selling/doctype/sales_common/sales_common.js @@ -320,7 +320,27 @@ cur_frm.fields_dict[cur_frm.cscript.fname].grid.get_field('batch_no').get_query } } +cur_frm.fields_dict.customer_address.on_new = function(dn) { + locals['Address'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; + locals['Address'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; +} +cur_frm.fields_dict.contact_person.on_new = function(dn) { + locals['Contact'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; + locals['Contact'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; +} + +cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { + return 'SELECT name, address_line1, city FROM tabAddress \ + WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND \ + %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; +} + +cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { + return 'SELECT name, CONCAT(first_name," ",ifnull(last_name,"")) As FullName, \ + department, designation FROM tabContact WHERE customer = "'+ doc.customer + + '" AND docstatus != 2 AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50'; +} // *********************** QUANTITY *************************** cur_frm.cscript.qty = function(doc, cdt, cdn) { cur_frm.cscript.recalc(doc, 1); } diff --git a/selling/doctype/sales_order/sales_order.js b/selling/doctype/sales_order/sales_order.js index a3b71b4cbb..f8d9fde41d 100644 --- a/selling/doctype/sales_order/sales_order.js +++ b/selling/doctype/sales_order/sales_order.js @@ -36,7 +36,9 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { // load default charges if(doc.__islocal && !doc.customer){ - hide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']); + hide_field(['customer_address', 'contact_person', 'customer_name', + 'address_display', 'contact_display', 'contact_mobile', + 'contact_email', 'territory', 'customer_group']); } } @@ -59,9 +61,8 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { if (!cur_frm.cscript.is_onload) cur_frm.cscript.hide_price_list_currency(doc, cdt, cdn); - if(doc.customer) $(cur_frm.fields_dict.contact_info.row.wrapper).toggle(true); - else $(cur_frm.fields_dict.contact_info.row.wrapper).toggle(false); - + cur_frm.toggle_display("contact_info", doc.customer); + if(doc.docstatus==1) { if(doc.status != 'Stopped') { cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms); @@ -105,11 +106,11 @@ cur_frm.cscript.order_type = function(doc) { //customer cur_frm.cscript.customer = function(doc,dt,dn) { + cur_frm.toggle_display("contact_info", doc.customer); + var pl = doc.price_list_name; var callback = function(r,rt) { var callback2 = function(r, rt) { - - if(doc.customer) unhide_field(['customer_address', 'contact_person', 'territory','customer_group']); cur_frm.refresh(); if(!onload && (pl != doc.price_list_name)) cur_frm.cscript.price_list_name(doc, dt, dn); @@ -126,24 +127,6 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1); } -cur_frm.fields_dict.customer_address.on_new = function(dn) { - locals['Address'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Address'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Contact'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; -} - -cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; -} - cur_frm.cscript.pull_quotation_details = function(doc,dt,dn) { var callback = function(r,rt){ var doc = locals[cur_frm.doctype][cur_frm.docname]; diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js index a80966aaa4..21e6dc0514 100644 --- a/stock/doctype/delivery_note/delivery_note.js +++ b/stock/doctype/delivery_note/delivery_note.js @@ -69,8 +69,7 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { cur_frm.add_custom_button('Make Packing Slip', cur_frm.cscript['Make Packing Slip']); } - if(doc.customer) $(cur_frm.fields_dict.contact_info.row.wrapper).toggle(true); - else $(cur_frm.fields_dict.contact_info.row.wrapper).toggle(false); + cur_frm.toggle_display("contact_info", doc.customer); set_print_hide(doc, cdt, cdn); } @@ -78,38 +77,25 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { //customer cur_frm.cscript.customer = function(doc,dt,dn,onload) { + cur_frm.toggle_display("contact_info", doc.customer); + var pl = doc.price_list_name; var callback = function(r,rt) { var doc = locals[cur_frm.doctype][cur_frm.docname]; - if(doc.customer) unhide_field(['customer_address','contact_person','territory','customer_group']); + if(doc.customer) + unhide_field(['customer_address','contact_person','territory','customer_group']); cur_frm.refresh(); if(!onload && (pl != doc.price_list_name)) cur_frm.cscript.price_list_name(doc, dt, dn); } var args = onload ? 'onload':'' - if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name), 'get_default_customer_shipping_address', args, callback); + if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name), + 'get_default_customer_shipping_address', args, callback); } cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) { if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1); } -cur_frm.fields_dict.customer_address.on_new = function(dn) { - locals['Address'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Address'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Contact'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; -} - -cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { - return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; -} cur_frm.cscript.get_items = function(doc,dt,dn) { var callback = function(r,rt){ @@ -117,9 +103,12 @@ cur_frm.cscript.get_items = function(doc,dt,dn) { if(r.message){ doc.sales_order_no = r.message; if(doc.sales_order_no) { - unhide_field(['customer_address','contact_person','territory','customer_group']); + unhide_field(['customer_address','contact_person','territory','customer_group']); } - refresh_many(['delivery_note_details','customer','customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']); + + refresh_many(['delivery_note_details', 'customer', 'customer_address', + 'contact_person', 'customer_name', 'address_display', 'contact_display', + 'contact_mobile', 'contact_email', 'territory', 'customer_group']); } } $c_obj(make_doclist(doc.doctype, doc.name),'pull_sales_order_details','',callback);