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 | |
Rushabh Mehta | 06fa46f | 2015-01-29 18:09:11 +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 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +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 | wrapper.pos.on_refresh_page() |
| 19 | } |
| 20 | |
| 21 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 22 | erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 23 | init: function(wrapper){ |
| 24 | this.load = true; |
| 25 | this.page = wrapper.page; |
| 26 | this.wrapper = $(wrapper).find('.page-content'); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 27 | this.set_indicator(); |
| 28 | this.onload(); |
| 29 | this.make_menu_list(); |
| 30 | this.set_interval_for_si_sync(); |
| 31 | this.si_docs = this.get_doc_from_localstorage(); |
| 32 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 33 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 34 | on_refresh_page: function() { |
| 35 | var me = this; |
| 36 | if(this.load){ |
| 37 | this.load = false; |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 38 | }else if(this.connection_status){ |
| 39 | this.onload(); |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 40 | }else{ |
| 41 | this.create_new(); |
| 42 | } |
| 43 | }, |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 44 | |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 45 | beforeunload: function(e){ |
| 46 | if(this.connection_status == false && frappe.get_route()[0] == "pos"){ |
| 47 | e = e || window.event; |
| 48 | |
| 49 | // For IE and Firefox prior to version 4 |
| 50 | if (e) { |
| 51 | e.returnValue = __("You are in offline mode. You will not be able to reload until you have network."); |
| 52 | return |
| 53 | } |
| 54 | |
| 55 | // For Safari |
| 56 | return __("You are in offline mode. You will not be able to reload until you have network."); |
| 57 | } |
| 58 | }, |
| 59 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 60 | check_internet_connection: function(){ |
| 61 | var me = this; |
| 62 | //Check Internet connection after every 30 seconds |
| 63 | setInterval(function(){ |
| 64 | me.set_indicator(); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 65 | }, 5000) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 66 | }, |
| 67 | |
| 68 | set_indicator: function(){ |
| 69 | var me = this; |
| 70 | // navigator.onLine |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 71 | this.connection_status = false; |
Rohit Waghchaure | 26cf01a | 2016-07-22 13:24:33 +0530 | [diff] [blame] | 72 | this.page.set_indicator(__("Offline"), "grey") |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 73 | frappe.call({ |
| 74 | method:"frappe.handler.ping", |
| 75 | callback: function(r){ |
| 76 | if(r.message){ |
| 77 | me.connection_status = true; |
Rohit Waghchaure | 26cf01a | 2016-07-22 13:24:33 +0530 | [diff] [blame] | 78 | me.page.set_indicator(__("Online"), "green") |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | }) |
| 82 | }, |
| 83 | |
| 84 | onload: function(){ |
| 85 | var me = this; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 86 | this.get_data_from_server(function(){ |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 87 | me.create_new(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 88 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 89 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 90 | this.check_internet_connection(); |
| 91 | }, |
| 92 | |
| 93 | make_menu_list: function(){ |
| 94 | var me = this; |
| 95 | |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 96 | this.page.add_menu_item(__("New Sales Invoice"), function() { |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 97 | me.save_previous_entry(); |
| 98 | me.create_new(); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 99 | }) |
| 100 | |
| 101 | this.page.add_menu_item(__("View Offline Records"), function(){ |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 102 | me.show_unsync_invoice_list(); |
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 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 105 | this.page.add_menu_item(__("Sync Master Data"), function(){ |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 106 | me.get_data_from_server(function(){ |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 107 | me.load_data(false); |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 108 | me.make_customer(); |
| 109 | me.make_item_list(); |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 110 | me.set_missing_values(); |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 111 | }) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 112 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 113 | |
| 114 | this.page.add_menu_item(__("POS Profile"), function() { |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 115 | frappe.set_route('List', 'POS Profile'); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 116 | }); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 117 | }, |
| 118 | |
| 119 | show_unsync_invoice_list: function(){ |
| 120 | var me = this; |
| 121 | this.si_docs = this.get_doc_from_localstorage(); |
| 122 | |
| 123 | this.list_dialog = new frappe.ui.Dialog({ |
| 124 | title: 'Invoice List' |
| 125 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 126 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 127 | this.list_dialog.show(); |
| 128 | this.list_body = this.list_dialog.body; |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 129 | if(this.si_docs.length > 0){ |
| 130 | $(this.list_body).append('<div class="row list-row list-row-head pos-invoice-list">\ |
| 131 | <div class="col-xs-2">Sr</div>\ |
| 132 | <div class="col-xs-4">Customer</div>\ |
| 133 | <div class="col-xs-2 text-left">Status</div>\ |
| 134 | <div class="col-xs-4 text-right">Grand Total</div>\ |
| 135 | </div>') |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 136 | |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 137 | $.each(this.si_docs, function(index, data){ |
| 138 | for(key in data) { |
| 139 | $(frappe.render_template("pos_invoice_list", { |
| 140 | sr: index + 1, |
| 141 | name: key, |
| 142 | customer: data[key].customer, |
| 143 | grand_total: format_currency(data[key].grand_total, me.frm.doc.currency), |
| 144 | data: me.get_doctype_status(data[key]) |
| 145 | })).appendTo($(me.list_body)); |
| 146 | } |
| 147 | }) |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 148 | |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 149 | $(this.list_body).find('.list-row').click(function() { |
| 150 | me.name = $(this).attr('invoice-name') |
| 151 | doc_data = me.get_invoice_doc(me.si_docs) |
| 152 | if(doc_data){ |
| 153 | me.frm.doc = doc_data[0][me.name]; |
| 154 | me.set_missing_values(); |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 155 | me.refresh(false); |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 156 | me.disable_input_field(); |
| 157 | me.list_dialog.hide(); |
| 158 | } |
| 159 | }) |
| 160 | }else{ |
| 161 | $(this.list_body).append(repl('<div class="media-heading">%(message)s</div>', {'message': __("All records are synced.")})) |
| 162 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 163 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 164 | |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 165 | get_doctype_status: function(doc){ |
| 166 | if(doc.outstanding_amount == 0){ |
| 167 | return {status: "Paid", indicator: "green"} |
| 168 | }else if(doc.docstatus == 0){ |
| 169 | return {status: "Draft", indicator: "red"} |
| 170 | }else if(doc.paid_amount >= 0){ |
| 171 | return {status: "Unpaid", indicator: "orange"} |
| 172 | } |
| 173 | }, |
| 174 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 175 | set_missing_values: function(){ |
| 176 | var me = this; |
| 177 | doc = JSON.parse(localStorage.getItem('doc')) |
| 178 | if(this.frm.doc.payments.length == 0){ |
| 179 | this.frm.doc.payments = doc.payments; |
Rohit Waghchaure | b77a105 | 2016-08-01 18:35:18 +0530 | [diff] [blame] | 180 | this.calculate_outstanding_amount(); |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 181 | } |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 182 | |
| 183 | if(this.frm.doc.customer){ |
| 184 | this.party_field.$input.val(this.frm.doc.customer); |
| 185 | } |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 186 | }, |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 187 | |
| 188 | get_invoice_doc: function(si_docs){ |
| 189 | var me = this; |
| 190 | this.si_docs = this.get_doc_from_localstorage(); |
| 191 | |
| 192 | return $.grep(this.si_docs, function(data){ |
| 193 | for(key in data){ |
| 194 | return key == me.name |
| 195 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 196 | }) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 197 | }, |
| 198 | |
| 199 | get_data_from_server: function(callback){ |
| 200 | var me = this; |
| 201 | frappe.call({ |
| 202 | method: "erpnext.accounts.doctype.sales_invoice.pos.get_pos_data", |
| 203 | freeze: true, |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 204 | freeze_message: __("Master data syncing, it might take some time"), |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 205 | callback: function(r){ |
| 206 | window.items = r.message.items; |
| 207 | window.customers = r.message.customers; |
| 208 | window.pricing_rules = r.message.pricing_rules; |
| 209 | window.meta = r.message.meta; |
| 210 | window.print_template = r.message.print_template; |
Rohit Waghchaure | 539e913 | 2016-07-07 16:44:40 +0530 | [diff] [blame] | 211 | me.default_customer = r.message.default_customer || null; |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 212 | me.write_off_account = r.message.write_off_account; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 213 | localStorage.setItem('doc', JSON.stringify(r.message.doc)); |
| 214 | if(callback){ |
| 215 | callback(); |
| 216 | } |
| 217 | } |
| 218 | }) |
| 219 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 220 | |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 221 | save_previous_entry : function(){ |
| 222 | if(this.frm.doc.items.length > 0){ |
| 223 | this.create_invoice() |
| 224 | } |
| 225 | }, |
| 226 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 227 | create_new: function(){ |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 228 | var me = this; |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 229 | this.frm = {} |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 230 | this.name = ''; |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 231 | this.load_data(true); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 232 | this.setup(); |
| 233 | }, |
| 234 | |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 235 | load_data: function(load_doc){ |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 236 | this.items = window.items; |
| 237 | this.customers = window.customers; |
| 238 | this.pricing_rules = window.pricing_rules; |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 239 | |
| 240 | if(load_doc) { |
| 241 | this.frm.doc = JSON.parse(localStorage.getItem('doc')); |
| 242 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 243 | |
| 244 | $.each(window.meta, function(i, data){ |
| 245 | frappe.meta.sync(data) |
| 246 | }) |
| 247 | |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 248 | this.print_template = frappe.render_template("print_template", |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 249 | {content: window.print_template, title:"POS"}) |
| 250 | }, |
| 251 | |
| 252 | setup: function(){ |
| 253 | this.wrapper.html(frappe.render_template("pos", this.frm.doc)); |
| 254 | this.set_transaction_defaults("Customer"); |
| 255 | this.make(); |
| 256 | this.set_primary_action(); |
| 257 | }, |
| 258 | |
| 259 | set_transaction_defaults: function(party) { |
| 260 | var me = this; |
| 261 | this.party = party; |
| 262 | this.price_list = (party == "Customer" ? |
| 263 | this.frm.doc.selling_price_list : this.frm.doc.buying_price_list); |
| 264 | this.price_list_field = (party == "Customer" ? "selling_price_list" : "buying_price_list"); |
| 265 | this.sales_or_purchase = (party == "Customer" ? "Sales" : "Purchase"); |
| 266 | }, |
| 267 | |
| 268 | make: function() { |
| 269 | this.make_search(); |
| 270 | this.make_customer(); |
| 271 | this.make_item_list(); |
| 272 | this.make_discount_field() |
| 273 | }, |
| 274 | |
| 275 | make_search: function() { |
| 276 | var me = this; |
| 277 | this.search = frappe.ui.form.make_control({ |
| 278 | df: { |
| 279 | "fieldtype": "Data", |
| 280 | "label": "Item", |
| 281 | "fieldname": "pos_item", |
Rohit Waghchaure | 26cf01a | 2016-07-22 13:24:33 +0530 | [diff] [blame] | 282 | "placeholder": __("Search Item") |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 283 | }, |
| 284 | parent: this.wrapper.find(".search-area"), |
| 285 | only_input: true, |
| 286 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 287 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 288 | this.search.make_input(); |
| 289 | this.search.$input.on("keyup", function() { |
| 290 | setTimeout(function() { |
| 291 | me.items = me.get_items(); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 292 | me.make_item_list(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 293 | }, 1000); |
| 294 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 295 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 296 | this.party_field = frappe.ui.form.make_control({ |
| 297 | df: { |
| 298 | "fieldtype": "Data", |
| 299 | "options": this.party, |
| 300 | "label": this.party, |
| 301 | "fieldname": this.party.toLowerCase(), |
Rushabh Mehta | e0686b3 | 2016-06-10 12:34:41 +0530 | [diff] [blame] | 302 | "placeholder": __("Select or add new customer") |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 303 | }, |
| 304 | parent: this.wrapper.find(".party-area"), |
| 305 | only_input: true, |
| 306 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 307 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 308 | this.party_field.make_input(); |
| 309 | }, |
| 310 | |
| 311 | make_customer: function() { |
| 312 | var me = this; |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 313 | |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 314 | if(this.default_customer && !this.frm.doc.customer){ |
Rohit Waghchaure | 539e913 | 2016-07-07 16:44:40 +0530 | [diff] [blame] | 315 | this.party_field.$input.val(this.default_customer); |
| 316 | this.frm.doc.customer = this.default_customer; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 317 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 318 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 319 | this.party_field.$input.autocomplete({ |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 320 | autoFocus: true, |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 321 | source: function (request, response) { |
| 322 | me.customer_data = me.get_customers(request.term) |
| 323 | response($.map(me.customer_data, function(data){ |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 324 | return {label: data.name, value: data.name, |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 325 | customer_group: data.customer_group, territory: data.territory} |
| 326 | })) |
| 327 | }, |
| 328 | change: function(event, ui){ |
| 329 | if(ui.item){ |
| 330 | me.frm.doc.customer = ui.item.label; |
| 331 | me.frm.doc.customer_name = ui.item.customer_name; |
| 332 | me.frm.doc.customer_group = ui.item.customer_group; |
| 333 | me.frm.doc.territory = ui.item.territory; |
| 334 | }else{ |
| 335 | me.frm.doc.customer = me.party_field.$input.val(); |
| 336 | } |
| 337 | me.refresh(); |
| 338 | } |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 339 | }).on("focus", function(){ |
| 340 | setTimeout(function() { |
| 341 | if(!me.party_field.$input.val()) { |
| 342 | me.party_field.$input.autocomplete( "search", " " ); |
| 343 | } |
| 344 | }, 500); |
| 345 | }); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 346 | }, |
| 347 | |
| 348 | get_customers: function(key){ |
| 349 | var me = this; |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 350 | key = key.toLowerCase().trim() |
| 351 | if(key){ |
| 352 | return $.grep(this.customers, function(data) { |
| 353 | if(data.name.toLowerCase().match(key) |
| 354 | || data.customer_name.toLowerCase().match(key) |
| 355 | || (data.customer_group && data.customer_group.toLowerCase().match(key))){ |
| 356 | return data |
| 357 | } |
| 358 | }) |
| 359 | }else{ |
| 360 | customers = this.customers.sort(function(a,b){ return a.idx < b.idx }) |
| 361 | return customers.slice(0, 20) |
| 362 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 363 | }, |
| 364 | |
| 365 | make_item_list: function() { |
| 366 | var me = this; |
| 367 | if(!this.price_list) { |
| 368 | msgprint(__("Price List not found or disabled")); |
| 369 | return; |
| 370 | } |
| 371 | |
| 372 | me.item_timeout = null; |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 373 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 374 | var $wrap = me.wrapper.find(".item-list"); |
| 375 | me.wrapper.find(".item-list").empty(); |
| 376 | |
| 377 | if (this.items) { |
| 378 | $.each(this.items, function(index, obj) { |
| 379 | if(index < 16){ |
| 380 | $(frappe.render_template("pos_item", { |
| 381 | item_code: obj.name, |
| 382 | item_price: format_currency(obj.price_list_rate, obj.currency), |
| 383 | item_name: obj.name===obj.item_name ? "" : obj.item_name, |
| 384 | item_image: obj.image ? "url('" + obj.image + "')" : null, |
| 385 | color: frappe.get_palette(obj.item_name), |
| 386 | abbr: frappe.get_abbr(obj.item_name) |
| 387 | })).tooltip().appendTo($wrap); |
| 388 | } |
| 389 | }); |
| 390 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 391 | |
Rohit Waghchaure | 28c02fe | 2016-06-10 00:48:03 +0530 | [diff] [blame] | 392 | if(this.items.length == 1 |
| 393 | && this.search.$input.val()) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 394 | this.search.$input.val(""); |
| 395 | this.add_to_cart(); |
| 396 | } |
| 397 | |
| 398 | // if form is local then allow this function |
| 399 | $(me.wrapper).find("div.pos-item").on("click", function() { |
| 400 | me.customer_validate(); |
| 401 | if(me.frm.doc.docstatus==0) { |
| 402 | me.items = me.get_items($(this).attr("data-item-code")) |
| 403 | me.add_to_cart(); |
| 404 | } |
| 405 | }); |
| 406 | }, |
| 407 | |
| 408 | get_items: function(item_code){ |
| 409 | // To search item as per the key enter |
| 410 | |
| 411 | var me = this; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 412 | this.item_serial_no = {}; |
| 413 | this.item_batch_no = {}; |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 414 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 415 | if(item_code){ |
| 416 | return $.grep(window.items, function(item){ |
| 417 | if(item.item_code == item_code ){ |
| 418 | return true |
| 419 | } |
| 420 | }) |
| 421 | } |
| 422 | |
| 423 | key = this.search.$input.val().toLowerCase(); |
| 424 | |
| 425 | if(key){ |
| 426 | return $.grep(window.items, function(item){ |
Rohit Waghchaure | a88dec8 | 2016-07-30 16:49:48 +0530 | [diff] [blame] | 427 | if(in_list(item.batch_nos, me.search.$input.val())){ |
| 428 | return me.item_batch_no[item.item_code] = me.search.$input.val() |
| 429 | } else if((item.item_code.toLowerCase().match(key)) || |
| 430 | (item.item_name.toLowerCase().match(key)) || (item.item_group.toLowerCase().match(key))){ |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 431 | return true |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 432 | }else if(item.barcode == me.search.$input.val()){ |
| 433 | return item.barcode == me.search.$input.val(); |
| 434 | } else if (in_list(Object.keys(item.serial_nos), me.search.$input.val())){ |
| 435 | me.item_serial_no[item.item_code] = [me.search.$input.val(), item.serial_nos[me.search.$input.val()]] |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 436 | return true |
| 437 | } |
| 438 | }) |
| 439 | }else{ |
| 440 | return window.items; |
| 441 | } |
| 442 | }, |
| 443 | |
| 444 | update_qty: function() { |
| 445 | var me = this; |
| 446 | |
| 447 | $(this.wrapper).find(".pos-item-qty").on("change", function(){ |
| 448 | var item_code = $(this).parents(".pos-bill-item").attr("data-item-code"); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 449 | me.update_qty_rate_against_item_code(item_code, "qty", $(this).val()); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 450 | }) |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 451 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 452 | $(this.wrapper).find("[data-action='increase-qty']").on("click", function(){ |
| 453 | var item_code = $(this).parents(".pos-bill-item").attr("data-item-code"); |
| 454 | var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) + 1; |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 455 | me.update_qty_rate_against_item_code(item_code, "qty", qty); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 456 | }) |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 457 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 458 | $(this.wrapper).find("[data-action='decrease-qty']").on("click", function(){ |
| 459 | var item_code = $(this).parents(".pos-bill-item").attr("data-item-code"); |
| 460 | var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) - 1; |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 461 | me.update_qty_rate_against_item_code(item_code, "qty", qty); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 462 | }) |
| 463 | }, |
| 464 | |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 465 | update_rate: function() { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 466 | var me = this; |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 467 | |
| 468 | $(this.wrapper).find(".pos-item-rate").on("change", function(){ |
| 469 | var item_code = $(this).parents(".pos-bill-item").attr("data-item-code"); |
| 470 | me.update_qty_rate_against_item_code(item_code, "rate", $(this).val()); |
| 471 | }) |
| 472 | }, |
| 473 | |
| 474 | update_qty_rate_against_item_code: function(item_code, field, value){ |
| 475 | var me = this; |
| 476 | if(value < 0){ |
| 477 | frappe.throw(__("Enter value must be positive")); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 478 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 479 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 480 | this.remove_item = [] |
| 481 | $.each(this.frm.doc["items"] || [], function(i, d) { |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 482 | if (d.item_code == item_code && d.serial_no |
| 483 | && field == 'qty' && cint(value) != value) { |
| 484 | d.qty = 0.0; |
| 485 | me.refresh(); |
| 486 | frappe.throw(__("Serial no item cannot be a fraction")) |
| 487 | } |
| 488 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 489 | if (d.item_code == item_code) { |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 490 | d[field] = flt(value); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 491 | d.amount = flt(d.rate) * flt(d.qty); |
| 492 | if(d.qty==0){ |
| 493 | me.remove_item.push(d.idx) |
| 494 | } |
| 495 | } |
| 496 | }); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 497 | |
| 498 | if(field == 'qty'){ |
| 499 | this.remove_zero_qty_item(); |
| 500 | } |
| 501 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 502 | this.refresh(); |
| 503 | }, |
| 504 | |
| 505 | remove_zero_qty_item: function(){ |
| 506 | var me = this; |
| 507 | idx = 0 |
| 508 | this.items = [] |
| 509 | idx = 0 |
| 510 | $.each(this.frm.doc["items"] || [], function(i, d) { |
| 511 | if(!in_list(me.remove_item, d.idx)){ |
| 512 | d.idx = idx; |
| 513 | me.items.push(d); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 514 | idx++; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 515 | } |
| 516 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 517 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 518 | this.frm.doc["items"] = this.items; |
| 519 | }, |
| 520 | |
| 521 | make_discount_field: function(){ |
| 522 | var me = this; |
| 523 | |
| 524 | this.wrapper.find('input.discount-percentage').on("change", function() { |
| 525 | me.frm.doc.additional_discount_percentage = flt($(this).val(), precision("additional_discount_percentage")); |
| 526 | total = me.frm.doc.grand_total |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 527 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 528 | if(me.frm.doc.apply_discount_on == 'Net Total'){ |
| 529 | total = me.frm.doc.net_total |
| 530 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 531 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 532 | me.frm.doc.discount_amount = flt(total*flt(me.frm.doc.additional_discount_percentage) / 100, precision("discount_amount")); |
| 533 | me.wrapper.find('input.discount-amount').val(me.frm.doc.discount_amount) |
| 534 | me.refresh(); |
| 535 | }); |
| 536 | |
| 537 | this.wrapper.find('input.discount-amount').on("change", function() { |
| 538 | me.frm.doc.discount_amount = flt($(this).val(), precision("discount_amount")); |
| 539 | me.frm.doc.additional_discount_percentage = 0.0; |
| 540 | me.wrapper.find('input.discount-percentage').val(0); |
| 541 | me.refresh(); |
| 542 | }); |
| 543 | }, |
| 544 | |
| 545 | customer_validate: function(){ |
| 546 | var me = this; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 547 | if(!this.frm.doc.customer){ |
| 548 | frappe.throw(__("Please select customer")) |
| 549 | } |
| 550 | }, |
| 551 | |
| 552 | add_to_cart: function() { |
| 553 | var me = this; |
| 554 | var caught = false; |
| 555 | var no_of_items = me.wrapper.find(".pos-bill-item").length; |
| 556 | |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 557 | this.customer_validate(); |
| 558 | this.mandatory_batch_no(); |
| 559 | this.validate_serial_no(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 560 | this.validate_warehouse(); |
| 561 | |
| 562 | if (no_of_items != 0) { |
| 563 | $.each(this.frm.doc["items"] || [], function(i, d) { |
| 564 | if (d.item_code == me.items[0].item_code) { |
| 565 | caught = true; |
| 566 | d.qty += 1; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 567 | d.amount = flt(d.rate) * flt(d.qty); |
| 568 | if(me.item_serial_no[d.item_code]){ |
| 569 | d.serial_no += '\n' + me.item_serial_no[d.item_code][0] |
| 570 | d.warehouse = me.item_serial_no[d.item_code][1] |
| 571 | } |
| 572 | |
| 573 | if(me.item_batch_no.length){ |
| 574 | d.batch_no = me.item_batch_no[d.item_code] |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 575 | } |
| 576 | } |
| 577 | }); |
| 578 | } |
| 579 | |
| 580 | // if item not found then add new item |
| 581 | if (!caught) |
| 582 | this.add_new_item_to_grid(); |
| 583 | |
| 584 | this.refresh(); |
| 585 | }, |
| 586 | |
| 587 | add_new_item_to_grid: function() { |
| 588 | var me = this; |
| 589 | this.child = frappe.model.add_child(this.frm.doc, this.frm.doc.doctype + " Item", "items"); |
| 590 | this.child.item_code = this.items[0].item_code; |
| 591 | this.child.item_name = this.items[0].item_name; |
| 592 | this.child.stock_uom = this.items[0].stock_uom; |
| 593 | this.child.description = this.items[0].description; |
| 594 | this.child.qty = 1; |
| 595 | this.child.item_group = this.items[0].item_group; |
| 596 | this.child.cost_center = this.items[0].cost_center; |
| 597 | this.child.income_account = this.items[0].income_account; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 598 | this.child.warehouse = (this.item_serial_no[this.child.item_code] |
| 599 | ? this.item_serial_no[this.child.item_code][1] : this.items[0].default_warehouse); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 600 | this.child.price_list_rate = flt(this.items[0].price_list_rate, 9) / flt(this.frm.doc.conversion_rate, 9); |
| 601 | this.child.rate = flt(this.items[0].price_list_rate, 9) / flt(this.frm.doc.conversion_rate, 9); |
| 602 | this.child.actual_qty = this.items[0].actual_qty; |
| 603 | this.child.amount = flt(this.child.qty) * flt(this.child.rate); |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 604 | this.child.batch_no = this.item_batch_no[this.child.item_code]; |
| 605 | this.child.serial_no = (this.item_serial_no[this.child.item_code] |
| 606 | ? this.item_serial_no[this.child.item_code][0] : ''); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 607 | }, |
| 608 | |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 609 | refresh: function(update_paid_amount) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 610 | var me = this; |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 611 | this.refresh_fields(update_paid_amount); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 612 | this.update_qty(); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 613 | this.update_rate(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 614 | this.set_primary_action(); |
| 615 | }, |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 616 | refresh_fields: function(update_paid_amount) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 617 | this.apply_pricing_rule(); |
| 618 | this.discount_amount_applied = false; |
| 619 | this._calculate_taxes_and_totals(); |
| 620 | this.calculate_discount_amount(); |
| 621 | this.show_items_in_item_cart(); |
| 622 | this.set_taxes(); |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 623 | this.calculate_outstanding_amount(update_paid_amount); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 624 | this.set_totals(); |
| 625 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 626 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 627 | get_company_currency: function() { |
| 628 | return erpnext.get_currency(this.frm.doc.company); |
| 629 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 630 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 631 | show_item_wise_taxes: function(){ |
| 632 | return null; |
| 633 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 634 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 635 | show_items_in_item_cart: function() { |
| 636 | var me = this; |
| 637 | var $items = this.wrapper.find(".items").empty(); |
| 638 | me.frm.doc.net_total = 0.0 |
| 639 | $.each(this.frm.doc.items|| [], function(i, d) { |
| 640 | $(frappe.render_template("pos_bill_item", { |
| 641 | item_code: d.item_code, |
| 642 | item_name: (d.item_name===d.item_code || !d.item_name) ? "" : ("<br>" + d.item_name), |
| 643 | qty: d.qty, |
| 644 | actual_qty: d.actual_qty, |
| 645 | projected_qty: d.projected_qty, |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 646 | rate: format_number(d.rate, me.frm.doc.currency), |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 647 | amount: format_currency(d.amount, me.frm.doc.currency) |
| 648 | })).appendTo($items); |
| 649 | }); |
| 650 | |
| 651 | this.wrapper.find("input.pos-item-qty").on("focus", function() { |
| 652 | $(this).select(); |
| 653 | }); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 654 | |
| 655 | this.wrapper.find("input.pos-item-rate").on("focus", function() { |
| 656 | $(this).select(); |
| 657 | }); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 658 | }, |
| 659 | |
| 660 | set_taxes: function(){ |
| 661 | var me = this; |
| 662 | me.frm.doc.total_taxes_and_charges = 0.0 |
| 663 | |
| 664 | var taxes = this.frm.doc.taxes || []; |
| 665 | $(this.wrapper) |
| 666 | .find(".tax-area").toggleClass("hide", (taxes && taxes.length) ? false : true) |
| 667 | .find(".tax-table").empty(); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 668 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 669 | $.each(taxes, function(i, d) { |
| 670 | if (d.tax_amount && cint(d.included_in_print_rate) == 0) { |
| 671 | $(frappe.render_template("pos_tax_row", { |
| 672 | description: d.description, |
| 673 | tax_amount: format_currency(flt(d.tax_amount_after_discount_amount), |
| 674 | me.frm.doc.currency) |
| 675 | })).appendTo(me.wrapper.find(".tax-table")); |
| 676 | } |
| 677 | }); |
| 678 | }, |
| 679 | |
| 680 | set_totals: function() { |
| 681 | var me = this; |
| 682 | this.wrapper.find(".net-total").text(format_currency(me.frm.doc.total, me.frm.doc.currency)); |
| 683 | this.wrapper.find(".grand-total").text(format_currency(me.frm.doc.grand_total, me.frm.doc.currency)); |
| 684 | }, |
| 685 | |
| 686 | set_primary_action: function() { |
| 687 | var me = this; |
| 688 | |
Rohit Waghchaure | 61b4a43 | 2016-07-20 11:21:51 +0530 | [diff] [blame] | 689 | if (this.frm.doc.docstatus==0) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 690 | this.page.set_primary_action(__("Pay"), function() { |
| 691 | me.validate() |
| 692 | me.create_invoice(); |
| 693 | me.make_payment(); |
Faris Ansari | 8908d19 | 2016-07-20 13:59:19 +0530 | [diff] [blame] | 694 | }, "octicon octicon-credit-card"); |
Rohit Waghchaure | 61b4a43 | 2016-07-20 11:21:51 +0530 | [diff] [blame] | 695 | }else if(this.frm.doc.docstatus == 1) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 696 | this.page.set_primary_action(__("Print"), function() { |
| 697 | html = frappe.render(me.print_template, me.frm.doc) |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 698 | me.print_document(html) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 699 | }) |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 700 | }else { |
| 701 | this.page.clear_primary_action() |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 702 | } |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 703 | |
| 704 | this.page.set_secondary_action(__("New"), function() { |
| 705 | me.save_previous_entry(); |
| 706 | me.create_new(); |
Faris Ansari | 8908d19 | 2016-07-20 13:59:19 +0530 | [diff] [blame] | 707 | }, "octicon octicon-plus").addClass("btn-primary"); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 708 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 709 | |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 710 | print_document: function(html){ |
| 711 | var w = window.open(); |
| 712 | w.document.write(html); |
| 713 | w.document.close(); |
| 714 | setTimeout(function(){ |
| 715 | w.print(); |
| 716 | w.close(); |
| 717 | }, 1000) |
| 718 | }, |
| 719 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 720 | write_off_amount: function(){ |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 721 | var me = this; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 722 | var value = 0.0; |
| 723 | |
| 724 | if(this.frm.doc.outstanding_amount > 0){ |
| 725 | dialog = new frappe.ui.Dialog({ |
| 726 | title: 'Write Off Amount', |
| 727 | fields: [ |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 728 | {fieldtype: "Check", fieldname: "write_off_amount", label: __("Write off Outstanding Amount")}, |
| 729 | {fieldtype: "Link", options:"Account", default:this.write_off_account, fieldname: "write_off_account", |
| 730 | label: __("Write off Account"), get_query: function() { |
| 731 | return { |
| 732 | filters: {'is_group': 0, 'report_type': 'Profit and Loss'} |
| 733 | } |
| 734 | }} |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 735 | ] |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 736 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 737 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 738 | dialog.show(); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 739 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 740 | dialog.fields_dict.write_off_amount.$input.change(function(){ |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 741 | write_off_amount = dialog.get_values().write_off_amount; |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 742 | me.frm.doc.write_off_outstanding_amount_automatically = write_off_amount; |
| 743 | me.frm.doc.base_write_off_amount = (write_off_amount==1) ? flt(me.frm.doc.grand_total - me.frm.doc.paid_amount, precision("outstanding_amount")) : 0; |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 744 | me.frm.doc.write_off_account = (write_off_amount==1) ? dialog.get_values().write_off_account : ''; |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 745 | me.frm.doc.write_off_amount = flt(me.frm.doc.base_write_off_amount * me.frm.doc.conversion_rate, precision("write_off_amount")) |
| 746 | me.calculate_outstanding_amount(); |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 747 | me.set_primary_action(); |
| 748 | }) |
| 749 | |
| 750 | dialog.fields_dict.write_off_account.$input.change(function(){ |
| 751 | me.frm.doc.write_off_account = dialog.get_values().write_off_account; |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 752 | }) |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 753 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 754 | dialog.set_primary_action(__("Submit"), function(){ |
| 755 | dialog.hide() |
| 756 | me.submit_invoice() |
| 757 | }) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 758 | }else{ |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 759 | this.submit_invoice() |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 760 | } |
| 761 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 762 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 763 | submit_invoice: function(){ |
| 764 | var me = this; |
| 765 | frappe.confirm(__("Do you really want to submit the invoice?"), function () { |
| 766 | me.change_status(); |
Rohit Waghchaure | 53bea82 | 2016-07-06 16:09:26 +0530 | [diff] [blame] | 767 | frappe.msgprint(__("Sales invoice submitted sucessfully.")) |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 768 | }) |
| 769 | }, |
| 770 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 771 | change_status: function(){ |
| 772 | if(this.frm.doc.docstatus == 0){ |
| 773 | this.frm.doc.docstatus = 1; |
| 774 | this.update_invoice(); |
| 775 | this.disable_input_field(); |
| 776 | } |
| 777 | }, |
| 778 | |
| 779 | disable_input_field: function(){ |
| 780 | var pointer_events = 'inherit' |
| 781 | $(this.wrapper).find('input').attr("disabled", false); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 782 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 783 | if(this.frm.doc.docstatus == 1){ |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 784 | pointer_events = 'none'; |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 785 | $(this.wrapper).find('input').attr("disabled", true); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 786 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 787 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 788 | $(this.wrapper).find('.pos-bill-wrapper').css('pointer-events', pointer_events); |
| 789 | $(this.wrapper).find('.pos-items-section').css('pointer-events', pointer_events); |
| 790 | this.set_primary_action(); |
| 791 | }, |
| 792 | |
| 793 | create_invoice: function(){ |
| 794 | var me = this; |
| 795 | var invoice_data = {} |
| 796 | this.si_docs = this.get_doc_from_localstorage(); |
| 797 | if(this.name){ |
| 798 | this.update_invoice() |
| 799 | }else{ |
| 800 | this.name = $.now(); |
| 801 | invoice_data[this.name] = this.frm.doc |
| 802 | this.si_docs.push(invoice_data) |
| 803 | this.update_localstorage(); |
| 804 | this.set_primary_action(); |
| 805 | } |
| 806 | }, |
| 807 | |
| 808 | update_invoice: function(){ |
| 809 | var me = this; |
| 810 | this.si_docs = this.get_doc_from_localstorage(); |
| 811 | $.each(this.si_docs, function(index, data){ |
| 812 | for(key in data){ |
| 813 | if(key == me.name){ |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 814 | me.si_docs[index][key] = me.frm.doc; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 815 | me.update_localstorage(); |
| 816 | } |
| 817 | } |
| 818 | }) |
| 819 | }, |
| 820 | |
| 821 | update_localstorage: function(){ |
| 822 | try{ |
| 823 | localStorage.setItem('sales_invoice_doc', JSON.stringify(this.si_docs)); |
| 824 | }catch(e){ |
| 825 | frappe.throw(__("LocalStorage is full , did not save")) |
| 826 | } |
| 827 | }, |
| 828 | |
| 829 | get_doc_from_localstorage: function(){ |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 830 | try{ |
| 831 | return JSON.parse(localStorage.getItem('sales_invoice_doc')) || []; |
| 832 | }catch(e){ |
| 833 | return [] |
| 834 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 835 | }, |
| 836 | |
| 837 | set_interval_for_si_sync: function(){ |
| 838 | var me = this; |
| 839 | setInterval(function(){ |
| 840 | me.sync_sales_invoice() |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 841 | }, 60000) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 842 | }, |
| 843 | |
| 844 | sync_sales_invoice: function(){ |
| 845 | var me = this; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 846 | this.si_docs = this.get_submitted_invoice(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 847 | |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 848 | if(this.si_docs.length){ |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 849 | frappe.call({ |
| 850 | method: "erpnext.accounts.doctype.sales_invoice.pos.make_invoice", |
| 851 | args: { |
| 852 | doc_list: me.si_docs |
| 853 | }, |
| 854 | callback: function(r){ |
| 855 | if(r.message){ |
| 856 | me.removed_items = r.message; |
| 857 | me.remove_doc_from_localstorage(); |
| 858 | } |
| 859 | } |
| 860 | }) |
| 861 | } |
| 862 | }, |
| 863 | |
| 864 | get_submitted_invoice: function(){ |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 865 | var invoices = []; |
| 866 | var index = 1; |
| 867 | docs = this.get_doc_from_localstorage(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 868 | if(docs){ |
| 869 | invoices = $.map(docs, function(data){ |
| 870 | for(key in data){ |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 871 | if(data[key].docstatus == 1 && index < 50){ |
| 872 | index++ |
Rohit Waghchaure | b77a105 | 2016-08-01 18:35:18 +0530 | [diff] [blame] | 873 | data[key].docstatus = 0; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 874 | return data |
| 875 | } |
| 876 | } |
| 877 | }); |
| 878 | } |
| 879 | |
| 880 | return invoices |
| 881 | }, |
| 882 | |
| 883 | remove_doc_from_localstorage: function(){ |
| 884 | var me = this; |
| 885 | this.si_docs = this.get_doc_from_localstorage(); |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 886 | this.new_si_docs = []; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 887 | if(this.removed_items){ |
| 888 | $.each(this.si_docs, function(index, data){ |
| 889 | for(key in data){ |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 890 | if(!in_list(me.removed_items, key)){ |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 891 | me.new_si_docs.push(data); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | }) |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 895 | this.si_docs = this.new_si_docs; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 896 | this.update_localstorage(); |
| 897 | } |
| 898 | }, |
| 899 | |
| 900 | validate: function(){ |
| 901 | var me = this; |
| 902 | this.customer_validate(); |
| 903 | this.item_validate(); |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 904 | this.validate_mode_of_payments(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 905 | }, |
| 906 | |
| 907 | item_validate: function(){ |
| 908 | if(this.frm.doc.items.length == 0){ |
| 909 | frappe.throw(__("Select items to save the invoice")) |
| 910 | } |
| 911 | }, |
Saurabh | 9a6c666 | 2016-06-27 16:51:44 +0530 | [diff] [blame] | 912 | |
| 913 | validate_mode_of_payments: function(){ |
| 914 | if (this.frm.doc.payments.length === 0){ |
| 915 | frappe.throw(__("Payment Mode is not configured. Please check, whether account has been set on Mode of Payments or on POS Profile.")) |
| 916 | } |
| 917 | }, |
| 918 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 919 | validate_serial_no: function(){ |
| 920 | var me = this; |
| 921 | var item_code = serial_no = ''; |
| 922 | for (key in this.item_serial_no){ |
| 923 | item_code = key; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 924 | serial_no = me.item_serial_no[key][0]; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 925 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 926 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 927 | if(item_code && serial_no){ |
| 928 | $.each(this.frm.doc.items, function(index, data){ |
| 929 | if(data.item_code == item_code){ |
| 930 | if(in_list(data.serial_no.split('\n'), serial_no)){ |
| 931 | frappe.throw(__(repl("Serial no %(serial_no)s is already taken", { |
| 932 | 'serial_no': serial_no |
| 933 | }))) |
| 934 | } |
| 935 | } |
| 936 | }) |
| 937 | } |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 938 | |
| 939 | if(this.items[0].has_serial_no && serial_no == ""){ |
| 940 | frappe.throw(__(repl("Error: Serial no is mandatory for item %(item)s", { |
| 941 | 'item': this.items[0].item_code |
| 942 | }))) |
| 943 | } |
| 944 | }, |
| 945 | |
| 946 | mandatory_batch_no: function(){ |
| 947 | var me = this; |
| 948 | if(this.items[0].has_batch_no && !this.item_batch_no[this.items[0].item_code]){ |
| 949 | frappe.throw(__(repl("Error: Batch no is mandatory for item %(item)s", { |
| 950 | 'item': this.items[0].item_code |
| 951 | }))) |
| 952 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 953 | }, |
| 954 | |
| 955 | apply_pricing_rule: function(){ |
| 956 | var me = this; |
| 957 | $.each(this.frm.doc["items"], function(n, item) { |
| 958 | pricing_rule = me.get_pricing_rule(item) |
| 959 | me.validate_pricing_rule(pricing_rule) |
| 960 | if(pricing_rule.length){ |
| 961 | item.margin_type = pricing_rule[0].margin_type; |
| 962 | item.price_list_rate = pricing_rule[0].price || item.price_list_rate; |
| 963 | item.margin_rate_or_amount = pricing_rule[0].margin_rate_or_amount; |
| 964 | item.discount_percentage = pricing_rule[0].discount_percentage || 0.0; |
| 965 | me.apply_pricing_rule_on_item(item) |
| 966 | } |
| 967 | }) |
| 968 | }, |
| 969 | |
| 970 | get_pricing_rule: function(item){ |
| 971 | var me = this; |
| 972 | return $.grep(this.pricing_rules, function(data){ |
| 973 | if(data.item_code == item.item_code || in_list(['All Item Groups', item.item_group], data.item_group)) { |
| 974 | if(in_list(['Customer', 'Customer Group', 'Territory'], data.applicable_for)){ |
| 975 | return me.validate_condition(data) |
| 976 | }else{ |
| 977 | return true |
| 978 | } |
| 979 | } |
| 980 | }) |
| 981 | }, |
| 982 | |
| 983 | validate_condition: function(data){ |
| 984 | //This method check condition based on applicable for |
| 985 | condition = this.get_mapper_for_pricing_rule(data)[data.applicable_for] |
| 986 | if(in_list(condition[1], condition[0])){ |
| 987 | return true |
| 988 | } |
| 989 | }, |
| 990 | |
| 991 | get_mapper_for_pricing_rule: function(data){ |
| 992 | return { |
Rohit Waghchaure | 89ee309 | 2016-07-08 15:17:04 +0530 | [diff] [blame] | 993 | 'Customer': [data.customer, [this.frm.doc.customer]], |
| 994 | 'Customer Group': [data.customer_group, [this.frm.doc.customer_group, 'All Customer Groups']], |
| 995 | 'Territory': [data.territory, [this.frm.doc.territory, 'All Territories']], |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 996 | } |
| 997 | }, |
| 998 | |
| 999 | validate_pricing_rule: function(pricing_rule){ |
| 1000 | //This method validate duplicate pricing rule |
| 1001 | var pricing_rule_name = ''; |
| 1002 | var priority = 0; |
| 1003 | var pricing_rule_list = []; |
| 1004 | var priority_list = [] |
| 1005 | |
| 1006 | if(pricing_rule.length > 1){ |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1007 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1008 | $.each(pricing_rule, function(index, data){ |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1009 | pricing_rule_name += data.name + ',' |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1010 | priority_list.push(data.priority) |
| 1011 | if(priority <= data.priority){ |
| 1012 | priority = data.priority |
| 1013 | pricing_rule_list.push(data) |
| 1014 | } |
| 1015 | }) |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1016 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1017 | count = 0 |
| 1018 | $.each(priority_list, function(index, value){ |
| 1019 | if(value == priority){ |
| 1020 | count++ |
| 1021 | } |
| 1022 | }) |
| 1023 | |
| 1024 | if(priority == 0 || count > 1){ |
| 1025 | frappe.throw(__(repl("Multiple Price Rules exists with same criteria, please resolve conflict by assigning priority. Price Rules: %(pricing_rule)s", { |
| 1026 | 'pricing_rule': pricing_rule_name |
| 1027 | }))) |
| 1028 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1029 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1030 | return pricing_rule_list |
| 1031 | } |
| 1032 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1033 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1034 | validate_warehouse: function(){ |
| 1035 | if(!this.items[0].default_warehouse){ |
| 1036 | frappe.throw(__("Deafault warehouse is required for selected item")) |
| 1037 | } |
| 1038 | } |
| 1039 | }) |