|
|
|
|
@@ -1,3 +1,4 @@
|
|
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
|
erpnext.PointOfSale.Payment = class {
|
|
|
|
|
constructor({ events, wrapper }) {
|
|
|
|
|
this.wrapper = wrapper;
|
|
|
|
|
@@ -31,7 +32,7 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
</div>
|
|
|
|
|
<div class="submit-order-btn">Complete Order</div>
|
|
|
|
|
</section>`
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
this.$component = this.wrapper.find('.payment-container');
|
|
|
|
|
this.$payment_modes = this.$component.find('.payment-modes');
|
|
|
|
|
this.$totals_section = this.$component.find('.totals-section');
|
|
|
|
|
@@ -54,8 +55,10 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
`<div class="invoice_detail_field ${df.fieldname}-field" data-fieldname="${df.fieldname}"></div>`
|
|
|
|
|
);
|
|
|
|
|
let df_events = {
|
|
|
|
|
onchange: function() { frm.set_value(this.df.fieldname, this.value); }
|
|
|
|
|
onchange: function() {
|
|
|
|
|
frm.set_value(this.df.fieldname, this.value);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
if (df.fieldtype == "Button") {
|
|
|
|
|
df_events = {
|
|
|
|
|
click: function() {
|
|
|
|
|
@@ -63,7 +66,7 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
frm.script_manager.trigger(df.fieldname, frm.doc.doctype, frm.doc.docname);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this[`${df.fieldname}_field`] = frappe.ui.form.make_control({
|
|
|
|
|
@@ -75,7 +78,7 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
render_input: true,
|
|
|
|
|
});
|
|
|
|
|
this[`${df.fieldname}_field`].set_value(frm.doc[df.fieldname]);
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -95,13 +98,12 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
[ 7, 8, 9 ],
|
|
|
|
|
[ '.', 0, 'Delete' ]
|
|
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.numpad_value = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
on_numpad_clicked($btn) {
|
|
|
|
|
const me = this;
|
|
|
|
|
const button_value = $btn.attr('data-button-value');
|
|
|
|
|
|
|
|
|
|
highlight_numpad_btn($btn);
|
|
|
|
|
@@ -158,7 +160,7 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
!current_value && doc.grand_total > doc.paid_amount && me.selected_mode ?
|
|
|
|
|
me.selected_mode.set_value(doc.grand_total - doc.paid_amount) : '';
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
frappe.realtime.on("process_phone_payment", function(data) {
|
|
|
|
|
frappe.dom.unfreeze();
|
|
|
|
|
@@ -168,7 +170,7 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
|
|
|
|
|
if (data["ResultCode"] == 0) {
|
|
|
|
|
title = __("Payment Received");
|
|
|
|
|
$('.btn.btn-xs.btn-default[data-fieldname=request_for_payment]').html(`Payment Received`)
|
|
|
|
|
$('.btn.btn-xs.btn-default[data-fieldname=request_for_payment]').html(`Payment Received`);
|
|
|
|
|
me.events.submit_invoice();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -178,10 +180,10 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.$payment_modes.on('click', '.shortcut', function(e) {
|
|
|
|
|
this.$payment_modes.on('click', '.shortcut', () => {
|
|
|
|
|
const value = $(this).attr('data-value');
|
|
|
|
|
me.selected_mode.set_value(value);
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.$component.on('click', '.submit-order-btn', () => {
|
|
|
|
|
const doc = this.events.get_frm().doc;
|
|
|
|
|
@@ -189,14 +191,14 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
const items = doc.items;
|
|
|
|
|
|
|
|
|
|
if (paid_amount == 0 || !items.length) {
|
|
|
|
|
const message = items.length ? __("You cannot submit the order without payment.") : __("You cannot submit empty order.")
|
|
|
|
|
const message = items.length ? __("You cannot submit the order without payment.") : __("You cannot submit empty order.");
|
|
|
|
|
frappe.show_alert({ message, indicator: "orange" });
|
|
|
|
|
frappe.utils.play_sound("error");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.events.submit_invoice();
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
frappe.ui.form.on('POS Invoice', 'paid_amount', (frm) => {
|
|
|
|
|
this.update_totals_section(frm.doc);
|
|
|
|
|
@@ -205,7 +207,7 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
const is_cash_shortcuts_invisible = !this.$payment_modes.find('.cash-shortcuts').is(':visible');
|
|
|
|
|
this.attach_cash_shortcuts(frm.doc);
|
|
|
|
|
!is_cash_shortcuts_invisible && this.$payment_modes.find('.cash-shortcuts').css('display', 'grid');
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
frappe.ui.form.on('POS Invoice', 'loyalty_amount', (frm) => {
|
|
|
|
|
const formatted_currency = format_currency(frm.doc.loyalty_amount, frm.doc.currency);
|
|
|
|
|
@@ -258,14 +260,8 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggle_numpad(show) {
|
|
|
|
|
// if (show) {
|
|
|
|
|
// this.$numpad.css('display', 'flex');
|
|
|
|
|
// this.$totals_section.addClass('w-60 justify-center').removeClass('justify-end w-full');
|
|
|
|
|
// } else {
|
|
|
|
|
// this.$numpad.css('display', 'none');
|
|
|
|
|
// this.$totals_section.removeClass('w-60 justify-center').addClass('justify-end w-full');
|
|
|
|
|
// }
|
|
|
|
|
toggle_numpad() {
|
|
|
|
|
// pass
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render_payment_section() {
|
|
|
|
|
@@ -309,8 +305,7 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
const payments = doc.payments;
|
|
|
|
|
const currency = doc.currency;
|
|
|
|
|
|
|
|
|
|
this.$payment_modes.html(
|
|
|
|
|
`${
|
|
|
|
|
this.$payment_modes.html(`${
|
|
|
|
|
payments.map((p, i) => {
|
|
|
|
|
const mode = p.mode_of_payment.replace(/ +/g, "_").toLowerCase();
|
|
|
|
|
const payment_type = p.type;
|
|
|
|
|
@@ -325,10 +320,9 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
<div class="${mode} mode-of-payment-control"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>`
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}).join('')
|
|
|
|
|
}`
|
|
|
|
|
)
|
|
|
|
|
}`);
|
|
|
|
|
|
|
|
|
|
payments.forEach(p => {
|
|
|
|
|
const mode = p.mode_of_payment.replace(/ +/g, "_").toLowerCase();
|
|
|
|
|
@@ -359,7 +353,7 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
this.$payment_modes.find(`.${mode}.mode-of-payment-control`).parent().click();
|
|
|
|
|
}, 500);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.render_loyalty_points_payment_mode();
|
|
|
|
|
|
|
|
|
|
@@ -377,11 +371,11 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
`<div class="cash-shortcuts">
|
|
|
|
|
${
|
|
|
|
|
shortcuts.map(s => {
|
|
|
|
|
return `<div class="shortcut" data-value="${s}">${format_currency(s, currency, 0)}</div>`
|
|
|
|
|
return `<div class="shortcut" data-value="${s}">${format_currency(s, currency, 0)}</div>`;
|
|
|
|
|
}).join('')
|
|
|
|
|
}
|
|
|
|
|
</div>`
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_cash_shortcuts(grand_total) {
|
|
|
|
|
@@ -393,7 +387,7 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
const get_nearest = (amount, x) => {
|
|
|
|
|
let nearest_x = Math.ceil((amount / x)) * x;
|
|
|
|
|
return nearest_x === amount ? nearest_x + x : nearest_x;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return steps.reduce((finalArr, x) => {
|
|
|
|
|
let nearest_x = get_nearest(grand_total, x);
|
|
|
|
|
@@ -416,7 +410,7 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
description = __("You don't have enough points to redeem.");
|
|
|
|
|
read_only = true;
|
|
|
|
|
} else {
|
|
|
|
|
max_redeemable_amount = flt(flt(loyalty_points) * flt(conversion_factor), precision("loyalty_amount", doc))
|
|
|
|
|
max_redeemable_amount = flt(flt(loyalty_points) * flt(conversion_factor), precision("loyalty_amount", doc));
|
|
|
|
|
description = __("You can redeem upto {0}.", [format_currency(max_redeemable_amount)]);
|
|
|
|
|
read_only = false;
|
|
|
|
|
}
|
|
|
|
|
@@ -432,7 +426,7 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
<div class="loyalty-amount mode-of-payment-control"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>`
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
this['loyalty-amount_control'] = frappe.ui.form.make_control({
|
|
|
|
|
df: {
|
|
|
|
|
@@ -474,7 +468,7 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
`<div class="w-full pr-2">
|
|
|
|
|
<div class="add-mode-of-payment w-half text-grey mb-4 no-select pointer">+ Add Payment Method</div>
|
|
|
|
|
</div>`
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update_totals_section(doc) {
|
|
|
|
|
@@ -482,7 +476,7 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
const paid_amount = doc.paid_amount;
|
|
|
|
|
const remaining = doc.grand_total - doc.paid_amount;
|
|
|
|
|
const change = doc.change_amount || remaining <= 0 ? -1 * remaining : undefined;
|
|
|
|
|
const currency = doc.currency
|
|
|
|
|
const currency = doc.currency;
|
|
|
|
|
const label = change ? __('Change') : __('To Be Paid');
|
|
|
|
|
|
|
|
|
|
this.$totals.html(
|
|
|
|
|
@@ -500,10 +494,10 @@ erpnext.PointOfSale.Payment = class {
|
|
|
|
|
<div class="total-label">${label}</div>
|
|
|
|
|
<div class="value">${format_currency(change || remaining, currency)}</div>
|
|
|
|
|
</div>`
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggle_component(show) {
|
|
|
|
|
show ? this.$component.css('display', 'flex') : this.$component.css('display', 'none');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|