예제 #1
0
        public string InsertLeave(FormCollection collection)
        {
            string result               = string.Empty;
            string fromDate             = collection["fromDate"].ToString();
            string toDate               = collection["toDate"].ToString();
            string reason               = collection["reason"].ToString();
            string leaveTypeCode        = collection["leaveTypeCode"].ToString();
            string sundayValidation     = collection["sundayValidation"].ToString();
            string isWeekend            = collection["isAddedWeekendHoliday"].ToString();
            string entryMode            = collection["entryMode"].ToString();
            string isAddHoliday         = collection["isAddHoliday"].ToString();
            int    originOfDCR          = 0;
            string checkLeaveValidation = string.Empty;
            //userLeaveTypeCode=" + userLeaveTypeCode + "&leaveTypeName=" + $("#ddlLeaveType :selected").text() + "&noOfDays=" + noOfDays,
            string userLeaveTypeCode   = collection["userLeaveTypeCode"].ToString();
            string leaveTypeName       = collection["leaveTypeName"].ToString();
            double noOfDays            = Convert.ToDouble(collection["noOfDays"]);
            string leaveweekendHoliday = string.Empty;

            if (entryMode == "WEB")
            {
                originOfDCR = 1;
            }
            else if (entryMode == "MOBILE")
            {
                originOfDCR = 2;
            }

            // check leave validation
            checkLeaveValidation = _objSP.CheckLeaveValidation(fromDate, toDate, leaveTypeCode, userLeaveTypeCode, leaveTypeName, isWeekend, isAddHoliday, noOfDays);

            if (checkLeaveValidation.Split('|')[0] == "SUCCESS" || checkLeaveValidation == "")
            {
                if (checkLeaveValidation != "")
                {
                    /*SET @Result= 'SUCCESS^'+@OtherLeaveType+'^'+@OtherLeaveTypeName+'^'+@HOLIDAYDATES+'^'+@WEEKENDDATES
                     +'^'+ISNULL(CONVERT(VARCHAR,@CurrentLeaveTypeBalane),'')+'^'+ISNULL(CONVERT(VARCHAR,@OtherLeaveTypeBalane),'')
                     +'^'+ISNULL(CONVERT(VARCHAR,@IntermediateDateCount),'')*/
                    string otherLeaveType      = checkLeaveValidation.Split('|')[1];
                    string otherLeaveName      = checkLeaveValidation.Split('|')[2];
                    string holidayDates        = checkLeaveValidation.Split('|')[3];
                    string weekendDates        = checkLeaveValidation.Split('|')[4];
                    double currentLeaveBal     = Convert.ToDouble(checkLeaveValidation.Split('|')[5]);
                    double otherLeaveBal       = Convert.ToDouble(checkLeaveValidation.Split('|')[6]);
                    int    weekendHolidayDates = Convert.ToInt32(checkLeaveValidation.Split('|')[7]);

                    if (weekendHolidayDates > 0)
                    {
                        int totalLeaves   = (weekendDates.Split('^').Count() - 1) + (holidayDates.Split('^').Count() - 1);
                        int leaveAssigned = 0;
                        foreach (string weekend in weekendDates.Split('^'))
                        {
                            if (weekend != "")
                            {
                                leaveAssigned++;
                                if (leaveAssigned <= currentLeaveBal)
                                {
                                    //assign leave for currentleave type
                                    leaveweekendHoliday += weekend + "^";
                                    leaveweekendHoliday += leaveTypeCode + "^";
                                }
                                else if (otherLeaveType != "" && leaveAssigned <= otherLeaveBal)
                                {
                                    //assign leave for other leave type
                                    leaveweekendHoliday += weekend + "^";
                                    leaveweekendHoliday += otherLeaveType + "^";
                                }
                                else
                                {
                                    result = "No enough leave balance to enter the leave..";
                                    return(result);
                                }
                            }
                        }

                        foreach (string holiday in holidayDates.Split('^'))
                        {
                            if (holiday != "")
                            {
                                if (!weekendDates.Split('^').Contains(holiday))
                                {
                                    leaveAssigned++;
                                    if (leaveAssigned <= currentLeaveBal)
                                    {
                                        //assign leave for currentleave type
                                        leaveweekendHoliday += holiday + "^";
                                        leaveweekendHoliday += leaveTypeCode + "^";
                                    }
                                    else if (otherLeaveType != "" && leaveAssigned <= otherLeaveBal)
                                    {
                                        //assign leave for other leave type
                                        leaveweekendHoliday += holiday + "^";
                                        leaveweekendHoliday += otherLeaveType + "^";
                                    }
                                    else
                                    {
                                        result = "No enough leave balance to enter the leave...";
                                        return(result);
                                    }
                                }
                            }
                        }
                    }
                }
                result = _objSP.InsertLeave(fromDate, toDate, reason, leaveTypeCode, sundayValidation, isWeekend, entryMode, originOfDCR, isAddHoliday, leaveweekendHoliday);


                DateTime leaveFromDate = Convert.ToDateTime(fromDate);
                DateTime leaveToDate   = Convert.ToDateTime(toDate);

                for (DateTime i = leaveFromDate; i <= leaveToDate; i = i.AddDays(1))
                {
                    try
                    {
                        IQueueService <DCRQueue> dcrHeaderQueue = new QueueService <DCRQueue>(_queueAccountKey, _topicName, _subscriptionName);
                        if (dcrHeaderQueue.Initialize())
                        {
                            DCRQueue        dcrQueue     = new DCRQueue();
                            List <DCRQueue> dcrQueueList = new List <DCRQueue>();
                            dcrQueue.CompanyCode  = _objCurr.GetCompanyCode();
                            dcrQueue.DCRCode      = _objCurr.GetDCRCode(i.ToString("yyyy-MM-dd"));
                            dcrQueue.UserCode     = _objCurr.GetUserCode();
                            dcrQueue.UserName     = _objCurr.GetUserName();
                            dcrQueue.DCRDate      = i.ToShortDateString();
                            dcrQueue.ActivityFlag = "L";
                            dcrQueue.DCRStatus    = 1;//Convert.ToInt32(dcrStatus);

                            dcrQueue.Event = "APPLIED";


                            DCRQueueTracker dcrQueueTracker = new DCRQueueTracker();
                            dcrQueueTracker.CompanyCode      = _objCurr.GetCompanyCode();
                            dcrQueueTracker.UserCode         = _objCurr.GetUserCode();
                            dcrQueueTracker.DCRCode          = _objCurr.GetDCRCode(i.ToString("yyyy-MM-dd"));
                            dcrQueueTracker.Flag             = "L";
                            dcrQueueTracker.TopicName        = _topicName;
                            dcrQueueTracker.SubscriptionName = _subscriptionName;
                            dcrQueueTracker.ProcessStatus    = 0;
                            dcrQueueTracker.EventName        = dcrQueue.Event;


                            dcrQueueList.Add(dcrQueue);
                            dcrQueueTracker.JSONObject = JsonConvert.SerializeObject(dcrQueueList);

                            BL_DCRHeader blDCRHeader = new BL_DCRHeader();
                            int          Id          = blDCRHeader.InsertDCRQueueTracker(_objCurr.GetCompanyCode(), dcrQueueTracker);
                            dcrQueueList[0].Id = Id;
                            dcrQueueTracker.Id = Id;
                            if (!dcrHeaderQueue.CreateQueueItem(dcrQueueList))
                            {
                                dcrQueueTracker.Mesg          = "Queue Failed.";
                                dcrQueueTracker.StackTrace    = "";
                                dcrQueueTracker.ProcessStatus = -1;
                                blDCRHeader.UpdateDCRQueueTracker(_objCurr.GetCompanyCode(), dcrQueueTracker);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        BL_DCRHeader blDCRHeader = new BL_DCRHeader();

                        string dcrCode = _objCurr.GetDCRCode(i.ToString("yyyy-MM-dd"));
                        blDCRHeader.InsertDCRQueueExceptionLogs(_objCurr.GetCompanyCode(), dcrCode, "L", _objCurr.GetUserCode(), i.ToString("yyyy-MM-dd"), ex.Message, ex.StackTrace, "Applied");
                    }
                }
            }
            else
            {
                result = checkLeaveValidation;
            }
            return(result);
        }