2016-04-09 09:01:09 +00:00
|
|
|
frappe.provide("erpnext.pos");
|
|
|
|
{% include "erpnext/public/js/controllers/taxes_and_totals.js" %}
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
frappe.pages['pos'].on_page_load = function (wrapper) {
|
2015-01-01 10:29:34 +00:00
|
|
|
var page = frappe.ui.make_app_page({
|
2014-08-08 10:00:49 +00:00
|
|
|
parent: wrapper,
|
2016-05-20 18:25:45 +00:00
|
|
|
title: __('Point of Sale'),
|
2014-08-08 10:00:49 +00:00
|
|
|
single_column: true
|
|
|
|
});
|
2016-05-11 09:34:57 +00:00
|
|
|
|
2017-08-29 09:57:17 +00:00
|
|
|
frappe.db.get_value('POS Settings', {name: 'POS Settings'}, 'is_online', (r) => {
|
2017-09-11 06:19:25 +00:00
|
|
|
if (r && r.use_pos_in_offline_mode && cint(r.use_pos_in_offline_mode)) {
|
2017-08-29 09:57:17 +00:00
|
|
|
// offline
|
|
|
|
wrapper.pos = new erpnext.pos.PointOfSale(wrapper);
|
|
|
|
cur_pos = wrapper.pos;
|
|
|
|
} else {
|
|
|
|
// online
|
2018-02-05 06:54:06 +00:00
|
|
|
frappe.flags.is_online = true
|
2017-08-29 09:57:17 +00:00
|
|
|
frappe.set_route('point-of-sale');
|
|
|
|
}
|
|
|
|
});
|
2016-05-11 09:34:57 +00:00
|
|
|
}
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
frappe.pages['pos'].refresh = function (wrapper) {
|
2016-06-13 16:07:10 +00:00
|
|
|
window.onbeforeunload = function () {
|
|
|
|
return wrapper.pos.beforeunload()
|
|
|
|
}
|
2018-02-05 06:54:06 +00:00
|
|
|
|
|
|
|
if (frappe.flags.is_online) {
|
|
|
|
frappe.set_route('point-of-sale');
|
|
|
|
}
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
2014-08-08 10:00:49 +00:00
|
|
|
|
2016-04-09 09:01:09 +00:00
|
|
|
erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
|
2017-02-01 12:37:22 +00:00
|
|
|
init: function (wrapper) {
|
2017-03-10 06:10:28 +00:00
|
|
|
this.page_len = 20;
|
2017-06-07 06:34:01 +00:00
|
|
|
this.freeze = false;
|
2016-05-11 09:34:57 +00:00
|
|
|
this.page = wrapper.page;
|
|
|
|
this.wrapper = $(wrapper).find('.page-content');
|
2016-04-09 09:01:09 +00:00
|
|
|
this.set_indicator();
|
|
|
|
this.onload();
|
|
|
|
this.make_menu_list();
|
2017-03-08 12:04:39 +00:00
|
|
|
this.bind_events();
|
2017-03-16 09:51:21 +00:00
|
|
|
this.bind_items_event();
|
2016-04-09 09:01:09 +00:00
|
|
|
this.si_docs = this.get_doc_from_localstorage();
|
|
|
|
},
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
beforeunload: function (e) {
|
|
|
|
if (this.connection_status == false && frappe.get_route()[0] == "pos") {
|
2016-06-13 16:07:10 +00:00
|
|
|
e = e || window.event;
|
|
|
|
|
|
|
|
// For IE and Firefox prior to version 4
|
|
|
|
if (e) {
|
2017-02-01 12:37:22 +00:00
|
|
|
e.returnValue = __("You are in offline mode. You will not be able to reload until you have network.");
|
2016-06-13 16:07:10 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// For Safari
|
|
|
|
return __("You are in offline mode. You will not be able to reload until you have network.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
check_internet_connection: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
//Check Internet connection after every 30 seconds
|
2017-02-01 12:37:22 +00:00
|
|
|
setInterval(function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
me.set_indicator();
|
2016-05-20 18:25:45 +00:00
|
|
|
}, 5000)
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
2014-08-08 10:00:49 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
set_indicator: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
// navigator.onLine
|
2016-05-20 18:25:45 +00:00
|
|
|
this.connection_status = false;
|
2016-07-22 07:54:33 +00:00
|
|
|
this.page.set_indicator(__("Offline"), "grey")
|
2016-04-09 09:01:09 +00:00
|
|
|
frappe.call({
|
2017-02-01 12:37:22 +00:00
|
|
|
method: "frappe.handler.ping",
|
|
|
|
callback: function (r) {
|
|
|
|
if (r.message) {
|
2016-04-09 09:01:09 +00:00
|
|
|
me.connection_status = true;
|
2016-07-22 07:54:33 +00:00
|
|
|
me.page.set_indicator(__("Online"), "green")
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2015-03-05 09:39:04 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
onload: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-02-01 12:37:22 +00:00
|
|
|
this.get_data_from_server(function () {
|
2017-06-07 06:34:01 +00:00
|
|
|
me.make_control();
|
2016-05-20 07:24:44 +00:00
|
|
|
me.create_new();
|
2017-10-21 05:53:45 +00:00
|
|
|
me.make();
|
2016-04-09 09:01:09 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
make_menu_list: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-03-16 09:51:21 +00:00
|
|
|
this.page.clear_menu();
|
2017-05-16 02:01:10 +00:00
|
|
|
|
|
|
|
// for mobile
|
|
|
|
this.page.add_menu_item(__("Pay"), function () {
|
|
|
|
me.validate();
|
|
|
|
me.update_paid_amount_status(true);
|
|
|
|
me.create_invoice();
|
|
|
|
me.make_payment();
|
|
|
|
}).addClass('visible-xs');
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
this.page.add_menu_item(__("New Sales Invoice"), function () {
|
2016-06-13 16:07:10 +00:00
|
|
|
me.save_previous_entry();
|
|
|
|
me.create_new();
|
2016-05-20 07:24:44 +00:00
|
|
|
})
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
this.page.add_menu_item(__("Sync Master Data"), function () {
|
|
|
|
me.get_data_from_server(function () {
|
2016-07-21 17:58:04 +00:00
|
|
|
me.load_data(false);
|
2016-10-09 10:02:56 +00:00
|
|
|
me.make_item_list();
|
2016-07-21 17:58:04 +00:00
|
|
|
me.set_missing_values();
|
2016-05-11 09:34:57 +00:00
|
|
|
})
|
2016-04-09 09:01:09 +00:00
|
|
|
});
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
this.page.add_menu_item(__("Sync Offline Invoices"), function () {
|
2017-10-02 06:43:36 +00:00
|
|
|
me.freeze_screen = true;
|
2016-10-04 07:16:37 +00:00
|
|
|
me.sync_sales_invoice()
|
|
|
|
});
|
|
|
|
|
2018-09-06 13:32:25 +00:00
|
|
|
this.page.add_menu_item(__("Cashier Closing"), function () {
|
|
|
|
frappe.set_route('List', 'Cashier Closing');
|
2019-01-27 10:39:07 +00:00
|
|
|
});
|
2018-09-06 13:32:25 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
this.page.add_menu_item(__("POS Profile"), function () {
|
2016-05-20 18:25:45 +00:00
|
|
|
frappe.set_route('List', 'POS Profile');
|
2016-05-20 07:24:44 +00:00
|
|
|
});
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-28 19:43:09 +00:00
|
|
|
email_prompt: function() {
|
|
|
|
var me = this;
|
2017-05-30 07:24:42 +00:00
|
|
|
var fields = [{label:__("To"), fieldtype:"Data", reqd: 0, fieldname:"recipients",length:524288},
|
2018-04-20 04:58:52 +00:00
|
|
|
{fieldtype: "Section Break", collapsible: 1, label: "CC & Email Template"},
|
2017-02-28 19:43:09 +00:00
|
|
|
{fieldtype: "Section Break"},
|
|
|
|
{label:__("Subject"), fieldtype:"Data", reqd: 1,
|
|
|
|
fieldname:"subject",length:524288},
|
|
|
|
{fieldtype: "Section Break"},
|
|
|
|
{label:__("Message"), fieldtype:"Text Editor", reqd: 1,
|
|
|
|
fieldname:"content"},
|
|
|
|
{fieldtype: "Section Break"},
|
|
|
|
{fieldtype: "Column Break"}];
|
|
|
|
|
|
|
|
this.email_dialog = new frappe.ui.Dialog({
|
|
|
|
title: "Email",
|
|
|
|
fields: fields,
|
|
|
|
primary_action_label: __("Send"),
|
|
|
|
primary_action: function() {
|
|
|
|
me.send_action();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.email_dialog.show()
|
|
|
|
},
|
|
|
|
|
|
|
|
send_action: function() {
|
|
|
|
this.email_queue = this.get_email_queue()
|
|
|
|
this.email_queue[this.frm.doc.offline_pos_name] = JSON.stringify(this.email_dialog.get_values())
|
|
|
|
this.update_email_queue()
|
|
|
|
this.email_dialog.hide()
|
|
|
|
},
|
|
|
|
|
|
|
|
update_email_queue: function () {
|
|
|
|
try {
|
|
|
|
localStorage.setItem('email_queue', JSON.stringify(this.email_queue));
|
|
|
|
} catch (e) {
|
2017-03-06 12:31:58 +00:00
|
|
|
frappe.throw(__("LocalStorage is full, did not save"))
|
2017-02-28 19:43:09 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get_email_queue: function () {
|
|
|
|
try {
|
|
|
|
return JSON.parse(localStorage.getItem('email_queue')) || {};
|
|
|
|
} catch (e) {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-03-07 08:31:04 +00:00
|
|
|
get_customers_details: function () {
|
|
|
|
try {
|
|
|
|
return JSON.parse(localStorage.getItem('customer_details')) || {};
|
|
|
|
} catch (e) {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
edit_record: function () {
|
2016-12-09 06:16:08 +00:00
|
|
|
var me = this;
|
|
|
|
|
|
|
|
doc_data = this.get_invoice_doc(this.si_docs);
|
2017-02-01 12:37:22 +00:00
|
|
|
if (doc_data) {
|
2017-11-08 06:03:39 +00:00
|
|
|
this.frm.doc = doc_data[0][this.frm.doc.offline_pos_name];
|
2016-12-09 06:16:08 +00:00
|
|
|
this.set_missing_values();
|
|
|
|
this.refresh(false);
|
2017-03-08 12:04:39 +00:00
|
|
|
this.toggle_input_field();
|
2017-02-01 12:37:22 +00:00
|
|
|
this.list_dialog && this.list_dialog.hide();
|
2016-12-09 06:16:08 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
delete_records: function () {
|
2016-12-09 06:16:08 +00:00
|
|
|
var me = this;
|
2017-03-10 09:26:19 +00:00
|
|
|
this.validate_list()
|
2016-12-09 06:16:08 +00:00
|
|
|
this.remove_doc_from_localstorage()
|
|
|
|
this.update_localstorage();
|
2017-03-10 09:26:19 +00:00
|
|
|
this.toggle_delete_button();
|
2016-12-09 06:16:08 +00:00
|
|
|
},
|
|
|
|
|
2017-03-10 09:26:19 +00:00
|
|
|
validate_list: function() {
|
2016-12-09 06:16:08 +00:00
|
|
|
var me = this;
|
2017-03-10 09:26:19 +00:00
|
|
|
this.si_docs = this.get_submitted_invoice()
|
2017-11-08 06:03:39 +00:00
|
|
|
$.each(this.removed_items, function(index, pos_name){
|
2017-03-10 09:26:19 +00:00
|
|
|
$.each(me.si_docs, function(key, data){
|
2017-11-08 06:03:39 +00:00
|
|
|
if(me.si_docs[key][pos_name] && me.si_docs[key][pos_name].offline_pos_name == pos_name ){
|
2017-03-10 09:26:19 +00:00
|
|
|
frappe.throw(__("Submitted orders can not be deleted"))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle_delete_button: function () {
|
|
|
|
var me = this;
|
|
|
|
if(this.pos_profile_data["allow_delete"]) {
|
2017-02-01 12:37:22 +00:00
|
|
|
if (this.removed_items && this.removed_items.length > 0) {
|
2017-03-10 09:26:19 +00:00
|
|
|
$(this.page.wrapper).find('.btn-danger').show();
|
2017-02-01 12:37:22 +00:00
|
|
|
} else {
|
2017-03-10 09:26:19 +00:00
|
|
|
$(this.page.wrapper).find('.btn-danger').hide();
|
2017-02-01 12:37:22 +00:00
|
|
|
}
|
2016-12-09 06:16:08 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
get_doctype_status: function (doc) {
|
|
|
|
if (doc.docstatus == 0) {
|
|
|
|
return { status: "Draft", indicator: "red" }
|
|
|
|
} else if (doc.outstanding_amount == 0) {
|
|
|
|
return { status: "Paid", indicator: "green" }
|
|
|
|
} else {
|
|
|
|
return { status: "Submitted", indicator: "blue" }
|
2016-05-20 18:25:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
set_missing_values: function () {
|
2016-05-11 09:34:57 +00:00
|
|
|
var me = this;
|
|
|
|
doc = JSON.parse(localStorage.getItem('doc'))
|
2017-02-01 12:37:22 +00:00
|
|
|
if (this.frm.doc.payments.length == 0) {
|
2016-05-11 09:34:57 +00:00
|
|
|
this.frm.doc.payments = doc.payments;
|
2016-08-01 13:05:18 +00:00
|
|
|
this.calculate_outstanding_amount();
|
2016-05-11 09:34:57 +00:00
|
|
|
}
|
2016-07-21 17:58:04 +00:00
|
|
|
|
2017-09-14 05:21:21 +00:00
|
|
|
this.set_customer_value_in_party_field();
|
2016-08-05 10:11:36 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (!this.frm.doc.write_off_account) {
|
2016-08-05 10:11:36 +00:00
|
|
|
this.frm.doc.write_off_account = doc.write_off_account
|
|
|
|
}
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (!this.frm.doc.account_for_change_amount) {
|
2016-08-17 10:50:13 +00:00
|
|
|
this.frm.doc.account_for_change_amount = doc.account_for_change_amount
|
2016-08-05 10:11:36 +00:00
|
|
|
}
|
2016-05-11 09:34:57 +00:00
|
|
|
},
|
2016-04-09 09:01:09 +00:00
|
|
|
|
2017-09-14 05:21:21 +00:00
|
|
|
set_customer_value_in_party_field: function() {
|
|
|
|
if (this.frm.doc.customer) {
|
|
|
|
this.party_field.$input.val(this.frm.doc.customer);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
get_invoice_doc: function (si_docs) {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
this.si_docs = this.get_doc_from_localstorage();
|
2014-08-08 10:00:49 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
return $.grep(this.si_docs, function (data) {
|
|
|
|
for (key in data) {
|
2017-11-08 06:03:39 +00:00
|
|
|
return key == me.frm.doc.offline_pos_name;
|
2014-08-08 10:00:49 +00:00
|
|
|
}
|
2016-05-20 07:24:44 +00:00
|
|
|
})
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
get_data_from_server: function (callback) {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
frappe.call({
|
|
|
|
method: "erpnext.accounts.doctype.sales_invoice.pos.get_pos_data",
|
|
|
|
freeze: true,
|
2016-05-11 09:34:57 +00:00
|
|
|
freeze_message: __("Master data syncing, it might take some time"),
|
2017-02-01 12:37:22 +00:00
|
|
|
callback: function (r) {
|
2016-04-09 09:01:09 +00:00
|
|
|
localStorage.setItem('doc', JSON.stringify(r.message.doc));
|
2017-03-08 12:04:39 +00:00
|
|
|
me.init_master_data(r)
|
2016-11-20 18:11:13 +00:00
|
|
|
me.set_interval_for_si_sync();
|
|
|
|
me.check_internet_connection();
|
2017-02-01 12:37:22 +00:00
|
|
|
if (callback) {
|
2016-04-09 09:01:09 +00:00
|
|
|
callback();
|
|
|
|
}
|
2018-07-17 12:52:51 +00:00
|
|
|
},
|
|
|
|
error: () => {
|
|
|
|
setTimeout(() => frappe.set_route('List', 'POS Profile'), 2000);
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
init_master_data: function (r) {
|
2016-11-20 18:11:13 +00:00
|
|
|
var me = this;
|
2017-03-08 12:04:39 +00:00
|
|
|
this.doc = JSON.parse(localStorage.getItem('doc'));
|
2016-11-20 18:11:13 +00:00
|
|
|
this.meta = r.message.meta;
|
|
|
|
this.item_data = r.message.items;
|
2017-02-01 12:37:22 +00:00
|
|
|
this.item_groups = r.message.item_groups;
|
2016-11-20 18:11:13 +00:00
|
|
|
this.customers = r.message.customers;
|
|
|
|
this.serial_no_data = r.message.serial_no_data;
|
|
|
|
this.batch_no_data = r.message.batch_no_data;
|
2017-12-10 16:27:09 +00:00
|
|
|
this.barcode_data = r.message.barcode_data;
|
2016-11-20 18:11:13 +00:00
|
|
|
this.tax_data = r.message.tax_data;
|
2017-06-07 06:34:01 +00:00
|
|
|
this.contacts = r.message.contacts;
|
2017-03-07 08:31:04 +00:00
|
|
|
this.address = r.message.address || {};
|
2016-11-20 18:11:13 +00:00
|
|
|
this.price_list_data = r.message.price_list_data;
|
2019-01-27 10:39:07 +00:00
|
|
|
this.customer_wise_price_list = r.message.customer_wise_price_list
|
2016-11-20 18:11:13 +00:00
|
|
|
this.bin_data = r.message.bin_data;
|
|
|
|
this.pricing_rules = r.message.pricing_rules;
|
|
|
|
this.print_template = r.message.print_template;
|
|
|
|
this.pos_profile_data = r.message.pos_profile;
|
|
|
|
this.default_customer = r.message.default_customer || null;
|
2016-12-20 11:24:24 +00:00
|
|
|
this.print_settings = locals[":Print Settings"]["Print Settings"];
|
2016-12-21 07:48:36 +00:00
|
|
|
this.letter_head = (this.pos_profile_data.length > 0) ? frappe.boot.letter_heads[this.pos_profile_data[letter_head]] : {};
|
2016-11-20 18:11:13 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
save_previous_entry: function () {
|
|
|
|
if (this.frm.doc.docstatus < 1 && this.frm.doc.items.length > 0) {
|
|
|
|
this.create_invoice();
|
2016-05-20 18:25:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
create_new: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2016-05-11 09:34:57 +00:00
|
|
|
this.frm = {}
|
2016-07-21 17:58:04 +00:00
|
|
|
this.load_data(true);
|
2019-03-26 13:42:25 +00:00
|
|
|
this.frm.doc.offline_pos_name = '';
|
2016-04-09 09:01:09 +00:00
|
|
|
this.setup();
|
2017-05-02 07:34:08 +00:00
|
|
|
this.set_default_customer()
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
load_data: function (load_doc) {
|
2016-11-20 18:11:13 +00:00
|
|
|
var me = this;
|
2016-07-21 17:58:04 +00:00
|
|
|
|
2016-11-20 18:11:13 +00:00
|
|
|
this.items = this.item_data;
|
2016-11-27 06:34:12 +00:00
|
|
|
this.actual_qty_dict = {};
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (load_doc) {
|
|
|
|
this.frm.doc = JSON.parse(localStorage.getItem('doc'));
|
2016-07-21 17:58:04 +00:00
|
|
|
}
|
2016-04-09 09:01:09 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
$.each(this.meta, function (i, data) {
|
2016-04-09 09:01:09 +00:00
|
|
|
frappe.meta.sync(data)
|
2016-12-27 08:45:52 +00:00
|
|
|
locals["DocType"][data.name] = data;
|
2016-04-09 09:01:09 +00:00
|
|
|
})
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
this.print_template_data = frappe.render_template("print_template", {
|
|
|
|
content: this.print_template,
|
2017-05-23 11:42:51 +00:00
|
|
|
title: "POS",
|
|
|
|
base_url: frappe.urllib.get_base_url(),
|
|
|
|
print_css: frappe.boot.print_css,
|
|
|
|
print_settings: this.print_settings,
|
|
|
|
header: this.letter_head.header,
|
|
|
|
footer: this.letter_head.footer,
|
2017-05-23 12:13:42 +00:00
|
|
|
landscape: false,
|
|
|
|
columns: []
|
2017-02-01 12:37:22 +00:00
|
|
|
})
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
setup: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
this.set_primary_action();
|
2017-03-08 12:04:39 +00:00
|
|
|
this.party_field.$input.attr('disabled', false);
|
|
|
|
if(this.selected_row) {
|
|
|
|
this.selected_row.hide()
|
|
|
|
}
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-05-02 07:34:08 +00:00
|
|
|
set_default_customer: function() {
|
|
|
|
if (this.default_customer && !this.frm.doc.customer) {
|
|
|
|
this.party_field.$input.val(this.default_customer);
|
|
|
|
this.frm.doc.customer = this.default_customer;
|
|
|
|
this.numeric_keypad.show();
|
|
|
|
this.toggle_list_customer(false)
|
|
|
|
this.toggle_item_cart(true)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
set_transaction_defaults: function (party) {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
this.party = party;
|
|
|
|
this.price_list = (party == "Customer" ?
|
|
|
|
this.frm.doc.selling_price_list : this.frm.doc.buying_price_list);
|
|
|
|
this.price_list_field = (party == "Customer" ? "selling_price_list" : "buying_price_list");
|
|
|
|
this.sales_or_purchase = (party == "Customer" ? "Sales" : "Purchase");
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
make: function () {
|
2017-03-08 12:04:39 +00:00
|
|
|
this.make_item_list();
|
|
|
|
this.make_discount_field()
|
|
|
|
},
|
2017-05-19 10:32:30 +00:00
|
|
|
|
2017-03-08 12:04:39 +00:00
|
|
|
make_control: function() {
|
|
|
|
this.frm = {}
|
|
|
|
this.frm.doc = this.doc
|
|
|
|
this.set_transaction_defaults("Customer");
|
2018-03-08 10:51:13 +00:00
|
|
|
this.frm.doc["allow_user_to_edit_rate"] = this.pos_profile_data["allow_user_to_edit_rate"] ? true : false;
|
|
|
|
this.frm.doc["allow_user_to_edit_discount"] = this.pos_profile_data["allow_user_to_edit_discount"] ? true : false;
|
2017-03-08 12:04:39 +00:00
|
|
|
this.wrapper.html(frappe.render_template("pos", this.frm.doc));
|
2016-04-09 09:01:09 +00:00
|
|
|
this.make_search();
|
|
|
|
this.make_customer();
|
2017-03-07 12:44:06 +00:00
|
|
|
this.make_list_customers();
|
2017-02-28 11:21:17 +00:00
|
|
|
this.bind_numeric_keypad();
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
make_search: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2018-05-13 10:47:18 +00:00
|
|
|
this.search_item = frappe.ui.form.make_control({
|
2016-04-09 09:01:09 +00:00
|
|
|
df: {
|
|
|
|
"fieldtype": "Data",
|
2018-07-01 11:14:09 +00:00
|
|
|
"label": __("Item"),
|
2016-04-09 09:01:09 +00:00
|
|
|
"fieldname": "pos_item",
|
2016-07-22 07:54:33 +00:00
|
|
|
"placeholder": __("Search Item")
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
2017-02-01 12:37:22 +00:00
|
|
|
parent: this.wrapper.find(".search-item"),
|
2016-04-09 09:01:09 +00:00
|
|
|
only_input: true,
|
|
|
|
});
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2018-05-13 10:47:18 +00:00
|
|
|
this.search_item.make_input();
|
2017-12-10 16:27:09 +00:00
|
|
|
|
2018-05-13 10:47:18 +00:00
|
|
|
this.search_item.$input.on("keypress", function (event) {
|
2017-08-28 11:22:20 +00:00
|
|
|
|
|
|
|
clearTimeout(me.last_search_timeout);
|
|
|
|
me.last_search_timeout = setTimeout(() => {
|
2018-05-13 10:47:18 +00:00
|
|
|
if((me.search_item.$input.val() != "") || (event.which == 13)) {
|
2017-08-28 11:22:20 +00:00
|
|
|
me.items = me.get_items();
|
|
|
|
me.make_item_list();
|
2017-12-10 16:27:09 +00:00
|
|
|
}
|
2017-08-28 11:22:20 +00:00
|
|
|
}, 400);
|
2016-04-09 09:01:09 +00:00
|
|
|
});
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-03-07 12:44:06 +00:00
|
|
|
this.search_item_group = this.wrapper.find('.search-item-group');
|
2017-04-17 08:06:08 +00:00
|
|
|
sorted_item_groups = this.get_sorted_item_groups()
|
|
|
|
var dropdown_html = sorted_item_groups.map(function(item_group) {
|
2017-03-07 12:44:06 +00:00
|
|
|
return "<li><a class='option' data-value='"+item_group+"'>"+item_group+"</a></li>";
|
|
|
|
}).join("");
|
|
|
|
|
|
|
|
this.search_item_group.find('.dropdown-menu').html(dropdown_html);
|
|
|
|
|
|
|
|
this.search_item_group.on('click', '.dropdown-menu a', function() {
|
|
|
|
me.selected_item_group = $(this).attr('data-value');
|
|
|
|
me.search_item_group.find('.dropdown-text').text(me.selected_item_group);
|
2017-02-01 12:37:22 +00:00
|
|
|
|
|
|
|
me.page_len = 20;
|
|
|
|
me.items = me.get_items();
|
|
|
|
me.make_item_list();
|
2017-03-07 12:44:06 +00:00
|
|
|
})
|
|
|
|
|
2017-03-09 09:13:37 +00:00
|
|
|
me.toggle_more_btn();
|
|
|
|
|
|
|
|
this.wrapper.on("click", ".btn-more", function() {
|
2017-03-10 06:10:28 +00:00
|
|
|
me.page_len += 20;
|
2017-02-01 12:47:35 +00:00
|
|
|
me.items = me.get_items();
|
2017-02-01 12:37:22 +00:00
|
|
|
me.make_item_list();
|
2017-03-09 09:13:37 +00:00
|
|
|
me.toggle_more_btn();
|
|
|
|
});
|
2017-03-07 08:31:04 +00:00
|
|
|
|
2017-03-09 09:13:37 +00:00
|
|
|
this.page.wrapper.on("click", ".edit-customer-btn", function() {
|
2017-03-07 08:31:04 +00:00
|
|
|
me.update_customer()
|
|
|
|
})
|
2017-02-01 12:37:22 +00:00
|
|
|
},
|
|
|
|
|
2017-04-17 08:06:08 +00:00
|
|
|
get_sorted_item_groups: function() {
|
|
|
|
list = {}
|
|
|
|
$.each(this.item_groups, function(i, data) {
|
|
|
|
list[i] = data[0]
|
|
|
|
})
|
|
|
|
|
|
|
|
return Object.keys(list).sort(function(a,b){return list[a]-list[b]})
|
|
|
|
},
|
|
|
|
|
2017-03-09 09:13:37 +00:00
|
|
|
toggle_more_btn: function() {
|
|
|
|
if(!this.items || this.items.length <= this.page_len) {
|
|
|
|
this.wrapper.find(".btn-more").hide();
|
|
|
|
} else {
|
|
|
|
this.wrapper.find(".btn-more").show();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle_totals_area: function(show) {
|
|
|
|
|
2017-03-09 11:33:14 +00:00
|
|
|
if(show === undefined) {
|
2017-03-09 09:13:37 +00:00
|
|
|
show = this.is_totals_area_collapsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
var totals_area = this.wrapper.find('.totals-area');
|
|
|
|
totals_area.find('.net-total-area, .tax-area, .discount-amount-area')
|
|
|
|
.toggle(show);
|
|
|
|
|
|
|
|
if(show) {
|
|
|
|
totals_area.find('.collapse-btn i')
|
|
|
|
.removeClass('octicon-chevron-down')
|
|
|
|
.addClass('octicon-chevron-up');
|
|
|
|
} else {
|
|
|
|
totals_area.find('.collapse-btn i')
|
|
|
|
.removeClass('octicon-chevron-up')
|
|
|
|
.addClass('octicon-chevron-down');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.is_totals_area_collapsed = !show;
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
make_list_customers: function () {
|
|
|
|
var me = this;
|
2017-03-07 12:44:06 +00:00
|
|
|
this.list_customers_btn = this.page.wrapper.find('.list-customers-btn');
|
2017-02-01 12:37:22 +00:00
|
|
|
this.add_customer_btn = this.wrapper.find('.add-customer-btn');
|
2017-03-07 12:44:06 +00:00
|
|
|
this.pos_bill = this.wrapper.find('.pos-bill-wrapper').hide();
|
2017-02-01 12:37:22 +00:00
|
|
|
this.list_customers = this.wrapper.find('.list-customers');
|
2017-02-24 12:32:50 +00:00
|
|
|
this.numeric_keypad = this.wrapper.find('.numeric_keypad');
|
2017-03-23 11:34:00 +00:00
|
|
|
this.list_customers_btn.addClass("view_customer")
|
2017-02-01 12:37:22 +00:00
|
|
|
|
2017-03-09 09:13:37 +00:00
|
|
|
me.render_list_customers();
|
|
|
|
me.toggle_totals_area(false);
|
|
|
|
|
2017-03-08 12:04:39 +00:00
|
|
|
this.page.wrapper.on('click', '.list-customers-btn', function() {
|
2017-02-01 12:37:22 +00:00
|
|
|
$(this).toggleClass("view_customer");
|
|
|
|
if($(this).hasClass("view_customer")) {
|
|
|
|
me.render_list_customers();
|
|
|
|
me.list_customers.show();
|
|
|
|
me.pos_bill.hide();
|
2017-02-24 12:32:50 +00:00
|
|
|
me.numeric_keypad.hide();
|
2017-03-10 09:26:19 +00:00
|
|
|
me.toggle_delete_button()
|
2017-02-01 12:37:22 +00:00
|
|
|
} else {
|
|
|
|
if(me.frm.doc.docstatus == 0) {
|
|
|
|
me.party_field.$input.attr('disabled', false);
|
|
|
|
}
|
|
|
|
me.pos_bill.show();
|
2017-03-09 09:13:37 +00:00
|
|
|
me.toggle_totals_area(false);
|
2017-03-10 09:26:19 +00:00
|
|
|
me.toggle_delete_button()
|
2017-03-09 09:13:37 +00:00
|
|
|
me.list_customers.hide();
|
2017-03-23 11:34:00 +00:00
|
|
|
me.numeric_keypad.show();
|
2017-02-01 12:37:22 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.add_customer_btn.on('click', function() {
|
|
|
|
me.save_previous_entry();
|
|
|
|
me.create_new();
|
|
|
|
me.refresh();
|
|
|
|
me.set_focus();
|
|
|
|
});
|
2017-03-09 09:13:37 +00:00
|
|
|
this.pos_bill.on('click', '.collapse-btn', function() {
|
|
|
|
me.toggle_totals_area();
|
|
|
|
});
|
2017-02-01 12:37:22 +00:00
|
|
|
},
|
2017-05-19 10:32:30 +00:00
|
|
|
|
2017-02-28 11:21:17 +00:00
|
|
|
bind_numeric_keypad: function() {
|
|
|
|
var me = this;
|
|
|
|
$(this.numeric_keypad).find('.pos-operation').on('click', function(){
|
|
|
|
me.numeric_val = '';
|
|
|
|
})
|
|
|
|
|
|
|
|
$(this.numeric_keypad).find('.numeric-keypad').on('click', function(){
|
|
|
|
me.numeric_id = $(this).attr("id") || me.numeric_id;
|
|
|
|
me.val = $(this).attr("val")
|
2017-03-08 12:04:39 +00:00
|
|
|
if(me.numeric_id) {
|
|
|
|
me.selected_field = $(me.wrapper).find('.selected-item').find('.' + me.numeric_id)
|
|
|
|
}
|
2017-03-07 12:44:06 +00:00
|
|
|
|
2017-02-28 11:21:17 +00:00
|
|
|
if(me.val && me.numeric_id) {
|
|
|
|
me.numeric_val += me.val;
|
|
|
|
me.selected_field.val(flt(me.numeric_val))
|
|
|
|
me.selected_field.trigger("change")
|
2017-03-10 09:26:19 +00:00
|
|
|
// me.render_selected_item()
|
2017-02-28 11:21:17 +00:00
|
|
|
}
|
2017-03-07 12:44:06 +00:00
|
|
|
|
|
|
|
if(me.numeric_id && $(this).hasClass('pos-operation')) {
|
|
|
|
me.numeric_keypad.find('button.pos-operation').removeClass('active');
|
|
|
|
$(this).addClass('active');
|
|
|
|
|
|
|
|
me.selected_row.find('.pos-list-row').removeClass('active');
|
|
|
|
me.selected_field.closest('.pos-list-row').addClass('active');
|
|
|
|
}
|
2017-02-28 11:21:17 +00:00
|
|
|
})
|
2017-05-19 10:32:30 +00:00
|
|
|
|
2017-02-28 11:21:17 +00:00
|
|
|
$(this.numeric_keypad).find('.numeric-del').click(function(){
|
2017-06-23 12:47:04 +00:00
|
|
|
if(me.numeric_id) {
|
|
|
|
me.selected_field = $(me.wrapper).find('.selected-item').find('.' + me.numeric_id)
|
|
|
|
me.numeric_val = cstr(flt(me.selected_field.val())).slice(0, -1);
|
|
|
|
me.selected_field.val(me.numeric_val);
|
|
|
|
me.selected_field.trigger("change")
|
|
|
|
} else {
|
|
|
|
//Remove an item from the cart, if focus is at selected item
|
|
|
|
me.remove_selected_item()
|
|
|
|
}
|
2017-02-28 11:21:17 +00:00
|
|
|
})
|
2017-05-19 10:32:30 +00:00
|
|
|
|
2017-02-28 11:21:17 +00:00
|
|
|
$(this.numeric_keypad).find('.pos-pay').click(function(){
|
|
|
|
me.validate();
|
|
|
|
me.update_paid_amount_status(true);
|
|
|
|
me.create_invoice();
|
|
|
|
me.make_payment();
|
|
|
|
})
|
|
|
|
},
|
2017-02-01 12:37:22 +00:00
|
|
|
|
2017-06-23 12:47:04 +00:00
|
|
|
remove_selected_item: function() {
|
|
|
|
this.remove_item = []
|
|
|
|
idx = $(this.wrapper).find(".pos-selected-item-action").attr("data-idx")
|
|
|
|
this.remove_item.push(idx)
|
2019-01-29 06:31:54 +00:00
|
|
|
this.remove_zero_qty_items_from_cart()
|
2017-06-23 12:47:04 +00:00
|
|
|
this.update_paid_amount_status(false)
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
render_list_customers: function () {
|
|
|
|
var me = this;
|
|
|
|
|
|
|
|
this.removed_items = [];
|
2017-03-09 09:13:37 +00:00
|
|
|
// this.list_customers.empty();
|
2017-02-01 12:37:22 +00:00
|
|
|
this.si_docs = this.get_doc_from_localstorage();
|
2017-03-10 06:10:28 +00:00
|
|
|
if (!this.si_docs.length) {
|
2017-11-08 06:03:39 +00:00
|
|
|
this.list_customers.find('.list-customers-table').html("");
|
2017-02-01 12:37:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-09 09:13:37 +00:00
|
|
|
|
|
|
|
var html = "";
|
2017-03-10 09:26:19 +00:00
|
|
|
if(this.si_docs.length) {
|
|
|
|
this.si_docs.forEach(function (data, i) {
|
2017-05-30 07:24:42 +00:00
|
|
|
for (var key in data) {
|
2017-03-10 09:26:19 +00:00
|
|
|
html += frappe.render_template("pos_invoice_list", {
|
|
|
|
sr: i + 1,
|
|
|
|
name: key,
|
|
|
|
customer: data[key].customer,
|
|
|
|
paid_amount: format_currency(data[key].paid_amount, me.frm.doc.currency),
|
|
|
|
grand_total: format_currency(data[key].grand_total, me.frm.doc.currency),
|
|
|
|
data: me.get_doctype_status(data[key])
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-03-09 09:13:37 +00:00
|
|
|
this.list_customers.find('.list-customers-table').html(html);
|
2017-02-01 12:37:22 +00:00
|
|
|
|
2017-03-10 09:26:19 +00:00
|
|
|
this.list_customers.on('click', '.customer-row', function () {
|
2017-02-01 12:37:22 +00:00
|
|
|
me.list_customers.hide();
|
2017-03-08 12:04:39 +00:00
|
|
|
me.numeric_keypad.show();
|
2017-02-01 12:37:22 +00:00
|
|
|
me.list_customers_btn.toggleClass("view_customer");
|
|
|
|
me.pos_bill.show();
|
|
|
|
me.list_customers_btn.show();
|
2019-03-26 13:42:25 +00:00
|
|
|
me.frm.doc.offline_pos_name = $(this).parents().attr('invoice-name');
|
2017-02-01 12:37:22 +00:00
|
|
|
me.edit_record();
|
|
|
|
})
|
|
|
|
|
|
|
|
//actions
|
|
|
|
$(this.wrapper).find('.list-select-all').click(function () {
|
|
|
|
me.list_customers.find('.list-delete').prop("checked", $(this).is(":checked"))
|
|
|
|
me.removed_items = [];
|
|
|
|
if ($(this).is(":checked")) {
|
|
|
|
$.each(me.si_docs, function (index, data) {
|
|
|
|
for (key in data) {
|
|
|
|
me.removed_items.push(key)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-03-10 09:26:19 +00:00
|
|
|
me.toggle_delete_button();
|
2017-02-01 12:37:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$(this.wrapper).find('.list-delete').click(function () {
|
2017-11-08 06:03:39 +00:00
|
|
|
me.frm.doc.offline_pos_name = $(this).parent().parent().attr('invoice-name');
|
2017-02-01 12:37:22 +00:00
|
|
|
if ($(this).is(":checked")) {
|
2017-11-08 06:03:39 +00:00
|
|
|
me.removed_items.push(me.frm.doc.offline_pos_name);
|
2017-02-01 12:37:22 +00:00
|
|
|
} else {
|
2017-11-08 06:03:39 +00:00
|
|
|
me.removed_items.pop(me.frm.doc.offline_pos_name)
|
2017-02-01 12:37:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 09:26:19 +00:00
|
|
|
me.toggle_delete_button();
|
2017-02-01 12:37:22 +00:00
|
|
|
});
|
2016-09-11 20:07:46 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
bind_delete_event: function() {
|
|
|
|
var me = this;
|
|
|
|
|
2017-03-10 09:26:19 +00:00
|
|
|
$(this.page.wrapper).on('click', '.btn-danger', function(){
|
2017-02-01 12:37:22 +00:00
|
|
|
frappe.confirm(__("Delete permanently?"), function () {
|
|
|
|
me.delete_records();
|
2017-03-10 09:26:19 +00:00
|
|
|
me.list_customers.find('.list-customers-table').html("");
|
2017-02-01 12:37:22 +00:00
|
|
|
me.render_list_customers();
|
|
|
|
})
|
2017-02-01 12:47:35 +00:00
|
|
|
})
|
2017-02-01 12:37:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set_focus: function () {
|
|
|
|
if (this.default_customer || this.frm.doc.customer) {
|
2017-09-14 05:21:21 +00:00
|
|
|
this.set_customer_value_in_party_field();
|
2018-05-13 10:47:18 +00:00
|
|
|
this.search_item.$input.focus();
|
2017-02-01 12:37:22 +00:00
|
|
|
} else {
|
2016-09-11 20:07:46 +00:00
|
|
|
this.party_field.$input.focus();
|
|
|
|
}
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
make_customer: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-03-06 12:31:58 +00:00
|
|
|
|
2017-03-08 12:04:39 +00:00
|
|
|
if(!this.party_field) {
|
|
|
|
if(this.page.wrapper.find('.pos-bill-toolbar').length === 0) {
|
|
|
|
$(frappe.render_template('customer_toolbar', {
|
2017-03-10 09:26:19 +00:00
|
|
|
allow_delete: this.pos_profile_data["allow_delete"]
|
2017-03-08 12:04:39 +00:00
|
|
|
})).insertAfter(this.page.$title_area.hide());
|
|
|
|
}
|
|
|
|
|
|
|
|
this.party_field = frappe.ui.form.make_control({
|
|
|
|
df: {
|
|
|
|
"fieldtype": "Data",
|
|
|
|
"options": this.party,
|
|
|
|
"label": this.party,
|
|
|
|
"fieldname": this.party.toLowerCase(),
|
|
|
|
"placeholder": __("Select or add new customer")
|
|
|
|
},
|
|
|
|
parent: this.page.wrapper.find(".party-area"),
|
|
|
|
only_input: true,
|
|
|
|
});
|
2017-03-06 12:31:58 +00:00
|
|
|
|
2017-03-08 12:04:39 +00:00
|
|
|
this.party_field.make_input();
|
|
|
|
setTimeout(this.set_focus.bind(this), 500);
|
2017-03-10 09:26:19 +00:00
|
|
|
me.toggle_delete_button();
|
2017-03-08 12:04:39 +00:00
|
|
|
}
|
2017-03-06 12:31:58 +00:00
|
|
|
|
2017-01-09 11:51:34 +00:00
|
|
|
this.party_field.awesomeplete =
|
|
|
|
new Awesomplete(this.party_field.$input.get(0), {
|
2016-12-27 06:44:26 +00:00
|
|
|
minChars: 0,
|
|
|
|
maxItems: 99,
|
|
|
|
autoFirst: true,
|
|
|
|
list: [],
|
2017-02-01 12:37:22 +00:00
|
|
|
filter: function (item, input) {
|
2017-06-07 06:34:01 +00:00
|
|
|
if (item.value.includes('is_action')) {
|
2017-01-09 11:51:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-06-07 06:34:01 +00:00
|
|
|
|
|
|
|
input = input.toLowerCase();
|
|
|
|
item = this.get_item(item.value);
|
2017-09-06 14:15:36 +00:00
|
|
|
result = item ? item.searchtext.includes(input) : '';
|
|
|
|
if(!result) {
|
|
|
|
me.prepare_customer_mapper(input);
|
|
|
|
} else {
|
|
|
|
return result;
|
|
|
|
}
|
2017-01-09 11:51:34 +00:00
|
|
|
},
|
2017-02-01 12:37:22 +00:00
|
|
|
item: function (item, input) {
|
2017-06-07 06:34:01 +00:00
|
|
|
var d = this.get_item(item.value);
|
2017-03-09 09:13:37 +00:00
|
|
|
var html = "<span>" + __(d.label || d.value) + "</span>";
|
2017-06-07 06:34:01 +00:00
|
|
|
if(d.customer_name) {
|
|
|
|
html += '<br><span class="text-muted ellipsis">' + __(d.customer_name) + '</span>';
|
|
|
|
}
|
|
|
|
|
2017-01-09 11:51:34 +00:00
|
|
|
return $('<li></li>')
|
|
|
|
.data('item.autocomplete', d)
|
|
|
|
.html('<a><p>' + html + '</p></a>')
|
|
|
|
.get(0);
|
|
|
|
}
|
2016-12-27 06:44:26 +00:00
|
|
|
});
|
2017-03-23 11:34:00 +00:00
|
|
|
|
2017-06-07 06:34:01 +00:00
|
|
|
this.prepare_customer_mapper()
|
2017-03-23 11:34:00 +00:00
|
|
|
this.autocomplete_customers();
|
2016-12-27 06:44:26 +00:00
|
|
|
|
|
|
|
this.party_field.$input
|
2017-02-01 12:37:22 +00:00
|
|
|
.on('input', function (e) {
|
2017-09-06 14:15:36 +00:00
|
|
|
if(me.customers_mapper.length <= 1) {
|
|
|
|
me.prepare_customer_mapper(e.target.value);
|
|
|
|
}
|
2017-06-07 06:34:01 +00:00
|
|
|
me.party_field.awesomeplete.list = me.customers_mapper;
|
2016-12-27 06:44:26 +00:00
|
|
|
})
|
2017-02-01 12:37:22 +00:00
|
|
|
.on('awesomplete-select', function (e) {
|
|
|
|
var customer = me.party_field.awesomeplete
|
2017-01-09 11:51:34 +00:00
|
|
|
.get_item(e.originalEvent.text.value);
|
2017-02-01 12:37:22 +00:00
|
|
|
if (!customer) return;
|
|
|
|
// create customer link
|
|
|
|
if (customer.action) {
|
|
|
|
customer.action.apply(me);
|
2017-01-09 11:51:34 +00:00
|
|
|
return;
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
2017-03-09 09:13:37 +00:00
|
|
|
me.toggle_list_customer(false);
|
|
|
|
me.toggle_edit_button(true);
|
2017-02-01 12:37:22 +00:00
|
|
|
me.update_customer_data(customer);
|
2016-04-09 09:01:09 +00:00
|
|
|
me.refresh();
|
2017-02-01 12:37:22 +00:00
|
|
|
me.set_focus();
|
2017-03-23 11:34:00 +00:00
|
|
|
me.list_customers_btn.removeClass("view_customer");
|
2016-12-27 06:44:26 +00:00
|
|
|
})
|
2017-02-01 12:37:22 +00:00
|
|
|
.on('focus', function (e) {
|
2016-12-27 06:44:26 +00:00
|
|
|
$(e.target).val('').trigger('input');
|
2017-03-09 09:13:37 +00:00
|
|
|
me.toggle_edit_button(false);
|
2017-03-10 09:20:39 +00:00
|
|
|
|
|
|
|
if(me.frm.doc.items.length) {
|
2017-03-10 06:10:28 +00:00
|
|
|
me.toggle_list_customer(false)
|
|
|
|
me.toggle_item_cart(true)
|
|
|
|
} else {
|
|
|
|
me.toggle_list_customer(true)
|
|
|
|
me.toggle_item_cart(false)
|
|
|
|
}
|
2017-01-09 11:51:34 +00:00
|
|
|
})
|
2017-02-01 12:37:22 +00:00
|
|
|
.on("awesomplete-selectcomplete", function (e) {
|
2017-01-09 11:51:34 +00:00
|
|
|
var item = me.party_field.awesomeplete
|
|
|
|
.get_item(e.originalEvent.text.value);
|
|
|
|
// clear text input if item is action
|
2017-02-01 12:37:22 +00:00
|
|
|
if (item.action) {
|
2017-01-09 11:51:34 +00:00
|
|
|
$(this).val("");
|
2016-05-20 18:25:45 +00:00
|
|
|
}
|
2019-01-27 10:39:07 +00:00
|
|
|
me.make_item_list(item.customer_name);
|
2016-12-27 06:44:26 +00:00
|
|
|
});
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
2014-08-08 10:00:49 +00:00
|
|
|
|
2017-09-06 14:15:36 +00:00
|
|
|
prepare_customer_mapper: function(key) {
|
2017-06-07 06:34:01 +00:00
|
|
|
var me = this;
|
2017-09-06 14:15:36 +00:00
|
|
|
var customer_data = '';
|
|
|
|
|
|
|
|
if (key) {
|
|
|
|
key = key.toLowerCase().trim();
|
|
|
|
var re = new RegExp('%', 'g');
|
|
|
|
var reg = new RegExp(key.replace(re, '\\w*\\s*[a-zA-Z0-9]*'));
|
|
|
|
|
|
|
|
customer_data = $.grep(this.customers, function(data) {
|
|
|
|
contact = me.contacts[data.name];
|
|
|
|
if(reg.test(data.name.toLowerCase())
|
|
|
|
|| reg.test(data.customer_name.toLowerCase())
|
|
|
|
|| (contact && reg.test(contact["phone"]))
|
|
|
|
|| (data.customer_group && reg.test(data.customer_group.toLowerCase()))){
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
customer_data = this.customers;
|
|
|
|
}
|
2017-06-07 06:34:01 +00:00
|
|
|
|
2017-09-06 14:15:36 +00:00
|
|
|
this.customers_mapper = [];
|
|
|
|
|
|
|
|
customer_data.forEach(function (c, index) {
|
|
|
|
if(index < 30) {
|
|
|
|
contact = me.contacts[c.name];
|
|
|
|
if(contact && !c['phone']) {
|
|
|
|
c["phone"] = contact["phone"];
|
|
|
|
c["email_id"] = contact["email_id"];
|
|
|
|
}
|
|
|
|
|
|
|
|
me.customers_mapper.push({
|
|
|
|
label: c.name,
|
|
|
|
value: c.name,
|
|
|
|
customer_name: c.customer_name,
|
|
|
|
customer_group: c.customer_group,
|
|
|
|
territory: c.territory,
|
|
|
|
phone: contact ? contact["phone"] : '',
|
|
|
|
email_id: contact ? contact["email_id"] : '',
|
|
|
|
searchtext: ['customer_name', 'customer_group', 'name', 'value',
|
2019-09-02 10:27:45 +00:00
|
|
|
'label', 'email_id', 'phone']
|
2017-09-06 14:15:36 +00:00
|
|
|
.map(key => c[key]).join(' ')
|
|
|
|
.toLowerCase()
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return;
|
2017-06-07 06:34:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.customers_mapper.push({
|
|
|
|
label: "<span class='text-primary link-option'>"
|
|
|
|
+ "<i class='fa fa-plus' style='margin-right: 5px;'></i> "
|
|
|
|
+ __("Create a new Customer")
|
|
|
|
+ "</span>",
|
|
|
|
value: 'is_action',
|
|
|
|
action: me.add_customer
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-03-23 11:34:00 +00:00
|
|
|
autocomplete_customers: function() {
|
|
|
|
this.party_field.awesomeplete.list = this.customers_mapper;
|
|
|
|
},
|
|
|
|
|
2017-03-09 09:13:37 +00:00
|
|
|
toggle_edit_button: function(flag) {
|
|
|
|
this.page.wrapper.find('.edit-customer-btn').toggle(flag);
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle_list_customer: function(flag) {
|
|
|
|
this.list_customers.toggle(flag);
|
|
|
|
},
|
|
|
|
|
2017-03-10 06:10:28 +00:00
|
|
|
toggle_item_cart: function(flag) {
|
|
|
|
this.wrapper.find('.pos-bill-wrapper').toggle(flag);
|
|
|
|
},
|
|
|
|
|
2017-03-07 08:31:04 +00:00
|
|
|
add_customer: function() {
|
|
|
|
this.frm.doc.customer = "";
|
2017-05-16 03:21:24 +00:00
|
|
|
this.update_customer(true);
|
|
|
|
this.numeric_keypad.show();
|
2017-03-07 08:31:04 +00:00
|
|
|
},
|
|
|
|
|
2017-03-23 11:34:00 +00:00
|
|
|
update_customer: function (new_customer) {
|
2017-01-09 11:51:34 +00:00
|
|
|
var me = this;
|
2017-02-01 12:47:35 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
this.customer_doc = new frappe.ui.Dialog({
|
|
|
|
'title': 'Customer',
|
|
|
|
fields: [
|
|
|
|
{
|
2017-02-01 12:47:35 +00:00
|
|
|
"label": __("Full Name"),
|
2017-02-01 12:37:22 +00:00
|
|
|
"fieldname": "full_name",
|
|
|
|
"fieldtype": "Data",
|
2017-02-01 12:47:35 +00:00
|
|
|
"reqd": 1
|
2017-02-01 12:37:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldtype": "Section Break"
|
|
|
|
},
|
|
|
|
{
|
2017-02-01 12:47:35 +00:00
|
|
|
"label": __("Email Id"),
|
2017-02-01 12:37:22 +00:00
|
|
|
"fieldname": "email_id",
|
|
|
|
"fieldtype": "Data"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldtype": "Column Break"
|
|
|
|
},
|
|
|
|
{
|
2017-02-01 12:47:35 +00:00
|
|
|
"label": __("Contact Number"),
|
2017-03-07 08:31:04 +00:00
|
|
|
"fieldname": "phone",
|
2017-02-01 12:37:22 +00:00
|
|
|
"fieldtype": "Data"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldtype": "Section Break"
|
|
|
|
},
|
2017-03-10 09:26:19 +00:00
|
|
|
{
|
|
|
|
"label": __("Address Name"),
|
|
|
|
"read_only": 1,
|
|
|
|
"fieldname": "name",
|
|
|
|
"fieldtype": "Data"
|
|
|
|
},
|
2017-02-01 12:37:22 +00:00
|
|
|
{
|
2017-02-01 12:47:35 +00:00
|
|
|
"label": __("Address Line 1"),
|
2017-02-01 12:37:22 +00:00
|
|
|
"fieldname": "address_line1",
|
|
|
|
"fieldtype": "Data"
|
|
|
|
},
|
|
|
|
{
|
2017-02-01 12:47:35 +00:00
|
|
|
"label": __("Address Line 2"),
|
2017-02-01 12:37:22 +00:00
|
|
|
"fieldname": "address_line2",
|
|
|
|
"fieldtype": "Data"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldtype": "Column Break"
|
|
|
|
},
|
|
|
|
{
|
2017-02-01 12:47:35 +00:00
|
|
|
"label": __("City"),
|
2017-02-01 12:37:22 +00:00
|
|
|
"fieldname": "city",
|
|
|
|
"fieldtype": "Data"
|
|
|
|
},
|
|
|
|
{
|
2017-02-01 12:47:35 +00:00
|
|
|
"label": __("State"),
|
2017-02-01 12:37:22 +00:00
|
|
|
"fieldname": "state",
|
|
|
|
"fieldtype": "Data"
|
|
|
|
},
|
|
|
|
{
|
2017-02-01 12:47:35 +00:00
|
|
|
"label": __("ZIP Code"),
|
2017-03-07 08:31:04 +00:00
|
|
|
"fieldname": "pincode",
|
|
|
|
"fieldtype": "Data"
|
2017-06-07 06:34:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"label": __("Customer POS Id"),
|
|
|
|
"fieldname": "customer_pos_id",
|
|
|
|
"fieldtype": "Data",
|
|
|
|
"hidden": 1
|
2017-02-01 12:37:22 +00:00
|
|
|
}
|
|
|
|
]
|
2016-12-27 08:45:52 +00:00
|
|
|
})
|
2017-02-01 12:37:22 +00:00
|
|
|
this.customer_doc.show()
|
2017-03-07 08:31:04 +00:00
|
|
|
this.render_address_data()
|
2017-02-01 12:47:35 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
this.customer_doc.set_primary_action(__("Save"), function () {
|
2017-03-23 11:34:00 +00:00
|
|
|
me.make_offline_customer(new_customer);
|
2017-02-01 12:37:22 +00:00
|
|
|
me.pos_bill.show();
|
2017-05-02 12:57:09 +00:00
|
|
|
me.list_customers.hide();
|
2017-02-01 12:37:22 +00:00
|
|
|
});
|
2016-12-27 08:45:52 +00:00
|
|
|
},
|
2017-02-01 12:47:35 +00:00
|
|
|
|
2017-03-07 08:31:04 +00:00
|
|
|
render_address_data: function() {
|
|
|
|
var me = this;
|
2017-06-07 06:34:01 +00:00
|
|
|
this.address_data = this.address[this.frm.doc.customer] || {};
|
|
|
|
if(!this.address_data.email_id || !this.address_data.phone) {
|
|
|
|
this.address_data = this.contacts[this.frm.doc.customer];
|
|
|
|
}
|
2017-03-07 08:31:04 +00:00
|
|
|
|
2017-06-07 06:34:01 +00:00
|
|
|
this.customer_doc.set_values(this.address_data)
|
2017-03-10 09:26:19 +00:00
|
|
|
if(!this.customer_doc.fields_dict.full_name.$input.val()) {
|
|
|
|
this.customer_doc.set_value("full_name", this.frm.doc.customer)
|
2017-03-07 08:31:04 +00:00
|
|
|
}
|
2017-06-07 06:34:01 +00:00
|
|
|
|
|
|
|
if(!this.customer_doc.fields_dict.customer_pos_id.value) {
|
2019-03-26 13:42:25 +00:00
|
|
|
this.customer_doc.set_value("customer_pos_id", frappe.datetime.now_datetime())
|
2017-06-07 06:34:01 +00:00
|
|
|
}
|
2017-03-07 08:31:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get_address_from_localstorage: function() {
|
|
|
|
this.address_details = this.get_customers_details()
|
|
|
|
return this.address_details[this.frm.doc.customer]
|
|
|
|
},
|
|
|
|
|
2017-03-23 11:34:00 +00:00
|
|
|
make_offline_customer: function(new_customer) {
|
2017-03-07 08:31:04 +00:00
|
|
|
this.frm.doc.customer = this.frm.doc.customer || this.customer_doc.get_values().full_name;
|
2017-06-07 06:34:01 +00:00
|
|
|
this.frm.doc.customer_pos_id = this.customer_doc.fields_dict.customer_pos_id.value;
|
2017-03-10 09:26:19 +00:00
|
|
|
this.customer_details = this.get_customers_details();
|
2017-03-07 08:31:04 +00:00
|
|
|
this.customer_details[this.frm.doc.customer] = this.get_prompt_details();
|
2017-02-01 12:37:22 +00:00
|
|
|
this.party_field.$input.val(this.frm.doc.customer);
|
2017-03-23 11:34:00 +00:00
|
|
|
this.update_address_and_customer_list(new_customer)
|
|
|
|
this.autocomplete_customers();
|
2017-03-07 08:31:04 +00:00
|
|
|
this.update_customer_in_localstorage()
|
|
|
|
this.update_customer_in_localstorage()
|
2017-02-01 12:37:22 +00:00
|
|
|
this.customer_doc.hide()
|
|
|
|
},
|
|
|
|
|
2017-03-23 11:34:00 +00:00
|
|
|
update_address_and_customer_list: function(new_customer) {
|
|
|
|
var me = this;
|
|
|
|
if(new_customer) {
|
|
|
|
this.customers_mapper.push({
|
|
|
|
label: this.frm.doc.customer,
|
|
|
|
value: this.frm.doc.customer,
|
|
|
|
customer_group: "",
|
|
|
|
territory: ""
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-07 06:34:01 +00:00
|
|
|
this.address[this.frm.doc.customer] = JSON.parse(this.get_prompt_details())
|
2017-03-23 11:34:00 +00:00
|
|
|
},
|
|
|
|
|
2017-03-07 08:31:04 +00:00
|
|
|
get_prompt_details: function() {
|
|
|
|
this.prompt_details = this.customer_doc.get_values();
|
2017-03-10 09:26:19 +00:00
|
|
|
this.prompt_details['country'] = this.pos_profile_data.country;
|
2017-07-28 15:22:02 +00:00
|
|
|
this.prompt_details['territory'] = this.pos_profile_data["territory"];
|
|
|
|
this.prompt_details['customer_group'] = this.pos_profile_data["customer_group"];
|
2017-06-07 06:34:01 +00:00
|
|
|
this.prompt_details['customer_pos_id'] = this.customer_doc.fields_dict.customer_pos_id.value;
|
2017-03-07 08:31:04 +00:00
|
|
|
return JSON.stringify(this.prompt_details)
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
update_customer_data: function (doc) {
|
2016-12-27 08:45:52 +00:00
|
|
|
var me = this;
|
|
|
|
this.frm.doc.customer = doc.label || doc.name;
|
|
|
|
this.frm.doc.customer_name = doc.customer_name;
|
|
|
|
this.frm.doc.customer_group = doc.customer_group;
|
|
|
|
this.frm.doc.territory = doc.territory;
|
2017-02-01 12:37:22 +00:00
|
|
|
this.pos_bill.show();
|
2017-02-24 12:32:50 +00:00
|
|
|
this.numeric_keypad.show();
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
2014-08-08 10:00:49 +00:00
|
|
|
|
2019-01-28 12:28:44 +00:00
|
|
|
make_item_list: function (customer) {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-02-01 12:37:22 +00:00
|
|
|
if (!this.price_list) {
|
2017-05-30 07:24:42 +00:00
|
|
|
frappe.msgprint(__("Price List not found or disabled"));
|
2016-04-09 09:01:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
me.item_timeout = null;
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2016-04-09 09:01:09 +00:00
|
|
|
var $wrap = me.wrapper.find(".item-list");
|
|
|
|
me.wrapper.find(".item-list").empty();
|
|
|
|
|
2016-11-16 18:44:21 +00:00
|
|
|
if (this.items.length > 0) {
|
2016-04-09 09:01:09 +00:00
|
|
|
$.each(this.items, function(index, obj) {
|
2019-01-27 10:39:07 +00:00
|
|
|
let customer_price_list = me.customer_wise_price_list[customer];
|
|
|
|
let item_price
|
|
|
|
if (customer && customer_price_list && customer_price_list[obj.name]) {
|
|
|
|
item_price = format_currency(customer_price_list[obj.name], me.frm.doc.currency);
|
|
|
|
} else {
|
|
|
|
item_price = format_currency(me.price_list_data[obj.name], me.frm.doc.currency);
|
|
|
|
}
|
2017-03-06 12:31:58 +00:00
|
|
|
if(index < me.page_len) {
|
2016-04-09 09:01:09 +00:00
|
|
|
$(frappe.render_template("pos_item", {
|
|
|
|
item_code: obj.name,
|
2019-01-27 10:39:07 +00:00
|
|
|
item_price: item_price,
|
2017-02-01 12:37:22 +00:00
|
|
|
item_name: obj.name === obj.item_name ? "" : obj.item_name,
|
2017-03-06 12:31:58 +00:00
|
|
|
item_image: obj.image,
|
2017-04-13 07:06:08 +00:00
|
|
|
item_stock: __('Stock Qty') + ": " + me.get_actual_qty(obj),
|
2018-05-17 07:02:03 +00:00
|
|
|
item_uom: obj.stock_uom,
|
2016-04-09 09:01:09 +00:00
|
|
|
color: frappe.get_palette(obj.item_name),
|
|
|
|
abbr: frappe.get_abbr(obj.item_name)
|
|
|
|
})).tooltip().appendTo($wrap);
|
|
|
|
}
|
|
|
|
});
|
2017-05-19 10:32:30 +00:00
|
|
|
|
2017-03-09 09:13:37 +00:00
|
|
|
$wrap.append(`
|
|
|
|
<div class="image-view-item btn-more text-muted text-center">
|
|
|
|
<div class="image-view-body">
|
|
|
|
<i class="mega-octicon octicon-package"></i>
|
|
|
|
<div>Load more items</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
me.toggle_more_btn();
|
2016-11-16 18:44:21 +00:00
|
|
|
} else {
|
2017-02-01 12:47:35 +00:00
|
|
|
$("<p class='text-muted small' style='padding-left: 10px'>"
|
|
|
|
+__("Not items found")+"</p>").appendTo($wrap)
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (this.items.length == 1
|
2018-05-13 10:47:18 +00:00
|
|
|
&& this.search_item.$input.val()) {
|
|
|
|
this.search_item.$input.val("");
|
2016-04-09 09:01:09 +00:00
|
|
|
this.add_to_cart();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
get_items: function (item_code) {
|
2016-04-09 09:01:09 +00:00
|
|
|
// To search item as per the key enter
|
|
|
|
|
|
|
|
var me = this;
|
2016-07-15 21:32:20 +00:00
|
|
|
this.item_serial_no = {};
|
|
|
|
this.item_batch_no = {};
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (item_code) {
|
|
|
|
return $.grep(this.item_data, function (item) {
|
|
|
|
if (item.item_code == item_code) {
|
2016-04-09 09:01:09 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2017-02-01 12:47:35 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
this.items_list = this.apply_category();
|
2016-04-09 09:01:09 +00:00
|
|
|
|
2018-05-13 10:47:18 +00:00
|
|
|
key = this.search_item.$input.val().toLowerCase().replace(/[&\/\\#,+()\[\]$~.'":*?<>{}]/g, '\\$&');
|
2016-10-05 08:08:02 +00:00
|
|
|
var re = new RegExp('%', 'g');
|
2016-10-09 10:02:56 +00:00
|
|
|
var reg = new RegExp(key.replace(re, '[\\w*\\s*[a-zA-Z0-9]*]*'))
|
2016-08-10 11:48:52 +00:00
|
|
|
search_status = true
|
2016-04-09 09:01:09 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (key) {
|
|
|
|
return $.grep(this.items_list, function (item) {
|
|
|
|
if (search_status) {
|
2018-05-13 10:47:18 +00:00
|
|
|
if (in_list(me.batch_no_data[item.item_code], me.search_item.$input.val())) {
|
2016-08-10 11:48:52 +00:00
|
|
|
search_status = false;
|
2018-05-13 10:47:18 +00:00
|
|
|
return me.item_batch_no[item.item_code] = me.search_item.$input.val()
|
2017-02-01 12:37:22 +00:00
|
|
|
} else if (me.serial_no_data[item.item_code]
|
2018-05-13 10:47:18 +00:00
|
|
|
&& in_list(Object.keys(me.serial_no_data[item.item_code]), me.search_item.$input.val())) {
|
2016-08-10 11:48:52 +00:00
|
|
|
search_status = false;
|
2018-05-13 10:47:18 +00:00
|
|
|
me.item_serial_no[item.item_code] = [me.search_item.$input.val(), me.serial_no_data[item.item_code][me.search_item.$input.val()]]
|
2016-08-10 11:48:52 +00:00
|
|
|
return true
|
2018-05-13 10:47:18 +00:00
|
|
|
} else if (in_list(me.barcode_data[item.item_code], me.search_item.$input.val())) {
|
2016-08-10 11:48:52 +00:00
|
|
|
search_status = false;
|
2017-12-10 16:27:09 +00:00
|
|
|
return true;
|
2017-07-12 09:31:56 +00:00
|
|
|
} else if (reg.test(item.item_code.toLowerCase()) || (item.description && reg.test(item.description.toLowerCase())) ||
|
2017-02-01 12:37:22 +00:00
|
|
|
reg.test(item.item_name.toLowerCase()) || reg.test(item.item_group.toLowerCase())) {
|
2016-08-10 11:48:52 +00:00
|
|
|
return true
|
|
|
|
}
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
|
|
|
})
|
2017-02-01 12:37:22 +00:00
|
|
|
} else {
|
|
|
|
return this.items_list;
|
|
|
|
}
|
|
|
|
},
|
2017-02-01 12:47:35 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
apply_category: function() {
|
2019-01-19 08:31:38 +00:00
|
|
|
var me = this;
|
|
|
|
category = this.selected_item_group || "All Item Groups";
|
|
|
|
if(category == 'All Item Groups') {
|
|
|
|
return this.item_data
|
|
|
|
} else {
|
|
|
|
return this.item_data.filter(function(element, index, array){
|
|
|
|
return element.item_group == category;
|
|
|
|
});
|
|
|
|
}
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
2017-05-19 10:32:30 +00:00
|
|
|
|
2017-02-28 11:21:17 +00:00
|
|
|
bind_items_event: function() {
|
|
|
|
var me = this;
|
2017-03-06 12:31:58 +00:00
|
|
|
$(this.wrapper).on('click', '.pos-bill-item', function() {
|
|
|
|
$(me.wrapper).find('.pos-bill-item').removeClass('active');
|
|
|
|
$(this).addClass('active');
|
2017-02-28 11:21:17 +00:00
|
|
|
me.numeric_val = "";
|
|
|
|
me.numeric_id = ""
|
|
|
|
me.item_code = $(this).attr("data-item-code");
|
|
|
|
me.render_selected_item()
|
|
|
|
me.bind_qty_event()
|
|
|
|
me.update_rate()
|
|
|
|
$(me.wrapper).find(".selected-item").scrollTop(1000);
|
|
|
|
})
|
|
|
|
},
|
2016-04-09 09:01:09 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
bind_qty_event: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-03-16 09:51:21 +00:00
|
|
|
|
2017-02-28 11:21:17 +00:00
|
|
|
$(this.wrapper).on("change", ".pos-item-qty", function () {
|
2017-03-08 12:04:39 +00:00
|
|
|
var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code");
|
2016-12-21 11:53:01 +00:00
|
|
|
var qty = $(this).val();
|
2019-01-29 06:31:54 +00:00
|
|
|
me.update_qty(item_code, qty);
|
|
|
|
me.update_value();
|
|
|
|
})
|
|
|
|
|
|
|
|
$(this.wrapper).on("focusout", ".pos-item-qty", function () {
|
|
|
|
var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code");
|
|
|
|
var qty = $(this).val();
|
|
|
|
me.update_qty(item_code, qty, true);
|
|
|
|
me.update_value();
|
2016-04-09 09:01:09 +00:00
|
|
|
})
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
$(this.wrapper).find("[data-action='increase-qty']").on("click", function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
|
|
|
|
var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) + 1;
|
2019-01-29 06:31:54 +00:00
|
|
|
me.update_qty(item_code, qty);
|
2016-04-09 09:01:09 +00:00
|
|
|
})
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
$(this.wrapper).find("[data-action='decrease-qty']").on("click", function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
|
|
|
|
var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) - 1;
|
2019-01-29 06:31:54 +00:00
|
|
|
me.update_qty(item_code, qty);
|
2016-05-20 18:25:45 +00:00
|
|
|
})
|
2017-05-19 10:32:30 +00:00
|
|
|
|
2017-02-28 11:21:17 +00:00
|
|
|
$(this.wrapper).on("change", ".pos-item-disc", function () {
|
2017-03-08 12:04:39 +00:00
|
|
|
var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code");
|
2017-02-01 12:37:22 +00:00
|
|
|
var discount = $(this).val();
|
2018-02-07 20:02:48 +00:00
|
|
|
if(discount > 100){
|
|
|
|
discount = $(this).val('');
|
|
|
|
frappe.show_alert({
|
|
|
|
indicator: 'red',
|
|
|
|
message: __('Discount amount cannot be greater than 100%')
|
|
|
|
});
|
|
|
|
me.update_discount(item_code, discount);
|
2018-07-17 12:52:51 +00:00
|
|
|
}else{
|
2018-02-07 20:02:48 +00:00
|
|
|
me.update_discount(item_code, discount);
|
|
|
|
me.update_value();
|
|
|
|
}
|
2017-02-01 12:37:22 +00:00
|
|
|
})
|
2016-05-20 18:25:45 +00:00
|
|
|
},
|
2016-12-27 06:44:26 +00:00
|
|
|
|
2017-03-08 12:04:39 +00:00
|
|
|
bind_events: function() {
|
|
|
|
var me = this;
|
|
|
|
// if form is local then allow this function
|
|
|
|
// $(me.wrapper).find(".pos-item-wrapper").on("click", function () {
|
|
|
|
$(this.wrapper).on("click", ".pos-item-wrapper", function () {
|
2017-03-30 13:46:38 +00:00
|
|
|
me.item_code = '';
|
2017-04-17 08:06:08 +00:00
|
|
|
me.customer_validate();
|
2017-03-23 11:34:00 +00:00
|
|
|
if($(me.pos_bill).is(":hidden")) return;
|
2017-03-08 12:04:39 +00:00
|
|
|
|
|
|
|
if (me.frm.doc.docstatus == 0) {
|
|
|
|
me.items = me.get_items($(this).attr("data-item-code"))
|
|
|
|
me.add_to_cart();
|
2017-03-16 09:51:21 +00:00
|
|
|
me.clear_selected_row();
|
2017-03-08 12:04:39 +00:00
|
|
|
}
|
|
|
|
});
|
2017-03-10 09:26:19 +00:00
|
|
|
|
|
|
|
me.bind_delete_event()
|
2017-03-08 12:04:39 +00:00
|
|
|
},
|
|
|
|
|
2019-01-29 06:31:54 +00:00
|
|
|
update_qty: function (item_code, qty, remove_zero_qty_items) {
|
2016-12-21 11:53:01 +00:00
|
|
|
var me = this;
|
|
|
|
this.items = this.get_items(item_code);
|
|
|
|
this.validate_serial_no()
|
2019-01-29 06:31:54 +00:00
|
|
|
this.set_item_details(item_code, "qty", qty, remove_zero_qty_items);
|
2017-02-01 12:37:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
update_discount: function(item_code, discount) {
|
|
|
|
var me = this;
|
|
|
|
this.items = this.get_items(item_code);
|
|
|
|
this.set_item_details(item_code, "discount_percentage", discount);
|
2016-12-21 11:53:01 +00:00
|
|
|
},
|
2016-05-20 18:25:45 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
update_rate: function () {
|
2016-05-20 18:25:45 +00:00
|
|
|
var me = this;
|
2017-02-28 11:21:17 +00:00
|
|
|
$(this.wrapper).on("change", ".pos-item-price", function () {
|
2017-03-08 12:04:39 +00:00
|
|
|
var item_code = $(this).parents(".pos-selected-item-action").attr("data-item-code");
|
2017-02-01 12:37:22 +00:00
|
|
|
me.set_item_details(item_code, "rate", $(this).val());
|
2017-03-16 09:51:21 +00:00
|
|
|
me.update_value()
|
2016-04-09 09:01:09 +00:00
|
|
|
})
|
|
|
|
},
|
2017-02-28 11:21:17 +00:00
|
|
|
|
2017-03-16 09:51:21 +00:00
|
|
|
update_value: function() {
|
|
|
|
var me = this;
|
|
|
|
var fields = {qty: ".pos-item-qty", "discount_percentage": ".pos-item-disc",
|
|
|
|
"rate": ".pos-item-price", "amount": ".pos-amount"}
|
|
|
|
this.child_doc = this.get_child_item(this.item_code);
|
|
|
|
|
|
|
|
if(me.child_doc.length) {
|
|
|
|
$.each(fields, function(key, field) {
|
|
|
|
$(me.selected_row).find(field).val(me.child_doc[0][key])
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.clear_selected_row();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clear_selected_row: function() {
|
|
|
|
$(this.wrapper).find('.selected-item').empty();
|
|
|
|
},
|
|
|
|
|
2017-02-28 11:21:17 +00:00
|
|
|
render_selected_item: function() {
|
2017-03-16 09:51:21 +00:00
|
|
|
this.child_doc = this.get_child_item(this.item_code);
|
2017-02-28 11:21:17 +00:00
|
|
|
$(this.wrapper).find('.selected-item').empty();
|
2017-03-16 09:51:21 +00:00
|
|
|
if(this.child_doc.length) {
|
2017-06-07 06:34:01 +00:00
|
|
|
this.child_doc[0]["allow_user_to_edit_rate"] = this.pos_profile_data["allow_user_to_edit_rate"] ? true : false,
|
2018-03-08 10:51:13 +00:00
|
|
|
this.child_doc[0]["allow_user_to_edit_discount"] = this.pos_profile_data["allow_user_to_edit_discount"] ? true : false;
|
2017-03-16 09:51:21 +00:00
|
|
|
this.selected_row = $(frappe.render_template("pos_selected_item", this.child_doc[0]))
|
2017-02-28 11:21:17 +00:00
|
|
|
$(this.wrapper).find('.selected-item').html(this.selected_row)
|
|
|
|
}
|
2017-03-16 09:51:21 +00:00
|
|
|
|
|
|
|
$(this.selected_row).find('.form-control').click(function(){
|
|
|
|
$(this).select();
|
|
|
|
})
|
2017-02-28 11:21:17 +00:00
|
|
|
},
|
2017-03-16 09:51:21 +00:00
|
|
|
|
2017-02-24 12:32:50 +00:00
|
|
|
get_child_item: function(item_code) {
|
|
|
|
var me = this;
|
|
|
|
return $.map(me.frm.doc.items, function(doc){
|
|
|
|
if(doc.item_code == item_code) {
|
|
|
|
return doc
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2017-02-28 11:21:17 +00:00
|
|
|
|
2019-01-29 06:31:54 +00:00
|
|
|
set_item_details: function (item_code, field, value, remove_zero_qty_items) {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-02-01 12:37:22 +00:00
|
|
|
if (value < 0) {
|
2016-05-20 18:25:45 +00:00
|
|
|
frappe.throw(__("Enter value must be positive"));
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2016-04-09 09:01:09 +00:00
|
|
|
this.remove_item = []
|
2017-02-01 12:37:22 +00:00
|
|
|
$.each(this.frm.doc["items"] || [], function (i, d) {
|
2016-04-09 09:01:09 +00:00
|
|
|
if (d.item_code == item_code) {
|
2017-02-01 12:37:22 +00:00
|
|
|
if (d.serial_no && field == 'qty') {
|
|
|
|
me.validate_serial_no_qty(d, item_code, field, value)
|
|
|
|
}
|
|
|
|
|
2016-05-20 18:25:45 +00:00
|
|
|
d[field] = flt(value);
|
2016-04-09 09:01:09 +00:00
|
|
|
d.amount = flt(d.rate) * flt(d.qty);
|
2019-01-29 06:31:54 +00:00
|
|
|
if (d.qty == 0 && remove_zero_qty_items) {
|
2016-04-09 09:01:09 +00:00
|
|
|
me.remove_item.push(d.idx)
|
|
|
|
}
|
2017-03-16 09:51:21 +00:00
|
|
|
|
|
|
|
if(field=="discount_percentage" && value == 0) {
|
|
|
|
d.rate = d.price_list_rate;
|
|
|
|
}
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
|
|
|
});
|
2016-05-20 18:25:45 +00:00
|
|
|
|
2019-01-29 06:31:54 +00:00
|
|
|
if (field == 'qty') {
|
|
|
|
this.remove_zero_qty_items_from_cart();
|
|
|
|
}
|
|
|
|
|
2016-08-19 09:41:36 +00:00
|
|
|
this.update_paid_amount_status(false)
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2019-01-29 06:31:54 +00:00
|
|
|
remove_zero_qty_items_from_cart: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-05-30 07:24:42 +00:00
|
|
|
var idx = 0;
|
2016-04-09 09:01:09 +00:00
|
|
|
this.items = []
|
2017-02-01 12:37:22 +00:00
|
|
|
$.each(this.frm.doc["items"] || [], function (i, d) {
|
|
|
|
if (!in_list(me.remove_item, d.idx)) {
|
2016-04-09 09:01:09 +00:00
|
|
|
d.idx = idx;
|
|
|
|
me.items.push(d);
|
2016-05-20 07:24:44 +00:00
|
|
|
idx++;
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
|
|
|
});
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2016-04-09 09:01:09 +00:00
|
|
|
this.frm.doc["items"] = this.items;
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
make_discount_field: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
this.wrapper.find('input.discount-percentage').on("change", function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
me.frm.doc.additional_discount_percentage = flt($(this).val(), precision("additional_discount_percentage"));
|
2017-10-21 05:53:45 +00:00
|
|
|
|
|
|
|
if(me.frm.doc.additional_discount_percentage && me.frm.doc.discount_amount) {
|
|
|
|
// Reset discount amount
|
|
|
|
me.frm.doc.discount_amount = 0;
|
|
|
|
}
|
|
|
|
|
2017-05-30 07:24:42 +00:00
|
|
|
var total = me.frm.doc.grand_total
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (me.frm.doc.apply_discount_on == 'Net Total') {
|
2016-04-09 09:01:09 +00:00
|
|
|
total = me.frm.doc.net_total
|
|
|
|
}
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
me.frm.doc.discount_amount = flt(total * flt(me.frm.doc.additional_discount_percentage) / 100, precision("discount_amount"));
|
2016-04-09 09:01:09 +00:00
|
|
|
me.refresh();
|
2017-10-21 05:53:45 +00:00
|
|
|
me.wrapper.find('input.discount-amount').val(me.frm.doc.discount_amount)
|
2016-04-09 09:01:09 +00:00
|
|
|
});
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
this.wrapper.find('input.discount-amount').on("change", function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
me.frm.doc.discount_amount = flt($(this).val(), precision("discount_amount"));
|
|
|
|
me.frm.doc.additional_discount_percentage = 0.0;
|
|
|
|
me.refresh();
|
2017-10-21 05:53:45 +00:00
|
|
|
me.wrapper.find('input.discount-percentage').val(0);
|
2016-04-09 09:01:09 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
customer_validate: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-03-23 11:34:00 +00:00
|
|
|
if (!this.frm.doc.customer || this.party_field.get_value() == "") {
|
2016-04-09 09:01:09 +00:00
|
|
|
frappe.throw(__("Please select customer"))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
add_to_cart: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
var caught = false;
|
|
|
|
var no_of_items = me.wrapper.find(".pos-bill-item").length;
|
|
|
|
|
2016-07-15 21:32:20 +00:00
|
|
|
this.customer_validate();
|
|
|
|
this.mandatory_batch_no();
|
|
|
|
this.validate_serial_no();
|
2016-04-09 09:01:09 +00:00
|
|
|
this.validate_warehouse();
|
|
|
|
|
|
|
|
if (no_of_items != 0) {
|
2017-02-01 12:37:22 +00:00
|
|
|
$.each(this.frm.doc["items"] || [], function (i, d) {
|
2016-04-09 09:01:09 +00:00
|
|
|
if (d.item_code == me.items[0].item_code) {
|
|
|
|
caught = true;
|
|
|
|
d.qty += 1;
|
2016-07-15 21:32:20 +00:00
|
|
|
d.amount = flt(d.rate) * flt(d.qty);
|
2017-02-01 12:37:22 +00:00
|
|
|
if (me.item_serial_no[d.item_code]) {
|
2016-07-15 21:32:20 +00:00
|
|
|
d.serial_no += '\n' + me.item_serial_no[d.item_code][0]
|
|
|
|
d.warehouse = me.item_serial_no[d.item_code][1]
|
|
|
|
}
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (me.item_batch_no.length) {
|
2016-07-15 21:32:20 +00:00
|
|
|
d.batch_no = me.item_batch_no[d.item_code]
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// if item not found then add new item
|
|
|
|
if (!caught)
|
|
|
|
this.add_new_item_to_grid();
|
|
|
|
|
2016-08-19 09:41:36 +00:00
|
|
|
this.update_paid_amount_status(false)
|
2017-03-09 09:13:37 +00:00
|
|
|
this.wrapper.find(".item-cart-items").scrollTop(1000);
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
add_new_item_to_grid: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
this.child = frappe.model.add_child(this.frm.doc, this.frm.doc.doctype + " Item", "items");
|
|
|
|
this.child.item_code = this.items[0].item_code;
|
|
|
|
this.child.item_name = this.items[0].item_name;
|
|
|
|
this.child.stock_uom = this.items[0].stock_uom;
|
2018-11-13 06:04:27 +00:00
|
|
|
this.child.uom = this.items[0].sales_uom || this.items[0].stock_uom;
|
|
|
|
this.child.conversion_factor = this.items[0].conversion_factor || 1;
|
2017-03-16 09:51:21 +00:00
|
|
|
this.child.brand = this.items[0].brand;
|
2017-07-12 09:31:56 +00:00
|
|
|
this.child.description = this.items[0].description || this.items[0].item_name;
|
2017-02-24 12:32:50 +00:00
|
|
|
this.child.discount_percentage = 0.0;
|
2016-04-09 09:01:09 +00:00
|
|
|
this.child.qty = 1;
|
|
|
|
this.child.item_group = this.items[0].item_group;
|
2016-11-20 18:11:13 +00:00
|
|
|
this.child.cost_center = this.pos_profile_data['cost_center'] || this.items[0].cost_center;
|
|
|
|
this.child.income_account = this.pos_profile_data['income_account'] || this.items[0].income_account;
|
2016-07-15 21:32:20 +00:00
|
|
|
this.child.warehouse = (this.item_serial_no[this.child.item_code]
|
2017-02-01 12:37:22 +00:00
|
|
|
? this.item_serial_no[this.child.item_code][1] : (this.pos_profile_data['warehouse'] || this.items[0].default_warehouse));
|
2019-01-27 10:39:07 +00:00
|
|
|
|
|
|
|
customer = this.frm.doc.customer;
|
2019-01-28 12:28:44 +00:00
|
|
|
let rate;
|
2019-01-27 10:39:07 +00:00
|
|
|
|
|
|
|
customer_price_list = this.customer_wise_price_list[customer]
|
|
|
|
if (customer_price_list && customer_price_list[this.child.item_code]){
|
|
|
|
rate = flt(this.customer_wise_price_list[customer][this.child.item_code] * this.child.conversion_factor, 9) / flt(this.frm.doc.conversion_rate, 9);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
rate = flt(this.price_list_data[this.child.item_code] * this.child.conversion_factor, 9) / flt(this.frm.doc.conversion_rate, 9);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.child.price_list_rate = rate;
|
|
|
|
this.child.rate = rate;
|
2016-11-20 18:11:13 +00:00
|
|
|
this.child.actual_qty = me.get_actual_qty(this.items[0]);
|
2016-04-09 09:01:09 +00:00
|
|
|
this.child.amount = flt(this.child.qty) * flt(this.child.rate);
|
2016-07-15 21:32:20 +00:00
|
|
|
this.child.batch_no = this.item_batch_no[this.child.item_code];
|
|
|
|
this.child.serial_no = (this.item_serial_no[this.child.item_code]
|
|
|
|
? this.item_serial_no[this.child.item_code][0] : '');
|
2016-11-20 18:11:13 +00:00
|
|
|
this.child.item_tax_rate = JSON.stringify(this.tax_data[this.child.item_code]);
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
update_paid_amount_status: function (update_paid_amount) {
|
2017-11-08 06:03:39 +00:00
|
|
|
if (this.frm.doc.offline_pos_name) {
|
2016-08-19 09:41:36 +00:00
|
|
|
update_paid_amount = update_paid_amount ? false : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.refresh(update_paid_amount);
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
refresh: function (update_paid_amount) {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2016-07-21 17:58:04 +00:00
|
|
|
this.refresh_fields(update_paid_amount);
|
2016-04-09 09:01:09 +00:00
|
|
|
this.set_primary_action();
|
|
|
|
},
|
2016-08-19 09:41:36 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
refresh_fields: function (update_paid_amount) {
|
2016-04-09 09:01:09 +00:00
|
|
|
this.apply_pricing_rule();
|
|
|
|
this.discount_amount_applied = false;
|
|
|
|
this._calculate_taxes_and_totals();
|
|
|
|
this.calculate_discount_amount();
|
|
|
|
this.show_items_in_item_cart();
|
|
|
|
this.set_taxes();
|
2016-07-21 17:58:04 +00:00
|
|
|
this.calculate_outstanding_amount(update_paid_amount);
|
2016-04-09 09:01:09 +00:00
|
|
|
this.set_totals();
|
2018-03-21 03:49:36 +00:00
|
|
|
this.update_total_qty();
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
get_company_currency: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
return erpnext.get_currency(this.frm.doc.company);
|
|
|
|
},
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
show_items_in_item_cart: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
var $items = this.wrapper.find(".items").empty();
|
2017-03-06 12:31:58 +00:00
|
|
|
var $no_items_message = this.wrapper.find(".no-items-message");
|
|
|
|
$no_items_message.toggle(this.frm.doc.items.length === 0);
|
|
|
|
|
|
|
|
var $totals_area = this.wrapper.find('.totals-area');
|
|
|
|
$totals_area.toggle(this.frm.doc.items.length > 0);
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
$.each(this.frm.doc.items || [], function (i, d) {
|
2017-03-06 12:31:58 +00:00
|
|
|
$(frappe.render_template("pos_bill_item_new", {
|
2016-04-09 09:01:09 +00:00
|
|
|
item_code: d.item_code,
|
2017-02-01 12:37:22 +00:00
|
|
|
item_name: (d.item_name === d.item_code || !d.item_name) ? "" : ("<br>" + d.item_name),
|
2016-04-09 09:01:09 +00:00
|
|
|
qty: d.qty,
|
2017-02-01 12:37:22 +00:00
|
|
|
discount_percentage: d.discount_percentage || 0.0,
|
|
|
|
actual_qty: me.actual_qty_dict[d.item_code] || 0.0,
|
2016-04-09 09:01:09 +00:00
|
|
|
projected_qty: d.projected_qty,
|
2017-04-17 06:54:11 +00:00
|
|
|
rate: format_currency(d.rate, me.frm.doc.currency),
|
2017-03-21 10:25:09 +00:00
|
|
|
amount: format_currency(d.amount, me.frm.doc.currency),
|
|
|
|
selected_class: (me.item_code == d.item_code) ? "active" : ""
|
2016-04-09 09:01:09 +00:00
|
|
|
})).appendTo($items);
|
|
|
|
});
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
this.wrapper.find("input.pos-item-qty").on("focus", function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
$(this).select();
|
|
|
|
});
|
2016-05-20 18:25:45 +00:00
|
|
|
|
2017-02-28 11:21:17 +00:00
|
|
|
this.wrapper.find("input.pos-item-disc").on("focus", function () {
|
2017-02-01 12:37:22 +00:00
|
|
|
$(this).select();
|
|
|
|
});
|
|
|
|
|
2017-02-28 11:21:17 +00:00
|
|
|
this.wrapper.find("input.pos-item-price").on("focus", function () {
|
2016-05-20 18:25:45 +00:00
|
|
|
$(this).select();
|
|
|
|
});
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
set_taxes: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
me.frm.doc.total_taxes_and_charges = 0.0
|
|
|
|
|
|
|
|
var taxes = this.frm.doc.taxes || [];
|
|
|
|
$(this.wrapper)
|
|
|
|
.find(".tax-area").toggleClass("hide", (taxes && taxes.length) ? false : true)
|
|
|
|
.find(".tax-table").empty();
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
$.each(taxes, function (i, d) {
|
2016-04-09 09:01:09 +00:00
|
|
|
if (d.tax_amount && cint(d.included_in_print_rate) == 0) {
|
|
|
|
$(frappe.render_template("pos_tax_row", {
|
|
|
|
description: d.description,
|
|
|
|
tax_amount: format_currency(flt(d.tax_amount_after_discount_amount),
|
|
|
|
me.frm.doc.currency)
|
|
|
|
})).appendTo(me.wrapper.find(".tax-table"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
set_totals: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
this.wrapper.find(".net-total").text(format_currency(me.frm.doc.total, me.frm.doc.currency));
|
|
|
|
this.wrapper.find(".grand-total").text(format_currency(me.frm.doc.grand_total, me.frm.doc.currency));
|
2017-10-21 05:53:45 +00:00
|
|
|
this.wrapper.find('input.discount-percentage').val(this.frm.doc.additional_discount_percentage);
|
|
|
|
this.wrapper.find('input.discount-amount').val(this.frm.doc.discount_amount);
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2018-03-21 03:49:36 +00:00
|
|
|
update_total_qty: function() {
|
|
|
|
var me = this;
|
|
|
|
var qty_total = 0;
|
|
|
|
$.each(this.frm.doc["items"] || [], function (i, d) {
|
|
|
|
if (d.item_code) {
|
|
|
|
qty_total += d.qty;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.frm.doc.qty_total = qty_total;
|
|
|
|
this.wrapper.find('.qty-total').text(this.frm.doc.qty_total);
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
set_primary_action: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-03-10 09:26:19 +00:00
|
|
|
this.page.set_primary_action(__("New Cart"), function () {
|
|
|
|
me.make_new_cart()
|
2017-03-16 09:51:21 +00:00
|
|
|
me.make_menu_list()
|
2017-03-09 09:13:37 +00:00
|
|
|
}, "fa fa-plus")
|
2017-03-10 09:26:19 +00:00
|
|
|
|
2017-11-16 09:58:42 +00:00
|
|
|
if (this.frm.doc.docstatus == 1 || this.pos_profile_data["allow_print_before_pay"]) {
|
2017-03-10 06:10:28 +00:00
|
|
|
this.page.set_secondary_action(__("Print"), function () {
|
2017-11-16 09:58:42 +00:00
|
|
|
me.create_invoice();
|
2017-05-30 07:24:42 +00:00
|
|
|
var html = frappe.render(me.print_template_data, me.frm.doc)
|
2016-05-20 18:25:45 +00:00
|
|
|
me.print_document(html)
|
2016-04-09 09:01:09 +00:00
|
|
|
})
|
2017-11-16 09:58:42 +00:00
|
|
|
}
|
2017-12-10 16:27:09 +00:00
|
|
|
|
|
|
|
if (this.frm.doc.docstatus == 1) {
|
2017-03-16 09:51:21 +00:00
|
|
|
this.page.add_menu_item(__("Email"), function () {
|
|
|
|
me.email_prompt()
|
|
|
|
})
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
2017-03-10 09:26:19 +00:00
|
|
|
},
|
2016-06-13 16:07:10 +00:00
|
|
|
|
2017-03-10 09:26:19 +00:00
|
|
|
make_new_cart: function (){
|
2017-03-30 13:46:38 +00:00
|
|
|
this.item_code = '';
|
2017-03-16 09:51:21 +00:00
|
|
|
this.page.clear_secondary_action();
|
2017-03-10 09:26:19 +00:00
|
|
|
this.save_previous_entry();
|
|
|
|
this.create_new();
|
|
|
|
this.refresh();
|
|
|
|
this.toggle_input_field();
|
|
|
|
this.render_list_customers();
|
|
|
|
this.set_focus();
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
print_dialog: function () {
|
2016-09-11 20:07:46 +00:00
|
|
|
var me = this;
|
|
|
|
|
2017-06-22 10:48:12 +00:00
|
|
|
this.msgprint = frappe.msgprint(
|
2017-05-30 07:24:42 +00:00
|
|
|
`<a class="btn btn-primary print_doc"
|
|
|
|
style="margin-right: 5px;">${__('Print')}</a>
|
|
|
|
<a class="btn btn-default new_doc">${__('New')}</a>`);
|
2016-09-11 20:07:46 +00:00
|
|
|
|
2018-10-29 11:20:18 +00:00
|
|
|
this.msgprint.msg_area.find('.print_doc').on('click', function() {
|
|
|
|
var html = frappe.render(me.print_template_data, me.frm.doc);
|
|
|
|
me.print_document(html);
|
2016-09-11 20:07:46 +00:00
|
|
|
})
|
|
|
|
|
2018-10-29 11:20:18 +00:00
|
|
|
this.msgprint.msg_area.find('.new_doc').on('click', function() {
|
|
|
|
me.msgprint.hide();
|
|
|
|
me.make_new_cart();
|
2016-09-11 20:07:46 +00:00
|
|
|
})
|
2018-10-29 11:20:18 +00:00
|
|
|
|
2016-09-11 20:07:46 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
print_document: function (html) {
|
2016-05-20 18:25:45 +00:00
|
|
|
var w = window.open();
|
|
|
|
w.document.write(html);
|
|
|
|
w.document.close();
|
2017-02-01 12:37:22 +00:00
|
|
|
setTimeout(function () {
|
2016-05-20 18:25:45 +00:00
|
|
|
w.print();
|
|
|
|
w.close();
|
|
|
|
}, 1000)
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
submit_invoice: function () {
|
2016-05-11 09:34:57 +00:00
|
|
|
var me = this;
|
2016-09-11 20:07:46 +00:00
|
|
|
this.change_status();
|
2017-03-14 13:33:49 +00:00
|
|
|
this.update_serial_no()
|
2017-02-01 12:37:22 +00:00
|
|
|
if (this.frm.doc.docstatus == 1) {
|
2016-09-11 20:07:46 +00:00
|
|
|
this.print_dialog()
|
|
|
|
}
|
2016-05-11 09:34:57 +00:00
|
|
|
},
|
|
|
|
|
2017-03-14 13:33:49 +00:00
|
|
|
update_serial_no: function() {
|
|
|
|
var me = this;
|
|
|
|
|
|
|
|
//Remove the sold serial no from the cache
|
|
|
|
$.each(this.frm.doc.items, function(index, data) {
|
2017-05-30 07:24:42 +00:00
|
|
|
var sn = data.serial_no.split('\n')
|
2017-03-14 13:33:49 +00:00
|
|
|
if(sn.length) {
|
2017-05-30 07:24:42 +00:00
|
|
|
var serial_no_list = me.serial_no_data[data.item_code]
|
2017-03-23 11:34:00 +00:00
|
|
|
if(serial_no_list) {
|
|
|
|
$.each(sn, function(i, serial_no) {
|
|
|
|
if(in_list(Object.keys(serial_no_list), serial_no)) {
|
|
|
|
delete serial_no_list[serial_no]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
me.serial_no_data[data.item_code] = serial_no_list;
|
|
|
|
}
|
2017-03-14 13:33:49 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
change_status: function () {
|
|
|
|
if (this.frm.doc.docstatus == 0) {
|
2016-04-09 09:01:09 +00:00
|
|
|
this.frm.doc.docstatus = 1;
|
|
|
|
this.update_invoice();
|
2017-03-08 12:04:39 +00:00
|
|
|
this.toggle_input_field();
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-03-08 12:04:39 +00:00
|
|
|
toggle_input_field: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var pointer_events = 'inherit'
|
2017-05-30 07:24:42 +00:00
|
|
|
var disabled = this.frm.doc.docstatus == 1 ? true: false;
|
2017-03-08 12:04:39 +00:00
|
|
|
$(this.wrapper).find('input').attr("disabled", disabled);
|
|
|
|
$(this.wrapper).find('select').attr("disabled", disabled);
|
|
|
|
$(this.wrapper).find('input').attr("disabled", disabled);
|
|
|
|
$(this.wrapper).find('select').attr("disabled", disabled);
|
2017-03-10 09:26:19 +00:00
|
|
|
$(this.wrapper).find('button').attr("disabled", disabled);
|
|
|
|
this.party_field.$input.attr('disabled', disabled);
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (this.frm.doc.docstatus == 1) {
|
2016-07-15 21:32:20 +00:00
|
|
|
pointer_events = 'none';
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
$(this.wrapper).find('.pos-bill').css('pointer-events', pointer_events);
|
2016-04-09 09:01:09 +00:00
|
|
|
$(this.wrapper).find('.pos-items-section').css('pointer-events', pointer_events);
|
|
|
|
this.set_primary_action();
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
create_invoice: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2019-03-26 13:42:25 +00:00
|
|
|
var existing_pos_list = [];
|
2017-11-08 06:03:39 +00:00
|
|
|
var invoice_data = {};
|
2016-04-09 09:01:09 +00:00
|
|
|
this.si_docs = this.get_doc_from_localstorage();
|
2018-03-21 03:49:36 +00:00
|
|
|
|
2019-03-26 13:42:25 +00:00
|
|
|
if(this.si_docs) {
|
|
|
|
this.si_docs.forEach((row) => {
|
|
|
|
existing_pos_list.push(Object.keys(row));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.frm.doc.offline_pos_name
|
|
|
|
&& in_list(existing_pos_list, this.frm.doc.offline_pos_name)) {
|
2016-04-09 09:01:09 +00:00
|
|
|
this.update_invoice()
|
2017-11-22 13:49:51 +00:00
|
|
|
//to retrieve and set the default payment
|
2018-02-01 11:24:10 +00:00
|
|
|
invoice_data[this.frm.doc.offline_pos_name] = this.frm.doc;
|
|
|
|
invoice_data[this.frm.doc.offline_pos_name].payments[0].amount = this.frm.doc.net_total
|
|
|
|
invoice_data[this.frm.doc.offline_pos_name].payments[0].base_amount = this.frm.doc.net_total
|
2017-11-22 13:49:51 +00:00
|
|
|
|
|
|
|
this.frm.doc.paid_amount = this.frm.doc.net_total
|
|
|
|
this.frm.doc.outstanding_amount = 0
|
2019-03-26 13:42:25 +00:00
|
|
|
} else if(!this.frm.doc.offline_pos_name) {
|
|
|
|
this.frm.doc.offline_pos_name = frappe.datetime.now_datetime();
|
2016-08-11 11:24:30 +00:00
|
|
|
this.frm.doc.posting_date = frappe.datetime.get_today();
|
|
|
|
this.frm.doc.posting_time = frappe.datetime.now_time();
|
2018-03-21 03:49:36 +00:00
|
|
|
this.frm.doc.pos_total_qty = this.frm.doc.qty_total;
|
2017-06-19 03:55:54 +00:00
|
|
|
this.frm.doc.pos_profile = this.pos_profile_data['name'];
|
2017-11-08 06:03:39 +00:00
|
|
|
invoice_data[this.frm.doc.offline_pos_name] = this.frm.doc;
|
|
|
|
this.si_docs.push(invoice_data);
|
2016-04-09 09:01:09 +00:00
|
|
|
this.update_localstorage();
|
|
|
|
this.set_primary_action();
|
|
|
|
}
|
2017-02-01 12:37:22 +00:00
|
|
|
return invoice_data;
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
update_invoice: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
this.si_docs = this.get_doc_from_localstorage();
|
2017-02-01 12:37:22 +00:00
|
|
|
$.each(this.si_docs, function (index, data) {
|
2017-05-30 07:24:42 +00:00
|
|
|
for (var key in data) {
|
2017-11-08 06:03:39 +00:00
|
|
|
if (key == me.frm.doc.offline_pos_name) {
|
2016-07-15 21:32:20 +00:00
|
|
|
me.si_docs[index][key] = me.frm.doc;
|
2016-04-09 09:01:09 +00:00
|
|
|
me.update_localstorage();
|
|
|
|
}
|
|
|
|
}
|
2017-11-08 06:03:39 +00:00
|
|
|
});
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
update_localstorage: function () {
|
|
|
|
try {
|
2016-04-09 09:01:09 +00:00
|
|
|
localStorage.setItem('sales_invoice_doc', JSON.stringify(this.si_docs));
|
2017-02-01 12:37:22 +00:00
|
|
|
} catch (e) {
|
2016-04-09 09:01:09 +00:00
|
|
|
frappe.throw(__("LocalStorage is full , did not save"))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
get_doc_from_localstorage: function () {
|
|
|
|
try {
|
2016-05-11 09:34:57 +00:00
|
|
|
return JSON.parse(localStorage.getItem('sales_invoice_doc')) || [];
|
2017-02-01 12:37:22 +00:00
|
|
|
} catch (e) {
|
2016-05-11 09:34:57 +00:00
|
|
|
return []
|
|
|
|
}
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
set_interval_for_si_sync: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-02-01 12:37:22 +00:00
|
|
|
setInterval(function () {
|
2017-10-02 06:43:36 +00:00
|
|
|
me.freeze_screen = false;
|
2016-04-09 09:01:09 +00:00
|
|
|
me.sync_sales_invoice()
|
2018-03-08 10:51:13 +00:00
|
|
|
}, 180000)
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
sync_sales_invoice: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-02-28 19:43:09 +00:00
|
|
|
this.si_docs = this.get_submitted_invoice() || [];
|
|
|
|
this.email_queue_list = this.get_email_queue() || {};
|
2017-03-07 08:31:04 +00:00
|
|
|
this.customers_list = this.get_customers_details() || {};
|
2017-11-08 06:03:39 +00:00
|
|
|
|
2019-08-23 05:43:58 +00:00
|
|
|
if (this.si_docs.length || this.email_queue_list || this.customers_list) {
|
2016-04-09 09:01:09 +00:00
|
|
|
frappe.call({
|
|
|
|
method: "erpnext.accounts.doctype.sales_invoice.pos.make_invoice",
|
2019-08-23 05:43:58 +00:00
|
|
|
freeze: true,
|
2016-04-09 09:01:09 +00:00
|
|
|
args: {
|
2017-02-28 19:43:09 +00:00
|
|
|
doc_list: me.si_docs,
|
2017-03-07 08:31:04 +00:00
|
|
|
email_queue_list: me.email_queue_list,
|
|
|
|
customers_list: me.customers_list
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
2017-02-01 12:37:22 +00:00
|
|
|
callback: function (r) {
|
|
|
|
if (r.message) {
|
2017-11-08 06:03:39 +00:00
|
|
|
me.freeze = false;
|
2017-06-07 06:34:01 +00:00
|
|
|
me.customers = r.message.synced_customers_list;
|
|
|
|
me.address = r.message.synced_address;
|
|
|
|
me.contacts = r.message.synced_contacts;
|
2017-02-28 19:43:09 +00:00
|
|
|
me.removed_items = r.message.invoice;
|
2017-11-08 06:03:39 +00:00
|
|
|
me.removed_email = r.message.email_queue;
|
|
|
|
me.removed_customers = r.message.customers;
|
2016-04-09 09:01:09 +00:00
|
|
|
me.remove_doc_from_localstorage();
|
2017-02-28 19:43:09 +00:00
|
|
|
me.remove_email_queue_from_localstorage();
|
2017-03-07 08:31:04 +00:00
|
|
|
me.remove_customer_from_localstorage();
|
2017-11-08 06:03:39 +00:00
|
|
|
me.prepare_customer_mapper();
|
|
|
|
me.autocomplete_customers();
|
|
|
|
me.render_list_customers();
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
get_submitted_invoice: function () {
|
2016-05-20 18:25:45 +00:00
|
|
|
var invoices = [];
|
|
|
|
var index = 1;
|
2017-05-30 07:24:42 +00:00
|
|
|
var docs = this.get_doc_from_localstorage();
|
2017-02-01 12:37:22 +00:00
|
|
|
if (docs) {
|
|
|
|
invoices = $.map(docs, function (data) {
|
2017-05-30 07:24:42 +00:00
|
|
|
for (var key in data) {
|
2017-02-01 12:37:22 +00:00
|
|
|
if (data[key].docstatus == 1 && index < 50) {
|
2016-05-20 18:25:45 +00:00
|
|
|
index++
|
2016-08-01 13:05:18 +00:00
|
|
|
data[key].docstatus = 0;
|
2016-04-09 09:01:09 +00:00
|
|
|
return data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return invoices
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
remove_doc_from_localstorage: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
this.si_docs = this.get_doc_from_localstorage();
|
2016-07-15 21:32:20 +00:00
|
|
|
this.new_si_docs = [];
|
2017-03-08 12:04:39 +00:00
|
|
|
if (this.removed_items) {
|
2017-02-01 12:37:22 +00:00
|
|
|
$.each(this.si_docs, function (index, data) {
|
2017-05-30 07:24:42 +00:00
|
|
|
for (var key in data) {
|
2017-03-08 12:04:39 +00:00
|
|
|
if (!in_list(me.removed_items, key)) {
|
2016-07-15 21:32:20 +00:00
|
|
|
me.new_si_docs.push(data);
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2017-03-10 09:26:19 +00:00
|
|
|
this.removed_items = [];
|
2016-05-11 09:34:57 +00:00
|
|
|
this.si_docs = this.new_si_docs;
|
2016-04-09 09:01:09 +00:00
|
|
|
this.update_localstorage();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-28 19:43:09 +00:00
|
|
|
remove_email_queue_from_localstorage: function() {
|
|
|
|
var me = this;
|
|
|
|
this.email_queue = this.get_email_queue()
|
|
|
|
if (this.removed_email) {
|
|
|
|
$.each(this.email_queue_list, function (index, data) {
|
|
|
|
if (in_list(me.removed_email, index)) {
|
|
|
|
delete me.email_queue[index]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.update_email_queue();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-03-07 08:31:04 +00:00
|
|
|
remove_customer_from_localstorage: function() {
|
|
|
|
var me = this;
|
|
|
|
this.customer_details = this.get_customers_details()
|
|
|
|
if (this.removed_customers) {
|
|
|
|
$.each(this.customers_list, function (index, data) {
|
|
|
|
if (in_list(me.removed_customers, index)) {
|
|
|
|
delete me.customer_details[index]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.update_customer_in_localstorage();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
validate: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
|
|
|
this.customer_validate();
|
2019-01-29 06:31:54 +00:00
|
|
|
this.validate_zero_qty_items();
|
2016-04-09 09:01:09 +00:00
|
|
|
this.item_validate();
|
2016-07-15 21:32:20 +00:00
|
|
|
this.validate_mode_of_payments();
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2019-01-29 06:31:54 +00:00
|
|
|
validate_zero_qty_items: function() {
|
|
|
|
this.remove_item = [];
|
|
|
|
|
|
|
|
this.frm.doc.items.forEach(d => {
|
|
|
|
if (d.qty == 0) {
|
|
|
|
this.remove_item.push(d.idx);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if(this.remove_item) {
|
|
|
|
this.remove_zero_qty_items_from_cart();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
item_validate: function () {
|
|
|
|
if (this.frm.doc.items.length == 0) {
|
2016-04-09 09:01:09 +00:00
|
|
|
frappe.throw(__("Select items to save the invoice"))
|
|
|
|
}
|
|
|
|
},
|
2016-12-27 06:44:26 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
validate_mode_of_payments: function () {
|
|
|
|
if (this.frm.doc.payments.length === 0) {
|
2016-06-27 11:21:44 +00:00
|
|
|
frappe.throw(__("Payment Mode is not configured. Please check, whether account has been set on Mode of Payments or on POS Profile."))
|
|
|
|
}
|
|
|
|
},
|
2016-12-27 06:44:26 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
validate_serial_no: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-05-30 07:24:42 +00:00
|
|
|
var item_code = ''
|
|
|
|
var serial_no = '';
|
|
|
|
for (var key in this.item_serial_no) {
|
2016-04-09 09:01:09 +00:00
|
|
|
item_code = key;
|
2016-07-15 21:32:20 +00:00
|
|
|
serial_no = me.item_serial_no[key][0];
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (this.items[0].has_serial_no && serial_no == "") {
|
2016-12-21 11:53:01 +00:00
|
|
|
this.refresh();
|
|
|
|
frappe.throw(__(repl("Error: Serial no is mandatory for item %(item)s", {
|
|
|
|
'item': this.items[0].item_code
|
|
|
|
})))
|
|
|
|
}
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (item_code && serial_no) {
|
|
|
|
$.each(this.frm.doc.items, function (index, data) {
|
|
|
|
if (data.item_code == item_code) {
|
|
|
|
if (in_list(data.serial_no.split('\n'), serial_no)) {
|
2016-04-09 09:01:09 +00:00
|
|
|
frappe.throw(__(repl("Serial no %(serial_no)s is already taken", {
|
|
|
|
'serial_no': serial_no
|
|
|
|
})))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2016-07-15 21:32:20 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
validate_serial_no_qty: function (args, item_code, field, value) {
|
2016-08-17 10:50:13 +00:00
|
|
|
var me = this;
|
|
|
|
if (args.item_code == item_code && args.serial_no
|
|
|
|
&& field == 'qty' && cint(value) != value) {
|
|
|
|
args.qty = 0.0;
|
|
|
|
this.refresh();
|
|
|
|
frappe.throw(__("Serial no item cannot be a fraction"))
|
|
|
|
}
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (args.item_code == item_code && args.serial_no && args.serial_no.split('\n').length != cint(value)) {
|
2016-08-17 10:50:13 +00:00
|
|
|
args.qty = 0.0;
|
|
|
|
args.serial_no = ''
|
|
|
|
this.refresh();
|
2016-12-21 11:53:01 +00:00
|
|
|
frappe.throw(__(repl("Total nos of serial no is not equal to quantity for item %(item)s.", {
|
|
|
|
'item': item_code
|
|
|
|
})))
|
2016-08-17 10:50:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
mandatory_batch_no: function () {
|
2016-07-15 21:32:20 +00:00
|
|
|
var me = this;
|
2017-02-01 12:37:22 +00:00
|
|
|
if (this.items[0].has_batch_no && !this.item_batch_no[this.items[0].item_code]) {
|
2017-05-30 07:24:42 +00:00
|
|
|
frappe.prompt([{
|
|
|
|
'fieldname': 'batch',
|
|
|
|
'fieldtype': 'Select',
|
|
|
|
'label': __('Batch No'),
|
|
|
|
'reqd': 1,
|
|
|
|
'options': this.batch_no_data[this.items[0].item_code]
|
|
|
|
}],
|
|
|
|
function(values){
|
|
|
|
me.item_batch_no[me.items[0].item_code] = values.batch;
|
2019-07-03 05:04:31 +00:00
|
|
|
const item = me.frm.doc.items.find(
|
|
|
|
({ item_code }) => item_code === me.items[0].item_code
|
|
|
|
);
|
|
|
|
if (item) {
|
|
|
|
item.batch_no = values.batch;
|
|
|
|
}
|
2017-05-30 07:24:42 +00:00
|
|
|
},
|
|
|
|
__('Select Batch No'))
|
|
|
|
}
|
2016-04-09 09:01:09 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
apply_pricing_rule: function () {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-02-01 12:37:22 +00:00
|
|
|
$.each(this.frm.doc["items"], function (n, item) {
|
2017-05-30 07:24:42 +00:00
|
|
|
var pricing_rule = me.get_pricing_rule(item)
|
2016-04-09 09:01:09 +00:00
|
|
|
me.validate_pricing_rule(pricing_rule)
|
2017-02-01 12:37:22 +00:00
|
|
|
if (pricing_rule.length) {
|
|
|
|
item.pricing_rule = pricing_rule[0].name;
|
2016-04-09 09:01:09 +00:00
|
|
|
item.margin_type = pricing_rule[0].margin_type;
|
|
|
|
item.price_list_rate = pricing_rule[0].price || item.price_list_rate;
|
|
|
|
item.margin_rate_or_amount = pricing_rule[0].margin_rate_or_amount;
|
|
|
|
item.discount_percentage = pricing_rule[0].discount_percentage || 0.0;
|
2017-02-28 11:21:17 +00:00
|
|
|
me.apply_pricing_rule_on_item(item)
|
|
|
|
} else if (item.pricing_rule) {
|
|
|
|
item.price_list_rate = me.price_list_data[item.item_code]
|
2016-11-07 09:59:17 +00:00
|
|
|
item.margin_rate_or_amount = 0.0;
|
|
|
|
item.discount_percentage = 0.0;
|
2017-02-01 12:37:22 +00:00
|
|
|
item.pricing_rule = null;
|
2017-02-28 11:21:17 +00:00
|
|
|
me.apply_pricing_rule_on_item(item)
|
|
|
|
}
|
2017-05-19 10:32:30 +00:00
|
|
|
|
2017-02-28 11:21:17 +00:00
|
|
|
if(item.discount_percentage > 0) {
|
|
|
|
me.apply_pricing_rule_on_item(item)
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
get_pricing_rule: function (item) {
|
2016-04-09 09:01:09 +00:00
|
|
|
var me = this;
|
2017-02-01 12:37:22 +00:00
|
|
|
return $.grep(this.pricing_rules, function (data) {
|
|
|
|
if (item.qty >= data.min_qty && (item.qty <= (data.max_qty ? data.max_qty : item.qty))) {
|
2017-04-17 08:06:08 +00:00
|
|
|
if (me.validate_item_condition(data, item)) {
|
2017-02-01 12:37:22 +00:00
|
|
|
if (in_list(['Customer', 'Customer Group', 'Territory', 'Campaign'], data.applicable_for)) {
|
2016-08-05 10:11:36 +00:00
|
|
|
return me.validate_condition(data)
|
2017-02-01 12:37:22 +00:00
|
|
|
} else {
|
2016-08-05 10:11:36 +00:00
|
|
|
return true
|
|
|
|
}
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2017-04-17 08:06:08 +00:00
|
|
|
validate_item_condition: function (data, item) {
|
|
|
|
var apply_on = frappe.model.scrub(data.apply_on);
|
|
|
|
|
|
|
|
return (data.apply_on == 'Item Group')
|
|
|
|
? this.validate_item_group(data.item_group, item.item_group) : (data[apply_on] == item[apply_on]);
|
|
|
|
},
|
|
|
|
|
|
|
|
validate_item_group: function (pr_item_group, cart_item_group) {
|
|
|
|
//pr_item_group = pricing rule's item group
|
|
|
|
//cart_item_group = cart item's item group
|
|
|
|
//this.item_groups has information about item group's lft and rgt
|
|
|
|
//for example: {'Foods': [12, 19]}
|
|
|
|
|
|
|
|
pr_item_group = this.item_groups[pr_item_group]
|
|
|
|
cart_item_group = this.item_groups[cart_item_group]
|
|
|
|
|
|
|
|
return (cart_item_group[0] >= pr_item_group[0] &&
|
|
|
|
cart_item_group[1] <= pr_item_group[1])
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
validate_condition: function (data) {
|
2016-04-09 09:01:09 +00:00
|
|
|
//This method check condition based on applicable for
|
2017-05-30 07:24:42 +00:00
|
|
|
var condition = this.get_mapper_for_pricing_rule(data)[data.applicable_for]
|
2017-02-01 12:37:22 +00:00
|
|
|
if (in_list(condition[1], condition[0])) {
|
2016-04-09 09:01:09 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
get_mapper_for_pricing_rule: function (data) {
|
2016-04-09 09:01:09 +00:00
|
|
|
return {
|
2016-07-08 09:47:04 +00:00
|
|
|
'Customer': [data.customer, [this.frm.doc.customer]],
|
|
|
|
'Customer Group': [data.customer_group, [this.frm.doc.customer_group, 'All Customer Groups']],
|
|
|
|
'Territory': [data.territory, [this.frm.doc.territory, 'All Territories']],
|
2016-08-05 10:11:36 +00:00
|
|
|
'Campaign': [data.campaign, [this.frm.doc.campaign]],
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
validate_pricing_rule: function (pricing_rule) {
|
2016-04-09 09:01:09 +00:00
|
|
|
//This method validate duplicate pricing rule
|
|
|
|
var pricing_rule_name = '';
|
|
|
|
var priority = 0;
|
|
|
|
var pricing_rule_list = [];
|
|
|
|
var priority_list = []
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (pricing_rule.length > 1) {
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
$.each(pricing_rule, function (index, data) {
|
2016-05-20 07:24:44 +00:00
|
|
|
pricing_rule_name += data.name + ','
|
2016-04-09 09:01:09 +00:00
|
|
|
priority_list.push(data.priority)
|
2017-02-01 12:37:22 +00:00
|
|
|
if (priority <= data.priority) {
|
2016-04-09 09:01:09 +00:00
|
|
|
priority = data.priority
|
|
|
|
pricing_rule_list.push(data)
|
|
|
|
}
|
|
|
|
})
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-05-30 07:24:42 +00:00
|
|
|
var count = 0
|
2017-02-01 12:37:22 +00:00
|
|
|
$.each(priority_list, function (index, value) {
|
|
|
|
if (value == priority) {
|
2016-04-09 09:01:09 +00:00
|
|
|
count++
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
if (priority == 0 || count > 1) {
|
2016-04-09 09:01:09 +00:00
|
|
|
frappe.throw(__(repl("Multiple Price Rules exists with same criteria, please resolve conflict by assigning priority. Price Rules: %(pricing_rule)s", {
|
|
|
|
'pricing_rule': pricing_rule_name
|
|
|
|
})))
|
|
|
|
}
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2016-04-09 09:01:09 +00:00
|
|
|
return pricing_rule_list
|
|
|
|
}
|
|
|
|
},
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
validate_warehouse: function () {
|
|
|
|
if (this.items[0].is_stock_item && !this.items[0].default_warehouse && !this.pos_profile_data['warehouse']) {
|
2016-10-24 09:55:33 +00:00
|
|
|
frappe.throw(__("Default warehouse is required for selected item"))
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
2016-11-20 18:11:13 +00:00
|
|
|
},
|
|
|
|
|
2017-02-01 12:37:22 +00:00
|
|
|
get_actual_qty: function (item) {
|
2016-11-20 18:11:13 +00:00
|
|
|
this.actual_qty = 0.0;
|
2016-11-27 06:34:12 +00:00
|
|
|
|
2016-11-20 18:11:13 +00:00
|
|
|
var warehouse = this.pos_profile_data['warehouse'] || item.default_warehouse;
|
2017-02-01 12:37:22 +00:00
|
|
|
if (warehouse && this.bin_data[item.item_code]) {
|
2016-11-20 18:11:13 +00:00
|
|
|
this.actual_qty = this.bin_data[item.item_code][warehouse] || 0;
|
2016-11-27 06:34:12 +00:00
|
|
|
this.actual_qty_dict[item.item_code] = this.actual_qty
|
2016-11-20 18:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.actual_qty
|
2017-03-07 08:31:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
update_customer_in_localstorage: function() {
|
|
|
|
var me = this;
|
|
|
|
try {
|
|
|
|
localStorage.setItem('customer_details', JSON.stringify(this.customer_details));
|
|
|
|
} catch (e) {
|
|
|
|
frappe.throw(__("LocalStorage is full , did not save"))
|
|
|
|
}
|
2016-04-09 09:01:09 +00:00
|
|
|
}
|
2018-02-07 20:02:48 +00:00
|
|
|
})
|