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