Exemple #1
0
        /// <summary>
        /// Updates the discount expire notified record for company.
        /// </summary>
        /// <param name="discountCodeUsage">The discount code usage.</param>
        /// <param name="company">The company.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="dataContext">The data context.</param>
        public void UpdateDiscountExpireNotifiedRecordForCompany(DiscountCodeUsage discountCodeUsage, Data.Company company, int userId, StageBitzDB dataContext)
        {
            CompanyDiscountNotificatonHistory companyDiscountNotificatonHistory = GetCompanyDiscountExpireNotifiedRecord(company.CompanyId, DataContext);

            if (companyDiscountNotificatonHistory != null)
            {
                // If it is a 100% discount code
                if (discountCodeUsage != null && discountCodeUsage.DiscountCode.Discount == 100)
                {
                    companyDiscountNotificatonHistory.IsActive            = false;
                    companyDiscountNotificatonHistory.LastUpdatedDate     = Utils.Today;
                    companyDiscountNotificatonHistory.LastUpdatedByUserId = userId;

                    // Also set the Company Status to Active if suspended;
                    if (company.CompanyStatusCodeId == Utils.GetCodeIdByCodeValue("CompanyStatus", "SUSPENDEDFORNOPAYMENTOPTIONS"))
                    {
                        company.CompanyStatusCodeId = Utils.GetCodeIdByCodeValue("CompanyStatus", "ACTIVE");
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Suspends the no payment option companies.
        /// </summary>
        /// <param name="dateToConsider">The date to consider.</param>
        public static void SuspendNoPaymentOptionCompanies(DateTime dateToConsider)
        {
            using (StageBitzDB dataContext = new StageBitzDB())
            {
                FinanceBL financeBL = new FinanceBL(dataContext);
                CompanyBL companyBL = new CompanyBL(dataContext);

                //Change the status to SuspendForNoPaymentOption if there are No option being selected.
                //Get all the No Payment option companies and check if they have to pay a certain amount before a certain period.
                //Send them an email, If they have a due amount to pay 2 weeks ahead (PBI 11444).
                int companyActiveStatusCodeId = Utils.GetCodeIdByCodeValue("CompanyStatus", "ACTIVE");

                List <CompanyPaymentPackage> companyPaymentPackages = (from cpp in dataContext.CompanyPaymentPackages
                                                                       where cpp.Company.CompanyStatusCodeId == companyActiveStatusCodeId &&
                                                                       cpp.PaymentMethodCodeId == null && cpp.StartDate <= dateToConsider &&
                                                                       (cpp.EndDate > dateToConsider || cpp.EndDate == null)
                                                                       select cpp).Distinct().ToList();

                foreach (CompanyPaymentPackage cpp in companyPaymentPackages)
                {
                    int     companyId = cpp.CompanyId;
                    decimal totalDue  = financeBL.CalculateALLPackageAmountsByPeriod(cpp.ProjectPaymentPackageTypeId, cpp.InventoryPaymentPackageTypeId, cpp.PaymentDurationCodeId);
                    if (totalDue > 0)
                    {
                        DiscountCodeUsage currentdiscountCodeUsage = financeBL.GetDiscountCodeUsageByDate(dateToConsider, companyId);
                        //Get the current DiscountCodeUsage. If the discount is 100%, check whether use has been notified. If not check for 14 days ahead and record if not.
                        if (currentdiscountCodeUsage != null && currentdiscountCodeUsage.DiscountCode.Discount == 100)
                        {
                            CompanyDiscountNotificatonHistory companyDiscountNotificatonHistory = companyBL.GetCompanyDiscountExpireNotifiedRecord(companyId, dataContext);
                            bool hasNotifiedUser = (companyDiscountNotificatonHistory != null);

                            if (!hasNotifiedUser)
                            {
                                //Get the DiscountCode Usage and check whether it has a 100% code
                                DiscountCodeUsage discountCodeUsage = financeBL.GetDiscountCodeUsageByDate(dateToConsider.AddDays(14), companyId);

                                //If there is no 100% discount
                                if (discountCodeUsage == null || discountCodeUsage != null && discountCodeUsage.DiscountCode.Discount != 100)
                                {
                                    //1. Notify via email

                                    //2. Log in the table
                                    CompanyDiscountNotificatonHistory companyDiscountNotificatonHistories = new CompanyDiscountNotificatonHistory()
                                    {
                                        CompanyId           = companyId,
                                        Date                = Utils.Today,
                                        IsActive            = true,
                                        CreatedDate         = Utils.Today,
                                        CreatedByUserId     = 0,
                                        LastUpdatedDate     = Utils.Today,
                                        LastUpdatedByUserId = 0
                                    };

                                    dataContext.CompanyDiscountNotificatonHistories.AddObject(companyDiscountNotificatonHistories);
                                }
                            }
                        }
                        else if (currentdiscountCodeUsage == null || currentdiscountCodeUsage != null && currentdiscountCodeUsage.DiscountCode.Discount != 100)
                        {
                            //Means We have to suspend the company
                            SuspendProjectsForCompany(companyId, dataContext);
                        }
                    }
                }

                dataContext.SaveChanges();
            }
        }