|
@@ -0,0 +1,829 @@
|
|
|
+function report_libro_venta_pos(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var instance = openerp;
|
|
|
+
|
|
|
+ reporting.ReportLibroVentaPosWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportLibroVentaPos',
|
|
|
+ content: [],
|
|
|
+ rowsData :[],
|
|
|
+ invoices: [],
|
|
|
+ PosOrder :[],
|
|
|
+ ResUser :[],
|
|
|
+ AccountJournal:[],
|
|
|
+ accountJournal:[],
|
|
|
+ accountJournalPos:[],
|
|
|
+ modules: ['point_of_sale'],
|
|
|
+ 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 == 'ref'){
|
|
|
+ this.do_action({
|
|
|
+ name:"Pos",
|
|
|
+ type: 'ir.actions.act_window',
|
|
|
+ res_model: "pos.order",
|
|
|
+ views: [[false,'form']],
|
|
|
+ target: 'new',
|
|
|
+ domain: [['id','=', row.id]],
|
|
|
+ context: {},
|
|
|
+ flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ res_id: row.id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ e.stopImmediatePropagation();
|
|
|
+ },
|
|
|
+ submitForm: function () {
|
|
|
+ var self = this;
|
|
|
+ self.fecthIrModuleModule().then(function(modules){
|
|
|
+ self.modules = modules;
|
|
|
+ return modules;
|
|
|
+ }).then(function(modules){
|
|
|
+ return self.fetchPosOrder();
|
|
|
+ }).then(function(PosOrder) {
|
|
|
+ self.PosOrder = PosOrder;
|
|
|
+ self.fecthCheckType();
|
|
|
+ return self.fetchStatementLine(PosOrder);
|
|
|
+ }).then(function(StatementLine){
|
|
|
+ self.StatementLine=StatementLine;
|
|
|
+ return self.fecthAccountJournalPos();
|
|
|
+ }).then(function(AccountJournalPos){
|
|
|
+ self.AccountJournalPos = AccountJournalPos;
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todas los metodos de pago.</option>');
|
|
|
+ _.each(AccountJournalPos,function(item){
|
|
|
+ if(item.type == 'cash' || item.type == 'bank'){
|
|
|
+ self.$el.find('#current-journal').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.fetchResPartner();
|
|
|
+ }).then(function(ResPartner){
|
|
|
+ self.ResPartner = ResPartner;
|
|
|
+ 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.fecthResUser();
|
|
|
+ }).then(function (ResUser) {
|
|
|
+ self.ResUser = ResUser;
|
|
|
+ return self.fecthCompanyCurrency();
|
|
|
+ }).then(function(resCompany){
|
|
|
+ self.resCompany = resCompany;
|
|
|
+ return self.fetchResCurrency();
|
|
|
+ }).then(function(ResCurrency){
|
|
|
+ self.ResCurrency = ResCurrency;
|
|
|
+ return self.fetchProductPricelist();
|
|
|
+ }).then(function(ProductPricelist){
|
|
|
+ self.ProductPricelist = ProductPricelist;
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ 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],['type','in',['sale','bank','cash']]];
|
|
|
+ var AccountJournal = new instance.web.Model('account.journal');
|
|
|
+ AccountJournal.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;
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountJournal: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.AccountJournal,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ fecthAccountJournalPos: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var field = ['id', 'name','store_ids','type'];
|
|
|
+ var domain = [['active','=',true],['type','in',['sale','bank','cash']]];
|
|
|
+ var AccountJournalPos = new instance.web.Model('account.journal');
|
|
|
+ AccountJournalPos.query(field).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchPosOrder: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var modules = self.checkModel('point_of_sale');
|
|
|
+ if (modules.length > 0){
|
|
|
+ var filter =[['state', 'in',['done','paid','invoiced']]];
|
|
|
+ var field =['id', 'partner_id','name', 'session_id', 'state', 'table_id', 'statement_ids','create_date','amount_total','user_id','amount_tax', 'pricelist_id', 'sale_journal'];
|
|
|
+ var PosOrder = new instance.web.Model('pos.order');
|
|
|
+ PosOrder.query(field).filter(filter).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ }else{
|
|
|
+ var PosOrder = [];
|
|
|
+ return PosOrder;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchProductPricelist : function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name','currency_id'];
|
|
|
+ var domain = [['active', '=', true],['type', '=', 'sale']];
|
|
|
+ var ProductPricelist = new instance.web.Model('product.pricelist');
|
|
|
+ ProductPricelist.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchStatementLine: function(PosOrder) {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+
|
|
|
+ var fields = ['id', 'name', 'amount', 'journal_id', 'pricelist_id','pos_statement_id'];
|
|
|
+ var domain = [['amount','>', 0]];
|
|
|
+ var StatementLine = new instance.web.Model('account.bank.statement.line');
|
|
|
+ StatementLine.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fecthCheckType: function(){
|
|
|
+ var self = this;
|
|
|
+ var modules = self.checkModel('point_of_sale');
|
|
|
+ if(modules.length == 0){
|
|
|
+ self.$el.find('.type').css('display','none');
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ getStatementLine: function(id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.StatementLine, function(item){
|
|
|
+ return item.pos_statement_id[0] === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountJournalPos: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.AccountJournalPos,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getProductPricelist: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ProductPricelist,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ 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;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getResCurrency: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCurrency,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;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ 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 CurrencyBase = self.getResCurrency(self.resCompany[0].currency_id[0]).shift();
|
|
|
+ var invoices = self.invoices;
|
|
|
+ var PosOrder = self.PosOrder;
|
|
|
+ var order = [];
|
|
|
+ var partner;
|
|
|
+ var data = [];
|
|
|
+ var store = [];
|
|
|
+ var amount_total_total = 0;
|
|
|
+ _.each(invoices, function(item){
|
|
|
+ order = self.getSaleOrder(item.user_id[0]);
|
|
|
+ partner= self.getResPartner(item.partner_id[0]);
|
|
|
+ var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
+ store= self.getAccountJournal(item.journal_id[0]);
|
|
|
+ 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{
|
|
|
+ untaxed = accounting.formatNumber(item.amount_untaxed,"","");
|
|
|
+ iva_10 = accounting.formatNumber(item.amount_tax,"","");
|
|
|
+ }
|
|
|
+
|
|
|
+ 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,
|
|
|
+ ref: "",
|
|
|
+ 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: moment(item.date_invoice).format("YYYY-MM-DD"),
|
|
|
+ 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: item.journal_id[0],
|
|
|
+ journal_name: item.journal_id[1],
|
|
|
+ user_id : item.user_id[0],
|
|
|
+ user: item.user_id[1],
|
|
|
+ store_id : store[0].store_ids[0]
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ _.each(PosOrder, function(item){
|
|
|
+ order = self.getStatementLine(item.id);
|
|
|
+ store = self.getAccountJournalPos(item.sale_journal[0]);
|
|
|
+ var pricelist = self.getProductPricelist(item.pricelist_id[0]).shift();
|
|
|
+ var currency = self.getResCurrency(pricelist.currency_id[0]).shift();
|
|
|
+ var untaxed = 0;
|
|
|
+ var exentas = 0;
|
|
|
+ var iva_10 = 0;
|
|
|
+ if(item.amount_tax == 0){
|
|
|
+ exentas = accounting.formatNumber(item.amount_total,"","");
|
|
|
+ }else{
|
|
|
+ untaxed = accounting.formatNumber((item.amount_total-item.amount_tax),"","");
|
|
|
+ iva_10 = accounting.formatNumber(item.amount_tax,"","");
|
|
|
+ }
|
|
|
+ if(order.length > 0 & store.length > 0){
|
|
|
+ var utc = moment.utc(item.create_date,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ var date = moment(utc._d).format('DD/MM/YYYY h:mm A');
|
|
|
+ var date_aux=moment(utc._d).format('YYYY-MM-DD');
|
|
|
+
|
|
|
+ data.push({
|
|
|
+ id : item.id,
|
|
|
+ number: "",
|
|
|
+ ref: item.name,
|
|
|
+ origin: item.session_id[1],
|
|
|
+ partner: item.partner_id[1],
|
|
|
+ date_invoice: date,
|
|
|
+ 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: date_aux,
|
|
|
+ partner_id : item.partner_id[0],
|
|
|
+ amount : (item.amount_total * (CurrencyBase.rate_silent/currency.rate_silent)),
|
|
|
+ journal_id: order[0].journal_id[0],
|
|
|
+ journal_name: order[0].journal_id[1],
|
|
|
+ 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)),
|
|
|
+ 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;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ 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: 17},
|
|
|
+ ref : {columnWidth: 15},
|
|
|
+ ruc : {columnWidth: 18},
|
|
|
+ partner : {columnWidth: 20},
|
|
|
+ date_invoice : {columnWidth: 18},
|
|
|
+ amount_tax : {halign:'right',columnWidth: 17},
|
|
|
+ amount_untaxed : {halign:'right',columnWidth: 17},
|
|
|
+ amount_exentas : {halign:'right',columnWidth: 17},
|
|
|
+ ref_iva : {columnWidth: 8},
|
|
|
+ ref_renta : {columnWidth: 8},
|
|
|
+ amount_total : {halign:'right',columnWidth: 17},
|
|
|
+ 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')
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|