示例#1
0
        public BE_Json GetUserGeneral(BE_UserFilter bE_UserFilter)
        {
            BE_Json objJson     = null;
            var     objListaAux = string.Empty;

            try
            {
                BL_Usuario _blUsuario = new BL_Usuario();
                _blUsuario.connectionString = AppConfig.DbConnection;
                objListaAux = JsonConvert.SerializeObject(_blUsuario.GetUserGeneral(bE_UserFilter));

                objJson        = new BE_Json();
                objJson.data   = objListaAux;
                objJson.status = CManager.RESULTADO_WCF.OK;
            }
            catch (Exception ex)
            {
                objJson        = new BE_Json();
                objJson.data   = "Hubo en error en servidor:" + ex.Message + ";" + ex.StackTrace + ";" + ex.ToString();
                objJson.status = CManager.RESULTADO_WCF.ERROR;
                objJson.status = CManager.RESULTADO_WCF.ERROR;
            }
            finally
            {
                objListaAux = null;
            }
            return(objJson);
        }
示例#2
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");
            }
        }