Пример #1
0
        /// <summary>
        /// افزايش باقيمانده مرخصي
        /// </summary>
        /// <param name="remainMinutes">به روز و دقيقه تبديل ميشود</param>
        /// <param name="date">تاريخ</param>
        public virtual void AddRemainLeaveMinute(int value)
        {
            try
            {
                if (value < 0)
                {
                    throw new Exception("AddRemainLeaveMinutes:Value <0");
                }
                PersianDateTime pdateTime = CalculationDate;
                int             month     = pdateTime.Month;

                #region Add UsedDetail

                UsedLeaveDetail detail = new UsedLeaveDetail();
                detail.UsedBudget = UsedBudget;
                detail.Date       = CalculationDate.GregorianDate;
                detail.Value      = value * -1;
                UsedBudget.DetailList.Add(detail);

                #endregion

                #region بدهکاری مرخصی
                if (this.Debit >= value)
                {
                    this.Debit -= value;
                    value       = 0;
                }
                else
                {
                    value     -= this.Debit;
                    this.Debit = 0;
                }
                #endregion

                if (UsedBudget[month - 1] >= value)
                {
                    UsedBudget[month - 1] -= value;
                    value = 0;
                }
                else
                {
                    value -= UsedBudget[month - 1];
                    UsedBudget[month - 1] = 0;
                }
                #region ماههای بعد
                if (!LeaveSettings.DoNotUseFutureMounthLeave)
                {
                    //ماههای بعد
                    for (int i = BudgetYear.Length - 1; i >= month && value > 0; i--)
                    {
                        if (UsedBudget[i] >= value)
                        {
                            UsedBudget[i] -= value;
                            value          = 0;
                        }
                        else
                        {
                            value        -= UsedBudget[month - 1];
                            UsedBudget[i] = 0;
                        }
                    }
                }
                #endregion

                #region ماههای قبل
                //ماههای قبل
                for (int i = month - 2; i >= 0 && value > 0; i--)
                {
                    if (UsedBudget[i] >= value)
                    {
                        UsedBudget[i] -= value;
                        value          = 0;
                    }
                    else
                    {
                        value        -= UsedBudget[month - 1];
                        UsedBudget[i] = 0;
                    }
                }
                #endregion

                #region طلب سالانه
                if (value > 0)
                {
                    CalculatedDemandLeave += value;
                    value = 0;
                }
                #endregion
            }
            catch (Exception ex)
            {
                throw new Exception("خطا در بخش مدیریت مرخصی ها.کد 103", ex);
            }
        }
Пример #2
0
        /// <summary>
        /// تعدادي مرخصي براي شخص در يک ماه خاص منظور ميکند
        /// اولويت:1-باقيمانده ماه جاري 2-طلب ساليانه 3-ماههاي گذشته 4-ماههاي آينده
        /// </summary>
        /// <param name="remainMinutes">به روز و دقيقه تبديل ميشود</param>
        /// <param name="date"></param>
        public virtual void AddUsedLeave(int value)
        {
            try
            {
                if (value != 0)
                {
                    PersianDateTime pdateTime         = CalculationDate;
                    int             month             = pdateTime.Month;
                    int             monthDayRemain    = Convert.ToInt32(value / MinutesInDay);
                    decimal         monthMinuteRemain = value - monthDayRemain * MinutesInDay;
                    int             requestedLeave    = value;


                    #region addUsedLeave
                    int allowedLeave = BudgetYear[month - 1] - UsedBudget[month - 1];
                    //کسر از مانده ماه جاري
                    if (value <= allowedLeave)
                    {
                        UsedBudget[month - 1] += value;
                        value = 0;
                    }
                    else
                    {
                        UsedBudget[month - 1] += allowedLeave;
                        value -= allowedLeave;
                    }
                    //کسر از طلب سالانه
                    if (value > 0)
                    {
                        int demandLeave = GetDemandLeave();
                        if (value <= demandLeave)
                        {
                            UsedBudget[month - 1] += value;
                            BudgetYear[month - 1] += value;
                            CalculatedDemandLeave -= value;
                            value = 0;
                        }
                        else
                        {
                            UsedBudget[month - 1] += demandLeave;
                            BudgetYear[month - 1] += demandLeave;
                            value -= CalculatedDemandLeave;
                            CalculatedDemandLeave = 0;
                        }
                    }
                    //کسر از طلب ماههاي قبل
                    if (value > 0)
                    {
                        for (int i = 0; i < month - 1; i++)
                        {
                            allowedLeave = BudgetYear[i] - UsedBudget[i];
                            if (value <= allowedLeave)
                            {
                                UsedBudget[month - 1] += value;
                                BudgetYear[i]         -= value;
                                BudgetYear[month - 1] += value;
                                value = 0;
                                break;
                            }
                            else
                            {
                                UsedBudget[month - 1] += allowedLeave;
                                BudgetYear[i]         -= allowedLeave;
                                BudgetYear[month - 1] += allowedLeave;
                                value -= allowedLeave;
                            }
                        }
                    }
                    //کسر از باقيمانده ماههاي آينده
                    if (value > 0 && !LeaveSettings.DoNotUseFutureMounthLeave)
                    {
                        for (int i = month; i < BudgetYear.Length; i++)
                        {
                            allowedLeave = BudgetYear[i] - UsedBudget[i];
                            if (value <= allowedLeave)
                            {
                                UsedBudget[month - 1] += value;
                                BudgetYear[i]         -= value;
                                BudgetYear[month - 1] += value;
                                value = 0;
                                break;
                            }
                            else
                            {
                                UsedBudget[month - 1] += allowedLeave;
                                BudgetYear[i]         -= allowedLeave;
                                BudgetYear[month - 1] += allowedLeave;
                                value -= allowedLeave;
                            }
                        }
                    }

                    //افزودن به بدهکاری سالیانه
                    if (value > 0)
                    {
                        this.Debit += value;
                        value       = 0;
                    }

                    #endregion

                    #region Add UsedDetail
                    if (value == 0)
                    {
                        UsedLeaveDetail detail = new UsedLeaveDetail();
                        detail.UsedBudget = UsedBudget;
                        detail.Date       = CalculationDate.GregorianDate;
                        detail.Value      = requestedLeave;
                        UsedBudget.DetailList.Add(detail);
                    }
                    #endregion

                    if (value > 0)
                    {
                        throw new OutOfExpectedRangeException("0", GetRemainLeave(CalculationDate.GregorianDate).ToString(), value.ToString(),
                                                              "GTS.Clock.Model.Concepts.BudgetYear.AddUsedLeave(end of method) Date:" + CalculationDate.ToString(), "The Total Remain Leave Is Less Than Value. \n the value checked at the top of the function but at the end of it value is not valid.there is a bad problem at the checking session \n rollback is needed here", ExceptionType.FATAL);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("خطا در بخش مدیریت مرخصی ها.کد 102", ex);
            }
        }