Commit a1930b1817ac3f50392986c10d03fa56a236eace
1 parent
db44eb9833
Exists in
master
Corregido errores de sintaxis.
Showing
1 changed file
with
17 additions
and
21 deletions
Show diff stats
src/js/controller.js
| 1 | angular.module('focaModalDescarga') | 1 | angular.module('focaModalDescarga') |
| 2 | .controller('focaModalDescargaCtrl', [ | 2 | .controller('focaModalDescargaCtrl', [ |
| 3 | '$scope', | 3 | '$scope', |
| 4 | 'focaModalDescargasService', | 4 | 'focaModalDescargasService', |
| 5 | '$filter', | 5 | '$filter', |
| 6 | 'focaModalService', | 6 | 'focaModalService', |
| 7 | '$timeout', | 7 | '$timeout', |
| 8 | '$uibModalInstance', | 8 | '$uibModalInstance', |
| 9 | '$uibModal', | 9 | '$uibModal', |
| 10 | 'remito', | 10 | 'remito', |
| 11 | 'focaModalDetalleHojaRutaService', | 11 | 'focaModalDetalleHojaRutaService', |
| 12 | 'focaSeguimientoService', | 12 | 'focaSeguimientoService', |
| 13 | 'crearRemitoService', | 13 | 'crearRemitoService', |
| 14 | function ($scope, focaModalDescargasService, $filter, | 14 | function ($scope, focaModalDescargasService, $filter, |
| 15 | focaModalService, $timeout, $uibModalInstance, $uibModal, remito, | 15 | focaModalService, $timeout, $uibModalInstance, $uibModal, remito, |
| 16 | focaModalDetalleHojaRutaService, focaSeguimientoService, crearRemitoService) { | 16 | focaModalDetalleHojaRutaService, focaSeguimientoService, crearRemitoService) { |
| 17 | 17 | ||
| 18 | //#region variables | 18 | //#region variables |
| 19 | $scope.remito = {}; | 19 | $scope.remito = {}; |
| 20 | $scope.remito = remito; | 20 | $scope.remito = remito; |
| 21 | $scope.nroRecibo = 0; | 21 | $scope.nroRecibo = 0; |
| 22 | $scope.cisternas = remito.cisternas; | 22 | $scope.cisternas = remito.cisternas; |
| 23 | $scope.nroSucursal; | 23 | $scope.nroSucursal = 0; |
| 24 | $scope.nroRemito; | 24 | $scope.nroRemito = 0; |
| 25 | $scope.articulos = []; | 25 | $scope.articulos = []; |
| 26 | $scope.hasErrorSucursalRemito = false; | 26 | $scope.hasErrorSucursalRemito = false; |
| 27 | //#endregion | 27 | //#endregion |
| 28 | 28 | ||
| 29 | function init() { | 29 | function init() { |
| 30 | crearRemitoService.getNumeroRemito().then( | 30 | crearRemitoService.getNumeroRemito().then( |
| 31 | function (res) { | 31 | function (res) { |
| 32 | $scope.nroSucursal = res.data.sucursal; | 32 | $scope.nroSucursal = res.data.sucursal; |
| 33 | $scope.nroRemito = res.data.numeroRemito; | 33 | $scope.nroRemito = res.data.numeroRemito; |
| 34 | $scope.validateSucursalRemito($scope.nroSucursal, $scope.nroRemito); | 34 | $scope.validateSucursalRemito($scope.nroSucursal, $scope.nroRemito); |
| 35 | }, | 35 | }, |
| 36 | function (err) { | 36 | function (err) { |
| 37 | focaModalService.alert('La terminal no esta configurada correctamente'); | 37 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 38 | console.info(err); | 38 | console.info(err); |
| 39 | } | 39 | } |
| 40 | ); | 40 | ); |
| 41 | }; | 41 | } |
| 42 | 42 | ||
| 43 | init(); | 43 | init(); |
| 44 | 44 | ||
| 45 | $scope.crearRemito = function () { | 45 | $scope.crearRemito = function () { |
| 46 | if (!$scope.remito.cliente) { | 46 | if (!$scope.remito.cliente) { |
| 47 | focaModalService.alert("No has seleccionado cliente"); | 47 | focaModalService.alert('No has seleccionado cliente'); |
| 48 | return; | 48 | return; |
| 49 | } | 49 | } |
| 50 | if (validarDescarga()) { | 50 | if (validarDescarga()) { |
| 51 | return; | 51 | return; |
| 52 | } | 52 | } |
| 53 | //#region OBJETO REMITO | 53 | //#region OBJETO REMITO |
| 54 | var remito = { | 54 | var remito = { |
| 55 | id: 0, | 55 | id: 0, |
| 56 | fechaRemito: new Date().toISOString().slice(0, 19).replace('T', ' '), | 56 | fechaRemito: new Date().toISOString().slice(0, 19).replace('T', ' '), |
| 57 | idCliente: $scope.remito.cliente.cod, | 57 | idCliente: $scope.remito.cliente.cod, |
| 58 | nombreCliente: $scope.remito.cliente.nom, | 58 | nombreCliente: $scope.remito.cliente.nom, |
| 59 | cuitCliente: $scope.remito.cliente.cuit, | 59 | cuitCliente: $scope.remito.cliente.cuit, |
| 60 | total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR, | 60 | total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR, |
| 61 | numeroNotaPedido: $scope.remito.numeroNotaPedido, | 61 | numeroNotaPedido: $scope.remito.numeroNotaPedido, |
| 62 | idVendedor: $scope.remito.cliente.ven, | 62 | idVendedor: $scope.remito.cliente.ven, |
| 63 | idProveedor: $scope.remito.proveedor.COD, | 63 | idProveedor: $scope.remito.proveedor.COD, |
| 64 | idDomicilio: 0, | 64 | idDomicilio: 0, |
| 65 | idCotizacion: $scope.remito.cotizacion.ID, | 65 | idCotizacion: $scope.remito.cotizacion.ID, |
| 66 | idListaPrecio: parseInt($scope.remito.cliente.mod) || '', | 66 | idListaPrecio: parseInt($scope.remito.cliente.mod) || '', |
| 67 | flete: $scope.remito.flete, | 67 | flete: $scope.remito.flete, |
| 68 | fob: $scope.remito.fob, | 68 | fob: $scope.remito.fob, |
| 69 | bomba: $scope.remito.bomba, | 69 | bomba: $scope.remito.bomba, |
| 70 | kilometros: $scope.remito.kilometros, | 70 | kilometros: $scope.remito.kilometros, |
| 71 | domicilioStamp: $scope.remito.cliente.DOM, | 71 | domicilioStamp: $scope.remito.cliente.DOM, |
| 72 | observaciones: $scope.remito.observaciones, | 72 | observaciones: $scope.remito.observaciones, |
| 73 | numeroRemito: parseInt($scope.nroRemito), | 73 | numeroRemito: parseInt($scope.nroRemito), |
| 74 | sucursal: parseInt($scope.nroSucursal), | 74 | sucursal: parseInt($scope.nroSucursal), |
| 75 | responsabilidadIvaCliente: $scope.remito.cliente.iva, | 75 | responsabilidadIvaCliente: $scope.remito.cliente.iva, |
| 76 | descuento: 0,//TODO, | 76 | descuento: 0,//TODO, |
| 77 | importeNeto: getImporte('netoUnitario'), | 77 | importeNeto: getImporte('netoUnitario'), |
| 78 | importeExento: getImporte('exentoUnitario'), | 78 | importeExento: getImporte('exentoUnitario'), |
| 79 | importeIva: getImporte('ivaUnitario'), | 79 | importeIva: getImporte('ivaUnitario'), |
| 80 | importeIvaServicios: 0,//TODO | 80 | importeIvaServicios: 0,//TODO |
| 81 | importeImpuestoInterno: getImporte('impuestoInternoUnitario'), | 81 | importeImpuestoInterno: getImporte('impuestoInternoUnitario'), |
| 82 | importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'), | 82 | importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'), |
| 83 | importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'), | 83 | importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'), |
| 84 | percepcion: 0,//TODO | 84 | percepcion: 0,//TODO |
| 85 | percepcionIva: 0,//TODO | 85 | percepcionIva: 0,//TODO |
| 86 | redondeo: 0,//TODO | 86 | redondeo: 0,//TODO |
| 87 | anulado: false, | 87 | anulado: false, |
| 88 | planilla: $filter('date')($scope.now, 'ddMMyyyy'), | 88 | planilla: $filter('date')($scope.now, 'ddMMyyyy'), |
| 89 | lugar: parseInt($scope.puntoVenta), | 89 | lugar: parseInt($scope.puntoVenta), |
| 90 | cuentaMadre: 0,//TODO | 90 | cuentaMadre: 0,//TODO |
| 91 | cuentaContable: 0,//TODO | 91 | cuentaContable: 0,//TODO |
| 92 | asiento: 0,//TODO | 92 | asiento: 0,//TODO |
| 93 | e_hd: '',//TODO | 93 | e_hd: '',//TODO |
| 94 | c_hd: '', | 94 | c_hd: '', |
| 95 | numeroLiquidoProducto: 0,//TODO | 95 | numeroLiquidoProducto: 0,//TODO |
| 96 | estado: 0, | 96 | estado: 0, |
| 97 | destinoVenta: 0,//TODO | 97 | destinoVenta: 0,//TODO |
| 98 | operacionTipo: 0, //TODO | 98 | operacionTipo: 0, //TODO |
| 99 | idHojaRuta: $scope.remito.idHojaRuta | 99 | idHojaRuta: $scope.remito.idHojaRuta |
| 100 | } | 100 | } |
| 101 | //#endregion | 101 | //#endregion |
| 102 | focaModalDescargasService.crearRemito({ remito: remito, notaPedido: { id: 0 } }) | 102 | focaModalDescargasService.crearRemito({ remito: remito, notaPedido: { id: 0 } }) |
| 103 | .then(function (res) { | 103 | .then(function (res) { |
| 104 | remitoId = res.data.id | 104 | var remitoId = res.data.id; |
| 105 | descargar(remitoId); | 105 | descargar(remitoId); |
| 106 | focaModalDescargasService. | 106 | focaModalDescargasService. |
| 107 | addArticulos($scope.remito.articulosRemito, $scope.articulos, remitoId, 1); | 107 | addArticulos($scope.remito.articulosRemito, |
| 108 | focaModalService.alert("Descarga realizada") | 108 | $scope.articulos, remitoId, 1); |
| 109 | focaModalService.alert('Descarga realizada') | ||
| 109 | .then(function () { | 110 | .then(function () { |
| 110 | $uibModalInstance.dismiss(); | 111 | $uibModalInstance.dismiss(); |
| 111 | }) | 112 | }) |
| 113 | .catch(function (e) { console.info(e); }); | ||
| 112 | }) | 114 | }) |
| 113 | .catch(function (e) { console.log(e); }) | 115 | .catch(function (e) { console.log(e); }); |
| 114 | 116 | ||
| 115 | }; | 117 | }; |
| 116 | $scope.getTotal = function () { | 118 | $scope.getTotal = function () { |
| 117 | var total = 0; | 119 | var total = 0; |
| 118 | $scope.cisternas.forEach(function (cisterna) { | 120 | $scope.cisternas.forEach(function (cisterna) { |
| 119 | 121 | ||
| 120 | total += cisterna.cisternaCarga.articulo.PreVen * cisterna.cisternaCarga.descargar; | 122 | total += cisterna.cisternaCarga.articulo.PreVen * |
| 123 | cisterna.cisternaCarga.descargar; | ||
| 121 | cisterna.cisternaCarga.articulo.cantidad = cisterna.cisternaCarga.descargar; | 124 | cisterna.cisternaCarga.articulo.cantidad = cisterna.cisternaCarga.descargar; |
| 122 | $scope.articulos.push(cisterna.cisternaCarga.articulo); | 125 | $scope.articulos.push(cisterna.cisternaCarga.articulo); |
| 123 | }); | 126 | }); |
| 124 | return parseFloat(total.toFixed(2)); | 127 | return parseFloat(total.toFixed(2)); |
| 125 | }; | 128 | }; |
| 126 | function descargar(idRemito) { | 129 | function descargar(idRemito) { |
| 127 | 130 | ||
| 128 | for (var i = 0; i < $scope.cisternas.length; i++) { | 131 | for (var i = 0; i < $scope.cisternas.length; i++) { |
| 129 | var descarga = $scope.cisternas[i].cisternaCarga.descargar; | 132 | var descarga = $scope.cisternas[i].cisternaCarga.descargar; |
| 130 | var hojaRutaMovimientos = []; | 133 | var hojaRutaMovimientos = []; |
| 131 | var cisternaMovimientos = []; | 134 | var cisternaMovimientos = []; |
| 132 | var cisternaCargas = []; | 135 | var cisternaCargas = []; |
| 133 | var cisternaCarga = $scope.cisternas[i].cisternaCarga; | 136 | var cisternaCarga = $scope.cisternas[i].cisternaCarga; |
| 134 | if (!descarga) continue; | 137 | if (!descarga) continue; |
| 135 | cisternaCarga.cantidad -= descarga; | 138 | cisternaCarga.cantidad -= descarga; |
| 136 | 139 | ||
| 137 | //Guardar | 140 | //Guardar |
| 138 | var now = new Date(); | 141 | var now = new Date(); |
| 139 | var cisternaMovimiento = { | 142 | var cisternaMovimiento = { |
| 140 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), | 143 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
| 141 | cantidad: descarga, | 144 | cantidad: descarga, |
| 142 | metodo: 'descarga', | 145 | metodo: 'descarga', |
| 143 | idCisternaCarga: cisternaCarga.id, | 146 | idCisternaCarga: cisternaCarga.id, |
| 144 | idRemito: idRemito | 147 | idRemito: idRemito |
| 145 | }; | 148 | }; |
| 146 | var hojaRutaMovimiento = { | 149 | var hojaRutaMovimiento = { |
| 147 | reciboDescarga: $scope.nroRecibo, | 150 | reciboDescarga: $scope.nroRecibo, |
| 148 | idRemito: idRemito | 151 | idRemito: idRemito |
| 149 | }; | 152 | }; |
| 150 | 153 | ||
| 151 | cisternaCarga = angular.copy($scope.cisternas[i].cisternaCarga); | 154 | cisternaCarga = angular.copy($scope.cisternas[i].cisternaCarga); |
| 152 | 155 | ||
| 153 | delete cisternaCarga.articulo; | 156 | delete cisternaCarga.articulo; |
| 154 | delete cisternaCarga.descargar; | 157 | delete cisternaCarga.descargar; |
| 155 | cisternaCargas.push(cisternaCarga); | 158 | cisternaCargas.push(cisternaCarga); |
| 156 | cisternaMovimientos.push(cisternaMovimiento); | 159 | cisternaMovimientos.push(cisternaMovimiento); |
| 157 | hojaRutaMovimientos.push(hojaRutaMovimiento); | 160 | hojaRutaMovimientos.push(hojaRutaMovimiento); |
| 158 | } | 161 | } |
| 159 | var save = { | 162 | var save = { |
| 160 | cisternaCargas: cisternaCargas, | 163 | cisternaCargas: cisternaCargas, |
| 161 | cisternaMovimientos: cisternaMovimientos, | 164 | cisternaMovimientos: cisternaMovimientos, |
| 162 | hojaRutaMovimientos: hojaRutaMovimientos, | 165 | hojaRutaMovimientos: hojaRutaMovimientos, |
| 163 | articulo: $scope.articuloSeleccionado | 166 | articulo: $scope.articuloSeleccionado |
| 164 | }; | 167 | }; |
| 165 | focaModalDetalleHojaRutaService | 168 | focaModalDetalleHojaRutaService |
| 166 | .postMovimientoHojaRuta(save) | 169 | .postMovimientoHojaRuta(save) |
| 167 | .then(guardarSeguimiento) | 170 | .then(guardarSeguimiento) |
| 168 | .catch(function () { }); | 171 | .catch(function () { }); |
| 169 | function guardarSeguimiento(res) { | 172 | function guardarSeguimiento(res) { |
| 170 | focaSeguimientoService | 173 | focaSeguimientoService |
| 171 | .guardarPosicion( | 174 | .guardarPosicion( |
| 172 | 'Entrega de producto', | 175 | 'Entrega de producto', |
| 173 | res.data[0].id, | 176 | res.data[0].id, |
| 174 | ''); | 177 | ''); |
| 175 | $scope.aDescargar = []; | 178 | $scope.aDescargar = []; |
| 176 | }; | 179 | } |
| 177 | }; | 180 | } |
| 178 | function getImporte(propiedad) { | 181 | function getImporte(propiedad) { |
| 179 | var importe = 0; | 182 | var importe = 0; |
| 180 | $scope.remito.articulosRemito.forEach(function (articulo) { | 183 | $scope.remito.articulosRemito.forEach(function (articulo) { |
| 181 | if (articulo[propiedad]) { | 184 | if (articulo[propiedad]) { |
| 182 | importe += articulo[propiedad] * articulo.cantidad; | 185 | importe += articulo[propiedad] * articulo.cantidad; |
| 183 | } | 186 | } |
| 184 | return; | 187 | return; |
| 185 | }); | 188 | }); |
| 186 | return importe; | 189 | return importe; |
| 187 | }; | 190 | } |
| 188 | function validarDescarga() { | 191 | function validarDescarga() { |
| 189 | 192 | ||
| 190 | if ($scope.nroRemito > 99999999) { | 193 | if ($scope.nroRemito > 99999999) { |
| 191 | focaModalService.alert('Numero remito mayor al permitido máximo 8'); | 194 | focaModalService.alert('Numero remito mayor al permitido máximo 8'); |
| 192 | return true; | 195 | return true; |
| 193 | } | 196 | } |
| 194 | 197 | ||
| 195 | if ($scope.nroSucursal > 9999) { | 198 | if ($scope.nroSucursal > 9999) { |
| 196 | focaModalService.alert('Numero sucursal mayor a la permitida máximo 4'); | 199 | focaModalService.alert('Numero sucursal mayor a la permitida máximo 4'); |
| 197 | return true; | 200 | return true; |
| 198 | } | 201 | } |
| 199 | 202 | ||
| 200 | for (var i = 0; i < $scope.cisternas.length; i++) { | 203 | for (var i = 0; i < $scope.cisternas.length; i++) { |
| 201 | if (parseInt($scope.cisternas[i].cisternaCarga.descargar) > | 204 | if (parseInt($scope.cisternas[i].cisternaCarga.descargar) > |
| 202 | $scope.cisternas[i].cisternaCarga.cantidad || | 205 | $scope.cisternas[i].cisternaCarga.cantidad || |
| 203 | parseInt($scope.cisternas[i].cisternaCarga.descargar) < 0) { | 206 | parseInt($scope.cisternas[i].cisternaCarga.descargar) < 0) { |
| 204 | focaModalService.alert("Cantidad de descarga ingresada erronea"); | 207 | focaModalService.alert('Cantidad de descarga ingresada erronea'); |
| 205 | return true; | 208 | return true; |
| 206 | } | 209 | } |
| 207 | } | 210 | } |
| 208 | return false; | 211 | return false; |
| 209 | }; | 212 | } |
| 210 | $scope.seleccionarCliente = function () { | 213 | $scope.seleccionarCliente = function () { |
| 211 | var modalInstance = $uibModal.open( | 214 | var modalInstance = $uibModal.open( |
| 212 | { | 215 | { |
| 213 | ariaLabelledBy: 'Busqueda de Cliente', | 216 | ariaLabelledBy: 'Busqueda de Cliente', |
| 214 | templateUrl: 'foca-busqueda-cliente-modal.html', | 217 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 215 | controller: 'focaBusquedaClienteModalController', | 218 | controller: 'focaBusquedaClienteModalController', |
| 216 | resolve: { | 219 | resolve: { |
| 217 | vendedor: function () { return null; }, | 220 | vendedor: function () { return null; }, |
| 218 | cobrador: function () { return null; } | 221 | cobrador: function () { return null; } |
| 219 | }, | 222 | }, |
| 220 | size: 'lg' | 223 | size: 'lg' |
| 221 | } | 224 | } |
| 222 | ); | 225 | ); |
| 223 | modalInstance.result.then(function (cliente) { | 226 | modalInstance.result.then(function (cliente) { |
| 224 | $scope.remito.cliente = cliente; | 227 | $scope.remito.cliente = cliente; |
| 225 | }, function () { | 228 | }, function () { |
| 226 | //funcion ejecutada al cancelar modal | 229 | //funcion ejecutada al cancelar modal |
| 227 | }); | 230 | }); |
| 228 | }; | 231 | }; |
| 229 | $scope.validateSucursalRemito = function (sucursal, remito) { | 232 | $scope.validateSucursalRemito = function (sucursal, remito) { |
| 230 | if (!sucursal || !remito) { | 233 | if (!sucursal || !remito) { |
| 231 | $scope.hasErrorSucursalRemito = false; | 234 | $scope.hasErrorSucursalRemito = false; |
| 232 | return; | 235 | return; |
| 233 | } | 236 | } |
| 234 | 237 | ||
| 235 | focaModalDescargasService.validarSucursalRemito(sucursal, remito) | 238 | focaModalDescargasService.validarSucursalRemito(sucursal, remito) |
| 236 | .then(function (res) { | 239 | .then(function (res) { |
| 237 | if (res.data.data === 1) { | 240 | if (res.data.data === 1) { |
| 238 | $scope.hasErrorSucursalRemito = true; | 241 | $scope.hasErrorSucursalRemito = true; |
| 239 | } else { | 242 | } else { |
| 240 | $scope.hasErrorSucursalRemito = false; | 243 | $scope.hasErrorSucursalRemito = false; |
| 241 | } | 244 | } |
| 242 | }) | 245 | }) |
| 243 | .catch(function (e) { console.error(e); }); | 246 | .catch(function (e) { console.error(e); }); |
| 244 | }; | 247 | }; |
| 245 | $scope.cancelar = function () { | 248 | $scope.cancelar = function () { |
| 246 | $uibModalInstance.dismiss(); | 249 | $uibModalInstance.dismiss(); |
| 247 | }; | 250 | }; |
| 248 | function rellenar(relleno, longitud) { | ||
| 249 | relleno = '' + relleno; | ||
| 250 | while (relleno.length < longitud) { | ||
| 251 | relleno = '0' + relleno; | ||
| 252 | } | ||
| 253 | return relleno; | ||
| 254 | }; |