Commit 1c2bda9be56c0f6f853e490b44627043a4243357

Authored by Luigi
1 parent 98e8b1ed02
Exists in master

Boton Pausar Agendar Visita

Showing 2 changed files with 30 additions and 4 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', '$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, $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; 10 $scope.focused = 0;
11 $scope.rol = 1; 11 $scope.rol = 1;
12 $scope.visita = {}; 12 $scope.visita = {};
13 $scope.now = new Date(); 13 $scope.now = new Date();
14 $scope.botonera = focaAgendarVisitaService.getBotonera(); 14 $scope.botonera = focaAgendarVisitaService.getBotonera();
15 $timeout(function() { 15 $timeout(function() {
16 focaBotoneraLateralService.showSalir(true); 16 focaBotoneraLateralService.showSalir(true);
17 focaBotoneraLateralService.showPausar(true); 17 focaBotoneraLateralService.showPausar(true);
18 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 18 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
19 }); 19 });
20 20
21 $timeout(function() {getLSVisita();});
22
21 $scope.seleccionarCliente = function() { 23 $scope.seleccionarCliente = function() {
22 var modalInstance = $uibModal.open( 24 var modalInstance = $uibModal.open(
23 { 25 {
24 ariaLabelledBy: 'Busqueda de Cliente', 26 ariaLabelledBy: 'Busqueda de Cliente',
25 templateUrl: 'foca-busqueda-cliente-modal.html', 27 templateUrl: 'foca-busqueda-cliente-modal.html',
26 controller: 'focaBusquedaClienteModalController', 28 controller: 'focaBusquedaClienteModalController',
27 resolve: { 29 resolve: {
28 vendedor: function() { return null; } 30 vendedor: function() { return null; }
29 }, 31 },
30 size: 'lg' 32 size: 'lg'
31 } 33 }
32 ); 34 );
33 modalInstance.result.then( 35 modalInstance.result.then(
34 function(cliente) { 36 function(cliente) {
35 $scope.visita.cliente = cliente; 37 $scope.visita.cliente = cliente;
36 $scope.$broadcast('addCabecera', { 38 $scope.$broadcast('addCabecera', {
37 label: 'Cliente:', 39 label: 'Cliente:',
38 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + 40 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' +
39 cliente.nom 41 cliente.nom
40 }); 42 });
41 } 43 }
42 ); 44 );
43 }; 45 };
46 function setearVisita(visita){
47 $scope.visita = visita;
48 $scope.$broadcast('addCabecera', {
49 label: 'Cliente:',
50 valor: $filter('rellenarDigitos')(visita.cliente.cod, 3) + ' - ' +
51 visita.cliente.nom
52 });
53 }
54 function getLSVisita(){
55 var visita= JSON.parse($localStorage.visita || null);
56 if (visita) {
57 setearVisita(visita);
58 delete $localStorage.visita;
59 }
60 }
61
44 $scope.seleccionarVisitante = function() { 62 $scope.seleccionarVisitante = function() {
45 var parametrosModal = { 63 var parametrosModal = {
46 query: '/vendedor-cobrador', 64 query: '/vendedor-cobrador',
47 columnas: [ 65 columnas: [
48 { 66 {
49 propiedad: 'NUM', 67 propiedad: 'NUM',
50 nombre: 'Codigo', 68 nombre: 'Codigo',
51 filtro: { 69 filtro: {
52 nombre: 'rellenarDigitos', 70 nombre: 'rellenarDigitos',
53 parametro: 3 71 parametro: 3
54 } 72 }
55 }, 73 },
56 { 74 {
57 propiedad: 'NOM', 75 propiedad: 'NOM',
58 nombre: 'Nombre' 76 nombre: 'Nombre'
59 } 77 }
60 ], 78 ],
61 titulo:'Búsqueda de vendedores y cobradores', 79 titulo:'Búsqueda de vendedores y cobradores',
62 size: 'md' 80 size: 'md'
63 }; 81 };
64 focaModalService.modal(parametrosModal).then(function(vendedorCobrador) { 82 focaModalService.modal(parametrosModal).then(function(vendedorCobrador) {
65 if (vendedorCobrador.rol === 3) { 83 if (vendedorCobrador.rol === 3) {
66 $uibModal.open( 84 $uibModal.open(
67 { 85 {
68 ariaLabelledBy: 'Seleccionar tipo de visita', 86 ariaLabelledBy: 'Seleccionar tipo de visita',
69 templateUrl: 'modal-tipo-visita.html', 87 templateUrl: 'modal-tipo-visita.html',
70 controller: 'focaModalTipoVisita', 88 controller: 'focaModalTipoVisita',
71 resolve: {}, 89 resolve: {},
72 size: 'md' 90 size: 'md'
73 } 91 }
74 ) 92 )
75 .result 93 .result
76 .then(function(res) { 94 .then(function(res) {
77 $scope.rol = res; 95 $scope.rol = res;
78 $scope.visita.visitante = vendedorCobrador; 96 $scope.visita.visitante = vendedorCobrador;
79 $scope.$broadcast('addCabecera', { 97 $scope.$broadcast('addCabecera', {
80 label: 'Vendedor:', 98 label: 'Vendedor:',
81 valor: $filter('rellenarDigitos')(vendedorCobrador.NUM, 3) + ' - ' + 99 valor: $filter('rellenarDigitos')(vendedorCobrador.NUM, 3) + ' - ' +
82 vendedorCobrador.NOM 100 vendedorCobrador.NOM
83 }); 101 });
84 }); 102 });
85 103
86 } else { 104 } else {
87 $scope.visita.visitante = vendedorCobrador; 105 $scope.visita.visitante = vendedorCobrador;
88 $scope.$broadcast('addCabecera', { 106 $scope.$broadcast('addCabecera', {
89 label: 'Vendedor:', 107 label: 'Vendedor:',
90 valor: $filter('rellenarDigitos')(vendedorCobrador.NUM, 3) + ' - ' + 108 valor: $filter('rellenarDigitos')(vendedorCobrador.NUM, 3) + ' - ' +
91 vendedorCobrador.NOM 109 vendedorCobrador.NOM
92 }); 110 });
93 } 111 }
94 112
95 }); 113 });
96 }; 114 };
97 $scope.seleccionarObservaciones = function() { 115 $scope.seleccionarObservaciones = function() {
98 focaModalService 116 focaModalService
99 .prompt('Ingrese observaciones', $scope.visita.observacion, true) 117 .prompt('Ingrese observaciones', $scope.visita.observacion, true)
100 .then(function(observacion) { 118 .then(function(observacion) {
101 $scope.visita.observacion = observacion; 119 $scope.visita.observacion = observacion;
102 }); 120 });
103 }; 121 };
104 122
105 $scope.next = function(key) { 123 $scope.next = function(key) {
106 if (key === 13) $scope.focused ++; 124 if (key === 13) $scope.focused ++;
107 }; 125 };
108 126
127 $scope.$watch('visita', function(newValue, oldValue){
128 focaBotoneraLateralService.setPausarData({
129 label: 'visita',
130 val: newValue
131 });
132 });
133
109 $scope.guardar = function() { 134 $scope.guardar = function() {
110 var rol; 135 var rol;
111 if ($scope.visita.visitante.rol === 1) { 136 if ($scope.visita.visitante.rol === 1) {
112 rol = 'Nota de pedido'; 137 rol = 'Nota de pedido';
113 } else if ($scope.visita.visitante.rol === 2) { 138 } else if ($scope.visita.visitante.rol === 2) {
114 rol = 'Cobranza'; 139 rol = 'Cobranza';
115 } else { 140 } else {
116 rol = ($scope.rol === 1) ? 'Nota de pedido' : 'Cobranza'; 141 rol = ($scope.rol === 1) ? 'Nota de pedido' : 'Cobranza';
117 } 142 }
118 143
119 focaAgendarVisitaService 144 focaAgendarVisitaService
120 .guardarVisita({ 145 .guardarVisita({
121 idVisitante: $scope.visita.visitante.NUM, 146 idVisitante: $scope.visita.visitante.NUM,
122 idCliente: $scope.visita.cliente.cod 147 idCliente: $scope.visita.cliente.cod
123 }) 148 })
124 .then(function(data) { 149 .then(function(data) {
125 focaSeguimientoService.guardarPosicion( 150 focaSeguimientoService.guardarPosicion(
126 rol, 151 rol,
127 data.data.id, 152 data.data.id,
128 $scope.visita.observacion, 153 $scope.visita.observacion,
129 data.data.id 154 data.data.id
130 ); 155 );
131 }) 156 })
132 .then(function() { 157 .then(function() {
133 $location.path('/'); 158 $location.path('/');
134 }); 159 });
135 }; 160 };
136 } 161 }
137 ]) 162 ])
138 .controller('focaModalTipoVisita', ['$uibModalInstance', '$scope', 163 .controller('focaModalTipoVisita', ['$uibModalInstance', '$scope',
139 function($uibModalInstance, $scope) { 164 function($uibModalInstance, $scope) {
140 $scope.cancel = function() { 165 $scope.cancel = function() {
141 $uibModalInstance.dismiss(); 166 $uibModalInstance.dismiss();
142 }; 167 };
143 168
144 $scope.select = function(val) { 169 $scope.select = function(val) {
145 $uibModalInstance.close(val); 170 $uibModalInstance.close(val);
146 }; 171 };
147 } 172 }
148 ]); 173 ]);
149 174
1 angular.module('focaAgendarVisita') 1 angular.module('focaAgendarVisita')
2 .factory('focaAgendarVisitaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { 2 .factory('focaAgendarVisitaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
3 return { 3 return {
4 guardarVisita: function(visita) { 4 guardarVisita: function(visita) {
5 return $http.post(API_ENDPOINT.URL + '/visita', {visita: visita}); 5 return $http.post(API_ENDPOINT.URL + '/visita', {visita: visita});
6 }, 6 },
7 getBotonera: function() { 7 getBotonera: function() {
8 return [ 8 return [
9 { 9 {
10 label: 'Cliente', 10 label: 'Cliente',
11 image: 'precios-condiciones.png' 11 image: 'precios-condiciones.png'
12 }, 12 },
13 { 13 {
14 label: 'Visitante', 14 label: 'Visitante',
15 image: 'precios-condiciones.png' 15 image: 'precios-condiciones.png'
16 }, 16 },
17 { 17 {
18 label: 'Observaciones', 18 label: 'Observaciones',
19 image: 'precios-condiciones.png' 19 image: 'precios-condiciones.png'
20 } 20 }
21 ] 21 ];
22 } 22 }
23 }; 23 };
24 }]); 24 }]);
25