Exemplo n.º 1
0
        public BE_Payment RegisterClientPayment(BE_Payment _bePayment)
        {
            _database = new MySQLDatabase(connectionString);

            var mensaje = "";


            BL_WorkFlow bL_WorkFlow = new BL_WorkFlow();

            bL_WorkFlow.connectionString = connectionString;
            var bOK = bL_WorkFlow.NextWorkFlowStep(ref mensaje, 2, int.Parse(_bePayment.id), _bePayment.userName, false);

            if (bOK)
            {
                BE_Payment bE_Payment = new DA_Payment(_database).createPaymentSales(_bePayment);

                BL_Bank bL_Bank = new BL_Bank();
                bL_Bank.connectionString = connectionString;
                BE_BankAccount bE_BankAccountAux = bL_Bank.updateBalanceBankAccountByInvoice(int.Parse(_bePayment.id), _bePayment.bankAccountId);

                return(bE_Payment);
            }
            else
            {
                throw new ApplicationException("Ud. no cuenta con los privilegios necesarios");
            }
        }
Exemplo n.º 2
0
        public List <VE_PaymentAuth> getPaymentsAuthByCompanyCode(string companyCode)
        {
            _database = new MySQLDatabase(connectionString);
            List <VE_PaymentAuth> _lstPaymentAuth = new DA_Payment(_database).getPaymentsAuthByCompanyCode(companyCode);

            foreach (VE_PaymentAuth paymentAuth in _lstPaymentAuth)
            {
                paymentAuth.paymentAuthDetail = new DA_Payment(_database).getAuthorizedUserByPAID(paymentAuth.paymentAuthId);
            }

            return(_lstPaymentAuth);
        }
Exemplo n.º 3
0
        public BE_Payment createPaymentGeneral(BE_Payment bE_Payment)
        {
            _database = new MySQLDatabase(connectionString);
            var aux = new DA_Payment(_database).createPaymentGeneral(bE_Payment);

            if (bE_Payment.PaymentDetail != null)
            {
                foreach (var pd in bE_Payment.PaymentDetail)
                {
                    pd.idPayment = int.Parse(aux.paymentId.ToString());
                    CreatePaymentDetail(pd);
                }
            }

            return(aux);
        }
Exemplo n.º 4
0
        public BE_Payment CreateAdvance(BE_Payment _BePayment)
        {
            _database = new MySQLDatabase(connectionString);
            BE_PaymentAuth       _PaymentAuth       = new BE_PaymentAuth();
            BE_PaymentAuthDetail _paymentAuthDetail = new BE_PaymentAuthDetail();

            _PaymentAuth = new BE_PaymentAuth();
            _PaymentAuth.bankAccountId = (int)_BePayment.bankAccountId;
            _PaymentAuth.companyCode   = _BePayment.companyCode;
            _PaymentAuth.userName      = _BePayment.userName;
            _PaymentAuth.exchangeRate  = _BePayment.exchangeRate == null ? 0 : decimal.Parse(_BePayment.exchangeRate);

            var aux = new DA_Payment(_database).createPaymentAuth(_PaymentAuth);

            _BePayment.paymentAuthId = aux.paymentAuthId;
            var aux2 = new DA_Payment(_database).createPaymentGeneral(_BePayment);

            _BePayment.paymentId = aux2.paymentId;

            BE_PaymentDetail bE_PaymentDetail = new BE_PaymentDetail();

            bE_PaymentDetail.idPayment = int.Parse(_BePayment.paymentId.ToString());
            bE_PaymentDetail.amount    = _BePayment.amountTotal;

            new DA_Payment(_database).CreatePaymentDetail(bE_PaymentDetail);
            new DA_Bank(_database).updateBalanceBankAccountByPayment((int)_BePayment.paymentId, _BePayment.bankAccountId);

            _paymentAuthDetail = new BE_PaymentAuthDetail();
            _paymentAuthDetail.paymentAuthId = (int)_BePayment.paymentAuthId;
            _paymentAuthDetail.userAudit     = _BePayment.userName;
            _paymentAuthDetail = new DA_Payment(_database).createFirstPAD(_paymentAuthDetail);

            if (aux != null && aux2 != null)
            {
                return(_BePayment);
            }
            else
            {
                throw new Exception("Ocurrió un error al realizar la transacción");
            }
        }
Exemplo n.º 5
0
        public BE_PaymentAuthDetail CreatePaymentAuthDetail(BE_PaymentAuthDetail _BePaymentAuthDetail)
        {
            _database = new MySQLDatabase(connectionString);



            BE_PaymentAuthDetail        _BePAD                  = new DA_Payment(_database).createPaymentAuthDetail(_BePaymentAuthDetail);
            List <VE_PaymentAuth>       _lstVePaymentAuth       = getPaymentsAuthById(_BePAD.paymentAuthId);
            List <VE_PaymentAuthDetail> _lstVePaymentAuthDetail = GetValueUserByPaymentAuthId(_BePAD.paymentAuthId);



            BL_Usuario _blUsuario = new BL_Usuario();

            _blUsuario.connectionString = connectionString;
            List <VE_UserCompany> _lstVeUserCompany = _blUsuario.GetUserNameByCompanyCode(_lstVePaymentAuth[0].companyCode, _lstVePaymentAuth[0].paymentAuthId);

            if (_lstVeUserCompany.Count > 0)
            {
                if (_lstVePaymentAuthDetail.Count == _lstVeUserCompany[0].quantityAuth)
                {
                    UpdatePaymentAuthStatus(2, _lstVePaymentAuth[0].paymentAuthId);
                }
                else
                {
                    UpdatePaymentAuthStatus(1, _lstVePaymentAuth[0].paymentAuthId);
                }
            }
            List <VE_Payment>    _lstVePayments  = getPaymentsByAuthId(_BePAD.paymentAuthId);
            VE_PaymentAuthDetail _VePADUserAudit = GetUserAuditByPaymentAuthId(_BePAD.paymentAuthId);

            /*
             * int idMail = 4;
             * BE_Mail _BeMail = GetMailInfo(idMail);*/


            foreach (VE_UserCompany _veUserCompany in _lstVeUserCompany)
            {
                foreach (VE_PaymentAuthDetail _vePaymentAuthDetail in _lstVePaymentAuthDetail)
                {
                    if (_veUserCompany.quantityAuth != _lstVePaymentAuthDetail.Count)
                    {
                        if (_veUserCompany.userName != _vePaymentAuthDetail.userAudit)
                        {
                            string amounttotal = (_veUserCompany.amountTotal).ToString();
                            string paymentsQ   = (_lstVePayments.Count).ToString();
                            string paid        = (_BePAD.paymentAuthId).ToString();
                            //string paydate = (_lstVePaymentAuth[0].payDate).ToString();

                            /*
                             * string body = _BeMail.bodyMail;
                             * body = body.Replace("@FirstName", _veUserCompany.firstName);
                             * body = body.Replace("@LastName", _veUserCompany.lastName);
                             * body = body.Replace("@AmountTotal", amounttotal);
                             * body = body.Replace("@PayDate", _lstVePaymentAuth[0].payDateFormat);
                             * body = body.Replace("@PaymentsQ", paymentsQ);
                             * body = body.Replace("@Generator", _vePaymentAuthDetail.userAudit);
                             * body = body.Replace("@PAID", paid);
                             * body = body.Replace("@Banco", _lstVePaymentAuth[0].bankName);
                             * body = body.Replace("@shortBank", _lstVePaymentAuth[0].bankShortName);
                             * body = body.Replace("@tipoMoneda", _lstVePaymentAuth[0].currency);
                             */

                            //body = body.Replace("@n", "<br>");
                            //string body = "<em> HRTDASDASDASD!!</em>";

                            /*
                             * if (_veUserCompany.authorize==1){
                             *
                             *
                             *           BL_Mail _BlMail = new BL_Mail();
                             *              try
                             *              {
                             *
                             *                  _BlMail.SendEmail("*****@*****.**", _veUserCompany.email, _BeMail.subjectMail, body);
                             *              } catch                                { }
                             *        }*/
                        }
                    }
                    else
                    {
                        BL_Bank _blBank = new BL_Bank();
                        _blBank.connectionString = connectionString;
                        VE_BankAccount _updateBalaceBankAccount = _blBank.UpdateBalanceBankAccount(_lstVePaymentAuth[0].paymentAuthId);
                        return(_BePaymentAuthDetail);
                    }
                }
            }
            return(_BePaymentAuthDetail);
        }
Exemplo n.º 6
0
        public List <VE_Invoice> MakePaymentsDetailsPartials(List <VE_Invoice> _lstVeInvoice, BE_Payment _BePayment)
        {
            _database = new MySQLDatabase(connectionString);

            BE_PaymentAuthDetail _paymentAuthDetail = new BE_PaymentAuthDetail();

            BE_PaymentAuth _PaymentAuth = new BE_PaymentAuth();


            BL_WorkFlow _blWorkFlow = new BL_WorkFlow();

            _blWorkFlow.connectionString = connectionString;

            /*
             * foreach (VE_Invoice _veInvoice in _lstVeInvoice)
             * {
             *  _blWorkFlow = new BL_WorkFlow();
             *  _blWorkFlow.connectionString = connectionString;
             *  var mensaje = "";
             *  bool bOk = _blWorkFlow.NextWorkFlowStep(ref mensaje, 2, int.Parse(_veInvoice.invoiceId), _veInvoice.userName, false);
             *  //bool bOk = _blWorkFlow.NextWorkFlowStep(ref mensaje, 2, int.Parse(_veInvoice.invoiceId), "marko.polo", false);
             *
             *  if (!bOk)
             *  {
             *      throw new Exception(mensaje);
             *
             *  }
             * }
             */
            _PaymentAuth = new BE_PaymentAuth();
            _PaymentAuth.bankAccountId = (int)_BePayment.bankAccountId;
            _PaymentAuth.companyCode   = _BePayment.companyCode;
            _PaymentAuth.userName      = _BePayment.userName;
            _PaymentAuth.exchangeRate  = _BePayment.exchangeRate == null ? 0 : decimal.Parse(_BePayment.exchangeRate);

            var aux = new DA_Payment(_database).createPaymentAuth(_PaymentAuth);

            _BePayment.paymentAuthId = aux.paymentAuthId;
            var aux2 = new DA_Payment(_database).createPaymentGeneral(_BePayment);

            _BePayment.paymentId = aux2.paymentId;


            foreach (VE_Invoice _veInvoice in _lstVeInvoice)
            {
                BE_PaymentDetail bE_PaymentDetail = new BE_PaymentDetail();
                bE_PaymentDetail.idPayment = int.Parse(_BePayment.paymentId.ToString());
                bE_PaymentDetail.idInvoice = int.Parse(_veInvoice.invoiceId);
                bE_PaymentDetail.amount    = _veInvoice.amountPayment;

                new DA_Payment(_database).CreatePaymentDetail(bE_PaymentDetail);
                new DA_Bank(_database).updateBalanceBankAccountByPayment((int)_BePayment.paymentId, _BePayment.bankAccountId);

                _paymentAuthDetail = new BE_PaymentAuthDetail();
                _paymentAuthDetail.paymentAuthId = (int)_BePayment.paymentAuthId;
                _paymentAuthDetail.userAudit     = _BePayment.userName;
                _paymentAuthDetail = new DA_Payment(_database).createFirstPAD(_paymentAuthDetail);
            }

            if (aux != null)
            {
                return(_lstVeInvoice);
            }
            else
            {
                throw new Exception("Ocurrió un error al realizar la transacción");
            }
        }
Exemplo n.º 7
0
        public List <BE_Invoice> MakePaymentsDetails(List <VE_Invoice> _lstVeInvoice)
        {
            _database = new MySQLDatabase(connectionString);
            List <BE_Invoice>     _lstBeInvoice      = new List <BE_Invoice>();
            List <BE_PaymentAuth> _lstPaymentAuth    = new List <BE_PaymentAuth>();
            List <BE_PaymentAuth> _lstPaymentAuthAux = new List <BE_PaymentAuth>();
            BE_Payment            _payment           = new BE_Payment();
            BE_Invoice            _beInvoice         = new BE_Invoice();
            BE_PaymentAuthDetail  _paymentAuthDetail = new BE_PaymentAuthDetail();

            BL_WorkFlow _blWorkFlow = new BL_WorkFlow();

            _blWorkFlow.connectionString = connectionString;


            foreach (VE_Invoice _veInvoice in _lstVeInvoice)
            {
                _blWorkFlow = new BL_WorkFlow();
                _blWorkFlow.connectionString = connectionString;
                var  mensaje = "";
                bool bOk     = _blWorkFlow.NextWorkFlowStep(ref mensaje, 2, int.Parse(_veInvoice.invoiceId), _veInvoice.userName, false);
                //bool bOk = _blWorkFlow.NextWorkFlowStep(ref mensaje, 2, int.Parse(_veInvoice.invoiceId), "marko.polo", false);

                if (!bOk)
                {
                    throw new Exception(mensaje);
                }
            }

            foreach (VE_Invoice _veInvoice in _lstVeInvoice)
            {
                if (_lstPaymentAuth.Count() == 0)
                {
                    BE_PaymentAuth _PaymentAuth = new BE_PaymentAuth();
                    _PaymentAuth.bankAccountId = _veInvoice.bankAccountId;
                    _PaymentAuth.companyCode   = _veInvoice.companyCode;
                    _PaymentAuth.userName      = _veInvoice.userName;
                    //_PaymentAuth.userName = "";
                    _PaymentAuth.exchangeRate = _veInvoice.exchangeRate == null ? 0 : decimal.Parse(_lstVeInvoice[0].exchangeRate);
                    _lstPaymentAuthAux.Add(_PaymentAuth);
                    _lstPaymentAuth.AddRange(_lstPaymentAuthAux);
                }
                else
                {
                    var cont = 0;
                    foreach (BE_PaymentAuth bE_PaymentAuth in _lstPaymentAuth)
                    {
                        cont++;
                        if (bE_PaymentAuth.bankAccountId != _veInvoice.bankAccountId && cont == _lstPaymentAuth.Count())
                        {
                            BE_PaymentAuth _PaymentAuth = new BE_PaymentAuth();
                            _PaymentAuth.bankAccountId = _veInvoice.bankAccountId;
                            _PaymentAuth.companyCode   = _veInvoice.companyCode;
                            _PaymentAuth.userName      = _veInvoice.userName;
                            //_PaymentAuth.userName = "";
                            _PaymentAuth.exchangeRate = _veInvoice.exchangeRate == null ? 0 : decimal.Parse(_lstVeInvoice[0].exchangeRate);
                            _lstPaymentAuthAux.Add(_PaymentAuth);
                        }
                    }
                    _lstPaymentAuth = new List <BE_PaymentAuth>();
                    _lstPaymentAuth.AddRange(_lstPaymentAuthAux);
                }
            }
            _lstPaymentAuthAux = new List <BE_PaymentAuth>();
            foreach (BE_PaymentAuth bE_PaymentAuth in _lstPaymentAuth)
            {
                var aux = new DA_Payment(_database).createPaymentAuth(bE_PaymentAuth);

                _lstPaymentAuthAux.Add(aux);
            }
            _lstPaymentAuth = new List <BE_PaymentAuth>();
            _lstPaymentAuth.AddRange(_lstPaymentAuthAux);

            foreach (VE_Invoice _veInvoice in _lstVeInvoice)
            {
                _beInvoice = GetInvoiceById(_veInvoice.invoiceId);
                _lstBeInvoice.Add(new DA_Invoice(_database).payInvoviceDetail(_veInvoice));

                var cont = 0;
                foreach (BE_PaymentAuth bE_PaymentAuth in _lstPaymentAuth)
                {
                    cont++;
                    if (bE_PaymentAuth.bankAccountId == _veInvoice.bankAccountId)
                    {
                        bE_PaymentAuth.amountPaid           += _beInvoice.amountBalance;
                        bE_PaymentAuth.amountPaidPen        += _beInvoice.amountPaymentPen;
                        bE_PaymentAuth.amountDetractionPaid += _beInvoice.amountPaymentDetraction;

                        _payment = new BE_Payment();
                        _payment.paymentAuthId     = bE_PaymentAuth.paymentAuthId;
                        _payment.id                = _veInvoice.invoiceId;
                        _payment.bankId            = _veInvoice.bankId;
                        _payment.bankAccountId     = _veInvoice.bankAccountId;
                        _payment.bankAccountNumber = _veInvoice.bankAccountNumber;
                        _payment.userName          = _veInvoice.userName;
                        //_payment.userName = "";
                        _payment = new DA_Payment(_database).createPayment(_payment);


                        BE_PaymentDetail bE_PaymentDetail = new BE_PaymentDetail();
                        bE_PaymentDetail.idPayment = int.Parse(_payment.paymentId.ToString());
                        bE_PaymentDetail.idInvoice = int.Parse(_payment.id);
                        bE_PaymentDetail.amount    = _beInvoice.amountTotal;

                        new DA_Payment(_database).CreatePaymentDetail(bE_PaymentDetail);
                        new DA_Bank(_database).updateBalanceBankAccountByInvoice(int.Parse(_beInvoice.invoiceId), _veInvoice.bankAccountId);

                        _paymentAuthDetail = new BE_PaymentAuthDetail();
                        _paymentAuthDetail.paymentAuthId = bE_PaymentAuth.paymentAuthId;
                        _paymentAuthDetail.userAudit     = _veInvoice.userName;
                        //_paymentAuthDetail.userAudit = "";
                        _paymentAuthDetail = new DA_Payment(_database).createFirstPAD(_paymentAuthDetail);
                    }
                }
            }

            foreach (BE_PaymentAuth bE_PaymentAuth in _lstPaymentAuth)
            {
                var aux = new DA_Payment(_database).updatePaymentAuth(bE_PaymentAuth);
                _lstPaymentAuthAux = new List <BE_PaymentAuth>();
                _lstPaymentAuthAux.Add(aux);
            }
            _lstPaymentAuth = _lstPaymentAuthAux;
            if (_lstBeInvoice.Count > 0 && _payment != null && _lstPaymentAuth != null)
            {
                return(_lstBeInvoice);
            }
            else
            {
                throw new Exception("Ocurrió un error al realizar la transacción");
            }
        }
Exemplo n.º 8
0
        /*public List<BE_Invoice> MakePayments(List<VE_Invoice> _lstVeInvoice)
         * {
         *  _database = new MySQLDatabase(connectionString);
         *  if (_lstVeInvoice.Count == 0)
         *  {
         *      throw new Exception("La lista enviada no contiene elementos");
         *  }
         *
         *  List<BE_Invoice> _lstBeInvoice = new List<BE_Invoice>();
         *  BE_PaymentAuth _paymentAuth = new BE_PaymentAuth();
         *  BE_Payment _payment = new BE_Payment();
         *  BE_PaymentAuthDetail _paymentAuthDetail = new BE_PaymentAuthDetail();
         *  BL_WorkFlow _blWorkFlow = new BL_WorkFlow();
         *  BL_Usuario bL_Usuario = new BL_Usuario();
         *  bL_Usuario.connectionString = connectionString;
         *  List<BE_User> bE_Users = new List<BE_User>();
         *
         *  foreach (VE_Invoice _veInvoice in _lstVeInvoice)
         *  {
         *      _lstBeInvoice.AddRange(new DA_Invoice(_database).getInvoiceToPayBySum(_veInvoice));
         *      bE_Users.AddRange(bL_Usuario.GetUserGeneral(new BE_UserFilter { id = _veInvoice.userId }));
         *  }
         *
         *  if (_lstBeInvoice.Count > 0)
         *  {
         *      foreach (BE_Invoice _beInvoice in _lstBeInvoice)
         *      {
         *          _blWorkFlow = new BL_WorkFlow();
         *          _blWorkFlow.connectionString = connectionString;
         *          var mensaje = "";
         *          bool bOk = _blWorkFlow.NextWorkFlowStep(ref mensaje, 2, int.Parse(_beInvoice.invoiceId), bE_Users[0].userName, false);
         *
         *          if (!bOk)
         *          {
         *              throw new Exception(mensaje);
         *
         *          }
         *      }
         *
         *      foreach (BE_Invoice _beInvoice in _lstBeInvoice)
         *      {
         *          _paymentAuth.amountPaid += _beInvoice.amountBalance;
         *          _paymentAuth.amountPaidPen += _beInvoice.amountPaymentPen;
         *          _paymentAuth.amountDetractionPaid += _beInvoice.amountPaymentDetraction;
         *      }
         *
         *      _paymentAuth.bankAccountId = _lstVeInvoice[0].bankAccountId;
         *      _paymentAuth.companyCode = _lstVeInvoice[0].companyCode;
         *      _paymentAuth.exchangeRate = _lstBeInvoice[0].exchangeRate == null ? 0 : decimal.Parse(_lstBeInvoice[0].exchangeRate);
         *      _paymentAuth = new DA_Payment(_database).createPaymentAuth(_paymentAuth);
         *
         *      foreach (BE_Invoice _beInvoice in _lstBeInvoice)
         *      {
         *          _beInvoice.bankId = _lstVeInvoice[0].bankId;
         *          _beInvoice.bankAccountId = _lstVeInvoice[0].bankAccountId;
         *          _beInvoice.bankAccountNumber = _lstVeInvoice[0].bankAccountNumber;
         *          new DA_Invoice(_database).payInvovice(_beInvoice);
         *
         *          _payment = new BE_Payment();
         *          _payment.paymentAuthId = _paymentAuth.paymentAuthId;
         *          _payment.id = _beInvoice.invoiceId;
         *          _payment.bankId = _lstVeInvoice[0].bankId;
         *          _payment.bankAccountId = _lstVeInvoice[0].bankAccountId;
         *          _payment.bankAccountNumber = _lstVeInvoice[0].bankAccountNumber;
         *
         *          _payment = new DA_Payment(_database).createPayment(_payment);
         *
         *          new DA_Bank(_database).updateBalanceBankAccountAmountTotal(int.Parse(_beInvoice.invoiceId), _lstVeInvoice[0].bankAccountId);
         *
         *      }
         *
         *  }
         *  if (_lstBeInvoice.Count > 0 && _payment != null && _paymentAuth != null)
         *          return _lstBeInvoice;
         *      else
         *          throw new Exception("Ocurrió un error al realizar la transacción");
         *
         *
         * }*/

        public List <BE_Invoice> MakePayments(List <VE_Invoice> _lstVeInvoice)
        {
            _database = new MySQLDatabase(connectionString);
            if (_lstVeInvoice.Count == 0)
            {
                throw new Exception("La lista enviada no contiene elementos");
            }

            List <BE_Invoice> _lstBeInvoice = new List <BE_Invoice>();

            List <BE_PaymentAuth> _lstPaymentAuth    = new List <BE_PaymentAuth>();
            List <BE_PaymentAuth> _lstPaymentAuthAux = new List <BE_PaymentAuth>();
            BE_Payment            _payment           = new BE_Payment();
            BE_PaymentAuthDetail  _paymentAuthDetail = new BE_PaymentAuthDetail();
            BL_WorkFlow           _blWorkFlow        = new BL_WorkFlow();
            BL_Usuario            bL_Usuario         = new BL_Usuario();

            bL_Usuario.connectionString = connectionString;
            List <BE_User> bE_Users = new List <BE_User>();

            foreach (VE_Invoice _veInvoice in _lstVeInvoice)
            {
                _lstBeInvoice.AddRange(new DA_Invoice(_database).getInvoiceToPayBySum(_veInvoice));
                bE_Users.AddRange(bL_Usuario.GetUserGeneral(new BE_UserFilter {
                    id = _veInvoice.userId
                }));
            }

            if (_lstBeInvoice.Count > 0)
            {
                foreach (BE_Invoice _beInvoice in _lstBeInvoice)
                {
                    _blWorkFlow = new BL_WorkFlow();
                    _blWorkFlow.connectionString = connectionString;
                    var  mensaje = "";
                    bool bOk     = _blWorkFlow.NextWorkFlowStep(ref mensaje, 2, int.Parse(_beInvoice.invoiceId), bE_Users[0].userName, false);

                    if (!bOk)
                    {
                        throw new Exception(mensaje);
                    }
                }
                foreach (VE_Invoice _veInvoice in _lstVeInvoice)
                {
                    if (_lstPaymentAuth.Count() == 0)
                    {
                        BE_PaymentAuth _PaymentAuth = new BE_PaymentAuth();
                        _PaymentAuth.bankAccountId = _veInvoice.bankAccountId;
                        _PaymentAuth.companyCode   = _veInvoice.companyCode;
                        //_PaymentAuth.userName = _veInvoice.userName;
                        _PaymentAuth.userName     = "";
                        _PaymentAuth.memoryRuc    = _veInvoice.customerRuc;
                        _PaymentAuth.exchangeRate = _veInvoice.exchangeRate == null ? 0 : decimal.Parse(_lstVeInvoice[0].exchangeRate);
                        _lstPaymentAuthAux.Add(_PaymentAuth);
                        _lstPaymentAuth.AddRange(_lstPaymentAuthAux);
                    }
                    else
                    {
                        var cont = 0;
                        foreach (BE_PaymentAuth bE_PaymentAuth in _lstPaymentAuth)
                        {
                            cont++;
                            if ((bE_PaymentAuth.bankAccountId != _veInvoice.bankAccountId || !bE_PaymentAuth.memoryRuc.Equals(_veInvoice.customerRuc)) && cont == _lstPaymentAuth.Count())
                            {
                                BE_PaymentAuth _PaymentAuth = new BE_PaymentAuth();
                                _PaymentAuth.bankAccountId = _veInvoice.bankAccountId;
                                _PaymentAuth.companyCode   = _veInvoice.companyCode;
                                //_PaymentAuth.userName = _veInvoice.userName;
                                _PaymentAuth.userName     = "";
                                _PaymentAuth.memoryRuc    = _veInvoice.customerRuc;
                                _PaymentAuth.exchangeRate = _veInvoice.exchangeRate == null ? 0 : decimal.Parse(_lstVeInvoice[0].exchangeRate);
                                _lstPaymentAuthAux.Add(_PaymentAuth);
                            }
                        }
                        _lstPaymentAuth = new List <BE_PaymentAuth>();
                        _lstPaymentAuth.AddRange(_lstPaymentAuthAux);
                    }
                }


                _lstPaymentAuthAux = new List <BE_PaymentAuth>();
                foreach (BE_PaymentAuth bE_PaymentAuth in _lstPaymentAuth)
                {
                    var aux = new DA_Payment(_database).createPaymentAuth(bE_PaymentAuth);

                    _lstPaymentAuthAux.Add(aux);
                }
                _lstPaymentAuth = new List <BE_PaymentAuth>();
                _lstPaymentAuth.AddRange(_lstPaymentAuthAux);

                foreach (BE_Invoice _beInvoice in _lstBeInvoice)
                {
                    foreach (BE_PaymentAuth bE_PaymentAuth in _lstPaymentAuth)
                    {
                        if (bE_PaymentAuth.bankAccountId == _beInvoice.bankAccountId)
                        {
                            _beInvoice.bankId            = _lstVeInvoice[0].bankId;
                            _beInvoice.bankAccountId     = _lstVeInvoice[0].bankAccountId;
                            _beInvoice.bankAccountNumber = _lstVeInvoice[0].bankAccountNumber;
                            new DA_Invoice(_database).payInvovice(_beInvoice);

                            _payment = new BE_Payment();
                            _payment.paymentAuthId     = bE_PaymentAuth.paymentAuthId;
                            _payment.id                = _beInvoice.invoiceId;
                            _payment.bankId            = _lstVeInvoice[0].bankId;
                            _payment.bankAccountId     = _lstVeInvoice[0].bankAccountId;
                            _payment.bankAccountNumber = _lstVeInvoice[0].bankAccountNumber;

                            _payment = new DA_Payment(_database).createPayment(_payment);



                            new DA_Bank(_database).updateBalanceBankAccountByInvoice(int.Parse(_beInvoice.invoiceId), _lstVeInvoice[0].bankAccountId);

                            _paymentAuthDetail = new BE_PaymentAuthDetail();
                            _paymentAuthDetail.paymentAuthId = bE_PaymentAuth.paymentAuthId;
                            //_paymentAuthDetail.userAudit = _veInvoice.userName;
                            _paymentAuthDetail.userAudit = "";
                            _paymentAuthDetail           = new DA_Payment(_database).createFirstPAD(_paymentAuthDetail);
                        }
                    }
                }
            }
            if (_lstBeInvoice.Count > 0 && _payment != null && _lstPaymentAuth != null)
            {
                return(_lstBeInvoice);
            }
            else
            {
                throw new Exception("Ocurrió un error al realizar la transacción");
            }
        }