|
@@ -0,0 +1,736 @@
|
|
|
+function report_comision_inmobiliaria(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportComisionWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportComision',
|
|
|
+ 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.fetchInitialSQL().then(function (InitialSQL) {
|
|
|
+ return InitialSQL;
|
|
|
+ }).then(function(InitialSQL) {
|
|
|
+ /*
|
|
|
+ =================================
|
|
|
+ RES COMPANY
|
|
|
+ =================================
|
|
|
+ */
|
|
|
+ self.ResCompany = InitialSQL.companies;
|
|
|
+ self.CompanyLogo = InitialSQL.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 = InitialSQL.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 = InitialSQL.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 = InitialSQL.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.ResPartners = DataSQL.partners;
|
|
|
+ self.AccountInvoice = DataSQL.invoices;
|
|
|
+ self.AccountInvoiceLine = DataSQL.invoice_line;
|
|
|
+ self.PosOrder = DataSQL.orders;
|
|
|
+
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInitialSQL: function() {
|
|
|
+ var self = this;
|
|
|
+ var data = $.get('/report-filter-data-inmobiliaria');
|
|
|
+ return data;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchDataSQL: function() {
|
|
|
+ var self = this;
|
|
|
+ var data = $.get('/report-sale-history-inmobiliaria');
|
|
|
+ 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 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(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;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return content;
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountInvoice:function() {
|
|
|
+ var self = this;
|
|
|
+ var content = self.AccountInvoice;
|
|
|
+ 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 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(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;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return content;
|
|
|
+ },
|
|
|
+
|
|
|
+ getStoreName:function(store_id){
|
|
|
+ var self = this;
|
|
|
+ var ResStore = _.filter(self.ResStore,function (item) {
|
|
|
+ return item.id == store_id;
|
|
|
+ });
|
|
|
+ return ResStore[0].name;
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountInvoiceLine:function(invoice_id){
|
|
|
+ var self = this;
|
|
|
+ var AccountInvoiceLine = _.filter(self.AccountInvoiceLine,function (item) {
|
|
|
+ return item.invoice_id == invoice_id;
|
|
|
+ });
|
|
|
+ return AccountInvoiceLine;
|
|
|
+ },
|
|
|
+
|
|
|
+ getOwnerName:function(partner_id){
|
|
|
+ var self = this;
|
|
|
+ var ResPartners = _.filter(self.ResPartners,function (item) {
|
|
|
+ return item.id == partner_id;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (ResPartners.length > 0){
|
|
|
+ return ResPartners[0].name;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ BuildTable: function(){
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ var CurrencyBase = self.ResCompany[0].currency_id;
|
|
|
+
|
|
|
+ var AccountInvoice = self.getAccountInvoice()
|
|
|
+
|
|
|
+ _.each(AccountInvoice, function(item){
|
|
|
+ var AccountInvoiceLine = self.getAccountInvoiceLine(item.invoice_id);
|
|
|
+
|
|
|
+ var suma_comision_inmobiliaria = 0;
|
|
|
+ var suma_comision_vendedor = 0;
|
|
|
+ var suma_comision_total = 0;
|
|
|
+ var owner;
|
|
|
+ _.each(AccountInvoiceLine, function(line){
|
|
|
+ suma_comision_inmobiliaria = suma_comision_inmobiliaria + ((line.subtotal * line.comision_inmobiliaria)/100)
|
|
|
+ suma_comision_vendedor = suma_comision_vendedor + ((line.subtotal * line.comision_vendedor)/100)
|
|
|
+ suma_comision_total = suma_comision_total + ((line.subtotal * line.comision_total)/100)
|
|
|
+ owner = line.t_propietario;
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ data.push({
|
|
|
+ id:item.id,
|
|
|
+ supplier_invoice_number:self.valorNull(item.supplier_invoice_number),
|
|
|
+ origin:self.valorNull(item.origin),
|
|
|
+ number:item.number,
|
|
|
+ type:'Pedido de venta',
|
|
|
+ date:moment(item.date).format('DD/MM/YYYY'),
|
|
|
+ seller_name:item.user_name,
|
|
|
+ user_id:item.user_id,
|
|
|
+ customer_ruc:self.valorNull(item.customer_ruc),
|
|
|
+ customer_name:self.valorNull(item.customer_name),
|
|
|
+ owner_name: self.getOwnerName(owner),
|
|
|
+ cuota: self.valorNull(item.cuotas),
|
|
|
+ seller_comision: accounting.formatMoney(suma_comision_vendedor, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ company_comision: accounting.formatMoney(suma_comision_inmobiliaria, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ /*
|
|
|
+ =======================
|
|
|
+ NO FORMAT
|
|
|
+ =======================
|
|
|
+ */
|
|
|
+ date_no_format: moment(item.date).format('YYYY-MM-DD'),
|
|
|
+ seller_comision_no_format:suma_comision_vendedor,
|
|
|
+ company_comision_no_format:suma_comision_inmobiliaria,
|
|
|
+ /*
|
|
|
+ =======================
|
|
|
+ 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 seller_comision = totalSeller(row);
|
|
|
+ var company_comision = totalCompany(row);
|
|
|
+ row.push({
|
|
|
+ date:'Totales',
|
|
|
+ seller_comision:seller_comision,
|
|
|
+ company_comision:company_comision,
|
|
|
+ });
|
|
|
+
|
|
|
+ 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 = 'Comisión sobre Ventas.';
|
|
|
+ var pdf_type = '';
|
|
|
+ var pdf_name = 'comision_sobre_ventas_';
|
|
|
+
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ date:{columnWidth:17, halign:'left'},
|
|
|
+ number:{columnWidth: 24, halign:'left'},
|
|
|
+ supplier_invoice_number:{columnWidth: 20, halign:'left'},
|
|
|
+ cuota:{columnWidth: 16,halign:'left'},
|
|
|
+ origin:{columnWidth: 17,halign:'left'},
|
|
|
+ customer_name:{halign:'left'},
|
|
|
+ owner_name:{columnWidth: 20, halign:'left'},
|
|
|
+ seller_name:{columnWidth: 20, halign:'left'},
|
|
|
+ seller_comision:{columnWidth: 25, halign:'right'},
|
|
|
+ company_comision:{columnWidth: 25, 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 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(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;
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|