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