Commit ccf0901ea06bc1415d503f911df9177edcf670c9
Exists in
master
Merge branch 'master' into 'develop'
Master See merge request !5
Showing
1 changed file
Show diff stats
src/js/controller.js
| 1 | angular.module('focaAgendarVisita') | 1 | angular.module('focaAgendarVisita') |
| 2 | .controller('focaAgendarVisitaController', [ | 2 | .controller('focaAgendarVisitaController', [ |
| 3 | '$scope', 'focaAgendarVisitaService', '$location','$localStorage', '$timeout', | 3 | '$scope', 'focaAgendarVisitaService', '$location','$localStorage', '$timeout', |
| 4 | '$uibModal', 'focaBotoneraLateralService', '$filter', | 4 | '$uibModal', 'focaBotoneraLateralService', '$filter', |
| 5 | 'focaModalService', 'focaSeguimientoService', | 5 | 'focaModalService', 'focaSeguimientoService', |
| 6 | function($scope, focaAgendarVisitaService, $location, $localStorage, $timeout, | 6 | function($scope, focaAgendarVisitaService, $location, $localStorage, $timeout, |
| 7 | $uibModal, focaBotoneraLateralService, $filter, | 7 | $uibModal, focaBotoneraLateralService, $filter, |
| 8 | focaModalService, focaSeguimientoService | 8 | focaModalService, focaSeguimientoService |
| 9 | ) { | 9 | ) { |
| 10 | $scope.focused = 0; | ||
| 11 | $scope.rol = 1; | ||
| 12 | $scope.visita = {}; | ||
| 13 | $scope.now = new Date(); | ||
| 14 | $scope.botonera = focaAgendarVisitaService.getBotonera(); | ||
| 15 | $timeout(function() { | ||
| 16 | focaBotoneraLateralService.showSalir(true); | ||
| 17 | focaBotoneraLateralService.showPausar(true); | ||
| 18 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | ||
| 19 | }); | ||
| 20 | 10 | ||
| 21 | $timeout(function() {getLSVisita();}); | 11 | config(); |
| 12 | init(); | ||
| 13 | |||
| 14 | function config() { | ||
| 15 | $scope.focused = 0; | ||
| 16 | $scope.rol = 1; | ||
| 17 | $scope.visita = {}; | ||
| 18 | $scope.now = new Date(); | ||
| 19 | } | ||
| 20 | |||
| 21 | function init() { | ||
| 22 | $scope.botonera = focaAgendarVisitaService.getBotonera(); | ||
| 23 | $timeout(function() { | ||
| 24 | focaBotoneraLateralService.showSalir(false); | ||
| 25 | focaBotoneraLateralService.showPausar(true); | ||
| 26 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | ||
| 27 | focaBotoneraLateralService.addCustomButton('Salir', salir); | ||
| 28 | }); | ||
| 29 | |||
| 30 | $timeout(function() {getLSVisita();}); | ||
| 31 | } | ||
| 22 | 32 | ||
| 23 | $scope.seleccionarCliente = function() { | 33 | $scope.seleccionarCliente = function() { |
| 24 | var modalInstance = $uibModal.open( | 34 | var modalInstance = $uibModal.open( |
| 25 | { | 35 | { |
| 26 | ariaLabelledBy: 'Busqueda de Cliente', | 36 | ariaLabelledBy: 'Busqueda de Cliente', |
| 27 | templateUrl: 'foca-busqueda-cliente-modal.html', | 37 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 28 | controller: 'focaBusquedaClienteModalController', | 38 | controller: 'focaBusquedaClienteModalController', |
| 29 | resolve: { | 39 | resolve: { |
| 30 | vendedor: function() { return null; } | 40 | vendedor: function() { return null; } |
| 31 | }, | 41 | }, |
| 32 | size: 'lg' | 42 | size: 'lg' |
| 33 | } | 43 | } |
| 34 | ); | 44 | ); |
| 35 | modalInstance.result.then( | 45 | modalInstance.result.then( |
| 36 | function(cliente) { | 46 | function(cliente) { |
| 37 | $scope.visita.cliente = cliente; | 47 | $scope.visita.cliente = cliente; |
| 38 | $scope.$broadcast('addCabecera', { | 48 | $scope.$broadcast('addCabecera', { |
| 39 | label: 'Cliente:', | 49 | label: 'Cliente:', |
| 40 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + | 50 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + |
| 41 | cliente.nom | 51 | cliente.nom |
| 42 | }); | 52 | }); |
| 43 | } | 53 | } |
| 44 | ); | 54 | ); |
| 45 | }; | 55 | }; |
| 46 | function setearVisita(visita){ | 56 | function setearVisita(visita){ |
| 47 | $scope.visita = visita; | 57 | $scope.visita = visita; |
| 48 | $scope.$broadcast('addCabecera', { | 58 | $scope.$broadcast('addCabecera', { |
| 49 | label: 'Cliente:', | 59 | label: 'Cliente:', |
| 50 | valor: $filter('rellenarDigitos')(visita.cliente.cod, 3) + ' - ' + | 60 | valor: $filter('rellenarDigitos')(visita.cliente.cod, 3) + ' - ' + |
| 51 | visita.cliente.nom | 61 | visita.cliente.nom |
| 52 | }); | 62 | }); |
| 53 | } | 63 | } |
| 54 | function getLSVisita(){ | 64 | function getLSVisita(){ |
| 55 | var visita= JSON.parse($localStorage.visita || null); | 65 | var visita = JSON.parse($localStorage.visita || null); |
| 56 | if (visita) { | 66 | if (visita) { |
| 57 | setearVisita(visita); | 67 | setearVisita(visita); |
| 58 | delete $localStorage.visita; | 68 | delete $localStorage.visita; |
| 59 | } | 69 | } |
| 60 | } | 70 | } |
| 61 | 71 | ||
| 62 | $scope.seleccionarVisitante = function() { | 72 | $scope.seleccionarVisitante = function() { |
| 63 | var parametrosModal = { | 73 | var parametrosModal = { |
| 64 | query: '/vendedor-cobrador', | 74 | query: '/vendedor-cobrador', |
| 65 | columnas: [ | 75 | columnas: [ |
| 66 | { | 76 | { |
| 67 | propiedad: 'NUM', | 77 | propiedad: 'NUM', |
| 68 | nombre: 'Codigo', | 78 | nombre: 'Codigo', |
| 69 | filtro: { | 79 | filtro: { |
| 70 | nombre: 'rellenarDigitos', | 80 | nombre: 'rellenarDigitos', |
| 71 | parametro: 3 | 81 | parametro: 3 |
| 72 | } | 82 | } |
| 73 | }, | 83 | }, |
| 74 | { | 84 | { |
| 75 | propiedad: 'NOM', | 85 | propiedad: 'NOM', |
| 76 | nombre: 'Nombre' | 86 | nombre: 'Nombre' |
| 77 | } | 87 | } |
| 78 | ], | 88 | ], |
| 79 | titulo:'Búsqueda de vendedores y cobradores', | 89 | titulo:'Búsqueda de vendedores y cobradores', |
| 80 | size: 'md' | 90 | size: 'md' |
| 81 | }; | 91 | }; |
| 82 | focaModalService.modal(parametrosModal).then(function(vendedorCobrador) { | 92 | focaModalService.modal(parametrosModal).then(function(vendedorCobrador) { |
| 83 | if (vendedorCobrador.rol === 3) { | 93 | if (vendedorCobrador.rol === 3) { |
| 84 | $uibModal.open( | 94 | $uibModal.open( |
| 85 | { | 95 | { |
| 86 | ariaLabelledBy: 'Seleccionar tipo de visita', | 96 | ariaLabelledBy: 'Seleccionar tipo de visita', |
| 87 | templateUrl: 'modal-tipo-visita.html', | 97 | templateUrl: 'modal-tipo-visita.html', |
| 88 | controller: 'focaModalTipoVisita', | 98 | controller: 'focaModalTipoVisita', |
| 89 | resolve: {}, | 99 | resolve: {}, |
| 90 | size: 'md' | 100 | size: 'md' |
| 91 | } | 101 | } |
| 92 | ) | 102 | ) |
| 93 | .result | 103 | .result |
| 94 | .then(function(res) { | 104 | .then(function(res) { |
| 95 | $scope.rol = res; | 105 | $scope.rol = res; |
| 96 | $scope.visita.visitante = vendedorCobrador; | 106 | $scope.visita.visitante = vendedorCobrador; |
| 97 | $scope.$broadcast('addCabecera', { | 107 | $scope.$broadcast('addCabecera', { |
| 98 | label: 'Vendedor:', | 108 | label: 'Vendedor:', |
| 99 | valor: $filter('rellenarDigitos')(vendedorCobrador.NUM, 3) + ' - ' + | 109 | valor: $filter('rellenarDigitos')(vendedorCobrador.NUM, 3) + ' - ' + |
| 100 | vendedorCobrador.NOM | 110 | vendedorCobrador.NOM |
| 101 | }); | 111 | }); |
| 102 | }); | 112 | }); |
| 103 | 113 | ||
| 104 | } else { | 114 | } else { |
| 105 | $scope.visita.visitante = vendedorCobrador; | 115 | $scope.visita.visitante = vendedorCobrador; |
| 106 | $scope.$broadcast('addCabecera', { | 116 | $scope.$broadcast('addCabecera', { |
| 107 | label: 'Vendedor:', | 117 | label: 'Vendedor:', |
| 108 | valor: $filter('rellenarDigitos')(vendedorCobrador.NUM, 3) + ' - ' + | 118 | valor: $filter('rellenarDigitos')(vendedorCobrador.NUM, 3) + ' - ' + |
| 109 | vendedorCobrador.NOM | 119 | vendedorCobrador.NOM |
| 110 | }); | 120 | }); |
| 111 | } | 121 | } |
| 112 | 122 | ||
| 113 | }); | 123 | }); |
| 114 | }; | 124 | }; |
| 115 | $scope.seleccionarObservaciones = function() { | 125 | $scope.seleccionarObservaciones = function() { |
| 116 | focaModalService | 126 | focaModalService |
| 117 | .prompt('Ingrese observaciones', $scope.visita.observacion, true) | 127 | .prompt('Ingrese observaciones', $scope.visita.observacion, true) |
| 118 | .then(function(observacion) { | 128 | .then(function(observacion) { |
| 119 | $scope.visita.observacion = observacion; | 129 | $scope.visita.observacion = observacion; |
| 120 | }); | 130 | }); |
| 121 | }; | 131 | }; |
| 122 | 132 | ||
| 123 | $scope.next = function(key) { | 133 | $scope.next = function(key) { |
| 124 | if (key === 13) $scope.focused ++; | 134 | if (key === 13) $scope.focused ++; |
| 125 | }; | 135 | }; |
| 126 | 136 | ||
| 127 | $scope.$watch('visita', function(newValue, oldValue){ | 137 | $scope.$watch('visita', function(newValue, oldValue){ |
| 128 | focaBotoneraLateralService.setPausarData({ | 138 | focaBotoneraLateralService.setPausarData({ |
| 129 | label: 'visita', | 139 | label: 'visita', |
| 130 | val: newValue | 140 | val: newValue |
| 131 | }); | 141 | }); |
| 132 | }); | 142 | }); |
| 133 | 143 | ||
| 134 | $scope.guardar = function() { | 144 | $scope.guardar = function() { |
| 135 | var rol; | 145 | var rol; |
| 136 | if ($scope.visita.visitante.rol === 1) { | 146 | if ($scope.visita.visitante.rol === 1) { |
| 137 | rol = 'Nota de pedido'; | 147 | rol = 'Nota de pedido'; |
| 138 | } else if ($scope.visita.visitante.rol === 2) { | 148 | } else if ($scope.visita.visitante.rol === 2) { |
| 139 | rol = 'Cobranza'; | 149 | rol = 'Cobranza'; |
| 140 | } else { | 150 | } else { |
| 141 | rol = ($scope.rol === 1) ? 'Nota de pedido' : 'Cobranza'; | 151 | rol = ($scope.rol === 1) ? 'Nota de pedido' : 'Cobranza'; |
| 142 | } | 152 | } |
| 143 | 153 | ||
| 144 | focaAgendarVisitaService | 154 | focaAgendarVisitaService |
| 145 | .guardarVisita({ | 155 | .guardarVisita({ |
| 146 | idVisitante: $scope.visita.visitante.NUM, | 156 | idVisitante: $scope.visita.visitante.NUM, |
| 147 | idCliente: $scope.visita.cliente.cod | 157 | idCliente: $scope.visita.cliente.cod |
| 148 | }) | 158 | }) |
| 149 | .then(function(data) { | 159 | .then(function(data) { |
| 150 | focaSeguimientoService.guardarPosicion( | 160 | focaSeguimientoService.guardarPosicion( |
| 151 | rol, | 161 | rol, |
| 152 | data.data.id, | 162 | data.data.id, |
| 153 | $scope.visita.observacion, | 163 | $scope.visita.observacion, |
| 154 | data.data.id | 164 | data.data.id |
| 155 | ); | 165 | ); |
| 156 | }) | 166 | }) |
| 157 | .then(function() { | 167 | .then(function() { |
| 158 | $location.path('/'); | 168 | $location.path('/'); |
| 159 | }); | 169 | }); |
| 160 | }; | 170 | }; |
| 171 | function salir() { | ||
| 172 | var confirmar = angular.equals($scope.visita, {}); | ||
| 173 | |||
| 174 | if (!confirmar) { | ||
| 175 | focaModalService.confirm( | ||
| 176 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | ||
| 177 | ).then(function(data) { | ||
| 178 | if (data) $location.path('/'); | ||
| 179 | }); | ||
| 180 | } else { | ||
| 181 | $location.path('/'); | ||
| 182 | } | ||
| 183 | } | ||
| 161 | } | 184 | } |
| 162 | ]) | 185 | ]) |
| 163 | .controller('focaModalTipoVisita', ['$uibModalInstance', '$scope', | 186 | .controller('focaModalTipoVisita', ['$uibModalInstance', '$scope', |
| 164 | function($uibModalInstance, $scope) { | 187 | function($uibModalInstance, $scope) { |