Commit 088b4ef18665073413acb754e63f48bd27688e3c

Authored by Eric Fernandez
Exists in master

Merge branch 'master' of https://debo.suite.repo/modulos-npm/foca-crear-remito

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