예제 #1
0
        public IActionResult Index([FromQuery] string access_token, [FromBody] WebHookRequest request)
        {
            var token = ConfigHelper.GetString("PaymentFileLoaded.access_token");

            if (token.ToLowerInvariant() != access_token.ToLowerInvariant())
            {
                return(BadRequest());
            }

            try
            {
                Logger.Info(request.ToString());
                var dao = DbServiceFactory.GetCurrent();
                if (dao == null)
                {
                    throw new NullReferenceException("Can not get database connection");
                }

                var customExporter = new CustomDistributeAndExportPayment();
                customExporter.Process(request.fileId, request.siteName);

                Logger.Info("Execute successful.");
                return(Ok("successful"));
            }
            catch (Exception ex)
            {
                Logger.Info("Execute failed.");
                Logger.Error(ex);
                throw;
            }
        }
예제 #2
0
        public void GetVendorsAndSendEmail()
        {
            var dao = DbServiceFactory.GetCurrent();

            if (dao == null)
            {
                throw new Exception("Can not get data connection");
            }
            var list = dao.ProcForListObject <VendorData>("[custom].usp_s_GetAllVendorWithPaymentMethod").ToList();

            LOGGER.Info($"Total {list.Count} vendors");
            if (list.Any())
            {
                StringBuilder builder = GenerateReportFileContent(list);
                SendEmail(builder);
            }
        }
        public bool ProcessCreateVendors(out string errors)
        {
            errors = string.Empty;
            var vendors = this._paymentDatas.Select(vendorSelector);
            var dt      = vendors.ToDataTable();
            var dao     = DbServiceFactory.GetCurrent();

            if (dao == null)
            {
                throw new Exception("Can not get customer data connection");
            }
            IDictionary <string, object> parameters = new Dictionary <string, object>();

            parameters["@PaymentConversionVendorAddressesTvp"] = dt;
            object oResult = dao.ProcForScalar("dbo.usp_i_CreateVendorFromPaymentFile", parameters);

            if (oResult != null && !AppHelper.IsNumeric(oResult))
            {
                errors = AppHelper.ToString(oResult);
                return(false);
            }
            return(true);
        }
        public void Process(int fileId, string siteName)
        {
            try
            {
                Logger.Info("begin CustomDistributeAndExportPayment process");
                var dao        = DbServiceFactory.GetCurrent();
                var parameters = new Dictionary <string, object>();
                parameters.Add("@I_vFileId", fileId);
                var list = dao.ProcForListObject <PaymentData>("[custom].usp_s_GetPaymentByFileID", parameters).ToList();

                var grouped = list.GroupBy(s => new
                {
                    TransactionId     = s.TransactionId,
                    PaymentNumber     = s.PaymentNumber,
                    PaymentMethod     = s.PaymentMethod,
                    PaymentDate       = s.PaymentDate,
                    PaymentAmount     = s.PaymentAmount,
                    VendorID          = s.VendorID,
                    VendorName        = s.VendorName,
                    PayeeAddressLine1 = s.PayeeAddressLine1,
                    PayeeAddressLine2 = s.PayeeAddressLine2,
                    PayeeAddressLine3 = s.PayeeAddressLine3,
                    PayeeAddressLine4 = s.PayeeAddressLine4,
                    PaymentBatchId    = s.PaymentBatchId,
                }).Select(s => new Payment
                {
                    Details = s.ToList(),
                    Header  = new PaymentHeader
                    {
                        TransactionId     = s.Key.TransactionId,
                        PaymentNumber     = s.Key.PaymentNumber,
                        PaymentMethod     = s.Key.PaymentMethod,
                        PaymentDate       = s.Key.PaymentDate,
                        PaymentAmount     = s.Key.PaymentAmount,
                        VendorID          = s.Key.VendorID,
                        VendorName        = s.Key.VendorName,
                        PayeeAddressLine1 = s.Key.PayeeAddressLine1,
                        PayeeAddressLine2 = s.Key.PayeeAddressLine2,
                        PayeeAddressLine3 = s.Key.PayeeAddressLine3,
                        PayeeAddressLine4 = s.Key.PayeeAddressLine4,
                        PaymentBatchId    = s.Key.PaymentBatchId,
                    }
                }).OrderBy(s => s.Header.VendorName);
                if (list.Any())
                {
                    var batchId             = list.First(s => s.PaymentBatchId.HasValue).PaymentBatchId;
                    var exportTime          = DateTime.Now.ToString("yyyyMMddHHmmss");
                    var checkFileOutputName = $"CHECK_{exportTime}_{batchId}.txt";
                    var eftFileOutputName   = $"EFT_{exportTime}_{batchId}.txt";
                    //gennerate check file
                    var checkPaymentList = grouped.Where(s => s.Header.PaymentMethod == 0).ToList();
                    Logger.Info($"check payment count: {checkPaymentList.Count})");

                    StringBuilder checkFileContent = GenerateCheckFileContent(checkPaymentList);

                    //gennerate eft file
                    var eftPaymentList = grouped.Where(s => s.Header.PaymentMethod != 0).ToList();

                    Logger.Info("eft payment count: " + eftPaymentList.Count);
                    StringBuilder eftFileContent = GenerateEftFileContent(eftPaymentList);

                    //upload to blob
                    if (checkFileContent.Length > 0)
                    {
                        UploadFileToBlobStorage(checkFileOutputName, checkFileContent, siteName);
                        //send msb
                        SendMessageToMsgBus(checkFileOutputName, siteName);
                    }
                    else
                    {
                        Logger.Info("No file is exported because there is no CHECK payment records");
                    }

                    if (eftFileContent.Length > 0)
                    {
                        UploadFileToBlobStorage(eftFileOutputName, eftFileContent, siteName);
                        SendMessageToMsgBus(eftFileOutputName, siteName);
                    }
                    else
                    {
                        Logger.Info("No file is exported because there is no EFT payment records");
                    }

                    //delete CHECK
                    if (checkPaymentList.Any())
                    {
                        parameters = new Dictionary <string, object>();
                        parameters.Add("@I_vBatchId", batchId);
                        Logger.Info($"call [custom].[usp_d_DeleteCheckPaymentFromBatch] with batchId = {batchId}");
                        dao.ProcForScalar("[custom].[usp_d_DeleteCheckPaymentFromBatch]", parameters);
                    }
                }
                else
                {
                    Logger.Info("No batch created with file: " + fileId);
                }
                Logger.Info("end CustomDistributeAndExportPayment process");
            }
            catch (Exception e)
            {
                Logger.Error("error:", e);
            }
        }