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