|
@@ -0,0 +1,809 @@
|
|
|
|
+function report_ventas_fidelizacion(reporting){
|
|
|
|
+ "use strict";
|
|
|
|
+
|
|
|
|
+ var model = openerp;
|
|
|
|
+
|
|
|
|
+ reporting.ReportVentasWidget = reporting.Base.extend({
|
|
|
|
+ template: 'ReportVentas',
|
|
|
|
+ rowsData :[],
|
|
|
|
+ content :[],
|
|
|
|
+ modules: ['point_of_sale'],
|
|
|
|
+
|
|
|
|
+ events:{
|
|
|
|
+ 'click #generate' : 'fetchGenerate',
|
|
|
|
+ 'change #current-company' : 'updateSelections',
|
|
|
|
+ 'change #current-date' : 'ShowDateRange',
|
|
|
|
+ 'click .print-report':'clickOnAction',
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ init : function(parent){
|
|
|
|
+ this._super(parent);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ start: function () {
|
|
|
|
+ var table = this.$el.find('#table');
|
|
|
|
+ table.bootstrapTable({data : self.rowsData});
|
|
|
|
+ var date = new model.eiru_reports.ReportDatePickerWidget(self);
|
|
|
|
+ date.fecthFecha();
|
|
|
|
+ this.fetchInitial();
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ checkModel : function(model){
|
|
|
|
+ var self = this;
|
|
|
|
+ return _.filter(self.IrModuleModule,function(item){
|
|
|
|
+ return item.name === model;
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ valorNull:function(dato){
|
|
|
|
+ var valor = "";
|
|
|
|
+ if (dato){
|
|
|
|
+ valor = dato;
|
|
|
|
+ }
|
|
|
|
+ return valor;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ ShowDateRange : function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
|
+ if(date == 'range'){
|
|
|
|
+ self.$el.find('.datepicker').css('display','block');
|
|
|
|
+ }
|
|
|
|
+ if(date != 'range'){
|
|
|
|
+ self.$el.find('.datepicker').css('display','none');
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchInitial: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ self.fetchIntialSQL().then(function (IntialSQL) {
|
|
|
|
+ return IntialSQL;
|
|
|
|
+ }).then(function(IntialSQL) {
|
|
|
|
+ /*
|
|
|
|
+ =================================
|
|
|
|
+ RES COMPANY
|
|
|
|
+ =================================
|
|
|
|
+ */
|
|
|
|
+ self.ResCompany = IntialSQL.companies;
|
|
|
|
+ self.CompanyLogo = IntialSQL.logo;
|
|
|
|
+ if(self.ResCompany.length > 1){
|
|
|
|
+ self.$el.find('#current-company').append('<option value="9999999">Todas las empresas</option>');
|
|
|
|
+ _.each(self.ResCompany,function(item){
|
|
|
|
+ self.$el.find('#current-company').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ });
|
|
|
|
+ }else{
|
|
|
|
+ self.$el.find('.company').css('display','none');
|
|
|
|
+ }
|
|
|
|
+ /*
|
|
|
|
+ =================================
|
|
|
|
+ RES STORE
|
|
|
|
+ =================================
|
|
|
|
+ */
|
|
|
|
+ self.ResStore = IntialSQL.stores;
|
|
|
|
+ if(self.ResStore.length > 1){
|
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
|
|
|
|
+ _.each(self.ResStore,function(item){
|
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ });
|
|
|
|
+ }else{
|
|
|
|
+ self.$el.find('.store').css('display','none');
|
|
|
|
+ }
|
|
|
|
+ /*
|
|
|
|
+ =================================
|
|
|
|
+ RES PARTNER
|
|
|
|
+ =================================
|
|
|
|
+ */
|
|
|
|
+ self.ResPartner = IntialSQL.partner;
|
|
|
|
+ if(self.ResPartner.length > 1){
|
|
|
|
+ self.$el.find('#current-customer').append('<option value="9999999">Todas los clientes</option>');
|
|
|
|
+ _.each(self.ResPartner,function(item){
|
|
|
|
+ self.$el.find('#current-customer').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ });
|
|
|
|
+ }else{
|
|
|
|
+ self.$el.find('.customer').css('display','none');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ =================================
|
|
|
|
+ RES USERS
|
|
|
|
+ =================================
|
|
|
|
+ */
|
|
|
|
+ self.ResUsers = IntialSQL.users;
|
|
|
|
+ var store_ids = _.flatten(_.map(self.ResStore, function (item) {
|
|
|
|
+ return item.id;
|
|
|
|
+ }));
|
|
|
|
+ var ResUsers = _.flatten(_.filter(self.ResUsers,function (item) {
|
|
|
|
+ return _.contains(store_ids, item.store_id);
|
|
|
|
+ }));
|
|
|
|
+ if(ResUsers.length > 0){
|
|
|
|
+ self.$el.find('#current-user').append('<option value="9999999">Todos los Vendedores</option>');
|
|
|
|
+ _.each(ResUsers,function(item){
|
|
|
|
+ self.$el.find('#current-user').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ });
|
|
|
|
+ }else{
|
|
|
|
+ self.$el.find('.users').css('display','none');
|
|
|
|
+ }
|
|
|
|
+ return self.fethIrModuleModule();
|
|
|
|
+ }).then(function(IrModuleModule) {
|
|
|
|
+ self.IrModuleModule = IrModuleModule;
|
|
|
|
+ return self.fethCheckType();
|
|
|
|
+ });
|
|
|
|
+ self.$el.find('#generate').css('display','inline');
|
|
|
|
+ return;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchGenerate: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ self.$el.find('.search-form').block({
|
|
|
|
+ message: null,
|
|
|
|
+ overlayCSS: {
|
|
|
|
+ backgroundColor: '#FAFAFA'
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ self.$el.find('.report-form').block({
|
|
|
|
+ message: null,
|
|
|
|
+ overlayCSS: {
|
|
|
|
+ backgroundColor: '#FAFAFA'
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ this.fetchDataSQL().then(function(DataSQL) {
|
|
|
|
+ return DataSQL;
|
|
|
|
+ }).then(function (DataSQL) {
|
|
|
|
+ self.ResPartner = DataSQL.partners;
|
|
|
|
+ self.AccountInvoice = DataSQL.invoices;
|
|
|
|
+ self.PosOrder = DataSQL.orders;
|
|
|
|
+
|
|
|
|
+ return self.BuildTable();
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchIntialSQL: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var data = $.get('/report-filter-data-baco');
|
|
|
|
+ return data;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchDataSQL: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var data = $.get('/report-sale-history-baco');
|
|
|
|
+ return data;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fethIrModuleModule: function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var fields = ['name','id'];
|
|
|
|
+ var domain=[['state','=','installed'],['name','in',self.modules]];
|
|
|
|
+ var IrModuleModule = new model.web.Model('ir.module.module');
|
|
|
|
+ IrModuleModule.query(fields).filter(domain).all().then(function(results){
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*=====================================================================
|
|
|
|
+ Check type
|
|
|
|
+ =====================================================================*/
|
|
|
|
+ fethCheckType: function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var modules = self.checkModel('point_of_sale');
|
|
|
|
+ if(modules.length == 0){
|
|
|
|
+ self.$el.find('.type').css('display','none');
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ UPDATE SELECTIONS
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ updateSelections: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ var store;
|
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
|
+ if(company != 9999999){
|
|
|
|
+ store = self.$el.find('#current-store').empty();
|
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
|
|
|
|
+ _.each(self.ResStore,function(item){
|
|
|
|
+ if(parseFloat(company) == item.company_id[0]){
|
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }else{
|
|
|
|
+ store = self.$el.find('#current-store').empty();
|
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
|
|
|
|
+ _.each(self.ResStore,function(item){
|
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getPosOrder:function(partner_id) {
|
|
|
|
+ var self = this;
|
|
|
|
+
|
|
|
|
+ var content = _.filter(self.PosOrder,function(item){
|
|
|
|
+ return item.customer_id == partner_id;
|
|
|
|
+ });
|
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
|
+ var state = self.$el.find('#current-state').val();
|
|
|
|
+ var type = self.$el.find('#current-type').val();
|
|
|
|
+ var sale_type = self.$el.find('#current-sale-type').val();
|
|
|
|
+ var user = self.$el.find('#current-user').val();
|
|
|
|
+ var customer = self.$el.find('#current-customer').val();
|
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
|
+
|
|
|
|
+ if((store && store == 9999999)||(company && company == 9999999)){
|
|
|
|
+ var store_ids = _.flatten(_.map(self.ResStore, function (item) {
|
|
|
|
+ return item.id;
|
|
|
|
+ }));
|
|
|
|
+ var company_ids = _.flatten(_.map(self.ResCompany, function (item) {
|
|
|
|
+ return item.id;
|
|
|
|
+ }));
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return _.contains(store_ids, item.store_id) && _.contains(company_ids, item.company_id);
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(company && company != 9999999){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.company_id == company;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(store && store != 9999999){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.store_id == store;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(state && state != 9999999){
|
|
|
|
+ if(state == 'open'){
|
|
|
|
+ content = [];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(type && type != 9999999){
|
|
|
|
+ if(type == 'sale'){
|
|
|
|
+ content = [];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(sale_type && sale_type != 9999999){
|
|
|
|
+ if(sale_type == 'local'){
|
|
|
|
+ content = [];
|
|
|
|
+ }
|
|
|
|
+ if(sale_type == 'envio'){
|
|
|
|
+ content = [];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(user && user != 9999999){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.user_id == user;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(customer && customer != 9999999){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.customer_id == customer;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(date && date != 9999999){
|
|
|
|
+ if(date == 'range'){
|
|
|
|
+ if(desde){
|
|
|
|
+ date = desde.split('/');
|
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
|
+ var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
|
|
|
|
+ utc = moment(utc._d).format('YYYY-MM-DD');
|
|
|
|
+ return moment(utc).format('YYYY-MM-DD') >= date;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(hasta){
|
|
|
|
+ date = hasta.split('/');
|
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
|
+ var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
|
|
|
|
+ utc = moment(utc._d).format('YYYY-MM-DD');
|
|
|
|
+ return moment(utc).format('YYYY-MM-DD') <= date;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(date == 'today'){
|
|
|
|
+ var today = moment().format('YYYY-MM-DD');
|
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
|
+ var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
|
|
|
|
+ utc = moment(utc._d).format('YYYY-MM-DD');
|
|
|
|
+ return moment(utc).format('YYYY-MM-DD') === today;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(date == 'yesterday'){
|
|
|
|
+ var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
|
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
|
+ var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
|
|
|
|
+ utc = moment(utc._d).format('YYYY-MM-DD');
|
|
|
|
+ return moment(utc).format('YYYY-MM-DD') === yesterday;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(date == 'currentMonth'){
|
|
|
|
+ var currentMonth = moment().format('YYYY-MM');
|
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
|
+ var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
|
|
|
|
+ utc = moment(utc._d).format('YYYY-MM-DD');
|
|
|
|
+ return moment(utc).format('YYYY-MM') === currentMonth;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(date == 'lastMonth'){
|
|
|
|
+ var lastMonth = moment().add(-1,'months').format('YYYY-MM');
|
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
|
+ var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
|
|
|
|
+ utc = moment(utc._d).format('YYYY-MM-DD');
|
|
|
|
+ return moment(utc).format('YYYY-MM') === lastMonth;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ var suma =0;
|
|
|
|
+ _.each(content,function(item){
|
|
|
|
+ suma = suma + item.amount
|
|
|
|
+ });
|
|
|
|
+ return [content,suma];
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getAccountInvoice:function(partner_id) {
|
|
|
|
+ var self = this;
|
|
|
|
+ var content = _.filter(self.AccountInvoice,function(item){
|
|
|
|
+ return item.customer_id == partner_id;
|
|
|
|
+ });
|
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
|
+ var state = self.$el.find('#current-state').val();
|
|
|
|
+ var type = self.$el.find('#current-type').val();
|
|
|
|
+ var sale_type = self.$el.find('#current-sale-type').val();
|
|
|
|
+ var user = self.$el.find('#current-user').val();
|
|
|
|
+ var customer = self.$el.find('#current-customer').val();
|
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
|
+
|
|
|
|
+ if((store && store == 9999999)||(company && company == 9999999)){
|
|
|
|
+ var store_ids = _.flatten(_.map(self.ResStore, function (item) {
|
|
|
|
+ return item.id;
|
|
|
|
+ }));
|
|
|
|
+ var company_ids = _.flatten(_.map(self.ResCompany, function (item) {
|
|
|
|
+ return item.id;
|
|
|
|
+ }));
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return _.contains(store_ids, item.store_id) && _.contains(company_ids, item.company_id);
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(company && company != 9999999){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.company_id == company;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(store && store != 9999999){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.store_id == store;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(state && state != 9999999){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.state == state;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(type && type != 9999999){
|
|
|
|
+ if(type == 'tpv'){
|
|
|
|
+ content = [];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(sale_type && sale_type != 9999999){
|
|
|
|
+ if(sale_type == 'local'){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.is_delivery == true && item.delivery_type == 'local';
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(sale_type == 'envio'){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.is_delivery == true && item.delivery_type == 'envio';
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(sale_type == 'tienda'){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.is_delivery != true;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(user && user != 9999999){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.user_id == user;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(customer && customer != 9999999){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.customer_id == customer;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(date && date != 9999999){
|
|
|
|
+ if(date == 'range'){
|
|
|
|
+ if(desde){
|
|
|
|
+ date = desde.split('/');
|
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
|
+ return moment(inv.date).format('YYYY-MM-DD') >= date;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(hasta){
|
|
|
|
+ date = hasta.split('/');
|
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
|
+ return moment(inv.date).format('YYYY-MM-DD') <= date;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(date == 'today'){
|
|
|
|
+ var today = moment().format('YYYY-MM-DD');
|
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
|
+ return moment(inv.date).format('YYYY-MM-DD') === today;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(date == 'yesterday'){
|
|
|
|
+ var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
|
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
|
+ return moment(inv.date).format('YYYY-MM-DD') === yesterday;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(date == 'currentMonth'){
|
|
|
|
+ var currentMonth = moment().format('YYYY-MM');
|
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
|
+ return moment(inv.date).format('YYYY-MM') === currentMonth;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(date == 'lastMonth'){
|
|
|
|
+ var lastMonth = moment().add(-1,'months').format('YYYY-MM');
|
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
|
+ return moment(inv.date).format('YYYY-MM') === lastMonth;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ var suma =0;
|
|
|
|
+ _.each(content,function(item){
|
|
|
|
+ suma = suma + item.amount
|
|
|
|
+ });
|
|
|
|
+ return [content,suma];
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getStoreName:function(store_id){
|
|
|
|
+ var self = this;
|
|
|
|
+ var ResStore = _.filter(self.ResStore,function (item) {
|
|
|
|
+ return item.id == store_id;
|
|
|
|
+ });
|
|
|
|
+ return ResStore[0].name;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ BuildTable: function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var data = [];
|
|
|
|
+ var CurrencyBase = self.ResCompany[0].currency_id;
|
|
|
|
+
|
|
|
|
+ var ResPartner = self.ResPartner;
|
|
|
|
+ _.each(ResPartner, function(partner){
|
|
|
|
+
|
|
|
|
+ var PosOrder = self.getPosOrder(partner.id);
|
|
|
|
+ var AccountInvoice = self.getAccountInvoice(partner.id);
|
|
|
|
+ var suma = PosOrder[1] + AccountInvoice[1];
|
|
|
|
+
|
|
|
|
+ _.each(PosOrder[0], function(item){
|
|
|
|
+
|
|
|
|
+ var utc = moment.utc(item.date,'YYYY-MM-DD h:mm:ss A');
|
|
|
|
+ data.push({
|
|
|
|
+ id:item.id,
|
|
|
|
+ store: self.getStoreName(item.store_id),
|
|
|
|
+ origin:'',
|
|
|
|
+ number:item.name,
|
|
|
|
+ type: 'TPV',
|
|
|
|
+ date:moment(utc._d).format('DD/MM/YYYY'),
|
|
|
|
+ sale_type: 'Tienda',
|
|
|
|
+ user_name:item.user_name,
|
|
|
|
+ user_id:item.user_id,
|
|
|
|
+ customer_ruc:self.valorNull(item.customer_ruc),
|
|
|
|
+ customer_name:self.valorNull(item.customer_name),
|
|
|
|
+ phone:self.valorNull(item.phone),
|
|
|
|
+ mobile:self.valorNull(item.mobile),
|
|
|
|
+ email:self.valorNull(item.email),
|
|
|
|
+ pos:PosOrder[0].length,
|
|
|
|
+ sale: AccountInvoice[0].length,
|
|
|
|
+ total:accounting.formatMoney(item.amount,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
|
+ sale_amount:accounting.formatMoney(suma,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
|
+ /*
|
|
|
|
+ ===========================
|
|
|
|
+ NO FORMAT
|
|
|
|
+ ===========================
|
|
|
|
+ */
|
|
|
|
+ date_no_format:moment(utc._d).format('YYYY-MM-DD'),
|
|
|
|
+ total_no_format:item.amount,
|
|
|
|
+ sale_amount_no_format: suma,
|
|
|
|
+ /*
|
|
|
|
+ ===========================
|
|
|
|
+ FOOTER
|
|
|
|
+ ===========================
|
|
|
|
+ */
|
|
|
|
+ decimal_places:CurrencyBase.decimal_places,
|
|
|
|
+ thousands_separator:CurrencyBase.thousands_separator,
|
|
|
|
+ decimal_separator:CurrencyBase.decimal_separator,
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ _.each(AccountInvoice[0], function(item){
|
|
|
|
+ if(item.is_delivery == true){
|
|
|
|
+ if(item.delivery_type == 'envio'){
|
|
|
|
+ var sale_type = 'Envío al exterior';
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ var sale_type = 'Delivery Local';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ var sale_type = 'Tienda';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ data.push({
|
|
|
|
+ id:item.id,
|
|
|
|
+ store: self.getStoreName(item.store_id),
|
|
|
|
+ supplier_invoice_number:self.valorNull(item.supplier_invoice_number),
|
|
|
|
+ origin:item.origin,
|
|
|
|
+ number:item.number,
|
|
|
|
+ type:'Pedido de venta',
|
|
|
|
+ date:moment(item.date).format('DD/MM/YYYY'),
|
|
|
|
+ sale_type: sale_type,
|
|
|
|
+ user_name:item.user_name,
|
|
|
|
+ user_id:item.user_id,
|
|
|
|
+ customer_ruc:self.valorNull(item.customer_ruc),
|
|
|
|
+ customer_name:self.valorNull(item.customer_name),
|
|
|
|
+ phone:self.valorNull(item.phone),
|
|
|
|
+ mobile:self.valorNull(item.mobile),
|
|
|
|
+ email:self.valorNull(item.email),
|
|
|
|
+ pos: PosOrder[0].length,
|
|
|
|
+ sale: AccountInvoice[0].length,
|
|
|
|
+ total:accounting.formatMoney(item.amount,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
|
+ sale_amount: accounting.formatMoney(suma,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
|
+ /*
|
|
|
|
+ =======================
|
|
|
|
+ NO FORMAT
|
|
|
|
+ =======================
|
|
|
|
+ */
|
|
|
|
+ date_no_format: moment(item.date).format('YYYY-MM-DD'),
|
|
|
|
+ total_no_format:item.amount,
|
|
|
|
+ sale_amount_no_format: suma,
|
|
|
|
+ /*
|
|
|
|
+ =======================
|
|
|
|
+ FOOTER
|
|
|
|
+ =======================
|
|
|
|
+ */
|
|
|
|
+ decimal_places:CurrencyBase.decimal_places,
|
|
|
|
+ thousands_separator:CurrencyBase.thousands_separator,
|
|
|
|
+ decimal_separator:CurrencyBase.decimal_separator,
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+ data.sort(function (a, b) {
|
|
|
|
+ if (a.date_no_format > b.date_no_format) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ if (a.date_no_format < b.date_no_format) {
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ return 0;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ self.content = data;
|
|
|
|
+ self.loadTable(data);
|
|
|
|
+ self.$el.find('.report-form').css('display','block');
|
|
|
|
+ self.$el.find('.search-form').unblock();
|
|
|
|
+ self.$el.find('.report-form').unblock();
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ loadTable:function(rowsTable){
|
|
|
|
+ var self = this;
|
|
|
|
+ self.rowsData = rowsTable;
|
|
|
|
+ var table = this.$el.find('#table');
|
|
|
|
+ table.bootstrapTable('load', rowsTable);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ clickOnAction: function (e) {
|
|
|
|
+ var self = this;
|
|
|
|
+ var ResCompany;
|
|
|
|
+ var CurrencyBase;
|
|
|
|
+ var action = this.$el.find(e.target).val();
|
|
|
|
+ var company = $('#current-company').val();
|
|
|
|
+ if(company && company != 9999999){
|
|
|
|
+ ResCompany = _.flatten(_.filter(self.ResCompany,function (inv) {
|
|
|
|
+ return inv.id == company;
|
|
|
|
+ }));
|
|
|
|
+ ResCompany = CompanyLogo[0];
|
|
|
|
+ CurrencyBase = ResCompany[0].currency_id;
|
|
|
|
+ }else{
|
|
|
|
+ ResCompany = self.CompanyLogo[0];
|
|
|
|
+ CurrencyBase = self.ResCompany[0].currency_id;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var getColumns=[];
|
|
|
|
+ var rows=[];
|
|
|
|
+ var table = this.$el.find("#table");
|
|
|
|
+ var column = table.bootstrapTable('getVisibleColumns');
|
|
|
|
+ var row = table.bootstrapTable('getData');
|
|
|
|
+
|
|
|
|
+ var total = TotalFooter(row);
|
|
|
|
+ var sale_amount = TotalSaleAmount(row);
|
|
|
|
+ row.push({
|
|
|
|
+ store:'Totales',
|
|
|
|
+ total:total,
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (action === 'pdf') {
|
|
|
|
+ var data = _.map(column, function (val){
|
|
|
|
+ return val.field;
|
|
|
|
+ });
|
|
|
|
+ _.each(_.map(column,function(val){
|
|
|
|
+ return val;
|
|
|
|
+ }), function(item){
|
|
|
|
+ getColumns.push([{
|
|
|
|
+ title: item.title,
|
|
|
|
+ dataKey: item.field
|
|
|
|
+ }]);
|
|
|
|
+ });
|
|
|
|
+ /*
|
|
|
|
+ ============================================================
|
|
|
|
+ CONFIGURACION DEL PDF
|
|
|
|
+ ============================================================
|
|
|
|
+ */
|
|
|
|
+ var pdf_title = 'Fidelización de Ventas.';
|
|
|
|
+ var pdf_type = 'l';
|
|
|
|
+ var pdf_name = 'fidelizacion_de_ventas_';
|
|
|
|
+ var pdf_columnStyles = {
|
|
|
|
+ store:{halign:'left'},
|
|
|
|
+ user_name:{ halign:'left'},
|
|
|
|
+ date:{halign:'center'},
|
|
|
|
+ type:{halign:'left'},
|
|
|
|
+ number:{halign:'left'},
|
|
|
|
+ supplier_invoice_number:{halign:'left'},
|
|
|
|
+ origin:{ halign:'left'},
|
|
|
|
+ customer_name:{ halign:'left'},
|
|
|
|
+ customer_ruc:{ halign:'left'},
|
|
|
|
+ phone:{ halign:'right'},
|
|
|
|
+ mobile:{ halign:'right'},
|
|
|
|
+ email:{ halign:'right'},
|
|
|
|
+ total:{columnWidth: 22, halign:'right'},
|
|
|
|
+ pos:{ halign:'center'},
|
|
|
|
+ sale:{ halign:'center'},
|
|
|
|
+ sale_amount:{columnWidth: 22, halign:'right'},
|
|
|
|
+ };
|
|
|
|
+ /*
|
|
|
|
+ ============================================================
|
|
|
|
+ LLAMAR FUNCION DE IMPRESION
|
|
|
|
+ ============================================================
|
|
|
|
+ */
|
|
|
|
+ var filter = self.getFilter();
|
|
|
|
+ var pdf = new model.eiru_reports.ReportPdfWidget(self);
|
|
|
|
+ pdf.drawPDF(
|
|
|
|
+ _.flatten(getColumns),
|
|
|
|
+ row,
|
|
|
|
+ ResCompany,
|
|
|
|
+ pdf_title,
|
|
|
|
+ pdf_type,
|
|
|
|
+ pdf_name,
|
|
|
|
+ pdf_columnStyles,
|
|
|
|
+ filter
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ getFilter: function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
|
+ var user = self.$el.find('#current-user').val();
|
|
|
|
+ var customer = self.$el.find('#current-customer').val();
|
|
|
|
+ var state = self.$el.find('#current-state').val();
|
|
|
|
+ var type = self.$el.find('#current-type').val();
|
|
|
|
+ var sale_type = self.$el.find('#current-sale-type').val();
|
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
|
+ var filter = [];
|
|
|
|
+ if(company && company != 9999999){
|
|
|
|
+ var ResCompany = _.filter(self.ResCompany, function(item){
|
|
|
|
+ return item.id == company;
|
|
|
|
+ });
|
|
|
|
+ filter.push({
|
|
|
|
+ title:'Empresa',
|
|
|
|
+ value: ResCompany[0].name,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if(store && store != 9999999){
|
|
|
|
+ var ResStore = _.filter(self.ResStore,function (item) {
|
|
|
|
+ return item.id == store;
|
|
|
|
+ });
|
|
|
|
+ filter.push({
|
|
|
|
+ title: 'Sucursal',
|
|
|
|
+ value: ResStore[0].name,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if(user && user != 9999999){
|
|
|
|
+ var ResUser = _.filter(self.ResUsers, function(item){
|
|
|
|
+ return item.id == user;
|
|
|
|
+ });
|
|
|
|
+ filter.push({
|
|
|
|
+ title:'Vendedor',
|
|
|
|
+ value: ResUser[0].name,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if(customer && customer != 9999999){
|
|
|
|
+ var ResPartner = _.filter(self.ResPartner, function(item){
|
|
|
|
+ return item.id == customer;
|
|
|
|
+ });
|
|
|
|
+ filter.push({
|
|
|
|
+ title:'Cliente',
|
|
|
|
+ value: ResPartner[0].name,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if(state && state != 9999999){
|
|
|
|
+ filter.push({
|
|
|
|
+ title: 'Estado',
|
|
|
|
+ value: $('#current-state option:selected').text(),
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(type && type != 9999999){
|
|
|
|
+ filter.push({
|
|
|
|
+ title: 'Tipo de Factura',
|
|
|
|
+ value: $('#current-type option:selected').text(),
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(sale_type && sale_type != 9999999){
|
|
|
|
+ filter.push({
|
|
|
|
+ title: 'Tipo de Venta',
|
|
|
|
+ value: $('#current-sale-type option:selected').text(),
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(date && date != 9999999){
|
|
|
|
+ moment.locale('es', {
|
|
|
|
+ months: 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if(date == 'range'){
|
|
|
|
+ filter.push({
|
|
|
|
+ title: 'Fecha',
|
|
|
|
+ value: desde +' al '+hasta,
|
|
|
|
+ });
|
|
|
|
+ }else {
|
|
|
|
+ var fecha;
|
|
|
|
+ if(date == 'today'){
|
|
|
|
+ fecha = moment().format('DD/MM/YYYY');
|
|
|
|
+ }
|
|
|
|
+ if(date == 'yesterday'){
|
|
|
|
+ fecha = moment().add(-1,'days').format('DD/MM/YYYY');
|
|
|
|
+ }
|
|
|
|
+ if(date == 'currentMonth'){
|
|
|
|
+ fecha = moment().format('MMMM/YYYY');
|
|
|
|
+ }
|
|
|
|
+ if(date == 'lastMonth'){
|
|
|
|
+ fecha = moment().add(-1,'months').format('MMMM/YYYY');
|
|
|
|
+ }
|
|
|
|
+ filter.push({
|
|
|
|
+ title: 'Fecha',
|
|
|
|
+ value: fecha,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return filter;
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+}
|