Commit d0ba160322a5a89d5ee981a87ddf72ff316c6be2

Authored by Pablo Marco del Pont
Exists in master

Merge branch 'master' into 'master'

Master (pmarco)

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