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