Commit f9733a66b27e3542b7d3b17b039e63ea219fef5b

Authored by Eric Fernandez
1 parent 088b4ef186
Exists in master

upstream

Showing 1 changed file with 2 additions and 31 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaCrearRemito') .controller('remitoController', 1 angular.module('focaCrearRemito') .controller('remitoController',
2 [ 2 [
3 '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', 3 '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService',
4 'focaModalService', 'remitoBusinessService', 4 'focaModalService', 'remitoBusinessService',
5 function( 5 function(
6 $scope, $uibModal, $location, $filter, crearRemitoService, focaModalService, 6 $scope, $uibModal, $location, $filter, crearRemitoService, focaModalService,
7 remitoBusinessService 7 remitoBusinessService
8 ) { 8 ) {
9 $scope.botonera = [ 9 $scope.botonera = [
10 {texto: 'Nota Pedido', accion: function() {$scope.seleccionarNotaPedido();}}, 10 {texto: 'Nota Pedido', accion: function() {$scope.seleccionarNotaPedido();}},
11 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}}, 11 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}},
12 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, 12 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}},
13 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}}, 13 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}},
14 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}}, 14 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}},
15 { 15 {
16 texto: 'Precios y condiciones', 16 texto: 'Precios y condiciones',
17 accion: function() {$scope.abrirModalListaPrecio();}}, 17 accion: function() {$scope.abrirModalListaPrecio();}},
18 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}}, 18 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}},
19 {texto: '', accion: function() {}} 19 {texto: '', accion: function() {}}
20 ]; 20 ];
21 $scope.datepickerAbierto = false; 21 $scope.datepickerAbierto = false;
22 22
23 $scope.show = false; 23 $scope.show = false;
24 $scope.cargando = true; 24 $scope.cargando = true;
25 $scope.dateOptions = { 25 $scope.dateOptions = {
26 maxDate: new Date(), 26 maxDate: new Date(),
27 minDate: new Date(2010, 0, 1) 27 minDate: new Date(2010, 0, 1)
28 }; 28 };
29 29
30 $scope.remito = { 30 $scope.remito = {
31 vendedor: {}, 31 vendedor: {},
32 cliente: {}, 32 cliente: {},
33 proveedor: {}, 33 proveedor: {},
34 domicilio: {dom: ''}, 34 domicilio: {dom: ''},
35 moneda: {}, 35 moneda: {},
36 cotizacion: {} 36 cotizacion: {}
37 }; 37 };
38 var monedaPorDefecto; 38 var monedaPorDefecto;
39 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' 39 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
40 crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) { 40 crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) {
41 monedaPorDefecto = { 41 monedaPorDefecto = {
42 id: res.data[0].ID, 42 id: res.data[0].ID,
43 detalle: res.data[0].DETALLE, 43 detalle: res.data[0].DETALLE,
44 simbolo: res.data[0].SIMBOLO, 44 simbolo: res.data[0].SIMBOLO,
45 cotizaciones: res.data[0].cotizaciones 45 cotizaciones: res.data[0].cotizaciones
46 }; 46 };
47 addCabecera('Moneda:', monedaPorDefecto.detalle); 47 addCabecera('Moneda:', monedaPorDefecto.detalle);
48 addCabecera('Fecha cotizacion:', 48 addCabecera('Fecha cotizacion:',
49 new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); 49 new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString());
50 addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION); 50 addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION);
51 $scope.remito.moneda = monedaPorDefecto; 51 $scope.remito.moneda = monedaPorDefecto;
52 $scope.remito.cotizacion = monedaPorDefecto.cotizaciones[0]; 52 $scope.remito.cotizacion = monedaPorDefecto.cotizaciones[0];
53 }); 53 });
54 54
55 $scope.cabecera = []; 55 $scope.cabecera = [];
56 $scope.showCabecera = true; 56 $scope.showCabecera = true;
57 57
58 $scope.now = new Date(); 58 $scope.now = new Date();
59 $scope.puntoVenta = Math.round(Math.random() * 10000); 59 $scope.puntoVenta = Math.round(Math.random() * 10000);
60 $scope.comprobante = Math.round(Math.random() * 1000000); 60 $scope.comprobante = Math.round(Math.random() * 1000000);
61 61
62 $scope.articulosTabla = []; 62 $scope.articulosTabla = [];
63 $scope.idLista = undefined; 63 $scope.idLista = undefined;
64 //La pantalla solo se usa para cargar remitos 64 //La pantalla solo se usa para cargar remitos
65 //var remitoTemp = crearRemitoService.getRemito(); 65 //var remitoTemp = crearRemitoService.getRemito();
66 66
67 crearRemitoService.getPrecioCondicion().then( 67 crearRemitoService.getPrecioCondicion().then(
68 function(res) { 68 function(res) {
69 $scope.precioCondiciones = res.data; 69 $scope.precioCondiciones = res.data;
70 } 70 }
71 ); 71 );
72 72
73 crearRemitoService.getNumeroRemito().then( 73 crearRemitoService.getNumeroRemito().then(
74 function(res) { 74 function(res) {
75 $scope.puntoVenta = rellenar(res.data.sucursal, 4); 75 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
76 $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); 76 $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8);
77 }, 77 },
78 function(err) { 78 function(err) {
79 focaModalService.alert('La terminal no esta configurada correctamente'); 79 focaModalService.alert('La terminal no esta configurada correctamente');
80 console.info(err); 80 console.info(err);
81 } 81 }
82 ); 82 );
83 83
84 $scope.seleccionarNotaPedido = function() { 84 $scope.seleccionarNotaPedido = function() {
85 var modalInstance = $uibModal.open( 85 var modalInstance = $uibModal.open(
86 { 86 {
87 ariaLabelledBy: 'Busqueda de Nota de Pedido', 87 ariaLabelledBy: 'Busqueda de Nota de Pedido',
88 templateUrl: 'foca-modal-nota-pedido.html', 88 templateUrl: 'foca-modal-nota-pedido.html',
89 controller: 'focaModalNotaPedidoController', 89 controller: 'focaModalNotaPedidoController',
90 resolve: {
91 parametroNotaPedido: {
92 idLista: $scope.idLista,
93 cotizacion: $scope.remito.cotizacion.COTIZACION,
94 simbolo: $scope.remito.moneda.simbolo
95 }
96 },
97 size: 'lg' 90 size: 'lg'
98 } 91 }
99 ); 92 );
100 modalInstance.result.then( 93 modalInstance.result.then(
101 function(notaPedido) { 94 function(notaPedido) {
102 //añado cabeceras 95 //añado cabeceras
103 removeCabecera('Moneda:'); 96 removeCabecera('Moneda:');
104 removeCabecera('Fecha cotizacion:'); 97 removeCabecera('Fecha cotizacion:');
105 removeCabecera('Cotizacion:'); 98 removeCabecera('Cotizacion:');
106 var cabeceras = [ 99 var cabeceras = [
107 { 100 {
108 label: 'Moneda', 101 label: 'Moneda',
109 valor: notaPedido.cotizacion[0].moneda[0].DETALLE 102 valor: notaPedido.cotizacion[0].moneda[0].DETALLE
110 }, 103 },
111 { 104 {
112 label: 'Fecha cotizacion', 105 label: 'Fecha cotizacion',
113 valor: $filter('date')(notaPedido.cotizacion[0].FECHA, 106 valor: $filter('date')(notaPedido.cotizacion[0].FECHA,
114 'dd/MM/yyyy') 107 'dd/MM/yyyy')
115 }, 108 },
116 { 109 {
117 label: 'Cotizacion', 110 label: 'Cotizacion',
118 valor: notaPedido.cotizacion[0].VENDEDOR 111 valor: notaPedido.cotizacion[0].VENDEDOR
119 }, 112 },
120 { 113 {
121 label: 'Cliente:', 114 label: 'Cliente:',
122 valor: notaPedido.cliente[0].NOM 115 valor: notaPedido.cliente[0].NOM
123 }, 116 },
124 { 117 {
125 label: 'Vendedor:', 118 label: 'Vendedor:',
126 valor: notaPedido.vendedor[0].NomVen 119 valor: notaPedido.vendedor[0].NomVen
127 }, 120 },
128 { 121 {
129 label: 'Proveedor:', 122 label: 'Proveedor:',
130 valor: notaPedido.proveedor[0].NOM 123 valor: notaPedido.proveedor[0].NOM
131 }, 124 },
132 { 125 {
133 label: 'Flete:', 126 label: 'Flete:',
134 valor: notaPedido.flete === 1 ? 'Si' : 'No' 127 valor: notaPedido.flete === 1 ? 'Si' : 'No'
135 }, 128 },
136 { 129 {
137 label: 'FOB:', 130 label: 'FOB:',
138 valor: notaPedido.fob === 1 ? 'Si' : 'No' 131 valor: notaPedido.fob === 1 ? 'Si' : 'No'
139 }, 132 },
140 { 133 {
141 label: 'Precio condicion:', 134 label: 'Precio condicion:',
142 valor: valorPrecioCondicion() 135 valor: valorPrecioCondicion()
143 } 136 }
144 ]; 137 ];
145 //TO DO CUANDO MOSTRAR PLAZOS 138 //TO DO CUANDO MOSTRAR PLAZOS
146 function valorPrecioCondicion() { 139 function valorPrecioCondicion() {
147 if(notaPedido.idPrecioCondicion > 0) { 140 if(notaPedido.idPrecioCondicion > 0) {
148 return notaPedido.precioCondicion[0].nombre; 141 return notaPedido.precioCondicion[0].nombre;
149 } else { 142 } else {
150 return 'Ingreso Manual'; 143 return 'Ingreso Manual';
151 } 144 }
152 145
153 } 146 }
154 147
155 if(notaPedido.flete === 1) { 148 if(notaPedido.flete === 1) {
156 var cabeceraBomba = { 149 var cabeceraBomba = {
157 label: 'Bomba', 150 label: 'Bomba',
158 valor: notaPedido.bomba === 1 ? 'Si' : 'No' 151 valor: notaPedido.bomba === 1 ? 'Si' : 'No'
159 }; 152 };
160 if(notaPedido.kilometros){ 153 if(notaPedido.kilometros){
161 var cabeceraKilometros = { 154 var cabeceraKilometros = {
162 label: 'Kilometros', 155 label: 'Kilometros',
163 valor: notaPedido.kilometros 156 valor: notaPedido.kilometros
164 }; 157 };
165 cabeceras.push(cabeceraKilometros); 158 cabeceras.push(cabeceraKilometros);
166 } 159 }
167 cabeceras.push(cabeceraBomba); 160 cabeceras.push(cabeceraBomba);
168 } 161 }
169 $scope.articulosTabla = notaPedido.articulosNotaPedido; 162 $scope.articulosTabla = notaPedido.articulosNotaPedido;
170 $scope.remito = notaPedido; 163 $scope.remito = notaPedido;
171 addArrayCabecera(cabeceras); 164 addArrayCabecera(cabeceras);
172 165
173 }, function() { 166 }, function() {
174 // funcion ejecutada cuando se cancela el modal 167 // funcion ejecutada cuando se cancela el modal
175 } 168 }
176 ); 169 );
177 }; 170 };
178 171
179 $scope.seleccionarRemito = function() { 172 $scope.seleccionarRemito = function() {
180 var modalInstance = $uibModal.open( 173 var modalInstance = $uibModal.open(
181 { 174 {
182 ariaLabelledBy: 'Busqueda de Remito', 175 ariaLabelledBy: 'Busqueda de Remito',
183 templateUrl: 'foca-modal-remito.html', 176 templateUrl: 'foca-modal-remito.html',
184 controller: 'focaModalRemitoController', 177 controller: 'focaModalRemitoController',
185 resolve: {
186 parametroRemito: {
187 idLista: $scope.idLista,
188 cotizacion: $scope.remito.cotizacion.COTIZACION,
189 simbolo: $scope.remito.moneda.simbolo
190 }
191 },
192 size: 'lg' 178 size: 'lg'
193 } 179 }
194 ); 180 );
195 modalInstance.result.then( 181 modalInstance.result.then(
196 function(producto) { 182 function() {
197 var newArt = 183 // TODO: Implementar carga remito
198 {
199 id: 0,
200 codigo: producto.codigo,
201 sector: producto.sector,
202 sectorCodigo: producto.sector + '-' + producto.codigo,
203 descripcion: producto.descripcion,
204 item: $scope.articulosTabla.length + 1,
205 nombre: producto.descripcion,
206 precio: parseFloat(producto.precio.toFixed(4)),
207 costoUnitario: producto.costo,
208 editCantidad: false,
209 editPrecio: false
210 };
211 $scope.articuloACargar = newArt;
212 $scope.cargando = false;
213 }, function() { 184 }, function() {
214 // funcion ejecutada cuando se cancela el modal 185 // funcion ejecutada cuando se cancela el modal
215 } 186 }
216 ); 187 );
217 }; 188 };
218 189
219 //La pantalla solo se usa para cargar remitos 190 //La pantalla solo se usa para cargar remitos
220 // if (remitoTemp !== undefined) { 191 // if (remitoTemp !== undefined) {
221 // remitoTemp.fechaCarga = new Date(remitoTemp.fechaCarga); 192 // remitoTemp.fechaCarga = new Date(remitoTemp.fechaCarga);
222 // $scope.remito = remitoTemp; 193 // $scope.remito = remitoTemp;
223 // $scope.remito.flete = ($scope.remito.flete).toString(); 194 // $scope.remito.flete = ($scope.remito.flete).toString();
224 // $scope.remito.bomba = ($scope.remito.bomba).toString(); 195 // $scope.remito.bomba = ($scope.remito.bomba).toString();
225 // $scope.idLista = $scope.remito.precioCondicion; 196 // $scope.idLista = $scope.remito.precioCondicion;
226 // crearRemitoService 197 // crearRemitoService
227 // .getArticulosByIdRemito($scope.remito.id).then( 198 // .getArticulosByIdRemito($scope.remito.id).then(
228 // function(res) { 199 // function(res) {
229 // $scope.articulosTabla = res.data; 200 // $scope.articulosTabla = res.data;
230 // } 201 // }
231 // ); 202 // );
232 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR REMITO 203 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR REMITO
233 //(NO REQUERIDO EN ESTA VERSION) 204 //(NO REQUERIDO EN ESTA VERSION)
234 // crearRemitoService.getDomiciliosByIdRemito($scope.remito.id).then( 205 // crearRemitoService.getDomiciliosByIdRemito($scope.remito.id).then(
235 // function(res) { 206 // function(res) {
236 // $scope.remito.domicilio = res.data; 207 // $scope.remito.domicilio = res.data;
237 // } 208 // }
238 // ); 209 // );
239 // } else { 210 // } else {
240 // $scope.remito.fechaCarga = new Date(); 211 // $scope.remito.fechaCarga = new Date();
241 // $scope.remito.bomba = '0'; 212 // $scope.remito.bomba = '0';
242 // $scope.remito.flete = '0'; 213 // $scope.remito.flete = '0';
243 // $scope.idLista = undefined; 214 // $scope.idLista = undefined;
244 // } 215 // }
245 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO 216 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO
246 // $scope.addNewDom = function() { 217 // $scope.addNewDom = function() {
247 // $scope.remito.domicilio.push({ 'id': 0 }); 218 // $scope.remito.domicilio.push({ 'id': 0 });
248 // }; 219 // };
249 // $scope.removeNewChoice = function(choice) { 220 // $scope.removeNewChoice = function(choice) {
250 // if ($scope.remito.domicilio.length > 1) { 221 // if ($scope.remito.domicilio.length > 1) {
251 // $scope.remito.domicilio.splice($scope.remito.domicilio.findIndex( 222 // $scope.remito.domicilio.splice($scope.remito.domicilio.findIndex(
252 // function(c) { 223 // function(c) {
253 // return c.$$hashKey === choice.$$hashKey; 224 // return c.$$hashKey === choice.$$hashKey;
254 // } 225 // }
255 // ), 1); 226 // ), 1);
256 // } 227 // }
257 // }; 228 // };
258 229
259 $scope.crearRemito = function() { 230 $scope.crearRemito = function() {
260 if(!$scope.remito.vendedor.codigo) { 231 if(!$scope.remito.vendedor.codigo) {
261 focaModalService.alert('Ingrese Vendedor'); 232 focaModalService.alert('Ingrese Vendedor');
262 return; 233 return;
263 } else if(!$scope.remito.cliente.cod) { 234 } else if(!$scope.remito.cliente.cod) {
264 focaModalService.alert('Ingrese Cliente'); 235 focaModalService.alert('Ingrese Cliente');
265 return; 236 return;
266 } else if(!$scope.remito.proveedor.codigo) { 237 } else if(!$scope.remito.proveedor.codigo) {
267 focaModalService.alert('Ingrese Proveedor'); 238 focaModalService.alert('Ingrese Proveedor');
268 return; 239 return;
269 } else if(!$scope.remito.moneda.id) { 240 } else if(!$scope.remito.moneda.id) {
270 focaModalService.alert('Ingrese Moneda'); 241 focaModalService.alert('Ingrese Moneda');
271 return; 242 return;
272 } else if(!$scope.remito.cotizacion.ID) { 243 } else if(!$scope.remito.cotizacion.ID) {
273 focaModalService.alert('Ingrese Cotización'); 244 focaModalService.alert('Ingrese Cotización');
274 return; 245 return;
275 } else if(!$scope.plazosPagos) { 246 } else if(!$scope.plazosPagos) {
276 focaModalService.alert('Ingrese Precios y Condiciones'); 247 focaModalService.alert('Ingrese Precios y Condiciones');
277 return; 248 return;
278 } else if( 249 } else if(
279 $scope.remito.flete === undefined || $scope.remito.flete === null) 250 $scope.remito.flete === undefined || $scope.remito.flete === null)
280 { 251 {
281 focaModalService.alert('Ingrese Flete'); 252 focaModalService.alert('Ingrese Flete');
282 return; 253 return;
283 } else if(!$scope.remito.domicilio.id) { 254 } else if(!$scope.remito.domicilio.id) {
284 focaModalService.alert('Ingrese Domicilio'); 255 focaModalService.alert('Ingrese Domicilio');
285 return; 256 return;
286 } else if($scope.articulosTabla.length === 0) { 257 } else if($scope.articulosTabla.length === 0) {
287 focaModalService.alert('Debe cargar al menos un articulo'); 258 focaModalService.alert('Debe cargar al menos un articulo');
288 return; 259 return;
289 } 260 }
290 var date = new Date(); 261 var date = new Date();
291 var remito = { 262 var remito = {
292 id: 0, 263 id: 0,
293 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) 264 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
294 .toISOString().slice(0, 19).replace('T', ' '), 265 .toISOString().slice(0, 19).replace('T', ' '),
295 idVendedor: $scope.remito.vendedor.codigo, 266 idVendedor: $scope.remito.vendedor.codigo,
296 idCliente: $scope.remito.cliente.cod, 267 idCliente: $scope.remito.cliente.cod,
297 nombreCliente: $scope.remito.cliente.nom, 268 nombreCliente: $scope.remito.cliente.nom,
298 cuitCliente: $scope.remito.cliente.cuit, 269 cuitCliente: $scope.remito.cliente.cuit,
299 idProveedor: $scope.remito.proveedor.codigo, 270 idProveedor: $scope.remito.proveedor.codigo,
300 idDomicilio: $scope.remito.domicilio.id, 271 idDomicilio: $scope.remito.domicilio.id,
301 idCotizacion: $scope.remito.cotizacion.ID, 272 idCotizacion: $scope.remito.cotizacion.ID,
302 cotizacion: $scope.remito.cotizacion.COTIZACION, 273 cotizacion: $scope.remito.cotizacion.COTIZACION,
303 flete: $scope.remito.flete, 274 flete: $scope.remito.flete,
304 fob: $scope.remito.fob, 275 fob: $scope.remito.fob,
305 bomba: $scope.remito.bomba, 276 bomba: $scope.remito.bomba,
306 kilometros: $scope.remito.kilometros, 277 kilometros: $scope.remito.kilometros,
307 estado: 0, 278 estado: 0,
308 total: $scope.getTotal() 279 total: $scope.getTotal()
309 }; 280 };
310 crearRemitoService.crearRemito(remito).then( 281 crearRemitoService.crearRemito(remito).then(
311 function(data) { 282 function(data) {
312 remitoBusinessService.addArticulos($scope.articulosTabla, 283 remitoBusinessService.addArticulos($scope.articulosTabla,
313 data.data.id, $scope.remito.cotizacion.COTIZACION); 284 data.data.id, $scope.remito.cotizacion.COTIZACION);
314 var plazos = $scope.plazosPagos; 285 var plazos = $scope.plazosPagos;
315 for(var j = 0; j < plazos.length; j++) { 286 for(var j = 0; j < plazos.length; j++) {
316 var json = { 287 var json = {
317 idRemito: data.data.id, 288 idRemito: data.data.id,
318 dias: plazos[j].dias 289 dias: plazos[j].dias
319 }; 290 };
320 crearRemitoService.crearPlazosParaRemito(json); 291 crearRemitoService.crearPlazosParaRemito(json);
321 } 292 }
322 remitoBusinessService.addEstado(data.data.id, 293 remitoBusinessService.addEstado(data.data.id,
323 $scope.remito.vendedor.codigo); 294 $scope.remito.vendedor.codigo);
324 295
325 focaModalService.alert('Nota remito creada'); 296 focaModalService.alert('Nota remito creada');
326 $scope.cabecera = []; 297 $scope.cabecera = [];
327 addCabecera('Moneda:', $scope.remito.moneda.detalle); 298 addCabecera('Moneda:', $scope.remito.moneda.detalle);
328 addCabecera( 299 addCabecera(
329 'Fecha cotizacion:', 300 'Fecha cotizacion:',
330 $filter('date')($scope.remito.cotizacion.FECHA, 'dd/MM/yyyy') 301 $filter('date')($scope.remito.cotizacion.FECHA, 'dd/MM/yyyy')
331 ); 302 );
332 addCabecera('Cotizacion:', $scope.remito.cotizacion.COTIZACION); 303 addCabecera('Cotizacion:', $scope.remito.cotizacion.COTIZACION);
333 $scope.remito.vendedor = {}; 304 $scope.remito.vendedor = {};
334 $scope.remito.cliente = {}; 305 $scope.remito.cliente = {};
335 $scope.remito.proveedor = {}; 306 $scope.remito.proveedor = {};
336 $scope.remito.domicilio = {}; 307 $scope.remito.domicilio = {};
337 $scope.remito.flete = null; 308 $scope.remito.flete = null;
338 $scope.remito.fob = null; 309 $scope.remito.fob = null;
339 $scope.remito.bomba = null; 310 $scope.remito.bomba = null;
340 $scope.remito.kilometros = null; 311 $scope.remito.kilometros = null;
341 $scope.articulosTabla = []; 312 $scope.articulosTabla = [];
342 } 313 }
343 ); 314 );
344 }; 315 };
345 316
346 $scope.seleccionarArticulo = function() { 317 $scope.seleccionarArticulo = function() {
347 if ($scope.idLista === undefined) { 318 if ($scope.idLista === undefined) {
348 focaModalService.alert( 319 focaModalService.alert(
349 'Primero seleccione una lista de precio y condicion'); 320 'Primero seleccione una lista de precio y condicion');
350 return; 321 return;
351 } 322 }
352 var modalInstance = $uibModal.open( 323 var modalInstance = $uibModal.open(
353 { 324 {
354 ariaLabelledBy: 'Busqueda de Productos', 325 ariaLabelledBy: 'Busqueda de Productos',
355 templateUrl: 'modal-busqueda-productos.html', 326 templateUrl: 'modal-busqueda-productos.html',
356 controller: 'modalBusquedaProductosCtrl', 327 controller: 'modalBusquedaProductosCtrl',
357 resolve: { 328 resolve: {
358 parametroProducto: { 329 parametroProducto: {
359 idLista: $scope.idLista, 330 idLista: $scope.idLista,
360 cotizacion: $scope.remito.cotizacion.COTIZACION, 331 cotizacion: $scope.remito.cotizacion.COTIZACION,
361 simbolo: $scope.remito.moneda.simbolo 332 simbolo: $scope.remito.moneda.simbolo
362 } 333 }
363 }, 334 },
364 size: 'lg' 335 size: 'lg'
365 } 336 }
366 ); 337 );
367 modalInstance.result.then( 338 modalInstance.result.then(
368 function(producto) { 339 function(producto) {
369 var newArt = 340 var newArt =
370 { 341 {
371 id: 0, 342 id: 0,
372 codigo: producto.codigo, 343 codigo: producto.codigo,
373 sector: producto.sector, 344 sector: producto.sector,
374 sectorCodigo: producto.sector + '-' + producto.codigo, 345 sectorCodigo: producto.sector + '-' + producto.codigo,
375 descripcion: producto.descripcion, 346 descripcion: producto.descripcion,
376 item: $scope.articulosTabla.length + 1, 347 item: $scope.articulosTabla.length + 1,
377 nombre: producto.descripcion, 348 nombre: producto.descripcion,
378 precio: parseFloat(producto.precio.toFixed(4)), 349 precio: parseFloat(producto.precio.toFixed(4)),
379 costoUnitario: producto.costo, 350 costoUnitario: producto.costo,
380 editCantidad: false, 351 editCantidad: false,
381 editPrecio: false 352 editPrecio: false
382 }; 353 };
383 $scope.articuloACargar = newArt; 354 $scope.articuloACargar = newArt;
384 $scope.cargando = false; 355 $scope.cargando = false;
385 }, function() { 356 }, function() {
386 // funcion ejecutada cuando se cancela el modal 357 // funcion ejecutada cuando se cancela el modal
387 } 358 }
388 ); 359 );
389 }; 360 };
390 361
391 $scope.seleccionarVendedor = function() { 362 $scope.seleccionarVendedor = function() {
392 var modalInstance = $uibModal.open( 363 var modalInstance = $uibModal.open(
393 { 364 {
394 ariaLabelledBy: 'Busqueda de Vendedores', 365 ariaLabelledBy: 'Busqueda de Vendedores',
395 templateUrl: 'modal-vendedores.html', 366 templateUrl: 'modal-vendedores.html',
396 controller: 'modalVendedoresCtrl', 367 controller: 'modalVendedoresCtrl',
397 size: 'lg' 368 size: 'lg'
398 } 369 }
399 ); 370 );
400 modalInstance.result.then( 371 modalInstance.result.then(
401 function(vendedor) { 372 function(vendedor) {
402 addCabecera('Vendedor:', vendedor.NomVen); 373 addCabecera('Vendedor:', vendedor.NomVen);
403 $scope.remito.vendedor.codigo = vendedor.CodVen; 374 $scope.remito.vendedor.codigo = vendedor.CodVen;
404 }, function() { 375 }, function() {
405 376
406 } 377 }
407 ); 378 );
408 }; 379 };
409 380
410 $scope.seleccionarProveedor = function() { 381 $scope.seleccionarProveedor = function() {
411 var modalInstance = $uibModal.open( 382 var modalInstance = $uibModal.open(
412 { 383 {
413 ariaLabelledBy: 'Busqueda de Proveedor', 384 ariaLabelledBy: 'Busqueda de Proveedor',
414 templateUrl: 'modal-proveedor.html', 385 templateUrl: 'modal-proveedor.html',
415 controller: 'focaModalProveedorCtrl', 386 controller: 'focaModalProveedorCtrl',
416 size: 'lg' 387 size: 'lg'
417 } 388 }
418 ); 389 );
419 modalInstance.result.then( 390 modalInstance.result.then(
420 function(proveedor) { 391 function(proveedor) {
421 $scope.remito.proveedor.codigo = proveedor.COD; 392 $scope.remito.proveedor.codigo = proveedor.COD;
422 addCabecera('Proveedor:', proveedor.NOM); 393 addCabecera('Proveedor:', proveedor.NOM);
423 }, function() { 394 }, function() {
424 395
425 } 396 }
426 ); 397 );
427 }; 398 };
428 399
429 $scope.seleccionarCliente = function() { 400 $scope.seleccionarCliente = function() {
430 401
431 var modalInstance = $uibModal.open( 402 var modalInstance = $uibModal.open(
432 { 403 {
433 ariaLabelledBy: 'Busqueda de Cliente', 404 ariaLabelledBy: 'Busqueda de Cliente',
434 templateUrl: 'foca-busqueda-cliente-modal.html', 405 templateUrl: 'foca-busqueda-cliente-modal.html',
435 controller: 'focaBusquedaClienteModalController', 406 controller: 'focaBusquedaClienteModalController',
436 size: 'lg' 407 size: 'lg'
437 } 408 }
438 ); 409 );
439 modalInstance.result.then( 410 modalInstance.result.then(
440 function(cliente) { 411 function(cliente) {
441 $scope.abrirModalDomicilios(cliente); 412 $scope.abrirModalDomicilios(cliente);
442 }, function() { 413 }, function() {
443 414
444 } 415 }
445 ); 416 );
446 }; 417 };
447 418
448 $scope.abrirModalDomicilios = function(cliente) { 419 $scope.abrirModalDomicilios = function(cliente) {
449 var modalInstanceDomicilio = $uibModal.open( 420 var modalInstanceDomicilio = $uibModal.open(
450 { 421 {
451 ariaLabelledBy: 'Busqueda de Domicilios', 422 ariaLabelledBy: 'Busqueda de Domicilios',
452 templateUrl: 'modal-domicilio.html', 423 templateUrl: 'modal-domicilio.html',
453 controller: 'focaModalDomicilioController', 424 controller: 'focaModalDomicilioController',
454 resolve: { idCliente: function() { return cliente.cod; }}, 425 resolve: { idCliente: function() { return cliente.cod; }},
455 size: 'lg', 426 size: 'lg',
456 } 427 }
457 ); 428 );
458 modalInstanceDomicilio.result.then( 429 modalInstanceDomicilio.result.then(
459 function(domicilio) { 430 function(domicilio) {
460 $scope.remito.domicilio.id = domicilio.nivel2; 431 $scope.remito.domicilio.id = domicilio.nivel2;
461 $scope.remito.cliente = cliente; 432 $scope.remito.cliente = cliente;
462 433
463 addCabecera('Cliente:', cliente.nom); 434 addCabecera('Cliente:', cliente.nom);
464 addCabecera('Domicilio:', domicilio.dom); 435 addCabecera('Domicilio:', domicilio.dom);
465 }, function() { 436 }, function() {
466 $scope.seleccionarCliente(); 437 $scope.seleccionarCliente();
467 return; 438 return;
468 } 439 }
469 ); 440 );
470 }; 441 };
471 442
472 $scope.mostrarFichaCliente = function() { 443 $scope.mostrarFichaCliente = function() {
473 $uibModal.open( 444 $uibModal.open(
474 { 445 {
475 ariaLabelledBy: 'Datos del Cliente', 446 ariaLabelledBy: 'Datos del Cliente',
476 templateUrl: 'foca-crear-remito-ficha-cliente.html', 447 templateUrl: 'foca-crear-remito-ficha-cliente.html',
477 controller: 'focaCrearRemitoFichaClienteController', 448 controller: 'focaCrearRemitoFichaClienteController',
478 size: 'lg' 449 size: 'lg'
479 } 450 }
480 ); 451 );
481 }; 452 };
482 453
483 $scope.getTotal = function() { 454 $scope.getTotal = function() {
484 var total = 0; 455 var total = 0;
485 var arrayTempArticulos = $scope.articulosTabla; 456 var arrayTempArticulos = $scope.articulosTabla;
486 for (var i = 0; i < arrayTempArticulos.length; i++) { 457 for (var i = 0; i < arrayTempArticulos.length; i++) {
487 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 458 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
488 } 459 }
489 return parseFloat(total.toFixed(2)); 460 return parseFloat(total.toFixed(2));
490 }; 461 };
491 462
492 $scope.getSubTotal = function() { 463 $scope.getSubTotal = function() {
493 if($scope.articuloACargar) { 464 if($scope.articuloACargar) {
494 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 465 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
495 } 466 }
496 }; 467 };
497 468
498 $scope.abrirModalListaPrecio = function() { 469 $scope.abrirModalListaPrecio = function() {
499 var modalInstance = $uibModal.open( 470 var modalInstance = $uibModal.open(
500 { 471 {
501 ariaLabelledBy: 'Busqueda de Precio Condición', 472 ariaLabelledBy: 'Busqueda de Precio Condición',
502 templateUrl: 'modal-precio-condicion.html', 473 templateUrl: 'modal-precio-condicion.html',
503 controller: 'focaModalPrecioCondicionController', 474 controller: 'focaModalPrecioCondicionController',
504 size: 'lg' 475 size: 'lg'
505 } 476 }
506 ); 477 );
507 modalInstance.result.then( 478 modalInstance.result.then(
508 function(precioCondicion) { 479 function(precioCondicion) {
509 var cabecera = ''; 480 var cabecera = '';
510 var plazosConcat = ''; 481 var plazosConcat = '';
511 if(!Array.isArray(precioCondicion)) { 482 if(!Array.isArray(precioCondicion)) {
512 $scope.plazosPagos = precioCondicion.plazoPago; 483 $scope.plazosPagos = precioCondicion.plazoPago;
513 $scope.idLista = precioCondicion.idListaPrecio; 484 $scope.idLista = precioCondicion.idListaPrecio;
514 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 485 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
515 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 486 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
516 } 487 }
517 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); 488 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim();
518 } else { //Cuando se ingresan los plazos manualmente 489 } else { //Cuando se ingresan los plazos manualmente
519 $scope.idLista = -1; //-1, el modal productos busca todos los productos 490 $scope.idLista = -1; //-1, el modal productos busca todos los productos
520 $scope.plazosPagos = precioCondicion; 491 $scope.plazosPagos = precioCondicion;
521 for(var j = 0; j < precioCondicion.length; j++) { 492 for(var j = 0; j < precioCondicion.length; j++) {
522 plazosConcat += precioCondicion[j].dias + ' '; 493 plazosConcat += precioCondicion[j].dias + ' ';
523 } 494 }
524 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 495 cabecera = 'Ingreso manual ' + plazosConcat.trim();
525 } 496 }
526 $scope.articulosTabla = []; 497 $scope.articulosTabla = [];
527 addCabecera('Precios y condiciones:', cabecera); 498 addCabecera('Precios y condiciones:', cabecera);
528 }, function() { 499 }, function() {
529 500
530 } 501 }
531 ); 502 );
532 }; 503 };
533 504
534 $scope.abrirModalFlete = function() { 505 $scope.abrirModalFlete = function() {
535 var modalInstance = $uibModal.open( 506 var modalInstance = $uibModal.open(
536 { 507 {
537 ariaLabelledBy: 'Busqueda de Flete', 508 ariaLabelledBy: 'Busqueda de Flete',
538 templateUrl: 'modal-flete.html', 509 templateUrl: 'modal-flete.html',
539 controller: 'focaModalFleteController', 510 controller: 'focaModalFleteController',
540 size: 'lg', 511 size: 'lg',
541 resolve: { 512 resolve: {
542 parametrosFlete: 513 parametrosFlete:
543 function() { 514 function() {
544 return { 515 return {
545 flete: $scope.remito.flete ? '1' : 516 flete: $scope.remito.flete ? '1' :
546 ($scope.remito.fob ? 'FOB' : 517 ($scope.remito.fob ? 'FOB' :
547 ($scope.remito.flete === undefined ? null : '0')), 518 ($scope.remito.flete === undefined ? null : '0')),
548 bomba: $scope.remito.bomba ? '1' : 519 bomba: $scope.remito.bomba ? '1' :
549 ($scope.remito.bomba === undefined ? null : '0'), 520 ($scope.remito.bomba === undefined ? null : '0'),
550 kilometros: $scope.remito.kilometros 521 kilometros: $scope.remito.kilometros
551 }; 522 };
552 } 523 }
553 } 524 }
554 } 525 }
555 ); 526 );
556 modalInstance.result.then( 527 modalInstance.result.then(
557 function(datos) { 528 function(datos) {
558 $scope.remito.flete = datos.flete; 529 $scope.remito.flete = datos.flete;
559 $scope.remito.fob = datos.FOB; 530 $scope.remito.fob = datos.FOB;
560 $scope.remito.bomba = datos.bomba; 531 $scope.remito.bomba = datos.bomba;
561 $scope.remito.kilometros = datos.kilometros; 532 $scope.remito.kilometros = datos.kilometros;
562 533
563 addCabecera('Flete:', datos.flete ? 'Si' : 534 addCabecera('Flete:', datos.flete ? 'Si' :
564 ($scope.remito.fob ? 'FOB' : 'No')); 535 ($scope.remito.fob ? 'FOB' : 'No'));
565 if(datos.flete) { 536 if(datos.flete) {
566 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); 537 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No');
567 addCabecera('Kilometros:', datos.kilometros); 538 addCabecera('Kilometros:', datos.kilometros);
568 } else { 539 } else {
569 removeCabecera('Bomba:'); 540 removeCabecera('Bomba:');
570 removeCabecera('Kilometros:'); 541 removeCabecera('Kilometros:');
571 $scope.remito.fob = false; 542 $scope.remito.fob = false;
572 $scope.remito.bomba = false; 543 $scope.remito.bomba = false;
573 $scope.remito.kilometros = null; 544 $scope.remito.kilometros = null;
574 } 545 }
575 }, function() { 546 }, function() {
576 547
577 } 548 }
578 ); 549 );
579 }; 550 };
580 551
581 $scope.abrirModalMoneda = function() { 552 $scope.abrirModalMoneda = function() {
582 var modalInstance = $uibModal.open( 553 var modalInstance = $uibModal.open(
583 { 554 {
584 ariaLabelledBy: 'Busqueda de Moneda', 555 ariaLabelledBy: 'Busqueda de Moneda',
585 templateUrl: 'modal-moneda.html', 556 templateUrl: 'modal-moneda.html',
586 controller: 'focaModalMonedaController', 557 controller: 'focaModalMonedaController',
587 size: 'lg' 558 size: 'lg'
588 } 559 }
589 ); 560 );
590 modalInstance.result.then( 561 modalInstance.result.then(
591 function(moneda) { 562 function(moneda) {
592 $scope.abrirModalCotizacion(moneda); 563 $scope.abrirModalCotizacion(moneda);
593 }, function() { 564 }, function() {
594 565
595 } 566 }
596 ); 567 );
597 }; 568 };
598 569
599 $scope.abrirModalCotizacion = function(moneda) { 570 $scope.abrirModalCotizacion = function(moneda) {
600 var modalInstance = $uibModal.open( 571 var modalInstance = $uibModal.open(
601 { 572 {
602 ariaLabelledBy: 'Busqueda de Cotización', 573 ariaLabelledBy: 'Busqueda de Cotización',
603 templateUrl: 'modal-cotizacion.html', 574 templateUrl: 'modal-cotizacion.html',
604 controller: 'focaModalCotizacionController', 575 controller: 'focaModalCotizacionController',
605 size: 'lg', 576 size: 'lg',
606 resolve: {idMoneda: function() {return moneda.ID;}} 577 resolve: {idMoneda: function() {return moneda.ID;}}
607 } 578 }
608 ); 579 );
609 modalInstance.result.then( 580 modalInstance.result.then(
610 function(cotizacion) { 581 function(cotizacion) {
611 var articulosTablaTemp = $scope.articulosTabla; 582 var articulosTablaTemp = $scope.articulosTabla;
612 for(var i = 0; i < articulosTablaTemp.length; i++) { 583 for(var i = 0; i < articulosTablaTemp.length; i++) {
613 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 584 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
614 $scope.remito.cotizacion.COTIZACION; 585 $scope.remito.cotizacion.COTIZACION;
615 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 586 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
616 cotizacion.COTIZACION; 587 cotizacion.COTIZACION;
617 } 588 }
618 $scope.articulosTabla = articulosTablaTemp; 589 $scope.articulosTabla = articulosTablaTemp;
619 $scope.remito.moneda = { 590 $scope.remito.moneda = {
620 id: moneda.ID, 591 id: moneda.ID,
621 detalle: moneda.DETALLE, 592 detalle: moneda.DETALLE,
622 simbolo: moneda.SIMBOLO 593 simbolo: moneda.SIMBOLO
623 }; 594 };
624 $scope.remito.cotizacion = { 595 $scope.remito.cotizacion = {
625 ID: cotizacion.ID, 596 ID: cotizacion.ID,
626 COTIZACION: cotizacion.COTIZACION, 597 COTIZACION: cotizacion.COTIZACION,
627 FECHA: cotizacion.FECHA 598 FECHA: cotizacion.FECHA
628 }; 599 };
629 addCabecera('Moneda:', moneda.DETALLE); 600 addCabecera('Moneda:', moneda.DETALLE);
630 addCabecera( 601 addCabecera(
631 'Fecha cotizacion:', 602 'Fecha cotizacion:',
632 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 603 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
633 ); 604 );
634 addCabecera('Cotizacion:', cotizacion.COTIZACION); 605 addCabecera('Cotizacion:', cotizacion.COTIZACION);
635 }, function() { 606 }, function() {
636 607
637 } 608 }
638 ); 609 );
639 }; 610 };
640 611
641 $scope.agregarATabla = function(key) { 612 $scope.agregarATabla = function(key) {
642 if(key === 13) { 613 if(key === 13) {
643 if($scope.articuloACargar.cantidad === undefined || 614 if($scope.articuloACargar.cantidad === undefined ||
644 $scope.articuloACargar.cantidad === 0 || 615 $scope.articuloACargar.cantidad === 0 ||
645 $scope.articuloACargar.cantidad === null ) { 616 $scope.articuloACargar.cantidad === null ) {
646 focaModalService.alert('El valor debe ser al menos 1'); 617 focaModalService.alert('El valor debe ser al menos 1');
647 return; 618 return;
648 } 619 }
649 delete $scope.articuloACargar.sectorCodigo; 620 delete $scope.articuloACargar.sectorCodigo;
650 $scope.articulosTabla.push($scope.articuloACargar); 621 $scope.articulosTabla.push($scope.articuloACargar);
651 $scope.cargando = true; 622 $scope.cargando = true;
652 } 623 }
653 }; 624 };
654 625
655 $scope.quitarArticulo = function(key) { 626 $scope.quitarArticulo = function(key) {
656 $scope.articulosTabla.splice(key, 1); 627 $scope.articulosTabla.splice(key, 1);
657 }; 628 };
658 629
659 $scope.editarArticulo = function(key, articulo) { 630 $scope.editarArticulo = function(key, articulo) {
660 if(key === 13) { 631 if(key === 13) {
661 if(articulo.cantidad === null || articulo.cantidad === 0 || 632 if(articulo.cantidad === null || articulo.cantidad === 0 ||
662 articulo.cantidad === undefined) { 633 articulo.cantidad === undefined) {
663 focaModalService.alert('El valor debe ser al menos 1'); 634 focaModalService.alert('El valor debe ser al menos 1');
664 return; 635 return;
665 } 636 }
666 articulo.editCantidad = false; 637 articulo.editCantidad = false;
667 articulo.editPrecio = false; 638 articulo.editPrecio = false;
668 } 639 }
669 }; 640 };
670 641
671 $scope.cambioEdit = function(articulo, propiedad) { 642 $scope.cambioEdit = function(articulo, propiedad) {
672 if(propiedad === 'cantidad') { 643 if(propiedad === 'cantidad') {
673 articulo.editCantidad = true; 644 articulo.editCantidad = true;
674 } else if(propiedad === 'precio') { 645 } else if(propiedad === 'precio') {
675 articulo.editPrecio = true; 646 articulo.editPrecio = true;
676 } 647 }
677 }; 648 };
678 649
679 $scope.limpiarFlete = function() { 650 $scope.limpiarFlete = function() {
680 $scope.remito.fleteNombre = ''; 651 $scope.remito.fleteNombre = '';
681 $scope.remito.chofer = ''; 652 $scope.remito.chofer = '';
682 $scope.remito.vehiculo = ''; 653 $scope.remito.vehiculo = '';
683 $scope.remito.kilometros = ''; 654 $scope.remito.kilometros = '';
684 $scope.remito.costoUnitarioKmFlete = ''; 655 $scope.remito.costoUnitarioKmFlete = '';
685 $scope.choferes = ''; 656 $scope.choferes = '';
686 $scope.vehiculos = ''; 657 $scope.vehiculos = '';
687 }; 658 };
688 659
689 $scope.limpiarPantalla = function() { 660 $scope.limpiarPantalla = function() {
690 $scope.limpiarFlete(); 661 $scope.limpiarFlete();
691 $scope.remito.flete = '0'; 662 $scope.remito.flete = '0';
692 $scope.remito.bomba = '0'; 663 $scope.remito.bomba = '0';
693 $scope.remito.precioCondicion = ''; 664 $scope.remito.precioCondicion = '';
694 $scope.articulosTabla = []; 665 $scope.articulosTabla = [];
695 $scope.remito.vendedor.nombre = ''; 666 $scope.remito.vendedor.nombre = '';
696 $scope.remito.cliente = {nombre: ''}; 667 $scope.remito.cliente = {nombre: ''};
697 $scope.remito.domicilio = {dom: ''}; 668 $scope.remito.domicilio = {dom: ''};
698 $scope.domiciliosCliente = []; 669 $scope.domiciliosCliente = [];
699 }; 670 };
700 671
701 $scope.resetFilter = function() { 672 $scope.resetFilter = function() {
702 $scope.articuloACargar = {}; 673 $scope.articuloACargar = {};
703 $scope.cargando = true; 674 $scope.cargando = true;
704 }; 675 };
705 676
706 $scope.selectFocus = function($event) { 677 $scope.selectFocus = function($event) {
707 $event.target.select(); 678 $event.target.select();
708 }; 679 };
709 680
710 $scope.salir = function() { 681 $scope.salir = function() {
711 $location.path('/'); 682 $location.path('/');
712 }; 683 };
713 function addArrayCabecera(array) { 684 function addArrayCabecera(array) {
714 for(var i = 0; i < array.length; i++) { 685 for(var i = 0; i < array.length; i++) {
715 addCabecera(array[i].label, array[i].valor); 686 addCabecera(array[i].label, array[i].valor);
716 } 687 }
717 } 688 }
718 689
719 function addCabecera(label, valor) { 690 function addCabecera(label, valor) {
720 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 691 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
721 if(propiedad.length === 1) { 692 if(propiedad.length === 1) {
722 propiedad[0].valor = valor; 693 propiedad[0].valor = valor;
723 } else { 694 } else {
724 $scope.cabecera.push({label: label, valor: valor}); 695 $scope.cabecera.push({label: label, valor: valor});
725 } 696 }
726 } 697 }
727 698
728 function removeCabecera(label) { 699 function removeCabecera(label) {
729 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 700 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
730 if(propiedad.length === 1) { 701 if(propiedad.length === 1) {
731 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); 702 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1);
732 } 703 }
733 } 704 }
734 705
735 function rellenar(relleno, longitud) { 706 function rellenar(relleno, longitud) {
736 relleno = '' + relleno; 707 relleno = '' + relleno;
737 while (relleno.length < longitud) { 708 while (relleno.length < longitud) {
738 relleno = '0' + relleno; 709 relleno = '0' + relleno;
739 } 710 }
740 711
741 return relleno; 712 return relleno;
742 } 713 }
743 } 714 }
744 ] 715 ]
745 ) 716 )
746 .controller('remitoListaCtrl', [ 717 .controller('remitoListaCtrl', [
747 '$scope', 718 '$scope',
748 'crearRemitoService', 719 'crearRemitoService',
749 '$location', 720 '$location',
750 function($scope, crearRemitoService, $location) { 721 function($scope, crearRemitoService, $location) {
751 crearRemitoService.obtenerRemito().then(function(datos) { 722 crearRemitoService.obtenerRemito().then(function(datos) {
752 $scope.remitos = datos.data; 723 $scope.remitos = datos.data;
753 }); 724 });
754 $scope.editar = function(remito) { 725 $scope.editar = function(remito) {
755 crearRemitoService.setRemito(remito); 726 crearRemitoService.setRemito(remito);
756 $location.path('/venta-nota-remito/abm/'); 727 $location.path('/venta-nota-remito/abm/');
757 }; 728 };
758 $scope.crearRemito = function() { 729 $scope.crearRemito = function() {
759 crearRemitoService.clearRemito(); 730 crearRemitoService.clearRemito();
760 $location.path('/venta-nota-remito/abm/'); 731 $location.path('/venta-nota-remito/abm/');
761 }; 732 };
762 } 733 }
763 ]) 734 ])
764 .controller('focaCrearRemitoFichaClienteController', [ 735 .controller('focaCrearRemitoFichaClienteController', [
765 '$scope', 736 '$scope',
766 'crearRemitoService', 737 'crearRemitoService',
767 '$location', 738 '$location',
768 function($scope, crearRemitoService, $location) { 739 function($scope, crearRemitoService, $location) {
769 crearRemitoService.obtenerRemito().then(function(datos) { 740 crearRemitoService.obtenerRemito().then(function(datos) {
770 $scope.remitos = datos.data; 741 $scope.remitos = datos.data;
771 }); 742 });
772 $scope.editar = function(remito) { 743 $scope.editar = function(remito) {
773 crearRemitoService.setRemito(remito); 744 crearRemitoService.setRemito(remito);
774 $location.path('/venta-nota-remito/abm/'); 745 $location.path('/venta-nota-remito/abm/');
775 }; 746 };
776 $scope.crearRemito = function() { 747 $scope.crearRemito = function() {
777 crearRemitoService.clearRemito(); 748 crearRemitoService.clearRemito();
778 $location.path('/venta-nota-remito/abm/'); 749 $location.path('/venta-nota-remito/abm/');
779 }; 750 };
780 } 751 }
781 ]); 752 ]);
782 753