Commit 2f5d95a07e37b1b45540026976ee61a55a7d6f91

Authored by Nicolás Guarnieri
1 parent fa3670018c
Exists in master and in 1 other branch develop

refactor AVENDCLI

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