Commit 51100380231c18b464d1aafa22052752ad78cc9d

Authored by Eric Fernandez
1 parent e11ad8e95f
Exists in master and in 1 other branch develop

fix flete

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