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