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