コード例 #1
0
        public async Task <JsonResult> Create(FormCollection fc)
        {
            Payrate o = PayrateHelper.GetObject(null, fc);

            Dictionary <string, object> err = null;

            ISession se = NHibernateHelper.CurrentSession;

            err = o.IsValid();

            if (err == null)
            {
                await Task.Run(() =>
                {
                    using (ITransaction tx = se.BeginTransaction())
                    {
                        se.SaveOrUpdate(o);
                        tx.Commit();
                    }
                });

                return(Json(new Dictionary <string, object>
                {
                    { "success", 1 },
                    { "message", "Pay Rate  was successfully added." }
                },
                            JsonRequestBehavior.AllowGet));
            }

            else
            {
                return(Json(err, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #2
0
        public async Task <ActionResult> List()
        {
            string staff_id   = CommonHelper.GetValue(Request["staff_id"]);
            int    month      = CommonHelper.GetValue <int>(Request["month"], 0);
            int    year       = CommonHelper.GetValue <int>(Request["year"], 0);
            int    pgnum      = CommonHelper.GetValue <int>(Request["pgnum"], 1);
            int    pgsize     = CommonHelper.GetValue <int>(Request["pgsize"], 0);
            string sortcolumn = CommonHelper.GetValue(Request["sortcolumn"], PayrateHelper.DEFAULT_SORT_COLUMN);
            string sortdir    = CommonHelper.GetValue(Request["sortdir"], PayrateHelper.DEFAULT_SORT_DIR);

            Sort sort = new Sort(sortcolumn, sortdir);

            Dictionary <string, object> filters = new Dictionary <string, object>
            {
                { "staff_id", staff_id },
                { "month", month },
                { "year", year }
            };

            ListModel <Payrate> l = null;

            if (string.IsNullOrEmpty(staff_id) && month == 0 && year == 0)
            {
                l = await PayrateHelper.GetAll(pgnum, pgsize, sort);
            }

            else
            {
                l = await PayrateHelper.GetFilterBy(filters, pgnum, pgsize, sort);
            }

            return(View("_list", l));
        }
コード例 #3
0
        //
        // GET: /Admin/PayRate/

        public async Task <ActionResult> Index()
        {
            ListModel <Payrate> l = null;

            l = await PayrateHelper.GetAll();

            return(View(l));
        }
コード例 #4
0
        public async Task <JsonResult> Delete(FormCollection fc)
        {
            string staff_id = CommonHelper.GetValue(Request["staff_id"]);
            int    month    = CommonHelper.GetValue <int>(Request["month"], 0);
            int    year     = CommonHelper.GetValue <int>(Request["year"], 0);
            int    pgnum    = CommonHelper.GetValue <int>(Request["pgnum"], 1);
            int    pgsize   = CommonHelper.GetValue <int>(Request["pgsize"], 0);
            string ids      = fc.Get("id[]");

            string[] idlist = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            string itemscount = null;

            Dictionary <string, object> filters = new Dictionary <string, object>
            {
                { "staff_id", staff_id },
                { "month", month },
                { "year", year }
            };

            ISession se = NHibernateHelper.CurrentSession;

            await Task.Run(() =>
            {
                using (ITransaction tx = se.BeginTransaction())
                {
                    se.CreateQuery("delete from Payrate where id in (:idlist)")
                    .SetParameterList("idlist", idlist)
                    .ExecuteUpdate();
                    tx.Commit();
                }
            });

            if (string.IsNullOrEmpty(staff_id) && month == 0 && year == 0)
            {
                itemscount = await PayrateHelper.GetItemMessage(null, pgnum, pgsize);
            }

            else
            {
                itemscount = await PayrateHelper.GetItemMessage(filters, pgnum, pgsize);
            }

            return(Json(new Dictionary <string, object>
            {
                { "success", 1 },
                { "itemscount", itemscount },
                { "message", string.Format("{0} pay rate(s) was successfully deleted.", idlist.Length) }
            },
                        JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
        public async Task <JsonResult> Data()
        {
            string staff_id = CommonHelper.GetValue(Request["staff_id"]);
            string _month   = Request["month"];
            string _year    = CommonHelper.GetValue(Request["year"], "0");

            if (string.IsNullOrEmpty(_month))
            {
                _month = Request["month[]"];
            }

            if (string.IsNullOrEmpty(_month))
            {
                _month = "0";
            }

            string title = "Hourly Payroll";
            string yaxis = "Total Amount (RM)";

            object[] o          = new object[12];
            double[] b          = new double[12];
            string[] categories = new string[12];
            double[] c          = new double[12];

            for (int i = 1; i < 13; i++)
            {
                o[i - 1] = new object[, ] {
                    { CommonHelper.GetMonthName(i), 0 }
                };
                categories[i - 1] = CommonHelper.GetAbbreviatedMonthName(i);
            }

            ISession se = NHibernateHelper.CurrentSession;

            ICriteria cr = se.CreateCriteria <Payrate>();

            List <string> liststaff = new List <string>();
            List <int>    listyear  = new List <int>();
            List <int>    listmonth = new List <int>();

            if (!string.IsNullOrEmpty(staff_id))
            {
                liststaff.Add(staff_id);
            }

            else
            {
                cr.SetProjection(Projections.Distinct(Projections.ProjectionList()
                                                      .Add(Projections.Alias(Projections.Property("Staffid"), "Staffid"))));

                cr.SetResultTransformer(new AliasToBeanResultTransformer(typeof(Payrate)));

                IList <Payrate> list = await Task.Run(() => { return(cr.List <Payrate>()); });

                await Task.Run(() =>
                {
                    foreach (Payrate x in list)
                    {
                        liststaff.Add(x.Staffid);
                    }
                });
            }

            if (_year != "0")
            {
                int year = Convert.ToInt32(_year);
                listyear.Add(year);
                title = string.Format("Hourly Payroll for {0}", year);
            }

            else
            {
                cr.SetProjection(Projections.Distinct(Projections.ProjectionList()
                                                      .Add(Projections.Alias(Projections.Property("Year"), "Year"))));

                cr.SetResultTransformer(new AliasToBeanResultTransformer(typeof(Payrate)));

                IList <Payrate> list = await Task.Run(() => { return(cr.List <Payrate>()); });

                await Task.Run(() =>
                {
                    foreach (Payrate x in list)
                    {
                        listyear.Add(x.Year);
                    }
                });
            }

            if (_month != "0")
            {
                string[] monthlist = _month.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string x in monthlist)
                {
                    listmonth.Add(Convert.ToInt32(x));
                }
            }

            else
            {
                for (int i = 1; i < 13; i++)
                {
                    listmonth.Add(i);
                }
            }

            foreach (int y in listyear)
            {
                foreach (int m in listmonth)
                {
                    foreach (string s in liststaff)
                    {
                        Dictionary <string, object> filters = new Dictionary <string, object>
                        {
                            { "year", y },
                            { "month", m },
                            { "staff_id", s }
                        };

                        double total_hours = await AttendanceHelper.GetTotalHours(filters);

                        double rate = await PayrateHelper.GetPayRate(filters);

                        double v = total_hours * rate;
                        object[,] t = o[m - 1] as object[, ];
                        double x = Convert.ToDouble(t[0, 1]);
                        x        += v;
                        t[0, 1]   = x;
                        b[m - 1] += v;
                    }
                }
            }

            for (int i = 0; i < b.Length; i++)
            {
                c[i] = Math.Round(b[i], 2);
            }

            return(Json(new Dictionary <string, object>
            {
                { "pie", o },
                { "column", new Dictionary <string, object>
                  {
                      { "data", c },
                      { "categories", categories },
                      { "yaxis", yaxis }
                  } },
                { "title", title }
            },
                        JsonRequestBehavior.AllowGet));
        }