Advertisement
Guest User

Custom Button Issue JS

a guest
Mar 31st, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cur_frm.cscript['Get Alternative Items']= function(doc){
  2.       var dialog = new frappe.ui.Dialog({
  3.         title:__('Alternative Items'),
  4.         fields: [
  5.           {fieldtype:'HTML', fieldname:'alt_item_name', label:__(''), reqd:false,
  6.             description: __("")},
  7.             {fieldtype:'Button', fieldname:'get_item_details', label:__('Ok') }
  8.         ]
  9.       })
  10.       var fd = dialog.fields_dict;
  11.       $(fd.get_item_details.input).closest('div').css("padding-top","15px")
  12.         frappe.call({
  13.           method:"erpnext.selling.custom_methods.get_alternative_item_details",
  14.           args:{"doc":cur_frm.doc},
  15.           callback:function(r){
  16.             var me = this;
  17.              var result_set =r.message
  18.              alter_dic={}
  19.              $.each(result_set,function(i,d){
  20.                 if (d.length!=0){
  21.                   me.table = $("<br><div><b>Alternative Items for "+i+"</b></div></br><div style='width:100%;height:200px;overflow:scroll'><form><table class='table table-bordered' id='mytable'>\
  22.                      <thead><tr><th></th><th>Item</th><th>Stock Level</th></tr></thead>\
  23.                       <tbody></tbody>\
  24.                       </table></form></div>").appendTo($(fd.alt_item_name.wrapper))
  25.                   $.each(d,function(key,val){
  26.                       var row = $("<tr>").appendTo(me.table.find("tbody"));
  27.                        $("<td>").html('<input type="radio" name="sp" id="'+i+'">')
  28.                           .attr("item", val["item_code"])
  29.                           .attr("qty", val["actual_qty"])
  30.                         .appendTo(row)
  31.                       $("<td>").html('<p>'+val["item_code"]+'</p>').appendTo(row);
  32.                       $("<td>").html('<p>'+val["actual_qty"]+'</p>').appendTo(row);
  33.                   })
  34.                      
  35.                 }
  36.                 else{
  37.                   $('<div><b>Alternative Items for '+i+'</b></div></br><div><h5>There is no Stock available of any Equivalent Item</h5></div>').appendTo($(fd.alt_item_name.wrapper))
  38.                 }
  39.             })
  40.               dialog.show();
  41.               $("input[name='sp']").change(function () {
  42.                     alter_dic[$(this).attr('id')]={"item_code":$(this).closest('td').attr("item"),"qty":$(this).closest('td').attr("qty")}
  43.               })
  44.               $(fd.get_item_details.input).click(function(){
  45.                 frappe.call({
  46.                   method: "erpnext.selling.custom_methods.set_alternative_item_details",
  47.                   args: { "alter_dic":alter_dic,"doc":cur_frm.doc},
  48.                   callback: function(r){
  49.                      dialog.hide()
  50.                      refresh_field('delivery_note_details')
  51.                   }
  52.               })
  53.  
  54.            })  
  55.                
  56.           }
  57.       })
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement