Commit a1fdb01b0bc7bb4cb46ec514604fbfc8700d3828

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

Merge branch 'master' into 'master'

fuera bug sobreescribe numero cantidad

See merge request !4
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', '$rootScope',
5 function( 5 function(
6 $scope, $uibModal, $location, $filter, crearRemitoService, focaModalService, 6 $scope, $uibModal, $location, $filter, crearRemitoService, focaModalService,
7 remitoBusinessService) 7 remitoBusinessService, $rootScope)
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.puntoVenta = rellenar(remito.sucursal, 4);
288 $scope.comprobante = rellenar(remito.numeroRemito, 8); 288 $scope.comprobante = rellenar(remito.numeroRemito, 8);
289 $scope.remito = remito; 289 $scope.remito = remito;
290 $scope.remito.moneda = remito.cotizacion.moneda; 290 $scope.remito.moneda = remito.cotizacion.moneda;
291 $scope.plazosPagos = remito.remitoPlazo; 291 $scope.plazosPagos = remito.remitoPlazo;
292 addArrayCabecera(cabeceras); 292 addArrayCabecera(cabeceras);
293 }, function() { 293 }, function() {
294 // funcion ejecutada cuando se cancela el modal 294 // funcion ejecutada cuando se cancela el modal
295 } 295 }
296 ); 296 );
297 }; 297 };
298 298
299 //validacion por domicilio y por plazo pago 299 //validacion por domicilio y por plazo pago
300 $scope.crearRemito = function() { 300 $scope.crearRemito = function() {
301 if(!$scope.remito.vendedor) { 301 if(!$scope.remito.vendedor) {
302 focaModalService.alert('Ingrese Vendedor'); 302 focaModalService.alert('Ingrese Vendedor');
303 return; 303 return;
304 } else if(!$scope.remito.cliente) { 304 } else if(!$scope.remito.cliente) {
305 focaModalService.alert('Ingrese Cliente'); 305 focaModalService.alert('Ingrese Cliente');
306 return; 306 return;
307 } else if(!$scope.remito.proveedor) { 307 } else if(!$scope.remito.proveedor) {
308 focaModalService.alert('Ingrese Proveedor'); 308 focaModalService.alert('Ingrese Proveedor');
309 return; 309 return;
310 } else if(!$scope.remito.moneda.id && !$scope.remito.moneda.ID) { 310 } else if(!$scope.remito.moneda.id && !$scope.remito.moneda.ID) {
311 focaModalService.alert('Ingrese Moneda'); 311 focaModalService.alert('Ingrese Moneda');
312 return; 312 return;
313 } else if(!$scope.remito.cotizacion.ID) { 313 } else if(!$scope.remito.cotizacion.ID) {
314 focaModalService.alert('Ingrese Cotización'); 314 focaModalService.alert('Ingrese Cotización');
315 return; 315 return;
316 } else if( 316 } else if(
317 $scope.remito.flete === undefined || $scope.remito.flete === null) 317 $scope.remito.flete === undefined || $scope.remito.flete === null)
318 { 318 {
319 focaModalService.alert('Ingrese Flete'); 319 focaModalService.alert('Ingrese Flete');
320 return; 320 return;
321 } else if($scope.articulosTabla.length === 0) { 321 } else if($scope.articulosTabla.length === 0) {
322 focaModalService.alert('Debe cargar al menos un articulo'); 322 focaModalService.alert('Debe cargar al menos un articulo');
323 return; 323 return;
324 } 324 }
325 var save = { 325 var save = {
326 remito: { 326 remito: {
327 id: $scope.remito.id, 327 id: $scope.remito.id,
328 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), 328 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '),
329 idCliente: $scope.remito.cliente.COD, 329 idCliente: $scope.remito.cliente.COD,
330 nombreCliente: $scope.remito.cliente.NOM, 330 nombreCliente: $scope.remito.cliente.NOM,
331 cuitCliente: $scope.remito.cliente.CUIT, 331 cuitCliente: $scope.remito.cliente.CUIT,
332 responsabilidadIvaCliente: 0,//TODO, 332 responsabilidadIvaCliente: 0,//TODO,
333 descuento: 0,//TODO, 333 descuento: 0,//TODO,
334 importeNeto: 0,//TODO 334 importeNeto: 0,//TODO
335 importeExento: 0,//TODO 335 importeExento: 0,//TODO
336 importeIva: 0,//TODO 336 importeIva: 0,//TODO
337 importeIvaServicios: 0,//TODO 337 importeIvaServicios: 0,//TODO
338 importeImpuestoInterno: 0,//TODO 338 importeImpuestoInterno: 0,//TODO
339 importeImpuestoInterno1: 0,//TODO 339 importeImpuestoInterno1: 0,//TODO
340 importeImpuestoInterno2: 0,//TODO 340 importeImpuestoInterno2: 0,//TODO
341 percepcion: 0,//TODO 341 percepcion: 0,//TODO
342 percepcionIva: 0,//TODO 342 percepcionIva: 0,//TODO
343 redondeo: 0,//TODO 343 redondeo: 0,//TODO
344 total: $scope.getTotal(), 344 total: $scope.getTotal(),
345 numeroNotaPedido: $scope.remito.numeroNotaPedido, 345 numeroNotaPedido: $scope.remito.numeroNotaPedido,
346 anulado: false, 346 anulado: false,
347 planilla: 0,//TODO 347 planilla: 0,//TODO
348 lugar: 0,//TODO 348 lugar: 0,//TODO
349 cuentaMadre: 0,// 349 cuentaMadre: 0,//
350 cuentaContable: 0,//TODO 350 cuentaContable: 0,//TODO
351 asiento: 0,//TODO 351 asiento: 0,//TODO
352 e_hd: '',//TODO 352 e_hd: '',//TODO
353 c_hd: '', 353 c_hd: '',
354 numeroLiquidoProducto: 0,//TODO 354 numeroLiquidoProducto: 0,//TODO
355 idVendedor: $scope.remito.idVendedor, 355 idVendedor: $scope.remito.idVendedor,
356 idProveedor: $scope.remito.idProveedor, 356 idProveedor: $scope.remito.idProveedor,
357 idDomicilio: 0,//TODO 357 idDomicilio: 0,//TODO
358 idCotizacion: $scope.remito.cotizacion.ID, 358 idCotizacion: $scope.remito.cotizacion.ID,
359 idPrecioCondicion: $scope.remito.idPrecioCondicion, 359 idPrecioCondicion: $scope.remito.idPrecioCondicion,
360 flete: $scope.remito.flete, 360 flete: $scope.remito.flete,
361 fob: $scope.remito.fob, 361 fob: $scope.remito.fob,
362 bomba: $scope.remito.bomba, 362 bomba: $scope.remito.bomba,
363 kilometros: $scope.remito.kilometros, 363 kilometros: $scope.remito.kilometros,
364 domicilioStamp: $scope.remito.domicilioStamp, 364 domicilioStamp: $scope.remito.domicilioStamp,
365 estado: 0,//TODO 365 estado: 0,//TODO
366 destinoVenta: 0,//TODO 366 destinoVenta: 0,//TODO
367 operacionTipo: 0//TODO 367 operacionTipo: 0//TODO
368 }, 368 },
369 notaPedido: $scope.notaPedido 369 notaPedido: $scope.notaPedido
370 }; 370 };
371 crearRemitoService.crearRemito(save).then( 371 crearRemitoService.crearRemito(save).then(
372 function(data) { 372 function(data) {
373 remitoBusinessService.addArticulos($scope.articulosTabla, 373 remitoBusinessService.addArticulos($scope.articulosTabla,
374 data.data.id, $scope.remito.cotizacion.COTIZACION); 374 data.data.id, $scope.remito.cotizacion.COTIZACION);
375 375
376 focaModalService.alert('Remito creado'); 376 focaModalService.alert('Remito creado');
377 //TODO: updatear plazos 377 //TODO: updatear plazos
378 if($scope.remito.id === 0) { 378 if($scope.remito.id === 0) {
379 var plazos = $scope.plazosPagos; 379 var plazos = $scope.plazosPagos;
380 380
381 for(var j = 0; j < plazos.length; j++) { 381 for(var j = 0; j < plazos.length; j++) {
382 var json = { 382 var json = {
383 idRemito: data.data.id, 383 idRemito: data.data.id,
384 dias: plazos[j].dias 384 dias: plazos[j].dias
385 }; 385 };
386 crearRemitoService.crearPlazosParaRemito(json); 386 crearRemitoService.crearPlazosParaRemito(json);
387 } 387 }
388 } 388 }
389 389
390 $scope.cabecera = []; 390 $scope.cabecera = [];
391 addCabecera('Moneda:', $scope.remito.moneda.DETALLE); 391 addCabecera('Moneda:', $scope.remito.moneda.DETALLE);
392 addCabecera( 392 addCabecera(
393 'Fecha cotizacion:', 393 'Fecha cotizacion:',
394 $filter('date')($scope.remito.cotizacion.FECHA, 'dd/MM/yyyy') 394 $filter('date')($scope.remito.cotizacion.FECHA, 'dd/MM/yyyy')
395 ); 395 );
396 addCabecera('Cotizacion:', $scope.remito.cotizacion.COTIZACION); 396 addCabecera('Cotizacion:', $scope.remito.cotizacion.COTIZACION);
397 $scope.remito.vendedor = {}; 397 $scope.remito.vendedor = {};
398 $scope.remito.cliente = {}; 398 $scope.remito.cliente = {};
399 $scope.remito.proveedor = {}; 399 $scope.remito.proveedor = {};
400 $scope.remito.domicilio = {}; 400 $scope.remito.domicilio = {};
401 $scope.remito.flete = null; 401 $scope.remito.flete = null;
402 $scope.remito.fob = null; 402 $scope.remito.fob = null;
403 $scope.remito.bomba = null; 403 $scope.remito.bomba = null;
404 $scope.remito.kilometros = null; 404 $scope.remito.kilometros = null;
405 $scope.articulosTabla = []; 405 $scope.articulosTabla = [];
406 crearRemitoService.getNumeroRemito().then( 406 crearRemitoService.getNumeroRemito().then(
407 function(res) { 407 function(res) {
408 $scope.puntoVenta = rellenar(res.data.sucursal, 4); 408 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
409 $scope.comprobante = rellenar(res.data.numeroRemito, 8); 409 $scope.comprobante = rellenar(res.data.numeroRemito, 8);
410 }, 410 },
411 function(err) { 411 function(err) {
412 focaModalService 412 focaModalService
413 .alert('La terminal no esta configurada correctamente'); 413 .alert('La terminal no esta configurada correctamente');
414 console.info(err); 414 console.info(err);
415 } 415 }
416 ); 416 );
417 $scope.notaPedido = { 417 $scope.notaPedido = {
418 id: 0 418 id: 0
419 }; 419 };
420 } 420 }
421 ); 421 );
422 }; 422 };
423 423
424 $scope.seleccionarArticulo = function() { 424 $scope.seleccionarArticulo = function() {
425 if ($scope.idLista === undefined) { 425 if ($scope.idLista === undefined) {
426 focaModalService.alert( 426 focaModalService.alert(
427 'Primero seleccione una lista de precio y condicion'); 427 'Primero seleccione una lista de precio y condicion');
428 return; 428 return;
429 } 429 }
430 var modalInstance = $uibModal.open( 430 var modalInstance = $uibModal.open(
431 { 431 {
432 ariaLabelledBy: 'Busqueda de Productos', 432 ariaLabelledBy: 'Busqueda de Productos',
433 templateUrl: 'modal-busqueda-productos.html', 433 templateUrl: 'modal-busqueda-productos.html',
434 controller: 'modalBusquedaProductosCtrl', 434 controller: 'modalBusquedaProductosCtrl',
435 resolve: { 435 resolve: {
436 parametroProducto: { 436 parametroProducto: {
437 idLista: $scope.idLista, 437 idLista: $scope.idLista,
438 cotizacion: $scope.remito.cotizacion.COTIZACION, 438 cotizacion: $scope.remito.cotizacion.COTIZACION,
439 simbolo: $scope.remito.moneda.simbolo 439 simbolo: $scope.remito.moneda.simbolo
440 } 440 }
441 }, 441 },
442 size: 'lg' 442 size: 'lg'
443 } 443 }
444 ); 444 );
445 modalInstance.result.then( 445 modalInstance.result.then(
446 function(producto) { 446 function(producto) {
447 var newArt = 447 var newArt =
448 { 448 {
449 id: 0, 449 id: 0,
450 codigo: producto.codigo, 450 codigo: producto.codigo,
451 sector: producto.sector, 451 sector: producto.sector,
452 sectorCodigo: producto.sector + '-' + producto.codigo, 452 sectorCodigo: producto.sector + '-' + producto.codigo,
453 descripcion: producto.descripcion, 453 descripcion: producto.descripcion,
454 item: $scope.articulosTabla.length + 1, 454 item: $scope.articulosTabla.length + 1,
455 nombre: producto.descripcion, 455 nombre: producto.descripcion,
456 precio: parseFloat(producto.precio.toFixed(4)), 456 precio: parseFloat(producto.precio.toFixed(4)),
457 costoUnitario: producto.costo, 457 costoUnitario: producto.costo,
458 editCantidad: false, 458 editCantidad: false,
459 editPrecio: false, 459 editPrecio: false,
460 rubro: producto.CodRub, 460 rubro: producto.CodRub,
461 exentoUnitario: producto.precio, 461 exentoUnitario: producto.precio,
462 ivaUnitario: producto.IMPIVA, 462 ivaUnitario: producto.IMPIVA,
463 impuestoInternoUnitario: producto.ImpInt, 463 impuestoInternoUnitario: producto.ImpInt,
464 impuestoInterno1Unitario: producto.ImpInt2, 464 impuestoInterno1Unitario: producto.ImpInt2,
465 impuestoInterno2Unitario: producto.ImpInt3, 465 impuestoInterno2Unitario: producto.ImpInt3,
466 precioLista: producto.precio, 466 precioLista: producto.precio,
467 combustible: 1, 467 combustible: 1,
468 facturado: 0 468 facturado: 0
469 }; 469 };
470 $scope.articuloACargar = newArt; 470 $scope.articuloACargar = newArt;
471 $scope.cargando = false; 471 $scope.cargando = false;
472 }, function() { 472 }, function() {
473 // funcion ejecutada cuando se cancela el modal 473 // funcion ejecutada cuando se cancela el modal
474 } 474 }
475 ); 475 );
476 }; 476 };
477 477
478 $scope.seleccionarVendedor = function() { 478 $scope.seleccionarVendedor = function() {
479 var modalInstance = $uibModal.open( 479 var modalInstance = $uibModal.open(
480 { 480 {
481 ariaLabelledBy: 'Busqueda de Vendedores', 481 ariaLabelledBy: 'Busqueda de Vendedores',
482 templateUrl: 'modal-vendedores.html', 482 templateUrl: 'modal-vendedores.html',
483 controller: 'modalVendedoresCtrl', 483 controller: 'modalVendedoresCtrl',
484 size: 'lg' 484 size: 'lg'
485 } 485 }
486 ); 486 );
487 modalInstance.result.then( 487 modalInstance.result.then(
488 function(vendedor) { 488 function(vendedor) {
489 addCabecera('Vendedor:', vendedor.NomVen); 489 addCabecera('Vendedor:', vendedor.NomVen);
490 $scope.remito.idVendedor = vendedor.CodVen; 490 $scope.remito.idVendedor = vendedor.CodVen;
491 }, function() { 491 }, function() {
492 492
493 } 493 }
494 ); 494 );
495 }; 495 };
496 496
497 $scope.seleccionarProveedor = function() { 497 $scope.seleccionarProveedor = function() {
498 var modalInstance = $uibModal.open( 498 var modalInstance = $uibModal.open(
499 { 499 {
500 ariaLabelledBy: 'Busqueda de Proveedor', 500 ariaLabelledBy: 'Busqueda de Proveedor',
501 templateUrl: 'modal-proveedor.html', 501 templateUrl: 'modal-proveedor.html',
502 controller: 'focaModalProveedorCtrl', 502 controller: 'focaModalProveedorCtrl',
503 size: 'lg', 503 size: 'lg',
504 resolve: { 504 resolve: {
505 transportista: function() { 505 transportista: function() {
506 return false; 506 return false;
507 } 507 }
508 } 508 }
509 } 509 }
510 ); 510 );
511 modalInstance.result.then( 511 modalInstance.result.then(
512 function(proveedor) { 512 function(proveedor) {
513 $scope.remito.idProveedor = proveedor.COD; 513 $scope.remito.idProveedor = proveedor.COD;
514 addCabecera('Proveedor:', proveedor.NOM); 514 addCabecera('Proveedor:', proveedor.NOM);
515 }, function() { 515 }, function() {
516 516
517 } 517 }
518 ); 518 );
519 }; 519 };
520 520
521 $scope.seleccionarCliente = function() { 521 $scope.seleccionarCliente = function() {
522 522
523 var modalInstance = $uibModal.open( 523 var modalInstance = $uibModal.open(
524 { 524 {
525 ariaLabelledBy: 'Busqueda de Cliente', 525 ariaLabelledBy: 'Busqueda de Cliente',
526 templateUrl: 'foca-busqueda-cliente-modal.html', 526 templateUrl: 'foca-busqueda-cliente-modal.html',
527 controller: 'focaBusquedaClienteModalController', 527 controller: 'focaBusquedaClienteModalController',
528 size: 'lg' 528 size: 'lg'
529 } 529 }
530 ); 530 );
531 modalInstance.result.then( 531 modalInstance.result.then(
532 function(cliente) { 532 function(cliente) {
533 $scope.abrirModalDomicilios(cliente); 533 $scope.abrirModalDomicilios(cliente);
534 }, function() { 534 }, function() {
535 535
536 } 536 }
537 ); 537 );
538 }; 538 };
539 539
540 $scope.abrirModalDomicilios = function(cliente) { 540 $scope.abrirModalDomicilios = function(cliente) {
541 var modalInstanceDomicilio = $uibModal.open( 541 var modalInstanceDomicilio = $uibModal.open(
542 { 542 {
543 ariaLabelledBy: 'Busqueda de Domicilios', 543 ariaLabelledBy: 'Busqueda de Domicilios',
544 templateUrl: 'modal-domicilio.html', 544 templateUrl: 'modal-domicilio.html',
545 controller: 'focaModalDomicilioController', 545 controller: 'focaModalDomicilioController',
546 size: 'lg', 546 size: 'lg',
547 resolve: { idCliente: function() { return cliente.cod; }} 547 resolve: { idCliente: function() { return cliente.cod; }}
548 } 548 }
549 ); 549 );
550 modalInstanceDomicilio.result.then( 550 modalInstanceDomicilio.result.then(
551 function(domicilio) { 551 function(domicilio) {
552 //$scope.remito.domicilio.id = domicilio.nivel2; 552 //$scope.remito.domicilio.id = domicilio.nivel2;
553 $scope.remito.cliente = { 553 $scope.remito.cliente = {
554 COD: cliente.cod, 554 COD: cliente.cod,
555 CUIT: cliente.cuit, 555 CUIT: cliente.cuit,
556 NOM: cliente.nom 556 NOM: cliente.nom
557 }; 557 };
558 558
559 addCabecera('Cliente:', cliente.nom); 559 addCabecera('Cliente:', cliente.nom);
560 var domicilioStamp = 560 var domicilioStamp =
561 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 561 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
562 domicilio.Localidad + ', ' + domicilio.Provincia; 562 domicilio.Localidad + ', ' + domicilio.Provincia;
563 $scope.remito.domicilioStamp = domicilioStamp; 563 $scope.remito.domicilioStamp = domicilioStamp;
564 addCabecera('Domicilio:', domicilioStamp); 564 addCabecera('Domicilio:', domicilioStamp);
565 }, function() { 565 }, function() {
566 $scope.seleccionarCliente(); 566 $scope.seleccionarCliente();
567 return; 567 return;
568 } 568 }
569 ); 569 );
570 }; 570 };
571 571
572 $scope.mostrarFichaCliente = function() { 572 $scope.mostrarFichaCliente = function() {
573 $uibModal.open( 573 $uibModal.open(
574 { 574 {
575 ariaLabelledBy: 'Datos del Cliente', 575 ariaLabelledBy: 'Datos del Cliente',
576 templateUrl: 'foca-crear-remito-ficha-cliente.html', 576 templateUrl: 'foca-crear-remito-ficha-cliente.html',
577 controller: 'focaCrearRemitoFichaClienteController', 577 controller: 'focaCrearRemitoFichaClienteController',
578 size: 'lg' 578 size: 'lg'
579 } 579 }
580 ); 580 );
581 }; 581 };
582 582
583 $scope.getTotal = function() { 583 $scope.getTotal = function() {
584 var total = 0; 584 var total = 0;
585 var arrayTempArticulos = $scope.articulosTabla; 585 var arrayTempArticulos = $scope.articulosTabla;
586 for (var i = 0; i < arrayTempArticulos.length; i++) { 586 for (var i = 0; i < arrayTempArticulos.length; i++) {
587 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 587 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
588 } 588 }
589 return parseFloat(total.toFixed(2)); 589 return parseFloat(total.toFixed(2));
590 }; 590 };
591 591
592 $scope.getSubTotal = function() { 592 $scope.getSubTotal = function() {
593 if($scope.articuloACargar) { 593 if($scope.articuloACargar) {
594 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 594 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
595 } 595 }
596 }; 596 };
597 597
598 $scope.abrirModalListaPrecio = function() { 598 $scope.abrirModalListaPrecio = function() {
599 var modalInstance = $uibModal.open( 599 var modalInstance = $uibModal.open(
600 { 600 {
601 ariaLabelledBy: 'Busqueda de Precio Condición', 601 ariaLabelledBy: 'Busqueda de Precio Condición',
602 templateUrl: 'modal-precio-condicion.html', 602 templateUrl: 'modal-precio-condicion.html',
603 controller: 'focaModalPrecioCondicionController', 603 controller: 'focaModalPrecioCondicionController',
604 size: 'lg' 604 size: 'lg'
605 } 605 }
606 ); 606 );
607 modalInstance.result.then( 607 modalInstance.result.then(
608 function(precioCondicion) { 608 function(precioCondicion) {
609 var cabecera = ''; 609 var cabecera = '';
610 var plazosConcat = ''; 610 var plazosConcat = '';
611 if(!Array.isArray(precioCondicion)) { 611 if(!Array.isArray(precioCondicion)) {
612 $scope.remito.idPrecioCondicion = precioCondicion.id; 612 $scope.remito.idPrecioCondicion = precioCondicion.id;
613 $scope.plazosPagos = precioCondicion.plazoPago; 613 $scope.plazosPagos = precioCondicion.plazoPago;
614 $scope.idLista = precioCondicion.idListaPrecio; 614 $scope.idLista = precioCondicion.idListaPrecio;
615 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 615 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
616 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 616 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
617 } 617 }
618 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); 618 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim();
619 } else { //Cuando se ingresan los plazos manualmente 619 } else { //Cuando se ingresan los plazos manualmente
620 $scope.remito.idPrecioCondicion = 0; 620 $scope.remito.idPrecioCondicion = 0;
621 $scope.idLista = -1; //-1, el modal productos busca todos los productos 621 $scope.idLista = -1; //-1, el modal productos busca todos los productos
622 $scope.plazosPagos = precioCondicion; 622 $scope.plazosPagos = precioCondicion;
623 for(var j = 0; j < precioCondicion.length; j++) { 623 for(var j = 0; j < precioCondicion.length; j++) {
624 plazosConcat += precioCondicion[j].dias + ' '; 624 plazosConcat += precioCondicion[j].dias + ' ';
625 } 625 }
626 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 626 cabecera = 'Ingreso manual ' + plazosConcat.trim();
627 } 627 }
628 $scope.articulosTabla = []; 628 $scope.articulosTabla = [];
629 addCabecera('Precios y condiciones:', cabecera); 629 addCabecera('Precios y condiciones:', cabecera);
630 }, function() { 630 }, function() {
631 631
632 } 632 }
633 ); 633 );
634 }; 634 };
635 635
636 $scope.abrirModalFlete = function() { 636 $scope.abrirModalFlete = function() {
637 var modalInstance = $uibModal.open( 637 var modalInstance = $uibModal.open(
638 { 638 {
639 ariaLabelledBy: 'Busqueda de Flete', 639 ariaLabelledBy: 'Busqueda de Flete',
640 templateUrl: 'modal-flete.html', 640 templateUrl: 'modal-flete.html',
641 controller: 'focaModalFleteController', 641 controller: 'focaModalFleteController',
642 size: 'lg', 642 size: 'lg',
643 resolve: { 643 resolve: {
644 parametrosFlete: 644 parametrosFlete:
645 function() { 645 function() {
646 return { 646 return {
647 flete: $scope.remito.flete ? '1' : 647 flete: $scope.remito.flete ? '1' :
648 ($scope.remito.fob ? 'FOB' : 648 ($scope.remito.fob ? 'FOB' :
649 ($scope.remito.flete === undefined ? null : '0')), 649 ($scope.remito.flete === undefined ? null : '0')),
650 bomba: $scope.remito.bomba ? '1' : 650 bomba: $scope.remito.bomba ? '1' :
651 ($scope.remito.bomba === undefined ? null : '0'), 651 ($scope.remito.bomba === undefined ? null : '0'),
652 kilometros: $scope.remito.kilometros 652 kilometros: $scope.remito.kilometros
653 }; 653 };
654 } 654 }
655 } 655 }
656 } 656 }
657 ); 657 );
658 modalInstance.result.then( 658 modalInstance.result.then(
659 function(datos) { 659 function(datos) {
660 $scope.remito.flete = datos.flete; 660 $scope.remito.flete = datos.flete;
661 $scope.remito.fob = datos.FOB; 661 $scope.remito.fob = datos.FOB;
662 $scope.remito.bomba = datos.bomba; 662 $scope.remito.bomba = datos.bomba;
663 $scope.remito.kilometros = datos.kilometros; 663 $scope.remito.kilometros = datos.kilometros;
664 664
665 addCabecera('Flete:', datos.flete ? 'Si' : 665 addCabecera('Flete:', datos.flete ? 'Si' :
666 ($scope.remito.fob ? 'FOB' : 'No')); 666 ($scope.remito.fob ? 'FOB' : 'No'));
667 if(datos.flete) { 667 if(datos.flete) {
668 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); 668 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No');
669 addCabecera('Kilometros:', datos.kilometros); 669 addCabecera('Kilometros:', datos.kilometros);
670 } else { 670 } else {
671 removeCabecera('Bomba:'); 671 removeCabecera('Bomba:');
672 removeCabecera('Kilometros:'); 672 removeCabecera('Kilometros:');
673 $scope.remito.fob = false; 673 $scope.remito.fob = false;
674 $scope.remito.bomba = false; 674 $scope.remito.bomba = false;
675 $scope.remito.kilometros = null; 675 $scope.remito.kilometros = null;
676 } 676 }
677 }, function() { 677 }, function() {
678 678
679 } 679 }
680 ); 680 );
681 }; 681 };
682 682
683 $scope.abrirModalMoneda = function() { 683 $scope.abrirModalMoneda = function() {
684 var modalInstance = $uibModal.open( 684 var modalInstance = $uibModal.open(
685 { 685 {
686 ariaLabelledBy: 'Busqueda de Moneda', 686 ariaLabelledBy: 'Busqueda de Moneda',
687 templateUrl: 'modal-moneda.html', 687 templateUrl: 'modal-moneda.html',
688 controller: 'focaModalMonedaController', 688 controller: 'focaModalMonedaController',
689 size: 'lg' 689 size: 'lg'
690 } 690 }
691 ); 691 );
692 modalInstance.result.then( 692 modalInstance.result.then(
693 function(moneda) { 693 function(moneda) {
694 $scope.abrirModalCotizacion(moneda); 694 $scope.abrirModalCotizacion(moneda);
695 }, function() { 695 }, function() {
696 696
697 } 697 }
698 ); 698 );
699 }; 699 };
700 700
701 $scope.abrirModalCotizacion = function(moneda) { 701 $scope.abrirModalCotizacion = function(moneda) {
702 var modalInstance = $uibModal.open( 702 var modalInstance = $uibModal.open(
703 { 703 {
704 ariaLabelledBy: 'Busqueda de Cotización', 704 ariaLabelledBy: 'Busqueda de Cotización',
705 templateUrl: 'modal-cotizacion.html', 705 templateUrl: 'modal-cotizacion.html',
706 controller: 'focaModalCotizacionController', 706 controller: 'focaModalCotizacionController',
707 size: 'lg', 707 size: 'lg',
708 resolve: {idMoneda: function() {return moneda.ID;}} 708 resolve: {idMoneda: function() {return moneda.ID;}}
709 } 709 }
710 ); 710 );
711 modalInstance.result.then( 711 modalInstance.result.then(
712 function(cotizacion) { 712 function(cotizacion) {
713 var articulosTablaTemp = $scope.articulosTabla; 713 var articulosTablaTemp = $scope.articulosTabla;
714 for(var i = 0; i < articulosTablaTemp.length; i++) { 714 for(var i = 0; i < articulosTablaTemp.length; i++) {
715 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 715 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
716 $scope.remito.cotizacion.COTIZACION; 716 $scope.remito.cotizacion.COTIZACION;
717 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 717 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
718 cotizacion.COTIZACION; 718 cotizacion.COTIZACION;
719 } 719 }
720 $scope.articulosTabla = articulosTablaTemp; 720 $scope.articulosTabla = articulosTablaTemp;
721 $scope.remito.moneda = moneda; 721 $scope.remito.moneda = moneda;
722 $scope.remito.cotizacion = cotizacion; 722 $scope.remito.cotizacion = cotizacion;
723 addCabecera('Moneda:', moneda.DETALLE); 723 addCabecera('Moneda:', moneda.DETALLE);
724 addCabecera( 724 addCabecera(
725 'Fecha cotizacion:', 725 'Fecha cotizacion:',
726 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 726 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
727 ); 727 );
728 addCabecera('Cotizacion:', cotizacion.COTIZACION); 728 addCabecera('Cotizacion:', cotizacion.COTIZACION);
729 }, function() { 729 }, function() {
730 730
731 } 731 }
732 ); 732 );
733 }; 733 };
734 734
735 $scope.agregarATabla = function(key) { 735 $scope.agregarATabla = function(key) {
736 if(key === 13) { 736 if(key === 13) {
737 if($scope.articuloACargar.cantidad === undefined || 737 if($scope.articuloACargar.cantidad === undefined ||
738 $scope.articuloACargar.cantidad === 0 || 738 $scope.articuloACargar.cantidad === 0 ||
739 $scope.articuloACargar.cantidad === null ) { 739 $scope.articuloACargar.cantidad === null ) {
740 focaModalService.alert('El valor debe ser al menos 1'); 740 focaModalService.alert('El valor debe ser al menos 1');
741 return; 741 return;
742 } 742 }
743 delete $scope.articuloACargar.sectorCodigo; 743 delete $scope.articuloACargar.sectorCodigo;
744 $scope.articulosTabla.push($scope.articuloACargar); 744 $scope.articulosTabla.push($scope.articuloACargar);
745 $scope.cargando = true; 745 $scope.cargando = true;
746 } 746 }
747 }; 747 };
748 748
749 $scope.quitarArticulo = function(key) { 749 $scope.quitarArticulo = function(key) {
750 $scope.articulosTabla.splice(key, 1); 750 $scope.articulosTabla.splice(key, 1);
751 }; 751 };
752 752
753 $scope.editarArticulo = function(key, articulo) { 753 $scope.editarArticulo = function(key, articulo) {
754 if(key === 13) { 754 if(key === 13) {
755 if(articulo.cantidad === null || articulo.cantidad === 0 || 755 if(articulo.cantidad === null || articulo.cantidad === 0 ||
756 articulo.cantidad === undefined) { 756 articulo.cantidad === undefined) {
757 focaModalService.alert('El valor debe ser al menos 1'); 757 focaModalService.alert('El valor debe ser al menos 1');
758 return; 758 return;
759 } 759 }
760 articulo.editCantidad = false; 760 articulo.editCantidad = false;
761 articulo.editPrecio = false; 761 articulo.editPrecio = false;
762 } 762 }
763 }; 763 };
764 764
765 $scope.cambioEdit = function(articulo, propiedad) { 765 $scope.cambioEdit = function(articulo, propiedad) {
766 if(propiedad === 'cantidad') { 766 if(propiedad === 'cantidad') {
767 articulo.editCantidad = true; 767 articulo.editCantidad = true;
768 } else if(propiedad === 'precio') { 768 } else if(propiedad === 'precio') {
769 articulo.editPrecio = true; 769 articulo.editPrecio = true;
770 } 770 }
771 }; 771 };
772 772
773 $scope.limpiarFlete = function() { 773 $scope.limpiarFlete = function() {
774 $scope.remito.fleteNombre = ''; 774 $scope.remito.fleteNombre = '';
775 $scope.remito.chofer = ''; 775 $scope.remito.chofer = '';
776 $scope.remito.vehiculo = ''; 776 $scope.remito.vehiculo = '';
777 $scope.remito.kilometros = ''; 777 $scope.remito.kilometros = '';
778 $scope.remito.costoUnitarioKmFlete = ''; 778 $scope.remito.costoUnitarioKmFlete = '';
779 $scope.choferes = ''; 779 $scope.choferes = '';
780 $scope.vehiculos = ''; 780 $scope.vehiculos = '';
781 }; 781 };
782 782
783 $scope.limpiarPantalla = function() { 783 $scope.limpiarPantalla = function() {
784 $scope.limpiarFlete(); 784 $scope.limpiarFlete();
785 $scope.remito.flete = '0'; 785 $scope.remito.flete = '0';
786 $scope.remito.bomba = '0'; 786 $scope.remito.bomba = '0';
787 $scope.remito.precioCondicion = ''; 787 $scope.remito.precioCondicion = '';
788 $scope.articulosTabla = []; 788 $scope.articulosTabla = [];
789 $scope.remito.vendedor.nombre = ''; 789 $scope.remito.vendedor.nombre = '';
790 $scope.remito.cliente = {nombre: ''}; 790 $scope.remito.cliente = {nombre: ''};
791 $scope.remito.domicilio = {dom: ''}; 791 $scope.remito.domicilio = {dom: ''};
792 $scope.domiciliosCliente = []; 792 $scope.domiciliosCliente = [];
793 }; 793 };
794 794
795 $scope.resetFilter = function() { 795 $scope.resetFilter = function() {
796 $scope.articuloACargar = {}; 796 $scope.articuloACargar = {};
797 $scope.cargando = true; 797 $scope.cargando = true;
798 }; 798 };
799 //Recibe aviso si el teclado está en uso
800 $rootScope.$on('usarTeclado', function(event, data) {
801 if(data) {
802 $scope.mostrarTeclado = true;
803 return;
804 }
805 $scope.mostrarTeclado = false;
806 });
799 807
800 $scope.selectFocus = function($event) { 808 $scope.selectFocus = function($event) {
809 // Si el teclado esta en uso no selecciona el valor
810 if($scope.mostrarTeclado) {
811 return;
812 }
801 $event.target.select(); 813 $event.target.select();
802 }; 814 };
803 815
804 $scope.salir = function() { 816 $scope.salir = function() {
805 $location.path('/'); 817 $location.path('/');
806 }; 818 };
807 function addArrayCabecera(array) { 819 function addArrayCabecera(array) {
808 for(var i = 0; i < array.length; i++) { 820 for(var i = 0; i < array.length; i++) {
809 addCabecera(array[i].label, array[i].valor); 821 addCabecera(array[i].label, array[i].valor);
810 } 822 }
811 } 823 }
812 824
813 function addCabecera(label, valor) { 825 function addCabecera(label, valor) {
814 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 826 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
815 if(propiedad.length === 1) { 827 if(propiedad.length === 1) {
816 propiedad[0].valor = valor; 828 propiedad[0].valor = valor;
817 } else { 829 } else {
818 $scope.cabecera.push({label: label, valor: valor}); 830 $scope.cabecera.push({label: label, valor: valor});
819 } 831 }
820 } 832 }
821 833
822 function removeCabecera(label) { 834 function removeCabecera(label) {
823 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 835 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
824 if(propiedad.length === 1) { 836 if(propiedad.length === 1) {
825 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); 837 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1);
826 } 838 }
827 } 839 }
828 840
829 function rellenar(relleno, longitud) { 841 function rellenar(relleno, longitud) {
830 relleno = '' + relleno; 842 relleno = '' + relleno;
831 while (relleno.length < longitud) { 843 while (relleno.length < longitud) {
832 relleno = '0' + relleno; 844 relleno = '0' + relleno;
833 } 845 }
834 846
835 return relleno; 847 return relleno;
836 } 848 }
837 849
838 function varlidarRemitoFacturado(funcion) { 850 function varlidarRemitoFacturado(funcion) {
839 if($scope.remito.estado === 5) { 851 if($scope.remito.estado === 5) {
840 focaModalService.alert('No se puede editar un remito facturado'); 852 focaModalService.alert('No se puede editar un remito facturado');
841 } 853 }
842 else { 854 else {
843 funcion(); 855 funcion();
844 } 856 }
845 } 857 }
846 } 858 }
847 ]); 859 ]);
848 860