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