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