예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            double total   = 0;
            double hrs     = 0;
            double payOver = 0;
            double days    = 0;

            try
            {
                fromDate = Convert.ToDateTime(startLbl.Text).ToString("dd-MM-yyyy");
                toDate   = Convert.ToDateTime(endLbl.Text).ToString("dd-MM-yyyy");
            }
            catch (Exception k) {
                fromDate = DateTime.Now.ToString("dd-MM-yyyy");
                toDate   = DateTime.Now.ToString("dd-MM-yyyy");
            }

            LoadingWindow.ShowSplashScreen();
            LoadDeduction(fromDate, toDate);
            string Qs = "SELECT starts,period,userID,customerID FROM schedule  WHERE `date` >= '" + fromDate + "' AND  `date` <= '" + toDate + "'";

            MySqlDataReader Reader1 = MySQL.Reading(Qs);
            OnDays          l       = new OnDays();
            List <OnDays>   oD      = new List <OnDays>();

            while (Reader1.Read())
            {
                l = new OnDays(Convert.ToDateTime(Reader1["starts"]).ToString("ddd"), Reader1["period"].ToString(), Reader1["userID"].ToString(), Reader1["customerID"].ToString());
                oD.Add(l);
            }
            DBConnect.CloseMySqlConn();


            Payroll r = new Payroll();
            string  Q = "SELECT users.name,rate.period AS maxs ,customer.name AS client,customer.id AS customerID,rate.amount,account.bank,account.routing,SUM(schedule.period ) AS totalhours,SUM(schedule.cost ) AS cost,schedule.userID AS userID FROM schedule LEFT JOIN users ON schedule.userID = users.id LEFT JOIN customer ON schedule.customerID = customer.id LEFT JOIN rate ON users.id = rate.userID LEFT JOIN account ON users.id = account.userid LEFT JOIN deduction ON users.id = deduction.userID  WHERE (schedule.`date` >= '" + fromDate + "' AND  schedule.`date` <= '" + toDate + "') GROUP BY schedule.userID,users.name,customer.name,users.name,account.bank,account.routing,rate.amount,rate.period,customer.id";

            MySqlDataReader Reader = MySQL.Reading(Q);
            int             ct     = 0;
            double          ded    = 0;

            double totalHrs = 0;
            double maxs     = 0;
            double amount   = 0;

            while (Reader.Read())
            {
                if (ct == 1)
                {
                    ded = deductionDictionary.Where(u => u.Key.Contains(Reader["userID"].ToString())).Sum(k => k.Value);
                }
                else
                {
                    ded = 0;
                }

                totalHrs = Convert.ToDouble(Reader["totalhours"]);
                try
                {
                    maxs = Convert.ToDouble(Reader["maxs"]);
                }
                catch {
                }
                try
                {
                    amount = Convert.ToDouble(Reader["amount"]);
                }
                catch
                {
                }
                total = Convert.ToDouble(Reader["cost"]);
                double overtime = 0;
                if (totalHrs > maxs)
                {
                    overtime = totalHrs - maxs;
                }
                else
                {
                    overtime = 0;
                }
                double half        = amount / 2;
                double timeHalf    = amount + half;
                double overtimePay = timeHalf * overtime;
                double pay         = (total + overtimePay) - ded;
                string daying      = "";

                foreach (OnDays u in oD.Where(y => y.UserID.Contains(Reader["userID"].ToString()) && y.ClientID.Contains(Reader["customerID"].ToString())))
                {
                    daying = daying + "\n" + u.Day + "\t\t" + u.Hrs;
                }
                r = new Payroll(Reader["name"].ToString(), Reader["client"].ToString(), Reader["bank"].ToString() + "  " + Reader["routing"].ToString(), daying, days, "", Convert.ToDouble(Reader["totalhours"]), amount, Convert.ToDouble(Reader["cost"]), ded, pay, overtime, overtimePay);

                reports.Add(r);
                ct++;
            }
            DBConnect.CloseMySqlConn();

            /** end restaurant profit**/
            // Microsoft.Reporting.WinForms.ReportParameter rp = new Microsoft.Reporting.WinForms.ReportParameter("week", week.ToString());
            // this.reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter[] { rp });
            this.PayrollBindingSource.DataSource = reports;
            reportViewer1.RefreshReport();
            LoadingWindow.CloseForm();
        }
예제 #2
0
        public void LoadData(string fromDate, string toDate)
        {
            // create and execute query
            t = new DataTable();
            t.Columns.Add(new DataColumn("Select", typeof(bool)));
            t.Columns.Add("id");
            t.Columns.Add("uri");
            t.Columns.Add(new DataColumn("Img", typeof(Bitmap)));//1
            t.Columns.Add("Name");
            t.Columns.Add("No");
            t.Columns.Add("Date");
            t.Columns.Add("Method");
            t.Columns.Add("Start");
            t.Columns.Add("Ending");
            t.Columns.Add("Days");
            t.Columns.Add("Week");
            t.Columns.Add("Rate");
            t.Columns.Add("Hours");
            t.Columns.Add("Amount");
            t.Columns.Add("Over time Hours");
            t.Columns.Add("Over time Rate");
            t.Columns.Add("Over time Pay");
            t.Columns.Add("Deductions");
            t.Columns.Add("Paid");
            t.Columns.Add(new DataColumn("View", typeof(Image)));
            t.Columns.Add(new DataColumn("Delete", typeof(Image)));
            Bitmap b = new Bitmap(50, 50);

            using (Graphics g = Graphics.FromImage(b))
            {
                g.DrawString("Loading...", this.Font, new SolidBrush(Color.Black), 0f, 0f);
            }
            Image view   = new Bitmap(Properties.Resources.Note_Memo_16);
            Image delete = new Bitmap(Properties.Resources.Server_Delete_16);


            string Q = "SELECT * FROM pay WHERE (`date` >= '" + fromDate + "'  AND  `date` <= '" + toDate + "')";

            foreach (Pay c in Pay.List(Q))
            {
                string daying = "";
                string Qs     = "SELECT starts,period,userID,customerID FROM schedule  WHERE (`date` >= '" + c.Starts + "' AND  `date` <= '" + c.Ends + "')";

                MySqlDataReader Reader1 = MySQL.Reading(Qs);
                OnDays          l       = new OnDays();
                List <OnDays>   oD      = new List <OnDays>();
                while (Reader1.Read())
                {
                    l = new OnDays(Convert.ToDateTime(Reader1["starts"]).ToString("ddd"), Reader1["period"].ToString(), Reader1["userID"].ToString(), Reader1["customerID"].ToString());
                    oD.Add(l);
                }
                DBConnect.CloseMySqlConn();
                int ct = 1;
                foreach (OnDays u in oD.Where(y => y.UserID.Contains(c.UserID)))
                {
                    daying = daying + "\n" + ct++ + "." + u.Day + "\t\t-" + u.Hrs + "Hrs ";
                }
                string user = "";

                string imageUs = "";
                try { user = GenericCollection.users.Where(r => r.Id == c.UserID).First().Name; } catch { }
                try { imageUs = GenericCollection.users.Where(r => r.Id == c.UserID).First().Image; } catch { }

                try
                {
                    t.Rows.Add(new object[] { "false", c.Id, imageUs as string, b, user, c.No, c.Date, c.Method, c.Starts, c.Ends, daying, c.Week, c.Rate, c.Hours, c.Amount.ToString("N0"), c.OvertimeHrs, c.OvertimeRate, c.OvertimePay.ToString("N0"), c.Deductions.ToString("N0"), c.Paid, view, delete });
                }
                catch (Exception m)
                {
                    MessageBox.Show("" + m.Message);
                    Helper.Exceptions(m.Message, "Viewing pay slips { list }" + c.Date);
                }
            }

            dtGrid.DataSource = t;

            ThreadPool.QueueUserWorkItem(delegate
            {
                foreach (DataRow row in t.Rows)
                {
                    try
                    {
                        Image img = Helper.Base64ToImage(row["uri"].ToString().Replace('"', ' ').Trim());
                        System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img);
                        Bitmap bps     = new Bitmap(bmp, 50, 50);
                        Image dstImage = Helper.CropToCircle(bps, Color.White);
                        row["Img"]     = dstImage;
                    }
                    catch
                    {
                    }
                }
            });

            dtGrid.AllowUserToAddRows = false;
            dtGrid.Columns["Start"].DefaultCellStyle.BackColor  = Color.LightGreen;
            dtGrid.Columns["Ending"].DefaultCellStyle.BackColor = Color.PaleGoldenrod;
            dtGrid.RowTemplate.Height     = 60;
            dtGrid.Columns["uri"].Visible = false;
            dtGrid.Columns["id"].Visible  = false;
            // dtGrid.Columns["select"].Width = 30;
        }