|
@@ -10,6 +10,7 @@ function chart_purchase_expense (widget) {
|
|
|
events: {
|
|
|
'click .month': 'showMonth',
|
|
|
'click .week': 'showWeek',
|
|
|
+ 'click .days': 'showDays',
|
|
|
},
|
|
|
|
|
|
init: function (parent) {
|
|
@@ -92,6 +93,7 @@ function chart_purchase_expense (widget) {
|
|
|
return defer;
|
|
|
},
|
|
|
|
|
|
+ // Facturas de proveedor - Meses
|
|
|
getMonthAccountInvoicePurchase:function(month) {
|
|
|
var self = this;
|
|
|
if (month < 10){
|
|
@@ -116,6 +118,7 @@ function chart_purchase_expense (widget) {
|
|
|
}));
|
|
|
},
|
|
|
|
|
|
+ // Facturas de proveedor - Semana Actual
|
|
|
getWeekAccountInvoicePurchase:function(day) {
|
|
|
var self = this;
|
|
|
var week = moment().week();
|
|
@@ -131,11 +134,27 @@ function chart_purchase_expense (widget) {
|
|
|
return moment(inv.date_invoice).week() === week & inv.origin === false & moment(inv.date_invoice).isoWeekday() === day;
|
|
|
}));
|
|
|
},
|
|
|
+
|
|
|
+ // Facturas de proveedor - 15 dias
|
|
|
+ getDaysAccountInvoicePurchase: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.origin !== false;
|
|
|
+ }));
|
|
|
+ },
|
|
|
+ getDaysAccountInvoiceExpense: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.origin === false;
|
|
|
+ }));
|
|
|
+ },
|
|
|
|
|
|
showMonth: function() {
|
|
|
var self = this;
|
|
|
var invoices;
|
|
|
- var mes = 0;
|
|
|
+ var title = ['Enero', 'Febrero', 'Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'];
|
|
|
var dataPurchase = [];
|
|
|
var dataExpense = [];
|
|
|
|
|
@@ -146,9 +165,7 @@ function chart_purchase_expense (widget) {
|
|
|
}),function(memo, num) {
|
|
|
return memo + num;
|
|
|
},0);
|
|
|
- dataPurchase.push({
|
|
|
- amount_total: accounting.formatNumber(total,0,".",","),
|
|
|
- })
|
|
|
+ dataPurchase.push(total)
|
|
|
}
|
|
|
|
|
|
for (var i = 1; i <= 12; i++) {
|
|
@@ -158,20 +175,18 @@ function chart_purchase_expense (widget) {
|
|
|
}),function(memo, num) {
|
|
|
return memo + num;
|
|
|
},0);
|
|
|
- dataExpense.push({
|
|
|
- amount_total: accounting.formatNumber(total,0,".",","),
|
|
|
- })
|
|
|
+ dataExpense.push(total)
|
|
|
}
|
|
|
|
|
|
self.$el.unblock();
|
|
|
self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
- self.fetchMonthChart(dataPurchase, dataExpense);
|
|
|
+ self.fetchChart(dataPurchase, dataExpense, title);
|
|
|
},
|
|
|
|
|
|
showWeek: function() {
|
|
|
var self = this;
|
|
|
var invoices;
|
|
|
- var mes = 0;
|
|
|
+ var title = ['Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo'];
|
|
|
var dataPurchase = [];
|
|
|
var dataExpense = [];
|
|
|
|
|
@@ -182,9 +197,7 @@ function chart_purchase_expense (widget) {
|
|
|
}),function(memo, num) {
|
|
|
return memo + num;
|
|
|
},0);
|
|
|
- dataPurchase.push({
|
|
|
- amount_total: accounting.formatNumber(total,0,".",","),
|
|
|
- })
|
|
|
+ dataPurchase.push(total);
|
|
|
}
|
|
|
|
|
|
for (var i = 1; i <= 7; i++) {
|
|
@@ -194,144 +207,50 @@ function chart_purchase_expense (widget) {
|
|
|
}),function(memo, num) {
|
|
|
return memo + num;
|
|
|
},0);
|
|
|
- dataExpense.push({
|
|
|
- amount_total: accounting.formatNumber(total,0,".",","),
|
|
|
- })
|
|
|
+ dataExpense.push(total);
|
|
|
}
|
|
|
|
|
|
self.$el.unblock();
|
|
|
self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
- self.fetchWeekChart(dataPurchase, dataExpense);
|
|
|
+ self.fetchChart(dataPurchase, dataExpense, title);
|
|
|
},
|
|
|
|
|
|
- fetchMonthChart: function (dataPurchase,dataExpense) {
|
|
|
+ showDays: function() {
|
|
|
var self = this;
|
|
|
- var label = ['Enero', 'Febrero', 'Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'];
|
|
|
- var bodyPurchase = [];
|
|
|
- var bodyExpense = [];
|
|
|
- var item;
|
|
|
- var rank = 12;
|
|
|
-
|
|
|
- if (dataPurchase.length < rank && dataPurchase.length > 0){
|
|
|
- rank= ranking.length;
|
|
|
- }
|
|
|
- for (var i = 0; i < rank; i++) {
|
|
|
- if (dataPurchase[i]) {
|
|
|
- item = dataPurchase[i];
|
|
|
- }
|
|
|
- if (dataPurchase.length === 0) {
|
|
|
- item = {};
|
|
|
- item.amount_total = 0;
|
|
|
- }
|
|
|
- bodyPurchase.push(item.amount_total);
|
|
|
+ var title = [];
|
|
|
+ var invoices;
|
|
|
+ var dataPurchase = [];
|
|
|
+ var dataExpense = [];
|
|
|
+ for (var i = 15; i >= 0; i--) {
|
|
|
+ invoices = self.getDaysAccountInvoicePurchase(i);
|
|
|
+ var total = _.reduce(_.map(invoices,function(item) {
|
|
|
+ return item.amount_total;
|
|
|
+ }),function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ dataPurchase.push(total);
|
|
|
+ title.push(moment().subtract(i, 'days').format('DD / MM'));
|
|
|
}
|
|
|
-
|
|
|
- if (dataExpense.length < rank && dataExpense.length > 0){
|
|
|
- rank= ranking.length;
|
|
|
+
|
|
|
+ for (var i = 15; i >= 0; i--) {
|
|
|
+ invoices = self.getDaysAccountInvoiceExpense(i);
|
|
|
+ var total = _.reduce(_.map(invoices,function(item) {
|
|
|
+ return item.amount_total;
|
|
|
+ }),function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ dataExpense.push(total);
|
|
|
}
|
|
|
- for (var i = 0; i < rank; i++) {
|
|
|
- if (dataExpense[i]) {
|
|
|
- item = dataExpense[i];
|
|
|
- }
|
|
|
- if (dataExpense.length === 0) {
|
|
|
- item = {};
|
|
|
- item.amount_total = 0;
|
|
|
- }
|
|
|
- bodyExpense.push(item.amount_total);
|
|
|
- }
|
|
|
-
|
|
|
- // Global method for setting Y axis number format.
|
|
|
- Chart.scaleService.updateScaleDefaults('linear', {
|
|
|
- ticks: {
|
|
|
- callback: function(tick) {
|
|
|
- return tick.toLocaleString('de-DE');
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- Chart.defaults.global.tooltips.callbacks.label = function(tooltipItem, data) {
|
|
|
- var dataset = data.datasets[tooltipItem.datasetIndex];
|
|
|
- var datasetLabel = dataset.label || '';
|
|
|
- return datasetLabel + dataset.data[tooltipItem.index].toLocaleString('de-DE');
|
|
|
- };
|
|
|
- var chart = new Chart(this.$el.find(".widget-content").find('canvas'), {
|
|
|
- type: 'line',
|
|
|
- data: {
|
|
|
- labels: label,
|
|
|
- datasets: [
|
|
|
- {
|
|
|
- label: 'Compras ',
|
|
|
- data: bodyPurchase,
|
|
|
- backgroundColor: '#e3f2fd',
|
|
|
- borderColor: '#64b5f6',
|
|
|
- borderWidth: 2,
|
|
|
- fill: false,
|
|
|
- },
|
|
|
- {
|
|
|
- label: 'Gastos ',
|
|
|
- data: bodyExpense,
|
|
|
- backgroundColor: '#c8e6c9',
|
|
|
- borderColor: '#66bb6a',
|
|
|
- borderWidth: 2,
|
|
|
- fill: false,
|
|
|
- }
|
|
|
- ]
|
|
|
- },
|
|
|
- options: {
|
|
|
- responsive: true,
|
|
|
- title: {
|
|
|
- display: true,
|
|
|
- },
|
|
|
- hover: {
|
|
|
- mode: 'nearest',
|
|
|
- intersect: true
|
|
|
- },
|
|
|
- layout: {
|
|
|
- padding: {
|
|
|
- top: 0,
|
|
|
- bottom: 0,
|
|
|
- left : 0,
|
|
|
- rigth: 0,
|
|
|
- }
|
|
|
- },
|
|
|
- }
|
|
|
- });
|
|
|
+ self.$el.unblock();
|
|
|
+ self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
+ self.fetchChart(dataPurchase, dataExpense, title);
|
|
|
},
|
|
|
|
|
|
- fetchWeekChart: function (dataPurchase,dataExpense) {
|
|
|
+ fetchChart: function (dataPurchase, dataExpense, title) {
|
|
|
var self = this;
|
|
|
- var label = ['Lunes', 'Martes', 'Miercoles','Jueves','Viernes','Sabado','Domingo'];
|
|
|
- var bodyPurchase = [];
|
|
|
- var bodyExpense = [];
|
|
|
- var item;
|
|
|
- var rank = 7;
|
|
|
-
|
|
|
- if (dataPurchase.length < rank && dataPurchase.length > 0){
|
|
|
- rank= ranking.length;
|
|
|
- }
|
|
|
- for (var i = 0; i < rank; i++) {
|
|
|
- if (dataPurchase[i]) {
|
|
|
- item = dataPurchase[i];
|
|
|
- }
|
|
|
- if (dataPurchase.length === 0) {
|
|
|
- item = {};
|
|
|
- item.amount_total = 0;
|
|
|
- }
|
|
|
- bodyPurchase.push(item.amount_total);
|
|
|
- }
|
|
|
-
|
|
|
- if (dataExpense.length < rank && dataExpense.length > 0){
|
|
|
- rank= ranking.length;
|
|
|
- }
|
|
|
- for (var i = 0; i < rank; i++) {
|
|
|
- if (dataExpense[i]) {
|
|
|
- item = dataExpense[i];
|
|
|
- }
|
|
|
- if (dataExpense.length === 0) {
|
|
|
- item = {};
|
|
|
- item.amount_total = 0;
|
|
|
- }
|
|
|
- bodyExpense.push(item.amount_total);
|
|
|
- }
|
|
|
+ var label = title;
|
|
|
+ var bodyPurchase = dataPurchase;
|
|
|
+ var bodyExpense = dataExpense;
|
|
|
|
|
|
// Global method for setting Y axis number format.
|
|
|
Chart.scaleService.updateScaleDefaults('linear', {
|
|
@@ -380,8 +299,8 @@ function chart_purchase_expense (widget) {
|
|
|
},
|
|
|
layout: {
|
|
|
padding: {
|
|
|
- top: 0,
|
|
|
- bottom: 15,
|
|
|
+ top: 5,
|
|
|
+ bottom: 20,
|
|
|
left : 0,
|
|
|
rigth: 0,
|
|
|
}
|