Commit 455a2bc081ecc4d522a8223cea4b37d38b94adb0

Authored by Eric Fernandez
1 parent e774771306
Exists in master

agrego todo

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