Commit eaa234e5ab1e15dedfa715f770b1a0c719c4ee31

Authored by Jose Pinto
1 parent aa2f8afabd
Exists in master

ok boton guardar cargando

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