|
@@ -6,13 +6,13 @@ function chart_invoice (widget) {
|
|
|
widget.ChartInvoiceWidget = widget.Base.extend({
|
|
|
template: 'ChartInvoice',
|
|
|
data: [],
|
|
|
- countPosOrder: [],
|
|
|
- resPartner: [],
|
|
|
- modelId: [],
|
|
|
|
|
|
events: {
|
|
|
-
|
|
|
+ 'click .week': 'showWeeks',
|
|
|
+ 'click .days': 'showDays',
|
|
|
+ 'click .month': 'showMonths',
|
|
|
},
|
|
|
+
|
|
|
init: function (parent) {
|
|
|
this._super(parent, {
|
|
|
width: 6,
|
|
@@ -38,7 +38,7 @@ function chart_invoice (widget) {
|
|
|
return AccountInvoice;
|
|
|
}).then(function (AccountInvoice) {
|
|
|
self.AccountInvoice = AccountInvoice;
|
|
|
- return self.BuildChart();
|
|
|
+ return self.showWeeks();
|
|
|
});
|
|
|
},
|
|
|
|
|
@@ -78,7 +78,7 @@ function chart_invoice (widget) {
|
|
|
return defer;
|
|
|
},
|
|
|
|
|
|
- // Obtener Pedidos
|
|
|
+ // Obtener facturas
|
|
|
fecthAccountInvoice: function() {
|
|
|
var self = this;
|
|
|
var defer = $.Deferred();
|
|
@@ -91,7 +91,7 @@ function chart_invoice (widget) {
|
|
|
return defer;
|
|
|
},
|
|
|
|
|
|
- // Obtener facturas por cada proveedores
|
|
|
+ // Obtener facturas deproveedores por mes
|
|
|
getInAccountInvoice:function(mes) {
|
|
|
var self = this;
|
|
|
if (mes < 10){
|
|
@@ -104,7 +104,7 @@ function chart_invoice (widget) {
|
|
|
}));
|
|
|
},
|
|
|
|
|
|
- // Obtener facturas de clientes
|
|
|
+ // Obtener facturas de clientes por mes
|
|
|
getOutAccountInvoice:function(mes) {
|
|
|
var self = this;
|
|
|
if (mes < 10){
|
|
@@ -116,16 +116,83 @@ function chart_invoice (widget) {
|
|
|
return moment(inv.date_invoice).format('YYYY-MM') === fecha & inv.type === 'out_invoice';
|
|
|
}));
|
|
|
},
|
|
|
-
|
|
|
- // Generar el Ranking
|
|
|
- BuildChart: function() {
|
|
|
+
|
|
|
+ // Facturas de Proveedores por dias
|
|
|
+ getInDaysAccountInvoice:function(day) {
|
|
|
+ var self = this;
|
|
|
+ var date = moment().subtract(day, 'days').format('YYYY-MM-DD');
|
|
|
+ return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM-DD') === date & inv.type === 'in_invoice';
|
|
|
+ }));
|
|
|
+ },
|
|
|
+
|
|
|
+ // Facturas de Clientes por dias
|
|
|
+ getOutDaysAccountInvoice:function(day) {
|
|
|
+ var self = this;
|
|
|
+ var date = moment().subtract(day, 'days').format('YYYY-MM-DD');
|
|
|
+ return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM-DD') === date & inv.type === 'out_invoice';
|
|
|
+ }));
|
|
|
+ },
|
|
|
+
|
|
|
+ // Facturas de proveedor semana actual
|
|
|
+ getInWeekAccountInvoice:function(day) {
|
|
|
+ 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).isoWeekday() === day & inv.type === 'in_invoice';
|
|
|
+ }));
|
|
|
+ },
|
|
|
+
|
|
|
+ // Facturas de clientes semana Actual
|
|
|
+ getOutWeekAccountInvoice:function(day) {
|
|
|
+ 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).isoWeekday() === day & inv.type === 'out_invoice';
|
|
|
+ }));
|
|
|
+ },
|
|
|
+
|
|
|
+ // Mostrar grafico por dias
|
|
|
+ showDays: function() {
|
|
|
var self = this;
|
|
|
- // console.log(self);
|
|
|
+ var title = [];
|
|
|
var invoices;
|
|
|
- var mes = 0;
|
|
|
var dataIn = [];
|
|
|
var dataOut = [];
|
|
|
+ for (var i = 15; i >= 0; i--) {
|
|
|
+ invoices = self.getInDaysAccountInvoice(i);
|
|
|
+ var total = _.reduce(_.map(invoices,function(item) {
|
|
|
+ return item.amount_total;
|
|
|
+ }),function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ dataIn.push(total);
|
|
|
+ title.push(moment().subtract(i, 'days').format('DD / MM'));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (var i = 15; i >= 0; i--) {
|
|
|
+ invoices = self.getOutDaysAccountInvoice(i);
|
|
|
+ var total = _.reduce(_.map(invoices,function(item) {
|
|
|
+ return item.amount_total;
|
|
|
+ }),function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ dataOut.push(total);
|
|
|
+ }
|
|
|
+ self.$el.unblock();
|
|
|
+ self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
+ self.fetchChart(dataIn, dataOut, title);
|
|
|
+ },
|
|
|
|
|
|
+ // Mostrar por meses
|
|
|
+ showMonths: function() {
|
|
|
+ var self = this;
|
|
|
+ var title = ['Enero', 'Febrero', 'Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'];
|
|
|
+ var invoices;
|
|
|
+ var mes = 0;
|
|
|
+ var dataIn = [];
|
|
|
+ var dataOut = [];
|
|
|
for (var i = 1; i <= 12; i++) {
|
|
|
invoices = self.getInAccountInvoice(i);
|
|
|
var total = _.reduce(_.map(invoices,function(item) {
|
|
@@ -133,11 +200,8 @@ function chart_invoice (widget) {
|
|
|
}),function(memo, num) {
|
|
|
return memo + num;
|
|
|
},0);
|
|
|
- dataIn.push({
|
|
|
- amount_total: accounting.formatNumber(total,0,".",","),
|
|
|
- })
|
|
|
+ dataIn.push(total);
|
|
|
}
|
|
|
-
|
|
|
for (var i = 1; i <= 12; i++) {
|
|
|
invoices = self.getOutAccountInvoice(i);
|
|
|
var total = _.reduce(_.map(invoices,function(item) {
|
|
@@ -145,56 +209,51 @@ function chart_invoice (widget) {
|
|
|
}),function(memo, num) {
|
|
|
return memo + num;
|
|
|
},0);
|
|
|
- dataOut.push({
|
|
|
- amount_total: accounting.formatNumber(total,0,".",","),
|
|
|
- })
|
|
|
+ dataOut.push(total);
|
|
|
}
|
|
|
-
|
|
|
- // self.data = data;
|
|
|
self.$el.unblock();
|
|
|
self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
- self.fetchChart(dataIn, dataOut);
|
|
|
+ self.fetchChart(dataIn, dataOut, title);
|
|
|
},
|
|
|
|
|
|
- // Generar Grafico
|
|
|
- fetchChart: function (dataIn,dataOut) {
|
|
|
+ // Mostrar por semana Actual
|
|
|
+ showWeeks: function() {
|
|
|
var self = this;
|
|
|
- var label = ['Enero', 'Febrero', 'Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'];
|
|
|
- var bodyIn = [];
|
|
|
- var bodyOut = [];
|
|
|
- var item;
|
|
|
- var rank = 12;
|
|
|
-
|
|
|
- // InInvoice
|
|
|
- if (dataIn.length < rank && dataIn.length > 0){
|
|
|
- rank= ranking.length;
|
|
|
+ var title = ['Lunes', 'Martes', 'Miercoles','Jueves','Viernes','Sabado','Domingo'];
|
|
|
+ var invoices;
|
|
|
+ var mes = 0;
|
|
|
+ var dataIn = [];
|
|
|
+ var dataOut = [];
|
|
|
+ for (var i = 1; i <= 7; i++) {
|
|
|
+ invoices = self.getInWeekAccountInvoice(i);
|
|
|
+ var total = _.reduce(_.map(invoices,function(item) {
|
|
|
+ return item.amount_total;
|
|
|
+ }),function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ dataIn.push(total);
|
|
|
}
|
|
|
- for (var i = 0; i < rank; i++) {
|
|
|
- if (dataIn[i]) {
|
|
|
- item = dataIn[i];
|
|
|
- }
|
|
|
- if (dataIn.length === 0) {
|
|
|
- item = {};
|
|
|
- item.amount_total = 0;
|
|
|
- }
|
|
|
- bodyIn.push(item.amount_total);
|
|
|
+ for (var i = 1; i <= 7; i++) {
|
|
|
+ invoices = self.getOutWeekAccountInvoice(i);
|
|
|
+ var total = _.reduce(_.map(invoices,function(item) {
|
|
|
+ return item.amount_total;
|
|
|
+ }),function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ dataOut.push(total);
|
|
|
}
|
|
|
+ self.$el.unblock();
|
|
|
+ self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
+ self.fetchChart(dataIn, dataOut, title);
|
|
|
+ },
|
|
|
|
|
|
-
|
|
|
- // OutInvoice
|
|
|
- if (dataOut.length < rank && dataOut.length > 0){
|
|
|
- rank= ranking.length;
|
|
|
- }
|
|
|
- for (var i = 0; i < rank; i++) {
|
|
|
- if (dataOut[i]) {
|
|
|
- item = dataOut[i];
|
|
|
- }
|
|
|
- if (dataOut.length === 0) {
|
|
|
- item = {};
|
|
|
- item.amount_total = 0;
|
|
|
- }
|
|
|
- bodyOut.push(item.amount_total);
|
|
|
- }
|
|
|
+ // Generar Grafico
|
|
|
+ fetchChart: function (dataIn,dataOut,title) {
|
|
|
+ var self = this;
|
|
|
+ var label = title;
|
|
|
+ var bodyIn = dataIn;
|
|
|
+ var bodyOut = dataOut;
|
|
|
+ var item;
|
|
|
|
|
|
// Global method for setting Y axis number format.
|
|
|
Chart.scaleService.updateScaleDefaults('linear', {
|
|
@@ -215,7 +274,7 @@ function chart_invoice (widget) {
|
|
|
labels: label,
|
|
|
datasets: [
|
|
|
{
|
|
|
- label: 'Ingreso ',
|
|
|
+ label: 'Clientes ',
|
|
|
data: bodyOut,
|
|
|
backgroundColor: '#e3f2fd',
|
|
|
borderColor: '#64b5f6',
|
|
@@ -223,7 +282,7 @@ function chart_invoice (widget) {
|
|
|
fill: false,
|
|
|
},
|
|
|
{
|
|
|
- label: 'Egreso ',
|
|
|
+ label: 'Proveedores ',
|
|
|
data: bodyIn,
|
|
|
backgroundColor: '#c8e6c9',
|
|
|
borderColor: '#66bb6a',
|
|
@@ -244,7 +303,7 @@ function chart_invoice (widget) {
|
|
|
layout: {
|
|
|
padding: {
|
|
|
top: 5,
|
|
|
- bottom: 0,
|
|
|
+ bottom: 15,
|
|
|
left : 0,
|
|
|
rigth: 0,
|
|
|
}
|