Commit 90ff6023ac4313b554950dcacbdbda35a6d6591c
1 parent
e26d0fc934
Exists in
master
Seteo capacidad total luego de seleccionar producto
Showing
1 changed file
with
1 additions
and
0 deletions
Show diff stats
src/js/controllerDetalles.js
1 | angular.module('focaCrearHojaRuta') | 1 | angular.module('focaCrearHojaRuta') |
2 | .controller('focaModalDetalleController', [ | 2 | .controller('focaModalDetalleController', [ |
3 | '$scope', '$timeout', '$uibModalInstance', 'focaModalService', | 3 | '$scope', '$timeout', '$uibModalInstance', 'focaModalService', |
4 | 'focaCrearHojaRutaService', 'hojasRutas', '$uibModal', '$filter', | 4 | 'focaCrearHojaRutaService', 'hojasRutas', '$uibModal', '$filter', |
5 | function ($scope, $timeout, $uibModalInstance, focaModalService, | 5 | function ($scope, $timeout, $uibModalInstance, focaModalService, |
6 | focaCrearHojaRutaService, hojasRutas, $uibModal, $filter) { | 6 | focaCrearHojaRutaService, hojasRutas, $uibModal, $filter) { |
7 | 7 | ||
8 | $scope.mostrar = false; | 8 | $scope.mostrar = false; |
9 | $scope.articulos = []; | 9 | $scope.articulos = []; |
10 | $scope.cisternaMovimientos = []; | 10 | $scope.cisternaMovimientos = []; |
11 | 11 | ||
12 | init(); | 12 | init(); |
13 | function init() { | 13 | function init() { |
14 | $scope.hojasRutas = hojasRutas; | 14 | $scope.hojasRutas = hojasRutas; |
15 | 15 | ||
16 | $scope.hojasRutas.vehiculo.cisternas = $scope.hojasRutas.vehiculo.cisternas.filter( | 16 | $scope.hojasRutas.vehiculo.cisternas = $scope.hojasRutas.vehiculo.cisternas.filter( |
17 | function (cisterna) { | 17 | function (cisterna) { |
18 | return !cisterna.desactivado; | 18 | return !cisterna.desactivado; |
19 | } | 19 | } |
20 | ); | 20 | ); |
21 | focaCrearHojaRutaService.getArticulos() | 21 | focaCrearHojaRutaService.getArticulos() |
22 | .then(function (articulos) { | 22 | .then(function (articulos) { |
23 | $scope.articulos = articulos.data; | 23 | $scope.articulos = articulos.data; |
24 | }); | 24 | }); |
25 | } | 25 | } |
26 | 26 | ||
27 | $scope.validarCisternaDisponible = function (cisterna) { | 27 | $scope.validarCisternaDisponible = function (cisterna) { |
28 | if (parseInt(cisterna.disponible) > cisterna.capacidad) { | 28 | if (parseInt(cisterna.disponible) > cisterna.capacidad) { |
29 | focaModalService.alert('No se puede ingresar una capacidad disponible ' + | 29 | focaModalService.alert('No se puede ingresar una capacidad disponible ' + |
30 | 'superior a la ' + 'capacidad del vehiculo '); | 30 | 'superior a la ' + 'capacidad del vehiculo '); |
31 | cisterna.disponible = cisterna.capacidad; | 31 | cisterna.disponible = cisterna.capacidad; |
32 | return; | 32 | return; |
33 | } | 33 | } |
34 | }; | 34 | }; |
35 | 35 | ||
36 | $scope.seleccionarProductos = function (cisterna) { | 36 | $scope.seleccionarProductos = function (cisterna) { |
37 | focaModalService.modal({ | 37 | focaModalService.modal({ |
38 | titulo: 'Productos', | 38 | titulo: 'Productos', |
39 | data: $scope.articulos, | 39 | data: $scope.articulos, |
40 | size: 'md', | 40 | size: 'md', |
41 | columnas: [ | 41 | columnas: [ |
42 | { | 42 | { |
43 | propiedad: 'CodRub', | 43 | propiedad: 'CodRub', |
44 | nombre: 'Codigo' | 44 | nombre: 'Codigo' |
45 | }, | 45 | }, |
46 | { | 46 | { |
47 | propiedad: 'descripcion', | 47 | propiedad: 'descripcion', |
48 | nombre: 'Nombre' | 48 | nombre: 'Nombre' |
49 | }, | 49 | }, |
50 | ], | 50 | ], |
51 | }).then(function (res) { | 51 | }).then(function (res) { |
52 | cisterna.disponible = cisterna.capacidad; | ||
52 | var newArt = | 53 | var newArt = |
53 | { | 54 | { |
54 | id: 0, | 55 | id: 0, |
55 | idRemito: 0, | 56 | idRemito: 0, |
56 | codigo: res.codigo, | 57 | codigo: res.codigo, |
57 | sector: res.sector, | 58 | sector: res.sector, |
58 | sectorCodigo: res.sector + '-' + res.codigo, | 59 | sectorCodigo: res.sector + '-' + res.codigo, |
59 | descripcion: res.descripcion, | 60 | descripcion: res.descripcion, |
60 | item: 1, | 61 | item: 1, |
61 | nombre: res.descripcion, | 62 | nombre: res.descripcion, |
62 | precio: parseFloat(res.precio).toFixed(4), | 63 | precio: parseFloat(res.precio).toFixed(4), |
63 | costoUnitario: res.costo, | 64 | costoUnitario: res.costo, |
64 | editCantidad: false, | 65 | editCantidad: false, |
65 | editPrecio: false, | 66 | editPrecio: false, |
66 | rubro: res.CodRub, | 67 | rubro: res.CodRub, |
67 | ivaUnitario: res.IMPIVA, | 68 | ivaUnitario: res.IMPIVA, |
68 | impuestoInternoUnitario: res.ImpInt, | 69 | impuestoInternoUnitario: res.ImpInt, |
69 | impuestoInterno1Unitario: res.ImpInt2, | 70 | impuestoInterno1Unitario: res.ImpInt2, |
70 | impuestoInterno2Unitario: res.ImpInt3, | 71 | impuestoInterno2Unitario: res.ImpInt3, |
71 | precioLista: res.precio, | 72 | precioLista: res.precio, |
72 | combustible: 1, | 73 | combustible: 1, |
73 | facturado: 0, | 74 | facturado: 0, |
74 | idArticulo: res.id, | 75 | idArticulo: res.id, |
75 | tasaIva: res.tasaIVA | 76 | tasaIva: res.tasaIVA |
76 | }; | 77 | }; |
77 | 78 | ||
78 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : res.neto; | 79 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : res.neto; |
79 | newArt.netoUnitario = newArt.ivaUnitario ? res.neto : 0; | 80 | newArt.netoUnitario = newArt.ivaUnitario ? res.neto : 0; |
80 | 81 | ||
81 | cisterna.articuloSeleccionado = newArt; | 82 | cisterna.articuloSeleccionado = newArt; |
82 | cisterna.nombreArticulo = res.descripcion; | 83 | cisterna.nombreArticulo = res.descripcion; |
83 | }).catch(function (e) { | 84 | }).catch(function (e) { |
84 | console.log(e); | 85 | console.log(e); |
85 | }); | 86 | }); |
86 | }; | 87 | }; |
87 | 88 | ||
88 | $scope.guardar = function () { | 89 | $scope.guardar = function () { |
89 | 90 | ||
90 | var cisternasFilter = $scope.hojasRutas.vehiculo.cisternas.filter(function (cisterna) { | 91 | var cisternasFilter = $scope.hojasRutas.vehiculo.cisternas.filter(function (cisterna) { |
91 | return parseInt(cisterna.disponible) > 0 || cisterna.articuloSeleccionado; | 92 | return parseInt(cisterna.disponible) > 0 || cisterna.articuloSeleccionado; |
92 | }); | 93 | }); |
93 | 94 | ||
94 | 95 | ||
95 | var cisternasIncompletas = cisternasFilter.filter(function(cisterna) { | 96 | var cisternasIncompletas = cisternasFilter.filter(function(cisterna) { |
96 | return (cisterna.articuloSeleccionado && !cisterna.disponible) || | 97 | return (cisterna.articuloSeleccionado && !cisterna.disponible) || |
97 | (!cisterna.articuloSeleccionado && cisterna.disponible); | 98 | (!cisterna.articuloSeleccionado && cisterna.disponible); |
98 | }); | 99 | }); |
99 | 100 | ||
100 | if (cisternasIncompletas.length || !cisternasFilter.length) { | 101 | if (cisternasIncompletas.length || !cisternasFilter.length) { |
101 | return focaModalService.alert('Ingrese todos los campos para completar el remito'); | 102 | return focaModalService.alert('Ingrese todos los campos para completar el remito'); |
102 | } | 103 | } |
103 | 104 | ||
104 | var articulos = []; | 105 | var articulos = []; |
105 | 106 | ||
106 | cisternasFilter.forEach(function (cisterna) { | 107 | cisternasFilter.forEach(function (cisterna) { |
107 | 108 | ||
108 | var fechaReparto = $scope.hojasRutas.fechaReparto; | 109 | var fechaReparto = $scope.hojasRutas.fechaReparto; |
109 | 110 | ||
110 | var filtroCisternaCarga = cisterna.cisternasCarga.filter(function(carga) { | 111 | var filtroCisternaCarga = cisterna.cisternasCarga.filter(function(carga) { |
111 | return carga.fechaReparto === fechaReparto; | 112 | return carga.fechaReparto === fechaReparto; |
112 | }); | 113 | }); |
113 | 114 | ||
114 | if (filtroCisternaCarga.length) { | 115 | if (filtroCisternaCarga.length) { |
115 | cisterna.cisternaCarga = filtroCisternaCarga[0]; | 116 | cisterna.cisternaCarga = filtroCisternaCarga[0]; |
116 | } else { | 117 | } else { |
117 | cisterna.cisternaCarga = { | 118 | cisterna.cisternaCarga = { |
118 | confirmado: null, | 119 | confirmado: null, |
119 | fechaReparto: fechaReparto, | 120 | fechaReparto: fechaReparto, |
120 | idCisterna: cisterna.id, | 121 | idCisterna: cisterna.id, |
121 | }; | 122 | }; |
122 | } | 123 | } |
123 | 124 | ||
124 | //cargar | 125 | //cargar |
125 | if (cisterna.cisternaCarga.cantidad) { | 126 | if (cisterna.cisternaCarga.cantidad) { |
126 | cisterna.cisternaCarga.cantidad += cisterna.disponible; | 127 | cisterna.cisternaCarga.cantidad += cisterna.disponible; |
127 | } else { | 128 | } else { |
128 | cisterna.cisternaCarga.cantidad = cisterna.disponible; | 129 | cisterna.cisternaCarga.cantidad = cisterna.disponible; |
129 | cisterna.cisternaCarga.idProducto = | 130 | cisterna.cisternaCarga.idProducto = |
130 | cisterna.articuloSeleccionado.idArticulo; | 131 | cisterna.articuloSeleccionado.idArticulo; |
131 | } | 132 | } |
132 | 133 | ||
133 | //Guardar | 134 | //Guardar |
134 | var now = new Date(); | 135 | var now = new Date(); |
135 | var cisternaMovimiento = { | 136 | var cisternaMovimiento = { |
136 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), | 137 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
137 | cantidad: cisterna.disponible, | 138 | cantidad: cisterna.disponible, |
138 | metodo: 'carga', | 139 | metodo: 'carga', |
139 | idCisternaCarga: cisterna.cisternaCarga.id, | 140 | idCisternaCarga: cisterna.cisternaCarga.id, |
140 | }; | 141 | }; |
141 | 142 | ||
142 | cisterna.cisternaCarga.fechaReparto = fechaReparto; | 143 | cisterna.cisternaCarga.fechaReparto = fechaReparto; |
143 | cisterna.articuloSeleccionado.cantidad = cisterna.disponible; | 144 | cisterna.articuloSeleccionado.cantidad = cisterna.disponible; |
144 | articulos.push(cisterna.articuloSeleccionado); | 145 | articulos.push(cisterna.articuloSeleccionado); |
145 | $scope.cisternaMovimientos.push(cisternaMovimiento); | 146 | $scope.cisternaMovimientos.push(cisternaMovimiento); |
146 | }); | 147 | }); |
147 | 148 | ||
148 | $uibModalInstance.close({ | 149 | $uibModalInstance.close({ |
149 | cisternas: cisternasFilter, | 150 | cisternas: cisternasFilter, |
150 | movimientos: $scope.cisternaMovimientos, | 151 | movimientos: $scope.cisternaMovimientos, |
151 | articulos: articulos | 152 | articulos: articulos |
152 | }); | 153 | }); |
153 | }; | 154 | }; |
154 | 155 | ||
155 | $scope.cancel = function () { | 156 | $scope.cancel = function () { |
156 | $uibModalInstance.dismiss(null); | 157 | $uibModalInstance.dismiss(null); |
157 | }; | 158 | }; |
158 | } | 159 | } |
159 | ]); | 160 | ]); |
160 | 161 |