blob: e36fa29a386cfb1ab014e3643aa3f83ddc6edac7 [file] [log] [blame]
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301frappe.provide("erpnext.pos");
2{% include "erpnext/public/js/controllers/taxes_and_totals.js" %}
3
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05304frappe.pages['pos'].on_page_load = function (wrapper) {
Rushabh Mehta4c36d732015-01-01 15:59:34 +05305 var page = frappe.ui.make_app_page({
Rushabh Mehta72e17192014-08-08 15:30:49 +05306 parent: wrapper,
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05307 title: __('Point of Sale'),
Rushabh Mehta72e17192014-08-08 15:30:49 +05308 single_column: true
9 });
Rohit Waghchauree0934d12016-05-11 15:04:57 +053010
11 wrapper.pos = new erpnext.pos.PointOfSale(wrapper)
Rushabh Mehta72e17192014-08-08 15:30:49 +053012}
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053013
rohitwaghchaurec13dbd42017-02-01 18:07:22 +053014frappe.pages['pos'].refresh = function (wrapper) {
Rohit Waghchaure9fe40d52016-06-13 21:37:10 +053015 window.onbeforeunload = function () {
16 return wrapper.pos.beforeunload()
17 }
Rohit Waghchauree0934d12016-05-11 15:04:57 +053018}
19
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053020erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
rohitwaghchaurec13dbd42017-02-01 18:07:22 +053021 init: function (wrapper) {
Rohit Waghchaure6068aec2017-03-10 11:40:28 +053022 this.page_len = 20;
Rohit Waghchauree0934d12016-05-11 15:04:57 +053023 this.page = wrapper.page;
24 this.wrapper = $(wrapper).find('.page-content');
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053025 this.set_indicator();
26 this.onload();
27 this.make_menu_list();
Rohit Waghchaure017f5002017-03-08 17:34:39 +053028 this.bind_events();
Rohit Waghchaure75177c02017-03-16 15:21:21 +053029 this.bind_items_event();
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053030 this.si_docs = this.get_doc_from_localstorage();
31 },
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +053032
rohitwaghchaurec13dbd42017-02-01 18:07:22 +053033 beforeunload: function (e) {
34 if (this.connection_status == false && frappe.get_route()[0] == "pos") {
Rohit Waghchaure9fe40d52016-06-13 21:37:10 +053035 e = e || window.event;
36
37 // For IE and Firefox prior to version 4
38 if (e) {
rohitwaghchaurec13dbd42017-02-01 18:07:22 +053039 e.returnValue = __("You are in offline mode. You will not be able to reload until you have network.");
Rohit Waghchaure9fe40d52016-06-13 21:37:10 +053040 return
41 }
42
43 // For Safari
44 return __("You are in offline mode. You will not be able to reload until you have network.");
45 }
46 },
47
rohitwaghchaurec13dbd42017-02-01 18:07:22 +053048 check_internet_connection: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053049 var me = this;
50 //Check Internet connection after every 30 seconds
rohitwaghchaurec13dbd42017-02-01 18:07:22 +053051 setInterval(function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053052 me.set_indicator();
Rohit Waghchauref2aa1762016-05-20 23:55:45 +053053 }, 5000)
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053054 },
55
rohitwaghchaurec13dbd42017-02-01 18:07:22 +053056 set_indicator: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053057 var me = this;
58 // navigator.onLine
Rohit Waghchauref2aa1762016-05-20 23:55:45 +053059 this.connection_status = false;
Rohit Waghchaure26cf01a2016-07-22 13:24:33 +053060 this.page.set_indicator(__("Offline"), "grey")
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053061 frappe.call({
rohitwaghchaurec13dbd42017-02-01 18:07:22 +053062 method: "frappe.handler.ping",
63 callback: function (r) {
64 if (r.message) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053065 me.connection_status = true;
Rohit Waghchaure26cf01a2016-07-22 13:24:33 +053066 me.page.set_indicator(__("Online"), "green")
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053067 }
68 }
69 })
70 },
71
rohitwaghchaurec13dbd42017-02-01 18:07:22 +053072 onload: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053073 var me = this;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +053074 this.get_data_from_server(function () {
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +053075 me.create_new();
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053076 });
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053077 },
78
rohitwaghchaurec13dbd42017-02-01 18:07:22 +053079 make_menu_list: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +053080 var me = this;
Rohit Waghchaure75177c02017-03-16 15:21:21 +053081 this.page.clear_menu();
Faris Ansari769b6ba2017-05-16 07:31:10 +053082
83 // for mobile
84 this.page.add_menu_item(__("Pay"), function () {
85 me.validate();
86 me.update_paid_amount_status(true);
87 me.create_invoice();
88 me.make_payment();
89 }).addClass('visible-xs');
90
rohitwaghchaurec13dbd42017-02-01 18:07:22 +053091 this.page.add_menu_item(__("New Sales Invoice"), function () {
Rohit Waghchaure9fe40d52016-06-13 21:37:10 +053092 me.save_previous_entry();
93 me.create_new();
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +053094 })
95
rohitwaghchaurec13dbd42017-02-01 18:07:22 +053096 this.page.add_menu_item(__("Sync Master Data"), function () {
97 me.get_data_from_server(function () {
Rohit Waghchaureea278b52016-07-21 23:28:04 +053098 me.load_data(false);
Rohit Waghchaure9fe40d52016-06-13 21:37:10 +053099 me.make_customer();
Rohit Waghchaure6f33dfb2016-10-09 15:32:56 +0530100 me.make_item_list();
Rohit Waghchaureea278b52016-07-21 23:28:04 +0530101 me.set_missing_values();
Rohit Waghchauree0934d12016-05-11 15:04:57 +0530102 })
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530103 });
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +0530104
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530105 this.page.add_menu_item(__("Sync Offline Invoices"), function () {
Rohit Waghchaure82be0202016-10-04 12:46:37 +0530106 me.sync_sales_invoice()
107 });
108
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530109 this.page.add_menu_item(__("POS Profile"), function () {
Rohit Waghchauref2aa1762016-05-20 23:55:45 +0530110 frappe.set_route('List', 'POS Profile');
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +0530111 });
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530112 },
113
Rohit Waghchaureb5097ec2017-03-01 01:13:09 +0530114 email_prompt: function() {
115 var me = this;
116 fields = [{label:__("To"), fieldtype:"Data", reqd: 0, fieldname:"recipients",length:524288},
117 {fieldtype: "Section Break", collapsible: 1, label: "CC & Standard Reply"},
118 {fieldtype: "Section Break"},
119 {label:__("Subject"), fieldtype:"Data", reqd: 1,
120 fieldname:"subject",length:524288},
121 {fieldtype: "Section Break"},
122 {label:__("Message"), fieldtype:"Text Editor", reqd: 1,
123 fieldname:"content"},
124 {fieldtype: "Section Break"},
125 {fieldtype: "Column Break"}];
126
127 this.email_dialog = new frappe.ui.Dialog({
128 title: "Email",
129 fields: fields,
130 primary_action_label: __("Send"),
131 primary_action: function() {
132 me.send_action();
133 }
134 });
135
136 this.email_dialog.show()
137 },
138
139 send_action: function() {
140 this.email_queue = this.get_email_queue()
141 this.email_queue[this.frm.doc.offline_pos_name] = JSON.stringify(this.email_dialog.get_values())
142 this.update_email_queue()
143 this.email_dialog.hide()
144 },
145
146 update_email_queue: function () {
147 try {
148 localStorage.setItem('email_queue', JSON.stringify(this.email_queue));
149 } catch (e) {
Faris Ansari1f261a82017-03-06 18:01:58 +0530150 frappe.throw(__("LocalStorage is full, did not save"))
Rohit Waghchaureb5097ec2017-03-01 01:13:09 +0530151 }
152 },
153
154 get_email_queue: function () {
155 try {
156 return JSON.parse(localStorage.getItem('email_queue')) || {};
157 } catch (e) {
158 return {}
159 }
160 },
161
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530162 get_customers_details: function () {
163 try {
164 return JSON.parse(localStorage.getItem('customer_details')) || {};
165 } catch (e) {
166 return {}
167 }
168 },
169
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530170 dialog_actions: function () {
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530171 var me = this;
172
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530173 $(this.list_body).find('.list-select-all').click(function () {
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530174 me.removed_items = [];
175 $(me.list_body).find('.list-delete').prop("checked", $(this).is(":checked"))
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530176 if ($(this).is(":checked")) {
177 $.each(me.si_docs, function (index, data) {
178 for (key in data) {
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530179 me.removed_items.push(key)
180 }
181 })
182 }
183
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530184 me.toggle_delete_button();
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530185 })
186
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530187 $(this.list_body).find('.list-delete').click(function () {
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530188 me.name = $(this).parent().parent().attr('invoice-name');
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530189 if ($(this).is(":checked")) {
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530190 me.removed_items.push(me.name);
191 } else {
192 me.removed_items.pop(me.name)
193 }
194
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530195 me.toggle_delete_button();
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530196 })
197 },
198
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530199 edit_record: function () {
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530200 var me = this;
201
202 doc_data = this.get_invoice_doc(this.si_docs);
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530203 if (doc_data) {
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530204 this.frm.doc = doc_data[0][this.name];
205 this.set_missing_values();
206 this.refresh(false);
Rohit Waghchaure017f5002017-03-08 17:34:39 +0530207 this.toggle_input_field();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530208 this.list_dialog && this.list_dialog.hide();
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530209 }
210 },
211
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530212 delete_records: function () {
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530213 var me = this;
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530214 this.validate_list()
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530215 this.remove_doc_from_localstorage()
216 this.update_localstorage();
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530217 // this.dialog_actions();
218 this.toggle_delete_button();
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530219 },
220
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530221 validate_list: function() {
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530222 var me = this;
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530223 this.si_docs = this.get_submitted_invoice()
224 $.each(this.removed_items, function(index, name){
225 $.each(me.si_docs, function(key, data){
226 if(me.si_docs[key][name] && me.si_docs[key][name].offline_pos_name == name ){
227 frappe.throw(__("Submitted orders can not be deleted"))
228 }
229 })
230 })
231 },
232
233 toggle_delete_button: function () {
234 var me = this;
235 if(this.pos_profile_data["allow_delete"]) {
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530236 if (this.removed_items && this.removed_items.length > 0) {
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530237 $(this.page.wrapper).find('.btn-danger').show();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530238 } else {
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530239 $(this.page.wrapper).find('.btn-danger').hide();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530240 }
241 }
242 },
243
244 get_doctype_status: function (doc) {
245 if (doc.docstatus == 0) {
246 return { status: "Draft", indicator: "red" }
247 } else if (doc.outstanding_amount == 0) {
248 return { status: "Paid", indicator: "green" }
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530249 } else {
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530250 return { status: "Submitted", indicator: "blue" }
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +0530251 }
252 },
253
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530254 set_missing_values: function () {
Rohit Waghchauree0934d12016-05-11 15:04:57 +0530255 var me = this;
256 doc = JSON.parse(localStorage.getItem('doc'))
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530257 if (this.frm.doc.payments.length == 0) {
Rohit Waghchauree0934d12016-05-11 15:04:57 +0530258 this.frm.doc.payments = doc.payments;
Rohit Waghchaureb77a1052016-08-01 18:35:18 +0530259 this.calculate_outstanding_amount();
Rohit Waghchauree0934d12016-05-11 15:04:57 +0530260 }
Rohit Waghchaureea278b52016-07-21 23:28:04 +0530261
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530262 if (this.frm.doc.customer) {
Rohit Waghchaureea278b52016-07-21 23:28:04 +0530263 this.party_field.$input.val(this.frm.doc.customer);
264 }
Rohit Waghchaurebaef2622016-08-05 15:41:36 +0530265
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530266 if (!this.frm.doc.write_off_account) {
Rohit Waghchaurebaef2622016-08-05 15:41:36 +0530267 this.frm.doc.write_off_account = doc.write_off_account
268 }
269
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530270 if (!this.frm.doc.account_for_change_amount) {
Rohit Waghchauree4e69ec2016-08-17 16:20:13 +0530271 this.frm.doc.account_for_change_amount = doc.account_for_change_amount
Rohit Waghchaurebaef2622016-08-05 15:41:36 +0530272 }
Rohit Waghchauree0934d12016-05-11 15:04:57 +0530273 },
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530274
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530275 get_invoice_doc: function (si_docs) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530276 var me = this;
277 this.si_docs = this.get_doc_from_localstorage();
278
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530279 return $.grep(this.si_docs, function (data) {
280 for (key in data) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530281 return key == me.name
282 }
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +0530283 })
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530284 },
285
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530286 get_data_from_server: function (callback) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530287 var me = this;
288 frappe.call({
289 method: "erpnext.accounts.doctype.sales_invoice.pos.get_pos_data",
290 freeze: true,
Rohit Waghchauree0934d12016-05-11 15:04:57 +0530291 freeze_message: __("Master data syncing, it might take some time"),
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530292 callback: function (r) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530293 localStorage.setItem('doc', JSON.stringify(r.message.doc));
Rohit Waghchaure017f5002017-03-08 17:34:39 +0530294 me.init_master_data(r)
Rohit Waghchaurea27c4172016-11-20 23:41:13 +0530295 me.set_interval_for_si_sync();
296 me.check_internet_connection();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530297 if (callback) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530298 callback();
299 }
300 }
301 })
302 },
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +0530303
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530304 init_master_data: function (r) {
Rohit Waghchaurea27c4172016-11-20 23:41:13 +0530305 var me = this;
Rohit Waghchaure017f5002017-03-08 17:34:39 +0530306 this.doc = JSON.parse(localStorage.getItem('doc'));
Rohit Waghchaurea27c4172016-11-20 23:41:13 +0530307 this.meta = r.message.meta;
308 this.item_data = r.message.items;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530309 this.item_groups = r.message.item_groups;
Rohit Waghchaurea27c4172016-11-20 23:41:13 +0530310 this.customers = r.message.customers;
311 this.serial_no_data = r.message.serial_no_data;
312 this.batch_no_data = r.message.batch_no_data;
313 this.tax_data = r.message.tax_data;
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530314 this.address = r.message.address || {};
Rohit Waghchaurea27c4172016-11-20 23:41:13 +0530315 this.price_list_data = r.message.price_list_data;
316 this.bin_data = r.message.bin_data;
317 this.pricing_rules = r.message.pricing_rules;
318 this.print_template = r.message.print_template;
319 this.pos_profile_data = r.message.pos_profile;
320 this.default_customer = r.message.default_customer || null;
rohitwaghchaure34e820d2016-12-20 16:54:24 +0530321 this.print_settings = locals[":Print Settings"]["Print Settings"];
Rohit Waghchaured567e572016-12-21 13:18:36 +0530322 this.letter_head = (this.pos_profile_data.length > 0) ? frappe.boot.letter_heads[this.pos_profile_data[letter_head]] : {};
Rohit Waghchaure017f5002017-03-08 17:34:39 +0530323 this.make_control()
Rohit Waghchaurea27c4172016-11-20 23:41:13 +0530324 },
325
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530326 save_previous_entry: function () {
327 if (this.frm.doc.docstatus < 1 && this.frm.doc.items.length > 0) {
328 this.create_invoice();
Rohit Waghchauref2aa1762016-05-20 23:55:45 +0530329 }
330 },
331
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530332 create_new: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530333 var me = this;
Rohit Waghchauree0934d12016-05-11 15:04:57 +0530334 this.frm = {}
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530335 this.name = null;
Rohit Waghchaureea278b52016-07-21 23:28:04 +0530336 this.load_data(true);
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530337 this.setup();
Rohit Waghchaure61165122017-05-02 13:04:08 +0530338 this.set_default_customer()
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530339 },
340
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530341 load_data: function (load_doc) {
Rohit Waghchaurea27c4172016-11-20 23:41:13 +0530342 var me = this;
Rohit Waghchaureea278b52016-07-21 23:28:04 +0530343
Rohit Waghchaurea27c4172016-11-20 23:41:13 +0530344 this.items = this.item_data;
Rohit Waghchaure80f5bb62016-11-27 12:04:12 +0530345 this.actual_qty_dict = {};
346
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530347 if (load_doc) {
348 this.frm.doc = JSON.parse(localStorage.getItem('doc'));
Rohit Waghchaureea278b52016-07-21 23:28:04 +0530349 }
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530350
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530351 $.each(this.meta, function (i, data) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530352 frappe.meta.sync(data)
Rohit Waghchaurefe7a5b32016-12-27 14:15:52 +0530353 locals["DocType"][data.name] = data;
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530354 })
355
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530356 this.print_template_data = frappe.render_template("print_template", {
357 content: this.print_template,
358 title: "POS", base_url: frappe.urllib.get_base_url(), print_css: frappe.boot.print_css,
359 print_settings: this.print_settings, header: this.letter_head.header, footer: this.letter_head.footer
360 })
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530361 },
362
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530363 setup: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530364 this.make();
365 this.set_primary_action();
Rohit Waghchaure017f5002017-03-08 17:34:39 +0530366 this.party_field.$input.attr('disabled', false);
367 if(this.selected_row) {
368 this.selected_row.hide()
369 }
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530370 },
371
Rohit Waghchaure61165122017-05-02 13:04:08 +0530372 set_default_customer: function() {
373 if (this.default_customer && !this.frm.doc.customer) {
374 this.party_field.$input.val(this.default_customer);
375 this.frm.doc.customer = this.default_customer;
376 this.numeric_keypad.show();
377 this.toggle_list_customer(false)
378 this.toggle_item_cart(true)
379 }
380 },
381
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530382 set_transaction_defaults: function (party) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530383 var me = this;
384 this.party = party;
385 this.price_list = (party == "Customer" ?
386 this.frm.doc.selling_price_list : this.frm.doc.buying_price_list);
387 this.price_list_field = (party == "Customer" ? "selling_price_list" : "buying_price_list");
388 this.sales_or_purchase = (party == "Customer" ? "Sales" : "Purchase");
389 },
390
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530391 make: function () {
Rohit Waghchaure017f5002017-03-08 17:34:39 +0530392 this.make_item_list();
393 this.make_discount_field()
394 },
Charles-Henri Decultot8bec0232017-05-19 12:32:30 +0200395
Rohit Waghchaure017f5002017-03-08 17:34:39 +0530396 make_control: function() {
397 this.frm = {}
398 this.frm.doc = this.doc
399 this.set_transaction_defaults("Customer");
400 this.wrapper.html(frappe.render_template("pos", this.frm.doc));
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530401 this.make_search();
402 this.make_customer();
Faris Ansari339d9c92017-03-07 18:14:06 +0530403 this.make_list_customers();
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +0530404 this.bind_numeric_keypad();
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530405 },
406
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530407 make_search: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530408 var me = this;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530409 this.serach_item = frappe.ui.form.make_control({
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530410 df: {
411 "fieldtype": "Data",
412 "label": "Item",
413 "fieldname": "pos_item",
Rohit Waghchaure26cf01a2016-07-22 13:24:33 +0530414 "placeholder": __("Search Item")
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530415 },
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530416 parent: this.wrapper.find(".search-item"),
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530417 only_input: true,
418 });
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +0530419
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530420 this.serach_item.make_input();
421 this.serach_item.$input.on("keyup", function () {
422 setTimeout(function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530423 me.items = me.get_items();
Rohit Waghchaure6f33dfb2016-10-09 15:32:56 +0530424 me.make_item_list();
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530425 }, 1000);
426 });
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +0530427
Faris Ansari339d9c92017-03-07 18:14:06 +0530428 this.search_item_group = this.wrapper.find('.search-item-group');
Rohit Waghchaured7de3c62017-04-17 13:36:08 +0530429 sorted_item_groups = this.get_sorted_item_groups()
430 var dropdown_html = sorted_item_groups.map(function(item_group) {
Faris Ansari339d9c92017-03-07 18:14:06 +0530431 return "<li><a class='option' data-value='"+item_group+"'>"+item_group+"</a></li>";
432 }).join("");
433
434 this.search_item_group.find('.dropdown-menu').html(dropdown_html);
435
436 this.search_item_group.on('click', '.dropdown-menu a', function() {
437 me.selected_item_group = $(this).attr('data-value');
438 me.search_item_group.find('.dropdown-text').text(me.selected_item_group);
439
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530440 me.page_len = 20;
441 me.items = me.get_items();
442 me.make_item_list();
Faris Ansari339d9c92017-03-07 18:14:06 +0530443 })
444
Faris Ansari45510102017-03-09 14:43:37 +0530445 me.toggle_more_btn();
446
447 this.wrapper.on("click", ".btn-more", function() {
Rohit Waghchaure6068aec2017-03-10 11:40:28 +0530448 me.page_len += 20;
Rushabh Mehta37146262017-02-01 18:17:35 +0530449 me.items = me.get_items();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530450 me.make_item_list();
Faris Ansari45510102017-03-09 14:43:37 +0530451 me.toggle_more_btn();
452 });
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530453
Faris Ansari45510102017-03-09 14:43:37 +0530454 this.page.wrapper.on("click", ".edit-customer-btn", function() {
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530455 me.update_customer()
456 })
Rohit Waghchaure60a05322016-09-12 01:37:46 +0530457 },
458
Rohit Waghchaured7de3c62017-04-17 13:36:08 +0530459 get_sorted_item_groups: function() {
460 list = {}
461 $.each(this.item_groups, function(i, data) {
462 list[i] = data[0]
463 })
464
465 return Object.keys(list).sort(function(a,b){return list[a]-list[b]})
466 },
467
Faris Ansari45510102017-03-09 14:43:37 +0530468 toggle_more_btn: function() {
469 if(!this.items || this.items.length <= this.page_len) {
470 this.wrapper.find(".btn-more").hide();
471 } else {
472 this.wrapper.find(".btn-more").show();
473 }
474 },
475
476 toggle_totals_area: function(show) {
477
Faris Ansari07c9f352017-03-09 17:03:14 +0530478 if(show === undefined) {
Faris Ansari45510102017-03-09 14:43:37 +0530479 show = this.is_totals_area_collapsed;
480 }
481
482 var totals_area = this.wrapper.find('.totals-area');
483 totals_area.find('.net-total-area, .tax-area, .discount-amount-area')
484 .toggle(show);
485
486 if(show) {
487 totals_area.find('.collapse-btn i')
488 .removeClass('octicon-chevron-down')
489 .addClass('octicon-chevron-up');
490 } else {
491 totals_area.find('.collapse-btn i')
492 .removeClass('octicon-chevron-up')
493 .addClass('octicon-chevron-down');
494 }
495
496 this.is_totals_area_collapsed = !show;
497 },
498
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530499 make_list_customers: function () {
500 var me = this;
Faris Ansari339d9c92017-03-07 18:14:06 +0530501 this.list_customers_btn = this.page.wrapper.find('.list-customers-btn');
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530502 this.add_customer_btn = this.wrapper.find('.add-customer-btn');
Faris Ansari339d9c92017-03-07 18:14:06 +0530503 this.pos_bill = this.wrapper.find('.pos-bill-wrapper').hide();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530504 this.list_customers = this.wrapper.find('.list-customers');
Rohit Waghchauree30f83a2017-02-24 18:02:50 +0530505 this.numeric_keypad = this.wrapper.find('.numeric_keypad');
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530506 this.list_customers_btn.addClass("view_customer")
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530507
Faris Ansari45510102017-03-09 14:43:37 +0530508 me.render_list_customers();
509 me.toggle_totals_area(false);
510
Rohit Waghchaure017f5002017-03-08 17:34:39 +0530511 this.page.wrapper.on('click', '.list-customers-btn', function() {
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530512 $(this).toggleClass("view_customer");
513 if($(this).hasClass("view_customer")) {
514 me.render_list_customers();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530515 me.list_customers.show();
516 me.pos_bill.hide();
Rohit Waghchauree30f83a2017-02-24 18:02:50 +0530517 me.numeric_keypad.hide();
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530518 me.toggle_delete_button()
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530519 } else {
520 if(me.frm.doc.docstatus == 0) {
521 me.party_field.$input.attr('disabled', false);
522 }
523 me.pos_bill.show();
Faris Ansari45510102017-03-09 14:43:37 +0530524 me.toggle_totals_area(false);
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530525 me.toggle_delete_button()
Faris Ansari45510102017-03-09 14:43:37 +0530526 me.list_customers.hide();
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530527 me.numeric_keypad.show();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530528 }
529 });
530 this.add_customer_btn.on('click', function() {
531 me.save_previous_entry();
532 me.create_new();
533 me.refresh();
534 me.set_focus();
535 });
Faris Ansari45510102017-03-09 14:43:37 +0530536 this.pos_bill.on('click', '.collapse-btn', function() {
537 me.toggle_totals_area();
538 });
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530539 },
Charles-Henri Decultot8bec0232017-05-19 12:32:30 +0200540
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +0530541 bind_numeric_keypad: function() {
542 var me = this;
543 $(this.numeric_keypad).find('.pos-operation').on('click', function(){
544 me.numeric_val = '';
545 })
546
547 $(this.numeric_keypad).find('.numeric-keypad').on('click', function(){
548 me.numeric_id = $(this).attr("id") || me.numeric_id;
549 me.val = $(this).attr("val")
Rohit Waghchaure017f5002017-03-08 17:34:39 +0530550 if(me.numeric_id) {
551 me.selected_field = $(me.wrapper).find('.selected-item').find('.' + me.numeric_id)
552 }
Faris Ansari339d9c92017-03-07 18:14:06 +0530553
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +0530554 if(me.val && me.numeric_id) {
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +0530555 me.numeric_val += me.val;
556 me.selected_field.val(flt(me.numeric_val))
557 me.selected_field.trigger("change")
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530558 // me.render_selected_item()
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +0530559 }
Faris Ansari339d9c92017-03-07 18:14:06 +0530560
561 if(me.numeric_id && $(this).hasClass('pos-operation')) {
562 me.numeric_keypad.find('button.pos-operation').removeClass('active');
563 $(this).addClass('active');
564
565 me.selected_row.find('.pos-list-row').removeClass('active');
566 me.selected_field.closest('.pos-list-row').addClass('active');
567 }
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +0530568 })
Charles-Henri Decultot8bec0232017-05-19 12:32:30 +0200569
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +0530570 $(this.numeric_keypad).find('.numeric-del').click(function(){
571 me.selected_field = $(me.wrapper).find('.selected-item').find('.' + me.numeric_id)
572 me.numeric_val = cstr(flt(me.selected_field.val())).slice(0, -1);
573 me.selected_field.val(me.numeric_val);
574 me.selected_field.trigger("change")
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530575 // me.render_selected_item()
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +0530576 })
Charles-Henri Decultot8bec0232017-05-19 12:32:30 +0200577
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +0530578 $(this.numeric_keypad).find('.pos-pay').click(function(){
579 me.validate();
580 me.update_paid_amount_status(true);
581 me.create_invoice();
582 me.make_payment();
583 })
584 },
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530585
586 render_list_customers: function () {
587 var me = this;
588
589 this.removed_items = [];
Faris Ansari45510102017-03-09 14:43:37 +0530590 // this.list_customers.empty();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530591 this.si_docs = this.get_doc_from_localstorage();
Rohit Waghchaure6068aec2017-03-10 11:40:28 +0530592 if (!this.si_docs.length) {
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530593 return;
594 }
Faris Ansari45510102017-03-09 14:43:37 +0530595
596 var html = "";
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530597 if(this.si_docs.length) {
598 this.si_docs.forEach(function (data, i) {
599 for (key in data) {
600 html += frappe.render_template("pos_invoice_list", {
601 sr: i + 1,
602 name: key,
603 customer: data[key].customer,
604 paid_amount: format_currency(data[key].paid_amount, me.frm.doc.currency),
605 grand_total: format_currency(data[key].grand_total, me.frm.doc.currency),
606 data: me.get_doctype_status(data[key])
607 });
608 }
609 });
610 }
Faris Ansari45510102017-03-09 14:43:37 +0530611 this.list_customers.find('.list-customers-table').html(html);
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530612
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530613 this.list_customers.on('click', '.customer-row', function () {
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530614 me.list_customers.hide();
Rohit Waghchaure017f5002017-03-08 17:34:39 +0530615 me.numeric_keypad.show();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530616 me.list_customers_btn.toggleClass("view_customer");
617 me.pos_bill.show();
618 me.list_customers_btn.show();
619 me.name = $(this).parents().attr('invoice-name')
620 me.edit_record();
621 })
622
623 //actions
624 $(this.wrapper).find('.list-select-all').click(function () {
625 me.list_customers.find('.list-delete').prop("checked", $(this).is(":checked"))
626 me.removed_items = [];
627 if ($(this).is(":checked")) {
628 $.each(me.si_docs, function (index, data) {
629 for (key in data) {
630 me.removed_items.push(key)
631 }
632 });
633 }
634
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530635 me.toggle_delete_button();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530636 });
637
638 $(this.wrapper).find('.list-delete').click(function () {
639 me.name = $(this).parent().parent().attr('invoice-name');
640 if ($(this).is(":checked")) {
641 me.removed_items.push(me.name);
642 } else {
643 me.removed_items.pop(me.name)
644 }
645
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530646 me.toggle_delete_button();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530647 });
648 },
649
650 bind_delete_event: function() {
651 var me = this;
652
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530653 $(this.page.wrapper).on('click', '.btn-danger', function(){
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530654 frappe.confirm(__("Delete permanently?"), function () {
655 me.delete_records();
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530656 me.list_customers.find('.list-customers-table').html("");
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530657 me.render_list_customers();
658 })
Rushabh Mehta37146262017-02-01 18:17:35 +0530659 })
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530660 },
661
662 set_focus: function () {
663 if (this.default_customer || this.frm.doc.customer) {
664 this.serach_item.$input.focus();
665 } else {
Rohit Waghchaure60a05322016-09-12 01:37:46 +0530666 this.party_field.$input.focus();
667 }
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530668 },
669
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530670 make_customer: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530671 var me = this;
Rohit Waghchaure017f5002017-03-08 17:34:39 +0530672
673 if(!this.party_field) {
674 if(this.page.wrapper.find('.pos-bill-toolbar').length === 0) {
675 $(frappe.render_template('customer_toolbar', {
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530676 allow_delete: this.pos_profile_data["allow_delete"]
Rohit Waghchaure017f5002017-03-08 17:34:39 +0530677 })).insertAfter(this.page.$title_area.hide());
678 }
679
680 this.party_field = frappe.ui.form.make_control({
681 df: {
682 "fieldtype": "Data",
683 "options": this.party,
684 "label": this.party,
685 "fieldname": this.party.toLowerCase(),
686 "placeholder": __("Select or add new customer")
687 },
688 parent: this.page.wrapper.find(".party-area"),
689 only_input: true,
690 });
691
692 this.party_field.make_input();
693 setTimeout(this.set_focus.bind(this), 500);
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530694 me.toggle_delete_button();
Faris Ansari339d9c92017-03-07 18:14:06 +0530695 }
Faris Ansari1f261a82017-03-06 18:01:58 +0530696
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530697 this.party_field.awesomeplete =
698 new Awesomplete(this.party_field.$input.get(0), {
Rushabh Mehta512b85e2016-12-27 12:14:26 +0530699 minChars: 0,
700 maxItems: 99,
701 autoFirst: true,
702 list: [],
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530703 filter: function (item, input) {
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530704 var value = item.value.toLowerCase();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530705 if (value.indexOf('is_action') !== -1 ||
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530706 value.indexOf(input) !== -1) {
707 return true;
708 }
709 },
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530710 item: function (item, input) {
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530711 var d = item;
Faris Ansari45510102017-03-09 14:43:37 +0530712 var html = "<span>" + __(d.label || d.value) + "</span>";
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530713 return $('<li></li>')
714 .data('item.autocomplete', d)
715 .html('<a><p>' + html + '</p></a>')
716 .get(0);
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530717 }
Rushabh Mehta512b85e2016-12-27 12:14:26 +0530718 });
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530719
720 this.customers_mapper = this.customers.map(function (c) {
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530721 return {
722 label: c.name,
723 value: c.name,
724 customer_group: c.customer_group,
725 territory: c.territory
726 }
727 });
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530728
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530729 this.customers_mapper.push({
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530730 label: "<span class='text-primary link-option'>"
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530731 + "<i class='fa fa-plus' style='margin-right: 5px;'></i> "
732 + __("Create a new Customer")
733 + "</span>",
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530734 value: 'is_action',
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530735 action: me.add_customer
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530736 });
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530737 this.autocomplete_customers();
Rushabh Mehta512b85e2016-12-27 12:14:26 +0530738
739 this.party_field.$input
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530740 .on('input', function (e) {
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530741 me.party_field.awesomeplete.list = this.customers_mapper;
Rushabh Mehta512b85e2016-12-27 12:14:26 +0530742 })
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530743 .on('awesomplete-select', function (e) {
744 var customer = me.party_field.awesomeplete
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530745 .get_item(e.originalEvent.text.value);
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530746 if (!customer) return;
747 // create customer link
748 if (customer.action) {
749 customer.action.apply(me);
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530750 return;
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530751 }
Faris Ansari45510102017-03-09 14:43:37 +0530752 me.toggle_list_customer(false);
753 me.toggle_edit_button(true);
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530754 me.update_customer_data(customer);
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530755 me.refresh();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530756 me.set_focus();
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530757 me.list_customers_btn.removeClass("view_customer");
Rushabh Mehta512b85e2016-12-27 12:14:26 +0530758 })
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530759 .on('focus', function (e) {
Rushabh Mehta512b85e2016-12-27 12:14:26 +0530760 $(e.target).val('').trigger('input');
Faris Ansari45510102017-03-09 14:43:37 +0530761 me.toggle_edit_button(false);
Faris Ansari1fe15182017-03-10 14:50:39 +0530762
763 if(me.frm.doc.items.length) {
Rohit Waghchaure6068aec2017-03-10 11:40:28 +0530764 me.toggle_list_customer(false)
765 me.toggle_item_cart(true)
766 } else {
767 me.toggle_list_customer(true)
768 me.toggle_item_cart(false)
769 }
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530770 })
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530771 .on("awesomplete-selectcomplete", function (e) {
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530772 var item = me.party_field.awesomeplete
773 .get_item(e.originalEvent.text.value);
774 // clear text input if item is action
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530775 if (item.action) {
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530776 $(this).val("");
Rohit Waghchauref2aa1762016-05-20 23:55:45 +0530777 }
Rushabh Mehta512b85e2016-12-27 12:14:26 +0530778 });
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530779 },
780
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530781 autocomplete_customers: function() {
782 this.party_field.awesomeplete.list = this.customers_mapper;
783 },
784
Faris Ansari45510102017-03-09 14:43:37 +0530785 toggle_edit_button: function(flag) {
786 this.page.wrapper.find('.edit-customer-btn').toggle(flag);
787 },
788
789 toggle_list_customer: function(flag) {
790 this.list_customers.toggle(flag);
791 },
792
Rohit Waghchaure6068aec2017-03-10 11:40:28 +0530793 toggle_item_cart: function(flag) {
794 this.wrapper.find('.pos-bill-wrapper').toggle(flag);
795 },
796
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530797 add_customer: function() {
798 this.frm.doc.customer = "";
rohitwaghchaure09483d32017-05-16 08:51:24 +0530799 this.update_customer(true);
800 this.numeric_keypad.show();
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530801 },
802
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530803 update_customer: function (new_customer) {
Nabin Hait6e9d2a32017-01-09 17:21:34 +0530804 var me = this;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530805 if (!this.connection_status) return;
Rushabh Mehta37146262017-02-01 18:17:35 +0530806
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530807 this.customer_doc = new frappe.ui.Dialog({
808 'title': 'Customer',
809 fields: [
810 {
Rushabh Mehta37146262017-02-01 18:17:35 +0530811 "label": __("Full Name"),
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530812 "fieldname": "full_name",
813 "fieldtype": "Data",
Rushabh Mehta37146262017-02-01 18:17:35 +0530814 "reqd": 1
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530815 },
816 {
817 "fieldtype": "Section Break"
818 },
819 {
Rushabh Mehta37146262017-02-01 18:17:35 +0530820 "label": __("Email Id"),
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530821 "fieldname": "email_id",
822 "fieldtype": "Data"
823 },
824 {
825 "fieldtype": "Column Break"
826 },
827 {
Rushabh Mehta37146262017-02-01 18:17:35 +0530828 "label": __("Contact Number"),
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530829 "fieldname": "phone",
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530830 "fieldtype": "Data"
831 },
832 {
833 "fieldtype": "Section Break"
834 },
835 {
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530836 "label": __("Address Name"),
837 "read_only": 1,
838 "fieldname": "name",
839 "fieldtype": "Data"
840 },
841 {
Rushabh Mehta37146262017-02-01 18:17:35 +0530842 "label": __("Address Line 1"),
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530843 "fieldname": "address_line1",
844 "fieldtype": "Data"
845 },
846 {
Rushabh Mehta37146262017-02-01 18:17:35 +0530847 "label": __("Address Line 2"),
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530848 "fieldname": "address_line2",
849 "fieldtype": "Data"
850 },
851 {
852 "fieldtype": "Column Break"
853 },
854 {
Rushabh Mehta37146262017-02-01 18:17:35 +0530855 "label": __("City"),
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530856 "fieldname": "city",
857 "fieldtype": "Data"
858 },
859 {
Rushabh Mehta37146262017-02-01 18:17:35 +0530860 "label": __("State"),
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530861 "fieldname": "state",
862 "fieldtype": "Data"
863 },
864 {
Rushabh Mehta37146262017-02-01 18:17:35 +0530865 "label": __("ZIP Code"),
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530866 "fieldname": "pincode",
867 "fieldtype": "Data"
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530868 }
869 ]
Rohit Waghchaurefe7a5b32016-12-27 14:15:52 +0530870 })
Rushabh Mehta37146262017-02-01 18:17:35 +0530871
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530872 this.customer_doc.show()
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530873 this.render_address_data()
Rushabh Mehta37146262017-02-01 18:17:35 +0530874
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530875 this.customer_doc.set_primary_action(__("Save"), function () {
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530876 me.make_offline_customer(new_customer);
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530877 me.pos_bill.show();
Rohit Waghchaurefd375162017-05-02 18:27:09 +0530878 me.list_customers.hide();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530879 });
880 },
Rushabh Mehta37146262017-02-01 18:17:35 +0530881
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530882 render_address_data: function() {
883 var me = this;
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530884 this.address_data = this.address[this.frm.doc.customer];
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530885 this.customer_doc.set_values(this.address_data)
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530886
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530887 if(!this.customer_doc.fields_dict.full_name.$input.val()) {
888 this.customer_doc.set_value("full_name", this.frm.doc.customer)
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530889 }
890 },
891
892 get_address_from_localstorage: function() {
893 this.address_details = this.get_customers_details()
894 return this.address_details[this.frm.doc.customer]
895 },
896
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530897 make_offline_customer: function(new_customer) {
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530898 this.frm.doc.customer = this.frm.doc.customer || this.customer_doc.get_values().full_name;
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530899 this.customer_details = this.get_customers_details();
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530900 this.customer_details[this.frm.doc.customer] = this.get_prompt_details();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530901 this.party_field.$input.val(this.frm.doc.customer);
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530902 this.update_address_and_customer_list(new_customer)
903 this.autocomplete_customers();
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530904 this.update_customer_in_localstorage()
905 this.update_customer_in_localstorage()
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530906 this.customer_doc.hide()
Rohit Waghchaurefe7a5b32016-12-27 14:15:52 +0530907 },
908
Rohit Waghchaureb719dc52017-03-23 17:04:00 +0530909 update_address_and_customer_list: function(new_customer) {
910 var me = this;
911 if(new_customer) {
912 this.customers_mapper.push({
913 label: this.frm.doc.customer,
914 value: this.frm.doc.customer,
915 customer_group: "",
916 territory: ""
917 });
918 }
919
920 this.address[this.frm.doc.customer] = this.customer_doc.get_values();
921 },
922
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530923 get_prompt_details: function() {
924 this.prompt_details = this.customer_doc.get_values();
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +0530925 this.prompt_details['country'] = this.pos_profile_data.country;
Rohit Waghchaure1312fe32017-03-07 14:01:04 +0530926 return JSON.stringify(this.prompt_details)
927 },
928
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530929 update_customer_data: function (doc) {
Rohit Waghchaurefe7a5b32016-12-27 14:15:52 +0530930 var me = this;
931 this.frm.doc.customer = doc.label || doc.name;
932 this.frm.doc.customer_name = doc.customer_name;
933 this.frm.doc.customer_group = doc.customer_group;
934 this.frm.doc.territory = doc.territory;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530935 this.pos_bill.show();
Rohit Waghchauree30f83a2017-02-24 18:02:50 +0530936 this.numeric_keypad.show();
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530937 },
938
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530939 get_customers: function (key) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530940 var me = this;
Rohit Waghchauref2aa1762016-05-20 23:55:45 +0530941 key = key.toLowerCase().trim()
Rohit Waghchaure163e3592016-10-05 13:38:02 +0530942 var re = new RegExp('%', 'g');
943 var reg = new RegExp(key.replace(re, '\\w*\\s*[a-zA-Z0-9]*'))
944
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530945 if (key) {
946 return $.grep(this.customers, function (data) {
947 if (reg.test(data.name.toLowerCase())
Rohit Waghchaure163e3592016-10-05 13:38:02 +0530948 || reg.test(data.customer_name.toLowerCase())
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530949 || (data.customer_group && reg.test(data.customer_group.toLowerCase()))) {
Rohit Waghchauref2aa1762016-05-20 23:55:45 +0530950 return data
951 }
952 })
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530953 } else {
954 customers = this.customers.sort(function (a, b) { return a.idx < b.idx })
Rohit Waghchauref2aa1762016-05-20 23:55:45 +0530955 return customers.slice(0, 20)
956 }
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530957 },
958
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530959 make_item_list: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530960 var me = this;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530961 if (!this.price_list) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530962 msgprint(__("Price List not found or disabled"));
963 return;
964 }
965
966 me.item_timeout = null;
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +0530967
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530968 var $wrap = me.wrapper.find(".item-list");
969 me.wrapper.find(".item-list").empty();
970
Rohit Waghchaure801029e2016-11-17 00:14:21 +0530971 if (this.items.length > 0) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530972 $.each(this.items, function(index, obj) {
Faris Ansari1f261a82017-03-06 18:01:58 +0530973 if(index < me.page_len) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530974 $(frappe.render_template("pos_item", {
975 item_code: obj.name,
Rohit Waghchaurea27c4172016-11-20 23:41:13 +0530976 item_price: format_currency(me.price_list_data[obj.name], me.frm.doc.currency),
rohitwaghchaurec13dbd42017-02-01 18:07:22 +0530977 item_name: obj.name === obj.item_name ? "" : obj.item_name,
Faris Ansari1f261a82017-03-06 18:01:58 +0530978 item_image: obj.image,
Faris Ansari185762a2017-04-13 12:36:08 +0530979 item_stock: __('Stock Qty') + ": " + me.get_actual_qty(obj),
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530980 color: frappe.get_palette(obj.item_name),
981 abbr: frappe.get_abbr(obj.item_name)
982 })).tooltip().appendTo($wrap);
983 }
984 });
Charles-Henri Decultot8bec0232017-05-19 12:32:30 +0200985
Faris Ansari45510102017-03-09 14:43:37 +0530986 $wrap.append(`
987 <div class="image-view-item btn-more text-muted text-center">
988 <div class="image-view-body">
989 <i class="mega-octicon octicon-package"></i>
990 <div>Load more items</div>
991 </div>
992 </div>
993 `);
994
995 me.toggle_more_btn();
Rohit Waghchaure801029e2016-11-17 00:14:21 +0530996 } else {
Rushabh Mehta37146262017-02-01 18:17:35 +0530997 $("<p class='text-muted small' style='padding-left: 10px'>"
998 +__("Not items found")+"</p>").appendTo($wrap)
Rohit Waghchaure6087fe12016-04-09 14:31:09 +0530999 }
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301000
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301001 if (this.items.length == 1
1002 && this.serach_item.$input.val()) {
1003 this.serach_item.$input.val("");
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301004 this.add_to_cart();
1005 }
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301006 },
1007
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301008 get_items: function (item_code) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301009 // To search item as per the key enter
1010
1011 var me = this;
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301012 this.item_serial_no = {};
1013 this.item_batch_no = {};
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301014
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301015 if (item_code) {
1016 return $.grep(this.item_data, function (item) {
1017 if (item.item_code == item_code) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301018 return true
1019 }
1020 })
1021 }
Rushabh Mehta37146262017-02-01 18:17:35 +05301022
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301023 this.items_list = this.apply_category();
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301024
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301025 key = this.serach_item.$input.val().toLowerCase().replace(/[&\/\\#,+()\[\]$~.'":*?<>{}]/g, '\\$&');
Rohit Waghchaure163e3592016-10-05 13:38:02 +05301026 var re = new RegExp('%', 'g');
Rohit Waghchaure6f33dfb2016-10-09 15:32:56 +05301027 var reg = new RegExp(key.replace(re, '[\\w*\\s*[a-zA-Z0-9]*]*'))
Rohit Waghchaureea5a32d2016-08-10 17:18:52 +05301028 search_status = true
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301029
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301030 if (key) {
1031 return $.grep(this.items_list, function (item) {
1032 if (search_status) {
1033 if (in_list(me.batch_no_data[item.item_code], me.serach_item.$input.val())) {
Rohit Waghchaureea5a32d2016-08-10 17:18:52 +05301034 search_status = false;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301035 return me.item_batch_no[item.item_code] = me.serach_item.$input.val()
1036 } else if (me.serial_no_data[item.item_code]
1037 && in_list(Object.keys(me.serial_no_data[item.item_code]), me.serach_item.$input.val())) {
Rohit Waghchaureea5a32d2016-08-10 17:18:52 +05301038 search_status = false;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301039 me.item_serial_no[item.item_code] = [me.serach_item.$input.val(), me.serial_no_data[item.item_code][me.serach_item.$input.val()]]
Rohit Waghchaureea5a32d2016-08-10 17:18:52 +05301040 return true
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301041 } else if (item.barcode == me.serach_item.$input.val()) {
Rohit Waghchaureea5a32d2016-08-10 17:18:52 +05301042 search_status = false;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301043 return item.barcode == me.serach_item.$input.val();
1044 } else if (reg.test(item.item_code.toLowerCase()) || reg.test(item.description.toLowerCase()) ||
1045 reg.test(item.item_name.toLowerCase()) || reg.test(item.item_group.toLowerCase())) {
Rohit Waghchaureea5a32d2016-08-10 17:18:52 +05301046 return true
1047 }
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301048 }
1049 })
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301050 } else {
1051 return this.items_list;
1052 }
1053 },
Rushabh Mehta37146262017-02-01 18:17:35 +05301054
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301055 apply_category: function() {
1056 var me = this;
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301057 category = this.selected_item_group || "All Item Groups";
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301058
1059 if(category == 'All Item Groups') {
1060 return this.item_data
1061 } else {
1062 return this.item_data.filter(function(element, index, array){
1063 return element.item_group == category;
1064 });
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301065 }
1066 },
Charles-Henri Decultot8bec0232017-05-19 12:32:30 +02001067
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +05301068 bind_items_event: function() {
1069 var me = this;
Faris Ansari1f261a82017-03-06 18:01:58 +05301070 $(this.wrapper).on('click', '.pos-bill-item', function() {
1071 $(me.wrapper).find('.pos-bill-item').removeClass('active');
1072 $(this).addClass('active');
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +05301073 me.numeric_val = "";
1074 me.numeric_id = ""
1075 me.item_code = $(this).attr("data-item-code");
1076 me.render_selected_item()
1077 me.bind_qty_event()
1078 me.update_rate()
1079 $(me.wrapper).find(".selected-item").scrollTop(1000);
1080 })
1081 },
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301082
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301083 bind_qty_event: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301084 var me = this;
Rohit Waghchaure75177c02017-03-16 15:21:21 +05301085
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +05301086 $(this.wrapper).on("change", ".pos-item-qty", function () {
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301087 var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code");
Rohit Waghchauredd58d532016-12-21 17:23:01 +05301088 var qty = $(this).val();
1089 me.update_qty(item_code, qty)
Rohit Waghchaure75177c02017-03-16 15:21:21 +05301090 me.update_value()
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301091 })
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301092
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301093 $(this.wrapper).find("[data-action='increase-qty']").on("click", function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301094 var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
1095 var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) + 1;
Rohit Waghchauredd58d532016-12-21 17:23:01 +05301096 me.update_qty(item_code, qty)
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301097 })
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301098
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301099 $(this.wrapper).find("[data-action='decrease-qty']").on("click", function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301100 var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
1101 var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) - 1;
Rohit Waghchauredd58d532016-12-21 17:23:01 +05301102 me.update_qty(item_code, qty)
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301103 })
Charles-Henri Decultot8bec0232017-05-19 12:32:30 +02001104
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +05301105 $(this.wrapper).on("change", ".pos-item-disc", function () {
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301106 var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code");
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301107 var discount = $(this).val();
1108 me.update_discount(item_code, discount)
Rohit Waghchaure75177c02017-03-16 15:21:21 +05301109 me.update_value()
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05301110 })
1111 },
1112
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301113 bind_events: function() {
1114 var me = this;
1115 // if form is local then allow this function
1116 // $(me.wrapper).find(".pos-item-wrapper").on("click", function () {
1117 $(this.wrapper).on("click", ".pos-item-wrapper", function () {
Rohit Waghchaurea86bb692017-03-30 19:16:38 +05301118 me.item_code = '';
Rohit Waghchaured7de3c62017-04-17 13:36:08 +05301119 me.customer_validate();
Rohit Waghchaureb719dc52017-03-23 17:04:00 +05301120 if($(me.pos_bill).is(":hidden")) return;
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301121
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301122 if (me.frm.doc.docstatus == 0) {
1123 me.items = me.get_items($(this).attr("data-item-code"))
1124 me.add_to_cart();
Rohit Waghchaure75177c02017-03-16 15:21:21 +05301125 me.clear_selected_row();
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301126 }
1127 });
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +05301128
1129 me.bind_delete_event()
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301130 },
1131
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301132 update_qty: function (item_code, qty) {
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05301133 var me = this;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301134 this.items = this.get_items(item_code);
1135 this.validate_serial_no()
1136 this.set_item_details(item_code, "qty", qty);
1137 },
1138
1139 update_discount: function(item_code, discount) {
1140 var me = this;
1141 this.items = this.get_items(item_code);
1142 this.set_item_details(item_code, "discount_percentage", discount);
1143 },
1144
1145 update_rate: function () {
1146 var me = this;
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +05301147 $(this.wrapper).on("change", ".pos-item-price", function () {
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301148 var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code");
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301149 me.set_item_details(item_code, "rate", $(this).val());
Rohit Waghchaure75177c02017-03-16 15:21:21 +05301150 me.update_value()
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301151 })
1152 },
Rohit Waghchaure56a79742017-02-28 16:51:17 +05301153
Rohit Waghchaure75177c02017-03-16 15:21:21 +05301154 update_value: function() {
1155 var me = this;
1156 var fields = {qty: ".pos-item-qty", "discount_percentage": ".pos-item-disc",
1157 "rate": ".pos-item-price", "amount": ".pos-amount"}
1158 this.child_doc = this.get_child_item(this.item_code);
1159
1160 if(me.child_doc.length) {
1161 $.each(fields, function(key, field) {
1162 $(me.selected_row).find(field).val(me.child_doc[0][key])
1163 })
1164 } else {
1165 this.clear_selected_row();
Rohit Waghchaure56a79742017-02-28 16:51:17 +05301166 }
1167 },
Rohit Waghchaure75177c02017-03-16 15:21:21 +05301168
1169 clear_selected_row: function() {
1170 $(this.wrapper).find('.selected-item').empty();
1171 },
1172
1173 render_selected_item: function() {
1174 this.child_doc = this.get_child_item(this.item_code);
1175 $(this.wrapper).find('.selected-item').empty();
1176 if(this.child_doc.length) {
1177 this.selected_row = $(frappe.render_template("pos_selected_item", this.child_doc[0]))
1178 $(this.wrapper).find('.selected-item').html(this.selected_row)
1179 }
1180
1181 $(this.selected_row).find('.form-control').click(function(){
1182 $(this).select();
1183 })
1184 },
1185
Rohit Waghchaure86ab6a92017-02-24 18:02:50 +05301186 get_child_item: function(item_code) {
1187 var me = this;
1188 return $.map(me.frm.doc.items, function(doc){
1189 if(doc.item_code == item_code) {
1190 return doc
1191 }
1192 })
1193 },
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +05301194
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301195 set_item_details: function (item_code, field, value) {
1196 var me = this;
1197 if (value < 0) {
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05301198 frappe.throw(__("Enter value must be positive"));
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301199 }
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301200
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301201 this.remove_item = []
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301202 $.each(this.frm.doc["items"] || [], function (i, d) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301203 if (d.item_code == item_code) {
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301204 if (d.serial_no && field == 'qty') {
1205 me.validate_serial_no_qty(d, item_code, field, value)
1206 }
1207
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05301208 d[field] = flt(value);
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301209 d.amount = flt(d.rate) * flt(d.qty);
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301210 if (d.qty == 0) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301211 me.remove_item.push(d.idx)
1212 }
Rohit Waghchaure75177c02017-03-16 15:21:21 +05301213
1214 if(field=="discount_percentage" && value == 0) {
1215 d.rate = d.price_list_rate;
1216 }
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301217 }
1218 });
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05301219
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301220 if (field == 'qty') {
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05301221 this.remove_zero_qty_item();
1222 }
1223
Rohit Waghchaure713e2b72016-08-19 15:11:36 +05301224 this.update_paid_amount_status(false)
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301225 },
1226
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301227 remove_zero_qty_item: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301228 var me = this;
1229 idx = 0
1230 this.items = []
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301231 $.each(this.frm.doc["items"] || [], function (i, d) {
1232 if (!in_list(me.remove_item, d.idx)) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301233 d.idx = idx;
1234 me.items.push(d);
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301235 idx++;
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301236 }
1237 });
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301238
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301239 this.frm.doc["items"] = this.items;
1240 },
1241
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301242 make_discount_field: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301243 var me = this;
1244
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301245 this.wrapper.find('input.discount-percentage').on("change", function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301246 me.frm.doc.additional_discount_percentage = flt($(this).val(), precision("additional_discount_percentage"));
1247 total = me.frm.doc.grand_total
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301248
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301249 if (me.frm.doc.apply_discount_on == 'Net Total') {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301250 total = me.frm.doc.net_total
1251 }
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301252
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301253 me.frm.doc.discount_amount = flt(total * flt(me.frm.doc.additional_discount_percentage) / 100, precision("discount_amount"));
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301254 me.wrapper.find('input.discount-amount').val(me.frm.doc.discount_amount)
1255 me.refresh();
1256 });
1257
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301258 this.wrapper.find('input.discount-amount').on("change", function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301259 me.frm.doc.discount_amount = flt($(this).val(), precision("discount_amount"));
1260 me.frm.doc.additional_discount_percentage = 0.0;
1261 me.wrapper.find('input.discount-percentage').val(0);
1262 me.refresh();
1263 });
1264 },
1265
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301266 customer_validate: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301267 var me = this;
Rohit Waghchaureb719dc52017-03-23 17:04:00 +05301268 if (!this.frm.doc.customer || this.party_field.get_value() == "") {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301269 frappe.throw(__("Please select customer"))
1270 }
1271 },
1272
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301273 add_to_cart: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301274 var me = this;
1275 var caught = false;
1276 var no_of_items = me.wrapper.find(".pos-bill-item").length;
1277
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301278 this.customer_validate();
1279 this.mandatory_batch_no();
1280 this.validate_serial_no();
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301281 this.validate_warehouse();
1282
1283 if (no_of_items != 0) {
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301284 $.each(this.frm.doc["items"] || [], function (i, d) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301285 if (d.item_code == me.items[0].item_code) {
1286 caught = true;
1287 d.qty += 1;
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301288 d.amount = flt(d.rate) * flt(d.qty);
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301289 if (me.item_serial_no[d.item_code]) {
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301290 d.serial_no += '\n' + me.item_serial_no[d.item_code][0]
1291 d.warehouse = me.item_serial_no[d.item_code][1]
1292 }
1293
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301294 if (me.item_batch_no.length) {
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301295 d.batch_no = me.item_batch_no[d.item_code]
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301296 }
1297 }
1298 });
1299 }
1300
1301 // if item not found then add new item
1302 if (!caught)
1303 this.add_new_item_to_grid();
1304
Rohit Waghchaure713e2b72016-08-19 15:11:36 +05301305 this.update_paid_amount_status(false)
Faris Ansari45510102017-03-09 14:43:37 +05301306 this.wrapper.find(".item-cart-items").scrollTop(1000);
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301307 },
1308
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301309 add_new_item_to_grid: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301310 var me = this;
1311 this.child = frappe.model.add_child(this.frm.doc, this.frm.doc.doctype + " Item", "items");
1312 this.child.item_code = this.items[0].item_code;
1313 this.child.item_name = this.items[0].item_name;
1314 this.child.stock_uom = this.items[0].stock_uom;
Rohit Waghchaure75177c02017-03-16 15:21:21 +05301315 this.child.brand = this.items[0].brand;
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301316 this.child.description = this.items[0].description;
Rohit Waghchauree30f83a2017-02-24 18:02:50 +05301317 this.child.discount_percentage = 0.0;
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301318 this.child.qty = 1;
1319 this.child.item_group = this.items[0].item_group;
Rohit Waghchaurea27c4172016-11-20 23:41:13 +05301320 this.child.cost_center = this.pos_profile_data['cost_center'] || this.items[0].cost_center;
1321 this.child.income_account = this.pos_profile_data['income_account'] || this.items[0].income_account;
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301322 this.child.warehouse = (this.item_serial_no[this.child.item_code]
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301323 ? this.item_serial_no[this.child.item_code][1] : (this.pos_profile_data['warehouse'] || this.items[0].default_warehouse));
Rohit Waghchaurea27c4172016-11-20 23:41:13 +05301324 this.child.price_list_rate = flt(this.price_list_data[this.child.item_code], 9) / flt(this.frm.doc.conversion_rate, 9);
1325 this.child.rate = flt(this.price_list_data[this.child.item_code], 9) / flt(this.frm.doc.conversion_rate, 9);
1326 this.child.actual_qty = me.get_actual_qty(this.items[0]);
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301327 this.child.amount = flt(this.child.qty) * flt(this.child.rate);
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301328 this.child.batch_no = this.item_batch_no[this.child.item_code];
1329 this.child.serial_no = (this.item_serial_no[this.child.item_code]
1330 ? this.item_serial_no[this.child.item_code][0] : '');
Rohit Waghchaurea27c4172016-11-20 23:41:13 +05301331 this.child.item_tax_rate = JSON.stringify(this.tax_data[this.child.item_code]);
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301332 },
1333
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301334 update_paid_amount_status: function (update_paid_amount) {
1335 if (this.name) {
Rohit Waghchaure713e2b72016-08-19 15:11:36 +05301336 update_paid_amount = update_paid_amount ? false : true;
1337 }
1338
1339 this.refresh(update_paid_amount);
1340 },
1341
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301342 refresh: function (update_paid_amount) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301343 var me = this;
Rohit Waghchaureea278b52016-07-21 23:28:04 +05301344 this.refresh_fields(update_paid_amount);
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301345 this.set_primary_action();
1346 },
Rohit Waghchaure713e2b72016-08-19 15:11:36 +05301347
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301348 refresh_fields: function (update_paid_amount) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301349 this.apply_pricing_rule();
1350 this.discount_amount_applied = false;
1351 this._calculate_taxes_and_totals();
1352 this.calculate_discount_amount();
1353 this.show_items_in_item_cart();
1354 this.set_taxes();
Rohit Waghchaureea278b52016-07-21 23:28:04 +05301355 this.calculate_outstanding_amount(update_paid_amount);
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301356 this.set_totals();
1357 },
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301358
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301359 get_company_currency: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301360 return erpnext.get_currency(this.frm.doc.company);
1361 },
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301362
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301363 show_item_wise_taxes: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301364 return null;
1365 },
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301366
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301367 show_items_in_item_cart: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301368 var me = this;
1369 var $items = this.wrapper.find(".items").empty();
Faris Ansari1f261a82017-03-06 18:01:58 +05301370 var $no_items_message = this.wrapper.find(".no-items-message");
1371 $no_items_message.toggle(this.frm.doc.items.length === 0);
1372
1373 var $totals_area = this.wrapper.find('.totals-area');
1374 $totals_area.toggle(this.frm.doc.items.length > 0);
1375
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301376 $.each(this.frm.doc.items || [], function (i, d) {
Faris Ansari1f261a82017-03-06 18:01:58 +05301377 $(frappe.render_template("pos_bill_item_new", {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301378 item_code: d.item_code,
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301379 item_name: (d.item_name === d.item_code || !d.item_name) ? "" : ("<br>" + d.item_name),
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301380 qty: d.qty,
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301381 discount_percentage: d.discount_percentage || 0.0,
1382 actual_qty: me.actual_qty_dict[d.item_code] || 0.0,
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301383 projected_qty: d.projected_qty,
mbauskar22cedeb2017-04-17 12:24:11 +05301384 rate: format_currency(d.rate, me.frm.doc.currency),
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301385 enabled: me.pos_profile_data["allow_user_to_edit_rate"] ? true : false,
Rohit Waghchaure6ee91ec2017-03-21 15:55:09 +05301386 amount: format_currency(d.amount, me.frm.doc.currency),
1387 selected_class: (me.item_code == d.item_code) ? "active" : ""
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301388 })).appendTo($items);
1389 });
1390
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301391 this.wrapper.find("input.pos-item-qty").on("focus", function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301392 $(this).select();
1393 });
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05301394
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +05301395 this.wrapper.find("input.pos-item-disc").on("focus", function () {
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301396 $(this).select();
1397 });
1398
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +05301399 this.wrapper.find("input.pos-item-price").on("focus", function () {
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05301400 $(this).select();
1401 });
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301402 },
1403
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301404 set_taxes: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301405 var me = this;
1406 me.frm.doc.total_taxes_and_charges = 0.0
1407
1408 var taxes = this.frm.doc.taxes || [];
1409 $(this.wrapper)
1410 .find(".tax-area").toggleClass("hide", (taxes && taxes.length) ? false : true)
1411 .find(".tax-table").empty();
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301412
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301413 $.each(taxes, function (i, d) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301414 if (d.tax_amount && cint(d.included_in_print_rate) == 0) {
1415 $(frappe.render_template("pos_tax_row", {
1416 description: d.description,
1417 tax_amount: format_currency(flt(d.tax_amount_after_discount_amount),
1418 me.frm.doc.currency)
1419 })).appendTo(me.wrapper.find(".tax-table"));
1420 }
1421 });
1422 },
1423
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301424 set_totals: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301425 var me = this;
1426 this.wrapper.find(".net-total").text(format_currency(me.frm.doc.total, me.frm.doc.currency));
1427 this.wrapper.find(".grand-total").text(format_currency(me.frm.doc.grand_total, me.frm.doc.currency));
1428 },
1429
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301430 set_primary_action: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301431 var me = this;
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +05301432 this.page.set_primary_action(__("New Cart"), function () {
1433 me.make_new_cart()
Rohit Waghchaure75177c02017-03-16 15:21:21 +05301434 me.make_menu_list()
Faris Ansari45510102017-03-09 14:43:37 +05301435 }, "fa fa-plus")
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +05301436
1437 if (this.frm.doc.docstatus == 1) {
Rohit Waghchaure6068aec2017-03-10 11:40:28 +05301438 this.page.set_secondary_action(__("Print"), function () {
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +05301439 html = frappe.render(me.print_template_data, me.frm.doc)
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05301440 me.print_document(html)
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301441 })
Rohit Waghchaure75177c02017-03-16 15:21:21 +05301442 this.page.add_menu_item(__("Email"), function () {
1443 me.email_prompt()
1444 })
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301445 }
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +05301446 },
Rohit Waghchaure9fe40d52016-06-13 21:37:10 +05301447
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +05301448 make_new_cart: function (){
Rohit Waghchaurea86bb692017-03-30 19:16:38 +05301449 this.item_code = '';
Rohit Waghchaure75177c02017-03-16 15:21:21 +05301450 this.page.clear_secondary_action();
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +05301451 this.save_previous_entry();
1452 this.create_new();
1453 this.refresh();
1454 this.toggle_input_field();
1455 this.render_list_customers();
1456 this.set_focus();
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301457 },
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301458
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301459 print_dialog: function () {
Rohit Waghchaure60a05322016-09-12 01:37:46 +05301460 var me = this;
1461
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +05301462 this.msgprint = frappe.msgprint(format('<a class="btn btn-primary print_doc" \
Rohit Waghchaure60a05322016-09-12 01:37:46 +05301463 style="margin-right: 5px;">{0}</a>\
1464 <a class="btn btn-default new_doc">{1}</a>', [
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301465 __('Print'), __('New')
1466 ]));
Rohit Waghchaure60a05322016-09-12 01:37:46 +05301467
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301468 $('.print_doc').click(function () {
Rohit Waghchaure9f2cc382016-12-09 11:46:08 +05301469 html = frappe.render(me.print_template_data, me.frm.doc)
Rohit Waghchaure60a05322016-09-12 01:37:46 +05301470 me.print_document(html)
1471 })
1472
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301473 $('.new_doc').click(function () {
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +05301474 me.msgprint.hide()
1475 me.make_new_cart()
Rohit Waghchaure60a05322016-09-12 01:37:46 +05301476 })
1477 },
1478
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301479 print_document: function (html) {
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05301480 var w = window.open();
1481 w.document.write(html);
1482 w.document.close();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301483 setTimeout(function () {
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05301484 w.print();
1485 w.close();
1486 }, 1000)
1487 },
1488
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301489 submit_invoice: function () {
Rohit Waghchauree0934d12016-05-11 15:04:57 +05301490 var me = this;
Rohit Waghchaure60a05322016-09-12 01:37:46 +05301491 this.change_status();
Rohit Waghchauree259a9b2017-03-14 19:03:49 +05301492 this.update_serial_no()
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301493 if (this.frm.doc.docstatus == 1) {
Rohit Waghchaure60a05322016-09-12 01:37:46 +05301494 this.print_dialog()
1495 }
Rohit Waghchauree0934d12016-05-11 15:04:57 +05301496 },
1497
Rohit Waghchauree259a9b2017-03-14 19:03:49 +05301498 update_serial_no: function() {
1499 var me = this;
1500
1501 //Remove the sold serial no from the cache
1502 $.each(this.frm.doc.items, function(index, data) {
1503 sn = data.serial_no.split('\n')
1504 if(sn.length) {
1505 serial_no_list = me.serial_no_data[data.item_code]
Rohit Waghchaureb719dc52017-03-23 17:04:00 +05301506 if(serial_no_list) {
1507 $.each(sn, function(i, serial_no) {
1508 if(in_list(Object.keys(serial_no_list), serial_no)) {
1509 delete serial_no_list[serial_no]
1510 }
1511 })
1512 me.serial_no_data[data.item_code] = serial_no_list;
1513 }
Rohit Waghchauree259a9b2017-03-14 19:03:49 +05301514 }
1515 })
1516 },
1517
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301518 change_status: function () {
1519 if (this.frm.doc.docstatus == 0) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301520 this.frm.doc.docstatus = 1;
1521 this.update_invoice();
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301522 this.toggle_input_field();
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301523 }
1524 },
1525
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301526 toggle_input_field: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301527 var pointer_events = 'inherit'
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301528 disabled = this.frm.doc.docstatus == 1 ? true: false;
1529 $(this.wrapper).find('input').attr("disabled", disabled);
1530 $(this.wrapper).find('select').attr("disabled", disabled);
1531 $(this.wrapper).find('input').attr("disabled", disabled);
1532 $(this.wrapper).find('select').attr("disabled", disabled);
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +05301533 $(this.wrapper).find('button').attr("disabled", disabled);
1534 this.party_field.$input.attr('disabled', disabled);
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301535
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301536 if (this.frm.doc.docstatus == 1) {
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301537 pointer_events = 'none';
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301538 }
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301539
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301540 $(this.wrapper).find('.pos-bill').css('pointer-events', pointer_events);
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301541 $(this.wrapper).find('.pos-items-section').css('pointer-events', pointer_events);
1542 this.set_primary_action();
1543 },
1544
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301545 create_invoice: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301546 var me = this;
1547 var invoice_data = {}
1548 this.si_docs = this.get_doc_from_localstorage();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301549 if (this.name) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301550 this.update_invoice()
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301551 } else {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301552 this.name = $.now();
Rohit Waghchaure377c7ac2016-09-05 17:56:44 +05301553 this.frm.doc.offline_pos_name = this.name;
Rohit Waghchaure9cd356c2016-08-11 16:54:30 +05301554 this.frm.doc.posting_date = frappe.datetime.get_today();
1555 this.frm.doc.posting_time = frappe.datetime.now_time();
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301556 invoice_data[this.name] = this.frm.doc
1557 this.si_docs.push(invoice_data)
1558 this.update_localstorage();
1559 this.set_primary_action();
1560 }
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301561 return invoice_data;
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301562 },
1563
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301564 update_invoice: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301565 var me = this;
1566 this.si_docs = this.get_doc_from_localstorage();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301567 $.each(this.si_docs, function (index, data) {
1568 for (key in data) {
1569 if (key == me.name) {
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301570 me.si_docs[index][key] = me.frm.doc;
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301571 me.update_localstorage();
1572 }
1573 }
1574 })
1575 },
1576
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301577 update_localstorage: function () {
1578 try {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301579 localStorage.setItem('sales_invoice_doc', JSON.stringify(this.si_docs));
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301580 } catch (e) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301581 frappe.throw(__("LocalStorage is full , did not save"))
1582 }
1583 },
1584
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301585 get_doc_from_localstorage: function () {
1586 try {
Rohit Waghchauree0934d12016-05-11 15:04:57 +05301587 return JSON.parse(localStorage.getItem('sales_invoice_doc')) || [];
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301588 } catch (e) {
Rohit Waghchauree0934d12016-05-11 15:04:57 +05301589 return []
1590 }
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301591 },
1592
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301593 set_interval_for_si_sync: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301594 var me = this;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301595 setInterval(function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301596 me.sync_sales_invoice()
Rohit Waghchauree0934d12016-05-11 15:04:57 +05301597 }, 60000)
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301598 },
1599
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301600 sync_sales_invoice: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301601 var me = this;
Rohit Waghchaureb5097ec2017-03-01 01:13:09 +05301602 this.si_docs = this.get_submitted_invoice() || [];
1603 this.email_queue_list = this.get_email_queue() || {};
Rohit Waghchaure1312fe32017-03-07 14:01:04 +05301604 this.customers_list = this.get_customers_details() || {};
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301605
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +05301606 if (this.si_docs.length || this.email_queue_list || this.customers_list) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301607 frappe.call({
1608 method: "erpnext.accounts.doctype.sales_invoice.pos.make_invoice",
1609 args: {
Rohit Waghchaureb5097ec2017-03-01 01:13:09 +05301610 doc_list: me.si_docs,
Rohit Waghchaure1312fe32017-03-07 14:01:04 +05301611 email_queue_list: me.email_queue_list,
1612 customers_list: me.customers_list
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301613 },
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301614 callback: function (r) {
1615 if (r.message) {
Rohit Waghchaureb5097ec2017-03-01 01:13:09 +05301616 me.removed_items = r.message.invoice;
1617 me.removed_email = r.message.email_queue
Rohit Waghchaure1312fe32017-03-07 14:01:04 +05301618 me.removed_customers = r.message.customers
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301619 me.remove_doc_from_localstorage();
Rohit Waghchaureb5097ec2017-03-01 01:13:09 +05301620 me.remove_email_queue_from_localstorage();
Rohit Waghchaure1312fe32017-03-07 14:01:04 +05301621 me.remove_customer_from_localstorage();
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301622 }
1623 }
1624 })
1625 }
1626 },
1627
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301628 get_submitted_invoice: function () {
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05301629 var invoices = [];
1630 var index = 1;
1631 docs = this.get_doc_from_localstorage();
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301632 if (docs) {
1633 invoices = $.map(docs, function (data) {
1634 for (key in data) {
1635 if (data[key].docstatus == 1 && index < 50) {
Rohit Waghchauref2aa1762016-05-20 23:55:45 +05301636 index++
Rohit Waghchaureb77a1052016-08-01 18:35:18 +05301637 data[key].docstatus = 0;
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301638 return data
1639 }
1640 }
1641 });
1642 }
1643
1644 return invoices
1645 },
1646
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301647 remove_doc_from_localstorage: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301648 var me = this;
1649 this.si_docs = this.get_doc_from_localstorage();
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301650 this.new_si_docs = [];
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301651 if (this.removed_items) {
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301652 $.each(this.si_docs, function (index, data) {
1653 for (key in data) {
Rohit Waghchaure017f5002017-03-08 17:34:39 +05301654 if (!in_list(me.removed_items, key)) {
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301655 me.new_si_docs.push(data);
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301656 }
1657 }
1658 })
Rohit Waghchaure87fa59a2017-03-10 14:56:19 +05301659 this.removed_items = [];
Rohit Waghchauree0934d12016-05-11 15:04:57 +05301660 this.si_docs = this.new_si_docs;
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301661 this.update_localstorage();
1662 }
1663 },
1664
Rohit Waghchaureb5097ec2017-03-01 01:13:09 +05301665 remove_email_queue_from_localstorage: function() {
1666 var me = this;
1667 this.email_queue = this.get_email_queue()
1668 if (this.removed_email) {
1669 $.each(this.email_queue_list, function (index, data) {
1670 if (in_list(me.removed_email, index)) {
1671 delete me.email_queue[index]
1672 }
1673 })
1674 this.update_email_queue();
1675 }
1676 },
1677
Rohit Waghchaure1312fe32017-03-07 14:01:04 +05301678 remove_customer_from_localstorage: function() {
1679 var me = this;
1680 this.customer_details = this.get_customers_details()
1681 if (this.removed_customers) {
1682 $.each(this.customers_list, function (index, data) {
1683 if (in_list(me.removed_customers, index)) {
1684 delete me.customer_details[index]
1685 }
1686 })
1687 this.update_customer_in_localstorage();
1688 }
1689 },
1690
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301691 validate: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301692 var me = this;
1693 this.customer_validate();
1694 this.item_validate();
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301695 this.validate_mode_of_payments();
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301696 },
1697
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301698 item_validate: function () {
1699 if (this.frm.doc.items.length == 0) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301700 frappe.throw(__("Select items to save the invoice"))
1701 }
1702 },
Rushabh Mehta512b85e2016-12-27 12:14:26 +05301703
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301704 validate_mode_of_payments: function () {
1705 if (this.frm.doc.payments.length === 0) {
Saurabh9a6c6662016-06-27 16:51:44 +05301706 frappe.throw(__("Payment Mode is not configured. Please check, whether account has been set on Mode of Payments or on POS Profile."))
1707 }
1708 },
Rushabh Mehta512b85e2016-12-27 12:14:26 +05301709
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301710 validate_serial_no: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301711 var me = this;
1712 var item_code = serial_no = '';
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301713 for (key in this.item_serial_no) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301714 item_code = key;
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301715 serial_no = me.item_serial_no[key][0];
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301716 }
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301717
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301718 if (this.items[0].has_serial_no && serial_no == "") {
Rohit Waghchauredd58d532016-12-21 17:23:01 +05301719 this.refresh();
1720 frappe.throw(__(repl("Error: Serial no is mandatory for item %(item)s", {
1721 'item': this.items[0].item_code
1722 })))
1723 }
1724
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301725 if (item_code && serial_no) {
1726 $.each(this.frm.doc.items, function (index, data) {
1727 if (data.item_code == item_code) {
1728 if (in_list(data.serial_no.split('\n'), serial_no)) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301729 frappe.throw(__(repl("Serial no %(serial_no)s is already taken", {
1730 'serial_no': serial_no
1731 })))
1732 }
1733 }
1734 })
1735 }
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301736 },
1737
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301738 validate_serial_no_qty: function (args, item_code, field, value) {
Rohit Waghchauree4e69ec2016-08-17 16:20:13 +05301739 var me = this;
1740 if (args.item_code == item_code && args.serial_no
1741 && field == 'qty' && cint(value) != value) {
1742 args.qty = 0.0;
1743 this.refresh();
1744 frappe.throw(__("Serial no item cannot be a fraction"))
1745 }
1746
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301747 if (args.item_code == item_code && args.serial_no && args.serial_no.split('\n').length != cint(value)) {
Rohit Waghchauree4e69ec2016-08-17 16:20:13 +05301748 args.qty = 0.0;
1749 args.serial_no = ''
1750 this.refresh();
Rohit Waghchauredd58d532016-12-21 17:23:01 +05301751 frappe.throw(__(repl("Total nos of serial no is not equal to quantity for item %(item)s.", {
1752 'item': item_code
1753 })))
Rohit Waghchauree4e69ec2016-08-17 16:20:13 +05301754 }
1755 },
1756
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301757 mandatory_batch_no: function () {
Rohit Waghchaure03da40b2016-07-16 03:02:20 +05301758 var me = this;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301759 if (this.items[0].has_batch_no && !this.item_batch_no[this.items[0].item_code]) {
Charles-Henri Decultot8bec0232017-05-19 12:32:30 +02001760 frappe.prompt([
1761 {'fieldname': 'batch', 'fieldtype': 'Select', 'label': __('Batch No'), 'reqd': 1, 'options':this.batch_no_data[this.items[0].item_code]}
1762 ],
1763 function(values){
1764 me.item_batch_no[me.items[0].item_code] = values.batch;
1765 },
1766 __('Select Batch No'))
1767 }
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301768 },
1769
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301770 apply_pricing_rule: function () {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301771 var me = this;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301772 $.each(this.frm.doc["items"], function (n, item) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301773 pricing_rule = me.get_pricing_rule(item)
1774 me.validate_pricing_rule(pricing_rule)
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301775 if (pricing_rule.length) {
1776 item.pricing_rule = pricing_rule[0].name;
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301777 item.margin_type = pricing_rule[0].margin_type;
1778 item.price_list_rate = pricing_rule[0].price || item.price_list_rate;
1779 item.margin_rate_or_amount = pricing_rule[0].margin_rate_or_amount;
1780 item.discount_percentage = pricing_rule[0].discount_percentage || 0.0;
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +05301781 me.apply_pricing_rule_on_item(item)
1782 } else if (item.pricing_rule) {
1783 item.price_list_rate = me.price_list_data[item.item_code]
Rohit Waghchaure619c40b2016-11-07 15:29:17 +05301784 item.margin_rate_or_amount = 0.0;
1785 item.discount_percentage = 0.0;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301786 item.pricing_rule = null;
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +05301787 me.apply_pricing_rule_on_item(item)
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301788 }
Charles-Henri Decultot8bec0232017-05-19 12:32:30 +02001789
Rohit Waghchauref0c7ba42017-02-28 16:51:17 +05301790 if(item.discount_percentage > 0) {
1791 me.apply_pricing_rule_on_item(item)
1792 }
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301793 })
1794 },
1795
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301796 get_pricing_rule: function (item) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301797 var me = this;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301798 return $.grep(this.pricing_rules, function (data) {
1799 if (item.qty >= data.min_qty && (item.qty <= (data.max_qty ? data.max_qty : item.qty))) {
Rohit Waghchaured7de3c62017-04-17 13:36:08 +05301800 if (me.validate_item_condition(data, item)) {
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301801 if (in_list(['Customer', 'Customer Group', 'Territory', 'Campaign'], data.applicable_for)) {
Rohit Waghchaurebaef2622016-08-05 15:41:36 +05301802 return me.validate_condition(data)
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301803 } else {
Rohit Waghchaurebaef2622016-08-05 15:41:36 +05301804 return true
1805 }
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301806 }
1807 }
1808 })
1809 },
1810
Rohit Waghchaured7de3c62017-04-17 13:36:08 +05301811 validate_item_condition: function (data, item) {
1812 var apply_on = frappe.model.scrub(data.apply_on);
1813
1814 return (data.apply_on == 'Item Group')
1815 ? this.validate_item_group(data.item_group, item.item_group) : (data[apply_on] == item[apply_on]);
1816 },
1817
1818 validate_item_group: function (pr_item_group, cart_item_group) {
1819 //pr_item_group = pricing rule's item group
1820 //cart_item_group = cart item's item group
1821 //this.item_groups has information about item group's lft and rgt
1822 //for example: {'Foods': [12, 19]}
1823
1824 pr_item_group = this.item_groups[pr_item_group]
1825 cart_item_group = this.item_groups[cart_item_group]
1826
1827 return (cart_item_group[0] >= pr_item_group[0] &&
1828 cart_item_group[1] <= pr_item_group[1])
1829 },
1830
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301831 validate_condition: function (data) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301832 //This method check condition based on applicable for
1833 condition = this.get_mapper_for_pricing_rule(data)[data.applicable_for]
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301834 if (in_list(condition[1], condition[0])) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301835 return true
1836 }
1837 },
1838
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301839 get_mapper_for_pricing_rule: function (data) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301840 return {
Rohit Waghchaure89ee3092016-07-08 15:17:04 +05301841 'Customer': [data.customer, [this.frm.doc.customer]],
1842 'Customer Group': [data.customer_group, [this.frm.doc.customer_group, 'All Customer Groups']],
1843 'Territory': [data.territory, [this.frm.doc.territory, 'All Territories']],
Rohit Waghchaurebaef2622016-08-05 15:41:36 +05301844 'Campaign': [data.campaign, [this.frm.doc.campaign]],
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301845 }
1846 },
1847
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301848 validate_pricing_rule: function (pricing_rule) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301849 //This method validate duplicate pricing rule
1850 var pricing_rule_name = '';
1851 var priority = 0;
1852 var pricing_rule_list = [];
1853 var priority_list = []
1854
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301855 if (pricing_rule.length > 1) {
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301856
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301857 $.each(pricing_rule, function (index, data) {
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301858 pricing_rule_name += data.name + ','
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301859 priority_list.push(data.priority)
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301860 if (priority <= data.priority) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301861 priority = data.priority
1862 pricing_rule_list.push(data)
1863 }
1864 })
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301865
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301866 count = 0
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301867 $.each(priority_list, function (index, value) {
1868 if (value == priority) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301869 count++
1870 }
1871 })
1872
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301873 if (priority == 0 || count > 1) {
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301874 frappe.throw(__(repl("Multiple Price Rules exists with same criteria, please resolve conflict by assigning priority. Price Rules: %(pricing_rule)s", {
1875 'pricing_rule': pricing_rule_name
1876 })))
1877 }
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301878
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301879 return pricing_rule_list
1880 }
1881 },
Rushabh Mehtad0cee1b2016-05-20 12:54:44 +05301882
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301883 validate_warehouse: function () {
1884 if (this.items[0].is_stock_item && !this.items[0].default_warehouse && !this.pos_profile_data['warehouse']) {
Neil Trini Lasrado5ddd7ac2016-10-24 15:25:33 +05301885 frappe.throw(__("Default warehouse is required for selected item"))
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301886 }
Rohit Waghchaurea27c4172016-11-20 23:41:13 +05301887 },
1888
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301889 get_actual_qty: function (item) {
Rohit Waghchaurea27c4172016-11-20 23:41:13 +05301890 this.actual_qty = 0.0;
Rohit Waghchaure80f5bb62016-11-27 12:04:12 +05301891
Rohit Waghchaurea27c4172016-11-20 23:41:13 +05301892 var warehouse = this.pos_profile_data['warehouse'] || item.default_warehouse;
rohitwaghchaurec13dbd42017-02-01 18:07:22 +05301893 if (warehouse && this.bin_data[item.item_code]) {
Rohit Waghchaurea27c4172016-11-20 23:41:13 +05301894 this.actual_qty = this.bin_data[item.item_code][warehouse] || 0;
Rohit Waghchaure80f5bb62016-11-27 12:04:12 +05301895 this.actual_qty_dict[item.item_code] = this.actual_qty
Rohit Waghchaurea27c4172016-11-20 23:41:13 +05301896 }
1897
1898 return this.actual_qty
Rohit Waghchaure1312fe32017-03-07 14:01:04 +05301899 },
1900
1901 update_customer_in_localstorage: function() {
1902 var me = this;
1903 try {
1904 localStorage.setItem('customer_details', JSON.stringify(this.customer_details));
1905 } catch (e) {
1906 frappe.throw(__("LocalStorage is full , did not save"))
1907 }
Rohit Waghchaure6087fe12016-04-09 14:31:09 +05301908 }
Faris Ansari185762a2017-04-13 12:36:08 +05301909})