Commit 267e540896a69f1960996981001d72fb9b4c5328

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master

See merge request !40
src/js/controller.js
... ... @@ -17,78 +17,101 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
17 17 $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService,
18 18 focaBotoneraLateralService, focaModalService, notaPedidoBusinessService,
19 19 $rootScope, focaSeguimientoService, APP, focaLoginService)
20   - {
21   - if(APP === 'distribuidor') {
22   - var idVendedor = focaLoginService.getLoginData().vendedorCobrador;
23   - $scope.botonera = crearNotaPedidoService.getBotonera(idVendedor);
24   - crearNotaPedidoService.getVendedorById(idVendedor).then(
25   - function(res) {
26   - var vendedor = res.data;
27   - $scope.$broadcast('addCabecera', {
28   - label: 'Vendedor:',
29   - valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + ' - ' +
30   - vendedor.NomVen
31   - });
32   - $scope.notaPedido.vendedor = vendedor;
33   - }
34   - );
35   - }else {
36   - $scope.botonera = crearNotaPedidoService.getBotonera();
  20 + {
  21 + config();
  22 +
  23 + function config() {
  24 + // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA
  25 + $scope.isNumber = angular.isNumber;
  26 + $scope.datepickerAbierto = false;
  27 + $scope.show = false;
  28 + $scope.cargando = true;
  29 + $scope.now = new Date();
  30 + $scope.puntoVenta = '0000';
  31 + $scope.comprobante = '00000000';
  32 + $scope.dateOptions = {
  33 + maxDate: new Date(),
  34 + minDate: new Date(2010, 0, 1)
  35 + };
  36 +
  37 + //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
  38 + var monedaPorDefecto;
  39 + crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) {
  40 + monedaPorDefecto = res.data[0];
  41 +
  42 + $scope.notaPedido.moneda = monedaPorDefecto;
  43 + $scope.inicial.notaPedido.moneda = $scope.notaPedido.moneda;
  44 +
  45 + $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0];
  46 + $scope.inicial.notaPedido.cotizacion = $scope.notaPedido.cotizacion;
  47 + });
  48 +
  49 + //SETEO BOTONERA LATERAL
  50 + $timeout(function() {
  51 + focaBotoneraLateralService.showSalir(false);
  52 + focaBotoneraLateralService.showPausar(true);
  53 + focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido);
  54 + focaBotoneraLateralService.addCustomButton('Salir', salir);
  55 + });
  56 +
  57 + // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR
  58 + if (APP === 'distribuidor') {
  59 + $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador;
  60 + $scope.botonera = crearNotaPedidoService.getBotonera($scope.idVendedor);
  61 + } else {
  62 + $scope.botonera = crearNotaPedidoService.getBotonera();
  63 + }
  64 +
  65 + init();
37 66 }
38 67  
39   - $scope.isNumber = angular.isNumber;
40   - $scope.datepickerAbierto = false;
41   - $scope.show = false;
42   - $scope.cargando = true;
43   - $scope.dateOptions = {
44   - maxDate: new Date(),
45   - minDate: new Date(2010, 0, 1)
46   - };
  68 + function init() {
  69 + $scope.$broadcast('cleanCabecera');
47 70  
48   - $scope.notaPedido = {
49   - id: 0,
50   - vendedor: {},
51   - cliente: {},
52   - proveedor: {},
53   - domicilio: {dom: ''},
54   - moneda: {},
55   - cotizacion: {}
56   - };
57   - var monedaPorDefecto;
58   - //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
59   - crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) {
60   - monedaPorDefecto = res.data[0];
61   - $scope.notaPedido.moneda = monedaPorDefecto;
62   - $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0];
63   - });
  71 + $scope.notaPedido = {
  72 + id: 0,
  73 + cliente: {},
  74 + proveedor: {},
  75 + domicilio: {dom: ''},
  76 + vendedor: {}
  77 + };
  78 +
  79 + $scope.articulosTabla = [];
  80 + $scope.idLista = undefined;
64 81  
65   - $scope.cabecera = [];
66   - $scope.showCabecera = true;
67   -
68   - $scope.now = new Date();
69   - $scope.puntoVenta = '0000';
70   - $scope.comprobante = '00000000';
71   - $scope.articulosTabla = [];
72   - $scope.idLista = undefined;
73   -
74   - //SETEO BOTONERA LATERAL
75   - $timeout(function() {
76   - focaBotoneraLateralService.showSalir(false);
77   - focaBotoneraLateralService.showPausar(true);
78   - focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido);
79   - focaBotoneraLateralService.addCustomButton('Salir', salir);
80   - });
  82 + crearNotaPedidoService.getNumeroNotaPedido().then(
  83 + function(res) {
  84 + $scope.puntoVenta = rellenar(res.data.sucursal, 4);
  85 + $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8);
  86 + },
  87 + function(err) {
  88 + focaModalService.alert('La terminal no esta configurada correctamente');
  89 + console.info(err);
  90 + }
  91 + );
  92 +
  93 + if (APP === 'distribuidor') {
  94 + crearNotaPedidoService.getVendedorById($scope.idVendedor).then(
  95 + function(res) {
  96 + var vendedor = res.data;
  97 + $scope.$broadcast('addCabecera', {
  98 + label: 'Vendedor:',
  99 + valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + ' - ' +
  100 + vendedor.NomVen
  101 + });
81 102  
82   - crearNotaPedidoService.getNumeroNotaPedido().then(
83   - function(res) {
84   - $scope.puntoVenta = rellenar(res.data.sucursal, 4);
85   - $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8);
86   - },
87   - function(err) {
88   - focaModalService.alert('La terminal no esta configurada correctamente');
89   - console.info(err);
  103 + $scope.notaPedido.vendedor = vendedor;
  104 + $scope.inicial.notaPedido.vendedor =$scope.notaPedido.vendedor;
  105 + }
  106 + );
90 107 }
91   - );
  108 +
  109 + $scope.inicial = {
  110 + notaPedido: angular.copy($scope.notaPedido),
  111 + articulosTabla: angular.copy($scope.articulosTabla),
  112 + idLista: angular.copy($scope.idLista)
  113 + };
  114 + }
92 115  
93 116 $scope.crearNotaPedido = function() {
94 117 if(!$scope.notaPedido.vendedor.CodVen) {
... ... @@ -169,7 +192,8 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
169 192 dias: plazo.dias
170 193 });
171 194 });
172   - if(plazosACrear.length){
  195 +
  196 + if (plazosACrear.length) {
173 197 crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear);
174 198 }
175 199  
... ... @@ -178,45 +202,9 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
178 202  
179 203 focaBotoneraLateralService.endGuardar(true);
180 204 $scope.saveLoading = false;
181   - $scope.$broadcast('cleanCabecera');
182   - $scope.$broadcast('addCabecera', {
183   - label: 'Moneda:',
184   - valor: $scope.notaPedido.moneda.DETALLE
185   - });
186   - $scope.$broadcast('addCabecera', {
187   - label: 'Fecha cotizacion:',
188   - valor: $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy')
189   - });
190   - $scope.$broadcast('addCabecera', {
191   - label: 'Moneda:',
192   - valor: $scope.notaPedido.moneda.DETALLE
193   - });
194   - $scope.$broadcast('addCabecera', {
195   - label: 'Cotizacion:',
196   - valor: $filter('number')($scope.notaPedido.cotizacion.VENDEDOR, '2')
197   - });
198   - crearNotaPedidoService.getNumeroNotaPedido().then(
199   - function(res) {
200   - $scope.puntoVenta = rellenar(res.data.sucursal, 4);
201   - $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8);
202   - },
203   - function(err) {
204   - focaModalService.alert(
205   - 'La terminal no esta configurada correctamente');
206   - console.info(err);
207   - }
208   - );
209   - $scope.notaPedido.vendedor = {};
210   - $scope.notaPedido.cliente = {};
211   - $scope.notaPedido.proveedor = {};
212   - $scope.notaPedido.domicilio = {};
213   - $scope.notaPedido.flete = undefined;
214   - $scope.notaPedido.fob = undefined;
215   - $scope.notaPedido.bomba = undefined;
216   - $scope.notaPedido.kilometros = undefined;
217   - $scope.articulosTabla = [];
218   - },
219   - function(error) {
  205 +
  206 + init();
  207 + }, function(error) {
220 208 focaModalService.alert('Hubo un error al crear la nota de pedido');
221 209 focaBotoneraLateralService.endGuardar();
222 210 $scope.saveLoading = false;
... ... @@ -881,6 +869,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
881 869 return false;
882 870 }
883 871 }
  872 +
884 873 function formatearPuntosDescarga(puntosDescarga) {
885 874 var result = [];
886 875  
... ... @@ -917,23 +906,24 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
917 906 }
918 907  
919 908 function salir() {
920   - var notaPedido = {
921   - id: 0,
922   - vendedor: {},
923   - cliente: {},
924   - proveedor: {},
925   - domicilio: {dom: ''},
926   - moneda: $scope.notaPedido.moneda,
927   - cotizacion: $scope.notaPedido.cotizacion
928   - };
929   - if(JSON.stringify($scope.notaPedido) !== JSON.stringify(notaPedido)) {
930   - focaModalService
931   - .confirm('¿Esta seguro de que desea salir? ' +
932   - 'Se perderán todos los datos cargados.')
933   - .then(function(data) {
934   - if(data) $location.path('/');
935   - });
936   - }else {
  909 + var confirmacion = false;
  910 +
  911 + angular.forEach($scope.inicial, function(valor, key) {
  912 + if (!angular.equals($scope[key], $scope.inicial[key])) {
  913 + confirmacion = true;
  914 + }
  915 + });
  916 +
  917 + if (confirmacion) {
  918 + focaModalService.confirm(
  919 + '¿Esta seguro de que desea salir? ' +
  920 + 'Se perderán todos los datos cargados.'
  921 + ).then(function(data) {
  922 + if (data) {
  923 + $location.path('/');
  924 + }
  925 + });
  926 + } else {
937 927 $location.path('/');
938 928 }
939 929 }
src/views/nota-pedido.html
1 1 <div class="crear-nota-pedido foca-crear row">
2 2 <foca-cabecera-facturador
3   - titulo="'Nota de pedido'"
4   - numero="puntoVenta + '-' + comprobante"
5   - fecha="now"
6   - class="mb-0 col-lg-12"
7   - busqueda="seleccionarNotaPedido"
  3 + titulo="'Nota de pedido'"
  4 + numero="puntoVenta + '-' + comprobante"
  5 + fecha="now"
  6 + class="mb-0 col-lg-12"
  7 + busqueda="seleccionarNotaPedido"
8 8 ></foca-cabecera-facturador>
9 9 <div class="col-lg-12">
10 10 <div class="row">