Example #1
0
        public ActionResult ProcessPayroll(int?currentmonth, int?currentyear)
        {
            using (var dbContext = new HrDataContext())
            {
                var list = dbContext.SalaryStructureHeaders.GroupJoin(dbContext.SalaryStructureDetails,
                                                                      a => a.StructureID, b => b.StructureID,
                                                                      (a, b) => new { A = a, B = b.ToList() });
                PayrollBatchVm vm = new PayrollBatchVm();

                if (currentmonth != null && currentyear != null)
                {
                    vm.dt = PayslipbatchheaderBo.GeneratePayslip(Convert.ToInt16(BRANCHID), currentmonth.Value, currentyear.Value);
                }
                decimal?netamount  = 0;
                var     headerlist = salarystructureheaderBo.GetListByProperty(x => x.BranchId == BRANCHID && x.EffectiveDate.Value.Month <= currentmonth && x.EffectiveDate.Value.Year == currentyear && x.IsActive == true);
                if (headerlist != null && headerlist.Count() != 0)
                {
                    //       foreach(var item in headerlist)
                    //    {
                    //        decimal sum = 0;
                    //        sum = item.NetAmount.Value;

                    //        netamount = netamount + sum;
                    //    }
                    netamount = headerlist.Sum(x => x.NetAmount).Value;
                    if (vm.payslipBatchHeader == null)
                    {
                        vm.payslipBatchHeader = new PayslipBatchHeader();
                    }
                    vm.payslipBatchHeader.TotalSalary = netamount;
                    vm.payslipBatchHeader.Month       = Convert.ToByte(currentmonth.Value);
                    vm.payslipBatchHeader.Year        = currentyear.Value;

                    var header = PayslipbatchheaderBo.GetByProperty(x => x.Month == Convert.ToByte(currentmonth.Value) && x.Year == currentyear && x.BranchId == BRANCHID);
                    if (header != null)
                    {
                        vm.payslipBatchHeader.BatchNo = PayslipbatchheaderBo.GetByProperty(x => x.Month == Convert.ToByte(currentmonth.Value) && x.Year == currentyear && x.BranchId == BRANCHID).BatchNo;
                    }
                    else
                    {
                        var batchcount = PayslipbatchheaderBo.GetCount(BRANCHID);
                        batchcount = batchcount + 1;
                        vm.payslipBatchHeader.BatchNo = "BATCH" + batchcount.ToString("D4");
                    }
                }
                else
                {
                    vm.payslipBatchHeader       = new PayslipBatchHeader();
                    vm.payslipBatchHeader.Month = Convert.ToByte(currentmonth.Value);
                    vm.payslipBatchHeader.Year  = currentyear.Value;
                }
                ViewData["ConfirmError"] = "";
                if (Session["IsError"] != null && Convert.ToBoolean(Session["IsError"]))
                {
                    ViewData["ConfirmError"] = "Please Generate The Previous Months Payslip";
                    Session.Remove("IsError");
                }
                if (vm.dt != null && vm.dt.Columns.Count > 0)
                {
                    DataRow totalsRow = vm.dt.NewRow();
                    totalsRow["EMPLOYEE NAME"] = "Total";
                    for (int j = 5; j < vm.dt.Columns.Count; j++)
                    {
                        DataColumn col = vm.dt.Columns[j];

                        decimal colTotal = 0;
                        for (int i = 0; i < col.Table.Rows.Count; i++)
                        {
                            DataRow row = col.Table.Rows[i];
                            if (row[col] == null || row[col].ToString() == "")
                            {
                                row[col] = "0.00";
                            }
                            colTotal += Convert.ToDecimal(row[col]);
                        }
                        //col.Table.Rows[j]. = Color.Red;
                        totalsRow[col.ColumnName] = colTotal;
                    }

                    vm.dt.Rows.Add(totalsRow);
                }
                //var structureList = dbContext.SalaryStructureDetails.Where(x => x.BranchId == 10006).ToList();


                return(View(vm));
            }
        }
Example #2
0
        public ActionResult add(int?EmployeeId)
        {
            ViewData["BranchId"] = BRANCHID;
            ViewData["RoleCode"] = ROLECODE;
            var count = salaryStructureHeaderBO.GetListByProperty(x => x.BranchId == BRANCHID && x.IsActive == true).Count();

            ViewData["IsEnable"] = false;
            if (count > 0)
            {
                ViewData["IsEnable"] = true;
            }
            if (EmployeeId != null)
            {
                var empObj = new EmployeeVm();

                empObj.empHeader         = empHeaderBO.GetById(EmployeeId.Value);
                empObj.empPersonalDetail = empPersonalDetailBO.GetByProperty(x => x.EmployeeId == EmployeeId.Value);
                empObj.empWorkDetail     = empWorkDetailBO.GetByProperty(x => x.EmployeeId == EmployeeId.Value);
                empObj.address           = addressBO.GetByProperty(x => x.LinkID == EmployeeId.Value && x.AddressType == UTILITY.EMPLOYEE);
                empObj.empBankdetail     = empbankdetailBO.GetByProperty(x => x.EmployeeId == EmployeeId.Value);
                List <EmployeeDocumentDetail> empDocumentDetList = empDocDetailBO.GetAll().ToList();

                var documentTypeLookupids = lookUpBO.GetByAll()
                                            .Where(x => x.LookUpCategory == UTILITY.CONFIG_DOCUMENTTYPE)
                                            .Select(x => x.LookUpID)
                                            .ToList();
                empDocumentDetList = empDocumentDetList
                                     .Where(x => x.EmployeeId == EmployeeId.Value &&
                                            documentTypeLookupids.Contains(x.DocumentType))
                                     .ToList();

                var codeList = empDocumentDetList.Select(x => x.DocumentType).ToList();

                if (empObj != null)
                {
                    if (empDocumentDetList.Count > 0)
                    {
                        List <EmployeeDocumentVm> docVmList = new List <EmployeeDocumentVm>();
                        foreach (EmployeeDocumentDetail item in empDocumentDetList)
                        {
                            EmployeeDocumentVm docVm = new EmployeeDocumentVm()
                            {
                                DocumentType        = item.DocumentType,
                                DocumentDescription = lookUpBO
                                                      .GetByProperty(y => y.LookUpCategory == UTILITY.CONFIG_DOCUMENTTYPE && y.LookUpID == item.DocumentType)
                                                      .LookUpDescription,
                                fileName         = item.FileName,
                                DocumentDetailId = item.DocumentDetailID
                            };
                            docVmList.Add(docVm);
                        }



                        empObj.empDocument = lookUpBO.GetListByProperty(y => y.LookUpCategory == UTILITY.CONFIG_DOCUMENTTYPE)
                                             .Select(y => new EmployeeDocumentVm
                        {
                            DocumentType        = y.LookUpID,
                            DocumentDescription = y.LookUpDescription
                        }).Where(x => !codeList.Contains(x.DocumentType)).ToList();
                        empObj.empDocument.AddRange(docVmList);

                        ViewData["empdocumentsPath"] = "Uploads/" + empObj.empHeader.EmployeeId + "/";
                    }
                    else
                    {
                        empObj.empDocument = lookUpBO.GetListByProperty(y => y.LookUpCategory == UTILITY.CONFIG_DOCUMENTTYPE)
                                             .Select(y => new EmployeeDocumentVm
                        {
                            DocumentType        = y.LookUpID,
                            DocumentDescription = y.LookUpDescription
                        }).ToList();
                    }
                }
                return(View(empObj));
            }
            else
            {
                var documentTypes = lookUpBO.GetListByProperty(y => y.LookUpCategory == UTILITY.CONFIG_DOCUMENTTYPE)
                                    .Select(x => new EmployeeDocumentVm
                {
                    DocumentType        = x.LookUpID,
                    DocumentDescription = x.LookUpDescription
                }).ToList();
                var listleave = new List <OtherLeave>();
                listleave = otherleaveBo.GetListByProperty(x => x.BranchId == BRANCHID && x.IsActive == true).ToList();

                var List = new List <AssignLeaves>();
                foreach (var item in listleave)
                {
                    var AssignLeaves = new AssignLeaves()
                    {
                        LeaveTypeID = item.LeaveTypeId.Value,
                        Description = item.Description,
                    };

                    List.Add(AssignLeaves);
                }

                return(View(new EmployeeVm
                {
                    empHeader = new EmployeeHeader
                    {
                        EmployeeId = -1, IsActive = true
                    },
                    empDocument = documentTypes,
                    ListAssignLeaves = List,
                    empPersonalDetail = new EmployeePersonalDetail()
                    {
                        Gender = 101
                    }
                }));
            }
        }