Commit b1067ac76ba10382c9cc33553fb1d06c637a3b15
Exists in
master
and in
2 other branches
Merge branch 'master' into 'develop'
Master See merge request !54
Showing
1 changed file
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 | cisterna.disponible = cisterna.capacidad; |
53 | var newArt = | 53 | var newArt = |
54 | { | 54 | { |
55 | id: 0, | 55 | id: 0, |
56 | idRemito: 0, | 56 | idRemito: 0, |
57 | codigo: res.codigo, | 57 | codigo: res.codigo, |
58 | sector: res.sector, | 58 | sector: res.sector, |
59 | sectorCodigo: res.sector + '-' + res.codigo, | 59 | sectorCodigo: res.sector + '-' + res.codigo, |
60 | descripcion: res.descripcion, | 60 | descripcion: res.descripcion, |
61 | item: 1, | 61 | item: 1, |
62 | nombre: res.descripcion, | 62 | nombre: res.descripcion, |
63 | precio: parseFloat(res.precio).toFixed(4), | 63 | precio: parseFloat(res.precio).toFixed(4), |
64 | costoUnitario: res.costo, | 64 | costoUnitario: res.costo, |
65 | editCantidad: false, | 65 | editCantidad: false, |
66 | editPrecio: false, | 66 | editPrecio: false, |
67 | rubro: res.CodRub, | 67 | rubro: res.CodRub, |
68 | ivaUnitario: res.IMPIVA, | 68 | ivaUnitario: res.IMPIVA, |
69 | impuestoInternoUnitario: res.ImpInt, | 69 | impuestoInternoUnitario: res.ImpInt, |
70 | impuestoInterno1Unitario: res.ImpInt2, | 70 | impuestoInterno1Unitario: res.ImpInt2, |
71 | impuestoInterno2Unitario: res.ImpInt3, | 71 | impuestoInterno2Unitario: res.ImpInt3, |
72 | precioLista: res.precio, | 72 | precioLista: res.precio, |
73 | combustible: 1, | 73 | combustible: 1, |
74 | facturado: 0, | 74 | facturado: 0, |
75 | idArticulo: res.id, | 75 | idArticulo: res.id, |
76 | tasaIva: res.tasaIVA | 76 | tasaIva: res.tasaIVA |
77 | }; | 77 | }; |
78 | 78 | ||
79 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : res.neto; | 79 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : res.neto; |
80 | newArt.netoUnitario = newArt.ivaUnitario ? res.neto : 0; | 80 | newArt.netoUnitario = newArt.ivaUnitario ? res.neto : 0; |
81 | 81 | ||
82 | cisterna.articuloSeleccionado = newArt; | 82 | cisterna.articuloSeleccionado = newArt; |
83 | cisterna.nombreArticulo = res.descripcion; | 83 | cisterna.nombreArticulo = res.descripcion; |
84 | }).catch(function (e) { | 84 | }).catch(function (e) { |
85 | console.log(e); | 85 | console.log(e); |
86 | }); | 86 | }); |
87 | }; | 87 | }; |
88 | 88 | ||
89 | $scope.guardar = function () { | 89 | $scope.guardar = function () { |
90 | 90 | ||
91 | var cisternasFilter = $scope.hojasRutas.vehiculo.cisternas.filter(function (cisterna) { | 91 | var cisternasFilter = validarArticulos(); |
92 | return parseInt(cisterna.disponible) > 0 || cisterna.articuloSeleccionado; | ||
93 | }); | ||
94 | |||
95 | |||
96 | var cisternasIncompletas = cisternasFilter.filter(function(cisterna) { | ||
97 | return (cisterna.articuloSeleccionado && !cisterna.disponible) || | ||
98 | (!cisterna.articuloSeleccionado && cisterna.disponible); | ||
99 | }); | ||
100 | |||
101 | if (cisternasIncompletas.length || !cisternasFilter.length) { | ||
102 | return focaModalService.alert('Ingrese todos los campos para completar el remito'); | ||
103 | } | ||
104 | 92 | ||
105 | var articulos = []; | 93 | var articulos = []; |
106 | 94 | if (cisternasFilter === undefined) { | |
95 | return; | ||
96 | } | ||
107 | cisternasFilter.forEach(function (cisterna) { | 97 | cisternasFilter.forEach(function (cisterna) { |
108 | 98 | ||
109 | var fechaReparto = $scope.hojasRutas.fechaReparto; | 99 | var fechaReparto = $scope.hojasRutas.fechaReparto; |
110 | 100 | ||
111 | var filtroCisternaCarga = cisterna.cisternasCarga.filter(function(carga) { | 101 | var filtroCisternaCarga = cisterna.cisternasCarga.filter(function(carga) { |
112 | return carga.fechaReparto === fechaReparto; | 102 | return carga.fechaReparto === fechaReparto; |
113 | }); | 103 | }); |
114 | 104 | ||
115 | if (filtroCisternaCarga.length) { | 105 | if (filtroCisternaCarga.length) { |
116 | cisterna.cisternaCarga = filtroCisternaCarga[0]; | 106 | cisterna.cisternaCarga = filtroCisternaCarga[0]; |
117 | } else { | 107 | } else { |
118 | cisterna.cisternaCarga = { | 108 | cisterna.cisternaCarga = { |
119 | confirmado: null, | 109 | confirmado: null, |
120 | fechaReparto: fechaReparto, | 110 | fechaReparto: fechaReparto, |
121 | idCisterna: cisterna.id, | 111 | idCisterna: cisterna.id, |
122 | }; | 112 | }; |
123 | } | 113 | } |
124 | 114 | ||
125 | //cargar | 115 | //cargar |
126 | if (cisterna.cisternaCarga.cantidad) { | 116 | if (cisterna.cisternaCarga.cantidad) { |
127 | cisterna.cisternaCarga.cantidad += cisterna.disponible; | 117 | cisterna.cisternaCarga.cantidad += cisterna.disponible; |
128 | } else { | 118 | } else { |
129 | cisterna.cisternaCarga.cantidad = cisterna.disponible; | 119 | cisterna.cisternaCarga.cantidad = cisterna.disponible; |
130 | cisterna.cisternaCarga.idProducto = | 120 | cisterna.cisternaCarga.idProducto = |
131 | cisterna.articuloSeleccionado.idArticulo; | 121 | cisterna.articuloSeleccionado.idArticulo; |
132 | } | 122 | } |
133 | 123 | ||
134 | //Guardar | 124 | //Guardar |
135 | var now = new Date(); | 125 | var now = new Date(); |
136 | var cisternaMovimiento = { | 126 | var cisternaMovimiento = { |
137 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), | 127 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
138 | cantidad: cisterna.disponible, | 128 | cantidad: cisterna.disponible, |
139 | metodo: 'carga', | 129 | metodo: 'carga', |
140 | idCisternaCarga: cisterna.cisternaCarga.id, | 130 | idCisternaCarga: cisterna.cisternaCarga.id, |
141 | }; | 131 | }; |
142 | 132 | ||
143 | cisterna.cisternaCarga.fechaReparto = fechaReparto; | 133 | cisterna.cisternaCarga.fechaReparto = fechaReparto; |
144 | cisterna.articuloSeleccionado.cantidad = cisterna.disponible; | 134 | cisterna.articuloSeleccionado.cantidad = cisterna.disponible; |
145 | articulos.push(cisterna.articuloSeleccionado); | 135 | articulos.push(cisterna.articuloSeleccionado); |
146 | $scope.cisternaMovimientos.push(cisternaMovimiento); | 136 | $scope.cisternaMovimientos.push(cisternaMovimiento); |
147 | }); | 137 | }); |
148 | 138 | ||
149 | $uibModalInstance.close({ | 139 | $uibModalInstance.close({ |
150 | cisternas: cisternasFilter, | 140 | cisternas: cisternasFilter, |
151 | movimientos: $scope.cisternaMovimientos, | 141 | movimientos: $scope.cisternaMovimientos, |
152 | articulos: articulos | 142 | articulos: articulos |
153 | }); | 143 | }); |
154 | }; | 144 | }; |
155 | 145 | ||
156 | $scope.cancel = function () { | 146 | $scope.cancel = function () { |
157 | $uibModalInstance.dismiss(null); | 147 | var validarCisternas = validarArticulos(); |
148 | if (validarCisternas !== undefined) { | ||
149 | $uibModalInstance.dismiss(null); | ||
150 | } | ||
158 | }; | 151 | }; |
152 | |||
153 | function validarArticulos () { | ||
154 | var cisternasFilter = $scope.hojasRutas.vehiculo.cisternas.filter(function (cisterna) { | ||
155 | return parseInt(cisterna.disponible) > 0 || cisterna.articuloSeleccionado; | ||
156 | }); | ||
157 | |||
158 | var cisternasIncompletas = cisternasFilter.filter(function(cisterna) { | ||
159 | return (cisterna.articuloSeleccionado && !cisterna.disponible) || |