示例#1
0
        public ReturnData <string> SaveToWorkFlowCenter(ProcOnlineReq procOnlineReq, HrpEmployee userDetails, string docId, string notes = null)
        {
            var wkDocCenter = new WfdocCentre
            {
                Type        = procOnlineReq.DocType.ToUpper(),
                DocNo       = procOnlineReq.ReqRef,
                Description = string.IsNullOrEmpty(notes) ? "N/A" : notes,
                UserRef     = userDetails.EmpNo,
                Names       = userDetails.Names,
                Department  = userDetails.Department,
                Rdate       = DateTime.UtcNow,
                Rtime       = DateTime.UtcNow.ToLocalTime(),
                Personnel   = userDetails.EmpNo,
                FinalStatus = "Pending"
            };

            db.WfdocCentre.Add(wkDocCenter);
            db.SaveChanges();

            var documentCenterId = db.WfdocCentre.FirstOrDefault(d => d.DocNo == procOnlineReq.ReqRef)?.Id;

            var WFRoutingDetails = db.WfroutingDetails.Where(d => d.Ref == docId).ToList();

            var departmentHeadTitle = "HEAD OF DEPARTMENT";
            var supervisorTitle     = "SUPERVISOR";
            var deanTitle           = "Dean";

            foreach (var detail in WFRoutingDetails)
            {
                var approver       = db.Wfapprovers.FirstOrDefault(a => a.Title == detail.Approver);
                var approverId     = approver?.Id.ToString();
                var approversCodes = db.WfapproversDetails.Join(db.Users,
                                                                approverDetail => approverDetail.UserCode,
                                                                users => users.UserCode,
                                                                (approverDetail, users) => new
                {
                    approverDetail.Ref,
                    approverDetail.UserCode,
                    users.Department
                }).Where(u => u.Ref == approverId).Select(u => u.UserCode).Distinct().ToList();

                if (detail.Approver.ToLower().Contains(departmentHeadTitle.ToLower()))
                {
                    approversCodes = db.WfapproversDetails.Join(db.Users,
                                                                approverDetail => approverDetail.UserCode,
                                                                users => users.UserCode,
                                                                (approverDetail, users) => new
                    {
                        approverDetail.Ref,
                        approverDetail.UserCode,
                        users.Department
                    }).Where(u => u.Department == userDetails.Department && u.Ref == approverId).Select(u => u.UserCode).Distinct().ToList();
                }

                if (detail.Approver.ToLower().Contains(supervisorTitle.ToLower()))
                {
                    var employeeSupervisor = db.HrpEmployee.FirstOrDefault(e => e.EmpNo == userDetails.EmpNo)?.Supervisor;

                    approversCodes = db.Users.Where(u => u.EmpNo == employeeSupervisor).Select(u => u.UserCode).Distinct().ToList();
                }

                if (detail.Approver.ToLower().Contains(deanTitle.ToLower()))
                {
                    approversCodes = db.Schools.Join(db.Users,
                                                     schools => schools.DeanUserName,
                                                     users => users.UserCode,
                                                     (schools, users) => new
                    {
                        users.UserCode
                    }).Select(u => u.UserCode).Distinct().ToList();
                }

                foreach (var approverCode in approversCodes)
                {
                    var wkDocCenterDetails = new WfdocCentreDetails
                    {
                        Ref            = Convert.ToString(documentCenterId),
                        Approver       = detail.Approver,
                        Level          = detail.Level,
                        UserCode       = approverCode,
                        Action         = "Approval",
                        Reason         = null,
                        Rdate          = DateTime.UtcNow,
                        ActionSelected = null,
                        Station        = null
                    };

                    db.WfdocCentreDetails.Add(wkDocCenterDetails);
                }
            }

            db.SaveChanges();

            return(new ReturnData <string>
            {
                Success = true,
                Data = ""
            });
        }
示例#2
0
//
        public JsonResult SaveIndiviualMainClaims(ClaimDetailsViewModel pmodel, string pcref)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var emp = ReturnUserNames(pmodel.UserCode);

                    if (!pmodel.RequireUnit)
                    {
                        var saveClaim = new PClaimDetailModel
                        {
                            Amount     = Convert.ToDecimal(pmodel.TotalAmount),
                            PCRef      = pcref,
                            PayAccount = pmodel.PayAccount,
                            Qty        = pmodel.Quantity,
                            Rate       = 1,
                            Units      = ReturnUnitsForClaim(pmodel.ClaimId), //to fetch units from pclaimrated table
                            Notes      = pmodel.Notes
                        };
                        SaveClaimDetails(saveClaim);
                    }


                    if (pmodel.ClaimRequestUnits?.Count > 0)
                    {
                        foreach (var unit in pmodel.ClaimRequestUnits)
                        {
                            var saveUnit =
                                "INSERT INTO [dbo].[PClaimDetail]([PCRef] ,[PayAccount],[Code],[Rate],[Units],[Qty],[Amount],[Notes])VALUES("
                                + "'" + pcref + "','"
                                + pmodel.PayAccount + "','"
                                + unit.Code + "','"
                                + 1 + "','"
                                + unit.Rate + "','"
                                + unit.Quantity + "','"
                                + unit.Total + "','"
                                + +pmodel.ClaimRequestUnits.Count + " unit(s)/added by user'"
                                + ")";
                            _context.Database.ExecuteSqlCommand(saveUnit);
                        }
                    }

                    try
                    {
                        var wcf = new WfdocCentre
                        {
                            Type        = "PART-TIME CLAIM",
                            DocNo       = pcref,
                            Description = "AMOUNT : " + pmodel.TotalAmount + " SESSION : " + pmodel.Semester,
                            UserRef     = pmodel.UserCode,
                            Names       = emp.Names,
                            Department  = emp.Department,
                            Rdate       = DateTime.Now,
                            Rtime       = DateTime.Now.ToLocalTime(),
                            Personnel   = pmodel.UserCode,
                            FinalStatus = "Pending"
                        };
                        _context.WfdocCentre.Add(wcf);

                        _context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        return(Json(new
                        {
                            status = 0,
                            message = "A server error occured,please contact the administrator : " + ex.Message
                        }));
                    }

                    return(Json(new
                    {
                        status = 1,
                        message = "Claim saved successfully"
                    }));
                }
            }
            catch (Exception e)
            {
                return(Json(new
                {
                    Success = false,
                    Message = "A server error occured,please contact the administrator ",
                    Error = new Error(e)
                }));
            }

            return(Json(new
            {
                status = 0,
                message = "Could not save claim,please try again"
            }));
        }