Commit 7ea2b0fbbec5a15a3f89694c39be7cf42aec14cc

Authored by Eric Fernandez
1 parent 4f377f9fd6
Exists in master and in 1 other branch develop

cargar nota pedido para editar

Showing 2 changed files with 160 additions and 28 deletions   Show diff stats
src/js/controller.js
... ... @@ -7,17 +7,22 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
7 7 notaPedidoBusinessService, $rootScope
8 8 ) {
9 9 $scope.botonera = [
10   - {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}},
11   - {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}},
12   - {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}},
13   - {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}},
14   - {
15   - texto: 'Precios y condiciones',
16   - accion: function() {$scope.abrirModalListaPrecio();}},
17   - {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}},
  10 + {texto: 'Vendedor', accion: function() {
  11 + validarNotaRemitada($scope.seleccionarVendedor);}},
  12 + {texto: 'Cliente', accion: function() {
  13 + validarNotaRemitada($scope.seleccionarCliente);}},
  14 + {texto: 'Proveedor', accion: function() {
  15 + validarNotaRemitada($scope.seleccionarProveedor);}},
  16 + {texto: 'Moneda', accion: function() {
  17 + validarNotaRemitada($scope.abrirModalMoneda);}},
  18 + {texto: 'Precios y condiciones', accion: function() {
  19 + validarNotaRemitada($scope.abrirModalListaPrecio);}},
  20 + {texto: 'Flete', accion: function() {
  21 + validarNotaRemitada($scope.abrirModalFlete);}},
18 22 {texto: '', accion: function() {}},
19 23 {texto: '', accion: function() {}}
20 24 ];
  25 +
21 26 $scope.datepickerAbierto = false;
22 27  
23 28 $scope.show = false;
... ... @@ -28,6 +33,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
28 33 };
29 34  
30 35 $scope.notaPedido = {
  36 + id: 0,
31 37 vendedor: {},
32 38 cliente: {},
33 39 proveedor: {},
... ... @@ -120,16 +126,16 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
120 126 // };
121 127  
122 128 $scope.crearNotaPedido = function() {
123   - if(!$scope.notaPedido.vendedor.codigo) {
  129 + if(!$scope.notaPedido.vendedor.CodVen) {
124 130 focaModalService.alert('Ingrese Vendedor');
125 131 return;
126   - } else if(!$scope.notaPedido.cliente.cod) {
  132 + } else if(!$scope.notaPedido.cliente.COD) {
127 133 focaModalService.alert('Ingrese Cliente');
128 134 return;
129   - } else if(!$scope.notaPedido.proveedor.codigo) {
  135 + } else if(!$scope.notaPedido.proveedor.COD) {
130 136 focaModalService.alert('Ingrese Proveedor');
131 137 return;
132   - } else if(!$scope.notaPedido.moneda.id) {
  138 + } else if(!$scope.notaPedido.moneda.ID) {
133 139 focaModalService.alert('Ingrese Moneda');
134 140 return;
135 141 } else if(!$scope.notaPedido.cotizacion.ID) {
... ... @@ -143,7 +149,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
143 149 {
144 150 focaModalService.alert('Ingrese Flete');
145 151 return;
146   - } else if(!$scope.notaPedido.domicilio.id) {
  152 + } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto
147 153 focaModalService.alert('Ingrese Domicilio');
148 154 return;
149 155 } else if($scope.articulosTabla.length === 0) {
... ... @@ -152,14 +158,14 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
152 158 }
153 159 var date = new Date();
154 160 var notaPedido = {
155   - id: 0,
  161 + id: $scope.notaPedido.id,
156 162 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
157 163 .toISOString().slice(0, 19).replace('T', ' '),
158   - idVendedor: $scope.notaPedido.vendedor.codigo,
159   - idCliente: $scope.notaPedido.cliente.cod,
160   - nombreCliente: $scope.notaPedido.cliente.nom,
161   - cuitCliente: $scope.notaPedido.cliente.cuit,
162   - idProveedor: $scope.notaPedido.proveedor.codigo,
  164 + idVendedor: $scope.notaPedido.vendedor.CodVen,
  165 + idCliente: $scope.notaPedido.cliente.COD,
  166 + nombreCliente: $scope.notaPedido.cliente.NOM,
  167 + cuitCliente: $scope.notaPedido.cliente.CUIT,
  168 + idProveedor: $scope.notaPedido.proveedor.COD,
163 169 idDomicilio: $scope.notaPedido.domicilio.id,
164 170 idCotizacion: $scope.notaPedido.cotizacion.ID,
165 171 idPrecioCondicion: $scope.notaPedido.idPrecioCondicion,
... ... @@ -212,7 +218,111 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
212 218 }
213 219 );
214 220 };
  221 +
  222 + $scope.seleccionarNotaPedido = function() {
  223 + var modalInstance = $uibModal.open(
  224 + {
  225 + ariaLabelledBy: 'Busqueda de Nota de Pedido',
  226 + templateUrl: 'foca-modal-nota-pedido.html',
  227 + controller: 'focaModalNotaPedidoController',
  228 + size: 'lg'
  229 + }
  230 + );
  231 + modalInstance.result.then(
  232 + function(notaPedido) {
  233 + //añado cabeceras
  234 + $scope.notaPedido.id = notaPedido.id;
  235 + removeCabecera('Moneda:');
  236 + removeCabecera('Fecha cotizacion:');
  237 + removeCabecera('Cotizacion:');
  238 + var cabeceras = [
  239 + {
  240 + label: 'Moneda',
  241 + valor: notaPedido.cotizacion[0].moneda[0].DETALLE
  242 + },
  243 + {
  244 + label: 'Fecha cotizacion',
  245 + valor: $filter('date')(notaPedido.cotizacion[0].FECHA,
  246 + 'dd/MM/yyyy')
  247 + },
  248 + {
  249 + label: 'Cotizacion',
  250 + valor: notaPedido.cotizacion[0].VENDEDOR
  251 + },
  252 + {
  253 + label: 'Cliente:',
  254 + valor: notaPedido.cliente[0].NOM
  255 + },
  256 + {
  257 + label: 'Domicilio:',
  258 + valor: notaPedido.domicilioStamp
  259 + },
  260 + {
  261 + label: 'Vendedor:',
  262 + valor: notaPedido.vendedor[0].NomVen
  263 + },
  264 + {
  265 + label: 'Proveedor:',
  266 + valor: notaPedido.proveedor[0].NOM
  267 + },
  268 + {
  269 + label: 'Flete:',
  270 + valor: notaPedido.flete === 1 ? 'Si' : 'No'
  271 + },
  272 + {
  273 + label: 'FOB:',
  274 + valor: notaPedido.fob === 1 ? 'Si' : 'No'
  275 + },
  276 + {
  277 + label: 'Precio condicion:',
  278 + valor: valorPrecioCondicion()
  279 + }
  280 + ];
  281 + //TODO MOSTRAR PLAZOS
  282 + function valorPrecioCondicion() {
  283 + if(notaPedido.idPrecioCondicion > 0) {
  284 + return notaPedido.precioCondicion[0].nombre;
  285 + } else {
  286 + return 'Ingreso Manual';
  287 + }
  288 + }
215 289  
  290 + if(notaPedido.flete === 1) {
  291 + var cabeceraBomba = {
  292 + label: 'Bomba',
  293 + valor: notaPedido.bomba === 1 ? 'Si' : 'No'
  294 + };
  295 + if(notaPedido.kilometros) {
  296 + var cabeceraKilometros = {
  297 + label: 'Kilometros',
  298 + valor: notaPedido.kilometros
  299 + };
  300 + cabeceras.push(cabeceraKilometros);
  301 + }
  302 + cabeceras.push(cabeceraBomba);
  303 + }
  304 + $scope.articulosTabla = notaPedido.articulosNotaPedido;
  305 + if(notaPedido.precioCondicion.length > 0) {
  306 + $scope.idLista = notaPedido.precioCondicion[0].idListaPrecio;
  307 + } else {
  308 + $scope.idLista = -1;
  309 + }
  310 + $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8);
  311 + $scope.notaPedido = notaPedido;
  312 + $scope.notaPedido.vendedor = notaPedido.vendedor[0];
  313 + $scope.notaPedido.cliente = notaPedido.cliente[0];
  314 + $scope.notaPedido.proveedor = notaPedido.proveedor[0];
  315 + $scope.notaPedido.moneda = notaPedido.cotizacion[0].moneda[0];
  316 + $scope.notaPedido.cotizacion = notaPedido.cotizacion[0];
  317 + $scope.plazosPagos = notaPedido.plazoPago;
  318 + addArrayCabecera(cabeceras);
  319 +
  320 + }, function() {
  321 + // funcion ejecutada cuando se cancela el modal
  322 + }
  323 + );
  324 + }
  325 +
216 326 $scope.seleccionarArticulo = function() {
217 327 if ($scope.idLista === undefined) {
218 328 focaModalService.alert(
... ... @@ -279,7 +389,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
279 389 modalInstance.result.then(
280 390 function(vendedor) {
281 391 addCabecera('Vendedor:', vendedor.NomVen);
282   - $scope.notaPedido.vendedor.codigo = vendedor.CodVen;
  392 + $scope.notaPedido.vendedor = vendedor;
283 393 }, function() {
284 394  
285 395 }
... ... @@ -302,7 +412,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
302 412 );
303 413 modalInstance.result.then(
304 414 function(proveedor) {
305   - $scope.notaPedido.proveedor.codigo = proveedor.COD;
  415 + $scope.notaPedido.proveedor = proveedor;
306 416 addCabecera('Proveedor:', proveedor.NOM);
307 417 }, function() {
308 418  
... ... @@ -341,8 +451,12 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
341 451 );
342 452 modalInstanceDomicilio.result.then(
343 453 function(domicilio) {
344   - $scope.notaPedido.domicilio.id = domicilio.id;
345   - $scope.notaPedido.cliente = cliente;
  454 + $scope.notaPedido.domicilio = domicilio;
  455 + $scope.notaPedido.cliente = {
  456 + COD: cliente.cod,
  457 + CUIT: cliente.cuit,
  458 + NOM: cliente.nom
  459 + };
346 460 addCabecera('Cliente:', cliente.nom);
347 461 var domicilioStamp =
348 462 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
... ... @@ -505,11 +619,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
505 619 cotizacion.VENDEDOR;
506 620 }
507 621 $scope.articulosTabla = articulosTablaTemp;
508   - $scope.notaPedido.moneda = {
509   - id: moneda.ID,
510   - detalle: moneda.DETALLE,
511   - simbolo: moneda.SIMBOLO
512   - };
  622 + $scope.notaPedido.moneda = moneda;
513 623 $scope.notaPedido.cotizacion = cotizacion;
514 624 addCabecera('Moneda:', moneda.DETALLE);
515 625 addCabecera(
... ... @@ -612,6 +722,12 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
612 722 articulo.cantidad = parseFloat(articulo.cantidad);
613 723 articulo.precio = parseFloat(articulo.precio);
614 724 };
  725 +
  726 + function addArrayCabecera(array) {
  727 + for(var i = 0; i < array.length; i++) {
  728 + addCabecera(array[i].label, array[i].valor);
  729 + }
  730 + }
615 731  
616 732 function addCabecera(label, valor) {
617 733 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
... ... @@ -637,6 +753,15 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
637 753  
638 754 return relleno;
639 755 }
  756 +
  757 + function validarNotaRemitada(funcion) {
  758 + if($scope.notaPedido.idRemito) {
  759 + focaModalService.alert('No se puede editar una nota de pedido remitada');
  760 + }
  761 + else {
  762 + funcion();
  763 + }
  764 + }
640 765 }
641 766 ]
642 767 )
src/views/nota-pedido.html
... ... @@ -10,6 +10,13 @@
10 10 </div>
11 11 <div class="col-5 col-sm-4 numero-pedido"
12 12 >Nº {{puntoVenta}}-{{comprobante}}
  13 + <button
  14 + class="btn btn-xs btn-outline-dark"
  15 + type="button"
  16 + ng-click="seleccionarNotaPedido()"
  17 + >
  18 + <i class="fa fa-search"></i>
  19 + </button>
13 20 </div>
14 21 <div class="col-7 col-sm-4 text-right">
15 22 Fecha: