Commit de2d4b3e1e6a1315c4c2ee1373d775671f80498a

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master

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