mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 19:29:10 +00:00
Merge branch 'version-13-hotfix' of https://github.com/frappe/erpnext into bootstraped_gst_setup
This commit is contained in:
@@ -156,31 +156,31 @@ cur_frm.cscript.validate_taxes_and_charges = function(cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
var msg = "";
|
||||
|
||||
if(d.account_head && !d.description) {
|
||||
if (d.account_head && !d.description) {
|
||||
// set description from account head
|
||||
d.description = d.account_head.split(' - ').slice(0, -1).join(' - ');
|
||||
}
|
||||
|
||||
if(!d.charge_type && (d.row_id || d.rate || d.tax_amount)) {
|
||||
if (!d.charge_type && (d.row_id || d.rate || d.tax_amount)) {
|
||||
msg = __("Please select Charge Type first");
|
||||
d.row_id = "";
|
||||
d.rate = d.tax_amount = 0.0;
|
||||
} else if((d.charge_type == 'Actual' || d.charge_type == 'On Net Total') && d.row_id) {
|
||||
} else if ((d.charge_type == 'Actual' || d.charge_type == 'On Net Total' || d.charge_type == 'On Paid Amount') && d.row_id) {
|
||||
msg = __("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'");
|
||||
d.row_id = "";
|
||||
} else if((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
|
||||
} else if ((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
|
||||
if (d.idx == 1) {
|
||||
msg = __("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row");
|
||||
d.charge_type = '';
|
||||
} else if (!d.row_id) {
|
||||
msg = __("Please specify a valid Row ID for row {0} in table {1}", [d.idx, __(d.doctype)]);
|
||||
d.row_id = "";
|
||||
} else if(d.row_id && d.row_id >= d.idx) {
|
||||
} else if (d.row_id && d.row_id >= d.idx) {
|
||||
msg = __("Cannot refer row number greater than or equal to current row number for this Charge type");
|
||||
d.row_id = "";
|
||||
}
|
||||
}
|
||||
if(msg) {
|
||||
if (msg) {
|
||||
frappe.validated = false;
|
||||
refresh_field("taxes");
|
||||
frappe.throw(msg);
|
||||
|
||||
@@ -122,9 +122,20 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
this.set_from_product_bundle();
|
||||
}
|
||||
|
||||
this.toggle_subcontracting_fields();
|
||||
this._super();
|
||||
},
|
||||
|
||||
toggle_subcontracting_fields: function() {
|
||||
if (in_list(['Purchase Receipt', 'Purchase Invoice'], this.frm.doc.doctype)) {
|
||||
this.frm.fields_dict.supplied_items.grid.update_docfield_property('consumed_qty',
|
||||
'read_only', this.frm.doc.__onload && this.frm.doc.__onload.backflush_based_on === 'BOM');
|
||||
|
||||
this.frm.set_df_property('supplied_items', 'cannot_add_rows', 1);
|
||||
this.frm.set_df_property('supplied_items', 'cannot_delete_rows', 1);
|
||||
}
|
||||
},
|
||||
|
||||
supplier: function() {
|
||||
var me = this;
|
||||
erpnext.utils.get_party_details(this.frm, null, null, function(){
|
||||
|
||||
@@ -12,7 +12,7 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
if (in_list(["Sales Order", "Quotation"], item.parenttype) && item.blanket_order_rate) {
|
||||
effective_item_rate = item.blanket_order_rate;
|
||||
}
|
||||
if(item.margin_type == "Percentage"){
|
||||
if (item.margin_type == "Percentage") {
|
||||
item.rate_with_margin = flt(effective_item_rate)
|
||||
+ flt(effective_item_rate) * ( flt(item.margin_rate_or_amount) / 100);
|
||||
} else {
|
||||
@@ -22,7 +22,7 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
|
||||
item_rate = flt(item.rate_with_margin , precision("rate", item));
|
||||
|
||||
if(item.discount_percentage){
|
||||
if (item.discount_percentage) {
|
||||
item.discount_amount = flt(item.rate_with_margin) * flt(item.discount_percentage) / 100;
|
||||
}
|
||||
|
||||
@@ -73,15 +73,18 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
},
|
||||
|
||||
_calculate_taxes_and_totals: function() {
|
||||
this.validate_conversion_rate();
|
||||
this.calculate_item_values();
|
||||
this.initialize_taxes();
|
||||
this.determine_exclusive_rate();
|
||||
this.calculate_net_total();
|
||||
this.calculate_taxes();
|
||||
this.manipulate_grand_total_for_inclusive_tax();
|
||||
this.calculate_totals();
|
||||
this._cleanup();
|
||||
frappe.run_serially([
|
||||
() => this.validate_conversion_rate(),
|
||||
() => this.calculate_item_values(),
|
||||
() => this.update_item_tax_map(),
|
||||
() => this.initialize_taxes(),
|
||||
() => this.determine_exclusive_rate(),
|
||||
() => this.calculate_net_total(),
|
||||
() => this.calculate_taxes(),
|
||||
() => this.manipulate_grand_total_for_inclusive_tax(),
|
||||
() => this.calculate_totals(),
|
||||
() => this._cleanup()
|
||||
]);
|
||||
},
|
||||
|
||||
validate_conversion_rate: function() {
|
||||
@@ -263,6 +266,65 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
frappe.model.round_floats_in(this.frm.doc, ["total", "base_total", "net_total", "base_net_total"]);
|
||||
},
|
||||
|
||||
update_item_tax_map: function() {
|
||||
let me = this;
|
||||
let item_codes = [];
|
||||
let item_rates = {};
|
||||
$.each(this.frm.doc.items || [], function(i, item) {
|
||||
if (item.item_code) {
|
||||
// Use combination of name and item code in case same item is added multiple times
|
||||
item_codes.push([item.item_code, item.name]);
|
||||
item_rates[item.name] = item.net_rate;
|
||||
}
|
||||
});
|
||||
|
||||
if (item_codes.length) {
|
||||
return this.frm.call({
|
||||
method: "erpnext.stock.get_item_details.get_item_tax_info",
|
||||
args: {
|
||||
company: me.frm.doc.company,
|
||||
tax_category: cstr(me.frm.doc.tax_category),
|
||||
item_codes: item_codes,
|
||||
item_rates: item_rates
|
||||
},
|
||||
callback: function(r) {
|
||||
if (!r.exc) {
|
||||
$.each(me.frm.doc.items || [], function(i, item) {
|
||||
if (item.name && r.message.hasOwnProperty(item.name)) {
|
||||
item.item_tax_template = r.message[item.name].item_tax_template;
|
||||
item.item_tax_rate = r.message[item.name].item_tax_rate;
|
||||
me.add_taxes_from_item_tax_template(item.item_tax_rate);
|
||||
} else {
|
||||
item.item_tax_template = "";
|
||||
item.item_tax_rate = "{}";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
add_taxes_from_item_tax_template: function(item_tax_map) {
|
||||
let me = this;
|
||||
|
||||
if (item_tax_map && cint(frappe.defaults.get_default("add_taxes_from_item_tax_template"))) {
|
||||
if (typeof (item_tax_map) == "string") {
|
||||
item_tax_map = JSON.parse(item_tax_map);
|
||||
}
|
||||
|
||||
$.each(item_tax_map, function(tax, rate) {
|
||||
let found = (me.frm.doc.taxes || []).find(d => d.account_head === tax);
|
||||
if (!found) {
|
||||
let child = frappe.model.add_child(me.frm.doc, "taxes");
|
||||
child.charge_type = "On Net Total";
|
||||
child.account_head = tax;
|
||||
child.rate = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
calculate_taxes: function() {
|
||||
var me = this;
|
||||
this.frm.doc.rounding_adjustment = 0;
|
||||
@@ -406,6 +468,11 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
let tax_detail = tax.item_wise_tax_detail;
|
||||
let key = item.item_code || item.item_name;
|
||||
|
||||
if(typeof (tax_detail) == "string") {
|
||||
tax.item_wise_tax_detail = JSON.parse(tax.item_wise_tax_detail);
|
||||
tax_detail = tax.item_wise_tax_detail;
|
||||
}
|
||||
|
||||
let item_wise_tax_amount = current_tax_amount * this.frm.doc.conversion_rate;
|
||||
if (tax_detail && tax_detail[key])
|
||||
item_wise_tax_amount += tax_detail[key][1];
|
||||
@@ -464,7 +531,7 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
},
|
||||
|
||||
calculate_totals: function() {
|
||||
// Changing sequence can cause rounding_adjustmentng issue and on-screen discrepency
|
||||
// Changing sequence can because of rounding adjustment issue and on-screen discrepancy
|
||||
var me = this;
|
||||
var tax_count = this.frm.doc["taxes"] ? this.frm.doc["taxes"].length : 0;
|
||||
this.frm.doc.grand_total = flt(tax_count
|
||||
@@ -562,6 +629,8 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
tax.item_wise_tax_detail = JSON.stringify(tax.item_wise_tax_detail);
|
||||
});
|
||||
}
|
||||
|
||||
this.frm.refresh_fields();
|
||||
},
|
||||
|
||||
set_discount_amount: function() {
|
||||
|
||||
@@ -6,6 +6,7 @@ frappe.provide('erpnext.accounts.dimensions');
|
||||
erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
setup: function() {
|
||||
this._super();
|
||||
let me = this;
|
||||
frappe.flags.hide_serial_batch_dialog = true;
|
||||
frappe.ui.form.on(this.frm.doctype + " Item", "rate", function(frm, cdt, cdn) {
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
@@ -43,8 +44,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
cur_frm.cscript.calculate_stock_uom_rate(frm, cdt, cdn);
|
||||
});
|
||||
|
||||
|
||||
|
||||
frappe.ui.form.on(this.frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
});
|
||||
@@ -121,7 +120,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
}
|
||||
});
|
||||
|
||||
var me = this;
|
||||
if(this.frm.fields_dict["items"].grid.get_field('batch_no')) {
|
||||
this.frm.set_query("batch_no", "items", function(doc, cdt, cdn) {
|
||||
return me.set_query_for_batch(doc, cdt, cdn);
|
||||
@@ -261,11 +259,19 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
if(!in_list(["Delivery Note", "Sales Invoice", "Purchase Receipt", "Purchase Invoice"], this.frm.doc.doctype)) {
|
||||
return;
|
||||
}
|
||||
var me = this;
|
||||
var inspection_type = in_list(["Purchase Receipt", "Purchase Invoice"], this.frm.doc.doctype)
|
||||
|
||||
const me = this;
|
||||
if (!this.frm.is_new() && this.frm.doc.docstatus === 0) {
|
||||
this.frm.add_custom_button(__("Quality Inspection(s)"), () => {
|
||||
me.make_quality_inspection();
|
||||
}, __("Create"));
|
||||
this.frm.page.set_inner_btn_group_as_primary(__('Create'));
|
||||
}
|
||||
|
||||
const inspection_type = in_list(["Purchase Receipt", "Purchase Invoice"], this.frm.doc.doctype)
|
||||
? "Incoming" : "Outgoing";
|
||||
|
||||
var quality_inspection_field = this.frm.get_docfield("items", "quality_inspection");
|
||||
let quality_inspection_field = this.frm.get_docfield("items", "quality_inspection");
|
||||
quality_inspection_field.get_route_options_for_new_doc = function(row) {
|
||||
if(me.frm.is_new()) return;
|
||||
return {
|
||||
@@ -280,7 +286,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
}
|
||||
|
||||
this.frm.set_query("quality_inspection", "items", function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
let d = locals[cdt][cdn];
|
||||
return {
|
||||
filters: {
|
||||
docstatus: 1,
|
||||
@@ -381,7 +387,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
|
||||
if(this.frm.doc.scan_barcode) {
|
||||
frappe.call({
|
||||
method: "erpnext.selling.page.point_of_sale.point_of_sale.search_serial_or_batch_or_barcode_number",
|
||||
method: "erpnext.selling.page.point_of_sale.point_of_sale.search_for_serial_or_batch_or_barcode_number",
|
||||
args: { search_value: this.frm.doc.scan_barcode }
|
||||
}).then(r => {
|
||||
const data = r && r.message;
|
||||
@@ -556,6 +562,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
name: me.frm.doc.name,
|
||||
project: item.project || me.frm.doc.project,
|
||||
qty: item.qty || 1,
|
||||
net_rate: item.rate,
|
||||
stock_qty: item.stock_qty,
|
||||
conversion_factor: item.conversion_factor,
|
||||
weight_per_unit: item.weight_per_unit,
|
||||
@@ -712,30 +719,14 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
});
|
||||
},
|
||||
|
||||
add_taxes_from_item_tax_template: function(item_tax_map) {
|
||||
let me = this;
|
||||
|
||||
if(item_tax_map && cint(frappe.defaults.get_default("add_taxes_from_item_tax_template"))) {
|
||||
if(typeof (item_tax_map) == "string") {
|
||||
item_tax_map = JSON.parse(item_tax_map);
|
||||
}
|
||||
|
||||
$.each(item_tax_map, function(tax, rate) {
|
||||
let found = (me.frm.doc.taxes || []).find(d => d.account_head === tax);
|
||||
if(!found) {
|
||||
let child = frappe.model.add_child(me.frm.doc, "taxes");
|
||||
child.charge_type = "On Net Total";
|
||||
child.account_head = tax;
|
||||
child.rate = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
serial_no: function(doc, cdt, cdn) {
|
||||
var me = this;
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
|
||||
if (item && item.doctype === 'Purchase Receipt Item Supplied') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item && item.serial_no) {
|
||||
if (!item.item_code) {
|
||||
this.frm.trigger("item_code", cdt, cdn);
|
||||
@@ -835,9 +826,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
|
||||
frappe.run_serially([
|
||||
() => me.frm.script_manager.trigger("currency"),
|
||||
() => me.update_item_tax_map(),
|
||||
() => me.apply_default_taxes(),
|
||||
() => me.apply_pricing_rule()
|
||||
() => me.apply_pricing_rule(),
|
||||
() => me.calculate_taxes_and_totals()
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1816,7 +1807,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
item.item_tax_rate = r.message;
|
||||
me.add_taxes_from_item_tax_template(item.item_tax_rate);
|
||||
me.calculate_taxes_and_totals();
|
||||
}
|
||||
}
|
||||
@@ -1827,43 +1817,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
}
|
||||
},
|
||||
|
||||
update_item_tax_map: function() {
|
||||
var me = this;
|
||||
var item_codes = [];
|
||||
$.each(this.frm.doc.items || [], function(i, item) {
|
||||
if(item.item_code) {
|
||||
item_codes.push(item.item_code);
|
||||
}
|
||||
});
|
||||
|
||||
if(item_codes.length) {
|
||||
return this.frm.call({
|
||||
method: "erpnext.stock.get_item_details.get_item_tax_info",
|
||||
args: {
|
||||
company: me.frm.doc.company,
|
||||
tax_category: cstr(me.frm.doc.tax_category),
|
||||
item_codes: item_codes
|
||||
},
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
$.each(me.frm.doc.items || [], function(i, item) {
|
||||
if(item.item_code && r.message.hasOwnProperty(item.item_code)) {
|
||||
if (!item.item_tax_template) {
|
||||
item.item_tax_template = r.message[item.item_code].item_tax_template;
|
||||
item.item_tax_rate = r.message[item.item_code].item_tax_rate;
|
||||
}
|
||||
me.add_taxes_from_item_tax_template(item.item_tax_rate);
|
||||
} else {
|
||||
item.item_tax_template = "";
|
||||
item.item_tax_rate = "{}";
|
||||
}
|
||||
});
|
||||
me.calculate_taxes_and_totals();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
is_recurring: function() {
|
||||
// set default values for recurring documents
|
||||
@@ -1949,6 +1903,130 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
});
|
||||
},
|
||||
|
||||
make_quality_inspection: function () {
|
||||
let data = [];
|
||||
const fields = [
|
||||
{
|
||||
label: "Items",
|
||||
fieldtype: "Table",
|
||||
fieldname: "items",
|
||||
cannot_add_rows: true,
|
||||
in_place_edit: true,
|
||||
data: data,
|
||||
get_data: () => {
|
||||
return data;
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
fieldtype: "Data",
|
||||
fieldname: "docname",
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
fieldtype: "Read Only",
|
||||
fieldname: "item_code",
|
||||
label: __("Item Code"),
|
||||
in_list_view: true
|
||||
},
|
||||
{
|
||||
fieldtype: "Read Only",
|
||||
fieldname: "item_name",
|
||||
label: __("Item Name"),
|
||||
in_list_view: true
|
||||
},
|
||||
{
|
||||
fieldtype: "Float",
|
||||
fieldname: "qty",
|
||||
label: __("Accepted Quantity"),
|
||||
in_list_view: true,
|
||||
read_only: true
|
||||
},
|
||||
{
|
||||
fieldtype: "Float",
|
||||
fieldname: "sample_size",
|
||||
label: __("Sample Size"),
|
||||
reqd: true,
|
||||
in_list_view: true
|
||||
},
|
||||
{
|
||||
fieldtype: "Data",
|
||||
fieldname: "description",
|
||||
label: __("Description"),
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
fieldtype: "Data",
|
||||
fieldname: "serial_no",
|
||||
label: __("Serial No"),
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
fieldtype: "Data",
|
||||
fieldname: "batch_no",
|
||||
label: __("Batch No"),
|
||||
hidden: true
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
const me = this;
|
||||
const dialog = new frappe.ui.Dialog({
|
||||
title: __("Select Items for Quality Inspection"),
|
||||
fields: fields,
|
||||
primary_action: function () {
|
||||
const data = dialog.get_values();
|
||||
frappe.call({
|
||||
method: "erpnext.controllers.stock_controller.make_quality_inspections",
|
||||
args: {
|
||||
doctype: me.frm.doc.doctype,
|
||||
docname: me.frm.doc.name,
|
||||
items: data.items
|
||||
},
|
||||
freeze: true,
|
||||
callback: function (r) {
|
||||
if (r.message.length > 0) {
|
||||
if (r.message.length === 1) {
|
||||
frappe.set_route("Form", "Quality Inspection", r.message[0]);
|
||||
} else {
|
||||
frappe.route_options = {
|
||||
"reference_type": me.frm.doc.doctype,
|
||||
"reference_name": me.frm.doc.name
|
||||
};
|
||||
frappe.set_route("List", "Quality Inspection");
|
||||
}
|
||||
}
|
||||
dialog.hide();
|
||||
}
|
||||
});
|
||||
},
|
||||
primary_action_label: __("Create")
|
||||
});
|
||||
|
||||
this.frm.doc.items.forEach(item => {
|
||||
if (!item.quality_inspection) {
|
||||
let dialog_items = dialog.fields_dict.items;
|
||||
dialog_items.df.data.push({
|
||||
"docname": item.name,
|
||||
"item_code": item.item_code,
|
||||
"item_name": item.item_name,
|
||||
"qty": item.qty,
|
||||
"description": item.description,
|
||||
"serial_no": item.serial_no,
|
||||
"batch_no": item.batch_no
|
||||
});
|
||||
dialog_items.grid.refresh();
|
||||
}
|
||||
});
|
||||
|
||||
data = dialog.fields_dict.items.df.data;
|
||||
if (!data.length) {
|
||||
frappe.msgprint(__("All items in this document already have a linked Quality Inspection."));
|
||||
} else {
|
||||
dialog.show();
|
||||
}
|
||||
},
|
||||
|
||||
get_method_for_payment: function(){
|
||||
var method = "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry";
|
||||
if(cur_frm.doc.__onload && cur_frm.doc.__onload.make_payment_via_journal_entry){
|
||||
|
||||
@@ -20,10 +20,8 @@ class Quiz {
|
||||
}
|
||||
|
||||
make(data) {
|
||||
if (data.duration) {
|
||||
const timer_display = document.createElement("div");
|
||||
timer_display.classList.add("lms-timer", "float-right", "font-weight-bold");
|
||||
document.getElementsByClassName("lms-title")[0].appendChild(timer_display);
|
||||
if (data.is_time_bound) {
|
||||
$(".lms-timer").removeClass("hide");
|
||||
if (!data.activity || (data.activity && !data.activity.is_complete)) {
|
||||
this.initialiseTimer(data.duration);
|
||||
this.is_time_bound = true;
|
||||
@@ -118,7 +116,7 @@ class Quiz {
|
||||
quiz_response: this.get_selected(),
|
||||
course: this.course,
|
||||
program: this.program,
|
||||
time_taken: this.is_time_bound ? this.time_taken : ""
|
||||
time_taken: this.is_time_bound ? this.time_taken : 0
|
||||
}).then(res => {
|
||||
this.submit_btn.remove()
|
||||
if (!res.message) {
|
||||
@@ -237,4 +235,4 @@ class Question {
|
||||
this.options = option_list
|
||||
this.wrapper.appendChild(options_wrapper)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,24 +8,23 @@ erpnext.payments = erpnext.stock.StockController.extend({
|
||||
this.dialog = new frappe.ui.Dialog({
|
||||
title: 'Payment'
|
||||
});
|
||||
|
||||
|
||||
this.dialog.show();
|
||||
this.$body = this.dialog.body;
|
||||
this.set_payment_primary_action();
|
||||
this.make_keyboard();
|
||||
this.select_text()
|
||||
this.select_text();
|
||||
},
|
||||
|
||||
select_text: function(){
|
||||
var me = this;
|
||||
$(this.$body).find('.form-control').click(function(){
|
||||
select_text() {
|
||||
$(this.$body).find('.form-control').click(function() {
|
||||
$(this).select();
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
set_payment_primary_action: function(){
|
||||
set_payment_primary_action: function() {
|
||||
var me = this;
|
||||
|
||||
|
||||
this.dialog.set_primary_action(__("Submit"), function() {
|
||||
// Allow no ZERO payment
|
||||
$.each(me.frm.doc.payments, function (index, data) {
|
||||
@@ -38,20 +37,20 @@ erpnext.payments = erpnext.stock.StockController.extend({
|
||||
})
|
||||
},
|
||||
|
||||
make_keyboard: function(){
|
||||
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()
|
||||
this.clear_amount()
|
||||
this.bind_keyboard_event();
|
||||
this.clear_amount();
|
||||
},
|
||||
|
||||
make_multimode_payment: function(){
|
||||
make_multimode_payment: function() {
|
||||
var me = this;
|
||||
|
||||
if(this.frm.doc.change_amount > 0){
|
||||
me.payment_val = me.doc.outstanding_amount
|
||||
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");
|
||||
@@ -59,11 +58,11 @@ erpnext.payments = erpnext.stock.StockController.extend({
|
||||
this.payments.amount = flt(this.payment_val);
|
||||
},
|
||||
|
||||
show_payment_details: function(){
|
||||
show_payment_details: function() {
|
||||
var me = this;
|
||||
var multimode_payments = $(this.$body).find('.multimode-payments').empty();
|
||||
if(this.frm.doc.payments.length){
|
||||
$.each(this.frm.doc.payments, function(index, data){
|
||||
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,
|
||||
@@ -84,92 +83,90 @@ erpnext.payments = erpnext.stock.StockController.extend({
|
||||
}
|
||||
},
|
||||
|
||||
set_outstanding_amount: function(){
|
||||
set_outstanding_amount: function() {
|
||||
this.selected_mode = $(this.$body).find(repl("input[idx='%(idx)s']",{'idx': this.idx}));
|
||||
this.highlight_selected_row()
|
||||
this.payment_val = 0.0
|
||||
if(this.frm.doc.outstanding_amount > 0 && flt(this.selected_mode.val()) == 0.0){
|
||||
this.highlight_selected_row();
|
||||
this.payment_val = 0.0;
|
||||
if (this.frm.doc.outstanding_amount > 0 && flt(this.selected_mode.val()) == 0.0) {
|
||||
//When user first time click on row
|
||||
this.payment_val = flt(this.frm.doc.outstanding_amount / this.frm.doc.conversion_rate, precision("outstanding_amount"))
|
||||
this.selected_mode.val(format_currency(this.payment_val, this.frm.doc.currency));
|
||||
this.update_payment_amount()
|
||||
}else if(flt(this.selected_mode.val()) > 0){
|
||||
this.update_payment_amount();
|
||||
} else if (flt(this.selected_mode.val()) > 0) {
|
||||
//If user click on existing row which has value
|
||||
this.payment_val = flt(this.selected_mode.val());
|
||||
}
|
||||
this.selected_mode.select()
|
||||
this.bind_amount_change_event();
|
||||
},
|
||||
|
||||
bind_keyboard_event: function(){
|
||||
var me = this;
|
||||
|
||||
bind_keyboard_event() {
|
||||
this.payment_val = '';
|
||||
this.bind_form_control_event();
|
||||
this.bind_numeric_keys_event();
|
||||
},
|
||||
|
||||
bind_form_control_event: function(){
|
||||
bind_form_control_event: function() {
|
||||
var me = this;
|
||||
$(this.$body).find('.pos-payment-row').click(function(){
|
||||
$(this.$body).find('.pos-payment-row').click(function() {
|
||||
me.idx = $(this).attr("idx");
|
||||
me.set_outstanding_amount()
|
||||
})
|
||||
|
||||
$(this.$body).find('.form-control').click(function(){
|
||||
me.set_outstanding_amount();
|
||||
});
|
||||
|
||||
$(this.$body).find('.form-control').click(function() {
|
||||
me.idx = $(this).attr("idx");
|
||||
me.set_outstanding_amount();
|
||||
me.update_paid_amount(true);
|
||||
})
|
||||
|
||||
$(this.$body).find('.write_off_amount').change(function(){
|
||||
});
|
||||
|
||||
$(this.$body).find('.write_off_amount').change(function() {
|
||||
me.write_off_amount(flt($(this).val()), precision("write_off_amount"));
|
||||
})
|
||||
|
||||
$(this.$body).find('.change_amount').change(function(){
|
||||
});
|
||||
|
||||
$(this.$body).find('.change_amount').change(function() {
|
||||
me.change_amount(flt($(this).val()), precision("change_amount"));
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
highlight_selected_row: function(){
|
||||
var me = this;
|
||||
var 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')
|
||||
highlight_selected_row() {
|
||||
var 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_numeric_keys_event: function(){
|
||||
|
||||
bind_numeric_keys_event: function() {
|
||||
var me = this;
|
||||
$(this.$body).find('.pos-keyboard-key').click(function(){
|
||||
me.payment_val += $(this).text();
|
||||
me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency))
|
||||
me.idx = me.selected_mode.attr("idx")
|
||||
me.update_paid_amount()
|
||||
})
|
||||
|
||||
$(this.$body).find('.delete-btn').click(function(){
|
||||
me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency));
|
||||
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_currency(me.payment_val, me.frm.doc.currency));
|
||||
me.idx = me.selected_mode.attr("idx")
|
||||
me.idx = me.selected_mode.attr("idx");
|
||||
me.update_paid_amount();
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
bind_amount_change_event: function(){
|
||||
|
||||
bind_amount_change_event() {
|
||||
var me = this;
|
||||
this.selected_mode.change(function(){
|
||||
this.selected_mode.change(function() {
|
||||
me.payment_val = flt($(this).val()) || 0.0;
|
||||
me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency))
|
||||
me.idx = me.selected_mode.attr("idx")
|
||||
me.update_payment_amount()
|
||||
})
|
||||
me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency));
|
||||
me.idx = me.selected_mode.attr("idx");
|
||||
me.update_payment_amount();
|
||||
});
|
||||
},
|
||||
|
||||
clear_amount: function() {
|
||||
var me = this;
|
||||
$(this.$body).find('.clr').click(function(e){
|
||||
$(this.$body).find('.clr').click(function(e) {
|
||||
e.stopPropagation();
|
||||
me.idx = $(this).attr("idx");
|
||||
me.selected_mode = $(me.$body).find(repl("input[idx='%(idx)s']",{'idx': me.idx}));
|
||||
@@ -177,50 +174,48 @@ erpnext.payments = erpnext.stock.StockController.extend({
|
||||
me.selected_mode.val(0.0);
|
||||
me.highlight_selected_row();
|
||||
me.update_payment_amount();
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
write_off_amount: function(write_off_amount) {
|
||||
var me = this;
|
||||
|
||||
write_off_amount(write_off_amount) {
|
||||
this.frm.doc.write_off_amount = flt(write_off_amount, precision("write_off_amount"));
|
||||
this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate,
|
||||
precision("base_write_off_amount"));
|
||||
this.calculate_outstanding_amount(false)
|
||||
this.show_amounts()
|
||||
this.calculate_outstanding_amount(false);
|
||||
this.show_amounts();
|
||||
},
|
||||
|
||||
change_amount: function(change_amount) {
|
||||
var me = this;
|
||||
|
||||
this.frm.doc.change_amount = flt(change_amount, precision("change_amount"));
|
||||
this.calculate_write_off_amount()
|
||||
this.show_amounts()
|
||||
this.calculate_write_off_amount();
|
||||
this.show_amounts();
|
||||
},
|
||||
|
||||
update_paid_amount: function(update_write_off) {
|
||||
var me = this;
|
||||
if(in_list(['change_amount', 'write_off_amount'], this.idx)){
|
||||
if (in_list(['change_amount', 'write_off_amount'], this.idx)) {
|
||||
var value = me.selected_mode.val();
|
||||
if(me.idx == 'change_amount'){
|
||||
me.change_amount(value)
|
||||
} else{
|
||||
if (me.idx == 'change_amount') {
|
||||
me.change_amount(value);
|
||||
} else {
|
||||
if(flt(value) == 0 && update_write_off && me.frm.doc.outstanding_amount > 0) {
|
||||
value = flt(me.frm.doc.outstanding_amount / me.frm.doc.conversion_rate, precision(me.idx));
|
||||
}
|
||||
me.write_off_amount(value)
|
||||
me.write_off_amount(value);
|
||||
}
|
||||
}else{
|
||||
this.update_payment_amount()
|
||||
} else {
|
||||
this.update_payment_amount();
|
||||
}
|
||||
},
|
||||
|
||||
update_payment_amount: function(){
|
||||
update_payment_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)
|
||||
$.each(this.frm.doc.payments, function(index, data) {
|
||||
if (cint(me.idx) == cint(data.idx)) {
|
||||
data.amount = flt(me.selected_mode.val(), 2);
|
||||
}
|
||||
})
|
||||
|
||||
@@ -228,12 +223,12 @@ erpnext.payments = erpnext.stock.StockController.extend({
|
||||
this.show_amounts();
|
||||
},
|
||||
|
||||
show_amounts: function(){
|
||||
show_amounts: function() {
|
||||
var me = this;
|
||||
$(this.$body).find(".write_off_amount").val(format_currency(this.frm.doc.write_off_amount, this.frm.doc.currency));
|
||||
$(this.$body).find('.paid_amount').text(format_currency(this.frm.doc.paid_amount, this.frm.doc.currency));
|
||||
$(this.$body).find('.change_amount').val(format_currency(this.frm.doc.change_amount, this.frm.doc.currency))
|
||||
$(this.$body).find('.outstanding_amount').text(format_currency(this.frm.doc.outstanding_amount, frappe.get_doc(":Company", this.frm.doc.company).default_currency))
|
||||
$(this.$body).find('.change_amount').val(format_currency(this.frm.doc.change_amount, this.frm.doc.currency));
|
||||
$(this.$body).find('.outstanding_amount').text(format_currency(this.frm.doc.outstanding_amount, frappe.get_doc(":Company", this.frm.doc.company).default_currency));
|
||||
this.update_invoice();
|
||||
}
|
||||
})
|
||||
@@ -806,6 +806,9 @@
|
||||
display: none;
|
||||
float: right;
|
||||
font-weight: 700;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
> .cash-shortcuts {
|
||||
@@ -829,6 +832,11 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
> .loyalty-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1134,4 +1142,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user