Commit 7424f270a71a2150b94f5fcde927b4d95f5dde54

Authored by Jose Pinto
1 parent eaa234e5ab
Exists in master and in 1 other branch develop

agrego variable saveLoading

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