|
@@ -0,0 +1,668 @@
|
|
|
+function report_sales_invoice_analysis (reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportSaleInvoiceAnalysisWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportSaleInvoiceAnalysis',
|
|
|
+ invoices: [],
|
|
|
+ invoiceLines: [],
|
|
|
+ productProduct:[],
|
|
|
+ Currency:[],
|
|
|
+ rowsData :[],
|
|
|
+ rowOrigin:[],
|
|
|
+ accountJournal:[],
|
|
|
+ resCompany:[],
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click #X' : 'fectSearch',
|
|
|
+ 'click #A' : 'fectSearch',
|
|
|
+ 'click #B' : 'fectSearch',
|
|
|
+ 'click #C' : 'fectSearch',
|
|
|
+ 'click #D' : 'fectSearch',
|
|
|
+ 'click #Z' : 'fectSearch',
|
|
|
+ 'change #current-journal': 'fectSearch',
|
|
|
+ 'change #from' : 'fectSearch',
|
|
|
+ 'change #to': 'fectSearch',
|
|
|
+ 'click #volver_btn': 'volver',
|
|
|
+ 'click-row.bs.table #table' : 'ckickAnalysisDetail',
|
|
|
+ },
|
|
|
+ init : function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+ start: function () {
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable({data : self.rowOrigin});
|
|
|
+ this.fecthFecha();
|
|
|
+ this.submitForm();
|
|
|
+ },
|
|
|
+ ckickAnalysisDetail: function(e, row, $element, field){
|
|
|
+ if (field == 'name'){
|
|
|
+ this.do_action({
|
|
|
+ name : "Variantes de Producto",
|
|
|
+ type : 'ir.actions.act_window',
|
|
|
+ res_model : "product.product",
|
|
|
+ views : [[false,'form']],
|
|
|
+ target : 'new',
|
|
|
+ domain : [['id','=', row.id_product]],
|
|
|
+ context : {},
|
|
|
+ flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ res_id : row.id_product,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (field == 'number'){
|
|
|
+ this.do_action({
|
|
|
+ name : "Factura de Cliente",
|
|
|
+ type : 'ir.actions.act_window',
|
|
|
+ res_model : "account.invoice",
|
|
|
+ views : [[false,'form']],
|
|
|
+ target : 'new',
|
|
|
+ domain : [['type', '=', 'out_invoice'],['id','=', row.id]],
|
|
|
+ context : {},
|
|
|
+ flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ res_id : row.id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ e.stopImmediatePropagation();
|
|
|
+ },
|
|
|
+ volver: function(){
|
|
|
+ this.$el.find('#volver').empty();
|
|
|
+ this.$el.find('#grafico').empty();
|
|
|
+ this.$el.find('.bootstrap-table').show({
|
|
|
+ effect: 'drop',
|
|
|
+ direction: 'down',
|
|
|
+ duration: 200,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Cansultar
|
|
|
+ submitForm: function () {
|
|
|
+ var self = this;
|
|
|
+ this.fetchCurency().then(function(Currency) {
|
|
|
+ self.Currency = Currency;
|
|
|
+ return Currency;
|
|
|
+ }).then(function (Currency) {
|
|
|
+ return self.fetchJournal();
|
|
|
+ }).then(function (journal) {
|
|
|
+ self.accountJournal =journal;
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">TODAS LAS SUC.</option>');
|
|
|
+ _.each(journal, function (item) {
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ return self.fetchInvoiceV2();
|
|
|
+ }).then(function (invoices){
|
|
|
+ self.invoices = invoices;
|
|
|
+ return self.fetchInvoiceLine(invoices);
|
|
|
+ }).then(function (invoiceLines) {
|
|
|
+ self.invoiceLines = invoiceLines;
|
|
|
+ return self.fecthProduct(invoiceLines);
|
|
|
+ }).then(function(productProduct){
|
|
|
+ self.productProduct = productProduct;
|
|
|
+ return self.fecthComanyCurrency();
|
|
|
+ }).then(function(resCompany){
|
|
|
+ self.resCompany = resCompany;
|
|
|
+ return self.fetchResPartner();
|
|
|
+ }).then(function(ResPartner){
|
|
|
+ self.ResPartner = ResPartner;
|
|
|
+ self.search();
|
|
|
+ self.searchProduct();
|
|
|
+ return self.invoice_Currency();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // company_curency
|
|
|
+ fecthComanyCurrency: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency = new model.web.Model('res.company');
|
|
|
+ var field=['id', 'currency_id'];
|
|
|
+ var domain=[['id','=',1]];
|
|
|
+ currency.query(field).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // 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;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // Buscar Diario
|
|
|
+ fetchJournal: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var Journal = new model.web.Model('account.journal');
|
|
|
+ Journal.query(['id', 'name']).filter([['type', '=', 'sale'], ['active', '=', true]]).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Buscar Cambio de Monedas USD,PYG,ARG,BRL
|
|
|
+ fetchCurency: function () {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency_Rate = new model.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 filter ="[['state', 'in',['open','paid']],['type', '=', 'out_invoice']";
|
|
|
+ var journal_ids = _.flatten(_.map(this.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', 'state', 'journal_id', 'currency_id', 'invoice_line','date_invoice','partner_id'];
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var Invoice = new model.web.Model('account.invoice');
|
|
|
+ Invoice.query(field).filter(filter).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Invoice line (Linea de Factura)
|
|
|
+ fetchInvoiceLine: function (invoices) {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var linesIds = _.flatten(_.map(invoices, function (item) {
|
|
|
+ return item.invoice_line;
|
|
|
+ }));
|
|
|
+ var InvoiceLine = new model.web.Model('account.invoice.line');
|
|
|
+ InvoiceLine.query(['id', 'quantity', 'price_unit', 'discount', 'name', 'product_id', 'origin','invoice_id']).filter([['id', 'in', linesIds]]).all().then(function (results) {
|
|
|
+ defer.resolve(results)
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ fetchResPartner: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var ResPartner = new model.web.Model('res.partner');
|
|
|
+ ResPartner.query(['id','name','ruc']).filter([['active', '=', true],['customer', '=', true]]).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Product Product
|
|
|
+ fecthProduct: function(invoiceLines){
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var porductIDS = _.flatten(_.map(invoiceLines, function (item) {
|
|
|
+ return item.product_id[0];
|
|
|
+ }));
|
|
|
+ var ProductProdcut = new model.web.Model('product.product');
|
|
|
+ var fields = ['id','name', 'default_code', 'name_template','ean13', 'standard_price','type','attribute_str'];
|
|
|
+ ProductProdcut.query(fields).filter([['id', 'in', porductIDS]]).all().then(function (results) {
|
|
|
+ defer.resolve(results)
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Obtener Monedas de la Factura
|
|
|
+ getCutrrency: function (id){
|
|
|
+ return _.find(this.Currency,function (curr) {
|
|
|
+ return _.contains(curr.currency_id,id);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Actualizar cambio de las moneda de Factura
|
|
|
+ invoice_Currency: function(){
|
|
|
+ for (var i = 0; i < this.invoices.length; i++) {
|
|
|
+ var currency_new;
|
|
|
+ var item = this.invoices[i];
|
|
|
+ var id = item.currency_id[0];
|
|
|
+ currency_new = this.getCutrrency(id);
|
|
|
+ if (!currency_new){
|
|
|
+ currency_new={};
|
|
|
+ currency_new.rate=1;
|
|
|
+ }
|
|
|
+ this.invoices[i].rate=(currency_new.rate);
|
|
|
+ }
|
|
|
+ return this.fectUtility();
|
|
|
+ },
|
|
|
+ // Obtener la Detalles de la Factura
|
|
|
+ getInvoice: function (id_line){
|
|
|
+ return _.find(this.invoices, function (inv) {
|
|
|
+ return _.contains(inv.invoice_line, id_line);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Obtener las lineas de las Facturas
|
|
|
+ getProduct: function(pro_id){
|
|
|
+ return _.find(this.productProduct, function(prod){
|
|
|
+ return _.contains(pro_id, prod.id);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fectUtility: function(){
|
|
|
+ var data=[];
|
|
|
+ var item;
|
|
|
+ var invoice;
|
|
|
+ var producto;
|
|
|
+
|
|
|
+ for (var i = 0; i < this.invoiceLines.length; i++) {
|
|
|
+ item = this.invoiceLines[i];
|
|
|
+ invoice = this.getInvoice(item.id);
|
|
|
+ producto =this.getProduct(item.product_id);
|
|
|
+ if (!producto){
|
|
|
+ producto={};
|
|
|
+ producto.standard_price=0;
|
|
|
+ }
|
|
|
+ data.push({
|
|
|
+ id : invoice.id,
|
|
|
+ number : (invoice.number),
|
|
|
+ id_product : producto.id,
|
|
|
+ name : (item.name),
|
|
|
+ quantity : accounting.formatNumber((item.quantity),0, ".", ","),
|
|
|
+ price_unity : accounting.formatNumber((item.price_unit / invoice.rate),2, ".", ","),
|
|
|
+ standar_price : accounting.formatNumber((producto.standard_price),2, ".", ","),
|
|
|
+ price_tot : accounting.formatNumber((item.quantity * (item.price_unit / invoice.rate)),2, ".", ","),
|
|
|
+ standar_tot : accounting.formatNumber((item.quantity * producto.standard_price),2, ".", ","),
|
|
|
+ utility : accounting.formatNumber(((item.quantity * (item.price_unit / invoice.rate)) - (item.quantity * producto.standard_price)),2, ".", ","),
|
|
|
+ journal_id :(invoice.journal_id[0]),
|
|
|
+ journal_name :(invoice.journal_id[1]),
|
|
|
+ date_invoice : (invoice.date_invoice),
|
|
|
+ partner_id : invoice.partner_id[0],
|
|
|
+ partner_name : invoice.partner_id[1]
|
|
|
+ });
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ this.rowsData=data;
|
|
|
+ this.rowOrigin=data;
|
|
|
+ this.loadTable(data)
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ fectSearch: function(){
|
|
|
+ var self = this;
|
|
|
+ var hoy = moment().format('YYYY-MM-DD');
|
|
|
+ var partner = this.$el.find('#partner').val().split('-');
|
|
|
+ var product = this.$el.find('#product').val().split('-');
|
|
|
+ var desde =this.$el.find('#from').val();
|
|
|
+ var hasta =this.$el.find('#to').val();
|
|
|
+ self.rowsData=self.rowOrigin;
|
|
|
+
|
|
|
+ if ($('#A').is(":checked")){
|
|
|
+ self.rowsData = _.filter(self.rowsData, function (inv){
|
|
|
+ return inv.date_invoice == hoy;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#B').is(":checked")){
|
|
|
+ var date = hoy.split('-');
|
|
|
+ var ayer = date[2] - 1;
|
|
|
+ date.splice(2,0);
|
|
|
+ date[2] = '0'+ayer;
|
|
|
+ self.rowsData = _.filter(self.rowsData, function (inv){
|
|
|
+ return inv.date_invoice == date[0]+'-'+date[1]+'-'+date[2];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#C').is(":checked")){
|
|
|
+ var date = hoy.split('-');
|
|
|
+ self.rowsData = _.filter(self.rowsData, function (inv){
|
|
|
+ var mes = inv.date_invoice.split('-');
|
|
|
+ return mes[0]+'-'+mes[1] == date[0]+'-'+date[1];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#D').is(":checked")){
|
|
|
+ var date = hoy.split('-');
|
|
|
+ var mes = date[1] - 1;
|
|
|
+ var year;
|
|
|
+ date.splice(1,0);
|
|
|
+ if(date[1] == 1){
|
|
|
+ date[1] = '12';
|
|
|
+ year = date[0] - 1;
|
|
|
+ date[0] = year;
|
|
|
+ }else{
|
|
|
+
|
|
|
+ if(date[1] < 10){
|
|
|
+ date[1] = '0'+mes;
|
|
|
+ }else{
|
|
|
+ date[1] = mes;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.rowsData = _.filter(content, function (inv){
|
|
|
+ var mes = inv.date.split('-');
|
|
|
+ return mes[0]+'-'+mes[1] == date[0]+'-'+date[1];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#Z').is(":checked")){
|
|
|
+ $('#datepicker').css('display','block');
|
|
|
+ if (desde.length > 0){
|
|
|
+ var date= desde.split('/');
|
|
|
+ self.rowsData = _.filter(self.rowsData, function (inv){
|
|
|
+ return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (hasta.length > 0){
|
|
|
+ var date= hasta.split('/');
|
|
|
+ self.rowsData = _.filter(self.rowsData, function (inv){
|
|
|
+ return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $('#datepicker').css('display','none');
|
|
|
+ }
|
|
|
+ if (partner != ""){
|
|
|
+ self.rowsData = _.filter(self.rowsData, function(inv){
|
|
|
+ return inv.partner_id == partner[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (product != ""){
|
|
|
+ self.rowsData = _.filter(self.rowsData, function(inv){
|
|
|
+ return inv.id_product == product[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ self.loadTable(self.rowsData);
|
|
|
+ },
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor ="";
|
|
|
+ if (dato){
|
|
|
+ valor=dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+ search: function () {
|
|
|
+ var self = this;
|
|
|
+ var results = self.ResPartner;
|
|
|
+ results = _.map(results, function (item) {
|
|
|
+ return {
|
|
|
+ label: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc),
|
|
|
+ value: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.$('#partner').autocomplete({
|
|
|
+ source: results,
|
|
|
+ minLength:0,
|
|
|
+ search: function(event, ui) {
|
|
|
+ if (!(self.$('#partner').val())){
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ close: function( event, ui ) {
|
|
|
+ self.fectSearch();
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ searchProduct: function () {
|
|
|
+ var self = this;
|
|
|
+ var results = self.productProduct;
|
|
|
+ results = _.map(results, function (item) {
|
|
|
+ return {
|
|
|
+ label: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' + self.valorNull(item.attribute_str) + ' ) ' ,
|
|
|
+ value: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' + self.valorNull(item.attribute_str) + ' ) '
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.$('#product').autocomplete({
|
|
|
+ source: results,
|
|
|
+ minLength:0,
|
|
|
+ search: function(event, ui) {
|
|
|
+ if (!(self.$('#product').val())){
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ close: function( event, ui ) {
|
|
|
+ self.fectSearch();
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ loadTable:function(rowsTable){
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable('load', rowsTable);
|
|
|
+ },
|
|
|
+ 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.rowsData,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 suc =this.$el.find('#current-journal').val();
|
|
|
+ if (suc == 9999999){
|
|
|
+ self.fectCharFilter();
|
|
|
+ }else{
|
|
|
+ $("#dialog" ).dialog({
|
|
|
+ autoOpen: true,
|
|
|
+ resizable: false,
|
|
|
+ modal: true,
|
|
|
+ title: 'Atención',
|
|
|
+ open: function() {
|
|
|
+ $(this).html('Para Generar el Gráfico debes Seleccionar todas las Sucursales');
|
|
|
+ },
|
|
|
+ show: {
|
|
|
+ effect: "shake",
|
|
|
+ duration: 300
|
|
|
+ },
|
|
|
+ hide: {
|
|
|
+ effect: "fade",
|
|
|
+ duration: 300
|
|
|
+ },
|
|
|
+ buttons: {
|
|
|
+ Aceptar: function() {
|
|
|
+ $(this).dialog('close');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ drawPDF: function (getColumns,rows) {
|
|
|
+ var self = this;
|
|
|
+ var rowsPdf=[];
|
|
|
+ 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 jsPDF();
|
|
|
+
|
|
|
+ // rows=this.rowsData;
|
|
|
+ var quantity=_.reduce(_.map(rows,function(item){
|
|
|
+ var valor=0;
|
|
|
+ if (item.quantity){valor = parseFloat(((item.quantity.replace(".","")).replace(",",".")))}return valor}), function(memo, num){ return memo + num; },0);
|
|
|
+ var precio_unit=_.reduce(_.map(rows,function(item){
|
|
|
+ var valor =0;
|
|
|
+ if (item.price_unity){valor=parseFloat(((item.price_unity.replace(".","")).replace(",",".")))} return valor}), function(memo, num){ return memo + num; },0);
|
|
|
+ var precio_cost=_.reduce(_.map(rows,function(item){
|
|
|
+ var valor=0;
|
|
|
+ if(item.standar_price){valor=parseFloat(((item.standar_price.replace(".","")).replace(",",".")))} return valor}), function(memo, num){ return memo + num;},0);
|
|
|
+ var tot_unit=_.reduce(_.map(rows,function(item){
|
|
|
+ var valor=0;
|
|
|
+ if (item.price_tot){valor=parseFloat(((item.price_tot.replace(".","")).replace(",",".")))}return valor}), function(memo, num){ return memo + num; },0);
|
|
|
+ var tol_cost=_.reduce(_.map(rows,function(item){
|
|
|
+ var valor=0;
|
|
|
+ if (item.standar_tot){valor=parseFloat(((item.standar_tot.replace(".","")).replace(",",".")))} return valor }), function(memo, num){ return memo + num; },0);
|
|
|
+ var utility=_.reduce(_.map(rows,function(item){
|
|
|
+ var valor=0;
|
|
|
+ if (item.utility){valor=parseFloat(((item.utility.replace(".","")).replace(",",".")))}return valor }), function(memo, num){ return memo + num; },0);
|
|
|
+
|
|
|
+ rowsPdf=rows;
|
|
|
+
|
|
|
+ var company = _.map(self.resCompany, function (map) {
|
|
|
+ return map.currency_id[1];
|
|
|
+ });
|
|
|
+ rowsPdf.push({
|
|
|
+ number : "TOTAL "+company,
|
|
|
+ name : " ",
|
|
|
+ quantity: accounting.formatNumber(quantity,0, ".", ","),
|
|
|
+ price_unity : accounting.formatNumber(precio_unit,2, ".", ","),
|
|
|
+ standar_price : accounting.formatNumber(precio_cost,2, ".", ","),
|
|
|
+ price_tot : accounting.formatNumber(tot_unit,2, ".", ","),
|
|
|
+ standar_tot : accounting.formatNumber(tol_cost,2, ".", ","),
|
|
|
+ utility : accounting.formatNumber(utility,2, ".", ",")
|
|
|
+ });
|
|
|
+
|
|
|
+ rowsPdf.unshift({
|
|
|
+ number : "TOTAL "+company,
|
|
|
+ name : " ",
|
|
|
+ quantity: accounting.formatNumber(quantity,0, ".", ","),
|
|
|
+ price_unity : accounting.formatNumber(precio_unit,2, ".", ","),
|
|
|
+ standar_price : accounting.formatNumber(precio_cost,2, ".", ","),
|
|
|
+ price_tot : accounting.formatNumber(tot_unit,2, ".", ","),
|
|
|
+ standar_tot : accounting.formatNumber(tol_cost,2, ".", ","),
|
|
|
+ utility : accounting.formatNumber(utility,2, ".", ",")
|
|
|
+ });
|
|
|
+
|
|
|
+ pdfDoc.autoTable(getColumns, rowsPdf, {
|
|
|
+ styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
|
|
|
+ columnStyles: {
|
|
|
+ number: {fontStyle: 'bold'},
|
|
|
+ name :{columnWidth: '10px'},
|
|
|
+ quantity :{halign:'right' },
|
|
|
+ price_unity : {halign:'right' },
|
|
|
+ standar_price : {halign:'right' },
|
|
|
+ price_tot : {halign:'right' },
|
|
|
+ standar_tot : {halign:'right' },
|
|
|
+ utility : {halign:'right'},
|
|
|
+ },
|
|
|
+ margin: { top: 16, horizontal: 7},
|
|
|
+ addPageContent: function (data) {
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Análisis de facturas de venta ', 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;
|
|
|
+ }
|
|
|
+ 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('Análisis de facturas de venta.pdf')
|
|
|
+ },
|
|
|
+
|
|
|
+ // fectCharFilter: function(){
|
|
|
+ // var self = this;
|
|
|
+ // var dataBody=[];
|
|
|
+ // var dataHeader=[];
|
|
|
+
|
|
|
+ // var canvas="<canvas id='graf_resume'></canvas>";
|
|
|
+ // this.$el.find('#grafico').append(canvas);
|
|
|
+
|
|
|
+ // _.each(self.accountJournal, function(journal){
|
|
|
+ // dataHeader.push(journal.name);
|
|
|
+ // var utility=_.reduce(_.map(_.filter(self.rowsData, function (inv){ return inv.journal_id == journal.id}),function(item){
|
|
|
+ // return parseFloat(((item.utility.replace(".","")).replace(",",".")))}), function(memo, num){ return memo + num; },0);
|
|
|
+ // dataBody.push(accounting.toFixed((utility),2));
|
|
|
+ // });
|
|
|
+ // 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);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // drawChart: function (dataHeader,dataBody) {
|
|
|
+ // var barChart = new Chart(this.$el.find('#graf_resume'), {
|
|
|
+ // type: '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
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ });
|
|
|
+}
|