2015-03-03 09:25:30 +00:00
|
|
|
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2013-08-05 09:29:54 +00:00
|
|
|
// License: GNU General Public License v3. See license.txt
|
2013-01-11 13:55:46 +00:00
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.provide("erpnext.stock");
|
2013-01-11 13:55:46 +00:00
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
erpnext.stock.StockController = class StockController extends frappe.ui.form.Controller {
|
2014-06-24 13:23:04 +00:00
|
|
|
onload() {
|
|
|
|
// warehouse query if company
|
|
|
|
if (this.frm.fields_dict.company) {
|
|
|
|
this.setup_warehouse_query();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_warehouse_query() {
|
2015-08-13 06:17:25 +00:00
|
|
|
var me = this;
|
|
|
|
erpnext.queries.setup_queries(this.frm, "Warehouse", function() {
|
2014-06-25 07:59:43 +00:00
|
|
|
return erpnext.queries.warehouse(me.frm.doc);
|
2014-06-24 13:23:04 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-03-14 11:29:11 +00:00
|
|
|
setup_posting_date_time_check() {
|
|
|
|
// make posting date default and read only unless explictly checked
|
|
|
|
frappe.ui.form.on(this.frm.doctype, 'set_posting_date_and_time_read_only', function(frm) {
|
|
|
|
if(frm.doc.docstatus == 0 && frm.doc.set_posting_time) {
|
|
|
|
frm.set_df_property('posting_date', 'read_only', 0);
|
|
|
|
frm.set_df_property('posting_time', 'read_only', 0);
|
|
|
|
} else {
|
|
|
|
frm.set_df_property('posting_date', 'read_only', 1);
|
|
|
|
frm.set_df_property('posting_time', 'read_only', 1);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
frappe.ui.form.on(this.frm.doctype, 'set_posting_time', function(frm) {
|
|
|
|
frm.trigger('set_posting_date_and_time_read_only');
|
|
|
|
});
|
|
|
|
|
|
|
|
frappe.ui.form.on(this.frm.doctype, 'refresh', function(frm) {
|
|
|
|
// set default posting date / time
|
|
|
|
if(frm.doc.docstatus==0) {
|
|
|
|
if(!frm.doc.posting_date) {
|
|
|
|
frm.set_value('posting_date', frappe.datetime.nowdate());
|
|
|
|
}
|
|
|
|
if(!frm.doc.posting_time) {
|
|
|
|
frm.set_value('posting_time', frappe.datetime.now_time());
|
|
|
|
}
|
|
|
|
frm.trigger('set_posting_date_and_time_read_only');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-01-11 13:55:46 +00:00
|
|
|
show_stock_ledger() {
|
|
|
|
var me = this;
|
2020-04-30 05:08:58 +00:00
|
|
|
if(this.frm.doc.docstatus > 0) {
|
2014-12-16 11:49:36 +00:00
|
|
|
cur_frm.add_custom_button(__("Stock Ledger"), function() {
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.route_options = {
|
2013-07-30 09:12:15 +00:00
|
|
|
voucher_no: me.frm.doc.name,
|
|
|
|
from_date: me.frm.doc.posting_date,
|
2020-06-25 10:04:01 +00:00
|
|
|
to_date: moment(me.frm.doc.modified).format('YYYY-MM-DD'),
|
|
|
|
company: me.frm.doc.company,
|
|
|
|
show_cancelled_entries: me.frm.doc.docstatus === 2
|
2013-07-30 09:12:15 +00:00
|
|
|
};
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.set_route("query-report", "Stock Ledger");
|
2016-01-06 10:04:56 +00:00
|
|
|
}, __("View"));
|
2013-07-30 09:12:15 +00:00
|
|
|
}
|
2014-06-24 13:23:04 +00:00
|
|
|
|
2013-07-09 06:35:33 +00:00
|
|
|
}
|
2013-10-17 11:31:14 +00:00
|
|
|
|
2013-07-09 06:35:33 +00:00
|
|
|
show_general_ledger() {
|
2023-06-04 13:50:28 +00:00
|
|
|
let me = this;
|
2020-04-30 05:08:58 +00:00
|
|
|
if(this.frm.doc.docstatus > 0) {
|
2014-12-16 11:49:36 +00:00
|
|
|
cur_frm.add_custom_button(__('Accounting Ledger'), function() {
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.route_options = {
|
2013-12-23 11:37:57 +00:00
|
|
|
voucher_no: me.frm.doc.name,
|
|
|
|
from_date: me.frm.doc.posting_date,
|
2020-06-25 10:04:01 +00:00
|
|
|
to_date: moment(me.frm.doc.modified).format('YYYY-MM-DD'),
|
2014-01-03 07:00:24 +00:00
|
|
|
company: me.frm.doc.company,
|
2020-06-25 10:04:01 +00:00
|
|
|
group_by: "Group by Voucher (Consolidated)",
|
|
|
|
show_cancelled_entries: me.frm.doc.docstatus === 2
|
2013-07-09 06:35:33 +00:00
|
|
|
};
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.set_route("query-report", "General Ledger");
|
2016-01-06 10:04:56 +00:00
|
|
|
}, __("View"));
|
2013-07-09 06:35:33 +00:00
|
|
|
}
|
2013-01-11 13:55:46 +00:00
|
|
|
}
|
2023-06-04 13:50:28 +00:00
|
|
|
|
|
|
|
show_ledger_preview() {
|
|
|
|
let me = this
|
|
|
|
if(this.frm.doc.docstatus == 0) {
|
|
|
|
cur_frm.add_custom_button(__('Accounting Ledger Preview'), function() {
|
|
|
|
frappe.call({
|
|
|
|
"method": "erpnext.controllers.stock_controller.show_ledger_preview",
|
|
|
|
"args": {
|
|
|
|
"company": me.frm.doc.company,
|
|
|
|
"doctype": me.frm.doc.doctype,
|
|
|
|
"docname": me.frm.doc.name
|
|
|
|
},
|
|
|
|
"callback": function(response) {
|
2023-06-21 11:45:46 +00:00
|
|
|
me.make_dialog(response.message);
|
2023-06-04 13:50:28 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}, __("View"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-21 11:45:46 +00:00
|
|
|
make_dialog(data) {
|
|
|
|
let me = this;
|
|
|
|
let gl_columns = data.gl_columns;
|
|
|
|
let gl_data = data.gl_data;
|
|
|
|
let sl_columns = data.sl_columns;
|
|
|
|
let sl_data = data.sl_data;
|
|
|
|
|
|
|
|
let dialog = new frappe.ui.Dialog({
|
|
|
|
"size": "extra-large",
|
|
|
|
"title": __("Ledger Preview"),
|
|
|
|
"fields": [
|
|
|
|
{
|
|
|
|
"fieldtype": "HTML",
|
|
|
|
"fieldname": "accounting_ledger_preview_html",
|
|
|
|
"label": __("Accounting Ledger"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fieldtype": "HTML",
|
|
|
|
"fieldname": "stock_ledger_preview_html",
|
|
|
|
"label": __("Stock Ledger"),
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
me.get_datatable(gl_columns, gl_data, dialog.get_field("accounting_ledger_preview_html").wrapper);
|
|
|
|
}, 200);
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
|
2023-06-12 06:16:51 +00:00
|
|
|
get_datatable(columns, data, wrapper) {
|
2023-06-04 13:50:28 +00:00
|
|
|
const datatable_options = {
|
2023-06-12 06:16:51 +00:00
|
|
|
columns: columns,
|
|
|
|
data: data,
|
2023-06-04 13:50:28 +00:00
|
|
|
dynamicRowHeight: true,
|
|
|
|
checkboxColumn: false,
|
|
|
|
inlineFilters: true,
|
|
|
|
};
|
|
|
|
|
2023-06-12 06:16:51 +00:00
|
|
|
new frappe.DataTable(
|
|
|
|
wrapper,
|
2023-06-04 13:50:28 +00:00
|
|
|
datatable_options
|
|
|
|
);
|
|
|
|
}
|
2014-06-24 13:23:04 +00:00
|
|
|
};
|