Beispiel #1
0
 public HSBCBankFile(HSBCBankFile templateBankFile)
     : base(templateBankFile.dbConn)
 {
     this.AccountHolderName = templateBankFile.AccountHolderName;
     this.AccountNo         = templateBankFile.AccountNo;
     this.BankCode          = templateBankFile.BankCode;
     this.BranchCode        = templateBankFile.BranchCode;
     //this.dbConn = templateBankFile.dbConn;
     this.FirstPartyReference       = templateBankFile.FirstPartyReference;
     this.m_IsGenerateChequePayment = templateBankFile.IsGenerateChequePayment;
     this.PlanCode     = templateBankFile.PlanCode;
     this.UseBIBFormat = false;
     this.ValueDate    = templateBankFile.ValueDate;
 }
    protected void UploadToMasterDB(string uploadFile)
    {
        // uploadFile will be MOVED to bankfile folder
        if (!IsAllowEdit)
        {
            throw new Exception("Access Deny");
        }

        HROne.BankFile.HSBCBankFile bankFile = new HROne.BankFile.HSBCBankFile(dbConn);
        bankFile.LoadBankFileDetail(uploadFile);

        DateTime firstValueDate = bankFile.GetFirstValueDate();

        if (firstValueDate <= bankFileCutOffDateTime)
        {
            throw new Exception("Invalid value date:" + firstValueDate.ToString("dd-MMM"));
        }
        if (firstValueDate.DayOfWeek == DayOfWeek.Saturday || firstValueDate.DayOfWeek == DayOfWeek.Sunday)
        {
            throw new Exception("Invalid value date:" + firstValueDate.ToString("dd-MMM"));
        }
        if (HROne.SaaS.Entities.EPublicHoliday.IsHoliday(masterDBConn, firstValueDate))
        {
            throw new Exception("Invalid value date:" + firstValueDate.ToString("dd-MMM"));
        }
        DBFilter bankPaymentCodeFilter = new DBFilter();

        bankPaymentCodeFilter.add(new Match("CompanyDBID", (int)Session["CompanyDBID"]));
        ArrayList BankPaymentCodeList           = EHSBCBankPaymentCode.db.select(masterDBConn, bankPaymentCodeFilter);
        string    bankFileBranchAccountNoString = bankFile.BranchCode + bankFile.AccountNo;
        string    bankFileInOutFlag             = string.Empty;

        if ((bankFile.PlanCode.Equals("E") || bankFile.PlanCode.Equals("F")))
        {
            bankFileInOutFlag = "O";
        }
        else if ((bankFile.PlanCode.Equals("G") || bankFile.PlanCode.Equals("H")))
        {
            bankFileInOutFlag = "I";
        }
        int exchangeProfileID = 0;

        foreach (EHSBCBankPaymentCode bankPaymentCode in BankPaymentCodeList)
        {
            if (bankPaymentCode.HSBCBankPaymentCodeBankAccountNo.Substring(3).Trim().Equals(bankFileBranchAccountNoString.Trim()) &&
                bankPaymentCode.HSBCBankPaymentCode.Trim().Equals(bankFile.BankPaymentCode.Trim()) &&
                bankPaymentCode.HSBCBankPaymentCodeAutoPayInOutFlag.Trim().Equals(bankFileInOutFlag)
                )
            {
                HROne.SaaS.Entities.EHSBCExchangeProfile profile = new EHSBCExchangeProfile();
                profile.HSBCExchangeProfileID = bankPaymentCode.HSBCExchangeProfileID;
                if (HROne.SaaS.Entities.EHSBCExchangeProfile.db.select(masterDBConn, profile))
                {
                    if (!profile.HSBCExchangeProfileIsLocked)
                    {
                        bankFile.BankCode = bankPaymentCode.HSBCBankPaymentCodeBankAccountNo.Substring(0, 3);
                        exchangeProfileID = bankPaymentCode.HSBCExchangeProfileID;
                        break;
                    }
                }
            }
        }

        if (string.IsNullOrEmpty(bankFile.BankCode))
        {
            throw new Exception("Bank Account No. or Bank Payment Code is not registered.");
        }

        //if (errors.isEmpty())
        {
            string UploadBankFilePath = ESystemParameter.getParameter(masterDBConn, ESystemParameter.PARAM_CODE_BANKFILE_UPLOAD_FOLDER);
            if (System.IO.Directory.Exists(UploadBankFilePath))
            {
                System.IO.FileInfo bankFileInfo = new System.IO.FileInfo(uploadFile);
                string             relativePath = System.IO.Path.Combine(System.IO.Path.Combine(Session["CompanyDBID"].ToString(), "Autopay"), bankFileInfo.Name);
                string             fullPath     = System.IO.Path.Combine(UploadBankFilePath, relativePath);

                System.IO.Directory.CreateDirectory((new System.IO.FileInfo(fullPath)).Directory.FullName);
                bankFileInfo.MoveTo(fullPath);

                ECompanyAutopayFile CompanyAutopayFile = new ECompanyAutopayFile();
                CompanyAutopayFile.CompanyDBID                            = (int)Session["CompanyDBID"];
                CompanyAutopayFile.HSBCExchangeProfileID                  = exchangeProfileID;
                CompanyAutopayFile.CompanyAutopayFileBankCode             = bankFile.BankCode;
                CompanyAutopayFile.CompanyAutopayFileDataFileRelativePath = relativePath;
                CompanyAutopayFile.CompanyAutopayFileSubmitDateTime       = currentDateTime;
                CompanyAutopayFile.CompanyAutopayFileValueDate            = firstValueDate;
                if (!HROne.Lib.Entities.ESystemParameter.getParameter(dbConn, HROne.Lib.Entities.ESystemParameter.PARAM_CODE_ECHANNEL_SIGNATURE_REQUIRED_FOR_AUTOPAY_FILE).Equals("Y", StringComparison.CurrentCultureIgnoreCase))
                {
                    CompanyAutopayFile.CompanyAutopayFileConfirmDateTime = currentDateTime;
                }
                ECompanyAutopayFile.db.insert(masterDBConn, CompanyAutopayFile);
            }
        }
    }
Beispiel #3
0
        public override FileInfo GenerateBankFile()
        {
            if (!UseBIBFormat)
            {
                return(GenerateSingleBankFile(m_BankPaymentCode, BankFileDetails));
            }
            else
            {
                const int           MaxRecordSize = 200;
                List <HSBCBankFile> BankFileList  = new List <HSBCBankFile>();
                //List<GenericBankFileDetail> tmpBankFileDetails = new List<GenericBankFileDetail>();
                int paymentCodeCount    = 0;
                int bankFileDetailCount = 0;

                HSBCBankFile dummyBankFile = new HSBCBankFile(this);
                dummyBankFile.BankPaymentCode = m_BankPaymentCode;

                foreach (GenericBankFileDetail bankFileDetail in BankFileDetails)
                {
                    //tmpBankFileDetails.Add(bankFileDetail);
                    //  second condition is to prevent the last bank file contain 160 characters
                    if (dummyBankFile.BankFileDetails.Count >= MaxRecordSize || (dummyBankFile.BankFileDetails.Count.Equals(MaxRecordSize - 1) && BankFileDetails.Count - bankFileDetailCount == 2))
                    {
                        BankFileList.Add(dummyBankFile);

                        paymentCodeCount++;

                        string tmpBankPaymentCode = string.Empty;
                        if (MultipleBankPaymentCode.Length >= paymentCodeCount)
                        {
                            tmpBankPaymentCode = MultipleBankPaymentCode[paymentCodeCount - 1];
                        }
                        else
                        {
                            throw new InvalidFieldValueException("Bank Payment Code is not enough to generate");
                        }
                        //tmpBankFileDetails.Clear();
                        dummyBankFile = new HSBCBankFile(this);
                        dummyBankFile.BankPaymentCode = tmpBankPaymentCode;
                    }
                    bankFileDetailCount++;
                    dummyBankFile.BankFileDetails.Add(bankFileDetail);
                }
                if (dummyBankFile.BankFileDetails.Count > 0)
                {
                    BankFileList.Add(dummyBankFile);
                }

                if (BankFileList.Count == 1)
                {
                    UseBIBFormat = false;
                    return(GenerateBankFile());
                }
                FileInfo zipFileInfo = new FileInfo(Path.GetTempFileName());
                zipFileInfo.MoveTo(zipFileInfo.FullName + ".zip");
                DirectoryInfo   zipFolderInfo = zipFileInfo.Directory.CreateSubdirectory("BankFile" + AppUtils.ServerDateTime().ToString("yyyyMMddHHmmssfff"));
                List <FileInfo> fileInfoList  = new List <FileInfo>();
                foreach (HSBCBankFile bankFile in BankFileList)
                {
                    FileInfo fileInfo = bankFile.GenerateBankFile();
                    fileInfo.MoveTo(System.IO.Path.Combine(zipFolderInfo.FullName, bankFile.ActualBankFileName()));
                    fileInfoList.Add(fileInfo);
                }
                zip.Compress(zipFolderInfo.FullName, "*", zipFileInfo.FullName);
                foreach (FileInfo fileInfo in fileInfoList)
                {
                    fileInfo.Delete();
                }
                zipFolderInfo.Delete(true);
                return(zipFileInfo);
            }
        }