|
@@ -0,0 +1,631 @@
|
|
|
+function report_sale_vendor (reporting){
|
|
|
+
|
|
|
+ var instance = openerp;
|
|
|
+
|
|
|
+ reporting.ReportSaleVendorWidget = reporting.Base.extend({
|
|
|
+ template :'ReportSaleVendor',
|
|
|
+ accountVoucher:[],
|
|
|
+ resCurrency:[],
|
|
|
+ accountJournal:[],
|
|
|
+ dataVoucher:[],
|
|
|
+ currencyRate:[],
|
|
|
+ resCompany:[],
|
|
|
+ modules:[],
|
|
|
+
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click #X' : 'fectSearch',
|
|
|
+ 'click #A' : 'fectSearch',
|
|
|
+ 'click #B' : 'fectSearch',
|
|
|
+ 'click #C' : 'fectSearch',
|
|
|
+ 'click #D' : 'fectSearch',
|
|
|
+ 'click #Z' : 'fectSearch',
|
|
|
+
|
|
|
+ 'click #Y' : 'fectSearch',
|
|
|
+ 'change #current-journal': 'fectSearch',
|
|
|
+ 'change #current-warehouse': 'fectSearch',
|
|
|
+ 'change #current-currency': 'fectSearch',
|
|
|
+ 'change #from' : 'fectSearch',
|
|
|
+ 'change #to': 'fectSearch',
|
|
|
+ 'click #volver_btn': 'volver',
|
|
|
+ },
|
|
|
+
|
|
|
+ init:function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+ start: function(){
|
|
|
+ var self = this;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable({data : self.dataVoucher});
|
|
|
+ self.fecthFecha();
|
|
|
+ self.fecthInitial();
|
|
|
+ },
|
|
|
+ // Redirecionar
|
|
|
+ renderReport: function () {
|
|
|
+ var self = this;
|
|
|
+
|
|
|
+ var container = this.$el.closest('.oe_form_sheet.oe_form_sheet_width');
|
|
|
+ this.$el.closest('.report_view').remove();
|
|
|
+ container.find('.report_view').show({
|
|
|
+ effect: 'fade',
|
|
|
+ duration: 200,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Verificar el modelo
|
|
|
+ checkModel : function(model){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.modules,function(item){return item.name === model});
|
|
|
+ },
|
|
|
+ // Lanzar el mensaje
|
|
|
+ showMensaje : function(modelos){
|
|
|
+ var self = this;
|
|
|
+ $("#dialog" ).dialog({
|
|
|
+ autoOpen: true,
|
|
|
+ resizable: false,
|
|
|
+ modal: true,
|
|
|
+ title: 'Atención',
|
|
|
+ width: 500,
|
|
|
+ open: function() {
|
|
|
+ $(this).html('Reporte in-disponible, contacte con el administrador del sistema ref : '+modelos);
|
|
|
+ },
|
|
|
+ show: {
|
|
|
+ effect: "fade",
|
|
|
+ duration: 200
|
|
|
+ },
|
|
|
+ hide: {
|
|
|
+ effect: "fade",
|
|
|
+ duration: 200
|
|
|
+ },
|
|
|
+ buttons: {
|
|
|
+ Aceptar: function() {
|
|
|
+ $(this).dialog('close');
|
|
|
+ self.renderReport()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return
|
|
|
+ },
|
|
|
+
|
|
|
+ // Metodo inicial
|
|
|
+ fecthInitial: function(){
|
|
|
+ var self = this;
|
|
|
+ self.fecthIrModuleModule().then(function(modules){
|
|
|
+ self.modules = modules;
|
|
|
+ return modules;
|
|
|
+ }).then(function(modules){
|
|
|
+ return self.fecthJournalStore();
|
|
|
+ }).then(function(accountJournal){
|
|
|
+ self.accountJournal=accountJournal;
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todas las SUC.</option>');
|
|
|
+ _.each(accountJournal,function(item){
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ return self.fetchResCurrency();
|
|
|
+ }).then(function(ResCurrency){
|
|
|
+ self.ResCurrency = ResCurrency;
|
|
|
+ return self.fecthCompanyCurrency();
|
|
|
+ }).then(function(ResCompany){
|
|
|
+ self.ResCompany = ResCompany;
|
|
|
+ return self.fecthCurrencyRate();
|
|
|
+ }).then(function(currencyRate){
|
|
|
+ self.currencyRate =currencyRate;
|
|
|
+ return self.fecthVoucher();
|
|
|
+ }).then(function(accountVoucher){
|
|
|
+ self.accountVoucher=accountVoucher;
|
|
|
+ return self.fetchInvoiceV2();
|
|
|
+ }).then(function (invoices){
|
|
|
+ self.invoices = invoices;
|
|
|
+ return self.fetchWarehouse();
|
|
|
+ }).then(function(WareHouse){
|
|
|
+ self.WareHouse=WareHouse;
|
|
|
+ self.$el.find('#current-warehouse').append('<option value="9999999">Todos los vendedores</option>');
|
|
|
+ _.each(WareHouse,function(item){
|
|
|
+ self.$el.find('#current-warehouse').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ return self.fecthDataVoucher(self.accountVoucher,self.accountJournal);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // Fecha
|
|
|
+ fecthFecha: function() {
|
|
|
+ var to;
|
|
|
+ var dateFormat1 = "mm/dd/yy",
|
|
|
+ from = $( "#from" )
|
|
|
+ .datepicker({
|
|
|
+ dateFormat: "dd/mm/yy",
|
|
|
+ changeMonth: true,
|
|
|
+ numberOfMonths: 1,
|
|
|
+ })
|
|
|
+ .on( "change", function() {
|
|
|
+ to.datepicker( "option", "minDate", getDate(this), "dd/mm/yyyy");
|
|
|
+ });
|
|
|
+ to = $( "#to" ).datepicker({
|
|
|
+ dateFormat: "dd/mm/yy",
|
|
|
+ defaultDate: "+7d",
|
|
|
+ changeMonth: true,
|
|
|
+ numberOfMonths: 1,
|
|
|
+ })
|
|
|
+ .on( "change", function() {
|
|
|
+ from.datepicker( "option", "maxDate", getDate(this));
|
|
|
+ });
|
|
|
+
|
|
|
+ function getDate( element ) {
|
|
|
+ var fechaSel =element.value.split('/');
|
|
|
+ var date;
|
|
|
+ try {
|
|
|
+ date = $.datepicker.parseDate( dateFormat1, (fechaSel[1]+"/"+fechaSel[0]+"/"+fechaSel[2]));
|
|
|
+ } catch( error ) {
|
|
|
+ date = null;
|
|
|
+ }
|
|
|
+ return date;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // Modelos instalados
|
|
|
+ fecthIrModuleModule: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['name','id'];
|
|
|
+ var domain=[['state','=','installed']];
|
|
|
+ var irModule = new instance.web.Model('ir.module.module');
|
|
|
+
|
|
|
+ irModule.query(fields).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Journal
|
|
|
+ fecthJournalStore: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var modules = _.flatten(self.checkModel('multi_store'));
|
|
|
+
|
|
|
+ if (modules.length <= 0){
|
|
|
+ self.showMensaje('multi_store');
|
|
|
+ return defer;
|
|
|
+ }
|
|
|
+
|
|
|
+ var journal = new instance.web.Model('res.store');
|
|
|
+ var field=['id', 'name','journal_ids'];
|
|
|
+
|
|
|
+ journal.query(field).order_by('id').all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // company_curency
|
|
|
+ fecthCompanyCurrency: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var field=['id','name', 'currency_id', 'vat'];
|
|
|
+ var domain = [['id', '=', self.session.company_id]];
|
|
|
+ var ResCompany = new instance.web.Model('res.company');
|
|
|
+ ResCompany.query(field).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Moneda
|
|
|
+ fetchResCurrency:function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var ResCurrency = new instance.web.Model('res.currency');
|
|
|
+ var fields = ['id','name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
|
|
|
+ var domain = [['active','=', true]];
|
|
|
+ ResCurrency.query(fields).filter(domain).order_by('id').all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Cambio de la moneda
|
|
|
+ fecthCurrencyRate:function(){
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency_Rate = new instance.web.Model('res.currency.rate');
|
|
|
+ var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
|
|
|
+ var domain = [['currency_id', 'in', [166 , 20, 7, 3]]];
|
|
|
+ currency_Rate.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Invoice (FACTURAS)
|
|
|
+ fetchInvoiceV2: function () {
|
|
|
+ var self = this;
|
|
|
+ var filter ="[['state', 'in',['open','paid']],['type', '=', 'out_invoice']";
|
|
|
+ var journal_ids = _.flatten(_.map(self.AccountJournal, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ if (journal_ids){
|
|
|
+ filter=filter.concat(",['journal_id', 'in',["+journal_ids+"]]");
|
|
|
+ }
|
|
|
+ filter=filter.concat("]");
|
|
|
+ var field =['id', 'type', 'number', 'origin', 'reference', 'state', 'journal_id', 'currency_id', 'user_id','date_invoice','amount_total','amount_tax','amount_untaxed','partner_id'];
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var invoices = new instance.web.Model('account.invoice');
|
|
|
+ invoices.query(field).filter(filter).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ // Voucher -
|
|
|
+ fecthVoucher: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var voucher = new instance.web.Model('sale.order');
|
|
|
+ var filter = [['state', 'in', ['progress','done']],['shipped', '=', true]];
|
|
|
+ // var warehouse_ids = _.flatten(_.map(self.WareHouse, function (item) {
|
|
|
+ // return item.id;
|
|
|
+ // }));
|
|
|
+ // if (warehouse_ids){
|
|
|
+ // filter=filter.concat(",['warehouse_id', 'in',["+ warehouse_ids+"]]");
|
|
|
+ // }
|
|
|
+ // filter=filter.concat("]");
|
|
|
+ var field =['id', 'number', 'name','origin', 'state', 'type_id', 'warehouse_id', 'currency_id', 'amount_total', 'date_order', 'shipped'];
|
|
|
+ voucher.query(field).filter(filter).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchWarehouse: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var field=['id', 'name'];
|
|
|
+ var WareHouse = new instance.web.Model('stock.warehouse');
|
|
|
+ WareHouse.query(field).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ getResCurrency: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCurrency,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ getSaleOrder: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.accountVoucher,function (item) {
|
|
|
+ return item.number === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // Verificar Valor null
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor ="";
|
|
|
+ if (dato){
|
|
|
+ valor=dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+
|
|
|
+ // Join object
|
|
|
+ fecthDataVoucher:function(objVoucher,objJournal){
|
|
|
+ var self=this;
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ var item;
|
|
|
+ var journal;
|
|
|
+ var voucherLine;
|
|
|
+ var voucherItem;//Contenido del voucher
|
|
|
+ var sumaAmount; //Guardar la suma de los pagos
|
|
|
+ var voucherObject=[];
|
|
|
+ var voucherObjectItem=[];
|
|
|
+ var sale = [];
|
|
|
+ var cutrrencyRate; //Valor del cambio
|
|
|
+ var total=0;
|
|
|
+ var sumaAmountTot=0;
|
|
|
+ var itemVoucher;
|
|
|
+
|
|
|
+ for (var i = 0; i < objJournal.length; i++) {
|
|
|
+ voucherObjectItem=[];
|
|
|
+ journal=objJournal[i];
|
|
|
+
|
|
|
+ for (var f = 0; f < journal.journal_ids.length; f++) {
|
|
|
+ voucherLine = journal.journal_ids[f];
|
|
|
+ voucherItem = self.getVoucherjournal(objVoucher,voucherLine)
|
|
|
+
|
|
|
+ // sale = self.getSaleOrder(voucherItem.name);
|
|
|
+ // console.log(sale);
|
|
|
+
|
|
|
+ if (voucherItem.length > 0){
|
|
|
+ sumaAmount=_.reduce(_.map(voucherItem,function(item){return item.amount_total}), function(memo, num){ return memo + num; },0);
|
|
|
+ itemVoucher = voucherItem.shift();
|
|
|
+ var currency = self.getResCurrency(itemVoucher.currency_id[0]).shift();
|
|
|
+
|
|
|
+ // Guardar item
|
|
|
+ voucherObjectItem.push({journal : " ",
|
|
|
+ method :self.valorNull(itemVoucher.warehouse_id[1]),
|
|
|
+ amount : accounting.formatNumber(self.valorNull(sumaAmount * (CurrencyBase.rate_silent/currency.rate_silent)),0, ".", ","),
|
|
|
+ currency_name : self.valorNull(itemVoucher.currency_id[0]),
|
|
|
+ currency_id : self.valorNull(itemVoucher.currency_id[1]),
|
|
|
+ amountBase : self.valorNull(sumaAmount * (CurrencyBase.rate_silent/currency.rate_silent)),
|
|
|
+ journal_id: journal.id,
|
|
|
+ journal_name: journal.name,
|
|
|
+ warehouse_id: itemVoucher.warehouse_id[0],
|
|
|
+ graficar: false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (voucherObjectItem.length > 0){
|
|
|
+ var company = _.map(self.ResCompany, function (map) {
|
|
|
+ return map.currency_id[1];
|
|
|
+ });
|
|
|
+
|
|
|
+ sumaAmountTot=_.reduce(_.map(voucherObjectItem,function(item){return (item.amountBase)}), function(memo, num){ return memo + num; },0);
|
|
|
+ total=total+sumaAmountTot;
|
|
|
+ voucherObjectItem.push({journal : " ",
|
|
|
+ method :"Total " + company,
|
|
|
+ amount : accounting.formatNumber(self.valorNull(sumaAmountTot),0, ".", ","),
|
|
|
+ currency_name : "",
|
|
|
+ currency_id : "",
|
|
|
+ rate : "cutrrencyRate.rate",
|
|
|
+ amountBase:"",
|
|
|
+ journal_id: journal.id,
|
|
|
+ journal_name: journal.name,
|
|
|
+ graficar: true
|
|
|
+ });
|
|
|
+
|
|
|
+ // General la Cabezera
|
|
|
+ voucherObjectItem.unshift({ journal : journal.name, method :"", amount :"", voucherLine_name :"", voucherLine_id :"",rate :"",amountBase :"", warehouse_id:"",journal_id:journal.id, journal_name:journal.name, graficar:false});
|
|
|
+ // Generar Objeto Principal
|
|
|
+ voucherObject=voucherObject.concat(voucherObjectItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (voucherObject.length >0){
|
|
|
+ voucherObject.push({journal : " Total de Egreso",
|
|
|
+ method :"",
|
|
|
+ amount : accounting.formatNumber(self.valorNull(total),0, ".", ","),
|
|
|
+ currency_name : "",
|
|
|
+ currency_id : "",
|
|
|
+ rate : "",
|
|
|
+ amountBase:"",
|
|
|
+ journal_id: journal.id,
|
|
|
+ journal_name: journal.name,
|
|
|
+ warehouse_id:"",
|
|
|
+ graficar: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+ self.loadTable(voucherObject);
|
|
|
+ self.content = voucherObject;
|
|
|
+ },
|
|
|
+ // Obtener Voucher
|
|
|
+ getVoucherjournal:function(objVoucher,journal_id){
|
|
|
+ return _.map(_.filter(objVoucher, function (inv){return inv.warehouse_id[0] === journal_id}),function(item){return item});
|
|
|
+ },
|
|
|
+ // Obtener Cambio
|
|
|
+ // getCutrrencyRate: function(currency_id){
|
|
|
+ // return _.filter(this.currencyRate, function(rate){return rate.currency_id[0] === currency_id}).shift();
|
|
|
+ // },
|
|
|
+ // Generar la tabla
|
|
|
+ loadTable:function(rowsTable){
|
|
|
+ this.dataVoucher=rowsTable;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable('load' ,rowsTable);
|
|
|
+ },
|
|
|
+ // Buscar
|
|
|
+ fectSearch: function(){
|
|
|
+ var self = this;
|
|
|
+ var today = moment().format('YYYY-MM-DD');
|
|
|
+ var yesterday = moment().add(-1, 'days').format('YYYY-MM-DD');
|
|
|
+ var month = moment().format('YYYY-MM');
|
|
|
+ var last_month = moment().add(-1, 'months').format('YYYY-MM');
|
|
|
+ var desde =this.$el.find('#from').val();
|
|
|
+ var hasta =this.$el.find('#to').val();
|
|
|
+ var journal =this.$el.find('#current-journal').val();
|
|
|
+ var currency =this.$el.find('#current-currency').val();
|
|
|
+ var newJournal= self.accountJournal; //copia del Diario
|
|
|
+ var newVoucher= self.accountVoucher; //copia del Vouacher
|
|
|
+
|
|
|
+ if ($('#A').is(":checked")){
|
|
|
+ newVoucher = _.filter(newVoucher, function (inv){
|
|
|
+ return inv.date_order == today;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#B').is(":checked")){
|
|
|
+ newVoucher = _.filter(newVoucher, function (inv){
|
|
|
+ return moment(inv.date_order).format('YYYY-MM-DD') == yesterday;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#C').is(":checked")){
|
|
|
+ newVoucher = _.filter(newVoucher, function (inv){
|
|
|
+ return moment(inv.date_order).format('YYYY-MM') == month;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#D').is(":checked")){
|
|
|
+ newVoucher = _.filter(newVoucher, function (inv){
|
|
|
+ return moment(inv.date_order).format('YYYY-MM') == last_month;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($('#Z').is(":checked")){
|
|
|
+ $('#datepicker').css('display','block');
|
|
|
+ if (desde.length > 0){
|
|
|
+ var date= desde.split('/');
|
|
|
+ newVoucher = _.filter(newVoucher, function (inv){
|
|
|
+ return inv.date_order >= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (hasta.length > 0){
|
|
|
+ var date= hasta.split('/');
|
|
|
+ newVoucher = _.filter(newVoucher, function (inv){
|
|
|
+ return inv.date_order <= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $('#datepicker').css('display','none');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (journal != 9999999){
|
|
|
+ var botonChart =this.$el.find('#chart').attr("disabled", true);
|
|
|
+ newJournal=_.filter(newJournal, function (inv){ return inv.id == journal});
|
|
|
+ }else {
|
|
|
+ var botonChart =this.$el.find('#chart').attr("disabled", false);
|
|
|
+ }
|
|
|
+ self.fecthDataVoucher(newVoucher,newJournal);
|
|
|
+ },
|
|
|
+ // volver
|
|
|
+ volver: function(){
|
|
|
+ this.$el.find('#volver').empty();
|
|
|
+ this.$el.find('#grafico').empty();
|
|
|
+ this.$el.find('.bootstrap-table').show({
|
|
|
+ effect: 'drop',
|
|
|
+ direction: 'down',
|
|
|
+ duration: 200,
|
|
|
+ });
|
|
|
+ this.$el.find('#toolbar').show({
|
|
|
+ effect: 'drop',
|
|
|
+ direction: 'down',
|
|
|
+ duration: 200,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Click pdf -Grafic
|
|
|
+ clickOnAction: function (e) {
|
|
|
+ var action = this.$el.find(e.target).val();
|
|
|
+ var self = this;
|
|
|
+ var getColumns=[];
|
|
|
+ var rows=[];
|
|
|
+ var table = this.$el.find("#table");
|
|
|
+ var data2 = table.bootstrapTable('getVisibleColumns');
|
|
|
+ if (action === 'pdf') {
|
|
|
+ var dataNEW = _.map(data2, function (val){ return val.field});
|
|
|
+ _.each(this.dataVoucher,function (item){
|
|
|
+ rows.push(_.pick(item, dataNEW));
|
|
|
+ });
|
|
|
+ // Obtener los nombre de la Cabezera
|
|
|
+ _.each(_.map(data2,function(val){return val}), function(item){
|
|
|
+ getColumns.push([{title: item.title, dataKey: item.field}]);
|
|
|
+ });
|
|
|
+ // Llamar al pdf
|
|
|
+ this.drawPDF(_.flatten(getColumns),rows)
|
|
|
+ }
|
|
|
+ // if (action === 'chart'){
|
|
|
+ // var self = this;
|
|
|
+ // var objetChar;
|
|
|
+ // objetChar = _.filter(self.dataVoucher,function(item){return item.graficar === true});
|
|
|
+ // self.fectCharFilter(objetChar);
|
|
|
+ // }
|
|
|
+ },
|
|
|
+ // pdfDoc
|
|
|
+ drawPDF:function(getColumns,rows){
|
|
|
+ var self = this;
|
|
|
+ var fechaActu= new Date();
|
|
|
+ var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
|
|
|
+ var desde =(this.$el.find('#from').val());
|
|
|
+ var hasta =(this.$el.find('#to').val());
|
|
|
+ var totalPagesExp = "{total_pages_count_string}";
|
|
|
+ var pdfDoc = new window.jsPDF();
|
|
|
+
|
|
|
+ pdfDoc.autoTable(getColumns, rows, {
|
|
|
+ styles: { overflow: 'linebreak', fontSize:10 , columnWidth: 'wrap'},
|
|
|
+ columnStyles:{journal: {fontStyle: 'bold'},
|
|
|
+ method :{columnWidth: '10px'},
|
|
|
+ amount : {halign:'right'},
|
|
|
+ },
|
|
|
+ margin: { top: 16, horizontal: 7},
|
|
|
+ addPageContent: function (data) {
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Resumen de Egreso de '+ sucusal, data.settings.margin.left, 10);
|
|
|
+ if(desde.length > 0 || hasta.length > 0){
|
|
|
+ var fecha='';
|
|
|
+ if(desde){
|
|
|
+ fecha=fecha.concat(' Desde '+desde);
|
|
|
+ }
|
|
|
+ if (hasta){
|
|
|
+ fecha=fecha.concat(' Hasta '+hasta);
|
|
|
+ }
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40)
|
|
|
+ pdfDoc.text(fecha, data.settings.margin.left,14);
|
|
|
+ }
|
|
|
+ // FOOTER
|
|
|
+ var str = "Pagina " + data.pageCount;
|
|
|
+ // Total page number plugin only available in jspdf v1.0+
|
|
|
+ if (typeof pdfDoc.putTotalPages === 'function') {
|
|
|
+ str = str + " de " + totalPagesExp +"\n Día de Expedición "+fechaActu.getDate()+"/"+fechaActu.getMonth()+"/"+fechaActu.getFullYear();
|
|
|
+ }
|
|
|
+ pdfDoc.setFontSize(9);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(str, data.settings.margin.left, pdfDoc.internal.pageSize.height - 5);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (typeof pdfDoc.putTotalPages === 'function') {
|
|
|
+ pdfDoc.putTotalPages(totalPagesExp);
|
|
|
+ }
|
|
|
+ pdfDoc.save('Resumen de Egreso.pdf');
|
|
|
+ },
|
|
|
+ // // Char filter
|
|
|
+ // fectCharFilter: function(objetChar){
|
|
|
+ // var self = this;
|
|
|
+ // var dataBody=[];
|
|
|
+ // var dataHeader=[];
|
|
|
+ // // objetChar
|
|
|
+ // var canvas="<canvas id='graf_resume'></canvas>";
|
|
|
+ // this.$el.find('#grafico').append(canvas);
|
|
|
+ // _.each(objetChar,function(voucher){
|
|
|
+ // dataHeader.push(voucher.journal_name);
|
|
|
+ // dataBody.push(parseFloat(((voucher.amount.replace(".","")).replace(",","."))));
|
|
|
+ // });
|
|
|
+ // var selector ="<button type='button' class='oe_button oe_form_button oe_highlight' id='volver_btn' name='volver_btn'><span>Atras</span></button>";
|
|
|
+ // this.$el.find('#volver').append(selector);
|
|
|
+ // this.$el.find('.bootstrap-table').hide({
|
|
|
+ // effect: 'drop',
|
|
|
+ // direction: 'up',
|
|
|
+ // duration: 200,
|
|
|
+ // complete: function () {
|
|
|
+ // self.drawChart(dataHeader,dataBody);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // this.$el.find('#toolbar').hide({
|
|
|
+ // effect: 'drop',
|
|
|
+ // direction: 'up',
|
|
|
+ // duration: 200,
|
|
|
+ // complete: function () {
|
|
|
+ // self.drawChart(dataHeader,dataBody);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // //Chart
|
|
|
+ // drawChart: function (dataHeader,dataBody) {
|
|
|
+ // var barChart = new Chart(this.$el.find('#graf_resume'), {
|
|
|
+ // type: 'doughnut',//bar, doughnut
|
|
|
+ // data: {
|
|
|
+ // labels: dataHeader,
|
|
|
+ // datasets: [
|
|
|
+ // {
|
|
|
+ // labels: dataHeader,
|
|
|
+ // backgroundColor: [
|
|
|
+ // 'rgba(255, 99, 132, 0.2)',
|
|
|
+ // 'rgba(54, 162, 235, 0.2)',
|
|
|
+ // 'rgba(255, 206, 86, 0.2)',
|
|
|
+ // 'rgba(75, 192, 192, 0.2)',
|
|
|
+ // 'rgba(153, 102, 255, 0.2)',
|
|
|
+ // ],
|
|
|
+ // borderColor: [
|
|
|
+ // 'rgba(255,99,132,1)',
|
|
|
+ // 'rgba(54, 162, 235, 1)',
|
|
|
+ // 'rgba(255, 206, 86, 1)',
|
|
|
+ // 'rgba(75, 192, 192, 1)',
|
|
|
+ // 'rgba(153, 102, 255, 1)',
|
|
|
+ // ],
|
|
|
+ // borderWidth: 1,
|
|
|
+ // data: dataBody,
|
|
|
+ // }
|
|
|
+ // ]
|
|
|
+ // },
|
|
|
+ // options: {
|
|
|
+ // maintainAspectRatio: false,
|
|
|
+ // layout: {
|
|
|
+ // padding: 30
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ });
|
|
|
+}
|