Esempio n. 1
0
        public void UpdateAdjustments(List <ShipmentAdjustment> shipments)
        {
            Logs.AppLogs(LogPath, "SOA BL - UpdateAdjustments");
            UserStore userStore = new UserStore(_unitOfWork);

            if (shipments != null)
            {
                foreach (var item in shipments)
                {
                    item.ShipmentAdjustmentId = Guid.NewGuid();
                    item.DateAdjusted         = item.DateAdjusted;                                    // DateTime.Now; // ++++ commented for testing
                    item.AdjustmentReasonId   = Guid.Parse("{C29D0852-26F9-436D-A5CA-E5F723CFC427}"); // TODO AdjustmentReasonId for testing
                    item.AdjustedById         = userStore.FindByIdAsync(item.AdjustedById).Result.EmployeeId;
                    item.CreatedBy            = item.ModifiedBy;
                    item.CreatedDate          = item.ModifiedDate;
                    try
                    {
                        shipmentAdjustmentService.AddEdit(item);
                    }
                    catch (Exception ex)
                    {
                        Logs.ErrorLogs(LogPath, "SOA BL - UpdateAdjustments", ex.Message);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Update SOA with SOANo
        /// Generate PDF and store to file system
        /// Finalized SOA are non-editable
        /// </summary>
        /// <param name="entity"></param>
        public StatementOfAccountModel Finalize(StatementOfAccountModel model)
        {
            Logs.AppLogs(LogPath, "SOA BL - Finalize");
            StatementOfAccount entity = base.GetById(model.StatementOfAccountId);

            if (entity != null && string.IsNullOrEmpty(entity.StatementOfAccountNo))
            {
                //entity.StatementOfAccountNoInt = GetNewSoaNo(entity.StatementOfAccountId);
                entity.ModifiedBy   = model.ModifiedBy;
                entity.ModifiedDate = DateTime.Now;
                try
                {
                    base.Edit(entity);
                    //model.StatementOfAccountNo = entity.StatementOfAccountNo;
                    model.StatementOfAccountNoBarcode = BarcodeGenerator.GetBarcode(model.StatementOfAccountNo);
                    model.ModifiedDate = entity.ModifiedDate;
                    Logs.AppLogs(LogPath, "SOA BL - Finalize", "Successfull");
                }
                catch (Exception ex)
                {
                    Logs.ErrorLogs(LogPath, "SOA BL - Finalize", ex.Message);
                }
            }
            return(model);
        }
Esempio n. 3
0
        public List <StatementOfAccountModel> GetByCompanyAccountNo(string accountNo)
        {
            Logs.AppLogs(LogPath, "SOA BL - GetByCompanyAccountNo");
            var soa = FilterBy(x => x.Company.AccountNo.Equals(accountNo)).ToList();
            List <StatementOfAccountModel> models = new List <StatementOfAccountModel>();

            if (soa != null && soa.Count > 0)
            {
                models = EntitiesToModels(soa);
                models = ComputeSoas(models);
            }
            return(models);
        }
Esempio n. 4
0
        public void CreateSavePdfFile(StatementOfAccountModel model)
        {
            Logs.AppLogs(LogPath, "SOA BL - Create and Save Pdf File");
            // create PDF and save to file system
            if (model != null)
            {
                model = ComputeSoa(model);
            }
            string reportTemplatePath = "";
            string soaTemplateFile    = "";
            string soaReportPath      = "";
            //string branchName = model.Company.Area.Branch.BranchName;
            string bcoName     = model.Company.City.BranchCorpOffice.BranchCorpOfficeName;
            string soaDate     = model.StatementOfAccountDate.ToString("yyyyMMdd");
            string soaFileName = soaDate + "_" + model.StatementOfAccountNo + "_" + model.Company.AccountNo;

            if (ApplicationSetting != null)
            {
                reportTemplatePath = ApplicationSetting.SingleOrDefault(x => x.SettingName.Equals("SOAReportTemplatePath")).SettingValue;
                soaTemplateFile    = ApplicationSetting.SingleOrDefault(x => x.SettingName.Equals("SOATemplateFilename")).SettingValue;
                soaReportPath      = ApplicationSetting.SingleOrDefault(x => x.SettingName.Equals("SOAReportPath")).SettingValue + soaDate + "\\" + bcoName + "\\";

                string soaReportFile = soaFileName + ".pdf";

                if (!Directory.Exists(soaReportPath))
                {
                    Directory.CreateDirectory(soaReportPath);
                }

                // transfer model to dataset for crystal reports
                StatementOfAccountDataSet soaDs = new StatementOfAccountDataSet();
                // fill SOA Details
                // TODO check the assignment of data. Must not add.
                DataRow dr = soaDs.Tables["StatementOfAccount"].NewRow();
                dr["SoaNo"]                    = model.StatementOfAccountNo;
                dr["SoaDateString"]            = model.StatementOfAccountDateString;
                dr["SoaDueDate"]               = model.SoaDueDateString;
                dr["SoaBillingPeriod"]         = model.StatementOfAccountPeriod;
                dr["AccountNo"]                = model.Company.AccountNo;
                dr["AccountNoBarcode"]         = model.StatementOfAccountNoBarcode;
                dr["CompanyName"]              = model.Company.CompanyName;
                dr["CompanyAddress"]           = model.Company.BillingAddress1;
                dr["SoaAmountDue"]             = model.TotalSoaAmountString;
                dr["TotalCurrentBalance"]      = model.TotalCurrentChargesString;
                dr["TotalPreviousBalance"]     = model.TotalPreviousBalanceString;
                dr["TotalPreviousSurcharges"]  = model.TotalPreviousSurchargeString;
                dr["TotalFreightCharges"]      = model.TotalCurrentSubTotalString;
                dr["TotalVatAmount"]           = model.TotalCurrentVatAmountString;
                dr["TotalCurrentAmountDue"]    = model.TotalCurrentTotalString;
                dr["TotalPreviousAmountDue"]   = model.TotalPreviousAmountDueString;
                dr["TotalPreviousAdjustments"] = model.TotalPreviousAdjustmentsString;
                dr["TotalPreviousPayments"]    = model.TotalPreviousPaymentsString;
                soaDs.Tables["StatementOfAccount"].Rows.Add(dr);

                // fill current Shipments
                foreach (var item in model.CurrentShipments)
                {
                    dr = soaDs.Tables["CurrentShipments"].NewRow();
                    dr["DateAccepted"]   = item.DateAcceptedString;
                    dr["AirwayBillNo"]   = item.AirwayBillNo;
                    dr["Origin"]         = item.OriginCity.CityCode;
                    dr["Destination"]    = item.DestinationCity.CityCode;
                    dr["FreightCharges"] = item.ShipmentSubTotalString;
                    dr["VatAmount"]      = item.ShipmentVatAmountString;
                    dr["AmountDue"]      = item.ShipmentTotalString;
                    soaDs.Tables["CurrentShipments"].Rows.Add(dr);
                }

                // fill previous Shipments
                foreach (var item in model.PreviousShipments)
                {
                    dr                       = soaDs.Tables["PreviousShipments"].NewRow();
                    dr["SoaDate"]            = item.StatementOfAccount.StatementOfAccountDateString;
                    dr["SoaNo"]              = item.StatementOfAccount.StatementOfAccountNo;
                    dr["AwbNo"]              = item.AirwayBillNo;
                    dr["PreviousAmountDue"]  = item.PreviousAmountDueString;
                    dr["PreviousPayment"]    = item.PreviousPaymentsString;
                    dr["PreviousAdjustment"] = item.PreviousAdjustmentsString;
                    dr["PreviousBalance"]    = item.PreviousBalanceString;
                    dr["Surcharge"]          = item.SurchargeString;
                    soaDs.Tables["PreviousShipments"].Rows.Add(dr);
                }

                // fill SOA Payments
                foreach (var item in model.PreviousSoaPayments)
                {
                    dr = soaDs.Tables["Payments"].NewRow();
                    dr["PaymentDate"] = item.PaymentDateString;
                    dr["OrPrNo"]      = item.OrNo;
                    dr["Form"]        = item.PaymentType.PaymentTypeName;
                    dr["Remarks"]     = item.CheckBankName + " " + item.CheckNo + " " + item.Remarks;
                    dr["AmountPaid"]  = item.AmountString;
                    soaDs.Tables["Payments"].Rows.Add(dr);
                }

                try
                {
                    ReportDocument report = new ReportDocument();
                    report.Load(reportTemplatePath + soaTemplateFile);
                    report.SetDataSource(soaDs);
                    report.ExportToDisk(ExportFormatType.PortableDocFormat, soaReportPath + soaReportFile);
                    Logs.AppLogs(LogPath, "SOA BL - CreateSavePdfFile", "Successfull");
                }
                catch (Exception ex)
                {
                    Logs.ErrorLogs(LogPath, "SOA BL - CreateSavePdfFile", ex.Message);
                }
            }
            else
            {
                Logs.ErrorLogs(LogPath, "SOA BL - CreateSavePdfFile", "Application Settings is null");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Create a New Statement Of Account
        /// </summary>
        /// <param name="accountNo"></param>
        /// <param name="periodStart"></param>
        /// <param name="periodEnd"></param>
        /// <returns></returns>
        public StatementOfAccount CreateNewSoa(string companyAccountNo, DateTime periodStart, DateTime periodEnd, Guid userId)
        {
            Logs.AppLogs(LogPath, "SOA BL - Create SOA", companyAccountNo);
            Company companyModel = companyService.GetByAccountNo(companyAccountNo);

            if (companyModel == null)
            {
                // TODO log error and notify user
                return(null);
            }

            // get default SOA values from ApplicationSettings
            int dueDate      = Convert.ToInt32(ApplicationSetting.Where(x => x.SettingName.Equals("SOADueDate")).OrderByDescending(x => x.CreatedDate).FirstOrDefault().SettingValue);
            int clientPeriod = Convert.ToInt32(ApplicationSetting.Where(x => x.SettingName.Equals("SOABillingPeriod")).OrderByDescending(x => x.CreatedDate).FirstOrDefault().SettingValue);

            periodStart = periodEnd.AddDays(-(clientPeriod - 1));

            if (companyModel.BillingPeriod != null)
            {
                clientPeriod = companyModel.BillingPeriod.NumberOfDays;
                periodStart  = periodEnd.AddDays(-(clientPeriod - 1));
            }

            if (IsExist(x => x.CompanyId == companyModel.CompanyId && (periodEnd > x.StatementOfAccountPeriodFrom && periodEnd < x.StatementOfAccountPeriodUntil)))
            {
                return(null);
            }

            Guid newSoaId = Guid.NewGuid();
            // create the SOA
            StatementOfAccount entity = new StatementOfAccount()
            {
                StatementOfAccountId          = newSoaId,
                StatementOfAccountNoInt       = GetNewSoaNo(newSoaId),
                StatementOfAccountDate        = periodEnd,
                StatementOfAccountPeriodFrom  = periodStart,
                StatementOfAccountPeriodUntil = periodEnd,
                CompanyId    = companyModel.CompanyId,
                Company      = companyModel,
                SoaDueDate   = periodEnd.AddDays(dueDate),
                CreatedDate  = DateTime.Now,
                CreatedBy    = userId,
                ModifiedDate = DateTime.Now,
                ModifiedBy   = userId,
                RecordStatus = (int)RecordStatus.Active
            };

            try
            {
                Add(entity);
                Logs.AppLogs(LogPath, "SOA BL - Create SOA", "Successfull");
            }
            catch (Exception ex)
            {
                Logs.ErrorLogs(LogPath, "SOA BL - Create SOA", ex.Message);
            }


            // finalize previous SOA if not yet finalized
            StatementOfAccount previousSoa = GetByCompanyIdByPeriod(companyModel.CompanyId, periodStart.AddDays(-(clientPeriod)),
                                                                    periodEnd.AddDays(-(clientPeriod)));

            if (previousSoa != null && string.IsNullOrEmpty(previousSoa.StatementOfAccountNo))
            {
                Finalize(EntityToModel(previousSoa));
            }

            shipmentService.LinkToSoa(entity.StatementOfAccountId, companyAccountNo, periodStart, periodEnd);

            return(entity);
        }
Esempio n. 6
0
        /// <summary>
        /// Compute for the Amount Due, Previous Balance and Outstanding Balance
        /// </summary>
        /// <param name="StatementOfAccountModel"></param>
        /// <returns></returns>
        ///
        public StatementOfAccountModel ComputeSoa(StatementOfAccountModel model)
        {
            Logs.AppLogs(LogPath, "SOA BL - ComputeSoa", model.StatementOfAccountNo);
            model.CurrentShipments  = shipmentService.EntitiesToModels(shipmentService.FilterActiveBy(x => x.StatementOfAccountId == model.StatementOfAccountId)).OrderByDescending(x => x.DateAccepted).ToList();
            model.PreviousShipments = shipmentService.GetSoaShipmentsByCompanyId(model.CompanyId).Where(x => x.DateAccepted < model.StatementOfAccountPeriodFrom && x.StatementOfAccountId != null).OrderByDescending(x => x.DateAccepted).ToList();

            DateTime soaPaymentStart = new DateTime(model.StatementOfAccountPeriodUntil.Year, model.StatementOfAccountPeriodUntil.Month, model.StatementOfAccountPeriodUntil.Day, 0, 0, 0);
            DateTime soaPaymentEnd   = new DateTime(model.SoaDueDate.Year, model.SoaDueDate.Month, model.SoaDueDate.Day, 11, 59, 59);

            model.SoaPayments = soaPaymentService.FilterActiveBy(x => x.StatementOfAccountId == model.StatementOfAccountId && (x.PaymentDate > soaPaymentStart && x.PaymentDate <= soaPaymentEnd));

            DateTime previousSoaStartDate = model.StatementOfAccountPeriodFrom.AddDays(-model.Company.BillingPeriod.NumberOfDays);
            var      previousSoa          = FilterActiveBy(x => x.StatementOfAccountPeriodFrom.Year == previousSoaStartDate.Year && x.StatementOfAccountPeriodFrom.Month == previousSoaStartDate.Month && x.StatementOfAccountPeriodFrom.Day == previousSoaStartDate.Day).OrderByDescending(x => x.CreatedDate).FirstOrDefault();

            if (previousSoa != null)
            {
                model.PreviousSoaPayments = soaPaymentService.FilterActiveBy(x => x.StatementOfAccount.StatementOfAccountId == previousSoa.StatementOfAccountId);
            }

            List <ShipmentModel> shipments = new List <ShipmentModel>();

            Logs.AppLogs(LogPath, "SOA BL - ComputeSoa - CurrentShipments");
            if (model.CurrentShipments != null && model.CurrentShipments.Count > 0)
            {
                foreach (var item in model.CurrentShipments)
                {
                    ShipmentModel shipmentModel = shipmentService.ComputeBalances(item, model.SoaDueDate);
                    model.TotalCurrentSubTotal    = model.TotalCurrentSubTotal + shipmentModel.ShipmentSubTotal;
                    model.TotalCurrentVatAmount   = model.TotalCurrentVatAmount + shipmentModel.ShipmentVatAmount;
                    model.TotalCurrentTotal       = model.TotalCurrentTotal + shipmentModel.ShipmentTotal;
                    model.TotalCurrentPayments    = model.TotalCurrentPayments + shipmentModel.CurrentPayments;
                    model.TotalCurrentAdjustments = model.TotalCurrentAdjustments + shipmentModel.Adjustment;

                    model.TotalSoaPayments    = model.TotalSoaPayments + shipmentModel.CurrentPayments;
                    model.TotalSoaAdjustments = model.TotalSoaAdjustments + shipmentModel.Adjustment;

                    shipments.Add(shipmentModel);
                }
            }
            model.CurrentShipments = shipments;

            Logs.AppLogs(LogPath, "SOA BL - ComputeSoa - PreviousShipments");
            shipments = new List <ShipmentModel>();

            //string soaNo = model.StatementOfAccountNo; // ++++ for debugging
            if (model.PreviousShipments != null && model.PreviousShipments.Count > 0)
            {
                foreach (var item in model.PreviousShipments)
                {
                    ShipmentModel shipmentModel = shipmentService.ComputeBalances(item, model.SoaDueDate);
                    model.TotalPreviousAmountDue   = model.TotalPreviousAmountDue + shipmentModel.SoaPreviousAmountDue;
                    model.TotalPreviousPayments    = model.TotalPreviousPayments + shipmentModel.PreviousPayments;
                    model.TotalPreviousAdjustments = model.TotalPreviousAdjustments + shipmentModel.PreviousAdjustments;
                    model.TotalPreviousBalance     = model.TotalPreviousBalance + shipmentModel.PreviousBalance;
                    model.TotalPreviousSurcharge   = model.TotalPreviousSurcharge + shipmentModel.Surcharge;

                    model.TotalSoaPayments    = model.TotalSoaPayments + shipmentModel.CurrentPayments;
                    model.TotalSoaAdjustments = model.TotalSoaAdjustments + shipmentModel.Adjustment;

                    shipments.Add(shipmentModel);
                }
            }

            model.PreviousShipments         = shipments;
            model.TotalCurrentCharges       = model.TotalCurrentTotal + model.TotalPreviousSurcharge;
            model.TotalBalancesFromPrevious = model.TotalPreviousAmountDue - model.TotalPreviousPayments + model.TotalPreviousAdjustments;
            model.TotalSoaAmount            = model.TotalCurrentCharges + model.TotalBalancesFromPrevious;

            Logs.AppLogs(LogPath, "SOA BL - ComputeSoa - Done");
            return(model);
        }