Exemplo n.º 1
0
        public string ChangeStatus(FormCollection collection)
        {
            try
            {
                //Added DCR History details for Mobile
                BLApproval  _objApproval    = new BLApproval();
                DALApproval _objDALApproval = new DALApproval();
                string      leaveEntry      = collection["LeaveValidation"].ToString();
                string      remarks         = collection["Remarks"].ToString();
                string      status          = collection["Status"].ToString();
                string      dcrCode         = collection["DCRCode"].ToString();
                string      flag            = collection["Flag"].ToString();
                string      leaveType       = collection["LeaveTypeName"].ToString();
                string      userCode        = collection["UserCode"].ToString();
                string      calcFields      = collection["CalcFields"].ToString();
                string      DCR_ENTRY_UNAPPROVED_ACTIVITY_LOCK = collection["DCR_ENTRY_UNAPPROVED_ACTIVITY_LOCK"].ToString();
                string      dcr_Actual_Date = collection["DCR_Actual_Date"].ToString();
                string      twoActivityExpenseValidation = collection["twoActivityExpenseValidation"].ToString();
                string      fareDailyAllowance           = collection["fareDailyAllowance"].ToString();

                string calcFieldStatus = calcFields.ToUpper() == "APPLIED" ? "1" : "2";


                string[] privValues;
                //   string leaveTypeName = "";
                //   bool isCurBalanceNeed = false;
                //   double dblLeaveBalance = 0.0;

                string dcrStatus;
                int    CurrexpenseClaimValidation = 0;

                privValues = leaveEntry.Split(',');

                if (status == "0")
                {
                    if (string.IsNullOrEmpty(remarks))
                    {
                        return("FAIL:Reason must be given for unapproval");
                    }
                }

                if (twoActivityExpenseValidation.ToUpper() != "NO" && fareDailyAllowance != "" && flag != "L" && status == "0")
                {
                    string twoActivityDCRApproval = _objDALApproval.GetTwoActivityDCRApproval(dcrCode, flag, fareDailyAllowance);

                    objData.OpenConnection(_objCurrentInfo.GetCompanyCode());
                    {
                        dcrStatus = (string)objData.ExecuteScalar("exec SP_hdGetDCRStatus '" + _objCurrentInfo.GetCompanyCode() + "','" + dcrCode + "','" + flag + "'");
                    }
                    if (dcrStatus == "2")
                    {
                        CurrexpenseClaimValidation = _objDALApproval.CheckExpenseClaim(_objCurrentInfo.GetCompanyCode(), userCode, dcrCode, flag, dcr_Actual_Date);
                        if (CurrexpenseClaimValidation > 0)
                        {
                            return("FAIL:You Cannot Unapprove the DCR-" + dcr_Actual_Date + "  " + ((flag == "F") ? "Field" : ((flag == "A") ? "Attendace" : "Leave")) + " as the expenses are claimed in expenses claim");
                        }
                        string expenseClaimValidation = _objDALApproval.CheckDayExpenseClaim(dcrCode, flag);
                        if (expenseClaimValidation != "")
                        {
                            return("FAIL:You Cannot Unapprove the other DCR-" + expenseClaimValidation.Split('|')[0] + "  " + ((expenseClaimValidation.Split('|')[1] == "F") ? "Field" : ((expenseClaimValidation.Split('|')[1] == "A") ? "Attendace" : "Leave")) + " as the expenses are claimed in expenses claim");
                        }
                    }

                    if (twoActivityDCRApproval != "")
                    {
                        string TwoActivitydcrCode      = twoActivityDCRApproval.Split('|')[0];
                        string TwoActivityflag         = twoActivityDCRApproval.Split('|')[1];
                        string TwoActivitydcrStatusOld = twoActivityDCRApproval.Split('|')[2];
                        // dcrStatusOld = ((dcrStatusOld == "Applied") ? "1" : "0");
                        string TwoActivityoldReason     = twoActivityDCRApproval.Split('|')[3];
                        string TwoActivityleaveTypeName = twoActivityDCRApproval.Split('|')[4];
                        string TwoActivitydcrDate       = twoActivityDCRApproval.Split('|')[5];


                        objData.OpenConnection(_objCurrentInfo.GetCompanyCode());
                        {
                            dcrStatus = (string)objData.ExecuteScalar("exec SP_hdGetDCRStatus '" + _objCurrentInfo.GetCompanyCode() + "','" + TwoActivitydcrCode + "','" + TwoActivityflag + "'");
                        }

                        if (dcrStatus == "1" || dcrStatus == "2") // Applied and Approved
                        {
                            objData.OpenConnection(_objCurrentInfo.GetCompanyCode());
                            {
                                objData.ExecuteNonQuery("exec SP_hdUpdateDCRApproval '" + _objCurrentInfo.GetCompanyCode() + "','" + TwoActivitydcrCode + "','" + TwoActivityflag + "','" + status + "','" + _objCurrentInfo.GetUserName() + "','" + DateTime.Now.ToString() + "','" + remarks + "','" + TwoActivitydcrStatusOld + "','" + userCode + "'");
                            }
                            int firstexpenseRowCount = 0;
                            firstexpenseRowCount = _objDALApproval.DeleteDCRExpense(TwoActivityflag, TwoActivitydcrCode, fareDailyAllowance);

                            if (DCR_ENTRY_UNAPPROVED_ACTIVITY_LOCK.ToUpper().Trim() == "ENABLED")
                            {
                                IDCRLock objDCRLock = new BLDCRLock();
                                List <DCRActivityLockModel> lstDCRActivityLockModel = new List <DCRActivityLockModel>();

                                DCRActivityLockModel dcrActivityLockModel = new DCRActivityLockModel();
                                string comany_Code = _objCurrentInfo.GetCompanyCode();
                                dcrActivityLockModel.User_Code       = userCode;
                                dcrActivityLockModel.DCR_Actual_Date = dcr_Actual_Date;
                                dcrActivityLockModel.Activity_Flag   = TwoActivityflag;
                                dcrActivityLockModel.Locked_Date     = DateTime.Now.ToShortDateString();
                                lstDCRActivityLockModel.Add(dcrActivityLockModel);
                                int result = objDCRLock.InsertActivityLock(comany_Code, lstDCRActivityLockModel);
                            }
                            int result_History = _objApproval.InsertDcrHistory(_objCurrentInfo.GetCompanyCode(), TwoActivitydcrCode, TwoActivityflag);
                        }
                        else
                        {
                            return("FAIL:You cannot change the status of Unapproved DCRs.");
                        }
                    }
                }

                objData.OpenConnection(_objCurrentInfo.GetCompanyCode());
                {
                    dcrStatus = (string)objData.ExecuteScalar("exec SP_hdGetDCRStatus '" + _objCurrentInfo.GetCompanyCode() + "','" + dcrCode + "','" + flag + "'");
                }

                if (dcrStatus == "1" || dcrStatus == "2") // Applied and Approved
                {
                    //START: The Leave entry validation finctionality commented as per Customer Service Request.
                    //if (flag == "L")
                    // {
                    //leaveTypeName = leaveType;

                    //isCurBalanceNeed = false;

                    //for (int j = 0; j < privValues.Length; j++)
                    //{
                    //    if (privValues[j].ToString().Trim().ToUpper() == leaveTypeName.ToUpper())
                    //    {
                    //        isCurBalanceNeed = true;
                    //        break;
                    //    }
                    //}

                    //dblLeaveBalance = 0.0;

                    //if (isCurBalanceNeed)
                    //{
                    //    objData.OpenConnection(_objCurrentInfo.GetCompanyCode());
                    //    {
                    //        object leaveBal = objData.ExecuteScalar("exec SP_hdGetLeaveBalance '" + _objCurrentInfo.GetCompanyCode() + "','" + dcrCode + "','" + userCode + "'");
                    //        if (leaveBal.ToString() != "" && leaveBal != null)
                    //        {
                    //            if (!string.IsNullOrEmpty(leaveBal.ToString()))
                    //            {
                    //                dblLeaveBalance = float.Parse(leaveBal.ToString());
                    //            }
                    //        }
                    //    }

                    //    if (dblLeaveBalance > 0)
                    //    {
                    //        objData.OpenConnection(_objCurrentInfo.GetCompanyCode());
                    //        {
                    //            objData.ExecuteNonQuery("exec SP_hdUpdateDCRApproval '" + _objCurrentInfo.GetCompanyCode() + "','" + dcrCode + "','" + flag + "','" + status + "','" + _objCurrentInfo.GetUserName() + "','" + DateTime.Now.ToString() + "','" + remarks + "','" + calcFieldStatus + "','" + userCode + "'");
                    //        }
                    //        objData.OpenConnection(_objCurrentInfo.GetCompanyCode());
                    //        {
                    //            objData.ExecuteNonQuery("exec SP_hdUpdateUserLeaveCurBalance '" + _objCurrentInfo.GetCompanyCode() + "','" + dcrCode + "','" + flag + "','" + userCode + "','" + dcrStatus + "','" + status + "'");
                    //        }
                    //    }
                    //    else if (status == "0")
                    //    {
                    //        objData.OpenConnection(_objCurrentInfo.GetCompanyCode());
                    //        {
                    //            objData.ExecuteNonQuery("exec SP_hdUpdateDCRApproval '" + _objCurrentInfo.GetCompanyCode() + "','" + dcrCode + "','" + flag + "','" + status + "','" + _objCurrentInfo.GetUserName() + "','" + DateTime.Now.ToString() + "','" + remarks + "','" + calcFieldStatus + "','" + userCode + "'");
                    //        }

                    //        objData.OpenConnection(_objCurrentInfo.GetCompanyCode());
                    //        {
                    //            objData.ExecuteNonQuery("exec SP_hdUpdateUserLeaveCurBalance '" + _objCurrentInfo.GetCompanyCode() + "','" + dcrCode + "','" + flag + "','" + userCode + "','" + dcrStatus + "','" + status + "'");
                    //        }
                    //    }
                    //    else
                    //    {
                    //        return "FAIL:Due to insufficient leave balance, unable to approve leave for " + leaveTypeName + "";
                    //    }
                    //}
                    //else
                    //{
                    //    objData.OpenConnection(_objCurrentInfo.GetCompanyCode());
                    //  {
                    //    objData.ExecuteNonQuery("exec SP_hdUpdateDCRApproval '" + _objCurrentInfo.GetCompanyCode() + "','" + dcrCode + "','" + flag + "','" + status + "','" + _objCurrentInfo.GetUserName() + "','" + DateTime.Now.ToString() + "','" + remarks + "','" + calcFieldStatus + "','" + userCode + "'");
                    //}
                    //}
                    //}
                    //END: The Leave entry validation finctionality commented as per Customer Service Request.

                    objData.OpenConnection(_objCurrentInfo.GetCompanyCode());
                    {
                        objData.ExecuteNonQuery("exec SP_hdUpdateDCRApproval '" + _objCurrentInfo.GetCompanyCode() + "','" + dcrCode + "','" + flag + "','" + status + "','" + _objCurrentInfo.GetUserName() + "','" + DateTime.Now.ToString() + "','" + remarks + "','" + calcFieldStatus + "','" + userCode + "'");
                    }
                    if (flag.ToUpper() != "L" && status == "0")
                    {
                        int secondexpenseRowCount = 0;
                        secondexpenseRowCount = _objDALApproval.DeleteDCRExpense(flag, dcrCode, fareDailyAllowance);
                    }

                    if (DCR_ENTRY_UNAPPROVED_ACTIVITY_LOCK.ToUpper().Trim() == "ENABLED")
                    {
                        IDCRLock objDCRLock = new BLDCRLock();
                        List <DCRActivityLockModel> lstDCRActivityLockModel = new List <DCRActivityLockModel>();

                        DCRActivityLockModel dcrActivityLockModel = new DCRActivityLockModel();
                        string comany_Code = _objCurrentInfo.GetCompanyCode();
                        dcrActivityLockModel.User_Code       = userCode;
                        dcrActivityLockModel.DCR_Actual_Date = dcr_Actual_Date;
                        dcrActivityLockModel.Activity_Flag   = flag;
                        dcrActivityLockModel.Locked_Date     = DateTime.Now.ToShortDateString();
                        lstDCRActivityLockModel.Add(dcrActivityLockModel);
                        int result = objDCRLock.InsertActivityLock(comany_Code, lstDCRActivityLockModel);
                        if (result > 0)
                        {
                            return("SUCCESS:Status Changed Successfully. But Insert Activity Lock Fail.");
                        }
                    }
                    int result_History = _objApproval.InsertDcrHistory(_objCurrentInfo.GetCompanyCode(), dcrCode, flag);
                }
                else
                {
                    return("FAIL:You cannot change the status of Unapproved DCRs.");
                }

                return("SUCCESS:Status Changed Successfully");
            }
            finally
            {
                objData.CloseConnection();
            }
        }
Exemplo n.º 2
0
        public bool InsertAllValues(FormCollection collection)
        {
            DALApproval _objApproval = new DALApproval();

            try
            {
                bool               result = true;
                string             stockiestData = string.Empty, expenseData = string.Empty, dailyAllowance = string.Empty, dcrCode = string.Empty, dcrDate = string.Empty, dcrStatus = string.Empty;
                int                isSubmit               = 0;
                string             dcrFlag                = string.Empty;
                string             commonRemarks          = string.Empty;
                string             commonRemarksMandatory = string.Empty;
                DateCapturingModel _objDateDetails        = new DateCapturingModel();
                stockiestData          = collection["tblStockiestData"].ToString();
                expenseData            = collection["tblExpenseData"].ToString();
                dailyAllowance         = collection["dailyAllowance"].ToString();
                dcrDate                = collection["dcrDate"].ToString();
                dcrCode                = _objCurr.GetDCRCode(dcrDate);
                dcrStatus              = collection["dcrStatus"].ToString();
                isSubmit               = Convert.ToInt32(collection["submit"]);
                dcrFlag                = collection["flag"].ToString();
                commonRemarks          = collection["commonRemarks"].ToString();
                commonRemarksMandatory = collection["comRemarkMandatory"].ToString();
                _objDateDetails        = JsonConvert.DeserializeObject <DateCapturingModel>(collection["_objDateDetails"]);
                string companyCode = _objCurr.GetCompanyCode();
                string userCode    = _objCurr.GetUserCode();

                if (!(_objDateDetails.Off_Set.Contains('+') && !(_objDateDetails.Off_Set.Contains('-'))))
                {
                    _objDateDetails.Off_Set = '+' + _objDateDetails.Off_Set.Trim();
                }
                if (dcrFlag != "A")
                {
                    result = _objDCRBL.InsertStockiest(companyCode, userCode, dcrCode, dcrDate, dcrStatus, stockiestData);
                }
                else
                {
                    result = true;
                }

                if (result)
                {
                    result = _objDCRBL.InsertExpense(companyCode, userCode, dcrCode, expenseData, dcrDate, dcrStatus, dailyAllowance, dcrFlag, _objDateDetails);
                }

                if (result)
                {
                    // update product. This block is for save and submit button.
                    if (isSubmit == 1)
                    {
                        result = _objDCRBL.UpdateProductAndStatus(companyCode, userCode, _objCurr.GetUserName(), _objCurr.GetRegionCode(), _objCurr.GetRegionName(),
                                                                  dcrCode, dcrDate, collection["autoApproval"].ToString(), dcrFlag, _objCurr.GetLattitude(), _objCurr.GetLongitude(), _objCurr.GetLocation());

                        //try
                        //{
                        //    IQueueService<DCRQueue> dcrHeaderQueue = new QueueService<DCRQueue>(_queueAccountKey, _topicName, _subscriptionName);
                        //    if (dcrHeaderQueue.Initialize())
                        //    {
                        //        DCRQueue dcrQueue = new DCRQueue();

                        //        dcrQueue.CompanyCode = _objCurr.GetCompanyCode();
                        //        dcrQueue.DCRCode = dcrCode;
                        //        dcrQueue.UserCode = _objCurr.GetUserCode();
                        //        dcrQueue.UserName = _objCurr.GetUserName();
                        //        dcrQueue.DCRDate = dcrDate;
                        //        dcrQueue.ActivityFlag = dcrFlag;
                        //        dcrQueue.DCRStatus = Convert.ToInt32(dcrStatus);
                        //        if (commonRemarksMandatory == "NO")
                        //        {
                        //            dcrQueue.Event = "APPLIED";
                        //        }
                        //        else
                        //        {
                        //            dcrQueue.Event = "REAPPLIED";
                        //        }

                        //        DCRQueueTracker dcrQueueTracker = new DCRQueueTracker();
                        //        dcrQueueTracker.CompanyCode = companyCode;
                        //        dcrQueueTracker.UserCode = _objCurr.GetUserCode();
                        //        dcrQueueTracker.DCRCode = dcrCode;
                        //        dcrQueueTracker.Flag = dcrFlag;
                        //        dcrQueueTracker.TopicName = _topicName;
                        //        dcrQueueTracker.SubscriptionName = _subscriptionName;
                        //        dcrQueueTracker.ProcessStatus = 0;
                        //        dcrQueueTracker.EventName = dcrQueue.Event;


                        //        List<DCRQueue> dcrQueueList = new List<DCRQueue>();
                        //        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 eventName = commonRemarksMandatory == "NO" ? "Applied" : "ReApplied";
                        //    blDCRHeader.InsertDCRQueueExceptionLogs(_objCurr.GetCompanyCode(), dcrCode, dcrFlag, userCode, dcrDate, ex.Message, ex.StackTrace, eventName);
                        //}


                        //delete dcr temp table records
                        if (result)
                        {
                            result = _objDCRBL.DeleteDCRTempTableRecords(companyCode, dcrCode, dcrFlag);
                        }
                    }
                }

                // update common remarks remarks
                if (result)
                {
                    if (commonRemarks != "")
                    {
                        result = _objDCRBL.UpdateDCRCommonRemarks(companyCode, dcrCode, dcrFlag, dcrStatus, commonRemarks, isSubmit.ToString(), "1");
                    }
                    else
                    {
                        result = _objDCRBL.UpdateDCRCommonRemarks(companyCode, dcrCode, dcrFlag, dcrStatus, commonRemarks, isSubmit.ToString(), "0");
                    }
                }
                if (isSubmit == 1)
                {
                    result = _objDCRBL.UpdatePOBOrderStatus(companyCode, "-1", "1", "0", _objCurr.GetUserCode(), dcrDate);
                }
                int result_History = _objApproval.InsertDcrHistory(_objCurr.GetCompanyCode(), dcrCode, dcrFlag);

                return(result);
            }
            catch
            {
                throw;
            }
        }