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