Commit 427ce8385840a385ece3a4eeeff9b3a969ea6011

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master

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