public void Should_return_lists_of_transactions() { _batchHeaderDTO = _batch.GetPayerBatch(9650); IList<PaymentDTO> list = CreatePayments(); _batchHeaderDTO = _batch.IdentifyTransactionTypes(list); Assert.That(_batch.Transactions.Count > 0); }
public void SetupResult() { _mockery = new MockRepository(); _dataAccessMock = _mockery.CreateMock<DataAccess>(); _batch = new Batch(_dataAccessMock); _batchHeaderDTO = _mockery.CreateMock<BatchHeaderDTO>(); }
public BatchHeaderDTO GetBatchHeader(string ledgerType, int key) { IDataManager manager = SqlDataManager.UniqueInstance; string name; int thisKey = 0; DateTime? arDate = null; string userAdded = ""; DateTime? dateAdded = null; double sumPayments = 0; int countPayments = 0; string payerCheckNumber = ""; double payerCheckAmount = 0; DateTime? payerCheckDate = null; double sumCommissionPayments = 0; int countCommissionPayments = 0; double sumUnidentifiedPayments = 0; int countUnidentifiedPayments = 0; double sumOpenCreditPayments = 0; int countOpenCreditPayments = 0; BatchHeaderDTO batchHeaderDTO = null; if (ledgerType == "PayerAccountsReceivable") { name = "corBulkPosting_GetInsClmBatchHdr"; } else { throw new Exception("Invalid Ledger Type"); } const ExecuteType executeType = ExecuteType.ExecuteReader; SqlDataReader reader; ExecuteOutcome outcome; string outcomeMsg; IList<SqlParameter> parameters = new List<SqlParameter>(); parameters = AddSqlParameter(parameters, "@InsBatHdrKey", key.ToString(), SqlDbType.Int, "in"); try { reader = (SqlDataReader)manager.GetData( TransactionChoice.WithoutTransaction , CommandType.StoredProcedure , name, parameters , 3, executeType, out outcome, out outcomeMsg); } catch (Exception ex) { throw new Exception("DataAccess:GetBatchHeader:Error retrieving data.", ex); } EvaluateOutcome(outcome, outcomeMsg, "GetBatchHeader"); if (reader != null) { bool hasRows = reader.HasRows; if (hasRows) { while (reader.Read()) { //get the number of fields and store values into an array of objects Object[] values = new Object[reader.FieldCount]; int fieldCount = reader.GetValues(values); for (int i = 0; i < fieldCount; i++) { switch (i) { case 0: thisKey = (int)values[i]; break; case 1: arDate = (DateTime?)values[i]; break; case 2: userAdded = (string)values[i]; break; case 3: dateAdded = (DateTime?)values[i]; break; case 4: if (values[i].ToString().Length > 0) {sumPayments = Double.Parse(values[i].ToString()); sumPayments = Math.Abs(sumPayments); } break; case 5: if (values[i].ToString().Length > 0) {countPayments = (int) values[i];} break; case 6: if (values[i].ToString().Length > 0) {payerCheckNumber = (string)values[i];} break; case 7: if (values[i].ToString().Length > 0) {payerCheckAmount = Double.Parse(values[i].ToString());} break; case 8: payerCheckDate = (DateTime?) values[i]; break; case 9: if (values[i].ToString().Length > 0) {sumCommissionPayments = Double.Parse(values[i].ToString()); sumCommissionPayments = Math.Abs(sumCommissionPayments); } break; case 10: if (values[i].ToString().Length > 0) {countCommissionPayments = (int) values[i];} break; case 11: if (values[i].ToString().Length > 0) {sumUnidentifiedPayments = Double.Parse(values[i].ToString()); sumUnidentifiedPayments = Math.Abs(sumUnidentifiedPayments); } break; case 12: if (values[i].ToString().Length > 0) {countUnidentifiedPayments = (int) values[i];} break; case 13: if (values[i].ToString().Length > 0) {sumOpenCreditPayments = Double.Parse(values[i].ToString()); sumOpenCreditPayments = Math.Abs(sumOpenCreditPayments); } break; case 14: if (values[i].ToString().Length > 0) {countOpenCreditPayments = (int) values[i];} break; default: //do nothing; no more columns at this time break; } } if (thisKey != key) { throw new Exception("Key not found"); } } //store values into DTO object batchHeaderDTO = new BatchHeaderDTO(key , arDate, userAdded, dateAdded, sumPayments, countPayments , payerCheckNumber, payerCheckAmount, payerCheckDate , sumCommissionPayments, countCommissionPayments , sumUnidentifiedPayments, countUnidentifiedPayments , sumOpenCreditPayments, countOpenCreditPayments); } reader.Close(); reader.Dispose(); } return batchHeaderDTO; }
public void Should_return_batch_header_information() { _batchHeaderDTO = _batch.GetPayerBatch(9650); Assert.That(_batchHeaderDTO.Key > 0); }
/// <summary> /// Create a BatchHeaderDTO from bulkpayment /// </summary> private BatchHeaderDTO UpdateToBatchHeaderDTO() { BatchHeaderDTO batchHeaderDTO = new BatchHeaderDTO(); batchHeaderDTO.PayerCheckNumber = _id; batchHeaderDTO.PayerCheckAmount = _total; batchHeaderDTO.PayerCheckDate = _date; batchHeaderDTO.UserAdded = _user.Login; batchHeaderDTO.Key = _batchHeaderKey; batchHeaderDTO.SumPayments = _sumPayments; batchHeaderDTO.CountPayments = _countPayments; batchHeaderDTO.SumCommissions = _sumIdentifiedPayments; batchHeaderDTO.CountCommissions = _countIdentifiedPayments; batchHeaderDTO.SumOpenCredits = _sumOpenCreditPayments; batchHeaderDTO.CountOpenCredits = _countOpenCreditPayments; batchHeaderDTO.SumUnidentifieds = _sumUnidentifedPayments; batchHeaderDTO.CountUnidentifieds = _countUnidentifiedPayments; return batchHeaderDTO; }
/// <summary> /// Updates BulkPayment properties from information returned from a BatchHeaderDTO /// </summary> /// <param name="batchHeaderDTO"></param> private void UpdateFromBatchHeaderDTO(BatchHeaderDTO batchHeaderDTO) { if (batchHeaderDTO != null) { _id = batchHeaderDTO.PayerCheckNumber; _total = batchHeaderDTO.PayerCheckAmount; _date = batchHeaderDTO.PayerCheckDate; _user = new User(0, batchHeaderDTO.UserAdded); _batchHeaderKey = batchHeaderDTO.Key; _sumPayments = batchHeaderDTO.SumPayments; _countPayments = batchHeaderDTO.CountPayments; _sumIdentifiedPayments = batchHeaderDTO.SumCommissions; _countIdentifiedPayments = batchHeaderDTO.CountCommissions; _sumUnidentifedPayments = batchHeaderDTO.SumUnidentifieds; _countUnidentifiedPayments = batchHeaderDTO.CountUnidentifieds; _sumOpenCreditPayments = batchHeaderDTO.SumOpenCredits; _countOpenCreditPayments = batchHeaderDTO.CountOpenCredits; } }
/// <summary> /// Stores the information returned from a BatchHeaderDTO and stores to BulkPayment properties. /// </summary> /// <param name="batchHeaderDTO"></param> private void StoreBatchHeaderDTOSummaries(BatchHeaderDTO batchHeaderDTO) { CountPayments += batchHeaderDTO.CountPayments; SumPayments += batchHeaderDTO.SumPayments; CountIdentifiedPayments += batchHeaderDTO.CountCommissions; SumIdentifiedPayments += batchHeaderDTO.SumCommissions; CountUnidentifiedPayments += batchHeaderDTO.CountUnidentifieds; SumUnidentifedPayments += batchHeaderDTO.SumUnidentifieds; CountOpenCreditPayments += batchHeaderDTO.CountOpenCredits; SumOpenCreditPayments += batchHeaderDTO.SumOpenCredits; }
public BatchHeaderDTO IdentifyTransactionTypes(IList<PaymentDTO> paymentList) { _transactions.Clear(); _unidentifiedMoneys.Clear(); _openCredits.Clear(); BatchHeaderDTO batchHeaderDTO = new BatchHeaderDTO(); IList<PaymentDTO> futureTransactions = new List<PaymentDTO>(); IList<PaymentDTO> futureUnidentifiedMoneys = new List<PaymentDTO>(); IList<PaymentDTO> futureOpenCredits = new List<PaymentDTO>(); foreach (PaymentDTO payment in paymentList) { batchHeaderDTO.CountPayments += 1; batchHeaderDTO.SumPayments += payment.Amount; if (payment.ClaimHeaderKey > 0) { if (payment.IsInvoiceClosed) { futureTransactions.Add(payment); batchHeaderDTO.SumCommissions += payment.Amount; batchHeaderDTO.CountCommissions += 1; } else { batchHeaderDTO.SumOpenCredits += payment.Amount; batchHeaderDTO.CountOpenCredits += 1; futureOpenCredits.Add(payment); } } else { batchHeaderDTO.SumUnidentifieds += payment.Amount; batchHeaderDTO.CountUnidentifieds += 1; futureUnidentifiedMoneys.Add(payment); } } _unidentifiedMoneys = CreateUnidentifiedMoneyFromPayments(futureUnidentifiedMoneys, false); _openCredits = CreateUnidentifiedMoneyFromPayments(futureOpenCredits, true); _transactions = CreateTransactionsFromPayments(futureTransactions, TransactionCode.COM, DateTime.Now, DateTime.Now, 0); return batchHeaderDTO; }
public int CreateBatch(string ledgerType, BatchHeaderDTO batchHeaderDTO) { _batchHeaderDTO = batchHeaderDTO; int batchHeaderKey = 0; if (batchHeaderDTO.Key == 0) { batchHeaderKey = CreateBatchHeader(ledgerType , TransactionType.P, DateTime.Now, batchHeaderDTO.UserAdded); batchHeaderDTO.Key = batchHeaderKey; } else { batchHeaderKey = batchHeaderDTO.Key; } if (!EvaluateResult(batchHeaderKey)) { throw new BatchNotCreatedException("Error saving batch."); } bool result = CreateBatchDetails(ledgerType); if (!result) { throw new BatchNotCreatedException("Error saving batch details."); } return batchHeaderKey; }