Ejemplo n.º 1
0
        public void CityBankTextFile_CanLoadFile_AndValidateData()
        {
            DTO.UploadData data = ReadDataFromFile();

            IAS.DAL.Interfaces.IIASPersonEntities ctx = DAL.DALFactory.GetPersonContext();

            CityFileHeader header = BankFileFactory.ConcreateCityBankFileTransfer(ctx, "test.txt", data);

            Assert.IsNotNull(header);
            Assert.AreEqual(header.CityFileBoxHeaders.Count(), 3);
            Assert.AreEqual(header.CityFileOverFlows.Count(), 7);
            Assert.AreEqual(header.CityFileBatchHeaders.Count(), 6);
            Assert.AreEqual(header.CityFileDetails.Count(), 6);
            Assert.AreEqual(header.CityFileBatchTotals.Count(), 6);
            Assert.AreEqual(header.CityFileTotals.Count(), 3);


            Assert.AreEqual(header.CityFileTotals.ElementAt(0).CityFileDetails.Count(), 1);
            Assert.AreEqual(header.CityFileTotals.ElementAt(1).CityFileDetails.Count(), 3);
            Assert.AreEqual(header.CityFileTotals.ElementAt(2).CityFileDetails.Count(), 2);

            Int32 rownum = (1 + header.CityFileBoxHeaders.Count()
                            + header.CityFileOverFlows.Count()
                            + header.CityFileBatchHeaders.Count()
                            + header.CityFileDetails.Count()
                            + header.CityFileBatchTotals.Count()
                            + header.CityFileTotals.Count()
                            + 1);

            Assert.AreEqual(header.RowCount, rownum);


            DTO.UploadResult <DTO.SummaryBankTransaction, DTO.BankTransaction> uploadResult = header.ValidateData();
        }
Ejemplo n.º 2
0
        public DTO.UploadResult <DTO.SummaryBankTransaction, DTO.BankTransaction> ValidateData()
        {
            DTO.UploadResult <DTO.SummaryBankTransaction, DTO.BankTransaction> result = new DTO.UploadResult <DTO.SummaryBankTransaction, DTO.BankTransaction>();
            result.Header  = new List <DTO.SummaryBankTransaction>();
            result.Detail  = new List <DTO.BankTransaction>();
            result.GroupId = this.ID;


            foreach (CityFileDetail item in this.CityFileDetails)
            {
                DTO.BankTransaction detail = new DTO.BankTransaction()
                {
                    Id           = item.ID,
                    SequenceNo   = item.SequenceNo,
                    PaymentDate  = ParseDateFromString.ParseDateHeaderBank(item.PAYMENT_DATE).ToString("dd/MM/yyyy"), //  .Format("{0}/{1}/{2}", item.PAYMENT_DATE.Substring(0, 2), item.PAYMENT_DATE.Substring(2, 2), item.PAYMENT_DATE.Substring(4, 4)),
                    CustomerName = item.CUSTOMER_NAME,
                    Ref1         = item.CUSTOMER_NO_REF1,
                    Ref2         = item.REF2,
                    ChequeNo     = item.CHEQUE_NO,
                    Amount       = PhaseAmountHelper.ConvertStringAmountCity(item.AMOUNT),
                    AccountNo    = item.COMPANY_ACCOUNT,
                };

                detail.ErrorMessage = (item.GetBrokenRules().Count() > 0) ? item.GetBrokenRules().First().Rule : "";
                detail.Status       = (int)item.Status;
                if (item.Status == DTO.ImportPaymentStatus.Paylate)
                {
                    detail.ErrorMessage += String.Format("- นำส่งล้าช้า <br />");
                }


                result.Detail.Add(detail);
            }


            Int32 countDetail    = CityFileDetails.Count();
            Int32 countOfInvalid = result.Detail.Where(a => !String.IsNullOrEmpty(a.ErrorMessage)).Count();



            Decimal sumAmount = PhaseAmountHelper.ConvertStringAmountCity(CityFileTotal.TOTAL_CREDIT_AMOUNT);


            DTO.SummaryBankTransaction sumary = new DTO.SummaryBankTransaction()
            {
                UploadDate      = DateTime.Today,
                FileName        = FileName,
                NumberOfItems   = countDetail,
                NumberOfValid   = countDetail - countOfInvalid,
                NumberOfInValid = countOfInvalid,
                Total           = this.TotalAmount,
            };

            //foreach (CityFileTotal item in this.CityFileTotals)
            //{
            //    if (item.GetBrokenRules().Count() > 0)
            //    {
            //        sumary.ErrMessage = this.CityFileTotal.GetBrokenRules().First().Rule;
            //        break;
            //    }
            //}
            Decimal sumDetail = this.CityFileDetails.Sum(a => PhaseAmountHelper.ConvertStringAmountCity(a.AMOUNT));

            if (sumary.Total != sumDetail)
            {
                sumary.ErrMessage = "จำนวนเงินรวม เอกสารไม่ถูกต้อง";
            }

            result.Header.Add(sumary);
            return(result);
        }