Commit bdbd4d53ad093d716acc7b25e52e21044b34a7ff

Authored by Eric Fernandez
1 parent 19913b391c
Exists in master

Ordeno un poco el código

Showing 1 changed file with 70 additions and 77 deletions   Show diff stats
src/js/controller.js
1 1 angular.module('focaCrearNotaPedido')
2 2 .controller('notaPedidoCtrl',
3   - ['$scope', '$uibModal', '$location', 'crearNotaPedidoService', 'focaModalService',
4   - function($scope, $uibModal, $location, crearNotaPedidoService, focaModalService) {
  3 + ['$scope', '$uibModal', 'crearNotaPedidoService', 'focaModalService',
  4 + function($scope, $uibModal, crearNotaPedidoService, focaModalService) {
5 5 $scope.show = false;
6 6 $scope.cargando = true;
7 7 $scope.dateOptions = {
... ... @@ -10,12 +10,12 @@ angular.module('focaCrearNotaPedido')
10 10 };
11 11 $scope.notaPedido = {
12 12 vendedor: {},
13   - cliente: {}
  13 + cliente: {},
  14 + domicilio: { dom: ''}
14 15 };
15 16 $scope.articulosTabla = [];
16 17 var idLista;
17   - var notaPedidoTemp = crearNotaPedidoService.getNotaPedido();
18   - $scope.domiciliosCliente = crearNotaPedidoService.getDomicilios(1);
  18 + var notaPedidoTemp = crearNotaPedidoService.getNotaPedido();
19 19 crearNotaPedidoService.getPrecioCondicion().then(
20 20 function(res) {
21 21 $scope.precioCondiciones = res.data;
... ... @@ -33,15 +33,15 @@ angular.module('focaCrearNotaPedido')
33 33 $scope.articulosTabla = res.data;
34 34 }
35 35 );
36   - crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then(
37   - function(res) {
38   - $scope.notaPedido.domicilio = res.data;
39   - }
40   - );
  36 + // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then(
  37 + // function(res) {
  38 + // $scope.notaPedido.domicilio = res.data;
  39 + // }
  40 + // );
41 41 } else {
42 42 $scope.notaPedido.fechaCarga = new Date();
43   - $scope.notaPedido.domicilio = [{ id: 0 }];
44   - $scope.notaPedido.bomba = '1';
  43 + // $scope.notaPedido.domicilio = [{ id: 0 }];
  44 + $scope.notaPedido.bomba = '0';
45 45 $scope.notaPedido.flete = '0';
46 46 idLista = undefined;
47 47 }
... ... @@ -58,56 +58,44 @@ angular.module('focaCrearNotaPedido')
58 58 }
59 59 };
60 60 $scope.crearNotaPedido = function() {
  61 + if($scope.notaPedido.domicilio.id === undefined) {
  62 + $scope.notaPedido.domicilio.id = 0;
  63 + }
  64 + var date = new Date();
61 65 var notaPedido = {
62 66 id: 0,
63   - fechaCarga: $scope.notaPedido.fechaCarga,
  67 + fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
  68 + .toISOString().slice(0, 19).replace('T', ' '),
64 69 vendedor: $scope.notaPedido.vendedor.nombre,
65   - cliente: $scope.notaPedido.cliente.nombre,
66   - domicilio: $scope.notaPedido.domicilio.id,
  70 + idCliente: $scope.notaPedido.cliente.id,
  71 + domicilio: $scope.notaPedido.domicilio,
67 72 precioCondicion: $scope.notaPedido.precioCondicion,
68 73 bomba: $scope.notaPedido.bomba,
69 74 flete: $scope.notaPedido.flete,
70 75 total: $scope.getTotal()
71 76 };
72 77 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
73   - function() {
  78 + function(data) {
74 79 focaModalService.alert('Nota pedido creada');
75   - // $location.path('/venta-nota-pedido');
76   - // var flete = {
77   - // idNotaPedido: data.data.id,
78   - // idTransportista: $scope.notaPedido.fleteId,
79   - // idChofer: $scope.chofer.id,
80   - // idVehiculo: $scope.vehiculo.id,
81   - // kilometros: $scope.notaPedido.kilometros,
82   - // costoKilometro: $scope.notaPedido.costoUnitarioKmFlete
83   - // };
84   - //TO DO - Insert de flete
  80 + var flete = {
  81 + idNotaPedido: data.data.id,
  82 + idTransportista: $scope.notaPedido.fleteId,
  83 + idChofer: $scope.notaPedido.chofer.id,
  84 + idVehiculo: $scope.notaPedido.vehiculo.id,
  85 + kilometros: $scope.notaPedido.kilometros,
  86 + costoKilometro: $scope.notaPedido.costoUnitarioKmFlete
  87 + };
  88 + crearNotaPedidoService.crearFlete(flete);
  89 + var articulosNotaPedido = $scope.articulosTabla;
  90 + for(var i = 0; i< articulosNotaPedido.length;i++) {
  91 + delete articulosNotaPedido[i].edit;
  92 + articulosNotaPedido[i].idNotaPedido = data.data.id;
  93 + crearNotaPedidoService
  94 + .crearArticulosParaNotaPedido(articulosNotaPedido[i]);
  95 + }
  96 + $scope.limpiarPantalla();
85 97 }
86 98 );
87   - var articulosNotaPedido = $scope.articulosTabla;
88   - for(var i = 0; i< articulosNotaPedido.length;i++) {
89   - delete articulosNotaPedido[i].edit;
90   - crearNotaPedidoService
91   - .crearArticulosParaNotaPedido(articulosNotaPedido[i]).then(
92   - function() {
93   - return;
94   - }
95   - );
96   - }
97   - $scope.notaPedido.precioCondicion = '';
98   - $scope.articulosTabla = [];
99   - $scope.notaPedido.fleteNombre = '';
100   - $scope.notaPedido.chofer = '';
101   - $scope.notaPedido.vehiculo = '';
102   - $scope.notaPedido.kilometros = '';
103   - $scope.notaPedido.costoUnitarioKmFlete = '';
104   - $scope.notaPedido.vendedor.nombre = '';
105   - $scope.notaPedido.cliente.nombre = '';
106   - $scope.domicilio = '';
107   - $scope.notaPedido.flete = 0;
108   - };
109   - $scope.siguienteTab = function() {
110   - $scope.active = 1;
111 99 };
112 100 $scope.seleccionarArticulo = function() {
113 101 if (idLista === undefined) {
... ... @@ -190,7 +178,25 @@ angular.module(&#39;focaCrearNotaPedido&#39;)
190 178 );
191 179 modalInstance.result.then(
192 180 function(cliente) {
  181 + $scope.limpiarPantalla();
193 182 $scope.notaPedido.cliente.nombre = cliente.nom;
  183 + $scope.notaPedido.cliente.id = cliente.cod;
  184 + crearNotaPedidoService.getDomiciliosByIdCliente(cliente.cod).then(
  185 + function(data) {
  186 + if(data.data.length === 0){
  187 + focaModalService
  188 + .alert('El cliente no tienen domicilios de entrega')
  189 + .then(
  190 + function() {
  191 + $scope.seleccionarCliente();
  192 + $scope.notaPedido.cliente = {nombre: ''};
  193 + }
  194 + );
  195 + return;
  196 + }
  197 + $scope.domiciliosCliente = data.data;
  198 + }
  199 + );
194 200 }, function() {
195 201  
196 202 }
... ... @@ -206,13 +212,6 @@ angular.module(&#39;focaCrearNotaPedido&#39;)
206 212 }
207 213 );
208 214 };
209   - $scope.obtenerDomicilios = function(id) {
210   - crearNotaPedidoService.getDomicilios(id).then(
211   - function(res) {
212   - $scope.notaPedido.domicilio = res.data;
213   - }
214   - );
215   - };
216 215 $scope.getTotal = function() {
217 216 var total = 0;
218 217 var array = $scope.articulosTabla;
... ... @@ -226,10 +225,6 @@ angular.module(&#39;focaCrearNotaPedido&#39;)
226 225 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
227 226 }
228 227 };
229   - $scope.cargarArticulos = function() {
230   - idLista = $scope.notaPedido.precioCondicion;
231   - $scope.articulosTabla = [];
232   - };
233 228 $scope.abrirModalListaPrecio = function() {
234 229 var modalInstance = $uibModal.open(
235 230 {
... ... @@ -261,11 +256,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;)
261 256 );
262 257 modalInstance.result.then(
263 258 function(flete) {
264   - $scope.choferes = '';
265   - $scope.vehiculos = '';
266   - $scope.notaPedido.chofer = '';
267   - $scope.notaPedido.vehiculo = '';
268   - $scope.notaPedido.costoUnitarioKmFlete = '';
  259 + $scope.limpiarFlete();
269 260 $scope.notaPedido.fleteNombre = flete.nombre;
270 261 $scope.notaPedido.fleteId = flete.id;
271 262 $scope.choferes = flete.chofer;
... ... @@ -310,25 +301,27 @@ angular.module(&#39;focaCrearNotaPedido&#39;)
310 301 $scope.notaPedido.vehiculo = '';
311 302 $scope.notaPedido.kilometros = '';
312 303 $scope.notaPedido.costoUnitarioKmFlete = '';
  304 + $scope.choferes = '';
  305 + $scope.vehiculos = '';
313 306 };
314   - $scope.crearPedidoDemo = function() {
315   - focaModalService.alert('Pedido Creado');
  307 + $scope.limpiarPantalla = function() {
  308 + $scope.limpiarFlete();
  309 + $scope.notaPedido.flete = '0';
  310 + $scope.notaPedido.bomba = '0';
316 311 $scope.notaPedido.precioCondicion = '';
317   - $scope.articulosTabla = [];
318   - $scope.notaPedido.fleteNombre = '';
319   - $scope.notaPedido.chofer = '';
320   - $scope.notaPedido.vehiculo = '';
321   - $scope.notaPedido.kilometros = '';
322   - $scope.notaPedido.costoUnitarioKmFlete = '';
  312 + $scope.articulosTabla = [];
323 313 $scope.notaPedido.vendedor.nombre = '';
324   - $scope.notaPedido.cliente.nombre = '';
325   - $scope.domicilio.dom = '';
326   - $scope.notaPedido.flete = 0;
  314 + $scope.notaPedido.cliente = {nombre: ''};
  315 + $scope.notaPedido.domicilio = {dom: ''};
  316 + $scope.domiciliosCliente = [];
327 317 };
328 318 $scope.resetFilter = function() {
329 319 $scope.articuloACargar = {};
330 320 $scope.cargando = true;
331 321 };
  322 + $scope.selectFocus = function ($event) {
  323 + $event.target.select();
  324 + };
332 325 }
333 326 ]
334 327 )