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"); } }
public Boolean AddDetractionToInvoice(ref string mensaje, decimal amountDetraction, string invoiceId, string userName) { BL_WorkFlow _blWorkFlow = new BL_WorkFlow(); _blWorkFlow.connectionString = connectionString; bool bOk = _blWorkFlow.NextWorkFlowStep(ref mensaje, 1, int.Parse(invoiceId), userName, false); if (bOk) { _database = new MySQLDatabase(connectionString); return(new DA_CostCenter(_database).AddDetractionToInvoice(amountDetraction, invoiceId)); } else { return(false); } }
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"); } }
/* * public VE_Invoice updateInvoiceGeneral(VE_Invoice _vE_Invoice) * { * _database = new MySQLDatabase(connectionString); * return new DA_Invoice(_database).updateInvoiceGeneral(_vE_Invoice); * }*/ public VE_Invoice updateInvoiceGeneral(VE_Invoice _VeInvoice) { _database = new MySQLDatabase(connectionString); BL_Option bL_Option = new BL_Option(this.connectionString); //bL_Option.connectionString = connectionString; var ok = bL_Option.ValidateOption(9, _VeInvoice.userName); if (ok == 0) { throw new ApplicationException("Ud. no cuenta con los permisos necesarios"); } if (_VeInvoice.documentId != null) { var numbers = _VeInvoice.documentId.Split('-'); if (numbers.Count() < 2) { throw new ApplicationException("Ingrese una factura válida"); } _VeInvoice.nroSerie = numbers[0]; _VeInvoice.nroComprobante = numbers[1]; } new DA_Invoice(_database).updateInvoiceGeneral(_VeInvoice); var invoice = new DA_Invoice(_database).getInvoiceGeneral(new BEInvoiceFilter { invoiceIdList = _VeInvoice.invoiceId }); if (_VeInvoice.invoiceStatusId != invoice[0].invoiceStatusId) { BL_WorkFlow _blWorkFlow = new BL_WorkFlow(); _blWorkFlow.connectionString = connectionString; var mensaje = ""; bool bOk = false; if (_VeInvoice.invoiceStatusId == 2) { bOk = _blWorkFlow.NextWorkFlowStep(ref mensaje, 9, int.Parse(_VeInvoice.invoiceId), _VeInvoice.userName, false); } else { bOk = _blWorkFlow.NextWorkFlowStep(ref mensaje, 1, int.Parse(_VeInvoice.invoiceId), _VeInvoice.userName, false); } if (!bOk) { throw new ApplicationException(mensaje); } } new DA_Invoice(_database).DeleteInvoiceDetailByInvoiceId(_VeInvoice.invoiceId); if (_VeInvoice.invoiceDetail != null) { foreach (VE_InvoiceDetail _veInvoiceDetail in _VeInvoice.invoiceDetail) { _veInvoiceDetail.invoiceId = int.Parse(_VeInvoice.invoiceId); new DA_Invoice(_database).createInvoiceDetail(_veInvoiceDetail); } } return(_VeInvoice); }
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"); } }
/*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"); } }