Commit 202c7b56b3c5a99d8d3769fa3856fd164622beb8

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

inicializacion de controler y salir

Showing 1 changed file with 92 additions and 109 deletions   Show diff stats
src/js/controller.js
... ... @@ -6,66 +6,84 @@ angular.module('focaCrearRemito') .controller('remitoController',
6 6 $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService,
7 7 remitoBusinessService, $rootScope, focaBotoneraLateralService)
8 8 {
9   - $scope.botonera = crearRemitoService.getBotonera();
10   - $scope.isNumber = angular.isNumber;
11   - $scope.datepickerAbierto = false;
12   - $scope.show = false;
13   - $scope.cargando = true;
14   - $scope.dateOptions = {
15   - maxDate: new Date(),
16   - minDate: new Date(2010, 0, 1)
17   - };
18   -
19   - $scope.remito = {
20   - id: 0,
21   - estado: 0,
22   - vendedor: {},
23   - cliente: {},
24   - proveedor: {},
25   - domicilio: {dom: ''},
26   - moneda: {},
27   - cotizacion: {}
28   - };
  9 + config();
29 10  
30   - $scope.notaPedido = {
31   - id: 0
32   - };
33   - var monedaPorDefecto;
34   - //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
35   - crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) {
36   - monedaPorDefecto = res.data[0];
37   - $scope.remito.moneda = monedaPorDefecto;
38   - $scope.remito.cotizacion = monedaPorDefecto.cotizaciones[0];
39   - });
  11 + function config() {
  12 + $scope.botonera = crearRemitoService.getBotonera();
  13 + $scope.isNumber = angular.isNumber;
  14 + $scope.datepickerAbierto = false;
  15 + $scope.show = false;
  16 + $scope.cargando = true;
  17 + $scope.now = new Date();
  18 + $scope.puntoVenta = rellenar(0, 4);
  19 + $scope.comprobante = rellenar(0, 8);
  20 + $scope.dateOptions = {
  21 + maxDate: new Date(),
  22 + minDate: new Date(2010, 0, 1)
  23 + };
  24 +
  25 + var monedaPorDefecto;
  26 + //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
  27 + crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) {
  28 + monedaPorDefecto = res.data[0];
  29 +
  30 + $scope.remito.moneda = monedaPorDefecto;
  31 + $scope.inicial.remito.moneda = $scope.remito.moneda;
  32 +
  33 + $scope.remito.cotizacion = monedaPorDefecto.cotizaciones[0];
  34 + $scope.inicial.remito.cotizacion = $scope.remito.cotizacion;
  35 + });
  36 +
  37 + //SETEO BOTONERA LATERAL
  38 + $timeout(function() {
  39 + focaBotoneraLateralService.showSalir(false);
  40 + focaBotoneraLateralService.showPausar(true);
  41 + focaBotoneraLateralService.showGuardar(true, $scope.crearRemito);
  42 + focaBotoneraLateralService.addCustomButton('Salir', salir);
  43 + });
  44 +
  45 + init();
  46 + }
40 47  
41   - $scope.cabecera = [];
42   - $scope.showCabecera = true;
  48 + function init() {
  49 + $scope.$broadcast('cleanCabecera');
  50 +
  51 + $scope.remito = {
  52 + id: 0,
  53 + estado: 0,
  54 + vendedor: {},
  55 + cliente: {},
  56 + proveedor: {},
  57 + domicilio: {dom: ''},
  58 + moneda: {},
  59 + cotizacion: {}
  60 + };
43 61  
44   - $scope.now = new Date();
45   - $scope.puntoVenta = rellenar(0, 4);
46   - $scope.comprobante = rellenar(0, 8);
  62 + $scope.notaPedido = {
  63 + id: 0
  64 + };
47 65  
48   - $scope.articulosTabla = [];
49   - $scope.idLista = undefined;
  66 + $scope.articulosTabla = [];
  67 + $scope.idLista = undefined;
50 68  
51   - //SETEO BOTONERA LATERAL
52   - $timeout(function() {
53   - focaBotoneraLateralService.showSalir(false);
54   - focaBotoneraLateralService.showPausar(true);
55   - focaBotoneraLateralService.showGuardar(true, $scope.crearRemito);
56   - focaBotoneraLateralService.addCustomButton('Salir', salir);
57   - });
  69 + crearRemitoService.getNumeroRemito().then(
  70 + function(res) {
  71 + $scope.puntoVenta = rellenar(res.data.sucursal, 4);
  72 + $scope.comprobante = rellenar(res.data.numeroRemito, 8);
  73 + },
  74 + function(err) {
  75 + focaModalService.alert('La terminal no esta configurada correctamente');
  76 + console.info(err);
  77 + }
  78 + );
58 79  
59   - crearRemitoService.getNumeroRemito().then(
60   - function(res) {
61   - $scope.puntoVenta = rellenar(res.data.sucursal, 4);
62   - $scope.comprobante = rellenar(res.data.numeroRemito, 8);
63   - },
64   - function(err) {
65   - focaModalService.alert('La terminal no esta configurada correctamente');
66   - console.info(err);
67   - }
68   - );
  80 + $scope.inicial = {
  81 + remito: angular.copy($scope.remito),
  82 + notaPedido: angular.copy($scope.notaPedido),
  83 + articulosTabla: angular.copy($scope.articulosTabla),
  84 + idLista: angular.copy($scope.idLista)
  85 + };
  86 + }
69 87  
70 88 $scope.seleccionarNotaPedido = function() {
71 89 if(varlidarRemitoFacturado()) {
... ... @@ -383,43 +401,8 @@ angular.module('focaCrearRemito') .controller('remitoController',
383 401 crearRemitoService.crearPlazosParaRemito(json);
384 402 }
385 403 }
386   -
387   - $scope.$broadcast('cleanCabecera');
388   - $scope.$broadcast('addCabecera',{
389   - label: 'Moneda:',
390   - valor: $scope.remito.moneda.DETALLE
391   - });
392   - $scope.$broadcast('addCabecera',{
393   - label: 'Fecha cotizacion:',
394   - valor: $filter('date')($scope.remito.cotizacion.FECHA, 'dd/MM/yyyy')
395   - });
396   - $scope.$broadcast('addCabecera',{
397   - label: 'Cotizacion:',
398   - valor: $filter('number')($scope.remito.cotizacion.COTIZACION, '2')
399   - });
400   - $scope.remito.vendedor = {};
401   - $scope.remito.cliente = {};
402   - $scope.remito.proveedor = {};
403   - $scope.remito.domicilio = {};
404   - $scope.remito.flete = null;
405   - $scope.remito.fob = null;
406   - $scope.remito.bomba = null;
407   - $scope.remito.kilometros = null;
408   - $scope.articulosTabla = [];
409   - crearRemitoService.getNumeroRemito().then(
410   - function(res) {
411   - $scope.puntoVenta = rellenar(res.data.sucursal, 4);
412   - $scope.comprobante = rellenar(res.data.numeroRemito, 8);
413   - },
414   - function(err) {
415   - focaModalService
416   - .alert('La terminal no esta configurada correctamente');
417   - console.info(err);
418   - }
419   - );
420   - $scope.notaPedido = {
421   - id: 0
422   - };
  404 +
  405 + init();
423 406 }, function(error) {
424 407 focaModalService.alert('Hubo un error al crear el remito');
425 408 focaBotoneraLateralService.endGuardar();
... ... @@ -920,24 +903,24 @@ angular.module('focaCrearRemito') .controller('remitoController',
920 903 }
921 904  
922 905 function salir() {
923   - var remito = {
924   - id: 0,
925   - estado: 0,
926   - vendedor: {},
927   - cliente: {},
928   - proveedor: {},
929   - domicilio: {dom: ''},
930   - moneda: $scope.remito.moneda,
931   - cotizacion: $scope.remito.cotizacion
932   - };
933   - if(JSON.stringify($scope.remito) !== JSON.stringify(remito)) {
934   - focaModalService
935   - .confirm('¿Esta seguro de que desea salir? ' +
936   - 'Se perderán todos los datos cargados.')
937   - .then(function(data) {
938   - if(data) $location.path('/');
939   - });
940   - }else {
  906 + var confirmacion = false;
  907 +
  908 + angular.forEach($scope.inicial, function(valor, key) {
  909 + if (!angular.equals($scope[key], $scope.inicial[key])) {
  910 + confirmacion = true;
  911 + }
  912 + });
  913 +
  914 + if (confirmacion) {
  915 + focaModalService.confirm(
  916 + '¿Esta seguro de que desea salir? ' +
  917 + 'Se perderán todos los datos cargados.'
  918 + ).then(function(data) {
  919 + if (data) {
  920 + $location.path('/');
  921 + }
  922 + });
  923 + } else {
941 924 $location.path('/');
942 925 }
943 926 }