new form improvements

This commit is contained in:
Faris Ansari 2017-08-24 17:09:34 +05:30
parent e5f6b4d640
commit 5d9196960e

View File

@ -93,20 +93,22 @@ class PointOfSale {
}); });
} }
disable_text_box_and_button() { toggle_editing(flag) {
let disabled = this.frm.doc.docstatus == 1 ? true: false; let disabled;
let pointer_events = this.frm.doc.docstatus == 1 ? "none":"inherit"; if (flag !== undefined) {
disabled = !flag;
} else {
disabled = this.frm.doc.docstatus == 1 ? true: false;
}
const pointer_events = disabled ? 'none' : 'inherit';
$(this.wrapper).find('input, button', 'select').prop("disabled", disabled); this.wrapper.find('input, button, select').prop("disabled", disabled);
$(this.wrapper).find(".number-pad-container").toggleClass("hide", disabled); this.wrapper.find('.number-pad-container').toggleClass("hide", disabled);
$(this.wrapper).find('.cart-container').css('pointer-events', pointer_events); this.wrapper.find('.cart-container').css('pointer-events', pointer_events);
$(this.wrapper).find('.item-container').css('pointer-events', pointer_events); this.wrapper.find('.item-container').css('pointer-events', pointer_events);
this.page.clear_actions(); this.page.clear_actions();
if(this.frm.doc.docstatus === 1) {
this.set_primary_action()
}
} }
make_items() { make_items() {
@ -193,38 +195,27 @@ class PointOfSale {
} }
submit_sales_invoice() { submit_sales_invoice() {
var me = this;
this.frm.savesubmit(); frappe.confirm(__("Permanently Submit {0}?", [this.frm.doc.name]), () => {
// frappe.confirm(__("Permanently Submit {0}?", [this.frm.doc.name]), function() { frappe.call({
// return frappe.call({ method: 'erpnext.selling.page.point_of_sale.point_of_sale.submit_invoice',
// method: 'erpnext.selling.page.point_of_sale.point_of_sale.submit_invoice', freeze: true,
// freeze: true, args: {
// args: { doc: this.frm.doc
// doc: me.frm.doc }
// } }).then(r => {
// }).then(r => { if(r.message) {
// if(r.message) { this.frm.doc = r.message;
// me.frm.doc = r.message; frappe.show_alert({
// me.frm.meta.default_print_format = 'POS Invoice'; indicator: 'green',
// frappe.show_alert({ message: __(`Sales invoice ${r.message.name} created succesfully`)
// indicator: 'green', });
// message: __(`Sales invoice ${r.message.name} created succesfully`)
// }); this.toggle_editing();
// this.set_form_action();
// me.frm.msgbox = frappe.msgprint( }
// `<a class="btn btn-primary" onclick="cur_frm.print_preview.printit(true)" style="margin-right: 5px;"> });
// ${__('Print')}</a> });
// <a class="btn btn-default new_doc">
// ${__('New')}</a>`
// );
// $(me.frm.msgbox.wrapper).find('.new_doc').click(function() {
// me.frm.msgbox.hide()
// me.make_new_invoice()
// })
// me.disable_text_box_and_button();
// }
// });
// })
} }
bind_events() { bind_events() {
@ -246,27 +237,42 @@ class PointOfSale {
return frappe.run_serially([ return frappe.run_serially([
() => this.make_sales_invoice_frm(), () => this.make_sales_invoice_frm(),
() => { () => {
this.make_cart(); if (this.cart) {
this.disable_text_box_and_button(); this.cart.frm = this.frm;
this.cart.reset();
} else {
this.make_cart();
}
this.toggle_editing(true);
} }
]); ]);
} }
make_sales_invoice_frm() { make_sales_invoice_frm() {
this.dt = 'Sales Invoice'; const doctype = 'Sales Invoice';
return new Promise(resolve => { return new Promise(resolve => {
frappe.model.with_doctype(this.dt, () => { if (this.frm) {
const page = $('<div>'); this.frm = get_frm(this.frm);
const frm = new _f.Frm(this.dt, page, false);
const name = frappe.model.make_new_doc_and_get_name(this.dt, true);
frm.refresh(name);
frm.doc.items = [];
this.doc = frm.doc;
this.frm = frm;
this.frm.set_value('is_pos', 1);
resolve(); resolve();
}); } else {
frappe.model.with_doctype(doctype, () => {
this.frm = get_frm();
resolve();
});
}
}); });
function get_frm(_frm) {
const page = $('<div>');
const frm = _frm || new _f.Frm(doctype, page, false);
const name = frappe.model.make_new_doc_and_get_name(doctype, true);
frm.refresh(name);
frm.doc.items = [];
frm.set_value('is_pos', 1);
frm.meta.default_print_format = 'POS Invoice';
return frm;
}
} }
prepare_menu() { prepare_menu() {
@ -291,15 +297,16 @@ class PointOfSale {
}); });
} }
set_primary_action() { set_form_action() {
var me = this; if(this.frm.doc.docstatus !== 1) return;
this.page.set_secondary_action(__("Print"), function () {
me.frm.print_preview.printit(true)
})
this.page.set_primary_action(__("New"), function () { this.page.set_secondary_action(__("Print"), () => {
me.make_new_invoice() this.frm.print_preview.printit(true);
}) });
this.page.set_primary_action(__("New"), () => {
this.make_new_invoice();
});
} }
show_taxes_and_totals() { show_taxes_and_totals() {
@ -307,21 +314,18 @@ class PointOfSale {
let currency = this.frm.doc.currency; let currency = this.frm.doc.currency;
const taxes_wrapper = $(this.wrapper).find('.taxes'); const taxes_wrapper = $(this.wrapper).find('.taxes');
this.frm.refresh_field('taxes') this.frm.refresh_field('taxes');
$(this.wrapper).find('.net_total').html(format_currency(this.frm.doc.net_total, this.currency)) $(this.wrapper).find('.net-total').html(format_currency(this.frm.doc.net_total, this.currency))
console.log(this.frm.doc.taxes[0].tax_amount)
$.each(this.frm.doc.taxes, function(index, data) { $.each(this.frm.doc.taxes, function(index, data) {
console.log(data.tax_amount)
tax_template += ` tax_template += `
<div class="list-item" style="padding-right: 0;"> <div class="list-item" style="padding-right: 0;">
<div >${data.description}</div> <div >${data.description}</div>
<div class="text-right bold">${fmt_money(data.tax_amount, currency)}</div> <div class="text-right bold">${fmt_money(data.tax_amount, currency)}</div>
</div>` </div>`;
}) });
taxes_wrapper.empty() taxes_wrapper.empty()
console.log(tax_template) taxes_wrapper.html(tax_template);
taxes_wrapper.html(tax_template)
} }
} }
@ -341,7 +345,6 @@ class POSCart {
} }
make_dom() { make_dom() {
$(this.wrapper).find('.pos-cart').empty()
this.wrapper.append(` this.wrapper.append(`
<div class="pos-cart"> <div class="pos-cart">
<div class="customer-field"> <div class="customer-field">
@ -361,14 +364,7 @@ class POSCart {
</div> </div>
</div> </div>
<div class="taxes-and-totals"> <div class="taxes-and-totals">
<div class="list-item"> ${this.get_taxes_and_totals()}
<div class="list-item__content list-item__content--flex-2 text-muted">${__('Net Total')}</div>
<div class="list-item__content net_total">0.00</div>
</div>
<div class="list-item">
<div class="list-item__content list-item__content--flex-2 text-muted">${__('Taxes')}</div>
<div class="list-item__content taxes">0.00</div>
</div>
</div> </div>
</div> </div>
<div class="number-pad-container"> <div class="number-pad-container">
@ -376,6 +372,28 @@ class POSCart {
</div> </div>
`); `);
this.$cart_items = this.wrapper.find('.cart-items'); this.$cart_items = this.wrapper.find('.cart-items');
this.$empty_state = this.wrapper.find('.cart-items .empty-state');
this.$taxes_and_totals = this.wrapper.find('.taxes-and-totals');
}
reset() {
this.$cart_items.find('.list-item').remove();
this.$empty_state.show();
this.$taxes_and_totals.html(this.get_taxes_and_totals());
this.numpad && this.numpad.reset_value();
this.customer_field.set_value("");
}
get_taxes_and_totals() {
return `
<div class="list-item">
<div class="list-item__content list-item__content--flex-2 text-muted">${__('Net Total')}</div>
<div class="list-item__content net-total">0.00</div>
</div>
<div class="list-item">
<div class="list-item__content list-item__content--flex-2 text-muted">${__('Taxes')}</div>
<div class="list-item__content taxes">0.00</div>
</div>`;
} }
make_customer_field() { make_customer_field() {
@ -458,7 +476,7 @@ class POSCart {
} }
add_item(item) { add_item(item) {
this.wrapper.find('.cart-items .empty-state').hide(); this.$empty_state.hide();
if (this.exists(item.item_code)) { if (this.exists(item.item_code)) {
// update quantity // update quantity
@ -575,7 +593,6 @@ class POSCart {
// current item // current item
this.$cart_items.on('click', '.list-item', function() { this.$cart_items.on('click', '.list-item', function() {
console.log('cart item click');
me.set_selected_item($(this)); me.set_selected_item($(this));
}); });
@ -872,7 +889,7 @@ class NumberPad {
me.highlight_button($btn); me.highlight_button($btn);
} }
if (me.reset_btns.includes(btn_value)) { if (me.reset_btns.includes(btn_value)) {
me.value = ''; me.reset_value();
} else { } else {
if (btn_value === me.del_btn) { if (btn_value === me.del_btn) {
me.value = me.value.substr(0, me.value.length - 1); me.value = me.value.substr(0, me.value.length - 1);
@ -884,6 +901,10 @@ class NumberPad {
}); });
} }
reset_value() {
this.value = '';
}
get_value() { get_value() {
return flt(this.value); return flt(this.value);
} }
@ -951,9 +972,9 @@ class Payment {
var me = this; var me = this;
this.dialog.set_primary_action(__("Submit"), function() { this.dialog.set_primary_action(__("Submit"), function() {
me.dialog.hide() me.dialog.hide();
me.events.submit_form() me.events.submit_form();
}) });
} }
get_fields() { get_fields() {