Commit ff92a13716511b05effcb1858935405aa1b999f3

Authored by Eric Fernandez
1 parent cc61e65c81
Exists in master

refactor servicios

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