|
@@ -0,0 +1,694 @@
|
|
|
+function report_libro_venta(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var instance = openerp;
|
|
|
+
|
|
|
+ reporting.ReportLibroVentaWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportLibroVenta',
|
|
|
+ content: [],
|
|
|
+ rowsData :[],
|
|
|
+ invoices: [],
|
|
|
+ model: [],
|
|
|
+ AccountVoucher:[],
|
|
|
+ resCompany:[],
|
|
|
+ ResCurrency:[],
|
|
|
+ accountJournal:[],
|
|
|
+ modules:[],
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click #X' : 'factSearch',
|
|
|
+ 'click #A' : 'factSearch',
|
|
|
+ 'click #B' : 'factSearch',
|
|
|
+ 'click #C' : 'factSearch',
|
|
|
+ 'click #D' : 'factSearch',
|
|
|
+ 'click #Z' : 'factSearch',
|
|
|
+ 'change #from' : 'factSearch',
|
|
|
+ 'change #to' : 'factSearch',
|
|
|
+ 'change #user' : 'factSearch',
|
|
|
+ 'change #current-journal' : 'factSearch',
|
|
|
+ 'change #current-store' : 'factSearch',
|
|
|
+ 'click-row.bs.table #table ' : 'ckickAnalysisDetail',
|
|
|
+ },
|
|
|
+ init : function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+ start: function () {
|
|
|
+ var self = this;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable({data : self.rowsData});
|
|
|
+ this.fecthFecha();
|
|
|
+ this.submitForm();
|
|
|
+ },
|
|
|
+
|
|
|
+ // 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
|
|
|
+ },
|
|
|
+
|
|
|
+ ckickAnalysisDetail: function(e, row, $element, field){
|
|
|
+ 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,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (field === 'partner'){
|
|
|
+ this.do_action({
|
|
|
+ name:"Registro",
|
|
|
+ type: 'ir.actions.act_window',
|
|
|
+ res_model: "res.partner",
|
|
|
+ views: [[false,'form']],
|
|
|
+ target: 'new',
|
|
|
+ domain: [['id','=', row.partner_id]],
|
|
|
+ context: {},
|
|
|
+ flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ res_id: row.partner_id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ e.stopImmediatePropagation();
|
|
|
+ },
|
|
|
+ submitForm: function () {
|
|
|
+ var self = this;
|
|
|
+ self.fecthIrModuleModule().then(function(modules){
|
|
|
+ self.modules = modules;
|
|
|
+ return modules;
|
|
|
+ }).then(function(modules){
|
|
|
+ return self.fecthResStore();
|
|
|
+ }).then(function(ResStore){
|
|
|
+ self.ResStore = ResStore;
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las SUC.</option>');
|
|
|
+ _.each(ResStore,function(item){
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ return self.fecthAccountJournal();
|
|
|
+ }).then(function(AccountJournal){
|
|
|
+ self.AccountJournal = AccountJournal;
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todas las formas de pagos</option>');
|
|
|
+ _.each(AccountJournal,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.fetchAccountVoucher();
|
|
|
+ }).then(function (AccountVoucher) {
|
|
|
+ self.AccountVoucher = AccountVoucher;
|
|
|
+ return self.fetchResPartner();
|
|
|
+ }).then(function(ResPartner){
|
|
|
+ self.ResPartner = ResPartner;
|
|
|
+ return self.fetchResCurrency();
|
|
|
+ }).then(function(ResCurrency){
|
|
|
+ self.ResCurrency = ResCurrency;
|
|
|
+ return self.fecthCompanyCurrency();
|
|
|
+ }).then(function(resCompany){
|
|
|
+ self.resCompany = resCompany;
|
|
|
+ return self.fecthResUser();
|
|
|
+ }).then(function (ResUser) {
|
|
|
+ self.ResUser = ResUser;
|
|
|
+ self.search();
|
|
|
+ self.searchUser();
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ fecthResStore: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var field=['id', 'name'];
|
|
|
+ var ResStore = new instance.web.Model('res.store');
|
|
|
+ ResStore.query(field).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fecthAccountJournal: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var field = ['id', 'name','store_ids'];
|
|
|
+ var domain = [['active','=',true]];
|
|
|
+ var AccountJournal = new instance.web.Model('account.journal');
|
|
|
+ AccountJournal.query(field).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResCurrency : function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
|
|
|
+ var domain = [['active', '=', true]];
|
|
|
+ var ResCurrency = new instance.web.Model('res.currency');
|
|
|
+ ResCurrency.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fecthCompanyCurrency: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var field=['id','name', 'currency_id'];
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ // 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', 'state', 'journal_id', 'currency_id', 'user_id','date_invoice','amount_total','amount_tax','amount_untaxed','partner_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;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchAccountVoucher: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var AccountVoucher = new instance.web.Model('account.voucher');
|
|
|
+ AccountVoucher.query(['id', 'number','reference','journal_id','type']).filter([['state', '=', 'posted']]).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResPartner: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var ResPartner = new instance.web.Model('res.partner');
|
|
|
+ ResPartner.query(['id', 'name', 'ruc']).filter([['active', '=', true], ['customer', '=', true]]).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ 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.factSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ close: function( event, ui ) {
|
|
|
+ self.factSearch();
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.factSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // Consultar Usuario
|
|
|
+ fecthResUser: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var user_ids = _.map(self.invoices,function(map){
|
|
|
+ return map.user_id[0];
|
|
|
+ });
|
|
|
+ var fields = ['id', 'name'];
|
|
|
+ var domain = [['id', 'in', user_ids]];
|
|
|
+ var ResUsers = new instance.web.Model('res.users');
|
|
|
+ ResUsers.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ searchUser: function () {
|
|
|
+ var self = this;
|
|
|
+ var results = self.ResUser;
|
|
|
+ results = _.map(results, function (item) {
|
|
|
+ return {
|
|
|
+ label: item.id + '-'+ item.name,
|
|
|
+ value: item.id + '-'+ item.name
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.$('#user').autocomplete({
|
|
|
+ source: results,
|
|
|
+ minLength:0,
|
|
|
+ searchUser: function(event, ui) {
|
|
|
+ if (!(self.$('#user').val())){
|
|
|
+ self.factSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ close: function( event, ui ) {
|
|
|
+ self.factSearch();
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.factSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountJournal: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.AccountJournal,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getResPartner: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResPartner,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountVoucher: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.AccountVoucher,function (item) {
|
|
|
+ return item.reference === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getResCurrency: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCurrency,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ getSaleOrder:function(partner_id) {
|
|
|
+ var self = this;
|
|
|
+ return _.flatten(_.filter(self.invoices,function (inv) {
|
|
|
+ return inv.user_id[0] === partner_id;
|
|
|
+ }));
|
|
|
+ },
|
|
|
+
|
|
|
+ BuildTable: function(){
|
|
|
+ var self = this;
|
|
|
+ var invoices = self.invoices;
|
|
|
+ var CurrencyBase = self.getResCurrency(self.resCompany[0].currency_id[0]).shift();
|
|
|
+ var order = [];
|
|
|
+ var data = [];
|
|
|
+ var store = [];
|
|
|
+ var partner = [];
|
|
|
+ var amount_total_total = 0;
|
|
|
+ _.each(invoices, function(item){
|
|
|
+ order = self.getSaleOrder(item.user_id[0]);
|
|
|
+ store= self.getAccountJournal(item.journal_id[0]);
|
|
|
+ partner= self.getResPartner(item.partner_id[0]);
|
|
|
+ var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
+ var voucher = self.getAccountVoucher(item.number).shift();
|
|
|
+ var pago = '';
|
|
|
+ var pago_name = '';
|
|
|
+ var untaxed = 0;
|
|
|
+ var exentas = 0;
|
|
|
+ var iva_10 = 0;
|
|
|
+ // Determinar si fue aplicado algun impuesto a la factura.
|
|
|
+ if(item.amount_total == item.amount_untaxed){
|
|
|
+ exentas = accounting.formatNumber(item.amount_untaxed,"","");
|
|
|
+ }else{
|
|
|
+ // // Si fue aplicado impuesto, determina si fue de 10% o 5%.
|
|
|
+ // if(IVA == TAX){
|
|
|
+ untaxed = accounting.formatNumber(item.amount_untaxed,"","");
|
|
|
+ iva_10 = accounting.formatNumber(item.amount_tax,"","");
|
|
|
+ // tasa_10 = accounting.formatNumber(invoice.amount_untaxed,"","");
|
|
|
+ // }else{
|
|
|
+ // iva_5 = accounting.formatNumber(invoice.amount_tax,"","");;
|
|
|
+ // tasa_5 = accounting.formatNumber(invoice.amount_untaxed,"","");
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (voucher != undefined){
|
|
|
+ pago = voucher.journal_id[0];
|
|
|
+ pago_name=voucher.journal_id[1];
|
|
|
+ }else{
|
|
|
+ pago = '';
|
|
|
+ pago_name= '';
|
|
|
+ }
|
|
|
+ if(order.length > 0 & store.length > 0){
|
|
|
+ data.push({
|
|
|
+ id : item.id,
|
|
|
+ number: item.number,
|
|
|
+ partner: item.partner_id[1],
|
|
|
+ date_invoice: moment(item.date_invoice).format("DD/MM/YYYY"),
|
|
|
+ amount_tax: accounting.formatNumber((iva_10 * (CurrencyBase.rate_silent/currency.rate_silent)),0,".",","),
|
|
|
+ amount_untaxed: accounting.formatNumber((untaxed * (CurrencyBase.rate_silent/currency.rate_silent)),0,".",","),
|
|
|
+ amount_exentas: accounting.formatNumber((exentas * (CurrencyBase.rate_silent/currency.rate_silent)),0,".",","),
|
|
|
+ amount_total: accounting.formatNumber((item.amount_total * (CurrencyBase.rate_silent/currency.rate_silent)),0,".",","),
|
|
|
+ date: item.date_invoice,
|
|
|
+ partner_id : item.partner_id[0],
|
|
|
+ ruc: partner[0].ruc,
|
|
|
+ tax : (iva_10 * (CurrencyBase.rate_silent/currency.rate_silent)),
|
|
|
+ untaxed : (untaxed * (CurrencyBase.rate_silent/currency.rate_silent)),
|
|
|
+ exentas: (exentas * (CurrencyBase.rate_silent/currency.rate_silent)),
|
|
|
+ amount : (item.amount_total * (CurrencyBase.rate_silent/currency.rate_silent)),
|
|
|
+ journal_id: pago,
|
|
|
+ journal_name: pago_name,
|
|
|
+ user_id : item.user_id[0],
|
|
|
+ user: item.user_id[1],
|
|
|
+ store_id : store[0].store_ids[0]
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.content = data;
|
|
|
+ this.loadTable(data);
|
|
|
+ },
|
|
|
+
|
|
|
+ factSearch: 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 user= this.$el.find('#user').val();
|
|
|
+ var desde =this.$el.find('#from').val();
|
|
|
+ var hasta =this.$el.find('#to').val();
|
|
|
+ var partner= this.$el.find('#partner').val().split('-');
|
|
|
+ var journal = this.$el.find('#current-journal').val();
|
|
|
+ var store = this.$el.find('#current-store').val();
|
|
|
+ var content = self.content;
|
|
|
+
|
|
|
+ if ($('#A').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date).format('YYYY-MM-DD') == today;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#B').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date).format('YYYY-MM-DD') == yesterday;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#C').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date).format('YYYY-MM') == month;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#D').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date).format('YYYY-MM') == last_month;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#Z').is(":checked")){
|
|
|
+ $('#datepicker').css('display','block');
|
|
|
+ if (desde.length > 0){
|
|
|
+ var date= desde.split('/');
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.date >= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (hasta.length > 0){
|
|
|
+ var date= hasta.split('/');
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.date <= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $('#datepicker').css('display','none');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (partner != ""){
|
|
|
+ content = _.filter(content, function(inv){
|
|
|
+ return inv.partner_id == partner[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (user != ""){
|
|
|
+ content = _.filter(content,function(inv){
|
|
|
+ return inv.user_id == user[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (store != 9999999){
|
|
|
+ content =_.filter(content, function (inv){
|
|
|
+ return inv.store_id == store;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if(journal != 9999999){
|
|
|
+ content =_.filter(content, function (inv){
|
|
|
+ return inv.journal_id == journal;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ var amount_total_tax = _.reduce(_.map(content,function(map){
|
|
|
+ return(map.tax);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+
|
|
|
+ var amount_total_untaxed = _.reduce(_.map(content,function(map){
|
|
|
+ return(map.untaxed);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+
|
|
|
+ var amount_total_exentas = _.reduce(_.map(content,function(map){
|
|
|
+ return(map.exentas);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+
|
|
|
+ var amount_total_total = _.reduce(_.map(content,function(map){
|
|
|
+ return(map.amount);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+
|
|
|
+ content.push({
|
|
|
+ number: "Total",
|
|
|
+ amount_tax : accounting.formatNumber((amount_total_tax),0,".",","),
|
|
|
+ amount_untaxed : accounting.formatNumber((amount_total_untaxed),0,".",","),
|
|
|
+ amount_exentas : accounting.formatNumber((amount_total_exentas),0,".",","),
|
|
|
+ amount_total: accounting.formatNumber((amount_total_total),0,".",","),
|
|
|
+ });
|
|
|
+
|
|
|
+ self.loadTable(content)
|
|
|
+ },
|
|
|
+
|
|
|
+ loadTable:function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ self.rowsData = rowsTable;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable('load',rowsTable);
|
|
|
+ },
|
|
|
+
|
|
|
+ getObjetPdf: function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ var rows=self.rowsData;
|
|
|
+
|
|
|
+ return rows;
|
|
|
+ },
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ drawPDF: function (getColumns,rows) {
|
|
|
+ var self = this;
|
|
|
+ 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: 7, columnWidth: 'wrap'},
|
|
|
+ columnStyles: {
|
|
|
+ number : {columnWidth: 15},
|
|
|
+ ruc : {columnWidth: 20},
|
|
|
+ partner : {columnWidth: 20},
|
|
|
+ date_invoice : {columnWidth: 18},
|
|
|
+ amount_tax : {halign:'right',columnWidth: 18},
|
|
|
+ amount_untaxed : {halign:'right',columnWidth: 18},
|
|
|
+ amount_exentas : {halign:'right',columnWidth: 18},
|
|
|
+ ref_iva : {columnWidth: 10},
|
|
|
+ ref_renta : {columnWidth: 10},
|
|
|
+ amount_total : {halign:'right',columnWidth: 18},
|
|
|
+ journal_name : {columnWidth: 15},
|
|
|
+ user : {halign:'left',columnWidth: 14},
|
|
|
+ },
|
|
|
+ margin: { top: 16, horizontal: 7},
|
|
|
+ addPageContent: function (data) {
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Libro 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('Libro de Venta.pdf')
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|