|
@@ -28,6 +28,16 @@ openerp.eiru_reporting = function (instance, local) {
|
|
|
title: 'Listado de Stock por Ubicacion',
|
|
|
description: 'Permite visualizar un listado de productos activos.',
|
|
|
action: 'ReportStockLocation'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: 'Listado de Compras',
|
|
|
+ description: 'Permite visualizar un listado de Compras.',
|
|
|
+ action: 'AllPurchases'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: 'Listado de Gastos',
|
|
|
+ description: 'Permite visualizar un listado de Gastos.',
|
|
|
+ action: 'ReposrtExpenses'
|
|
|
}
|
|
|
],
|
|
|
start: function () {
|
|
@@ -1661,6 +1671,940 @@ openerp.eiru_reporting = function (instance, local) {
|
|
|
pdfDoc.save('Listado_de_Stock_Por_Ubicaion.pdf');
|
|
|
}
|
|
|
});
|
|
|
+ // AllPurchases Listado de Compras
|
|
|
+ local.AllPurchasesWidget = instance.Widget.extend({
|
|
|
+ template: 'AllPurchases',
|
|
|
+ invoice: [],
|
|
|
+ Currency:[],
|
|
|
+ resCurrency :[],
|
|
|
+ resCompany:[],
|
|
|
+ accountJournal:[],
|
|
|
+ supplier:[],
|
|
|
+ newInvoice:[],
|
|
|
+ rowsData :[],
|
|
|
+ // event
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'change #current-journal' : 'factSearch',
|
|
|
+ 'change #current-currency' : 'factSearch',
|
|
|
+ 'change #from' : 'factSearch',
|
|
|
+ 'change #to' : 'factSearch',
|
|
|
+ 'click #volver_btn' : 'volver',
|
|
|
+ },
|
|
|
+ // Initil
|
|
|
+ init : function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+ // start
|
|
|
+ start: function () {
|
|
|
+ var self = this;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable({data : self.rowsData});
|
|
|
+ this.fecthFecha();
|
|
|
+ this.submitForm();
|
|
|
+ },
|
|
|
+ // volver
|
|
|
+ volver: function(){
|
|
|
+ this.$el.find('#volver').empty();
|
|
|
+ this.$el.find('.bootstrap-table').show({
|
|
|
+ effect: 'drop',
|
|
|
+ direction: 'down',
|
|
|
+ duration: 200,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Consultar
|
|
|
+ submitForm: function () {
|
|
|
+ var self = this;
|
|
|
+ self.fetchResCurency().then(function(resCurrency) {
|
|
|
+ return resCurrency;
|
|
|
+ }).then(function (resCurrency) {
|
|
|
+ self.resCurrency = resCurrency;
|
|
|
+ self.$el.find('#current-currency').append('<option value="9999999">Todas las monedas</option>');
|
|
|
+ _.each(resCurrency, function (item) {
|
|
|
+ self.$el.find('#current-currency').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ return self.fetchCurency(resCurrency);
|
|
|
+ }).then(function(Currency){
|
|
|
+ self.Currency = 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.fetchInvoiceP2();
|
|
|
+ }).then(function (invoice){
|
|
|
+ self.invoice = invoice;
|
|
|
+ return self.fetchSupplier(invoice);
|
|
|
+ }).then(function(supplier){
|
|
|
+ self.supplier=supplier;
|
|
|
+ return self.fecthComanyCurrency();
|
|
|
+ }).then(function(resCompany){
|
|
|
+ self.resCompany = resCompany;
|
|
|
+ self.inicializarBuscadorsup();
|
|
|
+ return self.fect_generar(self.invoice);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 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 instance.web.Model('account.journal');
|
|
|
+ Journal.query(['id', 'name']).filter([['type', '=', 'purchase']]).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Buscar Cambio de Monedas USD,PYG,ARG,BRL
|
|
|
+ fetchCurency: function (currency) {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency_id = _.flatten(_.map(currency,function(map){
|
|
|
+ return map.id;
|
|
|
+ }))
|
|
|
+ var currency_Rate = new instance.web.Model('res.currency.rate');
|
|
|
+ var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
|
|
|
+ var domain = [['currency_id', '=', currency_id]];
|
|
|
+ currency_Rate.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Moneda
|
|
|
+ fetchResCurency: function () {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency = new instance.web.Model('res.currency');
|
|
|
+ var fields = ['id', 'name'];
|
|
|
+ var domain = [['active', '=', true]];
|
|
|
+ currency.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Invoice (FACTURAS)
|
|
|
+ fetchInvoiceP2: function () {
|
|
|
+ var journal_ids = _.flatten(_.map(this.accountJournal, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ var filter =[['state', '=',['open','paid']],['type', '=', 'in_invoice'],['origin', '!=', false],['journal_id', '=',journal_ids]];
|
|
|
+ var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'supplier_invoice_number','date_invoice','partner_id','amount_total','user_id'];
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var Invoice = new instance.web.Model('account.invoice');
|
|
|
+ Invoice.query(field).filter(filter).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // company_curency
|
|
|
+ fecthComanyCurrency: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency = new instance.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;
|
|
|
+ },
|
|
|
+ // Partner (Proveeedor)
|
|
|
+ fetchSupplier: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var supplier = new instance.web.Model('res.partner');
|
|
|
+ supplier.query(['id', 'name', 'ruc', 'active', 'supplier']).filter([['active', '=', true], ['supplier', '=', true]]).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Obtener el Cambio de la Moneda
|
|
|
+ getCurrency: function (id){
|
|
|
+ return _.find(this.Currency,function (curr) {
|
|
|
+ return _.contains(curr.currency_id,id);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Verificar si los Valores no son nulos
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor ="";
|
|
|
+ if (dato){
|
|
|
+ valor=dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+ // Buscador
|
|
|
+ inicializarBuscadorsup: function () {
|
|
|
+ var self = this;
|
|
|
+ var results = self.supplier;
|
|
|
+ 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.$('#customer').autocomplete({
|
|
|
+ source: results,
|
|
|
+ minLength:0,
|
|
|
+ search: function(event, ui) {
|
|
|
+ if (!(self.$('#customer').val())){
|
|
|
+ self.factSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.factSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // unir los objetos
|
|
|
+ fect_generar: function(invoices){
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ _.each(invoices, function(invoice){
|
|
|
+ data.push({
|
|
|
+ number: invoice.number,
|
|
|
+ supplier_invoice_number: self.valorNull(invoice.supplier_invoice_number),
|
|
|
+ partner: invoice.partner_id[1],
|
|
|
+ date: moment(invoice.date_invoice).format("DD/MM/YYYY"),
|
|
|
+ date_invoice: invoice.date_invoice,
|
|
|
+ user: invoice.user_id[1],
|
|
|
+ currency: invoice.currency_id[1],
|
|
|
+ amount_total: accounting.formatNumber(invoice.amount_total,2,".",","),
|
|
|
+ amount: invoice.amount_total,
|
|
|
+ journal_id : invoice.journal_id[0],
|
|
|
+ currency_id : invoice.currency_id[0],
|
|
|
+ partner_id : invoice.partner_id[0]
|
|
|
+ });
|
|
|
+ });
|
|
|
+ self.newInvoice = data;
|
|
|
+ this.loadTable(data);
|
|
|
+ },
|
|
|
+ // Buscar
|
|
|
+ factSearch: function(){
|
|
|
+ var self = this;
|
|
|
+ var desde =this.$el.find('#from').val();
|
|
|
+ var hasta =this.$el.find('#to').val();
|
|
|
+ var suc =this.$el.find('#current-journal').val();
|
|
|
+ var currency =this.$el.find('#current-currency').val();
|
|
|
+ var prov= this.$el.find('#customer').val().split('-');
|
|
|
+ var newInvoice = self.newInvoice;
|
|
|
+ // Buscar por Sucursales
|
|
|
+ if (suc != 9999999){
|
|
|
+ newInvoice=_.filter(newInvoice, function (inv){
|
|
|
+ return inv.journal_id == suc;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // Buscar por fecha Desde
|
|
|
+ if (desde.length > 0){
|
|
|
+ var date= desde.split('/');
|
|
|
+ newInvoice = _.filter(newInvoice, function (inv){
|
|
|
+ return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // Buscar por Fechas Hasta
|
|
|
+ if (hasta.length > 0){
|
|
|
+ var date= hasta.split('/');
|
|
|
+ newInvoice = _.filter(newInvoice, function (inv){
|
|
|
+ return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // Busacar por moneda
|
|
|
+ if(currency != 9999999){
|
|
|
+ newInvoice = _.filter(newInvoice,function(inv){
|
|
|
+ return inv.currency_id == currency;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // Busacara por proveedor
|
|
|
+ if (prov != ""){
|
|
|
+ newInvoice = _.filter(newInvoice, function(inv){
|
|
|
+ return inv.partner_id == prov[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ self.loadTable(newInvoice)
|
|
|
+ },
|
|
|
+ // cargara la tabla
|
|
|
+ loadTable:function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ self.rowsData = rowsTable;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable('load',rowsTable);
|
|
|
+ },
|
|
|
+ // Obtener Invoice por Monedad
|
|
|
+ getInvoice : function(currency_id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.rowsData, function(item){
|
|
|
+ return item.currency_id === currency_id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Crear Objete PDF
|
|
|
+ getObjetPdf: function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ var rowsPdf=[];
|
|
|
+ var rows=[];
|
|
|
+ var itemCurrecy;
|
|
|
+ var itenRow;
|
|
|
+ var item;
|
|
|
+ var curreRate;
|
|
|
+ var amount_total=0;
|
|
|
+ var amount=0;
|
|
|
+ var company = _.map(self.resCompany,function(map){return map.currency_id[1]});
|
|
|
+
|
|
|
+ for (var i = 0; i < self.resCurrency.length; i++) {
|
|
|
+ itemCurrecy = self.resCurrency[i];
|
|
|
+ itenRow = self.getInvoice(itemCurrecy.id);
|
|
|
+ rowsPdf=[];
|
|
|
+ if (itenRow.length > 0){
|
|
|
+ rowsPdf.push({number: itemCurrecy.name, supplier_invoice_number: "", partner: "", date: "", date_invoice: "", user: "", currency: "", amount_total: "", journal_id : "", currency_id : "", partner_id : ""});
|
|
|
+ _.each(itenRow, function(item){
|
|
|
+ rowsPdf.push({
|
|
|
+ number: item.number,
|
|
|
+ supplier_invoice_number: self.valorNull(item.supplier_invoice_number),
|
|
|
+ partner: item.partner,
|
|
|
+ date: moment(item.date_invoice).format("DD/MM/YYYY"),
|
|
|
+ date_invoice: item.date_invoice,
|
|
|
+ user: item.user,
|
|
|
+ currency: item.currency,
|
|
|
+ amount_total: accounting.formatNumber((item.amount),2,".",","),
|
|
|
+ amount: item.amount,
|
|
|
+ journal_id : item.journal_id,
|
|
|
+ currency_id : item.currency_id,
|
|
|
+ partner_id : item.partner_id
|
|
|
+ });
|
|
|
+ });
|
|
|
+ curreRate = self.getCurrency(itemCurrecy.id);
|
|
|
+ if (!curreRate){
|
|
|
+ curreRate={};
|
|
|
+ curreRate.rate=1;
|
|
|
+ }
|
|
|
+ amount_total= _.reduce(_.map(itenRow,function(map){
|
|
|
+ return(map.amount);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ amount = amount+(amount_total/curreRate.rate);
|
|
|
+ rowsPdf.push({
|
|
|
+ number: "Sub - Total "+itemCurrecy.name,
|
|
|
+ supplier_invoice_number: "",
|
|
|
+ partner: "",
|
|
|
+ date: "",
|
|
|
+ date_invoice: "",
|
|
|
+ user: "",
|
|
|
+ currency: "",
|
|
|
+ amount_total: accounting.formatNumber((amount_total),2,".",","),
|
|
|
+ journal_id : "",
|
|
|
+ currency_id : "",
|
|
|
+ partner_id : ""
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (rowsPdf.length >0){
|
|
|
+ rows = rows.concat(rowsPdf);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rows.length > 0){
|
|
|
+ rows.push({
|
|
|
+ number: "Total en "+company,
|
|
|
+ supplier_invoice_number: "",
|
|
|
+ partner: "",
|
|
|
+ date: "",
|
|
|
+ date_invoice: "",
|
|
|
+ user: "",
|
|
|
+ currency: "",
|
|
|
+ amount_total: accounting.formatNumber((amount),2,".",","),
|
|
|
+ journal_id : "",
|
|
|
+ currency_id : "",
|
|
|
+ partner_id : ""
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return rows;
|
|
|
+ },
|
|
|
+ // imprimir PDF
|
|
|
+ clickOnAction: function (e) {
|
|
|
+ var self = this;
|
|
|
+ var rowsNew;
|
|
|
+ var action = self.$el.find(e.target).val();
|
|
|
+ var table = self.$el.find("#table");
|
|
|
+ var data2 = table.bootstrapTable('getVisibleColumns');
|
|
|
+ var getColumns=[];
|
|
|
+ var rows=[];
|
|
|
+ rowsNew = self.getObjetPdf();
|
|
|
+ if (action === 'pdf') {
|
|
|
+ var dataNEW = _.map(data2, function (val){
|
|
|
+ return val.field;
|
|
|
+ });
|
|
|
+ _.each(rowsNew,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
|
|
|
+ }]);
|
|
|
+ });
|
|
|
+ this.drawPDF(_.flatten(getColumns),rows);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // Generar pdfDoc
|
|
|
+ drawPDF: function (getColumns,rows) {
|
|
|
+ var self = this;
|
|
|
+ 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();
|
|
|
+
|
|
|
+ pdfDoc.autoTable(getColumns, rows, {
|
|
|
+ styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
|
|
|
+ columnStyles: {
|
|
|
+ number : {columnWidth: '8px'},
|
|
|
+ supplier_invoice_number : {columnWidth: '8px'},
|
|
|
+ partner : {columnWidth: '8px'},
|
|
|
+ date : {columnWidth: '8px'},
|
|
|
+ user : {columnWidth: '8px'},
|
|
|
+ currency : {columnWidth: '8px'},
|
|
|
+ amount_total: {halign:'right',columnWidth: '8px'},
|
|
|
+ },
|
|
|
+ margin: { top: 16, horizontal: 7},
|
|
|
+
|
|
|
+ addPageContent: function (data) {
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Listado de Compras '+ 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;
|
|
|
+ }
|
|
|
+ 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('Listado de Compras.pdf')
|
|
|
+ },
|
|
|
+ });
|
|
|
+ // ReposrtExpenses Listado de Gastos
|
|
|
+ local.ReposrtExpensesWidget = instance.Widget.extend({
|
|
|
+ template: 'ReposrtExpenses',
|
|
|
+ invoice: [],
|
|
|
+ Currency:[],
|
|
|
+ resCurrency :[],
|
|
|
+ resCompany:[],
|
|
|
+ accountJournal:[],
|
|
|
+ supplier:[],
|
|
|
+ newInvoice:[],
|
|
|
+ rowsData :[],
|
|
|
+ // event
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'change #current-journal' : 'factSearch',
|
|
|
+ 'change #current-currency' : 'factSearch',
|
|
|
+ 'change #from' : 'factSearch',
|
|
|
+ 'change #to' : 'factSearch',
|
|
|
+ 'click #volver_btn' : 'volver',
|
|
|
+ },
|
|
|
+ // Initil
|
|
|
+ init : function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+ // start
|
|
|
+ start: function () {
|
|
|
+ var self = this;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable({data : self.rowsData});
|
|
|
+ this.fecthFecha();
|
|
|
+ this.submitForm();
|
|
|
+ },
|
|
|
+ // volver
|
|
|
+ volver: function(){
|
|
|
+ this.$el.find('#volver').empty();
|
|
|
+ this.$el.find('.bootstrap-table').show({
|
|
|
+ effect: 'drop',
|
|
|
+ direction: 'down',
|
|
|
+ duration: 200,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Consultar
|
|
|
+ submitForm: function () {
|
|
|
+ var self = this;
|
|
|
+ self.fetchResCurency().then(function(resCurrency) {
|
|
|
+ return resCurrency;
|
|
|
+ }).then(function (resCurrency) {
|
|
|
+ self.resCurrency = resCurrency;
|
|
|
+ self.$el.find('#current-currency').append('<option value="9999999">Todas las monedas</option>');
|
|
|
+ _.each(resCurrency, function (item) {
|
|
|
+ self.$el.find('#current-currency').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ return self.fetchCurency(resCurrency);
|
|
|
+ }).then(function(Currency){
|
|
|
+ self.Currency = 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.fetchInvoiceP2();
|
|
|
+ }).then(function (invoice){
|
|
|
+ self.invoice = invoice;
|
|
|
+ return self.fetchSupplier(invoice);
|
|
|
+ }).then(function(supplier){
|
|
|
+ self.supplier=supplier;
|
|
|
+ return self.fecthComanyCurrency();
|
|
|
+ }).then(function(resCompany){
|
|
|
+ self.resCompany = resCompany;
|
|
|
+ self.inicializarBuscadorsup();
|
|
|
+ return self.fect_generar(self.invoice);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 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 instance.web.Model('account.journal');
|
|
|
+ Journal.query(['id', 'name']).filter([['type', '=', 'purchase']]).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Buscar Cambio de Monedas USD,PYG,ARG,BRL
|
|
|
+ fetchCurency: function (currency) {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency_id = _.flatten(_.map(currency,function(map){
|
|
|
+ return map.id;
|
|
|
+ }))
|
|
|
+ var currency_Rate = new instance.web.Model('res.currency.rate');
|
|
|
+ var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
|
|
|
+ var domain = [['currency_id', '=', currency_id]];
|
|
|
+ currency_Rate.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Moneda
|
|
|
+ fetchResCurency: function () {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency = new instance.web.Model('res.currency');
|
|
|
+ var fields = ['id', 'name'];
|
|
|
+ var domain = [['active', '=', true]];
|
|
|
+ currency.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Invoice (FACTURAS)
|
|
|
+ fetchInvoiceP2: function () {
|
|
|
+ var journal_ids = _.flatten(_.map(this.accountJournal, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ var filter =[['state', '=',['open','paid']],['type', '=', 'in_invoice'],['origin', '=', false],['journal_id', '=',journal_ids]];
|
|
|
+ var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'supplier_invoice_number','date_invoice','partner_id','amount_total','user_id'];
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var Invoice = new instance.web.Model('account.invoice');
|
|
|
+ Invoice.query(field).filter(filter).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // company_curency
|
|
|
+ fecthComanyCurrency: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency = new instance.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;
|
|
|
+ },
|
|
|
+ // Partner (Proveeedor)
|
|
|
+ fetchSupplier: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var supplier = new instance.web.Model('res.partner');
|
|
|
+ supplier.query(['id', 'name', 'ruc', 'active', 'supplier']).filter([['active', '=', true], ['supplier', '=', true]]).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Obtener el Cambio de la Moneda
|
|
|
+ getCurrency: function (id){
|
|
|
+ return _.find(this.Currency,function (curr) {
|
|
|
+ return _.contains(curr.currency_id,id);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Verificar si los Valores no son nulos
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor ="";
|
|
|
+ if (dato){
|
|
|
+ valor=dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+ // Buscador
|
|
|
+ inicializarBuscadorsup: function () {
|
|
|
+ var self = this;
|
|
|
+ var results = self.supplier;
|
|
|
+ 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.$('#customer').autocomplete({
|
|
|
+ source: results,
|
|
|
+ minLength:0,
|
|
|
+ search: function(event, ui) {
|
|
|
+ if (!(self.$('#customer').val())){
|
|
|
+ self.factSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.factSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // unir los objetos
|
|
|
+ fect_generar: function(invoices){
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ _.each(invoices, function(invoice){
|
|
|
+ data.push({
|
|
|
+ number: invoice.number,
|
|
|
+ supplier_invoice_number: self.valorNull(invoice.supplier_invoice_number),
|
|
|
+ partner: invoice.partner_id[1],
|
|
|
+ date: moment(invoice.date_invoice).format("DD/MM/YYYY"),
|
|
|
+ date_invoice: invoice.date_invoice,
|
|
|
+ user: invoice.user_id[1],
|
|
|
+ currency: invoice.currency_id[1],
|
|
|
+ amount_total: accounting.formatNumber(invoice.amount_total,2,".",","),
|
|
|
+ amount: invoice.amount_total,
|
|
|
+ journal_id : invoice.journal_id[0],
|
|
|
+ currency_id : invoice.currency_id[0],
|
|
|
+ partner_id : invoice.partner_id[0]
|
|
|
+ });
|
|
|
+ });
|
|
|
+ self.newInvoice = data;
|
|
|
+ this.loadTable(data);
|
|
|
+ },
|
|
|
+ // Buscar
|
|
|
+ factSearch: function(){
|
|
|
+ var self = this;
|
|
|
+ var desde =this.$el.find('#from').val();
|
|
|
+ var hasta =this.$el.find('#to').val();
|
|
|
+ var suc =this.$el.find('#current-journal').val();
|
|
|
+ var currency =this.$el.find('#current-currency').val();
|
|
|
+ var prov= this.$el.find('#customer').val().split('-');
|
|
|
+ var newInvoice = self.newInvoice;
|
|
|
+ // Buscar por Sucursales
|
|
|
+ if (suc != 9999999){
|
|
|
+ newInvoice=_.filter(newInvoice, function (inv){
|
|
|
+ return inv.journal_id == suc;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // Buscar por fecha Desde
|
|
|
+ if (desde.length > 0){
|
|
|
+ var date= desde.split('/');
|
|
|
+ newInvoice = _.filter(newInvoice, function (inv){
|
|
|
+ return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // Buscar por Fechas Hasta
|
|
|
+ if (hasta.length > 0){
|
|
|
+ var date= hasta.split('/');
|
|
|
+ newInvoice = _.filter(newInvoice, function (inv){
|
|
|
+ return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // Busacar por moneda
|
|
|
+ if(currency != 9999999){
|
|
|
+ newInvoice = _.filter(newInvoice,function(inv){
|
|
|
+ return inv.currency_id == currency;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // Busacara por proveedor
|
|
|
+ if (prov != ""){
|
|
|
+ newInvoice = _.filter(newInvoice, function(inv){
|
|
|
+ return inv.partner_id == prov[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ self.loadTable(newInvoice)
|
|
|
+ },
|
|
|
+ // cargara la tabla
|
|
|
+ loadTable:function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ self.rowsData = rowsTable;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable('load',rowsTable);
|
|
|
+ },
|
|
|
+ // Obtener Invoice por Monedad
|
|
|
+ getInvoice : function(currency_id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.rowsData, function(item){
|
|
|
+ return item.currency_id === currency_id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Crear Objete PDF
|
|
|
+ getObjetPdf: function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ var rowsPdf=[];
|
|
|
+ var rows=[];
|
|
|
+ var itemCurrecy;
|
|
|
+ var itenRow;
|
|
|
+ var item;
|
|
|
+ var curreRate;
|
|
|
+ var amount_total=0;
|
|
|
+ var amount=0;
|
|
|
+ var company = _.map(self.resCompany,function(map){return map.currency_id[1]});
|
|
|
+
|
|
|
+ for (var i = 0; i < self.resCurrency.length; i++) {
|
|
|
+ itemCurrecy = self.resCurrency[i];
|
|
|
+ itenRow = self.getInvoice(itemCurrecy.id);
|
|
|
+ rowsPdf=[];
|
|
|
+ if (itenRow.length > 0){
|
|
|
+ rowsPdf.push({number: itemCurrecy.name, supplier_invoice_number: "", partner: "", date: "", date_invoice: "", user: "", currency: "", amount_total: "", journal_id : "", currency_id : "", partner_id : ""});
|
|
|
+ _.each(itenRow, function(item){
|
|
|
+ rowsPdf.push({
|
|
|
+ number: item.number,
|
|
|
+ supplier_invoice_number: self.valorNull(item.supplier_invoice_number),
|
|
|
+ partner: item.partner,
|
|
|
+ date: moment(item.date_invoice).format("DD/MM/YYYY"),
|
|
|
+ date_invoice: item.date_invoice,
|
|
|
+ user: item.user,
|
|
|
+ currency: item.currency,
|
|
|
+ amount_total: accounting.formatNumber((item.amount),2,".",","),
|
|
|
+ amount: item.amount,
|
|
|
+ journal_id : item.journal_id,
|
|
|
+ currency_id : item.currency_id,
|
|
|
+ partner_id : item.partner_id
|
|
|
+ });
|
|
|
+ });
|
|
|
+ curreRate = self.getCurrency(itemCurrecy.id);
|
|
|
+ if (!curreRate){
|
|
|
+ curreRate={};
|
|
|
+ curreRate.rate=1;
|
|
|
+ }
|
|
|
+ amount_total= _.reduce(_.map(itenRow,function(map){
|
|
|
+ return(map.amount);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ amount = amount+(amount_total/curreRate.rate);
|
|
|
+ rowsPdf.push({
|
|
|
+ number: "Sub - Total "+itemCurrecy.name,
|
|
|
+ supplier_invoice_number: "",
|
|
|
+ partner: "",
|
|
|
+ date: "",
|
|
|
+ date_invoice: "",
|
|
|
+ user: "",
|
|
|
+ currency: "",
|
|
|
+ amount_total: accounting.formatNumber((amount_total),2,".",","),
|
|
|
+ journal_id : "",
|
|
|
+ currency_id : "",
|
|
|
+ partner_id : ""
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (rowsPdf.length >0){
|
|
|
+ rows = rows.concat(rowsPdf);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rows.length > 0){
|
|
|
+ rows.push({
|
|
|
+ number: "Total en "+company,
|
|
|
+ supplier_invoice_number: "",
|
|
|
+ partner: "",
|
|
|
+ date: "",
|
|
|
+ date_invoice: "",
|
|
|
+ user: "",
|
|
|
+ currency: "",
|
|
|
+ amount_total: accounting.formatNumber((amount),2,".",","),
|
|
|
+ journal_id : "",
|
|
|
+ currency_id : "",
|
|
|
+ partner_id : ""
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return rows;
|
|
|
+ },
|
|
|
+ // imprimir PDF
|
|
|
+ clickOnAction: function (e) {
|
|
|
+ var self = this;
|
|
|
+ var rowsNew;
|
|
|
+ var action = self.$el.find(e.target).val();
|
|
|
+ var table = self.$el.find("#table");
|
|
|
+ var data2 = table.bootstrapTable('getVisibleColumns');
|
|
|
+ var getColumns=[];
|
|
|
+ var rows=[];
|
|
|
+ rowsNew = self.getObjetPdf();
|
|
|
+ if (action === 'pdf') {
|
|
|
+ var dataNEW = _.map(data2, function (val){
|
|
|
+ return val.field;
|
|
|
+ });
|
|
|
+ _.each(rowsNew,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
|
|
|
+ }]);
|
|
|
+ });
|
|
|
+ this.drawPDF(_.flatten(getColumns),rows);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // Generar pdfDoc
|
|
|
+ drawPDF: function (getColumns,rows) {
|
|
|
+ var self = this;
|
|
|
+ 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();
|
|
|
+
|
|
|
+ pdfDoc.autoTable(getColumns, rows, {
|
|
|
+ styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
|
|
|
+ columnStyles: {
|
|
|
+ number : {columnWidth: '8px'},
|
|
|
+ supplier_invoice_number : {columnWidth: '8px'},
|
|
|
+ partner : {columnWidth: '8px'},
|
|
|
+ date : {columnWidth: '8px'},
|
|
|
+ user : {columnWidth: '8px'},
|
|
|
+ currency : {columnWidth: '8px'},
|
|
|
+ amount_total: {halign:'right',columnWidth: '8px'},
|
|
|
+ },
|
|
|
+ margin: { top: 16, horizontal: 7},
|
|
|
+
|
|
|
+ addPageContent: function (data) {
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Listado de Compras '+ 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;
|
|
|
+ }
|
|
|
+ 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('Listado de Gastos.pdf')
|
|
|
+ },
|
|
|
+ });
|
|
|
+ // Proximo Report
|
|
|
instance.web.client_actions.add('eiru_reporting.action_report', 'instance.eiru_reporting.ReportingWidget');
|
|
|
}
|