Commit f5af55e1d304c16a64d65e7b9aaa3adb17e12e37
1 parent
7c0585b502
Exists in
master
and in
2 other branches
refactor guardar todo de una sola vez
Showing
2 changed files
with
51 additions
and
67 deletions
Show diff stats
src/js/businessService.js
| 1 | angular.module('focaCrearRemito') | 1 | angular.module('focaCrearRemito') |
| 2 | .factory('remitoBusinessService', [ | 2 | .factory('remitoBusinessService', ['crearRemitoService', 'focaModalService', |
| 3 | 'crearRemitoService', | 3 | function(crearRemitoService, focaModalService) { |
| 4 | function(crearRemitoService) { | ||
| 5 | return { | 4 | return { |
| 6 | addArticulos: function(articulosRemito, idRemito, cotizacion) { | 5 | quitarCotizacion: function(articulosRemito, cotizacion) { |
| 6 | |||
| 7 | for(var i = 0; i < articulosRemito.length; i++) { | 7 | for(var i = 0; i < articulosRemito.length; i++) { |
| 8 | |||
| 8 | delete articulosRemito[i].editCantidad; | 9 | delete articulosRemito[i].editCantidad; |
| 9 | delete articulosRemito[i].editPrecio; | 10 | delete articulosRemito[i].editPrecio; |
| 10 | articulosRemito[i].idRemito = articulosRemito[i].idRemito !== -1 ? | ||
| 11 | idRemito : articulosRemito[i].idRemito; | ||
| 12 | articulosRemito[i].precio = articulosRemito[i].precio * cotizacion; | ||
| 13 | delete articulosRemito[i].idNotaPedido; | 11 | delete articulosRemito[i].idNotaPedido; |
| 14 | crearRemitoService.crearArticulosParaRemito(articulosRemito[i]); | 12 | |
| 13 | articulosRemito[i].precio = articulosRemito[i].precio * cotizacion; | ||
| 15 | } | 14 | } |
| 15 | |||
| 16 | return articulosRemito; | ||
| 17 | |||
| 16 | }, | 18 | }, |
| 17 | addEstado: function(idRemito, idVendedor) { | 19 | addEstado: function(idRemito, idVendedor) { |
| 18 | var date = new Date(); | 20 | var date = new Date(); |
| 19 | var estado = { | 21 | var estado = { |
| 20 | idRemito: idRemito, | 22 | idRemito: idRemito, |
| 21 | fecha: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) | 23 | fecha: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) |
| 22 | .toISOString().slice(0, 19).replace('T', ' '), | 24 | .toISOString().slice(0, 19).replace('T', ' '), |
| 23 | estado: 0, | 25 | estado: 0, |
| 24 | idVendedor: idVendedor | 26 | idVendedor: idVendedor |
| 25 | }; | 27 | }; |
| 26 | crearRemitoService.crearEstadoParaRemito(estado); | 28 | crearRemitoService.crearEstadoParaRemito(estado); |
| 27 | }, | 29 | }, |
| 28 | calcularArticulos: function(articulos, cotizacion) { | 30 | calcularArticulos: function(articulos, cotizacion) { |
| 29 | for(var i = 0; i < articulos.length; i++) { | 31 | for(var i = 0; i < articulos.length; i++) { |
| 30 | articulos[i].precio = articulos[i].precio / cotizacion; | 32 | articulos[i].precio = articulos[i].precio / cotizacion; |
| 31 | } | 33 | } |
| 32 | }, | 34 | }, |
| 33 | plazoToString: function(plazos) { | 35 | plazoToString: function(plazos) { |
| 34 | var result = ''; | 36 | var result = ''; |
| 35 | for(var i = 0; i < plazos.length; i++) { | 37 | for(var i = 0; i < plazos.length; i++) { |
| 36 | result += plazos[i].dias + ' '; | 38 | result += plazos[i].dias + ' '; |
| 37 | } | 39 | } |
| 38 | return result.trim(); | 40 | return result.trim(); |
| 39 | }, | 41 | }, |
| 40 | addPuntosDescarga: function(idRemito, puntosDescarga) { | 42 | addPuntosDescarga: function(puntosDescarga) { |
| 41 | 43 | ||
| 42 | var puntos = []; | 44 | var puntos = []; |
| 43 | 45 | ||
| 44 | puntosDescarga.forEach(function(punto) { | 46 | puntosDescarga.forEach(function(punto) { |
| 45 | puntos.push({ | 47 | puntos.push({ |
| 46 | idPuntoDescarga: punto.puntoDescarga.id, | 48 | idPuntoDescarga: punto.puntoDescarga.id, |
| 47 | idRemito: idRemito, | ||
| 48 | }); | 49 | }); |
| 49 | }); | 50 | }); |
| 50 | 51 | ||
| 51 | return crearRemitoService.crearPuntosDescarga(puntos); | 52 | return puntos; |
| 53 | }, | ||
| 54 | validarRemito: function (remito, articulos) { | ||
| 55 | |||
| 56 | if (!remito.vendedor.NUM) { | ||
| 57 | focaModalService.alert('Ingrese Vendedor'); | ||
| 58 | return false; | ||
| 59 | } else if (!remito.cliente.COD) { | ||
| 60 | focaModalService.alert('Ingrese Cliente'); | ||
| 61 | return false; | ||
| 62 | } else if (!remito.proveedor.COD) { | ||
| 63 | focaModalService.alert('Ingrese Proveedor'); | ||
| 64 | return false; | ||
| 65 | } else if (!remito.cotizacion.moneda.id && | ||
| 66 | !remito.cotizacion.moneda.ID) { | ||
| 67 | focaModalService.alert('Ingrese Moneda'); | ||
| 68 | return false; | ||
| 69 | } else if (!remito.cotizacion.ID) { | ||
| 70 | focaModalService.alert('Ingrese Cotización'); | ||
| 71 | return false; | ||
| 72 | } else if (remito.flete === undefined || remito.flete === null) { | ||
| 73 | focaModalService.alert('Ingrese Flete'); | ||
| 74 | return false; | ||
| 75 | } else if (articulos.length === 0) { | ||
| 76 | focaModalService.alert('Debe cargar al menos un articulo'); | ||
| 77 | return false; | ||
| 78 | } | ||
| 79 |
src/js/controller.js
| 1 | angular.module('focaCrearRemito').controller('remitoController', | 1 | angular.module('focaCrearRemito').controller('remitoController', |
| 2 | [ | 2 | [ |
| 3 | '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout', | 3 | '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout', |
| 4 | 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService', | 4 | 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService', |
| 5 | '$localStorage', | 5 | '$localStorage', |
| 6 | function ( | 6 | function ( |
| 7 | $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService, | 7 | $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService, |
| 8 | remitoBusinessService, $rootScope, focaBotoneraLateralService, $localStorage) { | 8 | remitoBusinessService, $rootScope, focaBotoneraLateralService, $localStorage) { |
| 9 | config(); | 9 | config(); |
| 10 | 10 | ||
| 11 | var cotizacionPArgentino = {}; | 11 | var cotizacionPArgentino = {}; |
| 12 | 12 | ||
| 13 | function config() { | 13 | function config() { |
| 14 | $scope.tmpCantidad = Number; | 14 | $scope.tmpCantidad = Number; |
| 15 | $scope.tmpPrecio = Number; | 15 | $scope.tmpPrecio = Number; |
| 16 | $scope.botonera = crearRemitoService.getBotonera(); | 16 | $scope.botonera = crearRemitoService.getBotonera(); |
| 17 | $scope.isNumber = angular.isNumber; | 17 | $scope.isNumber = angular.isNumber; |
| 18 | $scope.datepickerAbierto = false; | 18 | $scope.datepickerAbierto = false; |
| 19 | $scope.show = false; | 19 | $scope.show = false; |
| 20 | $scope.cargando = true; | 20 | $scope.cargando = true; |
| 21 | $scope.now = new Date(); | 21 | $scope.now = new Date(); |
| 22 | $scope.puntoVenta = rellenar(0, 4); | 22 | $scope.puntoVenta = rellenar(0, 4); |
| 23 | $scope.comprobante = rellenar(0, 8); | 23 | $scope.comprobante = rellenar(0, 8); |
| 24 | $scope.dateOptions = { | 24 | $scope.dateOptions = { |
| 25 | maxDate: new Date(), | 25 | maxDate: new Date(), |
| 26 | minDate: new Date(2010, 0, 1) | 26 | minDate: new Date(2010, 0, 1) |
| 27 | }; | 27 | }; |
| 28 | $scope.cabeceras = []; | 28 | $scope.cabeceras = []; |
| 29 | crearRemitoService.getParametros().then(function (res) { | 29 | crearRemitoService.getParametros().then(function (res) { |
| 30 | var parametros = JSON.parse(res.data[0].jsonText); | 30 | var parametros = JSON.parse(res.data[0].jsonText); |
| 31 | if ($localStorage.remito) { | 31 | if ($localStorage.remito) { |
| 32 | $timeout(function () { getLSRemito(); }); | 32 | $timeout(function () { getLSRemito(); }); |
| 33 | } else { | 33 | } else { |
| 34 | for (var property in parametros) { | 34 | for (var property in parametros) { |
| 35 | $scope.remito[property] = parametros[property]; | 35 | $scope.remito[property] = parametros[property]; |
| 36 | $scope.inicial[property] = parametros[property]; | 36 | $scope.inicial[property] = parametros[property]; |
| 37 | } | 37 | } |
| 38 | setearRemito($scope.remito); | 38 | setearRemito($scope.remito); |
| 39 | } | 39 | } |
| 40 | }); | 40 | }); |
| 41 | 41 | ||
| 42 | //SETEO BOTONERA LATERAL | 42 | //SETEO BOTONERA LATERAL |
| 43 | $timeout(function () { | 43 | $timeout(function () { |
| 44 | focaBotoneraLateralService.showSalir(false); | 44 | focaBotoneraLateralService.showSalir(false); |
| 45 | focaBotoneraLateralService.showPausar(true); | 45 | focaBotoneraLateralService.showPausar(true); |
| 46 | focaBotoneraLateralService.showGuardar(true, $scope.crearRemito); | 46 | focaBotoneraLateralService.showGuardar(true, $scope.crearRemito); |
| 47 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 47 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 48 | }); | 48 | }); |
| 49 | 49 | ||
| 50 | init(); | 50 | init(); |
| 51 | 51 | ||
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | function init() { | 54 | function init() { |
| 55 | $scope.$broadcast('cleanCabecera'); | 55 | $scope.$broadcast('cleanCabecera'); |
| 56 | $scope.remito = { | 56 | $scope.remito = { |
| 57 | id: 0, | 57 | id: 0, |
| 58 | estado: 0, | 58 | estado: 0, |
| 59 | vendedor: {}, | 59 | vendedor: {}, |
| 60 | cliente: {}, | 60 | cliente: {}, |
| 61 | proveedor: {}, | 61 | proveedor: {}, |
| 62 | domicilio: { dom: '' }, | 62 | domicilio: { dom: '' }, |
| 63 | moneda: {}, | 63 | moneda: {}, |
| 64 | cotizacion: $scope.cotizacionPorDefecto || {}, | 64 | cotizacion: $scope.cotizacionPorDefecto || {}, |
| 65 | articulosRemito: [], | 65 | articulosRemito: [], |
| 66 | remitoPuntoDescarga: [] | 66 | remitoPuntoDescarga: [] |
| 67 | }; | 67 | }; |
| 68 | $scope.notaPedido = { | 68 | $scope.notaPedido = { |
| 69 | id: 0 | 69 | id: 0 |
| 70 | }; | 70 | }; |
| 71 | 71 | ||
| 72 | $scope.remito.articulosRemito = []; | 72 | $scope.remito.articulosRemito = []; |
| 73 | $scope.idLista = undefined; | 73 | $scope.idLista = undefined; |
| 74 | 74 | ||
| 75 | crearRemitoService.getNumeroRemito().then( | 75 | crearRemitoService.getNumeroRemito().then( |
| 76 | function (res) { | 76 | function (res) { |
| 77 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 77 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
| 78 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); | 78 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); |
| 79 | }, | 79 | }, |
| 80 | function (err) { | 80 | function (err) { |
| 81 | focaModalService.alert('La terminal no esta configurada correctamente'); | 81 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 82 | console.info(err); | 82 | console.info(err); |
| 83 | } | 83 | } |
| 84 | ); | 84 | ); |
| 85 | 85 | ||
| 86 | $scope.inicial = angular.copy($scope.remito); | 86 | $scope.inicial = angular.copy($scope.remito); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | $scope.$watch('remito', function (newValue) { | 89 | $scope.$watch('remito', function (newValue) { |
| 90 | focaBotoneraLateralService.setPausarData({ | 90 | focaBotoneraLateralService.setPausarData({ |
| 91 | label: 'remito', | 91 | label: 'remito', |
| 92 | val: newValue | 92 | val: newValue |
| 93 | }); | 93 | }); |
| 94 | }, true); | 94 | }, true); |
| 95 | 95 | ||
| 96 | $scope.seleccionarNotaPedido = function () { | 96 | $scope.seleccionarNotaPedido = function () { |
| 97 | if ($scope.remitoIsDirty) { | 97 | if ($scope.remitoIsDirty) { |
| 98 | focaModalService.confirm('¿Desea continuar? Se perderan los cambios') | 98 | focaModalService.confirm('¿Desea continuar? Se perderan los cambios') |
| 99 | .then(function () { | 99 | .then(function () { |
| 100 | $scope.getNotaPedidoModal(); | 100 | $scope.getNotaPedidoModal(); |
| 101 | }); | 101 | }); |
| 102 | } else { | 102 | } else { |
| 103 | $scope.getNotaPedidoModal(); | 103 | $scope.getNotaPedidoModal(); |
| 104 | } | 104 | } |
| 105 | }; | 105 | }; |
| 106 | 106 | ||
| 107 | $scope.getNotaPedidoModal = function () { | 107 | $scope.getNotaPedidoModal = function () { |
| 108 | if (!varlidarRemitoFacturado()) return; | 108 | if (!varlidarRemitoFacturado()) return; |
| 109 | if (!varlidarRemitoAbierto()) return; | 109 | if (!varlidarRemitoAbierto()) return; |
| 110 | var modalInstance = $uibModal.open( | 110 | var modalInstance = $uibModal.open( |
| 111 | { | 111 | { |
| 112 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 112 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
| 113 | templateUrl: 'foca-modal-nota-pedido.html', | 113 | templateUrl: 'foca-modal-nota-pedido.html', |
| 114 | controller: 'focaModalNotaPedidoController', | 114 | controller: 'focaModalNotaPedidoController', |
| 115 | size: 'lg', | 115 | size: 'lg', |
| 116 | resolve: { | 116 | resolve: { |
| 117 | usadoPor: function () { return 'remito'; }, | 117 | usadoPor: function () { return 'remito'; }, |
| 118 | idVendedor: function () { return null; } | 118 | idVendedor: function () { return null; } |
| 119 | } | 119 | } |
| 120 | } | 120 | } |
| 121 | ); | 121 | ); |
| 122 | modalInstance.result.then( | 122 | modalInstance.result.then( |
| 123 | function (notaPedido) { | 123 | function (notaPedido) { |
| 124 | //añado cabeceras | 124 | //añado cabeceras |
| 125 | $scope.remitoIsDirty = true; | 125 | $scope.remitoIsDirty = true; |
| 126 | $scope.notaPedido = notaPedido; | 126 | $scope.notaPedido = notaPedido; |
| 127 | $scope.remito.cliente = notaPedido.cliente; | 127 | $scope.remito.cliente = notaPedido.cliente; |
| 128 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 128 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 129 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 129 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 130 | var puntosDescarga = []; | 130 | var puntosDescarga = []; |
| 131 | notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedido) { | 131 | notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedido) { |
| 132 | puntosDescarga.push(notaPedido.puntoDescarga); | 132 | puntosDescarga.push(notaPedido.puntoDescarga); |
| 133 | }); | 133 | }); |
| 134 | $scope.cabeceras = [ | 134 | $scope.cabeceras = [ |
| 135 | { | 135 | { |
| 136 | label: 'Cliente:', | 136 | label: 'Cliente:', |
| 137 | valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) + | 137 | valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) + |
| 138 | ' - ' + notaPedido.cliente.NOM | 138 | ' - ' + notaPedido.cliente.NOM |
| 139 | }, | 139 | }, |
| 140 | { | 140 | { |
| 141 | label: 'Domicilio:', | 141 | label: 'Domicilio:', |
| 142 | valor: notaPedido.domicilioStamp | 142 | valor: notaPedido.domicilioStamp |
| 143 | }, | 143 | }, |
| 144 | { | 144 | { |
| 145 | label: 'Vendedor:', | 145 | label: 'Vendedor:', |
| 146 | valor: $filter('rellenarDigitos')( | 146 | valor: $filter('rellenarDigitos')( |
| 147 | notaPedido.vendedor.NUM, 3 | 147 | notaPedido.vendedor.NUM, 3 |
| 148 | ) + ' - ' + notaPedido.vendedor.NOM | 148 | ) + ' - ' + notaPedido.vendedor.NOM |
| 149 | }, | 149 | }, |
| 150 | 150 | ||
| 151 | { | 151 | { |
| 152 | label: 'Proveedor:', | 152 | label: 'Proveedor:', |
| 153 | valor: $filter('rellenarDigitos') | 153 | valor: $filter('rellenarDigitos') |
| 154 | (notaPedido.proveedor.COD, 5) + ' - ' + | 154 | (notaPedido.proveedor.COD, 5) + ' - ' + |
| 155 | notaPedido.proveedor.NOM | 155 | notaPedido.proveedor.NOM |
| 156 | }, | 156 | }, |
| 157 | 157 | ||
| 158 | { | 158 | { |
| 159 | label: 'Flete:', | 159 | label: 'Flete:', |
| 160 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 160 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
| 161 | notaPedido.flete === 1 ? 'Si' : 'No') | 161 | notaPedido.flete === 1 ? 'Si' : 'No') |
| 162 | }, | 162 | }, |
| 163 | { | 163 | { |
| 164 | label: 'Puntos de descarga: ', | 164 | label: 'Puntos de descarga: ', |
| 165 | valor: $filter('rellenarDigitos')( | 165 | valor: $filter('rellenarDigitos')( |
| 166 | getCabeceraPuntoDescarga(puntosDescarga)) | 166 | getCabeceraPuntoDescarga(puntosDescarga)) |
| 167 | } | 167 | } |
| 168 | ]; | 168 | ]; |
| 169 | actualizarCabeceraMoneda(notaPedido.cotizacion); | 169 | actualizarCabeceraMoneda(notaPedido.cotizacion); |
| 170 | valorPrecioCondicion(); | 170 | valorPrecioCondicion(); |
| 171 | // Seteo checked en cabeceras | 171 | // Seteo checked en cabeceras |
| 172 | $filter('filter')($scope.botonera, | 172 | $filter('filter')($scope.botonera, |
| 173 | { label: 'Cliente' })[0].checked = true; | 173 | { label: 'Cliente' })[0].checked = true; |
| 174 | $filter('filter')($scope.botonera, | 174 | $filter('filter')($scope.botonera, |
| 175 | { label: 'Proveedor' })[0].checked = true; | 175 | { label: 'Proveedor' })[0].checked = true; |
| 176 | $filter('filter')($scope.botonera, | 176 | $filter('filter')($scope.botonera, |
| 177 | { label: 'Moneda' })[0].checked = true; | 177 | { label: 'Moneda' })[0].checked = true; |
| 178 | $filter('filter')($scope.botonera, | 178 | $filter('filter')($scope.botonera, |
| 179 | { label: 'Nota pedido' })[0].checked = true; | 179 | { label: 'Nota pedido' })[0].checked = true; |
| 180 | $filter('filter')($scope.botonera, | 180 | $filter('filter')($scope.botonera, |
| 181 | { label: 'Precios y condiciones' })[0].checked = true; | 181 | { label: 'Precios y condiciones' })[0].checked = true; |
| 182 | $filter('filter')($scope.botonera, | 182 | $filter('filter')($scope.botonera, |
| 183 | { label: 'Domicilio de Entrega' })[0].checked = true; | 183 | { label: 'Domicilio de Entrega' })[0].checked = true; |
| 184 | 184 | ||
| 185 | if (notaPedido.observaciones) { | 185 | if (notaPedido.observaciones) { |
| 186 | $filter('filter')($scope.botonera, | 186 | $filter('filter')($scope.botonera, |
| 187 | { label: 'Observaciones' })[0].checked = true; | 187 | { label: 'Observaciones' })[0].checked = true; |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | function valorPrecioCondicion() { | 190 | function valorPrecioCondicion() { |
| 191 | if (parseInt(notaPedido.idListaPrecio) > 0) { | 191 | if (parseInt(notaPedido.idListaPrecio) > 0) { |
| 192 | crearRemitoService | 192 | crearRemitoService |
| 193 | .getListaPrecioById(parseInt(notaPedido.idListaPrecio)) | 193 | .getListaPrecioById(parseInt(notaPedido.idListaPrecio)) |
| 194 | .then(function (res) { | 194 | .then(function (res) { |
| 195 | $scope.cabeceras.push({ | 195 | $scope.cabeceras.push({ |
| 196 | label: 'Precios y Condiciones:', | 196 | label: 'Precios y Condiciones:', |
| 197 | valor: | 197 | valor: |
| 198 | parseInt(res.data[0].ID) + ' - ' + | 198 | parseInt(res.data[0].ID) + ' - ' + |
| 199 | res.data[0].DES + ' ' + | 199 | res.data[0].DES + ' ' + |
| 200 | remitoBusinessService | 200 | remitoBusinessService |
| 201 | .plazoToString(notaPedido.notaPedidoPlazo) | 201 | .plazoToString(notaPedido.notaPedidoPlazo) |
| 202 | }); | 202 | }); |
| 203 | addArrayCabecera($scope.cabeceras); | 203 | addArrayCabecera($scope.cabeceras); |
| 204 | }); | 204 | }); |
| 205 | } | 205 | } |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | if (notaPedido.flete === 1) { | 208 | if (notaPedido.flete === 1) { |
| 209 | var cabeceraBomba = { | 209 | var cabeceraBomba = { |
| 210 | label: 'Bomba:', | 210 | label: 'Bomba:', |
| 211 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 211 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
| 212 | }; | 212 | }; |
| 213 | if (notaPedido.kilometros) { | 213 | if (notaPedido.kilometros) { |
| 214 | var cabeceraKilometros = { | 214 | var cabeceraKilometros = { |
| 215 | label: 'Kilometros:', | 215 | label: 'Kilometros:', |
| 216 | valor: notaPedido.kilometros | 216 | valor: notaPedido.kilometros |
| 217 | }; | 217 | }; |
| 218 | $scope.cabeceras.push(cabeceraKilometros); | 218 | $scope.cabeceras.push(cabeceraKilometros); |
| 219 | } | 219 | } |
| 220 | $scope.cabeceras.push(cabeceraBomba); | 220 | $scope.cabeceras.push(cabeceraBomba); |
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | $scope.remito = angular.copy(notaPedido); | 223 | $scope.remito = angular.copy(notaPedido); |
| 224 | $scope.remito.id = 0; | 224 | $scope.remito.id = 0; |
| 225 | $scope.remito.remitoPlazo = notaPedido.notaPedidoPlazo; | 225 | $scope.remito.remitoPlazo = notaPedido.notaPedidoPlazo; |
| 226 | $scope.remito.remitoPuntoDescarga = notaPedido.notaPedidoPuntoDescarga; | 226 | $scope.remito.remitoPuntoDescarga = notaPedido.notaPedidoPuntoDescarga; |
| 227 | 227 | ||
| 228 | notaPedido.articulosNotaPedido.forEach(function (articulo) { | 228 | notaPedido.articulosNotaPedido.forEach(function (articulo) { |
| 229 | articulo.id = 0; | 229 | articulo.id = 0; |
| 230 | articulo.idRemito = 0; | 230 | articulo.idRemito = 0; |
| 231 | articulo.precio = | 231 | articulo.precio = |
| 232 | (articulo.precio / notaPedido.cotizacion.VENDEDOR).toFixed(4); | 232 | (articulo.precio / notaPedido.cotizacion.VENDEDOR).toFixed(4); |
| 233 | }); | 233 | }); |
| 234 | 234 | ||
| 235 | $scope.remito.articulosRemito = notaPedido.articulosNotaPedido; | 235 | $scope.remito.articulosRemito = notaPedido.articulosNotaPedido; |
| 236 | 236 | ||
| 237 | if (notaPedido.idPrecioCondicion > 0) { | 237 | if (notaPedido.idPrecioCondicion > 0) { |
| 238 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 238 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
| 239 | } else { | 239 | } else { |
| 240 | $scope.idLista = -1; | 240 | $scope.idLista = -1; |
| 241 | } | 241 | } |
| 242 | 242 | ||
| 243 | enableObservaciones(notaPedido.observaciones ? true : false); | 243 | enableObservaciones(notaPedido.observaciones ? true : false); |
| 244 | addArrayCabecera($scope.cabeceras); | 244 | addArrayCabecera($scope.cabeceras); |
| 245 | 245 | ||
| 246 | }, function () { | 246 | }, function () { |
| 247 | // funcion ejecutada cuando se cancela el modal | 247 | // funcion ejecutada cuando se cancela el modal |
| 248 | } | 248 | } |
| 249 | ); | 249 | ); |
| 250 | }; | 250 | }; |
| 251 | 251 | ||
| 252 | $scope.seleccionarRemito = function () { | 252 | $scope.seleccionarRemito = function () { |
| 253 | if ($scope.remitoIsDirty) { | 253 | if ($scope.remitoIsDirty) { |
| 254 | focaModalService.confirm('¿Desea continuar? Se perderan los cambios') | 254 | focaModalService.confirm('¿Desea continuar? Se perderan los cambios') |
| 255 | .then(function () { | 255 | .then(function () { |
| 256 | $scope.getRemitoModal(); | 256 | $scope.getRemitoModal(); |
| 257 | }); | 257 | }); |
| 258 | } else { | 258 | } else { |
| 259 | $scope.getRemitoModal(); | 259 | $scope.getRemitoModal(); |
| 260 | } | 260 | } |
| 261 | }; | 261 | }; |
| 262 | $scope.getRemitoModal = function () { | 262 | $scope.getRemitoModal = function () { |
| 263 | var modalInstance = $uibModal.open( | 263 | var modalInstance = $uibModal.open( |
| 264 | { | 264 | { |
| 265 | ariaLabelledBy: 'Busqueda de Remito', | 265 | ariaLabelledBy: 'Busqueda de Remito', |
| 266 | templateUrl: 'foca-modal-remito.html', | 266 | templateUrl: 'foca-modal-remito.html', |
| 267 | controller: 'focaModalRemitoController', | 267 | controller: 'focaModalRemitoController', |
| 268 | size: 'lg', | 268 | size: 'lg', |
| 269 | resolve: { usadoPor: function () { return 'remito'; } } | 269 | resolve: { usadoPor: function () { return 'remito'; } } |
| 270 | } | 270 | } |
| 271 | ); | 271 | ); |
| 272 | modalInstance.result.then(function (remito) { | 272 | modalInstance.result.then(function (remito) { |
| 273 | 273 | ||
| 274 | remito.articulosRemito.forEach(function (articulo) { | 274 | remito.articulosRemito.forEach(function (articulo) { |
| 275 | articulo.precio = | 275 | articulo.precio = |
| 276 | (articulo.precio / remito.cotizacion.VENDEDOR).toFixed(4); | 276 | (articulo.precio / remito.cotizacion.VENDEDOR).toFixed(4); |
| 277 | }); | 277 | }); |
| 278 | 278 | ||
| 279 | setearRemito(remito); | 279 | setearRemito(remito); |
| 280 | 280 | ||
| 281 | }, function () { | 281 | }, function () { |
| 282 | // funcion ejecutada cuando se cancela el modal | 282 | // funcion ejecutada cuando se cancela el modal |
| 283 | } | 283 | } |
| 284 | ); | 284 | ); |
| 285 | }; | 285 | }; |
| 286 | //validacion por domicilio y por plazo pago | 286 | //validacion por domicilio y por plazo pago |
| 287 | $scope.crearRemito = function () { | 287 | $scope.crearRemito = function () { |
| 288 | if (!$scope.remito.vendedor.NUM) { | 288 | |
| 289 | focaModalService.alert('Ingrese Vendedor'); | 289 | if (!remitoBusinessService.validarRemito($scope.remito, $scope.articulosFiltro())) |
| 290 | return; | 290 | { |
| 291 | } else if (!$scope.remito.cliente.COD) { | ||
| 292 | focaModalService.alert('Ingrese Cliente'); | ||
| 293 | return; | ||
| 294 | } else if (!$scope.remito.proveedor.COD) { | ||
| 295 | focaModalService.alert('Ingrese Proveedor'); | ||
| 296 | return; | ||
| 297 | } else if (!$scope.remito.cotizacion.moneda.id && | ||
| 298 | !$scope.remito.cotizacion.moneda.ID) { | ||
| 299 | focaModalService.alert('Ingrese Moneda'); | ||
| 300 | return; | ||
| 301 | } else if (!$scope.remito.cotizacion.ID) { | ||
| 302 | focaModalService.alert('Ingrese Cotización'); | ||
| 303 | return; | ||
| 304 | } else if ($scope.remito.flete === undefined || $scope.remito.flete === null) { | ||
| 305 | focaModalService.alert('Ingrese Flete'); | ||
| 306 | return; | ||
| 307 | } else if ($scope.articulosFiltro().length === 0) { | ||
| 308 | focaModalService.alert('Debe cargar al menos un articulo'); | ||
| 309 | return; | 291 | return; |
| 310 | } | 292 | } |
| 311 | 293 | ||
| 312 | focaBotoneraLateralService.startGuardar(); | 294 | focaBotoneraLateralService.startGuardar(); |
| 313 | $scope.saveLoading = true; | 295 | $scope.saveLoading = true; |
| 314 | var save = { | 296 | var save = { |
| 315 | remito: { | 297 | remito: { |
| 316 | id: $scope.remito.id, | 298 | id: $scope.remito.id, |
| 317 | fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), | 299 | fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), |
| 318 | idCliente: $scope.remito.cliente.COD, | 300 | idCliente: $scope.remito.cliente.COD, |
| 319 | nombreCliente: $scope.remito.cliente.NOM, | 301 | nombreCliente: $scope.remito.cliente.NOM, |
| 320 | cuitCliente: $scope.remito.cliente.CUIT, | 302 | cuitCliente: $scope.remito.cliente.CUIT, |
| 321 | total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR, | 303 | total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR, |
| 322 | numeroNotaPedido: $scope.remito.numeroNotaPedido, | 304 | numeroNotaPedido: $scope.remito.numeroNotaPedido, |
| 323 | idVendedor: parseInt($scope.remito.cliente.VEN), | 305 | idVendedor: parseInt($scope.remito.cliente.VEN), |
| 324 | idProveedor: $scope.remito.proveedor.COD, | 306 | idProveedor: $scope.remito.proveedor.COD, |
| 325 | idDomicilio: $scope.remito.idDomicilio || $scope.remito.domicilio.id, | 307 | idDomicilio: $scope.remito.idDomicilio || $scope.remito.domicilio.id, |
| 326 | idCotizacion: $scope.remito.cotizacion.ID, | 308 | idCotizacion: $scope.remito.cotizacion.ID, |
| 327 | idListaPrecio: $scope.idLista, | 309 | idListaPrecio: $scope.idLista, |
| 328 | flete: $scope.remito.flete, | 310 | flete: $scope.remito.flete, |
| 329 | fob: $scope.remito.fob, | 311 | fob: $scope.remito.fob, |
| 330 | bomba: $scope.remito.bomba, | 312 | bomba: $scope.remito.bomba, |
| 331 | kilometros: $scope.remito.kilometros, | 313 | kilometros: $scope.remito.kilometros, |
| 332 | domicilioStamp: $scope.remito.domicilioStamp, | 314 | domicilioStamp: $scope.remito.domicilioStamp, |
| 333 | observaciones: $scope.remito.observaciones, | 315 | observaciones: $scope.remito.observaciones, |
| 334 | numeroRemito: parseInt($scope.comprobante), | 316 | numeroRemito: parseInt($scope.comprobante), |
| 335 | sucursal: parseInt($scope.puntoVenta), | 317 | sucursal: parseInt($scope.puntoVenta), |
| 336 | responsabilidadIvaCliente: $scope.remito.cliente.IVA, | 318 | responsabilidadIvaCliente: $scope.remito.cliente.IVA, |
| 337 | descuento: 0,//TODO, | 319 | descuento: 0,//TODO, |
| 338 | importeNeto: getImporte('netoUnitario'), | 320 | importeNeto: getImporte('netoUnitario'), |
| 339 | importeExento: getImporte('exentoUnitario'), | 321 | importeExento: getImporte('exentoUnitario'), |
| 340 | importeIva: getImporte('ivaUnitario'), | 322 | importeIva: getImporte('ivaUnitario'), |
| 341 | importeIvaServicios: 0,//TODO | 323 | importeIvaServicios: 0,//TODO |
| 342 | importeImpuestoInterno: getImporte('impuestoInternoUnitario'), | 324 | importeImpuestoInterno: getImporte('impuestoInternoUnitario'), |
| 343 | importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'), | 325 | importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'), |
| 344 | importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'), | 326 | importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'), |
| 345 | percepcion: 0,//TODO | 327 | percepcion: 0,//TODO |
| 346 | percepcionIva: 0,//TODO | 328 | percepcionIva: 0,//TODO |
| 347 | redondeo: 0,//TODO | 329 | redondeo: 0,//TODO |
| 348 | anulado: false, | 330 | anulado: false, |
| 349 | planilla: $filter('date')($scope.now, 'ddMMyyyy'), | 331 | planilla: $filter('date')($scope.now, 'ddMMyyyy'), |
| 350 | lugar: parseInt($scope.puntoVenta), | 332 | lugar: parseInt($scope.puntoVenta), |
| 351 | cuentaMadre: 0,//TODO | 333 | cuentaMadre: 0,//TODO |
| 352 | cuentaContable: 0,//TODO | 334 | cuentaContable: 0,//TODO |
| 353 | asiento: 0,//TODO | 335 | asiento: 0,//TODO |
| 354 | e_hd: '',//TODO | 336 | e_hd: '',//TODO |
| 355 | c_hd: '', | 337 | c_hd: '', |
| 356 | numeroLiquidoProducto: 0,//TODO | 338 | numeroLiquidoProducto: 0,//TODO |
| 357 | estado: $scope.remito.estado, | 339 | estado: $scope.remito.estado, |
| 358 | destinoVenta: 0,//TODO | 340 | destinoVenta: 0,//TODO |
| 359 | operacionTipo: 0, //TODO | 341 | operacionTipo: 0, //TODO |
| 360 | }, | 342 | }, |
| 361 | notaPedido: $scope.notaPedido | 343 | notaPedido: $scope.notaPedido, |
| 344 | articulos: remitoBusinessService.quitarCotizacion($scope.articulosFiltro(), | ||
| 345 | $scope.remito.cotizacion.VENDEDOR), | ||
| 346 | puntosDescarga: remitoBusinessService.addPuntosDescarga( | ||
| 347 | $scope.remito.remitoPuntoDescarga), | ||
| 348 | plazos: $scope.remito.remitoPlazo | ||
| 362 | }; | 349 | }; |
| 363 | crearRemitoService.crearRemito(save).then( | 350 | crearRemitoService.crearRemito(save).then( |
| 364 | function (data) { | 351 | function (data) { |
| 365 | 352 | ||
| 366 | focaBotoneraLateralService.endGuardar(true); | 353 | focaBotoneraLateralService.endGuardar(true); |
| 367 | $scope.saveLoading = false; | 354 | $scope.saveLoading = false; |
| 368 | 355 | ||
| 369 | $scope.remito.numeroRemito = data.data.numero; | ||
| 370 | |||
| 371 | if ($scope.remito.remitoPuntoDescarga.length > 0) { | ||
| 372 | remitoBusinessService.addPuntosDescarga(data.data.id, | ||
| 373 | $scope.remito.remitoPuntoDescarga); | ||
| 374 | } | ||
| 375 | |||
| 376 | if (data.status === 500) { | 356 | if (data.status === 500) { |
| 377 | focaModalService.alert(data.data); | 357 | focaModalService.alert(data.data); |
| 378 | return; | 358 | return; |
| 379 | } | 359 | } |
| 380 | 360 | ||
| 381 | // TODO: updatear plazos | ||
| 382 | if ($scope.remito.id === 0) { | ||
| 383 | |||
| 384 | remitoBusinessService.addArticulos($scope.remito.articulosRemito, | ||
| 385 | data.data.id, $scope.remito.cotizacion.VENDEDOR); | ||
| 386 | |||
| 387 | var plazos = $scope.remito.remitoPlazo; | ||
| 388 | |||
| 389 | for (var j = 0; j < plazos.length; j++) { | ||
| 390 | var json = { | ||
| 391 | idRemito: data.data.id, | ||
| 392 | dias: plazos[j].dias | ||
| 393 | }; | ||
| 394 | crearRemitoService.crearPlazosParaRemito(json); | ||
| 395 | } | ||
| 396 | } | ||
| 397 | abrirModalMail(data.data.id, | 361 | abrirModalMail(data.data.id, |
| 398 | $scope.remito.cliente, | 362 | $scope.remito.cliente, |
| 399 | $filter('comprobante')([ | 363 | $filter('comprobante')([ |
| 400 | $scope.puntoVenta, | 364 | $scope.puntoVenta, |
| 401 | $scope.remito.numeroRemito | 365 | data.data.numero |
| 402 | ]) | 366 | ]) |
| 403 | ); | 367 | ); |
| 404 | 368 | ||
| 405 | config(); | 369 | config(); |
| 406 | 370 | ||
| 407 | }, function (error) { | 371 | }, function (error) { |
| 408 | focaModalService.alert(error.data || 'Hubo un error al crear el remito'); | 372 | focaModalService.alert(error.data || 'Hubo un error al crear el remito'); |
| 409 | focaBotoneraLateralService.endGuardar(); | 373 | focaBotoneraLateralService.endGuardar(); |
| 410 | $scope.saveLoading = false; | 374 | $scope.saveLoading = false; |
| 411 | console.info(error); | 375 | console.info(error); |
| 412 | } | 376 | } |
| 413 | ); | 377 | ); |
| 414 | }; | 378 | }; |
| 415 | 379 | ||
| 416 | $scope.seleccionarProductos = function () { | 380 | $scope.seleccionarProductos = function () { |
| 417 | if (!varlidarRemitoFacturado()) return; | 381 | if (!varlidarRemitoFacturado()) return; |
| 418 | if (!varlidarRemitoAbierto()) return; | 382 | if (!varlidarRemitoAbierto()) return; |
| 419 | if ($scope.notaPedido.id !== 0) { | 383 | if ($scope.notaPedido.id !== 0) { |
| 420 | $scope.idLista = parseInt($scope.notaPedido.idListaPrecio); | 384 | $scope.idLista = parseInt($scope.notaPedido.idListaPrecio); |
| 421 | } | 385 | } |
| 422 | if ($scope.idLista === undefined) { | 386 | if ($scope.idLista === undefined) { |
| 423 | focaModalService.alert( | 387 | focaModalService.alert( |
| 424 | 'Primero seleccione una lista de precio y condicion'); | 388 | 'Primero seleccione una lista de precio y condicion'); |
| 425 | return; | 389 | return; |
| 426 | } | 390 | } |
| 427 | var modalInstance = $uibModal.open( | 391 | var modalInstance = $uibModal.open( |
| 428 | { | 392 | { |
| 429 | ariaLabelledBy: 'Busqueda de Productos', | 393 | ariaLabelledBy: 'Busqueda de Productos', |
| 430 | templateUrl: 'modal-busqueda-productos.html', | 394 | templateUrl: 'modal-busqueda-productos.html', |
| 431 | controller: 'modalBusquedaProductosCtrl', | 395 | controller: 'modalBusquedaProductosCtrl', |
| 432 | resolve: { | 396 | resolve: { |
| 433 | parametroProducto: { | 397 | parametroProducto: { |
| 434 | idLista: $scope.idLista, | 398 | idLista: $scope.idLista, |
| 435 | cotizacion: $scope.remito.cotizacion.VENDEDOR, | 399 | cotizacion: $scope.remito.cotizacion.VENDEDOR, |
| 436 | simbolo: $scope.remito.cotizacion.moneda.SIMBOLO | 400 | simbolo: $scope.remito.cotizacion.moneda.SIMBOLO |
| 437 | } | 401 | } |
| 438 | }, | 402 | }, |
| 439 | size: 'lg' | 403 | size: 'lg' |
| 440 | } | 404 | } |
| 441 | ); | 405 | ); |
| 442 | modalInstance.result.then( | 406 | modalInstance.result.then( |
| 443 | function (producto) { | 407 | function (producto) { |
| 444 | var newArt = | 408 | var newArt = |
| 445 | { | 409 | { |
| 446 | id: 0, | 410 | id: 0, |
| 447 | idRemito: 0, | 411 | idRemito: 0, |
| 448 | codigo: producto.codigo, | 412 | codigo: producto.codigo, |
| 449 | sector: producto.sector, | 413 | sector: producto.sector, |
| 450 | sectorCodigo: producto.sector + '-' + producto.codigo, | 414 | sectorCodigo: producto.sector + '-' + producto.codigo, |
| 451 | descripcion: producto.descripcionLarga, | 415 | descripcion: producto.descripcionLarga, |
| 452 | item: $scope.remito.articulosRemito.length + 1, | 416 | item: $scope.remito.articulosRemito.length + 1, |
| 453 | nombre: producto.descripcion, | 417 | nombre: producto.descripcion, |
| 454 | precio: parseFloat(producto.precio.toFixed(4)), | 418 | precio: parseFloat(producto.precio.toFixed(4)), |
| 455 | costoUnitario: producto.costo, | 419 | costoUnitario: producto.costo, |
| 456 | editCantidad: false, | 420 | editCantidad: false, |
| 457 | editPrecio: false, | 421 | editPrecio: false, |
| 458 | rubro: producto.CodRub, | 422 | rubro: producto.CodRub, |
| 459 | ivaUnitario: producto.IMPIVA, | 423 | ivaUnitario: producto.IMPIVA, |
| 460 | impuestoInternoUnitario: producto.ImpInt, | 424 | impuestoInternoUnitario: producto.ImpInt, |
| 461 | impuestoInterno1Unitario: producto.ImpInt2, | 425 | impuestoInterno1Unitario: producto.ImpInt2, |
| 462 | impuestoInterno2Unitario: producto.ImpInt3, | 426 | impuestoInterno2Unitario: producto.ImpInt3, |
| 463 | precioLista: producto.precio, | 427 | precioLista: producto.precio, |
| 464 | combustible: 1, | 428 | combustible: 1, |
| 465 | facturado: 0, | 429 | facturado: 0, |
| 466 | idArticulo: producto.id, | 430 | idArticulo: producto.id, |
| 467 | tasaIva: producto.tasaIVA | 431 | tasaIva: producto.tasaIVA |
| 468 | }; | 432 | }; |
| 469 | 433 | ||
| 470 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; | 434 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; |
| 471 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; | 435 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; |
| 472 | 436 | ||
| 473 | $scope.articuloACargar = newArt; | 437 | $scope.articuloACargar = newArt; |
| 474 | $scope.cargando = false; | 438 | $scope.cargando = false; |
| 475 | }, function () { | 439 | }, function () { |
| 476 | // funcion ejecutada cuando se cancela el modal | 440 | // funcion ejecutada cuando se cancela el modal |
| 477 | } | 441 | } |
| 478 | ); | 442 | ); |
| 479 | }; | 443 | }; |
| 480 | 444 | ||
| 481 | $scope.seleccionarPuntosDeDescarga = function () { | 445 | $scope.seleccionarPuntosDeDescarga = function () { |
| 482 | if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) { | 446 | if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) { |
| 483 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 447 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
| 484 | return; | 448 | return; |
| 485 | } else { | 449 | } else { |
| 486 | var modalInstance = $uibModal.open( | 450 | var modalInstance = $uibModal.open( |
| 487 | { | 451 | { |
| 488 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 452 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
| 489 | templateUrl: 'modal-punto-descarga.html', | 453 | templateUrl: 'modal-punto-descarga.html', |
| 490 | controller: 'focaModalPuntoDescargaController', | 454 | controller: 'focaModalPuntoDescargaController', |
| 491 | size: 'lg', | 455 | size: 'lg', |
| 492 | resolve: { | 456 | resolve: { |
| 493 | filters: { | 457 | filters: { |
| 494 | idDomicilio: $scope.remito.domicilio.id, | 458 | idDomicilio: $scope.remito.domicilio.id, |
| 495 | idCliente: $scope.remito.cliente.COD, | 459 | idCliente: $scope.remito.cliente.COD, |
| 496 | articulos: $scope.remito.articulosRemito, | 460 | articulos: $scope.remito.articulosRemito, |
| 497 | puntosDescarga: $scope.remito.remitoPuntoDescarga, | 461 | puntosDescarga: $scope.remito.remitoPuntoDescarga, |
| 498 | domicilio: $scope.remito.domicilio | 462 | domicilio: $scope.remito.domicilio |
| 499 | } | 463 | } |
| 500 | } | 464 | } |
| 501 | } | 465 | } |
| 502 | ); | 466 | ); |
| 503 | modalInstance.result.then( | 467 | modalInstance.result.then( |
| 504 | function (puntosDescarga) { | 468 | function (puntosDescarga) { |
| 505 | 469 | ||
| 506 | puntosDescarga.forEach(function (punto) { | 470 | puntosDescarga.forEach(function (punto) { |
| 507 | $scope.remito.remitoPuntoDescarga.push( | 471 | $scope.remito.remitoPuntoDescarga.push( |
| 508 | { | 472 | { |
| 509 | puntoDescarga: punto | 473 | puntoDescarga: punto |
| 510 | } | 474 | } |
| 511 | ); | 475 | ); |
| 512 | }); | 476 | }); |
| 513 | 477 | ||
| 514 | $scope.$broadcast('addCabecera', { | 478 | $scope.$broadcast('addCabecera', { |
| 515 | label: 'Puntos de descarga:', | 479 | label: 'Puntos de descarga:', |
| 516 | valor: getCabeceraPuntoDescarga(puntosDescarga) | 480 | valor: getCabeceraPuntoDescarga(puntosDescarga) |
| 517 | }); | 481 | }); |
| 518 | }, function () { | 482 | }, function () { |
| 519 | $scope.abrirModalDomicilios($scope.cliente); | 483 | $scope.abrirModalDomicilios($scope.cliente); |
| 520 | } | 484 | } |
| 521 | ); | 485 | ); |
| 522 | } | 486 | } |
| 523 | }; | 487 | }; |
| 524 | 488 | ||
| 525 | $scope.seleccionarCliente = function () { | 489 | $scope.seleccionarCliente = function () { |
| 526 | if (!varlidarRemitoFacturado()) return; | 490 | if (!varlidarRemitoFacturado()) return; |
| 527 | if (!varlidarRemitoAbierto()) return; | 491 | if (!varlidarRemitoAbierto()) return; |
| 528 | var modalInstance = $uibModal.open( | 492 | var modalInstance = $uibModal.open( |
| 529 | { | 493 | { |
| 530 | ariaLabelledBy: 'Busqueda de Cliente', | 494 | ariaLabelledBy: 'Busqueda de Cliente', |
| 531 | templateUrl: 'foca-busqueda-cliente-modal.html', | 495 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 532 | controller: 'focaBusquedaClienteModalController', | 496 | controller: 'focaBusquedaClienteModalController', |
| 533 | resolve: { | 497 | resolve: { |
| 534 | parametros: function () { | 498 | parametros: function () { |
| 535 | return { | 499 | return { |
| 536 | vendedor: $scope.idVendedor, | 500 | vendedor: $scope.idVendedor, |
| 537 | cobrador: null, | 501 | cobrador: null, |
| 538 | searchText: $scope.cliente ? $scope.cliente.nom : '' | 502 | searchText: $scope.cliente ? $scope.cliente.nom : '' |
| 539 | }; | 503 | }; |
| 540 | }, | 504 | }, |
| 541 | }, | 505 | }, |
| 542 | size: 'lg' | 506 | size: 'lg' |
| 543 | } | 507 | } |
| 544 | ); | 508 | ); |
| 545 | modalInstance.result.then( | 509 | modalInstance.result.then( |
| 546 | function (cliente) { | 510 | function (cliente) { |
| 547 | 511 | ||
| 548 | if (angular.equals({}, cliente.vendedor)) { | 512 | if (angular.equals({}, cliente.vendedor)) { |
| 549 | 513 | ||
| 550 | focaModalService | 514 | focaModalService |
| 551 | .alert('El cliente seleccionado no tiene tiene ' + | 515 | .alert('El cliente seleccionado no tiene tiene ' + |
| 552 | 'vendedor asignado.') | 516 | 'vendedor asignado.') |
| 553 | .then($scope.seleccionarCliente); | 517 | .then($scope.seleccionarCliente); |
| 554 | 518 | ||
| 555 | return; | 519 | return; |
| 556 | } | 520 | } |
| 557 | 521 | ||
| 558 | $scope.cliente = cliente; | 522 | $scope.cliente = cliente; |
| 559 | $scope.abrirModalDomicilios(cliente); | 523 | $scope.abrirModalDomicilios(cliente); |
| 560 | }, function () { | 524 | }, function () { |
| 561 | } | 525 | } |
| 562 | ); | 526 | ); |
| 563 | }; | 527 | }; |
| 564 | 528 | ||
| 565 | $scope.seleccionarEliminarRemito = function () { | 529 | $scope.seleccionarEliminarRemito = function () { |
| 566 | focaModalService.confirm('¿Desea eliminar este remito?').then(function (data) { | 530 | focaModalService.confirm('¿Desea eliminar este remito?').then(function (data) { |
| 567 | if (data) { | 531 | if (data) { |
| 568 | $scope.remito.anulado = true; | 532 | $scope.remito.anulado = true; |
| 569 | delete $scope.remito.remitoPlazo; | 533 | delete $scope.remito.remitoPlazo; |
| 570 | delete $scope.remito.vendedor; | 534 | delete $scope.remito.vendedor; |
| 571 | delete $scope.remito.proveedor; | 535 | delete $scope.remito.proveedor; |
| 572 | delete $scope.remito.cliente; | 536 | delete $scope.remito.cliente; |
| 573 | delete $scope.remito.cotizacion; | 537 | delete $scope.remito.cotizacion; |
| 574 | delete $scope.remito.remitoPuntoDescarga; | 538 | delete $scope.remito.remitoPuntoDescarga; |
| 575 | delete $scope.remito.articulosRemito; | 539 | delete $scope.remito.articulosRemito; |
| 576 | delete $scope.remito.fechaRemito; | 540 | delete $scope.remito.fechaRemito; |
| 577 | crearRemitoService.eliminarRemito($scope.remito); | 541 | crearRemitoService.eliminarRemito($scope.remito); |
| 578 | } | 542 | } |
| 579 | config(); | 543 | config(); |
| 580 | }); | 544 | }); |
| 581 | }; | 545 | }; |
| 582 | 546 | ||
| 583 | $scope.seleccionarProveedor = function () { | 547 | $scope.seleccionarProveedor = function () { |
| 584 | if (!varlidarRemitoFacturado()) return; | 548 | if (!varlidarRemitoFacturado()) return; |
| 585 | if (!varlidarRemitoAbierto()) return; | 549 | if (!varlidarRemitoAbierto()) return; |
| 586 | var parametrosModal = { | 550 | var parametrosModal = { |
| 587 | titulo: 'Búsqueda de Proveedor', | 551 | titulo: 'Búsqueda de Proveedor', |
| 588 | query: '/proveedor', | 552 | query: '/proveedor', |
| 589 | columnas: [ | 553 | columnas: [ |
| 590 | { | 554 | { |
| 591 | nombre: 'Código', | 555 | nombre: 'Código', |
| 592 | propiedad: 'COD', | 556 | propiedad: 'COD', |
| 593 | filtro: { | 557 | filtro: { |
| 594 | nombre: 'rellenarDigitos', | 558 | nombre: 'rellenarDigitos', |
| 595 | parametro: 5 | 559 | parametro: 5 |
| 596 | } | 560 | } |
| 597 | }, | 561 | }, |
| 598 | { | 562 | { |
| 599 | nombre: 'Nombre', | 563 | nombre: 'Nombre', |
| 600 | propiedad: 'NOM' | 564 | propiedad: 'NOM' |
| 601 | }, | 565 | }, |
| 602 | { | 566 | { |
| 603 | nombre: 'CUIT', | 567 | nombre: 'CUIT', |
| 604 | propiedad: 'CUIT' | 568 | propiedad: 'CUIT' |
| 605 | } | 569 | } |
| 606 | ], | 570 | ], |
| 607 | tipo: 'POST', | 571 | tipo: 'POST', |
| 608 | json: { razonCuitCod: '' } | 572 | json: { razonCuitCod: '' } |
| 609 | }; | 573 | }; |
| 610 | focaModalService.modal(parametrosModal).then( | 574 | focaModalService.modal(parametrosModal).then( |
| 611 | function (proveedor) { | 575 | function (proveedor) { |
| 612 | $scope.seleccionarFlete(proveedor); | 576 | $scope.seleccionarFlete(proveedor); |
| 613 | }, function () { } | 577 | }, function () { } |
| 614 | ); | 578 | ); |
| 615 | }; | 579 | }; |
| 616 | 580 | ||
| 617 | $scope.seleccionarDomicilioDeEntrega = function () { | 581 | $scope.seleccionarDomicilioDeEntrega = function () { |
| 618 | if (!varlidarRemitoFacturado()) return; | 582 | if (!varlidarRemitoFacturado()) return; |
| 619 | if (!varlidarRemitoAbierto()) return; | 583 | if (!varlidarRemitoAbierto()) return; |
| 620 | if (!$scope.remito.cliente.COD && !$scope.cliente) { | 584 | if (!$scope.remito.cliente.COD && !$scope.cliente) { |
| 621 | focaModalService.alert('Seleccione un Cliente'); | 585 | focaModalService.alert('Seleccione un Cliente'); |
| 622 | return; | 586 | return; |
| 623 | } else { | 587 | } else { |
| 624 | $scope.abrirModalDomicilios($scope.remito.cliente.COD ? | 588 | $scope.abrirModalDomicilios($scope.remito.cliente.COD ? |
| 625 | $scope.remito.cliente.COD : $scope.cliente); | 589 | $scope.remito.cliente.COD : $scope.cliente); |
| 626 | } | 590 | } |
| 627 | }; | 591 | }; |
| 628 | 592 | ||
| 629 | $scope.abrirModalDomicilios = function (cliente) { | 593 | $scope.abrirModalDomicilios = function (cliente) { |
| 630 | var modalInstanceDomicilio = $uibModal.open( | 594 | var modalInstanceDomicilio = $uibModal.open( |
| 631 | { | 595 | { |
| 632 | ariaLabelledBy: 'Busqueda de Domicilios', | 596 | ariaLabelledBy: 'Busqueda de Domicilios', |
| 633 | templateUrl: 'modal-domicilio.html', | 597 | templateUrl: 'modal-domicilio.html', |
| 634 | controller: 'focaModalDomicilioController', | 598 | controller: 'focaModalDomicilioController', |
| 635 | size: 'lg', | 599 | size: 'lg', |
| 636 | resolve: { | 600 | resolve: { |
| 637 | idCliente: function () { | 601 | idCliente: function () { |
| 638 | return $scope.remito.cliente.COD ? $scope.remito.cliente.COD : | 602 | return $scope.remito.cliente.COD ? $scope.remito.cliente.COD : |
| 639 | cliente.COD; | 603 | cliente.COD; |
| 640 | }, | 604 | }, |
| 641 | esNuevo: function () { | 605 | esNuevo: function () { |
| 642 | return ($scope.remito.cliente.COD ? false : cliente.esNuevo); | 606 | return ($scope.remito.cliente.COD ? false : cliente.esNuevo); |
| 643 | } | 607 | } |
| 644 | } | 608 | } |
| 645 | } | 609 | } |
| 646 | ); | 610 | ); |
| 647 | modalInstanceDomicilio.result | 611 | modalInstanceDomicilio.result |
| 648 | .then(function (domicilio) { | 612 | .then(function (domicilio) { |
| 649 | $scope.remito.domicilio = domicilio; | 613 | $scope.remito.domicilio = domicilio; |
| 650 | $scope.remito.cliente = cliente; | 614 | $scope.remito.cliente = cliente; |
| 651 | $scope.remito.vendedor = cliente.vendedor; | 615 | $scope.remito.vendedor = cliente.vendedor; |
| 652 | 616 | ||
| 653 | var domicilioStamp = | 617 | var domicilioStamp = |
| 654 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 618 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
| 655 | domicilio.Localidad + ', ' + domicilio.Provincia; | 619 | domicilio.Localidad + ', ' + domicilio.Provincia; |
| 656 | 620 | ||
| 657 | $scope.remito.domicilioStamp = domicilioStamp; | 621 | $scope.remito.domicilioStamp = domicilioStamp; |
| 658 | 622 | ||
| 659 | $scope.$broadcast('addCabecera', { | 623 | $scope.$broadcast('addCabecera', { |
| 660 | label: 'Vendedor:', | 624 | label: 'Vendedor:', |
| 661 | valor: $filter('rellenarDigitos')($scope.remito.vendedor | 625 | valor: $filter('rellenarDigitos')($scope.remito.vendedor |
| 662 | .NUM, 3) + ' - ' + $scope.remito.vendedor.NOM | 626 | .NUM, 3) + ' - ' + $scope.remito.vendedor.NOM |
| 663 | }); | 627 | }); |
| 664 | $scope.$broadcast('addCabecera', { | 628 | $scope.$broadcast('addCabecera', { |
| 665 | label: 'Cliente:', | 629 | label: 'Cliente:', |
| 666 | valor: $filter('rellenarDigitos') | 630 | valor: $filter('rellenarDigitos') |
| 667 | ($scope.remito.cliente.COD, 3) + | 631 | ($scope.remito.cliente.COD, 3) + |
| 668 | ' - ' + $scope.remito.cliente.NOM | 632 | ' - ' + $scope.remito.cliente.NOM |
| 669 | }); | 633 | }); |
| 670 | $scope.$broadcast('addCabecera', { | 634 | $scope.$broadcast('addCabecera', { |
| 671 | label: 'Domicilio:', | 635 | label: 'Domicilio:', |
| 672 | valor: domicilioStamp | 636 | valor: domicilioStamp |
| 673 | }); | 637 | }); |
| 674 | 638 | ||
| 675 | if (domicilio.verPuntos) { | 639 | if (domicilio.verPuntos) { |
| 676 | delete $scope.remito.domicilio.verPuntos; | 640 | delete $scope.remito.domicilio.verPuntos; |
| 677 | $scope.seleccionarPuntosDeDescarga(); | 641 | $scope.seleccionarPuntosDeDescarga(); |
| 678 | } else { | ||
| 679 | crearRemitoService | ||
| 680 | .getPuntosDescargaByClienDom(domicilio.id, | ||
| 681 | $scope.remito.cliente.COD) | ||
| 682 | .then(function (res) { | ||
| 683 | if (res.data.length) { | ||
| 684 | $scope.seleccionarPuntosDeDescarga(); | ||
| 685 | } | ||
| 686 | }); | ||
| 687 | } | 642 | } |
| 688 | 643 | ||
| 689 | $filter('filter')($scope.botonera, | 644 | $filter('filter')($scope.botonera, |
| 690 | { label: 'Cliente' })[0].checked = true; | 645 | { label: 'Cliente' })[0].checked = true; |
| 691 | $filter('filter')($scope.botonera, | 646 | $filter('filter')($scope.botonera, |
| 692 | { label: 'Domicilio de Entrega' })[0].checked = true; | 647 | { label: 'Domicilio de Entrega' })[0].checked = true; |
| 693 | 648 | ||
| 694 | }) | 649 | }) |
| 695 | .catch(function (e) { | 650 | .catch(function (e) { |
| 696 | console.info(e); | 651 | console.info(e); |
| 697 | $scope.seleccionarCliente(true); | 652 | $scope.seleccionarCliente(true); |
| 698 | return; | 653 | return; |
| 699 | }); | 654 | }); |
| 700 | }; | 655 | }; |
| 701 | 656 | ||
| 702 | $scope.getTotal = function () { | 657 | $scope.getTotal = function () { |
| 703 | var total = 0; | 658 | var total = 0; |
| 704 | var arrayTempArticulos = $scope.articulosFiltro(); | 659 | var arrayTempArticulos = $scope.articulosFiltro(); |
| 705 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 660 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
| 706 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 661 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
| 707 | } | 662 | } |
| 708 | return parseFloat(total.toFixed(2)); | 663 | return parseFloat(total.toFixed(2)); |
| 709 | }; | 664 | }; |
| 710 | 665 | ||
| 711 | $scope.getSubTotal = function () { | 666 | $scope.getSubTotal = function () { |
| 712 | if ($scope.articuloACargar) { | 667 | if ($scope.articuloACargar) { |
| 713 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 668 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
| 714 | } | 669 | } |
| 715 | }; | 670 | }; |
| 716 | 671 | ||
| 717 | $scope.seleccionarPreciosYCondiciones = function () { | 672 | $scope.seleccionarPreciosYCondiciones = function () { |
| 718 | if (!$scope.remito.cliente.COD) { | 673 | if (!$scope.remito.cliente.COD) { |
| 719 | focaModalService.alert('Primero seleccione un cliente'); | 674 | focaModalService.alert('Primero seleccione un cliente'); |
| 720 | return; | 675 | return; |
| 721 | } | 676 | } |
| 722 | if ($scope.remito.articulosRemito.length !== 0) { | 677 | if ($scope.remito.articulosRemito.length !== 0) { |
| 723 | if (varlidarRemitoFacturado() && varlidarRemitoAbierto()) { | 678 | if (varlidarRemitoFacturado() && varlidarRemitoAbierto()) { |
| 724 | abrirModal(); | 679 | abrirModal(); |
| 725 | } | 680 | } |
| 726 | } else { | 681 | } else { |
| 727 | abrirModal(); | 682 | abrirModal(); |
| 728 | } | 683 | } |
| 729 | 684 | ||
| 730 | function abrirModal() { | 685 | function abrirModal() { |
| 731 | var parametros = { | 686 | var parametros = { |
| 732 | idCliente: $scope.remito.cliente.COD, | 687 | idCliente: $scope.remito.cliente.COD, |
| 733 | idListaPrecio: $scope.remito.cliente.MOD | 688 | idListaPrecio: $scope.remito.cliente.MOD |
| 734 | }; | 689 | }; |
| 735 | var modalInstance = $uibModal.open( | 690 | var modalInstance = $uibModal.open( |
| 736 | { | 691 | { |
| 737 | ariaLabelledBy: 'Busqueda de Precio Condición', | 692 | ariaLabelledBy: 'Busqueda de Precio Condición', |
| 738 | templateUrl: 'modal-precio-condicion.html', | 693 | templateUrl: 'modal-precio-condicion.html', |
| 739 | controller: 'focaModalPrecioCondicionController', | 694 | controller: 'focaModalPrecioCondicionController', |
| 740 | size: 'lg', | 695 | size: 'lg', |
| 741 | resolve: { | 696 | resolve: { |
| 742 | parametros: function () { return parametros; } | 697 | parametros: function () { return parametros; } |
| 743 | } | 698 | } |
| 744 | } | 699 | } |
| 745 | ); | 700 | ); |
| 746 | modalInstance.result.then( | 701 | modalInstance.result.then( |
| 747 | function (precioCondicion) { | 702 | function (precioCondicion) { |
| 748 | var cabecera = ''; | 703 | var cabecera = ''; |
| 749 | var plazosConcat = ''; | 704 | var plazosConcat = ''; |
| 750 | if (!Array.isArray(precioCondicion)) { | 705 | if (!Array.isArray(precioCondicion)) { |
| 751 | $scope.remito.idPrecioCondicion = precioCondicion.listaPrecio.ID; | 706 | $scope.remito.idPrecioCondicion = precioCondicion.listaPrecio.ID; |
| 752 | $scope.remito.remitoPlazo = precioCondicion.plazoPago; | 707 | $scope.remito.remitoPlazo = precioCondicion.plazoPago; |
| 753 | $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ? | 708 | $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ? |
| 754 | parseInt(precioCondicion.listaPrecio.ID) : -1; | 709 | parseInt(precioCondicion.listaPrecio.ID) : -1; |
| 755 | $scope.remito.cliente.MOD = precioCondicion.listaPrecio.ID; | 710 | $scope.remito.cliente.MOD = precioCondicion.listaPrecio.ID; |
| 756 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { | 711 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { |
| 757 | plazosConcat += precioCondicion.plazoPago[i].dias + ', '; | 712 | plazosConcat += precioCondicion.plazoPago[i].dias + ', '; |
| 758 | } | 713 | } |
| 759 | plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2); | 714 | plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2); |
| 760 | cabecera = $filter('rellenarDigitos') | 715 | cabecera = $filter('rellenarDigitos') |
| 761 | (parseInt(precioCondicion.listaPrecio.ID), 4) + | 716 | (parseInt(precioCondicion.listaPrecio.ID), 4) + |
| 762 | ' - ' + precioCondicion.listaPrecio.DES + ' ' + | 717 | ' - ' + precioCondicion.listaPrecio.DES + ' ' + |
| 763 | plazosConcat.trim(); | 718 | plazosConcat.trim(); |
| 764 | } else { //Cuando se ingresan los plazos manualmente | 719 | } else { //Cuando se ingresan los plazos manualmente |
| 765 | $scope.remito.idPrecioCondicion = 0; | 720 | $scope.remito.idPrecioCondicion = 0; |
| 766 | //-1, el modal productos busca todos los productos | 721 | //-1, el modal productos busca todos los productos |
| 767 | $scope.idLista = -1; | 722 | $scope.idLista = -1; |
| 768 | $scope.remito.remitoPlazo = precioCondicion; | 723 | $scope.remito.remitoPlazo = precioCondicion; |
| 769 | for (var j = 0; j < precioCondicion.length; j++) { | 724 | for (var j = 0; j < precioCondicion.length; j++) { |
| 770 | plazosConcat += precioCondicion[j].dias + ' '; | 725 | plazosConcat += precioCondicion[j].dias + ' '; |
| 771 | } | 726 | } |
| 772 | cabecera = plazosConcat.trim(); | 727 | cabecera = plazosConcat.trim(); |
| 773 | } | 728 | } |
| 774 | var cabecerasFilter = !$filter('filter')($scope.cabeceras, | 729 | var cabecerasFilter = !$filter('filter')($scope.cabeceras, |
| 775 | { label: 'Precios y Condiciones' }); | 730 | { label: 'Precios y Condiciones' }); |
| 776 | if (!cabecerasFilter) { | 731 | if (!cabecerasFilter) { |
| 777 | $scope.cabeceras.push({ | 732 | $scope.cabeceras.push({ |
| 778 | label: 'Precios y Condiciones:', | 733 | label: 'Precios y Condiciones:', |
| 779 | valor: parseInt(precioCondicion.listaPrecio.ID) + ' - ' + | 734 | valor: parseInt(precioCondicion.listaPrecio.ID) + ' - ' + |
| 780 | precioCondicion.listaPrecio.DES + ' ' + | 735 | precioCondicion.listaPrecio.DES + ' ' + |
| 781 | remitoBusinessService | 736 | remitoBusinessService |
| 782 | .plazoToString(precioCondicion.plazoPago) | 737 | .plazoToString(precioCondicion.plazoPago) |
| 783 | }); | 738 | }); |
| 784 | 739 | ||
| 785 | $scope.remito.idListaPrecio = parseInt( | 740 | $scope.remito.idListaPrecio = parseInt( |
| 786 | precioCondicion.listaPrecio.ID); | 741 | precioCondicion.listaPrecio.ID); |
| 787 | } | 742 | } |
| 788 | $filter('filter')($scope.cabeceras, | 743 | $filter('filter')($scope.cabeceras, |
| 789 | { label: 'Precios y Condiciones' })[0].valor = cabecera; | 744 | { label: 'Precios y Condiciones' })[0].valor = cabecera; |
| 790 | 745 | ||
| 791 | $scope.remito.precioCondicion = precioCondicion; | 746 | $scope.remito.precioCondicion = precioCondicion; |
| 792 | $filter('filter')($scope.botonera, | 747 | $filter('filter')($scope.botonera, |
| 793 | { label: 'Precios y Condiciones' })[0].checked = true; | 748 | { label: 'Precios y Condiciones' })[0].checked = true; |
| 794 | addArrayCabecera($scope.cabeceras); | 749 | addArrayCabecera($scope.cabeceras); |
| 795 | }, function () { | 750 | }, function () { |
| 796 | 751 | ||
| 797 | } | 752 | } |
| 798 | ); | 753 | ); |
| 799 | } | 754 | } |
| 800 | }; | 755 | }; |
| 801 | 756 | ||
| 802 | $scope.seleccionarFlete = function (proveedor) { | 757 | $scope.seleccionarFlete = function (proveedor) { |
| 803 | if (!varlidarRemitoFacturado()) return; | 758 | if (!varlidarRemitoFacturado()) return; |
| 804 | if (!varlidarRemitoAbierto()) return; | 759 | if (!varlidarRemitoAbierto()) return; |
| 805 | var modalInstance = $uibModal.open( | 760 | var modalInstance = $uibModal.open( |
| 806 | { | 761 | { |
| 807 | ariaLabelledBy: 'Busqueda de Flete', | 762 | ariaLabelledBy: 'Busqueda de Flete', |
| 808 | templateUrl: 'modal-flete.html', | 763 | templateUrl: 'modal-flete.html', |
| 809 | controller: 'focaModalFleteController', | 764 | controller: 'focaModalFleteController', |
| 810 | size: 'lg', | 765 | size: 'lg', |
| 811 | resolve: { | 766 | resolve: { |
| 812 | parametrosFlete: | 767 | parametrosFlete: |
| 813 | function () { | 768 | function () { |
| 814 | return { | 769 | return { |
| 815 | flete: $scope.remito.flete ? '1' : | 770 | flete: $scope.remito.flete ? '1' : |
| 816 | ($scope.remito.fob ? 'FOB' : | 771 | ($scope.remito.fob ? 'FOB' : |
| 817 | ($scope.remito.flete === undefined ? | 772 | ($scope.remito.flete === undefined ? |
| 818 | null : '0')), | 773 | null : '0')), |
| 819 | bomba: $scope.remito.bomba ? '1' : | 774 | bomba: $scope.remito.bomba ? '1' : |
| 820 | ($scope.remito.bomba === undefined ? | 775 | ($scope.remito.bomba === undefined ? |
| 821 | null : '0'), | 776 | null : '0'), |
| 822 | kilometros: $scope.remito.kilometros | 777 | kilometros: $scope.remito.kilometros |
| 823 | }; | 778 | }; |
| 824 | } | 779 | } |
| 825 | } | 780 | } |
| 826 | } | 781 | } |
| 827 | ); | 782 | ); |
| 828 | modalInstance.result.then( | 783 | modalInstance.result.then( |
| 829 | function (datos) { | 784 | function (datos) { |
| 830 | $scope.remitoIsDirty = true; | 785 | $scope.remitoIsDirty = true; |
| 831 | $scope.remito.proveedor = proveedor; | 786 | $scope.remito.proveedor = proveedor; |
| 832 | $scope.remito.idProveedor = proveedor.COD; | 787 | $scope.remito.idProveedor = proveedor.COD; |
| 833 | $scope.$broadcast('addCabecera', { | 788 | $scope.$broadcast('addCabecera', { |
| 834 | label: 'Proveedor:', | 789 | label: 'Proveedor:', |
| 835 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 790 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
| 836 | proveedor.NOM | 791 | proveedor.NOM |
| 837 | }); | 792 | }); |
| 838 | 793 | ||
| 839 | $scope.remito.flete = datos.flete; | 794 | $scope.remito.flete = datos.flete; |
| 840 | $scope.remito.fob = datos.FOB; | 795 | $scope.remito.fob = datos.FOB; |
| 841 | $scope.remito.bomba = datos.bomba; | 796 | $scope.remito.bomba = datos.bomba; |
| 842 | $scope.remito.kilometros = datos.kilometros; | 797 | $scope.remito.kilometros = datos.kilometros; |
| 843 | 798 | ||
| 844 | $scope.$broadcast('addCabecera', { | 799 | $scope.$broadcast('addCabecera', { |
| 845 | label: 'Flete:', | 800 | label: 'Flete:', |
| 846 | valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') | 801 | valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') |
| 847 | }); | 802 | }); |
| 848 | if (datos.flete) { | 803 | if (datos.flete) { |
| 849 | $scope.$broadcast('addCabecera', { | 804 | $scope.$broadcast('addCabecera', { |
| 850 | label: 'Bomba:', | 805 | label: 'Bomba:', |
| 851 | valor: datos.bomba ? 'Si' : 'No' | 806 | valor: datos.bomba ? 'Si' : 'No' |
| 852 | }); | 807 | }); |
| 853 | $scope.$broadcast('addCabecera', { | 808 | $scope.$broadcast('addCabecera', { |
| 854 | label: 'Kilometros:', | 809 | label: 'Kilometros:', |
| 855 | valor: datos.kilometros | 810 | valor: datos.kilometros |
| 856 | }); | 811 | }); |
| 857 | } else { | 812 | } else { |
| 858 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 813 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 859 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 814 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 860 | $scope.remito.bomba = false; | 815 | $scope.remito.bomba = false; |
| 861 | $scope.remito.kilometros = null; | 816 | $scope.remito.kilometros = null; |
| 862 | } | 817 | } |
| 863 | 818 | ||
| 864 | $filter('filter')($scope.botonera, | 819 | $filter('filter')($scope.botonera, |
| 865 | { label: 'Proveedor' })[0].checked = true; | 820 | { label: 'Proveedor' })[0].checked = true; |
| 866 | }, function () { | 821 | }, function () { |
| 867 | $scope.seleccionarTransportista(); | 822 | $scope.seleccionarTransportista(); |
| 868 | } | 823 | } |
| 869 | ); | 824 | ); |
| 870 | }; | 825 | }; |
| 871 | 826 | ||
| 872 | $scope.seleccionarMoneda = function () { | 827 | $scope.seleccionarMoneda = function () { |
| 873 | if (!varlidarRemitoFacturado()) return; | 828 | if (!varlidarRemitoFacturado()) return; |
| 874 | if (!varlidarRemitoAbierto()) return; | 829 | if (!varlidarRemitoAbierto()) return; |
| 875 | var parametrosModal = { | 830 | var parametrosModal = { |
| 876 | titulo: 'Búsqueda de monedas', | 831 | titulo: 'Búsqueda de monedas', |
| 877 | query: '/moneda', | 832 | query: '/moneda', |
| 878 | columnas: [ | 833 | columnas: [ |
| 879 | { | 834 | { |
| 880 | propiedad: 'DETALLE', | 835 | propiedad: 'DETALLE', |
| 881 | nombre: 'Nombre' | 836 | nombre: 'Nombre' |
| 882 | }, | 837 | }, |
| 883 | { | 838 | { |
| 884 | propiedad: 'SIMBOLO', | 839 | propiedad: 'SIMBOLO', |
| 885 | nombre: 'Símbolo' | 840 | nombre: 'Símbolo' |
| 886 | } | 841 | } |
| 887 | ], | 842 | ], |
| 888 | size: 'md' | 843 | size: 'md' |
| 889 | }; | 844 | }; |
| 890 | focaModalService.modal(parametrosModal).then( | 845 | focaModalService.modal(parametrosModal).then( |
| 891 | function (moneda) { | 846 | function (moneda) { |
| 892 | 847 | ||
| 893 | if (moneda.ID !== 1) { | 848 | if (moneda.ID !== 1) { |
| 894 | $scope.abrirModalCotizacion(moneda); | 849 | $scope.abrirModalCotizacion(moneda); |
| 895 | return; | 850 | return; |
| 896 | } | 851 | } |
| 897 | 852 | ||
| 898 | crearRemitoService.getCotizacionByIdMoneda(1) | 853 | crearRemitoService.getCotizacionByIdMoneda(1) |
| 899 | .then(function (res) { | 854 | .then(function (res) { |
| 900 | 855 | ||
| 901 | cotizacionPArgentino = res.data[0].cotizaciones[0]; | 856 | cotizacionPArgentino = res.data[0].cotizaciones[0]; |
| 902 | cotizacionPArgentino.moneda = moneda; | 857 | cotizacionPArgentino.moneda = moneda; |
| 903 | 858 | ||
| 904 | actualizarCabeceraMoneda(cotizacionPArgentino); | 859 | actualizarCabeceraMoneda(cotizacionPArgentino); |
| 905 | 860 | ||
| 906 | $scope.remito.cotizacion = cotizacionPArgentino; | 861 | $scope.remito.cotizacion = cotizacionPArgentino; |
| 907 | }); | 862 | }); |
| 908 | }, function () { | 863 | }, function () { |
| 909 | 864 | ||
| 910 | } | 865 | } |
| 911 | ); | 866 | ); |
| 912 | }; | 867 | }; |
| 913 | 868 | ||
| 914 | $scope.seleccionarObservaciones = function () { | 869 | $scope.seleccionarObservaciones = function () { |
| 915 | focaModalService | 870 | focaModalService |
| 916 | .prompt({ | 871 | .prompt({ |
| 917 | titulo: 'Observaciones', | 872 | titulo: 'Observaciones', |
| 918 | value: $scope.remito.observaciones, | 873 | value: $scope.remito.observaciones, |
| 919 | textarea: true, | 874 | textarea: true, |
| 920 | readonly: true | 875 | readonly: true |
| 921 | }) | 876 | }) |
| 922 | .then(function (observaciones) { | 877 | .then(function (observaciones) { |
| 923 | $scope.remito.observaciones = observaciones; | 878 | $scope.remito.observaciones = observaciones; |
| 924 | }); | 879 | }); |
| 925 | }; | 880 | }; |
| 926 | 881 | ||
| 927 | $scope.abrirModalCotizacion = function (moneda) { | 882 | $scope.abrirModalCotizacion = function (moneda) { |
| 928 | var modalInstance = $uibModal.open( | 883 | var modalInstance = $uibModal.open( |
| 929 | { | 884 | { |
| 930 | ariaLabelledBy: 'Busqueda de Cotización', | 885 | ariaLabelledBy: 'Busqueda de Cotización', |
| 931 | templateUrl: 'modal-cotizacion.html', | 886 | templateUrl: 'modal-cotizacion.html', |
| 932 | controller: 'focaModalCotizacionController', | 887 | controller: 'focaModalCotizacionController', |
| 933 | size: 'lg', | 888 | size: 'lg', |
| 934 | resolve: { idMoneda: function () { return moneda.ID; } } | 889 | resolve: { idMoneda: function () { return moneda.ID; } } |
| 935 | } | 890 | } |
| 936 | ); | 891 | ); |
| 937 | modalInstance.result.then( | 892 | modalInstance.result.then( |
| 938 | function (cotizacion) { | 893 | function (cotizacion) { |
| 939 | cotizacion.moneda = moneda; | 894 | cotizacion.moneda = moneda; |
| 940 | $scope.remitoIsDirty = true; | 895 | $scope.remitoIsDirty = true; |
| 941 | actualizarCabeceraMoneda(cotizacion); | 896 | actualizarCabeceraMoneda(cotizacion); |
| 942 | $scope.remito.cotizacion = cotizacion; | 897 | $scope.remito.cotizacion = cotizacion; |
| 943 | }, function () { | 898 | }, function () { |
| 944 | 899 | ||
| 945 | } | 900 | } |
| 946 | ); | 901 | ); |
| 947 | }; | 902 | }; |
| 948 | 903 | ||
| 949 | function actualizarCabeceraMoneda(cotizacion) { | 904 | function actualizarCabeceraMoneda(cotizacion) { |
| 950 | 905 | ||
| 951 | $scope.remito.articulosRemito.forEach(function (art) { | 906 | $scope.remito.articulosRemito.forEach(function (art) { |
| 952 | art.precio = (art.precio * $scope.remito.cotizacion.VENDEDOR).toFixed(4); | 907 | art.precio = (art.precio * $scope.remito.cotizacion.VENDEDOR).toFixed(4); |
| 953 | art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); | 908 | art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); |
| 954 | }); | 909 | }); |
| 955 | 910 | ||
| 956 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | 911 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { |
| 957 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 912 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
| 958 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 913 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
| 959 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 914 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
| 960 | } else { | 915 | } else { |
| 961 | $scope.$broadcast('addCabecera', { | 916 | $scope.$broadcast('addCabecera', { |
| 962 | label: 'Moneda:', | 917 | label: 'Moneda:', |
| 963 | valor: cotizacion.moneda.DETALLE | 918 | valor: cotizacion.moneda.DETALLE |
| 964 | }); | 919 | }); |
| 965 | $scope.$broadcast('addCabecera', { | 920 | $scope.$broadcast('addCabecera', { |
| 966 | label: 'Fecha cotizacion:', | 921 | label: 'Fecha cotizacion:', |
| 967 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 922 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
| 968 | }); | 923 | }); |
| 969 | $scope.$broadcast('addCabecera', { | 924 | $scope.$broadcast('addCabecera', { |
| 970 | label: 'Cotizacion:', | 925 | label: 'Cotizacion:', |
| 971 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 926 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
| 972 | }); | 927 | }); |
| 973 | } | 928 | } |
| 974 | } | 929 | } |
| 975 | 930 | ||
| 976 | $scope.agregarATabla = function (key) { | 931 | $scope.agregarATabla = function (key) { |
| 977 | if (key === 13) { | 932 | if (key === 13) { |
| 978 | if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) { | 933 | if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) { |
| 979 | focaModalService.alert('El valor debe ser al menos 1'); | 934 | focaModalService.alert('El valor debe ser al menos 1'); |
| 980 | return; | 935 | return; |
| 981 | } | 936 | } |
| 982 | delete $scope.articuloACargar.sectorCodigo; | 937 | delete $scope.articuloACargar.sectorCodigo; |
| 983 | $scope.remito.articulosRemito.push($scope.articuloACargar); | 938 | $scope.remito.articulosRemito.push($scope.articuloACargar); |
| 984 | $scope.cargando = true; | 939 | $scope.cargando = true; |
| 985 | } | 940 | } |
| 986 | }; | 941 | }; |
| 987 | 942 | ||
| 988 | $scope.quitarArticulo = function (articulo) { | 943 | $scope.quitarArticulo = function (articulo) { |
| 989 | articulo.idRemito = -1; | 944 | articulo.idRemito = -1; |
| 990 | }; | 945 | }; |
| 991 | 946 | ||
| 992 | $scope.articulosFiltro = function () { | 947 | $scope.articulosFiltro = function () { |
| 993 | 948 | ||
| 994 | var result = $scope.remito.articulosRemito.filter(function (articulo) { | 949 | var result = $scope.remito.articulosRemito.filter(function (articulo) { |
| 995 | return articulo.idRemito >= 0; | 950 | return articulo.idRemito >= 0; |
| 996 | }); | 951 | }); |
| 997 | 952 | ||
| 998 | // Agrego checked en cabecera si hay datos | 953 | // Agrego checked en cabecera si hay datos |
| 999 | if (result.length) { | 954 | if (result.length) { |
| 1000 | $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = true; | 955 | $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = true; |
| 1001 | } else { | 956 | } else { |
| 1002 | $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = false; | 957 | $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = false; |
| 1003 | } | 958 | } |
| 1004 | return result; | 959 | return result; |
| 1005 | }; | 960 | }; |
| 1006 | 961 | ||
| 1007 | $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) { | 962 | $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) { |
| 1008 | if (key === 13) { | 963 | if (key === 13) { |
| 1009 | if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) { | 964 | if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) { |
| 1010 | focaModalService.alert('Los valores deben ser al menos 1'); | 965 | focaModalService.alert('Los valores deben ser al menos 1'); |
| 1011 | return; | 966 | return; |
| 1012 | } else if (tmpCantidad === '0' || tmpPrecio === '0') { | 967 | } else if (tmpCantidad === '0' || tmpPrecio === '0') { |
| 1013 | focaModalService.alert('Esta ingresando un producto con valor 0'); | 968 | focaModalService.alert('Esta ingresando un producto con valor 0'); |
| 1014 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { | 969 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { |
| 1015 | focaModalService.alert('Los valores no pueden ser negativos'); | 970 | focaModalService.alert('Los valores no pueden ser negativos'); |
| 1016 | return; | 971 | return; |
| 1017 | } | 972 | } |
| 1018 | articulo.cantidad = tmpCantidad; | 973 | articulo.cantidad = tmpCantidad; |
| 1019 | articulo.precio = tmpPrecio; | 974 | articulo.precio = tmpPrecio; |
| 1020 | $scope.getTotal(); | 975 | $scope.getTotal(); |
| 1021 | articulo.editCantidad = articulo.editPrecio = false; | 976 | articulo.editCantidad = articulo.editPrecio = false; |
| 1022 | } | 977 | } |
| 1023 | }; | 978 | }; |
| 1024 | 979 | ||
| 1025 | $scope.cancelarEditar = function (articulo) { | 980 | $scope.cancelarEditar = function (articulo) { |
| 1026 | $scope.tmpCantidad = articulo.cantidad; | 981 | $scope.tmpCantidad = articulo.cantidad; |
| 1027 | $scope.tmpPrecio = articulo.precio; | 982 | $scope.tmpPrecio = articulo.precio; |
| 1028 | articulo.editCantidad = articulo.editPrecio = false; | 983 | articulo.editCantidad = articulo.editPrecio = false; |
| 1029 | }; | 984 | }; |
| 1030 | 985 | ||
| 1031 | $scope.cambioEdit = function (articulo, propiedad) { | 986 | $scope.cambioEdit = function (articulo, propiedad) { |
| 1032 | if (propiedad === 'cantidad') { | 987 | if (propiedad === 'cantidad') { |
| 1033 | articulo.editCantidad = true; | 988 | articulo.editCantidad = true; |
| 1034 | } else if (propiedad === 'precio') { | 989 | } else if (propiedad === 'precio') { |
| 1035 | articulo.editPrecio = true; | 990 | articulo.editPrecio = true; |
| 1036 | } | 991 | } |
| 1037 | }; | 992 | }; |
| 1038 | 993 | ||
| 1039 | $scope.resetFilter = function () { | 994 | $scope.resetFilter = function () { |
| 1040 | $scope.articuloACargar = {}; | 995 | $scope.articuloACargar = {}; |
| 1041 | $scope.cargando = true; | 996 | $scope.cargando = true; |
| 1042 | }; | 997 | }; |
| 1043 | //Recibe aviso si el teclado está en uso | 998 | //Recibe aviso si el teclado está en uso |
| 1044 | $rootScope.$on('usarTeclado', function (event, data) { | 999 | $rootScope.$on('usarTeclado', function (event, data) { |
| 1045 | if (data) { | 1000 | if (data) { |
| 1046 | $scope.mostrarTeclado = true; | 1001 | $scope.mostrarTeclado = true; |
| 1047 | return; | 1002 | return; |
| 1048 | } | 1003 | } |
| 1049 | $scope.mostrarTeclado = false; | 1004 | $scope.mostrarTeclado = false; |
| 1050 | }); | 1005 | }); |
| 1051 | 1006 | ||
| 1052 | $scope.selectFocus = function ($event) { | 1007 | $scope.selectFocus = function ($event) { |
| 1053 | // Si el teclado esta en uso no selecciona el valor | 1008 | // Si el teclado esta en uso no selecciona el valor |
| 1054 | if ($scope.mostrarTeclado) { | 1009 | if ($scope.mostrarTeclado) { |
| 1055 | return; | 1010 | return; |
| 1056 | } | 1011 | } |
| 1057 | $event.target.select(); | 1012 | $event.target.select(); |
| 1058 | }; | 1013 | }; |
| 1059 | 1014 | ||
| 1060 | function addArrayCabecera(array) { | 1015 | function addArrayCabecera(array) { |
| 1061 | for (var i = 0; i < array.length; i++) { | 1016 | for (var i = 0; i < array.length; i++) { |
| 1062 | $scope.$broadcast('addCabecera', { | 1017 | $scope.$broadcast('addCabecera', { |
| 1063 | label: array[i].label, | 1018 | label: array[i].label, |
| 1064 | valor: array[i].valor | 1019 | valor: array[i].valor |
| 1065 | }); | 1020 | }); |
| 1066 | } | 1021 | } |
| 1067 | } | 1022 | } |
| 1068 | 1023 | ||
| 1069 | function rellenar(relleno, longitud) { | 1024 | function rellenar(relleno, longitud) { |
| 1070 | relleno = '' + relleno; | 1025 | relleno = '' + relleno; |
| 1071 | while (relleno.length < longitud) { | 1026 | while (relleno.length < longitud) { |
| 1072 | relleno = '0' + relleno; | 1027 | relleno = '0' + relleno; |
| 1073 | } | 1028 | } |
| 1074 | return relleno; | 1029 | return relleno; |
| 1075 | } | 1030 | } |
| 1076 | 1031 | ||
| 1077 | function varlidarRemitoFacturado() { | 1032 | function varlidarRemitoFacturado() { |
| 1078 | if ($scope.remito.estado !== 5) { | 1033 | if ($scope.remito.estado !== 5) { |
| 1079 | return true; | 1034 | return true; |
| 1080 | } else { | 1035 | } else { |
| 1081 | focaModalService.alert('No se puede editar un remito facturado'); | 1036 | focaModalService.alert('No se puede editar un remito facturado'); |
| 1082 | return false; | 1037 | return false; |
| 1083 | } | 1038 | } |
| 1084 | } | 1039 | } |
| 1085 | 1040 | ||
| 1086 | function varlidarRemitoAbierto() { | 1041 | function varlidarRemitoAbierto() { |
| 1087 | if (!$scope.remito.hojaRuta) return true; | 1042 | if (!$scope.remito.hojaRuta) return true; |
| 1088 | if ($scope.remito.hojaRuta.abierta !== '1') { | 1043 | if ($scope.remito.hojaRuta.abierta !== '1') { |
| 1089 | return true; | 1044 | return true; |
| 1090 | } else { | 1045 | } else { |
| 1091 | focaModalService.alert('No se puede editar un remito abierto'); | 1046 | focaModalService.alert('No se puede editar un remito abierto'); |
| 1092 | return false; | 1047 | return false; |
| 1093 | } | 1048 | } |
| 1094 | } | 1049 | } |
| 1095 | 1050 | ||
| 1096 | function salir() { | 1051 | function salir() { |
| 1097 | var confirmacion = false; | 1052 | var confirmacion = false; |
| 1098 | 1053 | ||
| 1099 | if (!angular.equals($scope.remito, $scope.inicial)) { | 1054 | if (!angular.equals($scope.remito, $scope.inicial)) { |
| 1100 | confirmacion = true; | 1055 | confirmacion = true; |
| 1101 | } | 1056 | } |
| 1102 | 1057 | ||
| 1103 | if (confirmacion) { | 1058 | if (confirmacion) { |
| 1104 | focaModalService.confirm( | 1059 | focaModalService.confirm( |
| 1105 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 1060 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 1106 | ).then(function (data) { | 1061 | ).then(function (data) { |
| 1107 | if (data) { | 1062 | if (data) { |
| 1108 | $location.path('/'); | 1063 | $location.path('/'); |
| 1109 | } | 1064 | } |
| 1110 | }); | 1065 | }); |
| 1111 | } else { | 1066 | } else { |
| 1112 | $location.path('/'); | 1067 | $location.path('/'); |
| 1113 | } | 1068 | } |
| 1114 | } | 1069 | } |
| 1115 | 1070 | ||
| 1116 | function enableObservaciones(val) { | 1071 | function enableObservaciones(val) { |
| 1117 | var boton = $scope.botonera.filter(function (botonObs) { | 1072 | var boton = $scope.botonera.filter(function (botonObs) { |
| 1118 | return botonObs.label === 'Observaciones'; | 1073 | return botonObs.label === 'Observaciones'; |
| 1119 | }); | 1074 | }); |
| 1120 | boton[0].disable = !val; | 1075 | boton[0].disable = !val; |
| 1121 | } | 1076 | } |
| 1122 | 1077 | ||
| 1123 | function setearRemito(remito) { | 1078 | function setearRemito(remito) { |
| 1124 | //añado cabeceras | 1079 | //añado cabeceras |
| 1125 | console.log(remito); | 1080 | console.log(remito); |
| 1126 | var esAbierto = remito.hojaRuta ? | 1081 | var esAbierto = remito.hojaRuta ? |
| 1127 | (remito.hojaRuta.abierta === '1') : false; | 1082 | (remito.hojaRuta.abierta === '1') : false; |
| 1128 | if (remito.estado !== 5 && remito.id && !esAbierto) { | 1083 | if (remito.estado !== 5 && remito.id && !esAbierto) { |
| 1129 | 1084 | ||
| 1130 | $scope.botonera.forEach(function (boton) { | 1085 | $scope.botonera.forEach(function (boton) { |
| 1131 | 1086 | ||
| 1132 | if (boton.label === 'Eliminar Remito') { | 1087 | if (boton.label === 'Eliminar Remito') { |
| 1133 | boton.disable = false; | 1088 | boton.disable = false; |
| 1134 | } | 1089 | } |
| 1135 | }); | 1090 | }); |
| 1136 | } | 1091 | } |
| 1137 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 1092 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
| 1138 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 1093 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
| 1139 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 1094 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
| 1140 | $scope.$broadcast('removeCabecera', 'Vendedor:'); | 1095 | $scope.$broadcast('removeCabecera', 'Vendedor:'); |
| 1141 | 1096 | ||
| 1142 | $scope.cabeceras = []; | 1097 | $scope.cabeceras = []; |
| 1143 | 1098 | ||
| 1144 | if (remito.cotizacion && remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 1099 | if (remito.cotizacion && remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') { |
| 1145 | $scope.cabeceras.push({ | 1100 | $scope.cabeceras.push({ |
| 1146 | label: 'Moneda:', | 1101 | label: 'Moneda:', |
| 1147 | valor: remito.cotizacion.moneda.DETALLE | 1102 | valor: remito.cotizacion.moneda.DETALLE |
| 1148 | }); | 1103 | }); |
| 1149 | $scope.cabeceras.push({ | 1104 | $scope.cabeceras.push({ |
| 1150 | label: 'Fecha cotizacion:', | 1105 | label: 'Fecha cotizacion:', |
| 1151 | valor: $filter('date')(remito.cotizacion.FECHA, | 1106 | valor: $filter('date')(remito.cotizacion.FECHA, |
| 1152 | 'dd/MM/yyyy') | 1107 | 'dd/MM/yyyy') |
| 1153 | }); | 1108 | }); |
| 1154 | $scope.cabeceras.push({ | 1109 | $scope.cabeceras.push({ |
| 1155 | label: 'Cotizacion:', | 1110 | label: 'Cotizacion:', |
| 1156 | valor: $filter('number')(remito.cotizacion.VENDEDOR, | 1111 | valor: $filter('number')(remito.cotizacion.VENDEDOR, |
| 1157 | '2') | 1112 | '2') |
| 1158 | }); | 1113 | }); |
| 1159 | } | 1114 | } |
| 1160 | 1115 | ||
| 1161 | if (remito.cotizacion && remito.cotizacion.moneda) { | 1116 | if (remito.cotizacion && remito.cotizacion.moneda) { |
| 1162 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; | 1117 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; |
| 1163 | } | 1118 | } |
| 1164 | 1119 | ||
| 1165 | if (remito.cliente && remito.cliente.COD) { | 1120 | if (remito.cliente && remito.cliente.COD) { |
| 1166 | $scope.cabeceras.push({ | 1121 | $scope.cabeceras.push({ |
| 1167 | label: 'Cliente:', | 1122 | label: 'Cliente:', |
| 1168 | valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + | 1123 | valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + |
| 1169 | remito.cliente.NOM | 1124 | remito.cliente.NOM |
| 1170 | }); | 1125 | }); |
| 1171 | $scope.cabeceras.push({ | 1126 | $scope.cabeceras.push({ |
| 1172 | label: 'Domicilio:', | 1127 | label: 'Domicilio:', |
| 1173 | valor: remito.domicilioStamp | 1128 | valor: remito.domicilioStamp |
| 1174 | }); | 1129 | }); |
| 1175 | 1130 | ||
| 1176 | $filter('filter')($scope.botonera, | 1131 | $filter('filter')($scope.botonera, |
| 1177 | { label: 'Domicilio de Entrega' })[0].checked = true; | 1132 | { label: 'Domicilio de Entrega' })[0].checked = true; |
| 1178 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; | 1133 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; |
| 1179 | } | 1134 | } |
| 1180 | if (remito.vendedor && remito.vendedor.NUM) { | 1135 | if (remito.vendedor && remito.vendedor.NUM) { |
| 1181 | $scope.cabeceras.push({ | 1136 | $scope.cabeceras.push({ |
| 1182 | label: 'Vendedor:', | 1137 | label: 'Vendedor:', |
| 1183 | valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + | 1138 | valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + |
| 1184 | ' - ' + remito.vendedor.NOM | 1139 | ' - ' + remito.vendedor.NOM |
| 1185 | }); | 1140 | }); |
| 1186 | } | 1141 | } |
| 1187 | if (remito.proveedor && remito.proveedor.COD) { | 1142 | if (remito.proveedor && remito.proveedor.COD) { |
| 1188 | $scope.cabeceras.push({ | 1143 | $scope.cabeceras.push({ |
| 1189 | label: 'Proveedor:', | 1144 | label: 'Proveedor:', |
| 1190 | valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + | 1145 | valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + |
| 1191 | ' - ' + remito.proveedor.NOM | 1146 | ' - ' + remito.proveedor.NOM |
| 1192 | }); | 1147 | }); |
| 1193 | 1148 | ||
| 1194 | $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true; | 1149 | $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true; |
| 1195 | } | 1150 | } |
| 1196 | if (remito.flete !== undefined && remito.fob !== undefined) { | 1151 | if (remito.flete !== undefined && remito.fob !== undefined) { |
| 1197 | $scope.cabeceras.push({ | 1152 | $scope.cabeceras.push({ |
| 1198 | label: 'Flete:', | 1153 | label: 'Flete:', |
| 1199 | valor: remito.fob ? 'FOB' : ( | 1154 | valor: remito.fob ? 'FOB' : ( |
| 1200 | remito.flete ? 'Si' : 'No') | 1155 | remito.flete ? 'Si' : 'No') |
| 1201 | }); | 1156 | }); |
| 1202 | } | 1157 | } |
| 1203 | if (remito.remitoPlazo) { | 1158 | if (remito.remitoPlazo) { |
| 1204 | valorPrecioCondicion(); | 1159 | valorPrecioCondicion(); |
| 1205 | $filter('filter')($scope.botonera, | 1160 | $filter('filter')($scope.botonera, |
| 1206 | { label: 'Precios y condiciones' })[0].checked = true; | 1161 | { label: 'Precios y condiciones' })[0].checked = true; |
| 1207 | } | 1162 | } |
| 1208 | 1163 | ||
| 1209 | function valorPrecioCondicion() { | 1164 | function valorPrecioCondicion() { |
| 1210 | if (parseInt(remito.idListaPrecio)) { | 1165 | if (parseInt(remito.idListaPrecio)) { |
| 1211 | crearRemitoService.getListaPrecioById(parseInt(remito.idListaPrecio)) | 1166 | crearRemitoService.getListaPrecioById(parseInt(remito.idListaPrecio)) |
| 1212 | .then(function (res) { | 1167 | .then(function (res) { |
| 1213 | $timeout(function () { | 1168 | $timeout(function () { |
| 1214 | $scope.cabeceras.push({ | 1169 | $scope.cabeceras.push({ |
| 1215 | label: 'Precios y Condiciones:', | 1170 | label: 'Precios y Condiciones:', |
| 1216 | valor: parseInt(res.data[0].ID) + ' - ' + | 1171 | valor: parseInt(res.data[0].ID) + ' - ' + |
| 1217 | res.data[0].DES + ' ' + | 1172 | res.data[0].DES + ' ' + |
| 1218 | remitoBusinessService | 1173 | remitoBusinessService |
| 1219 | .plazoToString(remito.remitoPlazo) | 1174 | .plazoToString(remito.remitoPlazo) |
| 1220 | }); | 1175 | }); |
| 1221 | addArrayCabecera($scope.cabeceras); | 1176 | addArrayCabecera($scope.cabeceras); |
| 1222 | }, true); | 1177 | }, true); |
| 1223 | 1178 | ||
| 1224 | }); | 1179 | }); |
| 1225 | $scope.idLista = parseInt(remito.idListaPrecio); | 1180 | $scope.idLista = parseInt(remito.idListaPrecio); |
| 1226 | } | 1181 | } |
| 1227 | } | 1182 | } |
| 1228 | 1183 | ||
| 1229 | if (remito.flete === 1) { | 1184 | if (remito.flete === 1) { |
| 1230 | var cabeceraBomba = { | 1185 | var cabeceraBomba = { |
| 1231 | label: 'Bomba', | 1186 | label: 'Bomba', |
| 1232 | valor: remito.bomba === 1 ? 'Si' : 'No' | 1187 | valor: remito.bomba === 1 ? 'Si' : 'No' |
| 1233 | }; | 1188 | }; |
| 1234 | if (remito.kilometros) { | 1189 | if (remito.kilometros) { |
| 1235 | var cabeceraKilometros = { | 1190 | var cabeceraKilometros = { |
| 1236 | label: 'Kilometros', | 1191 | label: 'Kilometros', |
| 1237 | valor: remito.kilometros | 1192 | valor: remito.kilometros |
| 1238 | }; | 1193 | }; |
| 1239 | $scope.cabeceras.push(cabeceraKilometros); | 1194 | $scope.cabeceras.push(cabeceraKilometros); |
| 1240 | } | 1195 | } |
| 1241 | $scope.cabeceras.push(cabeceraBomba); | 1196 | $scope.cabeceras.push(cabeceraBomba); |
| 1242 | } | 1197 | } |
| 1243 | 1198 | ||
| 1244 | if (remito.idPrecioCondicion > 0) { | 1199 | if (remito.idPrecioCondicion > 0) { |
| 1245 | $scope.idLista = remito.precioCondicion.idListaPrecio; | 1200 | $scope.idLista = remito.precioCondicion.idListaPrecio; |
| 1246 | } else if (remito.idPrecioCondicion) { | 1201 | } else if (remito.idPrecioCondicion) { |
| 1247 | $scope.idLista = -1; | 1202 | $scope.idLista = -1; |
| 1248 | } | 1203 | } |
| 1249 | $scope.puntoVenta = rellenar(remito.sucursal, 4); | 1204 | $scope.puntoVenta = rellenar(remito.sucursal, 4); |
| 1250 | $scope.comprobante = rellenar(remito.numeroRemito, 8); | 1205 | $scope.comprobante = rellenar(remito.numeroRemito, 8); |
| 1251 | $scope.remito = remito; | 1206 | $scope.remito = remito; |
| 1252 | if ($scope.remito.remitoPuntoDescarga.length) { | 1207 | if ($scope.remito.remitoPuntoDescarga.length) { |
| 1253 | var puntoDescarga = []; | 1208 | var puntoDescarga = []; |
| 1254 | 1209 | ||
| 1255 | $scope.remito.remitoPuntoDescarga.forEach(function (remitoPuntoDescarga) { | 1210 | $scope.remito.remitoPuntoDescarga.forEach(function (remitoPuntoDescarga) { |
| 1256 | puntoDescarga.push(remitoPuntoDescarga.puntoDescarga); | 1211 | puntoDescarga.push(remitoPuntoDescarga.puntoDescarga); |
| 1257 | }); | 1212 | }); |
| 1258 | 1213 | ||
| 1259 | $scope.cabeceras.push({ | 1214 | $scope.cabeceras.push({ |
| 1260 | label: 'Puntos de descarga: ', | 1215 | label: 'Puntos de descarga: ', |
| 1261 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntoDescarga)) | 1216 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntoDescarga)) |
| 1262 | }); | 1217 | }); |
| 1263 | } | 1218 | } |
| 1264 | $scope.remitoIsDirty = false; | 1219 | $scope.remitoIsDirty = false; |
| 1265 | 1220 | ||
| 1266 | 1221 | ||
| 1267 | addArrayCabecera($scope.cabeceras); | 1222 | addArrayCabecera($scope.cabeceras); |
| 1268 | } | 1223 | } |
| 1269 | 1224 | ||
| 1270 | function getLSRemito() { | 1225 | function getLSRemito() { |
| 1271 | var remito = JSON.parse($localStorage.remito || null); | 1226 | var remito = JSON.parse($localStorage.remito || null); |
| 1272 | if (remito) { | 1227 | if (remito) { |
| 1273 | setearRemito(remito); | 1228 | setearRemito(remito); |
| 1274 | delete $localStorage.remito; | 1229 | delete $localStorage.remito; |
| 1275 | } | 1230 | } |
| 1276 | } | 1231 | } |
| 1277 | 1232 | ||
| 1278 | function getCabeceraPuntoDescarga(puntosDescarga) { | 1233 | function getCabeceraPuntoDescarga(puntosDescarga) { |
| 1279 | var puntosStamp = ''; | 1234 | var puntosStamp = ''; |
| 1280 | puntosDescarga.forEach(function (punto, idx, arr) { | 1235 | puntosDescarga.forEach(function (punto, idx, arr) { |
| 1281 | puntosStamp += punto.descripcion; | 1236 | puntosStamp += punto.descripcion; |
| 1282 | if ((idx + 1) !== arr.length) puntosStamp += ', '; | 1237 | if ((idx + 1) !== arr.length) puntosStamp += ', '; |
| 1283 | }); | 1238 | }); |
| 1284 | return puntosStamp; | 1239 | return puntosStamp; |
| 1285 | } | 1240 | } |
| 1286 | 1241 | ||
| 1287 | function abrirModalMail(id, cliente, numeroRemito) { | 1242 | function abrirModalMail(id, cliente, numeroRemito) { |
| 1288 | focaModalService.mail( | 1243 | focaModalService.mail( |
| 1289 | { | 1244 | { |
| 1290 | titulo: 'Comprobante de remito Nº ' + numeroRemito, | 1245 | titulo: 'Comprobante de remito Nº ' + numeroRemito, |
| 1291 | descarga: { | 1246 | descarga: { |
| 1292 | nombre: numeroRemito + '.pdf', | 1247 | nombre: numeroRemito + '.pdf', |
| 1293 | url: '/remito/comprobante', | 1248 | url: '/remito/comprobante', |
| 1294 | }, | 1249 | }, |
| 1295 | envio: { | 1250 | envio: { |
| 1296 | mailCliente: cliente.MAIL, | 1251 | mailCliente: cliente.MAIL, |
| 1297 | url: '/remito/mail', | 1252 | url: '/remito/mail', |
| 1298 | }, | 1253 | }, |
| 1299 | options: { | 1254 | options: { |
| 1300 | idRemito: id | 1255 | idRemito: id |
| 1301 | } | 1256 | } |
| 1302 | } | 1257 | } |
| 1303 | ) | 1258 | ) |
| 1304 | .then(function (res) { | 1259 | .then(function (res) { |
| 1305 | if (res === false) { | 1260 | if (res === false) { |
| 1306 | abrirModalMail(id); | 1261 | abrirModalMail(id); |
| 1307 | focaModalService.alert('Descarga o envíe su remito ' + | 1262 | focaModalService.alert('Descarga o envíe su remito ' + |
| 1308 | 'antes de cerrar esta ventana'); | 1263 | 'antes de cerrar esta ventana'); |
| 1309 | } | 1264 | } |
| 1310 | }); | 1265 | }); |
| 1311 | } | 1266 | } |
| 1312 | //recibo la propiedad por la cual quiero obtener el valor | 1267 | //recibo la propiedad por la cual quiero obtener el valor |
| 1313 | function getImporte(propiedad) { | 1268 | function getImporte(propiedad) { |
| 1314 | var importe = 0; | 1269 | var importe = 0; |
| 1315 | 1270 | ||
| 1316 | $scope.articulosFiltro().forEach(function (articulo) { | 1271 | $scope.articulosFiltro().forEach(function (articulo) { |
| 1317 | 1272 | ||
| 1318 | if (articulo[propiedad]) { | 1273 | if (articulo[propiedad]) { |
| 1319 | importe += articulo[propiedad] * articulo.cantidad; | 1274 | importe += articulo[propiedad] * articulo.cantidad; |
| 1320 | } | 1275 | } |
| 1321 | return; | 1276 | return; |
| 1322 | 1277 | ||
| 1323 | }); | 1278 | }); |
| 1324 | 1279 |