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