public DateTime?GetDueDate(TenantLease tenantLease, TenantLeaseCharge tenantLeaseCharge)
        {
            var chargeDueType = (ChargeDueType)tenantLeaseCharge.ChargeDueType;

            switch (chargeDueType)
            {
            case ChargeDueType.OnceOnlyWhenTheLeaseStarts:
                return(tenantLease.TermStartDate);

            case ChargeDueType.OnceOnlyWhenTheLeaseEnds:
                return(tenantLease.TermEndDate);

            case ChargeDueType.OnceOnlyOnaSpecificDate:
                return(tenantLeaseCharge.ChargeDueDate);

            case ChargeDueType.MonthlyOnaSpecificDay:
                var chargeDueDate = GenerateNextDay(tenantLeaseCharge.ValidFrom.Value, tenantLeaseCharge.ChargeDueDay.Value);
                if (chargeDueDate >= tenantLeaseCharge.ValidFrom.Value && chargeDueDate <= tenantLeaseCharge.ValidTo.Value)
                {
                    return(chargeDueDate);
                }
                return(null);

            case ChargeDueType.EachTimeRentIsDue:
            default:
                return(null);
            }
            ;
        }
Example #2
0
        /// <summary>
        /// The ChargePayment field has changed or not
        /// </summary>
        /// <param name="prevTenantLease"></param>
        /// <param name="curTenantLease"></param>
        /// <returns></returns>
        private bool HasChangedChargePayment(TenantLeaseCharge tenantLeaseCharge, TenantLeaseChargeModel model)
        {
            var changed = model.IsNew == false && (tenantLeaseCharge.ChargeTypeId != model.ChargeTypeId ||
                                                   tenantLeaseCharge.ChargeAmount != model.ChargeAmount ||
                                                   tenantLeaseCharge.ChargeDueType != (int?)model.ChargeDueType ||
                                                   tenantLeaseCharge.ChargeDueDate != model.ChargeDueDate ||
                                                   tenantLeaseCharge.ChargeDueDay != model.ChargeDueDay ||
                                                   tenantLeaseCharge.ValidFrom != model.ValidFrom ||
                                                   tenantLeaseCharge.ValidTo != model.ValidTo);

            return(changed);
        }
        public virtual void CreateChargePayment(TenantLeaseCharge tenantLeaseCharge, DateTime?dueDate)
        {
            var tenantLease   = tenantLeaseCharge.TenantLease;
            var tenantPayment = new TenantPayment
            {
                SiteId              = tenantLease.SiteId,
                TenantId            = tenantLease.TenantId,
                PropertyId          = tenantLease.PropertyId,
                TenantLeaseId       = tenantLease.Id,
                TenantLeaseChargeId = tenantLeaseCharge.Id,
                DueDate             = dueDate,
                ChargeTypeId        = tenantLeaseCharge.ChargeTypeId,
                DueAmount           = tenantLeaseCharge.ChargeAmount,
                CollectedAmount     = 0,
                BalanceAmount       = tenantLeaseCharge.ChargeAmount
            };

            //Will create payment only when has DueDate
            if (tenantPayment.DueDate.HasValue)
            {
                _tenantPaymentRepository.Insert(tenantPayment);
            }
        }
Example #4
0
        public ActionResult CreateTenantLeaseCharge(long tenantLeaseId)
        {
            //need to get tenantLease here to assign to new tenantLeaseCharge
            //so when mapping to Model, we will have StoreId as defined
            //in AutoMapper configuration
            var tenantLease       = _tenantLeaseRepository.GetById(tenantLeaseId);
            var tenantLeaseCharge = new TenantLeaseCharge
            {
                IsNew       = true,
                TenantLease = tenantLease
            };

            _tenantLeaseChargeRepository.Insert(tenantLeaseCharge);

            this._dbContext.SaveChanges();

            var model = new TenantLeaseChargeModel();

            model = tenantLeaseCharge.ToModel();
            PrepareTenantLeaseChargeModel(model);
            var html = this.TenantLeaseChargePanel(model);

            return(Json(new { Id = tenantLeaseCharge.Id, Html = html, ChargeDueType = model.ChargeDueType }));
        }