mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-20 03:47:11 +00:00
[Enhancement] POS
This commit is contained in:
158
erpnext/public/js/controllers/payments.js
Normal file
158
erpnext/public/js/controllers/payments.js
Normal file
@@ -0,0 +1,158 @@
|
||||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
erpnext.payments = erpnext.stock.StockController.extend({
|
||||
make_payment: function() {
|
||||
var me = this;
|
||||
|
||||
this.dialog = new frappe.ui.Dialog({
|
||||
title: 'Payment'
|
||||
});
|
||||
|
||||
this.dialog.show();
|
||||
this.$body = this.dialog.body;
|
||||
this.dialog.$wrapper.find('.modal-dialog').css("width", "750px");
|
||||
this.set_payment_primary_action();
|
||||
this.make_keyboard();
|
||||
},
|
||||
|
||||
set_payment_primary_action: function(){
|
||||
var me = this;
|
||||
|
||||
this.dialog.set_primary_action(__("Submit"), function() {
|
||||
frappe.confirm(__("Do you really want to submit the invoice?"), function () {
|
||||
me.write_off_amount();
|
||||
me.dialog.hide();
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
make_keyboard: function(){
|
||||
var me = this;
|
||||
$(this.$body).empty();
|
||||
$(this.$body).html(frappe.render_template('pos_payment', this.frm.doc))
|
||||
this.show_payment_details();
|
||||
this.bind_keyboard_event()
|
||||
},
|
||||
|
||||
pay_amount: function(){
|
||||
var me = this;
|
||||
this.make_multimode_payment();
|
||||
this.calculate_outstanding_amount()
|
||||
this.show_payment_details();
|
||||
},
|
||||
|
||||
make_multimode_payment: function(){
|
||||
var me = this;
|
||||
|
||||
if(this.frm.doc.change_amount > 0){
|
||||
me.payment_val = me.doc.outstanding_amount
|
||||
}
|
||||
|
||||
this.payments = frappe.model.add_child(this.frm.doc, 'Multi Mode Payment', "payments");
|
||||
this.payments.mode_of_payment = this.dialog.fields_dict.mode_of_payment.get_value();
|
||||
this.payments.amount = flt(this.payment_val);
|
||||
},
|
||||
|
||||
show_payment_details: function(){
|
||||
var me = this;
|
||||
multimode_payments = $(this.$body).find('.multimode-payments').empty();
|
||||
if(this.frm.doc.payments.length){
|
||||
$.each(this.frm.doc.payments, function(index, data){
|
||||
$(frappe.render_template('payment_details', {
|
||||
mode_of_payment: data.mode_of_payment,
|
||||
amount: data.amount,
|
||||
idx: data.idx,
|
||||
currency: me.frm.doc.currency,
|
||||
type: data.type
|
||||
})).appendTo(multimode_payments)
|
||||
})
|
||||
}else{
|
||||
$("<p>No payment mode selected in pos profile</p>").appendTo(multimode_payments)
|
||||
}
|
||||
},
|
||||
|
||||
bind_keyboard_event: function(){
|
||||
var me = this;
|
||||
this.payment_val = '';
|
||||
this.bind_payment_mode_keys_event();
|
||||
this.bind_keyboard_keys_event();
|
||||
},
|
||||
|
||||
bind_payment_mode_keys_event: function(){
|
||||
var me = this;
|
||||
$(this.$body).find('.pos-payment-row').click(function(){
|
||||
me.idx = $(this).attr("idx");
|
||||
me.selected_mode = $(me.$body).find(repl("input[idx='%(idx)s']",{'idx': me.idx}));
|
||||
me.highlight_selected_row()
|
||||
me.payment_val = 0.0
|
||||
if(me.frm.doc.outstanding_amount > 0 && flt(me.selected_mode.val()) == 0.0){
|
||||
//When user first time click on row
|
||||
me.payment_val = flt(me.frm.doc.outstanding_amount)
|
||||
me.selected_mode.val(format_number(me.payment_val, 2));
|
||||
me.update_paid_amount()
|
||||
me.bind_amount_change_event();
|
||||
}else if(flt(me.selected_mode.val()) > 0){
|
||||
//If user click on existing row which has value
|
||||
me.payment_val = flt(me.selected_mode.val());
|
||||
}
|
||||
me.selected_mode.select()
|
||||
})
|
||||
},
|
||||
|
||||
highlight_selected_row: function(){
|
||||
var me = this;
|
||||
selected_row = $(this.$body).find(repl(".pos-payment-row[idx='%(idx)s']",{'idx': this.idx}));
|
||||
$(this.$body).find('.pos-payment-row').removeClass('selected-payment-mode')
|
||||
selected_row.addClass('selected-payment-mode')
|
||||
$(this.$body).find('.amount').attr('disabled', true);
|
||||
this.selected_mode.attr('disabled', false);
|
||||
},
|
||||
|
||||
bind_keyboard_keys_event: function(){
|
||||
var me = this;
|
||||
$(this.$body).find('.pos-keyboard-key').click(function(){
|
||||
me.payment_val += $(this).text();
|
||||
me.selected_mode.val(format_number(me.payment_val, 2))
|
||||
me.idx = me.selected_mode.attr("idx")
|
||||
me.update_paid_amount()
|
||||
})
|
||||
|
||||
$(this.$body).find('.delete-btn').click(function(){
|
||||
me.payment_val = cstr(flt(me.selected_mode.val())).slice(0, -1);
|
||||
me.selected_mode.val(format_number(me.payment_val, 2));
|
||||
me.idx = me.selected_mode.attr("idx")
|
||||
me.update_paid_amount();
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
bind_amount_change_event: function(){
|
||||
var me = this;
|
||||
me.selected_mode.change(function(){
|
||||
me.payment_val = $(this).val() || 0.0;
|
||||
me.selected_mode.val(format_number(me.payment_val, 2))
|
||||
me.idx = me.selected_mode.attr("idx")
|
||||
me.update_paid_amount()
|
||||
})
|
||||
},
|
||||
|
||||
update_paid_amount: function(){
|
||||
var me = this;
|
||||
$.each(this.frm.doc.payments, function(index, data){
|
||||
if(cint(me.idx) == cint(data.idx)){
|
||||
data.amount = flt(me.selected_mode.val(), 2)
|
||||
}
|
||||
})
|
||||
this.calculate_outstanding_amount();
|
||||
this.show_amounts();
|
||||
},
|
||||
|
||||
show_amounts: function(){
|
||||
var me = this;
|
||||
$(this.$body).find('.paid_amount').text(format_currency(this.frm.doc.paid_amount, this.frm.doc.currency));
|
||||
$(this.$body).find('.change_amount').text(format_currency(this.frm.doc.change_amount, this.frm.doc.currency))
|
||||
$(this.$body).find('.outstanding_amount').text(format_currency(this.frm.doc.outstanding_amount, this.frm.doc.currency))
|
||||
this.update_invoice();
|
||||
}
|
||||
})
|
||||
@@ -1,13 +1,30 @@
|
||||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
apply_pricing_rule_on_item: function(item){
|
||||
if(!item.margin_type){
|
||||
item.margin_rate_or_amount = 0.0;
|
||||
}
|
||||
|
||||
if(item.margin_type == "Percentage"){
|
||||
item.total_margin = item.price_list_rate + item.price_list_rate * ( item.margin_rate_or_amount / 100);
|
||||
}else{
|
||||
item.total_margin = item.price_list_rate + item.margin_rate_or_amount;
|
||||
}
|
||||
|
||||
item.rate = flt(item.total_margin , 2);
|
||||
|
||||
if(item.discount_percentage){
|
||||
discount_value = flt(item.total_margin) * flt(item.discount_percentage) / 100;
|
||||
item.rate = flt((item.total_margin) - (discount_value), precision('rate'));
|
||||
}
|
||||
},
|
||||
|
||||
calculate_taxes_and_totals: function(update_paid_amount) {
|
||||
this.discount_amount_applied = false;
|
||||
this._calculate_taxes_and_totals();
|
||||
|
||||
if (frappe.meta.get_docfield(this.frm.doc.doctype, "discount_amount"))
|
||||
this.apply_discount_amount();
|
||||
this.calculate_discount_amount();
|
||||
|
||||
// Advance calculation applicable to Sales /Purchase Invoice
|
||||
if(in_list(["Sales Invoice", "Purchase Invoice"], this.frm.doc.doctype)
|
||||
@@ -24,6 +41,11 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
this.frm.refresh_fields();
|
||||
},
|
||||
|
||||
calculate_discount_amount: function(){
|
||||
if (frappe.meta.get_docfield(this.frm.doc.doctype, "discount_amount"))
|
||||
this.apply_discount_amount();
|
||||
},
|
||||
|
||||
_calculate_taxes_and_totals: function() {
|
||||
this.validate_conversion_rate();
|
||||
this.calculate_item_values();
|
||||
@@ -98,7 +120,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
|
||||
$.each(tax_fields, function(i, fieldname) { tax[fieldname] = 0.0 });
|
||||
|
||||
if (!this.discount_amount_applied) {
|
||||
if (!this.discount_amount_applied && cur_frm) {
|
||||
cur_frm.cscript.validate_taxes_and_charges(tax.doctype, tax.name);
|
||||
me.validate_inclusive_tax(tax);
|
||||
}
|
||||
@@ -433,13 +455,14 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
apply_discount_amount: function() {
|
||||
var me = this;
|
||||
var distributed_amount = 0.0;
|
||||
this.frm.doc.base_discount_amount = 0.0;
|
||||
|
||||
if (this.frm.doc.discount_amount) {
|
||||
if(!this.frm.doc.apply_discount_on)
|
||||
frappe.throw(__("Please select Apply Discount On"));
|
||||
|
||||
this.frm.set_value("base_discount_amount",
|
||||
flt(this.frm.doc.discount_amount * this.frm.doc.conversion_rate, precision("base_discount_amount")))
|
||||
|
||||
this.frm.doc.base_discount_amount = flt(this.frm.doc.discount_amount * this.frm.doc.conversion_rate,
|
||||
precision("base_discount_amount"));
|
||||
|
||||
var total_for_discount_amount = this.get_total_for_discount_amount();
|
||||
// calculate item amount after Discount Amount
|
||||
@@ -455,8 +478,6 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
this.discount_amount_applied = true;
|
||||
this._calculate_taxes_and_totals();
|
||||
}
|
||||
} else {
|
||||
this.frm.set_value("base_discount_amount", 0);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -524,18 +545,59 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
||||
this.frm.doc.paid_amount = 0
|
||||
}
|
||||
this.set_in_company_currency(this.frm.doc, ["paid_amount"]);
|
||||
this.frm.refresh_field("paid_amount");
|
||||
this.frm.refresh_field("base_paid_amount");
|
||||
|
||||
if(this.frm.refresh_field){
|
||||
this.frm.refresh_field("paid_amount");
|
||||
this.frm.refresh_field("base_paid_amount");
|
||||
}
|
||||
|
||||
if(this.frm.doc.doctype == "Sales Invoice"){
|
||||
this.calculate_paid_amount()
|
||||
}
|
||||
|
||||
var outstanding_amount = 0.0
|
||||
|
||||
var paid_amount = (this.frm.doc.party_account_currency == this.frm.doc.currency) ?
|
||||
this.frm.doc.paid_amount : this.frm.doc.base_paid_amount;
|
||||
|
||||
var outstanding_amount = flt(total_amount_to_pay - flt(paid_amount),
|
||||
precision("outstanding_amount"));
|
||||
if (total_amount_to_pay > paid_amount){
|
||||
outstanding_amount = flt(total_amount_to_pay - flt(paid_amount),
|
||||
precision("outstanding_amount"));
|
||||
}
|
||||
|
||||
} else if(this.frm.doc.doctype == "Purchase Invoice") {
|
||||
var outstanding_amount = flt(total_amount_to_pay, precision("outstanding_amount"));
|
||||
}
|
||||
this.frm.set_value("outstanding_amount", outstanding_amount);
|
||||
}
|
||||
|
||||
this.frm.doc.outstanding_amount = outstanding_amount;
|
||||
this.calculate_change_amount()
|
||||
},
|
||||
|
||||
calculate_paid_amount: function(){
|
||||
var me = this;
|
||||
var paid_amount = base_paid_amount = 0.0;
|
||||
$.each(this.frm.doc['payments'] || [], function(index, data){
|
||||
if(data.amount > 0){
|
||||
data.base_amount = flt(data.amount * me.frm.doc.conversion_rate);
|
||||
paid_amount += data.amount;
|
||||
base_paid_amount += data.base_amount;
|
||||
}
|
||||
})
|
||||
|
||||
this.frm.doc.paid_amount = flt(paid_amount, precision("paid_amount"));
|
||||
this.frm.doc.base_paid_amount = flt(base_paid_amount, precision("base_paid_amount"));
|
||||
},
|
||||
|
||||
calculate_change_amount: function(){
|
||||
var change_amount = 0.0;
|
||||
if(this.frm.doc.paid_amount > this.frm.doc.grand_total){
|
||||
change_amount = flt(this.frm.doc.paid_amount - this.frm.doc.grand_total,
|
||||
precision("change_amount"))
|
||||
}
|
||||
|
||||
this.frm.doc.change_amount = flt(change_amount,
|
||||
precision("change_amount"))
|
||||
this.frm.doc.base_change_amount = flt(change_amount * this.frm.doc.conversion_rate,
|
||||
precision("base_change_amount"))
|
||||
},
|
||||
})
|
||||
|
||||
@@ -165,7 +165,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
erpnext.hide_company();
|
||||
this.show_item_wise_taxes();
|
||||
this.set_dynamic_labels();
|
||||
erpnext.pos.make_pos_btn(this.frm);
|
||||
// erpnext.pos.make_pos_btn(this.frm);
|
||||
this.setup_sms();
|
||||
this.make_show_payments_btn();
|
||||
},
|
||||
@@ -550,7 +550,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
setup_field_label_map(["base_total", "base_net_total", "base_total_taxes_and_charges",
|
||||
"base_discount_amount", "base_grand_total", "base_rounded_total", "base_in_words",
|
||||
"base_taxes_and_charges_added", "base_taxes_and_charges_deducted", "total_amount_to_pay",
|
||||
"base_paid_amount", "base_write_off_amount"
|
||||
"base_paid_amount", "base_write_off_amount", "base_change_amount"
|
||||
], company_currency);
|
||||
|
||||
setup_field_label_map(["total", "net_total", "total_taxes_and_charges", "discount_amount",
|
||||
|
||||
Reference in New Issue
Block a user