Commit 60fba4e85e65bb7f66b0f131aa3d27be5626ec89

Authored by Nicolás Guarnieri
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

Master(efernandez)

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