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