Commit 1d6ba7bafe7279e5e304c04c5b0f332746718249
1 parent
6b748181ee
Exists in
master
validación despachos
Showing
1 changed file
with
8 additions
and
0 deletions
Show diff stats
src/js/controller.js
| 1 | angular.module('focaCrearFactura').controller('facturaController', [ | 1 | angular.module('focaCrearFactura').controller('facturaController', [ |
| 2 | '$scope', '$uibModal', '$location', '$filter', 'crearFacturaService', '$timeout', | 2 | '$scope', '$uibModal', '$location', '$filter', 'crearFacturaService', '$timeout', |
| 3 | 'focaModalService', 'crearRemitoService', '$rootScope', 'focaBotoneraLateralService', | 3 | 'focaModalService', 'crearRemitoService', '$rootScope', 'focaBotoneraLateralService', |
| 4 | '$localStorage', 'APP', 'focaLoginService', | 4 | '$localStorage', 'APP', 'focaLoginService', |
| 5 | function ( | 5 | function ( |
| 6 | $scope, $uibModal, $location, $filter, crearFacturaService, $timeout, focaModalService, | 6 | $scope, $uibModal, $location, $filter, crearFacturaService, $timeout, focaModalService, |
| 7 | crearRemitoService, $rootScope, focaBotoneraLateralService, $localStorage, APP, loginServ) | 7 | crearRemitoService, $rootScope, focaBotoneraLateralService, $localStorage, APP, loginServ) |
| 8 | { | 8 | { |
| 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 = crearFacturaService.getBotonera(); | 15 | $scope.botonera = crearFacturaService.getBotonera(); |
| 16 | $scope.botoneraProductos = []; | 16 | $scope.botoneraProductos = []; |
| 17 | $scope.isNumber = angular.isNumber; | 17 | $scope.isNumber = angular.isNumber; |
| 18 | $scope.datepickerAbierto = false; | 18 | $scope.datepickerAbierto = false; |
| 19 | $scope.show = false; | 19 | $scope.show = false; |
| 20 | $scope.cargando = true; | 20 | $scope.cargando = true; |
| 21 | $scope.now = new Date(); | 21 | $scope.now = new Date(); |
| 22 | $scope.puntoVenta = rellenar(0, 4); | 22 | $scope.puntoVenta = rellenar(0, 4); |
| 23 | $scope.comprobante = rellenar(0, 8); | 23 | $scope.comprobante = rellenar(0, 8); |
| 24 | $scope.dateOptions = { | 24 | $scope.dateOptions = { |
| 25 | maxDate: new Date(), | 25 | maxDate: new Date(), |
| 26 | minDate: new Date(2010, 0, 1) | 26 | minDate: new Date(2010, 0, 1) |
| 27 | }; | 27 | }; |
| 28 | $scope.cabeceras = []; | 28 | $scope.cabeceras = []; |
| 29 | crearFacturaService.getParametros().then(function (res) { | 29 | crearFacturaService.getParametros().then(function (res) { |
| 30 | 30 | ||
| 31 | var parametros = JSON.parse(res.data[0].jsonText); | 31 | var parametros = JSON.parse(res.data[0].jsonText); |
| 32 | 32 | ||
| 33 | if ($localStorage.factura) { | 33 | if ($localStorage.factura) { |
| 34 | 34 | ||
| 35 | $timeout(function () { getLSFactura(); }); | 35 | $timeout(function () { getLSFactura(); }); |
| 36 | } else { | 36 | } else { |
| 37 | 37 | ||
| 38 | for (var property in parametros) { | 38 | for (var property in parametros) { |
| 39 | $scope.factura[property] = parametros[property]; | 39 | $scope.factura[property] = parametros[property]; |
| 40 | $scope.inicial[property] = parametros[property]; | 40 | $scope.inicial[property] = parametros[property]; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | setearFactura($scope.factura); | 43 | setearFactura($scope.factura); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | }); | 46 | }); |
| 47 | 47 | ||
| 48 | //SETEO BOTONERA LATERAL | 48 | //SETEO BOTONERA LATERAL |
| 49 | $timeout(function () { | 49 | $timeout(function () { |
| 50 | focaBotoneraLateralService.showSalir(false); | 50 | focaBotoneraLateralService.showSalir(false); |
| 51 | focaBotoneraLateralService.showPausar(true); | 51 | focaBotoneraLateralService.showPausar(true); |
| 52 | focaBotoneraLateralService.showGuardar(true, $scope.seleccionarFormaDePago); | 52 | focaBotoneraLateralService.showGuardar(true, $scope.seleccionarFormaDePago); |
| 53 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 53 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 54 | }); | 54 | }); |
| 55 | 55 | ||
| 56 | init(); | 56 | init(); |
| 57 | 57 | ||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | function init() { | 60 | function init() { |
| 61 | 61 | ||
| 62 | $scope.$broadcast('cleanCabecera'); | 62 | $scope.$broadcast('cleanCabecera'); |
| 63 | 63 | ||
| 64 | $scope.factura = { | 64 | $scope.factura = { |
| 65 | id: 0, | 65 | id: 0, |
| 66 | estado: 0, | 66 | estado: 0, |
| 67 | vendedor: {}, | 67 | vendedor: {}, |
| 68 | cliente: {}, | 68 | cliente: {}, |
| 69 | proveedor: {}, | 69 | proveedor: {}, |
| 70 | domicilio: { dom: '' }, | 70 | domicilio: { dom: '' }, |
| 71 | moneda: {}, | 71 | moneda: {}, |
| 72 | cotizacion: $scope.cotizacionPorDefecto || {}, | 72 | cotizacion: $scope.cotizacionPorDefecto || {}, |
| 73 | articulosFactura: [], | 73 | articulosFactura: [], |
| 74 | despachos: [] | 74 | despachos: [] |
| 75 | }; | 75 | }; |
| 76 | 76 | ||
| 77 | $scope.factura.articulosFactura = []; | 77 | $scope.factura.articulosFactura = []; |
| 78 | $scope.idLista = undefined; | 78 | $scope.idLista = undefined; |
| 79 | 79 | ||
| 80 | crearRemitoService.getNumeroRemito().then( | 80 | crearRemitoService.getNumeroRemito().then( |
| 81 | function (res) { | 81 | function (res) { |
| 82 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 82 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
| 83 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); | 83 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); |
| 84 | }, | 84 | }, |
| 85 | function (err) { | 85 | function (err) { |
| 86 | focaModalService.alert('La terminal no esta configurada correctamente'); | 86 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 87 | console.info(err); | 87 | console.info(err); |
| 88 | } | 88 | } |
| 89 | ); | 89 | ); |
| 90 | 90 | ||
| 91 | $scope.inicial = angular.copy($scope.factura); | 91 | $scope.inicial = angular.copy($scope.factura); |
| 92 | 92 | ||
| 93 | if (APP == 'facturador') { | 93 | if (APP == 'facturador') { |
| 94 | crearFacturaService | 94 | crearFacturaService |
| 95 | .getVendedorPlayaById(loginServ.getLoginData().vendedorPlaya) | 95 | .getVendedorPlayaById(loginServ.getLoginData().vendedorPlaya) |
| 96 | .then(function (res) { | 96 | .then(function (res) { |
| 97 | 97 | ||
| 98 | validarPlanillaVendedor(res.data) | 98 | validarPlanillaVendedor(res.data) |
| 99 | .then(function () { | 99 | .then(function () { |
| 100 | 100 | ||
| 101 | $scope.$broadcast('addCabecera', { | 101 | $scope.$broadcast('addCabecera', { |
| 102 | label: 'Vendedor:', | 102 | label: 'Vendedor:', |
| 103 | valor: $filter('rellenarDigitos')(res.data.CodVen, 3) + | 103 | valor: $filter('rellenarDigitos')(res.data.CodVen, 3) + |
| 104 | ' - ' + | 104 | ' - ' + |
| 105 | res.data.NomVen | 105 | res.data.NomVen |
| 106 | }); | 106 | }); |
| 107 | 107 | ||
| 108 | $scope.factura.vendedor = res.data; | 108 | $scope.factura.vendedor = res.data; |
| 109 | $scope.inicial.vendedor = res.data; | ||
| 109 | 110 | ||
| 110 | getProductosByPlanilla(res.data.NplVen); | 111 | getProductosByPlanilla(res.data.NplVen); |
| 111 | }) | 112 | }) |
| 112 | .catch(function (err) { | 113 | .catch(function (err) { |
| 113 | console.log(err); | 114 | console.log(err); |
| 114 | focaModalService.alert('Ocurrió un error al intentar recuperar' + | 115 | focaModalService.alert('Ocurrió un error al intentar recuperar' + |
| 115 | 'el vendedor logeado'); | 116 | 'el vendedor logeado'); |
| 116 | }); | 117 | }); |
| 117 | }) | 118 | }) |
| 118 | } | 119 | } |
| 119 | } | 120 | } |
| 120 | 121 | ||
| 121 | $scope.$watch('factura', function (newValue) { | 122 | $scope.$watch('factura', function (newValue) { |
| 122 | focaBotoneraLateralService.setPausarData({ | 123 | focaBotoneraLateralService.setPausarData({ |
| 123 | label: 'factura', | 124 | label: 'factura', |
| 124 | val: newValue | 125 | val: newValue |
| 125 | }); | 126 | }); |
| 126 | }, true); | 127 | }, true); |
| 127 | 128 | ||
| 128 | $scope.seleccionarFormaDePago = function () { | 129 | $scope.seleccionarFormaDePago = function () { |
| 129 | if (!validarGuardar()) return; | 130 | if (!validarGuardar()) return; |
| 130 | var modalInstance = $uibModal.open( | 131 | var modalInstance = $uibModal.open( |
| 131 | { | 132 | { |
| 132 | templateUrl: 'modal-forma-pago.html', | 133 | templateUrl: 'modal-forma-pago.html', |
| 133 | controller: 'focaModalFormaPagoController', | 134 | controller: 'focaModalFormaPagoController', |
| 134 | resolve: { | 135 | resolve: { |
| 135 | parametros: function () { | 136 | parametros: function () { |
| 136 | return { | 137 | return { |
| 137 | importe: $scope.getTotal() | 138 | importe: $scope.getTotal() |
| 138 | }; | 139 | }; |
| 139 | }, | 140 | }, |
| 140 | }, | 141 | }, |
| 141 | size: 'lg', | 142 | size: 'lg', |
| 142 | } | 143 | } |
| 143 | ); | 144 | ); |
| 144 | modalInstance.result | 145 | modalInstance.result |
| 145 | .then(function (data) { | 146 | .then(function (data) { |
| 146 | 147 | ||
| 147 | $scope.crearFactura(data); | 148 | $scope.crearFactura(data); |
| 148 | }) | 149 | }) |
| 149 | .catch(function (e) { console.error(e); }); | 150 | .catch(function (e) { console.error(e); }); |
| 150 | }; | 151 | }; |
| 151 | 152 | ||
| 152 | $scope.crearFactura = function (formaPago) { | 153 | $scope.crearFactura = function (formaPago) { |
| 153 | 154 | ||
| 154 | var save = { | 155 | var save = { |
| 155 | factura: { | 156 | factura: { |
| 156 | 157 | ||
| 157 | BONIF: 0, | 158 | BONIF: 0, |
| 158 | CLI: $scope.factura.cliente.cod, | 159 | CLI: $scope.factura.cliente.cod, |
| 159 | CUI: $scope.factura.cliente.cuit, | 160 | CUI: $scope.factura.cliente.cuit, |
| 160 | CTA: $scope.factura.cliente.cod, | 161 | CTA: $scope.factura.cliente.cod, |
| 161 | DC1: '', | 162 | DC1: '', |
| 162 | DC2: '', | 163 | DC2: '', |
| 163 | DE1: '', | 164 | DE1: '', |
| 164 | DOM: $scope.factura.cliente.DOM, | 165 | DOM: $scope.factura.cliente.DOM, |
| 165 | FACAUT: 0, | 166 | FACAUT: 0, |
| 166 | DTO: 0, | 167 | DTO: 0, |
| 167 | FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'), | 168 | FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'), |
| 168 | FEC_ANT: '19000101', | 169 | FEC_ANT: '19000101', |
| 169 | FPA: 0, // 0 <- Múltiple formas de pago, 2 cta corriente | 170 | FPA: 0, // 0 <- Múltiple formas de pago, 2 cta corriente |
| 170 | IDEXCEPCION: 0, | 171 | IDEXCEPCION: 0, |
| 171 | IDLP: $scope.factura.cliente.mod.trim() || 0, | 172 | IDLP: $scope.factura.cliente.mod.trim() || 0, |
| 172 | IDPERSONERIA: 0, | 173 | IDPERSONERIA: 0, |
| 173 | IMI: 0, // TODO | 174 | IMI: 0, // TODO |
| 174 | IMI2: 0, // TODO | 175 | IMI2: 0, // TODO |
| 175 | IMI3: 0, // TODO | 176 | IMI3: 0, // TODO |
| 176 | IMP_LEY: 0, | 177 | IMP_LEY: 0, |
| 177 | IRI: 0, // TODO | 178 | IRI: 0, // TODO |
| 178 | IRS: 0, | 179 | IRS: 0, |
| 179 | LEG: '', | 180 | LEG: '', |
| 180 | LUG: $scope.factura.vendedor.LugVen, | 181 | LUG: $scope.factura.vendedor.LugVen, |
| 181 | MK_M: 0, | 182 | MK_M: 0, |
| 182 | NEE: 0, // TODO | 183 | NEE: 0, // TODO |
| 183 | NET: 0, // TODO | 184 | NET: 0, // TODO |
| 184 | NFI: '', | 185 | NFI: '', |
| 185 | NNP: 0, | 186 | NNP: 0, |
| 186 | NOM: $scope.factura.cliente.nom, | 187 | NOM: $scope.factura.cliente.nom, |
| 187 | OPE: $scope.factura.vendedor.CodVen, | 188 | OPE: $scope.factura.vendedor.CodVen, |
| 188 | PAG: $scope.getTotal(), | 189 | PAG: $scope.getTotal(), |
| 189 | PER: 0, | 190 | PER: 0, |
| 190 | PER_IVA: 0, | 191 | PER_IVA: 0, |
| 191 | PLA: $scope.factura.vendedor.NplVen, | 192 | PLA: $scope.factura.vendedor.NplVen, |
| 192 | PRO: '', | 193 | PRO: '', |
| 193 | REC_ANT: 0, | 194 | REC_ANT: 0, |
| 194 | SUC: parseInt($scope.puntoVenta), | 195 | SUC: parseInt($scope.puntoVenta), |
| 195 | TCA: 1, | 196 | TCA: 1, |
| 196 | TCO: 'FT', | 197 | TCO: 'FT', |
| 197 | TFI: '', | 198 | TFI: '', |
| 198 | TIP: $scope.factura.cliente.tipoFactura, | 199 | TIP: $scope.factura.cliente.tipoFactura, |
| 199 | TIV: 0, // TODO | 200 | TIV: 0, // TODO |
| 200 | TOT: $scope.getTotal(), | 201 | TOT: $scope.getTotal(), |
| 201 | TUR: 0, // TODO | 202 | TUR: 0, // TODO |
| 202 | VEN: $scope.factura.vendedor.CodVen, | 203 | VEN: $scope.factura.vendedor.CodVen, |
| 203 | VTO_CLI: '', | 204 | VTO_CLI: '', |
| 204 | ZON: 1, // TODO | 205 | ZON: 1, // TODO |
| 205 | OBSERVACIONES: $scope.factura.observaciones | 206 | OBSERVACIONES: $scope.factura.observaciones |
| 206 | }, | 207 | }, |
| 207 | cuerpo: $scope.articulosFiltro(), | 208 | cuerpo: $scope.articulosFiltro(), |
| 208 | despachos: $scope.factura.despachos, | 209 | despachos: $scope.factura.despachos, |
| 209 | formaPago: formaPago | 210 | formaPago: formaPago |
| 210 | }; | 211 | }; |
| 211 | 212 | ||
| 212 | crearFacturaService.guardarFactura(save).then(function (res) { | 213 | crearFacturaService.guardarFactura(save).then(function (res) { |
| 213 | 214 | ||
| 214 | focaBotoneraLateralService.endGuardar(true); | 215 | focaBotoneraLateralService.endGuardar(true); |
| 215 | 216 | ||
| 216 | focaModalService.alert('Comprobante guardado con éxito'); | 217 | focaModalService.alert('Comprobante guardado con éxito'); |
| 217 | 218 | ||
| 218 | config(); | 219 | config(); |
| 219 | 220 | ||
| 220 | }).catch(function (err) { | 221 | }).catch(function (err) { |
| 221 | focaModalService.alert('Hubo un error al guardar la factura'); | 222 | focaModalService.alert('Hubo un error al guardar la factura'); |
| 222 | console.error(err); | 223 | console.error(err); |
| 223 | }); | 224 | }); |
| 224 | 225 | ||
| 225 | }; | 226 | }; |
| 226 | 227 | ||
| 227 | $scope.seleccionarCliente = function () { | 228 | $scope.seleccionarCliente = function () { |
| 228 | 229 | ||
| 229 | var modalInstance = $uibModal.open( | 230 | var modalInstance = $uibModal.open( |
| 230 | { | 231 | { |
| 231 | ariaLabelledBy: 'Busqueda de Cliente', | 232 | ariaLabelledBy: 'Busqueda de Cliente', |
| 232 | templateUrl: 'foca-busqueda-cliente-modal.html', | 233 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 233 | controller: 'focaBusquedaClienteModalController', | 234 | controller: 'focaBusquedaClienteModalController', |
| 234 | resolve: { | 235 | resolve: { |
| 235 | vendedor: function () { return null; }, | 236 | vendedor: function () { return null; }, |
| 236 | cobrador: function () { return null; } | 237 | cobrador: function () { return null; } |
| 237 | }, | 238 | }, |
| 238 | size: 'lg' | 239 | size: 'lg' |
| 239 | } | 240 | } |
| 240 | ); | 241 | ); |
| 241 | modalInstance.result.then( | 242 | modalInstance.result.then( |
| 242 | function (cliente) { | 243 | function (cliente) { |
| 243 | var modalInstance = $uibModal.open( | 244 | var modalInstance = $uibModal.open( |
| 244 | { | 245 | { |
| 245 | templateUrl: 'modal-estado-cuenta.html', | 246 | templateUrl: 'modal-estado-cuenta.html', |
| 246 | controller: 'focaModalEstadoCuentaController', | 247 | controller: 'focaModalEstadoCuentaController', |
| 247 | size: 'lg', | 248 | size: 'lg', |
| 248 | resolve: { | 249 | resolve: { |
| 249 | parametros: function () { return { idCliente: cliente.cod }; }, | 250 | parametros: function () { return { idCliente: cliente.cod }; }, |
| 250 | } | 251 | } |
| 251 | } | 252 | } |
| 252 | ); | 253 | ); |
| 253 | modalInstance.result | 254 | modalInstance.result |
| 254 | .then(function (data) { | 255 | .then(function (data) { |
| 255 | 256 | ||
| 256 | $scope.factura.cliente = cliente; | 257 | $scope.factura.cliente = cliente; |
| 257 | 258 | ||
| 258 | $scope.$broadcast('addCabecera', { | 259 | $scope.$broadcast('addCabecera', { |
| 259 | label: 'Cliente:', | 260 | label: 'Cliente:', |
| 260 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + | 261 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + |
| 261 | ' - ' + cliente.nom | 262 | ' - ' + cliente.nom |
| 262 | }); | 263 | }); |
| 263 | 264 | ||
| 264 | $filter('filter')($scope.botonera, | 265 | $filter('filter')($scope.botonera, |
| 265 | { label: 'Cliente' })[0].checked = true; | 266 | { label: 'Cliente' })[0].checked = true; |
| 266 | 267 | ||
| 267 | $scope.$broadcast('addCabecera', { | 268 | $scope.$broadcast('addCabecera', { |
| 268 | label: 'Tipo de pago: ', | 269 | label: 'Tipo de pago: ', |
| 269 | valor: data | 270 | valor: data |
| 270 | }); | 271 | }); |
| 271 | }) | 272 | }) |
| 272 | .catch(function () { | 273 | .catch(function () { |
| 273 | 274 | ||
| 274 | $scope.seleccionarCliente(); | 275 | $scope.seleccionarCliente(); |
| 275 | }); | 276 | }); |
| 276 | 277 | ||
| 277 | }, function () { | 278 | }, function () { |
| 278 | } | 279 | } |
| 279 | ); | 280 | ); |
| 280 | 281 | ||
| 281 | }; | 282 | }; |
| 282 | 283 | ||
| 283 | $scope.seleccionarVendedor = function () { | 284 | $scope.seleccionarVendedor = function () { |
| 284 | var parametrosModal = { | 285 | var parametrosModal = { |
| 285 | titulo: 'Búsqueda vendedores', | 286 | titulo: 'Búsqueda vendedores', |
| 286 | query: '/vendedor-playa', | 287 | query: '/vendedor-playa', |
| 287 | columnas: [ | 288 | columnas: [ |
| 288 | { | 289 | { |
| 289 | propiedad: 'CodVen', | 290 | propiedad: 'CodVen', |
| 290 | nombre: 'Código', | 291 | nombre: 'Código', |
| 291 | filtro: { | 292 | filtro: { |
| 292 | nombre: 'rellenarDigitos', | 293 | nombre: 'rellenarDigitos', |
| 293 | parametro: 3 | 294 | parametro: 3 |
| 294 | } | 295 | } |
| 295 | }, | 296 | }, |
| 296 | { | 297 | { |
| 297 | propiedad: 'NomVen', | 298 | propiedad: 'NomVen', |
| 298 | nombre: 'Nombre' | 299 | nombre: 'Nombre' |
| 299 | } | 300 | } |
| 300 | ], | 301 | ], |
| 301 | size: 'md' | 302 | size: 'md' |
| 302 | }; | 303 | }; |
| 303 | focaModalService.modal(parametrosModal).then( | 304 | focaModalService.modal(parametrosModal).then( |
| 304 | function (vendedor) { | 305 | function (vendedor) { |
| 305 | 306 | ||
| 306 | indicarPassword(vendedor) | 307 | indicarPassword(vendedor) |
| 307 | .then(function () { | 308 | .then(function () { |
| 308 | validarPlanillaVendedor(vendedor) | 309 | validarPlanillaVendedor(vendedor) |
| 309 | .then(function () { | 310 | .then(function () { |
| 310 | 311 | ||
| 311 | $filter('filter')($scope.botonera, { | 312 | $filter('filter')($scope.botonera, { |
| 312 | label: 'Vendedor' | 313 | label: 'Vendedor' |
| 313 | })[0].checked = true; | 314 | })[0].checked = true; |
| 314 | 315 | ||
| 315 | $scope.$broadcast('addCabecera', { | 316 | $scope.$broadcast('addCabecera', { |
| 316 | label: 'Vendedor:', | 317 | label: 'Vendedor:', |
| 317 | valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + | 318 | valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + |
| 318 | ' - ' + | 319 | ' - ' + |
| 319 | vendedor.NomVen | 320 | vendedor.NomVen |
| 320 | }); | 321 | }); |
| 321 | 322 | ||
| 322 | $scope.factura.vendedor = vendedor; | 323 | $scope.factura.vendedor = vendedor; |
| 323 | 324 | ||
| 324 | getProductosByPlanilla(vendedor.NplVen); | 325 | getProductosByPlanilla(vendedor.NplVen); |
| 325 | }) | 326 | }) |
| 326 | .catch($scope.seleccionarVendedor); | 327 | .catch($scope.seleccionarVendedor); |
| 327 | }) | 328 | }) |
| 328 | .catch(function (err) { | 329 | .catch(function (err) { |
| 329 | console.error(err); | 330 | console.error(err); |
| 330 | }); | 331 | }); |
| 331 | 332 | ||
| 332 | }, function () { } | 333 | }, function () { } |
| 333 | ); | 334 | ); |
| 334 | }; | 335 | }; |
| 335 | 336 | ||
| 336 | $scope.seleccionarMoneda = function () { | 337 | $scope.seleccionarMoneda = function () { |
| 337 | 338 | ||
| 338 | var parametrosModal = { | 339 | var parametrosModal = { |
| 339 | titulo: 'Búsqueda de monedas', | 340 | titulo: 'Búsqueda de monedas', |
| 340 | query: '/moneda', | 341 | query: '/moneda', |
| 341 | columnas: [ | 342 | columnas: [ |
| 342 | { | 343 | { |
| 343 | propiedad: 'DETALLE', | 344 | propiedad: 'DETALLE', |
| 344 | nombre: 'Nombre' | 345 | nombre: 'Nombre' |
| 345 | }, | 346 | }, |
| 346 | { | 347 | { |
| 347 | propiedad: 'SIMBOLO', | 348 | propiedad: 'SIMBOLO', |
| 348 | nombre: 'Símbolo' | 349 | nombre: 'Símbolo' |
| 349 | } | 350 | } |
| 350 | ], | 351 | ], |
| 351 | size: 'md' | 352 | size: 'md' |
| 352 | }; | 353 | }; |
| 353 | focaModalService.modal(parametrosModal).then( | 354 | focaModalService.modal(parametrosModal).then( |
| 354 | function (moneda) { | 355 | function (moneda) { |
| 355 | 356 | ||
| 356 | if (moneda.ID !== 1) { | 357 | if (moneda.ID !== 1) { |
| 357 | $scope.abrirModalCotizacion(moneda); | 358 | $scope.abrirModalCotizacion(moneda); |
| 358 | return; | 359 | return; |
| 359 | } | 360 | } |
| 360 | 361 | ||
| 361 | crearRemitoService.getCotizacionByIdMoneda(1) | 362 | crearRemitoService.getCotizacionByIdMoneda(1) |
| 362 | .then(function (res) { | 363 | .then(function (res) { |
| 363 | 364 | ||
| 364 | var cotizacionPArgentino = res.data[0].cotizaciones[0]; | 365 | var cotizacionPArgentino = res.data[0].cotizaciones[0]; |
| 365 | cotizacionPArgentino.moneda = moneda; | 366 | cotizacionPArgentino.moneda = moneda; |
| 366 | 367 | ||
| 367 | actualizarCabeceraMoneda(cotizacionPArgentino); | 368 | actualizarCabeceraMoneda(cotizacionPArgentino); |
| 368 | 369 | ||
| 369 | $scope.remito.cotizacion = cotizacionPArgentino; | 370 | $scope.remito.cotizacion = cotizacionPArgentino; |
| 370 | }); | 371 | }); |
| 371 | }, function () { | 372 | }, function () { |
| 372 | 373 | ||
| 373 | } | 374 | } |
| 374 | ); | 375 | ); |
| 375 | }; | 376 | }; |
| 376 | 377 | ||
| 377 | $scope.abrirModalCotizacion = function (moneda) { | 378 | $scope.abrirModalCotizacion = function (moneda) { |
| 378 | var modalInstance = $uibModal.open( | 379 | var modalInstance = $uibModal.open( |
| 379 | { | 380 | { |
| 380 | ariaLabelledBy: 'Busqueda de Cotización', | 381 | ariaLabelledBy: 'Busqueda de Cotización', |
| 381 | templateUrl: 'modal-cotizacion.html', | 382 | templateUrl: 'modal-cotizacion.html', |
| 382 | controller: 'focaModalCotizacionController', | 383 | controller: 'focaModalCotizacionController', |
| 383 | size: 'lg', | 384 | size: 'lg', |
| 384 | resolve: { idMoneda: function () { return moneda.ID; } } | 385 | resolve: { idMoneda: function () { return moneda.ID; } } |
| 385 | } | 386 | } |
| 386 | ); | 387 | ); |
| 387 | modalInstance.result.then( | 388 | modalInstance.result.then( |
| 388 | function (cotizacion) { | 389 | function (cotizacion) { |
| 389 | 390 | ||
| 390 | cotizacion.moneda = moneda; | 391 | cotizacion.moneda = moneda; |
| 391 | actualizarCabeceraMoneda(cotizacion); | 392 | actualizarCabeceraMoneda(cotizacion); |
| 392 | $scope.factura.cotizacion = cotizacion; | 393 | $scope.factura.cotizacion = cotizacion; |
| 393 | 394 | ||
| 394 | }, function () { | 395 | }, function () { |
| 395 | 396 | ||
| 396 | } | 397 | } |
| 397 | ); | 398 | ); |
| 398 | }; | 399 | }; |
| 399 | 400 | ||
| 400 | $scope.seleccionarObservaciones = function () { | 401 | $scope.seleccionarObservaciones = function () { |
| 401 | var observacion = { | 402 | var observacion = { |
| 402 | titulo: 'Ingrese Observaciones', | 403 | titulo: 'Ingrese Observaciones', |
| 403 | value: $scope.factura.observaciones, | 404 | value: $scope.factura.observaciones, |
| 404 | maxlength: 155, | 405 | maxlength: 155, |
| 405 | textarea: true | 406 | textarea: true |
| 406 | }; | 407 | }; |
| 407 | 408 | ||
| 408 | focaModalService | 409 | focaModalService |
| 409 | .prompt(observacion) | 410 | .prompt(observacion) |
| 410 | .then(function (observaciones) { | 411 | .then(function (observaciones) { |
| 411 | $scope.factura.observaciones = observaciones; | 412 | $scope.factura.observaciones = observaciones; |
| 412 | }); | 413 | }); |
| 413 | }; | 414 | }; |
| 414 | 415 | ||
| 415 | $scope.articulosFiltro = function () { | 416 | $scope.articulosFiltro = function () { |
| 416 | return $scope.factura.articulosFactura.filter(function (articulo) { | 417 | return $scope.factura.articulosFactura.filter(function (articulo) { |
| 417 | return !articulo.desactivado; | 418 | return !articulo.desactivado; |
| 418 | }); | 419 | }); |
| 419 | }; | 420 | }; |
| 420 | 421 | ||
| 421 | $scope.getTotal = function () { | 422 | $scope.getTotal = function () { |
| 422 | 423 | ||
| 423 | var total = 0; | 424 | var total = 0; |
| 424 | 425 | ||
| 425 | $scope.articulosFiltro().forEach(function (articulo) { | 426 | $scope.articulosFiltro().forEach(function (articulo) { |
| 426 | total += articulo.PUN * articulo.CAN; | 427 | total += articulo.PUN * articulo.CAN; |
| 427 | }); | 428 | }); |
| 428 | 429 | ||
| 429 | return parseFloat(total.toFixed(2)); | 430 | return parseFloat(total.toFixed(2)); |
| 430 | }; | 431 | }; |
| 431 | 432 | ||
| 432 | $scope.quitarDespacho = function (articulo, index) { | 433 | $scope.quitarDespacho = function (articulo, index) { |
| 433 | 434 | ||
| 434 | crearFacturaService | 435 | crearFacturaService |
| 435 | .setearDespachoDesocupado({ | 436 | .setearDespachoDesocupado({ |
| 436 | surtidor: $scope.factura.despachos[index].SUR, | 437 | surtidor: $scope.factura.despachos[index].SUR, |
| 437 | producto: $scope.factura.despachos[index].PRO, | 438 | producto: $scope.factura.despachos[index].PRO, |
| 438 | carga: $scope.factura.despachos[index].CAR, | 439 | carga: $scope.factura.despachos[index].CAR, |
| 439 | planilla: $scope.factura.despachos[index].PLA | 440 | planilla: $scope.factura.despachos[index].PLA |
| 440 | }) | 441 | }) |
| 441 | .then(function () { | 442 | .then(function () { |
| 442 | articulo.desactivado = true; | 443 | articulo.desactivado = true; |
| 443 | $scope.factura.despachos.splice(index, 1); | 444 | $scope.factura.despachos.splice(index, 1); |
| 444 | }) | 445 | }) |
| 445 | .catch(function () { | 446 | .catch(function () { |
| 446 | focaModalService.alert('Hubo un error al desasociar este despacho'); | 447 | focaModalService.alert('Hubo un error al desasociar este despacho'); |
| 447 | }); | 448 | }); |
| 448 | }; | 449 | }; |
| 449 | 450 | ||
| 450 | function getProductosByPlanilla(numeroPlanilla) { | 451 | function getProductosByPlanilla(numeroPlanilla) { |
| 451 | 452 | ||
| 452 | crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function (res) { | 453 | crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function (res) { |
| 454 | |||
| 455 | if (!res.data.length) { | ||
| 456 | |||
| 457 | focaModalService.alert('No hay despachos disponibles por el momento'); | ||
| 458 | return; | ||
| 459 | } | ||
| 460 | |||
| 453 | $scope.botoneraProductos.length = 0; | 461 | $scope.botoneraProductos.length = 0; |
| 454 | res.data.forEach(function (producto) { | 462 | res.data.forEach(function (producto) { |
| 455 | 463 | ||
| 456 | $scope.botoneraProductos.push({ | 464 | $scope.botoneraProductos.push({ |
| 457 | label: producto.DetArt, | 465 | label: producto.DetArt, |
| 458 | image: producto.nombreImagen, | 466 | image: producto.nombreImagen, |
| 459 | imageDefault: 'productoDefault.png' | 467 | imageDefault: 'productoDefault.png' |
| 460 | }); | 468 | }); |
| 461 | 469 | ||
| 462 | 470 | ||
| 463 | crearFuncionesProductos(producto); | 471 | crearFuncionesProductos(producto); |
| 464 | 472 | ||
| 465 | }); | 473 | }); |
| 466 | $scope.botoneraProductos.push({ | 474 | $scope.botoneraProductos.push({ |
| 467 | label: 'Busqueda Productos', | 475 | label: 'Busqueda Productos', |
| 468 | image: 'buscarProductos.png', | 476 | image: 'buscarProductos.png', |
| 469 | imageDefault: 'productoDefault.png' | 477 | imageDefault: 'productoDefault.png' |
| 470 | }); | 478 | }); |
| 471 | }); | 479 | }); |
| 472 | } | 480 | } |
| 473 | 481 | ||
| 474 | $scope.seleccionarBusquedaProductos = function () { | 482 | $scope.seleccionarBusquedaProductos = function () { |
| 475 | 483 | ||
| 476 | var modalInstance = $uibModal.open( | 484 | var modalInstance = $uibModal.open( |
| 477 | { | 485 | { |
| 478 | ariaLabelledBy: 'Busqueda de Productos', | 486 | ariaLabelledBy: 'Busqueda de Productos', |
| 479 | templateUrl: 'modal-busqueda-productos.html', | 487 | templateUrl: 'modal-busqueda-productos.html', |
| 480 | controller: 'modalBusquedaProductosCtrl', | 488 | controller: 'modalBusquedaProductosCtrl', |
| 481 | resolve: { | 489 | resolve: { |
| 482 | parametroProducto: { | 490 | parametroProducto: { |
| 483 | idLista: null, | 491 | idLista: null, |
| 484 | cotizacion: $scope.factura.cotizacion.VENDEDOR, | 492 | cotizacion: $scope.factura.cotizacion.VENDEDOR, |
| 485 | simbolo: $scope.factura.cotizacion.moneda.SIMBOLO, | 493 | simbolo: $scope.factura.cotizacion.moneda.SIMBOLO, |
| 486 | buscarTodos: true | 494 | buscarTodos: true |
| 487 | } | 495 | } |
| 488 | }, | 496 | }, |
| 489 | size: 'lg' | 497 | size: 'lg' |
| 490 | } | 498 | } |
| 491 | ); | 499 | ); |
| 492 | 500 | ||
| 493 | modalInstance.result | 501 | modalInstance.result |
| 494 | .then(function (producto) { | 502 | .then(function (producto) { |
| 495 | 503 | ||
| 496 | var articulo = { | 504 | var articulo = { |
| 497 | TIP: $scope.factura.cliente.tipoFactura, | 505 | TIP: $scope.factura.cliente.tipoFactura, |
| 498 | TCO: 'FT', | 506 | TCO: 'FT', |
| 499 | SUC: parseInt($scope.puntoVenta), | 507 | SUC: parseInt($scope.puntoVenta), |
| 500 | ORD: $scope.articulosFiltro().length + 1, | 508 | ORD: $scope.articulosFiltro().length + 1, |
| 501 | SEC: producto.sector, | 509 | SEC: producto.sector, |
| 502 | ART: producto.codigo, | 510 | ART: producto.codigo, |
| 503 | RUB: producto.CodRub, | 511 | RUB: producto.CodRub, |
| 504 | DES: producto.descripcionLarga, | 512 | DES: producto.descripcionLarga, |
| 505 | PUN: producto.precio, // TODO | 513 | PUN: producto.precio, // TODO |
| 506 | IVA: producto.IMPIVA, // TODO | 514 | IVA: producto.IMPIVA, // TODO |
| 507 | NET: 0, // TODO | 515 | NET: 0, // TODO |
| 508 | NEX: 0, // TODO | 516 | NEX: 0, // TODO |
| 509 | IMI: producto.ImpInt, // TODO | 517 | IMI: producto.ImpInt, // TODO |
| 510 | IMI2: producto.ImpInt2, // TODO | 518 | IMI2: producto.ImpInt2, // TODO |
| 511 | IMI3: producto.ImpInt3, // TODO | 519 | IMI3: producto.ImpInt3, // TODO |
| 512 | PUT: producto.PreNet, // TODO | 520 | PUT: producto.PreNet, // TODO |
| 513 | SUR: 0, | 521 | SUR: 0, |
| 514 | PLA: $scope.factura.vendedor.NplVen, | 522 | PLA: $scope.factura.vendedor.NplVen, |
| 515 | LUG: $scope.factura.vendedor.LugVen, | 523 | LUG: $scope.factura.vendedor.LugVen, |
| 516 | LEG: $scope.factura.vendedor.CodVen, | 524 | LEG: $scope.factura.vendedor.CodVen, |
| 517 | TUR: $scope.factura.vendedor.TurVen, | 525 | TUR: $scope.factura.vendedor.TurVen, |
| 518 | ORDEN_PRECOMPRA: '', | 526 | ORDEN_PRECOMPRA: '', |
| 519 | ESC: producto.tipoFactura === 'L' ? 1 : 0, | 527 | ESC: producto.tipoFactura === 'L' ? 1 : 0, |
| 520 | CMF: 0, | 528 | CMF: 0, |
| 521 | PTA: 0, | 529 | PTA: 0, |
| 522 | IVS: 0, | 530 | IVS: 0, |
| 523 | TIVA: 0, | 531 | TIVA: 0, |
| 524 | CON: 0, | 532 | CON: 0, |
| 525 | SINO: '', | 533 | SINO: '', |
| 526 | ORD_TRA: 0, | 534 | ORD_TRA: 0, |
| 527 | IMP_DESP: 0, | 535 | IMP_DESP: 0, |
| 528 | PCD: 0, | 536 | PCD: 0, |
| 529 | RTO: '' | 537 | RTO: '' |
| 530 | }; | 538 | }; |
| 531 | // crearFacturaService.setearDespachoOcupado({ | 539 | // crearFacturaService.setearDespachoOcupado({ |
| 532 | // surtidor: articulo.SUR, | 540 | // surtidor: articulo.SUR, |
| 533 | // producto: articulo.PRO, | 541 | // producto: articulo.PRO, |
| 534 | // carga: articulo.CAR | 542 | // carga: articulo.CAR |
| 535 | // }) | 543 | // }) |
| 536 | // .then(function () { | 544 | // .then(function () { |
| 537 | $scope.factura.articulosFactura.push(articulo); | 545 | $scope.factura.articulosFactura.push(articulo); |
| 538 | $scope.cambioEdit(articulo, 'cantidad'); | 546 | $scope.cambioEdit(articulo, 'cantidad'); |
| 539 | // }) | 547 | // }) |
| 540 | // .catch(function (err) { | 548 | // .catch(function (err) { |
| 541 | 549 | ||
| 542 | // focaModalService.alert('El despacho esta en uso'); | 550 | // focaModalService.alert('El despacho esta en uso'); |
| 543 | // }); | 551 | // }); |
| 544 | }) | 552 | }) |
| 545 | .catch(function (e) { console.error(e); }); | 553 | .catch(function (e) { console.error(e); }); |
| 546 | }; | 554 | }; |
| 547 | 555 | ||
| 548 | function crearFuncionesProductos(producto) { | 556 | function crearFuncionesProductos(producto) { |
| 549 | 557 | ||
| 550 | $scope[nombreFuncion(producto.DetArt)] = function () { | 558 | $scope[nombreFuncion(producto.DetArt)] = function () { |
| 551 | 559 | ||
| 552 | if (angular.equals($scope.factura.cliente, {})) { | 560 | if (angular.equals($scope.factura.cliente, {})) { |
| 553 | focaModalService.alert('Seleccione cliente'); | 561 | focaModalService.alert('Seleccione cliente'); |
| 554 | return; | 562 | return; |
| 555 | } | 563 | } |
| 556 | 564 | ||
| 557 | var modalInstance = $uibModal.open( | 565 | var modalInstance = $uibModal.open( |
| 558 | { | 566 | { |
| 559 | templateUrl: 'modal-combustibles.html', | 567 | templateUrl: 'modal-combustibles.html', |
| 560 | controller: 'focaModalCombustiblesController', | 568 | controller: 'focaModalCombustiblesController', |
| 561 | resolve: { | 569 | resolve: { |
| 562 | parametros: function () { | 570 | parametros: function () { |
| 563 | return { | 571 | return { |
| 564 | despachos: producto.despachos, | 572 | despachos: producto.despachos, |
| 565 | nombreProducto: producto.DetArt | 573 | nombreProducto: producto.DetArt |
| 566 | }; | 574 | }; |
| 567 | } | 575 | } |
| 568 | }, | 576 | }, |
| 569 | size: 'md' | 577 | size: 'md' |
| 570 | } | 578 | } |
| 571 | ); | 579 | ); |
| 572 | 580 | ||
| 573 | modalInstance.result.then(function (despacho) { | 581 | modalInstance.result.then(function (despacho) { |
| 574 | 582 | ||
| 575 | var articulo = { | 583 | var articulo = { |
| 576 | TIP: $scope.factura.cliente.tipoFactura, | 584 | TIP: $scope.factura.cliente.tipoFactura, |
| 577 | TCO: 'FT', | 585 | TCO: 'FT', |
| 578 | SUC: parseInt($scope.puntoVenta), | 586 | SUC: parseInt($scope.puntoVenta), |
| 579 | ORD: $scope.articulosFiltro().length + 1, | 587 | ORD: $scope.articulosFiltro().length + 1, |
| 580 | SEC: despacho.SEC, | 588 | SEC: despacho.SEC, |
| 581 | ART: despacho.PRO, | 589 | ART: despacho.PRO, |
| 582 | RUB: producto.CodRub, | 590 | RUB: producto.CodRub, |
| 583 | DES: producto.DetArt, | 591 | DES: producto.DetArt, |
| 584 | CAN: despacho.LTS, | 592 | CAN: despacho.LTS, |
| 585 | PUN: producto.PreVen, // TODO | 593 | PUN: producto.PreVen, // TODO |
| 586 | IVA: producto.IMPIVA, // TODO | 594 | IVA: producto.IMPIVA, // TODO |
| 587 | NET: 0, // TODO | 595 | NET: 0, // TODO |
| 588 | NEX: 0, // TODO | 596 | NEX: 0, // TODO |
| 589 | IMI: producto.ImpInt, // TODO | 597 | IMI: producto.ImpInt, // TODO |
| 590 | IMI2: producto.ImpInt2, // TODO | 598 | IMI2: producto.ImpInt2, // TODO |
| 591 | IMI3: producto.ImpInt3, // TODO | 599 | IMI3: producto.ImpInt3, // TODO |
| 592 | PUT: producto.PreNet, // TODO | 600 | PUT: producto.PreNet, // TODO |
| 593 | SUR: despacho.SUR, | 601 | SUR: despacho.SUR, |
| 594 | PLA: despacho.PLA, | 602 | PLA: despacho.PLA, |
| 595 | LUG: despacho.LUG, | 603 | LUG: despacho.LUG, |
| 596 | LEG: $scope.factura.vendedor.CodVen, | 604 | LEG: $scope.factura.vendedor.CodVen, |
| 597 | TUR: $scope.factura.vendedor.TurVen, | 605 | TUR: $scope.factura.vendedor.TurVen, |
| 598 | ORDEN_PRECOMPRA: '', | 606 | ORDEN_PRECOMPRA: '', |
| 599 | ESC: producto.tipoFactura === 'L' ? 1 : 0, | 607 | ESC: producto.tipoFactura === 'L' ? 1 : 0, |
| 600 | CMF: 0, | 608 | CMF: 0, |
| 601 | PTA: 0, | 609 | PTA: 0, |
| 602 | IVS: 0, | 610 | IVS: 0, |
| 603 | TIVA: 0, | 611 | TIVA: 0, |
| 604 | CON: 0, | 612 | CON: 0, |
| 605 | SINO: '', | 613 | SINO: '', |
| 606 | ORD_TRA: 0, | 614 | ORD_TRA: 0, |
| 607 | IMP_DESP: 0, | 615 | IMP_DESP: 0, |
| 608 | PCD: 0, | 616 | PCD: 0, |
| 609 | RTO: '' | 617 | RTO: '' |
| 610 | }; | 618 | }; |
| 611 | 619 | ||
| 612 | crearFacturaService.setearDespachoOcupado({ | 620 | crearFacturaService.setearDespachoOcupado({ |
| 613 | surtidor: despacho.SUR, | 621 | surtidor: despacho.SUR, |
| 614 | producto: despacho.PRO, | 622 | producto: despacho.PRO, |
| 615 | carga: despacho.CAR | 623 | carga: despacho.CAR |
| 616 | }) | 624 | }) |
| 617 | .then(function () { | 625 | .then(function () { |
| 618 | $scope.factura.articulosFactura.push(articulo); | 626 | $scope.factura.articulosFactura.push(articulo); |
| 619 | $scope.factura.despachos.push(despacho); | 627 | $scope.factura.despachos.push(despacho); |
| 620 | }) | 628 | }) |
| 621 | .catch(function (err) { | 629 | .catch(function (err) { |
| 622 | 630 | ||
| 623 | console.error(err); | 631 | console.error(err); |
| 624 | focaModalService.alert('El despacho esta en uso'); | 632 | focaModalService.alert('El despacho esta en uso'); |
| 625 | }); | 633 | }); |
| 626 | 634 | ||
| 627 | }) | 635 | }) |
| 628 | .catch(function (err) { | 636 | .catch(function (err) { |
| 629 | console.error(err); | 637 | console.error(err); |
| 630 | }); | 638 | }); |
| 631 | 639 | ||
| 632 | }; | 640 | }; |
| 633 | } | 641 | } |
| 634 | 642 | ||
| 635 | function nombreFuncion(string) { | 643 | function nombreFuncion(string) { |
| 636 | var texto = 'seleccionar'; | 644 | var texto = 'seleccionar'; |
| 637 | var arr = string.split(' '); | 645 | var arr = string.split(' '); |
| 638 | arr.forEach(function (palabra) { | 646 | arr.forEach(function (palabra) { |
| 639 | palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); | 647 | palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); |
| 640 | texto += palabra; | 648 | texto += palabra; |
| 641 | }); | 649 | }); |
| 642 | return texto; | 650 | return texto; |
| 643 | } | 651 | } |
| 644 | 652 | ||
| 645 | function indicarPassword(vendedor) { | 653 | function indicarPassword(vendedor) { |
| 646 | 654 | ||
| 647 | return new Promise(function (resolve, reject) { | 655 | return new Promise(function (resolve, reject) { |
| 648 | 656 | ||
| 649 | focaModalService | 657 | focaModalService |
| 650 | .prompt({ | 658 | .prompt({ |
| 651 | titulo: 'Indique Contraseña', | 659 | titulo: 'Indique Contraseña', |
| 652 | value: '' | 660 | value: '' |
| 653 | }) | 661 | }) |
| 654 | .then(function (contraseña) { | 662 | .then(function (contraseña) { |
| 655 | 663 | ||
| 656 | if (contraseña !== vendedor.ClaVen.trim()) { | 664 | if (contraseña !== vendedor.ClaVen.trim()) { |
| 657 | 665 | ||
| 658 | focaModalService.alert('Clave incorrecta').then(function () { | 666 | focaModalService.alert('Clave incorrecta').then(function () { |
| 659 | indicarPassword(vendedor); | 667 | indicarPassword(vendedor); |
| 660 | }); | 668 | }); |
| 661 | } else { | 669 | } else { |
| 662 | resolve(); | 670 | resolve(); |
| 663 | } | 671 | } |
| 664 | }) | 672 | }) |
| 665 | .catch(reject); | 673 | .catch(reject); |
| 666 | }); | 674 | }); |
| 667 | } | 675 | } |
| 668 | 676 | ||
| 669 | function validarPlanillaVendedor(vendedor) { | 677 | function validarPlanillaVendedor(vendedor) { |
| 670 | 678 | ||
| 671 | return new Promise(function (resolve, reject) { | 679 | return new Promise(function (resolve, reject) { |
| 672 | 680 | ||
| 673 | crearFacturaService | 681 | crearFacturaService |
| 674 | .validarPlanillaVendedor(vendedor.CodVen.toString().trim()) | 682 | .validarPlanillaVendedor(vendedor.CodVen.toString().trim()) |
| 675 | .then(function (res) { | 683 | .then(function (res) { |
| 676 | 684 | ||
| 677 | if (!res.data.length) { | 685 | if (!res.data.length) { |
| 678 | 686 | ||
| 679 | focaModalService | 687 | focaModalService |
| 680 | .alert('No se encontró planilla abierta para el vendedor') | 688 | .alert('No se encontró planilla abierta para el vendedor') |
| 681 | .then(reject); | 689 | .then(reject); |
| 682 | 690 | ||
| 683 | } else { | 691 | } else { |
| 684 | resolve(); | 692 | resolve(); |
| 685 | } | 693 | } |
| 686 | 694 | ||
| 687 | }) | 695 | }) |
| 688 | .catch(function (err) { | 696 | .catch(function (err) { |
| 689 | console.log(err) | 697 | console.log(err) |
| 690 | reject(); | 698 | reject(); |
| 691 | }); | 699 | }); |
| 692 | }); | 700 | }); |
| 693 | } | 701 | } |
| 694 | 702 | ||
| 695 | function rellenar(relleno, longitud) { | 703 | function rellenar(relleno, longitud) { |
| 696 | relleno = '' + relleno; | 704 | relleno = '' + relleno; |
| 697 | while (relleno.length < longitud) { | 705 | while (relleno.length < longitud) { |
| 698 | relleno = '0' + relleno; | 706 | relleno = '0' + relleno; |
| 699 | } | 707 | } |
| 700 | return relleno; | 708 | return relleno; |
| 701 | } | 709 | } |
| 702 | 710 | ||
| 703 | function salir() { | 711 | function salir() { |
| 704 | var confirmacion = false; | 712 | var confirmacion = false; |
| 705 | 713 | ||
| 706 | if (!angular.equals($scope.factura, $scope.inicial)) { | 714 | if (!angular.equals($scope.factura, $scope.inicial)) { |
| 707 | confirmacion = true; | 715 | confirmacion = true; |
| 708 | } | 716 | } |
| 709 | 717 | ||
| 710 | if (confirmacion) { | 718 | if (confirmacion) { |
| 711 | focaModalService.confirm( | 719 | focaModalService.confirm( |
| 712 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 720 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 713 | ).then(function (data) { | 721 | ).then(function (data) { |
| 714 | if (data) { | 722 | if (data) { |
| 715 | $location.path('/'); | 723 | $location.path('/'); |
| 716 | } | 724 | } |
| 717 | }); | 725 | }); |
| 718 | } else { | 726 | } else { |
| 719 | $location.path('/'); | 727 | $location.path('/'); |
| 720 | } | 728 | } |
| 721 | } | 729 | } |
| 722 | 730 | ||
| 723 | function setearFactura(factura) { | 731 | function setearFactura(factura) { |
| 724 | 732 | ||
| 725 | $scope.$broadcast('cleanCabecera'); | 733 | $scope.$broadcast('cleanCabecera'); |
| 726 | 734 | ||
| 727 | $scope.cabeceras = []; | 735 | $scope.cabeceras = []; |
| 728 | 736 | ||
| 729 | if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 737 | if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') { |
| 730 | $scope.cabeceras.push({ | 738 | $scope.cabeceras.push({ |
| 731 | label: 'Moneda:', | 739 | label: 'Moneda:', |
| 732 | valor: factura.cotizacion.moneda.DETALLE | 740 | valor: factura.cotizacion.moneda.DETALLE |
| 733 | }); | 741 | }); |
| 734 | $scope.cabeceras.push({ | 742 | $scope.cabeceras.push({ |
| 735 | label: 'Fecha cotizacion:', | 743 | label: 'Fecha cotizacion:', |
| 736 | valor: $filter('date')(factura.cotizacion.FECHA, | 744 | valor: $filter('date')(factura.cotizacion.FECHA, |
| 737 | 'dd/MM/yyyy') | 745 | 'dd/MM/yyyy') |
| 738 | }); | 746 | }); |
| 739 | $scope.cabeceras.push({ | 747 | $scope.cabeceras.push({ |
| 740 | label: 'Cotizacion:', | 748 | label: 'Cotizacion:', |
| 741 | valor: $filter('number')(factura.cotizacion.VENDEDOR, | 749 | valor: $filter('number')(factura.cotizacion.VENDEDOR, |
| 742 | '2') | 750 | '2') |
| 743 | }); | 751 | }); |
| 744 | } | 752 | } |
| 745 | 753 | ||
| 746 | if (factura.cotizacion && factura.cotizacion.moneda) { | 754 | if (factura.cotizacion && factura.cotizacion.moneda) { |
| 747 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; | 755 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; |
| 748 | } | 756 | } |
| 749 | 757 | ||
| 750 | if (factura.cliente && factura.cliente.cod) { | 758 | if (factura.cliente && factura.cliente.cod) { |
| 751 | $scope.cabeceras.push({ | 759 | $scope.cabeceras.push({ |
| 752 | label: 'Cliente:', | 760 | label: 'Cliente:', |
| 753 | valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' + | 761 | valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' + |
| 754 | factura.cliente.nom | 762 | factura.cliente.nom |
| 755 | }); | 763 | }); |
| 756 | 764 | ||
| 757 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; | 765 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; |
| 758 | } | 766 | } |
| 759 | 767 | ||
| 760 | $scope.puntoVenta = rellenar(factura.sucursal, 4); | 768 | $scope.puntoVenta = rellenar(factura.sucursal, 4); |
| 761 | $scope.comprobante = rellenar(factura.numerofactura, 8); | 769 | $scope.comprobante = rellenar(factura.numerofactura, 8); |
| 762 | $scope.factura = factura; | 770 | $scope.factura = factura; |
| 763 | 771 | ||
| 764 | addArrayCabecera($scope.cabeceras); | 772 | addArrayCabecera($scope.cabeceras); |
| 765 | } | 773 | } |
| 766 | 774 | ||
| 767 | function getLSFactura() { | 775 | function getLSFactura() { |
| 768 | var factura = JSON.parse($localStorage.factura || null); | 776 | var factura = JSON.parse($localStorage.factura || null); |
| 769 | if (factura) { | 777 | if (factura) { |
| 770 | setearFactura(factura); | 778 | setearFactura(factura); |
| 771 | delete $localStorage.factura; | 779 | delete $localStorage.factura; |
| 772 | } | 780 | } |
| 773 | } | 781 | } |
| 774 | 782 | ||
| 775 | function addArrayCabecera(array) { | 783 | function addArrayCabecera(array) { |
| 776 | for (var i = 0; i < array.length; i++) { | 784 | for (var i = 0; i < array.length; i++) { |
| 777 | $scope.$broadcast('addCabecera', { | 785 | $scope.$broadcast('addCabecera', { |
| 778 | label: array[i].label, | 786 | label: array[i].label, |
| 779 | valor: array[i].valor | 787 | valor: array[i].valor |
| 780 | }); | 788 | }); |
| 781 | } | 789 | } |
| 782 | } | 790 | } |
| 783 | 791 | ||
| 784 | $scope.cambioEdit = function (articulo, propiedad) { | 792 | $scope.cambioEdit = function (articulo, propiedad) { |
| 785 | if (propiedad === 'cantidad') { | 793 | if (propiedad === 'cantidad') { |
| 786 | articulo.editCantidad = true; | 794 | articulo.editCantidad = true; |
| 787 | } | 795 | } |
| 788 | }; | 796 | }; |
| 789 | 797 | ||
| 790 | $scope.editarArticulo = function (key, articulo, tmpCantidad) { | 798 | $scope.editarArticulo = function (key, articulo, tmpCantidad) { |
| 791 | if (key === 13) { | 799 | if (key === 13) { |
| 792 | if (!articulo.cantidad && !tmpCantidad) { | 800 | if (!articulo.cantidad && !tmpCantidad) { |
| 793 | focaModalService.alert('Los valores deben ser al menos 1'); | 801 | focaModalService.alert('Los valores deben ser al menos 1'); |
| 794 | return; | 802 | return; |
| 795 | } else if (tmpCantidad === '0') { | 803 | } else if (tmpCantidad === '0') { |
| 796 | focaModalService.alert('Esta ingresando un producto con valor 0'); | 804 | focaModalService.alert('Esta ingresando un producto con valor 0'); |
| 797 | } else if (articulo.cantidad < 0) { | 805 | } else if (articulo.cantidad < 0) { |
| 798 | focaModalService.alert('Los valores no pueden ser negativos'); | 806 | focaModalService.alert('Los valores no pueden ser negativos'); |
| 799 | return; | 807 | return; |
| 800 | } | 808 | } |
| 801 | articulo.CAN = parseInt(tmpCantidad); | 809 | articulo.CAN = parseInt(tmpCantidad); |
| 802 | $scope.getTotal(); | 810 | $scope.getTotal(); |
| 803 | articulo.editCantidad = false; | 811 | articulo.editCantidad = false; |
| 804 | } | 812 | } |
| 805 | }; | 813 | }; |
| 806 | 814 | ||
| 807 | $scope.cancelarEditar = function (articulo) { | 815 | $scope.cancelarEditar = function (articulo) { |
| 808 | $scope.tmpCantidad = articulo.CAN; | 816 | $scope.tmpCantidad = articulo.CAN; |
| 809 | articulo.editCantidad = false; | 817 | articulo.editCantidad = false; |
| 810 | }; | 818 | }; |
| 811 | 819 | ||
| 812 | function actualizarCabeceraMoneda(cotizacion) { | 820 | function actualizarCabeceraMoneda(cotizacion) { |
| 813 | 821 | ||
| 814 | $scope.factura.articulosFactura.forEach(function (art) { | 822 | $scope.factura.articulosFactura.forEach(function (art) { |
| 815 | art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4); | 823 | art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4); |
| 816 | art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4); | 824 | art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4); |
| 817 | }); | 825 | }); |
| 818 | 826 | ||
| 819 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | 827 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { |
| 820 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 828 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
| 821 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 829 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
| 822 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 830 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
| 823 | } else { | 831 | } else { |
| 824 | $scope.$broadcast('addCabecera', { | 832 | $scope.$broadcast('addCabecera', { |
| 825 | label: 'Moneda:', | 833 | label: 'Moneda:', |
| 826 | valor: cotizacion.moneda.DETALLE | 834 | valor: cotizacion.moneda.DETALLE |
| 827 | }); | 835 | }); |
| 828 | $scope.$broadcast('addCabecera', { | 836 | $scope.$broadcast('addCabecera', { |
| 829 | label: 'Fecha cotizacion:', | 837 | label: 'Fecha cotizacion:', |
| 830 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 838 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
| 831 | }); | 839 | }); |
| 832 | $scope.$broadcast('addCabecera', { | 840 | $scope.$broadcast('addCabecera', { |
| 833 | label: 'Cotizacion:', | 841 | label: 'Cotizacion:', |
| 834 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 842 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
| 835 | }); | 843 | }); |
| 836 | } | 844 | } |
| 837 | } | 845 | } |
| 838 | 846 | ||
| 839 | function validarGuardar() { | 847 | function validarGuardar() { |
| 840 | 848 | ||
| 841 | if (angular.equals({}, $scope.factura.vendedor)) { | 849 | if (angular.equals({}, $scope.factura.vendedor)) { |
| 842 | 850 | ||
| 843 | focaModalService.alert('Seleccione Vendedor'); | 851 | focaModalService.alert('Seleccione Vendedor'); |
| 844 | return false; | 852 | return false; |
| 845 | } else if (angular.equals({}, $scope.factura.cliente)) { | 853 | } else if (angular.equals({}, $scope.factura.cliente)) { |
| 846 | 854 | ||
| 847 | focaModalService.alert('Seleccione Cliente'); | 855 | focaModalService.alert('Seleccione Cliente'); |
| 848 | return false; | 856 | return false; |
| 849 | } else if (!$scope.articulosFiltro().length) { | 857 | } else if (!$scope.articulosFiltro().length) { |
| 850 | 858 | ||
| 851 | focaModalService.alert('Seleccione al menos un Articulo'); | 859 | focaModalService.alert('Seleccione al menos un Articulo'); |
| 852 | return false; | 860 | return false; |
| 853 | } | 861 | } |
| 854 | 862 | ||
| 855 | return true; | 863 | return true; |
| 856 | } | 864 | } |
| 857 | } | 865 | } |
| 858 | ]); | 866 | ]); |
| 859 | 867 |