Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public StatementOfAccountModel EntityToModel(StatementOfAccount entity)
        {
            StatementOfAccountModel model = new StatementOfAccountModel();

            if (entity != null)
            {
                model.StatementOfAccountId          = entity.StatementOfAccountId;
                model.StatementOfAccountNo          = entity.StatementOfAccountNo;
                model.StatementOfAccountDate        = entity.StatementOfAccountDate;
                model.StatementOfAccountPeriodFrom  = entity.StatementOfAccountPeriodFrom;
                model.StatementOfAccountPeriodUntil = entity.StatementOfAccountPeriodUntil;
                model.CompanyId  = entity.CompanyId;
                model.Company    = entity.Company;
                model.SoaDueDate = entity.SoaDueDate;
                model.CiNo       = entity.CiNo;
                model.Remarks    = entity.Remarks;
                //StatementOfAccountPrints = entity.StatementOfAccountPrints,
                model.CreatedBy    = entity.CreatedBy;
                model.CreatedDate  = entity.CreatedDate;
                model.ModifiedBy   = entity.ModifiedBy;
                model.ModifiedDate = entity.ModifiedDate;
                model.RecordStatus = entity.RecordStatus;
                if (model.CompanyId != null || model.CompanyId == Guid.Empty)
                {
                    model.CompanyAccountNoBarcode = BarcodeGenerator.GetBarcode(model.Company.AccountNo);
                }

                model.StatementOfAccountNoBarcode = BarcodeGenerator.GetBarcode(model.StatementOfAccountNo);
            }

            return(model);
        }
Exemplo n.º 3
0
        public List <StatementOfAccountModel> EntitiesToModels(List <StatementOfAccount> entities)
        {
            List <StatementOfAccountModel> models = new List <StatementOfAccountModel>();

            foreach (var item in entities)
            {
                StatementOfAccountModel model = EntityToModel(item);
                //model = ComputeSoa(model);
                models.Add(model);
            }
            return(models);
        }
Exemplo n.º 4
0
        public StatementOfAccountModel GetByStatementOfAccountNo(string soaNo)
        {
            StatementOfAccount entity = FilterActiveBy(x => x.StatementOfAccountNo.Equals(soaNo)).FirstOrDefault();

            if (entity != null)
            {
                StatementOfAccountModel model = EntityToModel(entity);
                model = ComputeSoa(model);
                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        public new StatementOfAccountModel GetModelById(Guid id)
        {
            StatementOfAccount entity = base.GetById(id);

            if (entity != null)
            {
                StatementOfAccountModel model = EntityToModel(entity);
                model = ComputeSoa(model);
                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 6
0
        public List <StatementOfAccountModel> GetByCompanyId(Guid companyId)
        {
            List <StatementOfAccount>      entities = FilterActiveBy(x => x.CompanyId == companyId);
            List <StatementOfAccountModel> models   = new List <StatementOfAccountModel>();

            if (entities != null)
            {
                var _models = EntitiesToModels(entities);
                foreach (var item in _models)
                {
                    StatementOfAccountModel model = item;
                    model = ComputeSoa(model);
                    models.Add(model);
                }
                return(models);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 7
0
        public StatementOfAccount ModelToEntity(StatementOfAccountModel model)
        {
            StatementOfAccount entity = new StatementOfAccount()
            {
                StatementOfAccountId          = model.StatementOfAccountId,
                StatementOfAccountNo          = model.StatementOfAccountNo,
                StatementOfAccountDate        = model.StatementOfAccountDate,
                StatementOfAccountPeriodFrom  = model.StatementOfAccountPeriodFrom,
                StatementOfAccountPeriodUntil = model.StatementOfAccountPeriodUntil,
                CompanyId    = model.CompanyId,
                SoaDueDate   = model.SoaDueDate,
                CiNo         = model.CiNo,
                Remarks      = model.Remarks,
                CreatedBy    = model.CreatedBy,
                CreatedDate  = model.CreatedDate,
                ModifiedBy   = model.ModifiedBy,
                ModifiedDate = model.ModifiedDate,
                RecordStatus = model.RecordStatus
            };

            return(entity);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Payment made to all. Distribute amount to Shipments/AWBs
        /// </summary>
        /// <param name="soaPayment"></param>
        public void MakePayment(StatementOfAccountPayment soaPayment, StatementOfAccountModel model)
        {
            StatementOfAccountPayment _soaPayment = new StatementOfAccountPayment()
            {
                StatementOfAccountPaymentId = Guid.NewGuid(),
                StatementOfAccountId        = soaPayment.StatementOfAccountId,
                PaymentDate   = soaPayment.PaymentDate,
                OrNo          = soaPayment.OrNo,
                Amount        = soaPayment.Amount,
                PaymentTypeId = soaPayment.PaymentTypeId,
                CheckBankName = soaPayment.CheckBankName,
                CheckNo       = soaPayment.CheckNo,
                CheckDate     = soaPayment.CheckDate,
                ReceivedById  = soaPayment.ReceivedById,
                Remarks       = soaPayment.Remarks,
                CreatedBy     = soaPayment.CreatedBy,
                CreatedDate   = DateTime.Now,
                ModifiedBy    = soaPayment.ModifiedBy,
                ModifiedDate  = DateTime.Now,
                RecordStatus  = (int)RecordStatus.Active
            };

            soaPaymentService.Add(_soaPayment);


            // TODO move this to CreateSOA
            //if (model.StatementOfAccountId == null || model.StatementOfAccountId == Guid.Empty)
            //{
            //    model = EntityToModel(FilterActiveBy(x => x.StatementOfAccountId == soaPayment.StatementOfAccountId).FirstOrDefault());

            //    if (shipmentService == null)
            //        shipmentService = new ShipmentBL(this._unitOfWork);
            //    model.CurrentShipments = shipmentService.EntitiesToModels(shipmentService.FilterActiveBy(x => x.StatementOfAccountId == model.StatementOfAccountId).OrderByDescending(x => x.DateAccepted).ToList());

            //    var previousSoaIds = FilterActiveBy(x => x.CompanyId == model.CompanyId && x.StatementOfAccountId != model.StatementOfAccountId).OrderBy(x => x.SoaDueDate).Select(x => x.StatementOfAccountId);
            //    if (previousSoaIds != null)
            //    {
            //        foreach (var previousSoaId in previousSoaIds)
            //        {
            //            model.PreviousShipments.AddRange(shipmentService.EntitiesToModels(shipmentService.FilterActiveBy(x => x.StatementOfAccountId == previousSoaId).OrderByDescending(x => x.DateAccepted).ToList()));
            //        }
            //    }
            //}

            //// get current and unpaid Shipments of the current SOA
            //List<ShipmentModel> unpaid = new List<ShipmentModel>();
            //unpaid.AddRange(model.CurrentShipments);
            //unpaid.AddRange(model.PreviousShipments);
            //if (unpaid != null)
            //{
            //    unpaid = shipmentService.ComputeBalances(unpaid, null);
            //    decimal balance = 0;
            //    decimal amountToPay = 0;
            //    decimal availableAmount = soaPayment.Amount;
            //    foreach (var item in unpaid.OrderBy(x => x.DateAccepted).ToList())
            //    {
            //        if (item.DateOfFullPayment == null)
            //        {
            //            balance = item.CurrentBalance;
            //            if (availableAmount >= balance)
            //            {
            //                amountToPay = balance;
            //            }
            //            else
            //            {
            //                amountToPay = availableAmount;
            //            }
            //            Payment paymentModel = new Payment()
            //            {
            //                PaymentId = Guid.NewGuid(),
            //                ShipmentId = item.ShipmentId,
            //                PaymentDate = soaPayment.PaymentDate,
            //                OrNo = soaPayment.OrNo,
            //                Amount = amountToPay,
            //                PaymentTypeId = soaPayment.PaymentTypeId,
            //                CheckBankName = soaPayment.CheckBankName,
            //                CheckNo = soaPayment.CheckNo,
            //                CheckDate = soaPayment.CheckDate,
            //                ReceivedById = soaPayment.ReceivedById,
            //                Remarks = soaPayment.Remarks,
            //                CreatedBy = soaPayment.CreatedBy,
            //                CreatedDate = DateTime.Now,
            //                ModifiedBy = soaPayment.ModifiedBy,
            //                ModifiedDate = DateTime.Now,
            //                RecordStatus = (int)RecordStatus.Active,
            //                StatementOfAccountPaymentId = _soaPayment.StatementOfAccountPaymentId
            //            };
            //            paymentService.Add(paymentModel);
            //            if (balance == amountToPay)
            //            {
            //                var shipment = shipmentService.GetById(item.ShipmentId);
            //                shipment.DateOfFullPayment = DateTime.Now;
            //                shipment.ModifiedBy = soaPayment.ModifiedBy;
            //                shipment.ModifiedDate = DateTime.Now;
            //                shipmentService.Edit(shipment);
            //            }
            //            availableAmount = availableAmount - amountToPay;
            //            if (availableAmount <= 0)
            //            {
            //                break;
            //            }
            //        }
            //    }
            //}
        }
Exemplo n.º 9
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");
            }
        }
Exemplo n.º 10
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);
        }