odoo.define('base_accounting_kit.AccountingDashboard', function(require) { 'use strict'; var AbstractAction = require('web.AbstractAction'); var ajax = require('web.ajax'); var core = require('web.core'); var rpc = require('web.rpc'); var web_client = require('web.web_client'); var _t = core._t; var QWeb = core.qweb; var self = this; const { loadBundle } = require("@web/core/assets"); var currency; var ActionMenu = AbstractAction.extend({ contentTemplate: 'Invoicedashboard', events: { 'click .invoice_dashboard': 'onclick_dashboard', 'click #prog_bar': 'onclick_prog_bar', 'click #invoice_this_month': 'onclick_invoice_this_month', 'click #invoice_this_year': 'onclick_invoice_this_year', 'click #invoice_last_month': 'onclick_invoice_last_month', 'click #invoice_last_year': 'onclick_invoice_last_year', 'click #onclick_banks_balance': 'onclick_bank_balance', 'click #income_this_month': 'onclick_income_this_month', 'click #income_this_year': 'onclick_income_this_year', 'click #income_last_month': 'onclick_income_last_month', 'click #income_last_year': 'onclick_income_last_year', 'click #total_aged_payable': 'onclick_total_aged_payable', 'click #in_ex_bar_chart': 'onclick_in_ex_bar_chart', 'click #aged_recevable_pie_chart': 'onclick_aged_recevable_pie_chart', 'click #invoice_bar_chart': 'onclick_invoice_bar_chart', 'click .overdue_line_cust': 'onclick_overdue_line_cust', 'click .top_customers': 'onclick_top_customers', 'click .top_customers_amount': 'onclick_top_customers_amount', 'click #bank_balance_hide': 'onclick_bank_balance_hide', 'click #cash_balance_hide': 'onclick_cash_balance_hide', 'click #in_ex_hide': 'onclick_in_ex_hide', 'click #aged_payable_hide': 'onclick_aged_payable_hide', 'change #aged_receivable_values': function(e) { e.stopPropagation(); var $target = $(e.target); var value = $target.val(); this.onclick_aged_payable(this.$('#aged_receivable_values').val()); }, 'change #aged_payable_value': function(e) { e.stopPropagation(); var $target = $(e.target); var value = $target.val(); this.$('.aged_receivable_this_month').empty(); this.onclick_aged_receivable(this.$('#aged_payable_value').val()); }, 'change #top_10_customer_value': function(e) { e.stopPropagation(); var $target = $(e.target); var value = $target.val(); this.$('.top_10_customers_this_month').empty(); this.onclick_top_10_month(this.$('#top_10_customer_value').val()); }, 'change #invoice_values': function(e) { e.stopPropagation(); var $target = $(e.target); var value = $target.val(); if (value == 'this_year'){ this.onclick_invoice_this_year(this.$('#invoice_values').val()); } else{ this.onclick_invoice_this_month(this.$('#invoice_values').val()); } // this.$('.invoice_this_year').empty(); }, 'change #income_expense_values': function(e) { e.stopPropagation(); var $target = $(e.target); var value = $target.val(); if (value == 'income_this_year'){ this.onclick_income_this_year(this.$('#income_expense_values').val()); } else if (value == 'income_this_month'){ this.onclick_income_this_month(this.$('#income_expense_values').val()); } else if (value == 'income_last_month'){ this.onclick_income_last_month(this.$('#income_expense_values').val()); } else{ this.onclick_income_last_year(this.$('#income_expense_values').val()); } }, 'change #toggle-two': 'onclick_toggle_two', 'click #unreconciled_counts_this_year': 'unreconciled_year', 'click #unreconciled_items_': 'unreconciled_month', 'click #total_customer_invoice_paid_current_month': 'invoice_month_paid', 'click #total_customer_invoice_current_month': 'invoice_month', 'click #total_supplier_invoice_paid_current_month': 'bill_month_paid', 'click #total_supplier_invoice_current_month': 'bill_month', 'click #total_customer_invoice_paid_current_year': 'invoice_year_paid', 'click #total_customer_invoice_current_year': 'invoice_year', 'click #total_supplier_invoice_paid_current_year': 'bill_year_paid', 'click #total_supplier_invoice_current_year': 'bill_year', 'click #net_profit_current_year': 'profit_income_year', 'click #net_profit_current_months': 'profit_income_month', 'click #total_incomes_this_year': 'total_income_year', 'click #total_incomes_': 'total_income_month', 'click #total_expense_this_year': 'expense_year', 'click #total_expenses_': 'expense_month', }, profit_income_year: function(ev) { var posted = false; var self = this; rpc.query({ model: "account.move", method: "click_profit_income_year", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move.line', name: _t('Net Profit or Loss'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, profit_income_month: function(ev) { var posted = false; var self = this; rpc.query({ model: "account.move", method: "click_profit_income_month", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move.line', name: _t('Net Profit or Loss'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, total_income_year: function(ev) { var posted = false; var self = this; rpc.query({ model: "account.move", method: "click_total_income_year", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move.line', name: _t('Total Income'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, total_income_month: function(ev) { var posted = false; var self = this; rpc.query({ model: "account.move", method: "click_total_income_month", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move.line', name: _t('Total Income'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, expense_year: function(ev) { var posted = false; var self = this; rpc.query({ model: "account.move", method: "click_expense_year", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move.line', name: _t('Total Expenses'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, expense_month: function(ev) { var posted = false; var self = this; rpc.query({ model: "account.move", method: "click_expense_month", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move.line', name: _t('Total Expenses'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, unreconciled_year: function(ev) { var posted = false; var self = this; rpc.query({ model: "account.move", method: "click_unreconcile_year", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move.line', name: _t('Unreconciled'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, unreconciled_month: function(ev) { var posted = false; var self = this; rpc.query({ model: "account.move", method: "click_unreconcile_month", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move.line', name: _t('Unreconciled'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, invoice_month_paid: function(ev) { var posted = false; if ($('#toggle-two')[0].checked == true) { posted = "posted" } var self = this; rpc.query({ model: "account.move", method: "click_invoice_month_paid", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move', name: _t('Paid'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, invoice_month: function(ev) { var posted = false; if ($('#toggle-two')[0].checked == true) { posted = "posted" } var self = this; rpc.query({ model: "account.move", method: "click_invoice_month", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move', name: _t('Invoice'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, bill_month_paid: function(ev) { var posted = false; if ($('#toggle-two')[0].checked == true) { posted = "posted" } var self = this; rpc.query({ model: "account.move", method: "click_bill_month_paid", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move', name: _t('Paid'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, bill_month: function(ev) { var posted = false; if ($('#toggle-two')[0].checked == true) { posted = "posted" } var self = this; rpc.query({ model: "account.move", method: "click_bill_month", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move', name: _t('Invoice'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, bill_year: function(ev) { var posted = false; if ($('#toggle-two')[0].checked == true) { posted = "posted" } var self = this; rpc.query({ model: "account.move", method: "click_bill_year", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move', name: _t('Invoice'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, bill_year_paid: function(ev) { var posted = false; if ($('#toggle-two')[0].checked == true) { posted = "posted" } var self = this; rpc.query({ model: "account.move", method: "click_bill_year_paid", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move', name: _t('Paid'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, invoice_year: function(ev) { var posted = false; if ($('#toggle-two')[0].checked == true) { posted = "posted" } var self = this; rpc.query({ model: "account.move", method: "click_invoice_year", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move', name: _t('Invoice'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, invoice_year_paid: function(ev) { var posted = false; if ($('#toggle-two')[0].checked == true) { posted = "posted" } var self = this; rpc.query({ model: "account.move", method: "click_invoice_year_paid", args: [posted], }).then(function(result) { self.do_action({ res_model: 'account.move', name: _t('Paid'), views: [ [false, 'list'], [false, 'form'] ], type: 'ir.actions.act_window', domain: [ ['id', 'in', result] ], }); }) }, onclick_toggle_two: function(ev) { this.onclick_aged_payable(this.$('#aged_receivable_values').val()); this.onclick_aged_receivable(this.$('#aged_payable_value').val()); this.onclick_invoice_this_year(ev); this.onclick_invoice_this_month(ev); this.onclick_income_this_month(ev); this.onclick_income_last_month(ev); this.onclick_income_last_year(ev); this.onclick_income_this_year(ev); }, onclick_top_10_month: function(f) { var selected = $('.btn.btn-tool.income'); var data = $(selected[0]).data(); var posted = false; var self = this; var f = f; if ($('#toggle-two')[0].checked == true) { posted = "posted" } rpc.query({ model: "account.move", method: "get_currency", }).then(function(result) { currency = result; }) rpc.query({ model: "account.move", method: "get_top_10_customers_month", args: [posted, f] }).then(function(result) { $('#top_10_customers').hide(); $('#top_10_customers_last_month').hide(); $('#top_10_customers_this_month').show(); $('#top_10_customers_this_month').empty(); var due_count = 0; _.forEach(result, function(x) { due_count++; var amount = self.format_currency(currency, x.amount); $('#top_10_customers_this_month').append('
  • ' + x.customers + '
    ' + '
    ' + amount + '
    ' + '
  • '); $('#line_' + x.parent).on("click", function() { self.do_action({ res_model: 'res.partner', name: _t('Partner'), views: [ [false, 'form'] ], type: 'ir.actions.act_window', res_id: x.parent, }); }); }); }) }, onclick_income_last_year: function(ev) { // ev.preventDefault(); var selected = $('.btn.btn-tool.income'); var data = $(selected[0]).data(); var posted = false; if ($('#toggle-two')[0].checked == true) { posted = "posted" } rpc.query({ model: 'account.move', method: 'get_income_last_year', args: [posted], }).then(function(result) { $('#net_profit_current_months').hide(); $('#net_profit_last_month').hide(); $('#net_profit_last_year').show(); $('#net_profit_this_year').hide(); var ctx = document.getElementById("canvas").getContext('2d'); // Define the data var income = result.income; // Add data values to array var expense = result.expense; var profit = result.profit; var labels = result.month; // Add labels to array // End Defining data // End Defining data if (window.myCharts != undefined) window.myCharts.destroy(); window.myCharts = new Chart(ctx, { //var myChart = new Chart(ctx, { type: 'bar', data: { labels: labels, datasets: [{ label: 'Income', // Name the series data: income, // Specify the data values array backgroundColor: '#66aecf', borderColor: '#66aecf', borderWidth: 1, // Specify bar border width type: 'bar', // Set this data to a line chart fill: false }, { label: 'Expense', // Name the series data: expense, // Specify the data values array backgroundColor: '#6993d6', borderColor: '#6993d6', borderWidth: 1, // Specify bar border width type: 'bar', // Set this data to a line chart fill: false }, { label: 'Profit/Loss', // Name the series data: profit, // Specify the data values array backgroundColor: '#0bd465', borderColor: '#0bd465', borderWidth: 1, // Specify bar border width type: 'line', // Set this data to a line chart fill: false } ] }, options: { responsive: true, // Instruct chart js to respond nicely. maintainAspectRatio: false, // Add to prevent default behaviour of full-width/height } }); }) }, onclick_income_last_month: function(ev) { // ev.preventDefault(); var selected = $('.btn.btn-tool.income'); var data = $(selected[0]).data(); var posted = false; if ($('#toggle-two')[0].checked == true) { posted = "posted" } rpc.query({ model: 'account.move', method: 'get_income_last_month', args: [posted], }).then(function(result) { $('#net_profit_current_months').hide(); $('#net_profit_last_month').show(); $('#net_profit_this_year').hide(); $('#net_profit_last_year').hide(); var ctx = document.getElementById("canvas").getContext('2d'); // Define the data var income = result.income; // Add data values to array var expense = result.expense; var profit = result.profit; var labels = result.date; // Add labels to array // End Defining data // End Defining data if (window.myCharts != undefined) window.myCharts.destroy(); window.myCharts = new Chart(ctx, { type: 'bar', data: { labels: labels, datasets: [{ label: 'Income', // Name the series data: income, // Specify the data values array backgroundColor: '#66aecf', borderColor: '#66aecf', borderWidth: 1, // Specify bar border width type: 'bar', // Set this data to a line chart fill: false }, { label: 'Expense', // Name the series data: expense, // Specify the data values array backgroundColor: '#6993d6', borderColor: '#6993d6', borderWidth: 1, // Specify bar border width type: 'bar', // Set this data to a line chart fill: false }, { label: 'Profit/Loss', // Name the series data: profit, // Specify the data values array backgroundColor: '#0bd465', borderColor: '#0bd465', borderWidth: 1, // Specify bar border width type: 'line', // Set this data to a line chart fill: false } ] }, options: { responsive: true, // Instruct chart js to respond nicely. maintainAspectRatio: false, // Add to prevent default behaviour of full-width/height } }); }) }, onclick_income_this_year: function(ev) { // ev.preventDefault(); var selected = $('.btn.btn-tool.income'); var data = $(selected[0]).data(); var posted = false; if ($('#toggle-two')[0].checked == true) { posted = "posted" } rpc.query({ model: 'account.move', method: 'get_income_this_year', args: [posted], }).then(function(result) { $('#net_profit_current_months').hide(); $('#net_profit_last_month').hide(); $('#net_profit_last_year').hide(); $('#net_profit_this_year').show(); var ctx = document.getElementById("canvas").getContext('2d'); // Define the data var income = result.income; // Add data values to array var expense = result.expense; var profit = result.profit; var labels = result.month; // Add labels to array if (window.myCharts != undefined) window.myCharts.destroy(); window.myCharts = new Chart(ctx, { //var myChart = new Chart(ctx, { type: 'bar', data: { labels: labels, datasets: [{ label: 'Income', // Name the series data: income, // Specify the data values array backgroundColor: '#66aecf', borderColor: '#66aecf', borderWidth: 1, // Specify bar border width type: 'bar', // Set this data to a line chart fill: false }, { label: 'Expense', // Name the series data: expense, // Specify the data values array backgroundColor: '#6993d6', borderColor: '#6993d6', borderWidth: 1, // Specify bar border width type: 'bar', // Set this data to a line chart fill: false }, { label: 'Profit/Loss', // Name the series data: profit, // Specify the data values array backgroundColor: '#0bd465', borderColor: '#0bd465', borderWidth: 1, // Specify bar border width type: 'line', // Set this data to a line chart fill: false }] }, options: { responsive: true, // Instruct chart js to respond nicely. maintainAspectRatio: false, // Add to prevent default behaviour of full-width/height } }); }) }, onclick_invoice_this_year: function(ev) { // ev.preventDefault(); var selected = $('.btn.btn-tool.selected'); var data = $(selected[0]).data(); var posted = false; var self = this; if ($('#toggle-two')[0].checked == true) { posted = "posted" } rpc.query({ model: "account.move", method: "get_currency", }).then(function(result) { currency = result; }) rpc.query({ model: "account.move", method: "get_total_invoice_current_year", args: [posted], }).then(function(result) { $('#total_supplier_invoice_paid').hide(); $('#total_supplier_invoice').hide(); $('#total_customer_invoice_paid').hide(); $('#total_customer_invoice').hide(); $('#tot_invoice').hide(); $('#tot_supplier_inv').hide(); $('#total_supplier_invoice_paid_current_month').hide(); $('#total_supplier_invoice_current_month').hide(); $('#total_customer_invoice_paid_current_month').hide(); $('#total_customer_invoice_current_month').hide(); $('#tot_invoice_current_month').hide(); $('#tot_supplier_inv_current_month').hide(); $('#total_supplier_invoice_paid_current_year').empty(); $('#total_supplier_invoice_current_year').empty(); $('#total_customer_invoice_paid_current_year').empty(); $('#total_customer_invoice_current_year').empty(); $('#tot_invoice_current_year').empty(); $('#tot_supplier_inv_current_year').empty(); $('#total_supplier_invoice_paid_current_year').show(); $('#total_supplier_invoice_current_year').show(); $('#total_customer_invoice_paid_current_year').show(); $('#total_customer_invoice_current_year').show(); $('#tot_invoice_current_year').show(); $('#tot_supplier_inv_current_year').show(); var tot_invoice_current_year = result[0][0] var tot_credit_current_year = result[1][0] var tot_supplier_inv_current_year = result[2][0] var tot_supplier_refund_current_year = result[3][0] var tot_customer_invoice_paid_current_year = result[4][0] var tot_supplier_invoice_paid_current_year = result[5][0] var tot_customer_credit_paid_current_year = result[6][0] var tot_supplier_refund_paid_current_year = result[7][0] var customer_invoice_total_current_year = (tot_invoice_current_year - tot_credit_current_year).toFixed(2) var customer_invoice_paid_current_year = (tot_customer_invoice_paid_current_year - tot_customer_credit_paid_current_year).toFixed(2) var invoice_percentage_current_year = ((customer_invoice_total_current_year / customer_invoice_paid_current_year) * 100).toFixed(2) var supplier_invoice_total_current_year = (tot_supplier_inv_current_year - tot_supplier_refund_current_year).toFixed(2) var supplier_invoice_paid_current_year = (tot_supplier_invoice_paid_current_year - tot_supplier_refund_paid_current_year).toFixed(2) var supplier_percentage_current_year = ((supplier_invoice_total_current_year / supplier_invoice_paid_current_year) * 100).toFixed(2) $('#tot_supplier_inv_current_year').attr("value", supplier_invoice_paid_current_year); $('#tot_supplier_inv_current_year').attr("max", supplier_invoice_total_current_year); $('#tot_invoice_current_year').attr("value", customer_invoice_paid_current_year); $('#tot_invoice_current_year').attr("max", customer_invoice_total_current_year); customer_invoice_paid_current_year = self.format_currency(currency, customer_invoice_paid_current_year); customer_invoice_total_current_year = self.format_currency(currency, customer_invoice_total_current_year); supplier_invoice_paid_current_year = self.format_currency(currency, supplier_invoice_paid_current_year); supplier_invoice_total_current_year = self.format_currency(currency, supplier_invoice_total_current_year); $('#total_customer_invoice_paid_current_year').append(''); $('#total_customer_invoice_current_year').append('