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