|
@@ -0,0 +1,902 @@
|
|
|
+function report_guide_smile_analytic(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportGuideSmileAnalyticWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportGuideSmileAnalytic',
|
|
|
+ invoices: [],
|
|
|
+ invoiceLines: [],
|
|
|
+ productProduct:[],
|
|
|
+ ResCurrency:[],
|
|
|
+ AccountVoucher:[],
|
|
|
+ AccountMoveLine:[],
|
|
|
+ rowsData :[],
|
|
|
+ content :[],
|
|
|
+ rowOrigin:[],
|
|
|
+ accountJournal:[],
|
|
|
+ resCompany:[],
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click #X' : 'fectSearch',
|
|
|
+ 'click #A' : 'fectSearch',
|
|
|
+ 'click #B' : 'fectSearch',
|
|
|
+ 'click #C' : 'fectSearch',
|
|
|
+ 'click #D' : 'fectSearch',
|
|
|
+ 'click #Z' : 'fectSearch',
|
|
|
+ 'click #W' : 'fectSearch',
|
|
|
+ 'click #paid' : 'fectSearch',
|
|
|
+ 'click #open' : 'fectSearch',
|
|
|
+ 'change #current-store': 'fectSearch',
|
|
|
+ 'change #current-journal': 'fectSearch',
|
|
|
+ 'change #current-category' : 'fectSearch',
|
|
|
+ 'change #current-attribute': 'fectSearch',
|
|
|
+ 'change #current-attribute-value': 'fectSearch',
|
|
|
+ 'change #user': 'fectSearch',
|
|
|
+ 'change #from' : 'fectSearch',
|
|
|
+ 'change #to': 'fectSearch',
|
|
|
+ 'click #volver_btn': 'volver',
|
|
|
+ '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();
|
|
|
+ },
|
|
|
+ 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,
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ e.stopImmediatePropagation();
|
|
|
+ },
|
|
|
+ volver: function(){
|
|
|
+ this.$el.find('#volver').empty();
|
|
|
+ this.$el.find('#grafico').empty();
|
|
|
+ this.$el.find('.bootstrap-table').show({
|
|
|
+ effect: 'drop',
|
|
|
+ direction: 'down',
|
|
|
+ duration: 200,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Fecha
|
|
|
+ fecthFecha: function() {
|
|
|
+ var to;
|
|
|
+ var dateFormat1 = "mm/dd/yy",
|
|
|
+ from = $( "#from" )
|
|
|
+ .datepicker({
|
|
|
+ dateFormat: "dd/mm/yy",
|
|
|
+ changeMonth: true,
|
|
|
+ numberOfMonths: 1,
|
|
|
+ })
|
|
|
+ .on( "change", function() {
|
|
|
+ to.datepicker( "option", "minDate", getDate(this), "dd/mm/yyyy");
|
|
|
+ });
|
|
|
+ to = $( "#to" ).datepicker({
|
|
|
+ dateFormat: "dd/mm/yy",
|
|
|
+ defaultDate: "+7d",
|
|
|
+ changeMonth: true,
|
|
|
+ numberOfMonths: 1,
|
|
|
+ })
|
|
|
+ .on( "change", function() {
|
|
|
+ from.datepicker( "option", "maxDate", getDate(this));
|
|
|
+ });
|
|
|
+
|
|
|
+ function getDate( element ) {
|
|
|
+ var fechaSel =element.value.split('/');
|
|
|
+ var date;
|
|
|
+ try {
|
|
|
+ date = $.datepicker.parseDate( dateFormat1, (fechaSel[1]+"/"+fechaSel[0]+"/"+fechaSel[2]));
|
|
|
+ } catch( error ) {
|
|
|
+ date = null;
|
|
|
+ }
|
|
|
+ return date;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // Cansultar
|
|
|
+ submitForm: function () {
|
|
|
+ var self = this;
|
|
|
+ this.fetchResCurrency().then(function(ResCurrency) {
|
|
|
+ self.ResCurrency = ResCurrency;
|
|
|
+ return ResCurrency;
|
|
|
+ }).then(function (ResCurrency) {
|
|
|
+ return self.fecthResStore();
|
|
|
+ }).then(function(ResStore){
|
|
|
+ self.ResStore = ResStore;
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las Sucursales</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.fetchInvoiceLine(invoices);
|
|
|
+ }).then(function (invoiceLines) {
|
|
|
+ self.invoiceLines = invoiceLines;
|
|
|
+ return self.fetchProductProduct();
|
|
|
+ }).then(function(ProductProduct){
|
|
|
+ self.ProductProduct = ProductProduct;
|
|
|
+ return self.fetchProductAttribute();
|
|
|
+ }).then(function (ProductAttribute) {
|
|
|
+ self.ProductAttribute = ProductAttribute;
|
|
|
+ if(ProductAttribute.length > 0){
|
|
|
+ self.$el.find('#current-attribute').append('<option value="9999999">Todos los atributos</option>');
|
|
|
+ _.each(ProductAttribute,function(item){
|
|
|
+ self.$el.find('#current-attribute').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.attribute').css('display','none');
|
|
|
+ }
|
|
|
+ return self.fetchProductAttributeValue();
|
|
|
+ }).then(function(ProductAttributeValue){
|
|
|
+ self.ProductAttributeValue = ProductAttributeValue;
|
|
|
+ if(ProductAttributeValue.length > 0){
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="9999999">Todos los valores de atributos</option>');
|
|
|
+ _.each(ProductAttributeValue,function(item){
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.attribute-value').css('display','none');
|
|
|
+ }
|
|
|
+ return self.fetchProductCategory();
|
|
|
+ }).then(function(ProductCategory){
|
|
|
+ self.ProductCategory= ProductCategory;
|
|
|
+ self.$el.find('#current-category').append('<option value="9999999">Todas las categorias</option>');
|
|
|
+ _.each(ProductCategory, function (item) {
|
|
|
+ self.$el.find('#current-category').append('<option value="' + item.id + '">' + item.complete_name + '</option>');
|
|
|
+ });
|
|
|
+ return self.fecthCompanyCurrency();
|
|
|
+ }).then(function(resCompany){
|
|
|
+ self.resCompany = resCompany;
|
|
|
+ return self.fetchAccountVoucher();
|
|
|
+ }).then(function (AccountVoucher) {
|
|
|
+ self.AccountVoucher = AccountVoucher;
|
|
|
+ return self.fetchAccountMoveLine();
|
|
|
+ }).then(function (AccountMoveLine){
|
|
|
+ self.AccountMoveLine = AccountMoveLine;
|
|
|
+ return self.fetchResPartner();
|
|
|
+ }).then(function(ResPartner){
|
|
|
+ self.ResPartner = ResPartner;
|
|
|
+ return self.fecthResUser();
|
|
|
+ }).then(function (ResUser) {
|
|
|
+ self.ResUser = ResUser;
|
|
|
+ self.search();
|
|
|
+ self.searchProduct();
|
|
|
+ self.searchUser();
|
|
|
+ return self.fectUtility();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fecthResStore: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var field=['id', 'name'];
|
|
|
+ var ResStore = new model.web.Model('res.store');
|
|
|
+ ResStore.query(field).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.fectSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ close: function( event, ui ) {
|
|
|
+ self.fectSearch();
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ searchProduct: function () {
|
|
|
+ var self = this;
|
|
|
+ var results = self.ProductProduct;
|
|
|
+ results = _.map(results, function (item) {
|
|
|
+ return {
|
|
|
+ label: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' + self.valorNull(item.attribute_str) + ' ) ' ,
|
|
|
+ value: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' + self.valorNull(item.attribute_str) + ' ) '
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.$('#product').autocomplete({
|
|
|
+ source: results,
|
|
|
+ minLength:0,
|
|
|
+ search: function(event, ui) {
|
|
|
+ if (!(self.$('#product').val())){
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ close: function( event, ui ) {
|
|
|
+ self.fectSearch();
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ 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 model.web.Model('account.journal');
|
|
|
+ AccountJournal.query(field).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 model.web.Model('res.company');
|
|
|
+ ResCompany.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 model.web.Model('res.currency');
|
|
|
+ ResCurrency.query(fields).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', 'invoice_line','date_invoice','partner_id' ,'user_id', 'reference' ,'payment_ids'];
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var Invoice = new model.web.Model('account.invoice');
|
|
|
+ Invoice.query(field).filter(filter).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ // Invoice line (Linea de Factura)
|
|
|
+ fetchInvoiceLine: function (invoices) {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var linesIds = _.flatten(_.map(invoices, function (item) {
|
|
|
+ return item.invoice_line;
|
|
|
+ }));
|
|
|
+ var InvoiceLine = new model.web.Model('account.invoice.line');
|
|
|
+ InvoiceLine.query(['id', 'quantity', 'price_unit', 'discount', 'name', 'product_id', 'origin','invoice_id']).filter([['id', 'in', linesIds]]).all().then(function (results) {
|
|
|
+ defer.resolve(results)
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*
|
|
|
+ ====================================================================
|
|
|
+ ACCOUNT INVOICE LINE
|
|
|
+ ====================================================================
|
|
|
+ */
|
|
|
+ fetchAccountMoveLine: function (){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var invoice_numbers = _.flatten(_.map(self.invoices, function (item) {
|
|
|
+ return item.number;
|
|
|
+ }));
|
|
|
+ var domain = [
|
|
|
+ ['move_id','in',invoice_numbers],
|
|
|
+ ['debit','>',0],
|
|
|
+ ['date_maturity','!=', false]
|
|
|
+ ];
|
|
|
+
|
|
|
+ var AccountMoveLine = new model.web.Model('account.move.line');
|
|
|
+ AccountMoveLine.query(['id', 'move_id','journal_id']).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ fetchAccountVoucher: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var AccountVoucher = new model.web.Model('account.voucher');
|
|
|
+ AccountVoucher.query(['id', 'number','reference','journal_id','type']).filter([['state', '=', 'posted']]).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ RES PARTNER
|
|
|
+ ====================================================================*/
|
|
|
+ fetchResPartner: function(){
|
|
|
+ var self = this;
|
|
|
+ var domain = [['active','=',true]];
|
|
|
+ var ResPartner = new model.web.Model('res.partner');
|
|
|
+ return ResPartner.call('getResPartnerSmile',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ 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 model.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.fectSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ close: function( event, ui ) {
|
|
|
+ self.fectSearch();
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // Product Product
|
|
|
+ fetchProductProduct: function(){
|
|
|
+ var self = this;
|
|
|
+ var product_ids = _.flatten(_.map(self.invoiceLines, function (item) {
|
|
|
+ return item.product_id[0];
|
|
|
+ }));
|
|
|
+ var domain = [['id','in',product_ids]];
|
|
|
+ var ProductProduct = new model.web.Model('product.product');
|
|
|
+ return ProductProduct.call('getProductProduct',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // Buscar Category
|
|
|
+ fetchProductCategory : function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name','parent_id','complete_name'];
|
|
|
+ var ProductCategory = new model.web.Model('product.category');
|
|
|
+ ProductCategory.query(fields).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchProductAttribute : function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name'];
|
|
|
+ var ProductAttribute = new model.web.Model('product.attribute');
|
|
|
+ ProductAttribute.query(fields).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchProductAttributeValue : function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name','attribute_id'];
|
|
|
+ var ProductAttributeValue = new model.web.Model('product.attribute.value');
|
|
|
+ ProductAttributeValue.query(fields).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ // Obtener Monedas de la Factura
|
|
|
+ getResCurrency: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCurrency,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ // Obtener la Detalles de la Factura
|
|
|
+ getInvoice: function (id_line){
|
|
|
+ var self = this;
|
|
|
+ return _.find(this.invoices, function (inv) {
|
|
|
+ return _.contains(inv.invoice_line, id_line);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountVoucher: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.AccountVoucher,function (item) {
|
|
|
+ return item.reference === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountMoveLine: function (number) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.AccountMoveLine,function (item) {
|
|
|
+ return item.move_id[1] === number;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // Obtener las lineas de las Facturas
|
|
|
+ getProductProduct: function(pro_id){
|
|
|
+ var self = this;
|
|
|
+ return _.find(self.ProductProduct, function(item){
|
|
|
+ return _.contains(pro_id, item.id);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ 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;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fectUtility: function(){
|
|
|
+ var self = this;
|
|
|
+ var data=[];
|
|
|
+ var CurrencyBase = self.getResCurrency(self.resCompany[0].currency_id[0]).shift();
|
|
|
+ var item;
|
|
|
+ var state;
|
|
|
+ var invoice=[];
|
|
|
+ var partner=[];
|
|
|
+ var voucher=[];
|
|
|
+ var product;
|
|
|
+
|
|
|
+ for (var i = 0; i < this.invoiceLines.length; i++) {
|
|
|
+ item = this.invoiceLines[i];
|
|
|
+ invoice = this.getInvoice(item.id);
|
|
|
+ if(invoice.state=='open'){
|
|
|
+ state = 'Abierto'
|
|
|
+ }
|
|
|
+ if(invoice.state=='paid'){
|
|
|
+ state = 'Pagado'
|
|
|
+ }
|
|
|
+
|
|
|
+ partner= self.getResPartner(invoice.partner_id[0]);
|
|
|
+ var currency = self.getResCurrency(invoice.currency_id[0]).shift();
|
|
|
+ voucher = self.getAccountMoveLine(invoice.number);
|
|
|
+ var x = voucher.length;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ product =this.getProductProduct(item.product_id);
|
|
|
+
|
|
|
+ if (product != undefined){
|
|
|
+ var store_id = self.getAccountJournal(invoice.journal_id[0]);
|
|
|
+ if(store_id.length > 0 && partner.length > 0){
|
|
|
+ data.push({
|
|
|
+ id : invoice.id,
|
|
|
+ number : (invoice.number),
|
|
|
+ doctor_name : partner[0].medic[1],
|
|
|
+ product_id : item.product_id[0],
|
|
|
+ product_name : item.product_id[1],
|
|
|
+ ean13 : self.valorNull(product.ean13),
|
|
|
+ quantity : accounting.formatNumber((item.quantity),0, ".", ","),
|
|
|
+ price_unity : accounting.formatNumber((item.price_unit * (CurrencyBase.rate_silent/currency.rate_silent)),0, ".", ","),
|
|
|
+ standar_price : accounting.formatNumber((product.standard_price),0, ".", ","),
|
|
|
+ price_tot : accounting.formatNumber((item.quantity * (item.price_unit * (CurrencyBase.rate_silent/currency.rate_silent))),0, ".", ","),
|
|
|
+ standar_tot : accounting.formatNumber((item.quantity * product.standard_price),0, ".", ","),
|
|
|
+ total_cuota : x,
|
|
|
+ utility : accounting.formatNumber((((item.quantity * (item.price_unit * (CurrencyBase.rate_silent/currency.rate_silent))) - (item.quantity * product.standard_price))/x),0, ".", ","),
|
|
|
+ utilidad : accounting.formatNumber(((item.quantity * (item.price_unit * (CurrencyBase.rate_silent/currency.rate_silent))) - (item.quantity * product.standard_price)),0, ".", ","),
|
|
|
+ quantity_tot : (item.quantity),
|
|
|
+ price_tot_tot : ((item.quantity * (item.price_unit *(CurrencyBase.rate_silent/currency.rate_silent)))),
|
|
|
+ standar_tot_tot : ((item.quantity * product.standard_price)),
|
|
|
+ utility_tot : ((((item.quantity * (item.price_unit * (CurrencyBase.rate_silent/currency.rate_silent))) - (item.quantity * product.standard_price)))/x),
|
|
|
+ utilidad_tot : (((item.quantity * (item.price_unit * (CurrencyBase.rate_silent/currency.rate_silent))) - (item.quantity * product.standard_price))),
|
|
|
+ date_create : moment(invoice.date_invoice).format("DD/MM/YYYY"),
|
|
|
+ date_invoice : (invoice.date_invoice),
|
|
|
+ partner_id : invoice.partner_id[0],
|
|
|
+ partner_name : invoice.partner_id[1],
|
|
|
+ category_name : product.categ_id.complete_name,
|
|
|
+ category_id : product.categ_id.id,
|
|
|
+ user_id : self.valorNull(invoice.user_id[0]),
|
|
|
+ user_name : invoice.user_id[1],
|
|
|
+ store_id : store_id[0].store_ids[0],
|
|
|
+ state: state,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ data.sort(function (a, b) {
|
|
|
+ if (a.date_invoice > b.date_invoice) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (a.date_invoice < b.date_invoice) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ });
|
|
|
+ this.rowsData=data;
|
|
|
+ self.content = data;
|
|
|
+ console.log(data);
|
|
|
+ this.loadTable(data)
|
|
|
+ },
|
|
|
+
|
|
|
+ fectSearch: 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 partner = this.$el.find('#partner').val().split('-');
|
|
|
+ var user = this.$el.find('#user').val().split('-');
|
|
|
+ var product = this.$el.find('#product').val().split('-');
|
|
|
+ var categ_ids = [];
|
|
|
+ var category = self.$el.find('#current-category').val();
|
|
|
+ var state = self.$el.find('#current-state').val();
|
|
|
+ var desde =this.$el.find('#from').val();
|
|
|
+ var hasta =this.$el.find('#to').val();
|
|
|
+ var store = this.$el.find('#current-store').val();
|
|
|
+ var journal = this.$el.find('#current-journal').val();
|
|
|
+ var content = self.content;
|
|
|
+
|
|
|
+ if ($('#A').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM-DD') == today;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#B').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM-DD') == yesterday;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#C').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM') == month;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#D').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date_invoice).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_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (hasta.length > 0){
|
|
|
+ var date= hasta.split('/');
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $('#datepicker').css('display','none');
|
|
|
+ }
|
|
|
+ if ($('#paid').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.state == 'Pagado';
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#open').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.state == 'Abierto';
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (partner != ""){
|
|
|
+ content = _.filter(content, function(inv){
|
|
|
+ return inv.partner_id == partner[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (product != ""){
|
|
|
+ content = _.filter(content, function(inv){
|
|
|
+ return inv.product_id == product[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if(category){
|
|
|
+ // Nivel 0, nivel 1
|
|
|
+ var category_ids = _.map(_.filter(self.ProductCategory,function (item) {
|
|
|
+ return item.id == category || item.parent_id[0] == category;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+
|
|
|
+ // Nivel 0, nivel 1, nivel 2
|
|
|
+ var category_children_ids = _.map(_.filter(self.ProductCategory,function (item) {
|
|
|
+ return _.contains(category_ids, item.parent_id[0]) || item.id == category;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+
|
|
|
+ var category_grandchildren_ids = _.map(_.filter(self.ProductCategory,function (item) {
|
|
|
+ return _.contains(category_children_ids, item.parent_id[0]) || item.id == category;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ }) ;
|
|
|
+
|
|
|
+ categ_ids = _.map(_.filter(self.ProductCategory,function (item) {
|
|
|
+ return _.contains(category_grandchildren_ids, item.parent_id[0]) || item.id == category;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ if(category && category != 9999999){
|
|
|
+ content = _.filter(content,function (inv) {
|
|
|
+ return _.contains(categ_ids, inv.category_id);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (user != ""){
|
|
|
+ content = _.filter(content, function(inv){
|
|
|
+ return inv.user_id == user[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if(state && state != 9999999){
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ return item.state == state;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ var quantity_tot_total = _.reduce(_.map(content,function(map){
|
|
|
+ return(map.quantity_tot);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+
|
|
|
+ var price_total_total = _.reduce(_.map(content,function(map){
|
|
|
+ return(map.price_tot_tot);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+
|
|
|
+
|
|
|
+ content.push({
|
|
|
+ number: "Totales:",
|
|
|
+ quantity: accounting.formatNumber((quantity_tot_total),0,".",","),
|
|
|
+ price_tot: accounting.formatNumber((price_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 = this.$el.find(e.target).val();
|
|
|
+ var getColumns=[];
|
|
|
+ var rows=[];
|
|
|
+ rowsNew = self.getObjetPdf();
|
|
|
+ var table = this.$el.find("#table");
|
|
|
+ var data2 = table.bootstrapTable('getVisibleColumns');
|
|
|
+ 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
|
|
|
+ }]);
|
|
|
+ });
|
|
|
+ // Llamar al pdf
|
|
|
+ this.drawPDF(_.flatten(getColumns),rows)
|
|
|
+ }
|
|
|
+ if (action === 'chart'){
|
|
|
+ var suc = this.$el.find('#current-journal').val();
|
|
|
+ if (suc == 9999999){
|
|
|
+ self.fectCharFilter();
|
|
|
+ }else{
|
|
|
+ $("#dialog" ).dialog({
|
|
|
+ autoOpen: true,
|
|
|
+ resizable: false,
|
|
|
+ modal: true,
|
|
|
+ title: 'Atención',
|
|
|
+ open: function() {
|
|
|
+ $(this).html('Para Generar el Gráfico debes Seleccionar todas las Sucursales');
|
|
|
+ },
|
|
|
+ show: {
|
|
|
+ effect: "shake",
|
|
|
+ duration: 300
|
|
|
+ },
|
|
|
+ hide: {
|
|
|
+ effect: "fade",
|
|
|
+ duration: 300
|
|
|
+ },
|
|
|
+ buttons: {
|
|
|
+ Aceptar: function() {
|
|
|
+ $(this).dialog('close');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ drawPDF: function (getColumns,rows) {
|
|
|
+ var self = this;
|
|
|
+ var rowsPdf=[];
|
|
|
+ var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
|
|
|
+ var desde =(this.$el.find('#from').val());
|
|
|
+ var hasta =(this.$el.find('#to').val());
|
|
|
+ var totalPagesExp = "{total_pages_count_string}";
|
|
|
+ var pdfDoc = new jsPDF('l');
|
|
|
+
|
|
|
+ var company = _.map(self.resCompany, function (map) {
|
|
|
+ return map.currency_id[1];
|
|
|
+ });
|
|
|
+
|
|
|
+ pdfDoc.autoTable(getColumns, rows, {
|
|
|
+ styles: { overflow: 'linebreak', fontSize: 7, columnWidth: 'wrap'},
|
|
|
+ columnStyles: {
|
|
|
+ number: {columnWidth: 24},
|
|
|
+ date_create :{columnWidth: 17},
|
|
|
+ partner_name:{columnWidth: 20},
|
|
|
+ ean13:{columnWidth: 10},
|
|
|
+ doctor_name :{columnWidth: 40},
|
|
|
+ product_name :{columnWidth: 40},
|
|
|
+ category_name : {columnWidth: 30},
|
|
|
+ quantity :{halign:'right',columnWidth: 8},
|
|
|
+ price_unity : {halign:'right',columnWidth: 18},
|
|
|
+ price_tot : {halign:'right' ,columnWidth: 18},
|
|
|
+ total_cuota : {halign:'right',columnWidth: 17},
|
|
|
+ user_name : {columnWidth: 15},
|
|
|
+ state:{columnWidth: 12},
|
|
|
+ },
|
|
|
+ margin: { top: 16, horizontal: 7},
|
|
|
+ addPageContent: function (data) {
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Análisis de venta por médico', 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('Análisis de venta por médico.pdf')
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|