Newer
Older
odoo.define('lefilament_tdb.dashboard_year', function (require) {
var core = require('web.core');
var formats = require('web.formats');
var Model = require('web.Model');
var session = require('web.session');
var Widget = require('web.Widget');
var QWeb = core.qweb;
var _t = core._t;
var _lt = core._lt;
var YearDashboardView = Widget.extend({
template: 'YearDashboard',

Benjamin
a validé
events: {
'click .card': function() {
this.mychart.reflow();
},
'click #facture_non_encaisse': function() {
this.facture();
},
'click #commandes': function() {
this.commandes();
},

Benjamin
a validé
},
init: function() {
var result = this._super.apply(this, arguments);
return result;
},
willStart: function() {
var deferred = new jQuery.Deferred();
var self = this;
this.values = {};
this.progess = 0;
var dash_model = new Model('lefilament.dashboard');
dash_model.call('retrieve_datas_dashboard')
.then(function(results) {
self.values = results;
self.progress = results.facture / results.target;
deferred.resolve();
});
return jQuery.when(this._super.apply(this, arguments),deferred);
},
start: function() {
var pfact = (this.values.facture / this.values.target * 100).toFixed(0);
var pcomm = (this.values.commandes / this.values.target * 100).toFixed(0);
var ppipe_win = (this.values.pipe_win / this.values.target * 100).toFixed(0);
var ppipe_to_win = (this.values.pipe_to_win / this.values.target * 100).toFixed(0);
var ptarg = 100-pfact-pcomm-ppipe_win-ppipe_to_win;
var pfact2 = (this.values.facture);
var pcomm2 = (this.values.commandes);
var ppipe2_win = (this.values.pipe_win);
var ppipe2_to_win = (this.values.pipe_to_win);
var ptarg2 = this.values.target -pfact2-pcomm2-ppipe2_to_win-ppipe2_win;
var hchart = this.$el.find('#hchart')[0];
Highcharts.setOptions({ colors: ['#8ED8A2', '#F6DCA2', '#F6CCA2', '#F6ACA2', '#eee'], });
this.mychart = new Highcharts.chart({
chart: {
renderTo: hchart,
type: 'pie',
margin: 0
},
title: {
text: '<span class="ca_target">'+

Benjamin
a validé
self.values.target.toLocaleString('fr', { maximumFractionDigits: 0 }) + ' € </span><br />'
+'facturé '+ pfact + ' %<br />'
+'commandes '+ pcomm + ' %<br />'
+'gagné '+ ppipe_win + ' %<br />'
+'pipe '+ ppipe_to_win + ' %',
align: 'center',
verticalAlign: 'middle',
style: { 'color': '#73879C', 'font-size': '11px' },
},
plotOptions: {
pie: {
slicedOffset: 0,
size: '100%',
dataLabels: {
enabled: false
}
},
series: {
states: {
hover: {
enabled: false
}
}
}
},
tooltip: {
pointFormat: '<p class="point"><span class="point_percent">{point.percentage:.0f}% </span><br/> {point.y} €</p>',
backgroundColor: "rgba(255,255,255,0.85)",
borderColor: null,
borderRadius: 0,
borderWidth: 0,
useHTML: true,
shadow: false,

Benjamin
a validé
},
data: [ ['Facturé', pfact2], ['Commandes', pcomm2], ['Gagné', ppipe2_win], ['Pipe', ppipe2_to_win], ['To Do', ptarg2], ],
},
render_monetary: function(value) {
value = value.toLocaleString('fr', { maximumFractionDigits: 0 }) + ' €';
return value;
},
render_date: function(value) {
var dateFormat = new Date(value);
var new_value = moment(dateFormat).format('Do MMM YYYY');
return new_value;
},

Benjamin
a validé
if (value >= 0)
value = '<span class="positive">'+value.toLocaleString('fr', { maximumFractionDigits: 0 }) + ' €</span>';
else
value = '<span class="negative">'+value.toLocaleString('fr', { maximumFractionDigits: 0 }) + ' €</span>';
return value;
},
facture: function() {
var self = this;
var context = { 'user_id': this.session.uid, }
var action = ({
type: 'ir.actions.act_window',
res_model: 'account.invoice',
view_type: 'form',
view_mode: 'tree,form',
views: [[false, 'list'], [false, 'form']],
domain: [['state','=','open'],['type','=','out_invoice']],
target:'current',
name: 'Factures en cours',
context: context
})
this.do_action(action);
},
commandes: function() {
var self = this;
var context = { 'user_id': this.session.uid, }
var action = ({
type: 'ir.actions.act_window',
res_model: 'sale.order',
view_type: 'form',
view_mode: 'tree,form',
views: [[false, 'list'], [false, 'form']],
domain: [['invoice_status','=','to invoice']],
target:'current',
name: 'Commandes en cours',
context: context
})

Benjamin
a validé
},