Commit aa2f8afabd7b86596445a230f262e220bbf7f4bb

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

si tiene datos cargados, confirmar para salir

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