Exemple #1
0
        public ActionResult ProcessPayrollGeneration(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() });


                //var structureList = dbContext.SalaryStructureDetails.Where(x => x.BranchId == 10006).ToList();
                PayrollBatchVm vm = new PayrollBatchVm();
                //Session["ConfirmError"] = "";
                //var netsalarytotal = salarystructureheaderBo.GetAll();
                //if (netsalarytotal != null)
                //{
                //    vm.payslipBatchHeader.TotalSalary = salarystructureheaderBo.GetListByProperty(x => x.BranchId == BRANCHID && x.IsActive==true).Sum(x => x.NetAmount);
                //}
                // vm.dt = PayslipbatchheaderBo.GeneratePayslip(Convert.ToInt16(BRANCHID), 4, 2018);
                return(RedirectToAction("ProcessPayroll", new { currentmonth, currentyear }));
            }
        }
Exemple #2
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));
            }
        }