Commit 6523c2ded5a7b8e2913dc85a92709124ad7546b9

Authored by Pablo Marco del Pont
1 parent 5ec23981eb
Exists in master

Agregué llamado al modulo foca-seguimento.

Showing 1 changed file with 4 additions and 2 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', 1 angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
2 [ 2 [
3 '$scope', '$uibModal', '$location', '$filter', 'crearNotaPedidoService', 3 '$scope', '$uibModal', '$location', '$filter', 'crearNotaPedidoService',
4 'focaModalService', 4 'focaModalService', 'focaSeguimientoService',
5 function( 5 function(
6 $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService 6 $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService,
7 focaSeguimientoService
7 ) { 8 ) {
8 $scope.botonera = [ 9 $scope.botonera = [
9 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}}, 10 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}},
10 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, 11 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}},
11 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}}, 12 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}},
12 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}}, 13 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}},
13 { 14 {
14 texto: 'Precios y condiciones', 15 texto: 'Precios y condiciones',
15 accion: function() {$scope.abrirModalListaPrecio();}}, 16 accion: function() {$scope.abrirModalListaPrecio();}},
16 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}}, 17 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}},
17 {texto: '', accion: function() {}}, 18 {texto: '', accion: function() {}},
18 {texto: '', accion: function() {}} 19 {texto: '', accion: function() {}}
19 ]; 20 ];
20 $scope.datepickerAbierto = false; 21 $scope.datepickerAbierto = false;
21 22
22 $scope.show = false; 23 $scope.show = false;
23 $scope.cargando = true; 24 $scope.cargando = true;
24 $scope.dateOptions = { 25 $scope.dateOptions = {
25 maxDate: new Date(), 26 maxDate: new Date(),
26 minDate: new Date(2010, 0, 1) 27 minDate: new Date(2010, 0, 1)
27 }; 28 };
28 29
29 $scope.notaPedido = { 30 $scope.notaPedido = {
30 vendedor: {}, 31 vendedor: {},
31 cliente: {}, 32 cliente: {},
32 domicilio: {dom: ''}, 33 domicilio: {dom: ''},
33 moneda: {detalle: ''} 34 moneda: {detalle: ''}
34 }; 35 };
35 36
36 $scope.cabecera = []; 37 $scope.cabecera = [];
37 $scope.showCabecera = true; 38 $scope.showCabecera = true;
38 39
39 $scope.now = new Date(); 40 $scope.now = new Date();
40 $scope.puntoVenta = Math.round(Math.random() * 10000); 41 $scope.puntoVenta = Math.round(Math.random() * 10000);
41 $scope.comprobante = Math.round(Math.random() * 1000000); 42 $scope.comprobante = Math.round(Math.random() * 1000000);
42 43
43 $scope.articulosTabla = []; 44 $scope.articulosTabla = [];
44 var idLista; 45 var idLista;
45 var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); 46 var notaPedidoTemp = crearNotaPedidoService.getNotaPedido();
46 crearNotaPedidoService.getPrecioCondicion().then( 47 crearNotaPedidoService.getPrecioCondicion().then(
47 function(res) { 48 function(res) {
48 $scope.precioCondiciones = res.data; 49 $scope.precioCondiciones = res.data;
49 } 50 }
50 ); 51 );
51 if (notaPedidoTemp !== undefined) { 52 if (notaPedidoTemp !== undefined) {
52 notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); 53 notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga);
53 $scope.notaPedido = notaPedidoTemp; 54 $scope.notaPedido = notaPedidoTemp;
54 $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); 55 $scope.notaPedido.flete = ($scope.notaPedido.flete).toString();
55 $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); 56 $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString();
56 idLista = $scope.notaPedido.precioCondicion; 57 idLista = $scope.notaPedido.precioCondicion;
57 crearNotaPedidoService 58 crearNotaPedidoService
58 .getArticulosByIdNotaPedido($scope.notaPedido.id).then( 59 .getArticulosByIdNotaPedido($scope.notaPedido.id).then(
59 function(res) { 60 function(res) {
60 $scope.articulosTabla = res.data; 61 $scope.articulosTabla = res.data;
61 } 62 }
62 ); 63 );
63 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO 64 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO
64 //(NO REQUERIDO EN ESTA VERSION) 65 //(NO REQUERIDO EN ESTA VERSION)
65 // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( 66 // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then(
66 // function(res) { 67 // function(res) {
67 // $scope.notaPedido.domicilio = res.data; 68 // $scope.notaPedido.domicilio = res.data;
68 // } 69 // }
69 // ); 70 // );
70 } else { 71 } else {
71 $scope.notaPedido.fechaCarga = new Date(); 72 $scope.notaPedido.fechaCarga = new Date();
72 $scope.notaPedido.bomba = '0'; 73 $scope.notaPedido.bomba = '0';
73 $scope.notaPedido.flete = '0'; 74 $scope.notaPedido.flete = '0';
74 idLista = undefined; 75 idLista = undefined;
75 } 76 }
76 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO 77 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO
77 // $scope.addNewDom = function() { 78 // $scope.addNewDom = function() {
78 // $scope.notaPedido.domicilio.push({ 'id': 0 }); 79 // $scope.notaPedido.domicilio.push({ 'id': 0 });
79 // }; 80 // };
80 // $scope.removeNewChoice = function(choice) { 81 // $scope.removeNewChoice = function(choice) {
81 // if ($scope.notaPedido.domicilio.length > 1) { 82 // if ($scope.notaPedido.domicilio.length > 1) {
82 // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( 83 // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex(
83 // function(c) { 84 // function(c) {
84 // return c.$$hashKey === choice.$$hashKey; 85 // return c.$$hashKey === choice.$$hashKey;
85 // } 86 // }
86 // ), 1); 87 // ), 1);
87 // } 88 // }
88 // }; 89 // };
89 $scope.crearNotaPedido = function() { 90 $scope.crearNotaPedido = function() {
90 if($scope.articulosTabla.length === 0) { 91 if($scope.articulosTabla.length === 0) {
91 focaModalService.alert('Debe cargar almenos un articulo'); 92 focaModalService.alert('Debe cargar almenos un articulo');
92 return; 93 return;
93 } 94 }
94 if($scope.notaPedido.domicilio.id === undefined) { 95 if($scope.notaPedido.domicilio.id === undefined) {
95 $scope.notaPedido.domicilio.id = 0; 96 $scope.notaPedido.domicilio.id = 0;
96 } 97 }
97 var date = new Date(); 98 var date = new Date();
98 var notaPedido = { 99 var notaPedido = {
99 id: 0, 100 id: 0,
100 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) 101 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
101 .toISOString().slice(0, 19).replace('T', ' '), 102 .toISOString().slice(0, 19).replace('T', ' '),
102 vendedor: $scope.notaPedido.vendedor.nombre, 103 vendedor: $scope.notaPedido.vendedor.nombre,
103 idCliente: $scope.notaPedido.cliente.id, 104 idCliente: $scope.notaPedido.cliente.id,
104 domicilio: $scope.notaPedido.domicilio, 105 domicilio: $scope.notaPedido.domicilio,
105 bomba: $scope.notaPedido.bomba, 106 bomba: $scope.notaPedido.bomba,
106 flete: $scope.notaPedido.flete, 107 flete: $scope.notaPedido.flete,
107 total: $scope.getTotal() 108 total: $scope.getTotal()
108 }; 109 };
109 crearNotaPedidoService.crearNotaPedido(notaPedido).then( 110 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
110 function(data) { 111 function(data) {
112 focaSeguimientoService.guardarPosicion('crear nota pedido', '');
111 if($scope.notaPedido.flete === 1) { 113 if($scope.notaPedido.flete === 1) {
112 var flete = { 114 var flete = {
113 idNotaPedido: data.data.id, 115 idNotaPedido: data.data.id,
114 idTransportista: $scope.notaPedido.fleteId, 116 idTransportista: $scope.notaPedido.fleteId,
115 idChofer: $scope.notaPedido.chofer.id, 117 idChofer: $scope.notaPedido.chofer.id,
116 idVehiculo: $scope.notaPedido.vehiculo.id, 118 idVehiculo: $scope.notaPedido.vehiculo.id,
117 kilometros: $scope.notaPedido.kilometros, 119 kilometros: $scope.notaPedido.kilometros,
118 costoKilometro: $scope.notaPedido.costoUnitarioKmFlete 120 costoKilometro: $scope.notaPedido.costoUnitarioKmFlete
119 }; 121 };
120 crearNotaPedidoService.crearFlete(flete); 122 crearNotaPedidoService.crearFlete(flete);
121 } 123 }
122 var articulosNotaPedido = $scope.articulosTabla; 124 var articulosNotaPedido = $scope.articulosTabla;
123 for(var i = 0; i < articulosNotaPedido.length; i++) { 125 for(var i = 0; i < articulosNotaPedido.length; i++) {
124 delete articulosNotaPedido[i].edit; 126 delete articulosNotaPedido[i].edit;
125 articulosNotaPedido[i].idNotaPedido = data.data.id; 127 articulosNotaPedido[i].idNotaPedido = data.data.id;
126 crearNotaPedidoService 128 crearNotaPedidoService
127 .crearArticulosParaNotaPedido(articulosNotaPedido[i]); 129 .crearArticulosParaNotaPedido(articulosNotaPedido[i]);
128 } 130 }
129 var plazos = $scope.plazosPagos; 131 var plazos = $scope.plazosPagos;
130 for(var j = 0; j < plazos.length; j++) { 132 for(var j = 0; j < plazos.length; j++) {
131 var json = { 133 var json = {
132 idPedido: data.data.id, 134 idPedido: data.data.id,
133 dias: plazos[j].dias 135 dias: plazos[j].dias
134 }; 136 };
135 crearNotaPedidoService.crearPlazosParaNotaPedido(json); 137 crearNotaPedidoService.crearPlazosParaNotaPedido(json);
136 } 138 }
137 focaModalService.alert('Nota pedido creada'); 139 focaModalService.alert('Nota pedido creada');
138 $scope.limpiarPantalla(); 140 $scope.limpiarPantalla();
139 } 141 }
140 ); 142 );
141 }; 143 };
142 144
143 $scope.seleccionarArticulo = function() { 145 $scope.seleccionarArticulo = function() {
144 if (idLista === undefined) { 146 if (idLista === undefined) {
145 focaModalService.alert( 147 focaModalService.alert(
146 'Primero seleccione una lista de precio y condicion'); 148 'Primero seleccione una lista de precio y condicion');
147 return; 149 return;
148 } 150 }
149 var modalInstance = $uibModal.open( 151 var modalInstance = $uibModal.open(
150 { 152 {
151 ariaLabelledBy: 'Busqueda de Productos', 153 ariaLabelledBy: 'Busqueda de Productos',
152 templateUrl: 'modal-busqueda-productos.html', 154 templateUrl: 'modal-busqueda-productos.html',
153 controller: 'modalBusquedaProductosCtrl', 155 controller: 'modalBusquedaProductosCtrl',
154 resolve: { idLista: function() { return idLista; } }, 156 resolve: { idLista: function() { return idLista; } },
155 size: 'lg' 157 size: 'lg'
156 } 158 }
157 ); 159 );
158 modalInstance.result.then( 160 modalInstance.result.then(
159 function(producto) { 161 function(producto) {
160 var newArt = 162 var newArt =
161 { 163 {
162 id: 0, 164 id: 0,
163 codigo: producto.codigo, 165 codigo: producto.codigo,
164 sector: producto.sector, 166 sector: producto.sector,
165 sectorCodigo: producto.sector + '-' + producto.codigo, 167 sectorCodigo: producto.sector + '-' + producto.codigo,
166 descripcion: producto.descripcion, 168 descripcion: producto.descripcion,
167 item: $scope.articulosTabla.length + 1, 169 item: $scope.articulosTabla.length + 1,
168 nombre: producto.descripcion, 170 nombre: producto.descripcion,
169 precio: producto.precio.toFixed(2), 171 precio: producto.precio.toFixed(2),
170 costoUnitario: producto.costo, 172 costoUnitario: producto.costo,
171 edit: false 173 edit: false
172 }; 174 };
173 $scope.articuloACargar = newArt; 175 $scope.articuloACargar = newArt;
174 $scope.cargando = false; 176 $scope.cargando = false;
175 }, function() { 177 }, function() {
176 // funcion ejecutada cuando se cancela el modal 178 // funcion ejecutada cuando se cancela el modal
177 } 179 }
178 ); 180 );
179 }; 181 };
180 182
181 $scope.seleccionarVendedor = function() { 183 $scope.seleccionarVendedor = function() {
182 var modalInstance = $uibModal.open( 184 var modalInstance = $uibModal.open(
183 { 185 {
184 ariaLabelledBy: 'Busqueda de Vendedores', 186 ariaLabelledBy: 'Busqueda de Vendedores',
185 templateUrl: 'modal-vendedores.html', 187 templateUrl: 'modal-vendedores.html',
186 controller: 'modalVendedoresCtrl', 188 controller: 'modalVendedoresCtrl',
187 size: 'lg' 189 size: 'lg'
188 } 190 }
189 ); 191 );
190 modalInstance.result.then( 192 modalInstance.result.then(
191 function(vendedor) { 193 function(vendedor) {
192 addCabecera('Vendedor:', vendedor.NomVen); 194 addCabecera('Vendedor:', vendedor.NomVen);
193 $scope.notaPedido.vendedor.nombre = vendedor.NomVen; 195 $scope.notaPedido.vendedor.nombre = vendedor.NomVen;
194 }, function() { 196 }, function() {
195 197
196 } 198 }
197 ); 199 );
198 }; 200 };
199 201
200 $scope.seleccionarProveedor = function() { 202 $scope.seleccionarProveedor = function() {
201 var modalInstance = $uibModal.open( 203 var modalInstance = $uibModal.open(
202 { 204 {
203 ariaLabelledBy: 'Busqueda de Proveedor', 205 ariaLabelledBy: 'Busqueda de Proveedor',
204 templateUrl: 'modal-proveedor.html', 206 templateUrl: 'modal-proveedor.html',
205 controller: 'focaModalProveedorCtrl', 207 controller: 'focaModalProveedorCtrl',
206 size: 'lg' 208 size: 'lg'
207 } 209 }
208 ); 210 );
209 modalInstance.result.then( 211 modalInstance.result.then(
210 function(proveedor) { 212 function(proveedor) {
211 $scope.notaPedido.proveedor = proveedor.NOM; 213 $scope.notaPedido.proveedor = proveedor.NOM;
212 addCabecera('Proveedor:', proveedor.NOM); 214 addCabecera('Proveedor:', proveedor.NOM);
213 }, function() { 215 }, function() {
214 216
215 } 217 }
216 ); 218 );
217 }; 219 };
218 220
219 $scope.seleccionarCliente = function() { 221 $scope.seleccionarCliente = function() {
220 var modalInstance = $uibModal.open( 222 var modalInstance = $uibModal.open(
221 { 223 {
222 ariaLabelledBy: 'Busqueda de Cliente', 224 ariaLabelledBy: 'Busqueda de Cliente',
223 templateUrl: 'foca-busqueda-cliente-modal.html', 225 templateUrl: 'foca-busqueda-cliente-modal.html',
224 controller: 'focaBusquedaClienteModalController', 226 controller: 'focaBusquedaClienteModalController',
225 size: 'lg' 227 size: 'lg'
226 } 228 }
227 ); 229 );
228 modalInstance.result.then( 230 modalInstance.result.then(
229 function(cliente) { 231 function(cliente) {
230 $scope.notaPedido.cliente.nombre = cliente.nom; 232 $scope.notaPedido.cliente.nombre = cliente.nom;
231 $scope.notaPedido.cliente.id = cliente.cod; 233 $scope.notaPedido.cliente.id = cliente.cod;
232 crearNotaPedidoService.getDomiciliosByIdCliente(cliente.cod).then( 234 crearNotaPedidoService.getDomiciliosByIdCliente(cliente.cod).then(
233 function(data) { 235 function(data) {
234 if(data.data.length === 0){ 236 if(data.data.length === 0){
235 focaModalService 237 focaModalService
236 .alert('El cliente no tienen domicilios de entrega') 238 .alert('El cliente no tienen domicilios de entrega')
237 .then( 239 .then(
238 function() { 240 function() {
239 $scope.seleccionarCliente(); 241 $scope.seleccionarCliente();
240 $scope.notaPedido.cliente = {nombre: ''}; 242 $scope.notaPedido.cliente = {nombre: ''};
241 } 243 }
242 ); 244 );
243 return; 245 return;
244 } 246 }
245 var modalInstanceDomicilio = $uibModal.open( 247 var modalInstanceDomicilio = $uibModal.open(
246 { 248 {
247 ariaLabelledBy: 'Busqueda de Domicilios', 249 ariaLabelledBy: 'Busqueda de Domicilios',
248 templateUrl: 'modal-domicilio.html', 250 templateUrl: 'modal-domicilio.html',
249 controller: 'focaModalDomicilioController', 251 controller: 'focaModalDomicilioController',
250 resolve: { idCliente: function() { return cliente.cod; }}, 252 resolve: { idCliente: function() { return cliente.cod; }},
251 size: 'lg', 253 size: 'lg',
252 backdrop: 'static', 254 backdrop: 'static',
253 } 255 }
254 ); 256 );
255 modalInstanceDomicilio.result.then( 257 modalInstanceDomicilio.result.then(
256 function(domicilio) { 258 function(domicilio) {
257 focaModalService.alert('Domicilio elegido' + domicilio.dom); 259 focaModalService.alert('Domicilio elegido' + domicilio.dom);
258 }, function() { 260 }, function() {
259 $scope.notaPedido.cliente.nombre = ''; 261 $scope.notaPedido.cliente.nombre = '';
260 $scope.notaPedido.cliente.id = ''; 262 $scope.notaPedido.cliente.id = '';
261 removeCabecera('Cliente:'); 263 removeCabecera('Cliente:');
262 $scope.seleccionarCliente(); 264 $scope.seleccionarCliente();
263 return; 265 return;
264 } 266 }
265 ); 267 );
266 } 268 }
267 ); 269 );
268 addCabecera('Cliente:', cliente.nom); 270 addCabecera('Cliente:', cliente.nom);
269 }, function() { 271 }, function() {
270 272
271 } 273 }
272 ); 274 );
273 }; 275 };
274 276
275 $scope.mostrarFichaCliente = function() { 277 $scope.mostrarFichaCliente = function() {
276 $uibModal.open( 278 $uibModal.open(
277 { 279 {
278 ariaLabelledBy: 'Datos del Cliente', 280 ariaLabelledBy: 'Datos del Cliente',
279 templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', 281 templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html',
280 controller: 'focaCrearNotaPedidoFichaClienteController', 282 controller: 'focaCrearNotaPedidoFichaClienteController',
281 size: 'lg' 283 size: 'lg'
282 } 284 }
283 ); 285 );
284 }; 286 };
285 287
286 $scope.getTotal = function() { 288 $scope.getTotal = function() {
287 var total = 0; 289 var total = 0;
288 var arrayTempArticulos = $scope.articulosTabla; 290 var arrayTempArticulos = $scope.articulosTabla;
289 for (var i = 0; i < arrayTempArticulos.length; i++) { 291 for (var i = 0; i < arrayTempArticulos.length; i++) {
290 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 292 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
291 } 293 }
292 return total.toFixed(2); 294 return total.toFixed(2);
293 }; 295 };
294 296
295 $scope.getSubTotal = function() { 297 $scope.getSubTotal = function() {
296 if($scope.articuloACargar) { 298 if($scope.articuloACargar) {
297 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 299 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
298 } 300 }
299 }; 301 };
300 302
301 $scope.abrirModalListaPrecio = function() { 303 $scope.abrirModalListaPrecio = function() {
302 var modalInstance = $uibModal.open( 304 var modalInstance = $uibModal.open(
303 { 305 {
304 ariaLabelledBy: 'Busqueda de Precio Condición', 306 ariaLabelledBy: 'Busqueda de Precio Condición',
305 templateUrl: 'modal-precio-condicion.html', 307 templateUrl: 'modal-precio-condicion.html',
306 controller: 'focaModalPrecioCondicionController', 308 controller: 'focaModalPrecioCondicionController',
307 size: 'lg' 309 size: 'lg'
308 } 310 }
309 ); 311 );
310 modalInstance.result.then( 312 modalInstance.result.then(
311 function(precioCondicion) { 313 function(precioCondicion) {
312 var cabecera = ''; 314 var cabecera = '';
313 var plazosConcat = ''; 315 var plazosConcat = '';
314 if(!Array.isArray(precioCondicion)) { 316 if(!Array.isArray(precioCondicion)) {
315 $scope.plazosPagos = precioCondicion.plazoPago; 317 $scope.plazosPagos = precioCondicion.plazoPago;
316 idLista = precioCondicion.idListaPrecio; 318 idLista = precioCondicion.idListaPrecio;
317 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 319 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
318 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 320 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
319 } 321 }
320 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); 322 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim();
321 } else { //Cuando se ingresan los plazos manualmente 323 } else { //Cuando se ingresan los plazos manualmente
322 idLista = -1; //-1, el modal productos busca todos los productos 324 idLista = -1; //-1, el modal productos busca todos los productos
323 $scope.plazosPagos = precioCondicion; 325 $scope.plazosPagos = precioCondicion;
324 for(var j = 0; j < precioCondicion.length; j++) { 326 for(var j = 0; j < precioCondicion.length; j++) {
325 plazosConcat += precioCondicion[j].dias + ' '; 327 plazosConcat += precioCondicion[j].dias + ' ';
326 } 328 }
327 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 329 cabecera = 'Ingreso manual ' + plazosConcat.trim();
328 } 330 }
329 $scope.articulosTabla = []; 331 $scope.articulosTabla = [];
330 addCabecera('Precios y condiciones:', cabecera); 332 addCabecera('Precios y condiciones:', cabecera);
331 }, function() { 333 }, function() {
332 334
333 } 335 }
334 ); 336 );
335 }; 337 };
336 338
337 $scope.abrirModalFlete = function() { 339 $scope.abrirModalFlete = function() {
338 var modalInstance = $uibModal.open( 340 var modalInstance = $uibModal.open(
339 { 341 {
340 ariaLabelledBy: 'Busqueda de Flete', 342 ariaLabelledBy: 'Busqueda de Flete',
341 templateUrl: 'modal-flete.html', 343 templateUrl: 'modal-flete.html',
342 controller: 'focaModalFleteController', 344 controller: 'focaModalFleteController',
343 size: 'lg', 345 size: 'lg',
344 resolve: { 346 resolve: {
345 parametrosFlete: 347 parametrosFlete:
346 function() { 348 function() {
347 return { 349 return {
348 flete: $scope.notaPedido.flete, 350 flete: $scope.notaPedido.flete,
349 bomba: $scope.notaPedido.bomba, 351 bomba: $scope.notaPedido.bomba,
350 kilometros: $scope.notaPedido.kilometros 352 kilometros: $scope.notaPedido.kilometros
351 }; 353 };
352 } 354 }
353 } 355 }
354 } 356 }
355 ); 357 );
356 modalInstance.result.then( 358 modalInstance.result.then(
357 function(datos) { 359 function(datos) {
358 $scope.notaPedido.flete = datos.flete; 360 $scope.notaPedido.flete = datos.flete;
359 $scope.notaPedido.bomba = datos.bomba; 361 $scope.notaPedido.bomba = datos.bomba;
360 $scope.notaPedido.kilometros = datos.kilometros; 362 $scope.notaPedido.kilometros = datos.kilometros;
361 363
362 addCabecera('Flete:', datos.flete); 364 addCabecera('Flete:', datos.flete);
363 if(datos.flete === 'si') { 365 if(datos.flete === 'si') {
364 addCabecera('Bomba:', datos.bomba); 366 addCabecera('Bomba:', datos.bomba);
365 addCabecera('Kilometros:', datos.kilometros); 367 addCabecera('Kilometros:', datos.kilometros);
366 } else { 368 } else {
367 removeCabecera('Bomba:'); 369 removeCabecera('Bomba:');
368 removeCabecera('Kilometros:'); 370 removeCabecera('Kilometros:');
369 } 371 }
370 }, function() { 372 }, function() {
371 373
372 } 374 }
373 ); 375 );
374 }; 376 };
375 377
376 $scope.abrirModalMoneda = function() { 378 $scope.abrirModalMoneda = function() {
377 var modalInstance = $uibModal.open( 379 var modalInstance = $uibModal.open(
378 { 380 {
379 ariaLabelledBy: 'Busqueda de Moneda', 381 ariaLabelledBy: 'Busqueda de Moneda',
380 templateUrl: 'modal-moneda.html', 382 templateUrl: 'modal-moneda.html',
381 controller: 'focaModalMonedaController', 383 controller: 'focaModalMonedaController',
382 size: 'lg' 384 size: 'lg'
383 } 385 }
384 ); 386 );
385 modalInstance.result.then( 387 modalInstance.result.then(
386 function(moneda) { 388 function(moneda) {
387 $scope.notaPedido.moneda = { 389 $scope.notaPedido.moneda = {
388 id: moneda.ID, 390 id: moneda.ID,
389 detalle: moneda.DETALLE, 391 detalle: moneda.DETALLE,
390 simbolo: moneda.SIMBOLO 392 simbolo: moneda.SIMBOLO
391 }; 393 };
392 394
393 addCabecera('Moneda:', moneda.DETALLE); 395 addCabecera('Moneda:', moneda.DETALLE);
394 $scope.abrirModalCotizacion(moneda.ID); 396 $scope.abrirModalCotizacion(moneda.ID);
395 }, function() { 397 }, function() {
396 398
397 } 399 }
398 ); 400 );
399 }; 401 };
400 402
401 $scope.abrirModalCotizacion = function(idMoneda) { 403 $scope.abrirModalCotizacion = function(idMoneda) {
402 var modalInstance = $uibModal.open( 404 var modalInstance = $uibModal.open(
403 { 405 {
404 ariaLabelledBy: 'Busqueda de Cotización', 406 ariaLabelledBy: 'Busqueda de Cotización',
405 templateUrl: 'modal-cotizacion.html', 407 templateUrl: 'modal-cotizacion.html',
406 controller: 'focaModalCotizacionController', 408 controller: 'focaModalCotizacionController',
407 size: 'lg', 409 size: 'lg',
408 resolve: {idMoneda: function() {return idMoneda;}} 410 resolve: {idMoneda: function() {return idMoneda;}}
409 } 411 }
410 ); 412 );
411 modalInstance.result.then( 413 modalInstance.result.then(
412 function(cotizacion) { 414 function(cotizacion) {
413 $scope.notaPedido.cotizacion = { 415 $scope.notaPedido.cotizacion = {
414 id: cotizacion.ID, 416 id: cotizacion.ID,
415 cotizacion: cotizacion.COTIZACION 417 cotizacion: cotizacion.COTIZACION
416 }; 418 };
417 419
418 addCabecera( 420 addCabecera(
419 'Fecha cotizacion:', 421 'Fecha cotizacion:',
420 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 422 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
421 ); 423 );
422 addCabecera('Cotizacion:', cotizacion.COTIZACION); 424 addCabecera('Cotizacion:', cotizacion.COTIZACION);
423 }, function() { 425 }, function() {
424 426
425 } 427 }
426 ); 428 );
427 }; 429 };
428 430
429 $scope.agregarATabla = function(key) { 431 $scope.agregarATabla = function(key) {
430 if(key === 13) { 432 if(key === 13) {
431 if($scope.articuloACargar.cantidad === undefined || 433 if($scope.articuloACargar.cantidad === undefined ||
432 $scope.articuloACargar.cantidad === 0 || 434 $scope.articuloACargar.cantidad === 0 ||
433 $scope.articuloACargar.cantidad === null ){ 435 $scope.articuloACargar.cantidad === null ){
434 focaModalService.alert('El valor debe ser al menos 1'); 436 focaModalService.alert('El valor debe ser al menos 1');
435 return; 437 return;
436 } 438 }
437 delete $scope.articuloACargar.sectorCodigo; 439 delete $scope.articuloACargar.sectorCodigo;
438 $scope.articulosTabla.push($scope.articuloACargar); 440 $scope.articulosTabla.push($scope.articuloACargar);
439 $scope.cargando = true; 441 $scope.cargando = true;
440 } 442 }
441 }; 443 };
442 444
443 $scope.quitarArticulo = function(key) { 445 $scope.quitarArticulo = function(key) {
444 $scope.articulosTabla.splice(key, 1); 446 $scope.articulosTabla.splice(key, 1);
445 }; 447 };
446 448
447 $scope.editarArticulo = function(key, articulo) { 449 $scope.editarArticulo = function(key, articulo) {
448 if(key === 13) { 450 if(key === 13) {
449 if(articulo.cantidad === null || articulo.cantidad === 0 || 451 if(articulo.cantidad === null || articulo.cantidad === 0 ||
450 articulo.cantidad === undefined){ 452 articulo.cantidad === undefined){
451 focaModalService.alert('El valor debe ser al menos 1'); 453 focaModalService.alert('El valor debe ser al menos 1');
452 return; 454 return;
453 } 455 }
454 articulo.edit = false; 456 articulo.edit = false;
455 } 457 }
456 }; 458 };
457 459
458 $scope.cambioEdit = function(articulo) { 460 $scope.cambioEdit = function(articulo) {
459 articulo.edit = true; 461 articulo.edit = true;
460 }; 462 };
461 463
462 $scope.limpiarFlete = function() { 464 $scope.limpiarFlete = function() {
463 $scope.notaPedido.fleteNombre = ''; 465 $scope.notaPedido.fleteNombre = '';
464 $scope.notaPedido.chofer = ''; 466 $scope.notaPedido.chofer = '';
465 $scope.notaPedido.vehiculo = ''; 467 $scope.notaPedido.vehiculo = '';
466 $scope.notaPedido.kilometros = ''; 468 $scope.notaPedido.kilometros = '';
467 $scope.notaPedido.costoUnitarioKmFlete = ''; 469 $scope.notaPedido.costoUnitarioKmFlete = '';
468 $scope.choferes = ''; 470 $scope.choferes = '';
469 $scope.vehiculos = ''; 471 $scope.vehiculos = '';
470 }; 472 };
471 473
472 $scope.limpiarPantalla = function() { 474 $scope.limpiarPantalla = function() {
473 $scope.limpiarFlete(); 475 $scope.limpiarFlete();
474 $scope.notaPedido.flete = '0'; 476 $scope.notaPedido.flete = '0';
475 $scope.notaPedido.bomba = '0'; 477 $scope.notaPedido.bomba = '0';
476 $scope.notaPedido.precioCondicion = ''; 478 $scope.notaPedido.precioCondicion = '';
477 $scope.articulosTabla = []; 479 $scope.articulosTabla = [];
478 $scope.notaPedido.vendedor.nombre = ''; 480 $scope.notaPedido.vendedor.nombre = '';
479 $scope.notaPedido.cliente = {nombre: ''}; 481 $scope.notaPedido.cliente = {nombre: ''};
480 $scope.notaPedido.domicilio = {dom: ''}; 482 $scope.notaPedido.domicilio = {dom: ''};
481 $scope.domiciliosCliente = []; 483 $scope.domiciliosCliente = [];
482 }; 484 };
483 485
484 $scope.resetFilter = function() { 486 $scope.resetFilter = function() {
485 $scope.articuloACargar = {}; 487 $scope.articuloACargar = {};
486 $scope.cargando = true; 488 $scope.cargando = true;
487 }; 489 };
488 490
489 $scope.selectFocus = function($event) { 491 $scope.selectFocus = function($event) {
490 $event.target.select(); 492 $event.target.select();
491 }; 493 };
492 494
493 $scope.salir = function() { 495 $scope.salir = function() {
494 $location.path('/'); 496 $location.path('/');
495 }; 497 };
496 498
497 function addCabecera(label, valor) { 499 function addCabecera(label, valor) {
498 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 500 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
499 if(propiedad.length === 1) { 501 if(propiedad.length === 1) {
500 propiedad[0].valor = valor; 502 propiedad[0].valor = valor;
501 } else { 503 } else {
502 $scope.cabecera.push({label: label, valor: valor}); 504 $scope.cabecera.push({label: label, valor: valor});
503 } 505 }
504 } 506 }
505 507
506 function removeCabecera(label) { 508 function removeCabecera(label) {
507 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 509 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
508 if(propiedad.length === 1){ 510 if(propiedad.length === 1){
509 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); 511 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1);
510 } 512 }
511 } 513 }
512 } 514 }
513 ] 515 ]
514 ) 516 )
515 .controller('notaPedidoListaCtrl', [ 517 .controller('notaPedidoListaCtrl', [
516 '$scope', 518 '$scope',
517 'crearNotaPedidoService', 519 'crearNotaPedidoService',
518 '$location', 520 '$location',
519 function($scope, crearNotaPedidoService, $location) { 521 function($scope, crearNotaPedidoService, $location) {
520 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { 522 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
521 $scope.notaPedidos = datos.data; 523 $scope.notaPedidos = datos.data;
522 }); 524 });
523 $scope.editar = function(notaPedido) { 525 $scope.editar = function(notaPedido) {
524 crearNotaPedidoService.setNotaPedido(notaPedido); 526 crearNotaPedidoService.setNotaPedido(notaPedido);
525 $location.path('/venta-nota-pedido/abm/'); 527 $location.path('/venta-nota-pedido/abm/');
526 }; 528 };
527 $scope.crearPedido = function() { 529 $scope.crearPedido = function() {
528 crearNotaPedidoService.clearNotaPedido(); 530 crearNotaPedidoService.clearNotaPedido();
529 $location.path('/venta-nota-pedido/abm/'); 531 $location.path('/venta-nota-pedido/abm/');
530 }; 532 };
531 } 533 }
532 ]) 534 ])
533 .controller('focaCrearNotaPedidoFichaClienteController', [ 535 .controller('focaCrearNotaPedidoFichaClienteController', [
534 '$scope', 536 '$scope',
535 'crearNotaPedidoService', 537 'crearNotaPedidoService',
536 '$location', 538 '$location',
537 function($scope, crearNotaPedidoService, $location) { 539 function($scope, crearNotaPedidoService, $location) {
538 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { 540 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
539 $scope.notaPedidos = datos.data; 541 $scope.notaPedidos = datos.data;
540 }); 542 });
541 $scope.editar = function(notaPedido) { 543 $scope.editar = function(notaPedido) {
542 crearNotaPedidoService.setNotaPedido(notaPedido); 544 crearNotaPedidoService.setNotaPedido(notaPedido);
543 $location.path('/venta-nota-pedido/abm/'); 545 $location.path('/venta-nota-pedido/abm/');
544 }; 546 };
545 $scope.crearPedido = function() { 547 $scope.crearPedido = function() {
546 crearNotaPedidoService.clearNotaPedido(); 548 crearNotaPedidoService.clearNotaPedido();
547 $location.path('/venta-nota-pedido/abm/'); 549 $location.path('/venta-nota-pedido/abm/');
548 }; 550 };
549 } 551 }
550 ]); 552 ]);
551 553