|
|
|
|
!function(){"use strict";function e(e,a){var t;return frappe.call({method:"frappe.client.get",async:!1,args:{doctype:e,name:a},callback:function(e){e.message&&(t=e.message)}}),t}$(document).ready(function(){$(".dropdown-notifications").after('<li id="labels-toolbar" class="nav-item"><a class="nav-link label-printing-icon text-muted"><i class="fa fa-tag fa-lg" aria-hidden="true"></i></a></li>'),$("#labels-toolbar").click(function(a){!function(a){var t=a.view.cur_frm,l={labels:[{item_qty:0,label_qty:1}]};null!==t&&("Work Order"!==t.doctype&&"Item"!==t.doctype||t.docname&&(l.doctype=t.doctype,l.docname=t.docname));var i=new frappe.ui.Dialog({title:__("Print Labels"),fields:[{label:__("Reference Doctype"),options:["Work Order","Item","Label"],fieldname:"doctype",fieldtype:"Select",default:l.doctype},{label:__("Get data"),fieldname:"get_data",fieldtype:"Button",click:function(){n()}},{fieldtype:"Column Break"},{label:__("Reference Docname"),fieldname:"docname",fieldtype:"Data",options:"doctype",default:l.docname},{fieldtype:"Section Break",label:__("Information")},{label:__("Item Code"),fieldname:"item_code",fieldtype:"Data"},{label:__("Item Name"),fieldname:"item_name",fieldtype:"Data"},{label:__("Delivery Date"),fieldname:"delivery_date",fieldtype:"Date"},{fieldtype:"Column Break"},{label:__("Customer"),fieldname:"customer",fieldtype:"Data"},{label:__("Batch"),fieldname:"batch",fieldtype:"Data"},{fieldtype:"Section Break",label:__("Labels")},{fieldname:"labels",fieldtype:"Table",cannot_add_rows:!1,in_place_edit:!0,data:l.labels,get_data:function(){return l.labels},fields:[{fieldtype:"Int",fieldname:"item_qty",in_list_view:1,label:__("Item Qty")},{label:__("Label Qty"),fieldname:"label_qty",in_list_view:1,fieldtype:"Int"},{fieldtype:"Data",fieldname:"information",in_list_view:1,label:__("Information")}]}],primary_action_label:"Print",primary_action:function(e){frappe.call({method:"label_printing.api.print_label",args:{values:e},callback:function(e){200===e.message&&frappe.show_alert("Label printing successful",5)}}),i.hide()}});function n(){if((l=i.get_values()).doctype&&l.docname){var a=e(l.doctype,l.docname);if("Work Order"===l.doctype){var t=e("Item",a.production_item);if(frappe.call({method:"label_printing.api.get_associated_stockentry",async:!1,args:{workorder:l.docname},callback:function(e){e.message&&(l.batch=e.message.items[e.message.items.length-1].batch_no)}}),l.item_code=t.item_code,l.item_name=t.item_name,l.delivery_date=a.expected_delivery_date,l.labels[0].item_qty=a.qty,l.labels[0].label_qty=1,t.associated_company){var n=e("Customer",t.associated_company);n.short_name?l.customer=n.short_name:l.customer=t.associated_company}l.total_amount=a.qty,l.labels[0].qty_per_label=a.qty,i.fields_dict.labels.refresh()}else if("Item"===l.doctype){var o=e("Item",a.item_code);if(l.item_code=a.item_code,l.item_name=a.item_name,o.associated_company){var c=e("Customer",a.associated_company);c.short_name?l.customer=c.short_name:l.customer=a.associated_company}}i.set_values(l)}}n(),i.show(),i.fields_dict.doctype.$input.on("change",function(){i.fields_dict.docname.refresh()})}(a)})})}();
|