123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- function widget_balance(widget) {
- "use strict";
- var model = openerp;
- widget.WidgetBalanceWidget = widget.Base.extend({
- template: 'WidgetBalance',
- events: {
- 'click .today': 'showToday',
- 'click .thisWeek': 'showThisWeek',
- 'click .thisMonth': 'showThisMonth',
- },
- init: function (parent) {
- this._super(parent, {
- width: 3,
- height: 2
- });
- },
- start: function () {
- var self = this;
- self.fetchInitial();
- },
- fetchInitial: function(){
- var self = this;
- self.$el.find('#morosidad').block({
- message: null,
- overlayCSS: {
- backgroundColor: '#FAFAFA'
- }
- });
- self.$el.find('.widget-content.widget-loading').css('display','flex');
- self.fetchAccountInvoice().then(function (AccountInvoice) {
- return AccountInvoice;
- }).then(function (AccountInvoice) {
- self.AccountInvoice = AccountInvoice;
- return self.fetchPosOrder();
- }).then(function(PosOrder) {
- self.PosOrder = PosOrder;
- return self.fetchResCompany();
- }).then(function(ResCompany) {
- self.ResCompany = ResCompany;
- return self.fetchResCurrecy();
- }).then(function(ResCurrecy) {
- self.ResCurrecy = ResCurrecy;
- return self.showThisMonth();
- });
- },
- // Usuario Logeado
- fetchCurrentUser: function() {
- var self = this;
- var ResUser = new model.web.Model('res.users');
- return ResUser.call('get_user', {
- context: new model.web.CompoundContext()
- });
- },
- // Lista de Graficos disponibles para el usuario
- fetchResUser: function(id) {
- var self = this;
- var defer = $.Deferred();
- var fields = ['id','name','chart_ids'];
- var domain = [['id','=',id]];
- var ResUser = new model.web.Model('res.users');
- ResUser.query(fields).filter(domain).all().then(function (results) {
- defer.resolve(results);
- });
- return defer;
- },
- // Obtener detalles de la lista de graficos
- fetchChartList: function(chart_ids) {
- var self = this;
- var defer = $.Deferred();
- var fields = ['id','name'];
- var domain = [['id','in',chart_ids]];
- var ChartList = new model.web.Model('chart.list');
- ChartList.query(fields).filter(domain).all().then(function (results) {
- defer.resolve(results);
- });
- return defer;
- },
- fetchAccountInvoice: function() {
- var self = this;
- var defer = $.Deferred();
- var fields = ['id', 'name', 'date_invoice', 'amount_total'];
- var domain = [['state', 'not in', ['draft','cancel']],['type','=','in_invoice']];
- var AccountInvoice = new model.web.Model('account.invoice');
- AccountInvoice.query(fields).filter(domain).all().then(function(results) {
- defer.resolve(results);
- });
- return defer;
- },
- fetchPosOrder: function() {
- var self = this;
- var defer = $.Deferred();
- var fields = ['id', 'name', 'date_order', 'amount_total'];
- var domain = [['state', 'not in', ['draft','cancel']]];
- var PosOrder = new model.web.Model('pos.order');
- PosOrder.query(fields).filter(domain).all().then(function(results) {
- defer.resolve(results);
- });
- return defer;
- },
- fetchResCompany: function() {
- var self = this;
- var defer = $.Deferred();
- var fields = ['id','name', 'currency_id'];
- var domain = [['id', '=', 1]];
- var ResCompany = new model.web.Model('res.company');
- ResCompany.query(fields).filter(domain).all().then(function (results) {
- defer.resolve(results);
- });
- return defer;
- },
- fetchResCurrecy : function(){
- var self = this;
- var defer = $.Deferred();
- var fields = ['id','name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
- var domain = [['active', '=', true]];
- var ResCurrecy = new model.web.Model('res.currency');
- ResCurrecy.query(fields).filter(domain).all().then(function(results) {
- defer.resolve(results);
- });
- return defer;
- },
- getResCurrency: function (id) {
- var self = this;
- return _.filter(self.ResCurrecy,function (item) {
- return item.id === id;
- })
- },
- // Facturas
- getTodayAccountInvoice:function() {
- var self = this;
- var date = moment().format('YYYY-MM-DD');
- return _.flatten(_.filter(self.AccountInvoice,function (inv) {
- return moment(inv.date_invoice).format('YYYY-MM-DD') === date;
- }));
- },
- getThisWeekAccountInvoice:function() {
- var self = this;
- var week = moment().week();
- return _.flatten(_.filter(self.AccountInvoice,function (inv) {
- return moment(inv.date_invoice).week() === week & moment(inv.date_invoice).format('YYYY')=== moment().format('YYYY');
- }));
- },
- getThisMonthAccountInvoice:function() {
- var self = this;
- return _.flatten(_.filter(self.AccountInvoice,function (inv) {
- return moment(inv.date_invoice).format('YYYY-MM')=== moment().format('YYYY-MM');
- }));
- },
- // POS Orders
-
- getTodayPosOrder:function() {
- var self = this;
- var date = moment().format('YYYY-MM-DD');
- return _.flatten(_.filter(self.PosOrder,function (inv) {
- return moment(inv.date_order).format('YYYY-MM-DD') === date;
- }));
- },
- getThisWeekPosOrder:function() {
- var self = this;
- var week = moment().week();
- return _.flatten(_.filter(self.PosOrder,function (inv) {
- return moment(inv.date_order).week() === week & moment(inv.date_order).format('YYYY')=== moment().format('YYYY');
- }));
- },
- getThisMonthPosOrder:function() {
- var self = this;
- return _.flatten(_.filter(self.PosOrder,function (inv) {
- return moment(inv.date_order).format('YYYY-MM')=== moment().format('YYYY-MM');
- }));
- },
- showToday: function () {
- var self = this;
- var amount_order = 0;
- var amount_invoice = 0;
- var balance = 0;
- var data = [];
- var order = self.getTodayPosOrder();
- var invoice = self.getTodayAccountInvoice();
- var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
- if(order.length > 0){
- amount_order = _.reduce(_.map(order, function (map) {
- return map.amount_total;
- }), function (memo, num) {
- return memo + num;
- });
- }
- if(invoice.length > 0){
- amount_invoice = _.reduce(_.map(invoice, function (map) {
- return map.amount_total;
- }), function (memo, num) {
- return memo + num;
- });
- }
- balance = amount_order - amount_invoice;
- self.$el.find('.widget-content.widget-loading').css('display','none');
- self.$el.find('.widget-content').find('a').text(accounting.formatMoney(balance, CurrencyBase.symbol, CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator))
- },
- showThisWeek: function () {
- var self = this;
- var amount_order = 0;
- var amount_invoice = 0;
- var balance = 0;
- var data = [];
- var order = self.getThisWeekPosOrder();
- var invoice = self.getThisWeekAccountInvoice();
- var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
- if(order.length > 0){
- amount_order = _.reduce(_.map(order, function (map) {
- return map.amount_total;
- }), function (memo, num) {
- return memo + num;
- });
- }
- if(invoice.length > 0){
- amount_invoice = _.reduce(_.map(invoice, function (map) {
- return map.amount_total;
- }), function (memo, num) {
- return memo + num;
- });
- }
- balance = amount_order - amount_invoice;
- self.$el.find('.widget-content.widget-loading').css('display','none');
- self.$el.find('.widget-content').find('a').text(accounting.formatMoney(balance, CurrencyBase.symbol, CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator))
- },
- showThisMonth: function () {
- var self = this;
- var amount_order = 0;
- var amount_invoice = 0;
- var balance = 0;
- var data = [];
- var order = self.getThisMonthPosOrder();
- var invoice = self.getThisMonthAccountInvoice();
- var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
- if(order.length > 0){
- amount_order = _.reduce(_.map(order, function (map) {
- return map.amount_total;
- }), function (memo, num) {
- return memo + num;
- });
- }
- if(invoice.length > 0){
- amount_invoice = _.reduce(_.map(invoice, function (map) {
- return map.amount_total;
- }), function (memo, num) {
- return memo + num;
- });
- }
- balance = amount_order - amount_invoice;
- self.$el.find('.widget-content.widget-loading').css('display','none');
- self.$el.find('.widget-content').find('a').text(accounting.formatMoney(balance, CurrencyBase.symbol, CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator))
- },
- });
- }
|