Commit 15fb920e382803c4c5253b680700229c32a842d5

Authored by Jose Pinto
1 parent 6b95661cdd
Exists in master

ok modal-busqueda-cliente

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