Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1 | frappe.provide("erpnext.pos"); |
| 2 | {% include "erpnext/public/js/controllers/taxes_and_totals.js" %} |
| 3 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 4 | frappe.pages['pos'].on_page_load = function (wrapper) { |
Rushabh Mehta | 4c36d73 | 2015-01-01 15:59:34 +0530 | [diff] [blame] | 5 | var page = frappe.ui.make_app_page({ |
Rushabh Mehta | 72e1719 | 2014-08-08 15:30:49 +0530 | [diff] [blame] | 6 | parent: wrapper, |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 7 | title: __('Point of Sale'), |
Rushabh Mehta | 72e1719 | 2014-08-08 15:30:49 +0530 | [diff] [blame] | 8 | single_column: true |
| 9 | }); |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 10 | |
Faris Ansari | c70bbac | 2017-08-29 15:27:17 +0530 | [diff] [blame] | 11 | frappe.db.get_value('POS Settings', {name: 'POS Settings'}, 'is_online', (r) => { |
Rohit Waghchaure | 1a77922 | 2017-09-11 11:49:25 +0530 | [diff] [blame] | 12 | if (r && r.use_pos_in_offline_mode && cint(r.use_pos_in_offline_mode)) { |
Faris Ansari | c70bbac | 2017-08-29 15:27:17 +0530 | [diff] [blame] | 13 | // offline |
| 14 | wrapper.pos = new erpnext.pos.PointOfSale(wrapper); |
| 15 | cur_pos = wrapper.pos; |
| 16 | } else { |
| 17 | // online |
rohitwaghchaure | a4c40e0 | 2018-02-05 12:24:06 +0530 | [diff] [blame] | 18 | frappe.flags.is_online = true |
Faris Ansari | c70bbac | 2017-08-29 15:27:17 +0530 | [diff] [blame] | 19 | frappe.set_route('point-of-sale'); |
| 20 | } |
| 21 | }); |
Rushabh Mehta | 72e1719 | 2014-08-08 15:30:49 +0530 | [diff] [blame] | 22 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 23 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 24 | frappe.pages['pos'].refresh = function (wrapper) { |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 25 | window.onbeforeunload = function () { |
| 26 | return wrapper.pos.beforeunload() |
| 27 | } |
rohitwaghchaure | a4c40e0 | 2018-02-05 12:24:06 +0530 | [diff] [blame] | 28 | |
| 29 | if (frappe.flags.is_online) { |
| 30 | frappe.set_route('point-of-sale'); |
| 31 | } |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 32 | } |
| 33 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 34 | erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 35 | init: function (wrapper) { |
Rohit Waghchaure | 6068aec | 2017-03-10 11:40:28 +0530 | [diff] [blame] | 36 | this.page_len = 20; |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 37 | this.freeze = false; |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 38 | this.page = wrapper.page; |
| 39 | this.wrapper = $(wrapper).find('.page-content'); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 40 | this.set_indicator(); |
| 41 | this.onload(); |
| 42 | this.make_menu_list(); |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 43 | this.bind_events(); |
Rohit Waghchaure | 75177c0 | 2017-03-16 15:21:21 +0530 | [diff] [blame] | 44 | this.bind_items_event(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 45 | this.si_docs = this.get_doc_from_localstorage(); |
| 46 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 47 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 48 | beforeunload: function (e) { |
| 49 | if (this.connection_status == false && frappe.get_route()[0] == "pos") { |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 50 | e = e || window.event; |
| 51 | |
| 52 | // For IE and Firefox prior to version 4 |
| 53 | if (e) { |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 54 | e.returnValue = __("You are in offline mode. You will not be able to reload until you have network."); |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 55 | return |
| 56 | } |
| 57 | |
| 58 | // For Safari |
| 59 | return __("You are in offline mode. You will not be able to reload until you have network."); |
| 60 | } |
| 61 | }, |
| 62 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 63 | check_internet_connection: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 64 | var me = this; |
| 65 | //Check Internet connection after every 30 seconds |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 66 | setInterval(function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 67 | me.set_indicator(); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 68 | }, 5000) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 69 | }, |
| 70 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 71 | set_indicator: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 72 | var me = this; |
| 73 | // navigator.onLine |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 74 | this.connection_status = false; |
Rohit Waghchaure | 26cf01a | 2016-07-22 13:24:33 +0530 | [diff] [blame] | 75 | this.page.set_indicator(__("Offline"), "grey") |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 76 | frappe.call({ |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 77 | method: "frappe.handler.ping", |
| 78 | callback: function (r) { |
| 79 | if (r.message) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 80 | me.connection_status = true; |
Rohit Waghchaure | 26cf01a | 2016-07-22 13:24:33 +0530 | [diff] [blame] | 81 | me.page.set_indicator(__("Online"), "green") |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | }) |
| 85 | }, |
| 86 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 87 | onload: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 88 | var me = this; |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 89 | this.get_data_from_server(function () { |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 90 | me.make_control(); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 91 | me.create_new(); |
rohitwaghchaure | 5fdd26f | 2017-10-21 11:23:45 +0530 | [diff] [blame] | 92 | me.make(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 93 | }); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 94 | }, |
| 95 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 96 | make_menu_list: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 97 | var me = this; |
Rohit Waghchaure | 75177c0 | 2017-03-16 15:21:21 +0530 | [diff] [blame] | 98 | this.page.clear_menu(); |
Faris Ansari | 769b6ba | 2017-05-16 07:31:10 +0530 | [diff] [blame] | 99 | |
| 100 | // for mobile |
| 101 | this.page.add_menu_item(__("Pay"), function () { |
| 102 | me.validate(); |
| 103 | me.update_paid_amount_status(true); |
| 104 | me.create_invoice(); |
| 105 | me.make_payment(); |
| 106 | }).addClass('visible-xs'); |
| 107 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 108 | this.page.add_menu_item(__("New Sales Invoice"), function () { |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 109 | me.save_previous_entry(); |
| 110 | me.create_new(); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 111 | }) |
| 112 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 113 | this.page.add_menu_item(__("Sync Master Data"), function () { |
| 114 | me.get_data_from_server(function () { |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 115 | me.load_data(false); |
Rohit Waghchaure | 6f33dfb | 2016-10-09 15:32:56 +0530 | [diff] [blame] | 116 | me.make_item_list(); |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 117 | me.set_missing_values(); |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 118 | }) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 119 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 120 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 121 | this.page.add_menu_item(__("Sync Offline Invoices"), function () { |
rohitwaghchaure | 8849171 | 2017-10-02 12:13:36 +0530 | [diff] [blame] | 122 | me.freeze_screen = true; |
Rohit Waghchaure | 82be020 | 2016-10-04 12:46:37 +0530 | [diff] [blame] | 123 | me.sync_sales_invoice() |
| 124 | }); |
| 125 | |
Bassam Ramadan | 574cd46 | 2018-09-06 15:32:25 +0200 | [diff] [blame] | 126 | this.page.add_menu_item(__("Cashier Closing"), function () { |
| 127 | frappe.set_route('List', 'Cashier Closing'); |
deepeshgarg007 | c2ffcc5 | 2019-01-27 16:09:07 +0530 | [diff] [blame] | 128 | }); |
Bassam Ramadan | 574cd46 | 2018-09-06 15:32:25 +0200 | [diff] [blame] | 129 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 130 | this.page.add_menu_item(__("POS Profile"), function () { |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 131 | frappe.set_route('List', 'POS Profile'); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 132 | }); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 133 | }, |
| 134 | |
Rohit Waghchaure | b5097ec | 2017-03-01 01:13:09 +0530 | [diff] [blame] | 135 | email_prompt: function() { |
| 136 | var me = this; |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 137 | var fields = [{label:__("To"), fieldtype:"Data", reqd: 0, fieldname:"recipients",length:524288}, |
Shreya Shah | 44e719d | 2018-04-20 10:28:52 +0530 | [diff] [blame] | 138 | {fieldtype: "Section Break", collapsible: 1, label: "CC & Email Template"}, |
Rohit Waghchaure | b5097ec | 2017-03-01 01:13:09 +0530 | [diff] [blame] | 139 | {fieldtype: "Section Break"}, |
| 140 | {label:__("Subject"), fieldtype:"Data", reqd: 1, |
| 141 | fieldname:"subject",length:524288}, |
| 142 | {fieldtype: "Section Break"}, |
| 143 | {label:__("Message"), fieldtype:"Text Editor", reqd: 1, |
| 144 | fieldname:"content"}, |
| 145 | {fieldtype: "Section Break"}, |
| 146 | {fieldtype: "Column Break"}]; |
| 147 | |
| 148 | this.email_dialog = new frappe.ui.Dialog({ |
| 149 | title: "Email", |
| 150 | fields: fields, |
| 151 | primary_action_label: __("Send"), |
| 152 | primary_action: function() { |
| 153 | me.send_action(); |
| 154 | } |
| 155 | }); |
| 156 | |
| 157 | this.email_dialog.show() |
| 158 | }, |
| 159 | |
| 160 | send_action: function() { |
| 161 | this.email_queue = this.get_email_queue() |
| 162 | this.email_queue[this.frm.doc.offline_pos_name] = JSON.stringify(this.email_dialog.get_values()) |
| 163 | this.update_email_queue() |
| 164 | this.email_dialog.hide() |
| 165 | }, |
| 166 | |
| 167 | update_email_queue: function () { |
| 168 | try { |
| 169 | localStorage.setItem('email_queue', JSON.stringify(this.email_queue)); |
| 170 | } catch (e) { |
Faris Ansari | 1f261a8 | 2017-03-06 18:01:58 +0530 | [diff] [blame] | 171 | frappe.throw(__("LocalStorage is full, did not save")) |
Rohit Waghchaure | b5097ec | 2017-03-01 01:13:09 +0530 | [diff] [blame] | 172 | } |
| 173 | }, |
| 174 | |
| 175 | get_email_queue: function () { |
| 176 | try { |
| 177 | return JSON.parse(localStorage.getItem('email_queue')) || {}; |
| 178 | } catch (e) { |
| 179 | return {} |
| 180 | } |
| 181 | }, |
| 182 | |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 183 | get_customers_details: function () { |
| 184 | try { |
| 185 | return JSON.parse(localStorage.getItem('customer_details')) || {}; |
| 186 | } catch (e) { |
| 187 | return {} |
| 188 | } |
| 189 | }, |
| 190 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 191 | edit_record: function () { |
Rohit Waghchaure | 9f2cc38 | 2016-12-09 11:46:08 +0530 | [diff] [blame] | 192 | var me = this; |
| 193 | |
| 194 | doc_data = this.get_invoice_doc(this.si_docs); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 195 | if (doc_data) { |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 196 | this.frm.doc = doc_data[0][this.frm.doc.offline_pos_name]; |
Rohit Waghchaure | 9f2cc38 | 2016-12-09 11:46:08 +0530 | [diff] [blame] | 197 | this.set_missing_values(); |
| 198 | this.refresh(false); |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 199 | this.toggle_input_field(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 200 | this.list_dialog && this.list_dialog.hide(); |
Rohit Waghchaure | 9f2cc38 | 2016-12-09 11:46:08 +0530 | [diff] [blame] | 201 | } |
| 202 | }, |
| 203 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 204 | delete_records: function () { |
Rohit Waghchaure | 9f2cc38 | 2016-12-09 11:46:08 +0530 | [diff] [blame] | 205 | var me = this; |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 206 | this.validate_list() |
Rohit Waghchaure | 9f2cc38 | 2016-12-09 11:46:08 +0530 | [diff] [blame] | 207 | this.remove_doc_from_localstorage() |
| 208 | this.update_localstorage(); |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 209 | this.toggle_delete_button(); |
Rohit Waghchaure | 9f2cc38 | 2016-12-09 11:46:08 +0530 | [diff] [blame] | 210 | }, |
| 211 | |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 212 | validate_list: function() { |
Rohit Waghchaure | 9f2cc38 | 2016-12-09 11:46:08 +0530 | [diff] [blame] | 213 | var me = this; |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 214 | this.si_docs = this.get_submitted_invoice() |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 215 | $.each(this.removed_items, function(index, pos_name){ |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 216 | $.each(me.si_docs, function(key, data){ |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 217 | if(me.si_docs[key][pos_name] && me.si_docs[key][pos_name].offline_pos_name == pos_name ){ |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 218 | frappe.throw(__("Submitted orders can not be deleted")) |
| 219 | } |
| 220 | }) |
| 221 | }) |
| 222 | }, |
| 223 | |
| 224 | toggle_delete_button: function () { |
| 225 | var me = this; |
| 226 | if(this.pos_profile_data["allow_delete"]) { |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 227 | if (this.removed_items && this.removed_items.length > 0) { |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 228 | $(this.page.wrapper).find('.btn-danger').show(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 229 | } else { |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 230 | $(this.page.wrapper).find('.btn-danger').hide(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | }, |
| 234 | |
| 235 | get_doctype_status: function (doc) { |
| 236 | if (doc.docstatus == 0) { |
| 237 | return { status: "Draft", indicator: "red" } |
| 238 | } else if (doc.outstanding_amount == 0) { |
| 239 | return { status: "Paid", indicator: "green" } |
Rohit Waghchaure | 9f2cc38 | 2016-12-09 11:46:08 +0530 | [diff] [blame] | 240 | } else { |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 241 | return { status: "Submitted", indicator: "blue" } |
Rohit Waghchaure | 9f2cc38 | 2016-12-09 11:46:08 +0530 | [diff] [blame] | 242 | } |
| 243 | }, |
| 244 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 245 | set_missing_values: function () { |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 246 | var me = this; |
| 247 | doc = JSON.parse(localStorage.getItem('doc')) |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 248 | if (this.frm.doc.payments.length == 0) { |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 249 | this.frm.doc.payments = doc.payments; |
Rohit Waghchaure | b77a105 | 2016-08-01 18:35:18 +0530 | [diff] [blame] | 250 | this.calculate_outstanding_amount(); |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 251 | } |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 252 | |
rohitwaghchaure | 9a0db39 | 2017-09-14 10:51:21 +0530 | [diff] [blame] | 253 | this.set_customer_value_in_party_field(); |
Rohit Waghchaure | baef262 | 2016-08-05 15:41:36 +0530 | [diff] [blame] | 254 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 255 | if (!this.frm.doc.write_off_account) { |
Rohit Waghchaure | baef262 | 2016-08-05 15:41:36 +0530 | [diff] [blame] | 256 | this.frm.doc.write_off_account = doc.write_off_account |
| 257 | } |
| 258 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 259 | if (!this.frm.doc.account_for_change_amount) { |
Rohit Waghchaure | e4e69ec | 2016-08-17 16:20:13 +0530 | [diff] [blame] | 260 | this.frm.doc.account_for_change_amount = doc.account_for_change_amount |
Rohit Waghchaure | baef262 | 2016-08-05 15:41:36 +0530 | [diff] [blame] | 261 | } |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 262 | }, |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 263 | |
rohitwaghchaure | 9a0db39 | 2017-09-14 10:51:21 +0530 | [diff] [blame] | 264 | set_customer_value_in_party_field: function() { |
| 265 | if (this.frm.doc.customer) { |
| 266 | this.party_field.$input.val(this.frm.doc.customer); |
| 267 | } |
| 268 | }, |
| 269 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 270 | get_invoice_doc: function (si_docs) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 271 | var me = this; |
| 272 | this.si_docs = this.get_doc_from_localstorage(); |
| 273 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 274 | return $.grep(this.si_docs, function (data) { |
| 275 | for (key in data) { |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 276 | return key == me.frm.doc.offline_pos_name; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 277 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 278 | }) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 279 | }, |
| 280 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 281 | get_data_from_server: function (callback) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 282 | var me = this; |
| 283 | frappe.call({ |
| 284 | method: "erpnext.accounts.doctype.sales_invoice.pos.get_pos_data", |
| 285 | freeze: true, |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 286 | freeze_message: __("Master data syncing, it might take some time"), |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 287 | callback: function (r) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 288 | localStorage.setItem('doc', JSON.stringify(r.message.doc)); |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 289 | me.init_master_data(r) |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 290 | me.set_interval_for_si_sync(); |
| 291 | me.check_internet_connection(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 292 | if (callback) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 293 | callback(); |
| 294 | } |
Rushabh Mehta | 69fa808 | 2018-07-17 18:22:51 +0530 | [diff] [blame] | 295 | }, |
| 296 | error: () => { |
| 297 | setTimeout(() => frappe.set_route('List', 'POS Profile'), 2000); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 298 | } |
| 299 | }) |
| 300 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 301 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 302 | init_master_data: function (r) { |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 303 | var me = this; |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 304 | this.doc = JSON.parse(localStorage.getItem('doc')); |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 305 | this.meta = r.message.meta; |
| 306 | this.item_data = r.message.items; |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 307 | this.item_groups = r.message.item_groups; |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 308 | this.customers = r.message.customers; |
| 309 | this.serial_no_data = r.message.serial_no_data; |
| 310 | this.batch_no_data = r.message.batch_no_data; |
Giovanni | 2144e02 | 2017-12-10 17:27:09 +0100 | [diff] [blame] | 311 | this.barcode_data = r.message.barcode_data; |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 312 | this.tax_data = r.message.tax_data; |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 313 | this.contacts = r.message.contacts; |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 314 | this.address = r.message.address || {}; |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 315 | this.price_list_data = r.message.price_list_data; |
deepeshgarg007 | c2ffcc5 | 2019-01-27 16:09:07 +0530 | [diff] [blame] | 316 | this.customer_wise_price_list = r.message.customer_wise_price_list |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 317 | this.bin_data = r.message.bin_data; |
| 318 | this.pricing_rules = r.message.pricing_rules; |
| 319 | this.print_template = r.message.print_template; |
| 320 | this.pos_profile_data = r.message.pos_profile; |
| 321 | this.default_customer = r.message.default_customer || null; |
rohitwaghchaure | 34e820d | 2016-12-20 16:54:24 +0530 | [diff] [blame] | 322 | this.print_settings = locals[":Print Settings"]["Print Settings"]; |
Rohit Waghchaure | d567e57 | 2016-12-21 13:18:36 +0530 | [diff] [blame] | 323 | this.letter_head = (this.pos_profile_data.length > 0) ? frappe.boot.letter_heads[this.pos_profile_data[letter_head]] : {}; |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 324 | }, |
| 325 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 326 | save_previous_entry: function () { |
| 327 | if (this.frm.doc.docstatus < 1 && this.frm.doc.items.length > 0) { |
| 328 | this.create_invoice(); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 329 | } |
| 330 | }, |
| 331 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 332 | create_new: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 333 | var me = this; |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 334 | this.frm = {} |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 335 | this.load_data(true); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 336 | this.setup(); |
Rohit Waghchaure | 6116512 | 2017-05-02 13:04:08 +0530 | [diff] [blame] | 337 | this.set_default_customer() |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 338 | }, |
| 339 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 340 | load_data: function (load_doc) { |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 341 | var me = this; |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 342 | |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 343 | this.items = this.item_data; |
Rohit Waghchaure | 80f5bb6 | 2016-11-27 12:04:12 +0530 | [diff] [blame] | 344 | this.actual_qty_dict = {}; |
| 345 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 346 | if (load_doc) { |
| 347 | this.frm.doc = JSON.parse(localStorage.getItem('doc')); |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 348 | this.frm.doc.offline_pos_name = null; |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 349 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 350 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 351 | $.each(this.meta, function (i, data) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 352 | frappe.meta.sync(data) |
Rohit Waghchaure | fe7a5b3 | 2016-12-27 14:15:52 +0530 | [diff] [blame] | 353 | locals["DocType"][data.name] = data; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 354 | }) |
| 355 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 356 | this.print_template_data = frappe.render_template("print_template", { |
| 357 | content: this.print_template, |
Faris Ansari | 29d64ca | 2017-05-23 17:12:51 +0530 | [diff] [blame] | 358 | title: "POS", |
| 359 | base_url: frappe.urllib.get_base_url(), |
| 360 | print_css: frappe.boot.print_css, |
| 361 | print_settings: this.print_settings, |
| 362 | header: this.letter_head.header, |
| 363 | footer: this.letter_head.footer, |
Makarand Bauskar | 724cc35 | 2017-05-23 17:43:42 +0530 | [diff] [blame] | 364 | landscape: false, |
| 365 | columns: [] |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 366 | }) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 367 | }, |
| 368 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 369 | setup: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 370 | this.set_primary_action(); |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 371 | this.party_field.$input.attr('disabled', false); |
| 372 | if(this.selected_row) { |
| 373 | this.selected_row.hide() |
| 374 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 375 | }, |
| 376 | |
Rohit Waghchaure | 6116512 | 2017-05-02 13:04:08 +0530 | [diff] [blame] | 377 | set_default_customer: function() { |
| 378 | if (this.default_customer && !this.frm.doc.customer) { |
| 379 | this.party_field.$input.val(this.default_customer); |
| 380 | this.frm.doc.customer = this.default_customer; |
| 381 | this.numeric_keypad.show(); |
| 382 | this.toggle_list_customer(false) |
| 383 | this.toggle_item_cart(true) |
| 384 | } |
| 385 | }, |
| 386 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 387 | set_transaction_defaults: function (party) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 388 | var me = this; |
| 389 | this.party = party; |
| 390 | this.price_list = (party == "Customer" ? |
| 391 | this.frm.doc.selling_price_list : this.frm.doc.buying_price_list); |
| 392 | this.price_list_field = (party == "Customer" ? "selling_price_list" : "buying_price_list"); |
| 393 | this.sales_or_purchase = (party == "Customer" ? "Sales" : "Purchase"); |
| 394 | }, |
| 395 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 396 | make: function () { |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 397 | this.make_item_list(); |
| 398 | this.make_discount_field() |
| 399 | }, |
Charles-Henri Decultot | 8bec023 | 2017-05-19 12:32:30 +0200 | [diff] [blame] | 400 | |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 401 | make_control: function() { |
| 402 | this.frm = {} |
| 403 | this.frm.doc = this.doc |
| 404 | this.set_transaction_defaults("Customer"); |
rohitwaghchaure | a32e57a | 2018-03-08 16:21:13 +0530 | [diff] [blame] | 405 | this.frm.doc["allow_user_to_edit_rate"] = this.pos_profile_data["allow_user_to_edit_rate"] ? true : false; |
| 406 | this.frm.doc["allow_user_to_edit_discount"] = this.pos_profile_data["allow_user_to_edit_discount"] ? true : false; |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 407 | this.wrapper.html(frappe.render_template("pos", this.frm.doc)); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 408 | this.make_search(); |
| 409 | this.make_customer(); |
Faris Ansari | 339d9c9 | 2017-03-07 18:14:06 +0530 | [diff] [blame] | 410 | this.make_list_customers(); |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 411 | this.bind_numeric_keypad(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 412 | }, |
| 413 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 414 | make_search: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 415 | var me = this; |
Rohit Waghchaure | eee830e | 2018-05-13 16:17:18 +0530 | [diff] [blame] | 416 | this.search_item = frappe.ui.form.make_control({ |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 417 | df: { |
| 418 | "fieldtype": "Data", |
Mohammed R Abukhamseen | 8662a4f | 2018-07-01 14:14:09 +0300 | [diff] [blame] | 419 | "label": __("Item"), |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 420 | "fieldname": "pos_item", |
Rohit Waghchaure | 26cf01a | 2016-07-22 13:24:33 +0530 | [diff] [blame] | 421 | "placeholder": __("Search Item") |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 422 | }, |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 423 | parent: this.wrapper.find(".search-item"), |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 424 | only_input: true, |
| 425 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 426 | |
Rohit Waghchaure | eee830e | 2018-05-13 16:17:18 +0530 | [diff] [blame] | 427 | this.search_item.make_input(); |
Giovanni | 2144e02 | 2017-12-10 17:27:09 +0100 | [diff] [blame] | 428 | |
Rohit Waghchaure | eee830e | 2018-05-13 16:17:18 +0530 | [diff] [blame] | 429 | this.search_item.$input.on("keypress", function (event) { |
Faris Ansari | 8fbc08f | 2017-08-28 16:52:20 +0530 | [diff] [blame] | 430 | |
| 431 | clearTimeout(me.last_search_timeout); |
| 432 | me.last_search_timeout = setTimeout(() => { |
Rohit Waghchaure | eee830e | 2018-05-13 16:17:18 +0530 | [diff] [blame] | 433 | if((me.search_item.$input.val() != "") || (event.which == 13)) { |
Faris Ansari | 8fbc08f | 2017-08-28 16:52:20 +0530 | [diff] [blame] | 434 | me.items = me.get_items(); |
| 435 | me.make_item_list(); |
Giovanni | 2144e02 | 2017-12-10 17:27:09 +0100 | [diff] [blame] | 436 | } |
Faris Ansari | 8fbc08f | 2017-08-28 16:52:20 +0530 | [diff] [blame] | 437 | }, 400); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 438 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 439 | |
Faris Ansari | 339d9c9 | 2017-03-07 18:14:06 +0530 | [diff] [blame] | 440 | this.search_item_group = this.wrapper.find('.search-item-group'); |
Rohit Waghchaure | d7de3c6 | 2017-04-17 13:36:08 +0530 | [diff] [blame] | 441 | sorted_item_groups = this.get_sorted_item_groups() |
| 442 | var dropdown_html = sorted_item_groups.map(function(item_group) { |
Faris Ansari | 339d9c9 | 2017-03-07 18:14:06 +0530 | [diff] [blame] | 443 | return "<li><a class='option' data-value='"+item_group+"'>"+item_group+"</a></li>"; |
| 444 | }).join(""); |
| 445 | |
| 446 | this.search_item_group.find('.dropdown-menu').html(dropdown_html); |
| 447 | |
| 448 | this.search_item_group.on('click', '.dropdown-menu a', function() { |
| 449 | me.selected_item_group = $(this).attr('data-value'); |
| 450 | me.search_item_group.find('.dropdown-text').text(me.selected_item_group); |
| 451 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 452 | me.page_len = 20; |
| 453 | me.items = me.get_items(); |
| 454 | me.make_item_list(); |
Faris Ansari | 339d9c9 | 2017-03-07 18:14:06 +0530 | [diff] [blame] | 455 | }) |
| 456 | |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 457 | me.toggle_more_btn(); |
| 458 | |
| 459 | this.wrapper.on("click", ".btn-more", function() { |
Rohit Waghchaure | 6068aec | 2017-03-10 11:40:28 +0530 | [diff] [blame] | 460 | me.page_len += 20; |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 461 | me.items = me.get_items(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 462 | me.make_item_list(); |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 463 | me.toggle_more_btn(); |
| 464 | }); |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 465 | |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 466 | this.page.wrapper.on("click", ".edit-customer-btn", function() { |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 467 | me.update_customer() |
| 468 | }) |
Rohit Waghchaure | 60a0532 | 2016-09-12 01:37:46 +0530 | [diff] [blame] | 469 | }, |
| 470 | |
Rohit Waghchaure | d7de3c6 | 2017-04-17 13:36:08 +0530 | [diff] [blame] | 471 | get_sorted_item_groups: function() { |
| 472 | list = {} |
| 473 | $.each(this.item_groups, function(i, data) { |
| 474 | list[i] = data[0] |
| 475 | }) |
| 476 | |
| 477 | return Object.keys(list).sort(function(a,b){return list[a]-list[b]}) |
| 478 | }, |
| 479 | |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 480 | toggle_more_btn: function() { |
| 481 | if(!this.items || this.items.length <= this.page_len) { |
| 482 | this.wrapper.find(".btn-more").hide(); |
| 483 | } else { |
| 484 | this.wrapper.find(".btn-more").show(); |
| 485 | } |
| 486 | }, |
| 487 | |
| 488 | toggle_totals_area: function(show) { |
| 489 | |
Faris Ansari | 07c9f35 | 2017-03-09 17:03:14 +0530 | [diff] [blame] | 490 | if(show === undefined) { |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 491 | show = this.is_totals_area_collapsed; |
| 492 | } |
| 493 | |
| 494 | var totals_area = this.wrapper.find('.totals-area'); |
| 495 | totals_area.find('.net-total-area, .tax-area, .discount-amount-area') |
| 496 | .toggle(show); |
| 497 | |
| 498 | if(show) { |
| 499 | totals_area.find('.collapse-btn i') |
| 500 | .removeClass('octicon-chevron-down') |
| 501 | .addClass('octicon-chevron-up'); |
| 502 | } else { |
| 503 | totals_area.find('.collapse-btn i') |
| 504 | .removeClass('octicon-chevron-up') |
| 505 | .addClass('octicon-chevron-down'); |
| 506 | } |
| 507 | |
| 508 | this.is_totals_area_collapsed = !show; |
| 509 | }, |
| 510 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 511 | make_list_customers: function () { |
| 512 | var me = this; |
Faris Ansari | 339d9c9 | 2017-03-07 18:14:06 +0530 | [diff] [blame] | 513 | this.list_customers_btn = this.page.wrapper.find('.list-customers-btn'); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 514 | this.add_customer_btn = this.wrapper.find('.add-customer-btn'); |
Faris Ansari | 339d9c9 | 2017-03-07 18:14:06 +0530 | [diff] [blame] | 515 | this.pos_bill = this.wrapper.find('.pos-bill-wrapper').hide(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 516 | this.list_customers = this.wrapper.find('.list-customers'); |
Rohit Waghchaure | e30f83a | 2017-02-24 18:02:50 +0530 | [diff] [blame] | 517 | this.numeric_keypad = this.wrapper.find('.numeric_keypad'); |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 518 | this.list_customers_btn.addClass("view_customer") |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 519 | |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 520 | me.render_list_customers(); |
| 521 | me.toggle_totals_area(false); |
| 522 | |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 523 | this.page.wrapper.on('click', '.list-customers-btn', function() { |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 524 | $(this).toggleClass("view_customer"); |
| 525 | if($(this).hasClass("view_customer")) { |
| 526 | me.render_list_customers(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 527 | me.list_customers.show(); |
| 528 | me.pos_bill.hide(); |
Rohit Waghchaure | e30f83a | 2017-02-24 18:02:50 +0530 | [diff] [blame] | 529 | me.numeric_keypad.hide(); |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 530 | me.toggle_delete_button() |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 531 | } else { |
| 532 | if(me.frm.doc.docstatus == 0) { |
| 533 | me.party_field.$input.attr('disabled', false); |
| 534 | } |
| 535 | me.pos_bill.show(); |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 536 | me.toggle_totals_area(false); |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 537 | me.toggle_delete_button() |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 538 | me.list_customers.hide(); |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 539 | me.numeric_keypad.show(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 540 | } |
| 541 | }); |
| 542 | this.add_customer_btn.on('click', function() { |
| 543 | me.save_previous_entry(); |
| 544 | me.create_new(); |
| 545 | me.refresh(); |
| 546 | me.set_focus(); |
| 547 | }); |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 548 | this.pos_bill.on('click', '.collapse-btn', function() { |
| 549 | me.toggle_totals_area(); |
| 550 | }); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 551 | }, |
Charles-Henri Decultot | 8bec023 | 2017-05-19 12:32:30 +0200 | [diff] [blame] | 552 | |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 553 | bind_numeric_keypad: function() { |
| 554 | var me = this; |
| 555 | $(this.numeric_keypad).find('.pos-operation').on('click', function(){ |
| 556 | me.numeric_val = ''; |
| 557 | }) |
| 558 | |
| 559 | $(this.numeric_keypad).find('.numeric-keypad').on('click', function(){ |
| 560 | me.numeric_id = $(this).attr("id") || me.numeric_id; |
| 561 | me.val = $(this).attr("val") |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 562 | if(me.numeric_id) { |
| 563 | me.selected_field = $(me.wrapper).find('.selected-item').find('.' + me.numeric_id) |
| 564 | } |
Faris Ansari | 339d9c9 | 2017-03-07 18:14:06 +0530 | [diff] [blame] | 565 | |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 566 | if(me.val && me.numeric_id) { |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 567 | me.numeric_val += me.val; |
| 568 | me.selected_field.val(flt(me.numeric_val)) |
| 569 | me.selected_field.trigger("change") |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 570 | // me.render_selected_item() |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 571 | } |
Faris Ansari | 339d9c9 | 2017-03-07 18:14:06 +0530 | [diff] [blame] | 572 | |
| 573 | if(me.numeric_id && $(this).hasClass('pos-operation')) { |
| 574 | me.numeric_keypad.find('button.pos-operation').removeClass('active'); |
| 575 | $(this).addClass('active'); |
| 576 | |
| 577 | me.selected_row.find('.pos-list-row').removeClass('active'); |
| 578 | me.selected_field.closest('.pos-list-row').addClass('active'); |
| 579 | } |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 580 | }) |
Charles-Henri Decultot | 8bec023 | 2017-05-19 12:32:30 +0200 | [diff] [blame] | 581 | |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 582 | $(this.numeric_keypad).find('.numeric-del').click(function(){ |
rohitwaghchaure | 8f51a5e | 2017-06-23 18:17:04 +0530 | [diff] [blame] | 583 | if(me.numeric_id) { |
| 584 | me.selected_field = $(me.wrapper).find('.selected-item').find('.' + me.numeric_id) |
| 585 | me.numeric_val = cstr(flt(me.selected_field.val())).slice(0, -1); |
| 586 | me.selected_field.val(me.numeric_val); |
| 587 | me.selected_field.trigger("change") |
| 588 | } else { |
| 589 | //Remove an item from the cart, if focus is at selected item |
| 590 | me.remove_selected_item() |
| 591 | } |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 592 | }) |
Charles-Henri Decultot | 8bec023 | 2017-05-19 12:32:30 +0200 | [diff] [blame] | 593 | |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 594 | $(this.numeric_keypad).find('.pos-pay').click(function(){ |
| 595 | me.validate(); |
| 596 | me.update_paid_amount_status(true); |
| 597 | me.create_invoice(); |
| 598 | me.make_payment(); |
| 599 | }) |
| 600 | }, |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 601 | |
rohitwaghchaure | 8f51a5e | 2017-06-23 18:17:04 +0530 | [diff] [blame] | 602 | remove_selected_item: function() { |
| 603 | this.remove_item = [] |
| 604 | idx = $(this.wrapper).find(".pos-selected-item-action").attr("data-idx") |
| 605 | this.remove_item.push(idx) |
Rohit Waghchaure | 07f75a3 | 2019-01-29 12:01:54 +0530 | [diff] [blame] | 606 | this.remove_zero_qty_items_from_cart() |
rohitwaghchaure | 8f51a5e | 2017-06-23 18:17:04 +0530 | [diff] [blame] | 607 | this.update_paid_amount_status(false) |
| 608 | }, |
| 609 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 610 | render_list_customers: function () { |
| 611 | var me = this; |
| 612 | |
| 613 | this.removed_items = []; |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 614 | // this.list_customers.empty(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 615 | this.si_docs = this.get_doc_from_localstorage(); |
Rohit Waghchaure | 6068aec | 2017-03-10 11:40:28 +0530 | [diff] [blame] | 616 | if (!this.si_docs.length) { |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 617 | this.list_customers.find('.list-customers-table').html(""); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 618 | return; |
| 619 | } |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 620 | |
| 621 | var html = ""; |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 622 | if(this.si_docs.length) { |
| 623 | this.si_docs.forEach(function (data, i) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 624 | for (var key in data) { |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 625 | html += frappe.render_template("pos_invoice_list", { |
| 626 | sr: i + 1, |
| 627 | name: key, |
| 628 | customer: data[key].customer, |
| 629 | paid_amount: format_currency(data[key].paid_amount, me.frm.doc.currency), |
| 630 | grand_total: format_currency(data[key].grand_total, me.frm.doc.currency), |
| 631 | data: me.get_doctype_status(data[key]) |
| 632 | }); |
| 633 | } |
| 634 | }); |
| 635 | } |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 636 | this.list_customers.find('.list-customers-table').html(html); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 637 | |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 638 | this.list_customers.on('click', '.customer-row', function () { |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 639 | me.list_customers.hide(); |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 640 | me.numeric_keypad.show(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 641 | me.list_customers_btn.toggleClass("view_customer"); |
| 642 | me.pos_bill.show(); |
| 643 | me.list_customers_btn.show(); |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 644 | me.frm.doc.offline_pos_name = $(this).parents().attr('invoice-name') |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 645 | me.edit_record(); |
| 646 | }) |
| 647 | |
| 648 | //actions |
| 649 | $(this.wrapper).find('.list-select-all').click(function () { |
| 650 | me.list_customers.find('.list-delete').prop("checked", $(this).is(":checked")) |
| 651 | me.removed_items = []; |
| 652 | if ($(this).is(":checked")) { |
| 653 | $.each(me.si_docs, function (index, data) { |
| 654 | for (key in data) { |
| 655 | me.removed_items.push(key) |
| 656 | } |
| 657 | }); |
| 658 | } |
| 659 | |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 660 | me.toggle_delete_button(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 661 | }); |
| 662 | |
| 663 | $(this.wrapper).find('.list-delete').click(function () { |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 664 | me.frm.doc.offline_pos_name = $(this).parent().parent().attr('invoice-name'); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 665 | if ($(this).is(":checked")) { |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 666 | me.removed_items.push(me.frm.doc.offline_pos_name); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 667 | } else { |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 668 | me.removed_items.pop(me.frm.doc.offline_pos_name) |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 669 | } |
| 670 | |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 671 | me.toggle_delete_button(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 672 | }); |
| 673 | }, |
| 674 | |
| 675 | bind_delete_event: function() { |
| 676 | var me = this; |
| 677 | |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 678 | $(this.page.wrapper).on('click', '.btn-danger', function(){ |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 679 | frappe.confirm(__("Delete permanently?"), function () { |
| 680 | me.delete_records(); |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 681 | me.list_customers.find('.list-customers-table').html(""); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 682 | me.render_list_customers(); |
| 683 | }) |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 684 | }) |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 685 | }, |
| 686 | |
| 687 | set_focus: function () { |
| 688 | if (this.default_customer || this.frm.doc.customer) { |
rohitwaghchaure | 9a0db39 | 2017-09-14 10:51:21 +0530 | [diff] [blame] | 689 | this.set_customer_value_in_party_field(); |
Rohit Waghchaure | eee830e | 2018-05-13 16:17:18 +0530 | [diff] [blame] | 690 | this.search_item.$input.focus(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 691 | } else { |
Rohit Waghchaure | 60a0532 | 2016-09-12 01:37:46 +0530 | [diff] [blame] | 692 | this.party_field.$input.focus(); |
| 693 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 694 | }, |
| 695 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 696 | make_customer: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 697 | var me = this; |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 698 | |
| 699 | if(!this.party_field) { |
| 700 | if(this.page.wrapper.find('.pos-bill-toolbar').length === 0) { |
| 701 | $(frappe.render_template('customer_toolbar', { |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 702 | allow_delete: this.pos_profile_data["allow_delete"] |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 703 | })).insertAfter(this.page.$title_area.hide()); |
| 704 | } |
| 705 | |
| 706 | this.party_field = frappe.ui.form.make_control({ |
| 707 | df: { |
| 708 | "fieldtype": "Data", |
| 709 | "options": this.party, |
| 710 | "label": this.party, |
| 711 | "fieldname": this.party.toLowerCase(), |
| 712 | "placeholder": __("Select or add new customer") |
| 713 | }, |
| 714 | parent: this.page.wrapper.find(".party-area"), |
| 715 | only_input: true, |
| 716 | }); |
| 717 | |
| 718 | this.party_field.make_input(); |
| 719 | setTimeout(this.set_focus.bind(this), 500); |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 720 | me.toggle_delete_button(); |
Faris Ansari | 339d9c9 | 2017-03-07 18:14:06 +0530 | [diff] [blame] | 721 | } |
Faris Ansari | 1f261a8 | 2017-03-06 18:01:58 +0530 | [diff] [blame] | 722 | |
Nabin Hait | 6e9d2a3 | 2017-01-09 17:21:34 +0530 | [diff] [blame] | 723 | this.party_field.awesomeplete = |
| 724 | new Awesomplete(this.party_field.$input.get(0), { |
Rushabh Mehta | 512b85e | 2016-12-27 12:14:26 +0530 | [diff] [blame] | 725 | minChars: 0, |
| 726 | maxItems: 99, |
| 727 | autoFirst: true, |
| 728 | list: [], |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 729 | filter: function (item, input) { |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 730 | if (item.value.includes('is_action')) { |
Nabin Hait | 6e9d2a3 | 2017-01-09 17:21:34 +0530 | [diff] [blame] | 731 | return true; |
| 732 | } |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 733 | |
| 734 | input = input.toLowerCase(); |
| 735 | item = this.get_item(item.value); |
Rohit Waghchaure | 06b22e9 | 2017-09-06 19:45:36 +0530 | [diff] [blame] | 736 | result = item ? item.searchtext.includes(input) : ''; |
| 737 | if(!result) { |
| 738 | me.prepare_customer_mapper(input); |
| 739 | } else { |
| 740 | return result; |
| 741 | } |
Nabin Hait | 6e9d2a3 | 2017-01-09 17:21:34 +0530 | [diff] [blame] | 742 | }, |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 743 | item: function (item, input) { |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 744 | var d = this.get_item(item.value); |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 745 | var html = "<span>" + __(d.label || d.value) + "</span>"; |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 746 | if(d.customer_name) { |
| 747 | html += '<br><span class="text-muted ellipsis">' + __(d.customer_name) + '</span>'; |
| 748 | } |
| 749 | |
Nabin Hait | 6e9d2a3 | 2017-01-09 17:21:34 +0530 | [diff] [blame] | 750 | return $('<li></li>') |
| 751 | .data('item.autocomplete', d) |
| 752 | .html('<a><p>' + html + '</p></a>') |
| 753 | .get(0); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 754 | } |
Rushabh Mehta | 512b85e | 2016-12-27 12:14:26 +0530 | [diff] [blame] | 755 | }); |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 756 | |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 757 | this.prepare_customer_mapper() |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 758 | this.autocomplete_customers(); |
Rushabh Mehta | 512b85e | 2016-12-27 12:14:26 +0530 | [diff] [blame] | 759 | |
| 760 | this.party_field.$input |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 761 | .on('input', function (e) { |
Rohit Waghchaure | 06b22e9 | 2017-09-06 19:45:36 +0530 | [diff] [blame] | 762 | if(me.customers_mapper.length <= 1) { |
| 763 | me.prepare_customer_mapper(e.target.value); |
| 764 | } |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 765 | me.party_field.awesomeplete.list = me.customers_mapper; |
Rushabh Mehta | 512b85e | 2016-12-27 12:14:26 +0530 | [diff] [blame] | 766 | }) |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 767 | .on('awesomplete-select', function (e) { |
| 768 | var customer = me.party_field.awesomeplete |
Nabin Hait | 6e9d2a3 | 2017-01-09 17:21:34 +0530 | [diff] [blame] | 769 | .get_item(e.originalEvent.text.value); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 770 | if (!customer) return; |
| 771 | // create customer link |
| 772 | if (customer.action) { |
| 773 | customer.action.apply(me); |
Nabin Hait | 6e9d2a3 | 2017-01-09 17:21:34 +0530 | [diff] [blame] | 774 | return; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 775 | } |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 776 | me.toggle_list_customer(false); |
| 777 | me.toggle_edit_button(true); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 778 | me.update_customer_data(customer); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 779 | me.refresh(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 780 | me.set_focus(); |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 781 | me.list_customers_btn.removeClass("view_customer"); |
Rushabh Mehta | 512b85e | 2016-12-27 12:14:26 +0530 | [diff] [blame] | 782 | }) |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 783 | .on('focus', function (e) { |
Rushabh Mehta | 512b85e | 2016-12-27 12:14:26 +0530 | [diff] [blame] | 784 | $(e.target).val('').trigger('input'); |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 785 | me.toggle_edit_button(false); |
Faris Ansari | 1fe1518 | 2017-03-10 14:50:39 +0530 | [diff] [blame] | 786 | |
| 787 | if(me.frm.doc.items.length) { |
Rohit Waghchaure | 6068aec | 2017-03-10 11:40:28 +0530 | [diff] [blame] | 788 | me.toggle_list_customer(false) |
| 789 | me.toggle_item_cart(true) |
| 790 | } else { |
| 791 | me.toggle_list_customer(true) |
| 792 | me.toggle_item_cart(false) |
| 793 | } |
Nabin Hait | 6e9d2a3 | 2017-01-09 17:21:34 +0530 | [diff] [blame] | 794 | }) |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 795 | .on("awesomplete-selectcomplete", function (e) { |
Nabin Hait | 6e9d2a3 | 2017-01-09 17:21:34 +0530 | [diff] [blame] | 796 | var item = me.party_field.awesomeplete |
| 797 | .get_item(e.originalEvent.text.value); |
| 798 | // clear text input if item is action |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 799 | if (item.action) { |
Nabin Hait | 6e9d2a3 | 2017-01-09 17:21:34 +0530 | [diff] [blame] | 800 | $(this).val(""); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 801 | } |
deepeshgarg007 | c2ffcc5 | 2019-01-27 16:09:07 +0530 | [diff] [blame] | 802 | me.make_item_list(item.customer_name); |
Rushabh Mehta | 512b85e | 2016-12-27 12:14:26 +0530 | [diff] [blame] | 803 | }); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 804 | }, |
| 805 | |
Rohit Waghchaure | 06b22e9 | 2017-09-06 19:45:36 +0530 | [diff] [blame] | 806 | prepare_customer_mapper: function(key) { |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 807 | var me = this; |
Rohit Waghchaure | 06b22e9 | 2017-09-06 19:45:36 +0530 | [diff] [blame] | 808 | var customer_data = ''; |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 809 | |
Rohit Waghchaure | 06b22e9 | 2017-09-06 19:45:36 +0530 | [diff] [blame] | 810 | if (key) { |
| 811 | key = key.toLowerCase().trim(); |
| 812 | var re = new RegExp('%', 'g'); |
| 813 | var reg = new RegExp(key.replace(re, '\\w*\\s*[a-zA-Z0-9]*')); |
| 814 | |
| 815 | customer_data = $.grep(this.customers, function(data) { |
| 816 | contact = me.contacts[data.name]; |
| 817 | if(reg.test(data.name.toLowerCase()) |
| 818 | || reg.test(data.customer_name.toLowerCase()) |
| 819 | || (contact && reg.test(contact["mobile_no"])) |
| 820 | || (contact && reg.test(contact["phone"])) |
| 821 | || (data.customer_group && reg.test(data.customer_group.toLowerCase()))){ |
| 822 | return data; |
| 823 | } |
| 824 | }) |
| 825 | } else { |
| 826 | customer_data = this.customers; |
| 827 | } |
| 828 | |
| 829 | this.customers_mapper = []; |
| 830 | |
| 831 | customer_data.forEach(function (c, index) { |
| 832 | if(index < 30) { |
| 833 | contact = me.contacts[c.name]; |
| 834 | if(contact && !c['phone']) { |
| 835 | c["phone"] = contact["phone"]; |
| 836 | c["email_id"] = contact["email_id"]; |
| 837 | c["mobile_no"] = contact["mobile_no"]; |
| 838 | } |
| 839 | |
| 840 | me.customers_mapper.push({ |
| 841 | label: c.name, |
| 842 | value: c.name, |
| 843 | customer_name: c.customer_name, |
| 844 | customer_group: c.customer_group, |
| 845 | territory: c.territory, |
| 846 | phone: contact ? contact["phone"] : '', |
| 847 | mobile_no: contact ? contact["mobile_no"] : '', |
| 848 | email_id: contact ? contact["email_id"] : '', |
| 849 | searchtext: ['customer_name', 'customer_group', 'name', 'value', |
| 850 | 'label', 'email_id', 'phone', 'mobile_no'] |
| 851 | .map(key => c[key]).join(' ') |
| 852 | .toLowerCase() |
| 853 | }); |
| 854 | } else { |
| 855 | return; |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 856 | } |
| 857 | }); |
| 858 | |
| 859 | this.customers_mapper.push({ |
| 860 | label: "<span class='text-primary link-option'>" |
| 861 | + "<i class='fa fa-plus' style='margin-right: 5px;'></i> " |
| 862 | + __("Create a new Customer") |
| 863 | + "</span>", |
| 864 | value: 'is_action', |
| 865 | action: me.add_customer |
| 866 | }); |
| 867 | }, |
| 868 | |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 869 | autocomplete_customers: function() { |
| 870 | this.party_field.awesomeplete.list = this.customers_mapper; |
| 871 | }, |
| 872 | |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 873 | toggle_edit_button: function(flag) { |
| 874 | this.page.wrapper.find('.edit-customer-btn').toggle(flag); |
| 875 | }, |
| 876 | |
| 877 | toggle_list_customer: function(flag) { |
| 878 | this.list_customers.toggle(flag); |
| 879 | }, |
| 880 | |
Rohit Waghchaure | 6068aec | 2017-03-10 11:40:28 +0530 | [diff] [blame] | 881 | toggle_item_cart: function(flag) { |
| 882 | this.wrapper.find('.pos-bill-wrapper').toggle(flag); |
| 883 | }, |
| 884 | |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 885 | add_customer: function() { |
| 886 | this.frm.doc.customer = ""; |
rohitwaghchaure | 09483d3 | 2017-05-16 08:51:24 +0530 | [diff] [blame] | 887 | this.update_customer(true); |
| 888 | this.numeric_keypad.show(); |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 889 | }, |
| 890 | |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 891 | update_customer: function (new_customer) { |
Nabin Hait | 6e9d2a3 | 2017-01-09 17:21:34 +0530 | [diff] [blame] | 892 | var me = this; |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 893 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 894 | this.customer_doc = new frappe.ui.Dialog({ |
| 895 | 'title': 'Customer', |
| 896 | fields: [ |
| 897 | { |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 898 | "label": __("Full Name"), |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 899 | "fieldname": "full_name", |
| 900 | "fieldtype": "Data", |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 901 | "reqd": 1 |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 902 | }, |
| 903 | { |
| 904 | "fieldtype": "Section Break" |
| 905 | }, |
| 906 | { |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 907 | "label": __("Email Id"), |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 908 | "fieldname": "email_id", |
| 909 | "fieldtype": "Data" |
| 910 | }, |
| 911 | { |
| 912 | "fieldtype": "Column Break" |
| 913 | }, |
| 914 | { |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 915 | "label": __("Contact Number"), |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 916 | "fieldname": "phone", |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 917 | "fieldtype": "Data" |
| 918 | }, |
| 919 | { |
| 920 | "fieldtype": "Section Break" |
| 921 | }, |
| 922 | { |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 923 | "label": __("Address Name"), |
| 924 | "read_only": 1, |
| 925 | "fieldname": "name", |
| 926 | "fieldtype": "Data" |
| 927 | }, |
| 928 | { |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 929 | "label": __("Address Line 1"), |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 930 | "fieldname": "address_line1", |
| 931 | "fieldtype": "Data" |
| 932 | }, |
| 933 | { |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 934 | "label": __("Address Line 2"), |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 935 | "fieldname": "address_line2", |
| 936 | "fieldtype": "Data" |
| 937 | }, |
| 938 | { |
| 939 | "fieldtype": "Column Break" |
| 940 | }, |
| 941 | { |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 942 | "label": __("City"), |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 943 | "fieldname": "city", |
| 944 | "fieldtype": "Data" |
| 945 | }, |
| 946 | { |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 947 | "label": __("State"), |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 948 | "fieldname": "state", |
| 949 | "fieldtype": "Data" |
| 950 | }, |
| 951 | { |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 952 | "label": __("ZIP Code"), |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 953 | "fieldname": "pincode", |
| 954 | "fieldtype": "Data" |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 955 | }, |
| 956 | { |
| 957 | "label": __("Customer POS Id"), |
| 958 | "fieldname": "customer_pos_id", |
| 959 | "fieldtype": "Data", |
| 960 | "hidden": 1 |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 961 | } |
| 962 | ] |
Rohit Waghchaure | fe7a5b3 | 2016-12-27 14:15:52 +0530 | [diff] [blame] | 963 | }) |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 964 | this.customer_doc.show() |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 965 | this.render_address_data() |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 966 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 967 | this.customer_doc.set_primary_action(__("Save"), function () { |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 968 | me.make_offline_customer(new_customer); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 969 | me.pos_bill.show(); |
Rohit Waghchaure | fd37516 | 2017-05-02 18:27:09 +0530 | [diff] [blame] | 970 | me.list_customers.hide(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 971 | }); |
| 972 | }, |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 973 | |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 974 | render_address_data: function() { |
| 975 | var me = this; |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 976 | this.address_data = this.address[this.frm.doc.customer] || {}; |
| 977 | if(!this.address_data.email_id || !this.address_data.phone) { |
| 978 | this.address_data = this.contacts[this.frm.doc.customer]; |
| 979 | } |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 980 | |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 981 | this.customer_doc.set_values(this.address_data) |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 982 | if(!this.customer_doc.fields_dict.full_name.$input.val()) { |
| 983 | this.customer_doc.set_value("full_name", this.frm.doc.customer) |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 984 | } |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 985 | |
| 986 | if(!this.customer_doc.fields_dict.customer_pos_id.value) { |
| 987 | this.customer_doc.set_value("customer_pos_id", $.now()) |
| 988 | } |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 989 | }, |
| 990 | |
| 991 | get_address_from_localstorage: function() { |
| 992 | this.address_details = this.get_customers_details() |
| 993 | return this.address_details[this.frm.doc.customer] |
| 994 | }, |
| 995 | |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 996 | make_offline_customer: function(new_customer) { |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 997 | this.frm.doc.customer = this.frm.doc.customer || this.customer_doc.get_values().full_name; |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 998 | this.frm.doc.customer_pos_id = this.customer_doc.fields_dict.customer_pos_id.value; |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 999 | this.customer_details = this.get_customers_details(); |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 1000 | this.customer_details[this.frm.doc.customer] = this.get_prompt_details(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1001 | this.party_field.$input.val(this.frm.doc.customer); |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 1002 | this.update_address_and_customer_list(new_customer) |
| 1003 | this.autocomplete_customers(); |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 1004 | this.update_customer_in_localstorage() |
| 1005 | this.update_customer_in_localstorage() |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1006 | this.customer_doc.hide() |
Rohit Waghchaure | fe7a5b3 | 2016-12-27 14:15:52 +0530 | [diff] [blame] | 1007 | }, |
| 1008 | |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 1009 | update_address_and_customer_list: function(new_customer) { |
| 1010 | var me = this; |
| 1011 | if(new_customer) { |
| 1012 | this.customers_mapper.push({ |
| 1013 | label: this.frm.doc.customer, |
| 1014 | value: this.frm.doc.customer, |
| 1015 | customer_group: "", |
| 1016 | territory: "" |
| 1017 | }); |
| 1018 | } |
| 1019 | |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 1020 | this.address[this.frm.doc.customer] = JSON.parse(this.get_prompt_details()) |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 1021 | }, |
| 1022 | |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 1023 | get_prompt_details: function() { |
| 1024 | this.prompt_details = this.customer_doc.get_values(); |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 1025 | this.prompt_details['country'] = this.pos_profile_data.country; |
rohitwaghchaure | e2176b8 | 2017-07-28 20:52:02 +0530 | [diff] [blame] | 1026 | this.prompt_details['territory'] = this.pos_profile_data["territory"]; |
| 1027 | this.prompt_details['customer_group'] = this.pos_profile_data["customer_group"]; |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 1028 | this.prompt_details['customer_pos_id'] = this.customer_doc.fields_dict.customer_pos_id.value; |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 1029 | return JSON.stringify(this.prompt_details) |
| 1030 | }, |
| 1031 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1032 | update_customer_data: function (doc) { |
Rohit Waghchaure | fe7a5b3 | 2016-12-27 14:15:52 +0530 | [diff] [blame] | 1033 | var me = this; |
| 1034 | this.frm.doc.customer = doc.label || doc.name; |
| 1035 | this.frm.doc.customer_name = doc.customer_name; |
| 1036 | this.frm.doc.customer_group = doc.customer_group; |
| 1037 | this.frm.doc.territory = doc.territory; |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1038 | this.pos_bill.show(); |
Rohit Waghchaure | e30f83a | 2017-02-24 18:02:50 +0530 | [diff] [blame] | 1039 | this.numeric_keypad.show(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1040 | }, |
| 1041 | |
deepeshgarg007 | f0cfe98 | 2019-01-28 17:58:44 +0530 | [diff] [blame] | 1042 | make_item_list: function (customer) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1043 | var me = this; |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1044 | if (!this.price_list) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1045 | frappe.msgprint(__("Price List not found or disabled")); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1046 | return; |
| 1047 | } |
| 1048 | |
| 1049 | me.item_timeout = null; |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1050 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1051 | var $wrap = me.wrapper.find(".item-list"); |
| 1052 | me.wrapper.find(".item-list").empty(); |
| 1053 | |
Rohit Waghchaure | 801029e | 2016-11-17 00:14:21 +0530 | [diff] [blame] | 1054 | if (this.items.length > 0) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1055 | $.each(this.items, function(index, obj) { |
deepeshgarg007 | c2ffcc5 | 2019-01-27 16:09:07 +0530 | [diff] [blame] | 1056 | let customer_price_list = me.customer_wise_price_list[customer]; |
| 1057 | let item_price |
| 1058 | if (customer && customer_price_list && customer_price_list[obj.name]) { |
| 1059 | item_price = format_currency(customer_price_list[obj.name], me.frm.doc.currency); |
| 1060 | } else { |
| 1061 | item_price = format_currency(me.price_list_data[obj.name], me.frm.doc.currency); |
| 1062 | } |
Faris Ansari | 1f261a8 | 2017-03-06 18:01:58 +0530 | [diff] [blame] | 1063 | if(index < me.page_len) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1064 | $(frappe.render_template("pos_item", { |
| 1065 | item_code: obj.name, |
deepeshgarg007 | c2ffcc5 | 2019-01-27 16:09:07 +0530 | [diff] [blame] | 1066 | item_price: item_price, |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1067 | item_name: obj.name === obj.item_name ? "" : obj.item_name, |
Faris Ansari | 1f261a8 | 2017-03-06 18:01:58 +0530 | [diff] [blame] | 1068 | item_image: obj.image, |
Faris Ansari | 185762a | 2017-04-13 12:36:08 +0530 | [diff] [blame] | 1069 | item_stock: __('Stock Qty') + ": " + me.get_actual_qty(obj), |
Valmik Jangla | b52d5b2 | 2018-05-17 00:02:03 -0700 | [diff] [blame] | 1070 | item_uom: obj.stock_uom, |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1071 | color: frappe.get_palette(obj.item_name), |
| 1072 | abbr: frappe.get_abbr(obj.item_name) |
| 1073 | })).tooltip().appendTo($wrap); |
| 1074 | } |
| 1075 | }); |
Charles-Henri Decultot | 8bec023 | 2017-05-19 12:32:30 +0200 | [diff] [blame] | 1076 | |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 1077 | $wrap.append(` |
| 1078 | <div class="image-view-item btn-more text-muted text-center"> |
| 1079 | <div class="image-view-body"> |
| 1080 | <i class="mega-octicon octicon-package"></i> |
| 1081 | <div>Load more items</div> |
| 1082 | </div> |
| 1083 | </div> |
| 1084 | `); |
| 1085 | |
| 1086 | me.toggle_more_btn(); |
Rohit Waghchaure | 801029e | 2016-11-17 00:14:21 +0530 | [diff] [blame] | 1087 | } else { |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 1088 | $("<p class='text-muted small' style='padding-left: 10px'>" |
| 1089 | +__("Not items found")+"</p>").appendTo($wrap) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1090 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1091 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1092 | if (this.items.length == 1 |
Rohit Waghchaure | eee830e | 2018-05-13 16:17:18 +0530 | [diff] [blame] | 1093 | && this.search_item.$input.val()) { |
| 1094 | this.search_item.$input.val(""); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1095 | this.add_to_cart(); |
| 1096 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1097 | }, |
| 1098 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1099 | get_items: function (item_code) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1100 | // To search item as per the key enter |
| 1101 | |
| 1102 | var me = this; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1103 | this.item_serial_no = {}; |
| 1104 | this.item_batch_no = {}; |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1105 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1106 | if (item_code) { |
| 1107 | return $.grep(this.item_data, function (item) { |
| 1108 | if (item.item_code == item_code) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1109 | return true |
| 1110 | } |
| 1111 | }) |
| 1112 | } |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 1113 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1114 | this.items_list = this.apply_category(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1115 | |
Rohit Waghchaure | eee830e | 2018-05-13 16:17:18 +0530 | [diff] [blame] | 1116 | key = this.search_item.$input.val().toLowerCase().replace(/[&\/\\#,+()\[\]$~.'":*?<>{}]/g, '\\$&'); |
Rohit Waghchaure | 163e359 | 2016-10-05 13:38:02 +0530 | [diff] [blame] | 1117 | var re = new RegExp('%', 'g'); |
Rohit Waghchaure | 6f33dfb | 2016-10-09 15:32:56 +0530 | [diff] [blame] | 1118 | var reg = new RegExp(key.replace(re, '[\\w*\\s*[a-zA-Z0-9]*]*')) |
Rohit Waghchaure | ea5a32d | 2016-08-10 17:18:52 +0530 | [diff] [blame] | 1119 | search_status = true |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1120 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1121 | if (key) { |
| 1122 | return $.grep(this.items_list, function (item) { |
| 1123 | if (search_status) { |
Rohit Waghchaure | eee830e | 2018-05-13 16:17:18 +0530 | [diff] [blame] | 1124 | if (in_list(me.batch_no_data[item.item_code], me.search_item.$input.val())) { |
Rohit Waghchaure | ea5a32d | 2016-08-10 17:18:52 +0530 | [diff] [blame] | 1125 | search_status = false; |
Rohit Waghchaure | eee830e | 2018-05-13 16:17:18 +0530 | [diff] [blame] | 1126 | return me.item_batch_no[item.item_code] = me.search_item.$input.val() |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1127 | } else if (me.serial_no_data[item.item_code] |
Rohit Waghchaure | eee830e | 2018-05-13 16:17:18 +0530 | [diff] [blame] | 1128 | && in_list(Object.keys(me.serial_no_data[item.item_code]), me.search_item.$input.val())) { |
Rohit Waghchaure | ea5a32d | 2016-08-10 17:18:52 +0530 | [diff] [blame] | 1129 | search_status = false; |
Rohit Waghchaure | eee830e | 2018-05-13 16:17:18 +0530 | [diff] [blame] | 1130 | me.item_serial_no[item.item_code] = [me.search_item.$input.val(), me.serial_no_data[item.item_code][me.search_item.$input.val()]] |
Rohit Waghchaure | ea5a32d | 2016-08-10 17:18:52 +0530 | [diff] [blame] | 1131 | return true |
Rohit Waghchaure | eee830e | 2018-05-13 16:17:18 +0530 | [diff] [blame] | 1132 | } else if (in_list(me.barcode_data[item.item_code], me.search_item.$input.val())) { |
Rohit Waghchaure | ea5a32d | 2016-08-10 17:18:52 +0530 | [diff] [blame] | 1133 | search_status = false; |
Giovanni | 2144e02 | 2017-12-10 17:27:09 +0100 | [diff] [blame] | 1134 | return true; |
rohitwaghchaure | 860144f | 2017-07-12 15:01:56 +0530 | [diff] [blame] | 1135 | } else if (reg.test(item.item_code.toLowerCase()) || (item.description && reg.test(item.description.toLowerCase())) || |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1136 | reg.test(item.item_name.toLowerCase()) || reg.test(item.item_group.toLowerCase())) { |
Rohit Waghchaure | ea5a32d | 2016-08-10 17:18:52 +0530 | [diff] [blame] | 1137 | return true |
| 1138 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1139 | } |
| 1140 | }) |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1141 | } else { |
| 1142 | return this.items_list; |
| 1143 | } |
| 1144 | }, |
Rushabh Mehta | 3714626 | 2017-02-01 18:17:35 +0530 | [diff] [blame] | 1145 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1146 | apply_category: function() { |
Himanshu | 79d4400 | 2019-01-19 14:01:38 +0530 | [diff] [blame] | 1147 | var me = this; |
| 1148 | category = this.selected_item_group || "All Item Groups"; |
| 1149 | if(category == 'All Item Groups') { |
| 1150 | return this.item_data |
| 1151 | } else { |
| 1152 | return this.item_data.filter(function(element, index, array){ |
| 1153 | return element.item_group == category; |
| 1154 | }); |
| 1155 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1156 | }, |
Charles-Henri Decultot | 8bec023 | 2017-05-19 12:32:30 +0200 | [diff] [blame] | 1157 | |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 1158 | bind_items_event: function() { |
| 1159 | var me = this; |
Faris Ansari | 1f261a8 | 2017-03-06 18:01:58 +0530 | [diff] [blame] | 1160 | $(this.wrapper).on('click', '.pos-bill-item', function() { |
| 1161 | $(me.wrapper).find('.pos-bill-item').removeClass('active'); |
| 1162 | $(this).addClass('active'); |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 1163 | me.numeric_val = ""; |
| 1164 | me.numeric_id = "" |
| 1165 | me.item_code = $(this).attr("data-item-code"); |
| 1166 | me.render_selected_item() |
| 1167 | me.bind_qty_event() |
| 1168 | me.update_rate() |
| 1169 | $(me.wrapper).find(".selected-item").scrollTop(1000); |
| 1170 | }) |
| 1171 | }, |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1172 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1173 | bind_qty_event: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1174 | var me = this; |
Rohit Waghchaure | 75177c0 | 2017-03-16 15:21:21 +0530 | [diff] [blame] | 1175 | |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 1176 | $(this.wrapper).on("change", ".pos-item-qty", function () { |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 1177 | var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code"); |
Rohit Waghchaure | dd58d53 | 2016-12-21 17:23:01 +0530 | [diff] [blame] | 1178 | var qty = $(this).val(); |
Rohit Waghchaure | 07f75a3 | 2019-01-29 12:01:54 +0530 | [diff] [blame] | 1179 | me.update_qty(item_code, qty); |
| 1180 | me.update_value(); |
| 1181 | }) |
| 1182 | |
| 1183 | $(this.wrapper).on("focusout", ".pos-item-qty", function () { |
| 1184 | var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code"); |
| 1185 | var qty = $(this).val(); |
| 1186 | me.update_qty(item_code, qty, true); |
| 1187 | me.update_value(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1188 | }) |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1189 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1190 | $(this.wrapper).find("[data-action='increase-qty']").on("click", function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1191 | var item_code = $(this).parents(".pos-bill-item").attr("data-item-code"); |
| 1192 | var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) + 1; |
Rohit Waghchaure | 07f75a3 | 2019-01-29 12:01:54 +0530 | [diff] [blame] | 1193 | me.update_qty(item_code, qty); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1194 | }) |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1195 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1196 | $(this.wrapper).find("[data-action='decrease-qty']").on("click", function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1197 | var item_code = $(this).parents(".pos-bill-item").attr("data-item-code"); |
| 1198 | var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) - 1; |
Rohit Waghchaure | 07f75a3 | 2019-01-29 12:01:54 +0530 | [diff] [blame] | 1199 | me.update_qty(item_code, qty); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1200 | }) |
Charles-Henri Decultot | 8bec023 | 2017-05-19 12:32:30 +0200 | [diff] [blame] | 1201 | |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 1202 | $(this.wrapper).on("change", ".pos-item-disc", function () { |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 1203 | var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code"); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1204 | var discount = $(this).val(); |
Saurabh | 1a4d77a | 2018-02-08 01:32:48 +0530 | [diff] [blame] | 1205 | if(discount > 100){ |
| 1206 | discount = $(this).val(''); |
| 1207 | frappe.show_alert({ |
| 1208 | indicator: 'red', |
| 1209 | message: __('Discount amount cannot be greater than 100%') |
| 1210 | }); |
| 1211 | me.update_discount(item_code, discount); |
Rushabh Mehta | 69fa808 | 2018-07-17 18:22:51 +0530 | [diff] [blame] | 1212 | }else{ |
Saurabh | 1a4d77a | 2018-02-08 01:32:48 +0530 | [diff] [blame] | 1213 | me.update_discount(item_code, discount); |
| 1214 | me.update_value(); |
| 1215 | } |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 1216 | }) |
| 1217 | }, |
| 1218 | |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 1219 | bind_events: function() { |
| 1220 | var me = this; |
| 1221 | // if form is local then allow this function |
| 1222 | // $(me.wrapper).find(".pos-item-wrapper").on("click", function () { |
| 1223 | $(this.wrapper).on("click", ".pos-item-wrapper", function () { |
Rohit Waghchaure | a86bb69 | 2017-03-30 19:16:38 +0530 | [diff] [blame] | 1224 | me.item_code = ''; |
Rohit Waghchaure | d7de3c6 | 2017-04-17 13:36:08 +0530 | [diff] [blame] | 1225 | me.customer_validate(); |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 1226 | if($(me.pos_bill).is(":hidden")) return; |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 1227 | |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 1228 | if (me.frm.doc.docstatus == 0) { |
| 1229 | me.items = me.get_items($(this).attr("data-item-code")) |
| 1230 | me.add_to_cart(); |
Rohit Waghchaure | 75177c0 | 2017-03-16 15:21:21 +0530 | [diff] [blame] | 1231 | me.clear_selected_row(); |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 1232 | } |
| 1233 | }); |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 1234 | |
| 1235 | me.bind_delete_event() |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 1236 | }, |
| 1237 | |
Rohit Waghchaure | 07f75a3 | 2019-01-29 12:01:54 +0530 | [diff] [blame] | 1238 | update_qty: function (item_code, qty, remove_zero_qty_items) { |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 1239 | var me = this; |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1240 | this.items = this.get_items(item_code); |
| 1241 | this.validate_serial_no() |
Rohit Waghchaure | 07f75a3 | 2019-01-29 12:01:54 +0530 | [diff] [blame] | 1242 | this.set_item_details(item_code, "qty", qty, remove_zero_qty_items); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1243 | }, |
| 1244 | |
| 1245 | update_discount: function(item_code, discount) { |
| 1246 | var me = this; |
| 1247 | this.items = this.get_items(item_code); |
| 1248 | this.set_item_details(item_code, "discount_percentage", discount); |
| 1249 | }, |
| 1250 | |
| 1251 | update_rate: function () { |
| 1252 | var me = this; |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 1253 | $(this.wrapper).on("change", ".pos-item-price", function () { |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 1254 | var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code"); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1255 | me.set_item_details(item_code, "rate", $(this).val()); |
Rohit Waghchaure | 75177c0 | 2017-03-16 15:21:21 +0530 | [diff] [blame] | 1256 | me.update_value() |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1257 | }) |
| 1258 | }, |
Rohit Waghchaure | 56a7974 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 1259 | |
Rohit Waghchaure | 75177c0 | 2017-03-16 15:21:21 +0530 | [diff] [blame] | 1260 | update_value: function() { |
| 1261 | var me = this; |
| 1262 | var fields = {qty: ".pos-item-qty", "discount_percentage": ".pos-item-disc", |
| 1263 | "rate": ".pos-item-price", "amount": ".pos-amount"} |
| 1264 | this.child_doc = this.get_child_item(this.item_code); |
| 1265 | |
| 1266 | if(me.child_doc.length) { |
| 1267 | $.each(fields, function(key, field) { |
| 1268 | $(me.selected_row).find(field).val(me.child_doc[0][key]) |
| 1269 | }) |
| 1270 | } else { |
| 1271 | this.clear_selected_row(); |
Rohit Waghchaure | 56a7974 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 1272 | } |
| 1273 | }, |
Rohit Waghchaure | 75177c0 | 2017-03-16 15:21:21 +0530 | [diff] [blame] | 1274 | |
| 1275 | clear_selected_row: function() { |
| 1276 | $(this.wrapper).find('.selected-item').empty(); |
| 1277 | }, |
| 1278 | |
| 1279 | render_selected_item: function() { |
| 1280 | this.child_doc = this.get_child_item(this.item_code); |
| 1281 | $(this.wrapper).find('.selected-item').empty(); |
| 1282 | if(this.child_doc.length) { |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 1283 | this.child_doc[0]["allow_user_to_edit_rate"] = this.pos_profile_data["allow_user_to_edit_rate"] ? true : false, |
rohitwaghchaure | a32e57a | 2018-03-08 16:21:13 +0530 | [diff] [blame] | 1284 | this.child_doc[0]["allow_user_to_edit_discount"] = this.pos_profile_data["allow_user_to_edit_discount"] ? true : false; |
Rohit Waghchaure | 75177c0 | 2017-03-16 15:21:21 +0530 | [diff] [blame] | 1285 | this.selected_row = $(frappe.render_template("pos_selected_item", this.child_doc[0])) |
| 1286 | $(this.wrapper).find('.selected-item').html(this.selected_row) |
| 1287 | } |
| 1288 | |
| 1289 | $(this.selected_row).find('.form-control').click(function(){ |
| 1290 | $(this).select(); |
| 1291 | }) |
| 1292 | }, |
| 1293 | |
Rohit Waghchaure | 86ab6a9 | 2017-02-24 18:02:50 +0530 | [diff] [blame] | 1294 | get_child_item: function(item_code) { |
| 1295 | var me = this; |
| 1296 | return $.map(me.frm.doc.items, function(doc){ |
| 1297 | if(doc.item_code == item_code) { |
| 1298 | return doc |
| 1299 | } |
| 1300 | }) |
| 1301 | }, |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 1302 | |
Rohit Waghchaure | 07f75a3 | 2019-01-29 12:01:54 +0530 | [diff] [blame] | 1303 | set_item_details: function (item_code, field, value, remove_zero_qty_items) { |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1304 | var me = this; |
| 1305 | if (value < 0) { |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 1306 | frappe.throw(__("Enter value must be positive")); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1307 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1308 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1309 | this.remove_item = [] |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1310 | $.each(this.frm.doc["items"] || [], function (i, d) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1311 | if (d.item_code == item_code) { |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1312 | if (d.serial_no && field == 'qty') { |
| 1313 | me.validate_serial_no_qty(d, item_code, field, value) |
| 1314 | } |
| 1315 | |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 1316 | d[field] = flt(value); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1317 | d.amount = flt(d.rate) * flt(d.qty); |
Rohit Waghchaure | 07f75a3 | 2019-01-29 12:01:54 +0530 | [diff] [blame] | 1318 | if (d.qty == 0 && remove_zero_qty_items) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1319 | me.remove_item.push(d.idx) |
| 1320 | } |
Rohit Waghchaure | 75177c0 | 2017-03-16 15:21:21 +0530 | [diff] [blame] | 1321 | |
| 1322 | if(field=="discount_percentage" && value == 0) { |
| 1323 | d.rate = d.price_list_rate; |
| 1324 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1325 | } |
| 1326 | }); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 1327 | |
Rohit Waghchaure | 07f75a3 | 2019-01-29 12:01:54 +0530 | [diff] [blame] | 1328 | if (field == 'qty') { |
| 1329 | this.remove_zero_qty_items_from_cart(); |
| 1330 | } |
| 1331 | |
Rohit Waghchaure | 713e2b7 | 2016-08-19 15:11:36 +0530 | [diff] [blame] | 1332 | this.update_paid_amount_status(false) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1333 | }, |
| 1334 | |
Rohit Waghchaure | 07f75a3 | 2019-01-29 12:01:54 +0530 | [diff] [blame] | 1335 | remove_zero_qty_items_from_cart: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1336 | var me = this; |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1337 | var idx = 0; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1338 | this.items = [] |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1339 | $.each(this.frm.doc["items"] || [], function (i, d) { |
| 1340 | if (!in_list(me.remove_item, d.idx)) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1341 | d.idx = idx; |
| 1342 | me.items.push(d); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1343 | idx++; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1344 | } |
| 1345 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1346 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1347 | this.frm.doc["items"] = this.items; |
| 1348 | }, |
| 1349 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1350 | make_discount_field: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1351 | var me = this; |
| 1352 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1353 | this.wrapper.find('input.discount-percentage').on("change", function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1354 | me.frm.doc.additional_discount_percentage = flt($(this).val(), precision("additional_discount_percentage")); |
rohitwaghchaure | 5fdd26f | 2017-10-21 11:23:45 +0530 | [diff] [blame] | 1355 | |
| 1356 | if(me.frm.doc.additional_discount_percentage && me.frm.doc.discount_amount) { |
| 1357 | // Reset discount amount |
| 1358 | me.frm.doc.discount_amount = 0; |
| 1359 | } |
| 1360 | |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1361 | var total = me.frm.doc.grand_total |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1362 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1363 | if (me.frm.doc.apply_discount_on == 'Net Total') { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1364 | total = me.frm.doc.net_total |
| 1365 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1366 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1367 | me.frm.doc.discount_amount = flt(total * flt(me.frm.doc.additional_discount_percentage) / 100, precision("discount_amount")); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1368 | me.refresh(); |
rohitwaghchaure | 5fdd26f | 2017-10-21 11:23:45 +0530 | [diff] [blame] | 1369 | me.wrapper.find('input.discount-amount').val(me.frm.doc.discount_amount) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1370 | }); |
| 1371 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1372 | this.wrapper.find('input.discount-amount').on("change", function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1373 | me.frm.doc.discount_amount = flt($(this).val(), precision("discount_amount")); |
| 1374 | me.frm.doc.additional_discount_percentage = 0.0; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1375 | me.refresh(); |
rohitwaghchaure | 5fdd26f | 2017-10-21 11:23:45 +0530 | [diff] [blame] | 1376 | me.wrapper.find('input.discount-percentage').val(0); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1377 | }); |
| 1378 | }, |
| 1379 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1380 | customer_validate: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1381 | var me = this; |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 1382 | if (!this.frm.doc.customer || this.party_field.get_value() == "") { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1383 | frappe.throw(__("Please select customer")) |
| 1384 | } |
| 1385 | }, |
| 1386 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1387 | add_to_cart: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1388 | var me = this; |
| 1389 | var caught = false; |
| 1390 | var no_of_items = me.wrapper.find(".pos-bill-item").length; |
| 1391 | |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1392 | this.customer_validate(); |
| 1393 | this.mandatory_batch_no(); |
| 1394 | this.validate_serial_no(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1395 | this.validate_warehouse(); |
| 1396 | |
| 1397 | if (no_of_items != 0) { |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1398 | $.each(this.frm.doc["items"] || [], function (i, d) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1399 | if (d.item_code == me.items[0].item_code) { |
| 1400 | caught = true; |
| 1401 | d.qty += 1; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1402 | d.amount = flt(d.rate) * flt(d.qty); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1403 | if (me.item_serial_no[d.item_code]) { |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1404 | d.serial_no += '\n' + me.item_serial_no[d.item_code][0] |
| 1405 | d.warehouse = me.item_serial_no[d.item_code][1] |
| 1406 | } |
| 1407 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1408 | if (me.item_batch_no.length) { |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1409 | d.batch_no = me.item_batch_no[d.item_code] |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1410 | } |
| 1411 | } |
| 1412 | }); |
| 1413 | } |
| 1414 | |
| 1415 | // if item not found then add new item |
| 1416 | if (!caught) |
| 1417 | this.add_new_item_to_grid(); |
| 1418 | |
Rohit Waghchaure | 713e2b7 | 2016-08-19 15:11:36 +0530 | [diff] [blame] | 1419 | this.update_paid_amount_status(false) |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 1420 | this.wrapper.find(".item-cart-items").scrollTop(1000); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1421 | }, |
| 1422 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1423 | add_new_item_to_grid: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1424 | var me = this; |
| 1425 | this.child = frappe.model.add_child(this.frm.doc, this.frm.doc.doctype + " Item", "items"); |
| 1426 | this.child.item_code = this.items[0].item_code; |
| 1427 | this.child.item_name = this.items[0].item_name; |
| 1428 | this.child.stock_uom = this.items[0].stock_uom; |
Britlog | 9e9e37d | 2018-11-13 07:04:27 +0100 | [diff] [blame] | 1429 | this.child.uom = this.items[0].sales_uom || this.items[0].stock_uom; |
| 1430 | this.child.conversion_factor = this.items[0].conversion_factor || 1; |
Rohit Waghchaure | 75177c0 | 2017-03-16 15:21:21 +0530 | [diff] [blame] | 1431 | this.child.brand = this.items[0].brand; |
rohitwaghchaure | 860144f | 2017-07-12 15:01:56 +0530 | [diff] [blame] | 1432 | this.child.description = this.items[0].description || this.items[0].item_name; |
Rohit Waghchaure | e30f83a | 2017-02-24 18:02:50 +0530 | [diff] [blame] | 1433 | this.child.discount_percentage = 0.0; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1434 | this.child.qty = 1; |
| 1435 | this.child.item_group = this.items[0].item_group; |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 1436 | this.child.cost_center = this.pos_profile_data['cost_center'] || this.items[0].cost_center; |
| 1437 | this.child.income_account = this.pos_profile_data['income_account'] || this.items[0].income_account; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1438 | this.child.warehouse = (this.item_serial_no[this.child.item_code] |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1439 | ? this.item_serial_no[this.child.item_code][1] : (this.pos_profile_data['warehouse'] || this.items[0].default_warehouse)); |
deepeshgarg007 | c2ffcc5 | 2019-01-27 16:09:07 +0530 | [diff] [blame] | 1440 | |
| 1441 | customer = this.frm.doc.customer; |
deepeshgarg007 | f0cfe98 | 2019-01-28 17:58:44 +0530 | [diff] [blame] | 1442 | let rate; |
deepeshgarg007 | c2ffcc5 | 2019-01-27 16:09:07 +0530 | [diff] [blame] | 1443 | |
| 1444 | customer_price_list = this.customer_wise_price_list[customer] |
| 1445 | if (customer_price_list && customer_price_list[this.child.item_code]){ |
| 1446 | rate = flt(this.customer_wise_price_list[customer][this.child.item_code] * this.child.conversion_factor, 9) / flt(this.frm.doc.conversion_rate, 9); |
| 1447 | } |
| 1448 | else{ |
| 1449 | rate = flt(this.price_list_data[this.child.item_code] * this.child.conversion_factor, 9) / flt(this.frm.doc.conversion_rate, 9); |
| 1450 | } |
| 1451 | |
| 1452 | this.child.price_list_rate = rate; |
| 1453 | this.child.rate = rate; |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 1454 | this.child.actual_qty = me.get_actual_qty(this.items[0]); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1455 | this.child.amount = flt(this.child.qty) * flt(this.child.rate); |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1456 | this.child.batch_no = this.item_batch_no[this.child.item_code]; |
| 1457 | this.child.serial_no = (this.item_serial_no[this.child.item_code] |
| 1458 | ? this.item_serial_no[this.child.item_code][0] : ''); |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 1459 | this.child.item_tax_rate = JSON.stringify(this.tax_data[this.child.item_code]); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1460 | }, |
| 1461 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1462 | update_paid_amount_status: function (update_paid_amount) { |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 1463 | if (this.frm.doc.offline_pos_name) { |
Rohit Waghchaure | 713e2b7 | 2016-08-19 15:11:36 +0530 | [diff] [blame] | 1464 | update_paid_amount = update_paid_amount ? false : true; |
| 1465 | } |
| 1466 | |
| 1467 | this.refresh(update_paid_amount); |
| 1468 | }, |
| 1469 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1470 | refresh: function (update_paid_amount) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1471 | var me = this; |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 1472 | this.refresh_fields(update_paid_amount); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1473 | this.set_primary_action(); |
| 1474 | }, |
Rohit Waghchaure | 713e2b7 | 2016-08-19 15:11:36 +0530 | [diff] [blame] | 1475 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1476 | refresh_fields: function (update_paid_amount) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1477 | this.apply_pricing_rule(); |
| 1478 | this.discount_amount_applied = false; |
| 1479 | this._calculate_taxes_and_totals(); |
| 1480 | this.calculate_discount_amount(); |
| 1481 | this.show_items_in_item_cart(); |
| 1482 | this.set_taxes(); |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 1483 | this.calculate_outstanding_amount(update_paid_amount); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1484 | this.set_totals(); |
pawan | 53a4d2c | 2018-03-21 09:19:36 +0530 | [diff] [blame] | 1485 | this.update_total_qty(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1486 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1487 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1488 | get_company_currency: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1489 | return erpnext.get_currency(this.frm.doc.company); |
| 1490 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1491 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1492 | show_items_in_item_cart: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1493 | var me = this; |
| 1494 | var $items = this.wrapper.find(".items").empty(); |
Faris Ansari | 1f261a8 | 2017-03-06 18:01:58 +0530 | [diff] [blame] | 1495 | var $no_items_message = this.wrapper.find(".no-items-message"); |
| 1496 | $no_items_message.toggle(this.frm.doc.items.length === 0); |
| 1497 | |
| 1498 | var $totals_area = this.wrapper.find('.totals-area'); |
| 1499 | $totals_area.toggle(this.frm.doc.items.length > 0); |
| 1500 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1501 | $.each(this.frm.doc.items || [], function (i, d) { |
Faris Ansari | 1f261a8 | 2017-03-06 18:01:58 +0530 | [diff] [blame] | 1502 | $(frappe.render_template("pos_bill_item_new", { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1503 | item_code: d.item_code, |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1504 | item_name: (d.item_name === d.item_code || !d.item_name) ? "" : ("<br>" + d.item_name), |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1505 | qty: d.qty, |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1506 | discount_percentage: d.discount_percentage || 0.0, |
| 1507 | actual_qty: me.actual_qty_dict[d.item_code] || 0.0, |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1508 | projected_qty: d.projected_qty, |
mbauskar | 22cedeb | 2017-04-17 12:24:11 +0530 | [diff] [blame] | 1509 | rate: format_currency(d.rate, me.frm.doc.currency), |
Rohit Waghchaure | 6ee91ec | 2017-03-21 15:55:09 +0530 | [diff] [blame] | 1510 | amount: format_currency(d.amount, me.frm.doc.currency), |
| 1511 | selected_class: (me.item_code == d.item_code) ? "active" : "" |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1512 | })).appendTo($items); |
| 1513 | }); |
| 1514 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1515 | this.wrapper.find("input.pos-item-qty").on("focus", function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1516 | $(this).select(); |
| 1517 | }); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 1518 | |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 1519 | this.wrapper.find("input.pos-item-disc").on("focus", function () { |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1520 | $(this).select(); |
| 1521 | }); |
| 1522 | |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 1523 | this.wrapper.find("input.pos-item-price").on("focus", function () { |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 1524 | $(this).select(); |
| 1525 | }); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1526 | }, |
| 1527 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1528 | set_taxes: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1529 | var me = this; |
| 1530 | me.frm.doc.total_taxes_and_charges = 0.0 |
| 1531 | |
| 1532 | var taxes = this.frm.doc.taxes || []; |
| 1533 | $(this.wrapper) |
| 1534 | .find(".tax-area").toggleClass("hide", (taxes && taxes.length) ? false : true) |
| 1535 | .find(".tax-table").empty(); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1536 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1537 | $.each(taxes, function (i, d) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1538 | if (d.tax_amount && cint(d.included_in_print_rate) == 0) { |
| 1539 | $(frappe.render_template("pos_tax_row", { |
| 1540 | description: d.description, |
| 1541 | tax_amount: format_currency(flt(d.tax_amount_after_discount_amount), |
| 1542 | me.frm.doc.currency) |
| 1543 | })).appendTo(me.wrapper.find(".tax-table")); |
| 1544 | } |
| 1545 | }); |
| 1546 | }, |
| 1547 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1548 | set_totals: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1549 | var me = this; |
| 1550 | this.wrapper.find(".net-total").text(format_currency(me.frm.doc.total, me.frm.doc.currency)); |
| 1551 | this.wrapper.find(".grand-total").text(format_currency(me.frm.doc.grand_total, me.frm.doc.currency)); |
rohitwaghchaure | 5fdd26f | 2017-10-21 11:23:45 +0530 | [diff] [blame] | 1552 | this.wrapper.find('input.discount-percentage').val(this.frm.doc.additional_discount_percentage); |
| 1553 | this.wrapper.find('input.discount-amount').val(this.frm.doc.discount_amount); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1554 | }, |
| 1555 | |
pawan | 53a4d2c | 2018-03-21 09:19:36 +0530 | [diff] [blame] | 1556 | update_total_qty: function() { |
| 1557 | var me = this; |
| 1558 | var qty_total = 0; |
| 1559 | $.each(this.frm.doc["items"] || [], function (i, d) { |
| 1560 | if (d.item_code) { |
| 1561 | qty_total += d.qty; |
| 1562 | } |
| 1563 | }); |
| 1564 | this.frm.doc.qty_total = qty_total; |
| 1565 | this.wrapper.find('.qty-total').text(this.frm.doc.qty_total); |
| 1566 | }, |
| 1567 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1568 | set_primary_action: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1569 | var me = this; |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 1570 | this.page.set_primary_action(__("New Cart"), function () { |
| 1571 | me.make_new_cart() |
Rohit Waghchaure | 75177c0 | 2017-03-16 15:21:21 +0530 | [diff] [blame] | 1572 | me.make_menu_list() |
Faris Ansari | 4551010 | 2017-03-09 14:43:37 +0530 | [diff] [blame] | 1573 | }, "fa fa-plus") |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 1574 | |
augustinfotech | 135a54c | 2017-11-16 15:28:42 +0530 | [diff] [blame] | 1575 | if (this.frm.doc.docstatus == 1 || this.pos_profile_data["allow_print_before_pay"]) { |
Rohit Waghchaure | 6068aec | 2017-03-10 11:40:28 +0530 | [diff] [blame] | 1576 | this.page.set_secondary_action(__("Print"), function () { |
augustinfotech | 135a54c | 2017-11-16 15:28:42 +0530 | [diff] [blame] | 1577 | me.create_invoice(); |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1578 | var html = frappe.render(me.print_template_data, me.frm.doc) |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 1579 | me.print_document(html) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1580 | }) |
augustinfotech | 135a54c | 2017-11-16 15:28:42 +0530 | [diff] [blame] | 1581 | } |
Giovanni | 2144e02 | 2017-12-10 17:27:09 +0100 | [diff] [blame] | 1582 | |
| 1583 | if (this.frm.doc.docstatus == 1) { |
Rohit Waghchaure | 75177c0 | 2017-03-16 15:21:21 +0530 | [diff] [blame] | 1584 | this.page.add_menu_item(__("Email"), function () { |
| 1585 | me.email_prompt() |
| 1586 | }) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1587 | } |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 1588 | }, |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 1589 | |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 1590 | make_new_cart: function (){ |
Rohit Waghchaure | a86bb69 | 2017-03-30 19:16:38 +0530 | [diff] [blame] | 1591 | this.item_code = ''; |
Rohit Waghchaure | 75177c0 | 2017-03-16 15:21:21 +0530 | [diff] [blame] | 1592 | this.page.clear_secondary_action(); |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 1593 | this.save_previous_entry(); |
| 1594 | this.create_new(); |
| 1595 | this.refresh(); |
| 1596 | this.toggle_input_field(); |
| 1597 | this.render_list_customers(); |
| 1598 | this.set_focus(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1599 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1600 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1601 | print_dialog: function () { |
Rohit Waghchaure | 60a0532 | 2016-09-12 01:37:46 +0530 | [diff] [blame] | 1602 | var me = this; |
| 1603 | |
mbauskar | 66e2a51 | 2017-06-22 16:18:12 +0530 | [diff] [blame] | 1604 | this.msgprint = frappe.msgprint( |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1605 | `<a class="btn btn-primary print_doc" |
| 1606 | style="margin-right: 5px;">${__('Print')}</a> |
| 1607 | <a class="btn btn-default new_doc">${__('New')}</a>`); |
Rohit Waghchaure | 60a0532 | 2016-09-12 01:37:46 +0530 | [diff] [blame] | 1608 | |
Rohit Waghchaure | 152a0c8 | 2018-10-29 16:50:18 +0530 | [diff] [blame] | 1609 | this.msgprint.msg_area.find('.print_doc').on('click', function() { |
| 1610 | var html = frappe.render(me.print_template_data, me.frm.doc); |
| 1611 | me.print_document(html); |
Rohit Waghchaure | 60a0532 | 2016-09-12 01:37:46 +0530 | [diff] [blame] | 1612 | }) |
| 1613 | |
Rohit Waghchaure | 152a0c8 | 2018-10-29 16:50:18 +0530 | [diff] [blame] | 1614 | this.msgprint.msg_area.find('.new_doc').on('click', function() { |
| 1615 | me.msgprint.hide(); |
| 1616 | me.make_new_cart(); |
Rohit Waghchaure | 60a0532 | 2016-09-12 01:37:46 +0530 | [diff] [blame] | 1617 | }) |
Rohit Waghchaure | 152a0c8 | 2018-10-29 16:50:18 +0530 | [diff] [blame] | 1618 | |
Rohit Waghchaure | 60a0532 | 2016-09-12 01:37:46 +0530 | [diff] [blame] | 1619 | }, |
| 1620 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1621 | print_document: function (html) { |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 1622 | var w = window.open(); |
| 1623 | w.document.write(html); |
| 1624 | w.document.close(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1625 | setTimeout(function () { |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 1626 | w.print(); |
| 1627 | w.close(); |
| 1628 | }, 1000) |
| 1629 | }, |
| 1630 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1631 | submit_invoice: function () { |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 1632 | var me = this; |
Rohit Waghchaure | 60a0532 | 2016-09-12 01:37:46 +0530 | [diff] [blame] | 1633 | this.change_status(); |
Rohit Waghchaure | e259a9b | 2017-03-14 19:03:49 +0530 | [diff] [blame] | 1634 | this.update_serial_no() |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1635 | if (this.frm.doc.docstatus == 1) { |
Rohit Waghchaure | 60a0532 | 2016-09-12 01:37:46 +0530 | [diff] [blame] | 1636 | this.print_dialog() |
| 1637 | } |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 1638 | }, |
| 1639 | |
Rohit Waghchaure | e259a9b | 2017-03-14 19:03:49 +0530 | [diff] [blame] | 1640 | update_serial_no: function() { |
| 1641 | var me = this; |
| 1642 | |
| 1643 | //Remove the sold serial no from the cache |
| 1644 | $.each(this.frm.doc.items, function(index, data) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1645 | var sn = data.serial_no.split('\n') |
Rohit Waghchaure | e259a9b | 2017-03-14 19:03:49 +0530 | [diff] [blame] | 1646 | if(sn.length) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1647 | var serial_no_list = me.serial_no_data[data.item_code] |
Rohit Waghchaure | b719dc5 | 2017-03-23 17:04:00 +0530 | [diff] [blame] | 1648 | if(serial_no_list) { |
| 1649 | $.each(sn, function(i, serial_no) { |
| 1650 | if(in_list(Object.keys(serial_no_list), serial_no)) { |
| 1651 | delete serial_no_list[serial_no] |
| 1652 | } |
| 1653 | }) |
| 1654 | me.serial_no_data[data.item_code] = serial_no_list; |
| 1655 | } |
Rohit Waghchaure | e259a9b | 2017-03-14 19:03:49 +0530 | [diff] [blame] | 1656 | } |
| 1657 | }) |
| 1658 | }, |
| 1659 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1660 | change_status: function () { |
| 1661 | if (this.frm.doc.docstatus == 0) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1662 | this.frm.doc.docstatus = 1; |
| 1663 | this.update_invoice(); |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 1664 | this.toggle_input_field(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1665 | } |
| 1666 | }, |
| 1667 | |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 1668 | toggle_input_field: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1669 | var pointer_events = 'inherit' |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1670 | var disabled = this.frm.doc.docstatus == 1 ? true: false; |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 1671 | $(this.wrapper).find('input').attr("disabled", disabled); |
| 1672 | $(this.wrapper).find('select').attr("disabled", disabled); |
| 1673 | $(this.wrapper).find('input').attr("disabled", disabled); |
| 1674 | $(this.wrapper).find('select').attr("disabled", disabled); |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 1675 | $(this.wrapper).find('button').attr("disabled", disabled); |
| 1676 | this.party_field.$input.attr('disabled', disabled); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1677 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1678 | if (this.frm.doc.docstatus == 1) { |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1679 | pointer_events = 'none'; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1680 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1681 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1682 | $(this.wrapper).find('.pos-bill').css('pointer-events', pointer_events); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1683 | $(this.wrapper).find('.pos-items-section').css('pointer-events', pointer_events); |
| 1684 | this.set_primary_action(); |
| 1685 | }, |
| 1686 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1687 | create_invoice: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1688 | var me = this; |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 1689 | var invoice_data = {}; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1690 | this.si_docs = this.get_doc_from_localstorage(); |
pawan | 53a4d2c | 2018-03-21 09:19:36 +0530 | [diff] [blame] | 1691 | |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 1692 | if (this.frm.doc.offline_pos_name) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1693 | this.update_invoice() |
Helkyd | 2b6bf82 | 2017-11-22 14:49:51 +0100 | [diff] [blame] | 1694 | //to retrieve and set the default payment |
rohitwaghchaure | 441032d | 2018-02-01 16:54:10 +0530 | [diff] [blame] | 1695 | invoice_data[this.frm.doc.offline_pos_name] = this.frm.doc; |
| 1696 | invoice_data[this.frm.doc.offline_pos_name].payments[0].amount = this.frm.doc.net_total |
| 1697 | invoice_data[this.frm.doc.offline_pos_name].payments[0].base_amount = this.frm.doc.net_total |
Helkyd | 2b6bf82 | 2017-11-22 14:49:51 +0100 | [diff] [blame] | 1698 | |
| 1699 | this.frm.doc.paid_amount = this.frm.doc.net_total |
| 1700 | this.frm.doc.outstanding_amount = 0 |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1701 | } else { |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 1702 | this.frm.doc.offline_pos_name = $.now(); |
Rohit Waghchaure | 9cd356c | 2016-08-11 16:54:30 +0530 | [diff] [blame] | 1703 | this.frm.doc.posting_date = frappe.datetime.get_today(); |
| 1704 | this.frm.doc.posting_time = frappe.datetime.now_time(); |
pawan | 53a4d2c | 2018-03-21 09:19:36 +0530 | [diff] [blame] | 1705 | this.frm.doc.pos_total_qty = this.frm.doc.qty_total; |
Charles-Henri Decultot | 2305eda | 2017-06-19 05:55:54 +0200 | [diff] [blame] | 1706 | this.frm.doc.pos_profile = this.pos_profile_data['name']; |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 1707 | invoice_data[this.frm.doc.offline_pos_name] = this.frm.doc; |
| 1708 | this.si_docs.push(invoice_data); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1709 | this.update_localstorage(); |
| 1710 | this.set_primary_action(); |
| 1711 | } |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1712 | return invoice_data; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1713 | }, |
| 1714 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1715 | update_invoice: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1716 | var me = this; |
| 1717 | this.si_docs = this.get_doc_from_localstorage(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1718 | $.each(this.si_docs, function (index, data) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1719 | for (var key in data) { |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 1720 | if (key == me.frm.doc.offline_pos_name) { |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1721 | me.si_docs[index][key] = me.frm.doc; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1722 | me.update_localstorage(); |
| 1723 | } |
| 1724 | } |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 1725 | }); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1726 | }, |
| 1727 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1728 | update_localstorage: function () { |
| 1729 | try { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1730 | localStorage.setItem('sales_invoice_doc', JSON.stringify(this.si_docs)); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1731 | } catch (e) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1732 | frappe.throw(__("LocalStorage is full , did not save")) |
| 1733 | } |
| 1734 | }, |
| 1735 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1736 | get_doc_from_localstorage: function () { |
| 1737 | try { |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 1738 | return JSON.parse(localStorage.getItem('sales_invoice_doc')) || []; |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1739 | } catch (e) { |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 1740 | return [] |
| 1741 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1742 | }, |
| 1743 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1744 | set_interval_for_si_sync: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1745 | var me = this; |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1746 | setInterval(function () { |
rohitwaghchaure | 8849171 | 2017-10-02 12:13:36 +0530 | [diff] [blame] | 1747 | me.freeze_screen = false; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1748 | me.sync_sales_invoice() |
rohitwaghchaure | a32e57a | 2018-03-08 16:21:13 +0530 | [diff] [blame] | 1749 | }, 180000) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1750 | }, |
| 1751 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1752 | sync_sales_invoice: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1753 | var me = this; |
Rohit Waghchaure | b5097ec | 2017-03-01 01:13:09 +0530 | [diff] [blame] | 1754 | this.si_docs = this.get_submitted_invoice() || []; |
| 1755 | this.email_queue_list = this.get_email_queue() || {}; |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 1756 | this.customers_list = this.get_customers_details() || {}; |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 1757 | if(this.customer_doc) { |
| 1758 | this.freeze = this.customer_doc.display |
| 1759 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1760 | |
rohitwaghchaure | 8849171 | 2017-10-02 12:13:36 +0530 | [diff] [blame] | 1761 | freeze_screen = this.freeze_screen || false; |
| 1762 | |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 1763 | if ((this.si_docs.length || this.email_queue_list || this.customers_list) && !this.freeze) { |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 1764 | this.freeze = true; |
| 1765 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1766 | frappe.call({ |
| 1767 | method: "erpnext.accounts.doctype.sales_invoice.pos.make_invoice", |
rohitwaghchaure | 8849171 | 2017-10-02 12:13:36 +0530 | [diff] [blame] | 1768 | freeze: freeze_screen, |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1769 | args: { |
Rohit Waghchaure | b5097ec | 2017-03-01 01:13:09 +0530 | [diff] [blame] | 1770 | doc_list: me.si_docs, |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 1771 | email_queue_list: me.email_queue_list, |
| 1772 | customers_list: me.customers_list |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1773 | }, |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1774 | callback: function (r) { |
| 1775 | if (r.message) { |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 1776 | me.freeze = false; |
rohitwaghchaure | d2be55b | 2017-06-07 12:04:01 +0530 | [diff] [blame] | 1777 | me.customers = r.message.synced_customers_list; |
| 1778 | me.address = r.message.synced_address; |
| 1779 | me.contacts = r.message.synced_contacts; |
Rohit Waghchaure | b5097ec | 2017-03-01 01:13:09 +0530 | [diff] [blame] | 1780 | me.removed_items = r.message.invoice; |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 1781 | me.removed_email = r.message.email_queue; |
| 1782 | me.removed_customers = r.message.customers; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1783 | me.remove_doc_from_localstorage(); |
Rohit Waghchaure | b5097ec | 2017-03-01 01:13:09 +0530 | [diff] [blame] | 1784 | me.remove_email_queue_from_localstorage(); |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 1785 | me.remove_customer_from_localstorage(); |
rohitwaghchaure | f688af3 | 2017-11-08 11:33:39 +0530 | [diff] [blame] | 1786 | me.prepare_customer_mapper(); |
| 1787 | me.autocomplete_customers(); |
| 1788 | me.render_list_customers(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1789 | } |
| 1790 | } |
| 1791 | }) |
| 1792 | } |
| 1793 | }, |
| 1794 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1795 | get_submitted_invoice: function () { |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 1796 | var invoices = []; |
| 1797 | var index = 1; |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1798 | var docs = this.get_doc_from_localstorage(); |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1799 | if (docs) { |
| 1800 | invoices = $.map(docs, function (data) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1801 | for (var key in data) { |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1802 | if (data[key].docstatus == 1 && index < 50) { |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 1803 | index++ |
Rohit Waghchaure | b77a105 | 2016-08-01 18:35:18 +0530 | [diff] [blame] | 1804 | data[key].docstatus = 0; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1805 | return data |
| 1806 | } |
| 1807 | } |
| 1808 | }); |
| 1809 | } |
| 1810 | |
| 1811 | return invoices |
| 1812 | }, |
| 1813 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1814 | remove_doc_from_localstorage: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1815 | var me = this; |
| 1816 | this.si_docs = this.get_doc_from_localstorage(); |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1817 | this.new_si_docs = []; |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 1818 | if (this.removed_items) { |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1819 | $.each(this.si_docs, function (index, data) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1820 | for (var key in data) { |
Rohit Waghchaure | 017f500 | 2017-03-08 17:34:39 +0530 | [diff] [blame] | 1821 | if (!in_list(me.removed_items, key)) { |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1822 | me.new_si_docs.push(data); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1823 | } |
| 1824 | } |
| 1825 | }) |
Rohit Waghchaure | 87fa59a | 2017-03-10 14:56:19 +0530 | [diff] [blame] | 1826 | this.removed_items = []; |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 1827 | this.si_docs = this.new_si_docs; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1828 | this.update_localstorage(); |
| 1829 | } |
| 1830 | }, |
| 1831 | |
Rohit Waghchaure | b5097ec | 2017-03-01 01:13:09 +0530 | [diff] [blame] | 1832 | remove_email_queue_from_localstorage: function() { |
| 1833 | var me = this; |
| 1834 | this.email_queue = this.get_email_queue() |
| 1835 | if (this.removed_email) { |
| 1836 | $.each(this.email_queue_list, function (index, data) { |
| 1837 | if (in_list(me.removed_email, index)) { |
| 1838 | delete me.email_queue[index] |
| 1839 | } |
| 1840 | }) |
| 1841 | this.update_email_queue(); |
| 1842 | } |
| 1843 | }, |
| 1844 | |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 1845 | remove_customer_from_localstorage: function() { |
| 1846 | var me = this; |
| 1847 | this.customer_details = this.get_customers_details() |
| 1848 | if (this.removed_customers) { |
| 1849 | $.each(this.customers_list, function (index, data) { |
| 1850 | if (in_list(me.removed_customers, index)) { |
| 1851 | delete me.customer_details[index] |
| 1852 | } |
| 1853 | }) |
| 1854 | this.update_customer_in_localstorage(); |
| 1855 | } |
| 1856 | }, |
| 1857 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1858 | validate: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1859 | var me = this; |
| 1860 | this.customer_validate(); |
Rohit Waghchaure | 07f75a3 | 2019-01-29 12:01:54 +0530 | [diff] [blame] | 1861 | this.validate_zero_qty_items(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1862 | this.item_validate(); |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1863 | this.validate_mode_of_payments(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1864 | }, |
| 1865 | |
Rohit Waghchaure | 07f75a3 | 2019-01-29 12:01:54 +0530 | [diff] [blame] | 1866 | validate_zero_qty_items: function() { |
| 1867 | this.remove_item = []; |
| 1868 | |
| 1869 | this.frm.doc.items.forEach(d => { |
| 1870 | if (d.qty == 0) { |
| 1871 | this.remove_item.push(d.idx); |
| 1872 | } |
| 1873 | }); |
| 1874 | |
| 1875 | if(this.remove_item) { |
| 1876 | this.remove_zero_qty_items_from_cart(); |
| 1877 | } |
| 1878 | }, |
| 1879 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1880 | item_validate: function () { |
| 1881 | if (this.frm.doc.items.length == 0) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1882 | frappe.throw(__("Select items to save the invoice")) |
| 1883 | } |
| 1884 | }, |
Rushabh Mehta | 512b85e | 2016-12-27 12:14:26 +0530 | [diff] [blame] | 1885 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1886 | validate_mode_of_payments: function () { |
| 1887 | if (this.frm.doc.payments.length === 0) { |
Saurabh | 9a6c666 | 2016-06-27 16:51:44 +0530 | [diff] [blame] | 1888 | frappe.throw(__("Payment Mode is not configured. Please check, whether account has been set on Mode of Payments or on POS Profile.")) |
| 1889 | } |
| 1890 | }, |
Rushabh Mehta | 512b85e | 2016-12-27 12:14:26 +0530 | [diff] [blame] | 1891 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1892 | validate_serial_no: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1893 | var me = this; |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1894 | var item_code = '' |
| 1895 | var serial_no = ''; |
| 1896 | for (var key in this.item_serial_no) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1897 | item_code = key; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1898 | serial_no = me.item_serial_no[key][0]; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1899 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1900 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1901 | if (this.items[0].has_serial_no && serial_no == "") { |
Rohit Waghchaure | dd58d53 | 2016-12-21 17:23:01 +0530 | [diff] [blame] | 1902 | this.refresh(); |
| 1903 | frappe.throw(__(repl("Error: Serial no is mandatory for item %(item)s", { |
| 1904 | 'item': this.items[0].item_code |
| 1905 | }))) |
| 1906 | } |
| 1907 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1908 | if (item_code && serial_no) { |
| 1909 | $.each(this.frm.doc.items, function (index, data) { |
| 1910 | if (data.item_code == item_code) { |
| 1911 | if (in_list(data.serial_no.split('\n'), serial_no)) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1912 | frappe.throw(__(repl("Serial no %(serial_no)s is already taken", { |
| 1913 | 'serial_no': serial_no |
| 1914 | }))) |
| 1915 | } |
| 1916 | } |
| 1917 | }) |
| 1918 | } |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1919 | }, |
| 1920 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1921 | validate_serial_no_qty: function (args, item_code, field, value) { |
Rohit Waghchaure | e4e69ec | 2016-08-17 16:20:13 +0530 | [diff] [blame] | 1922 | var me = this; |
| 1923 | if (args.item_code == item_code && args.serial_no |
| 1924 | && field == 'qty' && cint(value) != value) { |
| 1925 | args.qty = 0.0; |
| 1926 | this.refresh(); |
| 1927 | frappe.throw(__("Serial no item cannot be a fraction")) |
| 1928 | } |
| 1929 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1930 | if (args.item_code == item_code && args.serial_no && args.serial_no.split('\n').length != cint(value)) { |
Rohit Waghchaure | e4e69ec | 2016-08-17 16:20:13 +0530 | [diff] [blame] | 1931 | args.qty = 0.0; |
| 1932 | args.serial_no = '' |
| 1933 | this.refresh(); |
Rohit Waghchaure | dd58d53 | 2016-12-21 17:23:01 +0530 | [diff] [blame] | 1934 | frappe.throw(__(repl("Total nos of serial no is not equal to quantity for item %(item)s.", { |
| 1935 | 'item': item_code |
| 1936 | }))) |
Rohit Waghchaure | e4e69ec | 2016-08-17 16:20:13 +0530 | [diff] [blame] | 1937 | } |
| 1938 | }, |
| 1939 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1940 | mandatory_batch_no: function () { |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 1941 | var me = this; |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1942 | if (this.items[0].has_batch_no && !this.item_batch_no[this.items[0].item_code]) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1943 | frappe.prompt([{ |
| 1944 | 'fieldname': 'batch', |
| 1945 | 'fieldtype': 'Select', |
| 1946 | 'label': __('Batch No'), |
| 1947 | 'reqd': 1, |
| 1948 | 'options': this.batch_no_data[this.items[0].item_code] |
| 1949 | }], |
| 1950 | function(values){ |
| 1951 | me.item_batch_no[me.items[0].item_code] = values.batch; |
| 1952 | }, |
| 1953 | __('Select Batch No')) |
| 1954 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1955 | }, |
| 1956 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1957 | apply_pricing_rule: function () { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1958 | var me = this; |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1959 | $.each(this.frm.doc["items"], function (n, item) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1960 | var pricing_rule = me.get_pricing_rule(item) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1961 | me.validate_pricing_rule(pricing_rule) |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1962 | if (pricing_rule.length) { |
| 1963 | item.pricing_rule = pricing_rule[0].name; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1964 | item.margin_type = pricing_rule[0].margin_type; |
| 1965 | item.price_list_rate = pricing_rule[0].price || item.price_list_rate; |
| 1966 | item.margin_rate_or_amount = pricing_rule[0].margin_rate_or_amount; |
| 1967 | item.discount_percentage = pricing_rule[0].discount_percentage || 0.0; |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 1968 | me.apply_pricing_rule_on_item(item) |
| 1969 | } else if (item.pricing_rule) { |
| 1970 | item.price_list_rate = me.price_list_data[item.item_code] |
Rohit Waghchaure | 619c40b | 2016-11-07 15:29:17 +0530 | [diff] [blame] | 1971 | item.margin_rate_or_amount = 0.0; |
| 1972 | item.discount_percentage = 0.0; |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1973 | item.pricing_rule = null; |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 1974 | me.apply_pricing_rule_on_item(item) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1975 | } |
Charles-Henri Decultot | 8bec023 | 2017-05-19 12:32:30 +0200 | [diff] [blame] | 1976 | |
Rohit Waghchaure | f0c7ba4 | 2017-02-28 16:51:17 +0530 | [diff] [blame] | 1977 | if(item.discount_percentage > 0) { |
| 1978 | me.apply_pricing_rule_on_item(item) |
| 1979 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1980 | }) |
| 1981 | }, |
| 1982 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1983 | get_pricing_rule: function (item) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1984 | var me = this; |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1985 | return $.grep(this.pricing_rules, function (data) { |
| 1986 | if (item.qty >= data.min_qty && (item.qty <= (data.max_qty ? data.max_qty : item.qty))) { |
Rohit Waghchaure | d7de3c6 | 2017-04-17 13:36:08 +0530 | [diff] [blame] | 1987 | if (me.validate_item_condition(data, item)) { |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1988 | if (in_list(['Customer', 'Customer Group', 'Territory', 'Campaign'], data.applicable_for)) { |
Rohit Waghchaure | baef262 | 2016-08-05 15:41:36 +0530 | [diff] [blame] | 1989 | return me.validate_condition(data) |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 1990 | } else { |
Rohit Waghchaure | baef262 | 2016-08-05 15:41:36 +0530 | [diff] [blame] | 1991 | return true |
| 1992 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1993 | } |
| 1994 | } |
| 1995 | }) |
| 1996 | }, |
| 1997 | |
Rohit Waghchaure | d7de3c6 | 2017-04-17 13:36:08 +0530 | [diff] [blame] | 1998 | validate_item_condition: function (data, item) { |
| 1999 | var apply_on = frappe.model.scrub(data.apply_on); |
| 2000 | |
| 2001 | return (data.apply_on == 'Item Group') |
| 2002 | ? this.validate_item_group(data.item_group, item.item_group) : (data[apply_on] == item[apply_on]); |
| 2003 | }, |
| 2004 | |
| 2005 | validate_item_group: function (pr_item_group, cart_item_group) { |
| 2006 | //pr_item_group = pricing rule's item group |
| 2007 | //cart_item_group = cart item's item group |
| 2008 | //this.item_groups has information about item group's lft and rgt |
| 2009 | //for example: {'Foods': [12, 19]} |
| 2010 | |
| 2011 | pr_item_group = this.item_groups[pr_item_group] |
| 2012 | cart_item_group = this.item_groups[cart_item_group] |
| 2013 | |
| 2014 | return (cart_item_group[0] >= pr_item_group[0] && |
| 2015 | cart_item_group[1] <= pr_item_group[1]) |
| 2016 | }, |
| 2017 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 2018 | validate_condition: function (data) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 2019 | //This method check condition based on applicable for |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 2020 | var condition = this.get_mapper_for_pricing_rule(data)[data.applicable_for] |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 2021 | if (in_list(condition[1], condition[0])) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 2022 | return true |
| 2023 | } |
| 2024 | }, |
| 2025 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 2026 | get_mapper_for_pricing_rule: function (data) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 2027 | return { |
Rohit Waghchaure | 89ee309 | 2016-07-08 15:17:04 +0530 | [diff] [blame] | 2028 | 'Customer': [data.customer, [this.frm.doc.customer]], |
| 2029 | 'Customer Group': [data.customer_group, [this.frm.doc.customer_group, 'All Customer Groups']], |
| 2030 | 'Territory': [data.territory, [this.frm.doc.territory, 'All Territories']], |
Rohit Waghchaure | baef262 | 2016-08-05 15:41:36 +0530 | [diff] [blame] | 2031 | 'Campaign': [data.campaign, [this.frm.doc.campaign]], |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 2032 | } |
| 2033 | }, |
| 2034 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 2035 | validate_pricing_rule: function (pricing_rule) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 2036 | //This method validate duplicate pricing rule |
| 2037 | var pricing_rule_name = ''; |
| 2038 | var priority = 0; |
| 2039 | var pricing_rule_list = []; |
| 2040 | var priority_list = [] |
| 2041 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 2042 | if (pricing_rule.length > 1) { |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 2043 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 2044 | $.each(pricing_rule, function (index, data) { |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 2045 | pricing_rule_name += data.name + ',' |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 2046 | priority_list.push(data.priority) |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 2047 | if (priority <= data.priority) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 2048 | priority = data.priority |
| 2049 | pricing_rule_list.push(data) |
| 2050 | } |
| 2051 | }) |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 2052 | |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 2053 | var count = 0 |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 2054 | $.each(priority_list, function (index, value) { |
| 2055 | if (value == priority) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 2056 | count++ |
| 2057 | } |
| 2058 | }) |
| 2059 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 2060 | if (priority == 0 || count > 1) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 2061 | frappe.throw(__(repl("Multiple Price Rules exists with same criteria, please resolve conflict by assigning priority. Price Rules: %(pricing_rule)s", { |
| 2062 | 'pricing_rule': pricing_rule_name |
| 2063 | }))) |
| 2064 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 2065 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 2066 | return pricing_rule_list |
| 2067 | } |
| 2068 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 2069 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 2070 | validate_warehouse: function () { |
| 2071 | if (this.items[0].is_stock_item && !this.items[0].default_warehouse && !this.pos_profile_data['warehouse']) { |
Neil Trini Lasrado | 5ddd7ac | 2016-10-24 15:25:33 +0530 | [diff] [blame] | 2072 | frappe.throw(__("Default warehouse is required for selected item")) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 2073 | } |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 2074 | }, |
| 2075 | |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 2076 | get_actual_qty: function (item) { |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 2077 | this.actual_qty = 0.0; |
Rohit Waghchaure | 80f5bb6 | 2016-11-27 12:04:12 +0530 | [diff] [blame] | 2078 | |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 2079 | var warehouse = this.pos_profile_data['warehouse'] || item.default_warehouse; |
rohitwaghchaure | c13dbd4 | 2017-02-01 18:07:22 +0530 | [diff] [blame] | 2080 | if (warehouse && this.bin_data[item.item_code]) { |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 2081 | this.actual_qty = this.bin_data[item.item_code][warehouse] || 0; |
Rohit Waghchaure | 80f5bb6 | 2016-11-27 12:04:12 +0530 | [diff] [blame] | 2082 | this.actual_qty_dict[item.item_code] = this.actual_qty |
Rohit Waghchaure | a27c417 | 2016-11-20 23:41:13 +0530 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | return this.actual_qty |
Rohit Waghchaure | 1312fe3 | 2017-03-07 14:01:04 +0530 | [diff] [blame] | 2086 | }, |
| 2087 | |
| 2088 | update_customer_in_localstorage: function() { |
| 2089 | var me = this; |
| 2090 | try { |
| 2091 | localStorage.setItem('customer_details', JSON.stringify(this.customer_details)); |
| 2092 | } catch (e) { |
| 2093 | frappe.throw(__("LocalStorage is full , did not save")) |
| 2094 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 2095 | } |
Saurabh | 1a4d77a | 2018-02-08 01:32:48 +0530 | [diff] [blame] | 2096 | }) |