// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt frappe.provide("erpnext.stock"); erpnext.stock.StockController = class StockController extends frappe.ui.form.Controller { onload() { // warehouse query if company if (this.frm.fields_dict.company) { this.setup_warehouse_query(); } } setup_warehouse_query() { var me = this; erpnext.queries.setup_queries(this.frm, "Warehouse", function() { return erpnext.queries.warehouse(me.frm.doc); }); } 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'); } }); } show_stock_ledger() { var me = this; if(this.frm.doc.docstatus > 0) { cur_frm.add_custom_button(__("Stock Ledger"), function() { frappe.route_options = { voucher_no: me.frm.doc.name, from_date: me.frm.doc.posting_date, to_date: moment(me.frm.doc.modified).format('YYYY-MM-DD'), company: me.frm.doc.company, show_cancelled_entries: me.frm.doc.docstatus === 2 }; frappe.set_route("query-report", "Stock Ledger"); }, __("View")); } } show_general_ledger() { let me = this; if(this.frm.doc.docstatus > 0) { cur_frm.add_custom_button(__('Accounting Ledger'), function() { frappe.route_options = { voucher_no: me.frm.doc.name, from_date: me.frm.doc.posting_date, to_date: moment(me.frm.doc.modified).format('YYYY-MM-DD'), company: me.frm.doc.company, group_by: "Group by Voucher (Consolidated)", show_cancelled_entries: me.frm.doc.docstatus === 2 }; frappe.set_route("query-report", "General Ledger"); }, __("View")); } } 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) { me.make_dialog(response.message); } }) }, __("View")); } } 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(); } get_datatable(columns, data, wrapper) { const datatable_options = { columns: columns, data: data, dynamicRowHeight: true, checkboxColumn: false, inlineFilters: true, }; new frappe.DataTable( wrapper, datatable_options ); } };