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