Commit f0b45eef525093b6daf234e060a474066a44a181

Authored by Eric Fernandez
1 parent 8682c021b1
Exists in master

espacio

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